Skip to main content

yapi_core/extensions/
codemode.rs

1//! What other parts of a session know about the `codemode` tool, which
2//! `yapi-ext` implements: its name, schema and prompt text, and how to tell the
3//! genuine tool from another extension's tool of the same name.
4
5use serde_json::{Value, json};
6
7use super::ToolInfo;
8use crate::tools::Exposure;
9
10/// The tool's name.
11pub const NAME: &str = "codemode";
12
13/// Its line in the system prompt's tool list.
14pub const SNIPPET: &str = "Run JavaScript that calls other tools";
15
16/// Its rule in the system prompt.
17pub const GUIDELINE: &str = "Use codemode to batch independent tool calls (Promise.allSettled), chain them, or filter large output, instead of many separate calls.";
18
19/// Its argument schema.
20pub fn parameters() -> Value {
21    json!({"type":"object","required":["code"],"properties":{"code":{"type":"string","description":"Raw JavaScript source."}}})
22}
23
24/// Whether `tool` is the codemode tool, as pi's `isCodemodeTool`, rather than
25/// another extension's tool of that name.
26pub fn is_codemode_tool(tool: &ToolInfo) -> bool {
27    tool.name == NAME && tool.exposure == Exposure::ModelOnly && tool.parameters == parameters()
28}