@herouucn/opencode-commandcode 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.
- package/LICENSE +21 -0
- package/README.md +163 -0
- package/_version.txt +1 -0
- package/index.ts +32 -0
- package/manifest.json +34 -0
- package/models.json +2182 -0
- package/package.json +80 -0
- package/plugin.ts +249 -0
- package/src/auth.ts +43 -0
- package/src/catalog-break.ts +41 -0
- package/src/catalog.ts +769 -0
- package/src/convert.ts +242 -0
- package/src/costs-docs.ts +179 -0
- package/src/costs-models-dev.ts +173 -0
- package/src/manifest.ts +134 -0
- package/src/model.ts +168 -0
- package/src/startup.ts +43 -0
- package/src/stream.ts +237 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brent Weatherall
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# opencode-commandcode
|
|
2
|
+
|
|
3
|
+
[](https://github.com/herouu/opencode-commandcode/actions)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
[Command Code](https://commandcode.ai) API provider for [opencode](https://opencode.ai) —— 通过一个 API key 使用 Claude、GPT、Gemini、DeepSeek、Qwen、Kimi、GLM、MiniMax、Step 等 50+ 模型。
|
|
7
|
+
|
|
8
|
+
本仓库是 [BrainerVirus/opencode-commandcode](https://github.com/BrainerVirus/opencode-commandcode) v0.7.54 的**自用 fork**,核心差异:**不发布 npm 包**。模型目录由本仓库 CI 自动同步并直推 `models.json`,插件运行时从 raw URL 拉取——模型列表与插件版本彻底解耦,永远拿最新,无需升级。
|
|
9
|
+
|
|
10
|
+
## 特性
|
|
11
|
+
|
|
12
|
+
| 特性 | 说明 |
|
|
13
|
+
|---|---|
|
|
14
|
+
| 单 key 多模型 | 通过 Command Code Provider API 聚合 50+ 模型 |
|
|
15
|
+
| 运行时目录拉取 | 每次启动拉取远端 `models.json`,新模型即时生效 |
|
|
16
|
+
| 离线兜底 | 拉取失败自动回退包内静态目录 → 本地缓存 |
|
|
17
|
+
| 目录自同步 | CI 每 6 小时检测上游新版本并直推 `main` |
|
|
18
|
+
| 数据安全护栏 | 提取失败 / 模型数跌破阈值时开 `catalog-break` issue,绝不推送坏数据 |
|
|
19
|
+
|
|
20
|
+
## 工作原理
|
|
21
|
+
|
|
22
|
+
```mermaid
|
|
23
|
+
sequenceDiagram
|
|
24
|
+
autonumber
|
|
25
|
+
participant NPM as command-code 官方 npm
|
|
26
|
+
participant CI as catalog-sync CI
|
|
27
|
+
participant REPO as 本仓库 main
|
|
28
|
+
participant PLUGIN as 插件 config hook
|
|
29
|
+
participant CACHE as 本地缓存
|
|
30
|
+
participant OC as opencode 模型列表
|
|
31
|
+
|
|
32
|
+
rect rgb(235, 248, 255)
|
|
33
|
+
Note over NPM,REPO: 同步线 · 每 6 小时(后台)
|
|
34
|
+
NPM->>CI: 发布新版本 command-code@X
|
|
35
|
+
CI->>CI: 比对 _version.txt,版本不一致
|
|
36
|
+
CI->>CI: sync-models 提取模型
|
|
37
|
+
alt 提取成功且模型数达标
|
|
38
|
+
CI->>REPO: 直推 models.json(不经 PR)
|
|
39
|
+
else 提取失败 / 跌破保护线
|
|
40
|
+
CI->>REPO: 开 catalog-break issue,不推坏数据
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
rect rgb(255, 250, 235)
|
|
45
|
+
Note over PLUGIN,OC: 使用线 · 每次启动(用户可见)
|
|
46
|
+
PLUGIN->>REPO: fetch raw models.json(8s 超时)
|
|
47
|
+
alt 拉取成功
|
|
48
|
+
PLUGIN->>CACHE: 写入缓存
|
|
49
|
+
else 拉取失败
|
|
50
|
+
PLUGIN->>CACHE: 回退 bundled → 缓存
|
|
51
|
+
end
|
|
52
|
+
CACHE->>PLUGIN: 模型列表
|
|
53
|
+
PLUGIN->>OC: 注入 provider.commandcode.models
|
|
54
|
+
end
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
三处关键设计:
|
|
58
|
+
|
|
59
|
+
1. **目录自更新**:`.github/workflows/catalog-sync.yml` 每 6 小时比对上游 `command-code` npm 版本与 `_version.txt`,有新版本则重新提取模型并**直接推送到 main**(commit 风格:`models.json edited <UTC time> (command-code@X)`)。
|
|
60
|
+
2. **运行时解耦**:插件每次启动 fetch 本仓库 raw `models.json`,不再依赖 npm 发版。
|
|
61
|
+
3. **质量护栏**:模型数跌破保护线时触发 `catalog-break` issue 并回滚,坏数据不落库。
|
|
62
|
+
|
|
63
|
+
## 快速开始
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# 1. 克隆本仓库
|
|
67
|
+
git clone https://github.com/herouu/opencode-commandcode.git
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```jsonc
|
|
71
|
+
// opencode.json(推荐 file: 引用本地 checkout,或填你的 git 地址)
|
|
72
|
+
{
|
|
73
|
+
"$schema": "https://opencode.ai/config.json",
|
|
74
|
+
"plugin": ["file:///absolute/path/to/opencode-commandcode"],
|
|
75
|
+
"provider": {
|
|
76
|
+
"commandcode": {
|
|
77
|
+
"npm": "@ai-sdk/openai-compatible",
|
|
78
|
+
"name": "Command Code",
|
|
79
|
+
"env": ["COMMANDCODE_API_KEY"],
|
|
80
|
+
"options": {
|
|
81
|
+
"baseURL": "https://api.commandcode.ai/provider/v1"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
插件只负责注入 `provider.commandcode.models` 元数据,transport 仍由 `@ai-sdk/openai-compatible` 提供。
|
|
89
|
+
|
|
90
|
+
## 配置
|
|
91
|
+
|
|
92
|
+
### API key(三选一)
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
export COMMANDCODE_API_KEY="你的 key" # 方式一:环境变量
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
opencode auth login --provider commandcode # 方式二:交互式(/connect 搜 Command Code)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
方式三:`~/.commandcode/auth.json`(若已用官方 CLI 登录则自动复用)。
|
|
103
|
+
|
|
104
|
+
### 目录源(可选覆盖)
|
|
105
|
+
|
|
106
|
+
默认拉取本仓库 `main` 分支的 `models.json`,一般无需配置。需要自定义时可覆盖:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
export COMMANDCODE_CATALOG_URL="https://raw.githubusercontent.com/herouu/opencode-commandcode/main/models.json"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
或写入 `~/.config/opencode/opencode-commandcode.json`:
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{ "catalogUrl": "https://raw.githubusercontent.com/herouu/opencode-commandcode/main/models.json" }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
| 取值 | 行为 |
|
|
119
|
+
|---|---|
|
|
120
|
+
| URL | 每次启动拉取该地址(8s 超时),成功后写本地缓存 |
|
|
121
|
+
| `disabled` | 关闭远程拉取,仅用包内静态 `models.json` |
|
|
122
|
+
|
|
123
|
+
### 选择模型
|
|
124
|
+
|
|
125
|
+
opencode 内运行 `/models` 选择(如 `commandcode/deepseek-v4-flash`)。
|
|
126
|
+
|
|
127
|
+
## 开发与维护
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
bun install
|
|
131
|
+
bun run check # CI 门槛:oxlint + oxfmt --check + bun test + tsc
|
|
132
|
+
|
|
133
|
+
bun run sync -- --remote # 本地手动刷新 models.json / manifest.json / _version.txt
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
> ⚠️ `models.json`、`manifest.json`、`_version.txt` 由 CI / 同步脚本自动生成,**不要手改**。
|
|
137
|
+
|
|
138
|
+
CI 一览:
|
|
139
|
+
|
|
140
|
+
- **`ci.yml`** — 4 个 check(test / typecheck / lint / format),push 与 PR 触发。
|
|
141
|
+
- **`catalog-sync.yml`** — 每 6 小时 + 手动 dispatch,直推 main(不经 PR、不发版)。
|
|
142
|
+
|
|
143
|
+
## 常见问题
|
|
144
|
+
|
|
145
|
+
**模型列表不更新?**
|
|
146
|
+
先确认能访问 `https://raw.githubusercontent.com/herouu/opencode-commandcode/main/models.json`;再查本机状态 `~/.local/state/opencode/commandcode-provider/startup.json` 里的 `catalogSource` 字段(应为 `remote`)。
|
|
147
|
+
|
|
148
|
+
**离线环境能用吗?**
|
|
149
|
+
能。首次成功后模型已写入本地缓存;离线启动时走 `bundled → cache` 回退链,模型不缺失。
|
|
150
|
+
|
|
151
|
+
**catalog-break issue 是什么?**
|
|
152
|
+
CI 提取失败或模型数异常时自动创建的告警 issue,表示最近一次同步被护栏拦截,正在使用上一份完好目录。
|
|
153
|
+
|
|
154
|
+
**为什么不再发布 npm?**
|
|
155
|
+
自用场景下 npm 发版是纯负担——模型目录经 raw URL 直推,升级插件包没有任何收益。
|
|
156
|
+
|
|
157
|
+
## 致谢
|
|
158
|
+
|
|
159
|
+
源自 [FanFan4204/opencode-commandcode-provider](https://github.com/FanFan4204/opencode-commandcode-provider) → [brent-weatherall/opencode-commandcode-provider](https://github.com/brent-weatherall/opencode-commandcode-provider)([Brent Weatherall](https://github.com/brent-weatherall) 原始实现)。
|
|
160
|
+
|
|
161
|
+
## 许可证
|
|
162
|
+
|
|
163
|
+
MIT — 见 [LICENSE](LICENSE)。原始版权归 [Brent Weatherall](https://github.com/brent-weatherall)。
|
package/_version.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.49.1
|
package/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { resolveApiKey } from "./src/auth.js";
|
|
2
|
+
import { CommandCodeLanguageModel } from "./src/model.js";
|
|
3
|
+
|
|
4
|
+
export interface CommandCodeProviderOptions {
|
|
5
|
+
name?: string;
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
authPaths?: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createCommandCode(options: CommandCodeProviderOptions = {}) {
|
|
13
|
+
const apiKey = resolveApiKey({ apiKey: options.apiKey, authPaths: options.authPaths });
|
|
14
|
+
if (!apiKey) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
"Command Code API key not found. Set COMMANDCODE_API_KEY env var, create ~/.commandcode/auth.json, or pass apiKey option.",
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
languageModel(modelId: string): CommandCodeLanguageModel {
|
|
22
|
+
return new CommandCodeLanguageModel(modelId, {
|
|
23
|
+
apiKey,
|
|
24
|
+
baseURL: typeof options.baseURL === "string" ? options.baseURL : undefined,
|
|
25
|
+
headers:
|
|
26
|
+
typeof options.headers === "object" && options.headers !== null
|
|
27
|
+
? (options.headers as Record<string, string>)
|
|
28
|
+
: undefined,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
package/manifest.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"generatedAt": "2026-09-05T06:00:51.158Z",
|
|
4
|
+
"pluginVersion": "0.7.54",
|
|
5
|
+
"commandCodeVersion": "1.49.1",
|
|
6
|
+
"commandCodeTarball": "https://registry.npmjs.org/command-code/-/command-code-1.49.1.tgz",
|
|
7
|
+
"modelCount": 73,
|
|
8
|
+
"reasoningModelCount": 62,
|
|
9
|
+
"extraction": {
|
|
10
|
+
"modelCatalog": "ok",
|
|
11
|
+
"costCatalog": "cli",
|
|
12
|
+
"costCatalogError": null
|
|
13
|
+
},
|
|
14
|
+
"costSources": {
|
|
15
|
+
"cli": 22,
|
|
16
|
+
"officialDocs": 46,
|
|
17
|
+
"thirdParty": 0,
|
|
18
|
+
"free": 5,
|
|
19
|
+
"fallback": 0,
|
|
20
|
+
"unmatched": 0
|
|
21
|
+
},
|
|
22
|
+
"review": {
|
|
23
|
+
"thirdParty": [],
|
|
24
|
+
"free": [
|
|
25
|
+
"inclusionai/ling-3.0-flash-free",
|
|
26
|
+
"minimax/minimax-m2.7-free",
|
|
27
|
+
"minimax/minimax-m3-free",
|
|
28
|
+
"MiniMaxAI/MiniMax-M3-Free",
|
|
29
|
+
"tencent/Hy3"
|
|
30
|
+
],
|
|
31
|
+
"unmatched": []
|
|
32
|
+
},
|
|
33
|
+
"status": "healthy"
|
|
34
|
+
}
|