agents 0.0.0-eeb70e2 → 0.0.0-ef38e84

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.
Files changed (78) hide show
  1. package/README.md +255 -27
  2. package/dist/ai-chat-agent.d.ts +20 -17
  3. package/dist/ai-chat-agent.js +532 -222
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration-DBHGW4Hv.js +155 -0
  6. package/dist/ai-chat-v5-migration-DBHGW4Hv.js.map +1 -0
  7. package/dist/ai-chat-v5-migration.d.ts +155 -0
  8. package/dist/ai-chat-v5-migration.js +3 -0
  9. package/dist/ai-react.d.ts +73 -85
  10. package/dist/ai-react.js +266 -199
  11. package/dist/ai-react.js.map +1 -1
  12. package/dist/ai-types-B3aQaFv3.js +20 -0
  13. package/dist/ai-types-B3aQaFv3.js.map +1 -0
  14. package/dist/ai-types-D5YoPrBZ.d.ts +95 -0
  15. package/dist/ai-types.d.ts +6 -74
  16. package/dist/ai-types.js +3 -1
  17. package/dist/cli.d.ts +8 -0
  18. package/dist/cli.js +27 -0
  19. package/dist/cli.js.map +1 -0
  20. package/dist/client-BfiZ3HQd.js +117 -0
  21. package/dist/client-BfiZ3HQd.js.map +1 -0
  22. package/dist/client-Bws9q38u.d.ts +5427 -0
  23. package/dist/client-CbWe9FBd.d.ts +104 -0
  24. package/dist/client-DvK0u9vD.js +898 -0
  25. package/dist/client-DvK0u9vD.js.map +1 -0
  26. package/dist/client.d.ts +12 -93
  27. package/dist/client.js +4 -11
  28. package/dist/codemode/ai.d.ts +27 -0
  29. package/dist/codemode/ai.js +151 -0
  30. package/dist/codemode/ai.js.map +1 -0
  31. package/dist/do-oauth-client-provider-CcTno-25.d.ts +142 -0
  32. package/dist/do-oauth-client-provider-D2P1lSft.js +93 -0
  33. package/dist/do-oauth-client-provider-D2P1lSft.js.map +1 -0
  34. package/dist/index-Bdzb2feZ.d.ts +572 -0
  35. package/dist/index-DhJCaDWd.d.ts +58 -0
  36. package/dist/index.d.ts +61 -402
  37. package/dist/index.js +7 -22
  38. package/dist/mcp/client.d.ts +4 -783
  39. package/dist/mcp/client.js +4 -9
  40. package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
  41. package/dist/mcp/do-oauth-client-provider.js +3 -7
  42. package/dist/mcp/index.d.ts +190 -81
  43. package/dist/mcp/index.js +1428 -770
  44. package/dist/mcp/index.js.map +1 -1
  45. package/dist/mcp/x402.d.ts +34 -0
  46. package/dist/mcp/x402.js +194 -0
  47. package/dist/mcp/x402.js.map +1 -0
  48. package/dist/mcp-Dw5vDrY8.d.ts +61 -0
  49. package/dist/observability/index.d.ts +3 -0
  50. package/dist/observability/index.js +7 -0
  51. package/dist/react-DFNXTQzy.d.ts +113 -0
  52. package/dist/react.d.ts +10 -119
  53. package/dist/react.js +183 -110
  54. package/dist/react.js.map +1 -1
  55. package/dist/schedule.d.ts +89 -12
  56. package/dist/schedule.js +46 -21
  57. package/dist/schedule.js.map +1 -1
  58. package/dist/serializable-CymX8ovI.d.ts +39 -0
  59. package/dist/serializable.d.ts +7 -32
  60. package/dist/serializable.js +1 -1
  61. package/dist/src-C1WWpbRo.js +1247 -0
  62. package/dist/src-C1WWpbRo.js.map +1 -0
  63. package/package.json +125 -71
  64. package/dist/ai-types.js.map +0 -1
  65. package/dist/chunk-BZXOAZUX.js +0 -106
  66. package/dist/chunk-BZXOAZUX.js.map +0 -1
  67. package/dist/chunk-OYJXQRRH.js +0 -465
  68. package/dist/chunk-OYJXQRRH.js.map +0 -1
  69. package/dist/chunk-P3RZJ72N.js +0 -783
  70. package/dist/chunk-P3RZJ72N.js.map +0 -1
  71. package/dist/chunk-VCSB47AK.js +0 -116
  72. package/dist/chunk-VCSB47AK.js.map +0 -1
  73. package/dist/client.js.map +0 -1
  74. package/dist/index.js.map +0 -1
  75. package/dist/mcp/client.js.map +0 -1
  76. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  77. package/dist/serializable.js.map +0 -1
  78. package/src/index.ts +0 -1252
