agents 0.0.0-569680f → 0.0.0-57c0db2

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 (68) hide show
  1. package/README.md +255 -27
  2. package/dist/_esm-LV5FJ3HK.js +3922 -0
  3. package/dist/_esm-LV5FJ3HK.js.map +1 -0
  4. package/dist/ai-chat-agent.d.ts +12 -9
  5. package/dist/ai-chat-agent.js +151 -59
  6. package/dist/ai-chat-agent.js.map +1 -1
  7. package/dist/ai-chat-v5-migration.d.ts +152 -0
  8. package/dist/ai-chat-v5-migration.js +20 -0
  9. package/dist/ai-chat-v5-migration.js.map +1 -0
  10. package/dist/ai-react.d.ts +68 -71
  11. package/dist/ai-react.js +178 -37
  12. package/dist/ai-react.js.map +1 -1
  13. package/dist/ai-types.d.ts +37 -19
  14. package/dist/ai-types.js +7 -0
  15. package/dist/ccip-CMBYN64O.js +15 -0
  16. package/dist/ccip-CMBYN64O.js.map +1 -0
  17. package/dist/chunk-5Y6BEZDY.js +276 -0
  18. package/dist/chunk-5Y6BEZDY.js.map +1 -0
  19. package/dist/chunk-BER7KXUJ.js +18 -0
  20. package/dist/chunk-BER7KXUJ.js.map +1 -0
  21. package/dist/{chunk-RX76B6DL.js → chunk-HS7VEROK.js} +454 -179
  22. package/dist/chunk-HS7VEROK.js.map +1 -0
  23. package/dist/chunk-JJBFIGUC.js +5202 -0
  24. package/dist/chunk-JJBFIGUC.js.map +1 -0
  25. package/dist/{chunk-767EASBA.js → chunk-LL2AFX7V.js} +5 -2
  26. package/dist/chunk-LL2AFX7V.js.map +1 -0
  27. package/dist/chunk-PR4QN5HX.js +43 -0
  28. package/dist/chunk-PR4QN5HX.js.map +1 -0
  29. package/dist/{chunk-NKZZ66QY.js → chunk-QEVM4BVL.js} +5 -5
  30. package/dist/chunk-QEVM4BVL.js.map +1 -0
  31. package/dist/{chunk-TN7QOY4S.js → chunk-SKACXF37.js} +164 -21
  32. package/dist/chunk-SKACXF37.js.map +1 -0
  33. package/dist/chunk-TYAY6AU6.js +159 -0
  34. package/dist/chunk-TYAY6AU6.js.map +1 -0
  35. package/dist/chunk-UJVEAURM.js +150 -0
  36. package/dist/chunk-UJVEAURM.js.map +1 -0
  37. package/dist/client-CvaJdLQA.d.ts +5015 -0
  38. package/dist/client.d.ts +2 -2
  39. package/dist/client.js +3 -1
  40. package/dist/index.d.ts +557 -31
  41. package/dist/index.js +14 -12
  42. package/dist/mcp/client.d.ts +9 -1053
  43. package/dist/mcp/client.js +2 -1
  44. package/dist/mcp/do-oauth-client-provider.d.ts +1 -0
  45. package/dist/mcp/do-oauth-client-provider.js +2 -1
  46. package/dist/mcp/index.d.ts +64 -56
  47. package/dist/mcp/index.js +954 -638
  48. package/dist/mcp/index.js.map +1 -1
  49. package/dist/mcp/x402.d.ts +31 -0
  50. package/dist/mcp/x402.js +3195 -0
  51. package/dist/mcp/x402.js.map +1 -0
  52. package/dist/observability/index.d.ts +46 -12
  53. package/dist/observability/index.js +6 -4
  54. package/dist/react.d.ts +10 -6
  55. package/dist/react.js +8 -5
  56. package/dist/react.js.map +1 -1
  57. package/dist/schedule.d.ts +83 -9
  58. package/dist/schedule.js +17 -2
  59. package/dist/schedule.js.map +1 -1
  60. package/dist/secp256k1-M22GZP2U.js +2193 -0
  61. package/dist/secp256k1-M22GZP2U.js.map +1 -0
  62. package/package.json +26 -10
  63. package/src/index.ts +651 -236
  64. package/dist/chunk-767EASBA.js.map +0 -1
  65. package/dist/chunk-NKZZ66QY.js.map +0 -1
  66. package/dist/chunk-RX76B6DL.js.map +0 -1
  67. package/dist/chunk-TN7QOY4S.js.map +0 -1
  68. package/dist/index-aBwVVXj7.d.ts +0 -529
