@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.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) {
|
|
@@ -10340,9 +10399,11 @@ var subagentInputItemSchema = z4.object({
|
|
|
10340
10399
|
}).passthrough();
|
|
10341
10400
|
var spawnAgentInputSchema = z4.object({
|
|
10342
10401
|
prompt: z4.string().nullish().describe("Alias for message. Initial plain-text task for the new agent."),
|
|
10343
|
-
message: z4.string().nullish().describe(
|
|
10402
|
+
message: z4.string().nullish().describe(
|
|
10403
|
+
"Initial plain-text task for the new agent. Combined with items when both are provided."
|
|
10404
|
+
),
|
|
10344
10405
|
items: z4.array(subagentInputItemSchema).nullish().describe(
|
|
10345
|
-
"Structured input items. Use this to pass explicit mentions (for example app:// connector paths)."
|
|
10406
|
+
"Structured input items. Use this to pass explicit mentions (for example app:// connector paths). Combined with message/input when both are provided."
|
|
10346
10407
|
),
|
|
10347
10408
|
agent_type: z4.string().nullish().describe(SPAWN_AGENT_TYPE_DESCRIPTION),
|
|
10348
10409
|
fork_context: z4.boolean().nullish().describe(
|
|
@@ -10501,7 +10562,6 @@ function createSubagentToolController(options) {
|
|
|
10501
10562
|
const initialPrompt = resolveCollabInputText({
|
|
10502
10563
|
textCandidates: [{ value: input.prompt }, { value: input.message }],
|
|
10503
10564
|
items: input.items,
|
|
10504
|
-
bothError: "Provide either prompt/message or items, but not both.",
|
|
10505
10565
|
missingError: "Provide one of: prompt/message or items.",
|
|
10506
10566
|
emptyTextError: "Empty message can't be sent to an agent.",
|
|
10507
10567
|
emptyItemsError: "Items can't be empty."
|
|
@@ -10554,7 +10614,6 @@ function createSubagentToolController(options) {
|
|
|
10554
10614
|
const nextInput = resolveCollabInputText({
|
|
10555
10615
|
textCandidates: [{ value: input.input }, { value: input.message }],
|
|
10556
10616
|
items: input.items,
|
|
10557
|
-
bothError: "Provide either input/message or items, but not both.",
|
|
10558
10617
|
missingError: "Provide one of: input/message or items.",
|
|
10559
10618
|
emptyTextError: "Empty message can't be sent to an agent.",
|
|
10560
10619
|
emptyItemsError: "Items can't be empty."
|
|
@@ -10708,18 +10767,19 @@ function resolveCollabInputText(params) {
|
|
|
10708
10767
|
);
|
|
10709
10768
|
const hasText = Boolean(textCandidate);
|
|
10710
10769
|
const hasItems = params.items !== void 0 && params.items !== null;
|
|
10711
|
-
if (hasText && hasItems) {
|
|
10712
|
-
throw new Error(params.bothError);
|
|
10713
|
-
}
|
|
10714
10770
|
if (!hasText && !hasItems) {
|
|
10715
10771
|
throw new Error(params.missingError);
|
|
10716
10772
|
}
|
|
10773
|
+
const blocks = [];
|
|
10717
10774
|
if (hasText) {
|
|
10718
10775
|
const value = textCandidate?.value?.trim();
|
|
10719
10776
|
if (!value) {
|
|
10720
10777
|
throw new Error(params.emptyTextError);
|
|
10721
10778
|
}
|
|
10722
|
-
|
|
10779
|
+
blocks.push(value);
|
|
10780
|
+
}
|
|
10781
|
+
if (!hasItems) {
|
|
10782
|
+
return blocks.join("\n\n");
|
|
10723
10783
|
}
|
|
10724
10784
|
if (!params.items || params.items.length === 0) {
|
|
10725
10785
|
throw new Error(params.emptyItemsError);
|
|
@@ -10728,7 +10788,8 @@ function resolveCollabInputText(params) {
|
|
|
10728
10788
|
if (!itemText) {
|
|
10729
10789
|
throw new Error(params.emptyItemsError);
|
|
10730
10790
|
}
|
|
10731
|
-
|
|
10791
|
+
blocks.push(itemText);
|
|
10792
|
+
return blocks.join("\n\n");
|
|
10732
10793
|
}
|
|
10733
10794
|
function resolveInputItemsText(items) {
|
|
10734
10795
|
if (!items || items.length === 0) {
|