Capability first · transport second

ToolCallRouter.js

Parses OpenAI-style tool calls and dispatches complete or streamed calls to injected handlers.

SDK 0.5.18Runtime 0.8.12Protocol arcane/1
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

JavaScript
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

BindingFormDeclaration or signatureParameter syntax
handleResponsefunctionasync function handleResponse(response={},handlers={})response={},handlers={}
handleStreamedCallsfunctionasync function handleStreamedCalls(calls={},handlers={})calls={},handlers={}
parseArgumentsfunctionfunction parseArguments(value,name='')value,name=''
CallableKindExact public signatureParameter syntax
parseArgumentsexported-functionfunction parseArguments(value,name='')value,name=''
handleResponseexported-functionasync function handleResponse(response={},handlers={})response={},handlers={}
handleStreamedCallsexported-functionasync 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

JavaScript
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}));

No direct Core call is claimed for this artifact. Any injected provider or consuming module retains its own documented authority.