agents 0.0.0-1eac06e → 0.0.0-1f8c517

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 +32 -7
  2. package/dist/ai-chat-agent.d.ts +9 -8
  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 +59 -70
  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-PVQZBKN7.js → chunk-LL2AFX7V.js} +5 -2
  16. package/dist/chunk-LL2AFX7V.js.map +1 -0
  17. package/dist/{chunk-XJR75HO7.js → chunk-MH46VMM4.js} +91 -27
  18. package/dist/chunk-MH46VMM4.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-2DJ6XAU6.js → chunk-YDUDMOL6.js} +115 -89
  24. package/dist/chunk-YDUDMOL6.js.map +1 -0
  25. package/dist/client-CvaJdLQA.d.ts +5015 -0
  26. package/dist/client.js +2 -1
  27. package/dist/index.d.ts +555 -32
  28. package/dist/index.js +7 -4
  29. package/dist/mcp/client.d.ts +9 -1057
  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 +63 -88
  34. package/dist/mcp/index.js +813 -692
  35. package/dist/mcp/index.js.map +1 -1
  36. package/dist/observability/index.d.ts +46 -14
  37. package/dist/observability/index.js +5 -4
  38. package/dist/react.d.ts +4 -2
  39. package/dist/react.js +7 -5
  40. package/dist/react.js.map +1 -1
  41. package/dist/schedule.d.ts +79 -5
  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 +152 -100
  46. package/dist/chunk-2DJ6XAU6.js.map +0 -1
  47. package/dist/chunk-KUH345EY.js.map +0 -1
  48. package/dist/chunk-PVQZBKN7.js.map +0 -1
  49. package/dist/chunk-XJR75HO7.js.map +0 -1
  50. package/dist/index-CLW1aEBr.d.ts +0 -615
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MCPClientManager,
3
3
  getNamespacedData
4
- } from "../chunk-XJR75HO7.js";
4
+ } from "../chunk-MH46VMM4.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,42 +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
3
  import { ElicitResult } from '@modelcontextprotocol/sdk/types.js';
6
4
  export { ElicitRequest, ElicitRequestSchema, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
7
- import { Connection, WSMessage } from 'partyserver';
8
- import { SSEClientTransport, SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
9
- import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
10
- import 'zod';
5
+ import { Agent, AgentContext } from '../index.js';
6
+ export { S as SSEEdgeClientTransport, a as StreamableHTTPEdgeClientTransport } from '../client-CvaJdLQA.js';
7
+ import { Connection, ConnectionContext, WSMessage } from 'partyserver';
8
+ import 'cloudflare:workers';
11
9
  import '@modelcontextprotocol/sdk/client/index.js';
12
- import '@modelcontextprotocol/sdk/shared/protocol.js';
10
+ import '../observability/index.js';
11
+ import '../ai-types.js';
13
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';
14
17
  import './do-oauth-client-provider.js';
15
18
  import '@modelcontextprotocol/sdk/client/auth.js';
16
19
  import '@modelcontextprotocol/sdk/shared/auth.js';
17
20
 
18
- declare class SSEEdgeClientTransport extends SSEClientTransport {
19
- private authProvider;
20
- /**
21
- * Creates a new EdgeSSEClientTransport, which overrides fetch to be compatible with the CF workers environment
22
- */
23
- constructor(url: URL, options: SSEClientTransportOptions);
24
- authHeaders(): Promise<{
25
- Authorization: string;
26
- } | undefined>;
27
- }
28
-
29
- declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
30
- private authProvider;
31
- /**
32
- * Creates a new StreamableHTTPEdgeClientTransport, which overrides fetch to be compatible with the CF workers environment
33
- */
34
- constructor(url: URL, options: StreamableHTTPClientTransportOptions);
35
- authHeaders(): Promise<{
36
- Authorization: string;
37
- } | undefined>;
38
- }
39
-
21
+ type MaybePromise<T> = T | Promise<T>;
22
+ type TransportType = "sse" | "streamable-http";
40
23
  interface CORSOptions {
41
24
  origin?: string;
42
25
  methods?: string;
@@ -44,79 +27,71 @@ interface CORSOptions {
44
27
  maxAge?: number;
45
28
  exposeHeaders?: string;
46
29
  }
47
- type MaybePromise<T> = T | Promise<T>;
48
- declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
49
- 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> {
50
37
  private _transport?;
51
- private _transportType;
52
38
  private _requestIdToConnectionId;
53
- /**
54
- * Since McpAgent's _aren't_ yet real "Agents", let's only expose a couple of the methods
55
- * to the outer class: initialState/state/setState/onStateUpdate/sql
56
- */
57
- private _agent;
58
- get mcp(): MCPClientManager;
59
- protected constructor(ctx: DurableObjectState, env: Env);
60
- /**
61
- * Agents API allowlist
62
- */
63
- initialState: State;
64
- get state(): State;
65
- sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
66
- setState(state: State): void;
67
- /**
68
- * Elicit user input with a message and schema
69
- */
70
- elicitInput(params: {
71
- message: string;
72
- requestedSchema: unknown;
73
- }): Promise<ElicitResult>;
74
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
75
- onStart(): Promise<void>;
76
- /**
77
- * McpAgent API
78
- */
39
+ private _standaloneSseConnectionId?;
40
+ props?: Props;
79
41
  abstract server: MaybePromise<McpServer | Server>;
80
- props: Props;
81
- initRun: boolean;
82
42
  abstract init(): Promise<void>;
83
- _init(props: Props): Promise<void>;
43
+ constructor(ctx: AgentContext, env: Env);
84
44
  setInitialized(): Promise<void>;
85
45
  isInitialized(): Promise<boolean>;
86
- private _initialize;
87
- fetch(request: Request): Promise<Response>;
88
- getWebSocket(): WebSocket | null;
89
- getWebSocketForResponseID(id: string): WebSocket | null;
90
- onMessage(connection: Connection, event: WSMessage): Promise<void>;
91
- /**
92
- * Wait for elicitation response through storage polling
46
+ /** Read the transport type for this agent.
47
+ * This relies on the naming scheme being `sse:${sessionId}`
48
+ * or `streamable-http:${sessionId}`.
93
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. */
66
+ onMessage(connection: Connection, event: WSMessage): Promise<void>;
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 */
94
77
  private _waitForElicitationResponse;
95
- /**
96
- * Handle elicitation responses */
78
+ /** Handle elicitation responses */
97
79
  private _handleElicitationResponse;
98
- onSSEMcpMessage(_sessionId: string, request: Request): Promise<Error | null>;
99
- webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
100
- webSocketError(ws: WebSocket, error: unknown): Promise<void>;
101
- webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
102
- static mount(path: string, { binding, corsOptions }?: {
103
- binding?: string;
104
- corsOptions?: CORSOptions;
105
- }): {
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): {
106
84
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
107
85
  };
108
- static serveSSE(path: string, { binding, corsOptions }?: {
109
- binding?: string;
110
- corsOptions?: CORSOptions;
111
- }): {
86
+ /**
87
+ * Legacy api
88
+ **/
89
+ static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
112
90
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
113
91
  };
114
- static serve(path: string, { binding, corsOptions }?: {
115
- binding?: string;
116
- corsOptions?: CORSOptions;
117
- }): {
92
+ static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
118
93
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
119
94
  };
120
95
  }
121
96
 
122
- export { McpAgent, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport };
97
+ export { McpAgent };