opencode-aicodewith-auth 0.1.0 → 0.1.1
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.ai.md +230 -0
- package/README.md +113 -44
- package/dist/index.js +2 -1
- package/package.json +1 -1
package/README.ai.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# Install & Configure OpenCode with AICodeWith Auth
|
|
2
|
+
|
|
3
|
+
You are an LLM agent.
|
|
4
|
+
Your task is to set up **OpenCode** with **opencode-aicodewith-auth** plugin using **AICodeWith** as the authentication provider.
|
|
5
|
+
|
|
6
|
+
You MUST follow the steps **in order**. DO NOT skip any step.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Step 0 — Ask for AICodeWith API Key (MANDATORY, DO NOT SKIP)
|
|
11
|
+
|
|
12
|
+
Ask the user **exactly** this (keep the wording natural, but the meaning must be preserved):
|
|
13
|
+
|
|
14
|
+
> **"你现在有没有 AICodeWith 的 API key?"**
|
|
15
|
+
>
|
|
16
|
+
> - 如果已经有了,请直接发给我
|
|
17
|
+
> - 如果还没有,请去 **https://aicodewith.com/** 注册(按住 Command 点击链接可直接跳转),注册后会有免费体验额度
|
|
18
|
+
>
|
|
19
|
+
> 请告诉我你的情况,我会继续帮你配置。
|
|
20
|
+
|
|
21
|
+
### Branching rules (IMPORTANT)
|
|
22
|
+
|
|
23
|
+
### Case A — User HAS a key
|
|
24
|
+
|
|
25
|
+
- User provides the key (format: `sk-...` or similar).
|
|
26
|
+
- Store it temporarily as: `AICODEWITH_API_KEY`.
|
|
27
|
+
- Continue to **Step 1**.
|
|
28
|
+
|
|
29
|
+
### Case B — User DOES NOT have a key
|
|
30
|
+
|
|
31
|
+
The link **https://aicodewith.com/** is already provided above. Just wait for the user to register and come back with their key.
|
|
32
|
+
|
|
33
|
+
**Rules:**
|
|
34
|
+
- DO NOT proceed with installation until the user confirms they have obtained a key.
|
|
35
|
+
- DO NOT fabricate or guess a key.
|
|
36
|
+
- Wait patiently for the user to respond.
|
|
37
|
+
|
|
38
|
+
Only continue when the user explicitly provides an AICodeWith API key.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Step 1 — Check if OpenCode is installed
|
|
43
|
+
|
|
44
|
+
Run:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
which opencode || command -v opencode
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### If OpenCode is NOT installed
|
|
51
|
+
|
|
52
|
+
Guide the user to install OpenCode first:
|
|
53
|
+
|
|
54
|
+
**macOS (Homebrew):**
|
|
55
|
+
```bash
|
|
56
|
+
brew install opencode
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**npm:**
|
|
60
|
+
```bash
|
|
61
|
+
npm install -g opencode-ai
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Other methods:** See https://opencode.ai/docs
|
|
65
|
+
|
|
66
|
+
After installation, verify:
|
|
67
|
+
```bash
|
|
68
|
+
opencode --version
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### If OpenCode IS installed
|
|
72
|
+
|
|
73
|
+
Continue to **Step 2**.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Step 2 — Write auth.json (DO NOT use opencode auth login)
|
|
78
|
+
|
|
79
|
+
**IMPORTANT:** Do NOT run `opencode auth login` — it is an interactive command that will block. Instead, directly edit the auth.json file.
|
|
80
|
+
|
|
81
|
+
Target path:
|
|
82
|
+
- **Linux / macOS:** `~/.local/share/opencode/auth.json`
|
|
83
|
+
|
|
84
|
+
### 2.1 Ensure directory exists
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
mkdir -p ~/.local/share/opencode
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 2.2 Read existing auth.json (if exists)
|
|
91
|
+
|
|
92
|
+
If `auth.json` exists:
|
|
93
|
+
- Read and parse it as JSON.
|
|
94
|
+
- Preserve all existing providers (openai / anthropic / google / others).
|
|
95
|
+
- Only modify or insert the `aicodewith` entry.
|
|
96
|
+
|
|
97
|
+
If it does NOT exist:
|
|
98
|
+
- Start from an empty JSON object `{}`.
|
|
99
|
+
|
|
100
|
+
### 2.3 Write AICodeWith entry
|
|
101
|
+
|
|
102
|
+
Add or update the `aicodewith` entry with the user's API key:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"aicodewith": {
|
|
107
|
+
"type": "api",
|
|
108
|
+
"key": "<USER_PROVIDED_API_KEY>"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Merge rules:**
|
|
114
|
+
- If `aicodewith` exists → overwrite its `key` field only
|
|
115
|
+
- If `aicodewith` does not exist → add the entire entry
|
|
116
|
+
- **NEVER delete or modify other providers**
|
|
117
|
+
|
|
118
|
+
After writing, re-read the file to ensure it is valid JSON.
|
|
119
|
+
|
|
120
|
+
Continue to **Step 3**.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Step 3 — Configure OpenCode to use the plugin
|
|
125
|
+
|
|
126
|
+
Target path:
|
|
127
|
+
- **Global config:** `~/.config/opencode/opencode.json`
|
|
128
|
+
- **Project config:** `./opencode.json` (in current directory)
|
|
129
|
+
|
|
130
|
+
### 3.1 Ensure config directory exists
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
mkdir -p ~/.config/opencode
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 3.2 Read existing opencode.json (if exists)
|
|
137
|
+
|
|
138
|
+
If `opencode.json` exists:
|
|
139
|
+
- Read and parse it as JSON.
|
|
140
|
+
- Preserve all existing configuration.
|
|
141
|
+
|
|
142
|
+
If it does NOT exist:
|
|
143
|
+
- Start with this base structure:
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"$schema": "https://opencode.ai/config.json"
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 3.3 Add plugin to configuration
|
|
151
|
+
|
|
152
|
+
Ensure the `plugin` array includes `opencode-aicodewith-auth`:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"$schema": "https://opencode.ai/config.json",
|
|
157
|
+
"plugin": ["opencode-aicodewith-auth"]
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Merge rules:**
|
|
162
|
+
- If `plugin` array exists → append `"opencode-aicodewith-auth"` if not already present
|
|
163
|
+
- If `plugin` does not exist → create the array with `["opencode-aicodewith-auth"]`
|
|
164
|
+
- **NEVER remove existing plugins**
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Step 4 — Verify installation
|
|
169
|
+
|
|
170
|
+
Tell the user:
|
|
171
|
+
|
|
172
|
+
> "Installation complete! Please restart OpenCode to load the plugin.
|
|
173
|
+
> You can now use any of these models:
|
|
174
|
+
> - `gpt-5.2-codex`
|
|
175
|
+
> - `gpt-5.2`
|
|
176
|
+
> - `claude-sonnet-4-5-20250929`
|
|
177
|
+
> - `claude-opus-4-5-20251101`
|
|
178
|
+
> - `gemini-3-pro-high`
|
|
179
|
+
>
|
|
180
|
+
> To test, run: `opencode --model gpt-5.2-codex`"
|
|
181
|
+
|
|
182
|
+
Or in Chinese:
|
|
183
|
+
|
|
184
|
+
> "安装完成!请重启 OpenCode 以加载插件。
|
|
185
|
+
> 你现在可以使用以下模型:
|
|
186
|
+
> - `gpt-5.2-codex`
|
|
187
|
+
> - `gpt-5.2`
|
|
188
|
+
> - `claude-sonnet-4-5-20250929`
|
|
189
|
+
> - `claude-opus-4-5-20251101`
|
|
190
|
+
> - `gemini-3-pro-high`
|
|
191
|
+
>
|
|
192
|
+
> 测试命令: `opencode --model gpt-5.2-codex`"
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Summary of changes
|
|
197
|
+
|
|
198
|
+
| File | Description |
|
|
199
|
+
|------|-------------|
|
|
200
|
+
| `~/.local/share/opencode/auth.json` | Stores AICodeWith API key |
|
|
201
|
+
| `~/.config/opencode/opencode.json` | Registers the plugin |
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Troubleshooting
|
|
206
|
+
|
|
207
|
+
If the user reports issues:
|
|
208
|
+
|
|
209
|
+
### "Provider not found: aicodewith"
|
|
210
|
+
- Verify `opencode.json` contains `"plugin": ["opencode-aicodewith-auth"]`
|
|
211
|
+
- Ask user to restart OpenCode
|
|
212
|
+
|
|
213
|
+
### "Authentication failed"
|
|
214
|
+
- Verify `auth.json` has correct key format
|
|
215
|
+
- Ask user to double-check their API key at https://aicodewith.com/
|
|
216
|
+
|
|
217
|
+
### "Model not found"
|
|
218
|
+
- The plugin auto-injects models on first load
|
|
219
|
+
- Ask user to restart OpenCode and try again
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Important rules for the AI agent
|
|
224
|
+
|
|
225
|
+
1. **NEVER skip Step 0** — Always ask for the API key first
|
|
226
|
+
2. **NEVER fabricate API keys** — Only use what the user provides
|
|
227
|
+
3. **NEVER delete existing config** — Always merge, never overwrite entirely
|
|
228
|
+
4. **NEVER run interactive commands** — Do NOT run `opencode auth login`, it will block. Edit files directly instead.
|
|
229
|
+
5. **ALWAYS verify file writes** — Re-read after writing to confirm valid JSON
|
|
230
|
+
6. **ALWAYS wait for user confirmation** — Don't assume, ask when unclear
|
package/README.md
CHANGED
|
@@ -1,56 +1,117 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
opencode-aicodewith-auth
|
|
3
|
+
An OpenCode auth plugin for AICodewith
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
<div align="center">
|
|
7
|
+
|
|
1
8
|
# opencode-aicodewith-auth
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
**OpenCode 的 AICodewith 认证插件**
|
|
11
|
+
一次登录 → 多模型可用(GPT、Claude、Gemini)
|
|
12
|
+
|
|
13
|
+
[](https://www.npmjs.com/package/opencode-aicodewith-auth)
|
|
14
|
+
[](https://www.npmjs.com/package/opencode-aicodewith-auth)
|
|
15
|
+
[](#license)
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 这是什么
|
|
22
|
+
|
|
23
|
+
OpenCode 支持多种 AI 提供商。这个插件把 **AICodewith** 作为统一的认证层,让你可以:
|
|
24
|
+
|
|
25
|
+
- 只维护 **一份** 配置
|
|
26
|
+
- 只认证 **一次**
|
|
27
|
+
- 在 OpenCode 里自由切换多个模型
|
|
28
|
+
|
|
29
|
+
如果你需要同时用 OpenAI / Anthropic / Google 的模型,这个插件能让配置变得简单可控。
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 支持的模型
|
|
34
|
+
|
|
35
|
+
开箱即用,插件提供以下模型:
|
|
36
|
+
|
|
37
|
+
- `gpt-5.2-codex`
|
|
38
|
+
- `gpt-5.2`
|
|
39
|
+
- `claude-sonnet-4-5-20250929`
|
|
40
|
+
- `claude-opus-4-5-20251101`
|
|
41
|
+
- `gemini-3-pro-high`
|
|
4
42
|
|
|
5
|
-
|
|
43
|
+
> AICodewith 后续支持更多模型时,插件也会同步更新。
|
|
6
44
|
|
|
7
|
-
|
|
8
|
-
- Support for the following models:
|
|
9
|
-
- `gpt-5.2-codex` - OpenAI GPT-5.2 Codex
|
|
10
|
-
- `gpt-5.2` - OpenAI GPT-5.2
|
|
11
|
-
- `claude-sonnet-4-5-20250929` - Anthropic Claude Sonnet 4.5
|
|
12
|
-
- `claude-opus-4-5-20251101` - Anthropic Claude Opus 4.5
|
|
13
|
-
- `gemini-3-pro-high` - Google Gemini 3 Pro High
|
|
14
|
-
- Automatic configuration injection
|
|
45
|
+
---
|
|
15
46
|
|
|
16
|
-
##
|
|
47
|
+
## 安装
|
|
17
48
|
|
|
18
|
-
###
|
|
49
|
+
### 第一步:获取 API Key
|
|
19
50
|
|
|
20
|
-
|
|
51
|
+
去 **https://aicodewith.com/** 注册账号,注册后会获得 API Key 和体验额度。
|
|
21
52
|
|
|
22
|
-
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### 第二步:让 AI 帮你装(推荐)
|
|
56
|
+
|
|
57
|
+
打开你的 AI 编程助手(OpenCode / Claude Code / Cursor 等),粘贴这句话:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
帮我安装配置 opencode-aicodewith-auth,按照这个说明操作:https://raw.githubusercontent.com/DaneelOlivaw1/opencode-aicodewith-auth/main/README.ai.md
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
AI 会引导你完成整个安装流程。
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
<details>
|
|
68
|
+
<summary><strong>手动安装</strong></summary>
|
|
69
|
+
|
|
70
|
+
#### 1. 添加插件
|
|
71
|
+
|
|
72
|
+
在你的 OpenCode 配置文件中添加插件:
|
|
73
|
+
|
|
74
|
+
```json
|
|
23
75
|
{
|
|
24
76
|
"$schema": "https://opencode.ai/config.json",
|
|
25
77
|
"plugin": ["opencode-aicodewith-auth"]
|
|
26
78
|
}
|
|
27
79
|
```
|
|
28
80
|
|
|
29
|
-
|
|
81
|
+
#### 2. 重启 OpenCode
|
|
30
82
|
|
|
31
|
-
|
|
83
|
+
关闭并重新打开 OpenCode,让插件生效。
|
|
32
84
|
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
git clone https://github.com/DaneelOlivaw1/opencode-aicodewith-auth.git
|
|
36
|
-
cd opencode-aicodewith-auth
|
|
37
|
-
```
|
|
85
|
+
#### 3. 运行认证
|
|
38
86
|
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
bun install
|
|
42
|
-
```
|
|
87
|
+
在终端运行:
|
|
43
88
|
|
|
44
|
-
3. Build the plugin:
|
|
45
89
|
```bash
|
|
46
|
-
|
|
90
|
+
opencode auth login
|
|
47
91
|
```
|
|
48
92
|
|
|
49
|
-
|
|
93
|
+
按提示操作:
|
|
94
|
+
|
|
95
|
+
1. 选择 **Other**
|
|
96
|
+
2. 供应商名称填:`aicodewith`
|
|
97
|
+
3. 输入你的 API Key(在 AICodewith 平台创建的 key)
|
|
98
|
+
4. 回车完成
|
|
99
|
+
|
|
100
|
+

|
|
101
|
+
|
|
102
|
+
</details>
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Provider 配置
|
|
50
107
|
|
|
51
|
-
|
|
108
|
+
### 自动注入(默认)
|
|
52
109
|
|
|
53
|
-
|
|
110
|
+
安装后,插件会自动在你的 OpenCode 配置中注入 `aicodewith` provider。
|
|
111
|
+
|
|
112
|
+
如果你想手动管理,可以用这个模板:
|
|
113
|
+
|
|
114
|
+
```json
|
|
54
115
|
{
|
|
55
116
|
"provider": {
|
|
56
117
|
"aicodewith": {
|
|
@@ -69,46 +130,54 @@ After installation, the plugin will automatically configure the `aicodewith` pro
|
|
|
69
130
|
}
|
|
70
131
|
```
|
|
71
132
|
|
|
72
|
-
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 使用
|
|
73
136
|
|
|
74
|
-
|
|
137
|
+
启动时指定模型:
|
|
75
138
|
|
|
76
139
|
```bash
|
|
77
|
-
|
|
140
|
+
opencode --model gpt-5.2-codex
|
|
78
141
|
```
|
|
79
142
|
|
|
80
|
-
|
|
143
|
+
或者在 OpenCode 界面里切换模型。
|
|
81
144
|
|
|
82
|
-
|
|
145
|
+
---
|
|
83
146
|
|
|
84
|
-
|
|
147
|
+
## 常见问题
|
|
85
148
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
149
|
+
### "Provider not found: aicodewith"
|
|
150
|
+
|
|
151
|
+
* 确认 `opencode.json` 中有 `"plugin": ["opencode-aicodewith-auth"]`
|
|
152
|
+
* 修改配置后记得重启 OpenCode
|
|
89
153
|
|
|
90
|
-
|
|
154
|
+
---
|
|
91
155
|
|
|
92
|
-
##
|
|
156
|
+
## 开发
|
|
93
157
|
|
|
94
|
-
|
|
158
|
+
克隆并构建:
|
|
95
159
|
|
|
96
160
|
```bash
|
|
161
|
+
git clone https://github.com/DaneelOlivaw1/opencode-aicodewith-auth.git
|
|
162
|
+
cd opencode-aicodewith-auth
|
|
163
|
+
bun install
|
|
97
164
|
bun run build
|
|
98
165
|
```
|
|
99
166
|
|
|
100
|
-
|
|
167
|
+
类型检查:
|
|
101
168
|
|
|
102
169
|
```bash
|
|
103
170
|
bun run typecheck
|
|
104
171
|
```
|
|
105
172
|
|
|
106
|
-
|
|
173
|
+
清理:
|
|
107
174
|
|
|
108
175
|
```bash
|
|
109
176
|
bun run clean
|
|
110
177
|
```
|
|
111
178
|
|
|
179
|
+
---
|
|
180
|
+
|
|
112
181
|
## License
|
|
113
182
|
|
|
114
183
|
MIT
|
package/dist/index.js
CHANGED
|
@@ -998,7 +998,8 @@ var CODEX_MODEL_PREFIXES = ["gpt-", "codex"];
|
|
|
998
998
|
var PACKAGE_NAME = "opencode-aicodewith-auth";
|
|
999
999
|
var PROVIDER_NAME = "AICodewith";
|
|
1000
1000
|
var PLUGIN_ENTRY = import.meta.url;
|
|
1001
|
-
var
|
|
1001
|
+
var PROVIDER_EXT = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
|
|
1002
|
+
var PROVIDER_NPM = new URL(`./provider${PROVIDER_EXT}`, import.meta.url).href;
|
|
1002
1003
|
var DEFAULT_API = "https://api.openai.com/v1";
|
|
1003
1004
|
var DEFAULT_ENV = ["AICODEWITH_API_KEY"];
|
|
1004
1005
|
var DEFAULT_OUTPUT_TOKEN_MAX = 32000;
|
package/package.json
CHANGED