agents 0.21.0 → 0.22.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/README.md +1 -0
- package/dist/{agent-tool-types-CzGGB-20.d.ts → agent-routing-CnkaHb-v.d.ts} +2921 -3057
- package/dist/agent-routing.d.ts +14 -0
- package/dist/agent-routing.js +187 -0
- package/dist/agent-routing.js.map +1 -0
- package/dist/agent-tool-types.d.ts +26 -26
- package/dist/{agent-tools-zR2d5uij.d.ts → agent-tools-C0XJqWzB.d.ts} +7 -7
- package/dist/agent-tools.d.ts +21 -21
- package/dist/agent-tools.js +2 -1
- package/dist/agent-tools.js.map +1 -1
- package/dist/browser/ai.js +2 -1
- package/dist/browser/ai.js.map +1 -1
- package/dist/capability-BjSKYpzg.js +42 -0
- package/dist/capability-BjSKYpzg.js.map +1 -0
- package/dist/capability-runner-CvHGZqUu.d.ts +150 -0
- package/dist/chat/index.d.ts +22 -15
- package/dist/chat/index.js +4 -4
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +14 -1
- package/dist/chat/react.js +82 -52
- package/dist/chat/react.js.map +1 -1
- package/dist/chat/transport.js +1 -1
- package/dist/chat-sdk/index.d.ts +4 -4
- package/dist/chat-sdk/index.js +1 -1
- package/dist/{client-zqKcsyFa.js → client-jagG8a9_.js} +129 -37
- package/dist/client-jagG8a9_.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/{cloudflare-BduZwmYK.js → cloudflare-Dzvc7V2N.js} +10 -3
- package/dist/{cloudflare-BduZwmYK.js.map → cloudflare-Dzvc7V2N.js.map} +1 -1
- package/dist/current-agent-CuMErtly.d.ts +283 -0
- package/dist/current-agent-DhoDkSnH.js +51 -0
- package/dist/current-agent-DhoDkSnH.js.map +1 -0
- package/dist/diagnostics-CaBjfz4J.js +41 -0
- package/dist/diagnostics-CaBjfz4J.js.map +1 -0
- package/dist/{do-oauth-client-provider-VTZj2VtM.d.ts → do-oauth-client-provider-Tmf1vgKz.d.ts} +2 -2
- package/dist/durable-object-lifecycle-D6nNQJJd.js +862 -0
- package/dist/durable-object-lifecycle-D6nNQJJd.js.map +1 -0
- package/dist/{email-CL27preh.d.ts → email-7TatiTnl.d.ts} +38 -9
- package/dist/email-send.d.ts +15 -0
- package/dist/email-send.js +32 -0
- package/dist/email-send.js.map +1 -0
- package/dist/email.d.ts +14 -10
- package/dist/email.js.map +1 -1
- package/dist/experimental/memory/session/index.d.ts +3 -2
- package/dist/experimental/memory/session/index.js +15 -10
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/{handler-stateless-C_bo-Ytq.d.ts → handler-stateless-DxYpJ_XF.d.ts} +3 -3
- package/dist/{handler-stateless-CIkKPETH.js → handler-stateless-VvrWSAVA.js} +5 -5
- package/dist/handler-stateless-VvrWSAVA.js.map +1 -0
- package/dist/{index-BRnybD6X.d.ts → index-DcSAZKsB.d.ts} +19 -31
- package/dist/index.d.ts +98 -95
- package/dist/index.js +10 -7234
- package/dist/internal_context-BlxFEWfn.d.ts +19 -0
- package/dist/internal_context.d.ts +10 -4
- package/dist/internal_context.js +1 -10
- package/dist/{client-invoker-BNSZxAkv.d.ts → invoker-CG0_p_Wq.d.ts} +2 -2
- package/dist/{client-invoker-VNZ7X0nn.js → invoker-CHMnoxIA.js} +2 -2
- package/dist/invoker-CHMnoxIA.js.map +1 -0
- package/dist/lifecycle/index.d.ts +48 -0
- package/dist/lifecycle/index.js +4 -0
- package/dist/mcp/{do-oauth-client-provider.d.ts → client/do-oauth-client-provider.d.ts} +1 -1
- package/dist/mcp/{do-oauth-client-provider.js → client/do-oauth-client-provider.js} +1 -1
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -0
- package/dist/mcp/client/index.d.ts +42 -0
- package/dist/mcp/{client.js → client/index.js} +1 -1
- package/dist/mcp/{x402.d.ts → client/x402.d.ts} +2 -2
- package/dist/mcp/{x402.js → client/x402.js} +2 -2
- package/dist/mcp/client/x402.js.map +1 -0
- package/dist/mcp/index.d.ts +36 -36
- package/dist/mcp/index.js +14 -16
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/{server.d.ts → server/index.d.ts} +1 -1
- package/dist/mcp/{server.js → server/index.js} +1 -1
- package/dist/observability/ai/index.js +50 -35
- package/dist/observability/ai/index.js.map +1 -1
- package/dist/observability/index.d.ts +4 -4
- package/dist/observability/index.js +3 -50
- package/dist/observability/index.js.map +1 -1
- package/dist/{protocol-Dqc2MQxo.js → protocol-B0nh6KNf.js} +19 -21
- package/dist/protocol-B0nh6KNf.js.map +1 -0
- package/dist/react.d.ts +4 -4
- package/dist/react.js +1 -1
- package/dist/schedule.d.ts +25 -94
- package/dist/schedule.js +1 -98
- package/dist/schedule.js.map +1 -1
- package/dist/scheduler-CR9RHGos.js +857 -0
- package/dist/scheduler-CR9RHGos.js.map +1 -0
- package/dist/scheduler-DQoTGoAW.d.ts +224 -0
- package/dist/schedules/index.d.ts +22 -0
- package/dist/schedules/index.js +2 -0
- package/dist/schedules/parser.d.ts +79 -0
- package/dist/schedules/parser.js +103 -0
- package/dist/schedules/parser.js.map +1 -0
- package/dist/serializable.d.ts +1 -1
- package/dist/sql-error-CPY-GXyI.d.ts +12 -0
- package/dist/sql-error.d.ts +2 -0
- package/dist/sql-error.js +16 -0
- package/dist/sql-error.js.map +1 -0
- package/dist/src-5W6JNKVb.js +6613 -0
- package/dist/src-5W6JNKVb.js.map +1 -0
- package/dist/sub-routing.d.ts +12 -12
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflows.d.ts +22 -22
- package/dist/workflows.js +2 -1
- package/dist/workflows.js.map +1 -1
- package/dist/{ws-chat-transport-CIoOBbO7.js → ws-chat-transport-rWwta645.js} +152 -15
- package/dist/ws-chat-transport-rWwta645.js.map +1 -0
- package/docs/agent-class.md +28 -86
- package/docs/chat-agents.md +13 -12
- package/docs/durable-execution.md +1 -1
- package/docs/http-websockets.md +1 -11
- package/docs/human-in-the-loop.md +1 -1
- package/docs/index.md +1 -0
- package/docs/lifecycle.md +323 -0
- package/docs/long-running-agents.md +2 -4
- package/docs/mcp-client.md +55 -0
- package/docs/observability.md +11 -11
- package/docs/resumable-streaming.md +1 -1
- package/docs/scheduling.md +175 -15
- package/docs/server-driven-messages.md +1 -1
- package/docs/sub-agents.md +1 -1
- package/package.json +30 -21
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -26
- package/dist/cli/index.js.map +0 -1
- package/dist/client-invoker-VNZ7X0nn.js.map +0 -1
- package/dist/client-zqKcsyFa.js.map +0 -1
- package/dist/handler-stateless-CIkKPETH.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal_context-Dg4Cgjcu.d.ts +0 -37
- package/dist/internal_context.js.map +0 -1
- package/dist/mcp/client.d.ts +0 -42
- package/dist/mcp/do-oauth-client-provider.js.map +0 -1
- package/dist/mcp/x402.js.map +0 -1
- package/dist/protocol-Dqc2MQxo.js.map +0 -1
- package/dist/ws-chat-transport-CIoOBbO7.js.map +0 -1
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import {
|
|
2
|
+
i as DurableObjectCapability,
|
|
3
|
+
l as LifecycleRouteAddress,
|
|
4
|
+
t as AlarmContribution
|
|
5
|
+
} from "./capability-runner-CvHGZqUu.js";
|
|
6
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
|
+
import { DurableObject } from "cloudflare:workers";
|
|
8
|
+
|
|
9
|
+
//#region src/lifecycle/types.d.ts
|
|
10
|
+
type ImmutablePrimitive = undefined | null | boolean | string | number;
|
|
11
|
+
type Immutable<T> = T extends ImmutablePrimitive
|
|
12
|
+
? T
|
|
13
|
+
: T extends Array<infer U>
|
|
14
|
+
? ImmutableArray<U>
|
|
15
|
+
: T extends Map<infer K, infer V>
|
|
16
|
+
? ImmutableMap<K, V>
|
|
17
|
+
: T extends Set<infer M>
|
|
18
|
+
? ImmutableSet<M>
|
|
19
|
+
: ImmutableObject<T>;
|
|
20
|
+
type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
|
|
21
|
+
type ImmutableMap<K, V> = ReadonlyMap<Immutable<K>, Immutable<V>>;
|
|
22
|
+
type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
|
|
23
|
+
type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };
|
|
24
|
+
/** Immutable state persisted in a hibernating WebSocket attachment. */
|
|
25
|
+
type ConnectionState<T> = ImmutableObject<T> | null;
|
|
26
|
+
/** Functional update applied to a connection's current state. */
|
|
27
|
+
type ConnectionSetStateFn<T> = (prevState: ConnectionState<T>) => T;
|
|
28
|
+
/** Context supplied when a lifecycle accepts a WebSocket connection. */
|
|
29
|
+
type ConnectionContext = {
|
|
30
|
+
/** Original WebSocket upgrade request. */ request: Request;
|
|
31
|
+
};
|
|
32
|
+
/** A WebSocket managed by a Durable Object lifecycle. */
|
|
33
|
+
type Connection<TState = unknown> = WebSocket & {
|
|
34
|
+
/** Connection identifier */ id: string;
|
|
35
|
+
/**
|
|
36
|
+
* The URL of the original WebSocket upgrade request.
|
|
37
|
+
* Persisted in the WebSocket attachment so it survives hibernation.
|
|
38
|
+
*/
|
|
39
|
+
uri: string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Arbitrary state associated with this connection.
|
|
42
|
+
* Read-only — use {@link Connection.setState} to update.
|
|
43
|
+
*
|
|
44
|
+
* This property is configurable, meaning it can be redefined via
|
|
45
|
+
* `Object.defineProperty` by downstream consumers (e.g. the Cloudflare
|
|
46
|
+
* Agents SDK) to namespace or wrap internal state storage.
|
|
47
|
+
*/
|
|
48
|
+
state: ConnectionState<TState>;
|
|
49
|
+
/**
|
|
50
|
+
* Update the state associated with this connection.
|
|
51
|
+
*
|
|
52
|
+
* Accepts either a new state value or an updater function that receives
|
|
53
|
+
* the previous state and returns the next state.
|
|
54
|
+
*
|
|
55
|
+
* This property is configurable, meaning it can be redefined via
|
|
56
|
+
* `Object.defineProperty` by downstream consumers that provide their own
|
|
57
|
+
* state projection.
|
|
58
|
+
*/
|
|
59
|
+
setState(
|
|
60
|
+
state: TState | ConnectionSetStateFn<TState> | null
|
|
61
|
+
): ConnectionState<TState>;
|
|
62
|
+
/**
|
|
63
|
+
* Tags returned by the owning Durable Object's `getConnectionTags` callback.
|
|
64
|
+
* Always includes the connection id as the first tag.
|
|
65
|
+
*/
|
|
66
|
+
tags: readonly string[];
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/lifecycle/durable-object-lifecycle.d.ts
|
|
70
|
+
/** Payload delivered to a lifecycle-managed WebSocket callback. */
|
|
71
|
+
type WSMessage = ArrayBuffer | ArrayBufferView | string;
|
|
72
|
+
/** Internal envelope transported between routed Lifecycle instances. */
|
|
73
|
+
type LifecycleRouteEnvelope = {
|
|
74
|
+
readonly capability: string;
|
|
75
|
+
readonly source: LifecycleRouteAddress | undefined;
|
|
76
|
+
readonly payload: unknown;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Installs and coordinates the runtime lifecycle for a Durable Object.
|
|
80
|
+
*
|
|
81
|
+
* Construct this as an instance field on a class that directly extends
|
|
82
|
+
* `DurableObject`, then call {@link Lifecycle.installHandlers}
|
|
83
|
+
* from that class's constructor.
|
|
84
|
+
*
|
|
85
|
+
* @experimental The API surface may change before stabilizing.
|
|
86
|
+
*/
|
|
87
|
+
declare class Lifecycle<
|
|
88
|
+
Env extends object = Cloudflare.Env,
|
|
89
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
90
|
+
> {
|
|
91
|
+
#private;
|
|
92
|
+
/**
|
|
93
|
+
* Construct and install a lifecycle in one explicit operation.
|
|
94
|
+
*
|
|
95
|
+
* @param host - The Durable Object whose runtime handlers the lifecycle owns.
|
|
96
|
+
* @returns The installed lifecycle.
|
|
97
|
+
*/
|
|
98
|
+
static install<
|
|
99
|
+
Env extends object,
|
|
100
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
101
|
+
>(host: DurableObject<Env>): Lifecycle<Env, Props>;
|
|
102
|
+
/**
|
|
103
|
+
* Bind a lifecycle to a Durable Object instance without mutating its handlers.
|
|
104
|
+
*
|
|
105
|
+
* @param host - The Durable Object whose runtime lifecycle this object owns.
|
|
106
|
+
*/
|
|
107
|
+
constructor(host: DurableObject<Env>);
|
|
108
|
+
/**
|
|
109
|
+
* Install platform fetch, alarm, and hibernating WebSocket handlers.
|
|
110
|
+
*
|
|
111
|
+
* Existing handlers are preserved for framework-owned dispatch such as the
|
|
112
|
+
* Agent's sub-agent router and alarm circuit breaker. Calling this method
|
|
113
|
+
* more than once is an error.
|
|
114
|
+
*/
|
|
115
|
+
installHandlers(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Add a reusable capability before this lifecycle starts.
|
|
118
|
+
*
|
|
119
|
+
* @param capability - The capability to add in dispatch order.
|
|
120
|
+
* @returns This lifecycle.
|
|
121
|
+
*/
|
|
122
|
+
use(capability: DurableObjectCapability<Props>): this;
|
|
123
|
+
/** @internal Deliver a generic capability envelope to this Lifecycle. */
|
|
124
|
+
route(envelope: LifecycleRouteEnvelope): Promise<unknown>;
|
|
125
|
+
/**
|
|
126
|
+
* Execute SQL queries against the Durable Object's database
|
|
127
|
+
* @template T Type of the returned rows
|
|
128
|
+
* @param strings SQL query template strings
|
|
129
|
+
* @param values Values to be inserted into the query
|
|
130
|
+
* @returns Array of query results
|
|
131
|
+
*/
|
|
132
|
+
sql<T = Record<string, string | number | boolean | null>>(
|
|
133
|
+
strings: TemplateStringsArray,
|
|
134
|
+
...values: (string | number | boolean | null)[]
|
|
135
|
+
): T[];
|
|
136
|
+
/**
|
|
137
|
+
* Handle an incoming request for the owning Durable Object.
|
|
138
|
+
*/
|
|
139
|
+
fetch(request: Request): Promise<Response>;
|
|
140
|
+
/** @internal Dispatch a hibernating WebSocket message. */
|
|
141
|
+
webSocketMessage(ws: WebSocket, message: WSMessage): Promise<void>;
|
|
142
|
+
/** @internal Dispatch and reciprocate a hibernating WebSocket close. */
|
|
143
|
+
webSocketClose(
|
|
144
|
+
ws: WebSocket,
|
|
145
|
+
code: number,
|
|
146
|
+
reason: string,
|
|
147
|
+
wasClean: boolean
|
|
148
|
+
): Promise<void>;
|
|
149
|
+
/** @internal Dispatch a hibernating WebSocket error. */
|
|
150
|
+
webSocketError(ws: WebSocket, error: unknown): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Start lifecycle capabilities and the owning Durable Object.
|
|
153
|
+
*
|
|
154
|
+
* Runtime fetch, alarm, and WebSocket entry points call this automatically.
|
|
155
|
+
* RPC methods may call it explicitly because native RPC bypasses fetch.
|
|
156
|
+
*
|
|
157
|
+
* @param props - Optional properties supplied to capability and host startup.
|
|
158
|
+
*/
|
|
159
|
+
start(props?: Props): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* The name used to address this Durable Object.
|
|
162
|
+
*
|
|
163
|
+
* Native `ctx.id.name` is authoritative. A read-only legacy storage fallback
|
|
164
|
+
* lets objects created by older PartyServer releases migrate without new
|
|
165
|
+
* name writes.
|
|
166
|
+
*/
|
|
167
|
+
get name(): string;
|
|
168
|
+
/** Send a message to all connected clients, except connection ids listed in `without` */
|
|
169
|
+
broadcast(
|
|
170
|
+
msg: string | ArrayBuffer | ArrayBufferView,
|
|
171
|
+
without?: string[] | undefined
|
|
172
|
+
): void;
|
|
173
|
+
/** Get a connection by connection id */
|
|
174
|
+
getConnection<TState = unknown>(id: string): Connection<TState> | undefined;
|
|
175
|
+
/** Get all managed connections, optionally filtered by tag. */
|
|
176
|
+
getConnections<TState = unknown>(tag?: string): Iterable<Connection<TState>>;
|
|
177
|
+
/**
|
|
178
|
+
* Recompute the physical Durable Object alarm from every capability.
|
|
179
|
+
*
|
|
180
|
+
* Concurrent requests are serialized so a later durable-state change cannot
|
|
181
|
+
* be overwritten by an earlier alarm calculation.
|
|
182
|
+
*/
|
|
183
|
+
rearmAlarm(): Promise<void>;
|
|
184
|
+
/** Dispose installed capabilities in reverse registration order. */
|
|
185
|
+
dispose(): Promise<void>;
|
|
186
|
+
/** Permanently disable and clear alarms during explicit object teardown. */
|
|
187
|
+
disableAlarms(): Promise<void>;
|
|
188
|
+
/** Dispatch lifecycle and host alarm callbacks after startup. */
|
|
189
|
+
alarm(): Promise<void>;
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/lifecycle/current-agent.d.ts
|
|
193
|
+
/**
|
|
194
|
+
* A Durable Object that has installed the Agents SDK Lifecycle.
|
|
195
|
+
*
|
|
196
|
+
* Pass a more specific Lifecycle Object type to {@link getCurrentAgent} when
|
|
197
|
+
* shared host code needs APIs implemented by a particular object.
|
|
198
|
+
*
|
|
199
|
+
* @experimental The API surface may change before stabilizing.
|
|
200
|
+
*/
|
|
201
|
+
interface LifecycleObject<
|
|
202
|
+
Env extends object = Cloudflare.Env,
|
|
203
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
204
|
+
> extends DurableObject<Env> {
|
|
205
|
+
readonly lifecycle: Lifecycle<Env, Props>;
|
|
206
|
+
onStart?(props?: Props): void | Promise<void>;
|
|
207
|
+
onRequest?(request: Request): Response | Promise<Response>;
|
|
208
|
+
onAlarm?(): void | Promise<void>;
|
|
209
|
+
getNextAlarm?(): AlarmContribution | Promise<AlarmContribution>;
|
|
210
|
+
onConnect?(
|
|
211
|
+
connection: Connection,
|
|
212
|
+
context: ConnectionContext
|
|
213
|
+
): void | Promise<void>;
|
|
214
|
+
onMessage?(connection: Connection, message: WSMessage): void | Promise<void>;
|
|
215
|
+
onClose?(
|
|
216
|
+
connection: Connection,
|
|
217
|
+
code: number,
|
|
218
|
+
reason: string,
|
|
219
|
+
wasClean: boolean
|
|
220
|
+
): void | Promise<void>;
|
|
221
|
+
onError?(connection: Connection, error: unknown): void | Promise<void>;
|
|
222
|
+
getConnectionTags?(
|
|
223
|
+
connection: Connection,
|
|
224
|
+
context: ConnectionContext
|
|
225
|
+
): string[] | Promise<string[]>;
|
|
226
|
+
}
|
|
227
|
+
/** Values associated with the currently executing Lifecycle host. */
|
|
228
|
+
type AgentContextStore = {
|
|
229
|
+
/** Lifecycle host selected for this invocation. */ agent: unknown /** WebSocket connection selected for this invocation, when applicable. */;
|
|
230
|
+
connection:
|
|
231
|
+
| Connection
|
|
232
|
+
| undefined /** HTTP request selected for this invocation, when applicable. */;
|
|
233
|
+
request:
|
|
234
|
+
| Request
|
|
235
|
+
| undefined /** Extension-owned value selected for this invocation, when applicable. */;
|
|
236
|
+
email: unknown;
|
|
237
|
+
};
|
|
238
|
+
/** Values returned by {@link getCurrentAgent}. */
|
|
239
|
+
type CurrentAgentContext<
|
|
240
|
+
Host extends DurableObject = LifecycleObject,
|
|
241
|
+
Email = unknown
|
|
242
|
+
> = {
|
|
243
|
+
agent: Host | undefined;
|
|
244
|
+
connection: Connection | undefined;
|
|
245
|
+
request: Request | undefined;
|
|
246
|
+
email: Email | undefined;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Shared invocation context for Lifecycle, Agent, AIChatAgent, and Think.
|
|
250
|
+
*
|
|
251
|
+
* @internal Importing or relying on this symbol will break your code in a
|
|
252
|
+
* future release. Use {@link getCurrentAgent} to read the public context.
|
|
253
|
+
*/
|
|
254
|
+
declare const __DO_NOT_USE_WILL_BREAK__agentContext: AsyncLocalStorage<AgentContextStore>;
|
|
255
|
+
/**
|
|
256
|
+
* Return the current Agent or Lifecycle Object and invocation-specific values.
|
|
257
|
+
*
|
|
258
|
+
* Lifecycle host startup and alarm hooks receive the current object with no
|
|
259
|
+
* request. Request hooks additionally receive the request being handled.
|
|
260
|
+
* Lifecycle-managed WebSocket hooks receive their connection and, during
|
|
261
|
+
* connect, its upgrade request. Agent extensions may also establish context
|
|
262
|
+
* for email, chat turns, callable methods, and detached work. Capability hooks
|
|
263
|
+
* do not run in this ambient context.
|
|
264
|
+
*/
|
|
265
|
+
declare function getCurrentAgent<
|
|
266
|
+
Host extends DurableObject = LifecycleObject
|
|
267
|
+
>(): CurrentAgentContext<Host>;
|
|
268
|
+
//#endregion
|
|
269
|
+
export {
|
|
270
|
+
getCurrentAgent as a,
|
|
271
|
+
WSMessage as c,
|
|
272
|
+
ConnectionSetStateFn as d,
|
|
273
|
+
ConnectionState as f,
|
|
274
|
+
__DO_NOT_USE_WILL_BREAK__agentContext as i,
|
|
275
|
+
Connection as l,
|
|
276
|
+
CurrentAgentContext as n,
|
|
277
|
+
Lifecycle as o,
|
|
278
|
+
LifecycleObject as r,
|
|
279
|
+
LifecycleRouteEnvelope as s,
|
|
280
|
+
AgentContextStore as t,
|
|
281
|
+
ConnectionContext as u
|
|
282
|
+
};
|
|
283
|
+
//# sourceMappingURL=current-agent-CuMErtly.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
//#region src/lifecycle/current-agent.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared invocation context for Lifecycle, Agent, AIChatAgent, and Think.
|
|
5
|
+
*
|
|
6
|
+
* @internal Importing or relying on this symbol will break your code in a
|
|
7
|
+
* future release. Use {@link getCurrentAgent} to read the public context.
|
|
8
|
+
*/
|
|
9
|
+
const __DO_NOT_USE_WILL_BREAK__agentContext = new AsyncLocalStorage();
|
|
10
|
+
/**
|
|
11
|
+
* Return the current Agent or Lifecycle Object and invocation-specific values.
|
|
12
|
+
*
|
|
13
|
+
* Lifecycle host startup and alarm hooks receive the current object with no
|
|
14
|
+
* request. Request hooks additionally receive the request being handled.
|
|
15
|
+
* Lifecycle-managed WebSocket hooks receive their connection and, during
|
|
16
|
+
* connect, its upgrade request. Agent extensions may also establish context
|
|
17
|
+
* for email, chat turns, callable methods, and detached work. Capability hooks
|
|
18
|
+
* do not run in this ambient context.
|
|
19
|
+
*/
|
|
20
|
+
function getCurrentAgent() {
|
|
21
|
+
const store = __DO_NOT_USE_WILL_BREAK__agentContext.getStore();
|
|
22
|
+
if (!store) return {
|
|
23
|
+
agent: void 0,
|
|
24
|
+
connection: void 0,
|
|
25
|
+
request: void 0,
|
|
26
|
+
email: void 0
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
agent: store.agent,
|
|
30
|
+
connection: store.connection,
|
|
31
|
+
request: store.request,
|
|
32
|
+
email: store.email
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Run one host hook in the context of its Lifecycle Object. */
|
|
36
|
+
function runInLifecycleHostContext(context, operation) {
|
|
37
|
+
return __DO_NOT_USE_WILL_BREAK__agentContext.run({
|
|
38
|
+
agent: context.host,
|
|
39
|
+
connection: context.connection,
|
|
40
|
+
request: context.request,
|
|
41
|
+
email: void 0
|
|
42
|
+
}, operation);
|
|
43
|
+
}
|
|
44
|
+
/** Run a capability hook without inheriting a current Agent or host context. */
|
|
45
|
+
function runWithoutCurrentAgent(operation) {
|
|
46
|
+
return __DO_NOT_USE_WILL_BREAK__agentContext.exit(operation);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { runWithoutCurrentAgent as i, getCurrentAgent as n, runInLifecycleHostContext as r, __DO_NOT_USE_WILL_BREAK__agentContext as t };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=current-agent-DhoDkSnH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-agent-DhoDkSnH.js","names":[],"sources":["../src/lifecycle/current-agent.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { DurableObject } from \"cloudflare:workers\";\n\nimport type { AlarmContribution } from \"./capability-runner\";\nimport type { Lifecycle, WSMessage } from \"./durable-object-lifecycle\";\nimport type { Connection, ConnectionContext } from \"./types\";\n\n/**\n * A Durable Object that has installed the Agents SDK Lifecycle.\n *\n * Pass a more specific Lifecycle Object type to {@link getCurrentAgent} when\n * shared host code needs APIs implemented by a particular object.\n *\n * @experimental The API surface may change before stabilizing.\n */\nexport interface LifecycleObject<\n Env extends object = Cloudflare.Env,\n Props extends Record<string, unknown> = Record<string, unknown>\n> extends DurableObject<Env> {\n readonly lifecycle: Lifecycle<Env, Props>;\n onStart?(props?: Props): void | Promise<void>;\n onRequest?(request: Request): Response | Promise<Response>;\n onAlarm?(): void | Promise<void>;\n getNextAlarm?(): AlarmContribution | Promise<AlarmContribution>;\n onConnect?(\n connection: Connection,\n context: ConnectionContext\n ): void | Promise<void>;\n onMessage?(connection: Connection, message: WSMessage): void | Promise<void>;\n onClose?(\n connection: Connection,\n code: number,\n reason: string,\n wasClean: boolean\n ): void | Promise<void>;\n onError?(connection: Connection, error: unknown): void | Promise<void>;\n getConnectionTags?(\n connection: Connection,\n context: ConnectionContext\n ): string[] | Promise<string[]>;\n}\n\n/** Values associated with the currently executing Lifecycle host. */\nexport type AgentContextStore = {\n /** Lifecycle host selected for this invocation. */\n agent: unknown;\n /** WebSocket connection selected for this invocation, when applicable. */\n connection: Connection | undefined;\n /** HTTP request selected for this invocation, when applicable. */\n request: Request | undefined;\n /** Extension-owned value selected for this invocation, when applicable. */\n email: unknown;\n};\n\n/** Values returned by {@link getCurrentAgent}. */\nexport type CurrentAgentContext<\n Host extends DurableObject = LifecycleObject,\n Email = unknown\n> = {\n agent: Host | undefined;\n connection: Connection | undefined;\n request: Request | undefined;\n email: Email | undefined;\n};\n\n/**\n * Shared invocation context for Lifecycle, Agent, AIChatAgent, and Think.\n *\n * @internal Importing or relying on this symbol will break your code in a\n * future release. Use {@link getCurrentAgent} to read the public context.\n */\nexport const __DO_NOT_USE_WILL_BREAK__agentContext =\n new AsyncLocalStorage<AgentContextStore>();\n\n/**\n * Return the current Agent or Lifecycle Object and invocation-specific values.\n *\n * Lifecycle host startup and alarm hooks receive the current object with no\n * request. Request hooks additionally receive the request being handled.\n * Lifecycle-managed WebSocket hooks receive their connection and, during\n * connect, its upgrade request. Agent extensions may also establish context\n * for email, chat turns, callable methods, and detached work. Capability hooks\n * do not run in this ambient context.\n */\nexport function getCurrentAgent<\n Host extends DurableObject = LifecycleObject\n>(): CurrentAgentContext<Host> {\n const store = __DO_NOT_USE_WILL_BREAK__agentContext.getStore();\n if (!store) {\n return {\n agent: undefined,\n connection: undefined,\n request: undefined,\n email: undefined\n };\n }\n\n return {\n agent: store.agent as Host,\n connection: store.connection,\n request: store.request,\n email: store.email\n };\n}\n\ntype LifecycleHostContext<\n Env extends object,\n Props extends Record<string, unknown>\n> = {\n readonly host: LifecycleObject<Env, Props>;\n readonly connection?: Connection;\n readonly request?: Request;\n};\n\n/** Run one host hook in the context of its Lifecycle Object. */\nexport function runInLifecycleHostContext<\n Env extends object,\n Props extends Record<string, unknown>,\n T\n>(context: LifecycleHostContext<Env, Props>, operation: () => T): T {\n return __DO_NOT_USE_WILL_BREAK__agentContext.run(\n {\n agent: context.host,\n connection: context.connection,\n request: context.request,\n email: undefined\n },\n operation\n );\n}\n\n/** Run a capability hook without inheriting a current Agent or host context. */\nexport function runWithoutCurrentAgent<T>(operation: () => T): T {\n return __DO_NOT_USE_WILL_BREAK__agentContext.exit(operation);\n}\n"],"mappings":";;;;;;;;AAuEA,MAAa,wCACX,IAAI,kBAAqC;;;;;;;;;;;AAY3C,SAAgB,kBAEe;CAC7B,MAAM,QAAQ,sCAAsC,SAAS;CAC7D,IAAI,CAAC,OACH,OAAO;EACL,OAAO,KAAA;EACP,YAAY,KAAA;EACZ,SAAS,KAAA;EACT,OAAO,KAAA;CACT;CAGF,OAAO;EACL,OAAO,MAAM;EACb,YAAY,MAAM;EAClB,SAAS,MAAM;EACf,OAAO,MAAM;CACf;AACF;;AAYA,SAAgB,0BAId,SAA2C,WAAuB;CAClE,OAAO,sCAAsC,IAC3C;EACE,OAAO,QAAQ;EACf,YAAY,QAAQ;EACpB,SAAS,QAAQ;EACjB,OAAO,KAAA;CACT,GACA,SACF;AACF;;AAGA,SAAgB,uBAA0B,WAAuB;CAC/D,OAAO,sCAAsC,KAAK,SAAS;AAC7D"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { channel } from "node:diagnostics_channel";
|
|
2
|
+
//#region src/observability/diagnostics.ts
|
|
3
|
+
/** Diagnostics channels for Agent and Lifecycle telemetry. */
|
|
4
|
+
const channels = {
|
|
5
|
+
state: channel("agents:state"),
|
|
6
|
+
rpc: channel("agents:rpc"),
|
|
7
|
+
message: channel("agents:message"),
|
|
8
|
+
chat: channel("agents:chat"),
|
|
9
|
+
transcript: channel("agents:transcript"),
|
|
10
|
+
fiber: channel("agents:fiber"),
|
|
11
|
+
agentTool: channel("agents:agent_tool"),
|
|
12
|
+
schedule: channel("agents:schedule"),
|
|
13
|
+
lifecycle: channel("agents:lifecycle"),
|
|
14
|
+
workflow: channel("agents:workflow"),
|
|
15
|
+
mcp: channel("agents:mcp"),
|
|
16
|
+
email: channel("agents:email"),
|
|
17
|
+
channel: channel("agents:channel")
|
|
18
|
+
};
|
|
19
|
+
function getChannel(type) {
|
|
20
|
+
if (type.startsWith("mcp:")) return channels.mcp;
|
|
21
|
+
if (type.startsWith("workflow:")) return channels.workflow;
|
|
22
|
+
if (type.startsWith("fiber:")) return channels.fiber;
|
|
23
|
+
if (type.startsWith("transcript:") || type.startsWith("chat:transcript:")) return channels.transcript;
|
|
24
|
+
if (type.startsWith("chat:")) return channels.chat;
|
|
25
|
+
if (type.startsWith("agent_tool:")) return channels.agentTool;
|
|
26
|
+
if (type.startsWith("schedule:") || type.startsWith("queue:")) return channels.schedule;
|
|
27
|
+
if (type.startsWith("message:") || type.startsWith("tool:") || type.startsWith("submission:") || type.startsWith("action:")) return channels.message;
|
|
28
|
+
if (type === "rpc" || type.startsWith("rpc:")) return channels.rpc;
|
|
29
|
+
if (type.startsWith("state:")) return channels.state;
|
|
30
|
+
if (type.startsWith("email:")) return channels.email;
|
|
31
|
+
if (type.startsWith("channel:") || type.startsWith("notice:")) return channels.channel;
|
|
32
|
+
return channels.lifecycle;
|
|
33
|
+
}
|
|
34
|
+
/** Publish one event to its existing diagnostics channel. */
|
|
35
|
+
function publishDiagnosticsEvent(event) {
|
|
36
|
+
getChannel(event.type).publish(event);
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { publishDiagnosticsEvent as n, channels as t };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=diagnostics-CaBjfz4J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics-CaBjfz4J.js","names":[],"sources":["../src/observability/diagnostics.ts"],"sourcesContent":["import { channel, type Channel } from \"node:diagnostics_channel\";\n\n/** Event shape accepted by the diagnostics-channel publisher. */\nexport type DiagnosticsEvent = {\n readonly type: string;\n readonly source?: string;\n readonly agent?: string;\n readonly name?: string;\n readonly payload: unknown;\n readonly timestamp: number;\n};\n\n/** Diagnostics channels for Agent and Lifecycle telemetry. */\nexport const channels = {\n state: channel(\"agents:state\"),\n rpc: channel(\"agents:rpc\"),\n message: channel(\"agents:message\"),\n chat: channel(\"agents:chat\"),\n transcript: channel(\"agents:transcript\"),\n fiber: channel(\"agents:fiber\"),\n agentTool: channel(\"agents:agent_tool\"),\n schedule: channel(\"agents:schedule\"),\n lifecycle: channel(\"agents:lifecycle\"),\n workflow: channel(\"agents:workflow\"),\n mcp: channel(\"agents:mcp\"),\n email: channel(\"agents:email\"),\n channel: channel(\"agents:channel\")\n} as const;\n\nfunction getChannel(type: string): Channel {\n if (type.startsWith(\"mcp:\")) return channels.mcp;\n if (type.startsWith(\"workflow:\")) return channels.workflow;\n if (type.startsWith(\"fiber:\")) return channels.fiber;\n if (type.startsWith(\"transcript:\") || type.startsWith(\"chat:transcript:\"))\n return channels.transcript;\n if (type.startsWith(\"chat:\")) return channels.chat;\n if (type.startsWith(\"agent_tool:\")) return channels.agentTool;\n if (type.startsWith(\"schedule:\") || type.startsWith(\"queue:\"))\n return channels.schedule;\n if (\n type.startsWith(\"message:\") ||\n type.startsWith(\"tool:\") ||\n type.startsWith(\"submission:\") ||\n type.startsWith(\"action:\")\n )\n return channels.message;\n if (type === \"rpc\" || type.startsWith(\"rpc:\")) return channels.rpc;\n if (type.startsWith(\"state:\")) return channels.state;\n if (type.startsWith(\"email:\")) return channels.email;\n if (type.startsWith(\"channel:\") || type.startsWith(\"notice:\"))\n return channels.channel;\n return channels.lifecycle;\n}\n\n/** Publish one event to its existing diagnostics channel. */\nexport function publishDiagnosticsEvent(event: DiagnosticsEvent): void {\n getChannel(event.type).publish(event);\n}\n"],"mappings":";;;AAaA,MAAa,WAAW;CACtB,OAAO,QAAQ,cAAc;CAC7B,KAAK,QAAQ,YAAY;CACzB,SAAS,QAAQ,gBAAgB;CACjC,MAAM,QAAQ,aAAa;CAC3B,YAAY,QAAQ,mBAAmB;CACvC,OAAO,QAAQ,cAAc;CAC7B,WAAW,QAAQ,mBAAmB;CACtC,UAAU,QAAQ,iBAAiB;CACnC,WAAW,QAAQ,kBAAkB;CACrC,UAAU,QAAQ,iBAAiB;CACnC,KAAK,QAAQ,YAAY;CACzB,OAAO,QAAQ,cAAc;CAC7B,SAAS,QAAQ,gBAAgB;AACnC;AAEA,SAAS,WAAW,MAAuB;CACzC,IAAI,KAAK,WAAW,MAAM,GAAG,OAAO,SAAS;CAC7C,IAAI,KAAK,WAAW,WAAW,GAAG,OAAO,SAAS;CAClD,IAAI,KAAK,WAAW,QAAQ,GAAG,OAAO,SAAS;CAC/C,IAAI,KAAK,WAAW,aAAa,KAAK,KAAK,WAAW,kBAAkB,GACtE,OAAO,SAAS;CAClB,IAAI,KAAK,WAAW,OAAO,GAAG,OAAO,SAAS;CAC9C,IAAI,KAAK,WAAW,aAAa,GAAG,OAAO,SAAS;CACpD,IAAI,KAAK,WAAW,WAAW,KAAK,KAAK,WAAW,QAAQ,GAC1D,OAAO,SAAS;CAClB,IACE,KAAK,WAAW,UAAU,KAC1B,KAAK,WAAW,OAAO,KACvB,KAAK,WAAW,aAAa,KAC7B,KAAK,WAAW,SAAS,GAEzB,OAAO,SAAS;CAClB,IAAI,SAAS,SAAS,KAAK,WAAW,MAAM,GAAG,OAAO,SAAS;CAC/D,IAAI,KAAK,WAAW,QAAQ,GAAG,OAAO,SAAS;CAC/C,IAAI,KAAK,WAAW,QAAQ,GAAG,OAAO,SAAS;CAC/C,IAAI,KAAK,WAAW,UAAU,KAAK,KAAK,WAAW,SAAS,GAC1D,OAAO,SAAS;CAClB,OAAO,SAAS;AAClB;;AAGA,SAAgB,wBAAwB,OAA+B;CACrE,WAAW,MAAM,IAAI,CAAC,CAAC,QAAQ,KAAK;AACtC"}
|
package/dist/{do-oauth-client-provider-VTZj2VtM.d.ts → do-oauth-client-provider-Tmf1vgKz.d.ts}
RENAMED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
StoredOAuthTokens
|
|
8
8
|
} from "@modelcontextprotocol/client";
|
|
9
9
|
|
|
10
|
-
//#region src/mcp/do-oauth-client-provider.d.ts
|
|
10
|
+
//#region src/mcp/client/do-oauth-client-provider.d.ts
|
|
11
11
|
interface AgentMcpOAuthProvider extends OAuthClientProvider {
|
|
12
12
|
authUrl: string | undefined;
|
|
13
13
|
clientId: string | undefined;
|
|
@@ -107,4 +107,4 @@ export {
|
|
|
107
107
|
DurableObjectOAuthClientProvider as r,
|
|
108
108
|
AgentMcpOAuthProvider as t
|
|
109
109
|
};
|
|
110
|
-
//# sourceMappingURL=do-oauth-client-provider-
|
|
110
|
+
//# sourceMappingURL=do-oauth-client-provider-Tmf1vgKz.d.ts.map
|