mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 14:30:44 +00:00
perf(status): skip unused status pricing lookups
This commit is contained in:
@@ -358,6 +358,25 @@ describe("lookupContextTokens", () => {
|
||||
expect(result).toBe(200_000);
|
||||
});
|
||||
|
||||
it("resolveContextTokensForModel treats explicit config as authoritative for read-only misses", async () => {
|
||||
const loadConfig = vi.fn(() => {
|
||||
throw new Error("runtime config should not be loaded");
|
||||
});
|
||||
mockContextModuleDeps(loadConfig);
|
||||
const resolveContextTokensForModel = await importResolveContextTokensForModel();
|
||||
|
||||
const result = resolveContextTokensForModel({
|
||||
cfg: { agents: { defaults: {} } } as never,
|
||||
provider: "openai",
|
||||
model: "unknown-test-model",
|
||||
fallbackContextTokens: 123_000,
|
||||
allowAsyncLoad: false,
|
||||
});
|
||||
|
||||
expect(result).toBe(123_000);
|
||||
expect(loadConfig).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("resolveContextTokensForModel: config direct scan prevents OpenRouter qualified key collision for Google provider", async () => {
|
||||
// When provider is explicitly "google" and cfg has a Google contextWindow
|
||||
// override, the config direct scan returns it before any cache lookup —
|
||||
|
||||
@@ -269,11 +269,14 @@ function ensureContextWindowCacheLoaded(): Promise<void> {
|
||||
|
||||
export function lookupContextTokens(
|
||||
modelId?: string,
|
||||
options?: { allowAsyncLoad?: boolean },
|
||||
options?: { allowAsyncLoad?: boolean; skipRuntimeConfigLoad?: boolean },
|
||||
): number | undefined {
|
||||
if (!modelId) {
|
||||
return undefined;
|
||||
}
|
||||
if (options?.skipRuntimeConfigLoad) {
|
||||
return lookupCachedContextTokens(modelId);
|
||||
}
|
||||
if (options?.allowAsyncLoad === false) {
|
||||
// Read-only callers still need synchronous config-backed overrides, but they
|
||||
// should not start background model discovery or models.json writes.
|
||||
@@ -515,7 +518,10 @@ export function resolveContextTokensForModel(params: {
|
||||
if (params.provider && ref && !ref.model.includes("/")) {
|
||||
const qualifiedResult = lookupContextTokens(
|
||||
`${normalizeProviderId(ref.provider)}/${ref.model}`,
|
||||
{ allowAsyncLoad: params.allowAsyncLoad },
|
||||
{
|
||||
allowAsyncLoad: params.allowAsyncLoad,
|
||||
skipRuntimeConfigLoad: Boolean(params.cfg),
|
||||
},
|
||||
);
|
||||
if (qualifiedResult !== undefined) {
|
||||
return qualifiedResult;
|
||||
@@ -526,6 +532,7 @@ export function resolveContextTokensForModel(params: {
|
||||
// (e.g. "google/gemini-2.5-pro") this IS the raw discovery cache key.
|
||||
const bareResult = lookupContextTokens(params.model, {
|
||||
allowAsyncLoad: params.allowAsyncLoad,
|
||||
skipRuntimeConfigLoad: Boolean(params.cfg),
|
||||
});
|
||||
if (bareResult !== undefined) {
|
||||
return bareResult;
|
||||
@@ -537,7 +544,10 @@ export function resolveContextTokensForModel(params: {
|
||||
if (!params.provider && ref && !ref.model.includes("/")) {
|
||||
const qualifiedResult = lookupContextTokens(
|
||||
`${normalizeProviderId(ref.provider)}/${ref.model}`,
|
||||
{ allowAsyncLoad: params.allowAsyncLoad },
|
||||
{
|
||||
allowAsyncLoad: params.allowAsyncLoad,
|
||||
skipRuntimeConfigLoad: Boolean(params.cfg),
|
||||
},
|
||||
);
|
||||
if (qualifiedResult !== undefined) {
|
||||
return qualifiedResult;
|
||||
|
||||
@@ -869,15 +869,16 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
? activeAuthMode
|
||||
: (selectedAuthMode ?? activeAuthMode);
|
||||
const showCost = effectiveCostAuthMode === "api-key" || effectiveCostAuthMode === "mixed";
|
||||
const costConfig = showCost
|
||||
? resolveModelCostConfig({
|
||||
provider: activeProvider,
|
||||
model: activeModel,
|
||||
config: args.config,
|
||||
allowPluginNormalization: false,
|
||||
})
|
||||
: undefined;
|
||||
const hasUsage = typeof inputTokens === "number" || typeof outputTokens === "number";
|
||||
const costConfig =
|
||||
showCost && hasUsage
|
||||
? resolveModelCostConfig({
|
||||
provider: activeProvider,
|
||||
model: activeModel,
|
||||
config: args.config,
|
||||
allowPluginNormalization: false,
|
||||
})
|
||||
: undefined;
|
||||
const cost =
|
||||
showCost && hasUsage
|
||||
? estimateUsageCost({
|
||||
|
||||
Reference in New Issue
Block a user