agents 0.0.0-931d633 → 0.0.0-93d3975
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.
- package/README.md +257 -27
- package/dist/ai-chat-agent.d.ts +104 -20
- package/dist/ai-chat-agent.js +812 -260
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration-DguhuLKF.js +155 -0
- package/dist/ai-chat-v5-migration-DguhuLKF.js.map +1 -0
- package/dist/ai-chat-v5-migration.d.ts +155 -0
- package/dist/ai-chat-v5-migration.js +3 -0
- package/dist/ai-react.d.ts +79 -85
- package/dist/ai-react.js +411 -199
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types-CwgHzwUb.js +24 -0
- package/dist/ai-types-CwgHzwUb.js.map +1 -0
- package/dist/ai-types-D_hTbf25.d.ts +103 -0
- package/dist/ai-types.d.ts +6 -74
- package/dist/ai-types.js +3 -1
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +28 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client-C_M5uPrn.d.ts +834 -0
- package/dist/client-CcyhkGfN.js +117 -0
- package/dist/client-CcyhkGfN.js.map +1 -0
- package/dist/client-ClORm6f0.d.ts +104 -0
- package/dist/client-QZa2Rq0l.js +1105 -0
- package/dist/client-QZa2Rq0l.js.map +1 -0
- package/dist/client.d.ts +12 -93
- package/dist/client.js +4 -11
- package/dist/codemode/ai.d.ts +27 -0
- package/dist/codemode/ai.js +152 -0
- package/dist/codemode/ai.js.map +1 -0
- package/dist/context-BkKbAa1R.js +8 -0
- package/dist/context-BkKbAa1R.js.map +1 -0
- package/dist/context-_sPQqJWv.d.ts +24 -0
- package/dist/context.d.ts +6 -0
- package/dist/context.js +3 -0
- package/dist/do-oauth-client-provider-B-ryFIPr.d.ts +70 -0
- package/dist/do-oauth-client-provider-B1fVIshX.js +155 -0
- package/dist/do-oauth-client-provider-B1fVIshX.js.map +1 -0
- package/dist/index-CyDpAVHZ.d.ts +58 -0
- package/dist/{index-CITGJflw.d.ts → index-DUnsVDnf.d.ts} +247 -156
- package/dist/index.d.ts +69 -30
- package/dist/index.js +8 -22
- package/dist/mcp/client.d.ts +4 -1055
- package/dist/mcp/client.js +4 -9
- package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
- package/dist/mcp/do-oauth-client-provider.js +3 -7
- package/dist/mcp/index.d.ts +191 -81
- package/dist/mcp/index.js +1457 -770
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/x402.d.ts +34 -0
- package/dist/mcp/x402.js +198 -0
- package/dist/mcp/x402.js.map +1 -0
- package/dist/mcp-CzbSsLfc.d.ts +61 -0
- package/dist/observability/index.d.ts +3 -12
- package/dist/observability/index.js +8 -10
- package/dist/react-DIGWa87z.d.ts +137 -0
- package/dist/react.d.ts +15 -119
- package/dist/react.js +190 -110
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +91 -14
- package/dist/schedule.js +46 -21
- package/dist/schedule.js.map +1 -1
- package/dist/serializable-C4GLimgv.d.ts +39 -0
- package/dist/serializable.d.ts +7 -32
- package/dist/serializable.js +1 -1
- package/dist/src-BmbDclOA.js +1181 -0
- package/dist/src-BmbDclOA.js.map +1 -0
- package/package.json +78 -28
- package/dist/ai-types.js.map +0 -1
- package/dist/chunk-767EASBA.js +0 -106
- package/dist/chunk-767EASBA.js.map +0 -1
- package/dist/chunk-E3LCYPCB.js +0 -469
- package/dist/chunk-E3LCYPCB.js.map +0 -1
- package/dist/chunk-JFRK72K3.js +0 -910
- package/dist/chunk-JFRK72K3.js.map +0 -1
- package/dist/chunk-NKZZ66QY.js +0 -116
- package/dist/chunk-NKZZ66QY.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mcp/client.js.map +0 -1
- package/dist/mcp/do-oauth-client-provider.js.map +0 -1
- package/dist/observability/index.js.map +0 -1
- package/dist/serializable.js.map +0 -1
- package/src/index.ts +0 -1365
|
@@ -1,87 +1,29 @@
|
|
|
1
|
+
import { n as AgentEmail } from "./context-_sPQqJWv.js";
|
|
2
|
+
import {
|
|
3
|
+
h as TransportType,
|
|
4
|
+
t as MCPClientManager,
|
|
5
|
+
u as MCPConnectionState
|
|
6
|
+
} from "./client-C_M5uPrn.js";
|
|
7
|
+
import { t as Observability } from "./index-CyDpAVHZ.js";
|
|
8
|
+
import { n as MessageType } from "./ai-types-D_hTbf25.js";
|
|
9
|
+
import {
|
|
10
|
+
Connection,
|
|
11
|
+
Connection as Connection$1,
|
|
12
|
+
ConnectionContext,
|
|
13
|
+
PartyServerOptions,
|
|
14
|
+
Server,
|
|
15
|
+
WSMessage
|
|
16
|
+
} from "partyserver";
|
|
1
17
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
18
|
import {
|
|
3
|
-
ServerCapabilities,
|
|
4
|
-
Tool,
|
|
5
19
|
Prompt,
|
|
6
20
|
Resource,
|
|
21
|
+
ServerCapabilities,
|
|
22
|
+
Tool
|
|
7
23
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
-
import {
|
|
9
|
-
import { MCPClientManager } from "./mcp/client.js";
|
|
10
|
-
import { Message } from "ai";
|
|
24
|
+
import { env } from "cloudflare:workers";
|
|
11
25
|
|
|
12
|
-
|
|
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;
|
|
26
|
+
//#region src/index.d.ts
|
|
85
27
|
|
|
86
28
|
/**
|
|
87
29
|
* RPC request message from client
|
|
@@ -96,14 +38,14 @@ type RPCRequest = {
|
|
|
96
38
|
* State update message from client
|
|
97
39
|
*/
|
|
98
40
|
type StateUpdateMessage = {
|
|
99
|
-
type:
|
|
41
|
+
type: MessageType.CF_AGENT_STATE;
|
|
100
42
|
state: unknown;
|
|
101
43
|
};
|
|
102
44
|
/**
|
|
103
45
|
* RPC response message to client
|
|
104
46
|
*/
|
|
105
47
|
type RPCResponse = {
|
|
106
|
-
type:
|
|
48
|
+
type: MessageType.RPC;
|
|
107
49
|
id: string;
|
|
108
50
|
} & (
|
|
109
51
|
| {
|
|
@@ -134,12 +76,24 @@ type CallableMetadata = {
|
|
|
134
76
|
* Decorator that marks a method as callable by clients
|
|
135
77
|
* @param metadata Optional metadata about the callable method
|
|
136
78
|
*/
|
|
137
|
-
declare function
|
|
79
|
+
declare function callable(
|
|
138
80
|
metadata?: CallableMetadata
|
|
139
81
|
): <This, Args extends unknown[], Return>(
|
|
140
82
|
target: (this: This, ...args: Args) => Return,
|
|
141
83
|
context: ClassMethodDecoratorContext
|
|
142
84
|
) => (this: This, ...args: Args) => Return;
|
|
85
|
+
/**
|
|
86
|
+
* Decorator that marks a method as callable by clients
|
|
87
|
+
* @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
|
|
88
|
+
* @param metadata Optional metadata about the callable method
|
|
89
|
+
*/
|
|
90
|
+
declare const unstable_callable: (metadata?: CallableMetadata) => void;
|
|
91
|
+
type QueueItem<T = string> = {
|
|
92
|
+
id: string;
|
|
93
|
+
payload: T;
|
|
94
|
+
callback: keyof Agent<unknown>;
|
|
95
|
+
created_at: number;
|
|
96
|
+
};
|
|
143
97
|
/**
|
|
144
98
|
* Represents a scheduled task within an Agent
|
|
145
99
|
* @template T Type of the payload data
|
|
@@ -179,41 +133,54 @@ type Schedule<T = string> = {
|
|
|
179
133
|
* MCP Server state update message from server -> Client
|
|
180
134
|
*/
|
|
181
135
|
type MCPServerMessage = {
|
|
182
|
-
type:
|
|
136
|
+
type: MessageType.CF_AGENT_MCP_SERVERS;
|
|
183
137
|
mcp: MCPServersState;
|
|
184
138
|
};
|
|
185
139
|
type MCPServersState = {
|
|
186
140
|
servers: {
|
|
187
141
|
[id: string]: MCPServer;
|
|
188
142
|
};
|
|
189
|
-
tools: Tool
|
|
190
|
-
|
|
191
|
-
|
|
143
|
+
tools: (Tool & {
|
|
144
|
+
serverId: string;
|
|
145
|
+
})[];
|
|
146
|
+
prompts: (Prompt & {
|
|
147
|
+
serverId: string;
|
|
148
|
+
})[];
|
|
149
|
+
resources: (Resource & {
|
|
150
|
+
serverId: string;
|
|
151
|
+
})[];
|
|
192
152
|
};
|
|
193
153
|
type MCPServer = {
|
|
194
154
|
name: string;
|
|
195
155
|
server_url: string;
|
|
196
156
|
auth_url: string | null;
|
|
197
|
-
state:
|
|
157
|
+
state: MCPConnectionState;
|
|
198
158
|
instructions: string | null;
|
|
199
159
|
capabilities: ServerCapabilities | null;
|
|
200
160
|
};
|
|
201
161
|
declare function getCurrentAgent<
|
|
202
|
-
T extends Agent<unknown, unknown> = Agent<unknown, unknown
|
|
162
|
+
T extends Agent<unknown, unknown> = Agent<unknown, unknown>
|
|
203
163
|
>(): {
|
|
204
164
|
agent: T | undefined;
|
|
205
165
|
connection: Connection | undefined;
|
|
206
|
-
request: Request
|
|
166
|
+
request: Request | undefined;
|
|
167
|
+
email: AgentEmail | undefined;
|
|
207
168
|
};
|
|
208
169
|
/**
|
|
209
170
|
* Base class for creating Agent implementations
|
|
210
171
|
* @template Env Environment type containing bindings
|
|
211
172
|
* @template State State type to store within the Agent
|
|
212
173
|
*/
|
|
213
|
-
declare class Agent<
|
|
174
|
+
declare class Agent<
|
|
175
|
+
Env = typeof env,
|
|
176
|
+
State = unknown,
|
|
177
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
178
|
+
> extends Server<Env, Props> {
|
|
214
179
|
private _state;
|
|
180
|
+
private _disposables;
|
|
181
|
+
private _destroyed;
|
|
215
182
|
private _ParentClass;
|
|
216
|
-
mcp: MCPClientManager;
|
|
183
|
+
readonly mcp: MCPClientManager;
|
|
217
184
|
/**
|
|
218
185
|
* Initial state for the Agent
|
|
219
186
|
* Override to provide default state values
|
|
@@ -259,17 +226,75 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
259
226
|
*/
|
|
260
227
|
onStateUpdate(state: State | undefined, source: Connection | "server"): void;
|
|
261
228
|
/**
|
|
262
|
-
* Called when the Agent receives an email
|
|
229
|
+
* Called when the Agent receives an email via routeAgentEmail()
|
|
230
|
+
* Override this method to handle incoming emails
|
|
263
231
|
* @param email Email message to process
|
|
264
232
|
*/
|
|
265
|
-
|
|
233
|
+
_onEmail(email: AgentEmail): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Reply to an email
|
|
236
|
+
* @param email The email to reply to
|
|
237
|
+
* @param options Options for the reply
|
|
238
|
+
* @returns void
|
|
239
|
+
*/
|
|
240
|
+
replyToEmail(
|
|
241
|
+
email: AgentEmail,
|
|
242
|
+
options: {
|
|
243
|
+
fromName: string;
|
|
244
|
+
subject?: string | undefined;
|
|
245
|
+
body: string;
|
|
246
|
+
contentType?: string;
|
|
247
|
+
headers?: Record<string, string>;
|
|
248
|
+
}
|
|
249
|
+
): Promise<void>;
|
|
266
250
|
private _tryCatch;
|
|
251
|
+
/**
|
|
252
|
+
* Automatically wrap custom methods with agent context
|
|
253
|
+
* This ensures getCurrentAgent() works in all custom methods without decorators
|
|
254
|
+
*/
|
|
255
|
+
private _autoWrapCustomMethods;
|
|
267
256
|
onError(connection: Connection, error: unknown): void | Promise<void>;
|
|
268
257
|
onError(error: unknown): void | Promise<void>;
|
|
269
258
|
/**
|
|
270
259
|
* Render content (not implemented in base class)
|
|
271
260
|
*/
|
|
272
261
|
render(): void;
|
|
262
|
+
/**
|
|
263
|
+
* Queue a task to be executed in the future
|
|
264
|
+
* @param payload Payload to pass to the callback
|
|
265
|
+
* @param callback Name of the method to call
|
|
266
|
+
* @returns The ID of the queued task
|
|
267
|
+
*/
|
|
268
|
+
queue<T = unknown>(callback: keyof this, payload: T): Promise<string>;
|
|
269
|
+
private _flushingQueue;
|
|
270
|
+
private _flushQueue;
|
|
271
|
+
/**
|
|
272
|
+
* Dequeue a task by ID
|
|
273
|
+
* @param id ID of the task to dequeue
|
|
274
|
+
*/
|
|
275
|
+
dequeue(id: string): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Dequeue all tasks
|
|
278
|
+
*/
|
|
279
|
+
dequeueAll(): Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* Dequeue all tasks by callback
|
|
282
|
+
* @param callback Name of the callback to dequeue
|
|
283
|
+
*/
|
|
284
|
+
dequeueAllByCallback(callback: string): Promise<void>;
|
|
285
|
+
/**
|
|
286
|
+
* Get a queued task by ID
|
|
287
|
+
* @param id ID of the task to get
|
|
288
|
+
* @returns The task or undefined if not found
|
|
289
|
+
*/
|
|
290
|
+
getQueue(id: string): Promise<QueueItem<string> | undefined>;
|
|
291
|
+
/**
|
|
292
|
+
* Get all queues by key and value
|
|
293
|
+
* @param key Key to filter by
|
|
294
|
+
* @param value Value to filter by
|
|
295
|
+
* @returns Array of matching QueueItem objects
|
|
296
|
+
*/
|
|
297
|
+
getQueues(key: string, value: string): Promise<QueueItem<string>[]>;
|
|
273
298
|
/**
|
|
274
299
|
* Schedule a task to be executed in the future
|
|
275
300
|
* @template T Type of the payload data
|
|
@@ -307,7 +332,7 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
307
332
|
/**
|
|
308
333
|
* Cancel a scheduled task
|
|
309
334
|
* @param id ID of the task to cancel
|
|
310
|
-
* @returns true if the task was cancelled, false
|
|
335
|
+
* @returns true if the task was cancelled, false if the task was not found
|
|
311
336
|
*/
|
|
312
337
|
cancelSchedule(id: string): Promise<boolean>;
|
|
313
338
|
private _scheduleNextAlarm;
|
|
@@ -332,55 +357,62 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
332
357
|
/**
|
|
333
358
|
* Connect to a new MCP Server
|
|
334
359
|
*
|
|
360
|
+
* @param serverName Name of the MCP server
|
|
335
361
|
* @param url MCP Server SSE URL
|
|
336
|
-
* @param callbackHost Base host for the agent, used for the redirect URI.
|
|
362
|
+
* @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
|
|
337
363
|
* @param agentsPrefix agents routing prefix if not using `agents`
|
|
338
|
-
* @param options MCP client and transport
|
|
339
|
-
* @returns authUrl
|
|
364
|
+
* @param options MCP client and transport options
|
|
365
|
+
* @returns Server id and state - either "authenticating" with authUrl, or "ready"
|
|
366
|
+
* @throws If connection or discovery fails
|
|
340
367
|
*/
|
|
341
368
|
addMcpServer(
|
|
342
369
|
serverName: string,
|
|
343
370
|
url: string,
|
|
344
|
-
callbackHost
|
|
371
|
+
callbackHost?: string,
|
|
345
372
|
agentsPrefix?: string,
|
|
346
373
|
options?: {
|
|
347
374
|
client?: ConstructorParameters<typeof Client>[1];
|
|
348
|
-
transport?: {
|
|
349
|
-
headers: HeadersInit;
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
): Promise<{
|
|
353
|
-
id: string;
|
|
354
|
-
authUrl: string | undefined;
|
|
355
|
-
}>;
|
|
356
|
-
_connectToMcpServerInternal(
|
|
357
|
-
_serverName: string,
|
|
358
|
-
url: string,
|
|
359
|
-
callbackUrl: string,
|
|
360
|
-
options?: {
|
|
361
|
-
client?: ConstructorParameters<typeof Client>[1];
|
|
362
|
-
/**
|
|
363
|
-
* We don't expose the normal set of transport options because:
|
|
364
|
-
* 1) we can't serialize things like the auth provider or a fetch function into the DB for reconnection purposes
|
|
365
|
-
* 2) We probably want these options to be agnostic to the transport type (SSE vs Streamable)
|
|
366
|
-
*
|
|
367
|
-
* 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).
|
|
368
|
-
*/
|
|
369
375
|
transport?: {
|
|
370
376
|
headers?: HeadersInit;
|
|
377
|
+
type?: TransportType;
|
|
371
378
|
};
|
|
372
|
-
},
|
|
373
|
-
reconnect?: {
|
|
374
|
-
id: string;
|
|
375
|
-
oauthClientId?: string;
|
|
376
379
|
}
|
|
377
|
-
): Promise<
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
380
|
+
): Promise<
|
|
381
|
+
| {
|
|
382
|
+
id: string;
|
|
383
|
+
state: typeof MCPConnectionState.AUTHENTICATING;
|
|
384
|
+
authUrl: string;
|
|
385
|
+
}
|
|
386
|
+
| {
|
|
387
|
+
id: string;
|
|
388
|
+
state: typeof MCPConnectionState.READY;
|
|
389
|
+
authUrl?: undefined;
|
|
390
|
+
}
|
|
391
|
+
>;
|
|
382
392
|
removeMcpServer(id: string): Promise<void>;
|
|
383
393
|
getMcpServers(): MCPServersState;
|
|
394
|
+
private broadcastMcpServers;
|
|
395
|
+
/**
|
|
396
|
+
* Handle MCP OAuth callback request if it's an OAuth callback.
|
|
397
|
+
*
|
|
398
|
+
* This method encapsulates the entire OAuth callback flow:
|
|
399
|
+
* 1. Checks if the request is an MCP OAuth callback
|
|
400
|
+
* 2. Processes the OAuth code exchange
|
|
401
|
+
* 3. Establishes the connection if successful
|
|
402
|
+
* 4. Broadcasts MCP server state updates
|
|
403
|
+
* 5. Returns the appropriate HTTP response
|
|
404
|
+
*
|
|
405
|
+
* @param request The incoming HTTP request
|
|
406
|
+
* @returns Response if this was an OAuth callback, null otherwise
|
|
407
|
+
*/
|
|
408
|
+
private handleMcpOAuthCallback;
|
|
409
|
+
/**
|
|
410
|
+
* Handle OAuth callback response using MCPClientManager configuration
|
|
411
|
+
* @param result OAuth callback result
|
|
412
|
+
* @param request The original request (needed for base URL)
|
|
413
|
+
* @returns Response for the OAuth callback
|
|
414
|
+
*/
|
|
415
|
+
private handleOAuthCallbackResponse;
|
|
384
416
|
}
|
|
385
417
|
/**
|
|
386
418
|
* Namespace for creating Agent instances
|
|
@@ -413,17 +445,62 @@ declare function routeAgentRequest<Env>(
|
|
|
413
445
|
env: Env,
|
|
414
446
|
options?: AgentOptions<Env>
|
|
415
447
|
): Promise<Response | null>;
|
|
448
|
+
type EmailResolver<Env> = (
|
|
449
|
+
email: ForwardableEmailMessage,
|
|
450
|
+
env: Env
|
|
451
|
+
) => Promise<{
|
|
452
|
+
agentName: string;
|
|
453
|
+
agentId: string;
|
|
454
|
+
} | null>;
|
|
455
|
+
/**
|
|
456
|
+
* Create a resolver that uses the message-id header to determine the agent to route the email to
|
|
457
|
+
* @returns A function that resolves the agent to route the email to
|
|
458
|
+
*/
|
|
459
|
+
declare function createHeaderBasedEmailResolver<Env>(): EmailResolver<Env>;
|
|
460
|
+
/**
|
|
461
|
+
* Create a resolver that uses the email address to determine the agent to route the email to
|
|
462
|
+
* @param defaultAgentName The default agent name to use if the email address does not contain a sub-address
|
|
463
|
+
* @returns A function that resolves the agent to route the email to
|
|
464
|
+
*/
|
|
465
|
+
declare function createAddressBasedEmailResolver<Env>(
|
|
466
|
+
defaultAgentName: string
|
|
467
|
+
): EmailResolver<Env>;
|
|
468
|
+
/**
|
|
469
|
+
* Create a resolver that uses the agentName and agentId to determine the agent to route the email to
|
|
470
|
+
* @param agentName The name of the agent to route the email to
|
|
471
|
+
* @param agentId The id of the agent to route the email to
|
|
472
|
+
* @returns A function that resolves the agent to route the email to
|
|
473
|
+
*/
|
|
474
|
+
declare function createCatchAllEmailResolver<Env>(
|
|
475
|
+
agentName: string,
|
|
476
|
+
agentId: string
|
|
477
|
+
): EmailResolver<Env>;
|
|
478
|
+
type EmailRoutingOptions<Env> = AgentOptions<Env> & {
|
|
479
|
+
resolver: EmailResolver<Env>;
|
|
480
|
+
};
|
|
416
481
|
/**
|
|
417
482
|
* Route an email to the appropriate Agent
|
|
418
|
-
* @param email
|
|
419
|
-
* @param env
|
|
420
|
-
* @param options
|
|
483
|
+
* @param email The email to route
|
|
484
|
+
* @param env The environment containing the Agent bindings
|
|
485
|
+
* @param options The options for routing the email
|
|
486
|
+
* @returns A promise that resolves when the email has been routed
|
|
421
487
|
*/
|
|
422
488
|
declare function routeAgentEmail<Env>(
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
489
|
+
email: ForwardableEmailMessage,
|
|
490
|
+
env: Env,
|
|
491
|
+
options: EmailRoutingOptions<Env>
|
|
426
492
|
): Promise<void>;
|
|
493
|
+
type EmailSendOptions = {
|
|
494
|
+
to: string;
|
|
495
|
+
subject: string;
|
|
496
|
+
body: string;
|
|
497
|
+
contentType?: string;
|
|
498
|
+
headers?: Record<string, string>;
|
|
499
|
+
includeRoutingHeaders?: boolean;
|
|
500
|
+
agentName?: string;
|
|
501
|
+
agentId?: string;
|
|
502
|
+
domain?: string;
|
|
503
|
+
};
|
|
427
504
|
/**
|
|
428
505
|
* Get or create an Agent by name
|
|
429
506
|
* @template Env Environment type containing bindings
|
|
@@ -433,12 +510,17 @@ declare function routeAgentEmail<Env>(
|
|
|
433
510
|
* @param options Options for Agent creation
|
|
434
511
|
* @returns Promise resolving to an Agent instance stub
|
|
435
512
|
*/
|
|
436
|
-
declare function getAgentByName<
|
|
513
|
+
declare function getAgentByName<
|
|
514
|
+
Env,
|
|
515
|
+
T extends Agent<Env>,
|
|
516
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
517
|
+
>(
|
|
437
518
|
namespace: AgentNamespace<T>,
|
|
438
519
|
name: string,
|
|
439
520
|
options?: {
|
|
440
521
|
jurisdiction?: DurableObjectJurisdiction;
|
|
441
522
|
locationHint?: DurableObjectLocationHint;
|
|
523
|
+
props?: Props;
|
|
442
524
|
}
|
|
443
525
|
): Promise<DurableObjectStub<T>>;
|
|
444
526
|
/**
|
|
@@ -460,27 +542,36 @@ declare class StreamingResponse {
|
|
|
460
542
|
*/
|
|
461
543
|
end(finalChunk?: unknown): void;
|
|
462
544
|
}
|
|
463
|
-
|
|
545
|
+
//#endregion
|
|
464
546
|
export {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
547
|
+
createCatchAllEmailResolver as C,
|
|
548
|
+
routeAgentEmail as D,
|
|
549
|
+
getCurrentAgent as E,
|
|
550
|
+
routeAgentRequest as O,
|
|
551
|
+
createAddressBasedEmailResolver as S,
|
|
552
|
+
getAgentByName as T,
|
|
553
|
+
Schedule as _,
|
|
554
|
+
CallableMetadata as a,
|
|
555
|
+
WSMessage as b,
|
|
556
|
+
EmailResolver as c,
|
|
557
|
+
MCPServer as d,
|
|
558
|
+
MCPServerMessage as f,
|
|
559
|
+
RPCResponse as g,
|
|
560
|
+
RPCRequest as h,
|
|
561
|
+
AgentOptions as i,
|
|
562
|
+
unstable_callable as k,
|
|
563
|
+
EmailRoutingOptions as l,
|
|
564
|
+
QueueItem as m,
|
|
565
|
+
AgentContext as n,
|
|
566
|
+
Connection$1 as o,
|
|
567
|
+
MCPServersState as p,
|
|
568
|
+
AgentNamespace as r,
|
|
569
|
+
ConnectionContext as s,
|
|
570
|
+
Agent as t,
|
|
571
|
+
EmailSendOptions as u,
|
|
572
|
+
StateUpdateMessage as v,
|
|
573
|
+
createHeaderBasedEmailResolver as w,
|
|
574
|
+
callable as x,
|
|
575
|
+
StreamingResponse as y
|
|
486
576
|
};
|
|
577
|
+
//# sourceMappingURL=index-DUnsVDnf.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,31 +1,70 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
|
|
4
|
-
import "./
|
|
1
|
+
import { n as AgentEmail } from "./context-_sPQqJWv.js";
|
|
2
|
+
import { h as TransportType } from "./client-C_M5uPrn.js";
|
|
3
|
+
import "./mcp-CzbSsLfc.js";
|
|
4
|
+
import "./do-oauth-client-provider-B-ryFIPr.js";
|
|
5
|
+
import "./index-CyDpAVHZ.js";
|
|
6
|
+
import "./ai-types-D_hTbf25.js";
|
|
7
|
+
import {
|
|
8
|
+
C as createCatchAllEmailResolver,
|
|
9
|
+
D as routeAgentEmail,
|
|
10
|
+
E as getCurrentAgent,
|
|
11
|
+
O as routeAgentRequest,
|
|
12
|
+
S as createAddressBasedEmailResolver,
|
|
13
|
+
T as getAgentByName,
|
|
14
|
+
_ as Schedule,
|
|
15
|
+
a as CallableMetadata,
|
|
16
|
+
b as WSMessage,
|
|
17
|
+
c as EmailResolver,
|
|
18
|
+
d as MCPServer,
|
|
19
|
+
f as MCPServerMessage,
|
|
20
|
+
g as RPCResponse,
|
|
21
|
+
h as RPCRequest,
|
|
22
|
+
i as AgentOptions,
|
|
23
|
+
k as unstable_callable,
|
|
24
|
+
l as EmailRoutingOptions,
|
|
25
|
+
m as QueueItem,
|
|
26
|
+
n as AgentContext,
|
|
27
|
+
o as Connection,
|
|
28
|
+
p as MCPServersState,
|
|
29
|
+
r as AgentNamespace,
|
|
30
|
+
s as ConnectionContext,
|
|
31
|
+
t as Agent,
|
|
32
|
+
u as EmailSendOptions,
|
|
33
|
+
v as StateUpdateMessage,
|
|
34
|
+
w as createHeaderBasedEmailResolver,
|
|
35
|
+
x as callable,
|
|
36
|
+
y as StreamingResponse
|
|
37
|
+
} from "./index-DUnsVDnf.js";
|
|
5
38
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
Agent,
|
|
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,
|
|
58
|
+
StreamingResponse,
|
|
59
|
+
TransportType,
|
|
60
|
+
WSMessage,
|
|
61
|
+
callable,
|
|
62
|
+
createAddressBasedEmailResolver,
|
|
63
|
+
createCatchAllEmailResolver,
|
|
64
|
+
createHeaderBasedEmailResolver,
|
|
65
|
+
getAgentByName,
|
|
66
|
+
getCurrentAgent,
|
|
67
|
+
routeAgentEmail,
|
|
68
|
+
routeAgentRequest,
|
|
69
|
+
unstable_callable
|
|
70
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "./chunk-JFRK72K3.js";
|
|
10
|
-
import "./chunk-E3LCYPCB.js";
|
|
11
|
-
import "./chunk-767EASBA.js";
|
|
12
|
-
import "./chunk-NKZZ66QY.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 "./context-BkKbAa1R.js";
|
|
2
|
+
import "./ai-types-CwgHzwUb.js";
|
|
3
|
+
import "./client-CcyhkGfN.js";
|
|
4
|
+
import "./client-QZa2Rq0l.js";
|
|
5
|
+
import "./do-oauth-client-provider-B1fVIshX.js";
|
|
6
|
+
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-BmbDclOA.js";
|
|
7
|
+
|
|
8
|
+
export { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };
|