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:
parent
a1ae100ef0
commit
a0265f92d2
2 changed files with 30 additions and 16 deletions
|
|
@ -364,6 +364,28 @@ async function App_updateModelContext_structuredContent(app: App) {
|
|||
//#endregion App_updateModelContext_structuredContent
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Report runtime error to model.
|
||||
*/
|
||||
async function App_updateModelContext_reportError(app: App) {
|
||||
//#region App_updateModelContext_reportError
|
||||
try {
|
||||
const _stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||
// ... use _stream for transcription
|
||||
} catch (err) {
|
||||
// Inform the model that the app is in a degraded state
|
||||
await app.updateModelContext({
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "Error: transcription unavailable",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
//#endregion App_updateModelContext_reportError
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Open documentation link.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -674,6 +674,9 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
|
|||
* @example Update with structured content
|
||||
* {@includeCode ./app.examples.ts#App_updateModelContext_structuredContent}
|
||||
*
|
||||
* @example Report runtime error to model
|
||||
* {@includeCode ./app.examples.ts#App_updateModelContext_reportError}
|
||||
*
|
||||
* @returns Promise that resolves when the context update is acknowledged
|
||||
*/
|
||||
updateModelContext(
|
||||
|
|
|
|||
Loading…
Reference in a new issue