agents 0.0.0-504a24f → 0.0.0-5320b13
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 +157 -27
- package/dist/ai-chat-agent.d.ts +11 -7
- package/dist/ai-chat-agent.js +168 -47
- 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 +61 -70
- package/dist/ai-react.js +144 -37
- 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-767EASBA.js → chunk-LL2AFX7V.js} +5 -2
- package/dist/chunk-LL2AFX7V.js.map +1 -0
- package/dist/{chunk-E3LCYPCB.js → chunk-MH46VMM4.js} +163 -20
- package/dist/chunk-MH46VMM4.js.map +1 -0
- package/dist/{chunk-NKZZ66QY.js → chunk-QEVM4BVL.js} +5 -5
- 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-CGWTDCBQ.js → chunk-YDUDMOL6.js} +607 -102
- package/dist/chunk-YDUDMOL6.js.map +1 -0
- package/dist/client-CvaJdLQA.d.ts +5015 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -1
- package/dist/index.d.ts +172 -20
- 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.d.ts +1 -0
- package/dist/mcp/do-oauth-client-provider.js +1 -1
- package/dist/mcp/index.d.ts +68 -55
- package/dist/mcp/index.js +854 -608
- 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 +9 -5
- package/dist/react.js +7 -5
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +79 -5
- package/dist/schedule.js +15 -2
- package/dist/schedule.js.map +1 -1
- package/package.json +25 -9
- package/src/index.ts +830 -140
- package/dist/chunk-767EASBA.js.map +0 -1
- package/dist/chunk-CGWTDCBQ.js.map +0 -1
- package/dist/chunk-E3LCYPCB.js.map +0 -1
- package/dist/chunk-NKZZ66QY.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,17 +1,21 @@
|
|
|
1
|
+
import { env } from "cloudflare:workers";
|
|
1
2
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
3
|
import {
|
|
3
4
|
ServerCapabilities,
|
|
4
5
|
Tool,
|
|
5
6
|
Prompt,
|
|
6
|
-
Resource
|
|
7
|
+
Resource
|
|
7
8
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
8
9
|
import { Server, Connection, PartyServerOptions } from "partyserver";
|
|
9
10
|
export { Connection, ConnectionContext, WSMessage } from "partyserver";
|
|
10
|
-
import { MCPClientManager } from "./
|
|
11
|
+
import { M as MCPClientManager } from "./client-CvaJdLQA.js";
|
|
12
|
+
import { Observability } from "./observability/index.js";
|
|
13
|
+
import { MessageType } from "./ai-types.js";
|
|
11
14
|
import "zod";
|
|
12
|
-
import "@modelcontextprotocol/sdk/client/sse.js";
|
|
13
15
|
import "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
14
16
|
import "ai";
|
|
17
|
+
import "@modelcontextprotocol/sdk/client/sse.js";
|
|
18
|
+
import "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
15
19
|
import "./mcp/do-oauth-client-provider.js";
|
|
16
20
|
import "@modelcontextprotocol/sdk/client/auth.js";
|
|
17
21
|
import "@modelcontextprotocol/sdk/shared/auth.js";
|
|
@@ -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,23 @@ 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<
|
|
163
|
+
declare class Agent<
|
|
164
|
+
Env = typeof env,
|
|
165
|
+
State = unknown,
|
|
166
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
167
|
+
> extends Server<Env, Props> {
|
|
147
168
|
private _state;
|
|
148
169
|
private _ParentClass;
|
|
149
170
|
mcp: MCPClientManager;
|
|
@@ -163,6 +184,10 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
163
184
|
/** Whether the Agent should hibernate when inactive */
|
|
164
185
|
hibernate: boolean;
|
|
165
186
|
};
|
|
187
|
+
/**
|
|
188
|
+
* The observability implementation to use for the Agent
|
|
189
|
+
*/
|
|
190
|
+
observability?: Observability;
|
|
166
191
|
/**
|
|
167
192
|
* Execute SQL queries against the Agent's database
|
|
168
193
|
* @template T Type of the returned rows
|
|
@@ -188,17 +213,75 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
188
213
|
*/
|
|
189
214
|
onStateUpdate(state: State | undefined, source: Connection | "server"): void;
|
|
190
215
|
/**
|
|
191
|
-
* Called when the Agent receives an email
|
|
216
|
+
* Called when the Agent receives an email via routeAgentEmail()
|
|
217
|
+
* Override this method to handle incoming emails
|
|
192
218
|
* @param email Email message to process
|
|
193
219
|
*/
|
|
194
|
-
|
|
220
|
+
_onEmail(email: AgentEmail): Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Reply to an email
|
|
223
|
+
* @param email The email to reply to
|
|
224
|
+
* @param options Options for the reply
|
|
225
|
+
* @returns void
|
|
226
|
+
*/
|
|
227
|
+
replyToEmail(
|
|
228
|
+
email: AgentEmail,
|
|
229
|
+
options: {
|
|
230
|
+
fromName: string;
|
|
231
|
+
subject?: string | undefined;
|
|
232
|
+
body: string;
|
|
233
|
+
contentType?: string;
|
|
234
|
+
headers?: Record<string, string>;
|
|
235
|
+
}
|
|
236
|
+
): Promise<void>;
|
|
195
237
|
private _tryCatch;
|
|
238
|
+
/**
|
|
239
|
+
* Automatically wrap custom methods with agent context
|
|
240
|
+
* This ensures getCurrentAgent() works in all custom methods without decorators
|
|
241
|
+
*/
|
|
242
|
+
private _autoWrapCustomMethods;
|
|
196
243
|
onError(connection: Connection, error: unknown): void | Promise<void>;
|
|
197
244
|
onError(error: unknown): void | Promise<void>;
|
|
198
245
|
/**
|
|
199
246
|
* Render content (not implemented in base class)
|
|
200
247
|
*/
|
|
201
248
|
render(): void;
|
|
249
|
+
/**
|
|
250
|
+
* Queue a task to be executed in the future
|
|
251
|
+
* @param payload Payload to pass to the callback
|
|
252
|
+
* @param callback Name of the method to call
|
|
253
|
+
* @returns The ID of the queued task
|
|
254
|
+
*/
|
|
255
|
+
queue<T = unknown>(callback: keyof this, payload: T): Promise<string>;
|
|
256
|
+
private _flushingQueue;
|
|
257
|
+
private _flushQueue;
|
|
258
|
+
/**
|
|
259
|
+
* Dequeue a task by ID
|
|
260
|
+
* @param id ID of the task to dequeue
|
|
261
|
+
*/
|
|
262
|
+
dequeue(id: string): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Dequeue all tasks
|
|
265
|
+
*/
|
|
266
|
+
dequeueAll(): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Dequeue all tasks by callback
|
|
269
|
+
* @param callback Name of the callback to dequeue
|
|
270
|
+
*/
|
|
271
|
+
dequeueAllByCallback(callback: string): Promise<void>;
|
|
272
|
+
/**
|
|
273
|
+
* Get a queued task by ID
|
|
274
|
+
* @param id ID of the task to get
|
|
275
|
+
* @returns The task or undefined if not found
|
|
276
|
+
*/
|
|
277
|
+
getQueue(id: string): Promise<QueueItem<string> | undefined>;
|
|
278
|
+
/**
|
|
279
|
+
* Get all queues by key and value
|
|
280
|
+
* @param key Key to filter by
|
|
281
|
+
* @param value Value to filter by
|
|
282
|
+
* @returns Array of matching QueueItem objects
|
|
283
|
+
*/
|
|
284
|
+
getQueues(key: string, value: string): Promise<QueueItem<string>[]>;
|
|
202
285
|
/**
|
|
203
286
|
* Schedule a task to be executed in the future
|
|
204
287
|
* @template T Type of the payload data
|
|
@@ -342,17 +425,72 @@ declare function routeAgentRequest<Env>(
|
|
|
342
425
|
env: Env,
|
|
343
426
|
options?: AgentOptions<Env>
|
|
344
427
|
): Promise<Response | null>;
|
|
428
|
+
type EmailResolver<Env> = (
|
|
429
|
+
email: ForwardableEmailMessage,
|
|
430
|
+
env: Env
|
|
431
|
+
) => Promise<{
|
|
432
|
+
agentName: string;
|
|
433
|
+
agentId: string;
|
|
434
|
+
} | null>;
|
|
435
|
+
/**
|
|
436
|
+
* Create a resolver that uses the message-id header to determine the agent to route the email to
|
|
437
|
+
* @returns A function that resolves the agent to route the email to
|
|
438
|
+
*/
|
|
439
|
+
declare function createHeaderBasedEmailResolver<Env>(): EmailResolver<Env>;
|
|
440
|
+
/**
|
|
441
|
+
* Create a resolver that uses the email address to determine the agent to route the email to
|
|
442
|
+
* @param defaultAgentName The default agent name to use if the email address does not contain a sub-address
|
|
443
|
+
* @returns A function that resolves the agent to route the email to
|
|
444
|
+
*/
|
|
445
|
+
declare function createAddressBasedEmailResolver<Env>(
|
|
446
|
+
defaultAgentName: string
|
|
447
|
+
): EmailResolver<Env>;
|
|
448
|
+
/**
|
|
449
|
+
* Create a resolver that uses the agentName and agentId to determine the agent to route the email to
|
|
450
|
+
* @param agentName The name of the agent to route the email to
|
|
451
|
+
* @param agentId The id of the agent to route the email to
|
|
452
|
+
* @returns A function that resolves the agent to route the email to
|
|
453
|
+
*/
|
|
454
|
+
declare function createCatchAllEmailResolver<Env>(
|
|
455
|
+
agentName: string,
|
|
456
|
+
agentId: string
|
|
457
|
+
): EmailResolver<Env>;
|
|
458
|
+
type EmailRoutingOptions<Env> = AgentOptions<Env> & {
|
|
459
|
+
resolver: EmailResolver<Env>;
|
|
460
|
+
};
|
|
345
461
|
/**
|
|
346
462
|
* Route an email to the appropriate Agent
|
|
347
|
-
* @param email
|
|
348
|
-
* @param env
|
|
349
|
-
* @param options
|
|
463
|
+
* @param email The email to route
|
|
464
|
+
* @param env The environment containing the Agent bindings
|
|
465
|
+
* @param options The options for routing the email
|
|
466
|
+
* @returns A promise that resolves when the email has been routed
|
|
350
467
|
*/
|
|
351
468
|
declare function routeAgentEmail<Env>(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
469
|
+
email: ForwardableEmailMessage,
|
|
470
|
+
env: Env,
|
|
471
|
+
options: EmailRoutingOptions<Env>
|
|
355
472
|
): Promise<void>;
|
|
473
|
+
type AgentEmail = {
|
|
474
|
+
from: string;
|
|
475
|
+
to: string;
|
|
476
|
+
getRaw: () => Promise<Uint8Array>;
|
|
477
|
+
headers: Headers;
|
|
478
|
+
rawSize: number;
|
|
479
|
+
setReject: (reason: string) => void;
|
|
480
|
+
forward: (rcptTo: string, headers?: Headers) => Promise<void>;
|
|
481
|
+
reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
|
|
482
|
+
};
|
|
483
|
+
type EmailSendOptions = {
|
|
484
|
+
to: string;
|
|
485
|
+
subject: string;
|
|
486
|
+
body: string;
|
|
487
|
+
contentType?: string;
|
|
488
|
+
headers?: Record<string, string>;
|
|
489
|
+
includeRoutingHeaders?: boolean;
|
|
490
|
+
agentName?: string;
|
|
491
|
+
agentId?: string;
|
|
492
|
+
domain?: string;
|
|
493
|
+
};
|
|
356
494
|
/**
|
|
357
495
|
* Get or create an Agent by name
|
|
358
496
|
* @template Env Environment type containing bindings
|
|
@@ -362,12 +500,17 @@ declare function routeAgentEmail<Env>(
|
|
|
362
500
|
* @param options Options for Agent creation
|
|
363
501
|
* @returns Promise resolving to an Agent instance stub
|
|
364
502
|
*/
|
|
365
|
-
declare function getAgentByName<
|
|
503
|
+
declare function getAgentByName<
|
|
504
|
+
Env,
|
|
505
|
+
T extends Agent<Env>,
|
|
506
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
507
|
+
>(
|
|
366
508
|
namespace: AgentNamespace<T>,
|
|
367
509
|
name: string,
|
|
368
510
|
options?: {
|
|
369
511
|
jurisdiction?: DurableObjectJurisdiction;
|
|
370
512
|
locationHint?: DurableObjectLocationHint;
|
|
513
|
+
props?: Props;
|
|
371
514
|
}
|
|
372
515
|
): Promise<DurableObjectStub<T>>;
|
|
373
516
|
/**
|
|
@@ -393,20 +536,29 @@ declare class StreamingResponse {
|
|
|
393
536
|
export {
|
|
394
537
|
Agent,
|
|
395
538
|
type AgentContext,
|
|
539
|
+
type AgentEmail,
|
|
396
540
|
type AgentNamespace,
|
|
397
541
|
type AgentOptions,
|
|
398
542
|
type CallableMetadata,
|
|
543
|
+
type EmailResolver,
|
|
544
|
+
type EmailRoutingOptions,
|
|
545
|
+
type EmailSendOptions,
|
|
399
546
|
type MCPServer,
|
|
400
547
|
type MCPServerMessage,
|
|
401
548
|
type MCPServersState,
|
|
549
|
+
type QueueItem,
|
|
402
550
|
type RPCRequest,
|
|
403
551
|
type RPCResponse,
|
|
404
552
|
type Schedule,
|
|
405
553
|
type StateUpdateMessage,
|
|
406
554
|
StreamingResponse,
|
|
555
|
+
callable,
|
|
556
|
+
createAddressBasedEmailResolver,
|
|
557
|
+
createCatchAllEmailResolver,
|
|
558
|
+
createHeaderBasedEmailResolver,
|
|
407
559
|
getAgentByName,
|
|
408
560
|
getCurrentAgent,
|
|
409
561
|
routeAgentEmail,
|
|
410
562
|
routeAgentRequest,
|
|
411
|
-
unstable_callable
|
|
563
|
+
unstable_callable
|
|
412
564
|
};
|
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-YDUDMOL6.js";
|
|
14
|
+
import "./chunk-MH46VMM4.js";
|
|
15
|
+
import "./chunk-LL2AFX7V.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,
|