


























@@ -52,8 +52,9 @@ const log = createSubsystemLogger("model-auth");
5252function resolveConfigAwareEnvApiKey(
5353cfg: OpenClawConfig | undefined,
5454provider: string,
55+workspaceDir?: string,
5556): EnvApiKeyResult | null {
56-return resolveEnvApiKey(provider, process.env, { config: cfg });
57+return resolveEnvApiKey(provider, process.env, { config: cfg, workspaceDir });
5758}
58595960function resolveProviderConfig(
@@ -315,14 +316,20 @@ export function hasSyntheticLocalProviderAuthConfig(params: {
315316export function hasRuntimeAvailableProviderAuth(params: {
316317provider: string;
317318cfg?: OpenClawConfig;
319+workspaceDir?: string;
318320env?: NodeJS.ProcessEnv;
319321}): boolean {
320322const provider = normalizeProviderId(params.provider);
321323const authOverride = resolveProviderAuthOverride(params.cfg, provider);
322324if (authOverride === "aws-sdk") {
323325return true;
324326}
325-if (resolveEnvApiKey(provider, params.env)) {
327+if (
328+resolveEnvApiKey(provider, params.env, {
329+config: params.cfg,
330+workspaceDir: params.workspaceDir,
331+})
332+) {
326333return true;
327334}
328335if (resolveUsableCustomProviderApiKey({ cfg: params.cfg, provider, env: params.env })) {
@@ -489,6 +496,7 @@ export async function resolveApiKeyForProvider(params: {
489496preferredProfile?: string;
490497store?: AuthProfileStore;
491498agentDir?: string;
499+workspaceDir?: string;
492500/** When true, treat profileId as a user-locked selection that must not be
493501 * silently overridden by env/config credentials. */
494502lockedProfile?: boolean;
@@ -553,7 +561,7 @@ export async function resolveApiKeyForProvider(params: {
553561}
554562555563if (params.credentialPrecedence === "env-first") {
556-const envResolved = resolveConfigAwareEnvApiKey(cfg, provider);
564+const envResolved = resolveConfigAwareEnvApiKey(cfg, provider, params.workspaceDir);
557565if (envResolved) {
558566const resolvedMode: ResolvedProviderAuth["mode"] = envResolved.source.includes("OAUTH_TOKEN")
559567 ? "oauth"
@@ -575,7 +583,7 @@ export async function resolveApiKeyForProvider(params: {
575583mode: "api-key",
576584};
577585}
578-const localMarkerEnv = resolveConfigAwareEnvApiKey(cfg, provider);
586+const localMarkerEnv = resolveConfigAwareEnvApiKey(cfg, provider, params.workspaceDir);
579587if (localMarkerEnv && isNonSecretApiKeyMarker(localMarkerEnv.apiKey)) {
580588return {
581589apiKey: localMarkerEnv.apiKey,
@@ -626,7 +634,7 @@ export async function resolveApiKeyForProvider(params: {
626634}
627635}
628636629-const envResolved = resolveConfigAwareEnvApiKey(cfg, provider);
637+const envResolved = resolveConfigAwareEnvApiKey(cfg, provider, params.workspaceDir);
630638if (envResolved) {
631639const resolvedMode: ResolvedProviderAuth["mode"] = envResolved.source.includes("OAUTH_TOKEN")
632640 ? "oauth"
@@ -699,6 +707,7 @@ export function resolveModelAuthMode(
699707provider?: string,
700708cfg?: OpenClawConfig,
701709store?: AuthProfileStore,
710+options?: { workspaceDir?: string },
702711): ModelAuthMode | undefined {
703712const resolved = provider?.trim();
704713if (!resolved) {
@@ -739,7 +748,7 @@ export function resolveModelAuthMode(
739748return "aws-sdk";
740749}
741750742-const envKey = resolveConfigAwareEnvApiKey(cfg, resolved);
751+const envKey = resolveConfigAwareEnvApiKey(cfg, resolved, options?.workspaceDir);
743752if (envKey?.apiKey) {
744753return envKey.source.includes("OAUTH_TOKEN") ? "oauth" : "api-key";
745754}
@@ -764,14 +773,15 @@ export async function hasAvailableAuthForProvider(params: {
764773preferredProfile?: string;
765774store?: AuthProfileStore;
766775agentDir?: string;
776+workspaceDir?: string;
767777}): Promise<boolean> {
768778const { provider, cfg, preferredProfile } = params;
769779770780const authOverride = resolveProviderAuthOverride(cfg, provider);
771781if (authOverride === "aws-sdk") {
772782return true;
773783}
774-if (resolveConfigAwareEnvApiKey(cfg, provider)) {
784+if (resolveConfigAwareEnvApiKey(cfg, provider, params.workspaceDir)) {
775785return true;
776786}
777787if (resolveUsableCustomProviderApiKey({ cfg, provider })) {
@@ -816,6 +826,7 @@ export async function getApiKeyForModel(params: {
816826preferredProfile?: string;
817827store?: AuthProfileStore;
818828agentDir?: string;
829+workspaceDir?: string;
819830lockedProfile?: boolean;
820831credentialPrecedence?: ProviderCredentialPrecedence;
821832}): Promise<ResolvedProviderAuth> {
@@ -826,6 +837,7 @@ export async function getApiKeyForModel(params: {
826837preferredProfile: params.preferredProfile,
827838store: params.store,
828839agentDir: params.agentDir,
840+workspaceDir: params.workspaceDir,
829841lockedProfile: params.lockedProfile,
830842credentialPrecedence: params.credentialPrecedence,
831843});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。