agents 0.0.0-f6c26e4 → 0.0.0-f7bd395

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 (50) hide show
  1. package/README.md +136 -6
  2. package/dist/ai-chat-agent.d.ts +12 -9
  3. package/dist/ai-chat-agent.js +142 -59
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration.d.ts +152 -0
  6. package/dist/ai-chat-v5-migration.js +19 -0
  7. package/dist/ai-chat-v5-migration.js.map +1 -0
  8. package/dist/ai-react.d.ts +62 -71
  9. package/dist/ai-react.js +144 -37
  10. package/dist/ai-react.js.map +1 -1
  11. package/dist/ai-types.d.ts +36 -19
  12. package/dist/ai-types.js +6 -0
  13. package/dist/chunk-AVYJQSLW.js +17 -0
  14. package/dist/chunk-AVYJQSLW.js.map +1 -0
  15. package/dist/{chunk-5YIRLLUX.js → chunk-IJPBZOSS.js} +137 -105
  16. package/dist/chunk-IJPBZOSS.js.map +1 -0
  17. package/dist/{chunk-PVQZBKN7.js → chunk-LL2AFX7V.js} +5 -2
  18. package/dist/chunk-LL2AFX7V.js.map +1 -0
  19. package/dist/{chunk-KUH345EY.js → chunk-QEVM4BVL.js} +5 -5
  20. package/dist/chunk-QEVM4BVL.js.map +1 -0
  21. package/dist/chunk-UJVEAURM.js +150 -0
  22. package/dist/chunk-UJVEAURM.js.map +1 -0
  23. package/dist/{chunk-MW5BQ2FW.js → chunk-VYENMKFS.js} +163 -20
  24. package/dist/chunk-VYENMKFS.js.map +1 -0
  25. package/dist/client-CcIORE73.d.ts +4607 -0
  26. package/dist/client.js +2 -1
  27. package/dist/index.d.ts +557 -32
  28. package/dist/index.js +7 -4
  29. package/dist/mcp/client.d.ts +9 -1053
  30. package/dist/mcp/client.js +1 -1
  31. package/dist/mcp/do-oauth-client-provider.d.ts +1 -0
  32. package/dist/mcp/do-oauth-client-provider.js +1 -1
  33. package/dist/mcp/index.d.ts +66 -53
  34. package/dist/mcp/index.js +850 -604
  35. package/dist/mcp/index.js.map +1 -1
  36. package/dist/observability/index.d.ts +46 -12
  37. package/dist/observability/index.js +5 -4
  38. package/dist/react.d.ts +7 -3
  39. package/dist/react.js +7 -5
  40. package/dist/react.js.map +1 -1
  41. package/dist/schedule.d.ts +83 -9
  42. package/dist/schedule.js +15 -2
  43. package/dist/schedule.js.map +1 -1
  44. package/package.json +19 -8
  45. package/src/index.ts +192 -123
  46. package/dist/chunk-5YIRLLUX.js.map +0 -1
  47. package/dist/chunk-KUH345EY.js.map +0 -1
  48. package/dist/chunk-MW5BQ2FW.js.map +0 -1
  49. package/dist/chunk-PVQZBKN7.js.map +0 -1
  50. package/dist/index-BIJvkfYt.d.ts +0 -614
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MCPClientManager,
3
3
  getNamespacedData
4
- } from "../chunk-MW5BQ2FW.js";
4
+ } from "../chunk-VYENMKFS.js";
5
5
  export {
6
6
  MCPClientManager,
7
7
  getNamespacedData
@@ -15,6 +15,7 @@ declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
15
15
  private _clientId_;
16
16
  constructor(storage: DurableObjectStorage, clientName: string, baseRedirectUrl: string);
17
17
  get clientMetadata(): OAuthClientMetadata;
18
+ get clientUri(): string;
18
19
  get redirectUrl(): string;
19
20
  get clientId(): string;
20
21
  set clientId(clientId_: string);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DurableObjectOAuthClientProvider
3
- } from "../chunk-PVQZBKN7.js";
3
+ } from "../chunk-LL2AFX7V.js";
4
4
  export {
5
5
  DurableObjectOAuthClientProvider
6
6
  };
