agents 0.3.0 → 0.3.2

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 (67) hide show
  1. package/README.md +12 -326
  2. package/dist/ai-chat-agent.d.ts +1 -324
  3. package/dist/ai-chat-agent.js +3 -1147
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration.d.ts +1 -155
  6. package/dist/ai-chat-v5-migration.js +4 -151
  7. package/dist/ai-chat-v5-migration.js.map +1 -1
  8. package/dist/ai-react.d.ts +1 -286
  9. package/dist/ai-react.js +3 -632
  10. package/dist/ai-react.js.map +1 -1
  11. package/dist/ai-types.d.ts +7 -6
  12. package/dist/ai-types.js +12 -2
  13. package/dist/ai-types.js.map +1 -0
  14. package/dist/{client-QZa2Rq0l.js → client-C7SOlYfK.js} +2 -2
  15. package/dist/{client-QZa2Rq0l.js.map → client-C7SOlYfK.js.map} +1 -1
  16. package/dist/{client-DjTPRM8-.js → client-CEO0P7vN.js} +2 -2
  17. package/dist/client-CEO0P7vN.js.map +1 -0
  18. package/dist/{client-DFotUKH_.d.ts → client-CbcnyqCo.d.ts} +10 -10
  19. package/dist/client.d.ts +92 -7
  20. package/dist/client.js +1 -1
  21. package/dist/codemode/ai.d.ts +1 -27
  22. package/dist/codemode/ai.js +3 -146
  23. package/dist/codemode/ai.js.map +1 -1
  24. package/dist/{do-oauth-client-provider--To1Tsjj.d.ts → do-oauth-client-provider-BH9zFtSy.d.ts} +1 -1
  25. package/dist/{do-oauth-client-provider-B1fVIshX.js → do-oauth-client-provider-BfPFgQU0.js} +1 -1
  26. package/dist/{do-oauth-client-provider-B1fVIshX.js.map → do-oauth-client-provider-BfPFgQU0.js.map} +1 -1
  27. package/dist/{index-DLuxm_9W.d.ts → index-B7Ny-XfU.d.ts} +2 -2
  28. package/dist/index.d.ts +553 -38
  29. package/dist/index.js +5 -5
  30. package/dist/{context-DcbQ8o7k.d.ts → internal_context-neg89p5n.d.ts} +2 -2
  31. package/dist/{context-BkKbAa1R.js → internal_context-oN047Id3.js} +2 -2
  32. package/dist/internal_context-oN047Id3.js.map +1 -0
  33. package/dist/{context.d.ts → internal_context.d.ts} +1 -1
  34. package/dist/internal_context.js +3 -0
  35. package/dist/mcp/client.d.ts +1 -1
  36. package/dist/mcp/client.js +2 -2
  37. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  38. package/dist/mcp/do-oauth-client-provider.js +1 -1
  39. package/dist/mcp/index.d.ts +3 -4
  40. package/dist/mcp/index.js +6 -6
  41. package/dist/mcp/index.js.map +1 -1
  42. package/dist/mcp/x402.d.ts +1 -1
  43. package/dist/{mcp-CPSfGUgd.d.ts → mcp-AK39tq6H.d.ts} +1 -1
  44. package/dist/observability/index.d.ts +1 -1
  45. package/dist/observability/index.js +5 -5
  46. package/dist/react.d.ts +14 -6
  47. package/dist/react.js +16 -8
  48. package/dist/react.js.map +1 -1
  49. package/dist/serializable.d.ts +33 -6
  50. package/dist/{src-BZDh910Z.js → src-CXf5SiV4.js} +6 -6
  51. package/dist/src-CXf5SiV4.js.map +1 -0
  52. package/dist/types-4b5tlB0u.js +15 -0
  53. package/dist/types-4b5tlB0u.js.map +1 -0
  54. package/dist/types-C5vR2Gzv.d.ts +13 -0
  55. package/dist/types.d.ts +2 -0
  56. package/dist/types.js +3 -0
  57. package/package.json +33 -25
  58. package/dist/ai-types-0OnT3FHg.d.ts +0 -127
  59. package/dist/ai-types-DEtF_8Km.js +0 -28
  60. package/dist/ai-types-DEtF_8Km.js.map +0 -1
  61. package/dist/client-CdM5I962.d.ts +0 -104
  62. package/dist/client-DjTPRM8-.js.map +0 -1
  63. package/dist/context-BkKbAa1R.js.map +0 -1
  64. package/dist/context.js +0 -3
  65. package/dist/index-CT2tCrLr.d.ts +0 -577
  66. package/dist/serializable-Crsj26mx.d.ts +0 -39
  67. package/dist/src-BZDh910Z.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,46 +1,560 @@
