|
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 | ], |
|
7102 | 7104 | { |
7103 | 7105 | "name": "AgentErrorKind", |
7104 | 7106 | "kind": "type", |
7105 | | - "description": "", |
| 7107 | + "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.", |
7106 | 7108 | "signature": "\"connection\" | \"auth\" | \"server\" | \"interrupted\" | \"aborted\"", |
7107 | 7109 | "examples": [] |
7108 | 7110 | }, |
|
7263 | 7265 | { |
7264 | 7266 | "name": "AGENT_ERROR_MESSAGES", |
7265 | 7267 | "kind": "const", |
7266 | | - "description": "Default human-facing copy per kind.", |
| 7268 | + "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.", |
7267 | 7269 | "signature": "Record<AgentErrorKind, string>", |
7268 | 7270 | "examples": [] |
7269 | 7271 | }, |
|
7725 | 7727 | { |
7726 | 7728 | "name": "isAbortError", |
7727 | 7729 | "kind": "function", |
7728 | | - "description": "True when `raw` represents a user-requested abort. Shared by adapters + classifier.", |
| 7730 | + "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.", |
7729 | 7731 | "signature": "isAbortError(raw: unknown): boolean", |
7730 | 7732 | "params": [ |
7731 | 7733 | { |
7732 | 7734 | "name": "raw", |
7733 | 7735 | "type": "unknown", |
7734 | | - "description": "", |
| 7736 | + "description": "Any thrown/rejected value.", |
7735 | 7737 | "optional": false |
7736 | 7738 | } |
7737 | 7739 | ], |
|
8047 | 8049 | { |
8048 | 8050 | "name": "toAgentError", |
8049 | 8051 | "kind": "function", |
8050 | | - "description": "Classify any raw error into a structured AgentError. Idempotent.", |
| 8052 | + "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).", |
8051 | 8053 | "signature": "toAgentError(raw: unknown): AgentError<>", |
8052 | 8054 | "params": [ |
8053 | 8055 | { |
8054 | 8056 | "name": "raw", |
8055 | 8057 | "type": "unknown", |
8056 | | - "description": "", |
| 8058 | + "description": "Any thrown/rejected value — an `Error`, a `{ status }` object, a string, etc.", |
8057 | 8059 | "optional": false |
8058 | 8060 | } |
8059 | 8061 | ], |
8060 | 8062 | "returns": { |
8061 | 8063 | "type": "AgentError<>", |
8062 | 8064 | "description": "" |
8063 | 8065 | }, |
8064 | | - "examples": [] |
| 8066 | + "examples": [ |
| 8067 | + "```ts\nconst e = toAgentError(new Error('HTTP 500: Internal Server Error'));\ne.kind; // 'server'\ne.retryable; // true\ne.status; // 500\n```" |
| 8068 | + ] |
8065 | 8069 | }, |
8066 | 8070 | { |
8067 | 8071 | "name": "toClientToolSpecs", |
|
0 commit comments