import { Channel } from "node:diagnostics_channel"; //#region src/observability/base.d.ts /** * Base event structure for all observability events */ type BaseEvent< T extends string, Payload extends Record = Record > = { type: T; /** * The class name of the agent that emitted this event * (e.g. "MyChatAgent"). * Always present on events emitted by an Agent instance. */ agent?: string; /** * The instance name (Durable Object ID name) of the agent. * Always present on events emitted by an Agent instance. */ name?: string; /** * The payload of the event */ payload: Payload; /** * The timestamp of the event in milliseconds since epoch */ timestamp: number; }; //#endregion //#region src/observability/mcp.d.ts /** * MCP-specific observability events * These track the lifecycle of MCP connections and operations */ type MCPObservabilityEvent = | BaseEvent< "mcp:client:preconnect", { serverId: string; } > | BaseEvent< "mcp:client:connect", { url: string; transport: string; state: string; error?: string; } > | BaseEvent< "mcp:client:authorize", { serverId: string; authUrl: string; clientId?: string; } > | BaseEvent< "mcp:client:discover", { url?: string; state?: string; error?: string; capability?: string; } > | BaseEvent< "mcp:client:close", { url: string; transport?: string; state: string; error?: string; phase?: "terminate-session" | "client-close"; } >; //#endregion //#region src/observability/agent.d.ts /** * Agent-specific observability events * These track the lifecycle and operations of an Agent */ type AgentObservabilityEvent = | BaseEvent<"state:update"> | BaseEvent< "rpc", { method: string; streaming?: boolean; } > | BaseEvent< "rpc:error", { method: string; error: string; } > | BaseEvent<"message:request"> | BaseEvent<"message:response"> | BaseEvent<"message:clear"> | BaseEvent< "message:cancel", { requestId: string; } > | BaseEvent< "message:error", { error: string; } > | BaseEvent< "tool:result", { toolCallId: string; toolName: string; } > | BaseEvent< "tool:approval", { toolCallId: string; approved: boolean; } > | BaseEvent< "schedule:create", { callback: string; id: string; } > | BaseEvent< "schedule:execute", { callback: string; id: string; } > | BaseEvent< "schedule:cancel", { callback: string; id: string; } > | BaseEvent< "schedule:retry", { callback: string; id: string; attempt: number; maxAttempts: number; } > | BaseEvent< "schedule:error", { callback: string; id: string; error: string; attempts: number; } > | BaseEvent< "schedule:duplicate_warning", { callback: string; count: number; type: string; } > | BaseEvent< "queue:create", { callback: string; id: string; } > | BaseEvent< "queue:retry", { callback: string; id: string; attempt: number; maxAttempts: number; } > | BaseEvent< "queue:error", { callback: string; id: string; error: string; attempts: number; } > | BaseEvent<"destroy"> | BaseEvent< "connect", { connectionId: string; } > | BaseEvent< "disconnect", { connectionId: string; code: number; reason: string; } > | BaseEvent< "email:receive", { from: string; to: string; subject?: string; } > | BaseEvent< "email:reply", { from: string; to: string; subject?: string; } > | BaseEvent< "email:send", { from: string; to: string | string[]; subject: string; } > | BaseEvent< "workflow:start", { workflowId: string; workflowName?: string; } > | BaseEvent< "workflow:event", { workflowId: string; eventType?: string; } > | BaseEvent< "workflow:approved", { workflowId: string; reason?: string; } > | BaseEvent< "workflow:rejected", { workflowId: string; reason?: string; } > | BaseEvent< "workflow:terminated", { workflowId: string; workflowName?: string; } > | BaseEvent< "workflow:paused", { workflowId: string; workflowName?: string; } > | BaseEvent< "workflow:resumed", { workflowId: string; workflowName?: string; } > | BaseEvent< "workflow:restarted", { workflowId: string; workflowName?: string; } >; //#endregion //#region src/observability/index.d.ts /** * Union of all observability event types from different domains */ type ObservabilityEvent = AgentObservabilityEvent | MCPObservabilityEvent; interface Observability { /** * Emit an event for the Agent's observability implementation to handle. * @param event - The event to emit */ emit(event: ObservabilityEvent): void; } /** * Diagnostics channels for agent observability. * * Events are published to named channels using the Node.js diagnostics_channel API. * By default, publishing to a channel with no subscribers is a no-op (zero overhead). * * To observe events, subscribe to the channels you care about: * ```ts * import { subscribe } from "node:diagnostics_channel"; * subscribe("agents:rpc", (event) => console.log(event)); * ``` * * In production, all published messages are automatically forwarded to * Tail Workers via `event.diagnosticsChannelEvents` — no subscription needed. */ declare const channels: { readonly state: Channel; readonly rpc: Channel; readonly message: Channel; readonly schedule: Channel; readonly lifecycle: Channel; readonly workflow: Channel; readonly mcp: Channel; readonly email: Channel; }; /** * The default observability implementation. * * Publishes events to diagnostics_channel. Events are silent unless * a subscriber is registered or a Tail Worker is attached. */ declare const genericObservability: Observability; /** * Maps each channel key to the observability events it carries. */ type ChannelEventMap = { state: Extract< ObservabilityEvent, { type: `state:${string}`; } >; rpc: Extract< ObservabilityEvent, { type: "rpc" | `rpc:${string}`; } >; message: Extract< ObservabilityEvent, { type: `message:${string}` | `tool:${string}`; } >; schedule: Extract< ObservabilityEvent, { type: `schedule:${string}` | `queue:${string}`; } >; lifecycle: Extract< ObservabilityEvent, { type: "connect" | "disconnect" | "destroy"; } >; workflow: Extract< ObservabilityEvent, { type: `workflow:${string}`; } >; mcp: Extract< ObservabilityEvent, { type: `mcp:${string}`; } >; email: Extract< ObservabilityEvent, { type: `email:${string}`; } >; }; /** * Subscribe to a typed observability channel. * * ```ts * import { subscribe } from "agents/observability"; * * const unsub = subscribe("rpc", (event) => { * console.log(event.payload.method); // fully typed * }); * ``` * * @returns A function that unsubscribes the callback. */ declare function subscribe$1( channelKey: K, callback: (event: ChannelEventMap[K]) => void ): () => void; //#endregion export { genericObservability as a, channels as i, Observability as n, subscribe$1 as o, ObservabilityEvent as r, MCPObservabilityEvent as s, ChannelEventMap as t }; //# sourceMappingURL=index-Biv6K70p.d.ts.map