better-opencode-openai-codex-auth 0.1.0

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.
Files changed (81) hide show
  1. package/LICENSE +37 -0
  2. package/README.md +99 -0
  3. package/assets/opencode-logo-ornate-dark.svg +18 -0
  4. package/assets/readme-hero.svg +31 -0
  5. package/config/README.md +103 -0
  6. package/config/minimal-opencode.json +12 -0
  7. package/config/opencode-legacy.json +571 -0
  8. package/config/opencode-modern.json +239 -0
  9. package/dist/index.d.ts +42 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +334 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/lib/account-pool.d.ts +17 -0
  14. package/dist/lib/account-pool.d.ts.map +1 -0
  15. package/dist/lib/account-pool.js +243 -0
  16. package/dist/lib/account-pool.js.map +1 -0
  17. package/dist/lib/auth/auth.d.ts +43 -0
  18. package/dist/lib/auth/auth.d.ts.map +1 -0
  19. package/dist/lib/auth/auth.js +162 -0
  20. package/dist/lib/auth/auth.js.map +1 -0
  21. package/dist/lib/auth/browser.d.ts +17 -0
  22. package/dist/lib/auth/browser.d.ts.map +1 -0
  23. package/dist/lib/auth/browser.js +76 -0
  24. package/dist/lib/auth/browser.js.map +1 -0
  25. package/dist/lib/auth/server.d.ts +10 -0
  26. package/dist/lib/auth/server.d.ts.map +1 -0
  27. package/dist/lib/auth/server.js +78 -0
  28. package/dist/lib/auth/server.js.map +1 -0
  29. package/dist/lib/config.d.ts +17 -0
  30. package/dist/lib/config.d.ts.map +1 -0
  31. package/dist/lib/config.js +53 -0
  32. package/dist/lib/config.js.map +1 -0
  33. package/dist/lib/constants.d.ts +67 -0
  34. package/dist/lib/constants.d.ts.map +1 -0
  35. package/dist/lib/constants.js +67 -0
  36. package/dist/lib/constants.js.map +1 -0
  37. package/dist/lib/logger.d.ts +21 -0
  38. package/dist/lib/logger.d.ts.map +1 -0
  39. package/dist/lib/logger.js +77 -0
  40. package/dist/lib/logger.js.map +1 -0
  41. package/dist/lib/oauth-success.html +712 -0
  42. package/dist/lib/prompts/codex-opencode-bridge.d.ts +19 -0
  43. package/dist/lib/prompts/codex-opencode-bridge.d.ts.map +1 -0
  44. package/dist/lib/prompts/codex-opencode-bridge.js +152 -0
  45. package/dist/lib/prompts/codex-opencode-bridge.js.map +1 -0
  46. package/dist/lib/prompts/codex.d.ts +27 -0
  47. package/dist/lib/prompts/codex.d.ts.map +1 -0
  48. package/dist/lib/prompts/codex.js +252 -0
  49. package/dist/lib/prompts/codex.js.map +1 -0
  50. package/dist/lib/prompts/opencode-codex.d.ts +21 -0
  51. package/dist/lib/prompts/opencode-codex.d.ts.map +1 -0
  52. package/dist/lib/prompts/opencode-codex.js +91 -0
  53. package/dist/lib/prompts/opencode-codex.js.map +1 -0
  54. package/dist/lib/request/fetch-helpers.d.ts +73 -0
  55. package/dist/lib/request/fetch-helpers.d.ts.map +1 -0
  56. package/dist/lib/request/fetch-helpers.js +221 -0
  57. package/dist/lib/request/fetch-helpers.js.map +1 -0
  58. package/dist/lib/request/helpers/input-utils.d.ts +6 -0
  59. package/dist/lib/request/helpers/input-utils.d.ts.map +1 -0
  60. package/dist/lib/request/helpers/input-utils.js +174 -0
  61. package/dist/lib/request/helpers/input-utils.js.map +1 -0
  62. package/dist/lib/request/helpers/model-map.d.ts +28 -0
  63. package/dist/lib/request/helpers/model-map.d.ts.map +1 -0
  64. package/dist/lib/request/helpers/model-map.js +126 -0
  65. package/dist/lib/request/helpers/model-map.js.map +1 -0
  66. package/dist/lib/request/request-transformer.d.ts +93 -0
  67. package/dist/lib/request/request-transformer.d.ts.map +1 -0
  68. package/dist/lib/request/request-transformer.js +418 -0
  69. package/dist/lib/request/request-transformer.js.map +1 -0
  70. package/dist/lib/request/response-handler.d.ts +14 -0
  71. package/dist/lib/request/response-handler.d.ts.map +1 -0
  72. package/dist/lib/request/response-handler.js +150 -0
  73. package/dist/lib/request/response-handler.js.map +1 -0
  74. package/dist/lib/types.d.ts +183 -0
  75. package/dist/lib/types.d.ts.map +1 -0
  76. package/dist/lib/types.js +2 -0
  77. package/dist/lib/types.js.map +1 -0
  78. package/package.json +74 -0
  79. package/scripts/install-opencode-codex-auth.js +433 -0
  80. package/scripts/test-all-models.sh +259 -0
  81. package/scripts/validate-model-map.sh +97 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-map.js","sourceRoot":"","sources":["../../../../lib/request/helpers/model-map.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAA2B;IACjD,+EAA+E;IAC/E,2EAA2E;IAC3E,+EAA+E;IAC9E,SAAS,EAAE,SAAS;IACpB,cAAc,EAAE,SAAS;IACzB,aAAa,EAAE,SAAS;IACxB,gBAAgB,EAAE,SAAS;IAC3B,cAAc,EAAE,SAAS;IACzB,eAAe,EAAE,SAAS;IAE1B,+EAA+E;IAC/E,+CAA+C;IAC/C,+EAA+E;IAC/E,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;IACpC,sBAAsB,EAAE,eAAe;IACvC,oBAAoB,EAAE,eAAe;IACrC,qBAAqB,EAAE,eAAe;IAEtC,+EAA+E;IAC/E,uBAAuB;IACvB,+EAA+E;IAC/E,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,eAAe;IACpC,sBAAsB,EAAE,eAAe;IACvC,oBAAoB,EAAE,eAAe;IAErC,+EAA+E;IAC/E,2BAA2B;IAC3B,+EAA+E;IAC/E,mBAAmB,EAAE,mBAAmB;IACxC,uBAAuB,EAAE,mBAAmB;IAC5C,0BAA0B,EAAE,mBAAmB;IAC/C,wBAAwB,EAAE,mBAAmB;IAC7C,yBAAyB,EAAE,mBAAmB;IAE9C,+EAA+E;IAC/E,2EAA2E;IAC3E,+EAA+E;IAC/E,SAAS,EAAE,SAAS;IACpB,cAAc,EAAE,SAAS;IACzB,aAAa,EAAE,SAAS;IACxB,gBAAgB,EAAE,SAAS;IAC3B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AS,CAAC,CAAC,IAAI,CACxC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,YAAY,CAC3C,CAAC;QAEF,OAAO,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC3C,OAAO,kBAAkB,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;AAClD,CAAC"}
