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_server;
16pub mod metadata;
17pub mod orchestration;
18pub mod runtime_paths;
19pub mod schema;
20pub mod stdlib;
21pub mod stdlib_modules;
22pub mod store;
23pub mod tool_annotations;
24pub mod tracing;
25pub mod value;
26pub mod visible_text;
27mod vm;
28
29pub use checkpoint::register_checkpoint_builtins;
30pub use chunk::*;
31pub use compiler::*;
32pub use http::{register_http_builtins, reset_http_state};
33pub use llm::register_llm_builtins;
34pub use mcp::{
35    connect_mcp_server, connect_mcp_server_from_json, connect_mcp_server_from_spec,
36    register_mcp_builtins,
37};
38pub use mcp_server::{
39    take_mcp_serve_prompts, take_mcp_serve_registry, take_mcp_serve_resource_templates,
40    take_mcp_serve_resources, tool_registry_to_mcp_tools, McpServer,
41};
42pub use metadata::{register_metadata_builtins, register_scan_builtins};
43pub use stdlib::host::{clear_host_call_bridge, set_host_call_bridge, HostCallBridge};
44pub use stdlib::{
45    register_agent_stdlib, register_core_stdlib, register_io_stdlib, register_vm_stdlib,
46};
47pub use store::register_store_builtins;
48pub use value::*;
49pub use vm::*;
50
51/// Lex, parse, type-check, and compile source to bytecode in one call.
52/// Bails on the first type error. For callers that need diagnostics
53/// rather than early exit, use `harn_parser::check_source` directly
54/// and then call `Compiler::new().compile(&program)`.
55pub fn compile_source(source: &str) -> Result<Chunk, String> {
56    let program = harn_parser::check_source_strict(source).map_err(|e| e.to_string())?;
57    Compiler::new().compile(&program).map_err(|e| e.to_string())
58}
59
60/// Reset all thread-local state that can leak between test runs.
61pub fn reset_thread_local_state() {
62    llm::reset_llm_state();
63    http::reset_http_state();
64    stdlib::reset_stdlib_state();
65    events::reset_event_sinks();
66    agent_events::reset_all_sinks();
67    agent_sessions::reset_session_store();
68}