@joaogsbarbosa/opencode-9router 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.id.md +498 -0
- package/README.md +506 -3
- package/dist/cache.d.ts +28 -0
- package/dist/cache.js +168 -0
- package/dist/capabilities.d.ts +50 -0
- package/dist/capabilities.js +300 -0
- package/dist/constants.d.ts +43 -0
- package/dist/constants.js +106 -0
- package/dist/discovery.d.ts +9 -0
- package/dist/discovery.js +145 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +21 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.js +85 -0
- package/dist/reasoning.d.ts +15 -0
- package/dist/reasoning.js +58 -0
- package/dist/types.d.ts +98 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.js +38 -0
- package/dist/v2-map.d.ts +19 -0
- package/dist/v2-map.js +104 -0
- package/dist/v2.d.ts +17 -0
- package/dist/v2.js +316 -0
- package/package.json +59 -6
- package/server.js +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vheins
|
|
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.id.md
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
# @vheins/opencode-9router
|
|
2
|
+
|
|
3
|
+
Plugin provider OpenCode untuk [9Router](https://github.com/decolua/9router) — Router AI & Penghemat Token GRATIS. 40+ provider, 100+ model.
|
|
4
|
+
|
|
5
|
+
Mendaftarkan 9Router sebagai custom provider di OpenCode dengan auto-discovery model.
|
|
6
|
+
|
|
7
|
+
> **Dukungan Ganda V1 + V2.** Paket ini menyediakan satu entrypoint yang bekerja di **OpenCode V1** (via hook `server` V1, OpenCode `1.18.29`+) maupun **OpenCode V2** (via API `Plugin.define({ id, setup })`). Core discovery dipakai bersama; hanya entrypoint plugin yang berbeda. Tidak perlu paket terpisah.
|
|
8
|
+
|
|
9
|
+
## Mulai Cepat
|
|
10
|
+
|
|
11
|
+
### OpenCode V1
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"$schema": "https://opencode.ai/config.json",
|
|
16
|
+
"plugin": ["@vheins/opencode-9router@latest"]
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
1. Tambahkan plugin ke `opencode.json`
|
|
21
|
+
2. Restart OpenCode
|
|
22
|
+
3. `/models` → pilih model 9Router
|
|
23
|
+
|
|
24
|
+
### OpenCode V2
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"$schema": "https://opencode.ai/config.json",
|
|
29
|
+
"plugins": ["@vheins/opencode-9router@latest"]
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Atau dengan opsi plugin (bentuk objek):
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"$schema": "https://opencode.ai/config.json",
|
|
38
|
+
"plugins": [
|
|
39
|
+
{
|
|
40
|
+
"package": "@vheins/opencode-9router@latest",
|
|
41
|
+
"options": {
|
|
42
|
+
"baseURL": "http://localhost:20128",
|
|
43
|
+
"apiKey": "{env:ROUTER_API_KEY}",
|
|
44
|
+
"cache": true,
|
|
45
|
+
"cacheTTL": 10800000,
|
|
46
|
+
"discoveryTimeout": 30000
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Plugin akan otomatis mendeteksi model dari `http://localhost:20128` (default).
|
|
54
|
+
|
|
55
|
+
## Fitur
|
|
56
|
+
|
|
57
|
+
- **Auto-discover model** — Model dari 9Router terdeteksi otomatis saat startup
|
|
58
|
+
- **Cache cerdas** — Hasil discovery di-cache 3 jam (bisa diatur) untuk startup instan berikutnya
|
|
59
|
+
- **Stale fallback** — Jika backend tidak terjangkau, tetap pakai model dari cache
|
|
60
|
+
- **Timeout bisa diatur** — Timeout discovery default 30 detik, bisa disesuaikan untuk backend lambat
|
|
61
|
+
- **Daftar model dinamis** — Semua model dari 9Router tersedia, termasuk combo kustom
|
|
62
|
+
- **Default multimodal combo** — Model combo (`owned_by: "combo"`) yang tidak memberikan info kemampuan dipaksa menerima input teks/gambar/audio dengan tool calling, reasoning, konteks 256K, output 128K, dan varian `low`/`medium`/`high`/`xhigh`/`max`/`minimal`/`thinking`
|
|
63
|
+
- **Kompatibel dengan OpenAI** — Menggunakan `@ai-sdk/openai-compatible` (V1) / `@opencode/ai/providers/openai-compatible` (V2)
|
|
64
|
+
- **Type-safe** — Menggunakan hook `config` (V1) / provider transform (V2) untuk registrasi provider yang sesuai dengan skema konfigurasi OpenCode
|
|
65
|
+
|
|
66
|
+
## OpenCode V2
|
|
67
|
+
|
|
68
|
+
OpenCode V2 menggantikan key config `plugin` dengan `plugins` dan bentuk plugin satu-fungsi dengan `Plugin.define({ id, setup })`. Paket ini menangani keduanya — entrypoint yang sama dimuat oleh V1 dan V2.
|
|
69
|
+
|
|
70
|
+
### Konfigurasi (V2)
|
|
71
|
+
|
|
72
|
+
```jsonc
|
|
73
|
+
{
|
|
74
|
+
"$schema": "https://opencode.ai/config.json",
|
|
75
|
+
"plugins": ["@vheins/opencode-9router@latest"]
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Untuk checkout lokal, pertahankan path direktori pada list V2 `plugins`:
|
|
80
|
+
|
|
81
|
+
```jsonc
|
|
82
|
+
{
|
|
83
|
+
"plugins": ["/absolute/path/to/opencode-9router"]
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Direktori lokal harus memiliki entrypoint `server` di root; repository ini menyediakan `server.js` untuk keperluan tersebut. Key konfigurasi V1 tetap `plugin` dan tetap dapat memakai nama paket yang dipublikasikan seperti contoh di atas.
|
|
88
|
+
|
|
89
|
+
Opsi plugin memakai bentuk objek (`{ "package": ..., "options": { ... } }`) dan dibaca dari `ctx.options`:
|
|
90
|
+
|
|
91
|
+
```jsonc
|
|
92
|
+
{
|
|
93
|
+
"$schema": "https://opencode.ai/config.json",
|
|
94
|
+
"plugins": [
|
|
95
|
+
{
|
|
96
|
+
"package": "@vheins/opencode-9router@latest",
|
|
97
|
+
"options": {
|
|
98
|
+
"baseURL": "http://localhost:20128",
|
|
99
|
+
"apiKey": "{env:ROUTER_API_KEY}",
|
|
100
|
+
"cache": true,
|
|
101
|
+
"cacheTTL": 10800000,
|
|
102
|
+
"discoveryTimeout": 30000
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Provider (V2)
|
|
110
|
+
|
|
111
|
+
Di V2, provider dideklarasikan di bawah key `providers`. Setiap provider 9router memakai paket runtime OpenAI-compatible dan menyimpan endpoint di `settings.baseURL`. Plugin mendeteksi model untuk setiap provider yang ID-nya diawali `9router` lalu mengisi daftar model.
|
|
112
|
+
|
|
113
|
+
```jsonc
|
|
114
|
+
{
|
|
115
|
+
"$schema": "https://opencode.ai/config.json",
|
|
116
|
+
"plugins": ["@vheins/opencode-9router@latest"],
|
|
117
|
+
"providers": {
|
|
118
|
+
"9router": {
|
|
119
|
+
"name": "9Router",
|
|
120
|
+
"package": "@opencode/ai/providers/openai-compatible",
|
|
121
|
+
"settings": {
|
|
122
|
+
"baseURL": "http://localhost:20128/v1",
|
|
123
|
+
"apiKey": "{env:ROUTER_API_KEY}"
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"9router-remote": {
|
|
127
|
+
"name": "Remote 9Router",
|
|
128
|
+
"package": "@opencode/ai/providers/openai-compatible",
|
|
129
|
+
"settings": {
|
|
130
|
+
"baseURL": "https://your-9router-endpoint.example.com/v1"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Jika tidak ada provider 9router, plugin mendaftarkan provider default `9router` menuju `http://localhost:20128`. Refresh latar belakang mendeteksi ulang model dan memanggil `ctx.provider.reload()` setiap 5 menit; interval dibersihkan saat plugin di-unload.
|
|
138
|
+
|
|
139
|
+
### Entrypoint Ganda V1 + V2
|
|
140
|
+
|
|
141
|
+
Default export menyediakan kedua implementasi:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { Plugin } from "@opencode/plugin"
|
|
145
|
+
import { NineRouterPlugin } from "./plugin.js" // V1
|
|
146
|
+
import { nineRouterV2 } from "./v2.js" // V2
|
|
147
|
+
|
|
148
|
+
const v2 = Plugin.define(nineRouterV2)
|
|
149
|
+
export default { id: v2.id, setup: v2.setup, server: NineRouterPlugin }
|
|
150
|
+
export { NineRouterPlugin }
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
V2 membaca `id`/`setup`; V1 (1.18.29+) membaca `server`. Named export `NineRouterPlugin` dipertahankan untuk V1 lama. Untuk pengembangan lokal, repository juga menyediakan bridge `server.js` di root karena OpenCode me-resolve direktori plugin absolut melalui entrypoint `server`. Paket yang dipublikasikan mengekspos entrypoint yang sama melalui export `./server`.
|
|
154
|
+
|
|
155
|
+
## Instalasi
|
|
156
|
+
|
|
157
|
+
### Dari npm (disarankan)
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"$schema": "https://opencode.ai/config.json",
|
|
162
|
+
"plugin": ["@vheins/opencode-9router@latest"]
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Tidak perlu mendefinisikan provider secara manual — plugin mendaftarkannya secara otomatis.
|
|
167
|
+
|
|
168
|
+
### Instalasi otomatis (skrip)
|
|
169
|
+
|
|
170
|
+
Repositorio menyertakan installer interaktif untuk bash dan PowerShell. Skrip
|
|
171
|
+
melakukan clone + build plugin secara lokal, memverifikasi endpoint, dan menulis
|
|
172
|
+
entry `plugins` untuk Anda.
|
|
173
|
+
|
|
174
|
+
**One-liner** (berfungsi setelah skrip di-commit/push):
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
curl -fsSL https://raw.githubusercontent.com/joaogsbarbosa/opencode-9router/main/install.sh | bash
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
```powershell
|
|
181
|
+
irm https://raw.githubusercontent.com/joaogsbarbosa/opencode-9router/main/install.ps1 | iex
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Dari checkout lokal:**
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
bash ./install.sh
|
|
188
|
+
# atau perintah tertentu
|
|
189
|
+
bash ./install.sh install
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
```powershell
|
|
193
|
+
.\install.ps1
|
|
194
|
+
# atau perintah tertentu
|
|
195
|
+
.\install.ps1 install
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Perintah:** `install`, `update`, `configure`, `uninstall` (menu interaktif bila dijalankan tanpa argumen).
|
|
199
|
+
|
|
200
|
+
**Prompt:** URL base (default `http://localhost:20128`), API key (opsional), cache (default `Y`). Koneksi diverifikasi sebelum install atau configure.
|
|
201
|
+
|
|
202
|
+
**Apa yang dilakukan:**
|
|
203
|
+
|
|
204
|
+
- Clone (atau `git pull`) repo ke `~/.local/share/opencode-9router` (Linux/macOS) atau `%LOCALAPPDATA%\opencode-9router` (Windows), lalu `npm install` + `npm run build`.
|
|
205
|
+
- Menambahkan `{ "package": "file://...", "options": { ... } }` ke `opencode.jsonc` global.
|
|
206
|
+
- `uninstall` menghapus entry config, clone lokal, dan cache plugin.
|
|
207
|
+
|
|
208
|
+
Membutuhkan `git`, `node`, dan `npm`. Komentar JSONC tidak dipertahankan.
|
|
209
|
+
|
|
210
|
+
### Multi Provider
|
|
211
|
+
|
|
212
|
+
Tambahkan satu atau lebih provider 9Router dengan opsi kustom:
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"$schema": "https://opencode.ai/config.json",
|
|
217
|
+
"plugin": ["@vheins/opencode-9router@latest"],
|
|
218
|
+
"provider": {
|
|
219
|
+
"9router": {
|
|
220
|
+
"npm": "@ai-sdk/openai-compatible",
|
|
221
|
+
"name": "Provider Anda",
|
|
222
|
+
"options": {
|
|
223
|
+
"baseURL": "https://your-9router-endpoint.example.com/v1",
|
|
224
|
+
"apiKey": "{env:ROUTER_API_KEY}",
|
|
225
|
+
"cache": true,
|
|
226
|
+
"cacheTTL": 10800000,
|
|
227
|
+
"discoveryTimeout": 60000
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
"9router-local": {
|
|
231
|
+
"npm": "@ai-sdk/openai-compatible",
|
|
232
|
+
"name": "Local Router",
|
|
233
|
+
"options": {
|
|
234
|
+
"baseURL": "http://127.0.0.1:20128/v1",
|
|
235
|
+
"apiKey": "sk-...",
|
|
236
|
+
"cache": true,
|
|
237
|
+
"discoveryTimeout": 60000
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Setiap key provider harus diawali `9router`. `npm` harus `@ai-sdk/openai-compatible`. `name` adalah label yang tampil di OpenCode.
|
|
245
|
+
|
|
246
|
+
> **Jangan pernah commit API key asli.** Ganti `baseURL`/`apiKey` di atas dengan endpoint Anda sendiri dan placeholder seperti `{env:ROUTER_API_KEY}` (atau nilai dummy seperti `sk-...`). Key asli sebaiknya disimpan di environment variable, bukan di `opencode.json` atau README ini.
|
|
247
|
+
|
|
248
|
+
### Dengan Environment Variable
|
|
249
|
+
|
|
250
|
+
```json
|
|
251
|
+
{
|
|
252
|
+
"provider": {
|
|
253
|
+
"9router": {
|
|
254
|
+
"npm": "@ai-sdk/openai-compatible",
|
|
255
|
+
"name": "Remote 9Router",
|
|
256
|
+
"options": {
|
|
257
|
+
"baseURL": "https://example.com/v1",
|
|
258
|
+
"apiKey": "{env:ROUTER_API_KEY}",
|
|
259
|
+
"cache": true,
|
|
260
|
+
"discoveryTimeout": 30000
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
export ROUTER_API_KEY=your-api-key-here
|
|
269
|
+
opencode
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Opsi Provider
|
|
273
|
+
|
|
274
|
+
| Opsi | Tipe | Default | Deskripsi |
|
|
275
|
+
| -------------------- | -------- | ------------- | ---------------------------------------------------- |
|
|
276
|
+
| `baseURL` | `string` | `http://localhost:20128` | Endpoint API 9Router |
|
|
277
|
+
| `apiKey` | `string` | — | API key (jika backend membutuhkan) |
|
|
278
|
+
| `cache` | `boolean` | `true` | Cache hasil discovery ke `~/.cache/opencode-9router/` |
|
|
279
|
+
| `cacheTTL` | `number` | `10800000` (3j) | Masa berlaku cache dalam milidetik |
|
|
280
|
+
| `discoveryTimeout` | `number` | `30000` (30dtk) | Timeout request `/v1/models` dalam milidetik |
|
|
281
|
+
|
|
282
|
+
### Contoh dengan tuning cache dan timeout
|
|
283
|
+
|
|
284
|
+
```json
|
|
285
|
+
{
|
|
286
|
+
"provider": {
|
|
287
|
+
"9router": {
|
|
288
|
+
"npm": "@ai-sdk/openai-compatible",
|
|
289
|
+
"name": "Local Router",
|
|
290
|
+
"options": {
|
|
291
|
+
"baseURL": "http://localhost:20128",
|
|
292
|
+
"cache": true,
|
|
293
|
+
"discoveryTimeout": 60000
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
"9router-remote": {
|
|
297
|
+
"npm": "@ai-sdk/openai-compatible",
|
|
298
|
+
"name": "Remote API",
|
|
299
|
+
"options": {
|
|
300
|
+
"baseURL": "https://your-9router-endpoint.example.com/v1",
|
|
301
|
+
"apiKey": "{env:ROUTER_API_KEY}",
|
|
302
|
+
"cacheTTL": 3600000
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Nonaktifkan cache
|
|
310
|
+
|
|
311
|
+
```json
|
|
312
|
+
{
|
|
313
|
+
"provider": {
|
|
314
|
+
"9router": {
|
|
315
|
+
"npm": "@ai-sdk/openai-compatible",
|
|
316
|
+
"name": "Local Router",
|
|
317
|
+
"options": {
|
|
318
|
+
"baseURL": "http://localhost:20128",
|
|
319
|
+
"apiKey": "sk-...",
|
|
320
|
+
"cache": false,
|
|
321
|
+
"discoveryTimeout": 30000
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Penggunaan
|
|
329
|
+
|
|
330
|
+
### Pilih model
|
|
331
|
+
|
|
332
|
+
```
|
|
333
|
+
/models
|
|
334
|
+
→ Cari provider 9Router
|
|
335
|
+
→ Pilih model (contoh: kr/claude-sonnet-4.5, cc/claude-opus-4-7)
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Prefix Model
|
|
339
|
+
|
|
340
|
+
| Prefix | Provider | Tingkat |
|
|
341
|
+
|--------|----------|---------|
|
|
342
|
+
| `cc/` | Claude Code | Berlangganan |
|
|
343
|
+
| `cx/` | Codex | Berlangganan |
|
|
344
|
+
| `gh/` | GitHub Copilot | Berlangganan |
|
|
345
|
+
| `cu/` | Cursor IDE | Berlangganan |
|
|
346
|
+
| `kr/` | Kiro AI | **GRATIS** |
|
|
347
|
+
| `oc/` | OpenCode Free | **GRATIS** |
|
|
348
|
+
| `vertex/` | Vertex AI | Kredit $300 |
|
|
349
|
+
| `glm/` | GLM | $0.6/1M |
|
|
350
|
+
| `minimax/` | MiniMax | $0.2/1M |
|
|
351
|
+
| `kimi/` | Kimi | $9/bulan flat |
|
|
352
|
+
| `openrouter/` | OpenRouter | API key |
|
|
353
|
+
| `deepseek/` | DeepSeek | API key |
|
|
354
|
+
| `groq/` | Groq | API key |
|
|
355
|
+
|
|
356
|
+
## Cara Kerja
|
|
357
|
+
|
|
358
|
+
```
|
|
359
|
+
opencode.json "plugin": ["@vheins/opencode-9router@latest"]
|
|
360
|
+
↓
|
|
361
|
+
Plugin dimuat saat startup, deteksi provider 9Router-family di config
|
|
362
|
+
↓
|
|
363
|
+
Untuk setiap provider:
|
|
364
|
+
1. Cek cache lokal (~/.cache/opencode-9router/discovery-*.json)
|
|
365
|
+
└─ Cache masih fresh (≤3j) → langsung pakai model dari cache
|
|
366
|
+
2. Jika cache tidak ada atau kedaluwarsa:
|
|
367
|
+
└─ GET {baseURL}/v1/models dengan timeout 30 detik (bisa diatur)
|
|
368
|
+
└─ Jika sukses → daftarkan model + simpan ke cache
|
|
369
|
+
└─ Jika gagal → fallback ke cache lama (jika ada), atau skip
|
|
370
|
+
↓
|
|
371
|
+
Hook config membuat/memperbarui provider dengan model yang ditemukan
|
|
372
|
+
↓
|
|
373
|
+
Provider muncul di /models
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Penyimpanan cache
|
|
377
|
+
|
|
378
|
+
File cache disimpan di `~/.cache/opencode-9router/discovery-{base64url}.json`, satu file per `baseURL` unik. Direktori cache juga menyimpan katalog kemampuan models.dev (`models-dev.json`).
|
|
379
|
+
|
|
380
|
+
## Catatan Rilis
|
|
381
|
+
|
|
382
|
+
### v0.9.1 — Registrasi model V2 untuk provider terkonfigurasi
|
|
383
|
+
- Perbaiki urutan setup plugin V2: plugin eksternal berjalan sebelum plugin provider bawaan OpenCode, sehingga provider `9router*` dari config belum terlihat saat setup
|
|
384
|
+
- Daftarkan model transform (`ctx.model.transform`) yang menyuntikkan inventaris hasil discovery ke provider begitu provider tersedia
|
|
385
|
+
- Refresh target setelah setup dengan retry terbatas dan event `provider.updated`, lalu `ctx.model.reload()`
|
|
386
|
+
- Tambah entrypoint root `server.js` dan export paket `./server` agar path plugin lokal absolut bisa di-resolve
|
|
387
|
+
- Tambah `test-v2.mjs` untuk menguji entrypoint paket dan siklus provider-config yang datang belakangan
|
|
388
|
+
|
|
389
|
+
### v0.9.0 — Dukungan OpenCode V2 (ganda V1 + V2)
|
|
390
|
+
- Tambah plugin V2 (`src/v2.ts`) dengan `Plugin.define({ id: "9router", setup })`, mendaftarkan provider/model melalui `ctx.provider.transform(...)` dan refresh via `ctx.provider.reload()`
|
|
391
|
+
- Tambah `src/v2-map.ts` yang memetakan `ModelConfig` hasil discovery ke `Model.Info` V2 (capabilities, `limit.context`/`limit.output` wajib, variants)
|
|
392
|
+
- Tambah entrypoint ganda `src/index.ts`: default export menggabungkan definisi V2 dengan `server: NineRouterPlugin` (V1 1.18.29+); named export `NineRouterPlugin` dipertahankan untuk V1 lama
|
|
393
|
+
- Entry paket (`exports`, `main`, `types`) kini mengarah ke `dist/index.js` / `dist/index.d.ts`
|
|
394
|
+
- `@opencode/plugin@^2.0.12` ditambahkan sebagai dependency runtime; `@opencode-ai/plugin` / `@opencode-ai/sdk` dipertahankan untuk tipe V1
|
|
395
|
+
- Perilaku V1 tidak berubah; algoritma discovery/capability/cache tidak disentuh
|
|
396
|
+
|
|
397
|
+
### v0.8.1 — Enrichment combo ketat
|
|
398
|
+
- Combo dianggap ter-enrich hanya bila match segmen models.dev **persis** (tidak lagi cocok substring longgar seperti `vision` → `gpt-4-turbo-vision`)
|
|
399
|
+
- Abaikan stub kemampuan `/models/info` (`{tools: true}`) untuk combo, sehingga backend yang membalas stub tetap mendapat default multimodal
|
|
400
|
+
|
|
401
|
+
### v0.8.0 — Default multimodal combo
|
|
402
|
+
- Deteksi model combo via `owned_by: "combo"` (fallback: tanpa prefix provider)
|
|
403
|
+
- Paksa default multimodal pada combo tanpa info kemampuan: input teks/gambar/audio, tool calling, reasoning, konteks 256K, output 128K
|
|
404
|
+
- Tambah varian `low`/`medium`/`high`/`xhigh`/`max`/`minimal`/`thinking`, serta `search: false`, `context_length`, dan `max_completion_tokens`
|
|
405
|
+
- Versi cache discovery agar entri lama diambil ulang
|
|
406
|
+
|
|
407
|
+
### v0.7.1 — Logging discovery
|
|
408
|
+
- Log level INFO untuk cache hit/miss, status fetch, timeout, dan stale fallback
|
|
409
|
+
|
|
410
|
+
### v0.7.0 — Caching & timeout
|
|
411
|
+
- **Cache discovery model** — TTL 3 jam dengan stale fallback saat backend tidak terjangkau
|
|
412
|
+
- **Timeout dapat diatur** — Default 30 detik, bisa diubah via opsi `discoveryTimeout`
|
|
413
|
+
- **Opsi provider baru** — `cache`, `cacheTTL`, `discoveryTimeout`
|
|
414
|
+
- Konstanta baru: `DISCOVERY_CACHE_TTL`, `DISCOVERY_TIMEOUT`
|
|
415
|
+
|
|
416
|
+
### v0.6.0 — Multi-provider & fallback
|
|
417
|
+
- Dukungan multiple provider 9Router (`9router`, `9router-local`, dll.)
|
|
418
|
+
- Katalog model fallback via API `models.dev`
|
|
419
|
+
- Resolusi kemampuan per-model (vision, tools, reasoning)
|
|
420
|
+
|
|
421
|
+
### v0.5.x — Rilis awal
|
|
422
|
+
- Auto-discovery dasar dari `localhost:20128`
|
|
423
|
+
- Model cadangan saat API tidak terjangkau
|
|
424
|
+
- Dukungan single provider
|
|
425
|
+
|
|
426
|
+
## Pengembangan
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
git clone https://github.com/vheins/opencode-9router
|
|
430
|
+
cd opencode-9router
|
|
431
|
+
npm install
|
|
432
|
+
npm run build
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Tes
|
|
436
|
+
|
|
437
|
+
```bash
|
|
438
|
+
node test-minimal.mjs
|
|
439
|
+
opencode models 9router --print-logs
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### Validasi setelah publikasi
|
|
443
|
+
|
|
444
|
+
Setelah publikasi ke npm, verifikasi plugin bekerja end-to-end:
|
|
445
|
+
|
|
446
|
+
```bash
|
|
447
|
+
opencode models 9router-local --print-logs --log-level DEBUG
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
Perintah ini menjalankan discovery model terhadap paket yang sudah dipublikasikan dengan log level DEBUG penuh untuk memastikan caching, timeout, dan resolusi kemampuan berfungsi dengan benar.
|
|
451
|
+
|
|
452
|
+
### Publikasi
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
npm login
|
|
456
|
+
npm version patch # atau minor, major
|
|
457
|
+
npm publish --access public
|
|
458
|
+
git push --follow-tags
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
## Berkas
|
|
462
|
+
|
|
463
|
+
```
|
|
464
|
+
opencode-9router/
|
|
465
|
+
src/
|
|
466
|
+
index.ts # Entry paket ganda V1 + V2
|
|
467
|
+
plugin.ts # Entry plugin V1 (registrasi provider + config hook)
|
|
468
|
+
v2.ts # Entry plugin V2 (Plugin.define + provider transform)
|
|
469
|
+
v2-map.ts # Pemetaan ModelConfig V1 → Model.Info V2
|
|
470
|
+
discovery.ts # Pipeline discovery model
|
|
471
|
+
capabilities.ts # Resolusi kapabilitas (katalog + per-model API)
|
|
472
|
+
cache.ts # Cache discovery + models.dev
|
|
473
|
+
types.ts # Tipe bersama
|
|
474
|
+
utils.ts # Helper bersama
|
|
475
|
+
constants.ts # Model, default, prefix
|
|
476
|
+
dist/ # Hasil kompilasi (dihasilkan)
|
|
477
|
+
install.sh # Installer Linux/macOS (bash)
|
|
478
|
+
install.ps1 # Installer Windows (PowerShell)
|
|
479
|
+
package.json # Konfigurasi paket npm
|
|
480
|
+
tsconfig.json # Konfigurasi TypeScript
|
|
481
|
+
README.md # Versi Bahasa Inggris
|
|
482
|
+
README.id.md # Berkas ini (Bahasa Indonesia)
|
|
483
|
+
LICENSE # MIT
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
## Proyek Terkait
|
|
487
|
+
|
|
488
|
+
- [local-memory-mcp](https://github.com/vheins/local-memory-mcp) — Server MCP ringan yang memberi agen AI memori persisten dengan pencarian semantik, berbasis SQLite. Local-first, isolasi konteks per domain, tanpa database eksternal. Tersedia di [npm](https://www.npmjs.com/package/@vheins/local-memory-mcp).
|
|
489
|
+
|
|
490
|
+
- [RustaSea framework](https://github.com/rustasea/framework) — Framework web Rust yang ekspresif dan terinspirasi Laravel, dengan keamanan, performa, dan konkurensi khas Rust.
|
|
491
|
+
- [RustaSea skeleton](https://github.com/rustasea/rustasea) — Kerangka aplikasi RustaSea (varian Blade), dibuat dengan `cargo rustasea new`.
|
|
492
|
+
|
|
493
|
+
## Tautan
|
|
494
|
+
|
|
495
|
+
- [Dokumentasi Plugin OpenCode](https://opencode.ai/docs/plugins/)
|
|
496
|
+
- [Custom Provider OpenCode](https://opencode.ai/docs/providers/#custom-provider)
|
|
497
|
+
- [9Router GitHub](https://github.com/decolua/9router)
|
|
498
|
+
- [Situs Web 9Router](https://9router.com)
|