llmist 0.1.3 → 0.1.5
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/README.md +67 -12
- package/dist/{chunk-TP7HE3MN.js → chunk-J3NCIWMY.js} +34 -36
- package/dist/chunk-J3NCIWMY.js.map +1 -0
- package/dist/{chunk-JEBGLCDW.js → chunk-MO5ONHPZ.js} +2 -2
- package/dist/{chunk-DCW33WV7.js → chunk-PVHHXDCV.js} +2 -2
- package/dist/cli.cjs +161 -92
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +130 -59
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +368 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +376 -50
- package/dist/index.d.ts +376 -50
- package/dist/index.js +338 -43
- package/dist/index.js.map +1 -1
- package/dist/{mock-stream-D4erlo7B.d.cts → mock-stream-C2sBQlvc.d.cts} +1 -2
- package/dist/{mock-stream-D4erlo7B.d.ts → mock-stream-C2sBQlvc.d.ts} +1 -2
- package/dist/testing/index.cjs +33 -35
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/package.json +2 -2
- package/dist/chunk-TP7HE3MN.js.map +0 -1
- /package/dist/{chunk-JEBGLCDW.js.map → chunk-MO5ONHPZ.js.map} +0 -0
- /package/dist/{chunk-DCW33WV7.js.map → chunk-PVHHXDCV.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseGadget
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-J3NCIWMY.js";
|
|
4
4
|
|
|
5
5
|
// src/gadgets/create-gadget.ts
|
|
6
6
|
function createGadget(config) {
|
|
@@ -19,4 +19,4 @@ function createGadget(config) {
|
|
|
19
19
|
export {
|
|
20
20
|
createGadget
|
|
21
21
|
};
|
|
22
|
-
//# sourceMappingURL=chunk-
|
|
22
|
+
//# sourceMappingURL=chunk-MO5ONHPZ.js.map
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
init_client,
|
|
8
8
|
init_constants,
|
|
9
9
|
init_logger
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-J3NCIWMY.js";
|
|
11
11
|
|
|
12
12
|
// src/gadgets/validation.ts
|
|
13
13
|
function validateAndApplyDefaults(schema, params) {
|
|
@@ -898,4 +898,4 @@ export {
|
|
|
898
898
|
MockGadgetBuilder,
|
|
899
899
|
mockGadget
|
|
900
900
|
};
|
|
901
|
-
//# sourceMappingURL=chunk-
|
|
901
|
+
//# sourceMappingURL=chunk-PVHHXDCV.js.map
|
package/dist/cli.cjs
CHANGED
|
@@ -420,14 +420,15 @@ var init_messages = __esm({
|
|
|
420
420
|
context
|
|
421
421
|
);
|
|
422
422
|
parts.push(mainInstruction);
|
|
423
|
-
parts.push(this.
|
|
423
|
+
parts.push(this.buildGadgetsSection(gadgets, parameterFormat));
|
|
424
424
|
parts.push(this.buildUsageSection(parameterFormat, context));
|
|
425
425
|
this.messages.push({ role: "system", content: parts.join("") });
|
|
426
426
|
return this;
|
|
427
427
|
}
|
|
428
|
-
|
|
428
|
+
buildGadgetsSection(gadgets, parameterFormat) {
|
|
429
429
|
const parts = [];
|
|
430
|
-
parts.push("
|
|
430
|
+
parts.push("\n\nAVAILABLE GADGETS");
|
|
431
|
+
parts.push("\n=================\n");
|
|
431
432
|
for (const gadget of gadgets) {
|
|
432
433
|
const gadgetName = gadget.name ?? gadget.constructor.name;
|
|
433
434
|
const instruction = gadget.getInstruction(parameterFormat);
|
|
@@ -435,18 +436,17 @@ var init_messages = __esm({
|
|
|
435
436
|
const schemaIndex = instruction.indexOf(schemaMarker);
|
|
436
437
|
const description = (schemaIndex !== -1 ? instruction.substring(0, schemaIndex) : instruction).trim();
|
|
437
438
|
const schema = schemaIndex !== -1 ? instruction.substring(schemaIndex + schemaMarker.length).trim() : "";
|
|
438
|
-
parts.push("\n <gadget>");
|
|
439
439
|
parts.push(`
|
|
440
|
-
|
|
440
|
+
GADGET: ${gadgetName}`);
|
|
441
441
|
parts.push(`
|
|
442
|
-
|
|
442
|
+
${description}`);
|
|
443
443
|
if (schema) {
|
|
444
444
|
parts.push(`
|
|
445
|
-
|
|
446
|
-
${
|
|
447
|
-
|
|
445
|
+
|
|
446
|
+
PARAMETERS (${parameterFormat.toUpperCase()}):
|
|
447
|
+
${schema}`);
|
|
448
448
|
}
|
|
449
|
-
parts.push("\n
|
|
449
|
+
parts.push("\n\n---");
|
|
450
450
|
}
|
|
451
451
|
return parts.join("");
|
|
452
452
|
}
|
|
@@ -461,26 +461,26 @@ ${schema}
|
|
|
461
461
|
DEFAULT_PROMPTS.formatDescriptionJson,
|
|
462
462
|
context
|
|
463
463
|
);
|
|
464
|
-
parts.push("
|
|
464
|
+
parts.push("\n\nHOW TO INVOKE GADGETS");
|
|
465
|
+
parts.push("\n=====================\n");
|
|
465
466
|
const criticalUsage = resolvePromptTemplate(
|
|
466
467
|
this.promptConfig.criticalUsage,
|
|
467
468
|
DEFAULT_PROMPTS.criticalUsage,
|
|
468
469
|
context
|
|
469
470
|
);
|
|
470
471
|
parts.push(`
|
|
471
|
-
|
|
472
|
-
|
|
472
|
+
CRITICAL: ${criticalUsage}
|
|
473
|
+
`);
|
|
474
|
+
parts.push("\nFORMAT:");
|
|
473
475
|
parts.push(`
|
|
474
|
-
|
|
476
|
+
1. Start marker: ${this.startPrefix}gadget_name`);
|
|
475
477
|
parts.push(`
|
|
476
|
-
|
|
478
|
+
2. ${formatDescription}`);
|
|
477
479
|
parts.push(`
|
|
478
|
-
|
|
479
|
-
parts.push("\n </format>");
|
|
480
|
+
3. End marker: ${this.endPrefix}`);
|
|
480
481
|
parts.push(this.buildExamplesSection(parameterFormat, context));
|
|
481
482
|
parts.push(this.buildRulesSection(context));
|
|
482
|
-
parts.push("\n
|
|
483
|
-
parts.push("\n</GADGETS>\n\n");
|
|
483
|
+
parts.push("\n");
|
|
484
484
|
return parts.join("");
|
|
485
485
|
}
|
|
486
486
|
buildExamplesSection(parameterFormat, context) {
|
|
@@ -488,7 +488,6 @@ ${schema}
|
|
|
488
488
|
return this.promptConfig.customExamples(context);
|
|
489
489
|
}
|
|
490
490
|
const parts = [];
|
|
491
|
-
parts.push("\n <examples>");
|
|
492
491
|
const singleExample = parameterFormat === "yaml" ? `${this.startPrefix}translate
|
|
493
492
|
from: English
|
|
494
493
|
to: Polish
|
|
@@ -497,9 +496,10 @@ ${this.endPrefix}` : `${this.startPrefix}translate
|
|
|
497
496
|
{"from": "English", "to": "Polish", "content": "Paris is the capital of France."}
|
|
498
497
|
${this.endPrefix}`;
|
|
499
498
|
parts.push(`
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
499
|
+
|
|
500
|
+
EXAMPLE (Single Gadget):
|
|
501
|
+
|
|
502
|
+
${singleExample}`);
|
|
503
503
|
const multipleExample = parameterFormat === "yaml" ? `${this.startPrefix}translate
|
|
504
504
|
from: English
|
|
505
505
|
to: Polish
|
|
@@ -516,21 +516,20 @@ ${this.startPrefix}analyze
|
|
|
516
516
|
{"type": "economic_analysis", "matter": "Polish Economy", "question": "Polish arms exports 2025."}
|
|
517
517
|
${this.endPrefix}`;
|
|
518
518
|
parts.push(`
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
519
|
+
|
|
520
|
+
EXAMPLE (Multiple Gadgets):
|
|
521
|
+
|
|
522
|
+
${multipleExample}`);
|
|
523
523
|
return parts.join("");
|
|
524
524
|
}
|
|
525
525
|
buildRulesSection(context) {
|
|
526
526
|
const parts = [];
|
|
527
|
-
parts.push("\n
|
|
527
|
+
parts.push("\n\nRULES:");
|
|
528
528
|
const rules = resolveRulesTemplate(this.promptConfig.rules, context);
|
|
529
529
|
for (const rule of rules) {
|
|
530
530
|
parts.push(`
|
|
531
|
-
|
|
531
|
+
- ${rule}`);
|
|
532
532
|
}
|
|
533
|
-
parts.push("\n </rules>");
|
|
534
533
|
return parts.join("");
|
|
535
534
|
}
|
|
536
535
|
addUser(content, metadata) {
|
|
@@ -1140,19 +1139,19 @@ var init_executor = __esm({
|
|
|
1140
1139
|
});
|
|
1141
1140
|
|
|
1142
1141
|
// src/gadgets/parser.ts
|
|
1143
|
-
var yaml, StreamParser;
|
|
1142
|
+
var yaml, globalInvocationCounter, StreamParser;
|
|
1144
1143
|
var init_parser = __esm({
|
|
1145
1144
|
"src/gadgets/parser.ts"() {
|
|
1146
1145
|
"use strict";
|
|
1147
1146
|
yaml = __toESM(require("js-yaml"), 1);
|
|
1148
1147
|
init_constants();
|
|
1148
|
+
globalInvocationCounter = 0;
|
|
1149
1149
|
StreamParser = class {
|
|
1150
1150
|
buffer = "";
|
|
1151
1151
|
lastReportedTextLength = 0;
|
|
1152
1152
|
startPrefix;
|
|
1153
1153
|
endPrefix;
|
|
1154
1154
|
parameterFormat;
|
|
1155
|
-
invocationCounter = 0;
|
|
1156
1155
|
constructor(options = {}) {
|
|
1157
1156
|
this.startPrefix = options.startPrefix ?? GADGET_START_PREFIX;
|
|
1158
1157
|
this.endPrefix = options.endPrefix ?? GADGET_END_PREFIX;
|
|
@@ -1219,7 +1218,7 @@ var init_parser = __esm({
|
|
|
1219
1218
|
invocationId = parts[1];
|
|
1220
1219
|
} else {
|
|
1221
1220
|
actualGadgetName = gadgetName;
|
|
1222
|
-
invocationId = `
|
|
1221
|
+
invocationId = `gadget_${++globalInvocationCounter}`;
|
|
1223
1222
|
}
|
|
1224
1223
|
const contentStartIndex = metadataEndIndex + 1;
|
|
1225
1224
|
let partEndIndex;
|
|
@@ -1276,11 +1275,10 @@ var init_parser = __esm({
|
|
|
1276
1275
|
yield { type: "text", content: remainingText };
|
|
1277
1276
|
}
|
|
1278
1277
|
}
|
|
1279
|
-
// Reset parser state
|
|
1278
|
+
// Reset parser state (note: global invocation counter is NOT reset to ensure unique IDs)
|
|
1280
1279
|
reset() {
|
|
1281
1280
|
this.buffer = "";
|
|
1282
1281
|
this.lastReportedTextLength = 0;
|
|
1283
|
-
this.invocationCounter = 0;
|
|
1284
1282
|
}
|
|
1285
1283
|
};
|
|
1286
1284
|
}
|
|
@@ -4255,7 +4253,7 @@ var import_commander3 = require("commander");
|
|
|
4255
4253
|
// package.json
|
|
4256
4254
|
var package_default = {
|
|
4257
4255
|
name: "llmist",
|
|
4258
|
-
version: "0.1.
|
|
4256
|
+
version: "0.1.5",
|
|
4259
4257
|
description: "Universal TypeScript LLM client with streaming-first agent framework. Works with any model - no structured outputs or native tool calling required. Implements its own flexible grammar for function calling.",
|
|
4260
4258
|
type: "module",
|
|
4261
4259
|
main: "dist/index.cjs",
|
|
@@ -4339,7 +4337,7 @@ var package_default = {
|
|
|
4339
4337
|
chalk: "^5.6.2",
|
|
4340
4338
|
commander: "^12.1.0",
|
|
4341
4339
|
"js-yaml": "^4.1.0",
|
|
4342
|
-
openai: "^
|
|
4340
|
+
openai: "^6.0.0",
|
|
4343
4341
|
tiktoken: "^1.0.22",
|
|
4344
4342
|
tslog: "^4.10.2",
|
|
4345
4343
|
zod: "^4.1.12"
|
|
@@ -4358,14 +4356,13 @@ var package_default = {
|
|
|
4358
4356
|
|
|
4359
4357
|
// src/cli/agent-command.ts
|
|
4360
4358
|
var import_promises = require("readline/promises");
|
|
4361
|
-
var
|
|
4359
|
+
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
4362
4360
|
var import_commander2 = require("commander");
|
|
4363
4361
|
init_builder();
|
|
4364
4362
|
init_registry();
|
|
4365
4363
|
init_constants2();
|
|
4366
4364
|
|
|
4367
4365
|
// src/cli/builtin-gadgets.ts
|
|
4368
|
-
var import_chalk = __toESM(require("chalk"), 1);
|
|
4369
4366
|
var import_zod = require("zod");
|
|
4370
4367
|
|
|
4371
4368
|
// src/gadgets/gadget.ts
|
|
@@ -4541,17 +4538,17 @@ var tellUser = createGadget({
|
|
|
4541
4538
|
type: import_zod.z.enum(["info", "success", "warning", "error"]).default("info").describe("Message type: info, success, warning, or error")
|
|
4542
4539
|
}),
|
|
4543
4540
|
execute: ({ message, done, type }) => {
|
|
4544
|
-
const
|
|
4545
|
-
info:
|
|
4546
|
-
success:
|
|
4547
|
-
warning:
|
|
4548
|
-
error:
|
|
4541
|
+
const prefixes = {
|
|
4542
|
+
info: "\u2139\uFE0F ",
|
|
4543
|
+
success: "\u2705 ",
|
|
4544
|
+
warning: "\u26A0\uFE0F ",
|
|
4545
|
+
error: "\u274C "
|
|
4549
4546
|
};
|
|
4550
|
-
const
|
|
4547
|
+
const plainResult = prefixes[type] + message;
|
|
4551
4548
|
if (done) {
|
|
4552
|
-
throw new BreakLoopException(
|
|
4549
|
+
throw new BreakLoopException(plainResult);
|
|
4553
4550
|
}
|
|
4554
|
-
return
|
|
4551
|
+
return plainResult;
|
|
4555
4552
|
}
|
|
4556
4553
|
});
|
|
4557
4554
|
var builtinGadgets = [askUser, tellUser];
|
|
@@ -4653,7 +4650,7 @@ async function loadGadgets(specifiers, cwd, importer = (specifier) => import(spe
|
|
|
4653
4650
|
}
|
|
4654
4651
|
|
|
4655
4652
|
// src/cli/utils.ts
|
|
4656
|
-
var
|
|
4653
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
4657
4654
|
var import_commander = require("commander");
|
|
4658
4655
|
init_constants2();
|
|
4659
4656
|
function createNumericParser({
|
|
@@ -4712,9 +4709,10 @@ function isInteractive(stream2) {
|
|
|
4712
4709
|
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
4713
4710
|
var SPINNER_DELAY_MS = 500;
|
|
4714
4711
|
var StreamProgress = class {
|
|
4715
|
-
constructor(target, isTTY) {
|
|
4712
|
+
constructor(target, isTTY, modelRegistry) {
|
|
4716
4713
|
this.target = target;
|
|
4717
4714
|
this.isTTY = isTTY;
|
|
4715
|
+
this.modelRegistry = modelRegistry;
|
|
4718
4716
|
}
|
|
4719
4717
|
// Animation state
|
|
4720
4718
|
frameIndex = 0;
|
|
@@ -4735,6 +4733,7 @@ var StreamProgress = class {
|
|
|
4735
4733
|
// Cumulative stats (cumulative mode)
|
|
4736
4734
|
totalStartTime = Date.now();
|
|
4737
4735
|
totalTokens = 0;
|
|
4736
|
+
totalCost = 0;
|
|
4738
4737
|
iterations = 0;
|
|
4739
4738
|
/**
|
|
4740
4739
|
* Starts a new LLM call. Switches to streaming mode.
|
|
@@ -4761,6 +4760,20 @@ var StreamProgress = class {
|
|
|
4761
4760
|
this.iterations++;
|
|
4762
4761
|
if (usage) {
|
|
4763
4762
|
this.totalTokens += usage.totalTokens;
|
|
4763
|
+
if (this.modelRegistry && this.model) {
|
|
4764
|
+
try {
|
|
4765
|
+
const modelName = this.model.includes(":") ? this.model.split(":")[1] : this.model;
|
|
4766
|
+
const cost = this.modelRegistry.estimateCost(
|
|
4767
|
+
modelName,
|
|
4768
|
+
usage.inputTokens,
|
|
4769
|
+
usage.outputTokens
|
|
4770
|
+
);
|
|
4771
|
+
if (cost) {
|
|
4772
|
+
this.totalCost += cost.totalCost;
|
|
4773
|
+
}
|
|
4774
|
+
} catch {
|
|
4775
|
+
}
|
|
4776
|
+
}
|
|
4764
4777
|
}
|
|
4765
4778
|
this.pause();
|
|
4766
4779
|
this.mode = "cumulative";
|
|
@@ -4824,33 +4837,39 @@ var StreamProgress = class {
|
|
|
4824
4837
|
const outTokens = this.callOutputTokensEstimated ? Math.round(this.callOutputChars / FALLBACK_CHARS_PER_TOKEN) : this.callOutputTokens;
|
|
4825
4838
|
const parts = [];
|
|
4826
4839
|
if (this.model) {
|
|
4827
|
-
parts.push(
|
|
4840
|
+
parts.push(import_chalk.default.cyan(this.model));
|
|
4828
4841
|
}
|
|
4829
4842
|
if (this.callInputTokens > 0) {
|
|
4830
4843
|
const prefix = this.callInputTokensEstimated ? "~" : "";
|
|
4831
|
-
parts.push(
|
|
4844
|
+
parts.push(import_chalk.default.dim("out:") + import_chalk.default.yellow(` ${prefix}${this.callInputTokens}`));
|
|
4832
4845
|
}
|
|
4833
4846
|
if (this.isStreaming || outTokens > 0) {
|
|
4834
4847
|
const prefix = this.callOutputTokensEstimated ? "~" : "";
|
|
4835
|
-
parts.push(
|
|
4848
|
+
parts.push(import_chalk.default.dim("in:") + import_chalk.default.green(` ${prefix}${outTokens}`));
|
|
4836
4849
|
}
|
|
4837
|
-
|
|
4838
|
-
|
|
4850
|
+
if (this.totalCost > 0) {
|
|
4851
|
+
parts.push(import_chalk.default.dim("cost:") + import_chalk.default.cyan(` $${this.formatCost(this.totalCost)}`));
|
|
4852
|
+
}
|
|
4853
|
+
parts.push(import_chalk.default.dim(`${elapsed}s`));
|
|
4854
|
+
this.target.write(`\r${import_chalk.default.cyan(spinner)} ${parts.join(import_chalk.default.dim(" | "))}`);
|
|
4839
4855
|
}
|
|
4840
4856
|
renderCumulativeMode(spinner) {
|
|
4841
4857
|
const elapsed = ((Date.now() - this.totalStartTime) / 1e3).toFixed(1);
|
|
4842
4858
|
const parts = [];
|
|
4843
4859
|
if (this.model) {
|
|
4844
|
-
parts.push(
|
|
4860
|
+
parts.push(import_chalk.default.cyan(this.model));
|
|
4845
4861
|
}
|
|
4846
4862
|
if (this.totalTokens > 0) {
|
|
4847
|
-
parts.push(
|
|
4863
|
+
parts.push(import_chalk.default.dim("total:") + import_chalk.default.magenta(` ${this.totalTokens}`));
|
|
4848
4864
|
}
|
|
4849
4865
|
if (this.iterations > 0) {
|
|
4850
|
-
parts.push(
|
|
4866
|
+
parts.push(import_chalk.default.dim("iter:") + import_chalk.default.blue(` ${this.iterations}`));
|
|
4867
|
+
}
|
|
4868
|
+
if (this.totalCost > 0) {
|
|
4869
|
+
parts.push(import_chalk.default.dim("cost:") + import_chalk.default.cyan(` $${this.formatCost(this.totalCost)}`));
|
|
4851
4870
|
}
|
|
4852
|
-
parts.push(
|
|
4853
|
-
this.target.write(`\r${
|
|
4871
|
+
parts.push(import_chalk.default.dim(`${elapsed}s`));
|
|
4872
|
+
this.target.write(`\r${import_chalk.default.cyan(spinner)} ${parts.join(import_chalk.default.dim(" | "))}`);
|
|
4854
4873
|
}
|
|
4855
4874
|
/**
|
|
4856
4875
|
* Pauses the progress indicator and clears the line.
|
|
@@ -4878,6 +4897,12 @@ var StreamProgress = class {
|
|
|
4878
4897
|
complete() {
|
|
4879
4898
|
this.pause();
|
|
4880
4899
|
}
|
|
4900
|
+
/**
|
|
4901
|
+
* Returns the total accumulated cost across all calls.
|
|
4902
|
+
*/
|
|
4903
|
+
getTotalCost() {
|
|
4904
|
+
return this.totalCost;
|
|
4905
|
+
}
|
|
4881
4906
|
/**
|
|
4882
4907
|
* Returns a formatted prompt string with stats (like bash PS1).
|
|
4883
4908
|
* Shows current call stats during streaming, cumulative stats otherwise.
|
|
@@ -4892,25 +4917,28 @@ var StreamProgress = class {
|
|
|
4892
4917
|
if (this.callInputTokens > 0) {
|
|
4893
4918
|
const prefix = this.callInputTokensEstimated ? "~" : "";
|
|
4894
4919
|
parts.push(
|
|
4895
|
-
|
|
4920
|
+
import_chalk.default.dim("out:") + import_chalk.default.yellow(` ${prefix}${this.formatTokens(this.callInputTokens)}`)
|
|
4896
4921
|
);
|
|
4897
4922
|
}
|
|
4898
4923
|
if (outTokens > 0) {
|
|
4899
4924
|
const prefix = outEstimated ? "~" : "";
|
|
4900
|
-
parts.push(
|
|
4925
|
+
parts.push(import_chalk.default.dim("in:") + import_chalk.default.green(` ${prefix}${this.formatTokens(outTokens)}`));
|
|
4901
4926
|
}
|
|
4902
|
-
parts.push(
|
|
4927
|
+
parts.push(import_chalk.default.dim(`${elapsed}s`));
|
|
4903
4928
|
} else {
|
|
4904
4929
|
const elapsed = Math.round((Date.now() - this.totalStartTime) / 1e3);
|
|
4905
4930
|
if (this.totalTokens > 0) {
|
|
4906
|
-
parts.push(
|
|
4931
|
+
parts.push(import_chalk.default.magenta(this.formatTokens(this.totalTokens)));
|
|
4907
4932
|
}
|
|
4908
4933
|
if (this.iterations > 0) {
|
|
4909
|
-
parts.push(
|
|
4934
|
+
parts.push(import_chalk.default.blue(`i${this.iterations}`));
|
|
4910
4935
|
}
|
|
4911
|
-
|
|
4936
|
+
if (this.totalCost > 0) {
|
|
4937
|
+
parts.push(import_chalk.default.cyan(`$${this.formatCost(this.totalCost)}`));
|
|
4938
|
+
}
|
|
4939
|
+
parts.push(import_chalk.default.dim(`${elapsed}s`));
|
|
4912
4940
|
}
|
|
4913
|
-
return `${parts.join(
|
|
4941
|
+
return `${parts.join(import_chalk.default.dim(" \u2502 "))} ${import_chalk.default.green(">")} `;
|
|
4914
4942
|
}
|
|
4915
4943
|
/**
|
|
4916
4944
|
* Formats token count compactly (3625 -> "3.6k").
|
|
@@ -4918,6 +4946,21 @@ var StreamProgress = class {
|
|
|
4918
4946
|
formatTokens(tokens) {
|
|
4919
4947
|
return tokens >= 1e3 ? `${(tokens / 1e3).toFixed(1)}k` : `${tokens}`;
|
|
4920
4948
|
}
|
|
4949
|
+
/**
|
|
4950
|
+
* Formats cost compactly (0.0001234 -> "0.00012", 0.1234 -> "0.12", 1.234 -> "1.23").
|
|
4951
|
+
*/
|
|
4952
|
+
formatCost(cost) {
|
|
4953
|
+
if (cost < 1e-3) {
|
|
4954
|
+
return cost.toFixed(5);
|
|
4955
|
+
}
|
|
4956
|
+
if (cost < 0.01) {
|
|
4957
|
+
return cost.toFixed(4);
|
|
4958
|
+
}
|
|
4959
|
+
if (cost < 1) {
|
|
4960
|
+
return cost.toFixed(3);
|
|
4961
|
+
}
|
|
4962
|
+
return cost.toFixed(2);
|
|
4963
|
+
}
|
|
4921
4964
|
};
|
|
4922
4965
|
async function readStream(stream2) {
|
|
4923
4966
|
const chunks = [];
|
|
@@ -4949,29 +4992,42 @@ async function resolvePrompt(promptArg, env) {
|
|
|
4949
4992
|
function renderSummary(metadata) {
|
|
4950
4993
|
const parts = [];
|
|
4951
4994
|
if (metadata.iterations !== void 0) {
|
|
4952
|
-
parts.push(
|
|
4995
|
+
parts.push(import_chalk.default.dim(`iterations: ${metadata.iterations}`));
|
|
4953
4996
|
}
|
|
4954
4997
|
if (metadata.finishReason) {
|
|
4955
|
-
parts.push(
|
|
4998
|
+
parts.push(import_chalk.default.dim(`finish: ${metadata.finishReason}`));
|
|
4956
4999
|
}
|
|
4957
5000
|
if (metadata.usage) {
|
|
4958
5001
|
const { inputTokens, outputTokens, totalTokens } = metadata.usage;
|
|
4959
5002
|
parts.push(
|
|
4960
|
-
|
|
5003
|
+
import_chalk.default.dim(`tokens: `) + import_chalk.default.cyan(`${totalTokens}`) + import_chalk.default.dim(` (in: ${inputTokens}, out: ${outputTokens})`)
|
|
4961
5004
|
);
|
|
4962
5005
|
}
|
|
5006
|
+
if (metadata.cost !== void 0 && metadata.cost > 0) {
|
|
5007
|
+
let formattedCost;
|
|
5008
|
+
if (metadata.cost < 1e-3) {
|
|
5009
|
+
formattedCost = metadata.cost.toFixed(5);
|
|
5010
|
+
} else if (metadata.cost < 0.01) {
|
|
5011
|
+
formattedCost = metadata.cost.toFixed(4);
|
|
5012
|
+
} else if (metadata.cost < 1) {
|
|
5013
|
+
formattedCost = metadata.cost.toFixed(3);
|
|
5014
|
+
} else {
|
|
5015
|
+
formattedCost = metadata.cost.toFixed(2);
|
|
5016
|
+
}
|
|
5017
|
+
parts.push(import_chalk.default.dim(`cost: `) + import_chalk.default.cyan(`$${formattedCost}`));
|
|
5018
|
+
}
|
|
4963
5019
|
if (parts.length === 0) {
|
|
4964
5020
|
return null;
|
|
4965
5021
|
}
|
|
4966
|
-
return `${
|
|
4967
|
-
${parts.join(
|
|
5022
|
+
return `${import_chalk.default.dim("\u2500".repeat(40))}
|
|
5023
|
+
${parts.join(import_chalk.default.dim(" \u2502 "))}`;
|
|
4968
5024
|
}
|
|
4969
5025
|
async function executeAction(action, env) {
|
|
4970
5026
|
try {
|
|
4971
5027
|
await action();
|
|
4972
5028
|
} catch (error) {
|
|
4973
5029
|
const message = error instanceof Error ? error.message : String(error);
|
|
4974
|
-
env.stderr.write(`${
|
|
5030
|
+
env.stderr.write(`${import_chalk.default.red.bold("Error:")} ${message}
|
|
4975
5031
|
`);
|
|
4976
5032
|
env.setExitCode(1);
|
|
4977
5033
|
}
|
|
@@ -5015,17 +5071,18 @@ ${statsPrompt}` : statsPrompt;
|
|
|
5015
5071
|
};
|
|
5016
5072
|
}
|
|
5017
5073
|
function formatGadgetSummary(result) {
|
|
5018
|
-
const gadgetLabel =
|
|
5019
|
-
const timeLabel =
|
|
5074
|
+
const gadgetLabel = import_chalk2.default.magenta.bold(result.gadgetName);
|
|
5075
|
+
const timeLabel = import_chalk2.default.dim(`${Math.round(result.executionTimeMs)}ms`);
|
|
5020
5076
|
if (result.error) {
|
|
5021
|
-
return `${
|
|
5077
|
+
return `${import_chalk2.default.red("\u2717")} ${gadgetLabel} ${import_chalk2.default.red("error:")} ${result.error} ${timeLabel}`;
|
|
5022
5078
|
}
|
|
5023
5079
|
if (result.breaksLoop) {
|
|
5024
|
-
return `${
|
|
5080
|
+
return `${import_chalk2.default.yellow("\u23F9")} ${gadgetLabel} ${import_chalk2.default.yellow("finished:")} ${result.result} ${timeLabel}`;
|
|
5025
5081
|
}
|
|
5026
5082
|
const maxLen = 80;
|
|
5027
|
-
const
|
|
5028
|
-
|
|
5083
|
+
const shouldTruncate = result.gadgetName !== "TellUser";
|
|
5084
|
+
const resultText = result.result ? shouldTruncate && result.result.length > maxLen ? `${result.result.slice(0, maxLen)}...` : result.result : "";
|
|
5085
|
+
return `${import_chalk2.default.green("\u2713")} ${gadgetLabel} ${import_chalk2.default.dim("\u2192")} ${resultText} ${timeLabel}`;
|
|
5029
5086
|
}
|
|
5030
5087
|
async function handleAgentCommand(promptArg, options, env) {
|
|
5031
5088
|
const prompt = await resolvePrompt(promptArg, env);
|
|
@@ -5045,7 +5102,7 @@ async function handleAgentCommand(promptArg, options, env) {
|
|
|
5045
5102
|
}
|
|
5046
5103
|
const printer = new StreamPrinter(env.stdout);
|
|
5047
5104
|
const stderrTTY = env.stderr.isTTY === true;
|
|
5048
|
-
const progress = new StreamProgress(env.stderr, stderrTTY);
|
|
5105
|
+
const progress = new StreamProgress(env.stderr, stderrTTY, client.modelRegistry);
|
|
5049
5106
|
let finishReason;
|
|
5050
5107
|
let usage;
|
|
5051
5108
|
let iterations = 0;
|
|
@@ -5102,16 +5159,25 @@ async function handleAgentCommand(promptArg, options, env) {
|
|
|
5102
5159
|
printer.write(event.content);
|
|
5103
5160
|
} else if (event.type === "gadget_result") {
|
|
5104
5161
|
progress.pause();
|
|
5105
|
-
|
|
5162
|
+
if (stderrTTY) {
|
|
5163
|
+
env.stderr.write(`${formatGadgetSummary(event.result)}
|
|
5106
5164
|
`);
|
|
5165
|
+
}
|
|
5107
5166
|
}
|
|
5108
5167
|
}
|
|
5109
5168
|
progress.complete();
|
|
5110
5169
|
printer.ensureNewline();
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5170
|
+
if (stderrTTY) {
|
|
5171
|
+
const summary = renderSummary({
|
|
5172
|
+
finishReason,
|
|
5173
|
+
usage,
|
|
5174
|
+
iterations,
|
|
5175
|
+
cost: progress.getTotalCost()
|
|
5176
|
+
});
|
|
5177
|
+
if (summary) {
|
|
5178
|
+
env.stderr.write(`${summary}
|
|
5114
5179
|
`);
|
|
5180
|
+
}
|
|
5115
5181
|
}
|
|
5116
5182
|
}
|
|
5117
5183
|
function registerAgentCommand(program, env) {
|
|
@@ -5157,7 +5223,7 @@ async function handleCompleteCommand(promptArg, options, env) {
|
|
|
5157
5223
|
});
|
|
5158
5224
|
const printer = new StreamPrinter(env.stdout);
|
|
5159
5225
|
const stderrTTY = env.stderr.isTTY === true;
|
|
5160
|
-
const progress = new StreamProgress(env.stderr, stderrTTY);
|
|
5226
|
+
const progress = new StreamProgress(env.stderr, stderrTTY, client.modelRegistry);
|
|
5161
5227
|
const estimatedInputTokens = Math.round(prompt.length / FALLBACK_CHARS_PER_TOKEN);
|
|
5162
5228
|
progress.startCall(options.model, estimatedInputTokens);
|
|
5163
5229
|
let finishReason;
|
|
@@ -5183,12 +5249,15 @@ async function handleCompleteCommand(promptArg, options, env) {
|
|
|
5183
5249
|
finishReason = chunk.finishReason;
|
|
5184
5250
|
}
|
|
5185
5251
|
}
|
|
5252
|
+
progress.endCall(usage);
|
|
5186
5253
|
progress.complete();
|
|
5187
5254
|
printer.ensureNewline();
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5255
|
+
if (stderrTTY) {
|
|
5256
|
+
const summary = renderSummary({ finishReason, usage, cost: progress.getTotalCost() });
|
|
5257
|
+
if (summary) {
|
|
5258
|
+
env.stderr.write(`${summary}
|
|
5191
5259
|
`);
|
|
5260
|
+
}
|
|
5192
5261
|
}
|
|
5193
5262
|
}
|
|
5194
5263
|
function registerCompleteCommand(program, env) {
|
|
@@ -5210,7 +5279,7 @@ function registerCompleteCommand(program, env) {
|
|
|
5210
5279
|
|
|
5211
5280
|
// src/cli/environment.ts
|
|
5212
5281
|
var import_node_readline = __toESM(require("readline"), 1);
|
|
5213
|
-
var
|
|
5282
|
+
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
5214
5283
|
init_client();
|
|
5215
5284
|
init_logger();
|
|
5216
5285
|
var LOG_LEVEL_MAP = {
|
|
@@ -5256,14 +5325,14 @@ function createPromptFunction(stdin, stdout) {
|
|
|
5256
5325
|
output: stdout
|
|
5257
5326
|
});
|
|
5258
5327
|
stdout.write("\n");
|
|
5259
|
-
stdout.write(`${
|
|
5328
|
+
stdout.write(`${import_chalk3.default.cyan("\u2500".repeat(60))}
|
|
5260
5329
|
`);
|
|
5261
|
-
stdout.write(
|
|
5330
|
+
stdout.write(import_chalk3.default.cyan.bold("\u{1F916} Agent asks:\n"));
|
|
5262
5331
|
stdout.write(`${question}
|
|
5263
5332
|
`);
|
|
5264
|
-
stdout.write(`${
|
|
5333
|
+
stdout.write(`${import_chalk3.default.cyan("\u2500".repeat(60))}
|
|
5265
5334
|
`);
|
|
5266
|
-
rl.question(
|
|
5335
|
+
rl.question(import_chalk3.default.green.bold("You: "), (answer) => {
|
|
5267
5336
|
rl.close();
|
|
5268
5337
|
resolve(answer);
|
|
5269
5338
|
});
|