@ljoukov/llm 7.0.5 → 7.0.7
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 +64 -5
- 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 +64 -5
- 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
|
}
|
|
@@ -8196,7 +8231,7 @@ function buildJsonSchemaConfig(request) {
|
|
|
8196
8231
|
name: schemaName,
|
|
8197
8232
|
target: isOpenAiVariant ? "openAi" : "jsonSchema7"
|
|
8198
8233
|
});
|
|
8199
|
-
const responseJsonSchema = isOpenAiVariant ? resolveOpenAiSchemaRoot(baseJsonSchema) : isGeminiVariant ? addGeminiPropertyOrdering(baseJsonSchema) : resolveOpenAiSchemaRoot(baseJsonSchema);
|
|
8234
|
+
const responseJsonSchema = isOpenAiVariant ? resolveOpenAiSchemaRoot(baseJsonSchema) : isGeminiVariant ? addGeminiPropertyOrdering(resolveOpenAiSchemaRoot(baseJsonSchema)) : resolveOpenAiSchemaRoot(baseJsonSchema);
|
|
8200
8235
|
if (isOpenAiVariant && !isJsonSchemaObject(responseJsonSchema)) {
|
|
8201
8236
|
throw new Error("OpenAI structured outputs require a JSON object schema at the root.");
|
|
8202
8237
|
}
|
|
@@ -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) {
|