1
- import { n as AgentEmail } from "./context-DcbQ8o7k.js";
2
- import { h as TransportType } from "./client-DFotUKH_.js";
3
- import "./ai-types-0OnT3FHg.js";
1
+ import { n as AgentEmail } from "./internal_context-neg89p5n.js";
4
2
  import {
5
- C as createCatchAllEmailResolver,
6
- D as routeAgentEmail,
7
- E as getCurrentAgent,
8
- O as routeAgentRequest,
9
- S as createAddressBasedEmailResolver,
10
- T as getAgentByName,
11
- _ as Schedule,
12
- a as CallableMetadata,
13
- b as WSMessage,
14
- c as EmailResolver,
15
- d as MCPServer,
16
- f as MCPServerMessage,
17
- g as RPCResponse,
18
- h as RPCRequest,
19
- i as AgentOptions,
20
- k as unstable_callable,
21
- l as EmailRoutingOptions,
22
- m as QueueItem,
23
- n as AgentContext,
24
- o as Connection,
25
- p as MCPServersState,
26
- r as AgentNamespace,
27
- s as ConnectionContext,
28
- t as Agent,
29
- u as EmailSendOptions,
30
- v as StateUpdateMessage,
31
- w as createHeaderBasedEmailResolver,
32
- x as callable,
33
- y as StreamingResponse
34
- } from "./index-CT2tCrLr.js";
3
+ h as TransportType,
4
+ t as MCPClientManager,
5
+ u as MCPConnectionState
6
+ } from "./client-CbcnyqCo.js";
7
+ import { t as Observability } from "./index-B7Ny-XfU.js";
8
+ import { t as MessageType } from "./types-C5vR2Gzv.js";
9
+ import {
10
+ Connection,
11
+ Connection as Connection$1,
12
+ ConnectionContext,
13
+ PartyServerOptions,
14
+ Server,
15
+ WSMessage
16
+ } from "partyserver";
17
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
18
+ import {
19
+ Prompt,
20
+ Resource,
21
+ ServerCapabilities,
22
+ Tool
23
+ } from "@modelcontextprotocol/sdk/types.js";
24
+
25
+ //#region src/index.d.ts
26
+
27
+ /**
28
+ * RPC request message from client
29
+ */
30
+ type RPCRequest = {
31
+ type: "rpc";
32
+ id: string;
33
+ method: string;
34
+ args: unknown[];
35
+ };
36
+ /**
37
+ * State update message from client
38
+ */
39
+ type StateUpdateMessage = {
40
+ type: MessageType.CF_AGENT_STATE;
41
+ state: unknown;
42
+ };
43
+ /**
44
+ * RPC response message to client
45
+ */
46
+ type RPCResponse = {
47
+ type: MessageType.RPC;
48
+ id: string;
49
+ } & (
50
+ | {
51
+ success: true;
52
+ result: unknown;
53
+ done?: false;
54
+ }
55
+ | {
56
+ success: true;
57
+ result: unknown;
58
+ done: true;
59
+ }
60
+ | {
61
+ success: false;
62
+ error: string;
63
+ }
64
+ );
65
+ /**
66
+ * Metadata for a callable method
67
+ */
68
+ type CallableMetadata = {
69
+ /** Optional description of what the method does */
70
+ description?: string;
71
+ /** Whether the method supports streaming responses */
72
+ streaming?: boolean;
73
+ };
74
+ /**
75
+ * Decorator that marks a method as callable by clients
76
+ * @param metadata Optional metadata about the callable method
77
+ */
78
+ declare function callable(
79
+ metadata?: CallableMetadata
80
+ ): <This, Args extends unknown[], Return>(
81
+ target: (this: This, ...args: Args) => Return,
82
+ context: ClassMethodDecoratorContext
83
+ ) => (this: This, ...args: Args) => Return;
84
+ /**
85
+ * Decorator that marks a method as callable by clients
86
+ * @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
87
+ * @param metadata Optional metadata about the callable method
88
+ */
89
+ declare const unstable_callable: (metadata?: CallableMetadata) => void;
90
+ type QueueItem<T = string> = {
91
+ id: string;
92
+ payload: T;
93
+ callback: keyof Agent<Cloudflare.Env>;
94
+ created_at: number;
95
+ };
96
+ /**
97
+ * Represents a scheduled task within an Agent
98
+ * @template T Type of the payload data
99
+ */
100
+ type Schedule<T = string> = {
101
+ /** Unique identifier for the schedule */
102
+ id: string;
103
+ /** Name of the method to be called */
104
+ callback: string;
105
+ /** Data to be passed to the callback */
106
+ payload: T;
107
+ } & (
108
+ | {
109
+ /** Type of schedule for one-time execution at a specific time */
110
+ type: "scheduled";
111
+ /** Timestamp when the task should execute */
112
+ time: number;
113
+ }
114
+ | {
115
+ /** Type of schedule for delayed execution */
116
+ type: "delayed";
117
+ /** Timestamp when the task should execute */
118
+ time: number;
119
+ /** Number of seconds to delay execution */
120
+ delayInSeconds: number;
121
+ }
122
+ | {
123
+ /** Type of schedule for recurring execution based on cron expression */
124
+ type: "cron";
125
+ /** Timestamp for the next execution */
126
+ time: number;
127
+ /** Cron expression defining the schedule */
128
+ cron: string;
129
+ }
130
+ );
131
+ /**
132
+ * MCP Server state update message from server -> Client
133
+ */
134
+ type MCPServerMessage = {
135
+ type: MessageType.CF_AGENT_MCP_SERVERS;
136
+ mcp: MCPServersState;
137
+ };
138
+ type MCPServersState = {
139
+ servers: {
140
+ [id: string]: MCPServer;
141
+ };
142
+ tools: (Tool & {
143
+ serverId: string;
144
+ })[];
145
+ prompts: (Prompt & {
146
+ serverId: string;
147
+ })[];
148
+ resources: (Resource & {
149
+ serverId: string;
150
+ })[];
151
+ };
152
+ type MCPServer = {
153
+ name: string;
154
+ server_url: string;
155
+ auth_url: string | null;
156
+ state: MCPConnectionState;
157
+ instructions: string | null;
158
+ capabilities: ServerCapabilities | null;
159
+ };
160
+ declare function getCurrentAgent<
161
+ T extends Agent<Cloudflare.Env> = Agent<Cloudflare.Env>
162
+ >(): {
163
+ agent: T | undefined;
164
+ connection: Connection$1 | undefined;
165
+ request: Request | undefined;
166
+ email: AgentEmail | undefined;
167
+ };
168
+ /**
169
+ * Base class for creating Agent implementations
170
+ * @template Env Environment type containing bindings
171
+ * @template State State type to store within the Agent
172
+ */
173
+ declare class Agent<
174
+ Env extends Cloudflare.Env = Cloudflare.Env,
175
+ State = unknown,
176
+ Props extends Record<string, unknown> = Record<string, unknown>
177
+ > extends Server<Env, Props> {
178
+ private _state;
179
+ private _disposables;
180
+ private _destroyed;
181
+ private _ParentClass;
182
+ readonly mcp: MCPClientManager;
183
+ /**
184
+ * Initial state for the Agent
185
+ * Override to provide default state values
186
+ */
187
+ initialState: State;
188
+ /**
189
+ * Current state of the Agent
190
+ */
191
+ get state(): State;
192
+ /**
193
+ * Agent configuration options
194
+ */
195
+ static options: {
196
+ /** Whether the Agent should hibernate when inactive */
197
+ hibernate: boolean;
198
+ };
199
+ /**
200
+ * The observability implementation to use for the Agent
201
+ */
202
+ observability?: Observability;
203
+ /**
204
+ * Execute SQL queries against the Agent's database
205
+ * @template T Type of the returned rows
206
+ * @param strings SQL query template strings
207
+ * @param values Values to be inserted into the query
208
+ * @returns Array of query results
209
+ */
210
+ sql<T = Record<string, string | number | boolean | null>>(
211
+ strings: TemplateStringsArray,
212
+ ...values: (string | number | boolean | null)[]
213
+ ): T[];
214
+ constructor(ctx: AgentContext, env: Env);
215
+ private _setStateInternal;
216
+ /**
217
+ * Update the Agent's state
218
+ * @param state New state to set
219
+ */
220
+ setState(state: State): void;
221
+ /**
222
+ * Called when the Agent's state is updated
223
+ * @param state Updated state
224
+ * @param source Source of the state update ("server" or a client connection)
225
+ */
226
+ onStateUpdate(
227
+ state: State | undefined,
228
+ source: Connection$1 | "server"
229
+ ): void;
230
+ /**
231
+ * Called when the Agent receives an email via routeAgentEmail()
232
+ * Override this method to handle incoming emails
233
+ * @param email Email message to process
234
+ */
235
+ _onEmail(email: AgentEmail): Promise<void>;
236
+ /**
237
+ * Reply to an email
238
+ * @param email The email to reply to
239
+ * @param options Options for the reply
240
+ * @returns void
241
+ */
242
+ replyToEmail(
243
+ email: AgentEmail,
244
+ options: {
245
+ fromName: string;
246
+ subject?: string | undefined;
247
+ body: string;
248
+ contentType?: string;
249
+ headers?: Record<string, string>;
250
+ }
251
+ ): Promise<void>;
252
+ private _tryCatch;
253
+ /**
254
+ * Automatically wrap custom methods with agent context
255
+ * This ensures getCurrentAgent() works in all custom methods without decorators
256
+ */
257
+ private _autoWrapCustomMethods;
258
+ onError(connection: Connection$1, error: unknown): void | Promise<void>;
259
+ onError(error: unknown): void | Promise<void>;
260
+ /**
261
+ * Render content (not implemented in base class)
262
+ */
263
+ render(): void;
264
+ /**
265
+ * Queue a task to be executed in the future
266
+ * @param payload Payload to pass to the callback
267
+ * @param callback Name of the method to call
268
+ * @returns The ID of the queued task
269
+ */
270
+ queue<T = unknown>(callback: keyof this, payload: T): Promise<string>;
271
+ private _flushingQueue;
272
+ private _flushQueue;
273
+ /**
274
+ * Dequeue a task by ID
275
+ * @param id ID of the task to dequeue
276
+ */
277
+ dequeue(id: string): Promise<void>;
278
+ /**
279
+ * Dequeue all tasks
280
+ */
281
+ dequeueAll(): Promise<void>;
282
+ /**
283
+ * Dequeue all tasks by callback
284
+ * @param callback Name of the callback to dequeue
285
+ */
286
+ dequeueAllByCallback(callback: string): Promise<void>;
287
+ /**
288
+ * Get a queued task by ID
289
+ * @param id ID of the task to get
290
+ * @returns The task or undefined if not found
291
+ */
292
+ getQueue(id: string): Promise<QueueItem<string> | undefined>;
293
+ /**
294
+ * Get all queues by key and value
295
+ * @param key Key to filter by
296
+ * @param value Value to filter by
297
+ * @returns Array of matching QueueItem objects
298
+ */
299
+ getQueues(key: string, value: string): Promise<QueueItem<string>[]>;
300
+ /**
301
+ * Schedule a task to be executed in the future
302
+ * @template T Type of the payload data
303
+ * @param when When to execute the task (Date, seconds delay, or cron expression)
304
+ * @param callback Name of the method to call
305
+ * @param payload Data to pass to the callback
306
+ * @returns Schedule object representing the scheduled task
307
+ */
308
+ schedule<T = string>(
309
+ when: Date | string | number,
310
+ callback: keyof this,
311
+ payload?: T
312
+ ): Promise<Schedule<T>>;
313
+ /**
314
+ * Get a scheduled task by ID
315
+ * @template T Type of the payload data
316
+ * @param id ID of the scheduled task
317
+ * @returns The Schedule object or undefined if not found
318
+ */
319
+ getSchedule<T = string>(id: string): Promise<Schedule<T> | undefined>;
320
+ /**
321
+ * Get scheduled tasks matching the given criteria
322
+ * @template T Type of the payload data
323
+ * @param criteria Criteria to filter schedules
324
+ * @returns Array of matching Schedule objects
325
+ */
326
+ getSchedules<T = string>(criteria?: {
327
+ id?: string;
328
+ type?: "scheduled" | "delayed" | "cron";
329
+ timeRange?: {
330
+ start?: Date;
331
+ end?: Date;
332
+ };
333
+ }): Schedule<T>[];
334
+ /**
335
+ * Cancel a scheduled task
336
+ * @param id ID of the task to cancel
337
+ * @returns true if the task was cancelled, false if the task was not found
338
+ */
339
+ cancelSchedule(id: string): Promise<boolean>;
340
+ private _scheduleNextAlarm;
341
+ /**
342
+ * Method called when an alarm fires.
343
+ * Executes any scheduled tasks that are due.
344
+ *
345
+ * @remarks
346
+ * To schedule a task, please use the `this.schedule` method instead.
347
+ * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
348
+ */
349
+ readonly alarm: () => Promise<void>;
350
+ /**
351
+ * Destroy the Agent, removing all state and scheduled tasks
352
+ */
353
+ destroy(): Promise<void>;
354
+ /**
355
+ * Get all methods marked as callable on this Agent
356
+ * @returns A map of method names to their metadata
357
+ */
358
+ private _isCallable;
359
+ /**
360
+ * Connect to a new MCP Server
361
+ *
362
+ * @param serverName Name of the MCP server
363
+ * @param url MCP Server SSE URL
364
+ * @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
365
+ * @param agentsPrefix agents routing prefix if not using `agents`
366
+ * @param options MCP client and transport options
367
+ * @returns Server id and state - either "authenticating" with authUrl, or "ready"
368
+ * @throws If connection or discovery fails
369
+ */
370
+ addMcpServer(
371
+ serverName: string,
372
+ url: string,
373
+ callbackHost?: string,
374
+ agentsPrefix?: string,
375
+ options?: {
376
+ client?: ConstructorParameters<typeof Client>[1];
377
+ transport?: {
378
+ headers?: HeadersInit;
379
+ type?: TransportType;
380
+ };
381
+ }
382
+ ): Promise<
383
+ | {
384
+ id: string;
385
+ state: typeof MCPConnectionState.AUTHENTICATING;
386
+ authUrl: string;
387
+ }
388
+ | {
389
+ id: string;
390
+ state: typeof MCPConnectionState.READY;
391
+ authUrl?: undefined;
392
+ }
393
+ >;
394
+ removeMcpServer(id: string): Promise<void>;
395
+ getMcpServers(): MCPServersState;
396
+ private broadcastMcpServers;
397
+ /**
398
+ * Handle MCP OAuth callback request if it's an OAuth callback.
399
+ *
400
+ * This method encapsulates the entire OAuth callback flow:
401
+ * 1. Checks if the request is an MCP OAuth callback
402
+ * 2. Processes the OAuth code exchange
403
+ * 3. Establishes the connection if successful
404
+ * 4. Broadcasts MCP server state updates
405
+ * 5. Returns the appropriate HTTP response
406
+ *
407
+ * @param request The incoming HTTP request
408
+ * @returns Response if this was an OAuth callback, null otherwise
409
+ */
410
+ private handleMcpOAuthCallback;
411
+ /**
412
+ * Handle OAuth callback response using MCPClientManager configuration
413
+ * @param result OAuth callback result
414
+ * @param request The original request (needed for base URL)
415
+ * @returns Response for the OAuth callback
416
+ */
417
+ private handleOAuthCallbackResponse;
418
+ }
419
+ /**
420
+ * Namespace for creating Agent instances
421
+ * @template Agentic Type of the Agent class
422
+ * @deprecated Use DurableObjectNamespace instead
423
+ */
424
+ type AgentNamespace<Agentic extends Agent<Cloudflare.Env>> =
425
+ DurableObjectNamespace<Agentic>;
426
+ /**
427
+ * Agent's durable context
428
+ */
429
+ type AgentContext = DurableObjectState;
430
+ /**
431
+ * Configuration options for Agent routing
432
+ */
433
+ type AgentOptions<Env> = PartyServerOptions<Env> & {
434
+ /**
435
+ * Whether to enable CORS for the Agent
436
+ */
437
+ cors?: boolean | HeadersInit | undefined;
438
+ };
439
+ /**
440
+ * Route a request to the appropriate Agent
441
+ * @param request Request to route
442
+ * @param env Environment containing Agent bindings
443
+ * @param options Routing options
444
+ * @returns Response from the Agent or undefined if no route matched
445
+ */
446
+ declare function routeAgentRequest<Env>(
447
+ request: Request,
448
+ env: Env,
449
+ options?: AgentOptions<Env>
450
+ ): Promise<Response | null>;
451
+ type EmailResolver<Env> = (
452
+ email: ForwardableEmailMessage,
453
+ env: Env
454
+ ) => Promise<{
455
+ agentName: string;
456
+ agentId: string;
457
+ } | null>;
458
+ /**
459
+ * Create a resolver that uses the message-id header to determine the agent to route the email to
460
+ * @returns A function that resolves the agent to route the email to
461
+ */
462
+ declare function createHeaderBasedEmailResolver<Env>(): EmailResolver<Env>;
463
+ /**
464
+ * Create a resolver that uses the email address to determine the agent to route the email to
465
+ * @param defaultAgentName The default agent name to use if the email address does not contain a sub-address
466
+ * @returns A function that resolves the agent to route the email to
467
+ */
468
+ declare function createAddressBasedEmailResolver<Env>(
469
+ defaultAgentName: string
470
+ ): EmailResolver<Env>;
471
+ /**
472
+ * Create a resolver that uses the agentName and agentId to determine the agent to route the email to
473
+ * @param agentName The name of the agent to route the email to
474
+ * @param agentId The id of the agent to route the email to
475
+ * @returns A function that resolves the agent to route the email to
476
+ */
477
+ declare function createCatchAllEmailResolver<Env>(
478
+ agentName: string,
479
+ agentId: string
480
+ ): EmailResolver<Env>;
481
+ type EmailRoutingOptions<Env> = AgentOptions<Env> & {
482
+ resolver: EmailResolver<Env>;
483
+ };
484
+ /**
485
+ * Route an email to the appropriate Agent
486
+ * @param email The email to route
487
+ * @param env The environment containing the Agent bindings
488
+ * @param options The options for routing the email
489
+ * @returns A promise that resolves when the email has been routed
490
+ */
491
+ declare function routeAgentEmail<Env extends Cloudflare.Env = Cloudflare.Env>(
492
+ email: ForwardableEmailMessage,
493
+ env: Env,
494
+ options: EmailRoutingOptions<Env>
495
+ ): Promise<void>;
496
+ type EmailSendOptions = {
497
+ to: string;
498
+ subject: string;
499
+ body: string;
500
+ contentType?: string;
501
+ headers?: Record<string, string>;
502
+ includeRoutingHeaders?: boolean;
503
+ agentName?: string;
504
+ agentId?: string;
505
+ domain?: string;
506
+ };
507
+ /**
508
+ * Get or create an Agent by name
509
+ * @template Env Environment type containing bindings
510
+ * @template T Type of the Agent class
511
+ * @param namespace Agent namespace
512
+ * @param name Name of the Agent instance
513
+ * @param options Options for Agent creation
514
+ * @returns Promise resolving to an Agent instance stub
515
+ */
516
+ declare function getAgentByName<
517
+ Env extends Cloudflare.Env = Cloudflare.Env,
518
+ T extends Agent<Env> = Agent<Env>,
519
+ Props extends Record<string, unknown> = Record<string, unknown>
520
+ >(
521
+ namespace: DurableObjectNamespace<T>,
522
+ name: string,
523
+ options?: {
524
+ jurisdiction?: DurableObjectJurisdiction;
525
+ locationHint?: DurableObjectLocationHint;
526
+ props?: Props;
527
+ }
528
+ ): Promise<DurableObjectStub<T>>;
529
+ /**
530
+ * A wrapper for streaming responses in callable methods
531
+ */
532
+ declare class StreamingResponse {
533
+ private _connection;
534
+ private _id;
535
+ private _closed;
536
+ constructor(connection: Connection$1, id: string);
537
+ /**
538
+ * Send a chunk of data to the client
539
+ * @param chunk The data to send
540
+ */
541
+ send(chunk: unknown): void;
542
+ /**
543
+ * End the stream and send the final chunk (if any)
544
+ * @param finalChunk Optional final chunk of data to send
545
+ */
546
+ end(finalChunk?: unknown): void;
547
+ }
548
+ //#endregion
35
549
  export {
36
550
  Agent,
37
551
  AgentContext,
38
- AgentEmail,
552
+ type AgentEmail,
39
553
  AgentNamespace,
40
554
  AgentOptions,
41
555
  CallableMetadata,
42
- Connection,
43
- ConnectionContext,
556
+ type Connection,
557
+ type ConnectionContext,
44
558
  EmailResolver,
45
559
  EmailRoutingOptions,
46
560
  EmailSendOptions,
@@ -53,8 +567,8 @@ export {
53
567
  Schedule,
54
568
  StateUpdateMessage,
55
569
  StreamingResponse,
56
- TransportType,
57
- WSMessage,
570
+ type TransportType,
571
+ type WSMessage,
58
572
  callable,
59
573
  createAddressBasedEmailResolver,
60
574
  createCatchAllEmailResolver,
@@ -65,3 +579,4 @@ export {
65
579
  routeAgentRequest,
66
580
  unstable_callable
67
581
  };
582
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import "./context-BkKbAa1R.js";
2
- import "./client-DjTPRM8-.js";
3
- import "./client-QZa2Rq0l.js";
4
- import "./do-oauth-client-provider-B1fVIshX.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-BZDh910Z.js";
1
+ import "./client-CEO0P7vN.js";
2
+ import "./internal_context-oN047Id3.js";
3
+ import "./client-C7SOlYfK.js";
4
+ import "./do-oauth-client-provider-BfPFgQU0.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-CXf5SiV4.js";
6
6
 
7
7
  export { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };
@@ -1,7 +1,7 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import { Connection } from "partyserver";
3
3
 
4
- //#region src/context.d.ts
4
+ //#region src/internal_context.d.ts
5
5
  type AgentEmail = {
6
6
  from: string;
7
7
  to: string;
@@ -21,4 +21,4 @@ type AgentContextStore = {
21
21
  declare const agentContext: AsyncLocalStorage<AgentContextStore>;
22
22
  //#endregion
23
23
  export { AgentEmail as n, agentContext as r, AgentContextStore as t };
24
- //# sourceMappingURL=context-DcbQ8o7k.d.ts.map
24
+ //# sourceMappingURL=internal_context-neg89p5n.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
 
3
- //#region src/context.ts
3
+ //#region src/internal_context.ts
4
4
  const agentContext = new AsyncLocalStorage();
5
5
 
6
6
  //#endregion
7
7
  export { agentContext as t };
8
- //# sourceMappingURL=context-BkKbAa1R.js.map
8
+ //# sourceMappingURL=internal_context-oN047Id3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal_context-oN047Id3.js","names":[],"sources":["../src/internal_context.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { Connection } from \"partyserver\";\n\nexport type AgentEmail = {\n from: string;\n to: string;\n getRaw: () => Promise<Uint8Array>;\n headers: Headers;\n rawSize: number;\n setReject: (reason: string) => void;\n forward: (rcptTo: string, headers?: Headers) => Promise<void>;\n reply: (options: { from: string; to: string; raw: string }) => Promise<void>;\n};\n\nexport type AgentContextStore = {\n // Using unknown to avoid circular dependency with Agent\n agent: unknown;\n connection: Connection | undefined;\n request: Request | undefined;\n email: AgentEmail | undefined;\n};\n\nexport const agentContext = new AsyncLocalStorage<AgentContextStore>();\n"],"mappings":";;;AAsBA,MAAa,eAAe,IAAI,mBAAsC"}
@@ -2,5 +2,5 @@ import {
2
2
  n as AgentEmail,
3
3
  r as agentContext,
4
4
  t as AgentContextStore
5
- } from "./context-DcbQ8o7k.js";
5
+ } from "./internal_context-neg89p5n.js";
6
6
  export { AgentContextStore, AgentEmail, agentContext };
@@ -0,0 +1,3 @@
1
+ import { t as agentContext } from "./internal_context-oN047Id3.js";
2
+
3
+ export { agentContext };
@@ -1,2 +1,2 @@
1
- import { a as MCPConnectionResult, c as RegisterServerOptions, i as MCPClientOAuthResult, l as getNamespacedData, n as MCPClientManagerOptions, o as MCPDiscoverResult, r as MCPClientOAuthCallbackConfig, s as MCPServerOptions, t as MCPClientManager } from "../client-DFotUKH_.js";
1
+ import { a as MCPConnectionResult, c as RegisterServerOptions, i as MCPClientOAuthResult, l as getNamespacedData, n as MCPClientManagerOptions, o as MCPDiscoverResult, r as MCPClientOAuthCallbackConfig, s as MCPServerOptions, t as MCPClientManager } from "../client-CbcnyqCo.js";
2
2
  export { MCPClientManager, MCPClientManagerOptions, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MCPConnectionResult, MCPDiscoverResult, MCPServerOptions, RegisterServerOptions, getNamespacedData };
@@ -1,4 +1,4 @@
1
- import { n as getNamespacedData, t as MCPClientManager } from "../client-QZa2Rq0l.js";
2
- import "../do-oauth-client-provider-B1fVIshX.js";
1
+ import { n as getNamespacedData, t as MCPClientManager } from "../client-C7SOlYfK.js";
2
+ import "../do-oauth-client-provider-BfPFgQU0.js";
3
3
 
4
4
  export { MCPClientManager, getNamespacedData };
@@ -1,2 +1,2 @@
1
- import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider--To1Tsjj.js";
1
+ import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider-BH9zFtSy.js";
2
2
  export { AgentsOAuthProvider, DurableObjectOAuthClientProvider };
@@ -1,3 +1,3 @@
1
- import { t as DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-B1fVIshX.js";
1
+ import { t as DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-BfPFgQU0.js";
2
2
 
3
3
  export { DurableObjectOAuthClientProvider };