agents 0.0.0-fbf5181 → 0.0.0-fce47ef

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 (42) hide show
  1. package/dist/ai-chat-agent.d.ts +46 -4
  2. package/dist/ai-chat-agent.js +138 -68
  3. package/dist/ai-chat-agent.js.map +1 -1
  4. package/dist/ai-react.d.ts +17 -4
  5. package/dist/ai-react.js +48 -37
  6. package/dist/ai-react.js.map +1 -1
  7. package/dist/ai-types.d.ts +5 -0
  8. package/dist/chunk-767EASBA.js +106 -0
  9. package/dist/chunk-767EASBA.js.map +1 -0
  10. package/dist/chunk-E3LCYPCB.js +469 -0
  11. package/dist/chunk-E3LCYPCB.js.map +1 -0
  12. package/dist/chunk-NKZZ66QY.js +116 -0
  13. package/dist/chunk-NKZZ66QY.js.map +1 -0
  14. package/dist/{chunk-XG52S6YY.js → chunk-ZRRXJUAA.js} +357 -160
  15. package/dist/chunk-ZRRXJUAA.js.map +1 -0
  16. package/dist/client.d.ts +15 -1
  17. package/dist/client.js +6 -126
  18. package/dist/client.js.map +1 -1
  19. package/dist/index.d.ts +123 -14
  20. package/dist/index.js +8 -6
  21. package/dist/mcp/client.d.ts +33 -13
  22. package/dist/mcp/client.js +3 -402
  23. package/dist/mcp/client.js.map +1 -1
  24. package/dist/mcp/do-oauth-client-provider.d.ts +3 -3
  25. package/dist/mcp/do-oauth-client-provider.js +3 -103
  26. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  27. package/dist/mcp/index.d.ts +30 -7
  28. package/dist/mcp/index.js +179 -174
  29. package/dist/mcp/index.js.map +1 -1
  30. package/dist/react.d.ts +85 -5
  31. package/dist/react.js +20 -8
  32. package/dist/react.js.map +1 -1
  33. package/dist/schedule.d.ts +2 -2
  34. package/dist/schedule.js +4 -6
  35. package/dist/schedule.js.map +1 -1
  36. package/dist/serializable.d.ts +32 -0
  37. package/dist/serializable.js +1 -0
  38. package/package.json +71 -65
  39. package/src/index.ts +429 -86
  40. package/dist/chunk-HMLY7DHA.js +0 -16
  41. package/dist/chunk-XG52S6YY.js.map +0 -1
  42. /package/dist/{chunk-HMLY7DHA.js.map → serializable.js.map} +0 -0
