agents 0.0.0-eeb70e2 → 0.0.0-f0c6dce
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 +131 -25
- package/dist/ai-chat-agent.d.ts +12 -8
- package/dist/ai-chat-agent.js +166 -59
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration.d.ts +152 -0
- package/dist/ai-chat-v5-migration.js +19 -0
- package/dist/ai-chat-v5-migration.js.map +1 -0
- package/dist/ai-react.d.ts +63 -72
- package/dist/ai-react.js +161 -54
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.d.ts +36 -19
- package/dist/ai-types.js +6 -0
- package/dist/chunk-AVYJQSLW.js +17 -0
- package/dist/chunk-AVYJQSLW.js.map +1 -0
- package/dist/chunk-MWQSU7GK.js +1301 -0
- package/dist/chunk-MWQSU7GK.js.map +1 -0
- package/dist/{chunk-BZXOAZUX.js → chunk-PVQZBKN7.js} +5 -5
- package/dist/chunk-PVQZBKN7.js.map +1 -0
- package/dist/{chunk-VCSB47AK.js → chunk-QEVM4BVL.js} +10 -10
- package/dist/chunk-QEVM4BVL.js.map +1 -0
- package/dist/chunk-UJVEAURM.js +150 -0
- package/dist/chunk-UJVEAURM.js.map +1 -0
- package/dist/{chunk-OYJXQRRH.js → chunk-VYENMKFS.js} +182 -35
- package/dist/chunk-VYENMKFS.js.map +1 -0
- package/dist/client-B9tFv5gX.d.ts +4607 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -1
- package/dist/index.d.ts +166 -22
- package/dist/index.js +13 -4
- package/dist/mcp/client.d.ts +9 -781
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/do-oauth-client-provider.js +1 -1
- package/dist/mcp/index.d.ts +38 -10
- package/dist/mcp/index.js +233 -59
- package/dist/mcp/index.js.map +1 -1
- package/dist/observability/index.d.ts +46 -0
- package/dist/observability/index.js +11 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/react.d.ts +12 -8
- package/dist/react.js +12 -10
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +81 -7
- package/dist/schedule.js +19 -6
- package/dist/schedule.js.map +1 -1
- package/package.json +83 -70
- package/src/index.ts +857 -170
- package/dist/chunk-BZXOAZUX.js.map +0 -1
- package/dist/chunk-OYJXQRRH.js.map +0 -1
- package/dist/chunk-P3RZJ72N.js +0 -783
- package/dist/chunk-P3RZJ72N.js.map +0 -1
- package/dist/chunk-VCSB47AK.js.map +0 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PartySocketOptions,
|
|
3
3
|
PartyFetchOptions,
|
|
4
|
-
PartySocket
|
|
4
|
+
PartySocket
|
|
5
5
|
} from "partysocket";
|
|
6
6
|
import { SerializableReturnValue, SerializableValue } from "./serializable.js";
|
|
7
7
|
|
|
@@ -94,5 +94,5 @@ export {
|
|
|
94
94
|
type AgentClientOptions,
|
|
95
95
|
type StreamOptions,
|
|
96
96
|
agentFetch,
|
|
97
|
-
camelCaseToKebabCase
|
|
97
|
+
camelCaseToKebabCase
|
|
98
98
|
};
|
package/dist/client.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { env } from "cloudflare:workers";
|
|
2
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
3
|
import {
|
|
4
4
|
ServerCapabilities,
|
|
5
5
|
Tool,
|
|
6
6
|
Prompt,
|
|
7
|
-
Resource
|
|
7
|
+
Resource
|
|
8
8
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
9
|
-
import {
|
|
10
|
-
|
|
9
|
+
import { Server, Connection, PartyServerOptions } from "partyserver";
|
|
10
|
+
export { Connection, ConnectionContext, WSMessage } from "partyserver";
|
|
11
|
+
import { M as MCPClientManager } from "./client-B9tFv5gX.js";
|
|
12
|
+
import { Observability } from "./observability/index.js";
|
|
13
|
+
import { MessageType } from "./ai-types.js";
|
|
11
14
|
import "zod";
|
|
15
|
+
import "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
16
|
+
import "ai";
|
|
12
17
|
import "@modelcontextprotocol/sdk/client/sse.js";
|
|
18
|
+
import "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
13
19
|
import "./mcp/do-oauth-client-provider.js";
|
|
14
20
|
import "@modelcontextprotocol/sdk/client/auth.js";
|
|
15
21
|
import "@modelcontextprotocol/sdk/shared/auth.js";
|
|
16
|
-
import "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
17
|
-
import "ai";
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
24
|
* RPC request message from client
|
|
@@ -29,14 +33,14 @@ type RPCRequest = {
|
|
|
29
33
|
* State update message from client
|
|
30
34
|
*/
|
|
31
35
|
type StateUpdateMessage = {
|
|
32
|
-
type:
|
|
36
|
+
type: MessageType.CF_AGENT_STATE;
|
|
33
37
|
state: unknown;
|
|
34
38
|
};
|
|
35
39
|
/**
|
|
36
40
|
* RPC response message to client
|
|
37
41
|
*/
|
|
38
42
|
type RPCResponse = {
|
|
39
|
-
type:
|
|
43
|
+
type: MessageType.RPC;
|
|
40
44
|
id: string;
|
|
41
45
|
} & (
|
|
42
46
|
| {
|
|
@@ -67,12 +71,24 @@ type CallableMetadata = {
|
|
|
67
71
|
* Decorator that marks a method as callable by clients
|
|
68
72
|
* @param metadata Optional metadata about the callable method
|
|
69
73
|
*/
|
|
70
|
-
declare function
|
|
74
|
+
declare function callable(
|
|
71
75
|
metadata?: CallableMetadata
|
|
72
76
|
): <This, Args extends unknown[], Return>(
|
|
73
77
|
target: (this: This, ...args: Args) => Return,
|
|
74
78
|
context: ClassMethodDecoratorContext
|
|
75
79
|
) => (this: This, ...args: Args) => Return;
|
|
80
|
+
/**
|
|
81
|
+
* Decorator that marks a method as callable by clients
|
|
82
|
+
* @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
|
|
83
|
+
* @param metadata Optional metadata about the callable method
|
|
84
|
+
*/
|
|
85
|
+
declare const unstable_callable: (metadata?: CallableMetadata) => void;
|
|
86
|
+
type QueueItem<T = string> = {
|
|
87
|
+
id: string;
|
|
88
|
+
payload: T;
|
|
89
|
+
callback: keyof Agent<unknown>;
|
|
90
|
+
created_at: number;
|
|
91
|
+
};
|
|
76
92
|
/**
|
|
77
93
|
* Represents a scheduled task within an Agent
|
|
78
94
|
* @template T Type of the payload data
|
|
@@ -112,7 +128,7 @@ type Schedule<T = string> = {
|
|
|
112
128
|
* MCP Server state update message from server -> Client
|
|
113
129
|
*/
|
|
114
130
|
type MCPServerMessage = {
|
|
115
|
-
type:
|
|
131
|
+
type: MessageType.CF_AGENT_MCP_SERVERS;
|
|
116
132
|
mcp: MCPServersState;
|
|
117
133
|
};
|
|
118
134
|
type MCPServersState = {
|
|
@@ -132,18 +148,19 @@ type MCPServer = {
|
|
|
132
148
|
capabilities: ServerCapabilities | null;
|
|
133
149
|
};
|
|
134
150
|
declare function getCurrentAgent<
|
|
135
|
-
T extends Agent<unknown, unknown> = Agent<unknown, unknown
|
|
151
|
+
T extends Agent<unknown, unknown> = Agent<unknown, unknown>
|
|
136
152
|
>(): {
|
|
137
153
|
agent: T | undefined;
|
|
138
154
|
connection: Connection | undefined;
|
|
139
|
-
request: Request
|
|
155
|
+
request: Request | undefined;
|
|
156
|
+
email: AgentEmail | undefined;
|
|
140
157
|
};
|
|
141
158
|
/**
|
|
142
159
|
* Base class for creating Agent implementations
|
|
143
160
|
* @template Env Environment type containing bindings
|
|
144
161
|
* @template State State type to store within the Agent
|
|
145
162
|
*/
|
|
146
|
-
declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
163
|
+
declare class Agent<Env = typeof env, State = unknown> extends Server<Env> {
|
|
147
164
|
private _state;
|
|
148
165
|
private _ParentClass;
|
|
149
166
|
mcp: MCPClientManager;
|
|
@@ -163,6 +180,10 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
163
180
|
/** Whether the Agent should hibernate when inactive */
|
|
164
181
|
hibernate: boolean;
|
|
165
182
|
};
|
|
183
|
+
/**
|
|
184
|
+
* The observability implementation to use for the Agent
|
|
185
|
+
*/
|
|
186
|
+
observability?: Observability;
|
|
166
187
|
/**
|
|
167
188
|
* Execute SQL queries against the Agent's database
|
|
168
189
|
* @template T Type of the returned rows
|
|
@@ -188,17 +209,75 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
188
209
|
*/
|
|
189
210
|
onStateUpdate(state: State | undefined, source: Connection | "server"): void;
|
|
190
211
|
/**
|
|
191
|
-
* Called when the Agent receives an email
|
|
212
|
+
* Called when the Agent receives an email via routeAgentEmail()
|
|
213
|
+
* Override this method to handle incoming emails
|
|
192
214
|
* @param email Email message to process
|
|
193
215
|
*/
|
|
194
|
-
|
|
216
|
+
_onEmail(email: AgentEmail): Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Reply to an email
|
|
219
|
+
* @param email The email to reply to
|
|
220
|
+
* @param options Options for the reply
|
|
221
|
+
* @returns void
|
|
222
|
+
*/
|
|
223
|
+
replyToEmail(
|
|
224
|
+
email: AgentEmail,
|
|
225
|
+
options: {
|
|
226
|
+
fromName: string;
|
|
227
|
+
subject?: string | undefined;
|
|
228
|
+
body: string;
|
|
229
|
+
contentType?: string;
|
|
230
|
+
headers?: Record<string, string>;
|
|
231
|
+
}
|
|
232
|
+
): Promise<void>;
|
|
195
233
|
private _tryCatch;
|
|
234
|
+
/**
|
|
235
|
+
* Automatically wrap custom methods with agent context
|
|
236
|
+
* This ensures getCurrentAgent() works in all custom methods without decorators
|
|
237
|
+
*/
|
|
238
|
+
private _autoWrapCustomMethods;
|
|
196
239
|
onError(connection: Connection, error: unknown): void | Promise<void>;
|
|
197
240
|
onError(error: unknown): void | Promise<void>;
|
|
198
241
|
/**
|
|
199
242
|
* Render content (not implemented in base class)
|
|
200
243
|
*/
|
|
201
244
|
render(): void;
|
|
245
|
+
/**
|
|
246
|
+
* Queue a task to be executed in the future
|
|
247
|
+
* @param payload Payload to pass to the callback
|
|
248
|
+
* @param callback Name of the method to call
|
|
249
|
+
* @returns The ID of the queued task
|
|
250
|
+
*/
|
|
251
|
+
queue<T = unknown>(callback: keyof this, payload: T): Promise<string>;
|
|
252
|
+
private _flushingQueue;
|
|
253
|
+
private _flushQueue;
|
|
254
|
+
/**
|
|
255
|
+
* Dequeue a task by ID
|
|
256
|
+
* @param id ID of the task to dequeue
|
|
257
|
+
*/
|
|
258
|
+
dequeue(id: string): Promise<void>;
|
|
259
|
+
/**
|
|
260
|
+
* Dequeue all tasks
|
|
261
|
+
*/
|
|
262
|
+
dequeueAll(): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Dequeue all tasks by callback
|
|
265
|
+
* @param callback Name of the callback to dequeue
|
|
266
|
+
*/
|
|
267
|
+
dequeueAllByCallback(callback: string): Promise<void>;
|
|
268
|
+
/**
|
|
269
|
+
* Get a queued task by ID
|
|
270
|
+
* @param id ID of the task to get
|
|
271
|
+
* @returns The task or undefined if not found
|
|
272
|
+
*/
|
|
273
|
+
getQueue(id: string): Promise<QueueItem<string> | undefined>;
|
|
274
|
+
/**
|
|
275
|
+
* Get all queues by key and value
|
|
276
|
+
* @param key Key to filter by
|
|
277
|
+
* @param value Value to filter by
|
|
278
|
+
* @returns Array of matching QueueItem objects
|
|
279
|
+
*/
|
|
280
|
+
getQueues(key: string, value: string): Promise<QueueItem<string>[]>;
|
|
202
281
|
/**
|
|
203
282
|
* Schedule a task to be executed in the future
|
|
204
283
|
* @template T Type of the payload data
|
|
@@ -283,7 +362,7 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
283
362
|
authUrl: string | undefined;
|
|
284
363
|
}>;
|
|
285
364
|
_connectToMcpServerInternal(
|
|
286
|
-
|
|
365
|
+
_serverName: string,
|
|
287
366
|
url: string,
|
|
288
367
|
callbackUrl: string,
|
|
289
368
|
options?: {
|
|
@@ -306,6 +385,7 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
306
385
|
): Promise<{
|
|
307
386
|
id: string;
|
|
308
387
|
authUrl: string | undefined;
|
|
388
|
+
clientId: string | undefined;
|
|
309
389
|
}>;
|
|
310
390
|
removeMcpServer(id: string): Promise<void>;
|
|
311
391
|
getMcpServers(): MCPServersState;
|
|
@@ -341,17 +421,72 @@ declare function routeAgentRequest<Env>(
|
|
|
341
421
|
env: Env,
|
|
342
422
|
options?: AgentOptions<Env>
|
|
343
423
|
): Promise<Response | null>;
|
|
424
|
+
type EmailResolver<Env> = (
|
|
425
|
+
email: ForwardableEmailMessage,
|
|
426
|
+
env: Env
|
|
427
|
+
) => Promise<{
|
|
428
|
+
agentName: string;
|
|
429
|
+
agentId: string;
|
|
430
|
+
} | null>;
|
|
431
|
+
/**
|
|
432
|
+
* Create a resolver that uses the message-id header to determine the agent to route the email to
|
|
433
|
+
* @returns A function that resolves the agent to route the email to
|
|
434
|
+
*/
|
|
435
|
+
declare function createHeaderBasedEmailResolver<Env>(): EmailResolver<Env>;
|
|
436
|
+
/**
|
|
437
|
+
* Create a resolver that uses the email address to determine the agent to route the email to
|
|
438
|
+
* @param defaultAgentName The default agent name to use if the email address does not contain a sub-address
|
|
439
|
+
* @returns A function that resolves the agent to route the email to
|
|
440
|
+
*/
|
|
441
|
+
declare function createAddressBasedEmailResolver<Env>(
|
|
442
|
+
defaultAgentName: string
|
|
443
|
+
): EmailResolver<Env>;
|
|
444
|
+
/**
|
|
445
|
+
* Create a resolver that uses the agentName and agentId to determine the agent to route the email to
|
|
446
|
+
* @param agentName The name of the agent to route the email to
|
|
447
|
+
* @param agentId The id of the agent to route the email to
|
|
448
|
+
* @returns A function that resolves the agent to route the email to
|
|
449
|
+
*/
|
|
450
|
+
declare function createCatchAllEmailResolver<Env>(
|
|
451
|
+
agentName: string,
|
|
452
|
+
agentId: string
|
|
453
|
+
): EmailResolver<Env>;
|
|
454
|
+
type EmailRoutingOptions<Env> = AgentOptions<Env> & {
|
|
455
|
+
resolver: EmailResolver<Env>;
|
|
456
|
+
};
|
|
344
457
|
/**
|
|
345
458
|
* Route an email to the appropriate Agent
|
|
346
|
-
* @param email
|
|
347
|
-
* @param env
|
|
348
|
-
* @param options
|
|
459
|
+
* @param email The email to route
|
|
460
|
+
* @param env The environment containing the Agent bindings
|
|
461
|
+
* @param options The options for routing the email
|
|
462
|
+
* @returns A promise that resolves when the email has been routed
|
|
349
463
|
*/
|
|
350
464
|
declare function routeAgentEmail<Env>(
|
|
351
465
|
email: ForwardableEmailMessage,
|
|
352
466
|
env: Env,
|
|
353
|
-
options
|
|
467
|
+
options: EmailRoutingOptions<Env>
|
|
354
468
|
): Promise<void>;
|
|
469
|
+
type AgentEmail = {
|
|
470
|
+
from: string;
|
|
471
|
+
to: string;
|
|
472
|
+
getRaw: () => Promise<Uint8Array>;
|
|
473
|
+
headers: Headers;
|
|
474
|
+
rawSize: number;
|
|
475
|
+
setReject: (reason: string) => void;
|
|
476
|
+
forward: (rcptTo: string, headers?: Headers) => Promise<void>;
|
|
477
|
+
reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
|
|
478
|
+
};
|
|
479
|
+
type EmailSendOptions = {
|
|
480
|
+
to: string;
|
|
481
|
+
subject: string;
|
|
482
|
+
body: string;
|
|
483
|
+
contentType?: string;
|
|
484
|
+
headers?: Record<string, string>;
|
|
485
|
+
includeRoutingHeaders?: boolean;
|
|
486
|
+
agentName?: string;
|
|
487
|
+
agentId?: string;
|
|
488
|
+
domain?: string;
|
|
489
|
+
};
|
|
355
490
|
/**
|
|
356
491
|
* Get or create an Agent by name
|
|
357
492
|
* @template Env Environment type containing bindings
|
|
@@ -392,20 +527,29 @@ declare class StreamingResponse {
|
|
|
392
527
|
export {
|
|
393
528
|
Agent,
|
|
394
529
|
type AgentContext,
|
|
530
|
+
type AgentEmail,
|
|
395
531
|
type AgentNamespace,
|
|
396
532
|
type AgentOptions,
|
|
397
533
|
type CallableMetadata,
|
|
534
|
+
type EmailResolver,
|
|
535
|
+
type EmailRoutingOptions,
|
|
536
|
+
type EmailSendOptions,
|
|
398
537
|
type MCPServer,
|
|
399
538
|
type MCPServerMessage,
|
|
400
539
|
type MCPServersState,
|
|
540
|
+
type QueueItem,
|
|
401
541
|
type RPCRequest,
|
|
402
542
|
type RPCResponse,
|
|
403
543
|
type Schedule,
|
|
404
544
|
type StateUpdateMessage,
|
|
405
545
|
StreamingResponse,
|
|
546
|
+
callable,
|
|
547
|
+
createAddressBasedEmailResolver,
|
|
548
|
+
createCatchAllEmailResolver,
|
|
549
|
+
createHeaderBasedEmailResolver,
|
|
406
550
|
getAgentByName,
|
|
407
551
|
getCurrentAgent,
|
|
408
552
|
routeAgentEmail,
|
|
409
553
|
routeAgentRequest,
|
|
410
|
-
unstable_callable
|
|
554
|
+
unstable_callable
|
|
411
555
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent,
|
|
3
3
|
StreamingResponse,
|
|
4
|
+
callable,
|
|
5
|
+
createAddressBasedEmailResolver,
|
|
6
|
+
createCatchAllEmailResolver,
|
|
7
|
+
createHeaderBasedEmailResolver,
|
|
4
8
|
getAgentByName,
|
|
5
9
|
getCurrentAgent,
|
|
6
10
|
routeAgentEmail,
|
|
7
11
|
routeAgentRequest,
|
|
8
12
|
unstable_callable
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-MWQSU7GK.js";
|
|
14
|
+
import "./chunk-VYENMKFS.js";
|
|
15
|
+
import "./chunk-PVQZBKN7.js";
|
|
16
|
+
import "./chunk-QEVM4BVL.js";
|
|
17
|
+
import "./chunk-AVYJQSLW.js";
|
|
13
18
|
export {
|
|
14
19
|
Agent,
|
|
15
20
|
StreamingResponse,
|
|
21
|
+
callable,
|
|
22
|
+
createAddressBasedEmailResolver,
|
|
23
|
+
createCatchAllEmailResolver,
|
|
24
|
+
createHeaderBasedEmailResolver,
|
|
16
25
|
getAgentByName,
|
|
17
26
|
getCurrentAgent,
|
|
18
27
|
routeAgentEmail,
|