agents 0.0.0-b213982 → 0.0.0-b2187b4

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 (80) hide show
  1. package/README.md +129 -7
  2. package/dist/ai-chat-agent.d.ts +20 -20
  3. package/dist/ai-chat-agent.js +532 -250
  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 -88
  10. package/dist/ai-react.js +261 -199
  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 -74
  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-BnO9jNtu.d.ts +5283 -0
  23. package/dist/client-CbWe9FBd.d.ts +104 -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 +11 -92
  27. package/dist/client.js +4 -11
  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-CuqiHyhT.d.ts +560 -0
  35. package/dist/index-DhJCaDWd.d.ts +58 -0
  36. package/dist/index.d.ts +57 -534
  37. package/dist/index.js +7 -28
  38. package/dist/mcp/client.d.ts +4 -11
  39. package/dist/mcp/client.js +3 -9
  40. package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
  41. package/dist/mcp/do-oauth-client-provider.js +3 -7
  42. package/dist/mcp/index.d.ts +167 -109
  43. package/dist/mcp/index.js +1388 -942
  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 -46
  50. package/dist/observability/index.js +7 -10
  51. package/dist/react-Cx9uE2Jd.d.ts +113 -0
  52. package/dist/react.d.ts +10 -122
  53. package/dist/react.js +183 -110
  54. package/dist/react.js.map +1 -1
  55. package/dist/schedule.d.ts +84 -7
  56. package/dist/schedule.js +46 -21
  57. package/dist/schedule.js.map +1 -1
  58. package/dist/serializable-CymX8ovI.d.ts +39 -0
  59. package/dist/serializable.d.ts +7 -32
  60. package/dist/serializable.js +1 -1
  61. package/dist/src-CwIW7tU2.js +1216 -0
  62. package/dist/src-CwIW7tU2.js.map +1 -0
  63. package/package.json +75 -30
  64. package/dist/ai-types.js.map +0 -1
  65. package/dist/chunk-DQJFYHG3.js +0 -1290
  66. package/dist/chunk-DQJFYHG3.js.map +0 -1
  67. package/dist/chunk-EM3J4KV7.js +0 -598
  68. package/dist/chunk-EM3J4KV7.js.map +0 -1
  69. package/dist/chunk-KUH345EY.js +0 -116
  70. package/dist/chunk-KUH345EY.js.map +0 -1
  71. package/dist/chunk-PVQZBKN7.js +0 -106
  72. package/dist/chunk-PVQZBKN7.js.map +0 -1
  73. package/dist/client-DgyzBU_8.d.ts +0 -4601
  74. package/dist/client.js.map +0 -1
  75. package/dist/index.js.map +0 -1
  76. package/dist/mcp/client.js.map +0 -1
  77. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  78. package/dist/observability/index.js.map +0 -1
  79. package/dist/serializable.js.map +0 -1
  80. package/src/index.ts +0 -1920
@@ -1,41 +1,2 @@
1
- import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
2
- import { OAuthClientMetadata, OAuthClientInformation, OAuthClientInformationFull, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
3
-
4
- interface AgentsOAuthProvider extends OAuthClientProvider {
5
- authUrl: string | undefined;
6
- clientId: string | undefined;
7
- serverId: string | undefined;
8
- }
9
- declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
10
- storage: DurableObjectStorage;
11
- clientName: string;
12
- baseRedirectUrl: string;
13
- private _authUrl_;
14
- private _serverId_;
15
- private _clientId_;
16
- constructor(storage: DurableObjectStorage, clientName: string, baseRedirectUrl: string);
17
- get clientMetadata(): OAuthClientMetadata;
18
- get redirectUrl(): string;
19
- get clientId(): string;
20
- set clientId(clientId_: string);
21
- get serverId(): string;
22
- set serverId(serverId_: string);
23
- keyPrefix(clientId: string): string;
24
- clientInfoKey(clientId: string): string;
25
- clientInformation(): Promise<OAuthClientInformation | undefined>;
26
- saveClientInformation(clientInformation: OAuthClientInformationFull): Promise<void>;
27
- tokenKey(clientId: string): string;
28
- tokens(): Promise<OAuthTokens | undefined>;
29
- saveTokens(tokens: OAuthTokens): Promise<void>;
30
- get authUrl(): string | undefined;
31
- /**
32
- * Because this operates on the server side (but we need browser auth), we send this url back to the user
33
- * and require user interact to initiate the redirect flow
34
- */
35
- redirectToAuthorization(authUrl: URL): Promise<void>;
36
- codeVerifierKey(clientId: string): string;
37
- saveCodeVerifier(verifier: string): Promise<void>;
38
- codeVerifier(): Promise<string>;
39
- }
40
-
41
- export { type AgentsOAuthProvider, DurableObjectOAuthClientProvider };
1
+ import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider-DGc5pP0l.js";
2
+ export { AgentsOAuthProvider, DurableObjectOAuthClientProvider };
@@ -1,7 +1,3 @@
1
- import {
2
- DurableObjectOAuthClientProvider
3
- } from "../chunk-PVQZBKN7.js";
4
- export {
5
- DurableObjectOAuthClientProvider
6
- };
7
- //# sourceMappingURL=do-oauth-client-provider.js.map
1
+ import { t as DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-CswoD5Lu.js";
2
+
3
+ export { DurableObjectOAuthClientProvider };
@@ -1,112 +1,170 @@
1
- import { M as MCPClientManager } from '../client-DgyzBU_8.js';
2
- export { S as SSEEdgeClientTransport, a as StreamableHTTPEdgeClientTransport } from '../client-DgyzBU_8.js';
3
- import { DurableObject } from 'cloudflare:workers';
4
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
5
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
6
- import { ElicitResult } from '@modelcontextprotocol/sdk/types.js';
7
- export { ElicitRequest, ElicitRequestSchema, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
8
- import { Connection, WSMessage } from 'partyserver';
9
- import 'zod';
10
- import '@modelcontextprotocol/sdk/client/index.js';
11
- import '@modelcontextprotocol/sdk/shared/protocol.js';
12
- import 'ai';
13
- import '@modelcontextprotocol/sdk/client/sse.js';
14
- import '@modelcontextprotocol/sdk/client/streamableHttp.js';
15
- import './do-oauth-client-provider.js';
16
- import '@modelcontextprotocol/sdk/client/auth.js';
17
- import '@modelcontextprotocol/sdk/shared/auth.js';
1
+ import { c as MaybePromise, l as ServeOptions, n as MCPClientOAuthCallbackConfig, o as BaseTransportType, r as MCPClientOAuthResult, s as CORSOptions } from "../client-BnO9jNtu.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-CuqiHyhT.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";
18
13
 
19
- interface CORSOptions {
20
- origin?: string;
21
- methods?: string;
22
- headers?: string;
23
- maxAge?: number;
24
- exposeHeaders?: string;
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);
25
20
  }
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;
29
- 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
41
- */
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
48
- */
49
- elicitInput(params: {
50
- message: string;
51
- requestedSchema: unknown;
52
- }): 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
- */
84
- private _waitForElicitationResponse;
85
- /**
86
- * Handle elicitation responses */
87
- 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
- }): {
96
- fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
97
- };
98
- static serveSSE(path: string, { binding, corsOptions }?: {
99
- binding?: string;
100
- corsOptions?: CORSOptions;
101
- }): {
102
- fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
103
- };
104
- static serve(path: string, { binding, corsOptions }?: {
105
- binding?: string;
106
- corsOptions?: CORSOptions;
107
- }): {
108
- fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
109
- };
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);
110
26
  }
111
-
112
- 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