@@ -1,18 +1,25 @@
1
- import { MCPClientManager } from './client.js';
2
- import { DurableObject } from 'cloudflare:workers';
3
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
2
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
- import { Connection, WSMessage } from 'partyserver';
6
- import 'zod';
3
+ import { ElicitResult } from '@modelcontextprotocol/sdk/types.js';
4
+ export { ElicitRequest, ElicitRequestSchema, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
5
+ import { Agent, AgentContext } from '../index.js';
6
+ export { S as SSEEdgeClientTransport, a as StreamableHTTPEdgeClientTransport } from '../client-CcIORE73.js';
7
+ import { Connection, ConnectionContext, WSMessage } from 'partyserver';
8
+ import 'cloudflare:workers';
7
9
  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';
10
+ import '../observability/index.js';
11
+ import '../ai-types.js';
11
12
  import 'ai';
13
+ import 'zod';
14
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
15
+ import '@modelcontextprotocol/sdk/client/sse.js';
16
+ import '@modelcontextprotocol/sdk/client/streamableHttp.js';
12
17
  import './do-oauth-client-provider.js';
13
18
  import '@modelcontextprotocol/sdk/client/auth.js';
14
19
  import '@modelcontextprotocol/sdk/shared/auth.js';
15
20
 
21
+ type MaybePromise<T> = T | Promise<T>;
22
+ type TransportType = "sse" | "streamable-http";
16
23
  interface CORSOptions {
17
24
  origin?: string;
18
25
  methods?: string;
@@ -20,63 +27,69 @@ interface CORSOptions {
20
27
  maxAge?: number;
21
28
  exposeHeaders?: string;
22
29
  }
23
- type MaybePromise<T> = T | Promise<T>;
24
- declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
25
- private _status;
30
+ interface ServeOptions {
31
+ binding?: string;
32
+ corsOptions?: CORSOptions;
33
+ transport?: TransportType;
34
+ }
35
+
36
+ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
26
37
  private _transport?;
27
- private _transportType;
28
38
  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;
35
- protected constructor(ctx: DurableObjectState, env: Env);
36
- /**
37
- * Agents API allowlist
38
- */
39
- initialState: State;
40
- get state(): State;
41
- sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
42
- setState(state: State): void;
43
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
44
- onStart(): Promise<void>;
45
- /**
46
- * McpAgent API
47
- */
39
+ private _standaloneSseConnectionId?;
40
+ props?: Props;
48
41
  abstract server: MaybePromise<McpServer | Server>;
49
- props: Props;
50
- initRun: boolean;
51
42
  abstract init(): Promise<void>;
52
- _init(props: Props): Promise<void>;
43
+ constructor(ctx: AgentContext, env: Env);
53
44
  setInitialized(): Promise<void>;
54
45
  isInitialized(): Promise<boolean>;
55
- private _initialize;
56
- fetch(request: Request): Promise<Response>;
57
- getWebSocket(): WebSocket | null;
58
- getWebSocketForResponseID(id: string): WebSocket | null;
46
+ /** Read the transport type for this agent.
47
+ * This relies on the naming scheme being `sse:${sessionId}`
48
+ * or `streamable-http:${sessionId}`.
49
+ */
50
+ getTransportType(): TransportType;
51
+ /** Get the WebSocket for the standalone SSE if any. Streamable HTTP only. */
52
+ private getWebSocketForStandaloneSse;
53
+ /** Get the unique WebSocket. SSE transport only. */
54
+ private getWebSocket;
55
+ /** Get the corresponding WebSocket for a responseId. Streamable HTTP only. */
56
+ private getWebSocketForResponseID;
57
+ /** Returns a new transport matching the type of the Agent. */
58
+ private initTransport;
59
+ /** Update and store the props */
60
+ updateProps(props?: Props): Promise<void>;
61
+ /** Sets up the MCP transport and server every time the Agent is started.*/
62
+ onStart(props?: Props): Promise<void>;
63
+ /** Validates new WebSocket connections. */
64
+ onConnect(conn: Connection, _: ConnectionContext): Promise<void>;
65
+ /** Handles MCP Messages for Streamable HTTP. */
59
66
  onMessage(connection: Connection, event: WSMessage): Promise<void>;
60
- onSSEMcpMessage(_sessionId: string, request: Request): Promise<Error | null>;
61
- webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
62
- webSocketError(ws: WebSocket, error: unknown): Promise<void>;
63
- webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
64
- static mount(path: string, { binding, corsOptions }?: {
65
- binding?: string;
66
- corsOptions?: CORSOptions;
67
- }): {
67
+ /** Remove clients from our cache when they disconnect */
68
+ onClose(conn: Connection, _code: number, _reason: string, _wasClean: boolean): Promise<void>;
69
+ /** Handles MCP Messages for the legacy SSE transport. */
70
+ onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
71
+ /** Elicit user input with a message and schema */
72
+ elicitInput(params: {
73
+ message: string;
74
+ requestedSchema: unknown;
75
+ }): Promise<ElicitResult>;
76
+ /** Wait for elicitation response through storage polling */
77
+ private _waitForElicitationResponse;
78
+ /** Handle elicitation responses */
79
+ private _handleElicitationResponse;
80
+ /** Return a handler for the given path for this MCP.
81
+ * Defaults to Streamable HTTP transport.
82
+ */
83
+ static serve(path: string, { binding, corsOptions, transport }?: ServeOptions): {
68
84
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
69
85
  };
70
- static serveSSE(path: string, { binding, corsOptions }?: {
71
- binding?: string;
72
- corsOptions?: CORSOptions;
73
- }): {
86
+ /**
87
+ * Legacy api
88
+ **/
89
+ static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
74
90
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
75
91
  };
76
- static serve(path: string, { binding, corsOptions }?: {
77
- binding?: string;
78
- corsOptions?: CORSOptions;
79
- }): {
92
+ static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
80
93
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
81
94
  };
82
95
  }