opencode-openai-multi-auth 5.0.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 (89) hide show
  1. package/LICENSE +37 -0
  2. package/README.md +145 -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 +4 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +321 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/lib/accounts/index.d.ts +4 -0
  14. package/dist/lib/accounts/index.d.ts.map +1 -0
  15. package/dist/lib/accounts/index.js +3 -0
  16. package/dist/lib/accounts/index.js.map +1 -0
  17. package/dist/lib/accounts/manager.d.ts +23 -0
  18. package/dist/lib/accounts/manager.d.ts.map +1 -0
  19. package/dist/lib/accounts/manager.js +270 -0
  20. package/dist/lib/accounts/manager.js.map +1 -0
  21. package/dist/lib/accounts/types.d.ts +35 -0
  22. package/dist/lib/accounts/types.d.ts.map +1 -0
  23. package/dist/lib/accounts/types.js +10 -0
  24. package/dist/lib/accounts/types.js.map +1 -0
  25. package/dist/lib/auth/auth.d.ts +43 -0
  26. package/dist/lib/auth/auth.d.ts.map +1 -0
  27. package/dist/lib/auth/auth.js +163 -0
  28. package/dist/lib/auth/auth.js.map +1 -0
  29. package/dist/lib/auth/browser.d.ts +17 -0
  30. package/dist/lib/auth/browser.d.ts.map +1 -0
  31. package/dist/lib/auth/browser.js +76 -0
  32. package/dist/lib/auth/browser.js.map +1 -0
  33. package/dist/lib/auth/server.d.ts +10 -0
  34. package/dist/lib/auth/server.d.ts.map +1 -0
  35. package/dist/lib/auth/server.js +78 -0
  36. package/dist/lib/auth/server.js.map +1 -0
  37. package/dist/lib/config.d.ts +17 -0
  38. package/dist/lib/config.d.ts.map +1 -0
  39. package/dist/lib/config.js +51 -0
  40. package/dist/lib/config.js.map +1 -0
  41. package/dist/lib/constants.d.ts +67 -0
  42. package/dist/lib/constants.d.ts.map +1 -0
  43. package/dist/lib/constants.js +67 -0
  44. package/dist/lib/constants.js.map +1 -0
  45. package/dist/lib/logger.d.ts +21 -0
  46. package/dist/lib/logger.d.ts.map +1 -0
  47. package/dist/lib/logger.js +77 -0
  48. package/dist/lib/logger.js.map +1 -0
  49. package/dist/lib/oauth-success.html +712 -0
  50. package/dist/lib/prompts/codex-opencode-bridge.d.ts +19 -0
  51. package/dist/lib/prompts/codex-opencode-bridge.d.ts.map +1 -0
  52. package/dist/lib/prompts/codex-opencode-bridge.js +152 -0
  53. package/dist/lib/prompts/codex-opencode-bridge.js.map +1 -0
  54. package/dist/lib/prompts/codex.d.ts +27 -0
  55. package/dist/lib/prompts/codex.d.ts.map +1 -0
  56. package/dist/lib/prompts/codex.js +241 -0
  57. package/dist/lib/prompts/codex.js.map +1 -0
  58. package/dist/lib/prompts/opencode-codex.d.ts +21 -0
  59. package/dist/lib/prompts/opencode-codex.d.ts.map +1 -0
  60. package/dist/lib/prompts/opencode-codex.js +91 -0
  61. package/dist/lib/prompts/opencode-codex.js.map +1 -0
  62. package/dist/lib/request/fetch-helpers.d.ts +73 -0
  63. package/dist/lib/request/fetch-helpers.d.ts.map +1 -0
  64. package/dist/lib/request/fetch-helpers.js +221 -0
  65. package/dist/lib/request/fetch-helpers.js.map +1 -0
  66. package/dist/lib/request/helpers/input-utils.d.ts +6 -0
  67. package/dist/lib/request/helpers/input-utils.d.ts.map +1 -0
  68. package/dist/lib/request/helpers/input-utils.js +174 -0
  69. package/dist/lib/request/helpers/input-utils.js.map +1 -0
  70. package/dist/lib/request/helpers/model-map.d.ts +28 -0
  71. package/dist/lib/request/helpers/model-map.d.ts.map +1 -0
  72. package/dist/lib/request/helpers/model-map.js +109 -0
  73. package/dist/lib/request/helpers/model-map.js.map +1 -0
  74. package/dist/lib/request/request-transformer.d.ts +93 -0
  75. package/dist/lib/request/request-transformer.d.ts.map +1 -0
  76. package/dist/lib/request/request-transformer.js +403 -0
  77. package/dist/lib/request/request-transformer.js.map +1 -0
  78. package/dist/lib/request/response-handler.d.ts +14 -0
  79. package/dist/lib/request/response-handler.d.ts.map +1 -0
  80. package/dist/lib/request/response-handler.js +88 -0
  81. package/dist/lib/request/response-handler.js.map +1 -0
  82. package/dist/lib/types.d.ts +167 -0
  83. package/dist/lib/types.d.ts.map +1 -0
  84. package/dist/lib/types.js +2 -0
  85. package/dist/lib/types.js.map +1 -0
  86. package/package.json +73 -0
  87. package/scripts/install-opencode-codex-auth.js +430 -0
  88. package/scripts/test-all-models.sh +259 -0
  89. package/scripts/validate-model-map.sh +97 -0
