agents 0.0.0-1e060d3 → 0.0.0-1e3b8c9

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 (73) hide show
  1. package/README.md +255 -27
  2. package/dist/ai-chat-agent.d.ts +56 -11
  3. package/dist/ai-chat-agent.js +532 -160
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration-DBHGW4Hv.js +155 -0
  6. package/dist/ai-chat-v5-migration-DBHGW4Hv.js.map +1 -0
  7. package/dist/ai-chat-v5-migration.d.ts +155 -0
  8. package/dist/ai-chat-v5-migration.js +3 -0
  9. package/dist/ai-react.d.ts +73 -72
  10. package/dist/ai-react.js +261 -188
  11. package/dist/ai-react.js.map +1 -1
  12. package/dist/ai-types-B3aQaFv3.js +20 -0
  13. package/dist/ai-types-B3aQaFv3.js.map +1 -0
  14. package/dist/ai-types-D5YoPrBZ.d.ts +95 -0
  15. package/dist/ai-types.d.ts +6 -69
  16. package/dist/ai-types.js +3 -1
  17. package/dist/cli.d.ts +8 -0
  18. package/dist/cli.js +27 -0
  19. package/dist/cli.js.map +1 -0
  20. package/dist/client-BfiZ3HQd.js +117 -0
  21. package/dist/client-BfiZ3HQd.js.map +1 -0
  22. package/dist/client-CbWe9FBd.d.ts +104 -0
  23. package/dist/client-CdzqBQ6O.d.ts +5283 -0
  24. package/dist/client-DZhjV_XA.js +719 -0
  25. package/dist/client-DZhjV_XA.js.map +1 -0
  26. package/dist/client.d.ts +12 -79
  27. package/dist/client.js +3 -130
  28. package/dist/codemode/ai.d.ts +27 -0
  29. package/dist/codemode/ai.js +151 -0
  30. package/dist/codemode/ai.js.map +1 -0
  31. package/dist/do-oauth-client-provider-CswoD5Lu.js +93 -0
  32. package/dist/do-oauth-client-provider-CswoD5Lu.js.map +1 -0
  33. package/dist/do-oauth-client-provider-DGc5pP0l.d.ts +55 -0
  34. package/dist/index-Bm_SHmgc.d.ts +560 -0
  35. package/dist/index-DhJCaDWd.d.ts +58 -0
  36. package/dist/index.d.ts +63 -295
  37. package/dist/index.js +7 -20
  38. package/dist/mcp/client.d.ts +4 -763
  39. package/dist/mcp/client.js +2 -407
  40. package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
  41. package/dist/mcp/do-oauth-client-provider.js +2 -106
  42. package/dist/mcp/index.d.ts +167 -57
  43. package/dist/mcp/index.js +1390 -762
  44. package/dist/mcp/index.js.map +1 -1
  45. package/dist/mcp/x402.d.ts +34 -0
  46. package/dist/mcp/x402.js +194 -0
  47. package/dist/mcp/x402.js.map +1 -0
  48. package/dist/mcp-Dw5vDrY8.d.ts +61 -0
  49. package/dist/observability/index.d.ts +3 -0
  50. package/dist/observability/index.js +7 -0
  51. package/dist/react-DV2yB3Bt.d.ts +115 -0
  52. package/dist/react.d.ts +10 -39
  53. package/dist/react.js +183 -98
  54. package/dist/react.js.map +1 -1
  55. package/dist/schedule.d.ts +89 -12
  56. package/dist/schedule.js +46 -23
  57. package/dist/schedule.js.map +1 -1
  58. package/dist/serializable-CymX8ovI.d.ts +39 -0
  59. package/dist/serializable.d.ts +7 -0
  60. package/dist/serializable.js +1 -0
  61. package/dist/src-CwIW7tU2.js +1216 -0
  62. package/dist/src-CwIW7tU2.js.map +1 -0
  63. package/package.json +116 -56
  64. package/dist/ai-types.js.map +0 -1
  65. package/dist/chunk-HMLY7DHA.js +0 -16
  66. package/dist/chunk-HMLY7DHA.js.map +0 -1
  67. package/dist/chunk-XG52S6YY.js +0 -591
  68. package/dist/chunk-XG52S6YY.js.map +0 -1
  69. package/dist/client.js.map +0 -1
  70. package/dist/index.js.map +0 -1
  71. package/dist/mcp/client.js.map +0 -1
  72. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  73. package/src/index.ts +0 -912
