agents 0.0.0-bfc9c75 → 0.0.0-bfe9e3d

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 (60) hide show
  1. package/dist/_esm-LV5FJ3HK.js +3922 -0
  2. package/dist/_esm-LV5FJ3HK.js.map +1 -0
  3. package/dist/ai-chat-agent.d.ts +2 -1
  4. package/dist/ai-chat-agent.js +350 -57
  5. package/dist/ai-chat-agent.js.map +1 -1
  6. package/dist/ai-chat-v5-migration.js +1 -0
  7. package/dist/ai-react.d.ts +8 -1
  8. package/dist/ai-react.js +157 -111
  9. package/dist/ai-react.js.map +1 -1
  10. package/dist/ai-types.d.ts +1 -0
  11. package/dist/ai-types.js +2 -1
  12. package/dist/ccip-CMBYN64O.js +15 -0
  13. package/dist/ccip-CMBYN64O.js.map +1 -0
  14. package/dist/{chunk-YDUDMOL6.js → chunk-254F4GDT.js} +97 -50
  15. package/dist/chunk-254F4GDT.js.map +1 -0
  16. package/dist/{chunk-MH46VMM4.js → chunk-3OT2NNEW.js} +396 -67
  17. package/dist/chunk-3OT2NNEW.js.map +1 -0
  18. package/dist/chunk-5Y6BEZDY.js +276 -0
  19. package/dist/chunk-5Y6BEZDY.js.map +1 -0
  20. package/dist/{chunk-AVYJQSLW.js → chunk-BER7KXUJ.js} +2 -1
  21. package/dist/chunk-BER7KXUJ.js.map +1 -0
  22. package/dist/chunk-JJBFIGUC.js +5202 -0
  23. package/dist/chunk-JJBFIGUC.js.map +1 -0
  24. package/dist/chunk-PR4QN5HX.js +43 -0
  25. package/dist/chunk-PR4QN5HX.js.map +1 -0
  26. package/dist/chunk-TYAY6AU6.js +159 -0
  27. package/dist/chunk-TYAY6AU6.js.map +1 -0
  28. package/dist/{chunk-LL2AFX7V.js → chunk-Z44WASMA.js} +7 -2
  29. package/dist/{chunk-LL2AFX7V.js.map → chunk-Z44WASMA.js.map} +1 -1
  30. package/dist/{client-CvaJdLQA.d.ts → client-DVoPb3-C.d.ts} +131 -26
  31. package/dist/client.js +2 -1
  32. package/dist/codemode/ai.d.ts +25 -0
  33. package/dist/codemode/ai.js +5112 -0
  34. package/dist/codemode/ai.js.map +1 -0
  35. package/dist/index.d.ts +25 -32
  36. package/dist/index.js +5 -4
  37. package/dist/mcp/client.d.ts +2 -1
  38. package/dist/mcp/client.js +2 -1
  39. package/dist/mcp/do-oauth-client-provider.js +2 -1
  40. package/dist/mcp/index.d.ts +13 -31
  41. package/dist/mcp/index.js +233 -163
  42. package/dist/mcp/index.js.map +1 -1
  43. package/dist/mcp/x402.d.ts +39 -0
  44. package/dist/mcp/x402.js +3195 -0
  45. package/dist/mcp/x402.js.map +1 -0
  46. package/dist/mcp-BH1fJeiU.d.ts +58 -0
  47. package/dist/observability/index.d.ts +12 -24
  48. package/dist/observability/index.js +5 -4
  49. package/dist/react.d.ts +10 -6
  50. package/dist/react.js +101 -3
  51. package/dist/react.js.map +1 -1
  52. package/dist/schedule.js +2 -0
  53. package/dist/schedule.js.map +1 -1
  54. package/dist/secp256k1-M22GZP2U.js +2193 -0
  55. package/dist/secp256k1-M22GZP2U.js.map +1 -0
  56. package/package.json +19 -6
  57. package/src/index.ts +141 -57
  58. package/dist/chunk-AVYJQSLW.js.map +0 -1
  59. package/dist/chunk-MH46VMM4.js.map +0 -1
  60. package/dist/chunk-YDUDMOL6.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-CvaJdLQA.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";
