agents 0.0.0-8bf3250 → 0.0.0-8c9aadd

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 (75) 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 -230
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration-gdyLiTd8.js +155 -0
  6. package/dist/ai-chat-v5-migration-gdyLiTd8.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 +261 -199
  11. package/dist/ai-react.js.map +1 -1
  12. package/dist/ai-types-BWW4umHY.d.ts +95 -0
  13. package/dist/ai-types-UZlfLOYP.js +20 -0
  14. package/dist/ai-types-UZlfLOYP.js.map +1 -0
  15. package/dist/ai-types.d.ts +6 -74
  16. package/dist/ai-types.js +3 -1
  17. package/dist/client-C-nwz-3N.d.ts +5313 -0
  18. package/dist/client-CZBVDDoO.js +786 -0
  19. package/dist/client-CZBVDDoO.js.map +1 -0
  20. package/dist/client-CmMi85Sj.d.ts +104 -0
  21. package/dist/client-DjR-lC16.js +117 -0
  22. package/dist/client-DjR-lC16.js.map +1 -0
  23. package/dist/client.d.ts +12 -93
  24. package/dist/client.js +4 -11
  25. package/dist/codemode/ai.d.ts +27 -0
  26. package/dist/codemode/ai.js +151 -0
  27. package/dist/codemode/ai.js.map +1 -0
  28. package/dist/do-oauth-client-provider-B2jr6UNq.js +93 -0
  29. package/dist/do-oauth-client-provider-B2jr6UNq.js.map +1 -0
  30. package/dist/do-oauth-client-provider-CCwGwnrA.d.ts +55 -0
  31. package/dist/index-DWJSBMbz.d.ts +736 -0
  32. package/dist/index-W4JUkafc.d.ts +54 -0
  33. package/dist/index.d.ts +75 -403
  34. package/dist/index.js +7 -22
  35. package/dist/mcp/client.d.ts +4 -1055
  36. package/dist/mcp/client.js +3 -9
  37. package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
  38. package/dist/mcp/do-oauth-client-provider.js +3 -7
  39. package/dist/mcp/index.d.ts +7 -84
  40. package/dist/mcp/index.js +6 -782
  41. package/dist/mcp/x402.d.ts +34 -0
  42. package/dist/mcp/x402.js +194 -0
  43. package/dist/mcp/x402.js.map +1 -0
  44. package/dist/mcp-BEwaCsxO.d.ts +61 -0
  45. package/dist/observability/index.d.ts +3 -0
  46. package/dist/observability/index.js +7 -0
  47. package/dist/react-GnTP-a01.d.ts +113 -0
  48. package/dist/react.d.ts +10 -119
  49. package/dist/react.js +183 -110
  50. package/dist/react.js.map +1 -1
  51. package/dist/schedule.d.ts +87 -10
  52. package/dist/schedule.js +46 -21
  53. package/dist/schedule.js.map +1 -1
  54. package/dist/serializable-gtr9YMhp.d.ts +34 -0
  55. package/dist/serializable.d.ts +7 -32
  56. package/dist/serializable.js +1 -1
  57. package/dist/src-tpG9NtHy.js +2457 -0
  58. package/dist/src-tpG9NtHy.js.map +1 -0
  59. package/package.json +52 -12
  60. package/dist/ai-types.js.map +0 -1
  61. package/dist/chunk-4CIGD73X.js +0 -791
  62. package/dist/chunk-4CIGD73X.js.map +0 -1
  63. package/dist/chunk-767EASBA.js +0 -106
  64. package/dist/chunk-767EASBA.js.map +0 -1
  65. package/dist/chunk-E3LCYPCB.js +0 -469
  66. package/dist/chunk-E3LCYPCB.js.map +0 -1
  67. package/dist/chunk-NKZZ66QY.js +0 -116
  68. package/dist/chunk-NKZZ66QY.js.map +0 -1
  69. package/dist/client.js.map +0 -1
  70. package/dist/index.js.map +0 -1
  71. package/dist/mcp/client.js.map +0 -1
  72. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  73. package/dist/mcp/index.js.map +0 -1
  74. package/dist/serializable.js.map +0 -1
  75. package/src/index.ts +0 -1257
