Skip to content

Function: chat()

ts
function chat(ctx: Context, options?: ChatOptions): RenderSession;

Defined in: packages/sdk/src/renderer/templates/chat.ts:164

Interactive chat template — a full, block-only conversational surface.

One long-lived render: a Chat block renders the transcript, a PromptInput + Suggestion chips (bound to the same messagesKey via pushTo) seed user turns, and replies stream in. By default the reply comes from Chrome's on-device Gemini Nano (model: chromeAI()); pass model: aiSdk({...}) to stream from a cloud model in the skill's Node context. Per-turn rich blocks come from model-chosen tools or the deterministic augment callback. Voice, attachments, per-message actions, and in-chat confirmations are built in — none resolve the render; only Dismiss does.

Fire-and-forget: returns a RenderSession the caller can await (resolves when Dismiss is pressed).

Parameters

ParameterTypeDescription
ctxContextRender context.
optionsChatOptionsChat configuration.

Returns

RenderSession

Example

ts
import {chat, aiSdk} from '@matterway/sdk/UI';

// On-device (default):
await chat(ctx, {title: 'Assistant', suggestions: ['Summarize this']});

// Cloud model with a typed tool (tools are keyed by name):
await chat(ctx, {
  model: aiSdk({model: 'gpt-4o-mini'}),
  tools: {
    search: chatTool({
      description: 'Search the web',
      inputSchema: z.object({query: z.string()}),
      execute: async ({input}) => ({reply: `Searched ${input.query}`}),
    }),
  },
});

// A tool that ALWAYS asks first — `confirm` gates `execute`:
tools: {
  deleteFile: chatTool({
    description: 'Delete the file',
    inputSchema: z.object({path: z.string()}),
    confirm: ({input}) => `Delete ${input.path}?`, // present ⇒ gate
    execute: ({input}) => ({reply: `Deleted ${input.path}.`}), // runs only after approval
  }),
}

Matterway Assistant SDK Documentation