CommandRouter
Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:19
Routes slash commands and unmatched text to agent handlers.
Type Parameters
Section titled “Type Parameters”ContentTypes
Section titled “ContentTypes”ContentTypes = unknown
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CommandRouter<
ContentTypes>(config?):CommandRouter<ContentTypes>
Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:24
Create a router. A help command is registered when configured.
Parameters
Section titled “Parameters”config?
Section titled “config?”CommandRouterConfig = {}
Returns
Section titled “Returns”CommandRouter<ContentTypes>
Accessors
Section titled “Accessors”commandList
Section titled “commandList”Get Signature
Section titled “Get Signature”get commandList():
string[]
Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:53
Return registered commands in insertion order.
Returns
Section titled “Returns”string[]
Methods
Section titled “Methods”command()
Section titled “command()”Register the command using the normalized handler arguments.
Call Signature
Section titled “Call Signature”command(
command,handler):this
Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:58
Register a slash command. Commands are matched case-insensitively.
Parameters
Section titled “Parameters”command
Section titled “command”string
handler
Section titled “handler”AgentMessageHandler<string>
Returns
Section titled “Returns”this
Call Signature
Section titled “Call Signature”command(
command,description,handler):this
Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:60
Register a command with a description shown by the help command.
Parameters
Section titled “Parameters”command
Section titled “command”string
description
Section titled “description”string
handler
Section titled “handler”AgentMessageHandler<string>
Returns
Section titled “Returns”this
default()
Section titled “default()”default(
handler):this
Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:98
Register the handler for text that does not match a command.
Parameters
Section titled “Parameters”handler
Section titled “handler”AgentMessageHandler<string>
Returns
Section titled “Returns”this
handle()
Section titled “handle()”handle(
ctx):Promise<boolean>
Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:104
Handle one text context and return whether a handler ran.
Parameters
Section titled “Parameters”MessageContext<string>
Returns
Section titled “Returns”Promise<boolean>
middleware()
Section titled “middleware()”middleware():
AgentMiddleware<ContentTypes>
Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:135
Return middleware that routes text messages to registered handlers.
Returns
Section titled “Returns”AgentMiddleware<ContentTypes>

