@polka-codes/cli-shared 0.9.34 → 0.9.36
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.js +43 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37261,14 +37261,23 @@ var handler4 = async (provider, args) => {
|
|
|
37261
37261
|
try {
|
|
37262
37262
|
console.log("Executing command:", command, "Requires approval:", requiresApproval);
|
|
37263
37263
|
const result = await provider.executeCommand(command, requiresApproval);
|
|
37264
|
-
|
|
37264
|
+
let message = `<command>${command}</command>
|
|
37265
37265
|
<command_exit_code>${result.exitCode}</command_exit_code>
|
|
37266
|
-
|
|
37266
|
+
`;
|
|
37267
|
+
if (result.summary) {
|
|
37268
|
+
message += `<command_output_summary>
|
|
37269
|
+
${result.summary}
|
|
37270
|
+
</command_output_summary>
|
|
37271
|
+
`;
|
|
37272
|
+
} else {
|
|
37273
|
+
message += `<command_stdout>
|
|
37267
37274
|
${result.stdout}
|
|
37268
37275
|
</command_stdout>
|
|
37269
37276
|
<command_stderr>
|
|
37270
37277
|
${result.stderr}
|
|
37271
|
-
</command_stderr
|
|
37278
|
+
</command_stderr>
|
|
37279
|
+
`;
|
|
37280
|
+
}
|
|
37272
37281
|
if (result.exitCode === 0) {
|
|
37273
37282
|
return {
|
|
37274
37283
|
type: "Reply" /* Reply */,
|
|
@@ -38267,10 +38276,10 @@ class UsageMeter {
|
|
|
38267
38276
|
};
|
|
38268
38277
|
const usage = "totalUsage" in resp ? resp.totalUsage : resp.usage;
|
|
38269
38278
|
const result = this.#calculageUsage(usage, resp.providerMetadata, modelInfo);
|
|
38270
|
-
this.#totals.input += result.input;
|
|
38271
|
-
this.#totals.output += result.output;
|
|
38272
|
-
this.#totals.cachedRead += result.cachedRead;
|
|
38273
|
-
this.#totals.cost += result.cost;
|
|
38279
|
+
this.#totals.input += result.input || 0;
|
|
38280
|
+
this.#totals.output += result.output || 0;
|
|
38281
|
+
this.#totals.cachedRead += result.cachedRead || 0;
|
|
38282
|
+
this.#totals.cost += result.cost || 0;
|
|
38274
38283
|
this.#totals.messageCount += 1;
|
|
38275
38284
|
}
|
|
38276
38285
|
setUsage(newUsage) {
|
|
@@ -38311,6 +38320,14 @@ class UsageMeter {
|
|
|
38311
38320
|
get usage() {
|
|
38312
38321
|
return { ...this.#totals };
|
|
38313
38322
|
}
|
|
38323
|
+
merge(other) {
|
|
38324
|
+
const otherUsage = other.usage;
|
|
38325
|
+
this.#totals.input += otherUsage.input;
|
|
38326
|
+
this.#totals.output += otherUsage.output;
|
|
38327
|
+
this.#totals.cachedRead += otherUsage.cachedRead;
|
|
38328
|
+
this.#totals.cost += otherUsage.cost;
|
|
38329
|
+
this.#totals.messageCount += otherUsage.messageCount;
|
|
38330
|
+
}
|
|
38314
38331
|
printUsage(customConsole = console) {
|
|
38315
38332
|
const u = this.usage;
|
|
38316
38333
|
customConsole.log(`Usage - messages: ${u.messageCount}, input: ${u.input}, cached: ${u.cachedRead}, ` + `output: ${u.output}, cost: $${u.cost.toFixed(4)}`);
|
|
@@ -51043,6 +51060,7 @@ var configSchema = exports_external.object({
|
|
|
51043
51060
|
budget: exports_external.number().positive().optional(),
|
|
51044
51061
|
retryCount: exports_external.number().int().min(0).optional(),
|
|
51045
51062
|
requestTimeoutSeconds: exports_external.number().int().positive().optional(),
|
|
51063
|
+
summaryThreshold: exports_external.number().int().positive().optional(),
|
|
51046
51064
|
scripts: exports_external.record(exports_external.string(), exports_external.string().or(exports_external.object({
|
|
51047
51065
|
command: exports_external.string(),
|
|
51048
51066
|
description: exports_external.string()
|
|
@@ -56850,8 +56868,25 @@ var getProvider = (options = {}) => {
|
|
|
56850
56868
|
options.command?.onStderr(dataStr);
|
|
56851
56869
|
stderrText += dataStr;
|
|
56852
56870
|
});
|
|
56853
|
-
child.on("close", (code) => {
|
|
56871
|
+
child.on("close", async (code) => {
|
|
56854
56872
|
options.command?.onExit(code ?? 0);
|
|
56873
|
+
const totalLength = stdoutText.length + stderrText.length;
|
|
56874
|
+
if (totalLength > (options.summaryThreshold ?? 5000) && options.summarizeOutput) {
|
|
56875
|
+
try {
|
|
56876
|
+
const summary = await options.summarizeOutput(stdoutText, stderrText);
|
|
56877
|
+
if (summary) {
|
|
56878
|
+
resolve4({
|
|
56879
|
+
summary,
|
|
56880
|
+
stdout: stdoutText,
|
|
56881
|
+
stderr: stderrText,
|
|
56882
|
+
exitCode: code ?? 0
|
|
56883
|
+
});
|
|
56884
|
+
return;
|
|
56885
|
+
}
|
|
56886
|
+
} catch (_e) {
|
|
56887
|
+
console.error("Summarization failed:", _e);
|
|
56888
|
+
}
|
|
56889
|
+
}
|
|
56855
56890
|
resolve4({
|
|
56856
56891
|
stdout: stdoutText,
|
|
56857
56892
|
stderr: stderrText,
|