agents
Version:
A home for your AI agents
178 lines (176 loc) • 4.43 kB
TypeScript
import {
n as ObservabilityEvent,
r as genericObservability,
t as Observability
} from "../emitter-BJZtCVjQ.js";
import { Channel } from "node:diagnostics_channel";
//#region src/observability/diagnostics.d.ts
/** Diagnostics channels for Agent and Lifecycle telemetry. */
declare const channels: {
readonly state: Channel<any, any>;
readonly rpc: Channel<any, any>;
readonly message: Channel<any, any>;
readonly chat: Channel<any, any>;
readonly transcript: Channel<any, any>;
readonly fiber: Channel<any, any>;
readonly task: Channel<any, any>;
readonly stream: Channel<any, any>;
readonly agentTool: Channel<any, any>;
readonly schedule: Channel<any, any>;
readonly lifecycle: Channel<any, any>;
readonly workflow: Channel<any, any>;
readonly mcp: Channel<any, any>;
readonly email: Channel<any, any>;
readonly channel: Channel<any, any>;
};
//#endregion
//#region src/observability/otel/index.d.ts
/**
* Connects the OpenTelemetry API (`@opentelemetry/api`) to Workers tracing.
* Call once at module scope:
*
* ```ts
* import { experimental_registerOpenTelemetry } from "agents/observability";
*
* experimental_registerOpenTelemetry();
* ```
*
* Afterwards, libraries instrumented with the OpenTelemetry API (the MCP SDK,
* AI SDK telemetry, your own `trace.getTracer(...)` spans) record native
* Workers spans. They nest with the Agents SDK's spans and the automatic
* fetch, KV, D1 and Durable Object spans, and export through
* `observability.traces.destinations`. Enable `observability.traces` in your
* Wrangler configuration for anything to be recorded.
*
* Safe to call more than once. When OpenTelemetry is already fully registered,
* by your own SDK setup or natively by the Workers runtime, this leaves it in
* place and does nothing. Throws when only part of an OpenTelemetry setup is
* registered.
*
* @experimental Undocumented and subject to change: a temporary bridge until
* Workers supports the OpenTelemetry API natively. See
* `design/rfc-opentelemetry-bridge.md` for what it records and refuses.
*/
declare function experimental_registerOpenTelemetry(): void;
//#endregion
//#region src/observability/index.d.ts
/**
* 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}`
| `submission:${string}`
| `action:${string}`;
}
>;
chat: Exclude<
Extract<
ObservabilityEvent,
{
type: `chat:${string}`;
}
>,
{
type: `chat:transcript:${string}`;
}
>;
transcript: Extract<
ObservabilityEvent,
{
type: `transcript:${string}` | `chat:transcript:${string}`;
}
>;
fiber: Extract<
ObservabilityEvent,
{
type: `fiber:${string}`;
}
>;
agentTool: Extract<
ObservabilityEvent,
{
type: `agent_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}`;
}
>;
channel: Extract<
ObservabilityEvent,
{
type: `channel:${string}` | `notice:${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<K extends keyof ChannelEventMap>(
channelKey: K,
callback: (event: ChannelEventMap[K]) => void
): () => void;
//#endregion
export {
ChannelEventMap,
type Observability,
type ObservabilityEvent,
channels,
experimental_registerOpenTelemetry,
genericObservability,
subscribe
};
//# sourceMappingURL=index.d.ts.map