@ljoukov/llm 7.0.6 → 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 +63 -4
- 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 +63 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -341,6 +341,7 @@ type LlmFunctionTool<Schema extends z.ZodType, Output> = {
|
|
|
341
341
|
readonly type?: "function";
|
|
342
342
|
readonly description?: string;
|
|
343
343
|
readonly inputSchema: Schema;
|
|
344
|
+
readonly terminal?: boolean;
|
|
344
345
|
readonly execute: (input: z.output<Schema>) => Promise<Output> | Output;
|
|
345
346
|
};
|
|
346
347
|
type LlmCustomToolInputFormat = {
|
|
@@ -354,6 +355,7 @@ type LlmCustomTool<Output> = {
|
|
|
354
355
|
readonly type: "custom";
|
|
355
356
|
readonly description?: string;
|
|
356
357
|
readonly format?: LlmCustomToolInputFormat;
|
|
358
|
+
readonly terminal?: boolean;
|
|
357
359
|
readonly execute: (input: string) => Promise<Output> | Output;
|
|
358
360
|
};
|
|
359
361
|
type LlmExecutableTool<Schema extends z.ZodType, Output> = LlmFunctionTool<Schema, Output> | LlmCustomTool<Output>;
|
|
@@ -361,11 +363,13 @@ type LlmToolSet = Record<string, LlmExecutableTool<z.ZodType, unknown>>;
|
|
|
361
363
|
declare function tool<Schema extends z.ZodType, Output>(options: {
|
|
362
364
|
readonly description?: string;
|
|
363
365
|
readonly inputSchema: Schema;
|
|
366
|
+
readonly terminal?: boolean;
|
|
364
367
|
readonly execute: (input: z.output<Schema>) => Promise<Output> | Output;
|
|
365
368
|
}): LlmFunctionTool<Schema, Output>;
|
|
366
369
|
declare function customTool<Output>(options: {
|
|
367
370
|
readonly description?: string;
|
|
368
371
|
readonly format?: LlmCustomToolInputFormat;
|
|
372
|
+
readonly terminal?: boolean;
|
|
369
373
|
readonly execute: (input: string) => Promise<Output> | Output;
|
|
370
374
|
}): LlmCustomTool<Output>;
|
|
371
375
|
type LlmToolCallResult = {
|
package/dist/index.d.ts
CHANGED
|
@@ -341,6 +341,7 @@ type LlmFunctionTool<Schema extends z.ZodType, Output> = {
|
|
|
341
341
|
readonly type?: "function";
|
|
342
342
|
readonly description?: string;
|
|
343
343
|
readonly inputSchema: Schema;
|
|
344
|
+
readonly terminal?: boolean;
|
|
344
345
|
readonly execute: (input: z.output<Schema>) => Promise<Output> | Output;
|
|
345
346
|
};
|
|
346
347
|
type LlmCustomToolInputFormat = {
|
|
@@ -354,6 +355,7 @@ type LlmCustomTool<Output> = {
|
|
|
354
355
|
readonly type: "custom";
|
|
355
356
|
readonly description?: string;
|
|
356
357
|
readonly format?: LlmCustomToolInputFormat;
|
|
358
|
+
readonly terminal?: boolean;
|
|
357
359
|
readonly execute: (input: string) => Promise<Output> | Output;
|
|
358
360
|
};
|
|
359
361
|
type LlmExecutableTool<Schema extends z.ZodType, Output> = LlmFunctionTool<Schema, Output> | LlmCustomTool<Output>;
|
|
@@ -361,11 +363,13 @@ type LlmToolSet = Record<string, LlmExecutableTool<z.ZodType, unknown>>;
|
|
|
361
363
|
declare function tool<Schema extends z.ZodType, Output>(options: {
|
|
362
364
|
readonly description?: string;
|
|
363
365
|
readonly inputSchema: Schema;
|
|
366
|
+
readonly terminal?: boolean;
|
|
364
367
|
readonly execute: (input: z.output<Schema>) => Promise<Output> | Output;
|
|
365
368
|
}): LlmFunctionTool<Schema, Output>;
|
|
366
369
|
declare function customTool<Output>(options: {
|
|
367
370
|
readonly description?: string;
|
|
368
371
|
readonly format?: LlmCustomToolInputFormat;
|
|
372
|
+
readonly terminal?: boolean;
|
|
369
373
|
readonly execute: (input: string) => Promise<Output> | Output;
|
|
370
374
|
}): LlmCustomTool<Output>;
|
|
371
375
|
type LlmToolCallResult = {
|
package/dist/index.js
CHANGED
|
@@ -6955,6 +6955,41 @@ async function executeToolCall(params) {
|
|
|
6955
6955
|
);
|
|
6956
6956
|
}
|
|
6957
6957
|
}
|
|
6958
|
+
function findTerminalToolCall(tools, toolCalls) {
|
|
6959
|
+
for (let index = toolCalls.length - 1; index >= 0; index -= 1) {
|
|
6960
|
+
const toolCall = toolCalls[index];
|
|
6961
|
+
if (!toolCall) {
|
|
6962
|
+
continue;
|
|
6963
|
+
}
|
|
6964
|
+
const toolDef = tools[toolCall.toolName];
|
|
6965
|
+
if (toolDef?.terminal === true && !toolCall.error) {
|
|
6966
|
+
return toolCall;
|
|
6967
|
+
}
|
|
6968
|
+
}
|
|
6969
|
+
return null;
|
|
6970
|
+
}
|
|
6971
|
+
function terminalToolCallText(toolCall) {
|
|
6972
|
+
const output = toolCall.output;
|
|
6973
|
+
if (typeof output === "string") {
|
|
6974
|
+
return output;
|
|
6975
|
+
}
|
|
6976
|
+
if (output && typeof output === "object") {
|
|
6977
|
+
const record = output;
|
|
6978
|
+
const summary = record.summary;
|
|
6979
|
+
if (typeof summary === "string" && summary.trim().length > 0) {
|
|
6980
|
+
return summary;
|
|
6981
|
+
}
|
|
6982
|
+
const status = record.status;
|
|
6983
|
+
const title = record.presentationTitle;
|
|
6984
|
+
if (typeof status === "string" && typeof title === "string" && title.trim().length > 0) {
|
|
6985
|
+
return `${status}: ${title}`;
|
|
6986
|
+
}
|
|
6987
|
+
if (typeof status === "string" && status.trim().length > 0) {
|
|
6988
|
+
return status;
|
|
6989
|
+
}
|
|
6990
|
+
}
|
|
6991
|
+
return "";
|
|
6992
|
+
}
|
|
6958
6993
|
function buildToolLogId(turn, toolIndex) {
|
|
6959
6994
|
return `turn${turn.toString()}/tool${toolIndex.toString()}`;
|
|
6960
6995
|
}
|
|
@@ -8866,6 +8901,7 @@ async function runToolLoop(request) {
|
|
|
8866
8901
|
costUsd: stepCostUsd,
|
|
8867
8902
|
timing
|
|
8868
8903
|
});
|
|
8904
|
+
const terminalToolCall = findTerminalToolCall(request.tools, stepToolCalls);
|
|
8869
8905
|
const steeringInput = steeringInternal?.drainPendingContents() ?? [];
|
|
8870
8906
|
const steeringItems = steeringInput.length > 0 ? toOpenAiInput(steeringInput, {
|
|
8871
8907
|
defaultMediaResolution: request.mediaResolution,
|
|
@@ -8886,9 +8922,14 @@ async function runToolLoop(request) {
|
|
|
8886
8922
|
responseChars: responseText.length,
|
|
8887
8923
|
thoughtChars: reasoningSummary.length,
|
|
8888
8924
|
toolCalls: stepToolCalls.length,
|
|
8889
|
-
finalStep:
|
|
8925
|
+
finalStep: terminalToolCall !== null
|
|
8890
8926
|
}
|
|
8891
8927
|
});
|
|
8928
|
+
if (terminalToolCall) {
|
|
8929
|
+
finalText = terminalToolCallText(terminalToolCall) || responseText;
|
|
8930
|
+
finalThoughts = reasoningSummary;
|
|
8931
|
+
return { text: finalText, thoughts: finalThoughts, steps, totalCostUsd };
|
|
8932
|
+
}
|
|
8892
8933
|
previousResponseId = finalResponse.id;
|
|
8893
8934
|
input = steeringItems.length > 0 ? toolOutputs.concat(steeringItems) : toolOutputs;
|
|
8894
8935
|
} catch (error) {
|
|
@@ -9204,6 +9245,7 @@ async function runToolLoop(request) {
|
|
|
9204
9245
|
costUsd: stepCostUsd,
|
|
9205
9246
|
timing
|
|
9206
9247
|
});
|
|
9248
|
+
const terminalToolCall = findTerminalToolCall(request.tools, toolCalls);
|
|
9207
9249
|
const steeringInput = steeringInternal?.drainPendingContents() ?? [];
|
|
9208
9250
|
const steeringItems = steeringInput.length > 0 ? toChatGptInput(steeringInput, {
|
|
9209
9251
|
defaultMediaResolution: request.mediaResolution,
|
|
@@ -9223,9 +9265,14 @@ async function runToolLoop(request) {
|
|
|
9223
9265
|
responseChars: responseText.length,
|
|
9224
9266
|
thoughtChars: reasoningSummaryText.length,
|
|
9225
9267
|
toolCalls: toolCalls.length,
|
|
9226
|
-
finalStep:
|
|
9268
|
+
finalStep: terminalToolCall !== null
|
|
9227
9269
|
}
|
|
9228
9270
|
});
|
|
9271
|
+
if (terminalToolCall) {
|
|
9272
|
+
finalText = terminalToolCallText(terminalToolCall) || responseText;
|
|
9273
|
+
finalThoughts = reasoningSummaryText;
|
|
9274
|
+
return { text: finalText, thoughts: finalThoughts, steps, totalCostUsd };
|
|
9275
|
+
}
|
|
9229
9276
|
input = steeringItems.length > 0 ? input.concat(toolOutputs, steeringItems) : input.concat(toolOutputs);
|
|
9230
9277
|
} catch (error) {
|
|
9231
9278
|
stepCallLogger?.fail(error, {
|
|
@@ -9489,6 +9536,7 @@ async function runToolLoop(request) {
|
|
|
9489
9536
|
costUsd: stepCostUsd,
|
|
9490
9537
|
timing
|
|
9491
9538
|
});
|
|
9539
|
+
const terminalToolCall = findTerminalToolCall(request.tools, stepToolCalls);
|
|
9492
9540
|
stepCallLogger?.complete({
|
|
9493
9541
|
responseText,
|
|
9494
9542
|
toolCallText: stepToolCallText,
|
|
@@ -9504,9 +9552,14 @@ async function runToolLoop(request) {
|
|
|
9504
9552
|
responseChars: responseText.length,
|
|
9505
9553
|
thoughtChars: 0,
|
|
9506
9554
|
toolCalls: stepToolCalls.length,
|
|
9507
|
-
finalStep:
|
|
9555
|
+
finalStep: terminalToolCall !== null
|
|
9508
9556
|
}
|
|
9509
9557
|
});
|
|
9558
|
+
if (terminalToolCall) {
|
|
9559
|
+
finalText = terminalToolCallText(terminalToolCall) || responseText;
|
|
9560
|
+
finalThoughts = "";
|
|
9561
|
+
return { text: finalText, thoughts: finalThoughts, steps, totalCostUsd };
|
|
9562
|
+
}
|
|
9510
9563
|
messages.push({
|
|
9511
9564
|
role: "assistant",
|
|
9512
9565
|
...responseText.length > 0 ? { content: responseText } : {},
|
|
@@ -9850,6 +9903,7 @@ async function runToolLoop(request) {
|
|
|
9850
9903
|
costUsd: stepCostUsd,
|
|
9851
9904
|
timing
|
|
9852
9905
|
});
|
|
9906
|
+
const terminalToolCall = findTerminalToolCall(request.tools, toolCalls);
|
|
9853
9907
|
stepCallLogger?.complete({
|
|
9854
9908
|
responseText,
|
|
9855
9909
|
attachments: responseOutputAttachments,
|
|
@@ -9865,9 +9919,14 @@ async function runToolLoop(request) {
|
|
|
9865
9919
|
responseChars: responseText.length,
|
|
9866
9920
|
thoughtChars: thoughtsText.length,
|
|
9867
9921
|
toolCalls: toolCalls.length,
|
|
9868
|
-
finalStep:
|
|
9922
|
+
finalStep: terminalToolCall !== null
|
|
9869
9923
|
}
|
|
9870
9924
|
});
|
|
9925
|
+
if (terminalToolCall) {
|
|
9926
|
+
finalText = terminalToolCallText(terminalToolCall) || responseText;
|
|
9927
|
+
finalThoughts = thoughtsText;
|
|
9928
|
+
return { text: finalText, thoughts: finalThoughts, steps, totalCostUsd };
|
|
9929
|
+
}
|
|
9871
9930
|
geminiContents.push({ role: "user", parts: responseParts });
|
|
9872
9931
|
const steeringInput = steeringInternal?.drainPendingContents() ?? [];
|
|
9873
9932
|
if (steeringInput.length > 0) {
|