@openclaw/codex 2026.5.10-beta.3 → 2026.5.10-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -163,10 +163,19 @@ function normalizeCodexAppServerBindingModelProvider(params) {
163
163
  function resolveCodexAppServerAuthProfileCredential(lookup) {
164
164
  const authProfileId = lookup.authProfileId?.trim();
165
165
  if (!authProfileId) return;
166
- return (lookup.authProfileStore ?? loadCodexAppServerAuthProfileStore(lookup.agentDir, lookup.config)).profiles[authProfileId];
166
+ return (lookup.authProfileStore ?? loadCodexAppServerAuthProfileStore({
167
+ agentDir: lookup.agentDir,
168
+ authProfileId,
169
+ config: lookup.config
170
+ })).profiles[authProfileId];
167
171
  }
168
- function loadCodexAppServerAuthProfileStore(agentDir, config) {
169
- return ensureAuthProfileStore(agentDir?.trim() || resolveDefaultAgentDir(config ?? {}), { allowKeychainPrompt: false });
172
+ function loadCodexAppServerAuthProfileStore(params) {
173
+ return ensureAuthProfileStore(params.agentDir?.trim() || resolveDefaultAgentDir(params.config ?? {}), {
174
+ allowKeychainPrompt: false,
175
+ config: params.config,
176
+ externalCliProviderIds: [CODEX_APP_SERVER_NATIVE_AUTH_PROVIDER],
177
+ externalCliProfileIds: [params.authProfileId]
178
+ });
170
179
  }
171
180
  function isCodexAppServerNativeAuthProvider(params) {
172
181
  const provider = params.provider?.trim();
@@ -6,11 +6,12 @@ import { createHash } from "node:crypto";
6
6
  import { constants, readFileSync } from "node:fs";
7
7
  import fs, { access } from "node:fs/promises";
8
8
  import path from "node:path";
9
- import { ensureAuthProfileStore, loadAuthProfileStoreForSecretsRuntime, resolveApiKeyForProfile, resolveAuthProfileOrder, resolveDefaultAgentDir, resolvePersistedAuthProfileOwnerAgentDir, resolveProviderIdForAuth, saveAuthProfileStore } from "openclaw/plugin-sdk/agent-runtime";
9
+ import { ensureAuthProfileStore, ensureAuthProfileStoreWithoutExternalProfiles, loadAuthProfileStoreForSecretsRuntime, refreshOAuthCredentialForRuntime, resolveApiKeyForProfile, resolveAuthProfileOrder, resolveDefaultAgentDir, resolvePersistedAuthProfileOwnerAgentDir, resolveProviderIdForAuth, saveAuthProfileStore } from "openclaw/plugin-sdk/agent-runtime";
10
10
  import { fileURLToPath } from "node:url";
11
11
  import { withTimeout } from "openclaw/plugin-sdk/security-runtime";
12
12
  //#region extensions/codex/src/app-server/auth-bridge.ts
13
13
  const CODEX_APP_SERVER_AUTH_PROVIDER = "openai-codex";
14
+ const OPENAI_PROVIDER = "openai";
14
15
  const OPENAI_CODEX_DEFAULT_PROFILE_ID = "openai-codex:default";
15
16
  const CODEX_HOME_ENV_VAR = "CODEX_HOME";
16
17
  const HOME_ENV_VAR = "HOME";
@@ -21,7 +22,11 @@ const CODEX_APP_SERVER_ISOLATION_ENV_VARS = [CODEX_HOME_ENV_VAR, HOME_ENV_VAR];
21
22
  async function bridgeCodexAppServerStartOptions(params) {
22
23
  if (params.startOptions.transport !== "stdio") return params.startOptions;
23
24
  const isolatedStartOptions = await withAgentCodexHomeEnvironment(params.startOptions, params.agentDir);
24
- const store = ensureAuthProfileStore(params.agentDir, { allowKeychainPrompt: false });
25
+ const store = ensureCodexAppServerAuthProfileStore({
26
+ agentDir: params.agentDir,
27
+ authProfileId: params.authProfileId,
28
+ config: params.config
29
+ });
25
30
  return shouldClearOpenAiApiKeyForCodexAuthProfile({
26
31
  store,
27
32
  authProfileId: resolveCodexAppServerAuthProfileId({
@@ -42,16 +47,53 @@ function resolveCodexAppServerAuthProfileId(params) {
42
47
  })[0]?.trim();
43
48
  }
44
49
  function resolveCodexAppServerAuthProfileIdForAgent(params) {
45
- const store = ensureAuthProfileStore(params.agentDir?.trim() || resolveDefaultAgentDir(params.config ?? {}), { allowKeychainPrompt: false });
50
+ const store = ensureCodexAppServerAuthProfileStore({
51
+ agentDir: params.agentDir?.trim() || resolveDefaultAgentDir(params.config ?? {}),
52
+ authProfileId: params.authProfileId,
53
+ config: params.config
54
+ });
46
55
  return resolveCodexAppServerAuthProfileId({
47
56
  authProfileId: params.authProfileId,
48
57
  store,
49
58
  config: params.config
50
59
  });
51
60
  }
61
+ function ensureCodexAppServerAuthProfileStore(params) {
62
+ return ensureAuthProfileStore(params.agentDir, {
63
+ allowKeychainPrompt: false,
64
+ config: params.config,
65
+ externalCliProviderIds: [CODEX_APP_SERVER_AUTH_PROVIDER],
66
+ ...params.authProfileId ? { externalCliProfileIds: [params.authProfileId] } : {}
67
+ });
68
+ }
69
+ function resolveCodexAppServerAuthProfileStore(params) {
70
+ const overlaidStore = ensureCodexAppServerAuthProfileStore({
71
+ agentDir: params.agentDir,
72
+ authProfileId: params.authProfileId,
73
+ config: params.config
74
+ });
75
+ if (!params.authProfileStore) return overlaidStore;
76
+ const order = params.authProfileStore.order || overlaidStore.order ? {
77
+ ...overlaidStore.order,
78
+ ...params.authProfileStore.order
79
+ } : void 0;
80
+ return {
81
+ ...params.authProfileStore,
82
+ ...order ? { order } : {},
83
+ profiles: {
84
+ ...overlaidStore.profiles,
85
+ ...params.authProfileStore.profiles
86
+ }
87
+ };
88
+ }
52
89
  async function resolveCodexAppServerAuthAccountCacheKey(params) {
53
90
  const agentDir = params.agentDir?.trim() || resolveDefaultAgentDir(params.config ?? {});
54
- const store = params.authProfileStore ?? ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false });
91
+ const store = resolveCodexAppServerAuthProfileStore({
92
+ agentDir,
93
+ authProfileId: params.authProfileId,
94
+ authProfileStore: params.authProfileStore,
95
+ config: params.config
96
+ });
55
97
  const profileId = resolveCodexAppServerAuthProfileId({
56
98
  authProfileId: params.authProfileId,
57
99
  store,
@@ -59,7 +101,7 @@ async function resolveCodexAppServerAuthAccountCacheKey(params) {
59
101
  });
60
102
  if (!profileId) return;
61
103
  const credential = store.profiles[profileId];
62
- if (!credential || !isCodexAppServerAuthProvider(credential.provider, params.config)) return;
104
+ if (!credential || !isCodexAppServerAuthProfileCredential(credential, params.config)) return;
63
105
  if (credential.type === "api_key") {
64
106
  const apiKey = (await resolveApiKeyForProfile({
65
107
  store,
@@ -165,7 +207,11 @@ async function refreshCodexAppServerAuthTokens(params) {
165
207
  };
166
208
  }
167
209
  async function resolveCodexAppServerAuthProfileLoginParamsInternal(params) {
168
- const store = ensureAuthProfileStore(params.agentDir, { allowKeychainPrompt: false });
210
+ const store = ensureCodexAppServerAuthProfileStore({
211
+ agentDir: params.agentDir,
212
+ authProfileId: params.authProfileId,
213
+ config: params.config
214
+ });
169
215
  const profileId = resolveCodexAppServerAuthProfileId({
170
216
  authProfileId: params.authProfileId,
171
217
  store,
@@ -174,7 +220,7 @@ async function resolveCodexAppServerAuthProfileLoginParamsInternal(params) {
174
220
  if (!profileId) return;
175
221
  const credential = store.profiles[profileId];
176
222
  if (!credential) throw new Error(`Codex app-server auth profile "${profileId}" was not found.`);
177
- if (!isCodexAppServerAuthProvider(credential.provider, params.config)) throw new Error(`Codex app-server auth profile "${profileId}" must belong to provider "openai-codex" or a supported alias.`);
223
+ if (!isCodexAppServerAuthProfileCredential(credential, params.config)) throw new Error(`Codex app-server auth profile "${profileId}" must be OpenAI Codex auth or an OpenAI API-key backup.`);
178
224
  const loginParams = await resolveLoginParamsForCredential(profileId, credential, {
179
225
  agentDir: params.agentDir,
180
226
  forceOAuthRefresh: params.forceOAuthRefresh === true,
@@ -227,10 +273,23 @@ async function resolveOAuthCredentialForCodexAppServer(profileId, credential, pa
227
273
  agentDir: params.agentDir,
228
274
  profileId
229
275
  });
230
- const store = ensureAuthProfileStore(ownerAgentDir, { allowKeychainPrompt: false });
276
+ const store = ensureCodexAppServerAuthProfileStore({
277
+ agentDir: ownerAgentDir,
278
+ authProfileId: profileId,
279
+ config: params.config
280
+ });
281
+ const persistedCredential = ensureAuthProfileStoreWithoutExternalProfiles(ownerAgentDir, { allowKeychainPrompt: false }).profiles[profileId];
282
+ const persistedOAuthCredential = persistedCredential?.type === "oauth" && isCodexAppServerAuthProvider(persistedCredential.provider, params.config) ? persistedCredential : void 0;
231
283
  const ownerCredential = store.profiles[profileId];
232
- const credentialForOwner = ownerCredential?.type === "oauth" && isCodexAppServerAuthProvider(ownerCredential.provider, params.config) ? ownerCredential : credential;
233
- if (params.forceRefresh) {
284
+ const overlaidOAuthCredential = ownerCredential?.type === "oauth" && isCodexAppServerAuthProvider(ownerCredential.provider, params.config) ? ownerCredential : void 0;
285
+ const credentialForOwner = persistedOAuthCredential ?? overlaidOAuthCredential ?? credential;
286
+ if (params.forceRefresh && !persistedOAuthCredential && overlaidOAuthCredential) {
287
+ const refreshedRuntimeCredential = await refreshOAuthCredentialForRuntime({ credential: overlaidOAuthCredential });
288
+ if (!refreshedRuntimeCredential?.access?.trim()) throw new Error(`Codex app-server auth profile "${profileId}" could not refresh.`);
289
+ store.profiles[profileId] = refreshedRuntimeCredential;
290
+ return refreshedRuntimeCredential;
291
+ }
292
+ if (params.forceRefresh && persistedOAuthCredential) {
234
293
  store.profiles[profileId] = {
235
294
  ...credentialForOwner,
236
295
  expires: 0
@@ -253,6 +312,12 @@ async function resolveOAuthCredentialForCodexAppServer(profileId, credential, pa
253
312
  function isCodexAppServerAuthProvider(provider, config) {
254
313
  return resolveProviderIdForAuth(provider, { config }) === CODEX_APP_SERVER_AUTH_PROVIDER;
255
314
  }
315
+ function isOpenAIApiKeyBackupCredential(credential, config) {
316
+ return credential.type === "api_key" && resolveProviderIdForAuth(credential.provider, { config }) === OPENAI_PROVIDER;
317
+ }
318
+ function isCodexAppServerAuthProfileCredential(credential, config) {
319
+ return isCodexAppServerAuthProvider(credential.provider, config) || isOpenAIApiKeyBackupCredential(credential, config);
320
+ }
256
321
  function shouldClearOpenAiApiKeyForCodexAuthProfile(params) {
257
322
  const profileId = params.authProfileId?.trim();
258
323
  return isCodexSubscriptionCredential(profileId ? params.store.profiles[profileId] : params.store.profiles[OPENAI_CODEX_DEFAULT_PROFILE_ID], params.config);
@@ -531,4 +596,4 @@ function clearSharedClientIfCurrent(client) {
531
596
  state.key = void 0;
532
597
  }
533
598
  //#endregion
534
- export { refreshCodexAppServerAuthTokens as a, resolveCodexAppServerAuthProfileIdForAgent as c, withTimeout$1 as i, resolveCodexAppServerEnvApiKeyCacheKey as l, getSharedCodexAppServerClient as n, resolveCodexAppServerAuthAccountCacheKey as o, shared_client_exports as r, resolveCodexAppServerAuthProfileId as s, clearSharedCodexAppServerClientIfCurrent as t, resolveCodexAppServerHomeDir as u };
599
+ export { withTimeout$1 as a, resolveCodexAppServerAuthProfileId as c, resolveCodexAppServerHomeDir as d, shared_client_exports as i, resolveCodexAppServerAuthProfileIdForAgent as l, createIsolatedCodexAppServerClient as n, refreshCodexAppServerAuthTokens as o, getSharedCodexAppServerClient as r, resolveCodexAppServerAuthAccountCacheKey as s, clearSharedCodexAppServerClientIfCurrent as t, resolveCodexAppServerEnvApiKeyCacheKey as u };