@cuylabs/agent-server 0.11.0 → 0.13.0
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/index.js +125 -57
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -118,7 +118,11 @@ function matchesNotificationSubscription(notification, options) {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// src/protocol/adapter.ts
|
|
121
|
-
import {
|
|
121
|
+
import {
|
|
122
|
+
extractModelId,
|
|
123
|
+
extractProvider,
|
|
124
|
+
ensureSessionLoaded
|
|
125
|
+
} from "@cuylabs/agent-core";
|
|
122
126
|
function createAgentServerAdapter(agent, options = {}) {
|
|
123
127
|
const interactiveAgent = agent;
|
|
124
128
|
const pluginCommands = options.pluginCommands ?? [];
|
|
@@ -187,7 +191,11 @@ function createAgentServerAdapter(agent, options = {}) {
|
|
|
187
191
|
cwd: agent.cwd,
|
|
188
192
|
getCapabilities: () => mergeAgentServerCapabilities(
|
|
189
193
|
mergeAgentServerCapabilities(createDefaultAgentServerCapabilities(), {
|
|
190
|
-
protocol: {
|
|
194
|
+
protocol: {
|
|
195
|
+
transport: "in-process",
|
|
196
|
+
reconnectable: false,
|
|
197
|
+
multiClient: true
|
|
198
|
+
},
|
|
191
199
|
turns: { steer: true, followUp: true, followUpManagement: true },
|
|
192
200
|
interactive: { approvalRequests: true, humanRequests: hasHumanInput },
|
|
193
201
|
runtime: {
|
|
@@ -298,7 +306,9 @@ function createAgentServerAdapter(agent, options = {}) {
|
|
|
298
306
|
getSessionStorage: () => agent.getSessionManager().getStorage(),
|
|
299
307
|
listPluginCommands: () => pluginCommandInfos,
|
|
300
308
|
executePluginCommand: async (name, args) => {
|
|
301
|
-
const command = pluginCommandTokens.get(
|
|
309
|
+
const command = pluginCommandTokens.get(
|
|
310
|
+
normalizePluginCommandToken(name)
|
|
311
|
+
);
|
|
302
312
|
if (!command) {
|
|
303
313
|
throw new Error(`Plugin command not found: ${name}`);
|
|
304
314
|
}
|
|
@@ -436,15 +446,13 @@ var InProcessAgentServer = class {
|
|
|
436
446
|
}
|
|
437
447
|
this.capabilities = capabilities;
|
|
438
448
|
if (this.adapter.subscribeTeamNotifications) {
|
|
439
|
-
this.teamNotificationUnsubscribe = this.adapter.subscribeTeamNotifications(
|
|
440
|
-
(
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
);
|
|
449
|
+
this.teamNotificationUnsubscribe = this.adapter.subscribeTeamNotifications((notification) => {
|
|
450
|
+
this.emit({
|
|
451
|
+
type: "team/notification",
|
|
452
|
+
teamId: notification.teamId,
|
|
453
|
+
notification
|
|
454
|
+
});
|
|
455
|
+
});
|
|
448
456
|
}
|
|
449
457
|
}
|
|
450
458
|
getCapabilities() {
|
|
@@ -480,7 +488,9 @@ var InProcessAgentServer = class {
|
|
|
480
488
|
}
|
|
481
489
|
async getModelState() {
|
|
482
490
|
if (!this.adapter.getModelState) {
|
|
483
|
-
throw new Error(
|
|
491
|
+
throw new Error(
|
|
492
|
+
"Model inspection is not available on this agent-server."
|
|
493
|
+
);
|
|
484
494
|
}
|
|
485
495
|
return await this.adapter.getModelState();
|
|
486
496
|
}
|
|
@@ -512,13 +522,17 @@ var InProcessAgentServer = class {
|
|
|
512
522
|
}
|
|
513
523
|
async executePluginCommand(name, args) {
|
|
514
524
|
if (!this.adapter.executePluginCommand) {
|
|
515
|
-
throw new Error(
|
|
525
|
+
throw new Error(
|
|
526
|
+
"Plugin command execution is not available on this agent-server."
|
|
527
|
+
);
|
|
516
528
|
}
|
|
517
529
|
return await this.adapter.executePluginCommand(name, args);
|
|
518
530
|
}
|
|
519
531
|
async compactSessionContext(sessionId) {
|
|
520
532
|
if (!this.adapter.compactSessionContext) {
|
|
521
|
-
throw new Error(
|
|
533
|
+
throw new Error(
|
|
534
|
+
"Context compaction is not available on this agent-server."
|
|
535
|
+
);
|
|
522
536
|
}
|
|
523
537
|
return await this.adapter.compactSessionContext(sessionId);
|
|
524
538
|
}
|
|
@@ -546,7 +560,10 @@ var InProcessAgentServer = class {
|
|
|
546
560
|
...options.title ? { title: options.title } : {}
|
|
547
561
|
});
|
|
548
562
|
const detail = await this.readSessionOrThrow(id);
|
|
549
|
-
this.emit({
|
|
563
|
+
this.emit({
|
|
564
|
+
type: "session/created",
|
|
565
|
+
session: toSessionSummaryFromDetail(detail)
|
|
566
|
+
});
|
|
550
567
|
return detail;
|
|
551
568
|
}
|
|
552
569
|
async readSession(sessionId) {
|
|
@@ -576,7 +593,9 @@ var InProcessAgentServer = class {
|
|
|
576
593
|
async deleteSession(sessionId) {
|
|
577
594
|
const runtime = this.sessionRuntime.get(sessionId);
|
|
578
595
|
if (runtime && runtime.activeTurnIds.size > 0) {
|
|
579
|
-
throw new Error(
|
|
596
|
+
throw new Error(
|
|
597
|
+
`Cannot delete session "${sessionId}" while turns are running.`
|
|
598
|
+
);
|
|
580
599
|
}
|
|
581
600
|
const deleted = await this.adapter.deleteSession(sessionId);
|
|
582
601
|
if (deleted) {
|
|
@@ -719,7 +738,9 @@ var InProcessAgentServer = class {
|
|
|
719
738
|
if (this.adapter.listFollowUps) {
|
|
720
739
|
return await this.adapter.listFollowUps(options);
|
|
721
740
|
}
|
|
722
|
-
const statuses = options.status ? new Set(
|
|
741
|
+
const statuses = options.status ? new Set(
|
|
742
|
+
Array.isArray(options.status) ? options.status : [options.status]
|
|
743
|
+
) : void 0;
|
|
723
744
|
return [...this.followUps.values()].filter((record) => {
|
|
724
745
|
if (options.sessionId && record.sessionId !== options.sessionId) {
|
|
725
746
|
return false;
|
|
@@ -806,14 +827,11 @@ var InProcessAgentServer = class {
|
|
|
806
827
|
});
|
|
807
828
|
}
|
|
808
829
|
if (payload.kind === "approval" && pending.request.kind === "approval") {
|
|
809
|
-
this.resolveMatchingApprovalRequests(
|
|
810
|
-
|
|
811
|
-
{
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
...payload.rememberScope ? { rememberScope: payload.rememberScope } : {}
|
|
815
|
-
}
|
|
816
|
-
);
|
|
830
|
+
this.resolveMatchingApprovalRequests(pending.request.request, {
|
|
831
|
+
action: payload.action,
|
|
832
|
+
...payload.feedback ? { feedback: payload.feedback } : {},
|
|
833
|
+
...payload.rememberScope ? { rememberScope: payload.rememberScope } : {}
|
|
834
|
+
});
|
|
817
835
|
}
|
|
818
836
|
return true;
|
|
819
837
|
}
|
|
@@ -879,10 +897,14 @@ var InProcessAgentServer = class {
|
|
|
879
897
|
async runTurn(turn, options) {
|
|
880
898
|
try {
|
|
881
899
|
let sequence = 0;
|
|
882
|
-
for await (const event of this.adapter.chat(
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
900
|
+
for await (const event of this.adapter.chat(
|
|
901
|
+
turn.sessionId,
|
|
902
|
+
turn.message,
|
|
903
|
+
{
|
|
904
|
+
abort: turn.abortController.signal,
|
|
905
|
+
...options.system ? { system: options.system } : {}
|
|
906
|
+
}
|
|
907
|
+
)) {
|
|
886
908
|
const record = {
|
|
887
909
|
sequence: ++sequence,
|
|
888
910
|
timestamp: nowIso(),
|
|
@@ -951,7 +973,10 @@ var InProcessAgentServer = class {
|
|
|
951
973
|
}
|
|
952
974
|
await manager.create({ id: sessionId, cwd: this.adapter.cwd });
|
|
953
975
|
const detail = await this.readSessionOrThrow(sessionId);
|
|
954
|
-
this.emit({
|
|
976
|
+
this.emit({
|
|
977
|
+
type: "session/created",
|
|
978
|
+
session: toSessionSummaryFromDetail(detail)
|
|
979
|
+
});
|
|
955
980
|
}
|
|
956
981
|
getOrCreateRuntimeRecord(sessionId) {
|
|
957
982
|
let record = this.sessionRuntime.get(sessionId);
|
|
@@ -1099,7 +1124,9 @@ var InProcessAgentServer = class {
|
|
|
1099
1124
|
...turn.usage ? { usage: turn.usage } : {},
|
|
1100
1125
|
...turn.error ? { error: turn.error } : {},
|
|
1101
1126
|
...turn.queuedFollowUpIds.length > 0 ? {
|
|
1102
|
-
queuedFollowUps: turn.queuedFollowUpIds.map((id) => this.followUps.get(id)).filter(
|
|
1127
|
+
queuedFollowUps: turn.queuedFollowUpIds.map((id) => this.followUps.get(id)).filter(
|
|
1128
|
+
(record) => Boolean(record)
|
|
1129
|
+
).map((record) => structuredClone(record))
|
|
1103
1130
|
} : {}
|
|
1104
1131
|
};
|
|
1105
1132
|
}
|
|
@@ -1340,7 +1367,9 @@ var AgentServerRpcConnection = class {
|
|
|
1340
1367
|
case "agent/model/switch":
|
|
1341
1368
|
return await this.server.switchModel(request.params.spec);
|
|
1342
1369
|
case "session/status":
|
|
1343
|
-
return await this.server.getSessionRuntimeStatus(
|
|
1370
|
+
return await this.server.getSessionRuntimeStatus(
|
|
1371
|
+
request.params.sessionId
|
|
1372
|
+
);
|
|
1344
1373
|
case "agent/tools":
|
|
1345
1374
|
return await this.server.listTools();
|
|
1346
1375
|
case "agent/skills":
|
|
@@ -1355,7 +1384,9 @@ var AgentServerRpcConnection = class {
|
|
|
1355
1384
|
request.params.args ?? ""
|
|
1356
1385
|
);
|
|
1357
1386
|
case "session/compact":
|
|
1358
|
-
return await this.server.compactSessionContext(
|
|
1387
|
+
return await this.server.compactSessionContext(
|
|
1388
|
+
request.params.sessionId
|
|
1389
|
+
);
|
|
1359
1390
|
case "session/undo":
|
|
1360
1391
|
return await this.server.undoSessionTurn(request.params.sessionId);
|
|
1361
1392
|
case "session/diff":
|
|
@@ -1389,7 +1420,10 @@ var AgentServerRpcConnection = class {
|
|
|
1389
1420
|
case "turn/interrupt":
|
|
1390
1421
|
return this.server.interruptTurn(request.params.turnId);
|
|
1391
1422
|
case "turn/steer":
|
|
1392
|
-
return this.server.steerTurn(
|
|
1423
|
+
return this.server.steerTurn(
|
|
1424
|
+
request.params.turnId,
|
|
1425
|
+
request.params.message
|
|
1426
|
+
);
|
|
1393
1427
|
case "turn/follow-up":
|
|
1394
1428
|
return this.server.followUpTurn(
|
|
1395
1429
|
request.params.turnId,
|
|
@@ -1469,7 +1503,10 @@ var RemoteAgentServerClient = class {
|
|
|
1469
1503
|
return this.capabilities;
|
|
1470
1504
|
}
|
|
1471
1505
|
async getWorkspaceSummary() {
|
|
1472
|
-
return await this.request(
|
|
1506
|
+
return await this.request(
|
|
1507
|
+
"workspace/summary",
|
|
1508
|
+
{}
|
|
1509
|
+
);
|
|
1473
1510
|
}
|
|
1474
1511
|
async getSessionRuntimeStatus(sessionId) {
|
|
1475
1512
|
return await this.request("session/status", {
|
|
@@ -1480,7 +1517,9 @@ var RemoteAgentServerClient = class {
|
|
|
1480
1517
|
return await this.request("agent/model/get", {});
|
|
1481
1518
|
}
|
|
1482
1519
|
async switchModel(spec) {
|
|
1483
|
-
return await this.request("agent/model/switch", {
|
|
1520
|
+
return await this.request("agent/model/switch", {
|
|
1521
|
+
spec
|
|
1522
|
+
});
|
|
1484
1523
|
}
|
|
1485
1524
|
async listTools() {
|
|
1486
1525
|
return await this.request("agent/tools", {});
|
|
@@ -1492,10 +1531,16 @@ var RemoteAgentServerClient = class {
|
|
|
1492
1531
|
return await this.request("agent/sub-agents", {});
|
|
1493
1532
|
}
|
|
1494
1533
|
async listPluginCommands() {
|
|
1495
|
-
return await this.request(
|
|
1534
|
+
return await this.request(
|
|
1535
|
+
"plugin-command/list",
|
|
1536
|
+
{}
|
|
1537
|
+
);
|
|
1496
1538
|
}
|
|
1497
1539
|
async executePluginCommand(name, args) {
|
|
1498
|
-
return await this.request("plugin-command/execute", {
|
|
1540
|
+
return await this.request("plugin-command/execute", {
|
|
1541
|
+
name,
|
|
1542
|
+
args
|
|
1543
|
+
});
|
|
1499
1544
|
}
|
|
1500
1545
|
async compactSessionContext(sessionId) {
|
|
1501
1546
|
return await this.request("session/compact", {
|
|
@@ -1512,19 +1557,27 @@ var RemoteAgentServerClient = class {
|
|
|
1512
1557
|
return await this.request("session/list", {});
|
|
1513
1558
|
}
|
|
1514
1559
|
async createSession(options) {
|
|
1515
|
-
return await this.request(
|
|
1560
|
+
return await this.request(
|
|
1561
|
+
"session/create",
|
|
1562
|
+
options ?? {}
|
|
1563
|
+
);
|
|
1516
1564
|
}
|
|
1517
1565
|
async readSession(sessionId) {
|
|
1518
|
-
return await this.request("session/read", {
|
|
1566
|
+
return await this.request("session/read", {
|
|
1567
|
+
sessionId
|
|
1568
|
+
});
|
|
1519
1569
|
}
|
|
1520
1570
|
async deleteSession(sessionId) {
|
|
1521
1571
|
return await this.request("session/delete", { sessionId });
|
|
1522
1572
|
}
|
|
1523
1573
|
async branchSession(sessionId, options) {
|
|
1524
|
-
return await this.request(
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1574
|
+
return await this.request(
|
|
1575
|
+
"session/branch",
|
|
1576
|
+
{
|
|
1577
|
+
sessionId,
|
|
1578
|
+
...options ? { options } : {}
|
|
1579
|
+
}
|
|
1580
|
+
);
|
|
1528
1581
|
}
|
|
1529
1582
|
async startTurn(sessionId, message, options) {
|
|
1530
1583
|
return await this.request("turn/start", {
|
|
@@ -1556,10 +1609,13 @@ var RemoteAgentServerClient = class {
|
|
|
1556
1609
|
});
|
|
1557
1610
|
}
|
|
1558
1611
|
async resolveFollowUp(followUpId, action) {
|
|
1559
|
-
return await this.request(
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1612
|
+
return await this.request(
|
|
1613
|
+
"follow-up/resolve",
|
|
1614
|
+
{
|
|
1615
|
+
followUpId,
|
|
1616
|
+
action
|
|
1617
|
+
}
|
|
1618
|
+
);
|
|
1563
1619
|
}
|
|
1564
1620
|
async listTeamNotifications(options) {
|
|
1565
1621
|
return await this.request("team/notification/list", {
|
|
@@ -1582,9 +1638,11 @@ var RemoteAgentServerClient = class {
|
|
|
1582
1638
|
return true;
|
|
1583
1639
|
}
|
|
1584
1640
|
respondToInputRequest(requestId, payload) {
|
|
1585
|
-
void this.request("input/respond", { requestId, payload }).catch(
|
|
1586
|
-
|
|
1587
|
-
|
|
1641
|
+
void this.request("input/respond", { requestId, payload }).catch(
|
|
1642
|
+
(error) => {
|
|
1643
|
+
logFireAndForgetError("input/respond", error);
|
|
1644
|
+
}
|
|
1645
|
+
);
|
|
1588
1646
|
return true;
|
|
1589
1647
|
}
|
|
1590
1648
|
subscribe(listener, options) {
|
|
@@ -1626,7 +1684,10 @@ var RemoteAgentServerClient = class {
|
|
|
1626
1684
|
if (envelope.kind === "notification") {
|
|
1627
1685
|
this.trackNotification(envelope.notification);
|
|
1628
1686
|
for (const record of this.listeners) {
|
|
1629
|
-
if (!matchesNotificationSubscription(
|
|
1687
|
+
if (!matchesNotificationSubscription(
|
|
1688
|
+
envelope.notification,
|
|
1689
|
+
record.options
|
|
1690
|
+
)) {
|
|
1630
1691
|
continue;
|
|
1631
1692
|
}
|
|
1632
1693
|
record.listener(envelope.notification);
|
|
@@ -1646,7 +1707,9 @@ var RemoteAgentServerClient = class {
|
|
|
1646
1707
|
pending.resolve(envelope.result);
|
|
1647
1708
|
return;
|
|
1648
1709
|
}
|
|
1649
|
-
pending.reject(
|
|
1710
|
+
pending.reject(
|
|
1711
|
+
new Error(envelope.error?.message ?? "agent-server request failed")
|
|
1712
|
+
);
|
|
1650
1713
|
}
|
|
1651
1714
|
failPending(error) {
|
|
1652
1715
|
for (const [id, pending] of this.pending) {
|
|
@@ -1831,8 +1894,10 @@ function parseWireEnvelope(line) {
|
|
|
1831
1894
|
return isAgentServerWireEnvelope(parsed) ? parsed : null;
|
|
1832
1895
|
}
|
|
1833
1896
|
function defaultTransportErrorHandler(error) {
|
|
1834
|
-
process.stderr.write(
|
|
1835
|
-
`
|
|
1897
|
+
process.stderr.write(
|
|
1898
|
+
`agent-server stdio transport error: ${error.message}
|
|
1899
|
+
`
|
|
1900
|
+
);
|
|
1836
1901
|
}
|
|
1837
1902
|
function toError(error) {
|
|
1838
1903
|
return error instanceof Error ? error : new Error(String(error));
|
|
@@ -1901,7 +1966,10 @@ function startAgentServerWebSocketServer(server, options) {
|
|
|
1901
1966
|
};
|
|
1902
1967
|
}
|
|
1903
1968
|
async function connectWebSocketAgentServerClient(options) {
|
|
1904
|
-
const transport = new WebSocketAgentServerTransport(
|
|
1969
|
+
const transport = new WebSocketAgentServerTransport(
|
|
1970
|
+
options.url,
|
|
1971
|
+
options.headers
|
|
1972
|
+
);
|
|
1905
1973
|
const client = new RemoteAgentServerClient(transport, {
|
|
1906
1974
|
requestTimeoutMs: options.requestTimeoutMs
|
|
1907
1975
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuylabs/agent-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Transport-neutral local server for @cuylabs/agent-core sessions, turns, and streamed events",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"ws": "^8.19.0",
|
|
22
|
-
"@cuylabs/agent-core": "^0.
|
|
22
|
+
"@cuylabs/agent-core": "^0.13.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^22.0.0",
|