/** * @license * Copyright 2026 Qwen * SPDX-License-Identifier: Apache-2.0 */ /** * Routes realtime function calls to handlers and turns whatever happens — * success, handler error, bad arguments, timeout — into a JSON receipt * string. No call is ever left unanswered: an unanswered function call * would stall the realtime response arbitration. */ import { type RuntimeFailureSink } from '../log/runtime-failure.js'; /** Per-call context threaded through from the realtime function-call event. */ export interface ToolContext { /** Transcript tail captured at call time (capturesTranscript tools). */ activeTranscript: ReadonlyArray<{ role: 'user' | 'assistant'; text: string; }>; /** Current real user's request, not a synthetic notification or earlier turn. */ userRequest?: string; } export type ToolHandler = (args: Record, ctx: ToolContext) => Promise> | Record; export interface ToolDispatchResult { /** JSON receipt to submit as the function call output. */ receipt: string; ok: boolean; } export interface ToolDispatcherOptions { handlers: ReadonlyMap; timeoutMs?: number; /** Guidance must match the capabilities available in the current call. */ timeoutNote?: string; /** Best-effort diagnostics; never changes tool execution or receipts. */ onFailure?: RuntimeFailureSink; } export declare class ToolDispatcher { private readonly handlers; private readonly timeoutMs; private readonly timeoutNote; private readonly onFailure?; constructor(options: ToolDispatcherOptions); dispatch(name: string, rawArguments: string, ctx: ToolContext): Promise; private observeBusinessResult; private reportFailure; }