Complete "Giving errors back to model" pattern documentation

Adds JSDoc example `App_updateModelContext_reportError` showing how to
report runtime errors (e.g., microphone permission denied) back to the
model using `updateModelContext`.

Updates patterns.md with clearer framing:
- Server-side (tool handler): return `{ isError: true, ... }`
- Client-side (app): use `updateModelContext` for runtime errors

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jonathan Hefner 2026-01-19 15:42:16 -06:00
commit a0265f92d2
2 changed files with 30 additions and 16 deletions

View file

@ -20,12 +20,13 @@ Set {@link types!McpUiToolMeta.visibility Tool.\_meta.ui.visibility} to `["app"]
{@includeCode ./patterns.tsx#authenticatedCalls}
## [TODO] Giving errors back to model
## Giving errors back to model
- Before app runs: validate inputs in tool call
- After it runs: use `updateModelContext`
**Server-side**: Tool handler validates inputs and returns `{ isError: true, content: [...] }`. The model receives this error through the normal tool call response.
{@includeCode ./patterns.tsx#errorsToModel}
**Client-side**: If a runtime error occurs (e.g., API failure, permission denied, resource unavailable), use {@link app!App.updateModelContext updateModelContext} to inform the model:
{@includeCode ../src/app.examples.ts#App_updateModelContext_reportError}
## Matching host styling (CSS variables, theme, and fonts)

View file

@ -27,17 +27,6 @@ function authenticatedCalls(app: App) {
//#endregion authenticatedCalls
}
/**
* Example: Giving errors back to model
*/
function errorsToModel(app: App) {
//#region errorsToModel
// Before app runs: validate inputs in tool call
// After it runs: updateModelContext
// TODO: Complete implementation
//#endregion errorsToModel
}
/**
* Example: Unified host styling (theme, CSS variables, fonts)
*/
@ -132,7 +121,6 @@ function migrateFromOpenai() {
// Suppress unused variable warnings
void authenticatedCalls;
void errorsToModel;
void hostStylingVanillaJs;
void hostStylingReact;
void persistData;