mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-23 22:55:24 +00:00
perf(reply): lazy-load usage cost resolution
This commit is contained in:
@@ -18,7 +18,6 @@ import { generateSecureUuid } from "../../infra/secure-random.js";
|
||||
import { enqueueSystemEvent } from "../../infra/system-events.js";
|
||||
import { resolveAgentIdFromSessionKey } from "../../routing/session-key.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { estimateUsageCost, resolveModelCostConfig } from "../../utils/usage-format.js";
|
||||
import {
|
||||
buildFallbackClearedNotice,
|
||||
buildFallbackNotice,
|
||||
@@ -64,6 +63,7 @@ let agentRunnerExecutionRuntimePromise: Promise<
|
||||
let agentRunnerMemoryRuntimePromise: Promise<
|
||||
typeof import("./agent-runner-memory.runtime.js")
|
||||
> | null = null;
|
||||
let usageCostRuntimePromise: Promise<typeof import("./usage-cost.runtime.js")> | null = null;
|
||||
|
||||
function loadPiEmbeddedQueueRuntime() {
|
||||
piEmbeddedQueueRuntimePromise ??= import("../../agents/pi-embedded-queue.runtime.js");
|
||||
@@ -80,6 +80,11 @@ function loadAgentRunnerMemoryRuntime() {
|
||||
return agentRunnerMemoryRuntimePromise;
|
||||
}
|
||||
|
||||
function loadUsageCostRuntime() {
|
||||
usageCostRuntimePromise ??= import("./usage-cost.runtime.js");
|
||||
return usageCostRuntimePromise;
|
||||
}
|
||||
|
||||
export async function runReplyAgent(params: {
|
||||
commandBody: string;
|
||||
followupRun: FollowupRun;
|
||||
@@ -575,6 +580,7 @@ export async function runReplyAgent(params: {
|
||||
await signalTypingIfNeeded(guardedReplyPayloads, typingSignals);
|
||||
|
||||
if (isDiagnosticsEnabled(cfg) && hasNonzeroUsage(usage)) {
|
||||
const { estimateUsageCost, resolveModelCostConfig } = await loadUsageCostRuntime();
|
||||
const input = usage.input ?? 0;
|
||||
const output = usage.output ?? 0;
|
||||
const cacheRead = usage.cacheRead ?? 0;
|
||||
@@ -617,6 +623,7 @@ export async function runReplyAgent(params: {
|
||||
(sessionKey ? activeSessionStore?.[sessionKey]?.responseUsage : undefined);
|
||||
const responseUsageMode = resolveResponseUsageMode(responseUsageRaw);
|
||||
if (responseUsageMode !== "off" && hasNonzeroUsage(usage)) {
|
||||
const { resolveModelCostConfig } = await loadUsageCostRuntime();
|
||||
const authMode = resolveModelAuthMode(providerUsed, cfg);
|
||||
const showCost = authMode === "api-key";
|
||||
const costConfig = showCost
|
||||
|
||||
1
src/auto-reply/reply/usage-cost.runtime.ts
Normal file
1
src/auto-reply/reply/usage-cost.runtime.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { estimateUsageCost, resolveModelCostConfig } from "../../utils/usage-format.js";
|
||||
Reference in New Issue
Block a user