@iam-brain/opencode-codex-auth 0.1.6 → 0.1.8
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.
- package/README.md +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/codex-native.d.ts +6 -2
- package/dist/lib/codex-native.d.ts.map +1 -1
- package/dist/lib/codex-native.js +140 -34
- package/dist/lib/codex-native.js.map +1 -1
- package/dist/lib/config.d.ts +8 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +181 -4
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/fetch-orchestrator.d.ts +5 -0
- package/dist/lib/fetch-orchestrator.d.ts.map +1 -1
- package/dist/lib/fetch-orchestrator.js +20 -2
- package/dist/lib/fetch-orchestrator.js.map +1 -1
- package/dist/lib/installer-cli.d.ts.map +1 -1
- package/dist/lib/installer-cli.js +5 -1
- package/dist/lib/installer-cli.js.map +1 -1
- package/dist/lib/paths.d.ts +8 -0
- package/dist/lib/paths.d.ts.map +1 -1
- package/dist/lib/paths.js +29 -2
- package/dist/lib/paths.js.map +1 -1
- package/dist/lib/personality-skill.d.ts +17 -0
- package/dist/lib/personality-skill.d.ts.map +1 -0
- package/dist/lib/personality-skill.js +136 -0
- package/dist/lib/personality-skill.js.map +1 -0
- package/dist/lib/rotation.d.ts.map +1 -1
- package/dist/lib/rotation.js +64 -73
- package/dist/lib/rotation.js.map +1 -1
- package/dist/lib/session-affinity.d.ts +26 -0
- package/dist/lib/session-affinity.d.ts.map +1 -0
- package/dist/lib/session-affinity.js +166 -0
- package/dist/lib/session-affinity.js.map +1 -0
- package/package.json +1 -1
- package/schemas/codex-config.schema.json +7 -0
package/README.md
CHANGED
|
@@ -54,12 +54,14 @@ The installer does two things:
|
|
|
54
54
|
- `Codex Compact.md.disabled`
|
|
55
55
|
3. Creates `~/.config/opencode/codex-config.json` with defaults when missing.
|
|
56
56
|
4. Synchronizes `~/.config/opencode/commands/create-personality.md` for `/create-personality` (created/updated as needed).
|
|
57
|
+
5. Synchronizes `~/.config/opencode/skills/personality-builder/SKILL.md` (plus references) for skill-driven personality workflows.
|
|
57
58
|
|
|
58
59
|
At plugin startup, files are reconciled against runtime mode:
|
|
59
60
|
|
|
60
61
|
- `mode: "collab"` -> `.md.disabled` files are activated to `.md`
|
|
61
62
|
- `mode: "native"` or `mode: "codex"` -> Codex agents are disabled to `.md.disabled`
|
|
62
63
|
- `/create-personality` command template is synchronized to the latest managed version.
|
|
64
|
+
- `personality-builder` skill template bundle is synchronized to the latest managed version.
|
|
63
65
|
|
|
64
66
|
To install only the agent templates (no `opencode.json` edits):
|
|
65
67
|
|
|
@@ -102,6 +104,8 @@ Create guided custom personalities with:
|
|
|
102
104
|
|
|
103
105
|
- Provider auth marker: `~/.local/share/opencode/auth.json`
|
|
104
106
|
- Plugin multi-account store: `~/.config/opencode/codex-accounts.json`
|
|
107
|
+
- Session affinity cache: `~/.config/opencode/cache/codex-session-affinity.json`
|
|
108
|
+
- Quota snapshot cache: `~/.config/opencode/cache/codex-snapshots.json`
|
|
105
109
|
|
|
106
110
|
Legacy sources can be imported explicitly from the auth menu:
|
|
107
111
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAyCjD,eAAO,MAAM,qBAAqB,EAAE,MA6LnC,CAAA;AAED,eAAe,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { tool } from "@opencode-ai/plugin";
|
|
2
2
|
import { listAccountsForTools, removeAccountByIndex, switchAccountByIndex, toggleAccountEnabledByIndex } from "./lib/accounts-tools";
|
|
3
3
|
import { CodexAuthPlugin, refreshAccessToken } from "./lib/codex-native";
|
|
4
|
-
import { ensureDefaultConfigFile, getCompatInputSanitizerEnabled, getCustomSettings, getDebugEnabled, getHeaderSnapshotsEnabled, getMode, getPidOffsetEnabled, getPersonality, getProactiveRefreshBufferMs, getProactiveRefreshEnabled, getSpoofMode, getQuietMode, loadConfigFile, resolveConfig } from "./lib/config";
|
|
4
|
+
import { ensureDefaultConfigFile, getCompatInputSanitizerEnabled, getCustomSettings, getDebugEnabled, getHeaderTransformDebugEnabled, getHeaderSnapshotsEnabled, getMode, getRotationStrategy, getPidOffsetEnabled, getPersonality, getProactiveRefreshBufferMs, getProactiveRefreshEnabled, getSpoofMode, getQuietMode, loadConfigFile, resolveConfig } from "./lib/config";
|
|
5
5
|
import { createLogger } from "./lib/logger";
|
|
6
6
|
import { reconcileOrchestratorAgentsState } from "./lib/orchestrator-agents";
|
|
7
7
|
import { generatePersonaSpec } from "./lib/persona-tool";
|
|
8
8
|
import { createPersonalityFile } from "./lib/personality-create";
|
|
9
9
|
import { installCreatePersonalityCommand } from "./lib/personality-command";
|
|
10
|
+
import { installPersonalityBuilderSkill } from "./lib/personality-skill";
|
|
10
11
|
import { runOneProactiveRefreshTick } from "./lib/proactive-refresh";
|
|
11
12
|
import { toolOutputForStatus } from "./lib/codex-status-tool";
|
|
12
13
|
import { requireOpenAIMultiOauthAuth, saveAuthStorage } from "./lib/storage";
|
|
@@ -19,6 +20,7 @@ export const OpenAIMultiAuthPlugin = async (input) => {
|
|
|
19
20
|
}
|
|
20
21
|
await ensureDefaultConfigFile({ env: process.env }).catch(() => { });
|
|
21
22
|
await installCreatePersonalityCommand({ force: true }).catch(() => { });
|
|
23
|
+
await installPersonalityBuilderSkill({ force: true }).catch(() => { });
|
|
22
24
|
const cfg = resolveConfig({
|
|
23
25
|
env: process.env,
|
|
24
26
|
file: loadConfigFile({ env: process.env })
|
|
@@ -66,9 +68,11 @@ export const OpenAIMultiAuthPlugin = async (input) => {
|
|
|
66
68
|
mode: runtimeMode,
|
|
67
69
|
quietMode: getQuietMode(cfg),
|
|
68
70
|
pidOffsetEnabled: getPidOffsetEnabled(cfg),
|
|
71
|
+
rotationStrategy: getRotationStrategy(cfg),
|
|
69
72
|
spoofMode: getSpoofMode(cfg),
|
|
70
73
|
compatInputSanitizer: getCompatInputSanitizerEnabled(cfg),
|
|
71
74
|
headerSnapshots: getHeaderSnapshotsEnabled(cfg),
|
|
75
|
+
headerTransformDebug: getHeaderTransformDebugEnabled(cfg),
|
|
72
76
|
customSettings: getCustomSettings(cfg)
|
|
73
77
|
});
|
|
74
78
|
const z = tool.schema;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAE1C,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,2BAA2B,EAC5B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EACL,uBAAuB,EACvB,8BAA8B,EAC9B,iBAAiB,EACjB,eAAe,EACf,yBAAyB,EACzB,OAAO,EACP,mBAAmB,EACnB,cAAc,EACd,2BAA2B,EAC3B,0BAA0B,EAC1B,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,aAAa,EACd,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAChE,O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C3B,QAAQ,EAAE,SAAS,CAAC,cAAc;qBACnC,CAAC,CAAA;oBACF,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,CAAA;oBAC3D,OAAO,GAAG,MAAM,iBAAiB,MAAM,CAAC,GAAG,QAAQ,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,KAAK,cAAc,SAAS,CAAC,cAAc,EAAE,CAAA;gBAC7H,CAAC;gBAED,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC;oBACzC,GAAG,IAAI;oBACP,IAAI;oBACJ,WAAW,EAAE,KAAK,CAAC,QAAQ;iBAC5B,CAAC,CAAA;gBACF,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,CAAA;gBAC3D,OAAO,GAAG,MAAM,iBAAiB,MAAM,CAAC,GAAG,QAAQ,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,KAAK,GAAG,CAAA;YACxF,CAAC;SACF,CAAC;KACH,CAAA;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,eAAe,qBAAqB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Hooks, PluginInput } from "@opencode-ai/plugin";
|
|
2
2
|
import { type IdTokenClaims } from "./claims";
|
|
3
3
|
import type { Logger } from "./logger";
|
|
4
|
-
import type { AccountRecord, OpenAIAuthMode, OpenAIOAuthDomain } from "./types";
|
|
4
|
+
import type { AccountRecord, OpenAIAuthMode, OpenAIOAuthDomain, RotationStrategy } from "./types";
|
|
5
5
|
import type { CodexSpoofMode, CustomSettings, PersonalityOption, PluginRuntimeMode } from "./config";
|
|
6
6
|
type BrowserOpenInvocation = {
|
|
7
7
|
command: string;
|
|
@@ -39,6 +39,7 @@ export declare const __testOnly: {
|
|
|
39
39
|
resolveHookAgentName: typeof resolveHookAgentName;
|
|
40
40
|
resolveCollaborationModeKind: typeof resolveCollaborationModeKind;
|
|
41
41
|
resolveSubagentHeaderValue: typeof resolveSubagentHeaderValue;
|
|
42
|
+
isOAuthDebugEnabled: typeof isOAuthDebugEnabled;
|
|
42
43
|
stopOAuthServer: typeof stopOAuthServer;
|
|
43
44
|
};
|
|
44
45
|
export declare function refreshAccessToken(refreshToken: string): Promise<TokenResponse>;
|
|
@@ -48,10 +49,11 @@ declare function composeCodexSuccessRedirectUrl(tokens: TokenResponse, options?:
|
|
|
48
49
|
}): string;
|
|
49
50
|
declare function buildOAuthSuccessHtml(mode?: CodexSpoofMode): string;
|
|
50
51
|
declare function buildOAuthErrorHtml(error: string): string;
|
|
52
|
+
declare function isOAuthDebugEnabled(): boolean;
|
|
51
53
|
declare function stopOAuthServer(): void;
|
|
52
54
|
declare function modeForRuntimeMode(runtimeMode: PluginRuntimeMode): OpenAIAuthMode;
|
|
53
55
|
export declare function upsertAccount(openai: OpenAIOAuthDomain, incoming: AccountRecord): AccountRecord;
|
|
54
|
-
type CodexOriginator = "codex_cli_rs" | "codex_exec";
|
|
56
|
+
type CodexOriginator = "opencode" | "codex_cli_rs" | "codex_exec";
|
|
55
57
|
declare function buildCodexUserAgent(originator: CodexOriginator): string;
|
|
56
58
|
declare function resolveRequestUserAgent(spoofMode: CodexSpoofMode, originator: CodexOriginator): string;
|
|
57
59
|
type CodexCollaborationModeKind = "plan" | "code" | "execute" | "pair_programming";
|
|
@@ -65,9 +67,11 @@ export type CodexAuthPluginOptions = {
|
|
|
65
67
|
mode?: PluginRuntimeMode;
|
|
66
68
|
quietMode?: boolean;
|
|
67
69
|
pidOffsetEnabled?: boolean;
|
|
70
|
+
rotationStrategy?: RotationStrategy;
|
|
68
71
|
spoofMode?: CodexSpoofMode;
|
|
69
72
|
compatInputSanitizer?: boolean;
|
|
70
73
|
headerSnapshots?: boolean;
|
|
74
|
+
headerTransformDebug?: boolean;
|
|
71
75
|
};
|
|
72
76
|
export declare function CodexAuthPlugin(input: PluginInput, opts?: CodexAuthPluginOptions): Promise<Hooks>;
|
|
73
77
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-native.d.ts","sourceRoot":"","sources":["../../lib/codex-native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAS7D,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,UAAU,CAAA;AAuBjB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,KAAK,EAEV,aAAa,EAEb,cAAc,EACd,iBAAiB,
|
|
1
|
+
{"version":3,"file":"codex-native.d.ts","sourceRoot":"","sources":["../../lib/codex-native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAS7D,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,UAAU,CAAA;AAuBjB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,KAAK,EAEV,aAAa,EAEb,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAA;AAyFjB,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,EAAE,CAAA;CACf,CAAA;AAED,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC3C,qBAAqB,CAQvB;AAED,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,MAAM,EACX,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,OAAO,CAAC,CAoBlB;AAWD,KAAK,SAAS,GAAG;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EA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"}
|
package/dist/lib/codex-native.js
CHANGED
|
@@ -9,7 +9,7 @@ import { CodexStatus } from "./codex-status";
|
|
|
9
9
|
import { saveSnapshots } from "./codex-status-storage";
|
|
10
10
|
import { PluginFatalError, formatWaitTime, isPluginFatalError, toSyntheticErrorResponse } from "./fatal-errors";
|
|
11
11
|
import { buildIdentityKey, ensureIdentityKey, normalizeEmail, normalizePlan } from "./identity";
|
|
12
|
-
import { defaultSnapshotsPath } from "./paths";
|
|
12
|
+
import { defaultSessionAffinityPath, defaultSnapshotsPath } from "./paths";
|
|
13
13
|
import { createStickySessionState, selectAccount } from "./rotation";
|
|
14
14
|
import { ensureOpenAIOAuthDomain, getOpenAIOAuthDomain, importLegacyInstallData, listOpenAIOAuthDomains, loadAuthStorage, saveAuthStorage, setAccountCooldown, shouldOfferLegacyTransfer } from "./storage";
|
|
15
15
|
import { toolOutputForStatus } from "./codex-status-tool";
|
|
@@ -22,6 +22,7 @@ import { sanitizeRequestPayloadForCompat } from "./compat-sanitizer";
|
|
|
22
22
|
import { fetchQuotaSnapshotFromBackend } from "./codex-quota-fetch";
|
|
23
23
|
import { createRequestSnapshots } from "./request-snapshots";
|
|
24
24
|
import { CODEX_OAUTH_SUCCESS_HTML } from "./oauth-pages";
|
|
25
|
+
import { createSessionExistsFn, loadSessionAffinity, pruneSessionAffinitySnapshot, readSessionAffinitySnapshot, saveSessionAffinity, writeSessionAffinitySnapshot } from "./session-affinity";
|
|
25
26
|
const CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
26
27
|
const ISSUER = "https://auth.openai.com";
|
|
27
28
|
const CODEX_API_ENDPOINT = "https://chatgpt.com/backend-api/codex/responses";
|
|
@@ -192,6 +193,7 @@ export const __testOnly = {
|
|
|
192
193
|
resolveHookAgentName,
|
|
193
194
|
resolveCollaborationModeKind,
|
|
194
195
|
resolveSubagentHeaderValue,
|
|
196
|
+
isOAuthDebugEnabled,
|
|
195
197
|
stopOAuthServer
|
|
196
198
|
};
|
|
197
199
|
async function exchangeCodeForTokens(code, redirectUri, pkce) {
|
|
@@ -373,7 +375,8 @@ let oauthServer;
|
|
|
373
375
|
let pendingOAuth;
|
|
374
376
|
let oauthServerCloseTimer;
|
|
375
377
|
function isOAuthDebugEnabled() {
|
|
376
|
-
|
|
378
|
+
const raw = process.env.CODEX_AUTH_DEBUG?.trim().toLowerCase();
|
|
379
|
+
return raw === "1" || raw === "true" || raw === "yes" || raw === "on";
|
|
377
380
|
}
|
|
378
381
|
function emitOAuthDebug(event, meta = {}) {
|
|
379
382
|
if (!isOAuthDebugEnabled())
|
|
@@ -680,7 +683,8 @@ function rewriteUrl(requestInput) {
|
|
|
680
683
|
return parsed;
|
|
681
684
|
}
|
|
682
685
|
function opencodeUserAgent() {
|
|
683
|
-
|
|
686
|
+
const version = resolvePluginVersion();
|
|
687
|
+
return `opencode/${version} (${os.platform()} ${os.release()}; ${os.arch()})`;
|
|
684
688
|
}
|
|
685
689
|
let cachedPluginVersion;
|
|
686
690
|
let cachedMacProductVersion;
|
|
@@ -858,6 +862,8 @@ function resolveCodexPlatformSignature(platform = process.platform) {
|
|
|
858
862
|
return `${platform} ${os.release()}; ${architecture}`;
|
|
859
863
|
}
|
|
860
864
|
function buildCodexUserAgent(originator) {
|
|
865
|
+
if (originator === "opencode")
|
|
866
|
+
return opencodeUserAgent();
|
|
861
867
|
const buildVersion = resolvePluginVersion();
|
|
862
868
|
const terminalToken = resolveTerminalUserAgentToken();
|
|
863
869
|
const prefix = `${originator}/${buildVersion} (${resolveCodexPlatformSignature()}) ${terminalToken}`;
|
|
@@ -1017,7 +1023,7 @@ function isTuiWorkerInvocation(argv) {
|
|
|
1017
1023
|
}
|
|
1018
1024
|
function resolveCodexOriginator(spoofMode, argv = process.argv) {
|
|
1019
1025
|
if (spoofMode !== "codex")
|
|
1020
|
-
return "
|
|
1026
|
+
return "opencode";
|
|
1021
1027
|
const normalizedArgv = argv.map((entry) => String(entry));
|
|
1022
1028
|
if (isTuiWorkerInvocation(normalizedArgv))
|
|
1023
1029
|
return "codex_cli_rs";
|
|
@@ -1152,7 +1158,7 @@ function hydrateAccountIdentityFromAccessClaims(account) {
|
|
|
1152
1158
|
ensureAccountAuthTypes(account);
|
|
1153
1159
|
ensureIdentityKey(account);
|
|
1154
1160
|
}
|
|
1155
|
-
async function selectCatalogAuthCandidate(authMode, pidOffsetEnabled) {
|
|
1161
|
+
async function selectCatalogAuthCandidate(authMode, pidOffsetEnabled, rotationStrategy) {
|
|
1156
1162
|
try {
|
|
1157
1163
|
const auth = await loadAuthStorage();
|
|
1158
1164
|
const domain = getOpenAIOAuthDomain(auth, authMode);
|
|
@@ -1161,7 +1167,7 @@ async function selectCatalogAuthCandidate(authMode, pidOffsetEnabled) {
|
|
|
1161
1167
|
}
|
|
1162
1168
|
const selected = selectAccount({
|
|
1163
1169
|
accounts: domain.accounts,
|
|
1164
|
-
strategy: domain.strategy,
|
|
1170
|
+
strategy: rotationStrategy ?? domain.strategy,
|
|
1165
1171
|
activeIdentityKey: domain.activeIdentityKey,
|
|
1166
1172
|
now: Date.now(),
|
|
1167
1173
|
stickyPidOffset: pidOffsetEnabled
|
|
@@ -1195,6 +1201,14 @@ function asStringArray(value) {
|
|
|
1195
1201
|
return undefined;
|
|
1196
1202
|
return value.filter((item) => typeof item === "string" && item.trim().length > 0);
|
|
1197
1203
|
}
|
|
1204
|
+
function normalizeReasoningSummaryOption(value) {
|
|
1205
|
+
const normalized = asString(value)?.toLowerCase();
|
|
1206
|
+
if (!normalized || normalized === "none")
|
|
1207
|
+
return undefined;
|
|
1208
|
+
if (normalized === "auto" || normalized === "concise" || normalized === "detailed")
|
|
1209
|
+
return normalized;
|
|
1210
|
+
return undefined;
|
|
1211
|
+
}
|
|
1198
1212
|
function readModelRuntimeDefaults(options) {
|
|
1199
1213
|
const raw = options.codexRuntimeDefaults;
|
|
1200
1214
|
if (!isRecord(raw))
|
|
@@ -1203,6 +1217,7 @@ function readModelRuntimeDefaults(options) {
|
|
|
1203
1217
|
applyPatchToolType: asString(raw.applyPatchToolType),
|
|
1204
1218
|
defaultReasoningEffort: asString(raw.defaultReasoningEffort),
|
|
1205
1219
|
supportsReasoningSummaries: typeof raw.supportsReasoningSummaries === "boolean" ? raw.supportsReasoningSummaries : undefined,
|
|
1220
|
+
reasoningSummaryFormat: asString(raw.reasoningSummaryFormat),
|
|
1206
1221
|
defaultVerbosity: raw.defaultVerbosity === "low" || raw.defaultVerbosity === "medium" || raw.defaultVerbosity === "high"
|
|
1207
1222
|
? raw.defaultVerbosity
|
|
1208
1223
|
: undefined,
|
|
@@ -1349,14 +1364,31 @@ function applyCodexRuntimeDefaultsToParams(input) {
|
|
|
1349
1364
|
}
|
|
1350
1365
|
const reasoningEffort = asString(options.reasoningEffort);
|
|
1351
1366
|
const hasReasoning = reasoningEffort !== undefined && reasoningEffort !== "none";
|
|
1352
|
-
const
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1367
|
+
const rawReasoningSummary = asString(options.reasoningSummary);
|
|
1368
|
+
const hadExplicitReasoningSummary = rawReasoningSummary !== undefined;
|
|
1369
|
+
const currentReasoningSummary = normalizeReasoningSummaryOption(rawReasoningSummary);
|
|
1370
|
+
if (rawReasoningSummary !== undefined) {
|
|
1371
|
+
if (currentReasoningSummary) {
|
|
1372
|
+
options.reasoningSummary = currentReasoningSummary;
|
|
1356
1373
|
}
|
|
1357
|
-
else
|
|
1374
|
+
else {
|
|
1375
|
+
delete options.reasoningSummary;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
if (!hadExplicitReasoningSummary && currentReasoningSummary === undefined) {
|
|
1379
|
+
if (hasReasoning &&
|
|
1358
1380
|
(defaults.supportsReasoningSummaries === true || input.thinkingSummariesOverride === true)) {
|
|
1359
|
-
|
|
1381
|
+
if (input.thinkingSummariesOverride === false) {
|
|
1382
|
+
delete options.reasoningSummary;
|
|
1383
|
+
}
|
|
1384
|
+
else {
|
|
1385
|
+
if (defaults.reasoningSummaryFormat?.toLowerCase() === "none") {
|
|
1386
|
+
delete options.reasoningSummary;
|
|
1387
|
+
}
|
|
1388
|
+
else {
|
|
1389
|
+
options.reasoningSummary = defaults.reasoningSummaryFormat ?? "auto";
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1360
1392
|
}
|
|
1361
1393
|
}
|
|
1362
1394
|
if (asString(options.textVerbosity) === undefined &&
|
|
@@ -1371,7 +1403,8 @@ function applyCodexRuntimeDefaultsToParams(input) {
|
|
|
1371
1403
|
options.parallelToolCalls = input.modelToolCallCapable;
|
|
1372
1404
|
}
|
|
1373
1405
|
const shouldIncludeReasoning = hasReasoning &&
|
|
1374
|
-
((asString(options.reasoningSummary) !== undefined &&
|
|
1406
|
+
((asString(options.reasoningSummary) !== undefined &&
|
|
1407
|
+
asString(options.reasoningSummary)?.toLowerCase() !== "none") ||
|
|
1375
1408
|
defaults.supportsReasoningSummaries === true);
|
|
1376
1409
|
if (shouldIncludeReasoning) {
|
|
1377
1410
|
const include = asStringArray(options.include) ?? [];
|
|
@@ -1434,7 +1467,7 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
1434
1467
|
};
|
|
1435
1468
|
};
|
|
1436
1469
|
const requestSnapshots = createRequestSnapshots({
|
|
1437
|
-
enabled: opts.headerSnapshots === true,
|
|
1470
|
+
enabled: opts.headerSnapshots === true || opts.headerTransformDebug === true,
|
|
1438
1471
|
log: opts.log
|
|
1439
1472
|
});
|
|
1440
1473
|
const showToast = async (message, variant = "info", quietMode = false) => {
|
|
@@ -1730,7 +1763,37 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
1730
1763
|
}
|
|
1731
1764
|
if (!hasOAuth)
|
|
1732
1765
|
return {};
|
|
1733
|
-
const
|
|
1766
|
+
const sessionAffinityPath = defaultSessionAffinityPath();
|
|
1767
|
+
const loadedSessionAffinity = await loadSessionAffinity(sessionAffinityPath).catch(() => ({ version: 1 }));
|
|
1768
|
+
const initialSessionAffinity = readSessionAffinitySnapshot(loadedSessionAffinity, authMode);
|
|
1769
|
+
const sessionExists = createSessionExistsFn(process.env);
|
|
1770
|
+
await pruneSessionAffinitySnapshot(initialSessionAffinity, sessionExists).catch(() => 0);
|
|
1771
|
+
const orchestratorState = createFetchOrchestratorState();
|
|
1772
|
+
orchestratorState.seenSessionKeys = initialSessionAffinity.seenSessionKeys;
|
|
1773
|
+
const stickySessionState = createStickySessionState();
|
|
1774
|
+
stickySessionState.bySessionKey = initialSessionAffinity.stickyBySessionKey;
|
|
1775
|
+
const hybridSessionState = createStickySessionState();
|
|
1776
|
+
hybridSessionState.bySessionKey = initialSessionAffinity.hybridBySessionKey;
|
|
1777
|
+
let sessionAffinityPersistQueue = Promise.resolve();
|
|
1778
|
+
const persistSessionAffinityState = () => {
|
|
1779
|
+
sessionAffinityPersistQueue = sessionAffinityPersistQueue
|
|
1780
|
+
.then(async () => {
|
|
1781
|
+
await pruneSessionAffinitySnapshot({
|
|
1782
|
+
seenSessionKeys: orchestratorState.seenSessionKeys,
|
|
1783
|
+
stickyBySessionKey: stickySessionState.bySessionKey,
|
|
1784
|
+
hybridBySessionKey: hybridSessionState.bySessionKey
|
|
1785
|
+
}, sessionExists);
|
|
1786
|
+
await saveSessionAffinity(async (current) => writeSessionAffinitySnapshot(current, authMode, {
|
|
1787
|
+
seenSessionKeys: orchestratorState.seenSessionKeys,
|
|
1788
|
+
stickyBySessionKey: stickySessionState.bySessionKey,
|
|
1789
|
+
hybridBySessionKey: hybridSessionState.bySessionKey
|
|
1790
|
+
}), sessionAffinityPath);
|
|
1791
|
+
})
|
|
1792
|
+
.catch(() => {
|
|
1793
|
+
// best-effort persistence
|
|
1794
|
+
});
|
|
1795
|
+
};
|
|
1796
|
+
const catalogAuth = await selectCatalogAuthCandidate(authMode, opts.pidOffsetEnabled === true, opts.rotationStrategy);
|
|
1734
1797
|
const catalogModels = await getCodexModelCatalog({
|
|
1735
1798
|
accessToken: catalogAuth.accessToken,
|
|
1736
1799
|
accountId: catalogAuth.accountId,
|
|
@@ -1743,23 +1806,47 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
1743
1806
|
fallbackModels: STATIC_FALLBACK_MODELS,
|
|
1744
1807
|
personality: opts.personality
|
|
1745
1808
|
});
|
|
1746
|
-
const orchestratorState = createFetchOrchestratorState();
|
|
1747
|
-
const stickySessionState = createStickySessionState();
|
|
1748
1809
|
return {
|
|
1749
1810
|
apiKey: OAUTH_DUMMY_KEY,
|
|
1750
1811
|
async fetch(requestInput, init) {
|
|
1751
1812
|
const baseRequest = new Request(requestInput, init);
|
|
1813
|
+
const inboundCollaborationModeKind = baseRequest.headers.get(INTERNAL_COLLABORATION_MODE_HEADER) ?? undefined;
|
|
1814
|
+
if (opts.headerTransformDebug === true) {
|
|
1815
|
+
await requestSnapshots.captureRequest("before-header-transform", baseRequest, {
|
|
1816
|
+
spoofMode,
|
|
1817
|
+
...(inboundCollaborationModeKind
|
|
1818
|
+
? { collaborationModeKind: inboundCollaborationModeKind }
|
|
1819
|
+
: {})
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1752
1822
|
const outbound = new Request(rewriteUrl(baseRequest), baseRequest);
|
|
1753
1823
|
const inboundOriginator = outbound.headers.get("originator")?.trim();
|
|
1754
|
-
const outboundOriginator = inboundOriginator === "
|
|
1824
|
+
const outboundOriginator = inboundOriginator === "opencode" ||
|
|
1825
|
+
inboundOriginator === "codex_exec" ||
|
|
1826
|
+
inboundOriginator === "codex_cli_rs"
|
|
1755
1827
|
? inboundOriginator
|
|
1756
1828
|
: resolveCodexOriginator(spoofMode);
|
|
1757
1829
|
outbound.headers.set("originator", outboundOriginator);
|
|
1758
|
-
outbound.headers.
|
|
1830
|
+
const inboundUserAgent = outbound.headers.get("user-agent")?.trim();
|
|
1831
|
+
if (spoofMode === "native" && inboundUserAgent) {
|
|
1832
|
+
outbound.headers.set("user-agent", inboundUserAgent);
|
|
1833
|
+
}
|
|
1834
|
+
else {
|
|
1835
|
+
outbound.headers.set("user-agent", resolveRequestUserAgent(spoofMode, outboundOriginator));
|
|
1836
|
+
}
|
|
1759
1837
|
const collaborationModeKind = outbound.headers.get(INTERNAL_COLLABORATION_MODE_HEADER);
|
|
1760
1838
|
if (collaborationModeKind) {
|
|
1761
1839
|
outbound.headers.delete(INTERNAL_COLLABORATION_MODE_HEADER);
|
|
1762
1840
|
}
|
|
1841
|
+
const subagentHeader = outbound.headers.get("x-openai-subagent")?.trim();
|
|
1842
|
+
const isSubagentRequest = Boolean(subagentHeader);
|
|
1843
|
+
if (opts.headerTransformDebug === true) {
|
|
1844
|
+
await requestSnapshots.captureRequest("after-header-transform", outbound, {
|
|
1845
|
+
spoofMode,
|
|
1846
|
+
...(collaborationModeKind ? { collaborationModeKind } : {}),
|
|
1847
|
+
...(isSubagentRequest ? { subagent: subagentHeader } : {})
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1763
1850
|
let selectedIdentityKey;
|
|
1764
1851
|
await requestSnapshots.captureRequest("before-auth", outbound, {
|
|
1765
1852
|
spoofMode,
|
|
@@ -1774,6 +1861,11 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
1774
1861
|
let email;
|
|
1775
1862
|
let plan;
|
|
1776
1863
|
try {
|
|
1864
|
+
if (isSubagentRequest && context?.sessionKey) {
|
|
1865
|
+
orchestratorState.seenSessionKeys.delete(context.sessionKey);
|
|
1866
|
+
stickySessionState.bySessionKey.delete(context.sessionKey);
|
|
1867
|
+
hybridSessionState.bySessionKey.delete(context.sessionKey);
|
|
1868
|
+
}
|
|
1777
1869
|
await saveAuthStorage(undefined, async (authFile) => {
|
|
1778
1870
|
const now = Date.now();
|
|
1779
1871
|
const openai = authFile.openai;
|
|
@@ -1807,8 +1899,9 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
1807
1899
|
let sawInvalidGrant = false;
|
|
1808
1900
|
let sawRefreshFailure = false;
|
|
1809
1901
|
let sawMissingRefresh = false;
|
|
1902
|
+
const rotationStrategy = opts.rotationStrategy ?? domain.strategy ?? "sticky";
|
|
1810
1903
|
opts.log?.debug("rotation begin", {
|
|
1811
|
-
strategy:
|
|
1904
|
+
strategy: rotationStrategy,
|
|
1812
1905
|
activeIdentityKey: domain.activeIdentityKey,
|
|
1813
1906
|
totalAccounts: domain.accounts.length,
|
|
1814
1907
|
enabledAccounts: enabled.length,
|
|
@@ -1816,14 +1909,19 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
1816
1909
|
sessionKey: context?.sessionKey ?? null
|
|
1817
1910
|
});
|
|
1818
1911
|
while (attempted.size < domain.accounts.length) {
|
|
1912
|
+
const sessionState = rotationStrategy === "sticky"
|
|
1913
|
+
? stickySessionState
|
|
1914
|
+
: rotationStrategy === "hybrid"
|
|
1915
|
+
? hybridSessionState
|
|
1916
|
+
: undefined;
|
|
1819
1917
|
const selected = selectAccount({
|
|
1820
1918
|
accounts: domain.accounts,
|
|
1821
|
-
strategy:
|
|
1919
|
+
strategy: rotationStrategy,
|
|
1822
1920
|
activeIdentityKey: domain.activeIdentityKey,
|
|
1823
1921
|
now,
|
|
1824
1922
|
stickyPidOffset: opts.pidOffsetEnabled === true,
|
|
1825
|
-
stickySessionKey: context?.sessionKey,
|
|
1826
|
-
stickySessionState,
|
|
1923
|
+
stickySessionKey: isSubagentRequest ? undefined : context?.sessionKey,
|
|
1924
|
+
stickySessionState: sessionState,
|
|
1827
1925
|
onDebug: (event) => {
|
|
1828
1926
|
opts.log?.debug("rotation decision", event);
|
|
1829
1927
|
}
|
|
@@ -1848,6 +1946,9 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
1848
1946
|
break;
|
|
1849
1947
|
}
|
|
1850
1948
|
attempted.add(attemptKey);
|
|
1949
|
+
if (!isSubagentRequest && context?.sessionKey && sessionState) {
|
|
1950
|
+
persistSessionAffinityState();
|
|
1951
|
+
}
|
|
1851
1952
|
opts.log?.debug("rotation candidate selected", {
|
|
1852
1953
|
attemptKey,
|
|
1853
1954
|
selectedIdentityKey: selected.identityKey,
|
|
@@ -2003,6 +2104,17 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
2003
2104
|
},
|
|
2004
2105
|
quietMode: opts.quietMode === true,
|
|
2005
2106
|
state: orchestratorState,
|
|
2107
|
+
onSessionObserved: ({ event, sessionKey }) => {
|
|
2108
|
+
if (isSubagentRequest) {
|
|
2109
|
+
orchestratorState.seenSessionKeys.delete(sessionKey);
|
|
2110
|
+
stickySessionState.bySessionKey.delete(sessionKey);
|
|
2111
|
+
hybridSessionState.bySessionKey.delete(sessionKey);
|
|
2112
|
+
return;
|
|
2113
|
+
}
|
|
2114
|
+
if (event === "new" || event === "resume" || event === "switch") {
|
|
2115
|
+
persistSessionAffinityState();
|
|
2116
|
+
}
|
|
2117
|
+
},
|
|
2006
2118
|
showToast,
|
|
2007
2119
|
onAttemptRequest: async ({ attempt, maxAttempts, request, auth, sessionKey }) => {
|
|
2008
2120
|
await requestSnapshots.captureRequest("outbound-attempt", request, {
|
|
@@ -2094,7 +2206,7 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
2094
2206
|
const { redirectUri } = await startOAuthServer();
|
|
2095
2207
|
const pkce = await generatePKCE();
|
|
2096
2208
|
const state = generateState();
|
|
2097
|
-
const authUrl = buildAuthorizeUrl(redirectUri, pkce, state, "codex_cli_rs");
|
|
2209
|
+
const authUrl = buildAuthorizeUrl(redirectUri, pkce, state, spoofMode === "codex" ? "codex_cli_rs" : "opencode");
|
|
2098
2210
|
const callbackPromise = waitForOAuthCallback(pkce, state, authMode);
|
|
2099
2211
|
void tryOpenUrlInBrowser(authUrl, opts.log);
|
|
2100
2212
|
process.stdout.write(`\nGo to: ${authUrl}\n`);
|
|
@@ -2160,7 +2272,7 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
2160
2272
|
const { redirectUri } = await startOAuthServer();
|
|
2161
2273
|
const pkce = await generatePKCE();
|
|
2162
2274
|
const state = generateState();
|
|
2163
|
-
const authUrl = buildAuthorizeUrl(redirectUri, pkce, state, "codex_cli_rs");
|
|
2275
|
+
const authUrl = buildAuthorizeUrl(redirectUri, pkce, state, spoofMode === "codex" ? "codex_cli_rs" : "opencode");
|
|
2164
2276
|
const callbackPromise = waitForOAuthCallback(pkce, state, authMode);
|
|
2165
2277
|
void tryOpenUrlInBrowser(authUrl, opts.log);
|
|
2166
2278
|
return {
|
|
@@ -2342,15 +2454,9 @@ export async function CodexAuthPlugin(input, opts = {}) {
|
|
|
2342
2454
|
const modelOptions = isRecord(hookInput.model.options) ? hookInput.model.options : {};
|
|
2343
2455
|
const promptCacheKey = resolvePromptCacheKey(modelOptions);
|
|
2344
2456
|
if (spoofMode === "native") {
|
|
2345
|
-
output.headers
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
output.headers.conversation_id = promptCacheKey;
|
|
2349
|
-
}
|
|
2350
|
-
else {
|
|
2351
|
-
delete output.headers.session_id;
|
|
2352
|
-
delete output.headers.conversation_id;
|
|
2353
|
-
}
|
|
2457
|
+
output.headers.session_id = hookInput.sessionID;
|
|
2458
|
+
delete output.headers["OpenAI-Beta"];
|
|
2459
|
+
delete output.headers.conversation_id;
|
|
2354
2460
|
}
|
|
2355
2461
|
else {
|
|
2356
2462
|
output.headers.session_id = promptCacheKey ?? hookInput.sessionID;
|