agents 0.0.0-dfa677f → 0.0.0-e19fea6
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 +255 -27
- package/dist/_esm-LV5FJ3HK.js +3922 -0
- package/dist/_esm-LV5FJ3HK.js.map +1 -0
- package/dist/ai-chat-agent.d.ts +57 -7
- package/dist/ai-chat-agent.js +580 -95
- 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 +20 -0
- package/dist/ai-react.d.ts +78 -67
- package/dist/ai-react.js +287 -120
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.d.ts +41 -18
- package/dist/ai-types.js +7 -0
- package/dist/ccip-CMBYN64O.js +15 -0
- package/dist/ccip-CMBYN64O.js.map +1 -0
- package/dist/chunk-254F4GDT.js +1343 -0
- package/dist/chunk-254F4GDT.js.map +1 -0
- package/dist/chunk-3OT2NNEW.js +941 -0
- package/dist/chunk-3OT2NNEW.js.map +1 -0
- package/dist/chunk-5Y6BEZDY.js +276 -0
- package/dist/chunk-5Y6BEZDY.js.map +1 -0
- package/dist/chunk-BER7KXUJ.js +18 -0
- package/dist/chunk-BER7KXUJ.js.map +1 -0
- package/dist/chunk-JJBFIGUC.js +5202 -0
- package/dist/chunk-JJBFIGUC.js.map +1 -0
- package/dist/chunk-PR4QN5HX.js +43 -0
- package/dist/chunk-PR4QN5HX.js.map +1 -0
- package/dist/chunk-QEVM4BVL.js +116 -0
- package/dist/chunk-QEVM4BVL.js.map +1 -0
- package/dist/chunk-TYAY6AU6.js +159 -0
- package/dist/chunk-TYAY6AU6.js.map +1 -0
- package/dist/chunk-UJVEAURM.js +150 -0
- package/dist/chunk-UJVEAURM.js.map +1 -0
- package/dist/chunk-Z44WASMA.js +114 -0
- package/dist/chunk-Z44WASMA.js.map +1 -0
- package/dist/client-DVoPb3-C.d.ts +5120 -0
- package/dist/client.d.ts +16 -2
- package/dist/client.js +8 -133
- package/dist/client.js.map +1 -1
- package/dist/codemode/ai.d.ts +25 -0
- package/dist/codemode/ai.js +5112 -0
- package/dist/codemode/ai.js.map +1 -0
- package/dist/index.d.ts +275 -27
- package/dist/index.js +18 -8
- package/dist/mcp/client.d.ts +12 -0
- package/dist/mcp/client.js +10 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/do-oauth-client-provider.d.ts +42 -0
- package/dist/mcp/do-oauth-client-provider.js +8 -0
- package/dist/mcp/do-oauth-client-provider.js.map +1 -0
- package/dist/mcp/index.d.ts +79 -0
- package/dist/mcp/index.js +1099 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/x402.d.ts +39 -0
- package/dist/mcp/x402.js +3195 -0
- package/dist/mcp/x402.js.map +1 -0
- package/dist/mcp-BH1fJeiU.d.ts +58 -0
- package/dist/observability/index.d.ts +34 -0
- package/dist/observability/index.js +12 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/react.d.ts +97 -9
- package/dist/react.js +153 -34
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +81 -7
- package/dist/schedule.js +20 -7
- package/dist/schedule.js.map +1 -1
- package/dist/secp256k1-M22GZP2U.js +2193 -0
- package/dist/secp256k1-M22GZP2U.js.map +1 -0
- package/dist/serializable.d.ts +32 -0
- package/dist/serializable.js +1 -0
- package/dist/serializable.js.map +1 -0
- package/package.json +106 -50
- package/src/index.ts +1268 -162
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-KRBQHBPA.js +0 -599
- package/dist/chunk-KRBQHBPA.js.map +0 -1
- package/dist/mcp.d.ts +0 -58
- package/dist/mcp.js +0 -945
- package/dist/mcp.js.map +0 -1
- /package/dist/{chunk-HMLY7DHA.js.map → ai-chat-v5-migration.js.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
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";
|
|
1
9
|
import { Server, Connection, PartyServerOptions } from "partyserver";
|
|
2
10
|
export { Connection, ConnectionContext, WSMessage } from "partyserver";
|
|
3
|
-
import {
|
|
4
|
-
|
|
11
|
+
import {
|
|
12
|
+
e as MCPClientManager,
|
|
13
|
+
T as TransportType,
|
|
14
|
+
f as MCPConnectionState
|
|
15
|
+
} from "./client-DVoPb3-C.js";
|
|
16
|
+
import { Observability } from "./observability/index.js";
|
|
17
|
+
import { MessageType } from "./ai-types.js";
|
|
18
|
+
import "zod";
|
|
19
|
+
import "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
20
|
+
import "ai";
|
|
21
|
+
import "./mcp-BH1fJeiU.js";
|
|
22
|
+
import "@modelcontextprotocol/sdk/client/sse.js";
|
|
23
|
+
import "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
24
|
+
import "./mcp/do-oauth-client-provider.js";
|
|
25
|
+
import "@modelcontextprotocol/sdk/client/auth.js";
|
|
26
|
+
import "@modelcontextprotocol/sdk/shared/auth.js";
|
|
5
27
|
|
|
6
28
|
/**
|
|
7
29
|
* RPC request message from client
|
|
@@ -16,14 +38,14 @@ type RPCRequest = {
|
|
|
16
38
|
* State update message from client
|
|
17
39
|
*/
|
|
18
40
|
type StateUpdateMessage = {
|
|
19
|
-
type:
|
|
41
|
+
type: MessageType.CF_AGENT_STATE;
|
|
20
42
|
state: unknown;
|
|
21
43
|
};
|
|
22
44
|
/**
|
|
23
45
|
* RPC response message to client
|
|
24
46
|
*/
|
|
25
47
|
type RPCResponse = {
|
|
26
|
-
type:
|
|
48
|
+
type: MessageType.RPC;
|
|
27
49
|
id: string;
|
|
28
50
|
} & (
|
|
29
51
|
| {
|
|
@@ -54,16 +76,24 @@ type CallableMetadata = {
|
|
|
54
76
|
* Decorator that marks a method as callable by clients
|
|
55
77
|
* @param metadata Optional metadata about the callable method
|
|
56
78
|
*/
|
|
57
|
-
declare function
|
|
79
|
+
declare function callable(
|
|
58
80
|
metadata?: CallableMetadata
|
|
59
81
|
): <This, Args extends unknown[], Return>(
|
|
60
82
|
target: (this: This, ...args: Args) => Return,
|
|
61
83
|
context: ClassMethodDecoratorContext
|
|
62
84
|
) => (this: This, ...args: Args) => Return;
|
|
63
85
|
/**
|
|
64
|
-
*
|
|
86
|
+
* Decorator that marks a method as callable by clients
|
|
87
|
+
* @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
|
|
88
|
+
* @param metadata Optional metadata about the callable method
|
|
65
89
|
*/
|
|
66
|
-
declare
|
|
90
|
+
declare const unstable_callable: (metadata?: CallableMetadata) => void;
|
|
91
|
+
type QueueItem<T = string> = {
|
|
92
|
+
id: string;
|
|
93
|
+
payload: T;
|
|
94
|
+
callback: keyof Agent<unknown>;
|
|
95
|
+
created_at: number;
|
|
96
|
+
};
|
|
67
97
|
/**
|
|
68
98
|
* Represents a scheduled task within an Agent
|
|
69
99
|
* @template T Type of the payload data
|
|
@@ -99,18 +129,52 @@ type Schedule<T = string> = {
|
|
|
99
129
|
cron: string;
|
|
100
130
|
}
|
|
101
131
|
);
|
|
102
|
-
|
|
103
|
-
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* MCP Server state update message from server -> Client
|
|
135
|
+
*/
|
|
136
|
+
type MCPServerMessage = {
|
|
137
|
+
type: MessageType.CF_AGENT_MCP_SERVERS;
|
|
138
|
+
mcp: MCPServersState;
|
|
139
|
+
};
|
|
140
|
+
type MCPServersState = {
|
|
141
|
+
servers: {
|
|
142
|
+
[id: string]: MCPServer;
|
|
143
|
+
};
|
|
144
|
+
tools: Tool[];
|
|
145
|
+
prompts: Prompt[];
|
|
146
|
+
resources: Resource[];
|
|
147
|
+
};
|
|
148
|
+
type MCPServer = {
|
|
149
|
+
name: string;
|
|
150
|
+
server_url: string;
|
|
151
|
+
auth_url: string | null;
|
|
152
|
+
state: MCPConnectionState;
|
|
153
|
+
instructions: string | null;
|
|
154
|
+
capabilities: ServerCapabilities | null;
|
|
155
|
+
};
|
|
156
|
+
declare function getCurrentAgent<
|
|
157
|
+
T extends Agent<unknown, unknown> = Agent<unknown, unknown>
|
|
158
|
+
>(): {
|
|
159
|
+
agent: T | undefined;
|
|
104
160
|
connection: Connection | undefined;
|
|
105
161
|
request: Request | undefined;
|
|
106
|
-
|
|
162
|
+
email: AgentEmail | undefined;
|
|
163
|
+
};
|
|
107
164
|
/**
|
|
108
165
|
* Base class for creating Agent implementations
|
|
109
166
|
* @template Env Environment type containing bindings
|
|
110
167
|
* @template State State type to store within the Agent
|
|
111
168
|
*/
|
|
112
|
-
declare class Agent<
|
|
113
|
-
|
|
169
|
+
declare class Agent<
|
|
170
|
+
Env = typeof env,
|
|
171
|
+
State = unknown,
|
|
172
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
173
|
+
> extends Server<Env, Props> {
|
|
174
|
+
private _state;
|
|
175
|
+
private _disposables;
|
|
176
|
+
private _ParentClass;
|
|
177
|
+
readonly mcp: MCPClientManager;
|
|
114
178
|
/**
|
|
115
179
|
* Initial state for the Agent
|
|
116
180
|
* Override to provide default state values
|
|
@@ -127,6 +191,10 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
127
191
|
/** Whether the Agent should hibernate when inactive */
|
|
128
192
|
hibernate: boolean;
|
|
129
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* The observability implementation to use for the Agent
|
|
196
|
+
*/
|
|
197
|
+
observability?: Observability;
|
|
130
198
|
/**
|
|
131
199
|
* Execute SQL queries against the Agent's database
|
|
132
200
|
* @template T Type of the returned rows
|
|
@@ -139,6 +207,7 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
139
207
|
...values: (string | number | boolean | null)[]
|
|
140
208
|
): T[];
|
|
141
209
|
constructor(ctx: AgentContext, env: Env);
|
|
210
|
+
private _setStateInternal;
|
|
142
211
|
/**
|
|
143
212
|
* Update the Agent's state
|
|
144
213
|
* @param state New state to set
|
|
@@ -151,16 +220,75 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
151
220
|
*/
|
|
152
221
|
onStateUpdate(state: State | undefined, source: Connection | "server"): void;
|
|
153
222
|
/**
|
|
154
|
-
* Called when the Agent receives an email
|
|
223
|
+
* Called when the Agent receives an email via routeAgentEmail()
|
|
224
|
+
* Override this method to handle incoming emails
|
|
155
225
|
* @param email Email message to process
|
|
156
226
|
*/
|
|
157
|
-
|
|
227
|
+
_onEmail(email: AgentEmail): Promise<void>;
|
|
228
|
+
/**
|
|
229
|
+
* Reply to an email
|
|
230
|
+
* @param email The email to reply to
|
|
231
|
+
* @param options Options for the reply
|
|
232
|
+
* @returns void
|
|
233
|
+
*/
|
|
234
|
+
replyToEmail(
|
|
235
|
+
email: AgentEmail,
|
|
236
|
+
options: {
|
|
237
|
+
fromName: string;
|
|
238
|
+
subject?: string | undefined;
|
|
239
|
+
body: string;
|
|
240
|
+
contentType?: string;
|
|
241
|
+
headers?: Record<string, string>;
|
|
242
|
+
}
|
|
243
|
+
): Promise<void>;
|
|
244
|
+
private _tryCatch;
|
|
245
|
+
/**
|
|
246
|
+
* Automatically wrap custom methods with agent context
|
|
247
|
+
* This ensures getCurrentAgent() works in all custom methods without decorators
|
|
248
|
+
*/
|
|
249
|
+
private _autoWrapCustomMethods;
|
|
158
250
|
onError(connection: Connection, error: unknown): void | Promise<void>;
|
|
159
251
|
onError(error: unknown): void | Promise<void>;
|
|
160
252
|
/**
|
|
161
253
|
* Render content (not implemented in base class)
|
|
162
254
|
*/
|
|
163
255
|
render(): void;
|
|
256
|
+
/**
|
|
257
|
+
* Queue a task to be executed in the future
|
|
258
|
+
* @param payload Payload to pass to the callback
|
|
259
|
+
* @param callback Name of the method to call
|
|
260
|
+
* @returns The ID of the queued task
|
|
261
|
+
*/
|
|
262
|
+
queue<T = unknown>(callback: keyof this, payload: T): Promise<string>;
|
|
263
|
+
private _flushingQueue;
|
|
264
|
+
private _flushQueue;
|
|
265
|
+
/**
|
|
266
|
+
* Dequeue a task by ID
|
|
267
|
+
* @param id ID of the task to dequeue
|
|
268
|
+
*/
|
|
269
|
+
dequeue(id: string): Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* Dequeue all tasks
|
|
272
|
+
*/
|
|
273
|
+
dequeueAll(): Promise<void>;
|
|
274
|
+
/**
|
|
275
|
+
* Dequeue all tasks by callback
|
|
276
|
+
* @param callback Name of the callback to dequeue
|
|
277
|
+
*/
|
|
278
|
+
dequeueAllByCallback(callback: string): Promise<void>;
|
|
279
|
+
/**
|
|
280
|
+
* Get a queued task by ID
|
|
281
|
+
* @param id ID of the task to get
|
|
282
|
+
* @returns The task or undefined if not found
|
|
283
|
+
*/
|
|
284
|
+
getQueue(id: string): Promise<QueueItem<string> | undefined>;
|
|
285
|
+
/**
|
|
286
|
+
* Get all queues by key and value
|
|
287
|
+
* @param key Key to filter by
|
|
288
|
+
* @param value Value to filter by
|
|
289
|
+
* @returns Array of matching QueueItem objects
|
|
290
|
+
*/
|
|
291
|
+
getQueues(key: string, value: string): Promise<QueueItem<string>[]>;
|
|
164
292
|
/**
|
|
165
293
|
* Schedule a task to be executed in the future
|
|
166
294
|
* @template T Type of the payload data
|
|
@@ -188,7 +316,6 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
188
316
|
* @returns Array of matching Schedule objects
|
|
189
317
|
*/
|
|
190
318
|
getSchedules<T = string>(criteria?: {
|
|
191
|
-
description?: string;
|
|
192
319
|
id?: string;
|
|
193
320
|
type?: "scheduled" | "delayed" | "cron";
|
|
194
321
|
timeRange?: {
|
|
@@ -202,15 +329,62 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
|
202
329
|
* @returns true if the task was cancelled, false otherwise
|
|
203
330
|
*/
|
|
204
331
|
cancelSchedule(id: string): Promise<boolean>;
|
|
332
|
+
private _scheduleNextAlarm;
|
|
205
333
|
/**
|
|
206
|
-
* Method called when an alarm fires
|
|
207
|
-
* Executes any scheduled tasks that are due
|
|
334
|
+
* Method called when an alarm fires.
|
|
335
|
+
* Executes any scheduled tasks that are due.
|
|
336
|
+
*
|
|
337
|
+
* @remarks
|
|
338
|
+
* To schedule a task, please use the `this.schedule` method instead.
|
|
339
|
+
* See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
|
|
208
340
|
*/
|
|
209
|
-
alarm()
|
|
341
|
+
readonly alarm: () => Promise<void>;
|
|
210
342
|
/**
|
|
211
343
|
* Destroy the Agent, removing all state and scheduled tasks
|
|
212
344
|
*/
|
|
213
345
|
destroy(): Promise<void>;
|
|
346
|
+
/**
|
|
347
|
+
* Get all methods marked as callable on this Agent
|
|
348
|
+
* @returns A map of method names to their metadata
|
|
349
|
+
*/
|
|
350
|
+
private _isCallable;
|
|
351
|
+
/**
|
|
352
|
+
* Connect to a new MCP Server
|
|
353
|
+
*
|
|
354
|
+
* @param serverName Name of the MCP server
|
|
355
|
+
* @param url MCP Server SSE URL
|
|
356
|
+
* @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
|
|
357
|
+
* @param agentsPrefix agents routing prefix if not using `agents`
|
|
358
|
+
* @param options MCP client and transport options
|
|
359
|
+
* @returns authUrl
|
|
360
|
+
*/
|
|
361
|
+
addMcpServer(
|
|
362
|
+
serverName: string,
|
|
363
|
+
url: string,
|
|
364
|
+
callbackHost?: string,
|
|
365
|
+
agentsPrefix?: string,
|
|
366
|
+
options?: {
|
|
367
|
+
client?: ConstructorParameters<typeof Client>[1];
|
|
368
|
+
transport?: {
|
|
369
|
+
headers?: HeadersInit;
|
|
370
|
+
type?: TransportType;
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
): Promise<{
|
|
374
|
+
id: string;
|
|
375
|
+
authUrl: string | undefined;
|
|
376
|
+
}>;
|
|
377
|
+
private _connectToMcpServerInternal;
|
|
378
|
+
removeMcpServer(id: string): Promise<void>;
|
|
379
|
+
getMcpServers(): MCPServersState;
|
|
380
|
+
private broadcastMcpServers;
|
|
381
|
+
/**
|
|
382
|
+
* Handle OAuth callback response using MCPClientManager configuration
|
|
383
|
+
* @param result OAuth callback result
|
|
384
|
+
* @param request The original request (needed for base URL)
|
|
385
|
+
* @returns Response for the OAuth callback
|
|
386
|
+
*/
|
|
387
|
+
private handleOAuthCallbackResponse;
|
|
214
388
|
}
|
|
215
389
|
/**
|
|
216
390
|
* Namespace for creating Agent instances
|
|
@@ -243,17 +417,72 @@ declare function routeAgentRequest<Env>(
|
|
|
243
417
|
env: Env,
|
|
244
418
|
options?: AgentOptions<Env>
|
|
245
419
|
): Promise<Response | null>;
|
|
420
|
+
type EmailResolver<Env> = (
|
|
421
|
+
email: ForwardableEmailMessage,
|
|
422
|
+
env: Env
|
|
423
|
+
) => Promise<{
|
|
424
|
+
agentName: string;
|
|
425
|
+
agentId: string;
|
|
426
|
+
} | null>;
|
|
427
|
+
/**
|
|
428
|
+
* Create a resolver that uses the message-id header to determine the agent to route the email to
|
|
429
|
+
* @returns A function that resolves the agent to route the email to
|
|
430
|
+
*/
|
|
431
|
+
declare function createHeaderBasedEmailResolver<Env>(): EmailResolver<Env>;
|
|
432
|
+
/**
|
|
433
|
+
* Create a resolver that uses the email address to determine the agent to route the email to
|
|
434
|
+
* @param defaultAgentName The default agent name to use if the email address does not contain a sub-address
|
|
435
|
+
* @returns A function that resolves the agent to route the email to
|
|
436
|
+
*/
|
|
437
|
+
declare function createAddressBasedEmailResolver<Env>(
|
|
438
|
+
defaultAgentName: string
|
|
439
|
+
): EmailResolver<Env>;
|
|
440
|
+
/**
|
|
441
|
+
* Create a resolver that uses the agentName and agentId to determine the agent to route the email to
|
|
442
|
+
* @param agentName The name of the agent to route the email to
|
|
443
|
+
* @param agentId The id of the agent to route the email to
|
|
444
|
+
* @returns A function that resolves the agent to route the email to
|
|
445
|
+
*/
|
|
446
|
+
declare function createCatchAllEmailResolver<Env>(
|
|
447
|
+
agentName: string,
|
|
448
|
+
agentId: string
|
|
449
|
+
): EmailResolver<Env>;
|
|
450
|
+
type EmailRoutingOptions<Env> = AgentOptions<Env> & {
|
|
451
|
+
resolver: EmailResolver<Env>;
|
|
452
|
+
};
|
|
246
453
|
/**
|
|
247
454
|
* Route an email to the appropriate Agent
|
|
248
|
-
* @param email
|
|
249
|
-
* @param env
|
|
250
|
-
* @param options
|
|
455
|
+
* @param email The email to route
|
|
456
|
+
* @param env The environment containing the Agent bindings
|
|
457
|
+
* @param options The options for routing the email
|
|
458
|
+
* @returns A promise that resolves when the email has been routed
|
|
251
459
|
*/
|
|
252
460
|
declare function routeAgentEmail<Env>(
|
|
253
461
|
email: ForwardableEmailMessage,
|
|
254
462
|
env: Env,
|
|
255
|
-
options
|
|
463
|
+
options: EmailRoutingOptions<Env>
|
|
256
464
|
): Promise<void>;
|
|
465
|
+
type AgentEmail = {
|
|
466
|
+
from: string;
|
|
467
|
+
to: string;
|
|
468
|
+
getRaw: () => Promise<Uint8Array>;
|
|
469
|
+
headers: Headers;
|
|
470
|
+
rawSize: number;
|
|
471
|
+
setReject: (reason: string) => void;
|
|
472
|
+
forward: (rcptTo: string, headers?: Headers) => Promise<void>;
|
|
473
|
+
reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
|
|
474
|
+
};
|
|
475
|
+
type EmailSendOptions = {
|
|
476
|
+
to: string;
|
|
477
|
+
subject: string;
|
|
478
|
+
body: string;
|
|
479
|
+
contentType?: string;
|
|
480
|
+
headers?: Record<string, string>;
|
|
481
|
+
includeRoutingHeaders?: boolean;
|
|
482
|
+
agentName?: string;
|
|
483
|
+
agentId?: string;
|
|
484
|
+
domain?: string;
|
|
485
|
+
};
|
|
257
486
|
/**
|
|
258
487
|
* Get or create an Agent by name
|
|
259
488
|
* @template Env Environment type containing bindings
|
|
@@ -263,19 +492,26 @@ declare function routeAgentEmail<Env>(
|
|
|
263
492
|
* @param options Options for Agent creation
|
|
264
493
|
* @returns Promise resolving to an Agent instance stub
|
|
265
494
|
*/
|
|
266
|
-
declare function getAgentByName<
|
|
495
|
+
declare function getAgentByName<
|
|
496
|
+
Env,
|
|
497
|
+
T extends Agent<Env>,
|
|
498
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
499
|
+
>(
|
|
267
500
|
namespace: AgentNamespace<T>,
|
|
268
501
|
name: string,
|
|
269
502
|
options?: {
|
|
270
503
|
jurisdiction?: DurableObjectJurisdiction;
|
|
271
504
|
locationHint?: DurableObjectLocationHint;
|
|
505
|
+
props?: Props;
|
|
272
506
|
}
|
|
273
507
|
): Promise<DurableObjectStub<T>>;
|
|
274
508
|
/**
|
|
275
509
|
* A wrapper for streaming responses in callable methods
|
|
276
510
|
*/
|
|
277
511
|
declare class StreamingResponse {
|
|
278
|
-
|
|
512
|
+
private _connection;
|
|
513
|
+
private _id;
|
|
514
|
+
private _closed;
|
|
279
515
|
constructor(connection: Connection, id: string);
|
|
280
516
|
/**
|
|
281
517
|
* Send a chunk of data to the client
|
|
@@ -292,18 +528,30 @@ declare class StreamingResponse {
|
|
|
292
528
|
export {
|
|
293
529
|
Agent,
|
|
294
530
|
type AgentContext,
|
|
531
|
+
type AgentEmail,
|
|
295
532
|
type AgentNamespace,
|
|
296
533
|
type AgentOptions,
|
|
297
534
|
type CallableMetadata,
|
|
535
|
+
type EmailResolver,
|
|
536
|
+
type EmailRoutingOptions,
|
|
537
|
+
type EmailSendOptions,
|
|
538
|
+
type MCPServer,
|
|
539
|
+
type MCPServerMessage,
|
|
540
|
+
type MCPServersState,
|
|
541
|
+
type QueueItem,
|
|
298
542
|
type RPCRequest,
|
|
299
543
|
type RPCResponse,
|
|
300
544
|
type Schedule,
|
|
301
545
|
type StateUpdateMessage,
|
|
302
546
|
StreamingResponse,
|
|
303
|
-
|
|
547
|
+
TransportType,
|
|
548
|
+
callable,
|
|
549
|
+
createAddressBasedEmailResolver,
|
|
550
|
+
createCatchAllEmailResolver,
|
|
551
|
+
createHeaderBasedEmailResolver,
|
|
304
552
|
getAgentByName,
|
|
553
|
+
getCurrentAgent,
|
|
305
554
|
routeAgentEmail,
|
|
306
555
|
routeAgentRequest,
|
|
307
|
-
unstable_callable
|
|
308
|
-
unstable_context,
|
|
556
|
+
unstable_callable
|
|
309
557
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent,
|
|
3
3
|
StreamingResponse,
|
|
4
|
-
|
|
4
|
+
callable,
|
|
5
|
+
createAddressBasedEmailResolver,
|
|
6
|
+
createCatchAllEmailResolver,
|
|
7
|
+
createHeaderBasedEmailResolver,
|
|
5
8
|
getAgentByName,
|
|
9
|
+
getCurrentAgent,
|
|
6
10
|
routeAgentEmail,
|
|
7
11
|
routeAgentRequest,
|
|
8
|
-
unstable_callable
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import "./chunk-
|
|
12
|
+
unstable_callable
|
|
13
|
+
} from "./chunk-254F4GDT.js";
|
|
14
|
+
import "./chunk-3OT2NNEW.js";
|
|
15
|
+
import "./chunk-Z44WASMA.js";
|
|
16
|
+
import "./chunk-QEVM4BVL.js";
|
|
17
|
+
import "./chunk-BER7KXUJ.js";
|
|
18
|
+
import "./chunk-PR4QN5HX.js";
|
|
12
19
|
export {
|
|
13
20
|
Agent,
|
|
14
21
|
StreamingResponse,
|
|
15
|
-
|
|
22
|
+
callable,
|
|
23
|
+
createAddressBasedEmailResolver,
|
|
24
|
+
createCatchAllEmailResolver,
|
|
25
|
+
createHeaderBasedEmailResolver,
|
|
16
26
|
getAgentByName,
|
|
27
|
+
getCurrentAgent,
|
|
17
28
|
routeAgentEmail,
|
|
18
29
|
routeAgentRequest,
|
|
19
|
-
unstable_callable
|
|
20
|
-
unstable_context
|
|
30
|
+
unstable_callable
|
|
21
31
|
};
|
|
22
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'zod';
|
|
2
|
+
import '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
+
import '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
4
|
+
import '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import 'ai';
|
|
6
|
+
export { e as MCPClientManager, d as MCPClientOAuthCallbackConfig, c as MCPClientOAuthResult, g as getNamespacedData } from '../client-DVoPb3-C.js';
|
|
7
|
+
import '../mcp-BH1fJeiU.js';
|
|
8
|
+
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
9
|
+
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
10
|
+
import './do-oauth-client-provider.js';
|
|
11
|
+
import '@modelcontextprotocol/sdk/client/auth.js';
|
|
12
|
+
import '@modelcontextprotocol/sdk/shared/auth.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
2
|
+
import { OAuthClientMetadata, OAuthClientInformation, OAuthClientInformationFull, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
3
|
+
|
|
4
|
+
interface AgentsOAuthProvider extends OAuthClientProvider {
|
|
5
|
+
authUrl: string | undefined;
|
|
6
|
+
clientId: string | undefined;
|
|
7
|
+
serverId: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
|
|
10
|
+
storage: DurableObjectStorage;
|
|
11
|
+
clientName: string;
|
|
12
|
+
baseRedirectUrl: string;
|
|
13
|
+
private _authUrl_;
|
|
14
|
+
private _serverId_;
|
|
15
|
+
private _clientId_;
|
|
16
|
+
constructor(storage: DurableObjectStorage, clientName: string, baseRedirectUrl: string);
|
|
17
|
+
get clientMetadata(): OAuthClientMetadata;
|
|
18
|
+
get clientUri(): string;
|
|
19
|
+
get redirectUrl(): string;
|
|
20
|
+
get clientId(): string;
|
|
21
|
+
set clientId(clientId_: string);
|
|
22
|
+
get serverId(): string;
|
|
23
|
+
set serverId(serverId_: string);
|
|
24
|
+
keyPrefix(clientId: string): string;
|
|
25
|
+
clientInfoKey(clientId: string): string;
|
|
26
|
+
clientInformation(): Promise<OAuthClientInformation | undefined>;
|
|
27
|
+
saveClientInformation(clientInformation: OAuthClientInformationFull): Promise<void>;
|
|
28
|
+
tokenKey(clientId: string): string;
|
|
29
|
+
tokens(): Promise<OAuthTokens | undefined>;
|
|
30
|
+
saveTokens(tokens: OAuthTokens): Promise<void>;
|
|
31
|
+
get authUrl(): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Because this operates on the server side (but we need browser auth), we send this url back to the user
|
|
34
|
+
* and require user interact to initiate the redirect flow
|
|
35
|
+
*/
|
|
36
|
+
redirectToAuthorization(authUrl: URL): Promise<void>;
|
|
37
|
+
codeVerifierKey(clientId: string): string;
|
|
38
|
+
saveCodeVerifier(verifier: string): Promise<void>;
|
|
39
|
+
codeVerifier(): Promise<string>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { type AgentsOAuthProvider, DurableObjectOAuthClientProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { JSONRPCMessage, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
export { ElicitRequest, ElicitRequestSchema, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { Agent } from '../index.js';
|
|
6
|
+
import { M as MaybePromise, B as BaseTransportType, S as ServeOptions } from '../client-DVoPb3-C.js';
|
|
7
|
+
export { d as MCPClientOAuthCallbackConfig, c as MCPClientOAuthResult, a as SSEEdgeClientTransport, b as StreamableHTTPEdgeClientTransport } from '../client-DVoPb3-C.js';
|
|
8
|
+
import { Connection, ConnectionContext } from 'partyserver';
|
|
9
|
+
import 'cloudflare:workers';
|
|
10
|
+
import '@modelcontextprotocol/sdk/client/index.js';
|
|
11
|
+
import '../observability/index.js';
|
|
12
|
+
import '../mcp-BH1fJeiU.js';
|
|
13
|
+
import '../ai-types.js';
|
|
14
|
+
import 'ai';
|
|
15
|
+
import 'zod';
|
|
16
|
+
import '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
17
|
+
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
18
|
+
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
19
|
+
import './do-oauth-client-provider.js';
|
|
20
|
+
import '@modelcontextprotocol/sdk/client/auth.js';
|
|
21
|
+
import '@modelcontextprotocol/sdk/shared/auth.js';
|
|
22
|
+
|
|
23
|
+
declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
|
|
24
|
+
private _transport?;
|
|
25
|
+
props?: Props;
|
|
26
|
+
abstract server: MaybePromise<McpServer | Server>;
|
|
27
|
+
abstract init(): Promise<void>;
|
|
28
|
+
setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
|
|
29
|
+
getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
|
|
30
|
+
/** Read the transport type for this agent.
|
|
31
|
+
* This relies on the naming scheme being `sse:${sessionId}`
|
|
32
|
+
* or `streamable-http:${sessionId}`.
|
|
33
|
+
*/
|
|
34
|
+
getTransportType(): BaseTransportType;
|
|
35
|
+
/** Read the sessionId for this agent.
|
|
36
|
+
* This relies on the naming scheme being `sse:${sessionId}`
|
|
37
|
+
* or `streamable-http:${sessionId}`.
|
|
38
|
+
*/
|
|
39
|
+
getSessionId(): string;
|
|
40
|
+
/** Get the unique WebSocket. SSE transport only. */
|
|
41
|
+
private getWebSocket;
|
|
42
|
+
/** Returns a new transport matching the type of the Agent. */
|
|
43
|
+
private initTransport;
|
|
44
|
+
/** Update and store the props */
|
|
45
|
+
updateProps(props?: Props): Promise<void>;
|
|
46
|
+
reinitializeServer(): Promise<void>;
|
|
47
|
+
/** Sets up the MCP transport and server every time the Agent is started.*/
|
|
48
|
+
onStart(props?: Props): Promise<void>;
|
|
49
|
+
/** Validates new WebSocket connections. */
|
|
50
|
+
onConnect(conn: Connection, { request: req }: ConnectionContext): Promise<void>;
|
|
51
|
+
/** Handles MCP Messages for the legacy SSE transport. */
|
|
52
|
+
onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
|
|
53
|
+
/** Elicit user input with a message and schema */
|
|
54
|
+
elicitInput(params: {
|
|
55
|
+
message: string;
|
|
56
|
+
requestedSchema: unknown;
|
|
57
|
+
}): Promise<ElicitResult>;
|
|
58
|
+
/** Wait for elicitation response through storage polling */
|
|
59
|
+
private _waitForElicitationResponse;
|
|
60
|
+
/** Handle elicitation responses */
|
|
61
|
+
private _handleElicitationResponse;
|
|
62
|
+
/** Return a handler for the given path for this MCP.
|
|
63
|
+
* Defaults to Streamable HTTP transport.
|
|
64
|
+
*/
|
|
65
|
+
static serve(path: string, { binding, corsOptions, transport }?: ServeOptions): {
|
|
66
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Legacy api
|
|
70
|
+
**/
|
|
71
|
+
static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
|
|
72
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
73
|
+
};
|
|
74
|
+
static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
|
|
75
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { McpAgent };
|