@ljoukov/llm 7.0.6 → 7.0.8
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 +74 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +74 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7068,6 +7068,41 @@ async function executeToolCall(params) {
|
|
|
7068
7068
|
);
|
|
7069
7069
|
}
|
|
7070
7070
|
}
|
|
7071
|
+
function findTerminalToolCall(tools, toolCalls) {
|
|
7072
|
+
for (let index = toolCalls.length - 1; index >= 0; index -= 1) {
|
|
7073
|
+
const toolCall = toolCalls[index];
|
|
7074
|
+
if (!toolCall) {
|
|
7075
|
+
continue;
|
|
7076
|
+
}
|
|
7077
|
+
const toolDef = tools[toolCall.toolName];
|
|
7078
|
+
if (toolDef?.terminal === true && !toolCall.error) {
|
|
7079
|
+
return toolCall;
|
|
7080
|
+
}
|
|
7081
|
+
}
|
|
7082
|
+
return null;
|
|
7083
|
+
}
|
|
7084
|
+
function terminalToolCallText(toolCall) {
|
|
7085
|
+
const output = toolCall.output;
|
|
7086
|
+
if (typeof output === "string") {
|
|
7087
|
+
return output;
|
|
7088
|
+
}
|
|
7089
|
+
if (output && typeof output === "object") {
|
|
7090
|
+
const record = output;
|
|
7091
|
+
const summary = record.summary;
|
|
7092
|
+
if (typeof summary === "string" && summary.trim().length > 0) {
|
|
7093
|
+
return summary;
|
|
7094
|
+
}
|
|
7095
|
+
const status = record.status;
|
|
7096
|
+
const title = record.presentationTitle;
|
|
7097
|
+
if (typeof status === "string" && typeof title === "string" && title.trim().length > 0) {
|
|
7098
|
+
return `${status}: ${title}`;
|
|
7099
|
+
}
|
|
7100
|
+
if (typeof status === "string" && status.trim().length > 0) {
|
|
7101
|
+
return status;
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
return "";
|
|
7105
|
+
}
|
|
7071
7106
|
function buildToolLogId(turn, toolIndex) {
|
|
7072
7107
|
return `turn${turn.toString()}/tool${toolIndex.toString()}`;
|
|
7073
7108
|
}
|
|
@@ -8979,6 +9014,7 @@ async function runToolLoop(request) {
|
|
|
8979
9014
|
costUsd: stepCostUsd,
|
|
8980
9015
|
timing
|
|
8981
9016
|
});
|
|
9017
|
+
const terminalToolCall = findTerminalToolCall(request.tools, stepToolCalls);
|
|
8982
9018
|
const steeringInput = steeringInternal?.drainPendingContents() ?? [];
|
|
8983
9019
|
const steeringItems = steeringInput.length > 0 ? toOpenAiInput(steeringInput, {
|
|
8984
9020
|
defaultMediaResolution: request.mediaResolution,
|
|
@@ -8999,9 +9035,14 @@ async function runToolLoop(request) {
|
|
|
8999
9035
|
responseChars: responseText.length,
|
|
9000
9036
|
thoughtChars: reasoningSummary.length,
|
|
9001
9037
|
toolCalls: stepToolCalls.length,
|
|
9002
|
-
finalStep:
|
|
9038
|
+
finalStep: terminalToolCall !== null
|
|
9003
9039
|
}
|
|
9004
9040
|
});
|
|
9041
|
+
if (terminalToolCall) {
|
|
9042
|
+
finalText = terminalToolCallText(terminalToolCall) || responseText;
|
|
9043
|
+
finalThoughts = reasoningSummary;
|
|
9044
|
+
return { text: finalText, thoughts: finalThoughts, steps, totalCostUsd };
|
|
9045
|
+
}
|
|
9005
9046
|
previousResponseId = finalResponse.id;
|
|
9006
9047
|
input = steeringItems.length > 0 ? toolOutputs.concat(steeringItems) : toolOutputs;
|
|
9007
9048
|
} catch (error) {
|
|
@@ -9317,6 +9358,7 @@ async function runToolLoop(request) {
|
|
|
9317
9358
|
costUsd: stepCostUsd,
|
|
9318
9359
|
timing
|
|
9319
9360
|
});
|
|
9361
|
+
const terminalToolCall = findTerminalToolCall(request.tools, toolCalls);
|
|
9320
9362
|
const steeringInput = steeringInternal?.drainPendingContents() ?? [];
|
|
9321
9363
|
const steeringItems = steeringInput.length > 0 ? toChatGptInput(steeringInput, {
|
|
9322
9364
|
defaultMediaResolution: request.mediaResolution,
|
|
@@ -9336,9 +9378,14 @@ async function runToolLoop(request) {
|
|
|
9336
9378
|
responseChars: responseText.length,
|
|
9337
9379
|
thoughtChars: reasoningSummaryText.length,
|
|
9338
9380
|
toolCalls: toolCalls.length,
|
|
9339
|
-
finalStep:
|
|
9381
|
+
finalStep: terminalToolCall !== null
|
|
9340
9382
|
}
|
|
9341
9383
|
});
|
|
9384
|
+
if (terminalToolCall) {
|
|
9385
|
+
finalText = terminalToolCallText(terminalToolCall) || responseText;
|
|
9386
|
+
finalThoughts = reasoningSummaryText;
|
|
9387
|
+
return { text: finalText, thoughts: finalThoughts, steps, totalCostUsd };
|
|
9388
|
+
}
|
|
9342
9389
|
input = steeringItems.length > 0 ? input.concat(toolOutputs, steeringItems) : input.concat(toolOutputs);
|
|
9343
9390
|
} catch (error) {
|
|
9344
9391
|
stepCallLogger?.fail(error, {
|
|
@@ -9602,6 +9649,7 @@ async function runToolLoop(request) {
|
|
|
9602
9649
|
costUsd: stepCostUsd,
|
|
9603
9650
|
timing
|
|
9604
9651
|
});
|
|
9652
|
+
const terminalToolCall = findTerminalToolCall(request.tools, stepToolCalls);
|
|
9605
9653
|
stepCallLogger?.complete({
|
|
9606
9654
|
responseText,
|
|
9607
9655
|
toolCallText: stepToolCallText,
|
|
@@ -9617,9 +9665,14 @@ async function runToolLoop(request) {
|
|
|
9617
9665
|
responseChars: responseText.length,
|
|
9618
9666
|
thoughtChars: 0,
|
|
9619
9667
|
toolCalls: stepToolCalls.length,
|
|
9620
|
-
finalStep:
|
|
9668
|
+
finalStep: terminalToolCall !== null
|
|
9621
9669
|
}
|
|
9622
9670
|
});
|
|
9671
|
+
if (terminalToolCall) {
|
|
9672
|
+
finalText = terminalToolCallText(terminalToolCall) || responseText;
|
|
9673
|
+
finalThoughts = "";
|
|
9674
|
+
return { text: finalText, thoughts: finalThoughts, steps, totalCostUsd };
|
|
9675
|
+
}
|
|
9623
9676
|
messages.push({
|
|
9624
9677
|
role: "assistant",
|
|
9625
9678
|
...responseText.length > 0 ? { content: responseText } : {},
|
|
@@ -9963,6 +10016,7 @@ async function runToolLoop(request) {
|
|
|
9963
10016
|
costUsd: stepCostUsd,
|
|
9964
10017
|
timing
|
|
9965
10018
|
});
|
|
10019
|
+
const terminalToolCall = findTerminalToolCall(request.tools, toolCalls);
|
|
9966
10020
|
stepCallLogger?.complete({
|
|
9967
10021
|
responseText,
|
|
9968
10022
|
attachments: responseOutputAttachments,
|
|
@@ -9978,9 +10032,14 @@ async function runToolLoop(request) {
|
|
|
9978
10032
|
responseChars: responseText.length,
|
|
9979
10033
|
thoughtChars: thoughtsText.length,
|
|
9980
10034
|
toolCalls: toolCalls.length,
|
|
9981
|
-
finalStep:
|
|
10035
|
+
finalStep: terminalToolCall !== null
|
|
9982
10036
|
}
|
|
9983
10037
|
});
|
|
10038
|
+
if (terminalToolCall) {
|
|
10039
|
+
finalText = terminalToolCallText(terminalToolCall) || responseText;
|
|
10040
|
+
finalThoughts = thoughtsText;
|
|
10041
|
+
return { text: finalText, thoughts: finalThoughts, steps, totalCostUsd };
|
|
10042
|
+
}
|
|
9984
10043
|
geminiContents.push({ role: "user", parts: responseParts });
|
|
9985
10044
|
const steeringInput = steeringInternal?.drainPendingContents() ?? [];
|
|
9986
10045
|
if (steeringInput.length > 0) {
|
|
@@ -10453,9 +10512,11 @@ var subagentInputItemSchema = import_zod4.z.object({
|
|
|
10453
10512
|
}).passthrough();
|
|
10454
10513
|
var spawnAgentInputSchema = import_zod4.z.object({
|
|
10455
10514
|
prompt: import_zod4.z.string().nullish().describe("Alias for message. Initial plain-text task for the new agent."),
|
|
10456
|
-
message: import_zod4.z.string().nullish().describe(
|
|
10515
|
+
message: import_zod4.z.string().nullish().describe(
|
|
10516
|
+
"Initial plain-text task for the new agent. Combined with items when both are provided."
|
|
10517
|
+
),
|
|
10457
10518
|
items: import_zod4.z.array(subagentInputItemSchema).nullish().describe(
|
|
10458
|
-
"Structured input items. Use this to pass explicit mentions (for example app:// connector paths)."
|
|
10519
|
+
"Structured input items. Use this to pass explicit mentions (for example app:// connector paths). Combined with message/input when both are provided."
|
|
10459
10520
|
),
|
|
10460
10521
|
agent_type: import_zod4.z.string().nullish().describe(SPAWN_AGENT_TYPE_DESCRIPTION),
|
|
10461
10522
|
fork_context: import_zod4.z.boolean().nullish().describe(
|
|
@@ -10614,7 +10675,6 @@ function createSubagentToolController(options) {
|
|
|
10614
10675
|
const initialPrompt = resolveCollabInputText({
|
|
10615
10676
|
textCandidates: [{ value: input.prompt }, { value: input.message }],
|
|
10616
10677
|
items: input.items,
|
|
10617
|
-
bothError: "Provide either prompt/message or items, but not both.",
|
|
10618
10678
|
missingError: "Provide one of: prompt/message or items.",
|
|
10619
10679
|
emptyTextError: "Empty message can't be sent to an agent.",
|
|
10620
10680
|
emptyItemsError: "Items can't be empty."
|
|
@@ -10667,7 +10727,6 @@ function createSubagentToolController(options) {
|
|
|
10667
10727
|
const nextInput = resolveCollabInputText({
|
|
10668
10728
|
textCandidates: [{ value: input.input }, { value: input.message }],
|
|
10669
10729
|
items: input.items,
|
|
10670
|
-
bothError: "Provide either input/message or items, but not both.",
|
|
10671
10730
|
missingError: "Provide one of: input/message or items.",
|
|
10672
10731
|
emptyTextError: "Empty message can't be sent to an agent.",
|
|
10673
10732
|
emptyItemsError: "Items can't be empty."
|
|
@@ -10821,18 +10880,19 @@ function resolveCollabInputText(params) {
|
|
|
10821
10880
|
);
|
|
10822
10881
|
const hasText = Boolean(textCandidate);
|
|
10823
10882
|
const hasItems = params.items !== void 0 && params.items !== null;
|
|
10824
|
-
if (hasText && hasItems) {
|
|
10825
|
-
throw new Error(params.bothError);
|
|
10826
|
-
}
|
|
10827
10883
|
if (!hasText && !hasItems) {
|
|
10828
10884
|
throw new Error(params.missingError);
|
|
10829
10885
|
}
|
|
10886
|
+
const blocks = [];
|
|
10830
10887
|
if (hasText) {
|
|
10831
10888
|
const value = textCandidate?.value?.trim();
|
|
10832
10889
|
if (!value) {
|
|
10833
10890
|
throw new Error(params.emptyTextError);
|
|
10834
10891
|
}
|
|
10835
|
-
|
|
10892
|
+
blocks.push(value);
|
|
10893
|
+
}
|
|
10894
|
+
if (!hasItems) {
|
|
10895
|
+
return blocks.join("\n\n");
|
|
10836
10896
|
}
|
|
10837
10897
|
if (!params.items || params.items.length === 0) {
|
|
10838
10898
|
throw new Error(params.emptyItemsError);
|
|
@@ -10841,7 +10901,8 @@ function resolveCollabInputText(params) {
|
|
|
10841
10901
|
if (!itemText) {
|
|
10842
10902
|
throw new Error(params.emptyItemsError);
|
|
10843
10903
|
}
|
|
10844
|
-
|
|
10904
|
+
blocks.push(itemText);
|
|
10905
|
+
return blocks.join("\n\n");
|
|
10845
10906
|
}
|
|
10846
10907
|
function resolveInputItemsText(items) {
|
|
10847
10908
|
if (!items || items.length === 0) {
|