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