@livx.cc/agentx 0.99.74 → 0.99.75
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/{Agent-Bs2ufrIU.d.ts → Agent-BBlKI8uD.d.ts} +7 -0
- package/dist/cli.d.ts +6 -1
- package/dist/cli.js +13 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -308,6 +308,13 @@ interface RunResult {
|
|
|
308
308
|
cacheCreationTokens?: number;
|
|
309
309
|
cacheReadTokens?: number;
|
|
310
310
|
};
|
|
311
|
+
/** Present iff `finishReason === 'budget'`: the weighted spend vs `maxTokens`, and the last step's prompt
|
|
312
|
+
* size — a prompt near the limit means the CONVERSATION is too big for one run (compact / new chat). */
|
|
313
|
+
budget?: {
|
|
314
|
+
spent: number;
|
|
315
|
+
limit: number;
|
|
316
|
+
stepPrompt: number;
|
|
317
|
+
};
|
|
311
318
|
/** True if ANY turn's usage was estimated (provider gave none) rather than exact — lets the UI mark cost `~`. */
|
|
312
319
|
usageEstimated?: boolean;
|
|
313
320
|
/** Set by a router (`--model auto`) whose turn spans several models: the turn's USD at each model's own rate. */
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { m as RouterState, H as Hooks, n as RunResult, R as ReasoningEffort, A as Agent } from './Agent-
|
|
2
|
+
import { m as RouterState, H as Hooks, n as RunResult, R as ReasoningEffort, A as Agent } from './Agent-BBlKI8uD.js';
|
|
3
3
|
import { IFilesystem } from '@livx.cc/wcli/core';
|
|
4
4
|
import { M as Message, U as UserQuestion, H as HostBridge, c as ContentPart, o as MessageContent } from './tools-lC3jn60o.js';
|
|
5
5
|
|
|
@@ -297,6 +297,11 @@ declare function jsonResult(res: RunResult, session: SessionData): {
|
|
|
297
297
|
sessionId: string;
|
|
298
298
|
costUsd?: number | undefined;
|
|
299
299
|
routing?: Record<string, unknown> | undefined;
|
|
300
|
+
budget?: {
|
|
301
|
+
spent: number;
|
|
302
|
+
limit: number;
|
|
303
|
+
stepPrompt: number;
|
|
304
|
+
} | undefined;
|
|
300
305
|
text: string;
|
|
301
306
|
steps: number;
|
|
302
307
|
tools: number;
|
package/dist/cli.js
CHANGED
|
@@ -4876,6 +4876,7 @@ var Agent = class _Agent {
|
|
|
4876
4876
|
let steps = 0;
|
|
4877
4877
|
const usage = { promptTokens: 0, completionTokens: 0, totalTokens: 0, cacheCreationTokens: 0, cacheReadTokens: 0 };
|
|
4878
4878
|
let usageEstimated = false;
|
|
4879
|
+
let spent = 0, prevPrompt = -1, stepPrompt = 0;
|
|
4879
4880
|
const start = Date.now();
|
|
4880
4881
|
this.parkedMs = 0;
|
|
4881
4882
|
this.ctx.needsInput = void 0;
|
|
@@ -4886,12 +4887,12 @@ var Agent = class _Agent {
|
|
|
4886
4887
|
let closureNudged = false;
|
|
4887
4888
|
let lastProgressAt = start;
|
|
4888
4889
|
const kill = (finishReason) => {
|
|
4889
|
-
log8.warn(`kill-switch: ${finishReason} (steps=${steps}, tokens=${usage.totalTokens}, budgetTokens=${Math.round(
|
|
4890
|
+
log8.warn(`kill-switch: ${finishReason} (steps=${steps}, tokens=${usage.totalTokens}, budgetTokens=${Math.round(spent)}, ms=${Date.now() - start - this.parkedMs}${finishReason === "timeout" ? `, idle=${Date.now() - lastProgressAt - this.parkedMs}ms` : ""}${this.parkedMs ? ` +${this.parkedMs} parked` : ""})`);
|
|
4890
4891
|
this.jobs.killAll(`run ended: ${finishReason}`, true);
|
|
4891
4892
|
const claims = this.survivingClaims();
|
|
4892
|
-
return { text: lastAssistantText(this.transcript), steps, finishReason, messages: this.transcript, usage, usageEstimated, ...claims.length ? { fabricatedToolClaims: claims } : {} };
|
|
4893
|
+
return { text: lastAssistantText(this.transcript), steps, finishReason, messages: this.transcript, usage, usageEstimated, ...finishReason === "budget" ? { budget: { spent: Math.round(spent), limit: o.maxTokens, stepPrompt } } : {}, ...claims.length ? { fabricatedToolClaims: claims } : {} };
|
|
4893
4894
|
};
|
|
4894
|
-
const overBudget = () => !!o.maxTokens &&
|
|
4895
|
+
const overBudget = () => !!o.maxTokens && spent >= o.maxTokens;
|
|
4895
4896
|
const canNudge = () => steps < o.maxSteps && !overBudget();
|
|
4896
4897
|
while (true) {
|
|
4897
4898
|
if (o.signal?.aborted) return kill("aborted");
|
|
@@ -5045,6 +5046,14 @@ var Agent = class _Agent {
|
|
|
5045
5046
|
usage.totalTokens += res.usage.totalTokens ?? 0;
|
|
5046
5047
|
usage.cacheCreationTokens += res.usage.cacheCreationTokens ?? 0;
|
|
5047
5048
|
usage.cacheReadTokens += res.usage.cacheReadTokens ?? 0;
|
|
5049
|
+
const prompt = res.usage.promptTokens ?? 0, cacheRead = res.usage.cacheReadTokens ?? 0;
|
|
5050
|
+
if (prevPrompt < 0) {
|
|
5051
|
+
const u = sent.map((m) => m.role).lastIndexOf("user");
|
|
5052
|
+
prevPrompt = u > 0 ? estimateTokens(sent.slice(0, u)) : 0;
|
|
5053
|
+
}
|
|
5054
|
+
const reused = Math.min(prompt, Math.max(cacheRead, prevPrompt));
|
|
5055
|
+
spent += (res.usage.totalTokens ?? 0) - 0.9 * reused;
|
|
5056
|
+
prevPrompt = stepPrompt = prompt;
|
|
5048
5057
|
}
|
|
5049
5058
|
const delegatedTools = res.delegatedTools ?? [];
|
|
5050
5059
|
if (delegatedTools.length) {
|
|
@@ -16942,6 +16951,7 @@ function jsonResult(res, session) {
|
|
|
16942
16951
|
steps: res.steps,
|
|
16943
16952
|
tools: res.messages.slice(lastUser).filter((m) => m.role === "tool").length,
|
|
16944
16953
|
usage: res.usage,
|
|
16954
|
+
...res.budget ? { budget: res.budget } : {},
|
|
16945
16955
|
...res.routing ? { costUsd: res.costUsd, routing: res.routing } : {},
|
|
16946
16956
|
// cast: tsup dts hoists a modelRouter import above the shebang
|
|
16947
16957
|
sessionId: session.meta.id,
|