agents 0.0.0-eede2bd → 0.0.0-ef38e84

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 (75) hide show
  1. package/README.md +255 -27
  2. package/dist/ai-chat-agent.d.ts +47 -18
  3. package/dist/ai-chat-agent.js +532 -226
  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 +266 -201
  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-Bws9q38u.d.ts +5427 -0
  23. package/dist/client-CbWe9FBd.d.ts +104 -0
  24. package/dist/client-DvK0u9vD.js +898 -0
  25. package/dist/client-DvK0u9vD.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-CcTno-25.d.ts +142 -0
  32. package/dist/do-oauth-client-provider-D2P1lSft.js +93 -0
  33. package/dist/do-oauth-client-provider-D2P1lSft.js.map +1 -0
  34. package/dist/index-Bdzb2feZ.d.ts +572 -0
  35. package/dist/index-DhJCaDWd.d.ts +58 -0
  36. package/dist/index.d.ts +62 -306
  37. package/dist/index.js +7 -21
  38. package/dist/mcp/client.d.ts +4 -777
  39. package/dist/mcp/client.js +4 -10
  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 +190 -71
  43. package/dist/mcp/index.js +1429 -799
  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-DFNXTQzy.d.ts +113 -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-C1WWpbRo.js +1247 -0
  62. package/dist/src-C1WWpbRo.js.map +1 -0
  63. package/package.json +125 -69
  64. package/dist/ai-types.js.map +0 -1
  65. package/dist/chunk-5W7ZWKOP.js +0 -617
  66. package/dist/chunk-5W7ZWKOP.js.map +0 -1
  67. package/dist/chunk-HMLY7DHA.js +0 -16
  68. package/dist/chunk-HMLY7DHA.js.map +0 -1
  69. package/dist/chunk-Q5ZBHY4Z.js +0 -456
  70. package/dist/chunk-Q5ZBHY4Z.js.map +0 -1
  71. package/dist/client.js.map +0 -1
  72. package/dist/index.js.map +0 -1
  73. package/dist/mcp/client.js.map +0 -1
  74. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  75. package/src/index.ts +0 -952
