mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:21:35 +00:00
chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -1,19 +1,11 @@
|
||||
import fs from "node:fs";
|
||||
|
||||
import { lookupContextTokens } from "../agents/context.js";
|
||||
import {
|
||||
DEFAULT_CONTEXT_TOKENS,
|
||||
DEFAULT_MODEL,
|
||||
DEFAULT_PROVIDER,
|
||||
} from "../agents/defaults.js";
|
||||
import { DEFAULT_CONTEXT_TOKENS, DEFAULT_MODEL, DEFAULT_PROVIDER } from "../agents/defaults.js";
|
||||
import { resolveModelAuthMode } from "../agents/model-auth.js";
|
||||
import { resolveConfiguredModelRef } from "../agents/model-selection.js";
|
||||
import { resolveSandboxRuntimeStatus } from "../agents/sandbox.js";
|
||||
import {
|
||||
derivePromptTokens,
|
||||
normalizeUsage,
|
||||
type UsageLike,
|
||||
} from "../agents/usage.js";
|
||||
import { derivePromptTokens, normalizeUsage, type UsageLike } from "../agents/usage.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import {
|
||||
resolveMainSessionKey,
|
||||
@@ -29,20 +21,10 @@ import {
|
||||
resolveModelCostConfig,
|
||||
} from "../utils/usage-format.js";
|
||||
import { VERSION } from "../version.js";
|
||||
import {
|
||||
listChatCommands,
|
||||
listChatCommandsForConfig,
|
||||
} from "./commands-registry.js";
|
||||
import type {
|
||||
ElevatedLevel,
|
||||
ReasoningLevel,
|
||||
ThinkLevel,
|
||||
VerboseLevel,
|
||||
} from "./thinking.js";
|
||||
import { listChatCommands, listChatCommandsForConfig } from "./commands-registry.js";
|
||||
import type { ElevatedLevel, ReasoningLevel, ThinkLevel, VerboseLevel } from "./thinking.js";
|
||||
|
||||
type AgentConfig = Partial<
|
||||
NonNullable<NonNullable<ClawdbotConfig["agents"]>["defaults"]>
|
||||
>;
|
||||
type AgentConfig = Partial<NonNullable<NonNullable<ClawdbotConfig["agents"]>["defaults"]>>;
|
||||
|
||||
export const formatTokenCount = formatTokenCountShared;
|
||||
|
||||
@@ -73,10 +55,7 @@ type StatusArgs = {
|
||||
now?: number;
|
||||
};
|
||||
|
||||
const formatTokens = (
|
||||
total: number | null | undefined,
|
||||
contextTokens: number | null,
|
||||
) => {
|
||||
const formatTokens = (total: number | null | undefined, contextTokens: number | null) => {
|
||||
const ctx = contextTokens ?? null;
|
||||
if (total == null) {
|
||||
const ctxLabel = ctx ? formatTokenCount(ctx) : "?";
|
||||
@@ -115,9 +94,7 @@ const formatQueueDetails = (queue?: QueueStatus) => {
|
||||
if (typeof queue.debounceMs === "number") {
|
||||
const ms = Math.max(0, Math.round(queue.debounceMs));
|
||||
const label =
|
||||
ms >= 1000
|
||||
? `${ms % 1000 === 0 ? ms / 1000 : (ms / 1000).toFixed(1)}s`
|
||||
: `${ms}ms`;
|
||||
ms >= 1000 ? `${ms % 1000 === 0 ? ms / 1000 : (ms / 1000).toFixed(1)}s` : `${ms}ms`;
|
||||
detailParts.push(`debounce ${label}`);
|
||||
}
|
||||
if (typeof queue.cap === "number") detailParts.push(`cap ${queue.cap}`);
|
||||
@@ -173,8 +150,7 @@ const readUsageFromSessionLog = (
|
||||
if (!lastUsage) return undefined;
|
||||
input = lastUsage.input ?? 0;
|
||||
output = lastUsage.output ?? 0;
|
||||
promptTokens =
|
||||
derivePromptTokens(lastUsage) ?? lastUsage.total ?? input + output;
|
||||
promptTokens = derivePromptTokens(lastUsage) ?? lastUsage.total ?? input + output;
|
||||
const total = lastUsage.total ?? promptTokens + output;
|
||||
if (promptTokens === 0 && total === 0) return undefined;
|
||||
return { input, output, promptTokens, total, model };
|
||||
@@ -186,8 +162,7 @@ const readUsageFromSessionLog = (
|
||||
const formatUsagePair = (input?: number | null, output?: number | null) => {
|
||||
if (input == null && output == null) return null;
|
||||
const inputLabel = typeof input === "number" ? formatTokenCount(input) : "?";
|
||||
const outputLabel =
|
||||
typeof output === "number" ? formatTokenCount(output) : "?";
|
||||
const outputLabel = typeof output === "number" ? formatTokenCount(output) : "?";
|
||||
return `🧮 Tokens: ${inputLabel} in / ${outputLabel} out`;
|
||||
};
|
||||
|
||||
@@ -203,8 +178,7 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
defaultProvider: DEFAULT_PROVIDER,
|
||||
defaultModel: DEFAULT_MODEL,
|
||||
});
|
||||
const provider =
|
||||
entry?.providerOverride ?? resolved.provider ?? DEFAULT_PROVIDER;
|
||||
const provider = entry?.providerOverride ?? resolved.provider ?? DEFAULT_PROVIDER;
|
||||
let model = entry?.modelOverride ?? resolved.model ?? DEFAULT_MODEL;
|
||||
let contextTokens =
|
||||
entry?.contextTokens ??
|
||||
@@ -214,9 +188,7 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
|
||||
let inputTokens = entry?.inputTokens;
|
||||
let outputTokens = entry?.outputTokens;
|
||||
let totalTokens =
|
||||
entry?.totalTokens ??
|
||||
(entry?.inputTokens ?? 0) + (entry?.outputTokens ?? 0);
|
||||
let totalTokens = entry?.totalTokens ?? (entry?.inputTokens ?? 0) + (entry?.outputTokens ?? 0);
|
||||
|
||||
// Prefer prompt-size tokens from the session transcript when it looks larger
|
||||
// (cached prompt tokens are often missing from agent meta/store).
|
||||
@@ -237,8 +209,7 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
}
|
||||
|
||||
const thinkLevel = args.resolvedThink ?? args.agent?.thinkingDefault ?? "off";
|
||||
const verboseLevel =
|
||||
args.resolvedVerbose ?? args.agent?.verboseDefault ?? "off";
|
||||
const verboseLevel = args.resolvedVerbose ?? args.agent?.verboseDefault ?? "off";
|
||||
const reasoningLevel = args.resolvedReasoning ?? "off";
|
||||
const elevatedLevel =
|
||||
args.resolvedElevated ??
|
||||
@@ -274,9 +245,7 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
const updatedAt = entry?.updatedAt;
|
||||
const sessionLine = [
|
||||
`Session: ${args.sessionKey ?? "unknown"}`,
|
||||
typeof updatedAt === "number"
|
||||
? `updated ${formatAge(now - updatedAt)}`
|
||||
: "no activity",
|
||||
typeof updatedAt === "number" ? `updated ${formatAge(now - updatedAt)}` : "no activity",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" • ");
|
||||
@@ -318,8 +287,7 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
|
||||
const authMode = resolveModelAuthMode(provider, args.config);
|
||||
const authLabelValue =
|
||||
args.modelAuth ??
|
||||
(authMode && authMode !== "unknown" ? authMode : undefined);
|
||||
args.modelAuth ?? (authMode && authMode !== "unknown" ? authMode : undefined);
|
||||
const showCost = authLabelValue === "api-key" || authLabelValue === "mixed";
|
||||
const costConfig = showCost
|
||||
? resolveModelCostConfig({
|
||||
@@ -328,8 +296,7 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
config: args.config,
|
||||
})
|
||||
: undefined;
|
||||
const hasUsage =
|
||||
typeof inputTokens === "number" || typeof outputTokens === "number";
|
||||
const hasUsage = typeof inputTokens === "number" || typeof outputTokens === "number";
|
||||
const cost =
|
||||
showCost && hasUsage
|
||||
? estimateUsageCost({
|
||||
@@ -350,9 +317,7 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
const usagePair = formatUsagePair(inputTokens, outputTokens);
|
||||
const costLine = costLabel ? `💵 Cost: ${costLabel}` : null;
|
||||
const usageCostLine =
|
||||
usagePair && costLine
|
||||
? `${usagePair} · ${costLine}`
|
||||
: (usagePair ?? costLine);
|
||||
usagePair && costLine ? `${usagePair} · ${costLine}` : (usagePair ?? costLine);
|
||||
|
||||
return [
|
||||
versionLine,
|
||||
@@ -405,9 +370,7 @@ export function buildCommandsMessage(cfg?: ClawdbotConfig): string {
|
||||
seen.add(key);
|
||||
return true;
|
||||
});
|
||||
const aliasLabel = aliases.length
|
||||
? ` (aliases: ${aliases.join(", ")})`
|
||||
: "";
|
||||
const aliasLabel = aliases.length ? ` (aliases: ${aliases.join(", ")})` : "";
|
||||
const scopeLabel = command.scope === "text" ? " (text-only)" : "";
|
||||
lines.push(`${primary}${aliasLabel}${scopeLabel} - ${command.description}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user