agents 0.0.0-4100b67 → 0.0.0-412321b

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 +261 -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-BnO9jNtu.d.ts +5283 -0
  23. package/dist/client-CbWe9FBd.d.ts +104 -0
  24. package/dist/client-DZhjV_XA.js +719 -0
  25. package/dist/client-DZhjV_XA.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-CswoD5Lu.js +93 -0
  32. package/dist/do-oauth-client-provider-CswoD5Lu.js.map +1 -0
  33. package/dist/do-oauth-client-provider-DGc5pP0l.d.ts +55 -0
  34. package/dist/index-B_xUDCSO.d.ts +567 -0
  35. package/dist/index-DhJCaDWd.d.ts +58 -0
  36. package/dist/index.d.ts +62 -396
  37. package/dist/index.js +7 -22
  38. package/dist/mcp/client.d.ts +4 -783
  39. package/dist/mcp/client.js +3 -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-4KUZZPoU.d.ts +113 -0
  52. package/dist/react.d.ts +10 -101
  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-BmdxQRpB.js +1235 -0
  62. package/dist/src-BmdxQRpB.js.map +1 -0
  63. package/package.json +125 -72
  64. package/dist/ai-types.js.map +0 -1
  65. package/dist/chunk-4ARKO5R4.js +0 -781
  66. package/dist/chunk-4ARKO5R4.js.map +0 -1
  67. package/dist/chunk-BZXOAZUX.js +0 -106
  68. package/dist/chunk-BZXOAZUX.js.map +0 -1
  69. package/dist/chunk-QSGN3REV.js +0 -123
  70. package/dist/chunk-QSGN3REV.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 -1244
package/dist/index.d.ts CHANGED
@@ -1,404 +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
- /**
250
- * Get all methods marked as callable on this Agent
251
- * @returns A map of method names to their metadata
252
- */
253
- private _isCallable;
254
- /**
255
- * Connect to a new MCP Server
256
- *
257
- * @param url MCP Server SSE URL
258
- * @param callbackHost Base host for the agent, used for the redirect URI.
259
- * @param agentsPrefix agents routing prefix if not using `agents`
260
- * @param options MCP client and transport (header) options
261
- * @returns authUrl
262
- */
263
- addMcpServer(
264
- serverName: string,
265
- url: string,
266
- callbackHost: string,
267
- agentsPrefix?: string,
268
- options?: {
269
- client?: ConstructorParameters<typeof Client>[1];
270
- transport?: {
271
- headers: HeadersInit;
272
- };
273
- }
274
- ): Promise<{
275
- id: string;
276
- authUrl: string | undefined;
277
- }>;
278
- _connectToMcpServerInternal(
279
- serverName: string,
280
- url: string,
281
- callbackUrl: string,
282
- options?: {
283
- client?: ConstructorParameters<typeof Client>[1];
284
- /**
285
- * We don't expose the normal set of transport options because:
286
- * 1) we can't serialize things like the auth provider or a fetch function into the DB for reconnection purposes
287
- * 2) We probably want these options to be agnostic to the transport type (SSE vs Streamable)
288
- *
289
- * 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).
290
- */
291
- transport?: {
292
- headers?: HeadersInit;
293
- };
294
- },
295
- reconnect?: {
296
- id: string;
297
- oauthClientId?: string;
298
- }
299
- ): Promise<{
300
- id: string;
301
- authUrl: string | undefined;
302
- }>;
303
- removeMcpServer(id: string): Promise<void>;
304
- private _getMcpServerStateInternal;
305
- }
306
- /**
307
- * Namespace for creating Agent instances
308
- * @template Agentic Type of the Agent class
309
- */
310
- type AgentNamespace<Agentic extends Agent<unknown>> =
311
- DurableObjectNamespace<Agentic>;
312
- /**
313
- * Agent's durable context
314
- */
315
- type AgentContext = DurableObjectState;
316
- /**
317
- * Configuration options for Agent routing
318
- */
319
- type AgentOptions<Env> = PartyServerOptions<Env> & {
320
- /**
321
- * Whether to enable CORS for the Agent
322
- */
323
- cors?: boolean | HeadersInit | undefined;
324
- };
325
- /**
326
- * Route a request to the appropriate Agent
327
- * @param request Request to route
328
- * @param env Environment containing Agent bindings
329
- * @param options Routing options
330
- * @returns Response from the Agent or undefined if no route matched
331
- */
332
- declare function routeAgentRequest<Env>(
333
- request: Request,
334
- env: Env,
335
- options?: AgentOptions<Env>
336
- ): Promise<Response | null>;
337
- /**
338
- * Route an email to the appropriate Agent
339
- * @param email Email message to route
340
- * @param env Environment containing Agent bindings
341
- * @param options Routing options
342
- */
343
- declare function routeAgentEmail<Env>(
344
- email: ForwardableEmailMessage,
345
- env: Env,
346
- options?: AgentOptions<Env>
347
- ): Promise<void>;
348
- /**
349
- * Get or create an Agent by name
350
- * @template Env Environment type containing bindings
351
- * @template T Type of the Agent class
352
- * @param namespace Agent namespace
353
- * @param name Name of the Agent instance
354
- * @param options Options for Agent creation
355
- * @returns Promise resolving to an Agent instance stub
356
- */
357
- declare function getAgentByName<Env, T extends Agent<Env>>(
358
- namespace: AgentNamespace<T>,
359
- name: string,
360
- options?: {
361
- jurisdiction?: DurableObjectJurisdiction;
362
- locationHint?: DurableObjectLocationHint;
363
- }
364
- ): Promise<DurableObjectStub<T>>;
365
- /**
366
- * A wrapper for streaming responses in callable methods
367
- */
368
- declare class StreamingResponse {
369
- private _connection;
370
- private _id;
371
- private _closed;
372
- constructor(connection: Connection, id: string);
373
- /**
374
- * Send a chunk of data to the client
375
- * @param chunk The data to send
376
- */
377
- send(chunk: unknown): void;
378
- /**
379
- * End the stream and send the final chunk (if any)
380
- * @param finalChunk Optional final chunk of data to send
381
- */
382
- end(finalChunk?: unknown): void;
383
- }
384
-
1
+ import { u as TransportType } from "./client-BnO9jNtu.js";
2
+ import "./mcp-Dw5vDrY8.js";
3
+ import "./do-oauth-client-provider-DGc5pP0l.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-B_xUDCSO.js";
385
38
  export {
386
39
  Agent,
387
- type AgentContext,
388
- type AgentNamespace,
389
- type AgentOptions,
390
- type CallableMetadata,
391
- type MCPServer,
392
- type MCPServerMessage,
393
- type MCPServersState,
394
- type RPCRequest,
395
- type RPCResponse,
396
- type Schedule,
397
- 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,
398
58
  StreamingResponse,
59
+ TransportType,
60
+ WSMessage,
61
+ callable,
62
+ createAddressBasedEmailResolver,
63
+ createCatchAllEmailResolver,
64
+ createHeaderBasedEmailResolver,
399
65
  getAgentByName,
400
66
  getCurrentAgent,
401
67
  routeAgentEmail,
402
68
  routeAgentRequest,
403
- unstable_callable,
69
+ unstable_callable
404
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-4ARKO5R4.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-DZhjV_XA.js";
4
+ import "./do-oauth-client-provider-CswoD5Lu.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-BmdxQRpB.js";
6
+
7
+ export { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };