Skip to main content

vifu_runtime/
lib.rs

1//! Embeddable, stateful Agent Runtime primitives for Rust applications.
2//!
3//! Add application behavior as Bevy plugins, dispatch [`RuntimeCommand`] values,
4//! and let the host execute the resulting effects.
5
6mod application;
7pub mod bridge;
8mod manifest;
9pub mod protocol;
10pub mod providers;
11mod runtime;
12#[cfg(feature = "sqlite")]
13mod sqlite_store;
14
15pub use application::{
16    AgentDefinition, AgentProvider, CancellationToken, EffectExecution, EndpointDefinition,
17    InvocationData, InvocationEvent, InvocationEventKind, InvocationHandle, InvocationInput,
18    InvocationOutput, InvocationPoll, InvocationStatus, InvocationTraceEvent, MemoryRuntimeStore,
19    ProviderEvent, ProviderEventSink, ProviderFuture, ProviderRequest, ProviderResponse,
20    ProviderStage, RuntimeError, RuntimeMonitorEvent, RuntimeMonitorObserver,
21    RuntimeMonitorStageStatus, RuntimeMonitorStatus, RuntimeSession, RuntimeStore, VifuRuntime,
22};
23pub use bridge::{
24    RuntimeBridge, RuntimeBridgeCancelParams, RuntimeBridgeError, RuntimeBridgeHelloParams,
25    RuntimeBridgeHelloPayload, RuntimeBridgeInvocationEvent, RuntimeBridgeInvokePayload,
26    RUNTIME_BRIDGE_CANCELLED_EVENT, RUNTIME_BRIDGE_CANCEL_METHOD, RUNTIME_BRIDGE_COMPLETED_EVENT,
27    RUNTIME_BRIDGE_FAILED_EVENT, RUNTIME_BRIDGE_HELLO_METHOD, RUNTIME_BRIDGE_INVOKE_METHOD,
28    RUNTIME_BRIDGE_OUTPUT_DELTA_EVENT, RUNTIME_BRIDGE_STARTED_EVENT,
29    VIFU_RUNTIME_BRIDGE_PROTOCOL_VERSION,
30};
31pub use manifest::{
32    LocalProviderBinding, ProjectSettings, ProviderRequirement, RuntimeManifest, RuntimeRelease,
33    RuntimeTraceRecord, RUNTIME_MANIFEST_SCHEMA_VERSION,
34};
35pub use protocol::{
36    decode_protocol_frame, encode_protocol_frame, ErrorShape, EventFrame, EventFrameType,
37    ProtocolFrame, RequestFrame, RequestFrameType, ResponseFrame, ResponseFrameType, StateVersion,
38    MAX_PROTOCOL_FRAME_BYTES,
39};
40pub use providers::{HttpCapabilityProvider, HttpCapabilityRoute};
41pub use runtime::{
42    EffectRequest, EffectRequestQueue, EffectResult, EffectResultQueue, HeadlessRuntime,
43    RuntimeAdvance, RuntimeCommand, RuntimeCommandQueue, RuntimeEvent, RuntimeEventQueue,
44    RuntimeSchedule, RuntimeSnapshot, RuntimeState, VifuRuntimePlugin,
45};
46#[cfg(feature = "sqlite")]
47pub use sqlite_store::SqliteRuntimeStore;
48
49pub(crate) fn unix_time_ms() -> u64 {
50    std::time::SystemTime::now()
51        .duration_since(std::time::UNIX_EPOCH)
52        .map_or(0, |duration| {
53            u64::try_from(duration.as_millis()).unwrap_or(u64::MAX)
54        })
55}
56
57pub mod prelude {
58    //! Common imports for application runtime plugins.
59
60    pub use bevy_app::{App, Plugin};
61    pub use bevy_ecs::prelude::*;
62    pub use serde_json::{json, Value};
63
64    pub use crate::{
65        AgentDefinition, AgentProvider, CancellationToken, EffectExecution, EffectRequest,
66        EffectRequestQueue, EffectResult, EffectResultQueue, EndpointDefinition, HeadlessRuntime,
67        HttpCapabilityProvider, HttpCapabilityRoute, InvocationData, InvocationEvent,
68        InvocationEventKind, InvocationHandle, InvocationInput, InvocationOutput, InvocationPoll,
69        InvocationStatus, InvocationTraceEvent, MemoryRuntimeStore, ProjectSettings, ProviderEvent,
70        ProviderEventSink, ProviderFuture, ProviderRequest, ProviderRequirement, ProviderResponse,
71        ProviderStage, RuntimeAdvance, RuntimeBridge, RuntimeBridgeError, RuntimeCommand,
72        RuntimeCommandQueue, RuntimeError, RuntimeEvent, RuntimeEventQueue, RuntimeManifest,
73        RuntimeMonitorEvent, RuntimeMonitorObserver, RuntimeMonitorStageStatus,
74        RuntimeMonitorStatus, RuntimeRelease, RuntimeSchedule, RuntimeSession, RuntimeSnapshot,
75        RuntimeState, RuntimeStore, RuntimeTraceRecord, VifuRuntime, VifuRuntimePlugin,
76    };
77}