This commit is contained in:
seb
2026-10-05 10:08:24 +02:00
parent c0e8171ef7
commit 9b24e8ece4
6 changed files with 128 additions and 25 deletions

View File

@@ -105,9 +105,9 @@ class LLMOrbiter {
this._activeController = controller;
const runSignal = controller.signal;
const call = (fn, arg) => {
const call = (fn, ...args) => {
if (fn) {
try { fn(arg); } catch (_) {}
try { fn(...args); } catch (_) {}
}
};
@@ -187,7 +187,7 @@ class LLMOrbiter {
signal: runSignal,
extraBody,
onStatus: (s) => call(onStatus, s),
onContent: (c) => call(onContent, c),
onContent: (...args) => call(onContent, ...args),
onReasoning: (r) => call(onReasoning, r),
});
@@ -213,6 +213,8 @@ class LLMOrbiter {
role: 'assistant',
content: content || null,
...(hasToolCalls ? { tool_calls: toolCalls } : {}),
...(completion.reasoning_details?.length ? { reasoning_details: completion.reasoning_details } : {}),
...(completion.reasoning ? { reasoning: completion.reasoning } : {}),
});
// No tool calls → done
@@ -247,7 +249,7 @@ class LLMOrbiter {
}
if (!isError) {
call(onToolCall, { name: fnName, args });
call(onToolCall, { name: fnName, args, id: callItem.id, callItem, tool_calls: toolCalls, reasoning_details: completion.reasoning_details, reasoning: completion.reasoning, content: content || null });
try {
result = await invokeFn(args, {
@@ -267,10 +269,12 @@ class LLMOrbiter {
// calls in the batch with synthetic tool messages, so the
// returned transcript stays valid to send back to the API
// (every tool_call must have a matching tool response).
recordToolResult(callItem, err.data);
for (let j = callIdx + 1; j < toolCalls.length; j++) {
const pending = toolCalls[j];
recordToolResult(pending, 'Skipped: run terminated by direct return');
if (err.recordResult !== false) {
recordToolResult(callItem, err.data);
for (let j = callIdx + 1; j < toolCalls.length; j++) {
const pending = toolCalls[j];
recordToolResult(pending, 'Skipped: run terminated by direct return');
}
}
break;
}
@@ -285,7 +289,7 @@ class LLMOrbiter {
errorMsg = 'Tool crashed due to an unspecified internal error';
}
result = { error: errorMsg };
call(onToolError, { name: fnName, error: errorMsg, args, rawError: err });
call(onToolError, { name: fnName, error: errorMsg, args, rawError: err, id: callItem.id, callItem });
}
// Also handle tools that return { error: ... } instead of throwing
@@ -310,7 +314,7 @@ class LLMOrbiter {
allToolResults[fnName].push(result);
if (!isError) {
call(onToolResult, { name: fnName, result });
call(onToolResult, { name: fnName, result, id: callItem.id, callItem });
}
// Feed result back to conversation