

























@@ -36,6 +36,7 @@ export async function bridgeCodexAppServerStartOptions(params: {
3636startOptions: CodexAppServerStartOptions;
3737agentDir: string;
3838authProfileId?: string;
39+config?: AuthProfileOrderConfig;
3940}): Promise<CodexAppServerStartOptions> {
4041if (params.startOptions.transport !== "stdio") {
4142return params.startOptions;
@@ -48,10 +49,12 @@ export async function bridgeCodexAppServerStartOptions(params: {
4849const authProfileId = resolveCodexAppServerAuthProfileId({
4950authProfileId: params.authProfileId,
5051 store,
52+config: params.config,
5153});
5254const shouldClearInheritedOpenAiApiKey = shouldClearOpenAiApiKeyForCodexAuthProfile({
5355 store,
5456 authProfileId,
57+config: params.config,
5558});
5659return shouldClearInheritedOpenAiApiKey
5760 ? withClearedEnvironmentVariables(isolatedStartOptions, CODEX_APP_SERVER_API_KEY_ENV_VARS)
@@ -139,10 +142,12 @@ export async function applyCodexAppServerAuthProfile(params: {
139142agentDir: string;
140143authProfileId?: string;
141144startOptions?: CodexAppServerStartOptions;
145+config?: AuthProfileOrderConfig;
142146}): Promise<void> {
143147const loginParams = await resolveCodexAppServerAuthProfileLoginParams({
144148agentDir: params.agentDir,
145149authProfileId: params.authProfileId,
150+config: params.config,
146151});
147152if (!loginParams) {
148153if (params.startOptions?.transport !== "stdio") {
@@ -164,13 +169,15 @@ export async function applyCodexAppServerAuthProfile(params: {
164169function resolveCodexAppServerAuthProfileLoginParams(params: {
165170agentDir: string;
166171authProfileId?: string;
172+config?: AuthProfileOrderConfig;
167173}): Promise<LoginAccountParams | undefined> {
168174return resolveCodexAppServerAuthProfileLoginParamsInternal(params);
169175}
170176171177export async function refreshCodexAppServerAuthTokens(params: {
172178agentDir: string;
173179authProfileId?: string;
180+config?: AuthProfileOrderConfig;
174181}): Promise<ChatgptAuthTokensRefreshResponse> {
175182const loginParams = await resolveCodexAppServerAuthProfileLoginParamsInternal({
176183 ...params,
@@ -190,11 +197,13 @@ async function resolveCodexAppServerAuthProfileLoginParamsInternal(params: {
190197agentDir: string;
191198authProfileId?: string;
192199forceOAuthRefresh?: boolean;
200+config?: AuthProfileOrderConfig;
193201}): Promise<LoginAccountParams | undefined> {
194202const store = ensureAuthProfileStore(params.agentDir, { allowKeychainPrompt: false });
195203const profileId = resolveCodexAppServerAuthProfileId({
196204authProfileId: params.authProfileId,
197205 store,
206+config: params.config,
198207});
199208if (!profileId) {
200209return undefined;
@@ -203,14 +212,15 @@ async function resolveCodexAppServerAuthProfileLoginParamsInternal(params: {
203212if (!credential) {
204213throw new Error(`Codex app-server auth profile "${profileId}" was not found.`);
205214}
206-if (!isCodexAppServerAuthProvider(credential.provider)) {
215+if (!isCodexAppServerAuthProvider(credential.provider, params.config)) {
207216throw new Error(
208217`Codex app-server auth profile "${profileId}" must belong to provider "openai-codex" or a supported alias.`,
209218);
210219}
211220const loginParams = await resolveLoginParamsForCredential(profileId, credential, {
212221agentDir: params.agentDir,
213222forceOAuthRefresh: params.forceOAuthRefresh === true,
223+config: params.config,
214224});
215225if (!loginParams) {
216226throw new Error(
@@ -240,7 +250,7 @@ async function resolveCodexAppServerEnvApiKeyLoginParams(params: {
240250async function resolveLoginParamsForCredential(
241251profileId: string,
242252credential: AuthProfileCredential,
243-params: { agentDir: string; forceOAuthRefresh: boolean },
253+params: { agentDir: string; forceOAuthRefresh: boolean; config?: AuthProfileOrderConfig },
244254): Promise<LoginAccountParams | undefined> {
245255if (credential.type === "api_key") {
246256const resolved = await resolveApiKeyForProfile({
@@ -265,6 +275,7 @@ async function resolveLoginParamsForCredential(
265275const resolvedCredential = await resolveOAuthCredentialForCodexAppServer(profileId, credential, {
266276agentDir: params.agentDir,
267277forceRefresh: params.forceOAuthRefresh,
278+config: params.config,
268279});
269280const accessToken = resolvedCredential.access?.trim();
270281return accessToken
@@ -275,7 +286,7 @@ async function resolveLoginParamsForCredential(
275286async function resolveOAuthCredentialForCodexAppServer(
276287profileId: string,
277288credential: OAuthCredential,
278-params: { agentDir: string; forceRefresh: boolean },
289+params: { agentDir: string; forceRefresh: boolean; config?: AuthProfileOrderConfig },
279290): Promise<OAuthCredential> {
280291const ownerAgentDir = resolvePersistedAuthProfileOwnerAgentDir({
281292agentDir: params.agentDir,
@@ -284,7 +295,8 @@ async function resolveOAuthCredentialForCodexAppServer(
284295const store = ensureAuthProfileStore(ownerAgentDir, { allowKeychainPrompt: false });
285296const ownerCredential = store.profiles[profileId];
286297const credentialForOwner =
287-ownerCredential?.type === "oauth" && isCodexAppServerAuthProvider(ownerCredential.provider)
298+ownerCredential?.type === "oauth" &&
299+isCodexAppServerAuthProvider(ownerCredential.provider, params.config)
288300 ? ownerCredential
289301 : credential;
290302if (params.forceRefresh) {
@@ -299,32 +311,36 @@ async function resolveOAuthCredentialForCodexAppServer(
299311const refreshed = loadAuthProfileStoreForSecretsRuntime(ownerAgentDir).profiles[profileId];
300312const storedCredential = store.profiles[profileId];
301313const candidate =
302-refreshed?.type === "oauth" && isCodexAppServerAuthProvider(refreshed.provider)
314+refreshed?.type === "oauth" && isCodexAppServerAuthProvider(refreshed.provider, params.config)
303315 ? refreshed
304316 : storedCredential?.type === "oauth" &&
305-isCodexAppServerAuthProvider(storedCredential.provider)
317+isCodexAppServerAuthProvider(storedCredential.provider, params.config)
306318 ? storedCredential
307319 : credential;
308320return resolved?.apiKey ? { ...candidate, access: resolved.apiKey } : candidate;
309321}
310322311-function isCodexAppServerAuthProvider(provider: string): boolean {
312-return resolveProviderIdForAuth(provider) === CODEX_APP_SERVER_AUTH_PROVIDER;
323+function isCodexAppServerAuthProvider(provider: string, config?: AuthProfileOrderConfig): boolean {
324+return resolveProviderIdForAuth(provider, { config }) === CODEX_APP_SERVER_AUTH_PROVIDER;
313325}
314326315327function shouldClearOpenAiApiKeyForCodexAuthProfile(params: {
316328store: ReturnType<typeof ensureAuthProfileStore>;
317329authProfileId?: string;
330+config?: AuthProfileOrderConfig;
318331}): boolean {
319332const profileId = params.authProfileId?.trim();
320333const credential = profileId
321334 ? params.store.profiles[profileId]
322335 : params.store.profiles[OPENAI_CODEX_DEFAULT_PROFILE_ID];
323-return isCodexSubscriptionCredential(credential);
336+return isCodexSubscriptionCredential(credential, params.config);
324337}
325338326-function isCodexSubscriptionCredential(credential: AuthProfileCredential | undefined): boolean {
327-if (!credential || !isCodexAppServerAuthProvider(credential.provider)) {
339+function isCodexSubscriptionCredential(
340+credential: AuthProfileCredential | undefined,
341+config?: AuthProfileOrderConfig,
342+): boolean {
343+if (!credential || !isCodexAppServerAuthProvider(credential.provider, config)) {
328344return false;
329345}
330346return credential.type === "oauth" || credential.type === "token";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。