agents 0.0.0-2a6e66e → 0.0.0-2d0d2e1
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.
- package/README.md +31 -7
- package/dist/ai-chat-agent.d.ts +7 -6
- package/dist/ai-chat-agent.js +148 -47
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration.d.ts +152 -0
- package/dist/ai-chat-v5-migration.js +19 -0
- package/dist/ai-chat-v5-migration.js.map +1 -0
- package/dist/ai-react.d.ts +57 -69
- package/dist/ai-react.js +144 -37
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.d.ts +36 -19
- package/dist/ai-types.js +6 -0
- package/dist/chunk-AVYJQSLW.js +17 -0
- package/dist/chunk-AVYJQSLW.js.map +1 -0
- package/dist/{chunk-PVQZBKN7.js → chunk-LL2AFX7V.js} +5 -2
- package/dist/chunk-LL2AFX7V.js.map +1 -0
- package/dist/{chunk-HY7ZLHJB.js → chunk-MH46VMM4.js} +18 -4
- package/dist/chunk-MH46VMM4.js.map +1 -0
- package/dist/{chunk-KUH345EY.js → chunk-QEVM4BVL.js} +5 -5
- package/dist/chunk-QEVM4BVL.js.map +1 -0
- package/dist/chunk-UJVEAURM.js +150 -0
- package/dist/chunk-UJVEAURM.js.map +1 -0
- package/dist/{chunk-CV3L6FQZ.js → chunk-YDUDMOL6.js} +71 -65
- package/dist/chunk-YDUDMOL6.js.map +1 -0
- package/dist/{client-DgyzBU_8.d.ts → client-CvaJdLQA.d.ts} +425 -11
- package/dist/client.js +2 -1
- package/dist/index.d.ts +24 -7
- package/dist/index.js +7 -4
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/do-oauth-client-provider.d.ts +1 -0
- package/dist/mcp/do-oauth-client-provider.js +1 -1
- package/dist/mcp/index.d.ts +60 -75
- package/dist/mcp/index.js +808 -738
- package/dist/mcp/index.js.map +1 -1
- package/dist/observability/index.js +5 -4
- package/dist/react.d.ts +2 -1
- package/dist/react.js +7 -5
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +76 -2
- package/dist/schedule.js +15 -2
- package/dist/schedule.js.map +1 -1
- package/package.json +14 -6
- package/src/index.ts +102 -75
- package/dist/chunk-CV3L6FQZ.js.map +0 -1
- package/dist/chunk-HY7ZLHJB.js.map +0 -1
- package/dist/chunk-KUH345EY.js.map +0 -1
- package/dist/chunk-PVQZBKN7.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,8 +8,9 @@ import {
|
|
|
8
8
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
9
9
|
import { Server, Connection, PartyServerOptions } from "partyserver";
|
|
10
10
|
export { Connection, ConnectionContext, WSMessage } from "partyserver";
|
|
11
|
-
import { M as MCPClientManager } from "./client-
|
|
11
|
+
import { M as MCPClientManager } from "./client-CvaJdLQA.js";
|
|
12
12
|
import { Observability } from "./observability/index.js";
|
|
13
|
+
import { MessageType } from "./ai-types.js";
|
|
13
14
|
import "zod";
|
|
14
15
|
import "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
15
16
|
import "ai";
|
|
@@ -32,14 +33,14 @@ type RPCRequest = {
|
|
|
32
33
|
* State update message from client
|
|
33
34
|
*/
|
|
34
35
|
type StateUpdateMessage = {
|
|
35
|
-
type:
|
|
36
|
+
type: MessageType.CF_AGENT_STATE;
|
|
36
37
|
state: unknown;
|
|
37
38
|
};
|
|
38
39
|
/**
|
|
39
40
|
* RPC response message to client
|
|
40
41
|
*/
|
|
41
42
|
type RPCResponse = {
|
|
42
|
-
type:
|
|
43
|
+
type: MessageType.RPC;
|
|
43
44
|
id: string;
|
|
44
45
|
} & (
|
|
45
46
|
| {
|
|
@@ -70,12 +71,18 @@ type CallableMetadata = {
|
|
|
70
71
|
* Decorator that marks a method as callable by clients
|
|
71
72
|
* @param metadata Optional metadata about the callable method
|
|
72
73
|
*/
|
|
73
|
-
declare function
|
|
74
|
+
declare function callable(
|
|
74
75
|
metadata?: CallableMetadata
|
|
75
76
|
): <This, Args extends unknown[], Return>(
|
|
76
77
|
target: (this: This, ...args: Args) => Return,
|
|
77
78
|
context: ClassMethodDecoratorContext
|
|
78
79
|
) => (this: This, ...args: Args) => Return;
|
|
80
|
+
/**
|
|
81
|
+
* Decorator that marks a method as callable by clients
|
|
82
|
+
* @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
|
|
83
|
+
* @param metadata Optional metadata about the callable method
|
|
84
|
+
*/
|
|
85
|
+
declare const unstable_callable: (metadata?: CallableMetadata) => void;
|
|
79
86
|
type QueueItem<T = string> = {
|
|
80
87
|
id: string;
|
|
81
88
|
payload: T;
|
|
@@ -121,7 +128,7 @@ type Schedule<T = string> = {
|
|
|
121
128
|
* MCP Server state update message from server -> Client
|
|
122
129
|
*/
|
|
123
130
|
type MCPServerMessage = {
|
|
124
|
-
type:
|
|
131
|
+
type: MessageType.CF_AGENT_MCP_SERVERS;
|
|
125
132
|
mcp: MCPServersState;
|
|
126
133
|
};
|
|
127
134
|
type MCPServersState = {
|
|
@@ -153,7 +160,11 @@ declare function getCurrentAgent<
|
|
|
153
160
|
* @template Env Environment type containing bindings
|
|
154
161
|
* @template State State type to store within the Agent
|
|
155
162
|
*/
|
|
156
|
-
declare class Agent<
|
|
163
|
+
declare class Agent<
|
|
164
|
+
Env = typeof env,
|
|
165
|
+
State = unknown,
|
|
166
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
167
|
+
> extends Server<Env, Props> {
|
|
157
168
|
private _state;
|
|
158
169
|
private _ParentClass;
|
|
159
170
|
mcp: MCPClientManager;
|
|
@@ -489,12 +500,17 @@ type EmailSendOptions = {
|
|
|
489
500
|
* @param options Options for Agent creation
|
|
490
501
|
* @returns Promise resolving to an Agent instance stub
|
|
491
502
|
*/
|
|
492
|
-
declare function getAgentByName<
|
|
503
|
+
declare function getAgentByName<
|
|
504
|
+
Env,
|
|
505
|
+
T extends Agent<Env>,
|
|
506
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
507
|
+
>(
|
|
493
508
|
namespace: AgentNamespace<T>,
|
|
494
509
|
name: string,
|
|
495
510
|
options?: {
|
|
496
511
|
jurisdiction?: DurableObjectJurisdiction;
|
|
497
512
|
locationHint?: DurableObjectLocationHint;
|
|
513
|
+
props?: Props;
|
|
498
514
|
}
|
|
499
515
|
): Promise<DurableObjectStub<T>>;
|
|
500
516
|
/**
|
|
@@ -536,6 +552,7 @@ export {
|
|
|
536
552
|
type Schedule,
|
|
537
553
|
type StateUpdateMessage,
|
|
538
554
|
StreamingResponse,
|
|
555
|
+
callable,
|
|
539
556
|
createAddressBasedEmailResolver,
|
|
540
557
|
createCatchAllEmailResolver,
|
|
541
558
|
createHeaderBasedEmailResolver,
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent,
|
|
3
3
|
StreamingResponse,
|
|
4
|
+
callable,
|
|
4
5
|
createAddressBasedEmailResolver,
|
|
5
6
|
createCatchAllEmailResolver,
|
|
6
7
|
createHeaderBasedEmailResolver,
|
|
@@ -9,13 +10,15 @@ import {
|
|
|
9
10
|
routeAgentEmail,
|
|
10
11
|
routeAgentRequest,
|
|
11
12
|
unstable_callable
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-YDUDMOL6.js";
|
|
14
|
+
import "./chunk-MH46VMM4.js";
|
|
15
|
+
import "./chunk-LL2AFX7V.js";
|
|
16
|
+
import "./chunk-QEVM4BVL.js";
|
|
17
|
+
import "./chunk-AVYJQSLW.js";
|
|
16
18
|
export {
|
|
17
19
|
Agent,
|
|
18
20
|
StreamingResponse,
|
|
21
|
+
callable,
|
|
19
22
|
createAddressBasedEmailResolver,
|
|
20
23
|
createCatchAllEmailResolver,
|
|
21
24
|
createHeaderBasedEmailResolver,
|
package/dist/mcp/client.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import '@modelcontextprotocol/sdk/client/index.js';
|
|
|
3
3
|
import '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
4
4
|
import '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import 'ai';
|
|
6
|
-
export { M as MCPClientManager, g as getNamespacedData } from '../client-
|
|
6
|
+
export { M as MCPClientManager, g as getNamespacedData } from '../client-CvaJdLQA.js';
|
|
7
7
|
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
8
8
|
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
9
9
|
import './do-oauth-client-provider.js';
|
package/dist/mcp/client.js
CHANGED
|
@@ -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);
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import { M as MCPClientManager } from '../client-DgyzBU_8.js';
|
|
2
|
-
export { S as SSEEdgeClientTransport, a as StreamableHTTPEdgeClientTransport } from '../client-DgyzBU_8.js';
|
|
3
|
-
import { DurableObject } from 'cloudflare:workers';
|
|
4
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
3
|
import { ElicitResult } from '@modelcontextprotocol/sdk/types.js';
|
|
7
4
|
export { ElicitRequest, ElicitRequestSchema, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
-
import {
|
|
9
|
-
|
|
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';
|
|
10
9
|
import '@modelcontextprotocol/sdk/client/index.js';
|
|
11
|
-
import '
|
|
10
|
+
import '../observability/index.js';
|
|
11
|
+
import '../ai-types.js';
|
|
12
12
|
import 'ai';
|
|
13
|
+
import 'zod';
|
|
14
|
+
import '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
13
15
|
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
14
16
|
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
15
17
|
import './do-oauth-client-provider.js';
|
|
16
18
|
import '@modelcontextprotocol/sdk/client/auth.js';
|
|
17
19
|
import '@modelcontextprotocol/sdk/shared/auth.js';
|
|
18
20
|
|
|
21
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
22
|
+
type TransportType = "sse" | "streamable-http";
|
|
19
23
|
interface CORSOptions {
|
|
20
24
|
origin?: string;
|
|
21
25
|
methods?: string;
|
|
@@ -23,88 +27,69 @@ interface CORSOptions {
|
|
|
23
27
|
maxAge?: number;
|
|
24
28
|
exposeHeaders?: string;
|
|
25
29
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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> {
|
|
29
37
|
private _transport?;
|
|
30
|
-
private _transportType;
|
|
31
38
|
private _requestIdToConnectionId;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* to the outer class: initialState/state/setState/onStateUpdate/sql
|
|
35
|
-
*/
|
|
36
|
-
private _agent;
|
|
37
|
-
get mcp(): MCPClientManager;
|
|
38
|
-
protected constructor(ctx: DurableObjectState, env: Env);
|
|
39
|
-
/**
|
|
40
|
-
* Agents API allowlist
|
|
41
|
-
*/
|
|
42
|
-
initialState: State;
|
|
43
|
-
get state(): State;
|
|
44
|
-
sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
|
|
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>;
|
|
53
|
-
onStateUpdate(state: State | undefined, source: Connection | "server"): void;
|
|
54
|
-
onStart(): Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* McpAgent API
|
|
57
|
-
*/
|
|
39
|
+
private _standaloneSseConnectionId?;
|
|
40
|
+
props?: Props;
|
|
58
41
|
abstract server: MaybePromise<McpServer | Server>;
|
|
59
|
-
props: Props;
|
|
60
|
-
initRun: boolean;
|
|
61
42
|
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
|
-
};
|
|
72
|
-
_init(props: Props): Promise<void>;
|
|
43
|
+
constructor(ctx: AgentContext, env: Env);
|
|
73
44
|
setInitialized(): Promise<void>;
|
|
74
45
|
isInitialized(): Promise<boolean>;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
getWebSocket(): WebSocket | null;
|
|
79
|
-
getWebSocketForResponseID(id: string): WebSocket | null;
|
|
80
|
-
onMessage(connection: Connection, event: WSMessage): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* 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}`.
|
|
83
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 */
|
|
84
77
|
private _waitForElicitationResponse;
|
|
85
|
-
/**
|
|
86
|
-
* Handle elicitation responses */
|
|
78
|
+
/** Handle elicitation responses */
|
|
87
79
|
private _handleElicitationResponse;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
static mount(path: string, { binding, corsOptions }?: {
|
|
93
|
-
binding?: string;
|
|
94
|
-
corsOptions?: CORSOptions;
|
|
95
|
-
}): {
|
|
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): {
|
|
96
84
|
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
97
85
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Legacy api
|
|
88
|
+
**/
|
|
89
|
+
static mount(path: string, opts?: Omit<ServeOptions, "transport">): {
|
|
102
90
|
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
103
91
|
};
|
|
104
|
-
static
|
|
105
|
-
binding?: string;
|
|
106
|
-
corsOptions?: CORSOptions;
|
|
107
|
-
}): {
|
|
92
|
+
static serveSSE(path: string, opts?: Omit<ServeOptions, "transport">): {
|
|
108
93
|
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
109
94
|
};
|
|
110
95
|
}
|