@@ -124,6 +129,7 @@ type Schedule<T = string> = {
124
129
  cron: string;
125
130
  }
126
131
  );
132
+
127
133
  /**
128
134
  * MCP Server state update message from server -> Client
129
135
  */
@@ -143,7 +149,7 @@ type MCPServer = {
143
149
  name: string;
144
150
  server_url: string;
145
151
  auth_url: string | null;
146
- state: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
152
+ state: MCPConnectionState;
147
153
  instructions: string | null;
148
154
  capabilities: ServerCapabilities | null;
149
155
  };
@@ -166,8 +172,9 @@ declare class Agent<
166
172
  Props extends Record<string, unknown> = Record<string, unknown>
167
173
  > extends Server<Env, Props> {
168
174
  private _state;
175
+ private _disposables;
169
176
  private _ParentClass;
170
- mcp: MCPClientManager;
177
+ readonly mcp: MCPClientManager;
171
178
  /**
172
179
  * Initial state for the Agent
173
180
  * Override to provide default state values
@@ -344,55 +351,40 @@ declare class Agent<
344
351
  /**
345
352
  * Connect to a new MCP Server
346
353
  *
354
+ * @param serverName Name of the MCP server
347
355
  * @param url MCP Server SSE URL
348
- * @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.
349
357
  * @param agentsPrefix agents routing prefix if not using `agents`
350
- * @param options MCP client and transport (header) options
358
+ * @param options MCP client and transport options
351
359
  * @returns authUrl
352
360
  */
353
361
  addMcpServer(
354
362
  serverName: string,
355
363
  url: string,
356
- callbackHost: string,
364
+ callbackHost?: string,
357
365
  agentsPrefix?: string,
358
366
  options?: {
359
367
  client?: ConstructorParameters<typeof Client>[1];
360
- transport?: {
361
- headers: HeadersInit;
362
- };
363
- }
364
- ): Promise<{
365
- id: string;
366
- authUrl: string | undefined;
367
- }>;
368
- _connectToMcpServerInternal(
369
- _serverName: string,
370
- url: string,
371
- callbackUrl: string,
372
- options?: {
373
- client?: ConstructorParameters<typeof Client>[1];
374
- /**
375
- * We don't expose the normal set of transport options because:
376
- * 1) we can't serialize things like the auth provider or a fetch function into the DB for reconnection purposes
377
- * 2) We probably want these options to be agnostic to the transport type (SSE vs Streamable)
378
- *
379
- * 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).
380
- */
381
368
  transport?: {
382
369
  headers?: HeadersInit;
370
+ type?: TransportType;
383
371
  };
384
- },
385
- reconnect?: {
386
- id: string;
387
- oauthClientId?: string;
388
372
  }
389
373
  ): Promise<{
390
374
  id: string;
391
375
  authUrl: string | undefined;
392
- clientId: string | undefined;
393
376
  }>;
377
+ private _connectToMcpServerInternal;
394
378
  removeMcpServer(id: string): Promise<void>;
395
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;
396
388
  }
