Skip to main content

harn_vm/
lib.rs

1#![allow(clippy::result_large_err, clippy::cloned_ref_to_slice_refs)]
2
3pub mod agent_events;
4pub mod agent_sessions;
5pub mod bridge;
6pub mod checkpoint;
7mod chunk;
8mod compiler;
9pub mod events;
10mod http;
11pub mod jsonrpc;
12pub mod llm;
13pub mod llm_config;
14pub mod mcp;
15pub mod mcp_card;
16pub mod mcp_registry;
17pub mod mcp_server;
18pub mod metadata;
19pub mod orchestration;
20pub mod runtime_paths;
21pub mod schema;
22pub mod skills;
23pub mod stdlib;
24pub mod stdlib_modules;
25pub mod store;
26pub mod tool_annotations;
27pub mod tracing;
28pub mod value;
29pub mod visible_text;
30mod vm;
31
32pub use checkpoint::register_checkpoint_builtins;
33pub use chunk::*;
34pub use compiler::*;
35pub use http::{register_http_builtins, reset_http_state};
36pub use llm::register_llm_builtins;
37pub use mcp::{
38    connect_mcp_server, connect_mcp_server_from_json, connect_mcp_server_from_spec,
39    register_mcp_builtins,
40};
41pub use mcp_card::{fetch_server_card, load_server_card_from_path, CardError};
42pub use mcp_registry::{
43    active_handle as mcp_active_handle, ensure_active as mcp_ensure_active,
44    get_registration as mcp_get_registration, install_active as mcp_install_active,
45    is_registered as mcp_is_registered, register_servers as mcp_register_servers,
46    release as mcp_release, reset as mcp_reset_registry, snapshot_status as mcp_snapshot_status,
47    sweep_expired as mcp_sweep_expired, RegisteredMcpServer, RegistryStatus,
48};
49pub use mcp_server::{
50    take_mcp_serve_prompts, take_mcp_serve_registry, take_mcp_serve_resource_templates,
51    take_mcp_serve_resources, tool_registry_to_mcp_tools, McpServer,
52};
53pub use metadata::{register_metadata_builtins, register_scan_builtins};
54pub use stdlib::host::{clear_host_call_bridge, set_host_call_bridge, HostCallBridge};
55pub use stdlib::template::{
56    lookup_prompt_consumers, lookup_prompt_span, prompt_render_indices, record_prompt_render_index,
57    PromptSourceSpan, PromptSpanKind,
58};
59pub use stdlib::{
60    register_agent_stdlib, register_core_stdlib, register_io_stdlib, register_vm_stdlib,
61};
62pub use store::register_store_builtins;
63pub use value::*;
64pub use vm::*;
65
66/// Lex, parse, type-check, and compile source to bytecode in one call.
67/// Bails on the first type error. For callers that need diagnostics
68/// rather than early exit, use `harn_parser::check_source` directly
69/// and then call `Compiler::new().compile(&program)`.
70pub fn compile_source(source: &str) -> Result<Chunk, String> {
71    let program = harn_parser::check_source_strict(source).map_err(|e| e.to_string())?;
72    Compiler::new().compile(&program).map_err(|e| e.to_string())
73}
74
75/// Reset all thread-local state that can leak between test runs.
76pub fn reset_thread_local_state() {
77    llm::reset_llm_state();
78    http::reset_http_state();
79    stdlib::reset_stdlib_state();
80    events::reset_event_sinks();
81    agent_events::reset_all_sinks();
82    agent_sessions::reset_session_store();
83    mcp_registry::reset();
84}