@@ -0,0 +1,58 @@
1
+ import { n as BaseEvent, t as MCPObservabilityEvent } from "./mcp-Dw5vDrY8.js";
2
+
3
+ //#region src/observability/agent.d.ts
4
+
5
+ /**
6
+ * Agent-specific observability events
7
+ * These track the lifecycle and operations of an Agent
8
+ */
9
+ type AgentObservabilityEvent =
10
+ | BaseEvent<"state:update", {}>
11
+ | BaseEvent<
12
+ "rpc",
13
+ {
14
+ method: string;
15
+ streaming?: boolean;
16
+ }
17
+ >
18
+ | BaseEvent<"message:request" | "message:response", {}>
19
+ | BaseEvent<"message:clear">
20
+ | BaseEvent<
21
+ "schedule:create" | "schedule:execute" | "schedule:cancel",
22
+ {
23
+ callback: string;
24
+ id: string;
25
+ }
26
+ >
27
+ | BaseEvent<"destroy">
28
+ | BaseEvent<
29
+ "connect",
30
+ {
31
+ connectionId: string;
32
+ }
33
+ >;
34
+ //#endregion
35
+ //#region src/observability/index.d.ts
36
+ /**
37
+ * Union of all observability event types from different domains
38
+ */
39
+ type ObservabilityEvent = AgentObservabilityEvent | MCPObservabilityEvent;
40
+ interface Observability {
41
+ /**
42
+ * Emit an event for the Agent's observability implementation to handle.
43
+ * @param event - The event to emit
44
+ * @param ctx - The execution context of the invocation (optional)
45
+ */
46
+ emit(event: ObservabilityEvent, ctx?: DurableObjectState): void;
47
+ }
48
+ /**
49
+ * A generic observability implementation that logs events to the console.
50
+ */
51
+ declare const genericObservability: Observability;
52
+ //#endregion
53
+ export {
54
+ ObservabilityEvent as n,
55
+ genericObservability as r,
56
+ Observability as t
57
+ };
58
+ //# sourceMappingURL=index-DhJCaDWd.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,411 +1,70 @@
1
- import { Server, Connection, PartyServerOptions } from "partyserver";
2
- export { Connection, ConnectionContext, WSMessage } from "partyserver";
1
+ import { m as TransportType } from "./client-Bws9q38u.js";
2
+ import "./mcp-Dw5vDrY8.js";
3
+ import "./do-oauth-client-provider-CcTno-25.js";
4
+ import "./index-DhJCaDWd.js";
5
+ import "./ai-types-D5YoPrBZ.js";
3
6
  import {
4
- ServerCapabilities,
5
- Tool,
6
- Prompt,
7
- Resource,
8
- } from "@modelcontextprotocol/sdk/types.js";
9
- import { MCPClientManager } from "./mcp/client.js";
10
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
11
- import "zod";
12
- import "@modelcontextprotocol/sdk/client/sse.js";
13
- import "./mcp/do-oauth-client-provider.js";
14
- import "@modelcontextprotocol/sdk/client/auth.js";
15
- import "@modelcontextprotocol/sdk/shared/auth.js";
16
- import "@modelcontextprotocol/sdk/shared/protocol.js";
17
- import "ai";
18
-
19
- /**
20
- * RPC request message from client
21
- */
22
- type RPCRequest = {
23
- type: "rpc";
24
- id: string;
25
- method: string;
26
- args: unknown[];
27
- };
28
- /**
29
- * State update message from client
30
- */
31
- type StateUpdateMessage = {
32
- type: "cf_agent_state";
33
- state: unknown;
34
- };
35
- /**
36
- * RPC response message to client
37
- */
38
- type RPCResponse = {
39
- type: "rpc";
40
- id: string;
41
- } & (
42
- | {
43
- success: true;
44
- result: unknown;
45
- done?: false;
46
- }
47
- | {
48
- success: true;
49
- result: unknown;
50
- done: true;
51
- }
52
- | {
53
- success: false;
54
- error: string;
55
- }
56
- );
57
- /**
58
- * Metadata for a callable method
59
- */
60
- type CallableMetadata = {
61
- /** Optional description of what the method does */
62
- description?: string;
63
- /** Whether the method supports streaming responses */
64
- streaming?: boolean;
65
- };
66
- /**
67
- * Decorator that marks a method as callable by clients
68
- * @param metadata Optional metadata about the callable method
69
- */
70
- declare function unstable_callable(
71
- metadata?: CallableMetadata
72
- ): <This, Args extends unknown[], Return>(
73
- target: (this: This, ...args: Args) => Return,
74
- context: ClassMethodDecoratorContext
75
- ) => (this: This, ...args: Args) => Return;
76
- /**
77
- * Represents a scheduled task within an Agent
78
- * @template T Type of the payload data
79
- */
80
- type Schedule<T = string> = {
81
- /** Unique identifier for the schedule */
82
- id: string;
83
- /** Name of the method to be called */
84
- callback: string;
85
- /** Data to be passed to the callback */
86
- payload: T;
87
- } & (
88
- | {
89
- /** Type of schedule for one-time execution at a specific time */
90
- type: "scheduled";
91
- /** Timestamp when the task should execute */
92
- time: number;
93
- }
94
- | {
95
- /** Type of schedule for delayed execution */
96
- type: "delayed";
97
- /** Timestamp when the task should execute */
98
- time: number;
99
- /** Number of seconds to delay execution */
100
- delayInSeconds: number;
101
- }
102
- | {
103
- /** Type of schedule for recurring execution based on cron expression */
104
- type: "cron";
105
- /** Timestamp for the next execution */
106
- time: number;
107
- /** Cron expression defining the schedule */
108
- cron: string;
109
- }
110
- );
111
- /**
112
- * MCP Server state update message from server -> Client
113
- */
114
- type MCPServerMessage = {
115
- type: "cf_agent_mcp_servers";
116
- mcp: MCPServersState;
117
- };
118
- type MCPServersState = {
119
- servers: {
120
- [id: string]: MCPServer;
121
- };
122
- tools: Tool[];
123
- prompts: Prompt[];
124
- resources: Resource[];
125
- };
126
- type MCPServer = {
127
- name: string;
128
- server_url: string;
129
- auth_url: string | null;
130
- state: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
131
- instructions: string | null;
132
- capabilities: ServerCapabilities | null;
133
- };
134
- declare function getCurrentAgent<
135
- T extends Agent<unknown, unknown> = Agent<unknown, unknown>,
136
- >(): {
137
- agent: T | undefined;
138
- connection: Connection | undefined;
139
- request: Request<unknown, CfProperties<unknown>> | undefined;
140
- };
141
- /**
142
- * Base class for creating Agent implementations
143
- * @template Env Environment type containing bindings
144
- * @template State State type to store within the Agent
145
- */
146
- declare class Agent<Env, State = unknown> extends Server<Env> {
147
- private _state;
148
- private _ParentClass;
149
- mcp: MCPClientManager;
150
- /**
151
- * Initial state for the Agent
152
- * Override to provide default state values
153
- */
154
- initialState: State;
155
- /**
156
- * Current state of the Agent
157
- */
158
- get state(): State;
159
- /**
160
- * Agent configuration options
161
- */
162
- static options: {
163
- /** Whether the Agent should hibernate when inactive */
164
- hibernate: boolean;
165
- };
166
- /**
167
- * Execute SQL queries against the Agent's database
168
- * @template T Type of the returned rows
169
- * @param strings SQL query template strings
170
- * @param values Values to be inserted into the query
171
- * @returns Array of query results
172
- */
173
- sql<T = Record<string, string | number | boolean | null>>(
174
- strings: TemplateStringsArray,
175
- ...values: (string | number | boolean | null)[]
176
- ): T[];
177
- constructor(ctx: AgentContext, env: Env);
178
- private _setStateInternal;
179
- /**
180
- * Update the Agent's state
181
- * @param state New state to set
182
- */
183
- setState(state: State): void;
184
- /**
185
- * Called when the Agent's state is updated
186
- * @param state Updated state
187
- * @param source Source of the state update ("server" or a client connection)
188
- */
189
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
190
- /**
191
- * Called when the Agent receives an email
192
- * @param email Email message to process
193
- */
194
- onEmail(email: ForwardableEmailMessage): Promise<void>;
195
- private _tryCatch;
196
- onError(connection: Connection, error: unknown): void | Promise<void>;
197
- onError(error: unknown): void | Promise<void>;
198
- /**
199
- * Render content (not implemented in base class)
200
- */
201
- render(): void;
202
- /**
203
- * Schedule a task to be executed in the future
204
- * @template T Type of the payload data
205
- * @param when When to execute the task (Date, seconds delay, or cron expression)
206
- * @param callback Name of the method to call
207
- * @param payload Data to pass to the callback
208
- * @returns Schedule object representing the scheduled task
209
- */
210
- schedule<T = string>(
211
- when: Date | string | number,
212
- callback: keyof this,
213
- payload?: T
214
- ): Promise<Schedule<T>>;
215
- /**
216
- * Get a scheduled task by ID
217
- * @template T Type of the payload data
218
- * @param id ID of the scheduled task
219
- * @returns The Schedule object or undefined if not found
220
- */
221
- getSchedule<T = string>(id: string): Promise<Schedule<T> | undefined>;
222
- /**
223
- * Get scheduled tasks matching the given criteria
224
- * @template T Type of the payload data
225
- * @param criteria Criteria to filter schedules
226
- * @returns Array of matching Schedule objects
227
- */
228
- getSchedules<T = string>(criteria?: {
229
- id?: string;
230
- type?: "scheduled" | "delayed" | "cron";
231
- timeRange?: {
232
- start?: Date;
233
- end?: Date;
234
- };
235
- }): Schedule<T>[];
236
- /**
237
- * Cancel a scheduled task
238
- * @param id ID of the task to cancel
239
- * @returns true if the task was cancelled, false otherwise
240
- */
241
- cancelSchedule(id: string): Promise<boolean>;
242
- private _scheduleNextAlarm;
243
- /**
244
- * Method called when an alarm fires.
245
- * Executes any scheduled tasks that are due.
246
- *
247
- * @remarks
248
- * To schedule a task, please use the `this.schedule` method instead.
249
- * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
250
- */
251
- readonly alarm: () => Promise<void>;
252
- /**
253
- * Destroy the Agent, removing all state and scheduled tasks
254
- */
255
- destroy(): Promise<void>;
256
- /**
257
- * Get all methods marked as callable on this Agent
258
- * @returns A map of method names to their metadata
259
- */
260
- private _isCallable;
261
- /**
262
- * Connect to a new MCP Server
263
- *
264
- * @param url MCP Server SSE URL
265
- * @param callbackHost Base host for the agent, used for the redirect URI.
266
- * @param agentsPrefix agents routing prefix if not using `agents`
267
- * @param options MCP client and transport (header) options
268
- * @returns authUrl
269
- */
270
- addMcpServer(
271
- serverName: string,
272
- url: string,
273
- callbackHost: string,
274
- agentsPrefix?: string,
275
- options?: {
276
- client?: ConstructorParameters<typeof Client>[1];
277
- transport?: {
278
- headers: HeadersInit;
279
- };
280
- }
281
- ): Promise<{
282
- id: string;
283
- authUrl: string | undefined;
284
- }>;
285
- _connectToMcpServerInternal(
286
- serverName: string,
287
- url: string,
288
- callbackUrl: string,
289
- options?: {
290
- client?: ConstructorParameters<typeof Client>[1];
291
- /**
292
- * We don't expose the normal set of transport options because:
293
- * 1) we can't serialize things like the auth provider or a fetch function into the DB for reconnection purposes
294
- * 2) We probably want these options to be agnostic to the transport type (SSE vs Streamable)
295
- *
296
- * This has the limitation that you can't override fetch, but I think headers should handle nearly all cases needed (i.e. non-standard bearer auth).
297
- */
298
- transport?: {
299
- headers?: HeadersInit;
300
- };
301
- },
302
- reconnect?: {
303
- id: string;
304
- oauthClientId?: string;
305
- }
306
- ): Promise<{
307
- id: string;
308
- authUrl: string | undefined;
309
- }>;
310
- removeMcpServer(id: string): Promise<void>;
311
- getMcpServers(): MCPServersState;
312
- }
313
- /**
314
- * Namespace for creating Agent instances
315
- * @template Agentic Type of the Agent class
316
- */
317
- type AgentNamespace<Agentic extends Agent<unknown>> =
318
- DurableObjectNamespace<Agentic>;
319
- /**
320
- * Agent's durable context
321
- */
322
- type AgentContext = DurableObjectState;
323
- /**
324
- * Configuration options for Agent routing
325
- */
326
- type AgentOptions<Env> = PartyServerOptions<Env> & {
327
- /**
328
- * Whether to enable CORS for the Agent
329
- */
330
- cors?: boolean | HeadersInit | undefined;
331
- };
332
- /**
333
- * Route a request to the appropriate Agent
334
- * @param request Request to route
335
- * @param env Environment containing Agent bindings
336
- * @param options Routing options
337
- * @returns Response from the Agent or undefined if no route matched
338
- */
339
- declare function routeAgentRequest<Env>(
340
- request: Request,
341
- env: Env,
342
- options?: AgentOptions<Env>
343
- ): Promise<Response | null>;
344
- /**
345
- * Route an email to the appropriate Agent
346
- * @param email Email message to route
347
- * @param env Environment containing Agent bindings
348
- * @param options Routing options
349
- */
350
- declare function routeAgentEmail<Env>(
351
- email: ForwardableEmailMessage,
352
- env: Env,
353
- options?: AgentOptions<Env>
354
- ): Promise<void>;
355
- /**
356
- * Get or create an Agent by name
357
- * @template Env Environment type containing bindings
358
- * @template T Type of the Agent class
359
- * @param namespace Agent namespace
360
- * @param name Name of the Agent instance
361
- * @param options Options for Agent creation
362
- * @returns Promise resolving to an Agent instance stub
363
- */
364
- declare function getAgentByName<Env, T extends Agent<Env>>(
365
- namespace: AgentNamespace<T>,
366
- name: string,
367
- options?: {
368
- jurisdiction?: DurableObjectJurisdiction;
369
- locationHint?: DurableObjectLocationHint;
370
- }
371
- ): Promise<DurableObjectStub<T>>;
372
- /**
373
- * A wrapper for streaming responses in callable methods
374
- */
375
- declare class StreamingResponse {
376
- private _connection;
377
- private _id;
378
- private _closed;
379
- constructor(connection: Connection, id: string);
380
- /**
381
- * Send a chunk of data to the client
382
- * @param chunk The data to send
383
- */
384
- send(chunk: unknown): void;
385
- /**
386
- * End the stream and send the final chunk (if any)
387
- * @param finalChunk Optional final chunk of data to send
388
- */
389
- end(finalChunk?: unknown): void;
390
- }
391
-
7
+ A as unstable_callable,
8
+ C as createAddressBasedEmailResolver,
9
+ D as getCurrentAgent,
10
+ E as getAgentByName,
11
+ O as routeAgentEmail,
12
+ S as callable,
13
+ T as createHeaderBasedEmailResolver,
14
+ _ as RPCResponse,
15
+ a as AgentOptions,
16
+ b as StreamingResponse,
17
+ c as ConnectionContext,
18
+ d as EmailSendOptions,
19
+ f as MCPServer,
20
+ g as RPCRequest,
21
+ h as QueueItem,
22
+ i as AgentNamespace,
23
+ k as routeAgentRequest,
24
+ l as EmailResolver,
25
+ m as MCPServersState,
26
+ n as AgentContext,
27
+ o as CallableMetadata,
28
+ p as MCPServerMessage,
29
+ r as AgentEmail,
30
+ s as Connection,
31
+ t as Agent,
32
+ u as EmailRoutingOptions,
33
+ v as Schedule,
34
+ w as createCatchAllEmailResolver,
35
+ x as WSMessage,
36
+ y as StateUpdateMessage
37
+ } from "./index-Bdzb2feZ.js";
392
38
  export {
393
39
  Agent,
394
- type AgentContext,
395
- type AgentNamespace,
396
- type AgentOptions,
397
- type CallableMetadata,
398
- type MCPServer,
399
- type MCPServerMessage,
400
- type MCPServersState,
401
- type RPCRequest,
402
- type RPCResponse,
403
- type Schedule,
404
- type StateUpdateMessage,
40
+ AgentContext,
41
+ AgentEmail,
42
+ AgentNamespace,
43
+ AgentOptions,
44
+ CallableMetadata,
45
+ Connection,
46
+ ConnectionContext,
47
+ EmailResolver,
48
+ EmailRoutingOptions,
49
+ EmailSendOptions,
50
+ MCPServer,
51
+ MCPServerMessage,
52
+ MCPServersState,
53
+ QueueItem,
54
+ RPCRequest,
55
+ RPCResponse,
56
+ Schedule,
57
+ StateUpdateMessage,
405
58
  StreamingResponse,
59
+ TransportType,
60
+ WSMessage,
61
+ callable,
62
+ createAddressBasedEmailResolver,
63
+ createCatchAllEmailResolver,
64
+ createHeaderBasedEmailResolver,
406
65
  getAgentByName,
407
66
  getCurrentAgent,
408
67
  routeAgentEmail,
409
68
  routeAgentRequest,
410
- unstable_callable,
69
+ unstable_callable
411
70
  };
