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
+15 -3
View File
@@ -11,6 +11,7 @@ import type {
import buildUsageCall from "../usage/build-usage-call";
import recordHarnessUsage from "../usage/record-harness-usage";
import grabChatParams from "./grab-chat-params";
import flattenSentParams from "../usage/flatten-sent-params";
import prepareMessagesForModel from "./prepare-messages-for-model";
import stripThinkTags from "./strip-think-tags";
@@ -55,6 +56,10 @@ export type GenerateTextResult = HarnessChatResult & {
*/
type ChatAnswer = Omit<HarnessChatResult, "text"> & {
text: string | null;
/**
* The generation settings sent to this candidate, for its usage row.
*/
sent_params?: Record<string, number | string | { effort: string }>;
};
/**
@@ -85,15 +90,22 @@ export default async function generateText({
harness: "text",
candidates: resolved,
prefer_key,
on_success: async ({ candidate: answered, result: answer }): Promise<void> =>
on_success: async ({ candidate: answered, result: answer, failed }): Promise<void> =>
await recordHarnessUsage({
call: buildUsageCall({
harness: "text",
candidate: answered,
usage: answer.usage,
failed,
settings: {
...(saved_params ? { settings_source: saved_params.source } : {}),
params: flattenSentParams({ params: answer.sent_params }),
...(max_tokens ? { max_tokens } : {}),
},
}),
}),
run: async (candidate) => {
const sent_params = params || saved_params?.paramsFor(candidate.model);
const answer = await grabHarnessAdapter({
kind: candidate.provider.kind,
}).chat({
@@ -108,7 +120,7 @@ export default async function generateText({
}),
tools,
max_tokens,
params: params || saved_params?.(candidate.model),
params: sent_params,
signal,
});
@@ -122,7 +134,7 @@ export default async function generateText({
});
}
return { ...answer, text: text || null };
return { ...answer, text: text || null, sent_params };
},
});
+9 -5
View File
@@ -18,22 +18,24 @@ type Params = {
* harness's setting (the workspace's, the bot's, else the default), else
* `HarnessParameterDefaults` so a fresh install is ready to go. Keyed by
* the field sent on the wire, keeping only what the model says it takes
* (a default only where the model explicitly advertises it).
* (a default only where the model explicitly advertises it). `source`
* says whose setting it was, for the call's usage row.
*/
export default async function grabChatParams({
harness,
bot_id,
workspace_id,
}: Params): Promise<
(model: HarnessModelInfo) => Record<string, number | string | { effort: string }>
> {
}: Params): Promise<{
paramsFor: (model: HarnessModelInfo) => Record<string, number | string | { effort: string }>;
source: "default" | "bot" | "workspace";
}> {
const setting = await grabHarnessSetting({
harness,
bot_id,
workspace_id,
});
return (model) =>
const paramsFor = (model: HarnessModelInfo) =>
Object.fromEntries(
HarnessParameters.flatMap((parameter) => {
const { value, saved } = harnessParameterValue({
@@ -67,4 +69,6 @@ export default async function grabChatParams({
];
}),
);
return { paramsFor, source: setting.source };
}