Skip to navigation

Mount another Hono app, or a fetch handler, alongside this agent’s routes. Use it instead of adding routes to the app from getApp() by hand: the agent rebuilds its app when its routes change (when you register a routing callback, for example), and a mount is replayed on every build.

A mounted app answers its own CORS preflights, since the agent’s CORS and CSRF middleware don’t apply to it. It also sets its own security headers and isn’t behind the agent’s basic auth. Mount before calling serve().

Parameters

appOrRouter
Hono | ((req: Request) => Response | Promise<Response>)Required

A Hono app, whose routes are added under prefix, or a fetch handler, which is mounted at prefix and doesn’t see it.

opts
{ prefix?: string; name?: string }

Mount options.

opts.prefix
string

Path to mount at, from the host root. A trailing slash is dropped. Defaults to the root.

opts.name
string

Accepted so code written for the Python SDK works. It has no effect.

Returns

AgentBase — Returns this for method chaining.

Example

import { AgentBase, AIChatClient, ChatGateway } from '@signalwire/sdk';
const agent = new AgentBase({ name: 'dispatch', route: '/dispatch' });
const gateway = new ChatGateway({
client: new AIChatClient(),
configUrl: 'https://bayview-taxi.example.com/dispatch',
key: '<YOUR_PUBLISHABLE_KEY>',
});
agent.mount(gateway.router(), { prefix: '/chat' });
await agent.serve();

See ChatGateway for what the mounted router serves.