@@ -1,529 +0,0 @@
1
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import {
3
- ServerCapabilities,
4
- Tool,
5
- Prompt,
6
- Resource,
7
- } from "@modelcontextprotocol/sdk/types.js";
8
- import { Server, Connection, PartyServerOptions } from "partyserver";
9
- import { MCPClientManager } from "./mcp/client.js";
10
- import { Message } from "ai";
11
-
12
- type BaseEvent<
13
- T extends string,
14
- Payload extends Record<string, unknown> = {},
15
- > = {
16
- type: T;
17
- /**
18
- * The unique identifier for the event
19
- */
20
- id: string;
21
- /**
22
- * The message to display in the logs for this event, should the implementation choose to display
23
- * a human-readable message.
24
- */
25
- displayMessage: string;
26
- /**
27
- * The payload of the event
28
- */
29
- payload: Payload;
30
- /**
31
- * The timestamp of the event in milliseconds since epoch
32
- */
33
- timestamp: number;
34
- };
35
- /**
36
- * The type of events that can be emitted by an Agent
37
- */
38
- type ObservabilityEvent =
39
- | BaseEvent<
40
- "state:update",
41
- {
42
- state: unknown;
43
- previousState: unknown;
44
- }
45
- >
46
- | BaseEvent<
47
- "rpc",
48
- {
49
- method: string;
50
- args: unknown[];
51
- streaming?: boolean;
52
- success: boolean;
53
- }
54
- >
55
- | BaseEvent<
56
- "message:request" | "message:response",
57
- {
58
- message: Message[];
59
- }
60
- >
61
- | BaseEvent<"message:clear">
62
- | BaseEvent<
63
- "schedule:create" | "schedule:execute" | "schedule:cancel",
64
- Schedule<unknown>
65
- >
66
- | BaseEvent<"destroy">
67
- | BaseEvent<
68
- "connect",
69
- {
70
- connectionId: string;
71
- }
72
- >;
73
- interface Observability {
74
- /**
75
- * Emit an event for the Agent's observability implementation to handle.
76
- * @param event - The event to emit
77
- * @param ctx - The execution context of the invocation
78
- */
79
- emit(event: ObservabilityEvent, ctx: DurableObjectState): void;
80
- }
81
- /**
82
- * A generic observability implementation that logs events to the console.
83
- */
84
- declare const genericObservability: Observability;
85
-
86
- /**
87
- * RPC request message from client
88
- */
89
- type RPCRequest = {
90
- type: "rpc";
91
- id: string;
92
- method: string;
93
- args: unknown[];
94
- };
95
- /**
96
- * State update message from client
97
- */
98
- type StateUpdateMessage = {
99
- type: "cf_agent_state";
100
- state: unknown;
101
- };
102
- /**
103
- * RPC response message to client
104
- */
105
- type RPCResponse = {
106
- type: "rpc";
107
- id: string;
108
- } & (
109
- | {
110
- success: true;
111
- result: unknown;
112
- done?: false;
113
- }
114
- | {
115
- success: true;
116
- result: unknown;
117
- done: true;
118
- }
119
- | {
120
- success: false;
121
- error: string;
122
- }
123
- );
124
- /**
125
- * Metadata for a callable method
126
- */
127
- type CallableMetadata = {
128
- /** Optional description of what the method does */
129
- description?: string;
130
- /** Whether the method supports streaming responses */
131
- streaming?: boolean;
132
- };
133
- /**
134
- * Decorator that marks a method as callable by clients
135
- * @param metadata Optional metadata about the callable method
136
- */
137
- declare function unstable_callable(
138
- metadata?: CallableMetadata
139
- ): <This, Args extends unknown[], Return>(
140
- target: (this: This, ...args: Args) => Return,
141
- context: ClassMethodDecoratorContext
142
- ) => (this: This, ...args: Args) => Return;
143
- /**
144
- * Represents a scheduled task within an Agent
145
- * @template T Type of the payload data
146
- */
147
- type Schedule<T = string> = {
148
- /** Unique identifier for the schedule */
149
- id: string;
150
- /** Name of the method to be called */
151
- callback: string;
152
- /** Data to be passed to the callback */
153
- payload: T;
154
- } & (
155
- | {
156
- /** Type of schedule for one-time execution at a specific time */
157
- type: "scheduled";
158
- /** Timestamp when the task should execute */
159
- time: number;
160
- }
161
- | {
162
- /** Type of schedule for delayed execution */
163
- type: "delayed";
164
- /** Timestamp when the task should execute */
165
- time: number;
166
- /** Number of seconds to delay execution */
167
- delayInSeconds: number;
168
- }
169
- | {
170
- /** Type of schedule for recurring execution based on cron expression */
171
- type: "cron";
172
- /** Timestamp for the next execution */
173
- time: number;
174
- /** Cron expression defining the schedule */
175
- cron: string;
176
- }
177
- );
178
- /**
179
- * MCP Server state update message from server -> Client
180
- */
181
- type MCPServerMessage = {
182
- type: "cf_agent_mcp_servers";
183
- mcp: MCPServersState;
184
- };
185
- type MCPServersState = {
186
- servers: {
187
- [id: string]: MCPServer;
188
- };
189
- tools: Tool[];
190
- prompts: Prompt[];
191
- resources: Resource[];
192
- };
193
- type MCPServer = {
194
- name: string;
195
- server_url: string;
196
- auth_url: string | null;
197
- state: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
198
- instructions: string | null;
199
- capabilities: ServerCapabilities | null;
200
- };
201
- declare function getCurrentAgent<
202
- T extends Agent<unknown, unknown> = Agent<unknown, unknown>,
203
- >(): {
204
- agent: T | undefined;
205
- connection: Connection | undefined;
206
- request: Request<unknown, CfProperties<unknown>> | undefined;
207
- };
208
- /**
209
- * Base class for creating Agent implementations
210
- * @template Env Environment type containing bindings
211
- * @template State State type to store within the Agent
212
- */
213
- declare class Agent<Env, State = unknown> extends Server<Env> {
214
- private _state;
215
- private _ParentClass;
216
- mcp: MCPClientManager;
217
- /**
218
- * Initial state for the Agent
219
- * Override to provide default state values
220
- */
221
- initialState: State;
222
- /**
223
- * Current state of the Agent
224
- */
225
- get state(): State;
226
- /**
227
- * Agent configuration options
228
- */
229
- static options: {
230
- /** Whether the Agent should hibernate when inactive */
231
- hibernate: boolean;
232
- };
233
- /**
234
- * The observability implementation to use for the Agent
235
- */
236
- observability?: Observability;
237
- /**
238
- * Execute SQL queries against the Agent's database
239
- * @template T Type of the returned rows
240
- * @param strings SQL query template strings
241
- * @param values Values to be inserted into the query
242
- * @returns Array of query results
243
- */
244
- sql<T = Record<string, string | number | boolean | null>>(
245
- strings: TemplateStringsArray,
246
- ...values: (string | number | boolean | null)[]
247
- ): T[];
248
- constructor(ctx: AgentContext, env: Env);
249
- private _setStateInternal;
250
- /**
251
- * Update the Agent's state
252
- * @param state New state to set
253
- */
254
- setState(state: State): void;
255
- /**
256
- * Called when the Agent's state is updated
257
- * @param state Updated state
258
- * @param source Source of the state update ("server" or a client connection)
259
- */
260
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
261
- /**
262
- * Called when the Agent receives an email
263
- * Override this method to handle incoming emails
264
- * @param email Email message to process
265
- */
266
- onEmail(email: ForwardableEmailMessage): Promise<void>;
267
- sendEmail(
268
- emailBinding: SendEmail,
269
- from: string,
270
- fromName: string,
271
- options: Omit<EmailSendOptions, "agentName" | "agentId">
272
- ): Promise<void>;
273
- private _tryCatch;
274
- onError(connection: Connection, error: unknown): void | Promise<void>;
275
- onError(error: unknown): void | Promise<void>;
276
- /**
277
- * Render content (not implemented in base class)
278
- */
279
- render(): void;
280
- /**
281
- * Schedule a task to be executed in the future
282
- * @template T Type of the payload data
283
- * @param when When to execute the task (Date, seconds delay, or cron expression)
284
- * @param callback Name of the method to call
285
- * @param payload Data to pass to the callback
286
- * @returns Schedule object representing the scheduled task
287
- */
288
- schedule<T = string>(
289
- when: Date | string | number,
290
- callback: keyof this,
291
- payload?: T
292
- ): Promise<Schedule<T>>;
293
- /**
294
- * Get a scheduled task by ID
295
- * @template T Type of the payload data
296
- * @param id ID of the scheduled task
297
- * @returns The Schedule object or undefined if not found
298
- */
299
- getSchedule<T = string>(id: string): Promise<Schedule<T> | undefined>;
300
- /**
301
- * Get scheduled tasks matching the given criteria
302
- * @template T Type of the payload data
303
- * @param criteria Criteria to filter schedules
304
- * @returns Array of matching Schedule objects
305
- */
306
- getSchedules<T = string>(criteria?: {
307
- id?: string;
308
- type?: "scheduled" | "delayed" | "cron";
309
- timeRange?: {
310
- start?: Date;
311
- end?: Date;
312
- };
313
- }): Schedule<T>[];
314
- /**
315
- * Cancel a scheduled task
316
- * @param id ID of the task to cancel
317
- * @returns true if the task was cancelled, false otherwise
318
- */
319
- cancelSchedule(id: string): Promise<boolean>;
320
- private _scheduleNextAlarm;
321
- /**
322
- * Method called when an alarm fires.
323
- * Executes any scheduled tasks that are due.
324
- *
325
- * @remarks
326
- * To schedule a task, please use the `this.schedule` method instead.
327
- * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
328
- */
329
- readonly alarm: () => Promise<void>;
330
- /**
331
- * Destroy the Agent, removing all state and scheduled tasks
332
- */
333
- destroy(): Promise<void>;
334
- /**
335
- * Get all methods marked as callable on this Agent
336
- * @returns A map of method names to their metadata
337
- */
338
- private _isCallable;
339
- /**
340
- * Connect to a new MCP Server
341
- *
342
- * @param url MCP Server SSE URL
343
- * @param callbackHost Base host for the agent, used for the redirect URI.
344
- * @param agentsPrefix agents routing prefix if not using `agents`
345
- * @param options MCP client and transport (header) options
346
- * @returns authUrl
347
- */
348
- addMcpServer(
349
- serverName: string,
350
- url: string,
351
- callbackHost: string,
352
- agentsPrefix?: string,
353
- options?: {
354
- client?: ConstructorParameters<typeof Client>[1];
355
- transport?: {
356
- headers: HeadersInit;
357
- };
358
- }
359
- ): Promise<{
360
- id: string;
361
- authUrl: string | undefined;
362
- }>;
363
- _connectToMcpServerInternal(
364
- _serverName: string,
365
- url: string,
366
- callbackUrl: string,
367
- options?: {
368
- client?: ConstructorParameters<typeof Client>[1];
369
- /**
370
- * We don't expose the normal set of transport options because:
371
- * 1) we can't serialize things like the auth provider or a fetch function into the DB for reconnection purposes
372
- * 2) We probably want these options to be agnostic to the transport type (SSE vs Streamable)
373
- *
374
- * 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).
375
- */
376
- transport?: {
377
- headers?: HeadersInit;
378
- };
379
- },
380
- reconnect?: {
381
- id: string;
382
- oauthClientId?: string;
383
- }
384
- ): Promise<{
385
- id: string;
386
- authUrl: string | undefined;
387
- clientId: string | undefined;
388
- }>;
389
- removeMcpServer(id: string): Promise<void>;
390
- getMcpServers(): MCPServersState;
391
- }
392
- /**
393
- * Namespace for creating Agent instances
394
- * @template Agentic Type of the Agent class
395
- */
396
- type AgentNamespace<Agentic extends Agent<unknown>> =
397
- DurableObjectNamespace<Agentic>;
398
- /**
399
- * Agent's durable context
400
- */
401
- type AgentContext = DurableObjectState;
402
- /**
403
- * Configuration options for Agent routing
404
- */
405
- type AgentOptions<Env> = PartyServerOptions<Env> & {
406
- /**
407
- * Whether to enable CORS for the Agent
408
- */
409
- cors?: boolean | HeadersInit | undefined;
410
- };
411
- /**
412
- * Route a request to the appropriate Agent
413
- * @param request Request to route
414
- * @param env Environment containing Agent bindings
415
- * @param options Routing options
416
- * @returns Response from the Agent or undefined if no route matched
417
- */
418
- declare function routeAgentRequest<Env>(
419
- request: Request,
420
- env: Env,
421
- options?: AgentOptions<Env>
422
- ): Promise<Response | null>;
423
- type EmailResolver<Env> = (
424
- email: ForwardableEmailMessage,
425
- env: Env
426
- ) => Promise<{
427
- agentName: string;
428
- agentId: string;
429
- } | null>;
430
- declare function createHeaderBasedResolver<Env>(): EmailResolver<Env>;
431
- declare function createAddressBasedResolver<Env>(
432
- defaultAgentName: string
433
- ): EmailResolver<Env>;
434
- declare function createCatchAllResolver<Env>(
435
- agentName: string,
436
- agentId: string
437
- ): EmailResolver<Env>;
438
- type EmailRoutingOptions<Env> = AgentOptions<Env> & {
439
- resolver: EmailResolver<Env>;
440
- };
441
- declare function routeAgentEmail<Env>(
442
- email: ForwardableEmailMessage,
443
- env: Env,
444
- options: EmailRoutingOptions<Env>
445
- ): Promise<void>;
446
- type EmailSendOptions = {
447
- to: string;
448
- subject: string;
449
- body: string;
450
- contentType?: string;
451
- headers?: Record<string, string>;
452
- includeRoutingHeaders?: boolean;
453
- agentName?: string;
454
- agentId?: string;
455
- domain?: string;
456
- };
457
- declare function sendEmailWithRouting(
458
- emailBinding: SendEmail,
459
- from: string,
460
- fromName: string,
461
- options: EmailSendOptions
462
- ): Promise<void>;
463
- /**
464
- * Get or create an Agent by name
465
- * @template Env Environment type containing bindings
466
- * @template T Type of the Agent class
467
- * @param namespace Agent namespace
468
- * @param name Name of the Agent instance
469
- * @param options Options for Agent creation
470
- * @returns Promise resolving to an Agent instance stub
471
- */
472
- declare function getAgentByName<Env, T extends Agent<Env>>(
473
- namespace: AgentNamespace<T>,
474
- name: string,
475
- options?: {
476
- jurisdiction?: DurableObjectJurisdiction;
477
- locationHint?: DurableObjectLocationHint;
478
- }
479
- ): Promise<DurableObjectStub<T>>;
480
- /**
481
- * A wrapper for streaming responses in callable methods
482
- */
483
- declare class StreamingResponse {
484
- private _connection;
485
- private _id;
486
- private _closed;
487
- constructor(connection: Connection, id: string);
488
- /**
489
- * Send a chunk of data to the client
490
- * @param chunk The data to send
491
- */
492
- send(chunk: unknown): void;
493
- /**
494
- * End the stream and send the final chunk (if any)
495
- * @param finalChunk Optional final chunk of data to send
496
- */
497
- end(finalChunk?: unknown): void;
498
- }
499
-
500
- export {
501
- Agent as A,
502
- type CallableMetadata as C,
503
- type EmailResolver as E,
504
- type MCPServersState as M,
505
- type ObservabilityEvent as O,
506
- type RPCRequest as R,
507
- type StateUpdateMessage as S,
508
- type AgentContext as a,
509
- type Observability as b,
510
- type RPCResponse as c,
511
- type Schedule as d,
512
- type MCPServerMessage as e,
513
- type MCPServer as f,
514
- genericObservability as g,
515
- getCurrentAgent as h,
516
- type AgentNamespace as i,
517
- type AgentOptions as j,
518
- createHeaderBasedResolver as k,
519
- createAddressBasedResolver as l,
520
- createCatchAllResolver as m,
521
- type EmailRoutingOptions as n,
522
- routeAgentEmail as o,
523
- type EmailSendOptions as p,
524
- getAgentByName as q,
525
- routeAgentRequest as r,
526
- sendEmailWithRouting as s,
527
- StreamingResponse as t,
528
- unstable_callable as u,
529
- };