agents 0.0.0-ac74811 → 0.0.0-b123357
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 -3
- package/dist/ai-chat-agent.js +4 -4
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.d.ts +6 -4
- package/dist/ai-react.js.map +1 -1
- package/dist/{chunk-E3LCYPCB.js → chunk-HY7ZLHJB.js} +146 -17
- package/dist/chunk-HY7ZLHJB.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-JFRK72K3.js → chunk-OJFA7RKX.js} +445 -85
- package/dist/chunk-OJFA7RKX.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-CITGJflw.d.ts → index-BCJclX6q.d.ts} +147 -18
- package/dist/index.d.ts +17 -7
- package/dist/index.js +10 -4
- package/dist/mcp/client.d.ts +9 -1053
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/do-oauth-client-provider.js +1 -1
- package/dist/mcp/index.d.ts +24 -7
- package/dist/mcp/index.js +136 -11
- package/dist/mcp/index.js.map +1 -1
- package/dist/observability/index.d.ts +5 -3
- package/dist/observability/index.js +4 -4
- package/dist/react.d.ts +8 -6
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +4 -4
- package/dist/schedule.js.map +1 -1
- package/package.json +7 -6
- package/src/index.ts +667 -137
- package/dist/chunk-767EASBA.js.map +0 -1
- package/dist/chunk-E3LCYPCB.js.map +0 -1
- package/dist/chunk-JFRK72K3.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
|
@@ -1,17 +1,18 @@
|
|
|
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
|
-
import { MCPClientManager } from "./
|
|
10
|
+
import { M as MCPClientManager } from "./client-DgyzBU_8.js";
|
|
10
11
|
import { Message } from "ai";
|
|
11
12
|
|
|
12
13
|
type BaseEvent<
|
|
13
14
|
T extends string,
|
|
14
|
-
Payload extends Record<string, unknown> = {}
|
|
15
|
+
Payload extends Record<string, unknown> = {}
|
|
15
16
|
> = {
|
|
16
17
|
type: T;
|
|
17
18
|
/**
|
|
@@ -140,6 +141,12 @@ declare function unstable_callable(
|
|
|
140
141
|
target: (this: This, ...args: Args) => Return,
|
|
141
142
|
context: ClassMethodDecoratorContext
|
|
142
143
|
) => (this: This, ...args: Args) => Return;
|
|
144
|
+
type QueueItem<T = string> = {
|
|
145
|
+
id: string;
|
|
146
|
+
payload: T;
|
|
147
|
+
callback: keyof Agent<unknown>;
|
|
148
|
+
created_at: number;
|
|
149
|
+
};
|
|
143
150
|
/**
|
|
144
151
|
* Represents a scheduled task within an Agent
|
|
145
152
|
* @template T Type of the payload data
|
|
@@ -199,18 +206,19 @@ type MCPServer = {
|
|
|
199
206
|
capabilities: ServerCapabilities | null;
|
|
200
207
|
};
|
|
201
208
|
declare function getCurrentAgent<
|
|
202
|
-
T extends Agent<unknown, unknown> = Agent<unknown, unknown
|
|
209
|
+
T extends Agent<unknown, unknown> = Agent<unknown, unknown>
|
|
203
210
|
>(): {
|
|
204
211
|
agent: T | undefined;
|
|
205
212
|
connection: Connection | undefined;
|
|
206
|
-
request: Request
|
|
213
|
+
request: Request | undefined;
|
|
214
|
+
email: AgentEmail | undefined;
|
|
207
215
|
};
|
|
208
216
|
/**
|
|
209
217
|
* Base class for creating Agent implementations
|
|
210
218
|
* @template Env Environment type containing bindings
|
|
211
219
|
* @template State State type to store within the Agent
|
|
212
220
|
*/
|
|
213
|
-
declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
221
|
+
declare class Agent<Env = typeof env, State = unknown> extends Server<Env> {
|
|
214
222
|
private _state;
|
|
215
223
|
private _ParentClass;
|
|
216
224
|
mcp: MCPClientManager;
|
|
@@ -259,17 +267,75 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
259
267
|
*/
|
|
260
268
|
onStateUpdate(state: State | undefined, source: Connection | "server"): void;
|
|
261
269
|
/**
|
|
262
|
-
* Called when the Agent receives an email
|
|
270
|
+
* Called when the Agent receives an email via routeAgentEmail()
|
|
271
|
+
* Override this method to handle incoming emails
|
|
263
272
|
* @param email Email message to process
|
|
264
273
|
*/
|
|
265
|
-
|
|
274
|
+
_onEmail(email: AgentEmail): Promise<void>;
|
|
275
|
+
/**
|
|
276
|
+
* Reply to an email
|
|
277
|
+
* @param email The email to reply to
|
|
278
|
+
* @param options Options for the reply
|
|
279
|
+
* @returns void
|
|
280
|
+
*/
|
|
281
|
+
replyToEmail(
|
|
282
|
+
email: AgentEmail,
|
|
283
|
+
options: {
|
|
284
|
+
fromName: string;
|
|
285
|
+
subject?: string | undefined;
|
|
286
|
+
body: string;
|
|
287
|
+
contentType?: string;
|
|
288
|
+
headers?: Record<string, string>;
|
|
289
|
+
}
|
|
290
|
+
): Promise<void>;
|
|
266
291
|
private _tryCatch;
|
|
292
|
+
/**
|
|
293
|
+
* Automatically wrap custom methods with agent context
|
|
294
|
+
* This ensures getCurrentAgent() works in all custom methods without decorators
|
|
295
|
+
*/
|
|
296
|
+
private _autoWrapCustomMethods;
|
|
267
297
|
onError(connection: Connection, error: unknown): void | Promise<void>;
|
|
268
298
|
onError(error: unknown): void | Promise<void>;
|
|
269
299
|
/**
|
|
270
300
|
* Render content (not implemented in base class)
|
|
271
301
|
*/
|
|
272
302
|
render(): void;
|
|
303
|
+
/**
|
|
304
|
+
* Queue a task to be executed in the future
|
|
305
|
+
* @param payload Payload to pass to the callback
|
|
306
|
+
* @param callback Name of the method to call
|
|
307
|
+
* @returns The ID of the queued task
|
|
308
|
+
*/
|
|
309
|
+
queue<T = unknown>(callback: keyof this, payload: T): Promise<string>;
|
|
310
|
+
private _flushingQueue;
|
|
311
|
+
private _flushQueue;
|
|
312
|
+
/**
|
|
313
|
+
* Dequeue a task by ID
|
|
314
|
+
* @param id ID of the task to dequeue
|
|
315
|
+
*/
|
|
316
|
+
dequeue(id: string): Promise<void>;
|
|
317
|
+
/**
|
|
318
|
+
* Dequeue all tasks
|
|
319
|
+
*/
|
|
320
|
+
dequeueAll(): Promise<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Dequeue all tasks by callback
|
|
323
|
+
* @param callback Name of the callback to dequeue
|
|
324
|
+
*/
|
|
325
|
+
dequeueAllByCallback(callback: string): Promise<void>;
|
|
326
|
+
/**
|
|
327
|
+
* Get a queued task by ID
|
|
328
|
+
* @param id ID of the task to get
|
|
329
|
+
* @returns The task or undefined if not found
|
|
330
|
+
*/
|
|
331
|
+
getQueue(id: string): Promise<QueueItem<string> | undefined>;
|
|
332
|
+
/**
|
|
333
|
+
* Get all queues by key and value
|
|
334
|
+
* @param key Key to filter by
|
|
335
|
+
* @param value Value to filter by
|
|
336
|
+
* @returns Array of matching QueueItem objects
|
|
337
|
+
*/
|
|
338
|
+
getQueues(key: string, value: string): Promise<QueueItem<string>[]>;
|
|
273
339
|
/**
|
|
274
340
|
* Schedule a task to be executed in the future
|
|
275
341
|
* @template T Type of the payload data
|
|
@@ -413,17 +479,72 @@ declare function routeAgentRequest<Env>(
|
|
|
413
479
|
env: Env,
|
|
414
480
|
options?: AgentOptions<Env>
|
|
415
481
|
): Promise<Response | null>;
|
|
482
|
+
type EmailResolver<Env> = (
|
|
483
|
+
email: ForwardableEmailMessage,
|
|
484
|
+
env: Env
|
|
485
|
+
) => Promise<{
|
|
486
|
+
agentName: string;
|
|
487
|
+
agentId: string;
|
|
488
|
+
} | null>;
|
|
489
|
+
/**
|
|
490
|
+
* Create a resolver that uses the message-id header to determine the agent to route the email to
|
|
491
|
+
* @returns A function that resolves the agent to route the email to
|
|
492
|
+
*/
|
|
493
|
+
declare function createHeaderBasedEmailResolver<Env>(): EmailResolver<Env>;
|
|
494
|
+
/**
|
|
495
|
+
* Create a resolver that uses the email address to determine the agent to route the email to
|
|
496
|
+
* @param defaultAgentName The default agent name to use if the email address does not contain a sub-address
|
|
497
|
+
* @returns A function that resolves the agent to route the email to
|
|
498
|
+
*/
|
|
499
|
+
declare function createAddressBasedEmailResolver<Env>(
|
|
500
|
+
defaultAgentName: string
|
|
501
|
+
): EmailResolver<Env>;
|
|
502
|
+
/**
|
|
503
|
+
* Create a resolver that uses the agentName and agentId to determine the agent to route the email to
|
|
504
|
+
* @param agentName The name of the agent to route the email to
|
|
505
|
+
* @param agentId The id of the agent to route the email to
|
|
506
|
+
* @returns A function that resolves the agent to route the email to
|
|
507
|
+
*/
|
|
508
|
+
declare function createCatchAllEmailResolver<Env>(
|
|
509
|
+
agentName: string,
|
|
510
|
+
agentId: string
|
|
511
|
+
): EmailResolver<Env>;
|
|
512
|
+
type EmailRoutingOptions<Env> = AgentOptions<Env> & {
|
|
513
|
+
resolver: EmailResolver<Env>;
|
|
514
|
+
};
|
|
416
515
|
/**
|
|
417
516
|
* Route an email to the appropriate Agent
|
|
418
|
-
* @param email
|
|
419
|
-
* @param env
|
|
420
|
-
* @param options
|
|
517
|
+
* @param email The email to route
|
|
518
|
+
* @param env The environment containing the Agent bindings
|
|
519
|
+
* @param options The options for routing the email
|
|
520
|
+
* @returns A promise that resolves when the email has been routed
|
|
421
521
|
*/
|
|
422
522
|
declare function routeAgentEmail<Env>(
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
523
|
+
email: ForwardableEmailMessage,
|
|
524
|
+
env: Env,
|
|
525
|
+
options: EmailRoutingOptions<Env>
|
|
426
526
|
): Promise<void>;
|
|
527
|
+
type AgentEmail = {
|
|
528
|
+
from: string;
|
|
529
|
+
to: string;
|
|
530
|
+
getRaw: () => Promise<Uint8Array>;
|
|
531
|
+
headers: Headers;
|
|
532
|
+
rawSize: number;
|
|
533
|
+
setReject: (reason: string) => void;
|
|
534
|
+
forward: (rcptTo: string, headers?: Headers) => Promise<void>;
|
|
535
|
+
reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
|
|
536
|
+
};
|
|
537
|
+
type EmailSendOptions = {
|
|
538
|
+
to: string;
|
|
539
|
+
subject: string;
|
|
540
|
+
body: string;
|
|
541
|
+
contentType?: string;
|
|
542
|
+
headers?: Record<string, string>;
|
|
543
|
+
includeRoutingHeaders?: boolean;
|
|
544
|
+
agentName?: string;
|
|
545
|
+
agentId?: string;
|
|
546
|
+
domain?: string;
|
|
547
|
+
};
|
|
427
548
|
/**
|
|
428
549
|
* Get or create an Agent by name
|
|
429
550
|
* @template Env Environment type containing bindings
|
|
@@ -464,8 +585,10 @@ declare class StreamingResponse {
|
|
|
464
585
|
export {
|
|
465
586
|
Agent as A,
|
|
466
587
|
type CallableMetadata as C,
|
|
588
|
+
type EmailResolver as E,
|
|
467
589
|
type MCPServersState as M,
|
|
468
590
|
type ObservabilityEvent as O,
|
|
591
|
+
type QueueItem as Q,
|
|
469
592
|
type RPCRequest as R,
|
|
470
593
|
type StateUpdateMessage as S,
|
|
471
594
|
type AgentContext as a,
|
|
@@ -478,9 +601,15 @@ export {
|
|
|
478
601
|
getCurrentAgent as h,
|
|
479
602
|
type AgentNamespace as i,
|
|
480
603
|
type AgentOptions as j,
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
604
|
+
createHeaderBasedEmailResolver as k,
|
|
605
|
+
createAddressBasedEmailResolver as l,
|
|
606
|
+
createCatchAllEmailResolver as m,
|
|
607
|
+
type EmailRoutingOptions as n,
|
|
608
|
+
routeAgentEmail as o,
|
|
609
|
+
type AgentEmail as p,
|
|
610
|
+
type EmailSendOptions as q,
|
|
484
611
|
routeAgentRequest as r,
|
|
485
|
-
|
|
612
|
+
getAgentByName as s,
|
|
613
|
+
StreamingResponse as t,
|
|
614
|
+
unstable_callable as u
|
|
486
615
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,31 +1,41 @@
|
|
|
1
|
+
import "cloudflare:workers";
|
|
1
2
|
import "@modelcontextprotocol/sdk/client/index.js";
|
|
2
3
|
import "@modelcontextprotocol/sdk/types.js";
|
|
3
4
|
export { Connection, ConnectionContext, WSMessage } from "partyserver";
|
|
4
|
-
import "./
|
|
5
|
+
import "./client-DgyzBU_8.js";
|
|
5
6
|
export {
|
|
6
7
|
A as Agent,
|
|
7
8
|
a as AgentContext,
|
|
9
|
+
p as AgentEmail,
|
|
8
10
|
i as AgentNamespace,
|
|
9
11
|
j as AgentOptions,
|
|
10
12
|
C as CallableMetadata,
|
|
13
|
+
E as EmailResolver,
|
|
14
|
+
n as EmailRoutingOptions,
|
|
15
|
+
q as EmailSendOptions,
|
|
11
16
|
f as MCPServer,
|
|
12
17
|
e as MCPServerMessage,
|
|
13
18
|
M as MCPServersState,
|
|
19
|
+
Q as QueueItem,
|
|
14
20
|
R as RPCRequest,
|
|
15
21
|
c as RPCResponse,
|
|
16
22
|
d as Schedule,
|
|
17
23
|
S as StateUpdateMessage,
|
|
18
|
-
|
|
19
|
-
l as
|
|
24
|
+
t as StreamingResponse,
|
|
25
|
+
l as createAddressBasedEmailResolver,
|
|
26
|
+
m as createCatchAllEmailResolver,
|
|
27
|
+
k as createHeaderBasedEmailResolver,
|
|
28
|
+
s as getAgentByName,
|
|
20
29
|
h as getCurrentAgent,
|
|
21
|
-
|
|
30
|
+
o as routeAgentEmail,
|
|
22
31
|
r as routeAgentRequest,
|
|
23
|
-
u as unstable_callable
|
|
24
|
-
} from "./index-
|
|
32
|
+
u as unstable_callable
|
|
33
|
+
} from "./index-BCJclX6q.js";
|
|
25
34
|
import "zod";
|
|
26
|
-
import "@modelcontextprotocol/sdk/client/sse.js";
|
|
27
35
|
import "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
28
36
|
import "ai";
|
|
37
|
+
import "@modelcontextprotocol/sdk/client/sse.js";
|
|
38
|
+
import "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
29
39
|
import "./mcp/do-oauth-client-provider.js";
|
|
30
40
|
import "@modelcontextprotocol/sdk/client/auth.js";
|
|
31
41
|
import "@modelcontextprotocol/sdk/shared/auth.js";
|
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-OJFA7RKX.js";
|
|
13
|
+
import "./chunk-HY7ZLHJB.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,
|