@@ -1,106 +1,6 @@
1
- import "../chunk-HMLY7DHA.js";
2
-
3
- // 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
- redirect_uris: [this.redirectUrl],
13
- token_endpoint_auth_method: "none",
14
- grant_types: ["authorization_code", "refresh_token"],
15
- response_types: ["code"],
16
- client_name: this.clientName,
17
- client_uri: "example.com"
18
- };
19
- }
20
- get redirectUrl() {
21
- return `${this.baseRedirectUrl}/${this.serverId}`;
22
- }
23
- get clientId() {
24
- if (!this.clientId_) {
25
- throw new Error("Trying to access clientId before it was set");
26
- }
27
- return this.clientId_;
28
- }
29
- set clientId(clientId_) {
30
- this.clientId_ = clientId_;
31
- }
32
- get serverId() {
33
- if (!this.serverId_) {
34
- throw new Error("Trying to access serverId before it was set");
35
- }
36
- return this.serverId_;
37
- }
38
- set serverId(serverId_) {
39
- this.serverId_ = serverId_;
40
- }
41
- keyPrefix(clientId) {
42
- return `/${this.clientName}/${this.serverId}/${clientId}`;
43
- }
44
- clientInfoKey(clientId) {
45
- return `${this.keyPrefix(clientId)}/client_info/`;
46
- }
47
- async clientInformation() {
48
- if (!this.clientId_) {
49
- return void 0;
50
- }
51
- return await this.storage.get(
52
- this.clientInfoKey(this.clientId)
53
- ) ?? void 0;
54
- }
55
- async saveClientInformation(clientInformation) {
56
- await this.storage.put(
57
- this.clientInfoKey(clientInformation.client_id),
58
- clientInformation
59
- );
60
- this.clientId = clientInformation.client_id;
61
- }
62
- tokenKey(clientId) {
63
- return `${this.keyPrefix(clientId)}/token`;
64
- }
65
- async tokens() {
66
- if (!this.clientId_) {
67
- return void 0;
68
- }
69
- return await this.storage.get(this.tokenKey(this.clientId)) ?? void 0;
70
- }
71
- async saveTokens(tokens) {
72
- await this.storage.put(this.tokenKey(this.clientId), tokens);
73
- }
74
- get authUrl() {
75
- return this.authUrl_;
76
- }
77
- /**
78
- * Because this operates on the server side (but we need browser auth), we send this url back to the user
79
- * and require user interact to initiate the redirect flow
80
- */
81
- async redirectToAuthorization(authUrl) {
82
- const client_id = authUrl.searchParams.get("client_id");
83
- if (client_id) {
84
- authUrl.searchParams.append("state", client_id);
85
- }
86
- this.authUrl_ = authUrl.toString();
87
- }
88
- codeVerifierKey(clientId) {
89
- return `${this.keyPrefix(clientId)}/code_verifier`;
90
- }
91
- async saveCodeVerifier(verifier) {
92
- await this.storage.put(this.codeVerifierKey(this.clientId), verifier);
93
- }
94
- async codeVerifier() {
95
- const codeVerifier = await this.storage.get(
96
- this.codeVerifierKey(this.clientId)
97
- );
98
- if (!codeVerifier) {
99
- throw new Error("No code verifier found");
100
- }
101
- return codeVerifier;
102
- }
103
- };
1
+ import {
2
+ DurableObjectOAuthClientProvider
3
+ } from "../chunk-767EASBA.js";
104
4
  export {
105
5
  DurableObjectOAuthClientProvider
106
6
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mcp/do-oauth-client-provider.ts"],"sourcesContent":["import type { OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport type {\n OAuthTokens,\n OAuthClientMetadata,\n OAuthClientInformation,\n OAuthClientInformationFull,\n} from \"@modelcontextprotocol/sdk/shared/auth.js\";\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: DurableObjectStorage,\n public clientName: string,\n public baseRedirectUrl: string\n ) {}\n\n get clientMetadata(): OAuthClientMetadata {\n return {\n redirect_uris: [this.redirectUrl],\n token_endpoint_auth_method: \"none\",\n grant_types: [\"authorization_code\", \"refresh_token\"],\n response_types: [\"code\"],\n client_name: this.clientName,\n client_uri: \"example.com\",\n };\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(): Promise<OAuthClientInformation | undefined> {\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(\n clientInformation: OAuthClientInformationFull\n ): Promise<void> {\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(): Promise<OAuthTokens | undefined> {\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): Promise<void> {\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 async redirectToAuthorization(authUrl: URL): Promise<void> {\n // We want to track the client ID in state here because the typescript SSE client sometimes does\n // a dynamic client registration AFTER generating this redirect URL.\n const client_id = authUrl.searchParams.get(\"client_id\");\n if (client_id) {\n authUrl.searchParams.append(\"state\", client_id);\n }\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): Promise<void> {\n await this.storage.put(this.codeVerifierKey(this.clientId), verifier);\n }\n\n async codeVerifier(): Promise<string> {\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":";;;AAgBO,IAAM,mCAAN,MAAsE;AAAA,EAK3E,YACS,SACA,YACA,iBACP;AAHO;AACA;AACA;AAAA,EACN;AAAA,EAEH,IAAI,iBAAsC;AACxC,WAAO;AAAA,MACL,eAAe,CAAC,KAAK,WAAW;AAAA,MAChC,4BAA4B;AAAA,MAC5B,aAAa,CAAC,sBAAsB,eAAe;AAAA,MACnD,gBAAgB,CAAC,MAAM;AAAA,MACvB,aAAa,KAAK;AAAA,MAClB,YAAY;AAAA,IACd;AAAA,EACF;AAAA,EAEA,IAAI,cAAc;AAChB,WAAO,GAAG,KAAK,eAAe,IAAI,KAAK,QAAQ;AAAA,EACjD;AAAA,EAEA,IAAI,WAAW;AACb,QAAI,CAAC,KAAK,WAAW;AACnB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,SAAS,WAAmB;AAC9B,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,IAAI,WAAW;AACb,QAAI,CAAC,KAAK,WAAW;AACnB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,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,KAAK,UAAU,QAAQ,CAAC;AAAA,EACpC;AAAA,EAEA,MAAM,iBAAiB,UAAiC;AACtD,UAAM,KAAK,QAAQ,IAAI,KAAK,gBAAgB,KAAK,QAAQ,GAAG,QAAQ;AAAA,EACtE;AAAA,EAEA,MAAM,eAAgC;AACpC,UAAM,eAAe,MAAM,KAAK,QAAQ;AAAA,MACtC,KAAK,gBAAgB,KAAK,QAAQ;AAAA,IACpC;AACA,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,15 +1,37 @@
1
+ import { MCPClientManager } from './client.js';
1
2
  import { DurableObject } from 'cloudflare:workers';
2
- import { Connection, WSMessage } from 'partyserver';
3
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
4
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { Connection, WSMessage } from 'partyserver';
6
+ import 'zod';
7
+ import '@modelcontextprotocol/sdk/client/index.js';
8
+ import '@modelcontextprotocol/sdk/client/sse.js';
9
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
10
+ import '@modelcontextprotocol/sdk/types.js';
11
+ import 'ai';
12
+ import './do-oauth-client-provider.js';
13
+ import '@modelcontextprotocol/sdk/client/auth.js';
14
+ import '@modelcontextprotocol/sdk/shared/auth.js';
4
15
 
5
16
  interface CORSOptions {
6
17
  origin?: string;
7
18
  methods?: string;
8
19
  headers?: string;
9
20
  maxAge?: number;
21
+ exposeHeaders?: string;
10
22
  }
23
+ type MaybePromise<T> = T | Promise<T>;
11
24
  declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
12
- #private;
25
+ private _status;
26
+ private _transport?;
27
+ private _transportType;
28
+ private _requestIdToConnectionId;
29
+ /**
30
+ * Since McpAgent's _aren't_ yet real "Agents", let's only expose a couple of the methods
31
+ * to the outer class: initialState/state/setState/onStateUpdate/sql
32
+ */
33
+ private _agent;
34
+ get mcp(): MCPClientManager;
13
35
  protected constructor(ctx: DurableObjectState, env: Env);
14
36
  /**
15
37
  * Agents API allowlist
@@ -23,18 +45,19 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
23
45
  /**
24
46
  * McpAgent API
25
47
  */
26
- abstract server: McpServer;
48
+ abstract server: MaybePromise<McpServer | Server>;
27
49
  props: Props;
28
50
  initRun: boolean;
29
51
  abstract init(): Promise<void>;
30
52
  _init(props: Props): Promise<void>;
31
53
  setInitialized(): Promise<void>;
32
54
  isInitialized(): Promise<boolean>;
55
+ private _initialize;
33
56
  fetch(request: Request): Promise<Response>;
34
57
  getWebSocket(): WebSocket | null;
35
58
  getWebSocketForResponseID(id: string): WebSocket | null;
36
59
  onMessage(connection: Connection, event: WSMessage): Promise<void>;
37
- onSSEMcpMessage(sessionId: string, request: Request): Promise<Error | null>;
60
+ onSSEMcpMessage(_sessionId: string, request: Request): Promise<Error | null>;
38
61
  webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
39
62
  webSocketError(ws: WebSocket, error: unknown): Promise<void>;
40
63
  webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
@@ -42,19 +65,19 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
42
65
  binding?: string;
43
66
  corsOptions?: CORSOptions;
44
67
  }): {
45
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
68
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
46
69
  };
47
70
  static serveSSE(path: string, { binding, corsOptions, }?: {
48
71
  binding?: string;
49
72
  corsOptions?: CORSOptions;
50
73
  }): {
51
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
74
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
52
75
  };
53
76
  static serve(path: string, { binding, corsOptions, }?: {
54
77
  binding?: string;
55
78
  corsOptions?: CORSOptions;
56
79
  }): {
57
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response>;
80
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
58
81
  };
59
82
  }
60
83