/** * withAnycast() — transparent observability wrapper for @anthropic-ai/claude-agent-sdk sessions. * * Intercepts the session's stream() to forward usage, tool-call, and custom event data * to the Anycast portal without modifying any event data or blocking the stream. * * Features: * - Telemetry: usage + tool calls forwarded automatically * - Attributes: arbitrary KV attached to all telemetry (OTel-aligned) * - emit(): custom event emission at any point * - Plugins: lifecycle hooks (onSessionStart, onToolUse, onResult, onSessionEnd) * - Memory: persistent KV via portal API * - Session persistence: auto-save session_id for resume */ import type { AnycastPlugin } from './types.js'; interface AgentSDKContentBlock { type: 'text' | 'tool_use' | string; text?: string; name?: string; id?: string; input?: unknown; } interface AgentSDKEvent { type: 'assistant' | 'tool_use_summary' | 'result' | string; message?: { content: AgentSDKContentBlock[]; }; summary?: string; session_id?: string; usage?: { input_tokens?: number; output_tokens?: number; cache_read_input_tokens?: number; cache_creation_input_tokens?: number; }; total_cost_usd?: number; num_turns?: number; duration_ms?: number; duration_api_ms?: number; } interface AgentSDKSession { stream(): AsyncIterable; send(prompt: string): Promise; close(): void; sessionId?: string; } export interface WithAnycastOptions { agentToken: string; portalUrl?: string; agentName?: string; debug?: boolean; enableMemory?: boolean; memoryScope?: 'agent' | 'tenant'; persistSession?: boolean; agentId?: string; /** Key index from resolveApiKey() — forwarded in usage reports for per-key tracking */ _resolvedKeyIndex?: number; /** Arbitrary attributes attached to all telemetry. Use OTel semantic conventions. */ attributes?: Record; /** Lifecycle hook plugins */ plugins?: AnycastPlugin[]; } export declare class AnycastMemory { private agentToken; private portalUrl; private scope; private debug; constructor(agentToken: string, portalUrl: string, scope: 'agent' | 'tenant', debug?: boolean); get(key: string): Promise; set(key: string, value: unknown, options?: { ttl?: number; }): Promise; list(prefix?: string): Promise; delete(key: string): Promise; } /** * withAnycast() — two call signatures: * * 1. Session wrapping: withAnycast(session, options) → wrapped session with memory + emit * 2. Standalone agent: withAnycast(options) → keep-alive agent with heartbeat + emit */ export declare function withAnycast(sessionOrOptions: T | WithAnycastOptions, maybeOptions?: WithAnycastOptions): (T & { memory: AnycastMemory; emit: (eventName: string, data?: Record) => Promise; }) | StandaloneAgent; export declare namespace withAnycast { var getLastSessionId: (agentToken: string, options?: { portalUrl?: string; agentId?: string; }) => Promise; var resolveApiKey: (options: { agentToken: string; portalUrl?: string; model?: string; provider?: string; }) => Promise<{ apiKey: string; provider: string; providerName: string; model: string | null; keyIndex: number; providerId: string; }>; } export interface StandaloneAgent { memory: AnycastMemory; emit: (eventName: string, data?: Record) => Promise; stop: () => void; } export {}; //# sourceMappingURL=with-anycast.d.ts.map