package/LICENSE ADDED
@@ -0,0 +1,37 @@
1
+ MIT License with Usage Disclaimer
2
+
3
+ Copyright (c) 2024-2025 numman-ali
4
+
5
+ USAGE NOTICE AND DISCLAIMER:
6
+ This software is provided for personal development use only. Users must comply
7
+ with OpenAI's Terms of Service (https://openai.com/policies/terms-of-use/) and
8
+ Usage Policies (https://openai.com/policies/usage-policies/) when using this
9
+ software to access OpenAI services.
10
+
11
+ The authors and contributors are not responsible for any violations of
12
+ third-party terms of service. For commercial use or production applications,
13
+ obtain proper API access from OpenAI directly through the OpenAI Platform
14
+ (https://platform.openai.com/).
15
+
16
+ This software uses OpenAI's official OAuth authentication system and is not
17
+ affiliated with, endorsed by, or sponsored by OpenAI.
18
+
19
+ ---
20
+
21
+ Permission is hereby granted, free of charge, to any person obtaining a copy
22
+ of this software and associated documentation files (the "Software"), to deal
23
+ in the Software without restriction, including without limitation the rights
24
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
+ copies of the Software, and to permit persons to whom the Software is
26
+ furnished to do so, subject to the following conditions:
27
+
28
+ The above copyright notice, usage notice, and this permission notice shall be
29
+ included in all copies or substantial portions of the Software.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,145 @@
1
+ ![Image 1: opencode-openai-multi-auth](assets/readme-hero.svg)
2
+
3
+ **Maintained by [ZenysTX](https://x.com/zenysTX)**
4
+ **Most of the work and original implementation by [Numman Ali](https://x.com/nummanali)**
5
+ **Inspired by [opencode-google-antigravity-auth](https://github.com/shekohex/opencode-google-antigravity-auth)**
6
+ [![Twitter Follow](https://img.shields.io/twitter/follow/zenysTX?style=social)](https://x.com/zenysTX)
7
+
8
+
9
+
10
+
11
+
12
+ [![Twitter Follow](https://img.shields.io/twitter/follow/nummanali?style=social)](https://x.com/nummanali)
13
+ [![npm version](https://img.shields.io/npm/v/opencode-openai-multi-auth.svg)](https://www.npmjs.com/package/opencode-openai-multi-auth)
14
+ [![Tests](https://github.com/dkraemerwork/opencode-openai-multi-auth/actions/workflows/ci.yml/badge.svg)](https://github.com/dkraemerwork/opencode-openai-multi-auth/actions)
15
+ [![npm downloads](https://img.shields.io/npm/dm/opencode-openai-multi-auth.svg)](https://www.npmjs.com/package/opencode-openai-multi-auth)
16
+ **One install. Every Codex model. Multi-account ready.**
17
+ [Install](#-quick-start) · [Models](#-models) · [Configuration](#-configuration) · [Docs](#-docs)
18
+
19
+ ---
20
+
21
+ ## 💡 Philosophy
22
+
23
+ > **"One config. Every model."**
24
+ > OpenCode should feel effortless. This plugin keeps the setup minimal while giving you full GPT‑5.x + Codex access via ChatGPT OAuth across multiple accounts
25
+ > from different organizations.
26
+
27
+ ```
28
+ ┌─────────────────────────────────────────────────────────┐
29
+ │ │
30
+ │ ChatGPT OAuth → Codex backend → OpenCode │
31
+ │ One command install, full model presets, done. │
32
+ │ │
33
+ └─────────────────────────────────────────────────────────┘
34
+ ```
35
+
36
+ ---
37
+
38
+ ## 🚀 Quick Start
39
+
40
+ ```bash
41
+ npx -y opencode-openai-multi-auth@latest
42
+ ```
43
+
44
+ Then:
45
+
46
+ ```bash
47
+ opencode auth login
48
+ opencode run "write hello world to test.txt" --model=openai/gpt-5.2 --variant=medium
49
+ ```
50
+
51
+ Legacy OpenCode (v1.0.209 and below):
52
+
53
+ ```bash
54
+ npx -y opencode-openai-multi-auth@latest --legacy
55
+ opencode run "write hello world to test.txt" --model=openai/gpt-5.2-medium
56
+ ```
57
+
58
+ Uninstall:
59
+
60
+ ```bash
61
+ npx -y opencode-openai-multi-auth@latest --uninstall
62
+ npx -y opencode-openai-multi-auth@latest --uninstall --all
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 📦 Models
68
+
69
+ - **gpt-5.2** (none/low/medium/high/xhigh)
70
+ - **gpt-5.2-codex** (low/medium/high/xhigh)
71
+ - **gpt-5.1-codex-max** (low/medium/high/xhigh)
72
+ - **gpt-5.1-codex** (low/medium/high)
73
+ - **gpt-5.1-codex-mini** (medium/high)
74
+ - **gpt-5.1** (none/low/medium/high)
75
+
76
+ ---
77
+
78
+ ## 🧩 Configuration
79
+
80
+ - Modern (OpenCode v1.0.210+): `config/opencode-modern.json`
81
+ - Legacy (OpenCode v1.0.209 and below): `config/opencode-legacy.json`
82
+
83
+ Minimal configs are not supported for GPT‑5.x; use the full configs above.
84
+ ---
85
+
86
+ ## ✅ Features
87
+
88
+ - **Multi-account support** with automatic rotation on rate limits
89
+ - ChatGPT Plus/Pro OAuth authentication (official flow)
90
+ - 22 model presets across GPT‑5.2 / GPT‑5.2 Codex / GPT‑5.1 families
91
+ - Variant system support (v1.0.210+) + legacy presets
92
+ - Multimodal input enabled for all models
93
+ - Toast notifications for account switches and rate limits
94
+ - Usage‑aware errors + automatic token refresh
95
+
96
+ ---
97
+
98
+ ## 🔄 Multi-Account Support
99
+
100
+ Add multiple ChatGPT accounts and automatically rotate between them when rate limited:
101
+
102
+ ```bash
103
+ # Add first account
104
+ opencode auth login
105
+ # Select "ChatGPT Plus/Pro (Codex Subscription)"
106
+
107
+ # Add additional accounts
108
+ opencode auth login
109
+ # Select "Add Another OpenAI Account"
110
+ ```
111
+
112
+ **Features:**
113
+ - Automatic rotation when an account hits rate limits
114
+ - Per-model rate limit tracking
115
+ - Toast notifications showing active account
116
+ - Seamless failover between accounts
117
+ - Imports existing tokens from OpenCode auth
118
+
119
+ **Environment Variables:**
120
+ | Variable | Description |
121
+ |----------|-------------|
122
+ | `OPENCODE_OPENAI_QUIET=1` | Disable toast notifications |
123
+ | `OPENCODE_OPENAI_DEBUG=1` | Enable debug logging |
124
+ | `OPENCODE_OPENAI_STRATEGY` | Account selection: `sticky` (default), `round-robin`, `hybrid` |
125
+
126
+ **Accounts storage:** `~/.config/opencode/openai-accounts.json`
127
+
128
+ ---
129
+
130
+ ## 📚 Docs
131
+
132
+ - Getting Started: `docs/getting-started.md`
133
+ - Configuration: `docs/configuration.md`
134
+ - Troubleshooting: `docs/troubleshooting.md`
135
+ - Architecture: `docs/development/ARCHITECTURE.md`
136
+
137
+ ---
138
+
139
+ ## ⚠️ Usage Notice
140
+
141
+ This plugin is for **personal development use** with your own ChatGPT Plus/Pro subscriptions.
142
+
143
+ **Built for developers who value simplicity.**
144
+
145
+ ## Force Build 1
@@ -0,0 +1,18 @@
1
+ <svg width="234" height="42" viewBox="0 0 234 42" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M18 30H6V18H18V30Z" fill="#4B4646"/>
3
+ <path d="M18 12H6V30H18V12ZM24 36H0V6H24V36Z" fill="#B7B1B1"/>
4
+ <path d="M48 30H36V18H48V30Z" fill="#4B4646"/>
5
+ <path d="M36 30H48V12H36V30ZM54 36H36V42H30V6H54V36Z" fill="#B7B1B1"/>
6
+ <path d="M84 24V30H66V24H84Z" fill="#4B4646"/>
7
+ <path d="M84 24H66V30H84V36H60V6H84V24ZM66 18H78V12H66V18Z" fill="#B7B1B1"/>
8
+ <path d="M108 36H96V18H108V36Z" fill="#4B4646"/>
9
+ <path d="M108 12H96V36H90V6H108V12ZM114 36H108V12H114V36Z" fill="#B7B1B1"/>
10
+ <path d="M144 30H126V18H144V30Z" fill="#4B4646"/>
11
+ <path d="M144 12H126V30H144V36H120V6H144V12Z" fill="#F1ECEC"/>
12
+ <path d="M168 30H156V18H168V30Z" fill="#4B4646"/>
13
+ <path d="M168 12H156V30H168V12ZM174 36H150V6H174V36Z" fill="#F1ECEC"/>
14
+ <path d="M198 30H186V18H198V30Z" fill="#4B4646"/>
15
+ <path d="M198 12H186V30H198V12ZM204 36H180V6H198V0H204V36Z" fill="#F1ECEC"/>
16
+ <path d="M234 24V30H216V24H234Z" fill="#4B4646"/>
17
+ <path d="M216 12V18H228V12H216ZM234 24H216V30H234V36H210V6H234V24Z" fill="#F1ECEC"/>
18
+ </svg>
@@ -0,0 +1,31 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1200" height="300" viewBox="0 0 1200 300" role="img" aria-label="OpenCode Codex OAuth">
2
+ <defs>
3
+ <linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0%" stop-color="#0f172a" />
5
+ <stop offset="100%" stop-color="#1f2937" />
6
+ </linearGradient>
7
+ <linearGradient id="accent" x1="0" y1="0" x2="1" y2="0">
8
+ <stop offset="0%" stop-color="#38bdf8" />
9
+ <stop offset="100%" stop-color="#22d3ee" />
10
+ </linearGradient>
11
+ </defs>
12
+ <rect width="1200" height="300" rx="28" fill="url(#bg)" />
13
+ <g opacity="0.12">
14
+ <circle cx="1020" cy="70" r="120" fill="#38bdf8" />
15
+ <circle cx="150" cy="260" r="140" fill="#22d3ee" />
16
+ </g>
17
+ <g fill="none" stroke="url(#accent)" stroke-width="8" stroke-linecap="round" stroke-linejoin="round">
18
+ <path d="M160 95 L100 150 L160 205" />
19
+ <path d="M280 95 L340 150 L280 205" />
20
+ <path d="M205 80 L235 220" />
21
+ </g>
22
+ <text x="420" y="120" fill="#e2e8f0" font-size="42" font-family="'IBM Plex Sans','Segoe UI',Arial,sans-serif" font-weight="600">
23
+ OpenCode Codex OAuth
24
+ </text>
25
+ <text x="420" y="170" fill="#cbd5f5" font-size="24" font-family="'IBM Plex Sans','Segoe UI',Arial,sans-serif">
26
+ ChatGPT Plus/Pro auth for GPT-5.2 and Codex models
27
+ </text>
28
+ <text x="420" y="220" fill="#7dd3fc" font-size="18" font-family="'IBM Plex Sans','Segoe UI',Arial,sans-serif">
29
+ One-command install, modern variants, full tool support
30
+ </text>
31
+ </svg>
@@ -0,0 +1,103 @@
1
+ # Configuration
2
+
3
+ This directory contains the official opencode configuration files for the OpenAI Codex OAuth plugin.
4
+
5
+ ## ⚠️ REQUIRED: Choose the Right Configuration
6
+
7
+ **Two configuration files are available based on your OpenCode version:**
8
+
9
+ | File | OpenCode Version | Description |
10
+ |------|------------------|-------------|
11
+ | [`opencode-modern.json`](./opencode-modern.json) | **v1.0.210+ (Jan 2026+)** | Compact config using variants system - 6 models with built-in reasoning level variants |
12
+ | [`opencode-legacy.json`](./opencode-legacy.json) | **v1.0.209 and below** | Extended config with separate model entries for each reasoning level - 20+ individual model definitions |
13
+
14
+ ### Which one should I use?
15
+
16
+ **If you have OpenCode v1.0.210 or newer** (check with `opencode --version`):
17
+ ```bash
18
+ cp config/opencode-modern.json ~/.config/opencode/opencode.jsonc
19
+ ```
20
+
21
+ **If you have OpenCode v1.0.209 or older**:
22
+ ```bash
23
+ cp config/opencode-legacy.json ~/.config/opencode/opencode.jsonc
24
+ ```
25
+
26
+ ### Why two configs?
27
+
28
+ OpenCode v1.0.210+ introduced a **variants system** that allows defining reasoning effort levels as variants under a single model. This reduces config size from 572 lines to ~150 lines while maintaining the same functionality.
29
+
30
+ **What you get:**
31
+
32
+ | Config File | Model Families | Reasoning Variants | Total Models |
33
+ |------------|----------------|-------------------|--------------|
34
+ | `opencode-modern.json` | 6 | Built-in variants (low/medium/high/xhigh) | 6 base models with 19 total variants |
35
+ | `opencode-legacy.json` | 6 | Separate model entries | 20 individual model definitions |
36
+
37
+ Both configs provide:
38
+ - ✅ All supported GPT 5.2/5.1 variants: gpt-5.2, gpt-5.2-codex, gpt-5.1, gpt-5.1-codex, gpt-5.1-codex-max, gpt-5.1-codex-mini
39
+ - ✅ Proper reasoning effort settings for each variant (including `xhigh` for Codex Max/5.2)
40
+ - ✅ Context limits (272k context / 128k output for all Codex families)
41
+ - ✅ Required options: `store: false`, `include: ["reasoning.encrypted_content"]`
42
+ - ✅ Image input support for all models
43
+ - ✅ All required metadata for OpenCode features
44
+
45
+ ### Modern Config Benefits (v1.0.210+)
46
+
47
+ - **74% smaller**: 150 lines vs 572 lines
48
+ - **DRY**: Common options defined once at provider level
49
+ - **Variant cycling**: Built-in support for `Ctrl+T` to switch reasoning levels
50
+ - **Easier maintenance**: Add new variants without copying model definitions
51
+
52
+ ## Usage
53
+
54
+ 1. **Check your OpenCode version**:
55
+ ```bash
56
+ opencode --version
57
+ ```
58
+
59
+ 2. **Copy the appropriate config** based on your version:
60
+ ```bash
61
+ # For v1.0.210+ (recommended):
62
+ cp config/opencode-modern.json ~/.config/opencode/opencode.jsonc
63
+
64
+ # For older versions:
65
+ cp config/opencode-legacy.json ~/.config/opencode/opencode.jsonc
66
+ ```
67
+
68
+ 3. **Run opencode**:
69
+ ```bash
70
+ # Modern config (v1.0.210+):
71
+ opencode run "task" --model=openai/gpt-5.2 --variant=medium
72
+ opencode run "task" --model=openai/gpt-5.2 --variant=high
73
+
74
+ # Legacy config:
75
+ opencode run "task" --model=openai/gpt-5.2-medium
76
+ opencode run "task" --model=openai/gpt-5.2-high
77
+ ```
78
+
79
+ > **⚠️ Important**: Use the config file appropriate for your OpenCode version. Using the modern config with an older OpenCode version (v1.0.209 or below) will not work correctly.
80
+
81
+ > **Note**: The config templates use an **unversioned** plugin entry (`opencode-openai-multi-auth`) so the installer can always pull the latest release. If you need reproducibility, pin a specific version manually.
82
+
83
+ ## Available Models
84
+
85
+ Both configs provide access to the same model families:
86
+
87
+ - **gpt-5.2** (none/low/medium/high/xhigh) - Latest GPT 5.2 model with full reasoning support
88
+ - **gpt-5.2-codex** (low/medium/high/xhigh) - GPT 5.2 Codex presets
89
+ - **gpt-5.1-codex-max** (low/medium/high/xhigh) - Codex Max presets
90
+ - **gpt-5.1-codex** (low/medium/high) - Codex model presets
91
+ - **gpt-5.1-codex-mini** (medium/high) - Codex mini tier presets
92
+ - **gpt-5.1** (none/low/medium/high) - General-purpose reasoning presets
93
+
94
+ All appear in the opencode model selector as "GPT 5.1 Codex Low (OAuth)", "GPT 5.1 High (OAuth)", etc.
95
+
96
+ ## Configuration Options
97
+
98
+ See the main [README.md](../README.md#configuration) for detailed documentation of all configuration options.
99
+
100
+ ## Version History
101
+
102
+ - **January 2026 (v1.0.210+)**: Introduced variant system support. Use `opencode-modern.json`
103
+ - **December 2025 and earlier**: Use `opencode-legacy.json`
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://opencode.ai/config.json",
3
+ "plugin": ["opencode-openai-multi-auth"],
4
+ "provider": {
5
+ "openai": {
6
+ "options": {
7
+ "store": false
8
+ }
9
+ }
10
+ },
11
+ "model": "openai/gpt-5-codex"
12
+ }