@kenkaiiii/gg-agent 5.72.0 → 5.74.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 +23 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +23 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1556,6 +1556,7 @@ async function* agentLoop(messages, options) {
|
|
|
1556
1556
|
}
|
|
1557
1557
|
messages.push({ role: "tool", content: executionResult.toolResults });
|
|
1558
1558
|
yield { type: "checkpoint", turn };
|
|
1559
|
+
if (executionResult.endRun) break;
|
|
1559
1560
|
const toolsAborted = executionResult.aborted;
|
|
1560
1561
|
if (fatalToolArgumentError) {
|
|
1561
1562
|
if (fatalToolArgumentRecoverable && !toolArgumentAutoContinueUsed) {
|
|
@@ -1692,6 +1693,7 @@ async function executeSingleToolCall(toolCall, options, pushEvent) {
|
|
|
1692
1693
|
let resultContent;
|
|
1693
1694
|
let details;
|
|
1694
1695
|
let isError = false;
|
|
1696
|
+
let endRun = false;
|
|
1695
1697
|
let invalidArgAttempt;
|
|
1696
1698
|
const tool = options.toolMap.get(toolCall.name);
|
|
1697
1699
|
if (tool) {
|
|
@@ -1744,6 +1746,7 @@ async function executeSingleToolCall(toolCall, options, pushEvent) {
|
|
|
1744
1746
|
};
|
|
1745
1747
|
const raw = await tool.execute(parsed, ctx);
|
|
1746
1748
|
const normalized = normalizeToolResult(raw);
|
|
1749
|
+
endRun = normalized.endRun === true;
|
|
1747
1750
|
resultContent = (0, import_gg_ai2.redactValue)(normalized.content, toolRedactionOptions());
|
|
1748
1751
|
details = (0, import_gg_ai2.redactValue)(normalized.details, toolRedactionOptions());
|
|
1749
1752
|
if (options.transformToolResult) {
|
|
@@ -1813,11 +1816,12 @@ ${hints}` : "") + "\nRe-issue the call with each field as the correct type.";
|
|
|
1813
1816
|
durationMs,
|
|
1814
1817
|
...invalidArgAttempt === void 0 ? {} : { invalidArgAttempt }
|
|
1815
1818
|
});
|
|
1816
|
-
return { toolCallId: toolCall.id, content: resultContent, isError };
|
|
1819
|
+
return { toolCallId: toolCall.id, content: resultContent, isError, endRun: endRun && !isError };
|
|
1817
1820
|
}
|
|
1818
1821
|
function createPreemptTracker(options, eventStream, state, resultsById, dispatchedIds) {
|
|
1819
1822
|
const running = /* @__PURE__ */ new Map();
|
|
1820
1823
|
let graceTimer;
|
|
1824
|
+
let endRun = false;
|
|
1821
1825
|
const preemptSignal = options.preemptSignal;
|
|
1822
1826
|
const abandon = () => {
|
|
1823
1827
|
graceTimer = void 0;
|
|
@@ -1841,7 +1845,7 @@ function createPreemptTracker(options, eventStream, state, resultsById, dispatch
|
|
|
1841
1845
|
preemptSignal?.addEventListener("abort", onPreempt, { once: true });
|
|
1842
1846
|
return {
|
|
1843
1847
|
async run(toolCall) {
|
|
1844
|
-
if (options.preemptSignal?.aborted) return;
|
|
1848
|
+
if (endRun || options.preemptSignal?.aborted) return;
|
|
1845
1849
|
dispatchedIds.add(toolCall.id);
|
|
1846
1850
|
const interruptible = isInterruptibleTool(options.toolMap.get(toolCall.name), toolCall.name);
|
|
1847
1851
|
running.set(toolCall.id, { toolCall, interruptible, startedAt: Date.now() });
|
|
@@ -1853,15 +1857,15 @@ function createPreemptTracker(options, eventStream, state, resultsById, dispatch
|
|
|
1853
1857
|
running.delete(toolCall.id);
|
|
1854
1858
|
if (resultsById.has(toolCall.id)) return;
|
|
1855
1859
|
const alreadyMarked = typeof record.content === "string" ? record.content.startsWith(STEER_INTERRUPTED_TEXT) : record.content[0]?.type === "text" && record.content[0].text.startsWith(STEER_INTERRUPTED_TEXT);
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
);
|
|
1860
|
+
const result = interruptible && preemptSignal?.aborted && !alreadyMarked ? markSteerInterrupted(record) : record;
|
|
1861
|
+
resultsById.set(toolCall.id, result);
|
|
1862
|
+
if (result.endRun && !result.isError) endRun = true;
|
|
1860
1863
|
if (preemptSignal?.aborted && graceTimer === void 0 && running.size === 0) {
|
|
1861
1864
|
eventStream.close();
|
|
1862
1865
|
}
|
|
1863
1866
|
},
|
|
1864
1867
|
preempted: () => preemptSignal?.aborted === true,
|
|
1868
|
+
endRun: () => endRun,
|
|
1865
1869
|
dispose: () => {
|
|
1866
1870
|
if (graceTimer !== void 0) clearTimeout(graceTimer);
|
|
1867
1871
|
preemptSignal?.removeEventListener("abort", onPreempt);
|
|
@@ -1896,7 +1900,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1896
1900
|
void (async () => {
|
|
1897
1901
|
try {
|
|
1898
1902
|
for (const phase of phases) {
|
|
1899
|
-
if (options.signal?.aborted || options.preemptSignal?.aborted) break;
|
|
1903
|
+
if (options.signal?.aborted || options.preemptSignal?.aborted || tracker.endRun()) break;
|
|
1900
1904
|
if (phase.sequential) {
|
|
1901
1905
|
const signature = JSON.stringify([
|
|
1902
1906
|
phase.sequential.name,
|
|
@@ -1934,7 +1938,12 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1934
1938
|
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById, dispatchedIds);
|
|
1935
1939
|
capToolResults(toolResults, options.maxToolResultChars);
|
|
1936
1940
|
capTurnToolResults(toolResults, options.maxTurnToolResultChars);
|
|
1937
|
-
return {
|
|
1941
|
+
return {
|
|
1942
|
+
toolResults,
|
|
1943
|
+
aborted,
|
|
1944
|
+
preempted: !aborted && tracker.preempted(),
|
|
1945
|
+
endRun: tracker.endRun()
|
|
1946
|
+
};
|
|
1938
1947
|
}
|
|
1939
1948
|
async function* executeToolCallsParallel(toolCalls, initialToolResults, options) {
|
|
1940
1949
|
const eventStream = new import_gg_ai2.EventStream();
|
|
@@ -1968,7 +1977,12 @@ async function* executeToolCallsParallel(toolCalls, initialToolResults, options)
|
|
|
1968
1977
|
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById, dispatchedIds);
|
|
1969
1978
|
capToolResults(toolResults, options.maxToolResultChars);
|
|
1970
1979
|
capTurnToolResults(toolResults, options.maxTurnToolResultChars);
|
|
1971
|
-
return {
|
|
1980
|
+
return {
|
|
1981
|
+
toolResults,
|
|
1982
|
+
aborted,
|
|
1983
|
+
preempted: !aborted && tracker.preempted(),
|
|
1984
|
+
endRun: tracker.endRun()
|
|
1985
|
+
};
|
|
1972
1986
|
}
|
|
1973
1987
|
function cancelledBeforeStartText(name) {
|
|
1974
1988
|
return `\`${name}\` was cancelled before it started, so it had no effect. Safe to retry.`;
|