scripts/gen-website-api.ts renders website/zh-CN/api/{cordis,harness}/* and the
api-sidebar.json fragment the VitePress config imports, so pages and navigation
can never drift from the code: signatures, @param/@returns prose, dispatch
modes, and GitHub source links are extracted, never transcribed, and the
generator hard-errors on any rendered member missing docs. verify-website-api
(doc-sync + run-gates) is the freshness gate.
Replaces the hand-written zh api pages (7 pages covering 7 of 15 services,
with phantom APIs: Context.current/Context.events, agent/post-step, tool/call,
compact/*, llm/pre-request none of which exist) with generated English
references: 5 cordis pages, 15 per-service pages, and a 35-event catalog
grouped by scope. The hand-written hub api/index.md stays and now indexes the
full surface; zh for these pages arrives with the unified translation flow.
3.7 KiB
ctx.tools
ToolRegistry — provided by @deepseek-ai/dsh-tools.
Tool registry (ctx.tools): tool plugins register definitions; the agent loop executes calls through the tools/pre-execute → tools/execute → tools/post-execute pipeline. The registry contributes its schemas into the system-prompt assembly — WHICH schemas is governed by its mode config (see Config.mode); under a non-native mode it also registers the run_code tool and the tools:sdk prompt section itself.
ctx.tools.register(definition)
register(definition: ToolDefinition): () => void
Register a tool. Throws if a tool with the same name is already registered. The tool's schema (minus the execute function) is automatically contributed to the system-prompt assembly. Disposed with the calling fiber. Emits tools/change on register/unregister.
definition— the tool's schema plus its execute (and optional presentation) functions.
Returns the disposer that unregisters the tool.
ctx.tools.get(name)
get(name: string): ToolDefinition | undefined
Look up a registered tool.
name— the tool name as registered.
Returns the definition, or undefined when no tool has that name.
ctx.tools.schemas()
schemas(): ToolSchema[]
Return all registered tool schemas — exactly the model-facing fields (name, description, parameters), as sent to the model via the system-prompt assembly. Constructed EXPLICITLY rather than by stripping known non-schema members: a ToolDefinition also carries execute and the optional presentCall/presentResult UI callbacks, and those (especially the functions) must never leak into a model request. An allowlist can't drift when a new non-schema member is added to the definition; a denylist (rest-destructure) would silently leak it.
Returns one deep-cloned schema per registered tool, in registration order.
ctx.tools.execute(exec)
async execute(exec: ToolExecution): Promise<ToolExecutionResult>
Execute one tool call through the tools/pre-execute → tools/execute (around dispatch) → tools/post-execute pipeline. pre-execute is the gate (allow/deny), tools/execute wraps core dispatch (a timeout/retry/metrics seam), and post-execute is the inspect/transform seam; core dispatch sits as the base next() of the tools/execute waterfall. The whole thing is wrapped in one outer try/catch so a throwing listener (in any waterfall) becomes an isError result instead of failing the turn; the tool body ALSO keeps its own inner try/catch, so a thrown tool becomes an isError result that tools/execute and post-execute listeners can still inspect. If the tool is not registered, the result is an isError carrying a UNKNOWN_TOOL structured error. A thrown HarnessError surfaces its { name, code } on the result.
exec— the call to run (name, parsed arguments, caller agent, signal).
Returns the final result after every waterfall; failures resolve as isError results, never rejections.