agents 0.0.0-cec3cca → 0.0.0-cf3b3d7
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 +3 -3
- package/dist/ai-chat-agent.js +3 -3
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.d.ts +4 -4
- package/dist/ai-react.js +8 -3
- package/dist/ai-react.js.map +1 -1
- package/dist/{client-Csp_m13H.d.ts → client-BaCHMay9.d.ts} +191 -79
- package/dist/{client-9Ld2_lnt.js → client-DpkZyXgJ.js} +239 -124
- package/dist/client-DpkZyXgJ.js.map +1 -0
- package/dist/codemode/ai.js +3 -3
- package/dist/do-oauth-client-provider-CnbnngL2.d.ts +134 -0
- package/dist/{do-oauth-client-provider-CswoD5Lu.js → do-oauth-client-provider-D2P1lSft.js} +2 -2
- package/dist/do-oauth-client-provider-D2P1lSft.js.map +1 -0
- package/dist/{index-DFqsR7mb.d.ts → index-DCRAdW9R.d.ts} +30 -18
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/mcp/client.d.ts +3 -3
- package/dist/mcp/client.js +2 -1
- package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/do-oauth-client-provider.js +1 -1
- package/dist/mcp/index.d.ts +68 -29
- package/dist/mcp/index.js +80 -10
- package/dist/mcp/index.js.map +1 -1
- package/dist/observability/index.js +3 -3
- package/dist/{react-NCPvtyCY.d.ts → react-DM_FD53F.d.ts} +31 -33
- package/dist/react.d.ts +4 -4
- package/dist/{src-Dz0H9hSU.js → src-Dk8lwxHf.js} +181 -138
- package/dist/src-Dk8lwxHf.js.map +1 -0
- package/package.json +46 -38
- package/dist/client-9Ld2_lnt.js.map +0 -1
- package/dist/do-oauth-client-provider-CswoD5Lu.js.map +0 -1
- package/dist/do-oauth-client-provider-DGc5pP0l.d.ts +0 -55
- package/dist/src-Dz0H9hSU.js.map +0 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
2
|
+
import {
|
|
3
|
+
OAuthClientInformationFull,
|
|
4
|
+
OAuthClientMetadata,
|
|
5
|
+
OAuthTokens
|
|
6
|
+
} from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
7
|
+
|
|
8
|
+
//#region src/mcp/client-storage.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Represents a row in the cf_agents_mcp_servers table
|
|
11
|
+
*/
|
|
12
|
+
type MCPServerRow = {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
server_url: string;
|
|
16
|
+
client_id: string | null;
|
|
17
|
+
auth_url: string | null;
|
|
18
|
+
callback_url: string;
|
|
19
|
+
server_options: string | null;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* KV storage interface for OAuth-related data
|
|
23
|
+
* Used by OAuth providers to store tokens, client info, etc.
|
|
24
|
+
*/
|
|
25
|
+
interface OAuthClientStorage {
|
|
26
|
+
/**
|
|
27
|
+
* Get a value from key-value storage (for OAuth data like tokens, client info, etc.)
|
|
28
|
+
*/
|
|
29
|
+
get<T>(key: string): Promise<T | undefined> | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Put a value into key-value storage (for OAuth data like tokens, client info, etc.)
|
|
32
|
+
*/
|
|
33
|
+
put(key: string, value: unknown): Promise<void> | void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Storage interface for MCP client manager
|
|
37
|
+
* Abstracts storage operations to decouple from specific storage implementations
|
|
38
|
+
*/
|
|
39
|
+
interface MCPClientStorage extends OAuthClientStorage {
|
|
40
|
+
/**
|
|
41
|
+
* Save or update an MCP server configuration
|
|
42
|
+
*/
|
|
43
|
+
saveServer(server: MCPServerRow): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Remove an MCP server from storage
|
|
46
|
+
*/
|
|
47
|
+
removeServer(serverId: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* List all MCP servers from storage
|
|
50
|
+
*/
|
|
51
|
+
listServers(): Promise<MCPServerRow[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Get an MCP server by its callback URL
|
|
54
|
+
* Used during OAuth callback to identify which server is being authenticated
|
|
55
|
+
*/
|
|
56
|
+
getServerByCallbackUrl(callbackUrl: string): Promise<MCPServerRow | null>;
|
|
57
|
+
/**
|
|
58
|
+
* Clear auth_url after successful OAuth authentication
|
|
59
|
+
* This prevents the agent from continuously asking for OAuth on reconnect
|
|
60
|
+
* when stored tokens are still valid.
|
|
61
|
+
*/
|
|
62
|
+
clearAuthUrl(serverId: string): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/mcp/do-oauth-client-provider.d.ts
|
|
66
|
+
interface AgentsOAuthProvider extends OAuthClientProvider {
|
|
67
|
+
authUrl: string | undefined;
|
|
68
|
+
clientId: string | undefined;
|
|
69
|
+
serverId: string | undefined;
|
|
70
|
+
}
|
|
71
|
+
declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
|
|
72
|
+
storage: OAuthClientStorage;
|
|
73
|
+
clientName: string;
|
|
74
|
+
baseRedirectUrl: string;
|
|
75
|
+
private _authUrl_;
|
|
76
|
+
private _serverId_;
|
|
77
|
+
private _clientId_;
|
|
78
|
+
constructor(
|
|
79
|
+
storage: OAuthClientStorage,
|
|
80
|
+
clientName: string,
|
|
81
|
+
baseRedirectUrl: string
|
|
82
|
+
);
|
|
83
|
+
get clientMetadata(): OAuthClientMetadata;
|
|
84
|
+
get clientUri(): string;
|
|
85
|
+
get redirectUrl(): string;
|
|
86
|
+
get clientId(): string;
|
|
87
|
+
set clientId(clientId_: string);
|
|
88
|
+
get serverId(): string;
|
|
89
|
+
set serverId(serverId_: string);
|
|
90
|
+
keyPrefix(clientId: string): string;
|
|
91
|
+
clientInfoKey(clientId: string): string;
|
|
92
|
+
clientInformation(): Promise<
|
|
93
|
+
| {
|
|
94
|
+
client_id: string;
|
|
95
|
+
client_secret?: string | undefined;
|
|
96
|
+
client_id_issued_at?: number | undefined;
|
|
97
|
+
client_secret_expires_at?: number | undefined;
|
|
98
|
+
}
|
|
99
|
+
| undefined
|
|
100
|
+
>;
|
|
101
|
+
saveClientInformation(
|
|
102
|
+
clientInformation: OAuthClientInformationFull
|
|
103
|
+
): Promise<void>;
|
|
104
|
+
tokenKey(clientId: string): string;
|
|
105
|
+
tokens(): Promise<
|
|
106
|
+
| {
|
|
107
|
+
access_token: string;
|
|
108
|
+
token_type: string;
|
|
109
|
+
id_token?: string | undefined;
|
|
110
|
+
expires_in?: number | undefined;
|
|
111
|
+
scope?: string | undefined;
|
|
112
|
+
refresh_token?: string | undefined;
|
|
113
|
+
}
|
|
114
|
+
| undefined
|
|
115
|
+
>;
|
|
116
|
+
saveTokens(tokens: OAuthTokens): Promise<void>;
|
|
117
|
+
get authUrl(): string | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Because this operates on the server side (but we need browser auth), we send this url back to the user
|
|
120
|
+
* and require user interact to initiate the redirect flow
|
|
121
|
+
*/
|
|
122
|
+
redirectToAuthorization(authUrl: URL): void;
|
|
123
|
+
codeVerifierKey(clientId: string): string;
|
|
124
|
+
saveCodeVerifier(verifier: string): Promise<void>;
|
|
125
|
+
codeVerifier(): Promise<string>;
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
export {
|
|
129
|
+
MCPServerRow as i,
|
|
130
|
+
DurableObjectOAuthClientProvider as n,
|
|
131
|
+
MCPClientStorage as r,
|
|
132
|
+
AgentsOAuthProvider as t
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=do-oauth-client-provider-CnbnngL2.d.ts.map
|
|
@@ -68,7 +68,7 @@ var DurableObjectOAuthClientProvider = class {
|
|
|
68
68
|
* Because this operates on the server side (but we need browser auth), we send this url back to the user
|
|
69
69
|
* and require user interact to initiate the redirect flow
|
|
70
70
|
*/
|
|
71
|
-
|
|
71
|
+
redirectToAuthorization(authUrl) {
|
|
72
72
|
const stateToken = nanoid();
|
|
73
73
|
authUrl.searchParams.set("state", stateToken);
|
|
74
74
|
this._authUrl_ = authUrl.toString();
|
|
@@ -90,4 +90,4 @@ var DurableObjectOAuthClientProvider = class {
|
|
|
90
90
|
|
|
91
91
|
//#endregion
|
|
92
92
|
export { DurableObjectOAuthClientProvider as t };
|
|
93
|
-
//# sourceMappingURL=do-oauth-client-provider-
|
|
93
|
+
//# sourceMappingURL=do-oauth-client-provider-D2P1lSft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"do-oauth-client-provider-D2P1lSft.js","names":["storage: OAuthClientStorage","clientName: string","baseRedirectUrl: string"],"sources":["../src/mcp/do-oauth-client-provider.ts"],"sourcesContent":["import type { OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport type {\n OAuthClientInformation,\n OAuthClientInformationFull,\n OAuthClientMetadata,\n OAuthTokens\n} from \"@modelcontextprotocol/sdk/shared/auth.js\";\nimport { nanoid } from \"nanoid\";\nimport type { OAuthClientStorage } from \"./client-storage\";\n\n// A slight extension to the standard OAuthClientProvider interface because `redirectToAuthorization` doesn't give us the interface we need\n// This allows us to track authentication for a specific server and associated dynamic client registration\nexport interface AgentsOAuthProvider extends OAuthClientProvider {\n authUrl: string | undefined;\n clientId: string | undefined;\n serverId: string | undefined;\n}\n\nexport class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {\n private _authUrl_: string | undefined;\n private _serverId_: string | undefined;\n private _clientId_: string | undefined;\n\n constructor(\n public storage: OAuthClientStorage,\n public clientName: string,\n public baseRedirectUrl: string\n ) {}\n\n get clientMetadata(): OAuthClientMetadata {\n return {\n client_name: this.clientName,\n client_uri: this.clientUri,\n grant_types: [\"authorization_code\", \"refresh_token\"],\n redirect_uris: [this.redirectUrl],\n response_types: [\"code\"],\n token_endpoint_auth_method: \"none\"\n };\n }\n\n get clientUri() {\n return new URL(this.redirectUrl).origin;\n }\n\n get redirectUrl() {\n return `${this.baseRedirectUrl}/${this.serverId}`;\n }\n\n get clientId() {\n if (!this._clientId_) {\n throw new Error(\"Trying to access clientId before it was set\");\n }\n return this._clientId_;\n }\n\n set clientId(clientId_: string) {\n this._clientId_ = clientId_;\n }\n\n get serverId() {\n if (!this._serverId_) {\n throw new Error(\"Trying to access serverId before it was set\");\n }\n return this._serverId_;\n }\n\n set serverId(serverId_: string) {\n this._serverId_ = serverId_;\n }\n\n keyPrefix(clientId: string) {\n return `/${this.clientName}/${this.serverId}/${clientId}`;\n }\n\n clientInfoKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/client_info/`;\n }\n\n async clientInformation() {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthClientInformation>(\n this.clientInfoKey(this.clientId)\n )) ?? undefined\n );\n }\n\n async saveClientInformation(clientInformation: OAuthClientInformationFull) {\n await this.storage.put(\n this.clientInfoKey(clientInformation.client_id),\n clientInformation\n );\n this.clientId = clientInformation.client_id;\n }\n\n tokenKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/token`;\n }\n\n async tokens() {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthTokens>(this.tokenKey(this.clientId))) ??\n undefined\n );\n }\n\n async saveTokens(tokens: OAuthTokens) {\n await this.storage.put(this.tokenKey(this.clientId), tokens);\n }\n\n get authUrl() {\n return this._authUrl_;\n }\n\n /**\n * Because this operates on the server side (but we need browser auth), we send this url back to the user\n * and require user interact to initiate the redirect flow\n */\n redirectToAuthorization(authUrl: URL) {\n // Generate secure random token for state parameter\n const stateToken = nanoid();\n authUrl.searchParams.set(\"state\", stateToken);\n this._authUrl_ = authUrl.toString();\n }\n\n codeVerifierKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/code_verifier`;\n }\n\n async saveCodeVerifier(verifier: string) {\n const key = this.codeVerifierKey(this.clientId);\n\n // Don't overwrite existing verifier to preserve first PKCE verifier\n const existing = await this.storage.get<string>(key);\n if (existing) {\n return;\n }\n\n await this.storage.put(key, verifier);\n }\n\n async codeVerifier() {\n const codeVerifier = await this.storage.get<string>(\n this.codeVerifierKey(this.clientId)\n );\n if (!codeVerifier) {\n throw new Error(\"No code verifier found\");\n }\n return codeVerifier;\n }\n}\n"],"mappings":";;;AAkBA,IAAa,mCAAb,MAA6E;CAK3E,YACE,AAAOA,SACP,AAAOC,YACP,AAAOC,iBACP;EAHO;EACA;EACA;;CAGT,IAAI,iBAAsC;AACxC,SAAO;GACL,aAAa,KAAK;GAClB,YAAY,KAAK;GACjB,aAAa,CAAC,sBAAsB,gBAAgB;GACpD,eAAe,CAAC,KAAK,YAAY;GACjC,gBAAgB,CAAC,OAAO;GACxB,4BAA4B;GAC7B;;CAGH,IAAI,YAAY;AACd,SAAO,IAAI,IAAI,KAAK,YAAY,CAAC;;CAGnC,IAAI,cAAc;AAChB,SAAO,GAAG,KAAK,gBAAgB,GAAG,KAAK;;CAGzC,IAAI,WAAW;AACb,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MAAM,8CAA8C;AAEhE,SAAO,KAAK;;CAGd,IAAI,SAAS,WAAmB;AAC9B,OAAK,aAAa;;CAGpB,IAAI,WAAW;AACb,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MAAM,8CAA8C;AAEhE,SAAO,KAAK;;CAGd,IAAI,SAAS,WAAmB;AAC9B,OAAK,aAAa;;CAGpB,UAAU,UAAkB;AAC1B,SAAO,IAAI,KAAK,WAAW,GAAG,KAAK,SAAS,GAAG;;CAGjD,cAAc,UAAkB;AAC9B,SAAO,GAAG,KAAK,UAAU,SAAS,CAAC;;CAGrC,MAAM,oBAAoB;AACxB,MAAI,CAAC,KAAK,WACR;AAEF,SACG,MAAM,KAAK,QAAQ,IAClB,KAAK,cAAc,KAAK,SAAS,CAClC,IAAK;;CAIV,MAAM,sBAAsB,mBAA+C;AACzE,QAAM,KAAK,QAAQ,IACjB,KAAK,cAAc,kBAAkB,UAAU,EAC/C,kBACD;AACD,OAAK,WAAW,kBAAkB;;CAGpC,SAAS,UAAkB;AACzB,SAAO,GAAG,KAAK,UAAU,SAAS,CAAC;;CAGrC,MAAM,SAAS;AACb,MAAI,CAAC,KAAK,WACR;AAEF,SACG,MAAM,KAAK,QAAQ,IAAiB,KAAK,SAAS,KAAK,SAAS,CAAC,IAClE;;CAIJ,MAAM,WAAW,QAAqB;AACpC,QAAM,KAAK,QAAQ,IAAI,KAAK,SAAS,KAAK,SAAS,EAAE,OAAO;;CAG9D,IAAI,UAAU;AACZ,SAAO,KAAK;;;;;;CAOd,wBAAwB,SAAc;EAEpC,MAAM,aAAa,QAAQ;AAC3B,UAAQ,aAAa,IAAI,SAAS,WAAW;AAC7C,OAAK,YAAY,QAAQ,UAAU;;CAGrC,gBAAgB,UAAkB;AAChC,SAAO,GAAG,KAAK,UAAU,SAAS,CAAC;;CAGrC,MAAM,iBAAiB,UAAkB;EACvC,MAAM,MAAM,KAAK,gBAAgB,KAAK,SAAS;AAI/C,MADiB,MAAM,KAAK,QAAQ,IAAY,IAAI,CAElD;AAGF,QAAM,KAAK,QAAQ,IAAI,KAAK,SAAS;;CAGvC,MAAM,eAAe;EACnB,MAAM,eAAe,MAAM,KAAK,QAAQ,IACtC,KAAK,gBAAgB,KAAK,SAAS,CACpC;AACD,MAAI,CAAC,aACH,OAAM,IAAI,MAAM,yBAAyB;AAE3C,SAAO"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "./client-
|
|
2
|
+
l as MCPConnectionState,
|
|
3
|
+
m as TransportType,
|
|
4
|
+
t as MCPClientManager
|
|
5
|
+
} from "./client-BaCHMay9.js";
|
|
6
6
|
import { t as Observability } from "./index-DhJCaDWd.js";
|
|
7
7
|
import { n as MessageType } from "./ai-types-D5YoPrBZ.js";
|
|
8
8
|
import {
|
|
@@ -87,9 +87,9 @@ declare function callable(
|
|
|
87
87
|
* @param metadata Optional metadata about the callable method
|
|
88
88
|
*/
|
|
89
89
|
declare const unstable_callable: (metadata?: CallableMetadata) => void;
|
|
90
|
-
type QueueItem<T
|
|
90
|
+
type QueueItem<T = string> = {
|
|
91
91
|
id: string;
|
|
92
|
-
payload: T
|
|
92
|
+
payload: T;
|
|
93
93
|
callback: keyof Agent<unknown>;
|
|
94
94
|
created_at: number;
|
|
95
95
|
};
|
|
@@ -97,13 +97,13 @@ type QueueItem<T$1 = string> = {
|
|
|
97
97
|
* Represents a scheduled task within an Agent
|
|
98
98
|
* @template T Type of the payload data
|
|
99
99
|
*/
|
|
100
|
-
type Schedule<T
|
|
100
|
+
type Schedule<T = string> = {
|
|
101
101
|
/** Unique identifier for the schedule */
|
|
102
102
|
id: string;
|
|
103
103
|
/** Name of the method to be called */
|
|
104
104
|
callback: string;
|
|
105
105
|
/** Data to be passed to the callback */
|
|
106
|
-
payload: T
|
|
106
|
+
payload: T;
|
|
107
107
|
} & (
|
|
108
108
|
| {
|
|
109
109
|
/** Type of schedule for one-time execution at a specific time */
|
|
@@ -152,9 +152,9 @@ type MCPServer = {
|
|
|
152
152
|
capabilities: ServerCapabilities | null;
|
|
153
153
|
};
|
|
154
154
|
declare function getCurrentAgent<
|
|
155
|
-
T
|
|
155
|
+
T extends Agent<unknown, unknown> = Agent<unknown, unknown>
|
|
156
156
|
>(): {
|
|
157
|
-
agent: T
|
|
157
|
+
agent: T | undefined;
|
|
158
158
|
connection: Connection | undefined;
|
|
159
159
|
request: Request | undefined;
|
|
160
160
|
email: AgentEmail | undefined;
|
|
@@ -171,7 +171,7 @@ declare class Agent<
|
|
|
171
171
|
> extends Server<Env, Props> {
|
|
172
172
|
private _state;
|
|
173
173
|
private _disposables;
|
|
174
|
-
private
|
|
174
|
+
private _destroyed;
|
|
175
175
|
private _ParentClass;
|
|
176
176
|
readonly mcp: MCPClientManager;
|
|
177
177
|
/**
|
|
@@ -347,7 +347,6 @@ declare class Agent<
|
|
|
347
347
|
* @returns A map of method names to their metadata
|
|
348
348
|
*/
|
|
349
349
|
private _isCallable;
|
|
350
|
-
private _ensureMcpStateRestored;
|
|
351
350
|
/**
|
|
352
351
|
* Connect to a new MCP Server
|
|
353
352
|
*
|
|
@@ -374,10 +373,23 @@ declare class Agent<
|
|
|
374
373
|
id: string;
|
|
375
374
|
authUrl: string | undefined;
|
|
376
375
|
}>;
|
|
377
|
-
private _connectToMcpServerInternal;
|
|
378
376
|
removeMcpServer(id: string): Promise<void>;
|
|
379
|
-
getMcpServers(): MCPServersState
|
|
377
|
+
getMcpServers(): Promise<MCPServersState>;
|
|
380
378
|
private broadcastMcpServers;
|
|
379
|
+
/**
|
|
380
|
+
* Handle MCP OAuth callback request if it's an OAuth callback.
|
|
381
|
+
*
|
|
382
|
+
* This method encapsulates the entire OAuth callback flow:
|
|
383
|
+
* 1. Checks if the request is an MCP OAuth callback
|
|
384
|
+
* 2. Processes the OAuth code exchange
|
|
385
|
+
* 3. Establishes the connection if successful
|
|
386
|
+
* 4. Broadcasts MCP server state updates
|
|
387
|
+
* 5. Returns the appropriate HTTP response
|
|
388
|
+
*
|
|
389
|
+
* @param request The incoming HTTP request
|
|
390
|
+
* @returns Response if this was an OAuth callback, null otherwise
|
|
391
|
+
*/
|
|
392
|
+
private handleMcpOAuthCallback;
|
|
381
393
|
/**
|
|
382
394
|
* Handle OAuth callback response using MCPClientManager configuration
|
|
383
395
|
* @param result OAuth callback result
|
|
@@ -494,17 +506,17 @@ type EmailSendOptions = {
|
|
|
494
506
|
*/
|
|
495
507
|
declare function getAgentByName<
|
|
496
508
|
Env,
|
|
497
|
-
T
|
|
509
|
+
T extends Agent<Env>,
|
|
498
510
|
Props extends Record<string, unknown> = Record<string, unknown>
|
|
499
511
|
>(
|
|
500
|
-
namespace: AgentNamespace<T
|
|
512
|
+
namespace: AgentNamespace<T>,
|
|
501
513
|
name: string,
|
|
502
514
|
options?: {
|
|
503
515
|
jurisdiction?: DurableObjectJurisdiction;
|
|
504
516
|
locationHint?: DurableObjectLocationHint;
|
|
505
517
|
props?: Props;
|
|
506
518
|
}
|
|
507
|
-
): Promise<DurableObjectStub<T
|
|
519
|
+
): Promise<DurableObjectStub<T>>;
|
|
508
520
|
/**
|
|
509
521
|
* A wrapper for streaming responses in callable methods
|
|
510
522
|
*/
|
|
@@ -557,4 +569,4 @@ export {
|
|
|
557
569
|
WSMessage as x,
|
|
558
570
|
StateUpdateMessage as y
|
|
559
571
|
};
|
|
560
|
-
//# sourceMappingURL=index-
|
|
572
|
+
//# sourceMappingURL=index-DCRAdW9R.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as TransportType } from "./client-BaCHMay9.js";
|
|
2
2
|
import "./mcp-Dw5vDrY8.js";
|
|
3
|
-
import "./do-oauth-client-provider-
|
|
3
|
+
import "./do-oauth-client-provider-CnbnngL2.js";
|
|
4
4
|
import "./index-DhJCaDWd.js";
|
|
5
5
|
import "./ai-types-D5YoPrBZ.js";
|
|
6
6
|
import {
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
w as createCatchAllEmailResolver,
|
|
35
35
|
x as WSMessage,
|
|
36
36
|
y as StateUpdateMessage
|
|
37
|
-
} from "./index-
|
|
37
|
+
} from "./index-DCRAdW9R.js";
|
|
38
38
|
export {
|
|
39
39
|
Agent,
|
|
40
40
|
AgentContext,
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./ai-types-B3aQaFv3.js";
|
|
2
2
|
import "./client-BfiZ3HQd.js";
|
|
3
|
-
import "./client-
|
|
4
|
-
import "./do-oauth-client-provider-
|
|
5
|
-
import { a as createCatchAllEmailResolver, c as getCurrentAgent, d as unstable_callable, i as createAddressBasedEmailResolver, l as routeAgentEmail, n as StreamingResponse, o as createHeaderBasedEmailResolver, r as callable, s as getAgentByName, t as Agent, u as routeAgentRequest } from "./src-
|
|
3
|
+
import "./client-DpkZyXgJ.js";
|
|
4
|
+
import "./do-oauth-client-provider-D2P1lSft.js";
|
|
5
|
+
import { a as createCatchAllEmailResolver, c as getCurrentAgent, d as unstable_callable, i as createAddressBasedEmailResolver, l as routeAgentEmail, n as StreamingResponse, o as createHeaderBasedEmailResolver, r as callable, s as getAgentByName, t as Agent, u as routeAgentRequest } from "./src-Dk8lwxHf.js";
|
|
6
6
|
|
|
7
7
|
export { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };
|
package/dist/mcp/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as MCPConnectionResult, c as getNamespacedData, i as MCPClientOAuthResult, n as MCPClientManagerOptions, o as MCPServerOptions, r as MCPClientOAuthCallbackConfig, s as RegisterServerOptions, t as MCPClientManager } from "../client-BaCHMay9.js";
|
|
2
2
|
import "../mcp-Dw5vDrY8.js";
|
|
3
|
-
import "../do-oauth-client-provider-
|
|
4
|
-
export { MCPClientManager, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, getNamespacedData };
|
|
3
|
+
import "../do-oauth-client-provider-CnbnngL2.js";
|
|
4
|
+
export { MCPClientManager, MCPClientManagerOptions, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MCPConnectionResult, MCPServerOptions, RegisterServerOptions, getNamespacedData };
|
package/dist/mcp/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { n as getNamespacedData, t as MCPClientManager } from "../client-
|
|
1
|
+
import { n as getNamespacedData, t as MCPClientManager } from "../client-DpkZyXgJ.js";
|
|
2
|
+
import "../do-oauth-client-provider-D2P1lSft.js";
|
|
2
3
|
|
|
3
4
|
export { MCPClientManager, getNamespacedData };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider-
|
|
1
|
+
import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider-CnbnngL2.js";
|
|
2
2
|
export { AgentsOAuthProvider, DurableObjectOAuthClientProvider };
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,23 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as MCPConnectionResult, d as CORSOptions, f as MaybePromise, i as MCPClientOAuthResult, o as MCPServerOptions, p as ServeOptions, r as MCPClientOAuthCallbackConfig, u as BaseTransportType } from "../client-BaCHMay9.js";
|
|
2
2
|
import "../mcp-Dw5vDrY8.js";
|
|
3
|
-
import "../do-oauth-client-provider-
|
|
3
|
+
import "../do-oauth-client-provider-CnbnngL2.js";
|
|
4
4
|
import "../index-DhJCaDWd.js";
|
|
5
5
|
import "../ai-types-D5YoPrBZ.js";
|
|
6
|
-
import { c as ConnectionContext, s as Connection, t as Agent } from "../index-
|
|
6
|
+
import { c as ConnectionContext, s as Connection, t as Agent } from "../index-DCRAdW9R.js";
|
|
7
|
+
import { SSEClientTransport, SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
8
|
+
import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
7
9
|
import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
|
|
8
10
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
9
11
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
-
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
12
|
+
import { Transport, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
11
13
|
|
|
14
|
+
//#region src/mcp/client-transports.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
|
|
17
|
+
*/
|
|
18
|
+
declare class SSEEdgeClientTransport extends SSEClientTransport {
|
|
19
|
+
constructor(url: URL, options: SSEClientTransportOptions);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. This alias will be removed in the next major version.
|
|
23
|
+
*/
|
|
24
|
+
declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
|
|
25
|
+
constructor(url: URL, options: StreamableHTTPClientTransportOptions);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
12
28
|
//#region src/mcp/worker-transport.d.ts
|
|
29
|
+
declare const SUPPORTED_PROTOCOL_VERSIONS: readonly ["2025-03-26", "2025-06-18"];
|
|
30
|
+
type ProtocolVersion = (typeof SUPPORTED_PROTOCOL_VERSIONS)[number];
|
|
31
|
+
interface MCPStorageApi {
|
|
32
|
+
get(): Promise<TransportState | undefined> | TransportState | undefined;
|
|
33
|
+
set(state: TransportState): Promise<void> | void;
|
|
34
|
+
}
|
|
35
|
+
interface TransportState {
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
initialized: boolean;
|
|
38
|
+
protocolVersion?: ProtocolVersion;
|
|
39
|
+
}
|
|
13
40
|
interface WorkerTransportOptions {
|
|
14
41
|
sessionIdGenerator?: () => string;
|
|
42
|
+
/**
|
|
43
|
+
* Enable traditional Request/Response mode, this will disable streaming.
|
|
44
|
+
*/
|
|
15
45
|
enableJsonResponse?: boolean;
|
|
16
46
|
onsessioninitialized?: (sessionId: string) => void;
|
|
17
47
|
corsOptions?: CORSOptions;
|
|
48
|
+
/**
|
|
49
|
+
* Optional storage api for persisting transport state.
|
|
50
|
+
* Use this to store session state in Durable Object/Agent storage
|
|
51
|
+
* so it survives hibernation/restart.
|
|
52
|
+
*/
|
|
53
|
+
storage?: MCPStorageApi;
|
|
18
54
|
}
|
|
19
55
|
declare class WorkerTransport implements Transport {
|
|
20
|
-
|
|
56
|
+
started: boolean;
|
|
21
57
|
private initialized;
|
|
22
58
|
private sessionIdGenerator?;
|
|
23
59
|
private enableJsonResponse;
|
|
@@ -28,11 +64,22 @@ declare class WorkerTransport implements Transport {
|
|
|
28
64
|
private requestResponseMap;
|
|
29
65
|
private corsOptions?;
|
|
30
66
|
private protocolVersion?;
|
|
67
|
+
private storage?;
|
|
68
|
+
private stateRestored;
|
|
31
69
|
sessionId?: string;
|
|
32
70
|
onclose?: () => void;
|
|
33
71
|
onerror?: (error: Error) => void;
|
|
34
72
|
onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
|
|
35
73
|
constructor(options?: WorkerTransportOptions);
|
|
74
|
+
/**
|
|
75
|
+
* Restore transport state from persistent storage.
|
|
76
|
+
* This is automatically called on start.
|
|
77
|
+
*/
|
|
78
|
+
private restoreState;
|
|
79
|
+
/**
|
|
80
|
+
* Persist current transport state to storage.
|
|
81
|
+
*/
|
|
82
|
+
private saveState;
|
|
36
83
|
start(): Promise<void>;
|
|
37
84
|
private validateProtocolVersion;
|
|
38
85
|
private getHeaders;
|
|
@@ -44,8 +91,14 @@ declare class WorkerTransport implements Transport {
|
|
|
44
91
|
private handleUnsupportedRequest;
|
|
45
92
|
private validateSession;
|
|
46
93
|
close(): Promise<void>;
|
|
47
|
-
send(message: JSONRPCMessage): Promise<void>;
|
|
94
|
+
send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/mcp/auth-context.d.ts
|
|
98
|
+
interface McpAuthContext {
|
|
99
|
+
props: Record<string, unknown>;
|
|
48
100
|
}
|
|
101
|
+
declare function getMcpAuthContext(): McpAuthContext | undefined;
|
|
49
102
|
//#endregion
|
|
50
103
|
//#region src/mcp/handler.d.ts
|
|
51
104
|
interface CreateMcpHandlerOptions extends WorkerTransportOptions {
|
|
@@ -56,36 +109,22 @@ interface CreateMcpHandlerOptions extends WorkerTransportOptions {
|
|
|
56
109
|
*/
|
|
57
110
|
route?: string;
|
|
58
111
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* CORS headers to all responses.
|
|
62
|
-
*
|
|
63
|
-
* Default values are:
|
|
64
|
-
* - origin: "*"
|
|
65
|
-
* - headers: "Content-Type, Accept, Authorization, mcp-session-id, MCP-Protocol-Version"
|
|
66
|
-
* - methods: "GET, POST, DELETE, OPTIONS"
|
|
67
|
-
* - exposeHeaders: "mcp-session-id"
|
|
68
|
-
* - maxAge: 86400
|
|
69
|
-
*
|
|
70
|
-
* Provided options will overwrite the defaults.
|
|
112
|
+
* An optional auth context to use for handling MCP requests.
|
|
113
|
+
* If not provided, the handler will look for props in the execution context.
|
|
71
114
|
*/
|
|
72
|
-
|
|
115
|
+
authContext?: McpAuthContext;
|
|
116
|
+
/**
|
|
117
|
+
* An optional transport to use for handling MCP requests.
|
|
118
|
+
* If not provided, a WorkerTransport will be created with the provided WorkerTransportOptions.
|
|
119
|
+
*/
|
|
120
|
+
transport?: WorkerTransport;
|
|
73
121
|
}
|
|
74
|
-
type OAuthExecutionContext = ExecutionContext & {
|
|
75
|
-
props?: Record<string, unknown>;
|
|
76
|
-
};
|
|
77
122
|
declare function createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
|
|
78
123
|
/**
|
|
79
124
|
* @deprecated This has been renamed to createMcpHandler, and experimental_createMcpHandler will be removed in the next major version
|
|
80
125
|
*/
|
|
81
126
|
declare function experimental_createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
|
|
82
127
|
//#endregion
|
|
83
|
-
//#region src/mcp/auth-context.d.ts
|
|
84
|
-
interface McpAuthContext {
|
|
85
|
-
props: Record<string, unknown>;
|
|
86
|
-
}
|
|
87
|
-
declare function getMcpAuthContext(): McpAuthContext | undefined;
|
|
88
|
-
//#endregion
|
|
89
128
|
//#region src/mcp/index.d.ts
|
|
90
129
|
declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
|
|
91
130
|
private _transport?;
|
|
@@ -150,5 +189,5 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
|
|
|
150
189
|
};
|
|
151
190
|
}
|
|
152
191
|
//#endregion
|
|
153
|
-
export { type CreateMcpHandlerOptions, type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult,
|
|
192
|
+
export { type CreateMcpHandlerOptions, type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult, type MCPConnectionResult, type MCPServerOptions, McpAgent, type McpAuthContext, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport, type TransportState, WorkerTransport, type WorkerTransportOptions, createMcpHandler, experimental_createMcpHandler, getMcpAuthContext };
|
|
154
193
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/mcp/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { t as MessageType } from "../ai-types-B3aQaFv3.js";
|
|
2
2
|
import "../client-BfiZ3HQd.js";
|
|
3
|
-
import
|
|
4
|
-
import "../do-oauth-client-provider-
|
|
5
|
-
import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-
|
|
3
|
+
import "../client-DpkZyXgJ.js";
|
|
4
|
+
import "../do-oauth-client-provider-D2P1lSft.js";
|
|
5
|
+
import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-Dk8lwxHf.js";
|
|
6
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
8
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
7
9
|
import { ElicitRequestSchema, InitializeRequestSchema, JSONRPCMessageSchema, isInitializeRequest, isJSONRPCError, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResponse } from "@modelcontextprotocol/sdk/types.js";
|
|
8
10
|
|
|
9
11
|
//#region src/mcp/utils.ts
|
|
@@ -637,6 +639,35 @@ var StreamableHTTPServerTransport = class {
|
|
|
637
639
|
}
|
|
638
640
|
};
|
|
639
641
|
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/mcp/client-transports.ts
|
|
644
|
+
let didWarnAboutSSEEdgeClientTransport = false;
|
|
645
|
+
/**
|
|
646
|
+
* @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
|
|
647
|
+
*/
|
|
648
|
+
var SSEEdgeClientTransport = class extends SSEClientTransport {
|
|
649
|
+
constructor(url, options) {
|
|
650
|
+
super(url, options);
|
|
651
|
+
if (!didWarnAboutSSEEdgeClientTransport) {
|
|
652
|
+
didWarnAboutSSEEdgeClientTransport = true;
|
|
653
|
+
console.warn("SSEEdgeClientTransport is deprecated. Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. SSEEdgeClientTransport will be removed in the next major version.");
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
let didWarnAboutStreamableHTTPEdgeClientTransport = false;
|
|
658
|
+
/**
|
|
659
|
+
* @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. This alias will be removed in the next major version.
|
|
660
|
+
*/
|
|
661
|
+
var StreamableHTTPEdgeClientTransport = class extends StreamableHTTPClientTransport {
|
|
662
|
+
constructor(url, options) {
|
|
663
|
+
super(url, options);
|
|
664
|
+
if (!didWarnAboutStreamableHTTPEdgeClientTransport) {
|
|
665
|
+
didWarnAboutStreamableHTTPEdgeClientTransport = true;
|
|
666
|
+
console.warn("StreamableHTTPEdgeClientTransport is deprecated. Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. StreamableHTTPEdgeClientTransport will be removed in the next major version.");
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
|
|
640
671
|
//#endregion
|
|
641
672
|
//#region src/mcp/worker-transport.ts
|
|
642
673
|
const SUPPORTED_PROTOCOL_VERSIONS = ["2025-03-26", "2025-06-18"];
|
|
@@ -651,10 +682,38 @@ var WorkerTransport = class {
|
|
|
651
682
|
this.streamMapping = /* @__PURE__ */ new Map();
|
|
652
683
|
this.requestToStreamMapping = /* @__PURE__ */ new Map();
|
|
653
684
|
this.requestResponseMap = /* @__PURE__ */ new Map();
|
|
685
|
+
this.stateRestored = false;
|
|
654
686
|
this.sessionIdGenerator = options?.sessionIdGenerator;
|
|
655
687
|
this.enableJsonResponse = options?.enableJsonResponse ?? false;
|
|
656
688
|
this.onsessioninitialized = options?.onsessioninitialized;
|
|
657
689
|
this.corsOptions = options?.corsOptions;
|
|
690
|
+
this.storage = options?.storage;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Restore transport state from persistent storage.
|
|
694
|
+
* This is automatically called on start.
|
|
695
|
+
*/
|
|
696
|
+
async restoreState() {
|
|
697
|
+
if (!this.storage || this.stateRestored) return;
|
|
698
|
+
const state = await Promise.resolve(this.storage.get());
|
|
699
|
+
if (state) {
|
|
700
|
+
this.sessionId = state.sessionId;
|
|
701
|
+
this.initialized = state.initialized;
|
|
702
|
+
this.protocolVersion = state.protocolVersion;
|
|
703
|
+
}
|
|
704
|
+
this.stateRestored = true;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Persist current transport state to storage.
|
|
708
|
+
*/
|
|
709
|
+
async saveState() {
|
|
710
|
+
if (!this.storage) return;
|
|
711
|
+
const state = {
|
|
712
|
+
sessionId: this.sessionId,
|
|
713
|
+
initialized: this.initialized,
|
|
714
|
+
protocolVersion: this.protocolVersion
|
|
715
|
+
};
|
|
716
|
+
await Promise.resolve(this.storage.set(state));
|
|
658
717
|
}
|
|
659
718
|
async start() {
|
|
660
719
|
if (this.started) throw new Error("Transport already started");
|
|
@@ -729,6 +788,7 @@ var WorkerTransport = class {
|
|
|
729
788
|
};
|
|
730
789
|
}
|
|
731
790
|
async handleRequest(request, parsedBody) {
|
|
791
|
+
await this.restoreState();
|
|
732
792
|
switch (request.method) {
|
|
733
793
|
case "OPTIONS": return this.handleOptionsRequest(request);
|
|
734
794
|
case "GET": return this.handleGetRequest(request);
|
|
@@ -801,7 +861,7 @@ var WorkerTransport = class {
|
|
|
801
861
|
}
|
|
802
862
|
async handlePostRequest(request, parsedBody) {
|
|
803
863
|
const acceptHeader = request.headers.get("Accept");
|
|
804
|
-
if (!acceptHeader?.includes("application/json") || !acceptHeader
|
|
864
|
+
if (!acceptHeader?.includes("application/json") || !acceptHeader?.includes("text/event-stream")) return new Response(JSON.stringify({
|
|
805
865
|
jsonrpc: "2.0",
|
|
806
866
|
error: {
|
|
807
867
|
code: -32e3,
|
|
@@ -907,6 +967,7 @@ var WorkerTransport = class {
|
|
|
907
967
|
}
|
|
908
968
|
this.sessionId = this.sessionIdGenerator?.();
|
|
909
969
|
this.initialized = true;
|
|
970
|
+
await this.saveState();
|
|
910
971
|
if (this.sessionId && this.onsessioninitialized) this.onsessioninitialized(this.sessionId);
|
|
911
972
|
}
|
|
912
973
|
if (!isInitializationRequest) {
|
|
@@ -1040,8 +1101,8 @@ var WorkerTransport = class {
|
|
|
1040
1101
|
this.requestResponseMap.clear();
|
|
1041
1102
|
this.onclose?.();
|
|
1042
1103
|
}
|
|
1043
|
-
async send(message) {
|
|
1044
|
-
let requestId;
|
|
1104
|
+
async send(message, options) {
|
|
1105
|
+
let requestId = options?.relatedRequestId;
|
|
1045
1106
|
if (isJSONRPCResponse(message) || isJSONRPCError(message)) requestId = message.id;
|
|
1046
1107
|
if (requestId === void 0) {
|
|
1047
1108
|
if (isJSONRPCResponse(message) || isJSONRPCError(message)) throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
|
|
@@ -1103,13 +1164,22 @@ function createMcpHandler(server, options = {}) {
|
|
|
1103
1164
|
return async (request, _env, ctx) => {
|
|
1104
1165
|
const url = new URL(request.url);
|
|
1105
1166
|
if (route && url.pathname !== route) return new Response("Not Found", { status: 404 });
|
|
1106
|
-
const
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1167
|
+
const transport = options.transport ?? new WorkerTransport({
|
|
1168
|
+
sessionIdGenerator: options.sessionIdGenerator,
|
|
1169
|
+
enableJsonResponse: options.enableJsonResponse,
|
|
1170
|
+
onsessioninitialized: options.onsessioninitialized,
|
|
1171
|
+
corsOptions: options.corsOptions,
|
|
1172
|
+
storage: options.storage
|
|
1173
|
+
});
|
|
1174
|
+
const buildAuthContext = () => {
|
|
1175
|
+
if (options.authContext) return options.authContext;
|
|
1176
|
+
if (ctx.props && Object.keys(ctx.props).length > 0) return { props: ctx.props };
|
|
1177
|
+
};
|
|
1110
1178
|
const handleRequest = async () => {
|
|
1111
1179
|
return await transport.handleRequest(request);
|
|
1112
1180
|
};
|
|
1181
|
+
const authContext = buildAuthContext();
|
|
1182
|
+
if (!transport.started) await server.connect(transport);
|
|
1113
1183
|
try {
|
|
1114
1184
|
if (authContext) return await runWithAuthContext(authContext, handleRequest);
|
|
1115
1185
|
else return await handleRequest();
|