@@ -0,0 +1,736 @@
1
+ import {
2
+ BaseTransportType,
3
+ MCPClientManager,
4
+ MCPConnectionState,
5
+ MaybePromise,
6
+ ServeOptions,
7
+ TransportType
8
+ } from "./client-C-nwz-3N.js";
9
+ import { Observability } from "./index-W4JUkafc.js";
10
+ import { MessageType } from "./ai-types-BWW4umHY.js";
11
+ import {
12
+ Connection,
13
+ Connection as Connection$1,
14
+ ConnectionContext,
15
+ PartyServerOptions,
16
+ Server,
17
+ WSMessage
18
+ } from "partyserver";
19
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
20
+ import {
21
+ ElicitRequest as ElicitRequest$1,
22
+ ElicitRequestSchema as ElicitRequestSchema$1,
23
+ ElicitResult,
24
+ ElicitResult as ElicitResult$1,
25
+ JSONRPCMessage,
26
+ Prompt,
27
+ Resource,
28
+ ServerCapabilities,
29
+ Tool
30
+ } from "@modelcontextprotocol/sdk/types.js";
31
+ import { env } from "cloudflare:workers";
32
+ import { Server as Server$1 } from "@modelcontextprotocol/sdk/server/index.js";
33
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
34
+ import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
35
+
36
+ //#region src/mcp/worker-transport.d.ts
37
+ interface WorkerTransportOptions {
38
+ sessionIdGenerator?: () => string;
39
+ enableJsonResponse?: boolean;
40
+ onsessioninitialized?: (sessionId: string) => void;
41
+ }
42
+ declare class WorkerTransport implements Transport {
43
+ private started;
44
+ private initialized;
45
+ private sessionIdGenerator?;
46
+ private enableJsonResponse;
47
+ private onsessioninitialized?;
48
+ private standaloneSseStreamId;
49
+ private streamMapping;
50
+ private requestToStreamMapping;
51
+ private requestResponseMap;
52
+ sessionId?: string;
53
+ onclose?: () => void;
54
+ onerror?: (error: Error) => void;
55
+ onmessage?: (message: JSONRPCMessage) => void;
56
+ constructor(options?: WorkerTransportOptions);
57
+ start(): Promise<void>;
58
+ handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
59
+ private handleGetRequest;
60
+ private handlePostRequest;
61
+ private handleDeleteRequest;
62
+ private handleOptionsRequest;
63
+ private handleUnsupportedRequest;
64
+ private validateSession;
65
+ close(): Promise<void>;
66
+ send(message: JSONRPCMessage): Promise<void>;
67
+ }
68
+ //#endregion
69
+ //#region src/mcp/handler.d.ts
70
+ interface CreateMcpHandlerOptions extends WorkerTransportOptions {
71
+ /**
72
+ * The route path that this MCP handler should respond to.
73
+ * If specified, the handler will only process requests that match this route.
74
+ * @default "/mcp"
75
+ */
76
+ route?: string;
77
+ }
78
+ type OAuthExecutionContext = ExecutionContext & {
79
+ props?: Record<string, unknown>;
80
+ };
81
+ declare function experimental_createMcpHandler(
82
+ server: McpServer | Server$1,
83
+ options?: CreateMcpHandlerOptions
84
+ ): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
85
+ //#endregion
86
+ //#region src/mcp/auth-context.d.ts
87
+ interface McpAuthContext {
88
+ props: Record<string, unknown>;
89
+ }
90
+ declare function getMcpAuthContext(): McpAuthContext | undefined;
91
+ //#endregion
92
+ //#region src/mcp/index.d.ts
93
+ declare abstract class McpAgent<
94
+ Env = unknown,
95
+ State = unknown,
96
+ Props extends Record<string, unknown> = Record<string, unknown>
97
+ > extends Agent<Env, State, Props> {
98
+ private _transport?;
99
+ props?: Props;
100
+ abstract server: MaybePromise<McpServer | Server$1>;
101
+ abstract init(): Promise<void>;
102
+ setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
103
+ getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
104
+ /** Read the transport type for this agent.
105
+ * This relies on the naming scheme being `sse:${sessionId}`
106
+ * or `streamable-http:${sessionId}`.
107
+ */
108
+ getTransportType(): BaseTransportType;
109
+ /** Read the sessionId for this agent.
110
+ * This relies on the naming scheme being `sse:${sessionId}`
111
+ * or `streamable-http:${sessionId}`.
112
+ */
113
+ getSessionId(): string;
114
+ /** Get the unique WebSocket. SSE transport only. */
115
+ private getWebSocket;
116
+ /** Returns a new transport matching the type of the Agent. */
117
+ private initTransport;
118
+ /** Update and store the props */
119
+ updateProps(props?: Props): Promise<void>;
120
+ reinitializeServer(): Promise<void>;
121
+ /** Sets up the MCP transport and server every time the Agent is started.*/
122
+ onStart(props?: Props): Promise<void>;
123
+ /** Validates new WebSocket connections. */
124
+ onConnect(
125
+ conn: Connection$1,
126
+ { request: req }: ConnectionContext
127
+ ): Promise<void>;
128
+ /** Handles MCP Messages for the legacy SSE transport. */
129
+ onSSEMcpMessage(
130
+ _sessionId: string,
131
+ messageBody: unknown
132
+ ): Promise<Error | null>;
133
+ /** Elicit user input with a message and schema */
134
+ elicitInput(params: {
135
+ message: string;
136
+ requestedSchema: unknown;
137
+ }): Promise<ElicitResult>;
138
+ /** Wait for elicitation response through storage polling */
139
+ private _waitForElicitationResponse;
140
+ /** Handle elicitation responses */
141
+ private _handleElicitationResponse;
142
+ /** Return a handler for the given path for this MCP.
143
+ * Defaults to Streamable HTTP transport.
144
+ */
145
+ static serve(
146
+ path: string,
147
+ { binding, corsOptions, transport }?: ServeOptions
148
+ ): {
149
+ fetch<Env>(
150
+ this: void,
151
+ request: Request,
152
+ env: Env,
153
+ ctx: ExecutionContext
154
+ ): Promise<Response>;
155
+ };
156
+ /**
157
+ * Legacy api
158
+ **/
159
+ static mount(
160
+ path: string,
161
+ opts?: Omit<ServeOptions, "transport">
162
+ ): {
163
+ fetch<Env>(
164
+ this: void,
165
+ request: Request,
166
+ env: Env,
167
+ ctx: ExecutionContext
168
+ ): Promise<Response>;
169
+ };
170
+ static serveSSE(
171
+ path: string,
172
+ opts?: Omit<ServeOptions, "transport">
173
+ ): {
174
+ fetch<Env>(
175
+ this: void,
176
+ request: Request,
177
+ env: Env,
178
+ ctx: ExecutionContext
179
+ ): Promise<Response>;
180
+ };
181
+ }
182
+ //#endregion
183
+ //#region src/index.d.ts
184
+ /**
185
+ * RPC request message from client
186
+ */
187
+ type RPCRequest = {
188
+ type: "rpc";
189
+ id: string;
190
+ method: string;
191
+ args: unknown[];
192
+ };
193
+ /**
194
+ * State update message from client
195
+ */
196
+ type StateUpdateMessage = {
197
+ type: MessageType.CF_AGENT_STATE;
198
+ state: unknown;
199
+ };
200
+ /**
201
+ * RPC response message to client
202
+ */
203
+ type RPCResponse = {
204
+ type: MessageType.RPC;
205
+ id: string;
206
+ } & (
207
+ | {
208
+ success: true;
209
+ result: unknown;
210
+ done?: false;
211
+ }
212
+ | {
213
+ success: true;
214
+ result: unknown;
215
+ done: true;
216
+ }
217
+ | {
218
+ success: false;
219
+ error: string;
220
+ }
221
+ );
222
+ /**
223
+ * Metadata for a callable method
224
+ */
225
+ type CallableMetadata = {
226
+ /** Optional description of what the method does */
227
+ description?: string;
228
+ /** Whether the method supports streaming responses */
229
+ streaming?: boolean;
230
+ };
231
+ /**
232
+ * Decorator that marks a method as callable by clients
233
+ * @param metadata Optional metadata about the callable method
234
+ */
235
+ declare function callable(
236
+ metadata?: CallableMetadata
237
+ ): <This, Args extends unknown[], Return>(
238
+ target: (this: This, ...args: Args) => Return,
239
+ context: ClassMethodDecoratorContext
240
+ ) => (this: This, ...args: Args) => Return;
241
+ /**
242
+ * Decorator that marks a method as callable by clients
243
+ * @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
244
+ * @param metadata Optional metadata about the callable method
245
+ */
246
+ declare const unstable_callable: (metadata?: CallableMetadata) => void;
247
+ type QueueItem<T = string> = {
248
+ id: string;
249
+ payload: T;
250
+ callback: keyof Agent<unknown>;
251
+ created_at: number;
252
+ };
253
+ /**
254
+ * Represents a scheduled task within an Agent
255
+ * @template T Type of the payload data
256
+ */
257
+ type Schedule<T = string> = {
258
+ /** Unique identifier for the schedule */
259
+ id: string;
260
+ /** Name of the method to be called */
261
+ callback: string;
262
+ /** Data to be passed to the callback */
263
+ payload: T;
264
+ } & (
265
+ | {
266
+ /** Type of schedule for one-time execution at a specific time */
267
+ type: "scheduled";
268
+ /** Timestamp when the task should execute */
269
+ time: number;
270
+ }
271
+ | {
272
+ /** Type of schedule for delayed execution */
273
+ type: "delayed";
274
+ /** Timestamp when the task should execute */
275
+ time: number;
276
+ /** Number of seconds to delay execution */
277
+ delayInSeconds: number;
278
+ }
279
+ | {
280
+ /** Type of schedule for recurring execution based on cron expression */
281
+ type: "cron";
282
+ /** Timestamp for the next execution */
283
+ time: number;
284
+ /** Cron expression defining the schedule */
285
+ cron: string;
286
+ }
287
+ );
288
+ /**
289
+ * MCP Server state update message from server -> Client
290
+ */
291
+ type MCPServerMessage = {
292
+ type: MessageType.CF_AGENT_MCP_SERVERS;
293
+ mcp: MCPServersState;
294
+ };
295
+ type MCPServersState = {
296
+ servers: {
297
+ [id: string]: MCPServer;
298
+ };
299
+ tools: Tool[];
300
+ prompts: Prompt[];
301
+ resources: Resource[];
302
+ };
303
+ type MCPServer = {
304
+ name: string;
305
+ server_url: string;
306
+ auth_url: string | null;
307
+ state: MCPConnectionState;
308
+ instructions: string | null;
309
+ capabilities: ServerCapabilities | null;
310
+ };
311
+ declare function getCurrentAgent<
312
+ T extends Agent<unknown, unknown> = Agent<unknown, unknown>
313
+ >(): {
314
+ agent: T | undefined;
315
+ connection: Connection | undefined;
316
+ request: Request | undefined;
317
+ email: AgentEmail | undefined;
318
+ };
319
+ /**
320
+ * Base class for creating Agent implementations
321
+ * @template Env Environment type containing bindings
322
+ * @template State State type to store within the Agent
323
+ */
324
+ declare class Agent<
325
+ Env = typeof env,
326
+ State = unknown,
327
+ Props extends Record<string, unknown> = Record<string, unknown>
328
+ > extends Server<Env, Props> {
329
+ private _state;
330
+ private _disposables;
331
+ private _ParentClass;
332
+ readonly mcp: MCPClientManager;
333
+ /**
334
+ * Initial state for the Agent
335
+ * Override to provide default state values
336
+ */
337
+ initialState: State;
338
+ /**
339
+ * Current state of the Agent
340
+ */
341
+ get state(): State;
342
+ /**
343
+ * Agent configuration options
344
+ */
345
+ static options: {
346
+ /** Whether the Agent should hibernate when inactive */
347
+ hibernate: boolean;
348
+ };
349
+ /**
350
+ * The observability implementation to use for the Agent
351
+ */
352
+ observability?: Observability;
353
+ /**
354
+ * Execute SQL queries against the Agent's database
355
+ * @template T Type of the returned rows
356
+ * @param strings SQL query template strings
357
+ * @param values Values to be inserted into the query
358
+ * @returns Array of query results
359
+ */
360
+ sql<T = Record<string, string | number | boolean | null>>(
361
+ strings: TemplateStringsArray,
362
+ ...values: (string | number | boolean | null)[]
363
+ ): T[];
364
+ constructor(ctx: AgentContext, env: Env);
365
+ private _setStateInternal;
366
+ /**
367
+ * Update the Agent's state
368
+ * @param state New state to set
369
+ */
370
+ setState(state: State): void;
371
+ /**
372
+ * Called when the Agent's state is updated
373
+ * @param state Updated state
374
+ * @param source Source of the state update ("server" or a client connection)
375
+ */
376
+ onStateUpdate(state: State | undefined, source: Connection | "server"): void;
377
+ /**
378
+ * Called when the Agent receives an email via routeAgentEmail()
379
+ * Override this method to handle incoming emails
380
+ * @param email Email message to process
381
+ */
382
+ _onEmail(email: AgentEmail): Promise<void>;
383
+ /**
384
+ * Reply to an email
385
+ * @param email The email to reply to
386
+ * @param options Options for the reply
387
+ * @returns void
388
+ */
389
+ replyToEmail(
390
+ email: AgentEmail,
391
+ options: {
392
+ fromName: string;
393
+ subject?: string | undefined;
394
+ body: string;
395
+ contentType?: string;
396
+ headers?: Record<string, string>;
397
+ }
398
+ ): Promise<void>;
399
+ private _tryCatch;
400
+ /**
401
+ * Automatically wrap custom methods with agent context
402
+ * This ensures getCurrentAgent() works in all custom methods without decorators
403
+ */
404
+ private _autoWrapCustomMethods;
405
+ onError(connection: Connection, error: unknown): void | Promise<void>;
406
+ onError(error: unknown): void | Promise<void>;
407
+ /**
408
+ * Render content (not implemented in base class)
409
+ */
410
+ render(): void;
411
+ /**
412
+ * Queue a task to be executed in the future
413
+ * @param payload Payload to pass to the callback
414
+ * @param callback Name of the method to call
415
+ * @returns The ID of the queued task
416
+ */
417
+ queue<T = unknown>(callback: keyof this, payload: T): Promise<string>;
418
+ private _flushingQueue;
419
+ private _flushQueue;
420
+ /**
421
+ * Dequeue a task by ID
422
+ * @param id ID of the task to dequeue
423
+ */
424
+ dequeue(id: string): Promise<void>;
425
+ /**
426
+ * Dequeue all tasks
427
+ */
428
+ dequeueAll(): Promise<void>;
429
+ /**
430
+ * Dequeue all tasks by callback
431
+ * @param callback Name of the callback to dequeue
432
+ */
433
+ dequeueAllByCallback(callback: string): Promise<void>;
434
+ /**
435
+ * Get a queued task by ID
436
+ * @param id ID of the task to get
437
+ * @returns The task or undefined if not found
438
+ */
439
+ getQueue(id: string): Promise<QueueItem<string> | undefined>;
440
+ /**
441
+ * Get all queues by key and value
442
+ * @param key Key to filter by
443
+ * @param value Value to filter by
444
+ * @returns Array of matching QueueItem objects
445
+ */
446
+ getQueues(key: string, value: string): Promise<QueueItem<string>[]>;
447
+ /**
448
+ * Schedule a task to be executed in the future
449
+ * @template T Type of the payload data
450
+ * @param when When to execute the task (Date, seconds delay, or cron expression)
451
+ * @param callback Name of the method to call
452
+ * @param payload Data to pass to the callback
453
+ * @returns Schedule object representing the scheduled task
454
+ */
455
+ schedule<T = string>(
456
+ when: Date | string | number,
457
+ callback: keyof this,
458
+ payload?: T
459
+ ): Promise<Schedule<T>>;
460
+ /**
461
+ * Get a scheduled task by ID
462
+ * @template T Type of the payload data
463
+ * @param id ID of the scheduled task
464
+ * @returns The Schedule object or undefined if not found
465
+ */
466
+ getSchedule<T = string>(id: string): Promise<Schedule<T> | undefined>;
467
+ /**
468
+ * Get scheduled tasks matching the given criteria
469
+ * @template T Type of the payload data
470
+ * @param criteria Criteria to filter schedules
471
+ * @returns Array of matching Schedule objects
472
+ */
473
+ getSchedules<T = string>(criteria?: {
474
+ id?: string;
475
+ type?: "scheduled" | "delayed" | "cron";
476
+ timeRange?: {
477
+ start?: Date;
478
+ end?: Date;
479
+ };
480
+ }): Schedule<T>[];
481
+ /**
482
+ * Cancel a scheduled task
483
+ * @param id ID of the task to cancel
484
+ * @returns true if the task was cancelled, false otherwise
485
+ */
486
+ cancelSchedule(id: string): Promise<boolean>;
487
+ private _scheduleNextAlarm;
488
+ /**
489
+ * Method called when an alarm fires.
490
+ * Executes any scheduled tasks that are due.
491
+ *
492
+ * @remarks
493
+ * To schedule a task, please use the `this.schedule` method instead.
494
+ * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
495
+ */
496
+ readonly alarm: () => Promise<void>;
497
+ /**
498
+ * Destroy the Agent, removing all state and scheduled tasks
499
+ */
500
+ destroy(): Promise<void>;
501
+ /**
502
+ * Get all methods marked as callable on this Agent
503
+ * @returns A map of method names to their metadata
504
+ */
505
+ private _isCallable;
506
+ /**
507
+ * Connect to a new MCP Server
508
+ *
509
+ * @param serverName Name of the MCP server
510
+ * @param url MCP Server SSE URL
511
+ * @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
512
+ * @param agentsPrefix agents routing prefix if not using `agents`
513
+ * @param options MCP client and transport options
514
+ * @returns authUrl
515
+ */
516
+ addMcpServer(
517
+ serverName: string,
518
+ url: string,
519
+ callbackHost?: string,
520
+ agentsPrefix?: string,
521
+ options?: {
522
+ client?: ConstructorParameters<typeof Client>[1];
523
+ transport?: {
524
+ headers?: HeadersInit;
525
+ type?: TransportType;
526
+ };
527
+ }
528
+ ): Promise<{
529
+ id: string;
530
+ authUrl: string | undefined;
531
+ }>;
532
+ /**
533
+ * Handle potential OAuth callback requests after DO hibernation.
534
+ * Detects OAuth callbacks, restores state from database, and processes the callback.
535
+ * Returns a Response if this was an OAuth callback, otherwise returns undefined.
536
+ */
537
+ private _handlePotentialOAuthCallback;
538
+ /**
539
+ * Process an OAuth callback request (assumes state is already restored)
540
+ */
541
+ private _processOAuthCallback;
542
+ private _connectToMcpServerInternal;
543
+ removeMcpServer(id: string): Promise<void>;
544
+ getMcpServers(): MCPServersState;
545
+ private broadcastMcpServers;
546
+ /**
547
+ * Handle OAuth callback response using MCPClientManager configuration
548
+ * @param result OAuth callback result
549
+ * @param request The original request (needed for base URL)
550
+ * @returns Response for the OAuth callback
551
+ */
552
+ private handleOAuthCallbackResponse;
553
+ }
554
+ /**
555
+ * Namespace for creating Agent instances
556
+ * @template Agentic Type of the Agent class
557
+ */
558
+ type AgentNamespace<Agentic extends Agent<unknown>> =
559
+ DurableObjectNamespace<Agentic>;
560
+ /**
561
+ * Agent's durable context
562
+ */
563
+ type AgentContext = DurableObjectState;
564
+ /**
565
+ * Configuration options for Agent routing
566
+ */
567
+ type AgentOptions<Env> = PartyServerOptions<Env> & {
568
+ /**
569
+ * Whether to enable CORS for the Agent
570
+ */
571
+ cors?: boolean | HeadersInit | undefined;
572
+ };
573
+ /**
574
+ * Route a request to the appropriate Agent
575
+ * @param request Request to route
576
+ * @param env Environment containing Agent bindings
577
+ * @param options Routing options
578
+ * @returns Response from the Agent or undefined if no route matched
579
+ */
580
+ declare function routeAgentRequest<Env>(
581
+ request: Request,
582
+ env: Env,
583
+ options?: AgentOptions<Env>
584
+ ): Promise<Response | null>;
585
+ type EmailResolver<Env> = (
586
+ email: ForwardableEmailMessage,
587
+ env: Env
588
+ ) => Promise<{
589
+ agentName: string;
590
+ agentId: string;
591
+ } | null>;
592
+ /**
593
+ * Create a resolver that uses the message-id header to determine the agent to route the email to
594
+ * @returns A function that resolves the agent to route the email to
595
+ */
596
+ declare function createHeaderBasedEmailResolver<Env>(): EmailResolver<Env>;
597
+ /**
598
+ * Create a resolver that uses the email address to determine the agent to route the email to
599
+ * @param defaultAgentName The default agent name to use if the email address does not contain a sub-address
600
+ * @returns A function that resolves the agent to route the email to
601
+ */
602
+ declare function createAddressBasedEmailResolver<Env>(
603
+ defaultAgentName: string
604
+ ): EmailResolver<Env>;
605
+ /**
606
+ * Create a resolver that uses the agentName and agentId to determine the agent to route the email to
607
+ * @param agentName The name of the agent to route the email to
608
+ * @param agentId The id of the agent to route the email to
609
+ * @returns A function that resolves the agent to route the email to
610
+ */
611
+ declare function createCatchAllEmailResolver<Env>(
612
+ agentName: string,
613
+ agentId: string
614
+ ): EmailResolver<Env>;
615
+ type EmailRoutingOptions<Env> = AgentOptions<Env> & {
616
+ resolver: EmailResolver<Env>;
617
+ };
618
+ /**
619
+ * Route an email to the appropriate Agent
620
+ * @param email The email to route
621
+ * @param env The environment containing the Agent bindings
622
+ * @param options The options for routing the email
623
+ * @returns A promise that resolves when the email has been routed
624
+ */
625
+ declare function routeAgentEmail<Env>(
626
+ email: ForwardableEmailMessage,
627
+ env: Env,
628
+ options: EmailRoutingOptions<Env>
629
+ ): Promise<void>;
630
+ type AgentEmail = {
631
+ from: string;
632
+ to: string;
633
+ getRaw: () => Promise<Uint8Array>;
634
+ headers: Headers;
635
+ rawSize: number;
636
+ setReject: (reason: string) => void;
637
+ forward: (rcptTo: string, headers?: Headers) => Promise<void>;
638
+ reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
639
+ };
640
+ type EmailSendOptions = {
641
+ to: string;
642
+ subject: string;
643
+ body: string;
644
+ contentType?: string;
645
+ headers?: Record<string, string>;
646
+ includeRoutingHeaders?: boolean;
647
+ agentName?: string;
648
+ agentId?: string;
649
+ domain?: string;
650
+ };
651
+ /**
652
+ * Get or create an Agent by name
653
+ * @template Env Environment type containing bindings
654
+ * @template T Type of the Agent class
655
+ * @param namespace Agent namespace
656
+ * @param name Name of the Agent instance
657
+ * @param options Options for Agent creation
658
+ * @returns Promise resolving to an Agent instance stub
659
+ */
660
+ declare function getAgentByName<
661
+ Env,
662
+ T extends Agent<Env>,
663
+ Props extends Record<string, unknown> = Record<string, unknown>
664
+ >(
665
+ namespace: AgentNamespace<T>,
666
+ name: string,
667
+ options?: {
668
+ jurisdiction?: DurableObjectJurisdiction;
669
+ locationHint?: DurableObjectLocationHint;
670
+ props?: Props;
671
+ }
672
+ ): Promise<DurableObjectStub<T>>;
673
+ /**
674
+ * A wrapper for streaming responses in callable methods
675
+ */
676
+ declare class StreamingResponse {
677
+ private _connection;
678
+ private _id;
679
+ private _closed;
680
+ constructor(connection: Connection, id: string);
681
+ /**
682
+ * Send a chunk of data to the client
683
+ * @param chunk The data to send
684
+ */
685
+ send(chunk: unknown): void;
686
+ /**
687
+ * End the stream and send the final chunk (if any)
688
+ * @param finalChunk Optional final chunk of data to send
689
+ */
690
+ end(finalChunk?: unknown): void;
691
+ }
692
+ //#endregion
693
+ export {
694
+ Agent,
695
+ AgentContext,
696
+ AgentEmail,
697
+ AgentNamespace,
698
+ AgentOptions,
699
+ CallableMetadata,
700
+ type Connection$1 as Connection,
701
+ type ConnectionContext,
702
+ type CreateMcpHandlerOptions,
703
+ type ElicitRequest$1 as ElicitRequest,
704
+ ElicitRequestSchema$1 as ElicitRequestSchema,
705
+ type ElicitResult$1 as ElicitResult,
706
+ EmailResolver,
707
+ EmailRoutingOptions,
708
+ EmailSendOptions,
709
+ MCPServer,
710
+ MCPServerMessage,
711
+ MCPServersState,
712
+ McpAgent,
713
+ type McpAuthContext,
714
+ type OAuthExecutionContext,
715
+ QueueItem,
716
+ RPCRequest,
717
+ RPCResponse,
718
+ Schedule,
719
+ StateUpdateMessage,
720
+ StreamingResponse,
721
+ type WSMessage,
722
+ WorkerTransport,
723
+ type WorkerTransportOptions,
724
+ callable,
725
+ createAddressBasedEmailResolver,
726
+ createCatchAllEmailResolver,
727
+ createHeaderBasedEmailResolver,
728
+ experimental_createMcpHandler,
729
+ getAgentByName,
730
+ getCurrentAgent,
731
+ getMcpAuthContext,
732
+ routeAgentEmail,
733
+ routeAgentRequest,
734
+ unstable_callable
735
+ };
736
+ //# sourceMappingURL=index-DWJSBMbz.d.ts.map