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
15const MAX_ENDPOINT_TIMEOUT_MS: u64 = 15 * 60 * 1_000;
16
17pub use application::{
18    AgentDefinition, AgentProvider, CancellationToken, EffectExecution, EndpointDefinition,
19    InvocationData, InvocationEvent, InvocationEventKind, InvocationHandle, InvocationInput,
20    InvocationOutput, InvocationPoll, InvocationStatus, InvocationTraceEvent, MemoryRuntimeStore,
21    ProviderEvent, ProviderEventSink, ProviderFuture, ProviderRequest, ProviderResponse,
22    ProviderStage, RuntimeError, RuntimeMonitorEvent, RuntimeMonitorIoEvent,
23    RuntimeMonitorIoObserver, RuntimeMonitorIoSummary, RuntimeMonitorObserver,
24    RuntimeMonitorStageStatus, RuntimeMonitorStatus, RuntimeSession, RuntimeStore, VifuRuntime,
25};
26pub use bridge::{
27    RuntimeBridge, RuntimeBridgeCancelParams, RuntimeBridgeError, RuntimeBridgeHelloParams,
28    RuntimeBridgeHelloPayload, RuntimeBridgeInvocationEvent, RuntimeBridgeInvokePayload,
29    RUNTIME_BRIDGE_CANCELLED_EVENT, RUNTIME_BRIDGE_CANCEL_METHOD, RUNTIME_BRIDGE_COMPLETED_EVENT,
30    RUNTIME_BRIDGE_FAILED_EVENT, RUNTIME_BRIDGE_HELLO_METHOD, RUNTIME_BRIDGE_INVOKE_METHOD,
31    RUNTIME_BRIDGE_OUTPUT_DELTA_EVENT, RUNTIME_BRIDGE_STARTED_EVENT,
32    VIFU_RUNTIME_BRIDGE_PROTOCOL_VERSION,
33};
34pub use manifest::{
35    LocalProviderBinding, ProjectSettings, ProviderRequirement, RuntimeManifest, RuntimeRelease,
36    RuntimeTraceRecord, RUNTIME_MANIFEST_SCHEMA_VERSION,
37};
38pub use protocol::{
39    decode_protocol_frame, encode_protocol_frame, ErrorShape, EventFrame, EventFrameType,
40    ProtocolFrame, RequestFrame, RequestFrameType, ResponseFrame, ResponseFrameType, StateVersion,
41    MAX_PROTOCOL_FRAME_BYTES,
42};
43#[cfg(feature = "local-whisper")]
44pub use providers::LocalWhisperProvider;
45pub use providers::{HttpCapabilityProvider, HttpCapabilityRoute};
46pub use runtime::{
47    EffectRequest, EffectRequestQueue, EffectResult, EffectResultQueue, HeadlessRuntime,
48    RuntimeAdvance, RuntimeCommand, RuntimeCommandQueue, RuntimeEvent, RuntimeEventQueue,
49    RuntimeSchedule, RuntimeSnapshot, RuntimeState, VifuRuntimePlugin,
50};
51#[cfg(feature = "sqlite")]
52pub use sqlite_store::SqliteRuntimeStore;
53
54pub(crate) fn unix_time_ms() -> u64 {
55    std::time::SystemTime::now()
56        .duration_since(std::time::UNIX_EPOCH)
57        .map_or(0, |duration| {
58            u64::try_from(duration.as_millis()).unwrap_or(u64::MAX)
59        })
60}
61
62pub mod prelude {
63    //! Common imports for application runtime plugins.
64
65    pub use bevy_app::{App, Plugin};
66    pub use bevy_ecs::prelude::*;
67    pub use serde_json::{json, Value};
68
69    #[cfg(feature = "local-whisper")]
70    pub use crate::LocalWhisperProvider;
71    pub use crate::{
72        AgentDefinition, AgentProvider, CancellationToken, EffectExecution, EffectRequest,
73        EffectRequestQueue, EffectResult, EffectResultQueue, EndpointDefinition, HeadlessRuntime,
74        HttpCapabilityProvider, HttpCapabilityRoute, InvocationData, InvocationEvent,
75        InvocationEventKind, InvocationHandle, InvocationInput, InvocationOutput, InvocationPoll,
76        InvocationStatus, InvocationTraceEvent, MemoryRuntimeStore, ProjectSettings, ProviderEvent,
77        ProviderEventSink, ProviderFuture, ProviderRequest, ProviderRequirement, ProviderResponse,
78        ProviderStage, RuntimeAdvance, RuntimeBridge, RuntimeBridgeError, RuntimeCommand,
79        RuntimeCommandQueue, RuntimeError, RuntimeEvent, RuntimeEventQueue, RuntimeManifest,
80        RuntimeMonitorEvent, RuntimeMonitorIoEvent, RuntimeMonitorIoObserver,
81        RuntimeMonitorIoSummary, RuntimeMonitorObserver, RuntimeMonitorStageStatus,
82        RuntimeMonitorStatus, RuntimeRelease, RuntimeSchedule, RuntimeSession, RuntimeSnapshot,
83        RuntimeState, RuntimeStore, RuntimeTraceRecord, VifuRuntime, VifuRuntimePlugin,
84    };
85}