Skip to main content

nanocodex_tools/
lib.rs

1#![doc = include_str!("../README.md")]
2#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4#![cfg_attr(target_family = "wasm", allow(clippy::module_name_repetitions))]
5
6#[cfg(not(target_family = "wasm"))]
7mod apply_patch;
8#[cfg(not(target_family = "wasm"))]
9#[cfg_attr(docsrs, doc(cfg(not(target_family = "wasm"))))]
10pub mod code_mode;
11pub mod hosted;
12#[cfg(not(target_family = "wasm"))]
13#[cfg_attr(docsrs, doc(cfg(not(target_family = "wasm"))))]
14pub mod image;
15#[cfg(not(target_family = "wasm"))]
16mod image_generation;
17#[cfg(not(target_family = "wasm"))]
18#[cfg_attr(docsrs, doc(cfg(not(target_family = "wasm"))))]
19pub mod mcp;
20#[cfg(not(target_family = "wasm"))]
21mod plan;
22#[cfg(not(target_family = "wasm"))]
23#[cfg_attr(docsrs, doc(cfg(not(target_family = "wasm"))))]
24pub mod runtime;
25mod runtime_config;
26#[cfg(not(target_family = "wasm"))]
27mod shell;
28#[cfg(not(target_family = "wasm"))]
29#[cfg_attr(docsrs, doc(cfg(not(target_family = "wasm"))))]
30pub mod standard;
31#[cfg(not(target_family = "wasm"))]
32mod view_image;
33#[cfg(not(target_family = "wasm"))]
34mod web_search;
35
36/// Model-visible tool definitions, inputs, outputs, and execution contracts.
37pub mod contract {
38    #[cfg(not(target_family = "wasm"))]
39    #[cfg_attr(docsrs, doc(cfg(not(target_family = "wasm"))))]
40    pub use async_trait::async_trait;
41    pub use nanocodex_oai_api::tools::{
42        DEFAULT_TOOL_OUTPUT_TOKENS, Tool, ToolContext, ToolDefinition, ToolError, ToolInput,
43        ToolInputError, ToolOutput, ToolOutputBody, ToolOutputContent, ToolOutputWire,
44        ToolProcessTraceWire, ToolResult,
45    };
46}
47
48#[cfg(target_family = "wasm")]
49/// Code Mode results and observation contracts for the host-backed WASM runtime.
50pub mod code_mode {
51    pub use crate::hosted::{
52        CodeModeExecution, CodeModeNotification, CodeModeObserver, CodeModeUpdate, NestedToolCall,
53    };
54}
55
56#[cfg(target_family = "wasm")]
57/// Image input and output preparation for the host-backed WASM runtime.
58pub mod image {
59    pub use crate::hosted::{prepare_output_images, prepare_user_input};
60    pub use nanocodex_oai_api::ImageDetail;
61}
62
63#[cfg(target_family = "wasm")]
64/// Host-backed tool selection and execution runtime.
65pub mod runtime {
66    pub use crate::{
67        hosted::{
68            HostedToolRuntime as ToolRuntime, HostedToolRuntimeControl as ToolRuntimeControl,
69            HostedTools as Tools, OwnedToolContext,
70        },
71        runtime_config::{ImageGenerationConfig, WebSearchConfig},
72    };
73}
74
75pub use contract::{Tool, ToolContext, ToolDefinition, ToolInput, ToolOutput, ToolResult};
76#[cfg(not(target_family = "wasm"))]
77pub(crate) use contract::{ToolOutputBody, ToolOutputContent};
78#[cfg(not(target_family = "wasm"))]
79pub(crate) use image::ImageDetail;
80#[cfg(not(target_family = "wasm"))]
81#[cfg_attr(docsrs, doc(cfg(not(target_family = "wasm"))))]
82pub use nanocodex_tools_macros::tool;
83pub use runtime::Tools;
84#[cfg(not(target_family = "wasm"))]
85pub(crate) use runtime::{DynamicToolProvider, ImageGenerationConfig, WebSearchConfig};
86#[cfg(not(target_family = "wasm"))]
87#[cfg_attr(docsrs, doc(cfg(not(target_family = "wasm"))))]
88pub use runtime::{ToolsBuildError, ToolsBuilder};
89#[cfg(not(target_family = "wasm"))]
90pub(crate) use standard::StandardTool;
91
92#[doc(hidden)]
93pub mod __private {
94    #[cfg(not(target_family = "wasm"))]
95    pub use async_trait::async_trait;
96    #[cfg(not(target_family = "wasm"))]
97    pub use schemars;
98    #[cfg(not(target_family = "wasm"))]
99    pub use serde;
100
101    #[cfg(not(target_family = "wasm"))]
102    pub use crate::{
103        Tool, ToolContext, ToolDefinition, ToolInput, ToolOutput, ToolResult, runtime::schema_for,
104    };
105
106    /// Builds the direct Responses tool prefix and the nested Code Mode name map together.
107    pub fn model_contract(
108        runtime: &crate::runtime::ToolRuntime,
109        session_id: &str,
110    ) -> (
111        Vec<nanocodex_oai_api::tools::ToolDefinition>,
112        Vec<(String, String)>,
113    ) {
114        runtime.model_contract(session_id)
115    }
116}