u
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user