@polka-codes/core 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/_tsup-dts-rollup.d.ts +7 -0
- package/dist/index.js +27 -4
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { FilePart } from 'ai';
|
|
2
2
|
import type { ImagePart } from 'ai';
|
|
3
3
|
import type { JSONValue } from '@ai-sdk/provider';
|
|
4
|
+
import { LanguageModelUsage } from 'ai';
|
|
4
5
|
import type { LanguageModelV2 } from '@ai-sdk/provider';
|
|
5
6
|
import type { LanguageModelV2ToolResultOutput } from '@ai-sdk/provider';
|
|
6
7
|
import type { LanguageModelV2Usage } from '@ai-sdk/provider';
|
|
@@ -321,6 +322,7 @@ declare type CommandProvider = {
|
|
|
321
322
|
stdout: string;
|
|
322
323
|
stderr: string;
|
|
323
324
|
exitCode: number;
|
|
325
|
+
summary?: string;
|
|
324
326
|
}>;
|
|
325
327
|
};
|
|
326
328
|
export { CommandProvider }
|
|
@@ -381,6 +383,7 @@ declare const configSchema: z.ZodObject<{
|
|
|
381
383
|
budget: z.ZodOptional<z.ZodNumber>;
|
|
382
384
|
retryCount: z.ZodOptional<z.ZodNumber>;
|
|
383
385
|
requestTimeoutSeconds: z.ZodOptional<z.ZodNumber>;
|
|
386
|
+
summaryThreshold: z.ZodOptional<z.ZodNumber>;
|
|
384
387
|
scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
385
388
|
command: z.ZodString;
|
|
386
389
|
description: z.ZodString;
|
|
@@ -1036,6 +1039,7 @@ declare class MockProvider implements ToolProvider {
|
|
|
1036
1039
|
stdout: string;
|
|
1037
1040
|
stderr: string;
|
|
1038
1041
|
exitCode: number;
|
|
1042
|
+
summary?: string;
|
|
1039
1043
|
}>;
|
|
1040
1044
|
askFollowupQuestion(_question: string, _options?: string[]): Promise<string>;
|
|
1041
1045
|
attemptCompletion(_result: string): Promise<string | undefined>;
|
|
@@ -1506,6 +1510,7 @@ export { TaskEventToolUse as TaskEventToolUse_alias_2 }
|
|
|
1506
1510
|
*/
|
|
1507
1511
|
declare interface TaskEventUsage extends TaskEventBase {
|
|
1508
1512
|
kind: TaskEventKind.Usage;
|
|
1513
|
+
usage: LanguageModelUsage;
|
|
1509
1514
|
}
|
|
1510
1515
|
export { TaskEventUsage }
|
|
1511
1516
|
export { TaskEventUsage as TaskEventUsage_alias_1 }
|
|
@@ -1931,6 +1936,8 @@ declare class UsageMeter {
|
|
|
1931
1936
|
cost: number;
|
|
1932
1937
|
messageCount: number;
|
|
1933
1938
|
};
|
|
1939
|
+
/** Merge another UsageMeter's totals into this one. */
|
|
1940
|
+
merge(other: UsageMeter): void;
|
|
1934
1941
|
/** Print a concise usage summary to console. */
|
|
1935
1942
|
printUsage(customConsole?: Console): void;
|
|
1936
1943
|
onFinishHandler(llm: LanguageModelV2): (evt: {
|
package/dist/index.js
CHANGED
|
@@ -266,14 +266,23 @@ var handler4 = async (provider, args) => {
|
|
|
266
266
|
try {
|
|
267
267
|
console.log("Executing command:", command2, "Requires approval:", requiresApproval);
|
|
268
268
|
const result = await provider.executeCommand(command2, requiresApproval);
|
|
269
|
-
|
|
269
|
+
let message = `<command>${command2}</command>
|
|
270
270
|
<command_exit_code>${result.exitCode}</command_exit_code>
|
|
271
|
-
|
|
271
|
+
`;
|
|
272
|
+
if (result.summary) {
|
|
273
|
+
message += `<command_output_summary>
|
|
274
|
+
${result.summary}
|
|
275
|
+
</command_output_summary>
|
|
276
|
+
`;
|
|
277
|
+
} else {
|
|
278
|
+
message += `<command_stdout>
|
|
272
279
|
${result.stdout}
|
|
273
280
|
</command_stdout>
|
|
274
281
|
<command_stderr>
|
|
275
282
|
${result.stderr}
|
|
276
|
-
</command_stderr
|
|
283
|
+
</command_stderr>
|
|
284
|
+
`;
|
|
285
|
+
}
|
|
277
286
|
if (result.exitCode === 0) {
|
|
278
287
|
return {
|
|
279
288
|
type: "Reply" /* Reply */,
|
|
@@ -1369,6 +1378,15 @@ var UsageMeter = class {
|
|
|
1369
1378
|
get usage() {
|
|
1370
1379
|
return { ...this.#totals };
|
|
1371
1380
|
}
|
|
1381
|
+
/** Merge another UsageMeter's totals into this one. */
|
|
1382
|
+
merge(other) {
|
|
1383
|
+
const otherUsage = other.usage;
|
|
1384
|
+
this.#totals.input += otherUsage.input;
|
|
1385
|
+
this.#totals.output += otherUsage.output;
|
|
1386
|
+
this.#totals.cachedRead += otherUsage.cachedRead;
|
|
1387
|
+
this.#totals.cost += otherUsage.cost;
|
|
1388
|
+
this.#totals.messageCount += otherUsage.messageCount;
|
|
1389
|
+
}
|
|
1372
1390
|
/** Print a concise usage summary to console. */
|
|
1373
1391
|
printUsage(customConsole = console) {
|
|
1374
1392
|
const u = this.usage;
|
|
@@ -2047,6 +2065,7 @@ Request timeout after ${requestTimeoutSeconds} seconds. Canceling current reques
|
|
|
2047
2065
|
};
|
|
2048
2066
|
try {
|
|
2049
2067
|
resetTimeout();
|
|
2068
|
+
const usageMeterOnFinishHandler = this.config.usageMeter.onFinishHandler(this.ai);
|
|
2050
2069
|
const streamTextOptions = {
|
|
2051
2070
|
model: this.ai,
|
|
2052
2071
|
temperature: 0,
|
|
@@ -2065,7 +2084,10 @@ Request timeout after ${requestTimeoutSeconds} seconds. Canceling current reques
|
|
|
2065
2084
|
break;
|
|
2066
2085
|
}
|
|
2067
2086
|
},
|
|
2068
|
-
onFinish:
|
|
2087
|
+
onFinish: (evt) => {
|
|
2088
|
+
usageMeterOnFinishHandler(evt);
|
|
2089
|
+
this.#callback({ kind: "Usage" /* Usage */, agent: this, usage: evt.totalUsage });
|
|
2090
|
+
},
|
|
2069
2091
|
onError: async (error) => {
|
|
2070
2092
|
console.error("Error in stream:", error);
|
|
2071
2093
|
},
|
|
@@ -3191,6 +3213,7 @@ var configSchema = z16.object({
|
|
|
3191
3213
|
budget: z16.number().positive().optional(),
|
|
3192
3214
|
retryCount: z16.number().int().min(0).optional(),
|
|
3193
3215
|
requestTimeoutSeconds: z16.number().int().positive().optional(),
|
|
3216
|
+
summaryThreshold: z16.number().int().positive().optional(),
|
|
3194
3217
|
scripts: z16.record(
|
|
3195
3218
|
z16.string(),
|
|
3196
3219
|
z16.string().or(
|