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