On this page
Overview
Parses OpenAI-style tool calls and dispatches complete or streamed calls to injected handlers.
- Artifact
ToolCallRouter.js· esm - Classification
public first party - Availability
Cross-host - Normalization
Object.prototype or null-prototype argument records require a nonempty user-facing message and retain every field unchanged; handler results are returned or all-settled.
Import and lifecycle
import * as module from '/arcane/modules/ToolCallRouter.js';
Pure parsing plus invocation of injected handlers. Complete calls execute sequentially; a streamed-name map executes concurrently with all-settled containment.
Application-facing behavior: parseArguments(), handleResponse(), handleStreamedCalls(); invalid or missing message fails AITOOLMESSAGEREQUIRED.
Protocol and host implementation
Injected handlers This detail does not widen the application-facing API or grant authority.
Exports, signatures, parameters, and results
| Binding | Form | Declaration or signature | Parameter syntax |
|---|---|---|---|
handleResponse | function | async function handleResponse(response={},handlers={}) | response={},handlers={} |
handleStreamedCalls | function | async function handleStreamedCalls(calls={},handlers={}) | calls={},handlers={} |
parseArguments | function | function parseArguments(value,name='') | value,name='' |
| Callable | Kind | Exact public signature | Parameter syntax |
|---|---|---|---|
parseArguments | exported-function | function parseArguments(value,name='') | value,name='' |
handleResponse | exported-function | async function handleResponse(response={},handlers={}) | response={},handlers={} |
handleStreamedCalls | exported-function | async function handleStreamedCalls(calls={},handlers={}) | calls={},handlers={} |
Parameter meanings and results
parseArguments(value,name) accepts an Object.prototype or null-prototype record, or JSON encoding that shape, and returns that original record only when it contains a nonempty user-facing message string. The complete object, including message, reaches the injected handler without cloning or freezing. handleResponse(OpenAI-style response,handlers) resolves one handler value or an ordered value array. handleStreamedCalls({name:args},handlers) resolves PromiseSettledResult[].
Events, side effects, and errors
Source-literal CustomEvent dispatches
No source-literal CustomEvent dispatch is part of this artifact.
Lifecycle and event flow
This artifact has no additional documented lifecycle event flow.
Direct coded failures
AI_TOOL_MESSAGE_REQUIRED
Exported Error subclasses
This artifact exports no Error subclass.
Documented failure behavior
- AI_TOOL_MESSAGE_REQUIRED when arguments are not a plain record, are an array or custom-prototype object, or omit a nonempty message.
- Uncoded Error for invalid/missing calls, invalid JSON, or an unregistered handler.
- handleResponse() propagates handler errors; handleStreamedCalls() reports rejected settlements.
Availability and capabilities
Cross-host. Object.prototype or null-prototype argument records require a nonempty user-facing message and retain every field unchanged; handler results are returned or all-settled.
None; injected handlers own authority.
Contract example
import {handleResponse} from '/arcane/modules/ToolCallRouter.js';
const response = {choices:[{message:{tool_calls:[{
function:{
name:'sum',
arguments:'{"a":2,"b":3,"message":"Adding the requested values."}'
}
}]}}]};
console.log(await handleResponse(response,{sum:({a,b}) => a+b}));
Related reference
No direct Core call is claimed for this artifact. Any injected provider or consuming module retains its own documented authority.