@kenkaiiii/gg-agent 5.49.10 → 5.50.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.cjs +32 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +30 -25
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,8 @@ __export(index_exports, {
|
|
|
23
23
|
Agent: () => Agent,
|
|
24
24
|
AgentStream: () => AgentStream,
|
|
25
25
|
agentLoop: () => agentLoop,
|
|
26
|
+
cancelledBeforeStartText: () => cancelledBeforeStartText,
|
|
27
|
+
indeterminateOutcomeText: () => indeterminateOutcomeText,
|
|
26
28
|
isAbortError: () => isAbortError,
|
|
27
29
|
isBillingError: () => isBillingError,
|
|
28
30
|
isContextOverflow: () => isContextOverflow,
|
|
@@ -1346,6 +1348,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1346
1348
|
const eventStream = new import_gg_ai.EventStream();
|
|
1347
1349
|
const state = { finalized: false };
|
|
1348
1350
|
const resultsById = /* @__PURE__ */ new Map();
|
|
1351
|
+
const dispatchedIds = /* @__PURE__ */ new Set();
|
|
1349
1352
|
const abortHandler = () => eventStream.abort(new Error("aborted"));
|
|
1350
1353
|
options.signal?.addEventListener("abort", abortHandler, { once: true });
|
|
1351
1354
|
const phases = [];
|
|
@@ -1370,6 +1373,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1370
1373
|
for (const phase of phases) {
|
|
1371
1374
|
if (options.signal?.aborted) break;
|
|
1372
1375
|
if (phase.sequential) {
|
|
1376
|
+
dispatchedIds.add(phase.sequential.id);
|
|
1373
1377
|
const record = await executeSingleToolCall(
|
|
1374
1378
|
phase.sequential,
|
|
1375
1379
|
options,
|
|
@@ -1377,6 +1381,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1377
1381
|
);
|
|
1378
1382
|
resultsById.set(record.toolCallId, record);
|
|
1379
1383
|
} else if (phase.parallel.length === 1) {
|
|
1384
|
+
dispatchedIds.add(phase.parallel[0].id);
|
|
1380
1385
|
const record = await executeSingleToolCall(
|
|
1381
1386
|
phase.parallel[0],
|
|
1382
1387
|
options,
|
|
@@ -1386,6 +1391,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1386
1391
|
} else {
|
|
1387
1392
|
await Promise.all(
|
|
1388
1393
|
phase.parallel.map(async (toolCall) => {
|
|
1394
|
+
dispatchedIds.add(toolCall.id);
|
|
1389
1395
|
const record = await executeSingleToolCall(
|
|
1390
1396
|
toolCall,
|
|
1391
1397
|
options,
|
|
@@ -1416,7 +1422,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1416
1422
|
options.signal?.removeEventListener("abort", abortHandler);
|
|
1417
1423
|
state.finalized = true;
|
|
1418
1424
|
}
|
|
1419
|
-
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById);
|
|
1425
|
+
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById, dispatchedIds);
|
|
1420
1426
|
capToolResults(toolResults, options.maxToolResultChars);
|
|
1421
1427
|
capTurnToolResults(toolResults, options.maxTurnToolResultChars);
|
|
1422
1428
|
return { toolResults, aborted };
|
|
@@ -1425,10 +1431,12 @@ async function* executeToolCallsParallel(toolCalls, initialToolResults, options)
|
|
|
1425
1431
|
const eventStream = new import_gg_ai.EventStream();
|
|
1426
1432
|
const state = { finalized: false };
|
|
1427
1433
|
const resultsById = /* @__PURE__ */ new Map();
|
|
1434
|
+
const dispatchedIds = /* @__PURE__ */ new Set();
|
|
1428
1435
|
const abortHandler = () => eventStream.abort(new Error("aborted"));
|
|
1429
1436
|
options.signal?.addEventListener("abort", abortHandler, { once: true });
|
|
1430
1437
|
Promise.all(
|
|
1431
1438
|
toolCalls.map(async (toolCall) => {
|
|
1439
|
+
dispatchedIds.add(toolCall.id);
|
|
1432
1440
|
const record = await executeSingleToolCall(
|
|
1433
1441
|
toolCall,
|
|
1434
1442
|
options,
|
|
@@ -1456,12 +1464,18 @@ async function* executeToolCallsParallel(toolCalls, initialToolResults, options)
|
|
|
1456
1464
|
options.signal?.removeEventListener("abort", abortHandler);
|
|
1457
1465
|
state.finalized = true;
|
|
1458
1466
|
}
|
|
1459
|
-
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById);
|
|
1467
|
+
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById, dispatchedIds);
|
|
1460
1468
|
capToolResults(toolResults, options.maxToolResultChars);
|
|
1461
1469
|
capTurnToolResults(toolResults, options.maxTurnToolResultChars);
|
|
1462
1470
|
return { toolResults, aborted };
|
|
1463
1471
|
}
|
|
1464
|
-
function
|
|
1472
|
+
function cancelledBeforeStartText(name) {
|
|
1473
|
+
return `\`${name}\` was cancelled before it started, so it had no effect. Safe to retry.`;
|
|
1474
|
+
}
|
|
1475
|
+
function indeterminateOutcomeText(name) {
|
|
1476
|
+
return `\`${name}\` started running and was cut off before it reported back, so its outcome is UNKNOWN \u2014 it may have completed. Check the real state (re-read the file, re-run a status command) before retrying it, and do not tell the user it did not happen.`;
|
|
1477
|
+
}
|
|
1478
|
+
function buildToolResults(initialToolResults, toolCalls, resultsById, dispatchedIds) {
|
|
1465
1479
|
const toolResults = [...initialToolResults];
|
|
1466
1480
|
for (const toolCall of toolCalls) {
|
|
1467
1481
|
const result = resultsById.get(toolCall.id);
|
|
@@ -1473,10 +1487,11 @@ function buildToolResults(initialToolResults, toolCalls, resultsById) {
|
|
|
1473
1487
|
isError: result.isError || void 0
|
|
1474
1488
|
});
|
|
1475
1489
|
} else {
|
|
1490
|
+
const dispatched = dispatchedIds?.has(toolCall.id) ?? true;
|
|
1476
1491
|
toolResults.push({
|
|
1477
1492
|
type: "tool_result",
|
|
1478
1493
|
toolCallId: toolCall.id,
|
|
1479
|
-
content:
|
|
1494
|
+
content: dispatched ? indeterminateOutcomeText(toolCall.name) : cancelledBeforeStartText(toolCall.name),
|
|
1480
1495
|
isError: true
|
|
1481
1496
|
});
|
|
1482
1497
|
}
|
|
@@ -1624,32 +1639,22 @@ function repairToolPairingAdjacent(messages) {
|
|
|
1624
1639
|
const msg = messages[i];
|
|
1625
1640
|
if (msg.role !== "assistant") continue;
|
|
1626
1641
|
if (typeof msg.content === "string" || !Array.isArray(msg.content)) continue;
|
|
1627
|
-
const
|
|
1628
|
-
if (
|
|
1642
|
+
const orphanCalls = msg.content.filter((p) => p.type === "tool_call").map((p) => p);
|
|
1643
|
+
if (orphanCalls.length === 0) continue;
|
|
1644
|
+
const repaired = (call) => ({
|
|
1645
|
+
type: "tool_result",
|
|
1646
|
+
toolCallId: call.id,
|
|
1647
|
+
content: indeterminateOutcomeText(call.name),
|
|
1648
|
+
isError: true
|
|
1649
|
+
});
|
|
1629
1650
|
const next = messages[i + 1];
|
|
1630
1651
|
if (next?.role === "tool" && Array.isArray(next.content)) {
|
|
1631
1652
|
const existingIds = new Set(next.content.map((r) => r.toolCallId));
|
|
1632
|
-
const
|
|
1633
|
-
|
|
1634
|
-
for (const id of missing) {
|
|
1635
|
-
next.content.push({
|
|
1636
|
-
type: "tool_result",
|
|
1637
|
-
toolCallId: id,
|
|
1638
|
-
content: "Tool execution was interrupted.",
|
|
1639
|
-
isError: true
|
|
1640
|
-
});
|
|
1641
|
-
}
|
|
1653
|
+
for (const call of orphanCalls) {
|
|
1654
|
+
if (!existingIds.has(call.id)) next.content.push(repaired(call));
|
|
1642
1655
|
}
|
|
1643
1656
|
} else {
|
|
1644
|
-
messages.splice(i + 1, 0, {
|
|
1645
|
-
role: "tool",
|
|
1646
|
-
content: toolCallIds.map((id) => ({
|
|
1647
|
-
type: "tool_result",
|
|
1648
|
-
toolCallId: id,
|
|
1649
|
-
content: "Tool execution was interrupted.",
|
|
1650
|
-
isError: true
|
|
1651
|
-
}))
|
|
1652
|
-
});
|
|
1657
|
+
messages.splice(i + 1, 0, { role: "tool", content: orphanCalls.map(repaired) });
|
|
1653
1658
|
}
|
|
1654
1659
|
}
|
|
1655
1660
|
const toolCallIdSet = /* @__PURE__ */ new Set();
|
|
@@ -1809,6 +1814,8 @@ var Agent = class {
|
|
|
1809
1814
|
Agent,
|
|
1810
1815
|
AgentStream,
|
|
1811
1816
|
agentLoop,
|
|
1817
|
+
cancelledBeforeStartText,
|
|
1818
|
+
indeterminateOutcomeText,
|
|
1812
1819
|
isAbortError,
|
|
1813
1820
|
isBillingError,
|
|
1814
1821
|
isContextOverflow,
|