agents 0.0.0-fbf5181 → 0.0.0-fce47ef
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/dist/ai-chat-agent.d.ts +46 -4
- package/dist/ai-chat-agent.js +138 -68
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.d.ts +17 -4
- package/dist/ai-react.js +48 -37
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.d.ts +5 -0
- package/dist/chunk-767EASBA.js +106 -0
- package/dist/chunk-767EASBA.js.map +1 -0
- package/dist/chunk-E3LCYPCB.js +469 -0
- package/dist/chunk-E3LCYPCB.js.map +1 -0
- package/dist/chunk-NKZZ66QY.js +116 -0
- package/dist/chunk-NKZZ66QY.js.map +1 -0
- package/dist/{chunk-XG52S6YY.js → chunk-ZRRXJUAA.js} +357 -160
- package/dist/chunk-ZRRXJUAA.js.map +1 -0
- package/dist/client.d.ts +15 -1
- package/dist/client.js +6 -126
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +123 -14
- package/dist/index.js +8 -6
- package/dist/mcp/client.d.ts +33 -13
- package/dist/mcp/client.js +3 -402
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/do-oauth-client-provider.d.ts +3 -3
- package/dist/mcp/do-oauth-client-provider.js +3 -103
- package/dist/mcp/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/index.d.ts +30 -7
- package/dist/mcp/index.js +179 -174
- package/dist/mcp/index.js.map +1 -1
- package/dist/react.d.ts +85 -5
- package/dist/react.js +20 -8
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +2 -2
- package/dist/schedule.js +4 -6
- package/dist/schedule.js.map +1 -1
- package/dist/serializable.d.ts +32 -0
- package/dist/serializable.js +1 -0
- package/package.json +71 -65
- package/src/index.ts +429 -86
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-XG52S6YY.js.map +0 -1
- /package/dist/{chunk-HMLY7DHA.js.map → serializable.js.map} +0 -0
|
@@ -1,106 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
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":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
|
+
import { MCPClientManager } from './client.js';
|
|
1
2
|
import { DurableObject } from 'cloudflare:workers';
|
|
2
|
-
import {
|
|
3
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
4
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
import { Connection, WSMessage } from 'partyserver';
|
|
6
|
+
import 'zod';
|
|
7
|
+
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';
|
|
11
|
+
import 'ai';
|
|
12
|
+
import './do-oauth-client-provider.js';
|
|
13
|
+
import '@modelcontextprotocol/sdk/client/auth.js';
|
|
14
|
+
import '@modelcontextprotocol/sdk/shared/auth.js';
|
|
4
15
|
|
|
5
16
|
interface CORSOptions {
|
|
6
17
|
origin?: string;
|
|
7
18
|
methods?: string;
|
|
8
19
|
headers?: string;
|
|
9
20
|
maxAge?: number;
|
|
21
|
+
exposeHeaders?: string;
|
|
10
22
|
}
|
|
23
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
11
24
|
declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends DurableObject<Env> {
|
|
12
|
-
|
|
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;
|
|
34
|
+
get mcp(): MCPClientManager;
|
|
13
35
|
protected constructor(ctx: DurableObjectState, env: Env);
|
|
14
36
|
/**
|
|
15
37
|
* Agents API allowlist
|
|
@@ -23,18 +45,19 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
|
|
|
23
45
|
/**
|
|
24
46
|
* McpAgent API
|
|
25
47
|
*/
|
|
26
|
-
abstract server: McpServer
|
|
48
|
+
abstract server: MaybePromise<McpServer | Server>;
|
|
27
49
|
props: Props;
|
|
28
50
|
initRun: boolean;
|
|
29
51
|
abstract init(): Promise<void>;
|
|
30
52
|
_init(props: Props): Promise<void>;
|
|
31
53
|
setInitialized(): Promise<void>;
|
|
32
54
|
isInitialized(): Promise<boolean>;
|
|
55
|
+
private _initialize;
|
|
33
56
|
fetch(request: Request): Promise<Response>;
|
|
34
57
|
getWebSocket(): WebSocket | null;
|
|
35
58
|
getWebSocketForResponseID(id: string): WebSocket | null;
|
|
36
59
|
onMessage(connection: Connection, event: WSMessage): Promise<void>;
|
|
37
|
-
onSSEMcpMessage(
|
|
60
|
+
onSSEMcpMessage(_sessionId: string, request: Request): Promise<Error | null>;
|
|
38
61
|
webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
|
|
39
62
|
webSocketError(ws: WebSocket, error: unknown): Promise<void>;
|
|
40
63
|
webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
|
|
@@ -42,19 +65,19 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
|
|
|
42
65
|
binding?: string;
|
|
43
66
|
corsOptions?: CORSOptions;
|
|
44
67
|
}): {
|
|
45
|
-
fetch:
|
|
68
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
46
69
|
};
|
|
47
70
|
static serveSSE(path: string, { binding, corsOptions, }?: {
|
|
48
71
|
binding?: string;
|
|
49
72
|
corsOptions?: CORSOptions;
|
|
50
73
|
}): {
|
|
51
|
-
fetch:
|
|
74
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
52
75
|
};
|
|
53
76
|
static serve(path: string, { binding, corsOptions, }?: {
|
|
54
77
|
binding?: string;
|
|
55
78
|
corsOptions?: CORSOptions;
|
|
56
79
|
}): {
|
|
57
|
-
fetch:
|
|
80
|
+
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
58
81
|
};
|
|
59
82
|
}
|
|
60
83
|
|