agents 0.0.0-de168a2 → 0.0.0-df52d4b

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 (48) hide show
  1. package/README.md +128 -22
  2. package/dist/ai-chat-agent.d.ts +49 -4
  3. package/dist/ai-chat-agent.js +158 -68
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-react.d.ts +21 -5
  6. package/dist/ai-react.js +49 -42
  7. package/dist/ai-react.js.map +1 -1
  8. package/dist/ai-types.d.ts +5 -0
  9. package/dist/chunk-DQJFYHG3.js +1290 -0
  10. package/dist/chunk-DQJFYHG3.js.map +1 -0
  11. package/dist/chunk-EM3J4KV7.js +598 -0
  12. package/dist/chunk-EM3J4KV7.js.map +1 -0
  13. package/dist/chunk-KUH345EY.js +116 -0
  14. package/dist/chunk-KUH345EY.js.map +1 -0
  15. package/dist/chunk-PVQZBKN7.js +106 -0
  16. package/dist/chunk-PVQZBKN7.js.map +1 -0
  17. package/dist/client-DgyzBU_8.d.ts +4601 -0
  18. package/dist/client.d.ts +16 -2
  19. package/dist/client.js +6 -126
  20. package/dist/client.js.map +1 -1
  21. package/dist/index.d.ts +263 -18
  22. package/dist/index.js +14 -6
  23. package/dist/mcp/client.d.ts +9 -761
  24. package/dist/mcp/client.js +3 -402
  25. package/dist/mcp/client.js.map +1 -1
  26. package/dist/mcp/do-oauth-client-provider.d.ts +3 -3
  27. package/dist/mcp/do-oauth-client-provider.js +3 -103
  28. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  29. package/dist/mcp/index.d.ts +73 -6
  30. package/dist/mcp/index.js +768 -162
  31. package/dist/mcp/index.js.map +1 -1
  32. package/dist/observability/index.d.ts +46 -0
  33. package/dist/observability/index.js +10 -0
  34. package/dist/react.d.ts +88 -5
  35. package/dist/react.js +20 -8
  36. package/dist/react.js.map +1 -1
  37. package/dist/schedule.d.ts +6 -6
  38. package/dist/schedule.js +4 -6
  39. package/dist/schedule.js.map +1 -1
  40. package/dist/serializable.d.ts +32 -0
  41. package/dist/serializable.js +1 -0
  42. package/dist/serializable.js.map +1 -0
  43. package/package.json +79 -56
  44. package/src/index.ts +1147 -139
  45. package/dist/chunk-HMLY7DHA.js +0 -16
  46. package/dist/chunk-XG52S6YY.js +0 -591
  47. package/dist/chunk-XG52S6YY.js.map +0 -1
  48. /package/dist/{chunk-HMLY7DHA.js.map → observability/index.js.map} +0 -0
@@ -1,15 +1,40 @@
1
+ import { M as MCPClientManager } from '../client-DgyzBU_8.js';
2
+ export { S as SSEEdgeClientTransport, a as StreamableHTTPEdgeClientTransport } from '../client-DgyzBU_8.js';
1
3
  import { DurableObject } from 'cloudflare:workers';
4
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
5
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import { Connection } from 'partyserver';
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';
4
18
 
5
19
  interface CORSOptions {
6
20
  origin?: string;
7
21
  methods?: string;
8
22
  headers?: string;
9
23
  maxAge?: number;
24
+ exposeHeaders?: string;
10
25
  }
26
+ type MaybePromise<T> = T | Promise<T>;
11
27
  declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
12
- #private;
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;
13
38
  protected constructor(ctx: DurableObjectState, env: Env);
14
39
  /**
15
40
  * Agents API allowlist
@@ -18,27 +43,69 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
18
43
  get state(): State;
19
44
  sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
20
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>;
21
53
  onStateUpdate(state: State | undefined, source: Connection | "server"): void;
22
54
  onStart(): Promise<void>;
23
55
  /**
24
56
  * McpAgent API
25
57
  */
26
- abstract server: McpServer;
58
+ abstract server: MaybePromise<McpServer | Server>;
27
59
  props: Props;
28
60
  initRun: boolean;
29
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
+ };
30
72
  _init(props: Props): Promise<void>;
73
+ setInitialized(): Promise<void>;
74
+ isInitialized(): Promise<boolean>;
75
+ updateProps(props: Props): Promise<void>;
76
+ private _initialize;
31
77
  fetch(request: Request): Promise<Response>;
32
78
  getWebSocket(): WebSocket | null;
33
- onMCPMessage(sessionId: string, request: Request): Promise<Response>;
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>;
34
89
  webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
35
90
  webSocketError(ws: WebSocket, error: unknown): Promise<void>;
36
91
  webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
37
- static mount(path: string, { binding, corsOptions, }?: {
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 }?: {
38
105
  binding?: string;
39
106
  corsOptions?: CORSOptions;
40
107
  }): {
41
- fetch: (request: Request, env: Record<string, DurableObjectNamespace<McpAgent>>, ctx: ExecutionContext) => Promise<Response | undefined>;
108
+ fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
42
109
  };
43
110
  }
44
111