@@ -0,0 +1,93 @@
1
+ import type { ConfigOptions, InputItem, ReasoningConfig, RequestBody, UserConfig } from "../types.js";
2
+ export { isOpenCodeSystemPrompt, filterOpenCodeSystemPromptsWithCachedPrompt, } from "./helpers/input-utils.js";
3
+ /**
4
+ * Normalize model name to Codex-supported variants
5
+ *
6
+ * Uses explicit model map for known models, with fallback pattern matching
7
+ * for unknown/custom model names.
8
+ *
9
+ * @param model - Original model name (e.g., "gpt-5.1-codex-low", "openai/gpt-5-codex")
10
+ * @returns Normalized model name (e.g., "gpt-5.1-codex", "gpt-5-codex")
11
+ */
12
+ export declare function normalizeModel(model: string | undefined): string;
13
+ /**
14
+ * Extract configuration for a specific model
15
+ * Merges global options with model-specific options (model-specific takes precedence)
16
+ * @param modelName - Model name (e.g., "gpt-5-codex")
17
+ * @param userConfig - Full user configuration object
18
+ * @returns Merged configuration for this model
19
+ */
20
+ export declare function getModelConfig(modelName: string, userConfig?: UserConfig): ConfigOptions;
21
+ /**
22
+ * Configure reasoning parameters based on model variant and user config
23
+ *
24
+ * NOTE: This plugin follows Codex CLI defaults instead of opencode defaults because:
25
+ * - We're accessing the ChatGPT backend API (not OpenAI Platform API)
26
+ * - opencode explicitly excludes gpt-5-codex from automatic reasoning configuration
27
+ * - Codex CLI has been thoroughly tested against this backend
28
+ *
29
+ * @param originalModel - Original model name before normalization
30
+ * @param userConfig - User configuration object
31
+ * @returns Reasoning configuration
32
+ */
33
+ export declare function getReasoningConfig(modelName: string | undefined, userConfig?: ConfigOptions): ReasoningConfig;
34
+ /**
35
+ * Filter input array for stateless Codex API (store: false)
36
+ *
37
+ * Two transformations needed:
38
+ * 1. Remove AI SDK-specific items (not supported by Codex API)
39
+ * 2. Strip IDs from all remaining items (stateless mode)
40
+ *
41
+ * AI SDK constructs to REMOVE (not in OpenAI Responses API spec):
42
+ * - type: "item_reference" - AI SDK uses this for server-side state lookup
43
+ *
44
+ * Items to KEEP (strip IDs):
45
+ * - type: "message" - Conversation messages (provides context to LLM)
46
+ * - type: "function_call" - Tool calls from conversation
47
+ * - type: "function_call_output" - Tool results from conversation
48
+ *
49
+ * Context is maintained through:
50
+ * - Full message history (without IDs)
51
+ * - reasoning.encrypted_content (for reasoning continuity)
52
+ *
53
+ * @param input - Original input array from OpenCode/AI SDK
54
+ * @returns Filtered input array compatible with Codex API
55
+ */
56
+ export declare function filterInput(input: InputItem[] | undefined): InputItem[] | undefined;
57
+ /**
58
+ * Filter out OpenCode system prompts from input
59
+ * Used in CODEX_MODE to replace OpenCode prompts with Codex-OpenCode bridge
60
+ * @param input - Input array
61
+ * @returns Input array without OpenCode system prompts
62
+ */
63
+ export declare function filterOpenCodeSystemPrompts(input: InputItem[] | undefined): Promise<InputItem[] | undefined>;
64
+ /**
65
+ * Add Codex-OpenCode bridge message to input if tools are present
66
+ * @param input - Input array
67
+ * @param hasTools - Whether tools are present in request
68
+ * @returns Input array with bridge message prepended if needed
69
+ */
70
+ export declare function addCodexBridgeMessage(input: InputItem[] | undefined, hasTools: boolean): InputItem[] | undefined;
71
+ /**
72
+ * Add tool remapping message to input if tools are present
73
+ * @param input - Input array
74
+ * @param hasTools - Whether tools are present in request
75
+ * @returns Input array with tool remap message prepended if needed
76
+ */
77
+ export declare function addToolRemapMessage(input: InputItem[] | undefined, hasTools: boolean): InputItem[] | undefined;
78
+ /**
79
+ * Transform request body for Codex API
80
+ *
81
+ * NOTE: Configuration follows Codex CLI patterns instead of opencode defaults:
82
+ * - opencode sets textVerbosity="low" for gpt-5, but Codex CLI uses "medium"
83
+ * - opencode excludes gpt-5-codex from reasoning configuration
84
+ * - This plugin uses store=false (stateless), requiring encrypted reasoning content
85
+ *
86
+ * @param body - Original request body
87
+ * @param codexInstructions - Codex system instructions
88
+ * @param userConfig - User configuration from loader
89
+ * @param codexMode - Enable CODEX_MODE (bridge prompt instead of tool remap) - defaults to true
90
+ * @returns Transformed request body
91
+ */
92
+ export declare function transformRequestBody(body: RequestBody, codexInstructions: string, userConfig?: UserConfig, codexMode?: boolean): Promise<RequestBody>;
93
+ //# sourceMappingURL=request-transformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-transformer.d.ts","sourceRoot":"","sources":["../../../lib/request/request-transformer.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACX,aAAa,EACb,SAAS,EACT,eAAe,EACf,WAAW,EACX,UAAU,EACV,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,sBAAsB,EACtB,2CAA2C,GAC3C,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CA8FhE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC7B,SAAS,EAAE,MAAM,EACjB,UAAU,GAAE,UAAuC,GACjD,aAAa,CAMf;AAiDD;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CACjC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,UAAU,GAAE,aAAkB,GAC5B,eAAe,CAqGjB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,GAC5B,SAAS,EAAE,GAAG,SAAS,CAmBzB;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAChD,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,GAC5B,OAAO,CAAC,SAAS,EAAE,GAAG,SAAS,CAAC,CAalC;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,EAC9B,QAAQ,EAAE,OAAO,GACf,SAAS,EAAE,GAAG,SAAS,CAezB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,EAC9B,QAAQ,EAAE,OAAO,GACf,SAAS,EAAE,GAAG,SAAS,CAezB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,oBAAoB,CACzC,IAAI,EAAE,WAAW,EACjB,iBAAiB,EAAE,MAAM,EACzB,UAAU,GAAE,UAAuC,EACnD,SAAS,UAAO,GACd,OAAO,CAAC,WAAW,CAAC,CAwGtB"}
@@ -0,0 +1,418 @@
1
+ import { logDebug, logWarn } from "../logger.js";
2
+ import { TOOL_REMAP_MESSAGE } from "../prompts/codex.js";
3
+ import { CODEX_OPENCODE_BRIDGE } from "../prompts/codex-opencode-bridge.js";
4
+ import { getOpenCodeCodexPrompt } from "../prompts/opencode-codex.js";
5
+ import { getNormalizedModel } from "./helpers/model-map.js";
6
+ import { filterOpenCodeSystemPromptsWithCachedPrompt, normalizeOrphanedToolOutputs, } from "./helpers/input-utils.js";
7
+ export { isOpenCodeSystemPrompt, filterOpenCodeSystemPromptsWithCachedPrompt, } from "./helpers/input-utils.js";
8
+ /**
9
+ * Normalize model name to Codex-supported variants
10
+ *
11
+ * Uses explicit model map for known models, with fallback pattern matching
12
+ * for unknown/custom model names.
13
+ *
14
+ * @param model - Original model name (e.g., "gpt-5.1-codex-low", "openai/gpt-5-codex")
15
+ * @returns Normalized model name (e.g., "gpt-5.1-codex", "gpt-5-codex")
16
+ */
17
+ export function normalizeModel(model) {
18
+ if (!model)
19
+ return "gpt-5.1";
20
+ // Strip provider prefix if present (e.g., "openai/gpt-5-codex" → "gpt-5-codex")
21
+ const modelId = model.includes("/") ? model.split("/").pop() : model;
22
+ // Try explicit model map first (handles all known model variants)
23
+ const mappedModel = getNormalizedModel(modelId);
24
+ if (mappedModel) {
25
+ return mappedModel;
26
+ }
27
+ // Fallback: Pattern-based matching for unknown/custom model names
28
+ // This preserves backwards compatibility with old verbose names
29
+ // like "GPT 5 Codex Low (ChatGPT Subscription)"
30
+ const normalized = modelId.toLowerCase();
31
+ // Priority order for pattern matching (most specific first):
32
+ // 1. GPT-5.3 Codex (newest codex model)
33
+ if (normalized.includes("gpt-5.3-codex") ||
34
+ normalized.includes("gpt 5.3 codex")) {
35
+ return "gpt-5.3-codex";
36
+ }
37
+ // 2. GPT-5.3 (general purpose)
38
+ if (normalized.includes("gpt-5.3") || normalized.includes("gpt 5.3")) {
39
+ return "gpt-5.3";
40
+ }
41
+ // 3. GPT-5.2 Codex
42
+ if (normalized.includes("gpt-5.2-codex") ||
43
+ normalized.includes("gpt 5.2 codex")) {
44
+ return "gpt-5.2-codex";
45
+ }
46
+ // 4. GPT-5.2 (general purpose)
47
+ if (normalized.includes("gpt-5.2") || normalized.includes("gpt 5.2")) {
48
+ return "gpt-5.2";
49
+ }
50
+ // 5. GPT-5.1 Codex Max
51
+ if (normalized.includes("gpt-5.1-codex-max") ||
52
+ normalized.includes("gpt 5.1 codex max")) {
53
+ return "gpt-5.1-codex-max";
54
+ }
55
+ // 6. GPT-5.1 Codex Mini
56
+ if (normalized.includes("gpt-5.1-codex-mini") ||
57
+ normalized.includes("gpt 5.1 codex mini")) {
58
+ return "gpt-5.1-codex-mini";
59
+ }
60
+ // 5. Legacy Codex Mini
61
+ if (normalized.includes("codex-mini-latest") ||
62
+ normalized.includes("gpt-5-codex-mini") ||
63
+ normalized.includes("gpt 5 codex mini")) {
64
+ return "codex-mini-latest";
65
+ }
66
+ // 6. GPT-5.1 Codex
67
+ if (normalized.includes("gpt-5.1-codex") ||
68
+ normalized.includes("gpt 5.1 codex")) {
69
+ return "gpt-5.1-codex";
70
+ }
71
+ // 7. GPT-5.1 (general-purpose)
72
+ if (normalized.includes("gpt-5.1") || normalized.includes("gpt 5.1")) {
73
+ return "gpt-5.1";
74
+ }
75
+ // 8. GPT-5 Codex family (any variant with "codex")
76
+ if (normalized.includes("codex")) {
77
+ return "gpt-5.1-codex";
78
+ }
79
+ // 9. GPT-5 family (any variant) - default to 5.1 as 5 is being phased out
80
+ if (normalized.includes("gpt-5") || normalized.includes("gpt 5")) {
81
+ return "gpt-5.1";
82
+ }
83
+ // Default fallback - use gpt-5.1 as gpt-5 is being phased out
84
+ return "gpt-5.1";
85
+ }
86
+ /**
87
+ * Extract configuration for a specific model
88
+ * Merges global options with model-specific options (model-specific takes precedence)
89
+ * @param modelName - Model name (e.g., "gpt-5-codex")
90
+ * @param userConfig - Full user configuration object
91
+ * @returns Merged configuration for this model
92
+ */
93
+ export function getModelConfig(modelName, userConfig = { global: {}, models: {} }) {
94
+ const globalOptions = userConfig.global || {};
95
+ const modelOptions = userConfig.models?.[modelName]?.options || {};
96
+ // Model-specific options override global options
97
+ return { ...globalOptions, ...modelOptions };
98
+ }
99
+ function resolveReasoningConfig(modelName, modelConfig, body) {
100
+ const providerOpenAI = body.providerOptions?.openai;
101
+ const existingEffort = body.reasoning?.effort ?? providerOpenAI?.reasoningEffort;
102
+ const existingSummary = body.reasoning?.summary ?? providerOpenAI?.reasoningSummary;
103
+ const mergedConfig = {
104
+ ...modelConfig,
105
+ ...(existingEffort ? { reasoningEffort: existingEffort } : {}),
106
+ ...(existingSummary ? { reasoningSummary: existingSummary } : {}),
107
+ };
108
+ return getReasoningConfig(modelName, mergedConfig);
109
+ }
110
+ function resolveTextVerbosity(modelConfig, body) {
111
+ const providerOpenAI = body.providerOptions?.openai;
112
+ return (body.text?.verbosity ??
113
+ providerOpenAI?.textVerbosity ??
114
+ modelConfig.textVerbosity ??
115
+ "medium");
116
+ }
117
+ function resolveInclude(modelConfig, body) {
118
+ const providerOpenAI = body.providerOptions?.openai;
119
+ const base = body.include ??
120
+ providerOpenAI?.include ??
121
+ modelConfig.include ??
122
+ ["reasoning.encrypted_content"];
123
+ const include = Array.from(new Set(base.filter(Boolean)));
124
+ if (!include.includes("reasoning.encrypted_content")) {
125
+ include.push("reasoning.encrypted_content");
126
+ }
127
+ return include;
128
+ }
129
+ /**
130
+ * Configure reasoning parameters based on model variant and user config
131
+ *
132
+ * NOTE: This plugin follows Codex CLI defaults instead of opencode defaults because:
133
+ * - We're accessing the ChatGPT backend API (not OpenAI Platform API)
134
+ * - opencode explicitly excludes gpt-5-codex from automatic reasoning configuration
135
+ * - Codex CLI has been thoroughly tested against this backend
136
+ *
137
+ * @param originalModel - Original model name before normalization
138
+ * @param userConfig - User configuration object
139
+ * @returns Reasoning configuration
140
+ */
141
+ export function getReasoningConfig(modelName, userConfig = {}) {
142
+ const normalizedName = modelName?.toLowerCase() ?? "";
143
+ // GPT-5.3 Codex is the newest codex model (supports xhigh, but not "none")
144
+ const isGpt53Codex = normalizedName.includes("gpt-5.3-codex") ||
145
+ normalizedName.includes("gpt 5.3 codex");
146
+ // GPT-5.3 general purpose (not codex variant)
147
+ const isGpt53General = (normalizedName.includes("gpt-5.3") || normalizedName.includes("gpt 5.3")) &&
148
+ !isGpt53Codex;
149
+ // GPT-5.2 Codex (supports xhigh, but not "none")
150
+ const isGpt52Codex = normalizedName.includes("gpt-5.2-codex") ||
151
+ normalizedName.includes("gpt 5.2 codex");
152
+ // GPT-5.2 general purpose (not codex variant)
153
+ const isGpt52General = (normalizedName.includes("gpt-5.2") || normalizedName.includes("gpt 5.2")) &&
154
+ !isGpt52Codex;
155
+ const isCodexMax = normalizedName.includes("codex-max") ||
156
+ normalizedName.includes("codex max");
157
+ const isCodexMini = normalizedName.includes("codex-mini") ||
158
+ normalizedName.includes("codex mini") ||
159
+ normalizedName.includes("codex_mini") ||
160
+ normalizedName.includes("codex-mini-latest");
161
+ const isCodex = normalizedName.includes("codex") && !isCodexMini;
162
+ const isLightweight = !isCodexMini &&
163
+ (normalizedName.includes("nano") ||
164
+ normalizedName.includes("mini"));
165
+ // GPT-5.1 general purpose (not codex variants) - supports "none" per OpenAI API docs
166
+ const isGpt51General = (normalizedName.includes("gpt-5.1") || normalizedName.includes("gpt 5.1")) &&
167
+ !isCodex &&
168
+ !isCodexMax &&
169
+ !isCodexMini;
170
+ // GPT 5.3, GPT 5.2, GPT 5.2 Codex, and Codex Max support xhigh reasoning
171
+ const supportsXhigh = isGpt53General || isGpt53Codex || isGpt52General || isGpt52Codex || isCodexMax;
172
+ // GPT 5.3 general, GPT 5.2 general, and GPT 5.1 general support "none" reasoning per:
173
+ // - OpenAI API docs: "gpt-5.1 defaults to none, supports: none, low, medium, high"
174
+ // - Codex CLI: ReasoningEffort enum includes None variant (codex-rs/protocol/src/openai_models.rs)
175
+ // - Codex CLI: docs/config.md lists "none" as valid for model_reasoning_effort
176
+ // - gpt-5.2 and gpt-5.3 (being newer) also supports: none, low, medium, high, xhigh
177
+ // - Codex models (including GPT-5.2 Codex and GPT-5.3 Codex) do NOT support "none"
178
+ const supportsNone = isGpt53General || isGpt52General || isGpt51General;
179
+ // Default based on model type (Codex CLI defaults)
180
+ // Note: OpenAI docs say gpt-5.1 defaults to "none", but we default to "medium"
181
+ // for better coding assistance unless user explicitly requests "none"
182
+ const defaultEffort = isCodexMini
183
+ ? "medium"
184
+ : supportsXhigh
185
+ ? "high"
186
+ : isLightweight
187
+ ? "minimal"
188
+ : "medium";
189
+ // Get user-requested effort
190
+ let effort = userConfig.reasoningEffort || defaultEffort;
191
+ if (isCodexMini) {
192
+ if (effort === "minimal" || effort === "low" || effort === "none") {
193
+ effort = "medium";
194
+ }
195
+ if (effort === "xhigh") {
196
+ effort = "high";
197
+ }
198
+ if (effort !== "high" && effort !== "medium") {
199
+ effort = "medium";
200
+ }
201
+ }
202
+ // For models that don't support xhigh, downgrade to high
203
+ if (!supportsXhigh && effort === "xhigh") {
204
+ effort = "high";
205
+ }
206
+ // For models that don't support "none", upgrade to "low"
207
+ // (Codex models don't support "none" - only GPT-5.1 and GPT-5.2 general purpose do)
208
+ if (!supportsNone && effort === "none") {
209
+ effort = "low";
210
+ }
211
+ // Normalize "minimal" to "low" for all non-mini models
212
+ // The ChatGPT Codex backend does not accept "minimal" (supports none/low/medium/high).
213
+ if (effort === "minimal") {
214
+ effort = "low";
215
+ }
216
+ return {
217
+ effort,
218
+ summary: userConfig.reasoningSummary || "auto", // Changed from "detailed" to match Codex CLI
219
+ };
220
+ }
221
+ /**
222
+ * Filter input array for stateless Codex API (store: false)
223
+ *
224
+ * Two transformations needed:
225
+ * 1. Remove AI SDK-specific items (not supported by Codex API)
226
+ * 2. Strip IDs from all remaining items (stateless mode)
227
+ *
228
+ * AI SDK constructs to REMOVE (not in OpenAI Responses API spec):
229
+ * - type: "item_reference" - AI SDK uses this for server-side state lookup
230
+ *
231
+ * Items to KEEP (strip IDs):
232
+ * - type: "message" - Conversation messages (provides context to LLM)
233
+ * - type: "function_call" - Tool calls from conversation
234
+ * - type: "function_call_output" - Tool results from conversation
235
+ *
236
+ * Context is maintained through:
237
+ * - Full message history (without IDs)
238
+ * - reasoning.encrypted_content (for reasoning continuity)
239
+ *
240
+ * @param input - Original input array from OpenCode/AI SDK
241
+ * @returns Filtered input array compatible with Codex API
242
+ */
243
+ export function filterInput(input) {
244
+ if (!Array.isArray(input))
245
+ return input;
246
+ return input
247
+ .filter((item) => {
248
+ // Remove AI SDK constructs not supported by Codex API
249
+ if (item.type === "item_reference") {
250
+ return false; // AI SDK only - references server state
251
+ }
252
+ return true; // Keep all other items
253
+ })
254
+ .map((item) => {
255
+ // Strip IDs from all items (Codex API stateless mode)
256
+ if (item.id) {
257
+ const { id, ...itemWithoutId } = item;
258
+ return itemWithoutId;
259
+ }
260
+ return item;
261
+ });
262
+ }
263
+ /**
264
+ * Filter out OpenCode system prompts from input
265
+ * Used in CODEX_MODE to replace OpenCode prompts with Codex-OpenCode bridge
266
+ * @param input - Input array
267
+ * @returns Input array without OpenCode system prompts
268
+ */
269
+ export async function filterOpenCodeSystemPrompts(input) {
270
+ if (!Array.isArray(input))
271
+ return input;
272
+ // Fetch cached OpenCode prompt for verification
273
+ let cachedPrompt = null;
274
+ try {
275
+ cachedPrompt = await getOpenCodeCodexPrompt();
276
+ }
277
+ catch {
278
+ // If fetch fails, fallback to text-based detection only
279
+ // This is safe because we still have the "starts with" check
280
+ }
281
+ return filterOpenCodeSystemPromptsWithCachedPrompt(input, cachedPrompt);
282
+ }
283
+ /**
284
+ * Add Codex-OpenCode bridge message to input if tools are present
285
+ * @param input - Input array
286
+ * @param hasTools - Whether tools are present in request
287
+ * @returns Input array with bridge message prepended if needed
288
+ */
289
+ export function addCodexBridgeMessage(input, hasTools) {
290
+ if (!hasTools || !Array.isArray(input))
291
+ return input;
292
+ const bridgeMessage = {
293
+ type: "message",
294
+ role: "developer",
295
+ content: [
296
+ {
297
+ type: "input_text",
298
+ text: CODEX_OPENCODE_BRIDGE,
299
+ },
300
+ ],
301
+ };
302
+ return [bridgeMessage, ...input];
303
+ }
304
+ /**
305
+ * Add tool remapping message to input if tools are present
306
+ * @param input - Input array
307
+ * @param hasTools - Whether tools are present in request
308
+ * @returns Input array with tool remap message prepended if needed
309
+ */
310
+ export function addToolRemapMessage(input, hasTools) {
311
+ if (!hasTools || !Array.isArray(input))
312
+ return input;
313
+ const toolRemapMessage = {
314
+ type: "message",
315
+ role: "developer",
316
+ content: [
317
+ {
318
+ type: "input_text",
319
+ text: TOOL_REMAP_MESSAGE,
320
+ },
321
+ ],
322
+ };
323
+ return [toolRemapMessage, ...input];
324
+ }
325
+ /**
326
+ * Transform request body for Codex API
327
+ *
328
+ * NOTE: Configuration follows Codex CLI patterns instead of opencode defaults:
329
+ * - opencode sets textVerbosity="low" for gpt-5, but Codex CLI uses "medium"
330
+ * - opencode excludes gpt-5-codex from reasoning configuration
331
+ * - This plugin uses store=false (stateless), requiring encrypted reasoning content
332
+ *
333
+ * @param body - Original request body
334
+ * @param codexInstructions - Codex system instructions
335
+ * @param userConfig - User configuration from loader
336
+ * @param codexMode - Enable CODEX_MODE (bridge prompt instead of tool remap) - defaults to true
337
+ * @returns Transformed request body
338
+ */
339
+ export async function transformRequestBody(body, codexInstructions, userConfig = { global: {}, models: {} }, codexMode = true) {
340
+ const originalModel = body.model;
341
+ const normalizedModel = normalizeModel(body.model);
342
+ // Get model-specific configuration using ORIGINAL model name (config key)
343
+ // This allows per-model options like "gpt-5-codex-low" to work correctly
344
+ const lookupModel = originalModel || normalizedModel;
345
+ const modelConfig = getModelConfig(lookupModel, userConfig);
346
+ // Debug: Log which config was resolved
347
+ logDebug(`Model config lookup: "${lookupModel}" → normalized to "${normalizedModel}" for API`, {
348
+ hasModelSpecificConfig: !!userConfig.models?.[lookupModel],
349
+ resolvedConfig: modelConfig,
350
+ });
351
+ // Normalize model name for API call
352
+ body.model = normalizedModel;
353
+ // Codex required fields
354
+ // ChatGPT backend REQUIRES store=false (confirmed via testing)
355
+ body.store = false;
356
+ // Always set stream=true for API - response handling detects original intent
357
+ body.stream = true;
358
+ body.instructions = codexInstructions;
359
+ // Prompt caching relies on the host providing a stable prompt_cache_key
360
+ // (OpenCode passes its session identifier). We no longer synthesize one here.
361
+ // Filter and transform input
362
+ if (body.input && Array.isArray(body.input)) {
363
+ // Debug: Log original input message IDs before filtering
364
+ const originalIds = body.input
365
+ .filter((item) => item.id)
366
+ .map((item) => item.id);
367
+ if (originalIds.length > 0) {
368
+ logDebug(`Filtering ${originalIds.length} message IDs from input:`, originalIds);
369
+ }
370
+ body.input = filterInput(body.input);
371
+ // Debug: Verify all IDs were removed
372
+ const remainingIds = (body.input || [])
373
+ .filter((item) => item.id)
374
+ .map((item) => item.id);
375
+ if (remainingIds.length > 0) {
376
+ logWarn(`WARNING: ${remainingIds.length} IDs still present after filtering:`, remainingIds);
377
+ }
378
+ else if (originalIds.length > 0) {
379
+ logDebug(`Successfully removed all ${originalIds.length} message IDs`);
380
+ }
381
+ if (codexMode) {
382
+ // CODEX_MODE: Remove OpenCode system prompt, add bridge prompt
383
+ body.input = await filterOpenCodeSystemPrompts(body.input);
384
+ body.input = addCodexBridgeMessage(body.input, !!body.tools);
385
+ }
386
+ else {
387
+ // DEFAULT MODE: Keep original behavior with tool remap message
388
+ body.input = addToolRemapMessage(body.input, !!body.tools);
389
+ }
390
+ // Handle orphaned function_call_output items (where function_call was an item_reference that got filtered)
391
+ // Instead of removing orphans (which causes infinite loops as LLM loses tool results),
392
+ // convert them to messages to preserve context while avoiding API errors
393
+ if (body.input) {
394
+ body.input = normalizeOrphanedToolOutputs(body.input);
395
+ }
396
+ }
397
+ // Configure reasoning (prefer existing body/provider options, then config defaults)
398
+ const reasoningConfig = resolveReasoningConfig(normalizedModel, modelConfig, body);
399
+ body.reasoning = {
400
+ ...body.reasoning,
401
+ ...reasoningConfig,
402
+ };
403
+ // Configure text verbosity (support user config)
404
+ // Default: "medium" (matches Codex CLI default for all GPT-5 models)
405
+ body.text = {
406
+ ...body.text,
407
+ verbosity: resolveTextVerbosity(modelConfig, body),
408
+ };
409
+ // Add include for encrypted reasoning content
410
+ // Default: ["reasoning.encrypted_content"] (required for stateless operation with store=false)
411
+ // This allows reasoning context to persist across turns without server-side storage
412
+ body.include = resolveInclude(modelConfig, body);
413
+ // Remove unsupported parameters
414
+ body.max_output_tokens = undefined;
415
+ body.max_completion_tokens = undefined;
416
+ return body;
417
+ }
418
+ //# sourceMappingURL=request-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-transformer.js","sourceRoot":"","sources":["../../../lib/request/request-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM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A+D;YAC/D,IAAI,CAAC,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5D,CAAC;QAED,2GAA2G;QAC3G,uFAAuF;QACvF,yEAAyE;QACzE,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,GAAG,4BAA4B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvD,CAAC;IACF,CAAC;IAED,oFAAoF;IACpF,MAAM,eAAe,GAAG,sBAAsB,CAC7C,eAAe,EACf,WAAW,EACX,IAAI,CACJ,CAAC;IACF,IAAI,CAAC,SAAS,GAAG;QAChB,GAAG,IAAI,CAAC,SAAS;QACjB,GAAG,eAAe;KAClB,CAAC;IAEF,iDAAiD;IACjD,qEAAqE;IACrE,IAAI,CAAC,IAAI,GAAG;QACX,GAAG,IAAI,CAAC,IAAI;QACZ,SAAS,EAAE,oBAAoB,CAAC,WAAW,EAAE,IAAI,CAAC;KAClD,CAAC;IAEF,8CAA8C;IAC9C,+FAA+F;IAC/F,oFAAoF;IACpF,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAEjD,gCAAgC;IAChC,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;IACnC,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAEvC,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Convert SSE stream response to JSON for generateText()
3
+ * @param response - Fetch response with SSE stream
4
+ * @param headers - Response headers
5
+ * @returns Response with JSON body
6
+ */
7
+ export declare function convertSseToJson(response: Response, headers: Headers): Promise<Response>;
8
+ /**
9
+ * Ensure response has content-type header
10
+ * @param headers - Response headers
11
+ * @returns Headers with content-type set
12
+ */
13
+ export declare function ensureContentType(headers: Headers): Headers;
14
+ //# sourceMappingURL=response-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-handler.d.ts","sourceRoot":"","sources":["../../../lib/request/response-handler.ts"],"names":[],"mappings":"AAgGA;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA4D9F;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAQ3D"}