agents 0.0.0-ecf8926 → 0.0.0-ed3f94d

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.
Files changed (64) hide show
  1. package/README.md +126 -4
  2. package/dist/_esm-LV5FJ3HK.js +3922 -0
  3. package/dist/_esm-LV5FJ3HK.js.map +1 -0
  4. package/dist/ai-chat-agent.d.ts +2 -1
  5. package/dist/ai-chat-agent.js +391 -76
  6. package/dist/ai-chat-agent.js.map +1 -1
  7. package/dist/ai-chat-v5-migration.js +1 -0
  8. package/dist/ai-react.d.ts +8 -1
  9. package/dist/ai-react.js +157 -111
  10. package/dist/ai-react.js.map +1 -1
  11. package/dist/ai-types.d.ts +1 -0
  12. package/dist/ai-types.js +2 -1
  13. package/dist/ccip-CMBYN64O.js +15 -0
  14. package/dist/ccip-CMBYN64O.js.map +1 -0
  15. package/dist/{chunk-EGCWEPQL.js → chunk-254F4GDT.js} +151 -98
  16. package/dist/chunk-254F4GDT.js.map +1 -0
  17. package/dist/{chunk-DS7BJNPH.js → chunk-3OT2NNEW.js} +411 -68
  18. package/dist/chunk-3OT2NNEW.js.map +1 -0
  19. package/dist/chunk-5Y6BEZDY.js +276 -0
  20. package/dist/chunk-5Y6BEZDY.js.map +1 -0
  21. package/dist/{chunk-AVYJQSLW.js → chunk-BER7KXUJ.js} +2 -1
  22. package/dist/chunk-BER7KXUJ.js.map +1 -0
  23. package/dist/chunk-JJBFIGUC.js +5202 -0
  24. package/dist/chunk-JJBFIGUC.js.map +1 -0
  25. package/dist/chunk-PR4QN5HX.js +43 -0
  26. package/dist/chunk-PR4QN5HX.js.map +1 -0
  27. package/dist/chunk-TYAY6AU6.js +159 -0
  28. package/dist/chunk-TYAY6AU6.js.map +1 -0
  29. package/dist/{chunk-PVQZBKN7.js → chunk-Z44WASMA.js} +11 -3
  30. package/dist/chunk-Z44WASMA.js.map +1 -0
  31. package/dist/{client-BAqDHqAV.d.ts → client-DVoPb3-C.d.ts} +549 -30
  32. package/dist/client.js +2 -1
  33. package/dist/codemode/ai.d.ts +25 -0
  34. package/dist/codemode/ai.js +5112 -0
  35. package/dist/codemode/ai.js.map +1 -0
  36. package/dist/index.d.ts +44 -35
  37. package/dist/index.js +7 -4
  38. package/dist/mcp/client.d.ts +2 -1
  39. package/dist/mcp/client.js +2 -1
  40. package/dist/mcp/do-oauth-client-provider.d.ts +1 -0
  41. package/dist/mcp/do-oauth-client-provider.js +2 -1
  42. package/dist/mcp/index.d.ts +50 -83
  43. package/dist/mcp/index.js +903 -760
  44. package/dist/mcp/index.js.map +1 -1
  45. package/dist/mcp/x402.d.ts +39 -0
  46. package/dist/mcp/x402.js +3195 -0
  47. package/dist/mcp/x402.js.map +1 -0
  48. package/dist/mcp-BH1fJeiU.d.ts +58 -0
  49. package/dist/observability/index.d.ts +12 -24
  50. package/dist/observability/index.js +5 -4
  51. package/dist/react.d.ts +10 -6
  52. package/dist/react.js +101 -3
  53. package/dist/react.js.map +1 -1
  54. package/dist/schedule.d.ts +76 -2
  55. package/dist/schedule.js +17 -2
  56. package/dist/schedule.js.map +1 -1
  57. package/dist/secp256k1-M22GZP2U.js +2193 -0
  58. package/dist/secp256k1-M22GZP2U.js.map +1 -0
  59. package/package.json +22 -7
  60. package/src/index.ts +226 -116
  61. package/dist/chunk-AVYJQSLW.js.map +0 -1
  62. package/dist/chunk-DS7BJNPH.js.map +0 -1
  63. package/dist/chunk-EGCWEPQL.js.map +0 -1
  64. package/dist/chunk-PVQZBKN7.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -8,12 +8,17 @@ import {
8
8
  } from "@modelcontextprotocol/sdk/types.js";
9
9
  import { Server, Connection, PartyServerOptions } from "partyserver";
10
10
  export { Connection, ConnectionContext, WSMessage } from "partyserver";
