openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
40 lines (39 loc) • 1.51 kB
JavaScript
import { p as isDiagnosticsEnabled, s as emitTrustedDiagnosticEvent } from "./diagnostic-events-BjAH1Kbx.mjs";
import { h as createChildDiagnosticTraceContext, y as freezeDiagnosticTraceContext } from "./diagnostics-timeline-CSwiG24r.mjs";
import { a as hasBillableUsage, f as toDiagnosticUsage } from "./usage-CHLnzpJG.mjs";
import { n as estimateAggregateUsageCost } from "./usage-format-BisQoUIV.mjs";
//#region src/agents/internal-run-usage.ts
/** Detached maintenance settles its own usage, never the foreground conversation's totals. */
function emitInternalRunUsageDiagnostic(e, t) {
if (!isDiagnosticsEnabled(t.config)) return;
const n = e.meta?.agentMeta;
const r = n?.diagnosticUsage ?? n?.usage;
if (!hasBillableUsage(r)) return;
const i = n?.provider ?? t.provider;
const a = n?.model ?? t.model;
emitTrustedDiagnosticEvent({
type: "model.usage",
...e.diagnosticTrace ? { trace: freezeDiagnosticTraceContext(createChildDiagnosticTraceContext(e.diagnosticTrace)) } : {},
agentId: t.agentId,
sessionId: t.sessionId,
sessionKey: t.sessionKey,
provider: i,
model: a,
usage: toDiagnosticUsage(r),
lastCallUsage: n?.lastCallUsage,
context: {
limit: n?.contextTokens,
...n?.promptTokens !== void 0 ? { used: n.promptTokens } : {}
},
costUsd: estimateAggregateUsageCost({
usage: r,
provider: i,
model: a,
config: t.config,
agentDir: t.agentDir
}),
durationMs: e.meta?.durationMs
});
}
//#endregion
export { emitInternalRunUsageDiagnostic as t };