agents 0.0.0-df41827 → 0.0.0-df52d4b
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 +128 -22
- package/dist/ai-chat-agent.d.ts +5 -2
- package/dist/ai-chat-agent.js +24 -4
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.d.ts +6 -3
- package/dist/ai-react.js.map +1 -1
- package/dist/{chunk-ZRRXJUAA.js → chunk-DQJFYHG3.js} +595 -93
- package/dist/chunk-DQJFYHG3.js.map +1 -0
- package/dist/{chunk-E3LCYPCB.js → chunk-EM3J4KV7.js} +147 -18
- package/dist/chunk-EM3J4KV7.js.map +1 -0
- package/dist/{chunk-NKZZ66QY.js → chunk-KUH345EY.js} +1 -1
- package/dist/chunk-KUH345EY.js.map +1 -0
- package/dist/{chunk-767EASBA.js → chunk-PVQZBKN7.js} +1 -1
- package/dist/chunk-PVQZBKN7.js.map +1 -0
- package/dist/client-DgyzBU_8.d.ts +4601 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/index.d.ts +152 -16
- package/dist/index.js +10 -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 +35 -7
- package/dist/mcp/index.js +190 -18
- package/dist/mcp/index.js.map +1 -1
- package/dist/observability/index.d.ts +46 -0
- package/dist/observability/index.js +10 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/react.d.ts +8 -5
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +4 -4
- package/dist/schedule.js.map +1 -1
- package/package.json +34 -26
- package/src/index.ts +799 -134
- package/dist/chunk-767EASBA.js.map +0 -1
- package/dist/chunk-E3LCYPCB.js.map +0 -1
- package/dist/chunk-NKZZ66QY.js.map +0 -1
- package/dist/chunk-ZRRXJUAA.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,20 @@
|
|
|
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-DgyzBU_8.js";
|
|
12
|
+
import { Observability } from "./observability/index.js";
|
|
11
13
|
import "zod";
|
|
12
|
-
import "@modelcontextprotocol/sdk/client/sse.js";
|
|
13
14
|
import "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
14
15
|
import "ai";
|
|
16
|
+
import "@modelcontextprotocol/sdk/client/sse.js";
|
|
17
|
+
import "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
15
18
|
import "./mcp/do-oauth-client-provider.js";
|
|
16
19
|
import "@modelcontextprotocol/sdk/client/auth.js";
|
|
17
20
|
import "@modelcontextprotocol/sdk/shared/auth.js";
|
|
@@ -73,6 +76,12 @@ declare function unstable_callable(
|
|
|
73
76
|
target: (this: This, ...args: Args) => Return,
|
|
74
77
|
context: ClassMethodDecoratorContext
|
|
75
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
|
+
};
|
|
76
85
|
/**
|
|
77
86
|
* Represents a scheduled task within an Agent
|
|
78
87
|
* @template T Type of the payload data
|
|
@@ -132,18 +141,19 @@ type MCPServer = {
|
|
|
132
141
|
capabilities: ServerCapabilities | null;
|
|
133
142
|
};
|
|
134
143
|
declare function getCurrentAgent<
|
|
135
|
-
T extends Agent<unknown, unknown> = Agent<unknown, unknown
|
|
144
|
+
T extends Agent<unknown, unknown> = Agent<unknown, unknown>
|
|
136
145
|
>(): {
|
|
137
146
|
agent: T | undefined;
|
|
138
147
|
connection: Connection | undefined;
|
|
139
|
-
request: Request
|
|
148
|
+
request: Request | undefined;
|
|
149
|
+
email: AgentEmail | undefined;
|
|
140
150
|
};
|
|
141
151
|
/**
|
|
142
152
|
* Base class for creating Agent implementations
|
|
143
153
|
* @template Env Environment type containing bindings
|
|
144
154
|
* @template State State type to store within the Agent
|
|
145
155
|
*/
|
|
146
|
-
declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
156
|
+
declare class Agent<Env = typeof env, State = unknown> extends Server<Env> {
|
|
147
157
|
private _state;
|
|
148
158
|
private _ParentClass;
|
|
149
159
|
mcp: MCPClientManager;
|
|
@@ -163,6 +173,10 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
163
173
|
/** Whether the Agent should hibernate when inactive */
|
|
164
174
|
hibernate: boolean;
|
|
165
175
|
};
|
|
176
|
+
/**
|
|
177
|
+
* The observability implementation to use for the Agent
|
|
178
|
+
*/
|
|
179
|
+
observability?: Observability;
|
|
166
180
|
/**
|
|
167
181
|
* Execute SQL queries against the Agent's database
|
|
168
182
|
* @template T Type of the returned rows
|
|
@@ -188,17 +202,75 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
188
202
|
*/
|
|
189
203
|
onStateUpdate(state: State | undefined, source: Connection | "server"): void;
|
|
190
204
|
/**
|
|
191
|
-
* Called when the Agent receives an email
|
|
205
|
+
* Called when the Agent receives an email via routeAgentEmail()
|
|
206
|
+
* Override this method to handle incoming emails
|
|
192
207
|
* @param email Email message to process
|
|
193
208
|
*/
|
|
194
|
-
|
|
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>;
|
|
195
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;
|
|
196
232
|
onError(connection: Connection, error: unknown): void | Promise<void>;
|
|
197
233
|
onError(error: unknown): void | Promise<void>;
|
|
198
234
|
/**
|
|
199
235
|
* Render content (not implemented in base class)
|
|
200
236
|
*/
|
|
201
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>[]>;
|
|
202
274
|
/**
|
|
203
275
|
* Schedule a task to be executed in the future
|
|
204
276
|
* @template T Type of the payload data
|
|
@@ -283,7 +355,7 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
283
355
|
authUrl: string | undefined;
|
|
284
356
|
}>;
|
|
285
357
|
_connectToMcpServerInternal(
|
|
286
|
-
|
|
358
|
+
_serverName: string,
|
|
287
359
|
url: string,
|
|
288
360
|
callbackUrl: string,
|
|
289
361
|
options?: {
|
|
@@ -306,6 +378,7 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
306
378
|
): Promise<{
|
|
307
379
|
id: string;
|
|
308
380
|
authUrl: string | undefined;
|
|
381
|
+
clientId: string | undefined;
|
|
309
382
|
}>;
|
|
310
383
|
removeMcpServer(id: string): Promise<void>;
|
|
311
384
|
getMcpServers(): MCPServersState;
|
|
@@ -341,17 +414,72 @@ declare function routeAgentRequest<Env>(
|
|
|
341
414
|
env: Env,
|
|
342
415
|
options?: AgentOptions<Env>
|
|
343
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
|
+
};
|
|
344
450
|
/**
|
|
345
451
|
* Route an email to the appropriate Agent
|
|
346
|
-
* @param email
|
|
347
|
-
* @param env
|
|
348
|
-
* @param options
|
|
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
|
|
349
456
|
*/
|
|
350
457
|
declare function routeAgentEmail<Env>(
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
458
|
+
email: ForwardableEmailMessage,
|
|
459
|
+
env: Env,
|
|
460
|
+
options: EmailRoutingOptions<Env>
|
|
354
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
|
+
};
|
|
355
483
|
/**
|
|
356
484
|
* Get or create an Agent by name
|
|
357
485
|
* @template Env Environment type containing bindings
|
|
@@ -392,20 +520,28 @@ declare class StreamingResponse {
|
|
|
392
520
|
export {
|
|
393
521
|
Agent,
|
|
394
522
|
type AgentContext,
|
|
523
|
+
type AgentEmail,
|
|
395
524
|
type AgentNamespace,
|
|
396
525
|
type AgentOptions,
|
|
397
526
|
type CallableMetadata,
|
|
527
|
+
type EmailResolver,
|
|
528
|
+
type EmailRoutingOptions,
|
|
529
|
+
type EmailSendOptions,
|
|
398
530
|
type MCPServer,
|
|
399
531
|
type MCPServerMessage,
|
|
400
532
|
type MCPServersState,
|
|
533
|
+
type QueueItem,
|
|
401
534
|
type RPCRequest,
|
|
402
535
|
type RPCResponse,
|
|
403
536
|
type Schedule,
|
|
404
537
|
type StateUpdateMessage,
|
|
405
538
|
StreamingResponse,
|
|
539
|
+
createAddressBasedEmailResolver,
|
|
540
|
+
createCatchAllEmailResolver,
|
|
541
|
+
createHeaderBasedEmailResolver,
|
|
406
542
|
getAgentByName,
|
|
407
543
|
getCurrentAgent,
|
|
408
544
|
routeAgentEmail,
|
|
409
545
|
routeAgentRequest,
|
|
410
|
-
unstable_callable
|
|
546
|
+
unstable_callable
|
|
411
547
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent,
|
|
3
3
|
StreamingResponse,
|
|
4
|
+
createAddressBasedEmailResolver,
|
|
5
|
+
createCatchAllEmailResolver,
|
|
6
|
+
createHeaderBasedEmailResolver,
|
|
4
7
|
getAgentByName,
|
|
5
8
|
getCurrentAgent,
|
|
6
9
|
routeAgentEmail,
|
|
7
10
|
routeAgentRequest,
|
|
8
11
|
unstable_callable
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-DQJFYHG3.js";
|
|
13
|
+
import "./chunk-EM3J4KV7.js";
|
|
14
|
+
import "./chunk-PVQZBKN7.js";
|
|
15
|
+
import "./chunk-KUH345EY.js";
|
|
13
16
|
export {
|
|
14
17
|
Agent,
|
|
15
18
|
StreamingResponse,
|
|
19
|
+
createAddressBasedEmailResolver,
|
|
20
|
+
createCatchAllEmailResolver,
|
|
21
|
+
createHeaderBasedEmailResolver,
|
|
16
22
|
getAgentByName,
|
|
17
23
|
getCurrentAgent,
|
|
18
24
|
routeAgentEmail,
|