/** * Shared tool plumbing: the definition shape dsh's ToolRuntime accepts, * parameter compilation, argument narrowing, cancellation handling and the * per-call key resolution. * * @module dsh-realtimeavatar/tools/shared */ import type { CallContext } from '../api.js'; import type { ResolvedRtaConfig } from '../config.js'; import { type KeySource } from '../credentials.js'; /** A model-visible content block. */ export interface ContentBlock { type: 'text'; text: string; } /** The raw tool definition passed to ctx.tools.register. */ export interface RtaToolDefinition { name: string; description: string; parameters: { type: 'object'; properties: Record; required?: string[]; }; output: { schema: Record; render(args: unknown, value: unknown): ContentBlock[]; }; execute(args: unknown, exec: unknown): Promise; timeoutMs?: number; isConcurrencySafe?(args: unknown): boolean; } /** Everything the tools need from the plugin, injectable for tests. */ export interface ToolDeps { cfg: ResolvedRtaConfig; /** Evaluated per call so a credential service that appears later is picked up. */ keySource: () => KeySource; randomUUID: () => string; /** Absolute path of the shipped skills directory (snapshot fallback for rta_quickstart). */ skillsDir: string; configError?: string; } export interface ParamSpec { type?: string; description?: string; required?: boolean; items?: unknown; enum?: readonly string[]; properties?: Record; } export declare function compileParameters(spec: Record): RtaToolDefinition['parameters']; export declare function asRecord(value: unknown): Record; /** The harness's cancellation signal from the second execute() argument, when present. */ export declare function signalOf(exec: unknown): AbortSignal | undefined; /** * Run a tool body under the harness's cancellation signal. When the harness * aborted the call, settle with `empty` instead of throwing: dsh reports a body * that resolves after its signal aborted as its canonical ABORTED outcome. */ export declare function cancellable(signal: AbortSignal | undefined, empty: unknown, body: () => Promise): Promise; /** Read `aborted` through a call so TypeScript does not narrow the property across awaits. */ export declare function isAborted(signal: AbortSignal | undefined): boolean; export declare function optionalString(args: Record, key: string, max?: number): string | undefined; export declare function requiredString(args: Record, key: string, max?: number): string; export declare function optionalInt(args: Record, key: string, min: number, max: number): number | undefined; export declare function optionalEnum(args: Record, key: string, allowed: readonly T[]): T | undefined; export declare function optionalRecord(args: Record, key: string): Record | undefined; /** Resolve the key and build the per-call context. Throws a coded KeyError when no key is usable. */ export declare function callContext(deps: ToolDeps, signal: AbortSignal | undefined): Promise; /** Render any value as redacted, pretty JSON (total: never throws). */ export declare function renderJson(value: unknown, maxChars?: number): ContentBlock[]; /** Redacted text block. */ export declare function textBlock(text: string): ContentBlock[]; /** * Redacting boundary around a tool body: errors the plugin constructs are * already redacted; anything else (a credential service rejecting with the * secret in its message, a serialisation failure) is re-thrown redacted so no * exception can carry the key to the model. */ export declare function guarded(definition: RtaToolDefinition): RtaToolDefinition; /** Common schema fragment. */ export declare const ANY_OBJECT: { readonly type: "object"; readonly additionalProperties: true; }; /** * A nullable scalar/object in dsh's JSON-schema subset: type arrays are not * supported, exact-one `oneOf` with a `null` branch is. */ export declare function nullable(type: 'string' | 'number' | 'integer' | 'boolean' | 'object'): { oneOf: Array>; };