agents 0.0.0-be4b7a3 → 0.0.0-bfc9c75

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 (56) hide show
  1. package/README.md +255 -27
  2. package/dist/ai-chat-agent.d.ts +54 -8
  3. package/dist/ai-chat-agent.js +281 -90
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration.d.ts +152 -0
  6. package/dist/ai-chat-v5-migration.js +19 -0
  7. package/dist/ai-react.d.ts +71 -67
  8. package/dist/ai-react.js +166 -53
  9. package/dist/ai-react.js.map +1 -1
  10. package/dist/ai-types.d.ts +40 -18
  11. package/dist/ai-types.js +6 -0
  12. package/dist/chunk-AVYJQSLW.js +17 -0
  13. package/dist/chunk-AVYJQSLW.js.map +1 -0
  14. package/dist/chunk-LL2AFX7V.js +109 -0
  15. package/dist/chunk-LL2AFX7V.js.map +1 -0
  16. package/dist/chunk-MH46VMM4.js +612 -0
  17. package/dist/chunk-MH46VMM4.js.map +1 -0
  18. package/dist/chunk-QEVM4BVL.js +116 -0
  19. package/dist/chunk-QEVM4BVL.js.map +1 -0
  20. package/dist/chunk-UJVEAURM.js +150 -0
  21. package/dist/chunk-UJVEAURM.js.map +1 -0
  22. package/dist/chunk-YDUDMOL6.js +1296 -0
  23. package/dist/chunk-YDUDMOL6.js.map +1 -0
  24. package/dist/client-CvaJdLQA.d.ts +5015 -0
  25. package/dist/client.d.ts +16 -2
  26. package/dist/client.js +7 -126
  27. package/dist/client.js.map +1 -1
  28. package/dist/index.d.ts +284 -22
  29. package/dist/index.js +17 -6
  30. package/dist/mcp/client.d.ts +9 -761
  31. package/dist/mcp/client.js +3 -402
  32. package/dist/mcp/client.js.map +1 -1
  33. package/dist/mcp/do-oauth-client-provider.d.ts +4 -3
  34. package/dist/mcp/do-oauth-client-provider.js +3 -103
  35. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  36. package/dist/mcp/index.d.ts +81 -46
  37. package/dist/mcp/index.js +892 -641
  38. package/dist/mcp/index.js.map +1 -1
  39. package/dist/observability/index.d.ts +46 -0
  40. package/dist/observability/index.js +11 -0
  41. package/dist/observability/index.js.map +1 -0
  42. package/dist/react.d.ts +89 -5
  43. package/dist/react.js +23 -9
  44. package/dist/react.js.map +1 -1
  45. package/dist/schedule.d.ts +81 -7
  46. package/dist/schedule.js +19 -8
  47. package/dist/schedule.js.map +1 -1
  48. package/dist/serializable.d.ts +32 -0
  49. package/dist/serializable.js +1 -0
  50. package/dist/serializable.js.map +1 -0
  51. package/package.json +85 -67
  52. package/src/index.ts +1187 -152
  53. package/dist/chunk-HMLY7DHA.js +0 -16
  54. package/dist/chunk-XG52S6YY.js +0 -591
  55. package/dist/chunk-XG52S6YY.js.map +0 -1
  56. /package/dist/{chunk-HMLY7DHA.js.map → ai-chat-v5-migration.js.map} +0 -0
@@ -1,61 +1,96 @@
1
- import { DurableObject } from 'cloudflare:workers';
2
- import { Connection, WSMessage } from 'partyserver';
3
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
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, AgentContext } from '../index.js';
6
+ export { S as SSEEdgeClientTransport, a as StreamableHTTPEdgeClientTransport } from '../client-CvaJdLQA.js';
7
+ import { Connection, ConnectionContext, WSMessage } from 'partyserver';
8
+ import 'cloudflare:workers';
9
+ import '@modelcontextprotocol/sdk/client/index.js';
10
+ import '../observability/index.js';
11
+ import '../ai-types.js';
12
+ import 'ai';
13
+ import 'zod';
14
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
15
+ import '@modelcontextprotocol/sdk/client/sse.js';
16
+ import '@modelcontextprotocol/sdk/client/streamableHttp.js';
17
+ import './do-oauth-client-provider.js';
18
+ import '@modelcontextprotocol/sdk/client/auth.js';
19
+ import '@modelcontextprotocol/sdk/shared/auth.js';
5
20
 