@@ -0,0 +1,142 @@
1
+ import { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
2
+ import {
3
+ OAuthClientInformationFull,
4
+ OAuthClientMetadata,
5
+ OAuthTokens
6
+ } from "@modelcontextprotocol/sdk/shared/auth.js";
7
+
8
+ //#region src/mcp/client-storage.d.ts
9
+ /**
10
+ * Represents a row in the cf_agents_mcp_servers table
11
+ */
12
+ type MCPServerRow = {
13
+ id: string;
14
+ name: string;
15
+ server_url: string;
16
+ client_id: string | null;
17
+ auth_url: string | null;
18
+ callback_url: string;
19
+ server_options: string | null;
20
+ };
21
+ /**
22
+ * KV storage interface for OAuth-related data
23
+ * Used by OAuth providers to store tokens, client info, etc.
24
+ */
25
+ interface OAuthClientStorage {
26
+ /**
27
+ * Get a value from key-value storage (for OAuth data like tokens, client info, etc.)
28
+ */
29
+ get<T>(key: string): Promise<T | undefined> | undefined;
30
+ /**
31
+ * Put a value into key-value storage (for OAuth data like tokens, client info, etc.)
32
+ */
33
+ put(key: string, value: unknown): Promise<void> | void;
34
+ }
35
+ /**
36
+ * Storage interface for MCP client manager
37
+ * Abstracts storage operations to decouple from specific storage implementations
38
+ */
39
+ interface MCPClientStorage extends OAuthClientStorage {
40
+ /**
41
+ * Create the cf_agents_mcp_servers table if it doesn't exist
42
+ */
43
+ create(): Promise<void>;
44
+ /**
45
+ * Drop the cf_agents_mcp_servers table
46
+ */
47
+ destroy(): Promise<void>;
48
+ /**
49
+ * Save or update an MCP server configuration
50
+ */
51
+ saveServer(server: MCPServerRow): Promise<void>;
52
+ /**
53
+ * Remove an MCP server from storage
54
+ */
55
+ removeServer(serverId: string): Promise<void>;
56
+ /**
57
+ * List all MCP servers from storage
58
+ */
59
+ listServers(): Promise<MCPServerRow[]>;
60
+ /**
61
+ * Get an MCP server by its callback URL
62
+ * Used during OAuth callback to identify which server is being authenticated
63
+ */
64
+ getServerByCallbackUrl(callbackUrl: string): Promise<MCPServerRow | null>;
65
+ /**
66
+ * Clear auth_url after successful OAuth authentication
67
+ * This prevents the agent from continuously asking for OAuth on reconnect
68
+ * when stored tokens are still valid.
69
+ */
70
+ clearAuthUrl(serverId: string): Promise<void>;
71
+ }
72
+ //#endregion
73
+ //#region src/mcp/do-oauth-client-provider.d.ts
74
+ interface AgentsOAuthProvider extends OAuthClientProvider {
75
+ authUrl: string | undefined;
76
+ clientId: string | undefined;
77
+ serverId: string | undefined;
78
+ }
79
+ declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
80
+ storage: OAuthClientStorage;
81
+ clientName: string;
82
+ baseRedirectUrl: string;
83
+ private _authUrl_;
84
+ private _serverId_;
85
+ private _clientId_;
86
+ constructor(
87
+ storage: OAuthClientStorage,
88
+ clientName: string,
89
+ baseRedirectUrl: string
90
+ );
91
+ get clientMetadata(): OAuthClientMetadata;
92
+ get clientUri(): string;
93
+ get redirectUrl(): string;
94
+ get clientId(): string;
95
+ set clientId(clientId_: string);
96
+ get serverId(): string;
97
+ set serverId(serverId_: string);
98
+ keyPrefix(clientId: string): string;
99
+ clientInfoKey(clientId: string): string;
100
+ clientInformation(): Promise<
101
+ | {
102
+ client_id: string;
103
+ client_secret?: string | undefined;
104
+ client_id_issued_at?: number | undefined;
105
+ client_secret_expires_at?: number | undefined;
106
+ }
107
+ | undefined
108
+ >;
109
+ saveClientInformation(
110
+ clientInformation: OAuthClientInformationFull
111
+ ): Promise<void>;
112
+ tokenKey(clientId: string): string;
113
+ tokens(): Promise<
114
+ | {
115
+ access_token: string;
116
+ token_type: string;
117
+ id_token?: string | undefined;
118
+ expires_in?: number | undefined;
119
+ scope?: string | undefined;
120
+ refresh_token?: string | undefined;
121
+ }
122
+ | undefined
123
+ >;
124
+ saveTokens(tokens: OAuthTokens): Promise<void>;
125
+ get authUrl(): string | undefined;
126
+ /**
127
+ * Because this operates on the server side (but we need browser auth), we send this url back to the user
128
+ * and require user interact to initiate the redirect flow
129
+ */
130
+ redirectToAuthorization(authUrl: URL): void;
131
+ codeVerifierKey(clientId: string): string;
132
+ saveCodeVerifier(verifier: string): Promise<void>;
133
+ codeVerifier(): Promise<string>;
134
+ }
135
+ //#endregion
136
+ export {
137
+ MCPServerRow as i,
138
+ DurableObjectOAuthClientProvider as n,
139
+ MCPClientStorage as r,
140
+ AgentsOAuthProvider as t
141
+ };
142
+ //# sourceMappingURL=do-oauth-client-provider-CcTno-25.d.ts.map
@@ -0,0 +1,93 @@
1
+ import { nanoid } from "nanoid";
2
+
3
+ //#region src/mcp/do-oauth-client-provider.ts
4
+ var DurableObjectOAuthClientProvider = class {
5
+ constructor(storage, clientName, baseRedirectUrl) {
6
+ this.storage = storage;
7
+ this.clientName = clientName;
8
+ this.baseRedirectUrl = baseRedirectUrl;
9
+ }
10
+ get clientMetadata() {
11
+ return {
12
+ client_name: this.clientName,
13
+ client_uri: this.clientUri,
14
+ grant_types: ["authorization_code", "refresh_token"],
15
+ redirect_uris: [this.redirectUrl],
16
+ response_types: ["code"],
17
+ token_endpoint_auth_method: "none"
18
+ };
19
+ }
20
+ get clientUri() {
21
+ return new URL(this.redirectUrl).origin;
22
+ }
23
+ get redirectUrl() {
24
+ return `${this.baseRedirectUrl}/${this.serverId}`;
25
+ }
26
+ get clientId() {
27
+ if (!this._clientId_) throw new Error("Trying to access clientId before it was set");
28
+ return this._clientId_;
29
+ }
30
+ set clientId(clientId_) {
31
+ this._clientId_ = clientId_;
32
+ }
33
+ get serverId() {
34
+ if (!this._serverId_) throw new Error("Trying to access serverId before it was set");
35
+ return this._serverId_;
36
+ }
37
+ set serverId(serverId_) {
38
+ this._serverId_ = serverId_;
39
+ }
40
+ keyPrefix(clientId) {
41
+ return `/${this.clientName}/${this.serverId}/${clientId}`;
42
+ }
43
+ clientInfoKey(clientId) {
44
+ return `${this.keyPrefix(clientId)}/client_info/`;
45
+ }
46
+ async clientInformation() {
47
+ if (!this._clientId_) return;
48
+ return await this.storage.get(this.clientInfoKey(this.clientId)) ?? void 0;
49
+ }
50
+ async saveClientInformation(clientInformation) {
51
+ await this.storage.put(this.clientInfoKey(clientInformation.client_id), clientInformation);
52
+ this.clientId = clientInformation.client_id;
53
+ }
54
+ tokenKey(clientId) {
55
+ return `${this.keyPrefix(clientId)}/token`;
56
+ }
57
+ async tokens() {
58
+ if (!this._clientId_) return;
59
+ return await this.storage.get(this.tokenKey(this.clientId)) ?? void 0;
60
+ }
61
+ async saveTokens(tokens) {
62
+ await this.storage.put(this.tokenKey(this.clientId), tokens);
63
+ }
64
+ get authUrl() {
65
+ return this._authUrl_;
66
+ }
67
+ /**
68
+ * Because this operates on the server side (but we need browser auth), we send this url back to the user
69
+ * and require user interact to initiate the redirect flow
70
+ */
71
+ redirectToAuthorization(authUrl) {
72
+ const stateToken = nanoid();
73
+ authUrl.searchParams.set("state", stateToken);
74
+ this._authUrl_ = authUrl.toString();
75
+ }
76
+ codeVerifierKey(clientId) {
77
+ return `${this.keyPrefix(clientId)}/code_verifier`;
78
+ }
79
+ async saveCodeVerifier(verifier) {
80
+ const key = this.codeVerifierKey(this.clientId);
81
+ if (await this.storage.get(key)) return;
82
+ await this.storage.put(key, verifier);
83
+ }
84
+ async codeVerifier() {
85
+ const codeVerifier = await this.storage.get(this.codeVerifierKey(this.clientId));
86
+ if (!codeVerifier) throw new Error("No code verifier found");
87
+ return codeVerifier;
88
+ }
89
+ };
90
+
91
+ //#endregion
92
+ export { DurableObjectOAuthClientProvider as t };
93
+ //# sourceMappingURL=do-oauth-client-provider-D2P1lSft.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"do-oauth-client-provider-D2P1lSft.js","names":["storage: OAuthClientStorage","clientName: string","baseRedirectUrl: string"],"sources":["../src/mcp/do-oauth-client-provider.ts"],"sourcesContent":["import type { OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport type {\n OAuthClientInformation,\n OAuthClientInformationFull,\n OAuthClientMetadata,\n OAuthTokens\n} from \"@modelcontextprotocol/sdk/shared/auth.js\";\nimport { nanoid } from \"nanoid\";\nimport type { OAuthClientStorage } from \"./client-storage\";\n\n// A slight extension to the standard OAuthClientProvider interface because `redirectToAuthorization` doesn't give us the interface we need\n// This allows us to track authentication for a specific server and associated dynamic client registration\nexport interface AgentsOAuthProvider extends OAuthClientProvider {\n authUrl: string | undefined;\n clientId: string | undefined;\n serverId: string | undefined;\n}\n\nexport class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {\n private _authUrl_: string | undefined;\n private _serverId_: string | undefined;\n private _clientId_: string | undefined;\n\n constructor(\n public storage: OAuthClientStorage,\n public clientName: string,\n public baseRedirectUrl: string\n ) {}\n\n get clientMetadata(): OAuthClientMetadata {\n return {\n client_name: this.clientName,\n client_uri: this.clientUri,\n grant_types: [\"authorization_code\", \"refresh_token\"],\n redirect_uris: [this.redirectUrl],\n response_types: [\"code\"],\n token_endpoint_auth_method: \"none\"\n };\n }\n\n get clientUri() {\n return new URL(this.redirectUrl).origin;\n }\n\n get redirectUrl() {\n return `${this.baseRedirectUrl}/${this.serverId}`;\n }\n\n get clientId() {\n if (!this._clientId_) {\n throw new Error(\"Trying to access clientId before it was set\");\n }\n return this._clientId_;\n }\n\n set clientId(clientId_: string) {\n this._clientId_ = clientId_;\n }\n\n get serverId() {\n if (!this._serverId_) {\n throw new Error(\"Trying to access serverId before it was set\");\n }\n return this._serverId_;\n }\n\n set serverId(serverId_: string) {\n this._serverId_ = serverId_;\n }\n\n keyPrefix(clientId: string) {\n return `/${this.clientName}/${this.serverId}/${clientId}`;\n }\n\n clientInfoKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/client_info/`;\n }\n\n async clientInformation() {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthClientInformation>(\n this.clientInfoKey(this.clientId)\n )) ?? undefined\n );\n }\n\n async saveClientInformation(clientInformation: OAuthClientInformationFull) {\n await this.storage.put(\n this.clientInfoKey(clientInformation.client_id),\n clientInformation\n );\n this.clientId = clientInformation.client_id;\n }\n\n tokenKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/token`;\n }\n\n async tokens() {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthTokens>(this.tokenKey(this.clientId))) ??\n undefined\n );\n }\n\n async saveTokens(tokens: OAuthTokens) {\n await this.storage.put(this.tokenKey(this.clientId), tokens);\n }\n\n get authUrl() {\n return this._authUrl_;\n }\n\n /**\n * Because this operates on the server side (but we need browser auth), we send this url back to the user\n * and require user interact to initiate the redirect flow\n */\n redirectToAuthorization(authUrl: URL) {\n // Generate secure random token for state parameter\n const stateToken = nanoid();\n authUrl.searchParams.set(\"state\", stateToken);\n this._authUrl_ = authUrl.toString();\n }\n\n codeVerifierKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/code_verifier`;\n }\n\n async saveCodeVerifier(verifier: string) {\n const key = this.codeVerifierKey(this.clientId);\n\n // Don't overwrite existing verifier to preserve first PKCE verifier\n const existing = await this.storage.get<string>(key);\n if (existing) {\n return;\n }\n\n await this.storage.put(key, verifier);\n }\n\n async codeVerifier() {\n const codeVerifier = await this.storage.get<string>(\n this.codeVerifierKey(this.clientId)\n );\n if (!codeVerifier) {\n throw new Error(\"No code verifier found\");\n }\n return codeVerifier;\n }\n}\n"],"mappings":";;;AAkBA,IAAa,mCAAb,MAA6E;CAK3E,YACE,AAAOA,SACP,AAAOC,YACP,AAAOC,iBACP;EAHO;EACA;EACA;;CAGT,IAAI,iBAAsC;AACxC,SAAO;GACL,aAAa,KAAK;GAClB,YAAY,KAAK;GACjB,aAAa,CAAC,sBAAsB,gBAAgB;GACpD,eAAe,CAAC,KAAK,YAAY;GACjC,gBAAgB,CAAC,OAAO;GACxB,4BAA4B;GAC7B;;CAGH,IAAI,YAAY;AACd,SAAO,IAAI,IAAI,KAAK,YAAY,CAAC;;CAGnC,IAAI,cAAc;AAChB,SAAO,GAAG,KAAK,gBAAgB,GAAG,KAAK;;CAGzC,IAAI,WAAW;AACb,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MAAM,8CAA8C;AAEhE,SAAO,KAAK;;CAGd,IAAI,SAAS,WAAmB;AAC9B,OAAK,aAAa;;CAGpB,IAAI,WA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