11
- import { M as MCPClientManager } from "./client-BAqDHqAV.js";
11
+ import {
12
+ e as MCPClientManager,
13
+ T as TransportType,
14
+ f as MCPConnectionState
15
+ } from "./client-DVoPb3-C.js";
12
16
  import { Observability } from "./observability/index.js";
13
17
  import { MessageType } from "./ai-types.js";
14
18
  import "zod";
15
19
  import "@modelcontextprotocol/sdk/shared/protocol.js";
16
20
  import "ai";
21
+ import "./mcp-BH1fJeiU.js";
17
22
  import "@modelcontextprotocol/sdk/client/sse.js";
18
23
  import "@modelcontextprotocol/sdk/client/streamableHttp.js";
19
24
  import "./mcp/do-oauth-client-provider.js";
@@ -71,12 +76,18 @@ type CallableMetadata = {
71
76
  * Decorator that marks a method as callable by clients
72
77
  * @param metadata Optional metadata about the callable method
73
78
  */
74
- declare function unstable_callable(
79
+ declare function callable(
75
80
  metadata?: CallableMetadata
76
81
  ): <This, Args extends unknown[], Return>(
77
82
  target: (this: This, ...args: Args) => Return,
78
83
  context: ClassMethodDecoratorContext
79
84
  ) => (this: This, ...args: Args) => Return;
85
+ /**
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
89
+ */
90
+ declare const unstable_callable: (metadata?: CallableMetadata) => void;
80
91
  type QueueItem<T = string> = {
81
92
  id: string;
82
93
  payload: T;
@@ -118,6 +129,7 @@ type Schedule<T = string> = {
118
129
  cron: string;
119
130
  }
120
131
  );
132
+
121
133
  /**
122
134
  * MCP Server state update message from server -> Client
123
135
  */
@@ -137,7 +149,7 @@ type MCPServer = {
137
149
  name: string;
138
150
  server_url: string;
139
151
  auth_url: string | null;
140
- state: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
152
+ state: MCPConnectionState;
141
153
  instructions: string | null;
142
154
  capabilities: ServerCapabilities | null;
143
155
  };
@@ -154,10 +166,15 @@ declare function getCurrentAgent<
154
166
  * @template Env Environment type containing bindings
155
167
  * @template State State type to store within the Agent
156
168
  */
157
- declare class Agent<Env = typeof env, State = unknown> extends Server<Env> {
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> {
158
174
  private _state;
175
+ private _disposables;
159
176
  private _ParentClass;
160
- mcp: MCPClientManager;
177
+ readonly mcp: MCPClientManager;
161
178
  /**
162
179
  * Initial state for the Agent
163
180
  * Override to provide default state values
@@ -334,55 +351,40 @@ declare class Agent<Env = typeof env, State = unknown> extends Server<Env> {
334
351
  /**
335
352
  * Connect to a new MCP Server
336
353
  *
354
+ * @param serverName Name of the MCP server
337
355
  * @param url MCP Server SSE URL
338
- * @param callbackHost Base host for the agent, used for the redirect URI.
356
+ * @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
339
357
  * @param agentsPrefix agents routing prefix if not using `agents`
340
- * @param options MCP client and transport (header) options
358
+ * @param options MCP client and transport options
341
359
  * @returns authUrl
342
360
  */
343
361
  addMcpServer(
344
362
  serverName: string,
345
363
  url: string,
346
- callbackHost: string,
364
+ callbackHost?: string,
347
365
  agentsPrefix?: string,
348
366
  options?: {
349
367
  client?: ConstructorParameters<typeof Client>[1];
350
- transport?: {
351
- headers: HeadersInit;
352
- };
353
- }
354
- ): Promise<{
355
- id: string;
356
- authUrl: string | undefined;
357
- }>;
358
- _connectToMcpServerInternal(
359
- _serverName: string,
360
- url: string,
361
- callbackUrl: string,
362
- options?: {
363
- client?: ConstructorParameters<typeof Client>[1];
364
- /**
365
- * We don't expose the normal set of transport options because:
366
- * 1) we can't serialize things like the auth provider or a fetch function into the DB for reconnection purposes
367
- * 2) We probably want these options to be agnostic to the transport type (SSE vs Streamable)
368
- *
369
- * This has the limitation that you can't override fetch, but I think headers should handle nearly all cases needed (i.e. non-standard bearer auth).
370
- */
371
368
  transport?: {
372
369
  headers?: HeadersInit;
370
+ type?: TransportType;
373
371
  };
374
- },
375
- reconnect?: {
376
- id: string;
377
- oauthClientId?: string;
378
372
  }
379
373
  ): Promise<{
380
374
  id: string;
381
375
  authUrl: string | undefined;
382
- clientId: string | undefined;
383
376
  }>;
377
+ private _connectToMcpServerInternal;
384
378
  removeMcpServer(id: string): Promise<void>;
385
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;
386
388
  }
387
389
  /**
388
390
  * Namespace for creating Agent instances
@@ -490,12 +492,17 @@ type EmailSendOptions = {
490
492
  * @param options Options for Agent creation
491
493
  * @returns Promise resolving to an Agent instance stub
492
494
  */
493
- declare function getAgentByName<Env, T extends Agent<Env>>(
495
+ declare function getAgentByName<
496
+ Env,
497
+ T extends Agent<Env>,
498
+ Props extends Record<string, unknown> = Record<string, unknown>
499
+ >(
494
500
  namespace: AgentNamespace<T>,
495
501
  name: string,
496
502
  options?: {
497
503
  jurisdiction?: DurableObjectJurisdiction;
498
504
  locationHint?: DurableObjectLocationHint;
505
+ props?: Props;
499
506
  }
500
507
  ): Promise<DurableObjectStub<T>>;
501
508
  /**
@@ -537,6 +544,8 @@ export {
537
544
  type Schedule,
538
545
  type StateUpdateMessage,
539
546
  StreamingResponse,
547
+ TransportType,
548
+ callable,
540
549
  createAddressBasedEmailResolver,
541
550
  createCatchAllEmailResolver,
542
551
  createHeaderBasedEmailResolver,
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  Agent,
3
3
  StreamingResponse,
4
+ callable,
4
5
  createAddressBasedEmailResolver,
5
6
  createCatchAllEmailResolver,
6
7
  createHeaderBasedEmailResolver,
@@ -9,14 +10,16 @@ import {
9
10
  routeAgentEmail,
10
11
  routeAgentRequest,
11
12
  unstable_callable
12
- } from "./chunk-EGCWEPQL.js";
13
- import "./chunk-DS7BJNPH.js";
14
- import "./chunk-PVQZBKN7.js";
13
+ } from "./chunk-254F4GDT.js";
14
+ import "./chunk-3OT2NNEW.js";
15
+ import "./chunk-Z44WASMA.js";
15
16
  import "./chunk-QEVM4BVL.js";
16
- import "./chunk-AVYJQSLW.js";
17
+ import "./chunk-BER7KXUJ.js";
18
+ import "./chunk-PR4QN5HX.js";
17
19
  export {
18
20
  Agent,
19
21
  StreamingResponse,
22
+ callable,
20
23
  createAddressBasedEmailResolver,
21
24
  createCatchAllEmailResolver,
22
25
  createHeaderBasedEmailResolver,
@@ -3,7 +3,8 @@ import '@modelcontextprotocol/sdk/client/index.js';
3
3
  import '@modelcontextprotocol/sdk/shared/protocol.js';
4
4
  import '@modelcontextprotocol/sdk/types.js';
5
5
  import 'ai';
6
- export { M as MCPClientManager, g as getNamespacedData } from '../client-BAqDHqAV.js';
6
+ export { e as MCPClientManager, d as MCPClientOAuthCallbackConfig, c as MCPClientOAuthResult, g as getNamespacedData } from '../client-DVoPb3-C.js';
7
+ import '../mcp-BH1fJeiU.js';
7
8
  import '@modelcontextprotocol/sdk/client/sse.js';
8
9
  import '@modelcontextprotocol/sdk/client/streamableHttp.js';
9
10
  import './do-oauth-client-provider.js';
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  MCPClientManager,
3
3
  getNamespacedData
4
- } from "../chunk-DS7BJNPH.js";
4
+ } from "../chunk-3OT2NNEW.js";
5
+ import "../chunk-PR4QN5HX.js";
5
6
  export {
6
7
  MCPClientManager,
7
8
  getNamespacedData
@@ -15,6 +15,7 @@ declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
15
15
  private _clientId_;
16
16
  constructor(storage: DurableObjectStorage, clientName: string, baseRedirectUrl: string);
17
17
  get clientMetadata(): OAuthClientMetadata;
18
+ get clientUri(): string;
18
19
  get redirectUrl(): string;
19
20
  get clientId(): string;
20
21
  set clientId(clientId_: string);
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  DurableObjectOAuthClientProvider
3
- } from "../chunk-PVQZBKN7.js";
3
+ } from "../chunk-Z44WASMA.js";
4
+ import "../chunk-PR4QN5HX.js";
4
5
  export {
5
6
  DurableObjectOAuthClientProvider
6
7
  };
@@ -1,110 +1,77 @@
1
- import { M as MCPClientManager } from '../client-BAqDHqAV.js';
2
- export { S as SSEEdgeClientTransport, a as StreamableHTTPEdgeClientTransport } from '../client-BAqDHqAV.js';
3
- import { DurableObject } from 'cloudflare:workers';
4
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
5
2
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
6
- import { ElicitResult } from '@modelcontextprotocol/sdk/types.js';
3
+ import { JSONRPCMessage, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
7
4
  export { ElicitRequest, ElicitRequestSchema, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
8
- import { Connection, WSMessage } from 'partyserver';
9
- import 'zod';
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
10
  import '@modelcontextprotocol/sdk/client/index.js';
11
- import '@modelcontextprotocol/sdk/shared/protocol.js';
11
+ import '../observability/index.js';
12
+ import '../mcp-BH1fJeiU.js';
13
+ import '../ai-types.js';
12
14
  import 'ai';
15
+ import 'zod';
16
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
13
17
  import '@modelcontextprotocol/sdk/client/sse.js';
14
18
  import '@modelcontextprotocol/sdk/client/streamableHttp.js';
15
19
  import './do-oauth-client-provider.js';
16
20
  import '@modelcontextprotocol/sdk/client/auth.js';
17
21
  import '@modelcontextprotocol/sdk/shared/auth.js';
18
22
 
19
- interface CORSOptions {
20
- origin?: string;
21
- methods?: string;
22
- headers?: string;
23
- maxAge?: number;
24
- exposeHeaders?: string;
25
- }
26
- type MaybePromise<T> = T | Promise<T>;
27
- declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
28
- private _status;
23
+ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
29
24
  private _transport?;
30
- private _transportType;
31
- private _requestIdToConnectionId;
32
- /**
33
- * Since McpAgent's _aren't_ yet real "Agents", let's only expose a couple of the methods
34
- * to the outer class: initialState/state/setState/onStateUpdate/sql
35
- */
36
- private _agent;
37
- get mcp(): MCPClientManager;
38
- protected constructor(ctx: DurableObjectState, env: Env);
39
- /**
40
- * Agents API allowlist
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}`.
41
33
  */
42
- initialState: State;
43
- get state(): State;
44
- sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
45
- setState(state: State): void;
46
- /**
47
- * Elicit user input with a message and schema
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}`.
48
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 */
49
54
  elicitInput(params: {
50
55
  message: string;
51
56
  requestedSchema: unknown;
52
57
  }): Promise<ElicitResult>;
53
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
54
- onStart(): Promise<void>;
55
- /**
56
- * McpAgent API
57
- */
58
- abstract server: MaybePromise<McpServer | Server>;
59
- props: Props;
60
- initRun: boolean;
61
- abstract init(): Promise<void>;
62
- /**
63
- * Handle errors that occur during initialization or operation.
64
- * Override this method to provide custom error handling.
65
- * @param error - The error that occurred
66
- * @returns An error response object with status code and message
67
- */
68
- onError(error: Error): {
69
- status: number;
70
- message: string;
71
- };
72
- _init(props: Props): Promise<void>;
73
- setInitialized(): Promise<void>;
74
- isInitialized(): Promise<boolean>;
75
- updateProps(props: Props): Promise<void>;
76
- private _initialize;
77
- fetch(request: Request): Promise<Response>;
78
- getWebSocket(): WebSocket | null;
79
- getWebSocketForResponseID(id: string): WebSocket | null;
80
- onMessage(connection: Connection, event: WSMessage): Promise<void>;
81
- /**
82
- * Wait for elicitation response through storage polling
83
- */
58
+ /** Wait for elicitation response through storage polling */
84
59
  private _waitForElicitationResponse;
85
- /**
86
- * Handle elicitation responses */
60
+ /** Handle elicitation responses */
87
61
  private _handleElicitationResponse;
88
- onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
89
- webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
90
- webSocketError(ws: WebSocket, error: unknown): Promise<void>;
91
- webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
92
- static mount(path: string, { binding, corsOptions }?: {
93
- binding?: string;
94
- corsOptions?: CORSOptions;
95
- }): {
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): {
96
66
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
97
67
  };
98
- static serveSSE(path: string, { binding, corsOptions }?: {
99
- binding?: string;
100
- corsOptions?: CORSOptions;
101
- }): {
68
+ /**
69
+ * Legacy api
70
+ **/
71
+ static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
102
72
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
103
73
  };
104
- static serve(path: string, { binding, corsOptions }?: {
105
- binding?: string;
106
- corsOptions?: CORSOptions;
107
- }): {
74
+ static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
108
75
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
109
76
  };
110
77
  }