21
+ type MaybePromise<T> = T | Promise<T>;
22
+ type TransportType = "sse" | "streamable-http";
6
23
  interface CORSOptions {
7
24
  origin?: string;
8
25
  methods?: string;
9
26
  headers?: string;
10
27
  maxAge?: number;
28
+ exposeHeaders?: string;
11
29
  }
12
- declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
13
- #private;
14
- protected constructor(ctx: DurableObjectState, env: Env);
15
- /**
16
- * Agents API allowlist
17
- */
18
- initialState: State;
19
- get state(): State;
20
- sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
21
- setState(state: State): void;
22
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
23
- onStart(): Promise<void>;
24
- /**
25
- * McpAgent API
26
- */
27
- abstract server: McpServer | Server;
28
- props: Props;
29
- initRun: boolean;
30
+ interface ServeOptions {
31
+ binding?: string;
32
+ corsOptions?: CORSOptions;
33
+ transport?: TransportType;
34
+ }
35
+
36
+ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
37
+ private _transport?;
38
+ private _requestIdToConnectionId;
39
+ private _standaloneSseConnectionId?;
40
+ props?: Props;
41
+ abstract server: MaybePromise<McpServer | Server>;
30
42
  abstract init(): Promise<void>;
31
- _init(props: Props): Promise<void>;
32
- setInitialized(): Promise<void>;
33
- isInitialized(): Promise<boolean>;
34
- fetch(request: Request): Promise<Response>;
35
- getWebSocket(): WebSocket | null;
36
- getWebSocketForResponseID(id: string): WebSocket | null;
43
+ constructor(ctx: AgentContext, env: Env);
44
+ setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
45
+ getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
46
+ /** Read the transport type for this agent.
47
+ * This relies on the naming scheme being `sse:${sessionId}`
48
+ * or `streamable-http:${sessionId}`.
49
+ */
50
+ getTransportType(): TransportType;
51
+ /** Get the WebSocket for the standalone SSE if any. Streamable HTTP only. */
52
+ private getWebSocketForStandaloneSse;
53
+ /** Get the unique WebSocket. SSE transport only. */
54
+ private getWebSocket;
55
+ /** Get the corresponding WebSocket for a responseId. Streamable HTTP only. */
56
+ private getWebSocketForResponseID;
57
+ /** Returns a new transport matching the type of the Agent. */
58
+ private initTransport;
59
+ /** Update and store the props */
60
+ updateProps(props?: Props): Promise<void>;
61
+ /** Sets up the MCP transport and server every time the Agent is started.*/
62
+ onStart(props?: Props): Promise<void>;
63
+ /** Validates new WebSocket connections. */
64
+ onConnect(conn: Connection, _: ConnectionContext): Promise<void>;
65
+ /** Handles MCP Messages for Streamable HTTP. */
37
66
  onMessage(connection: Connection, event: WSMessage): Promise<void>;
38
- onSSEMcpMessage(sessionId: string, request: Request): Promise<Error | null>;
39
- webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
40
- webSocketError(ws: WebSocket, error: unknown): Promise<void>;
41
- webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
42
- static mount(path: string, { binding, corsOptions, }?: {
43
- binding?: string;
44
- corsOptions?: CORSOptions;
45
- }): {
46
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
67
+ /** Remove clients from our cache when they disconnect */
68
+ onClose(conn: Connection, _code: number, _reason: string, _wasClean: boolean): Promise<void>;
69
+ /** Handles MCP Messages for the legacy SSE transport. */
70
+ onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
71
+ /** Elicit user input with a message and schema */
72
+ elicitInput(params: {
73
+ message: string;
74
+ requestedSchema: unknown;
75
+ }): Promise<ElicitResult>;
76
+ /** Wait for elicitation response through storage polling */
77
+ private _waitForElicitationResponse;
78
+ /** Handle elicitation responses */
79
+ private _handleElicitationResponse;
80
+ /** Return a handler for the given path for this MCP.
81
+ * Defaults to Streamable HTTP transport.
82
+ */
83
+ static serve(path: string, { binding, corsOptions, transport }?: ServeOptions): {
84
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
47
85
  };
48
- static serveSSE(path: string, { binding, corsOptions, }?: {
49
- binding?: string;
50
- corsOptions?: CORSOptions;
51
- }): {
52
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
86
+ /**
87
+ * Legacy api
88
+ **/
89
+ static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
90
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
53
91
  };
54
- static serve(path: string, { binding, corsOptions, }?: {
55
- binding?: string;
56
- corsOptions?: CORSOptions;
57
- }): {
58
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
92
+ static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
93
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
59
94
  };
60
95
  }
61
96