




















@@ -12,6 +12,7 @@ import {
1212} from "../../agents/auth-health.js";
1313import { resolveAuthStorePathForDisplay } from "../../agents/auth-profiles/paths.js";
1414import { ensureAuthProfileStoreWithoutExternalProfiles as ensureAuthProfileStore } from "../../agents/auth-profiles/store.js";
15+import type { AuthProfileCredential } from "../../agents/auth-profiles/types.js";
1516import { resolveProfileUnusableUntilForDisplay } from "../../agents/auth-profiles/usage.js";
1617import { resolveProviderEnvApiKeyCandidates } from "../../agents/model-auth-env-vars.js";
1718import { resolveEnvApiKey } from "../../agents/model-auth.js";
@@ -29,6 +30,8 @@ import {
2930resolveAgentModelPrimaryValue,
3031} from "../../config/model-input.js";
3132import { getShellEnvAppliedKeys, shouldEnableShellEnvFallback } from "../../infra/shell-env.js";
33+import type { ProviderSyntheticAuthResult } from "../../plugins/provider-external-auth.types.js";
34+import { resolveProviderSyntheticAuthWithPlugin } from "../../plugins/provider-runtime.js";
3235import { resolveRuntimeSyntheticAuthProviderRefs } from "../../plugins/synthetic-auth.runtime.js";
3336import { type RuntimeEnv, writeRuntimeJson } from "../../runtime.js";
3437import { normalizeOptionalString } from "../../shared/string-coerce.js";
@@ -57,6 +60,14 @@ let listProbeRuntimePromise: Promise<ListProbeRuntime> | undefined;
57605861const DISPLAY_MODEL_PARSE_OPTIONS = { allowPluginNormalization: false } as const;
596263+type StatusSyntheticAuth = {
64+value: string;
65+source: string;
66+credential?: string;
67+mode?: ProviderSyntheticAuthResult["mode"];
68+expiresAt?: number;
69+};
70+6071function loadProviderUsageRuntime(): Promise<ProviderUsageRuntime> {
6172providerUsageRuntimePromise ??= import("../../infra/provider-usage.js");
6273return providerUsageRuntimePromise;
@@ -77,6 +88,56 @@ function loadListProbeRuntime(): Promise<ListProbeRuntime> {
7788return listProbeRuntimePromise;
7889}
799091+function resolveProviderConfigForStatus(
92+cfg: Awaited<ReturnType<typeof loadModelsConfig>>,
93+provider: string,
94+) {
95+const providers = cfg.models?.providers ?? {};
96+const direct = providers[provider];
97+if (direct) {
98+return direct;
99+}
100+const normalized = normalizeProviderId(provider);
101+return (
102+providers[normalized] ??
103+Object.entries(providers).find(([key]) => normalizeProviderId(key) === normalized)?.[1]
104+);
105+}
106+107+function syntheticAuthCredential(
108+provider: string,
109+auth: StatusSyntheticAuth,
110+): AuthProfileCredential | undefined {
111+if (!auth.mode) {
112+return undefined;
113+}
114+if (auth.mode === "api-key") {
115+return {
116+type: "api_key",
117+ provider,
118+key: auth.credential,
119+};
120+}
121+if (auth.mode === "token") {
122+return {
123+type: "token",
124+ provider,
125+token: auth.credential,
126+expires: auth.expiresAt,
127+};
128+}
129+if (auth.expiresAt === undefined) {
130+return undefined;
131+}
132+return {
133+type: "oauth",
134+ provider,
135+access: auth.credential ?? "",
136+refresh: "",
137+expires: auth.expiresAt,
138+};
139+}
140+80141export async function modelsStatusCommand(
81142opts: {
82143json?: boolean;
@@ -185,14 +246,30 @@ export async function modelsStatusCommand(
185246providersFromEnv.add(provider);
186247}
187248}
188-const syntheticAuthByProvider = new Map(
189-resolveRuntimeSyntheticAuthProviderRefs().map((provider) => [
190-normalizeProviderId(provider),
191-{
192-value: "plugin-owned",
193-source: "plugin synthetic auth",
249+const syntheticAuthByProvider = new Map<string, StatusSyntheticAuth>();
250+for (const provider of resolveRuntimeSyntheticAuthProviderRefs()) {
251+const normalized = normalizeProviderId(provider);
252+const resolved = resolveProviderSyntheticAuthWithPlugin({
253+provider: normalized,
254+config: cfg,
255+context: {
256+config: cfg,
257+provider: normalized,
258+providerConfig: resolveProviderConfigForStatus(cfg, normalized),
194259},
195-]),
260+});
261+syntheticAuthByProvider.set(normalized, {
262+value: "plugin-owned",
263+source: resolved?.source ?? "plugin synthetic auth",
264+credential: resolved?.apiKey,
265+mode: resolved?.mode,
266+expiresAt: resolved?.expiresAt,
267+});
268+}
269+const runtimeCredentialsByProvider = new Map(
270+Array.from(syntheticAuthByProvider.entries())
271+.map(([provider, auth]) => [provider, syntheticAuthCredential(provider, auth)] as const)
272+.filter((entry): entry is readonly [string, AuthProfileCredential] => Boolean(entry[1])),
196273);
197274198275const providers = Array.from(
@@ -325,6 +402,7 @@ export async function modelsStatusCommand(
325402 store,
326403 cfg,
327404warnAfterMs: DEFAULT_OAUTH_WARN_MS,
405+ runtimeCredentialsByProvider,
328406});
329407const oauthProfiles = authHealth.profiles.filter(
330408(profile) => profile.type === "oauth" || profile.type === "token",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。