397
389
  /**
398
390
  * Namespace for creating Agent instances
@@ -552,6 +544,7 @@ export {
552
544
  type Schedule,
553
545
  type StateUpdateMessage,
554
546
  StreamingResponse,
547
+ TransportType,
555
548
  callable,
556
549
  createAddressBasedEmailResolver,
557
550
  createCatchAllEmailResolver,
package/dist/index.js CHANGED
@@ -10,11 +10,12 @@ import {
10
10
  routeAgentEmail,
11
11
  routeAgentRequest,
12
12
  unstable_callable
13
- } from "./chunk-YDUDMOL6.js";
14
- import "./chunk-MH46VMM4.js";
15
- import "./chunk-LL2AFX7V.js";
13
+ } from "./chunk-254F4GDT.js";
14
+ import "./chunk-3OT2NNEW.js";
15
+ import "./chunk-Z44WASMA.js";
16
16
  import "./chunk-QEVM4BVL.js";
17
- import "./chunk-AVYJQSLW.js";
17
+ import "./chunk-BER7KXUJ.js";
18
+ import "./chunk-PR4QN5HX.js";
18
19
  export {
19
20
  Agent,
20
21
  StreamingResponse,
@@ -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-CvaJdLQA.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-MH46VMM4.js";
4
+ } from "../chunk-3OT2NNEW.js";
5
+ import "../chunk-PR4QN5HX.js";
5
6
  export {
6
7
  MCPClientManager,
7
8
  getNamespacedData
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  DurableObjectOAuthClientProvider
3
- } from "../chunk-LL2AFX7V.js";
3
+ } from "../chunk-Z44WASMA.js";
4
+ import "../chunk-PR4QN5HX.js";
4
5
  export {
5
6
  DurableObjectOAuthClientProvider
6
7
  };
@@ -2,12 +2,14 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
2
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import { JSONRPCMessage, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
4
4
  export { ElicitRequest, ElicitRequestSchema, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
5
- import { Agent, AgentContext } from '../index.js';
6
- export { S as SSEEdgeClientTransport, a as StreamableHTTPEdgeClientTransport } from '../client-CvaJdLQA.js';
7
- import { Connection, ConnectionContext, WSMessage } from 'partyserver';
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';
8
9
  import 'cloudflare:workers';
9
10
  import '@modelcontextprotocol/sdk/client/index.js';
10
11
  import '../observability/index.js';
12
+ import '../mcp-BH1fJeiU.js';
11
13
  import '../ai-types.js';
12
14
  import 'ai';
13
15
  import 'zod';
@@ -18,54 +20,34 @@ import './do-oauth-client-provider.js';
18
20
  import '@modelcontextprotocol/sdk/client/auth.js';
19
21
  import '@modelcontextprotocol/sdk/shared/auth.js';
20
22
 
21
- type MaybePromise<T> = T | Promise<T>;
22
- type TransportType = "sse" | "streamable-http";
23
- interface CORSOptions {
24
- origin?: string;
25
- methods?: string;
26
- headers?: string;
27
- maxAge?: number;
28
- exposeHeaders?: string;
29
- }
30
- interface ServeOptions {
31
- binding?: string;
32
- corsOptions?: CORSOptions;
33
- transport?: TransportType;
34
- }
35
-
36
23
  declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
37
24
  private _transport?;
38
- private _requestIdToConnectionId;
39
- private _standaloneSseConnectionId?;
40
25
  props?: Props;
41
26
  abstract server: MaybePromise<McpServer | Server>;
42
27
  abstract init(): Promise<void>;
43
- constructor(ctx: AgentContext, env: Env);
44
28
  setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
45
29
  getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
46
30
  /** Read the transport type for this agent.
47
31
  * This relies on the naming scheme being `sse:${sessionId}`
48
32
  * or `streamable-http:${sessionId}`.
49
33
  */
50
- getTransportType(): TransportType;
51
- /** Get the WebSocket for the standalone SSE if any. Streamable HTTP only. */
52
- private getWebSocketForStandaloneSse;
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;
53
40
  /** Get the unique WebSocket. SSE transport only. */
54
41
  private getWebSocket;
55
- /** Get the corresponding WebSocket for a responseId. Streamable HTTP only. */
56
- private getWebSocketForResponseID;
57
42
  /** Returns a new transport matching the type of the Agent. */
58
43
  private initTransport;
59
44
  /** Update and store the props */
60
45
  updateProps(props?: Props): Promise<void>;
46
+ reinitializeServer(): Promise<void>;
61
47
  /** Sets up the MCP transport and server every time the Agent is started.*/
62
48
  onStart(props?: Props): Promise<void>;
63
49
  /** Validates new WebSocket connections. */
64
- onConnect(conn: Connection, _: ConnectionContext): Promise<void>;
65
- /** Handles MCP Messages for Streamable HTTP. */
66
- onMessage(connection: Connection, event: WSMessage): Promise<void>;
67
- /** Remove clients from our cache when they disconnect */
68
- onClose(conn: Connection, _code: number, _reason: string, _wasClean: boolean): Promise<void>;
50
+ onConnect(conn: Connection, { request: req }: ConnectionContext): Promise<void>;
69
51
  /** Handles MCP Messages for the legacy SSE transport. */
70
52
  onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
71
53
  /** Elicit user input with a message and schema */