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