autotel-cloudflare 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents.d.ts +626 -123
- package/dist/agents.d.ts.map +1 -1
- package/dist/agents.js +253 -171
- package/dist/agents.js.map +1 -1
- package/package.json +1 -1
- package/src/agents/agent.ts +327 -0
- package/src/agents/base.ts +26 -0
- package/src/agents/index.ts +5 -1
- package/src/agents/mcp.ts +38 -0
- package/src/agents/observability.ts +145 -0
- package/src/agents/otel-observability.test.ts +165 -232
- package/src/agents/otel-observability.ts +350 -267
- package/src/agents/types.ts +26 -132
- package/src/agents.ts +17 -6
package/src/agents/types.ts
CHANGED
|
@@ -2,159 +2,53 @@
|
|
|
2
2
|
* Type definitions for Cloudflare Agents SDK observability integration
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { ConfigurationOption } from 'autotel-edge';
|
|
6
5
|
import type { Attributes } from '@opentelemetry/api';
|
|
6
|
+
import type { ConfigurationOption } from 'autotel-edge';
|
|
7
|
+
import type { AgentObservabilityEvent } from './agent';
|
|
8
|
+
import type { BaseEvent } from './base';
|
|
9
|
+
import type { MCPObservabilityEvent } from './mcp';
|
|
10
|
+
import type {
|
|
11
|
+
ChannelEventMap,
|
|
12
|
+
Observability,
|
|
13
|
+
ObservabilityEvent,
|
|
14
|
+
} from './observability';
|
|
7
15
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
export interface BaseAgentEvent<
|
|
12
|
-
T extends string,
|
|
13
|
-
Payload extends Record<string, unknown> = Record<string, unknown>
|
|
14
|
-
> {
|
|
15
|
-
type: T;
|
|
16
|
-
/** Unique identifier for the event */
|
|
17
|
-
id: string;
|
|
18
|
-
/** Human-readable message for logging */
|
|
19
|
-
displayMessage: string;
|
|
20
|
-
/** Event payload with type-specific data */
|
|
21
|
-
payload: Payload & Record<string, unknown>;
|
|
22
|
-
/** Timestamp in milliseconds since epoch */
|
|
23
|
-
timestamp: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Agent-specific observability events
|
|
28
|
-
*/
|
|
29
|
-
export type AgentObservabilityEvent =
|
|
30
|
-
| BaseAgentEvent<'state:update', Record<string, unknown>>
|
|
31
|
-
| BaseAgentEvent<
|
|
32
|
-
'rpc',
|
|
33
|
-
{
|
|
34
|
-
method: string;
|
|
35
|
-
streaming?: boolean;
|
|
36
|
-
}
|
|
37
|
-
>
|
|
38
|
-
| BaseAgentEvent<'message:request' | 'message:response', Record<string, unknown>>
|
|
39
|
-
| BaseAgentEvent<'message:clear'>
|
|
40
|
-
| BaseAgentEvent<
|
|
41
|
-
'schedule:create' | 'schedule:execute' | 'schedule:cancel',
|
|
42
|
-
{
|
|
43
|
-
callback: string;
|
|
44
|
-
id: string;
|
|
45
|
-
}
|
|
46
|
-
>
|
|
47
|
-
| BaseAgentEvent<'destroy'>
|
|
48
|
-
| BaseAgentEvent<
|
|
49
|
-
'connect',
|
|
50
|
-
{
|
|
51
|
-
connectionId: string;
|
|
52
|
-
}
|
|
53
|
-
>;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* MCP-specific observability events
|
|
57
|
-
*/
|
|
58
|
-
export type MCPObservabilityEvent =
|
|
59
|
-
| BaseAgentEvent<'mcp:client:preconnect', { serverId: string }>
|
|
60
|
-
| BaseAgentEvent<
|
|
61
|
-
'mcp:client:connect',
|
|
62
|
-
{ url: string; transport: string; state: string; error?: string }
|
|
63
|
-
>
|
|
64
|
-
| BaseAgentEvent<
|
|
65
|
-
'mcp:client:authorize',
|
|
66
|
-
{
|
|
67
|
-
serverId: string;
|
|
68
|
-
authUrl: string;
|
|
69
|
-
clientId?: string;
|
|
70
|
-
}
|
|
71
|
-
>
|
|
72
|
-
| BaseAgentEvent<'mcp:client:discover', Record<string, unknown>>;
|
|
16
|
+
export type { BaseEvent, AgentObservabilityEvent, MCPObservabilityEvent };
|
|
17
|
+
export type { Observability, ObservabilityEvent, ChannelEventMap };
|
|
73
18
|
|
|
74
|
-
|
|
75
|
-
* Union of all observability event types
|
|
76
|
-
*/
|
|
77
|
-
export type ObservabilityEvent = AgentObservabilityEvent | MCPObservabilityEvent;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Observability interface from Agents SDK
|
|
81
|
-
*/
|
|
82
|
-
export interface Observability {
|
|
83
|
-
/**
|
|
84
|
-
* Emit an event for the Agent's observability implementation to handle.
|
|
85
|
-
* @param event - The event to emit
|
|
86
|
-
* @param ctx - The execution context of the invocation (optional)
|
|
87
|
-
*/
|
|
88
|
-
emit(event: ObservabilityEvent, ctx?: DurableObjectState): void;
|
|
89
|
-
}
|
|
19
|
+
export type ObservabilityExecutionContext = DurableObjectState | ExecutionContext;
|
|
90
20
|
|
|
91
|
-
/**
|
|
92
|
-
* Agent-specific instrumentation options
|
|
93
|
-
*/
|
|
94
21
|
export interface AgentInstrumentationOptions {
|
|
95
|
-
/**
|
|
96
|
-
* Whether to create spans for RPC calls
|
|
97
|
-
* @default true
|
|
98
|
-
*/
|
|
99
22
|
traceRpc?: boolean;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Whether to create spans for schedule operations
|
|
103
|
-
* @default true
|
|
104
|
-
*/
|
|
105
23
|
traceSchedule?: boolean;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
* Whether to create spans for MCP operations
|
|
109
|
-
* @default true
|
|
110
|
-
*/
|
|
24
|
+
traceQueue?: boolean;
|
|
25
|
+
traceSubmissions?: boolean;
|
|
111
26
|
traceMcp?: boolean;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Whether to create spans for state updates
|
|
115
|
-
* @default false (can be noisy)
|
|
116
|
-
*/
|
|
117
27
|
traceStateUpdates?: boolean;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Whether to create spans for message events
|
|
121
|
-
* @default true
|
|
122
|
-
*/
|
|
123
28
|
traceMessages?: boolean;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Whether to create spans for connect/destroy lifecycle events
|
|
127
|
-
* @default true
|
|
128
|
-
*/
|
|
129
29
|
traceLifecycle?: boolean;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
30
|
+
traceChat?: boolean;
|
|
31
|
+
traceTranscripts?: boolean;
|
|
32
|
+
traceFibers?: boolean;
|
|
33
|
+
traceToolRecovery?: boolean;
|
|
34
|
+
traceWorkflow?: boolean;
|
|
35
|
+
traceEmail?: boolean;
|
|
134
36
|
attributeExtractor?: (event: ObservabilityEvent) => Attributes;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Custom span name formatter
|
|
138
|
-
*/
|
|
139
37
|
spanNameFormatter?: (event: ObservabilityEvent) => string;
|
|
140
38
|
}
|
|
141
39
|
|
|
142
|
-
/**
|
|
143
|
-
* Configuration for OtelObservability
|
|
144
|
-
*/
|
|
145
40
|
export type OtelObservabilityConfig = ConfigurationOption & {
|
|
146
|
-
/**
|
|
147
|
-
* Agent-specific instrumentation options
|
|
148
|
-
*/
|
|
149
41
|
agents?: AgentInstrumentationOptions;
|
|
150
42
|
};
|
|
151
43
|
|
|
152
|
-
/**
|
|
153
|
-
* Semantic attributes for Agent spans
|
|
154
|
-
*/
|
|
155
44
|
export interface AgentSpanAttributes {
|
|
156
45
|
'agent.event.type': string;
|
|
157
|
-
'agent.event.id'
|
|
46
|
+
'agent.event.id'?: string;
|
|
47
|
+
'agent.class'?: string;
|
|
48
|
+
'agent.instance.name'?: string;
|
|
49
|
+
'agent.display_message'?: string;
|
|
50
|
+
'agent.framework'?: string;
|
|
51
|
+
'gen_ai.agent.name'?: string;
|
|
158
52
|
'agent.rpc.method'?: string;
|
|
159
53
|
'agent.rpc.streaming'?: boolean;
|
|
160
54
|
'agent.schedule.callback'?: string;
|
package/src/agents.ts
CHANGED
|
@@ -47,12 +47,20 @@
|
|
|
47
47
|
* const observability = createOtelObservability({
|
|
48
48
|
* service: { name: 'my-agent' },
|
|
49
49
|
* agents: {
|
|
50
|
-
* traceRpc: true,
|
|
51
|
-
* traceSchedule: true,
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
50
|
+
* traceRpc: true, // RPC and rpc:error
|
|
51
|
+
* traceSchedule: true, // schedule:* events
|
|
52
|
+
* traceQueue: true, // queue:* events
|
|
53
|
+
* traceSubmissions: true, // submission:* events
|
|
54
|
+
* traceMcp: true, // mcp:* events
|
|
55
|
+
* traceStateUpdates: false, // state:update (off by default; noisy)
|
|
56
|
+
* traceMessages: true, // message:* and tool:* events
|
|
57
|
+
* traceChat: true, // chat:* recovery/stream/context events
|
|
58
|
+
* traceTranscripts: true, // chat:transcript:* events
|
|
59
|
+
* traceFibers: true, // fiber:* events
|
|
60
|
+
* traceToolRecovery: true, // agent_tool:* recovery events
|
|
61
|
+
* traceWorkflow: true, // workflow:* events
|
|
62
|
+
* traceEmail: true, // email:* events
|
|
63
|
+
* traceLifecycle: true, // connect/disconnect/destroy
|
|
56
64
|
* }
|
|
57
65
|
* })
|
|
58
66
|
* ```
|
|
@@ -65,12 +73,15 @@ export {
|
|
|
65
73
|
createOtelObservabilityFromEnv,
|
|
66
74
|
OtelObservability,
|
|
67
75
|
} from './agents/otel-observability';
|
|
76
|
+
export { channels, genericObservability, subscribe } from './agents/observability';
|
|
68
77
|
export type {
|
|
78
|
+
BaseEvent,
|
|
69
79
|
OtelObservabilityConfig,
|
|
70
80
|
AgentObservabilityEvent,
|
|
71
81
|
MCPObservabilityEvent,
|
|
72
82
|
ObservabilityEvent,
|
|
73
83
|
Observability,
|
|
84
|
+
ChannelEventMap,
|
|
74
85
|
AgentInstrumentationOptions,
|
|
75
86
|
AgentSpanAttributes,
|
|
76
87
|
} from './agents/types';
|