|
1 | 1 | // Shared runtime probes used by status text and JSON commands. |
2 | 2 | // Heavy modules stay lazily loaded so fast status output avoids security/provider/gateway costs. |
3 | 3 |
|
4 | | -import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce"; |
5 | | -import { resolveDefaultAgentDir } from "../agents/agent-scope.js"; |
6 | | -import { resolveAgentHarnessPolicy } from "../agents/harness/policy.js"; |
7 | | -import { resolveModelAuthLabel } from "../agents/model-auth-label.js"; |
8 | | -import { resolveDefaultModelForAgent } from "../agents/model-selection.js"; |
9 | | -import { listOpenAIAuthProfileProvidersForAgentRuntime } from "../agents/openai-routing.js"; |
10 | 4 | import type { OpenClawConfig } from "../config/types.js"; |
11 | 5 | import type { HeartbeatEventPayload } from "../infra/heartbeat-events.js"; |
12 | 6 | import { createLazyImportLoader } from "../shared/lazy-promise.js"; |
13 | 7 | import { |
14 | 8 | buildCodexSyntheticUsageAuth, |
15 | 9 | mergeUsageSummaries, |
| 10 | + resolveUsageCredentialType, |
16 | 11 | shouldUseCodexSyntheticUsageForRuntime, |
17 | 12 | } from "../status/codex-synthetic-usage.js"; |
18 | 13 | import type { HealthSummary } from "./health.js"; |
@@ -43,27 +38,21 @@ function loadGatewayCallModule() { |
43 | 38 | return gatewayCallModuleLoader.load(); |
44 | 39 | } |
45 | 40 |
|
46 | | -function resolveUsageCredentialType(authLabel?: string): "oauth" | "token" | "api_key" | undefined { |
47 | | - const auth = normalizeOptionalLowercaseString(authLabel); |
48 | | - if (!auth) { |
49 | | - return undefined; |
50 | | - } |
51 | | - if (auth.startsWith("oauth")) { |
52 | | - return "oauth"; |
53 | | - } |
54 | | - if (auth.startsWith("token")) { |
55 | | - return "token"; |
56 | | - } |
57 | | - if (auth.startsWith("api-key") || auth.startsWith("api key")) { |
58 | | - return "api_key"; |
59 | | - } |
60 | | - return undefined; |
61 | | -} |
62 | | - |
63 | | -function shouldUseConfiguredCodexSyntheticUsage(params: { |
| 41 | +async function shouldUseConfiguredCodexSyntheticUsage(params: { |
64 | 42 | config: OpenClawConfig; |
65 | 43 | agentDir: string; |
66 | | -}): boolean { |
| 44 | +}): Promise<boolean> { |
| 45 | + const [ |
| 46 | + { resolveAgentHarnessPolicy }, |
| 47 | + { resolveModelAuthLabel }, |
| 48 | + { resolveDefaultModelForAgent }, |
| 49 | + { listOpenAIAuthProfileProvidersForAgentRuntime }, |
| 50 | + ] = await Promise.all([ |
| 51 | + import("../agents/harness/policy.js"), |
| 52 | + import("../agents/model-auth-label.js"), |
| 53 | + import("../agents/model-selection.js"), |
| 54 | + import("../agents/openai-routing.js"), |
| 55 | + ]); |
67 | 56 | const configuredDefault = resolveDefaultModelForAgent({ |
68 | 57 | cfg: params.config, |
69 | 58 | allowPluginNormalization: false, |
@@ -131,13 +120,15 @@ type StatusUsageSummaryOptions = { |
131 | 120 | /** Loads provider usage for status output, defaulting to the config's default agent directory. */ |
132 | 121 | export async function resolveStatusUsageSummary(params: StatusUsageSummaryOptions) { |
133 | 122 | const { loadProviderUsageSummary } = await loadProviderUsage(); |
134 | | - const agentDir = params.agentDir ?? resolveDefaultAgentDir(params.config); |
| 123 | + const agentDir = |
| 124 | + params.agentDir ?? |
| 125 | + (await import("../agents/agent-scope.js")).resolveDefaultAgentDir(params.config); |
135 | 126 | const usage = await loadProviderUsageSummary({ |
136 | 127 | timeoutMs: params.timeoutMs, |
137 | 128 | config: params.config, |
138 | 129 | agentDir, |
139 | 130 | }); |
140 | | - if (!shouldUseConfiguredCodexSyntheticUsage({ config: params.config, agentDir })) { |
| 131 | + if (!(await shouldUseConfiguredCodexSyntheticUsage({ config: params.config, agentDir }))) { |
141 | 132 | return usage; |
142 | 133 | } |
143 | 134 | const codexUsage = await loadProviderUsageSummary({ |
|
0 commit comments