agents 0.0.0-d6a4eda → 0.0.0-d6d6d60

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