/** * Anthropic Messages API — SSE serialization. * * Converts simple response objects into the streaming event protocol * that pi's Anthropic provider expects. */ export interface TextBlock { type: "text"; text: string; } export interface ThinkingBlock { type: "thinking"; thinking: string; } export interface ToolCallBlock { type: "tool_call"; name: string; input: Record; } export interface ErrorBlock { type: "error"; message: string; } /** HTTP-level error — gateway returns actual HTTP status codes (429, 500, etc.) */ export interface HttpErrorBlock { type: "http_error"; status: number; message?: string; headers?: Record; /** * If true, include `x-should-retry: false` header to bypass the Anthropic SDK's * built-in retries (2 by default). This sends errors straight to pi's own retry * logic, which is usually what you want for testing. * * Set to false to test the full SDK retry chain (each error triggers 3 HTTP requests). * Default: true */ bypassSdkRetry?: boolean; } export type ResponseBlock = TextBlock | ThinkingBlock | ToolCallBlock; export type BrainResponse = ResponseBlock | ResponseBlock[] | ErrorBlock | HttpErrorBlock; export type Brain = (request: ApiRequest, index: number) => BrainResponse | Promise; export declare const text: (content: string) => TextBlock; export declare const toolCall: (name: string, input: Record) => ToolCallBlock; export declare const bash: (command: string, timeout?: number) => ToolCallBlock; export declare const edit: (path: string, oldText: string, newText: string) => ToolCallBlock; export declare const writeTool: (path: string, content: string) => ToolCallBlock; export declare const readTool: (path: string) => ToolCallBlock; export declare const thinking: (content: string) => ThinkingBlock; export declare const error: (message: string) => ErrorBlock; /** Generic HTTP error. Returns actual HTTP status code to trigger SDK/pi error handling. */ export declare const httpError: (status: number, message?: string, headers?: Record) => HttpErrorBlock; /** * 429 Too Many Requests — triggers pi's rate limit retry logic. * Includes retry-after header so pi/SDK know how long to wait. */ export declare const rateLimited: (retryAfterSeconds?: number) => HttpErrorBlock; /** 529 Overloaded — Anthropic-specific overload error. Triggers pi's retry logic. */ export declare const overloaded: (message?: string) => HttpErrorBlock; /** 500 Internal Server Error. */ export declare const serverError: (message?: string) => HttpErrorBlock; /** 503 Service Unavailable. */ export declare const serviceUnavailable: (message?: string) => HttpErrorBlock; export interface ApiRequest { model: string; messages: Array<{ role: string; content: string | Array>; }>; tools?: Array<{ name: string; description: string; input_schema: Record; }>; system?: string | Array<{ type: string; text: string; }>; max_tokens: number; stream?: boolean; /** Which provider format this request came from. Set by gateway. */ _provider?: string; /** HTTP request headers from the client. Set by gateway. */ _headers?: Record; /** Raw unparsed request body. Set by gateway. */ _raw?: unknown; } export declare function toSSE(response: BrainResponse, model: string): string; //# sourceMappingURL=anthropic.d.ts.map