@@ -1,60 +1,170 @@
1
- import { DurableObject } from 'cloudflare:workers';
2
- import { Connection, WSMessage } from 'partyserver';
3
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
1
+ import { c as MaybePromise, l as ServeOptions, n as MCPClientOAuthCallbackConfig, o as BaseTransportType, r as MCPClientOAuthResult, s as CORSOptions } from "../client-CdzqBQ6O.js";
2
+ import "../mcp-Dw5vDrY8.js";
3
+ import "../do-oauth-client-provider-DGc5pP0l.js";
4
+ import "../index-DhJCaDWd.js";
5
+ import "../ai-types-D5YoPrBZ.js";
6
+ import { c as ConnectionContext, s as Connection, t as Agent } from "../index-Bm_SHmgc.js";
7
+ import { SSEClientTransport, SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
8
+ import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
9
+ import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
10
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
11
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
12
+ import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
4
13
 
5
- interface CORSOptions {
6
- origin?: string;
7
- methods?: string;
8
- headers?: string;
9
- maxAge?: number;
14
+ //#region src/mcp/client-transports.d.ts
15
+ /**
16
+ * @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
17
+ */
18
+ declare class SSEEdgeClientTransport extends SSEClientTransport {
19
+ constructor(url: URL, options: SSEClientTransportOptions);
10
20
  }
11
- declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
12
- #private;
13
- protected constructor(ctx: DurableObjectState, env: Env);
14
- /**
15
- * Agents API allowlist
16
- */
17
- initialState: State;
18
- get state(): State;
19
- sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
20
- setState(state: State): void;
21
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
22
- onStart(): Promise<void>;
23
- /**
24
- * McpAgent API
25
- */
26
- abstract server: McpServer;
27
- props: Props;
28
- initRun: boolean;
29
- abstract init(): Promise<void>;
30
- _init(props: Props): Promise<void>;
31
- isInitialized(): boolean;
32
- fetch(request: Request): Promise<Response>;
33
- getWebSocket(): WebSocket | null;
34
- getWebSocketForResponseID(id: string): WebSocket | null;
35
- onMessage(connection: Connection, event: WSMessage): Promise<void>;
36
- onSSEMcpMessage(sessionId: string, request: Request): Promise<Error | null>;
37
- webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
38
- webSocketError(ws: WebSocket, error: unknown): Promise<void>;
39
- webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
40
- static mount(path: string, { binding, corsOptions, }?: {
41
- binding?: string;
42
- corsOptions?: CORSOptions;
43
- }): {
44
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
45
- };
46
- static serveSSE(path: string, { binding, corsOptions, }?: {
47
- binding?: string;
48
- corsOptions?: CORSOptions;
49
- }): {
50
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
51
- };
52
- static serve(path: string, { binding, corsOptions, }?: {
53
- binding?: string;
54
- corsOptions?: CORSOptions;
55
- }): {
56
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
57
- };
21
+ /**
22
+ * @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. This alias will be removed in the next major version.
23
+ */
24
+ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
25
+ constructor(url: URL, options: StreamableHTTPClientTransportOptions);
58
26
  }
59
-
60
- export { McpAgent };
27
+ //#endregion
28
+ //#region src/mcp/worker-transport.d.ts
29
+ interface WorkerTransportOptions {
30
+ sessionIdGenerator?: () => string;
31
+ enableJsonResponse?: boolean;
32
+ onsessioninitialized?: (sessionId: string) => void;
33
+ corsOptions?: CORSOptions;
34
+ }
35
+ declare class WorkerTransport implements Transport {
36
+ private started;
37
+ private initialized;
38
+ private sessionIdGenerator?;
39
+ private enableJsonResponse;
40
+ private onsessioninitialized?;
41
+ private standaloneSseStreamId;
42
+ private streamMapping;
43
+ private requestToStreamMapping;
44
+ private requestResponseMap;
45
+ private corsOptions?;
46
+ private protocolVersion?;
47
+ sessionId?: string;
48
+ onclose?: () => void;
49
+ onerror?: (error: Error) => void;
50
+ onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
51
+ constructor(options?: WorkerTransportOptions);
52
+ start(): Promise<void>;
53
+ private validateProtocolVersion;
54
+ private getHeaders;
55
+ handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
56
+ private handleGetRequest;
57
+ private handlePostRequest;
58
+ private handleDeleteRequest;
59
+ private handleOptionsRequest;
60
+ private handleUnsupportedRequest;
61
+ private validateSession;
62
+ close(): Promise<void>;
63
+ send(message: JSONRPCMessage): Promise<void>;
64
+ }
65
+ //#endregion
66
+ //#region src/mcp/handler.d.ts
67
+ interface CreateMcpHandlerOptions extends WorkerTransportOptions {
68
+ /**
69
+ * The route path that this MCP handler should respond to.
70
+ * If specified, the handler will only process requests that match this route.
71
+ * @default "/mcp"
72
+ */
73
+ route?: string;
74
+ /**
75
+ * CORS configuration options for handling cross-origin requests.
76
+ * These options are passed to the WorkerTransport which handles adding
77
+ * CORS headers to all responses.
78
+ *
79
+ * Default values are:
80
+ * - origin: "*"
81
+ * - headers: "Content-Type, Accept, Authorization, mcp-session-id, MCP-Protocol-Version"
82
+ * - methods: "GET, POST, DELETE, OPTIONS"
83
+ * - exposeHeaders: "mcp-session-id"
84
+ * - maxAge: 86400
85
+ *
86
+ * Provided options will overwrite the defaults.
87
+ */
88
+ corsOptions?: CORSOptions;
89
+ }
90
+ type OAuthExecutionContext = ExecutionContext & {
91
+ props?: Record<string, unknown>;
92
+ };
93
+ declare function createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
94
+ /**
95
+ * @deprecated This has been renamed to createMcpHandler, and experimental_createMcpHandler will be removed in the next major version
96
+ */
97
+ declare function experimental_createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
98
+ //#endregion
99
+ //#region src/mcp/auth-context.d.ts
100
+ interface McpAuthContext {
101
+ props: Record<string, unknown>;
102
+ }
103
+ declare function getMcpAuthContext(): McpAuthContext | undefined;
104
+ //#endregion
105
+ //#region src/mcp/index.d.ts
106
+ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
107
+ private _transport?;
108
+ props?: Props;
109
+ abstract server: MaybePromise<McpServer | Server>;
110
+ abstract init(): Promise<void>;
111
+ setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
112
+ getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
113
+ /** Read the transport type for this agent.
114
+ * This relies on the naming scheme being `sse:${sessionId}`
115
+ * or `streamable-http:${sessionId}`.
116
+ */
117
+ getTransportType(): BaseTransportType;
118
+ /** Read the sessionId for this agent.
119
+ * This relies on the naming scheme being `sse:${sessionId}`
120
+ * or `streamable-http:${sessionId}`.
121
+ */
122
+ getSessionId(): string;
123
+ /** Get the unique WebSocket. SSE transport only. */
124
+ private getWebSocket;
125
+ /** Returns a new transport matching the type of the Agent. */
126
+ private initTransport;
127
+ /** Update and store the props */
128
+ updateProps(props?: Props): Promise<void>;
129
+ reinitializeServer(): Promise<void>;
130
+ /** Sets up the MCP transport and server every time the Agent is started.*/
131
+ onStart(props?: Props): Promise<void>;
132
+ /** Validates new WebSocket connections. */
133
+ onConnect(conn: Connection, {
134
+ request: req
135
+ }: ConnectionContext): Promise<void>;
136
+ /** Handles MCP Messages for the legacy SSE transport. */
137
+ onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
138
+ /** Elicit user input with a message and schema */
139
+ elicitInput(params: {
140
+ message: string;
141
+ requestedSchema: unknown;
142
+ }): Promise<ElicitResult$1>;
143
+ /** Wait for elicitation response through storage polling */
144
+ private _waitForElicitationResponse;
145
+ /** Handle elicitation responses */
146
+ private _handleElicitationResponse;
147
+ /** Return a handler for the given path for this MCP.
148
+ * Defaults to Streamable HTTP transport.
149
+ */
150
+ static serve(path: string, {
151
+ binding,
152
+ corsOptions,
153
+ transport,
154
+ jurisdiction
155
+ }?: ServeOptions): {
156
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
157
+ };
158
+ /**
159
+ * Legacy api
160
+ **/
161
+ static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
162
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
163
+ };
164
+ static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
165
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
166
+ };
167
+ }
168
+ //#endregion
169
+ export { type CreateMcpHandlerOptions, type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult, McpAgent, type McpAuthContext, type OAuthExecutionContext, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport, WorkerTransport, type WorkerTransportOptions, createMcpHandler, experimental_createMcpHandler, getMcpAuthContext };
170
+ //# sourceMappingURL=index.d.ts.map