agents 0.0.0-dc0e8de → 0.0.0-dc7a99c

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 (45) hide show
  1. package/dist/ai-chat-agent.d.ts +32 -5
  2. package/dist/ai-chat-agent.js +149 -115
  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 +28 -29
  6. package/dist/ai-react.js.map +1 -1
  7. package/dist/chunk-767EASBA.js +106 -0
  8. package/dist/chunk-767EASBA.js.map +1 -0
  9. package/dist/{chunk-Q5ZBHY4Z.js → chunk-E3LCYPCB.js} +49 -36
  10. package/dist/chunk-E3LCYPCB.js.map +1 -0
  11. package/dist/{chunk-HD4VEHBA.js → chunk-JFRK72K3.js} +463 -161
  12. package/dist/chunk-JFRK72K3.js.map +1 -0
  13. package/dist/chunk-NKZZ66QY.js +116 -0
  14. package/dist/chunk-NKZZ66QY.js.map +1 -0
  15. package/dist/client.d.ts +15 -1
  16. package/dist/client.js +6 -126
  17. package/dist/client.js.map +1 -1
  18. package/dist/index-CITGJflw.d.ts +486 -0
  19. package/dist/index.d.ts +25 -308
  20. package/dist/index.js +4 -3
  21. package/dist/mcp/client.d.ts +301 -23
  22. package/dist/mcp/client.js +1 -2
  23. package/dist/mcp/do-oauth-client-provider.d.ts +3 -3
  24. package/dist/mcp/do-oauth-client-provider.js +3 -103
  25. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  26. package/dist/mcp/index.d.ts +17 -7
  27. package/dist/mcp/index.js +147 -173
  28. package/dist/mcp/index.js.map +1 -1
  29. package/dist/observability/index.d.ts +12 -0
  30. package/dist/observability/index.js +10 -0
  31. package/dist/react.d.ts +85 -5
  32. package/dist/react.js +20 -8
  33. package/dist/react.js.map +1 -1
  34. package/dist/schedule.d.ts +6 -6
  35. package/dist/schedule.js +4 -6
  36. package/dist/schedule.js.map +1 -1
  37. package/dist/serializable.d.ts +32 -0
  38. package/dist/serializable.js +1 -0
  39. package/dist/serializable.js.map +1 -0
  40. package/package.json +75 -68
  41. package/src/index.ts +506 -83
  42. package/dist/chunk-HD4VEHBA.js.map +0 -1
  43. package/dist/chunk-HMLY7DHA.js +0 -16
  44. package/dist/chunk-Q5ZBHY4Z.js.map +0 -1
  45. /package/dist/{chunk-HMLY7DHA.js.map → observability/index.js.map} +0 -0
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  MCPClientManager,
3
3
  getNamespacedData
4
- } from "../chunk-Q5ZBHY4Z.js";
5
- import "../chunk-HMLY7DHA.js";
4
+ } from "../chunk-E3LCYPCB.js";
6
5
  export {
7
6
  MCPClientManager,
8
7
  getNamespacedData
@@ -10,9 +10,9 @@ declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
10
10
  storage: DurableObjectStorage;
11
11
  clientName: string;
12
12
  baseRedirectUrl: string;
13
- private authUrl_;
14
- private serverId_;
15
- private clientId_;
13
+ private _authUrl_;
14
+ private _serverId_;
15
+ private _clientId_;
16
16
  constructor(storage: DurableObjectStorage, clientName: string, baseRedirectUrl: string);
17
17
  get clientMetadata(): OAuthClientMetadata;
18
18
  get redirectUrl(): string;
@@ -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,W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Q,CAAC;AAAA,EACpC;AAAA,EAEA,MAAM,SAA2C;AAC/C,QAAI,CAAC,KAAK,WAAW;AACnB,aAAO;AAAA,IACT;AACA,WACG,MAAM,KAAK,QAAQ,IAAiB,KAAK,SAAS,KAAK,QAAQ,CAAC,KACjE;AAAA,EAEJ;AAAA,EAEA,MAAM,WAAW,QAAoC;AACnD,UAAM,KAAK,QAAQ,IAAI,KAAK,SAAS,KAAK,QAAQ,GAAG,MAAM;AAAA,EAC7D;AAAA,EAEA,IAAI,UAAU;AACZ,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,wBAAwB,SAA6B;AAGzD,UAAM,YAAY,QAAQ,aAAa,IAAI,WAAW;AACtD,QAAI,WAAW;AACb,cAAQ,aAAa,OAAO,SAAS,SAAS;AAAA,IAChD;AACA,SAAK,WAAW,QAAQ,SAAS;AAAA,EACnC;AAAA,EAEA,gBAAgB,UAAkB;AAChC,WAAO,GAAG,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,27 +1,36 @@
1
1
  import { MCPClientManager } from './client.js';
2
2
  import { DurableObject } from 'cloudflare:workers';
3
- import { Connection, WSMessage } from 'partyserver';
4
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
3
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { Connection, WSMessage } from 'partyserver';
6
6
  import 'zod';
7
- import '@modelcontextprotocol/sdk/types.js';
8
7
  import '@modelcontextprotocol/sdk/client/index.js';
9
8
  import '@modelcontextprotocol/sdk/client/sse.js';
9
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
10
+ import '@modelcontextprotocol/sdk/types.js';
11
+ import 'ai';
10
12
  import './do-oauth-client-provider.js';
11
13
  import '@modelcontextprotocol/sdk/client/auth.js';
12
14
  import '@modelcontextprotocol/sdk/shared/auth.js';
13
- import '@modelcontextprotocol/sdk/shared/protocol.js';
14
- import 'ai';
15
15
 
16
16
  interface CORSOptions {
17
17
  origin?: string;
18
18
  methods?: string;
19
19
  headers?: string;
20
20
  maxAge?: number;
21
+ exposeHeaders?: string;
21
22
  }
22
23
  type MaybePromise<T> = T | Promise<T>;
23
24
  declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
24
- #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;
25
34
  get mcp(): MCPClientManager;
26
35
  protected constructor(ctx: DurableObjectState, env: Env);
27
36
  /**
@@ -43,11 +52,12 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
43
52
  _init(props: Props): Promise<void>;
44
53
  setInitialized(): Promise<void>;
45
54
  isInitialized(): Promise<boolean>;
55
+ private _initialize;
46
56
  fetch(request: Request): Promise<Response>;
47
57
  getWebSocket(): WebSocket | null;
48
58
  getWebSocketForResponseID(id: string): WebSocket | null;
49
59
  onMessage(connection: Connection, event: WSMessage): Promise<void>;
50
- onSSEMcpMessage(sessionId: string, request: Request): Promise<Error | null>;
60
+ onSSEMcpMessage(_sessionId: string, request: Request): Promise<Error | null>;
51
61
  webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
52
62
  webSocketError(ws: WebSocket, error: unknown): Promise<void>;
53
63
  webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;