
























@@ -74,21 +74,40 @@ export async function resolveLmstudioConfiguredApiKey(params: {
7474config?: OpenClawConfig;
7575env?: NodeJS.ProcessEnv;
7676path?: string;
77+allowUnresolved?: boolean;
7778}): Promise<string | undefined> {
7879const providerConfig = params.config?.models?.providers?.[LMSTUDIO_PROVIDER_ID];
7980const apiKeyInput = providerConfig?.apiKey;
8081if (apiKeyInput === undefined || apiKeyInput === null) {
8182return undefined;
8283}
838485+const path = params.path ?? "models.providers.lmstudio.apiKey";
86+const env = params.env ?? process.env;
8487const directApiKey = normalizeOptionalSecretInput(apiKeyInput);
8588if (directApiKey !== undefined) {
86-const trimmed = normalizeApiKeyConfig(directApiKey).trim();
89+const resolved = params.config
90+ ? await resolveConfiguredSecretInputString({
91+config: params.config,
92+ env,
93+value: directApiKey,
94+ path,
95+unresolvedReasonStyle: "detailed",
96+})
97+ : { value: directApiKey };
98+if (resolved.unresolvedRefReason) {
99+if (params.allowUnresolved) {
100+return undefined;
101+}
102+throw new Error(`${path}: ${resolved.unresolvedRefReason}`);
103+}
104+const resolvedValue = normalizeOptionalSecretInput(resolved.value);
105+const trimmed = resolvedValue ? normalizeApiKeyConfig(resolvedValue).trim() : "";
87106if (!trimmed) {
88107return undefined;
89108}
90109if (isKnownEnvApiKeyMarker(trimmed)) {
91-const envValue = normalizeOptionalSecretInput((params.env ?? process.env)[trimmed]);
110+const envValue = normalizeOptionalSecretInput(env[trimmed]);
92111return envValue;
93112}
94113return isNonSecretApiKeyMarker(trimmed) ? undefined : trimmed;
@@ -97,15 +116,17 @@ export async function resolveLmstudioConfiguredApiKey(params: {
97116if (!params.config) {
98117return undefined;
99118}
100-const path = params.path ?? "models.providers.lmstudio.apiKey";
101119const resolved = await resolveConfiguredSecretInputString({
102120config: params.config,
103-env: params.env ?? process.env,
121+ env,
104122value: apiKeyInput,
105123 path,
106124unresolvedReasonStyle: "detailed",
107125});
108126if (resolved.unresolvedRefReason) {
127+if (params.allowUnresolved) {
128+return undefined;
129+}
109130throw new Error(`${path}: ${resolved.unresolvedRefReason}`);
110131}
111132const resolvedValue = normalizeOptionalSecretInput(resolved.value);
@@ -205,6 +226,7 @@ export async function resolveLmstudioRuntimeApiKey(params: {
205226configuredApiKeyPromise ??= resolveLmstudioConfiguredApiKey({
206227 config,
207228env: params.env,
229+allowUnresolved: hasAuthorizationHeader,
208230});
209231return await configuredApiKeyPromise;
210232};
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。