refactor(usage): centralize responseUsage mode
This commit is contained in:
@@ -20,7 +20,7 @@ import { logVerbose } from "../../globals.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { resolveModelCostConfig } from "../../utils/usage-format.js";
|
||||
import type { OriginatingChannelType, TemplateContext } from "../templating.js";
|
||||
import type { VerboseLevel } from "../thinking.js";
|
||||
import { resolveResponseUsageMode, type VerboseLevel } from "../thinking.js";
|
||||
import type { GetReplyOptions, ReplyPayload } from "../types.js";
|
||||
import { runAgentTurnWithFallback } from "./agent-runner-execution.js";
|
||||
import {
|
||||
@@ -460,12 +460,7 @@ export async function runReplyAgent(params: {
|
||||
const responseUsageRaw =
|
||||
activeSessionEntry?.responseUsage ??
|
||||
(sessionKey ? activeSessionStore?.[sessionKey]?.responseUsage : undefined);
|
||||
const responseUsageMode =
|
||||
responseUsageRaw === "full"
|
||||
? "full"
|
||||
: responseUsageRaw === "tokens" || responseUsageRaw === "on"
|
||||
? "tokens"
|
||||
: "off";
|
||||
const responseUsageMode = resolveResponseUsageMode(responseUsageRaw);
|
||||
if (responseUsageMode !== "off" && hasNonzeroUsage(usage)) {
|
||||
const authMode = resolveModelAuthMode(providerUsed, cfg);
|
||||
const showCost = authMode === "api-key";
|
||||
|
||||
@@ -6,7 +6,7 @@ import { createInternalHookEvent, triggerInternalHook } from "../../hooks/intern
|
||||
import { scheduleGatewaySigusr1Restart, triggerClawdbotRestart } from "../../infra/restart.js";
|
||||
import { parseActivationCommand } from "../group-activation.js";
|
||||
import { parseSendPolicyCommand } from "../send-policy.js";
|
||||
import { normalizeUsageDisplay } from "../thinking.js";
|
||||
import { normalizeUsageDisplay, resolveResponseUsageMode } from "../thinking.js";
|
||||
import {
|
||||
formatAbortReplyText,
|
||||
isAbortTrigger,
|
||||
@@ -151,12 +151,7 @@ export const handleUsageCommand: CommandHandler = async (params, allowTextComman
|
||||
const currentRaw =
|
||||
params.sessionEntry?.responseUsage ??
|
||||
(params.sessionKey ? params.sessionStore?.[params.sessionKey]?.responseUsage : undefined);
|
||||
const current =
|
||||
currentRaw === "full"
|
||||
? "full"
|
||||
: currentRaw === "tokens" || currentRaw === "on"
|
||||
? "tokens"
|
||||
: "off";
|
||||
const current = resolveResponseUsageMode(currentRaw);
|
||||
const next = requested ?? (current === "off" ? "tokens" : current === "tokens" ? "full" : "off");
|
||||
|
||||
if (params.sessionEntry && params.sessionStore && params.sessionKey) {
|
||||
|
||||
@@ -103,6 +103,10 @@ export function normalizeUsageDisplay(raw?: string | null): UsageDisplayLevel |
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveResponseUsageMode(raw?: string | null): UsageDisplayLevel {
|
||||
return normalizeUsageDisplay(raw) ?? "off";
|
||||
}
|
||||
|
||||
// Normalize elevated flags used to toggle elevated bash permissions.
|
||||
export function normalizeElevatedLevel(raw?: string | null): ElevatedLevel | undefined {
|
||||
if (!raw) return undefined;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import type { Component, TUI } from "@mariozechner/pi-tui";
|
||||
import { formatThinkingLevels, normalizeUsageDisplay } from "../auto-reply/thinking.js";
|
||||
import {
|
||||
formatThinkingLevels,
|
||||
normalizeUsageDisplay,
|
||||
resolveResponseUsageMode,
|
||||
} from "../auto-reply/thinking.js";
|
||||
import { normalizeAgentId } from "../routing/session-key.js";
|
||||
import { helpText, parseCommand } from "./commands.js";
|
||||
import type { ChatLog } from "./components/chat-log.js";
|
||||
@@ -324,12 +328,7 @@ export function createCommandHandlers(context: CommandHandlerContext) {
|
||||
break;
|
||||
}
|
||||
const currentRaw = state.sessionInfo.responseUsage;
|
||||
const current =
|
||||
currentRaw === "full"
|
||||
? "full"
|
||||
: currentRaw === "tokens" || currentRaw === "on"
|
||||
? "tokens"
|
||||
: "off";
|
||||
const current = resolveResponseUsageMode(currentRaw);
|
||||
const next =
|
||||
normalized ?? (current === "off" ? "tokens" : current === "tokens" ? "full" : "off");
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user