Show how each bot message was generated

Every bot message gets an info button that opens its details: the
provider and model behind it, tokens and cost, the job that ran it, each
model used and every call in order. Each model call now records how it
was made in token_usages.settings (generation settings sent, whose
settings they were, pinned or automatic model, fallbacks), shown per
model in the modal.

Live replies now carry their token usage, from the job's push and the
live relay alike, so it shows without a reload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-25 04:33:47 +01:00
co-authored by Claude Opus 5.5
parent feec69adca
commit c13b9ea826
48 changed files with 1307 additions and 57 deletions
@@ -0,0 +1,9 @@
/**
* A price in USD, precise enough for a single model call. "Not reported"
* when the provider gave none (free models, most local ones).
*/
export default function costLabel({ cost }: { cost?: number | null }) {
if (typeof cost != "number" || !(cost > 0)) return "Not reported";
return `$${cost < 0.01 ? cost.toFixed(6) : cost.toFixed(4)}`;
}
@@ -0,0 +1,9 @@
import { Harnesses } from "@/src/dict/harness-dict";
/**
* What a harness is called in a message's details: its title in Settings,
* under Models.
*/
export default function harnessLabel({ harness }: { harness: string }) {
return Harnesses.find((h) => h.value == harness)?.title || harness;
}
@@ -0,0 +1,21 @@
import { describe, expect, test } from "bun:test";
import costLabel from "./cost-label";
import providerLabel from "./provider-label";
describe("providerLabel", () => {
test("adds the kind only when it says more than the name", () => {
expect(providerLabel({ name: "OpenRouter", kind: "openrouter" })).toBe("OpenRouter");
expect(providerLabel({ name: "Work key", kind: "openai" })).toBe("Work key · OpenAI");
expect(providerLabel({ name: "Old one", kind: null })).toBe("Old one");
expect(providerLabel({ name: null, kind: null })).toBe("Unknown provider");
});
});
describe("costLabel", () => {
test("keeps small prices readable", () => {
expect(costLabel({ cost: 0.000123 })).toBe("$0.000123");
expect(costLabel({ cost: 0.25 })).toBe("$0.2500");
expect(costLabel({ cost: 0 })).toBe("Not reported");
expect(costLabel({ cost: null })).toBe("Not reported");
});
});
@@ -0,0 +1,20 @@
import { HarnessProviderKinds } from "@/src/dict/harness-provider-dict";
type Params = {
name: string | null;
kind: string | null;
};
/**
* A provider as a message's details name it: the name it was saved under,
* with its kind beside it when that says something more ("Work key ·
* OpenAI").
*/
export default function providerLabel({ name, kind }: Params) {
const kind_title = kind ? HarnessProviderKinds.find((k) => k.value == kind)?.title : undefined;
if (!name) return kind_title || "Unknown provider";
if (!kind_title || kind_title.toLowerCase() == name.toLowerCase()) return name;
return `${name} · ${kind_title}`;
}