agents 0.0.0-cebd0de → 0.0.0-ced3b22

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 +157 -27
  2. package/dist/ai-chat-agent.d.ts +56 -7
  3. package/dist/ai-chat-agent.js +276 -93
  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 +180 -66
  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 +282 -26
  29. package/dist/index.js +17 -8
  30. package/dist/mcp/client.d.ts +11 -714
  31. package/dist/mcp/client.js +3 -465
  32. package/dist/mcp/client.js.map +1 -1
  33. package/dist/mcp/do-oauth-client-provider.d.ts +42 -0
  34. package/dist/mcp/do-oauth-client-provider.js +7 -0
  35. package/dist/mcp/do-oauth-client-provider.js.map +1 -0
  36. package/dist/mcp/index.d.ts +83 -30
  37. package/dist/mcp/index.js +949 -260
  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 +40 -26
  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 +88 -52
  52. package/src/index.ts +1184 -156
  53. package/dist/chunk-HMLY7DHA.js +0 -16
  54. package/dist/chunk-YMUU7QHV.js +0 -595
  55. package/dist/chunk-YMUU7QHV.js.map +0 -1
  56. /package/dist/{chunk-HMLY7DHA.js.map → ai-chat-v5-migration.js.map} +0 -0
@@ -1,43 +1,96 @@
1
- import { DurableObject } from 'cloudflare:workers';
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
2
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import { Connection } from 'partyserver';
3
+ import { 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';
4
20
 
21
+ type MaybePromise<T> = T | Promise<T>;
22
+ type TransportType = "sse" | "streamable-http";
5
23
  interface CORSOptions {
6
24
  origin?: string;
7
25
  methods?: string;
8
26
  headers?: string;
9
27
  maxAge?: number;
28
+ exposeHeaders?: string;
10
29
  }
11
- declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
12
- #private;
13
- /**
14
- * Agents API allowlist
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>;
42
+ abstract init(): Promise<void>;
43
+ constructor(ctx: AgentContext, env: Env);
44
+ setInitialized(): Promise<void>;
45
+ isInitialized(): Promise<boolean>;
46
+ /** Read the transport type for this agent.
47
+ * This relies on the naming scheme being `sse:${sessionId}`
48
+ * or `streamable-http:${sessionId}`.
15
49
  */
16
- initialState: State;
17
- get state(): State;
18
- sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
19
- setState(state: State): void;
20
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
21
- onStart(): Promise<void>;
22
- /**
23
- * McpAgent API
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. */
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>;
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.
24
82
  */
25
- abstract server: McpServer;
26
- props: Props;
27
- initRun: boolean;
28
- abstract init(): Promise<void>;
29
- _init(props: Props): Promise<void>;
30
- fetch(request: Request): Promise<Response>;
31
- getWebSocket(): WebSocket | null;
32
- onMCPMessage(sessionId: string, request: Request): Promise<Response>;
33
- webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
34
- webSocketError(ws: WebSocket, error: unknown): Promise<void>;
35
- webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
36
- static mount(path: string, { binding, corsOptions, }?: {
37
- binding?: string;
38
- corsOptions?: CORSOptions;
39
- }): {
40
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response | undefined>;
83
+ static serve(path: string, { binding, corsOptions, transport }?: ServeOptions): {
84
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
85
+ };
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>;
91
+ };
92
+ static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
93
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
41
94
  };
42
95
  }
43
96