@polka-codes/cli-shared 0.9.35 → 0.9.37
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 +44 -5
- 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 */,
|
|
@@ -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)}`);
|
|
@@ -50143,6 +50160,7 @@ Request timeout after ${requestTimeoutSeconds} seconds. Canceling current reques
|
|
|
50143
50160
|
};
|
|
50144
50161
|
try {
|
|
50145
50162
|
resetTimeout();
|
|
50163
|
+
const usageMeterOnFinishHandler = this.config.usageMeter.onFinishHandler(this.ai);
|
|
50146
50164
|
const streamTextOptions = {
|
|
50147
50165
|
model: this.ai,
|
|
50148
50166
|
temperature: 0,
|
|
@@ -50161,7 +50179,10 @@ Request timeout after ${requestTimeoutSeconds} seconds. Canceling current reques
|
|
|
50161
50179
|
break;
|
|
50162
50180
|
}
|
|
50163
50181
|
},
|
|
50164
|
-
onFinish:
|
|
50182
|
+
onFinish: (evt) => {
|
|
50183
|
+
usageMeterOnFinishHandler(evt);
|
|
50184
|
+
this.#callback({ kind: "Usage" /* Usage */, agent: this, usage: evt.totalUsage });
|
|
50185
|
+
},
|
|
50165
50186
|
onError: async (error43) => {
|
|
50166
50187
|
console.error("Error in stream:", error43);
|
|
50167
50188
|
},
|
|
@@ -51043,6 +51064,7 @@ var configSchema = exports_external.object({
|
|
|
51043
51064
|
budget: exports_external.number().positive().optional(),
|
|
51044
51065
|
retryCount: exports_external.number().int().min(0).optional(),
|
|
51045
51066
|
requestTimeoutSeconds: exports_external.number().int().positive().optional(),
|
|
51067
|
+
summaryThreshold: exports_external.number().int().positive().optional(),
|
|
51046
51068
|
scripts: exports_external.record(exports_external.string(), exports_external.string().or(exports_external.object({
|
|
51047
51069
|
command: exports_external.string(),
|
|
51048
51070
|
description: exports_external.string()
|
|
@@ -56850,8 +56872,25 @@ var getProvider = (options = {}) => {
|
|
|
56850
56872
|
options.command?.onStderr(dataStr);
|
|
56851
56873
|
stderrText += dataStr;
|
|
56852
56874
|
});
|
|
56853
|
-
child.on("close", (code) => {
|
|
56875
|
+
child.on("close", async (code) => {
|
|
56854
56876
|
options.command?.onExit(code ?? 0);
|
|
56877
|
+
const totalLength = stdoutText.length + stderrText.length;
|
|
56878
|
+
if (totalLength > (options.summaryThreshold ?? 5000) && options.summarizeOutput) {
|
|
56879
|
+
try {
|
|
56880
|
+
const summary = await options.summarizeOutput(stdoutText, stderrText);
|
|
56881
|
+
if (summary) {
|
|
56882
|
+
resolve4({
|
|
56883
|
+
summary,
|
|
56884
|
+
stdout: stdoutText,
|
|
56885
|
+
stderr: stderrText,
|
|
56886
|
+
exitCode: code ?? 0
|
|
56887
|
+
});
|
|
56888
|
+
return;
|
|
56889
|
+
}
|
|
56890
|
+
} catch (_e) {
|
|
56891
|
+
console.error("Summarization failed:", _e);
|
|
56892
|
+
}
|
|
56893
|
+
}
|
|
56855
56894
|
resolve4({
|
|
56856
56895
|
stdout: stdoutText,
|
|
56857
56896
|
stderr: stderrText,
|