agents 0.7.5 → 0.7.6
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/{client-CgXIwdcc.js → client-K8Z-u76l.js} +38 -12
- package/dist/client-K8Z-u76l.js.map +1 -0
- package/dist/client.js.map +1 -1
- package/dist/experimental/forever.d.ts +1 -1
- package/dist/experimental/forever.js +1 -1
- package/dist/experimental/forever.js.map +1 -1
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/experimental/workspace.js +3 -1
- package/dist/experimental/workspace.js.map +1 -1
- package/dist/{index-p1XLNvwQ.d.ts → index-WBy5hmm3.d.ts} +183 -62
- package/dist/index.d.ts +13 -9
- package/dist/index.js +280 -135
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +59 -49
- package/dist/mcp/index.js.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/dist/workflows.js +1 -1
- package/dist/workflows.js.map +1 -1
- package/package.json +12 -10
- package/dist/client-CgXIwdcc.js.map +0 -1
- package/dist/experimental/sub-agent.d.ts +0 -205
- package/dist/experimental/sub-agent.js +0 -190
- package/dist/experimental/sub-agent.js.map +0 -1
package/dist/mcp/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as RegisterServerOptions, F as MCPClientOAuthResult, I as MCPConnectionResult, L as MCPDiscoverResult, M as MCPClientManager, N as MCPClientManagerOptions, P as MCPClientOAuthCallbackConfig, R as MCPOAuthCallbackResult, V as getNamespacedData, z as MCPServerOptions } from "../index-WBy5hmm3.js";
|
|
2
2
|
export { MCPClientManager, MCPClientManagerOptions, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MCPConnectionResult, MCPDiscoverResult, MCPOAuthCallbackResult, MCPServerOptions, RegisterServerOptions, getNamespacedData };
|
package/dist/mcp/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as getNamespacedData, t as MCPClientManager } from "../client-
|
|
1
|
+
import { n as getNamespacedData, t as MCPClientManager } from "../client-K8Z-u76l.js";
|
|
2
2
|
export { MCPClientManager, getNamespacedData };
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as experimental_createMcpHandler, F as MCPClientOAuthResult, G as RPCServerTransportOptions, H as RPCClientTransport, I as MCPConnectionResult, J as ElicitRequestSchema, K as RPC_DO_PREFIX, L as MCPDiscoverResult, P as MCPClientOAuthCallbackConfig, Q as createMcpHandler, U as RPCClientTransportOptions, W as RPCServerTransport, X as McpAgent, Y as ElicitResult, Z as CreateMcpHandlerOptions, at as SSEEdgeClientTransport, et as McpAuthContext, it as WorkerTransportOptions, nt as TransportState, ot as StreamableHTTPEdgeClientTransport, q as ElicitRequest, rt as WorkerTransport, st as McpClientOptions, tt as getMcpAuthContext, z as MCPServerOptions } from "../index-WBy5hmm3.js";
|
|
2
2
|
export { CreateMcpHandlerOptions, ElicitRequest, ElicitRequestSchema, ElicitResult, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MCPConnectionResult, MCPDiscoverResult, MCPServerOptions, McpAgent, McpAuthContext, McpClientOptions, RPCClientTransport, RPCClientTransportOptions, RPCServerTransport, RPCServerTransportOptions, RPC_DO_PREFIX, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport, TransportState, WorkerTransport, WorkerTransportOptions, createMcpHandler, experimental_createMcpHandler, getMcpAuthContext };
|
package/dist/mcp/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MessageType } from "../types.js";
|
|
2
|
-
import { a as RPCServerTransport, i as RPCClientTransport, o as RPC_DO_PREFIX } from "../client-
|
|
2
|
+
import { a as RPCServerTransport, i as RPCClientTransport, o as RPC_DO_PREFIX } from "../client-K8Z-u76l.js";
|
|
3
3
|
import { Agent, getAgentByName, getCurrentAgent } from "../index.js";
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
5
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
@@ -1275,6 +1275,10 @@ function experimental_createMcpHandler(server, options = {}) {
|
|
|
1275
1275
|
//#endregion
|
|
1276
1276
|
//#region src/mcp/index.ts
|
|
1277
1277
|
var McpAgent = class McpAgent extends Agent {
|
|
1278
|
+
constructor(..._args) {
|
|
1279
|
+
super(..._args);
|
|
1280
|
+
this._pendingElicitations = /* @__PURE__ */ new Map();
|
|
1281
|
+
}
|
|
1278
1282
|
shouldSendProtocolMessages(_connection, ctx) {
|
|
1279
1283
|
return !ctx.request.headers.get(MCP_HTTP_METHOD_HEADER);
|
|
1280
1284
|
}
|
|
@@ -1334,8 +1338,8 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1334
1338
|
case "sse": return new McpSSETransport();
|
|
1335
1339
|
case "streamable-http": {
|
|
1336
1340
|
const transport = new StreamableHTTPServerTransport({});
|
|
1337
|
-
transport.messageInterceptor =
|
|
1338
|
-
return this._handleElicitationResponse(message);
|
|
1341
|
+
transport.messageInterceptor = (message) => {
|
|
1342
|
+
return Promise.resolve(this._handleElicitationResponse(message));
|
|
1339
1343
|
};
|
|
1340
1344
|
return transport;
|
|
1341
1345
|
}
|
|
@@ -1354,7 +1358,7 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1354
1358
|
/** Sets up the MCP transport and server every time the Agent is started.*/
|
|
1355
1359
|
async onStart(props) {
|
|
1356
1360
|
if (props) await this.updateProps(props);
|
|
1357
|
-
this.props = await this.ctx.storage.get("props");
|
|
1361
|
+
else this.props = await this.ctx.storage.get("props");
|
|
1358
1362
|
await this.init();
|
|
1359
1363
|
const server = await this.server;
|
|
1360
1364
|
this._transport = this.initTransport();
|
|
@@ -1402,7 +1406,7 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1402
1406
|
this._transport?.onerror?.(error);
|
|
1403
1407
|
throw error;
|
|
1404
1408
|
}
|
|
1405
|
-
if (
|
|
1409
|
+
if (this._handleElicitationResponse(parsedMessage)) return null;
|
|
1406
1410
|
this._transport?.onmessage?.(parsedMessage, extraInfo);
|
|
1407
1411
|
return null;
|
|
1408
1412
|
} catch (error) {
|
|
@@ -1414,11 +1418,6 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1414
1418
|
/** Elicit user input with a message and schema */
|
|
1415
1419
|
async elicitInput(params) {
|
|
1416
1420
|
const requestId = `elicit_${Math.random().toString(36).substring(2, 11)}`;
|
|
1417
|
-
await this.ctx.storage.put(`elicitation:${requestId}`, {
|
|
1418
|
-
message: params.message,
|
|
1419
|
-
requestedSchema: params.requestedSchema,
|
|
1420
|
-
timestamp: Date.now()
|
|
1421
|
-
});
|
|
1422
1421
|
const elicitRequest = {
|
|
1423
1422
|
jsonrpc: "2.0",
|
|
1424
1423
|
id: requestId,
|
|
@@ -1428,60 +1427,71 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1428
1427
|
requestedSchema: params.requestedSchema
|
|
1429
1428
|
}
|
|
1430
1429
|
};
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1430
|
+
let timeoutId;
|
|
1431
|
+
const responsePromise = new Promise((resolve, reject) => {
|
|
1432
|
+
timeoutId = setTimeout(() => {
|
|
1433
|
+
this._pendingElicitations.delete(requestId);
|
|
1434
|
+
reject(/* @__PURE__ */ new Error("Elicitation request timed out"));
|
|
1435
|
+
}, 6e4);
|
|
1436
|
+
this._pendingElicitations.set(requestId, {
|
|
1437
|
+
resolve: (result) => {
|
|
1438
|
+
clearTimeout(timeoutId);
|
|
1439
|
+
this._pendingElicitations.delete(requestId);
|
|
1440
|
+
resolve(result);
|
|
1441
|
+
},
|
|
1442
|
+
reject: (err) => {
|
|
1443
|
+
clearTimeout(timeoutId);
|
|
1444
|
+
this._pendingElicitations.delete(requestId);
|
|
1445
|
+
reject(err);
|
|
1446
|
+
}
|
|
1447
|
+
});
|
|
1448
|
+
});
|
|
1449
|
+
const cleanup = () => {
|
|
1450
|
+
clearTimeout(timeoutId);
|
|
1451
|
+
this._pendingElicitations.delete(requestId);
|
|
1452
|
+
};
|
|
1453
|
+
return this.keepAliveWhile(async () => {
|
|
1454
|
+
if (this._transport) try {
|
|
1455
|
+
await this._transport.send(elicitRequest);
|
|
1441
1456
|
} catch (error) {
|
|
1442
|
-
|
|
1457
|
+
cleanup();
|
|
1458
|
+
throw error;
|
|
1443
1459
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
await this.ctx.storage.delete(`elicitation:${requestId}`);
|
|
1456
|
-
await this.ctx.storage.delete(`elicitation:response:${requestId}`);
|
|
1457
|
-
return response;
|
|
1460
|
+
else {
|
|
1461
|
+
const connections = this.getConnections();
|
|
1462
|
+
if (!connections || Array.from(connections).length === 0) {
|
|
1463
|
+
cleanup();
|
|
1464
|
+
throw new Error("No active connections available for elicitation");
|
|
1465
|
+
}
|
|
1466
|
+
const connectionList = Array.from(connections);
|
|
1467
|
+
for (const connection of connectionList) try {
|
|
1468
|
+
connection.send(JSON.stringify(elicitRequest));
|
|
1469
|
+
} catch (error) {
|
|
1470
|
+
console.error("Failed to send elicitation request:", error);
|
|
1458
1471
|
}
|
|
1459
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1460
1472
|
}
|
|
1461
|
-
|
|
1462
|
-
}
|
|
1463
|
-
await this.ctx.storage.delete(`elicitation:${requestId}`);
|
|
1464
|
-
await this.ctx.storage.delete(`elicitation:response:${requestId}`);
|
|
1465
|
-
}
|
|
1473
|
+
return responsePromise;
|
|
1474
|
+
});
|
|
1466
1475
|
}
|
|
1467
|
-
/** Handle elicitation responses */
|
|
1468
|
-
|
|
1476
|
+
/** Handle elicitation responses via in-memory resolver */
|
|
1477
|
+
_handleElicitationResponse(message) {
|
|
1469
1478
|
if (isJSONRPCResultResponse(message) && message.result) {
|
|
1470
1479
|
const requestId = message.id?.toString();
|
|
1471
1480
|
if (!requestId || !requestId.startsWith("elicit_")) return false;
|
|
1472
|
-
|
|
1473
|
-
|
|
1481
|
+
const pending = this._pendingElicitations.get(requestId);
|
|
1482
|
+
if (!pending) return false;
|
|
1483
|
+
pending.resolve(message.result);
|
|
1474
1484
|
return true;
|
|
1475
1485
|
}
|
|
1476
1486
|
if (isJSONRPCErrorResponse(message)) {
|
|
1477
1487
|
const requestId = message.id?.toString();
|
|
1478
1488
|
if (!requestId || !requestId.startsWith("elicit_")) return false;
|
|
1479
|
-
|
|
1480
|
-
|
|
1489
|
+
const pending = this._pendingElicitations.get(requestId);
|
|
1490
|
+
if (!pending) return false;
|
|
1491
|
+
pending.resolve({
|
|
1481
1492
|
action: "cancel",
|
|
1482
1493
|
content: { error: message.error.message || "Elicitation request failed" }
|
|
1483
|
-
};
|
|
1484
|
-
await this.ctx.storage.put(`elicitation:response:${requestId}`, errorResult);
|
|
1494
|
+
});
|
|
1485
1495
|
return true;
|
|
1486
1496
|
}
|
|
1487
1497
|
return false;
|