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
54#[cfg(not(target_arch = "wasm32"))]
55pub(crate) fn unix_time_ms() -> u64 {
56    std::time::SystemTime::now()
57        .duration_since(std::time::UNIX_EPOCH)
58        .map_or(0, |duration| {
59            u64::try_from(duration.as_millis()).unwrap_or(u64::MAX)
60        })
61}
62
63#[cfg(target_arch = "wasm32")]
64pub(crate) fn unix_time_ms() -> u64 {
65    js_sys::Date::now().max(0.0) as u64
66}
67
68pub mod prelude {
69    //! Common imports for application runtime plugins.
70
71    pub use bevy_app::{App, Plugin};
72    pub use bevy_ecs::prelude::*;
73    pub use serde_json::{json, Value};
74
75    #[cfg(feature = "local-whisper")]
76    pub use crate::LocalWhisperProvider;
77    pub use crate::{
78        AgentDefinition, AgentProvider, CancellationToken, EffectExecution, EffectRequest,
79        EffectRequestQueue, EffectResult, EffectResultQueue, EndpointDefinition, HeadlessRuntime,
80        HttpCapabilityProvider, HttpCapabilityRoute, InvocationData, InvocationEvent,
81        InvocationEventKind, InvocationHandle, InvocationInput, InvocationOutput, InvocationPoll,
82        InvocationStatus, InvocationTraceEvent, MemoryRuntimeStore, ProjectSettings, ProviderEvent,
83        ProviderEventSink, ProviderFuture, ProviderRequest, ProviderRequirement, ProviderResponse,
84        ProviderStage, RuntimeAdvance, RuntimeBridge, RuntimeBridgeError, RuntimeCommand,
85        RuntimeCommandQueue, RuntimeError, RuntimeEvent, RuntimeEventQueue, RuntimeManifest,
86        RuntimeMonitorEvent, RuntimeMonitorIoEvent, RuntimeMonitorIoObserver,
87        RuntimeMonitorIoSummary, RuntimeMonitorObserver, RuntimeMonitorStageStatus,
88        RuntimeMonitorStatus, RuntimeRelease, RuntimeSchedule, RuntimeSession, RuntimeSnapshot,
89        RuntimeState, RuntimeStore, RuntimeTraceRecord, VifuRuntime, VifuRuntimePlugin,
90    };
91}