toAgentError
Classify any raw error into a structured AgentError.
Resolution order (first match wins): an existing AgentError is returned
unchanged (idempotent) → a user abort → a structured status/cause.status
→ network/connection markers → an HTTP-shaped status in the message → a
server + retryable fallback. The original error is always preserved on
cause. Runtime adapters call this before setting Agent.error; custom
backends can call it too (or throw an AgentError directly).
import { toAgentError } from '@threadplane/chat';Declaration · overload 1
export declare function toAgentError(raw: unknown): AgentError;Parameters
raw· requiredunknownAny thrown/rejected value — an
Error, a{ status }object, a string, etc.
Returns
AgentErrorThe classified AgentError (kind, retryable, status?, cause).
Examples
const e = toAgentError(new Error('HTTP 500: Internal Server Error'));
e.kind; // 'server'
e.retryable; // true
e.status; // 500