дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 19:25:54 +02:00
refactor(agents): Drop the session cost from the context usage
Цей коміт міститься в:
1 джерело
70f10e741c
коміт
443bb51bba
8 files changed
+13
-41
No files matched your search
@@ -172,7 +172,6 @@ function Header({ task, entries, head }: { task: AgentTask; entries: AgentEntry[
|
||||
);
|
||||
}
|
||||
|
||||
/** Context window use: "12%", the numbers (and cost) in the tooltip. */
|
||||
/** Context use (when the agent reports it) and the time spent on the task. */
|
||||
function Meters({ task, entries }: { task: AgentTask; entries: AgentEntry[] | null }) {
|
||||
const tx = useTx();
|
||||
@@ -188,6 +187,7 @@ function Meters({ task, entries }: { task: AgentTask; entries: AgentEntry[] | nu
|
||||
);
|
||||
}
|
||||
|
||||
/** Context window use: "12%", the numbers in the tooltip. */
|
||||
function Usage({ usage }: { usage: AgentUsage }) {
|
||||
const label = usageLabel(usage);
|
||||
return (
|
||||
|
||||
@@ -124,9 +124,9 @@ describe("agent composer", () => {
|
||||
"eye",
|
||||
"lock",
|
||||
]);
|
||||
expect(usageLabel({ used: 24_000, size: 200_000, cost: 0.4, currency: "USD" })).toEqual({
|
||||
expect(usageLabel({ used: 24_000, size: 200_000 })).toEqual({
|
||||
short: "12%",
|
||||
detail: "24k / 200k tokens · $0.40",
|
||||
detail: "24k / 200k tokens",
|
||||
});
|
||||
expect(imageFromDataUrl("data:image/png;base64,AAA", "a.png")).toEqual({ mimeType: "image/png", data: "AAA", name: "a.png" });
|
||||
expect(imageFromDataUrl("data:text/plain;base64,AAA")).toBeNull();
|
||||
@@ -135,7 +135,7 @@ describe("agent composer", () => {
|
||||
|
||||
describe("usage meters", () => {
|
||||
it("formats token counts", () => {
|
||||
expect(usageLabel({ used: 83_100, size: 1_000_000, cost: null, currency: null }).detail).toBe("83.1k / 1M tokens");
|
||||
expect(usageLabel({ used: 83_100, size: 1_000_000 }).detail).toBe("83.1k / 1M tokens");
|
||||
});
|
||||
|
||||
it("adds up the time spent on turns", () => {
|
||||
|
||||
@@ -131,8 +131,7 @@ export function nextValue(option: AgentConfigOption, current = option.current):
|
||||
/** "12%" of the context window and a tooltip with the numbers. */
|
||||
export function usageLabel(u: AgentUsage): { short: string; detail: string } {
|
||||
const pct = Math.min(100, Math.round((u.used / u.size) * 100));
|
||||
const cost = u.cost != null ? ` · ${costLabel(u)}` : "";
|
||||
return { short: `${pct}%`, detail: tx`${tokens(u.used)} / ${tokens(u.size)} tokens${cost}` };
|
||||
return { short: `${pct}%`, detail: tx`${tokens(u.used)} / ${tokens(u.size)} tokens` };
|
||||
}
|
||||
|
||||
/** `850`, `83.1k`, `1M`. */
|
||||
@@ -142,12 +141,6 @@ function tokens(n: number): string {
|
||||
return `${Math.round(n)}`;
|
||||
}
|
||||
|
||||
/** Session cost (`$4.23`), when the agent reports one. */
|
||||
function costLabel(u: AgentUsage): string | null {
|
||||
if (u.cost == null) return null;
|
||||
return `${u.currency === "USD" || !u.currency ? "$" : `${u.currency} `}${u.cost.toFixed(2)}`;
|
||||
}
|
||||
|
||||
/** Time the agent spent on the task's turns; a running one counts up to `now` (`null` when idle). */
|
||||
export function workTime(entries: readonly AgentEntry[], now: number | null): number {
|
||||
const users = entries.filter((e): e is Extract<AgentEntry, { type: "user" }> => e.type === "user");
|
||||
|
||||
Reference in new issue
Заблокувати користувача