|
1429 | 1429 | { |
1430 | 1430 | "name": "AgentError", |
1431 | 1431 | "kind": "class", |
1432 | | - "description": "Structured, classified failure surfaced on `Agent.error`. Extends `Error`\n so existing `.message` / `instanceof Error` reads keep working.", |
| 1432 | + "description": "Structured, classified failure surfaced on `Agent.error`. Extends `Error`, so\nexisting `.message` / `instanceof Error` reads keep working — but adds a\nmachine-readable AgentErrorKind, a `retryable` flag, an optional HTTP\n`status`, and the original `cause`.\n\nYou rarely construct one yourself; adapters normalize raw failures via\ntoAgentError. Read it off the agent to render legible, cause-specific UI:", |
1433 | 1433 | "params": [ |
1434 | 1434 | { |
1435 | 1435 | "name": "init", |
|
1438 | 1438 | "optional": false |
1439 | 1439 | } |
1440 | 1440 | ], |
1441 | | - "examples": [], |
| 1441 | + "examples": [ |
| 1442 | + "```ts\nconst err = agent.error(); // AgentError | undefined\nif (err) {\n console.warn(err.message); // legible, per-kind copy\n if (err.kind === 'auth') showApiKeyHelp();\n if (err.retryable) showRetryButton(); // → agent.retry()\n}\n```" |
| 1443 | + ], |
1442 | 1444 | "properties": [ |
1443 | 1445 | { |
1444 | 1446 | "name": "cause", |
1445 | 1447 | "type": "unknown", |
1446 | | - "description": "", |
| 1448 | + "description": "The original raw error this was classified from, preserved for debugging/telemetry.", |
1447 | 1449 | "optional": false |
1448 | 1450 | }, |
1449 | 1451 | { |
1450 | 1452 | "name": "kind", |
1451 | 1453 | "type": "AgentErrorKind", |
1452 | | - "description": "", |
| 1454 | + "description": "The classified failure type. See AgentErrorKind.", |
1453 | 1455 | "optional": false |
1454 | 1456 | }, |
1455 | 1457 | { |
|
1467 | 1469 | { |
1468 | 1470 | "name": "retryable", |
1469 | 1471 | "type": "boolean", |
1470 | | - "description": "connection | server | interrupted → true; auth | aborted | non-auth-4xx → false.", |
| 1472 | + "description": "Whether retrying the same request could plausibly succeed:\n `connection` | `server` (5xx) | `interrupted` → true; `auth` | `aborted` | non-auth `4xx` → false.", |
1471 | 1473 | "optional": false |
1472 | 1474 | }, |
1473 | 1475 | { |
|
1479 | 1481 | { |
1480 | 1482 | "name": "status", |
1481 | 1483 | "type": "number", |
1482 | | - "description": "", |
| 1484 | + "description": "The HTTP status code when the failure came from an HTTP response.", |
1483 | 1485 | "optional": true |
1484 | 1486 | } |
1485 | 1487 | ], |
|
7162 | 7164 | { |
7163 | 7165 | "name": "AgentErrorKind", |
7164 | 7166 | "kind": "type", |
7165 | | - "description": "", |
| 7167 | + "description": "The failure class of an AgentError, used to drive UI and retry logic:\n\n- `connection` — offline / DNS / connection refused / `fetch` failed. Retryable.\n- `auth` — `401` / `403`; credentials or API key are wrong. Not retryable.\n- `server` — a `5xx` (retryable) or a non-auth `4xx` like `400`/`404`/`429` (not retryable).\n- `interrupted` — the stream closed mid-response after a run had started. Retryable.\n- `aborted` — the user pressed stop; treated as a graceful idle, not surfaced as an error.", |
7166 | 7168 | "signature": "\"connection\" | \"auth\" | \"server\" | \"interrupted\" | \"aborted\"", |
7167 | 7169 | "examples": [] |
7168 | 7170 | }, |
|
7351 | 7353 | { |
7352 | 7354 | "name": "AGENT_ERROR_MESSAGES", |
7353 | 7355 | "kind": "const", |
7354 | | - "description": "Default human-facing copy per kind.", |
| 7356 | + "description": "Default, human-facing copy per AgentErrorKind. Used as the message when\na classified error has no better text. Override by mapping `error.kind` to your\nown strings in a custom error component.", |
7355 | 7357 | "signature": "Record<AgentErrorKind, string>", |
7356 | 7358 | "examples": [] |
7357 | 7359 | }, |
|
7838 | 7840 | { |
7839 | 7841 | "name": "isAbortError", |
7840 | 7842 | "kind": "function", |
7841 | | - "description": "True when `raw` represents a user-requested abort. Shared by adapters + classifier.", |
| 7843 | + "description": "Whether `raw` represents an abort (a `DOMException`/`Error` named `AbortError`,\nor an abort-ish message). Shared by the runtime adapters and toAgentError\nso a user-requested stop settles to idle instead of surfacing as an error.", |
7842 | 7844 | "signature": "isAbortError(raw: unknown): boolean", |
7843 | 7845 | "params": [ |
7844 | 7846 | { |
7845 | 7847 | "name": "raw", |
7846 | 7848 | "type": "unknown", |
7847 | | - "description": "", |
| 7849 | + "description": "Any thrown/rejected value.", |
7848 | 7850 | "optional": false |
7849 | 7851 | } |
7850 | 7852 | ], |
|
8162 | 8164 | { |
8163 | 8165 | "name": "toAgentError", |
8164 | 8166 | "kind": "function", |
8165 | | - "description": "Classify any raw error into a structured AgentError. Idempotent.", |
| 8167 | + "description": "Classify any raw error into a structured AgentError.\n\nResolution order (first match wins): an existing `AgentError` is returned\nunchanged (idempotent) → a user abort → a structured `status`/`cause.status`\n→ network/connection markers → an HTTP-shaped status in the message → a\n`server` + retryable fallback. The original error is always preserved on\n`cause`. Runtime adapters call this before setting `Agent.error`; custom\nbackends can call it too (or throw an `AgentError` directly).", |
8166 | 8168 | "signature": "toAgentError(raw: unknown): AgentError<>", |
8167 | 8169 | "params": [ |
8168 | 8170 | { |
8169 | 8171 | "name": "raw", |
8170 | 8172 | "type": "unknown", |
8171 | | - "description": "", |
| 8173 | + "description": "Any thrown/rejected value — an `Error`, a `{ status }` object, a string, etc.", |
8172 | 8174 | "optional": false |
8173 | 8175 | } |
8174 | 8176 | ], |
8175 | 8177 | "returns": { |
8176 | 8178 | "type": "AgentError<>", |
8177 | 8179 | "description": "" |
8178 | 8180 | }, |
8179 | | - "examples": [] |
| 8181 | + "examples": [ |
| 8182 | + "```ts\nconst e = toAgentError(new Error('HTTP 500: Internal Server Error'));\ne.kind; // 'server'\ne.retryable; // true\ne.status; // 500\n```" |
| 8183 | + ] |
8180 | 8184 | }, |
8181 | 8185 | { |
8182 | 8186 | "name": "toClientToolSpecs", |
|
0 commit comments