package/dist/index.js CHANGED
@@ -1,22 +1,7 @@
1
- import {
2
- Agent,
3
- StreamingResponse,
4
- getAgentByName,
5
- getCurrentAgent,
6
- routeAgentEmail,
7
- routeAgentRequest,
8
- unstable_callable
9
- } from "./chunk-P3RZJ72N.js";
10
- import "./chunk-OYJXQRRH.js";
11
- import "./chunk-BZXOAZUX.js";
12
- import "./chunk-VCSB47AK.js";
13
- export {
14
- Agent,
15
- StreamingResponse,
16
- getAgentByName,
17
- getCurrentAgent,
18
- routeAgentEmail,
19
- routeAgentRequest,
20
- unstable_callable
21
- };
22
- //# sourceMappingURL=index.js.map
1
+ import "./ai-types-B3aQaFv3.js";
2
+ import "./client-BfiZ3HQd.js";
3
+ import "./client-DvK0u9vD.js";
4
+ import "./do-oauth-client-provider-D2P1lSft.js";
5
+ import { a as createCatchAllEmailResolver, c as getCurrentAgent, d as unstable_callable, i as createAddressBasedEmailResolver, l as routeAgentEmail, n as StreamingResponse, o as createHeaderBasedEmailResolver, r as callable, s as getAgentByName, t as Agent, u as routeAgentRequest } from "./src-C1WWpbRo.js";
6
+
7
+ export { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };