@prestyj/agent 5.29.1 → 5.30.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
|
@@ -1617,6 +1617,7 @@ async function* agentLoop(messages, options) {
|
|
|
1617
1617
|
}
|
|
1618
1618
|
messages.push({ role: "tool", content: executionResult.toolResults });
|
|
1619
1619
|
yield { type: "checkpoint", turn };
|
|
1620
|
+
if (executionResult.endRun) break;
|
|
1620
1621
|
const toolsAborted = executionResult.aborted;
|
|
1621
1622
|
if (fatalToolArgumentError) {
|
|
1622
1623
|
if (fatalToolArgumentRecoverable && !toolArgumentAutoContinueUsed) {
|
|
@@ -1753,6 +1754,7 @@ async function executeSingleToolCall(toolCall, options, pushEvent) {
|
|
|
1753
1754
|
let resultContent;
|
|
1754
1755
|
let details;
|
|
1755
1756
|
let isError = false;
|
|
1757
|
+
let endRun = false;
|
|
1756
1758
|
let invalidArgAttempt;
|
|
1757
1759
|
const tool = options.toolMap.get(toolCall.name);
|
|
1758
1760
|
if (tool) {
|
|
@@ -1811,6 +1813,7 @@ async function executeSingleToolCall(toolCall, options, pushEvent) {
|
|
|
1811
1813
|
hardSignals.length === 1 ? toolTimeout : AbortSignal.any(hardSignals)
|
|
1812
1814
|
);
|
|
1813
1815
|
const normalized = normalizeToolResult(raw);
|
|
1816
|
+
endRun = normalized.endRun === true;
|
|
1814
1817
|
resultContent = (0, import_ai2.redactValue)(normalized.content, toolRedactionOptions());
|
|
1815
1818
|
details = (0, import_ai2.redactValue)(normalized.details, toolRedactionOptions());
|
|
1816
1819
|
if (options.transformToolResult) {
|
|
@@ -1882,11 +1885,12 @@ ${hints}` : "") + "\nRe-issue the call with each field as the correct type.";
|
|
|
1882
1885
|
durationMs,
|
|
1883
1886
|
...invalidArgAttempt === void 0 ? {} : { invalidArgAttempt }
|
|
1884
1887
|
});
|
|
1885
|
-
return { toolCallId: toolCall.id, content: resultContent, isError };
|
|
1888
|
+
return { toolCallId: toolCall.id, content: resultContent, isError, endRun: endRun && !isError };
|
|
1886
1889
|
}
|
|
1887
1890
|
function createPreemptTracker(options, eventStream, state, resultsById, dispatchedIds) {
|
|
1888
1891
|
const running = /* @__PURE__ */ new Map();
|
|
1889
1892
|
let graceTimer;
|
|
1893
|
+
let endRun = false;
|
|
1890
1894
|
const preemptSignal = options.preemptSignal;
|
|
1891
1895
|
const abandon = () => {
|
|
1892
1896
|
graceTimer = void 0;
|
|
@@ -1910,7 +1914,7 @@ function createPreemptTracker(options, eventStream, state, resultsById, dispatch
|
|
|
1910
1914
|
preemptSignal?.addEventListener("abort", onPreempt, { once: true });
|
|
1911
1915
|
return {
|
|
1912
1916
|
async run(toolCall) {
|
|
1913
|
-
if (options.preemptSignal?.aborted) return;
|
|
1917
|
+
if (endRun || options.preemptSignal?.aborted) return;
|
|
1914
1918
|
dispatchedIds.add(toolCall.id);
|
|
1915
1919
|
const interruptible = isInterruptibleTool(options.toolMap.get(toolCall.name), toolCall.name);
|
|
1916
1920
|
running.set(toolCall.id, { toolCall, interruptible, startedAt: Date.now() });
|
|
@@ -1922,15 +1926,15 @@ function createPreemptTracker(options, eventStream, state, resultsById, dispatch
|
|
|
1922
1926
|
running.delete(toolCall.id);
|
|
1923
1927
|
if (resultsById.has(toolCall.id)) return;
|
|
1924
1928
|
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);
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
);
|
|
1929
|
+
const result = interruptible && preemptSignal?.aborted && !alreadyMarked ? markSteerInterrupted(record) : record;
|
|
1930
|
+
resultsById.set(toolCall.id, result);
|
|
1931
|
+
if (result.endRun && !result.isError) endRun = true;
|
|
1929
1932
|
if (preemptSignal?.aborted && graceTimer === void 0 && running.size === 0) {
|
|
1930
1933
|
eventStream.close();
|
|
1931
1934
|
}
|
|
1932
1935
|
},
|
|
1933
1936
|
preempted: () => preemptSignal?.aborted === true,
|
|
1937
|
+
endRun: () => endRun,
|
|
1934
1938
|
dispose: () => {
|
|
1935
1939
|
if (graceTimer !== void 0) clearTimeout(graceTimer);
|
|
1936
1940
|
preemptSignal?.removeEventListener("abort", onPreempt);
|
|
@@ -1965,7 +1969,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1965
1969
|
void (async () => {
|
|
1966
1970
|
try {
|
|
1967
1971
|
for (const phase of phases) {
|
|
1968
|
-
if (options.signal?.aborted || options.preemptSignal?.aborted) break;
|
|
1972
|
+
if (options.signal?.aborted || options.preemptSignal?.aborted || tracker.endRun()) break;
|
|
1969
1973
|
if (phase.sequential) {
|
|
1970
1974
|
const signature = JSON.stringify([
|
|
1971
1975
|
phase.sequential.name,
|
|
@@ -2003,7 +2007,12 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
2003
2007
|
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById, dispatchedIds);
|
|
2004
2008
|
capToolResults(toolResults, options.maxToolResultChars);
|
|
2005
2009
|
capTurnToolResults(toolResults, options.maxTurnToolResultChars);
|
|
2006
|
-
return {
|
|
2010
|
+
return {
|
|
2011
|
+
toolResults,
|
|
2012
|
+
aborted,
|
|
2013
|
+
preempted: !aborted && tracker.preempted(),
|
|
2014
|
+
endRun: tracker.endRun()
|
|
2015
|
+
};
|
|
2007
2016
|
}
|
|
2008
2017
|
async function* executeToolCallsParallel(toolCalls, initialToolResults, options) {
|
|
2009
2018
|
const eventStream = new import_ai2.EventStream();
|
|
@@ -2037,7 +2046,12 @@ async function* executeToolCallsParallel(toolCalls, initialToolResults, options)
|
|
|
2037
2046
|
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById, dispatchedIds);
|
|
2038
2047
|
capToolResults(toolResults, options.maxToolResultChars);
|
|
2039
2048
|
capTurnToolResults(toolResults, options.maxTurnToolResultChars);
|
|
2040
|
-
return {
|
|
2049
|
+
return {
|
|
2050
|
+
toolResults,
|
|
2051
|
+
aborted,
|
|
2052
|
+
preempted: !aborted && tracker.preempted(),
|
|
2053
|
+
endRun: tracker.endRun()
|
|
2054
|
+
};
|
|
2041
2055
|
}
|
|
2042
2056
|
function cancelledBeforeStartText(name) {
|
|
2043
2057
|
return `\`${name}\` was cancelled before it started, so it had no effect. Safe to retry.`;
|