
















@@ -25,6 +25,7 @@ import {
2525} from "./protocol.js";
2626import {
2727clearCodexAppServerBinding,
28+isCodexAppServerNativeAuthProfileId,
2829readCodexAppServerBinding,
2930writeCodexAppServerBinding,
3031type CodexAppServerThreadBinding,
@@ -57,19 +58,24 @@ export async function startOrResumeThread(params: {
5758await clearCodexAppServerBinding(params.params.sessionFile);
5859} else {
5960try {
61+const authProfileId = params.params.authProfileId ?? binding.authProfileId;
6062const response = assertCodexThreadResumeResponse(
6163await params.client.request(
6264"thread/resume",
6365buildThreadResumeParams(params.params, {
6466threadId: binding.threadId,
67+ authProfileId,
6568appServer: params.appServer,
6669developerInstructions: params.developerInstructions,
6770config: params.config,
6871}),
6972),
7073);
71-const boundAuthProfileId = params.params.authProfileId ?? binding.authProfileId;
72-const fallbackModelProvider = resolveCodexAppServerModelProvider(params.params.provider);
74+const boundAuthProfileId = authProfileId;
75+const fallbackModelProvider = resolveCodexAppServerModelProvider({
76+provider: params.params.provider,
77+authProfileId: boundAuthProfileId,
78+});
7379await writeCodexAppServerBinding(params.params.sessionFile, {
7480threadId: response.thread.id,
7581cwd: params.cwd,
@@ -112,7 +118,10 @@ export async function startOrResumeThread(params: {
112118}),
113119),
114120);
115-const modelProvider = resolveCodexAppServerModelProvider(params.params.provider);
121+const modelProvider = resolveCodexAppServerModelProvider({
122+provider: params.params.provider,
123+authProfileId: params.params.authProfileId,
124+});
116125const createdAt = new Date().toISOString();
117126await writeCodexAppServerBinding(params.params.sessionFile, {
118127threadId: response.thread.id,
@@ -147,7 +156,10 @@ export function buildThreadStartParams(
147156config?: JsonObject;
148157},
149158): CodexThreadStartParams {
150-const modelProvider = resolveCodexAppServerModelProvider(params.provider);
159+const modelProvider = resolveCodexAppServerModelProvider({
160+provider: params.provider,
161+authProfileId: params.authProfileId,
162+});
151163return {
152164model: params.modelId,
153165 ...(modelProvider ? { modelProvider } : {}),
@@ -169,12 +181,16 @@ export function buildThreadResumeParams(
169181params: EmbeddedRunAttemptParams,
170182options: {
171183threadId: string;
184+authProfileId?: string;
172185appServer: CodexAppServerRuntimeOptions;
173186developerInstructions?: string;
174187config?: JsonObject;
175188},
176189): CodexThreadResumeParams {
177-const modelProvider = resolveCodexAppServerModelProvider(params.provider);
190+const modelProvider = resolveCodexAppServerModelProvider({
191+provider: params.provider,
192+authProfileId: options.authProfileId ?? params.authProfileId,
193+});
178194return {
179195threadId: options.threadId,
180196model: params.modelId,
@@ -326,14 +342,28 @@ function buildUserInput(
326342];
327343}
328344329-function resolveCodexAppServerModelProvider(provider: string): string | undefined {
330-const normalized = provider.trim();
331-if (!normalized || normalized === "codex") {
345+function resolveCodexAppServerModelProvider(params: {
346+provider: string;
347+authProfileId?: string;
348+}): string | undefined {
349+const normalized = params.provider.trim();
350+const normalizedLower = normalized.toLowerCase();
351+if (!normalized || normalizedLower === "codex") {
332352// `codex` is OpenClaw's virtual provider; let Codex app-server keep its
333353// native provider/auth selection instead of forcing the legacy OpenAI path.
334354return undefined;
335355}
336-return normalized === "openai-codex" ? "openai" : normalized;
356+if (
357+isCodexAppServerNativeAuthProfileId(params.authProfileId) &&
358+(normalizedLower === "openai" || normalizedLower === "openai-codex")
359+) {
360+// When OpenClaw is forwarding ChatGPT/Codex OAuth, forcing the public
361+// OpenAI model provider makes app-server call api.openai.com without the
362+// ChatGPT bearer and fails with "Missing bearer or basic authentication".
363+// Omit the provider so app-server keeps its native account-backed route.
364+return undefined;
365+}
366+return normalizedLower === "openai-codex" ? "openai" : normalized;
337367}
338368339369// Modern Codex models (gpt-5.5, gpt-5.4, gpt-5.4-mini, gpt-5.2) use the
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。