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