agents 0.0.0-881f11e → 0.0.0-89b649a
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 +28 -2
- package/dist/ai-chat-agent.js +99 -103
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.d.ts +12 -0
- package/dist/ai-react.js +0 -2
- package/dist/ai-react.js.map +1 -1
- package/dist/chunk-BZXOAZUX.js +106 -0
- package/dist/chunk-BZXOAZUX.js.map +1 -0
- package/dist/{chunk-JR3NW4A7.js → chunk-MXJNY43J.js} +265 -101
- package/dist/chunk-MXJNY43J.js.map +1 -0
- package/dist/{chunk-7VFQNJFK.js → chunk-OYJXQRRH.js} +26 -23
- package/dist/chunk-OYJXQRRH.js.map +1 -0
- package/dist/chunk-VCSB47AK.js +116 -0
- package/dist/chunk-VCSB47AK.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 +97 -4
- package/dist/index.js +4 -3
- package/dist/mcp/client.d.ts +13 -15
- package/dist/mcp/client.js +1 -2
- 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 +10 -1
- package/dist/mcp/index.js +90 -124
- package/dist/mcp/index.js.map +1 -1
- package/dist/react.d.ts +85 -5
- package/dist/react.js +14 -2
- package/dist/react.js.map +1 -1
- package/dist/schedule.js +0 -2
- package/dist/schedule.js.map +1 -1
- package/dist/serializable.d.ts +32 -0
- package/dist/serializable.js +1 -0
- package/package.json +8 -8
- package/src/index.ts +343 -45
- package/dist/chunk-7VFQNJFK.js.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-JR3NW4A7.js.map +0 -1
- /package/dist/{chunk-HMLY7DHA.js.map → serializable.js.map} +0 -0
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MCPClientManager
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OYJXQRRH.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "./chunk-
|
|
5
|
+
DurableObjectOAuthClientProvider
|
|
6
|
+
} from "./chunk-BZXOAZUX.js";
|
|
7
|
+
import {
|
|
8
|
+
camelCaseToKebabCase
|
|
9
|
+
} from "./chunk-VCSB47AK.js";
|
|
10
10
|
|
|
11
11
|
// src/index.ts
|
|
12
12
|
import {
|
|
13
13
|
Server,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
getServerByName,
|
|
15
|
+
routePartykitRequest
|
|
16
16
|
} from "partyserver";
|
|
17
17
|
import { parseCronExpression } from "cron-schedule";
|
|
18
18
|
import { nanoid } from "nanoid";
|
|
19
|
-
import { AsyncLocalStorage } from "
|
|
19
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
20
20
|
function isRPCRequest(msg) {
|
|
21
21
|
return typeof msg === "object" && msg !== null && "type" in msg && msg.type === "rpc" && "id" in msg && typeof msg.id === "string" && "method" in msg && typeof msg.method === "string" && "args" in msg && Array.isArray(msg.args);
|
|
22
22
|
}
|
|
@@ -51,14 +51,12 @@ function getCurrentAgent() {
|
|
|
51
51
|
}
|
|
52
52
|
return store;
|
|
53
53
|
}
|
|
54
|
-
var _state, _ParentClass, _Agent_instances, setStateInternal_fn, tryCatch_fn, scheduleNextAlarm_fn, isCallable_fn;
|
|
55
54
|
var Agent = class extends Server {
|
|
56
55
|
constructor(ctx, env) {
|
|
57
56
|
super(ctx, env);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.mcp = new MCPClientManager(__privateGet(this, _ParentClass).name, "0.0.1");
|
|
57
|
+
this._state = DEFAULT_STATE;
|
|
58
|
+
this._ParentClass = Object.getPrototypeOf(this).constructor;
|
|
59
|
+
this.mcp = new MCPClientManager(this._ParentClass.name, "0.0.1");
|
|
62
60
|
/**
|
|
63
61
|
* Initial state for the Agent
|
|
64
62
|
* Override to provide default state values
|
|
@@ -105,7 +103,7 @@ var Agent = class extends Server {
|
|
|
105
103
|
`;
|
|
106
104
|
}
|
|
107
105
|
}
|
|
108
|
-
await
|
|
106
|
+
await this._scheduleNextAlarm();
|
|
109
107
|
};
|
|
110
108
|
this.sql`
|
|
111
109
|
CREATE TABLE IF NOT EXISTS cf_agents_state (
|
|
@@ -114,7 +112,7 @@ var Agent = class extends Server {
|
|
|
114
112
|
)
|
|
115
113
|
`;
|
|
116
114
|
void this.ctx.blockConcurrencyWhile(async () => {
|
|
117
|
-
return
|
|
115
|
+
return this._tryCatch(async () => {
|
|
118
116
|
this.sql`
|
|
119
117
|
CREATE TABLE IF NOT EXISTS cf_agents_schedules (
|
|
120
118
|
id TEXT PRIMARY KEY NOT NULL DEFAULT (randomblob(9)),
|
|
@@ -130,12 +128,36 @@ var Agent = class extends Server {
|
|
|
130
128
|
await this.alarm();
|
|
131
129
|
});
|
|
132
130
|
});
|
|
131
|
+
this.sql`
|
|
132
|
+
CREATE TABLE IF NOT EXISTS cf_agents_mcp_servers (
|
|
133
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
134
|
+
name TEXT NOT NULL,
|
|
135
|
+
server_url TEXT NOT NULL,
|
|
136
|
+
callback_url TEXT NOT NULL,
|
|
137
|
+
client_id TEXT,
|
|
138
|
+
auth_url TEXT,
|
|
139
|
+
server_options TEXT
|
|
140
|
+
)
|
|
141
|
+
`;
|
|
133
142
|
const _onRequest = this.onRequest.bind(this);
|
|
134
143
|
this.onRequest = (request) => {
|
|
135
144
|
return agentContext.run(
|
|
136
145
|
{ agent: this, connection: void 0, request },
|
|
137
146
|
async () => {
|
|
138
|
-
|
|
147
|
+
if (this.mcp.isCallbackRequest(request)) {
|
|
148
|
+
await this.mcp.handleCallbackRequest(request);
|
|
149
|
+
this.broadcast(
|
|
150
|
+
JSON.stringify({
|
|
151
|
+
type: "cf_agent_mcp_servers",
|
|
152
|
+
mcp: this.getMcpServers()
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
return new Response("<script>window.close();</script>", {
|
|
156
|
+
status: 200,
|
|
157
|
+
headers: { "content-type": "text/html" }
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return this._tryCatch(() => _onRequest(request));
|
|
139
161
|
}
|
|
140
162
|
);
|
|
141
163
|
};
|
|
@@ -145,16 +167,16 @@ var Agent = class extends Server {
|
|
|
145
167
|
{ agent: this, connection, request: void 0 },
|
|
146
168
|
async () => {
|
|
147
169
|
if (typeof message !== "string") {
|
|
148
|
-
return
|
|
170
|
+
return this._tryCatch(() => _onMessage(connection, message));
|
|
149
171
|
}
|
|
150
172
|
let parsed;
|
|
151
173
|
try {
|
|
152
174
|
parsed = JSON.parse(message);
|
|
153
175
|
} catch (e) {
|
|
154
|
-
return
|
|
176
|
+
return this._tryCatch(() => _onMessage(connection, message));
|
|
155
177
|
}
|
|
156
178
|
if (isStateUpdateMessage(parsed)) {
|
|
157
|
-
|
|
179
|
+
this._setStateInternal(parsed.state, connection);
|
|
158
180
|
return;
|
|
159
181
|
}
|
|
160
182
|
if (isRPCRequest(parsed)) {
|
|
@@ -164,7 +186,7 @@ var Agent = class extends Server {
|
|
|
164
186
|
if (typeof methodFn !== "function") {
|
|
165
187
|
throw new Error(`Method ${method} does not exist`);
|
|
166
188
|
}
|
|
167
|
-
if (!
|
|
189
|
+
if (!this._isCallable(method)) {
|
|
168
190
|
throw new Error(`Method ${method} is not callable`);
|
|
169
191
|
}
|
|
170
192
|
const metadata = callableMetadata.get(methodFn);
|
|
@@ -194,7 +216,7 @@ var Agent = class extends Server {
|
|
|
194
216
|
}
|
|
195
217
|
return;
|
|
196
218
|
}
|
|
197
|
-
return
|
|
219
|
+
return this._tryCatch(() => _onMessage(connection, message));
|
|
198
220
|
}
|
|
199
221
|
);
|
|
200
222
|
};
|
|
@@ -212,18 +234,56 @@ var Agent = class extends Server {
|
|
|
212
234
|
})
|
|
213
235
|
);
|
|
214
236
|
}
|
|
215
|
-
|
|
237
|
+
connection.send(
|
|
238
|
+
JSON.stringify({
|
|
239
|
+
type: "cf_agent_mcp_servers",
|
|
240
|
+
mcp: this.getMcpServers()
|
|
241
|
+
})
|
|
242
|
+
);
|
|
243
|
+
return this._tryCatch(() => _onConnect(connection, ctx2));
|
|
216
244
|
}, 20);
|
|
217
245
|
}
|
|
218
246
|
);
|
|
219
247
|
};
|
|
248
|
+
const _onStart = this.onStart.bind(this);
|
|
249
|
+
this.onStart = async () => {
|
|
250
|
+
return agentContext.run(
|
|
251
|
+
{ agent: this, connection: void 0, request: void 0 },
|
|
252
|
+
async () => {
|
|
253
|
+
const servers = this.sql`
|
|
254
|
+
SELECT id, name, server_url, client_id, auth_url, callback_url, server_options FROM cf_agents_mcp_servers;
|
|
255
|
+
`;
|
|
256
|
+
await Promise.allSettled(
|
|
257
|
+
servers.filter((server) => server.auth_url === null).map((server) => {
|
|
258
|
+
return this._connectToMcpServerInternal(
|
|
259
|
+
server.name,
|
|
260
|
+
server.server_url,
|
|
261
|
+
server.callback_url,
|
|
262
|
+
server.server_options ? JSON.parse(server.server_options) : void 0,
|
|
263
|
+
{
|
|
264
|
+
id: server.id,
|
|
265
|
+
oauthClientId: server.client_id ?? void 0
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
})
|
|
269
|
+
);
|
|
270
|
+
this.broadcast(
|
|
271
|
+
JSON.stringify({
|
|
272
|
+
type: "cf_agent_mcp_servers",
|
|
273
|
+
mcp: this.getMcpServers()
|
|
274
|
+
})
|
|
275
|
+
);
|
|
276
|
+
await this._tryCatch(() => _onStart());
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
};
|
|
220
280
|
}
|
|
221
281
|
/**
|
|
222
282
|
* Current state of the Agent
|
|
223
283
|
*/
|
|
224
284
|
get state() {
|
|
225
|
-
if (
|
|
226
|
-
return
|
|
285
|
+
if (this._state !== DEFAULT_STATE) {
|
|
286
|
+
return this._state;
|
|
227
287
|
}
|
|
228
288
|
const wasChanged = this.sql`
|
|
229
289
|
SELECT state FROM cf_agents_state WHERE id = ${STATE_WAS_CHANGED}
|
|
@@ -234,8 +294,8 @@ var Agent = class extends Server {
|
|
|
234
294
|
if (wasChanged[0]?.state === "true" || // we do this check for people who updated their code before we shipped wasChanged
|
|
235
295
|
result[0]?.state) {
|
|
236
296
|
const state = result[0]?.state;
|
|
237
|
-
|
|
238
|
-
return
|
|
297
|
+
this._state = JSON.parse(state);
|
|
298
|
+
return this._state;
|
|
239
299
|
}
|
|
240
300
|
if (this.initialState === DEFAULT_STATE) {
|
|
241
301
|
return void 0;
|
|
@@ -263,12 +323,39 @@ var Agent = class extends Server {
|
|
|
263
323
|
throw this.onError(e);
|
|
264
324
|
}
|
|
265
325
|
}
|
|
326
|
+
_setStateInternal(state, source = "server") {
|
|
327
|
+
this._state = state;
|
|
328
|
+
this.sql`
|
|
329
|
+
INSERT OR REPLACE INTO cf_agents_state (id, state)
|
|
330
|
+
VALUES (${STATE_ROW_ID}, ${JSON.stringify(state)})
|
|
331
|
+
`;
|
|
332
|
+
this.sql`
|
|
333
|
+
INSERT OR REPLACE INTO cf_agents_state (id, state)
|
|
334
|
+
VALUES (${STATE_WAS_CHANGED}, ${JSON.stringify(true)})
|
|
335
|
+
`;
|
|
336
|
+
this.broadcast(
|
|
337
|
+
JSON.stringify({
|
|
338
|
+
type: "cf_agent_state",
|
|
339
|
+
state
|
|
340
|
+
}),
|
|
341
|
+
source !== "server" ? [source.id] : []
|
|
342
|
+
);
|
|
343
|
+
return this._tryCatch(() => {
|
|
344
|
+
const { connection, request } = agentContext.getStore() || {};
|
|
345
|
+
return agentContext.run(
|
|
346
|
+
{ agent: this, connection, request },
|
|
347
|
+
async () => {
|
|
348
|
+
return this.onStateUpdate(state, source);
|
|
349
|
+
}
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
}
|
|
266
353
|
/**
|
|
267
354
|
* Update the Agent's state
|
|
268
355
|
* @param state New state to set
|
|
269
356
|
*/
|
|
270
357
|
setState(state) {
|
|
271
|
-
|
|
358
|
+
this._setStateInternal(state, "server");
|
|
272
359
|
}
|
|
273
360
|
/**
|
|
274
361
|
* Called when the Agent's state is updated
|
|
@@ -289,6 +376,13 @@ var Agent = class extends Server {
|
|
|
289
376
|
}
|
|
290
377
|
);
|
|
291
378
|
}
|
|
379
|
+
async _tryCatch(fn) {
|
|
380
|
+
try {
|
|
381
|
+
return await fn();
|
|
382
|
+
} catch (e) {
|
|
383
|
+
throw this.onError(e);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
292
386
|
onError(connectionOrError, error) {
|
|
293
387
|
let theError;
|
|
294
388
|
if (connectionOrError && error) {
|
|
@@ -338,7 +432,7 @@ var Agent = class extends Server {
|
|
|
338
432
|
payload
|
|
339
433
|
)}, 'scheduled', ${timestamp})
|
|
340
434
|
`;
|
|
341
|
-
await
|
|
435
|
+
await this._scheduleNextAlarm();
|
|
342
436
|
return {
|
|
343
437
|
id,
|
|
344
438
|
callback,
|
|
@@ -356,7 +450,7 @@ var Agent = class extends Server {
|
|
|
356
450
|
payload
|
|
357
451
|
)}, 'delayed', ${when}, ${timestamp})
|
|
358
452
|
`;
|
|
359
|
-
await
|
|
453
|
+
await this._scheduleNextAlarm();
|
|
360
454
|
return {
|
|
361
455
|
id,
|
|
362
456
|
callback,
|
|
@@ -375,7 +469,7 @@ var Agent = class extends Server {
|
|
|
375
469
|
payload
|
|
376
470
|
)}, 'cron', ${when}, ${timestamp})
|
|
377
471
|
`;
|
|
378
|
-
await
|
|
472
|
+
await this._scheduleNextAlarm();
|
|
379
473
|
return {
|
|
380
474
|
id,
|
|
381
475
|
callback,
|
|
@@ -442,76 +536,152 @@ var Agent = class extends Server {
|
|
|
442
536
|
*/
|
|
443
537
|
async cancelSchedule(id) {
|
|
444
538
|
this.sql`DELETE FROM cf_agents_schedules WHERE id = ${id}`;
|
|
445
|
-
await
|
|
539
|
+
await this._scheduleNextAlarm();
|
|
446
540
|
return true;
|
|
447
541
|
}
|
|
542
|
+
async _scheduleNextAlarm() {
|
|
543
|
+
const result = this.sql`
|
|
544
|
+
SELECT time FROM cf_agents_schedules
|
|
545
|
+
WHERE time > ${Math.floor(Date.now() / 1e3)}
|
|
546
|
+
ORDER BY time ASC
|
|
547
|
+
LIMIT 1
|
|
548
|
+
`;
|
|
549
|
+
if (!result) return;
|
|
550
|
+
if (result.length > 0 && "time" in result[0]) {
|
|
551
|
+
const nextTime = result[0].time * 1e3;
|
|
552
|
+
await this.ctx.storage.setAlarm(nextTime);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
448
555
|
/**
|
|
449
556
|
* Destroy the Agent, removing all state and scheduled tasks
|
|
450
557
|
*/
|
|
451
558
|
async destroy() {
|
|
452
559
|
this.sql`DROP TABLE IF EXISTS cf_agents_state`;
|
|
453
560
|
this.sql`DROP TABLE IF EXISTS cf_agents_schedules`;
|
|
561
|
+
this.sql`DROP TABLE IF EXISTS cf_agents_mcp_servers`;
|
|
454
562
|
await this.ctx.storage.deleteAlarm();
|
|
455
563
|
await this.ctx.storage.deleteAll();
|
|
456
564
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
565
|
+
/**
|
|
566
|
+
* Get all methods marked as callable on this Agent
|
|
567
|
+
* @returns A map of method names to their metadata
|
|
568
|
+
*/
|
|
569
|
+
_isCallable(method) {
|
|
570
|
+
return callableMetadata.has(this[method]);
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Connect to a new MCP Server
|
|
574
|
+
*
|
|
575
|
+
* @param url MCP Server SSE URL
|
|
576
|
+
* @param callbackHost Base host for the agent, used for the redirect URI.
|
|
577
|
+
* @param agentsPrefix agents routing prefix if not using `agents`
|
|
578
|
+
* @param options MCP client and transport (header) options
|
|
579
|
+
* @returns authUrl
|
|
580
|
+
*/
|
|
581
|
+
async addMcpServer(serverName, url, callbackHost, agentsPrefix = "agents", options) {
|
|
582
|
+
const callbackUrl = `${callbackHost}/${agentsPrefix}/${camelCaseToKebabCase(this._ParentClass.name)}/${this.name}/callback`;
|
|
583
|
+
const result = await this._connectToMcpServerInternal(
|
|
584
|
+
serverName,
|
|
585
|
+
url,
|
|
586
|
+
callbackUrl,
|
|
587
|
+
options
|
|
588
|
+
);
|
|
589
|
+
this.broadcast(
|
|
590
|
+
JSON.stringify({
|
|
591
|
+
type: "cf_agent_mcp_servers",
|
|
592
|
+
mcp: this.getMcpServers()
|
|
593
|
+
})
|
|
594
|
+
);
|
|
595
|
+
return result;
|
|
596
|
+
}
|
|
597
|
+
async _connectToMcpServerInternal(serverName, url, callbackUrl, options, reconnect) {
|
|
598
|
+
const authProvider = new DurableObjectOAuthClientProvider(
|
|
599
|
+
this.ctx.storage,
|
|
600
|
+
this.name,
|
|
601
|
+
callbackUrl
|
|
602
|
+
);
|
|
603
|
+
if (reconnect) {
|
|
604
|
+
authProvider.serverId = reconnect.id;
|
|
605
|
+
if (reconnect.oauthClientId) {
|
|
606
|
+
authProvider.clientId = reconnect.oauthClientId;
|
|
484
607
|
}
|
|
608
|
+
}
|
|
609
|
+
let headerTransportOpts = {};
|
|
610
|
+
if (options?.transport?.headers) {
|
|
611
|
+
headerTransportOpts = {
|
|
612
|
+
eventSourceInit: {
|
|
613
|
+
fetch: (url2, init) => fetch(url2, {
|
|
614
|
+
...init,
|
|
615
|
+
headers: options?.transport?.headers
|
|
616
|
+
})
|
|
617
|
+
},
|
|
618
|
+
requestInit: {
|
|
619
|
+
headers: options?.transport?.headers
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
const { id, authUrl, clientId } = await this.mcp.connect(url, {
|
|
624
|
+
reconnect,
|
|
625
|
+
transport: {
|
|
626
|
+
...headerTransportOpts,
|
|
627
|
+
authProvider
|
|
628
|
+
},
|
|
629
|
+
client: options?.client
|
|
630
|
+
});
|
|
631
|
+
this.sql`
|
|
632
|
+
INSERT OR REPLACE INTO cf_agents_mcp_servers (id, name, server_url, client_id, auth_url, callback_url, server_options)
|
|
633
|
+
VALUES (
|
|
634
|
+
${id},
|
|
635
|
+
${serverName},
|
|
636
|
+
${url},
|
|
637
|
+
${clientId ?? null},
|
|
638
|
+
${authUrl ?? null},
|
|
639
|
+
${callbackUrl},
|
|
640
|
+
${options ? JSON.stringify(options) : null}
|
|
641
|
+
);
|
|
642
|
+
`;
|
|
643
|
+
return {
|
|
644
|
+
id,
|
|
645
|
+
authUrl
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
async removeMcpServer(id) {
|
|
649
|
+
this.mcp.closeConnection(id);
|
|
650
|
+
this.sql`
|
|
651
|
+
DELETE FROM cf_agents_mcp_servers WHERE id = ${id};
|
|
652
|
+
`;
|
|
653
|
+
this.broadcast(
|
|
654
|
+
JSON.stringify({
|
|
655
|
+
type: "cf_agent_mcp_servers",
|
|
656
|
+
mcp: this.getMcpServers()
|
|
657
|
+
})
|
|
485
658
|
);
|
|
486
|
-
});
|
|
487
|
-
};
|
|
488
|
-
tryCatch_fn = async function(fn) {
|
|
489
|
-
try {
|
|
490
|
-
return await fn();
|
|
491
|
-
} catch (e) {
|
|
492
|
-
throw this.onError(e);
|
|
493
659
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
660
|
+
getMcpServers() {
|
|
661
|
+
const mcpState = {
|
|
662
|
+
servers: {},
|
|
663
|
+
tools: this.mcp.listTools(),
|
|
664
|
+
prompts: this.mcp.listPrompts(),
|
|
665
|
+
resources: this.mcp.listResources()
|
|
666
|
+
};
|
|
667
|
+
const servers = this.sql`
|
|
668
|
+
SELECT id, name, server_url, client_id, auth_url, callback_url, server_options FROM cf_agents_mcp_servers;
|
|
501
669
|
`;
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
670
|
+
for (const server of servers) {
|
|
671
|
+
const serverConn = this.mcp.mcpConnections[server.id];
|
|
672
|
+
mcpState.servers[server.id] = {
|
|
673
|
+
name: server.name,
|
|
674
|
+
server_url: server.server_url,
|
|
675
|
+
auth_url: server.auth_url,
|
|
676
|
+
// mark as "authenticating" because the server isn't automatically connected, so it's pending authenticating
|
|
677
|
+
state: serverConn?.connectionState ?? "authenticating",
|
|
678
|
+
instructions: serverConn?.instructions ?? null,
|
|
679
|
+
capabilities: serverConn?.serverCapabilities ?? null
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
return mcpState;
|
|
506
683
|
}
|
|
507
684
|
};
|
|
508
|
-
/**
|
|
509
|
-
* Get all methods marked as callable on this Agent
|
|
510
|
-
* @returns A map of method names to their metadata
|
|
511
|
-
*/
|
|
512
|
-
isCallable_fn = function(method) {
|
|
513
|
-
return callableMetadata.has(this[method]);
|
|
514
|
-
};
|
|
515
685
|
/**
|
|
516
686
|
* Agent configuration options
|
|
517
687
|
*/
|
|
@@ -560,54 +730,48 @@ async function routeAgentEmail(email, env, options) {
|
|
|
560
730
|
async function getAgentByName(namespace, name, options) {
|
|
561
731
|
return getServerByName(namespace, name, options);
|
|
562
732
|
}
|
|
563
|
-
var _connection, _id, _closed;
|
|
564
733
|
var StreamingResponse = class {
|
|
565
734
|
constructor(connection, id) {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
__privateSet(this, _connection, connection);
|
|
570
|
-
__privateSet(this, _id, id);
|
|
735
|
+
this._closed = false;
|
|
736
|
+
this._connection = connection;
|
|
737
|
+
this._id = id;
|
|
571
738
|
}
|
|
572
739
|
/**
|
|
573
740
|
* Send a chunk of data to the client
|
|
574
741
|
* @param chunk The data to send
|
|
575
742
|
*/
|
|
576
743
|
send(chunk) {
|
|
577
|
-
if (
|
|
744
|
+
if (this._closed) {
|
|
578
745
|
throw new Error("StreamingResponse is already closed");
|
|
579
746
|
}
|
|
580
747
|
const response = {
|
|
581
748
|
type: "rpc",
|
|
582
|
-
id:
|
|
749
|
+
id: this._id,
|
|
583
750
|
success: true,
|
|
584
751
|
result: chunk,
|
|
585
752
|
done: false
|
|
586
753
|
};
|
|
587
|
-
|
|
754
|
+
this._connection.send(JSON.stringify(response));
|
|
588
755
|
}
|
|
589
756
|
/**
|
|
590
757
|
* End the stream and send the final chunk (if any)
|
|
591
758
|
* @param finalChunk Optional final chunk of data to send
|
|
592
759
|
*/
|
|
593
760
|
end(finalChunk) {
|
|
594
|
-
if (
|
|
761
|
+
if (this._closed) {
|
|
595
762
|
throw new Error("StreamingResponse is already closed");
|
|
596
763
|
}
|
|
597
|
-
|
|
764
|
+
this._closed = true;
|
|
598
765
|
const response = {
|
|
599
766
|
type: "rpc",
|
|
600
|
-
id:
|
|
767
|
+
id: this._id,
|
|
601
768
|
success: true,
|
|
602
769
|
result: finalChunk,
|
|
603
770
|
done: true
|
|
604
771
|
};
|
|
605
|
-
|
|
772
|
+
this._connection.send(JSON.stringify(response));
|
|
606
773
|
}
|
|
607
774
|
};
|
|
608
|
-
_connection = new WeakMap();
|
|
609
|
-
_id = new WeakMap();
|
|
610
|
-
_closed = new WeakMap();
|
|
611
775
|
|
|
612
776
|
export {
|
|
613
777
|
unstable_callable,
|
|
@@ -618,4 +782,4 @@ export {
|
|
|
618
782
|
getAgentByName,
|
|
619
783
|
StreamingResponse
|
|
620
784
|
};
|
|
621
|
-
//# sourceMappingURL=chunk-
|
|
785
|
+
//# sourceMappingURL=chunk-MXJNY43J.js.map
|