@joaogsbarbosa/opencode-9router 0.0.1 → 0.0.2

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 (3) hide show
  1. package/README.md +80 -96
  2. package/package.json +2 -3
  3. package/README.id.md +0 -498
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @vheins/opencode-9router
1
+ # @joaogsbarbosa/opencode-9router
2
2
 
3
3
  OpenCode plugin provider for [9Router](https://github.com/decolua/9router) — FREE AI Router & Token Saver. 40+ providers, 100+ models.
4
4
 
@@ -8,12 +8,15 @@ Registers 9Router as a custom provider in OpenCode with auto-discovery of models
8
8
 
9
9
  ## Quick Start
10
10
 
11
+ > **Automated:** run `npx @joaogsbarbosa/opencode-9router-installer` for the
12
+ > interactive installer, or add the plugin manually below.
13
+
11
14
  ### OpenCode V1
12
15
 
13
16
  ```json
14
17
  {
15
18
  "$schema": "https://opencode.ai/config.json",
16
- "plugin": ["@vheins/opencode-9router@latest"]
19
+ "plugin": ["@joaogsbarbosa/opencode-9router@latest"]
17
20
  }
18
21
  ```
19
22
 
@@ -26,7 +29,7 @@ Registers 9Router as a custom provider in OpenCode with auto-discovery of models
26
29
  ```json
27
30
  {
28
31
  "$schema": "https://opencode.ai/config.json",
29
- "plugins": ["@vheins/opencode-9router@latest"]
32
+ "plugins": ["@joaogsbarbosa/opencode-9router@latest"]
30
33
  }
31
34
  ```
32
35
 
@@ -37,7 +40,7 @@ Or with plugin options (object form):
37
40
  "$schema": "https://opencode.ai/config.json",
38
41
  "plugins": [
39
42
  {
40
- "package": "@vheins/opencode-9router@latest",
43
+ "package": "@joaogsbarbosa/opencode-9router@latest",
41
44
  "options": {
42
45
  "baseURL": "http://localhost:20128",
43
46
  "apiKey": "{env:ROUTER_API_KEY}",
@@ -79,7 +82,7 @@ OpenCode V2 replaces the V1 `plugin` config key with `plugins` and the single-fu
79
82
  ```jsonc
80
83
  {
81
84
  "$schema": "https://opencode.ai/config.json",
82
- "plugins": ["@vheins/opencode-9router@latest"]
85
+ "plugins": ["@joaogsbarbosa/opencode-9router@latest"]
83
86
  }
84
87
  ```
85
88
 
@@ -100,7 +103,7 @@ Plugin options use the object form (`{ "package": ..., "options": { ... } }`) an
100
103
  "$schema": "https://opencode.ai/config.json",
101
104
  "plugins": [
102
105
  {
103
- "package": "@vheins/opencode-9router@latest",
106
+ "package": "@joaogsbarbosa/opencode-9router@latest",
104
107
  "options": {
105
108
  "baseURL": "http://localhost:20128",
106
109
  "apiKey": "{env:ROUTER_API_KEY}",
@@ -120,7 +123,7 @@ In V2, providers are declared under the `providers` key. Each 9router-family pro
120
123
  ```jsonc
121
124
  {
122
125
  "$schema": "https://opencode.ai/config.json",
123
- "plugins": ["@vheins/opencode-9router@latest"],
126
+ "plugins": ["@joaogsbarbosa/opencode-9router@latest"],
124
127
  "providers": {
125
128
  "9router": {
126
129
  "name": "9Router",
@@ -166,53 +169,73 @@ V2 reads `id`/`setup`; V1 (1.18.29+) reads `server`. The named `NineRouterPlugin
166
169
  ```json
167
170
  {
168
171
  "$schema": "https://opencode.ai/config.json",
169
- "plugin": ["@vheins/opencode-9router@latest"]
172
+ "plugins": ["@joaogsbarbosa/opencode-9router@latest"]
170
173
  }
171
174
  ```
172
175
 
173
- No need to define a provider manually — the plugin registers it automatically.
176
+ No need to define a provider manually — the plugin registers it automatically. On
177
+ OpenCode V1, use the legacy `plugin` key as shown in the Quick Start above.
174
178
 
175
- ### Automated install (script)
179
+ ### Automated install (npx)
176
180
 
177
- The repository ships an interactive installer for bash and PowerShell. It clones
178
- and builds the plugin locally, verifies the endpoint, and writes the `plugins`
179
- entry for you.
181
+ A separate installer package ships the interactive setup. It uses
182
+ `jsonc-parser` to edit the `plugins` array and the matching `providers` entry,
183
+ preserving comments and formatting elsewhere in the file. It targets the V2
184
+ `plugins` key; on OpenCode V1, add the package to the legacy `plugin` key
185
+ manually (see Quick Start).
180
186
 
181
- **One-liner** (works once the scripts are committed/pushed):
187
+ **Run with npx:**
182
188
 
183
189
  ```bash
184
- curl -fsSL https://raw.githubusercontent.com/joaogsbarbosa/opencode-9router/main/install.sh | bash
185
- ```
186
-
187
- ```powershell
188
- irm https://raw.githubusercontent.com/joaogsbarbosa/opencode-9router/main/install.ps1 | iex
190
+ npx @joaogsbarbosa/opencode-9router-installer
189
191
  ```
190
192
 
191
- **From a local checkout:**
193
+ The interactive menu shows the current installation status (including the
194
+ effective base URL, API key, cache and timeouts) before asking what to do.
192
195
 
193
- ```bash
194
- bash ./install.sh
195
- # or a specific command
196
- bash ./install.sh install
197
- ```
196
+ **Flags:** `--project` edits the project config instead of the global config. It
197
+ uses `./opencode.jsonc` by default, or an existing `./opencode.json` or
198
+ `.opencode/opencode.json(c)`.
198
199
 
199
- ```powershell
200
- .\install.ps1
201
- # or a specific command
202
- .\install.ps1 install
203
- ```
200
+ **Prompts:** base URL (default `http://localhost:20128`), API key (optional),
201
+ cache (default `Y`), cache TTL in ms (default `10800000`, 3 h), discovery
202
+ timeout in ms (default `30000`). The install/configure option reads the current
203
+ values from the plugin options, or from a `providers` entry whose ID starts with
204
+ `9router` (its `settings.baseURL`/`settings.apiKey`) when one exists. The values
205
+ are pre-filled at the cursor, so pressing Enter keeps them. The connection
206
+ (`{baseURL}/v1/models`) is verified before saving.
204
207
 
205
- **Commands:** `install`, `update`, `configure`, `uninstall` (interactive menu when run with no argument).
208
+ **Menu:**
206
209
 
207
- **Prompts:** base URL (default `http://localhost:20128`), API key (optional), cache (default `Y`). The connection is verified before installing or configuring.
210
+ - Option 1 — `install` when not installed, `configure` when already installed.
211
+ Installs the plugin or changes the current configuration.
212
+ - Option 2 — `uninstall` removes the plugin entry and cache.
213
+ - Option 0 — `quit` exits.
208
214
 
209
- **What it does:**
215
+ **What it writes:**
210
216
 
211
- - Clones (or `git pull`) the repo into `~/.local/share/opencode-9router` (Linux/macOS) or `%LOCALAPPDATA%\opencode-9router` (Windows), then runs `npm install` + `npm run build`.
212
- - Adds `{ "package": "file://...", "options": { ... } }` to the global `opencode.jsonc`.
213
- - `uninstall` removes the config entry, the local clone, and the plugin cache.
217
+ ```json
218
+ {
219
+ "package": "@joaogsbarbosa/opencode-9router@latest",
220
+ "options": {
221
+ "baseURL": "...",
222
+ "apiKey": "...",
223
+ "cache": true,
224
+ "cacheTTL": 10800000,
225
+ "discoveryTimeout": 30000
226
+ }
227
+ }
228
+ ```
214
229
 
215
- Requires `git`, `node`, and `npm`. JSONC comments are not preserved.
230
+ `apiKey` is omitted when left empty. If the plugin options contain a
231
+ `providers` array, the matching entry is updated in place. If the config already
232
+ has a `providers` entry for `9router` (or another ID starting with `9router`), the
233
+ installer also updates that entry's `settings.baseURL` and `settings.apiKey`,
234
+ since V2 prefers the provider settings over the plugin options. OpenCode installs
235
+ the package and its dependencies automatically. The uninstall option removes the
236
+ config entry and the plugin cache (`~/.cache/opencode-9router`, or
237
+ `$XDG_CACHE_HOME/opencode-9router`); a `providers` entry for `9router` is left
238
+ untouched. Requires Node 18+.
216
239
 
217
240
  ### Multiple Providers
218
241
 
@@ -221,7 +244,7 @@ Add one or more 9Router-family providers with custom options:
221
244
  ```json
222
245
  {
223
246
  "$schema": "https://opencode.ai/config.json",
224
- "plugin": ["@vheins/opencode-9router@latest"],
247
+ "plugin": ["@joaogsbarbosa/opencode-9router@latest"],
225
248
  "provider": {
226
249
  "9router": {
227
250
  "npm": "@ai-sdk/openai-compatible",
@@ -363,7 +386,7 @@ opencode
363
386
  ## How It Works
364
387
 
365
388
  ```
366
- opencode.json "plugin": ["@vheins/opencode-9router@latest"]
389
+ opencode.json "plugin": ["@joaogsbarbosa/opencode-9router@latest"]
367
390
  ↓
368
391
  Plugin loads at startup detects 9Router-family providers in config
369
392
  ↓
@@ -384,59 +407,15 @@ Provider appears in /models
384
407
 
385
408
  Cache files are stored at `~/.cache/opencode-9router/discovery-{base64url}.json`, one per unique `baseURL`. The cache directory also stores the models.dev capability catalog (`models-dev.json`).
386
409
 
387
- ## Changelog
388
-
389
- ### v0.9.1 — V2 model registration for configured providers
390
- - Fix V2 plugin setup ordering: external plugins run before OpenCode's internal config-provider plugin, so config-defined `9router*` providers are not visible during setup
391
- - Register a model transform (`ctx.model.transform`) that injects the discovered inventory into providers once they become available
392
- - Refresh targets after setup with bounded retries and `provider.updated` events, then `ctx.model.reload()`
393
- - Add a root `server.js` entrypoint and `./server` package export so an absolute local plugin path resolves
394
- - Add `test-v2.mjs` covering the package entrypoint and the late config-provider lifecycle
395
-
396
- ### v0.9.0 — OpenCode V2 support (dual V1 + V2)
397
- - Add a V2 plugin (`src/v2.ts`) built with `Plugin.define({ id: "9router", setup })`, registering providers/models through `ctx.provider.transform(...)` and refreshing via `ctx.provider.reload()`
398
- - Add `src/v2-map.ts` mapping the discovered `ModelConfig` onto V2 `Model.Info` (capabilities, required `limit.context`/`limit.output`, variants)
399
- - Add `src/index.ts` dual entrypoint: default export merges the V2 definition with `server: NineRouterPlugin` (V1 1.18.29+); named `NineRouterPlugin` export retained for older V1
400
- - Package entry (`exports`, `main`, `types`) now points at `dist/index.js` / `dist/index.d.ts`
401
- - `@opencode/plugin@^2.0.12` added as a runtime dependency; `@opencode-ai/plugin` / `@opencode-ai/sdk` kept for V1 types
402
- - V1 behavior unchanged; discovery/capability/cache algorithms untouched
403
-
404
- ### v0.8.1 — Strict combo enrichment
405
- - Combos count as enriched only on an **exact** models.dev segment match (no more loose substring hits like `vision` → `gpt-4-turbo-vision`)
406
- - Ignore bare `/models/info` capability stubs (`{tools: true}`) for combos, so backends that return stubs still get forced multimodal defaults
407
-
408
- ### v0.8.0 — Combo multimodal defaults
409
- - Detect combo models via `owned_by: "combo"` (fallback: no provider prefix)
410
- - Force multimodal defaults on combos with no resolved capability info: text/image/audio input, tool calling, reasoning, 256K context, 128K output
411
- - Add `low`/`medium`/`high`/`xhigh`/`max`/`minimal`/`thinking` variants, plus `search: false`, `context_length`, and `max_completion_tokens`
412
- - Version discovery cache so older entries are refetched
413
-
414
- ### v0.7.1 — Discovery logging
415
- - Add INFO-level logging for cache hit/miss, fetch status, timeout, and stale fallback
416
-
417
- ### v0.7.0 — Caching & timeout
418
- - **Model discovery cache** — 3-hour TTL with stale fallback when backend is unreachable
419
- - **Configurable timeout** — 30s default, adjustable via `discoveryTimeout` option
420
- - **Provider options** — `cache`, `cacheTTL`, `discoveryTimeout`
421
- - New constant: `DISCOVERY_CACHE_TTL`, `DISCOVERY_TIMEOUT`
422
-
423
- ### v0.6.0 — Multi-provider & fallback
424
- - Support multiple 9Router-family providers (`9router`, `9router-local`, etc.)
425
- - Fallback models catalog via `models.dev` API
426
- - Per-model capability resolution (vision, tools, reasoning)
427
-
428
- ### v0.5.x — Initial releases
429
- - Basic auto-discovery from `localhost:20128`
430
- - Fallback models when API unreachable
431
- - Single provider support
432
-
433
410
  ## Development
434
411
 
435
412
  ```bash
436
- git clone https://github.com/vheins/opencode-9router
413
+ git clone https://github.com/joaogsbarbosa/opencode-9router
437
414
  cd opencode-9router
438
415
  npm install
416
+ npm install --prefix installer
439
417
  npm run build
418
+ node installer/install.mjs # run the installer locally
440
419
  ```
441
420
 
442
421
  ### Test
@@ -458,6 +437,8 @@ This runs model discovery against the published package with full debug logging
458
437
 
459
438
  ### Publish
460
439
 
440
+ Plugin:
441
+
461
442
  ```bash
462
443
  npm login
463
444
  npm version patch # or minor, major
@@ -465,6 +446,14 @@ npm publish --access public
465
446
  git push --follow-tags
466
447
  ```
467
448
 
449
+ Installer (separate package):
450
+
451
+ ```bash
452
+ cd installer
453
+ npm version patch # or minor, major
454
+ npm publish --access public
455
+ ```
456
+
468
457
  ## Files
469
458
 
470
459
  ```
@@ -482,24 +471,19 @@ opencode-9router/
482
471
  utils.ts # Shared helpers
483
472
  constants.ts # Models, defaults, prefixes
484
473
  dist/ # Compiled output (generated)
485
- install.sh # Linux/macOS installer (bash)
486
- install.ps1 # Windows installer (PowerShell)
474
+ installer/
475
+ install.mjs # Interactive installer (separate npx package)
476
+ package.json # Installer package config
477
+ README.md # Installer usage
487
478
  package.json # npm package config
488
479
  tsconfig.json # TypeScript config
489
480
  README.md # This file
490
- README.id.md # Bahasa Indonesia version
491
481
  LICENSE # MIT
492
482
  ```
493
483
 
494
- ## Related Projects
495
-
496
- - [local-memory-mcp](https://github.com/vheins/local-memory-mcp) — A lightweight MCP server that gives AI agents persistent memory with semantic search, backed by SQLite. Local-first, with domain-based context isolation and no external database. Available on [npm](https://www.npmjs.com/package/@vheins/local-memory-mcp).
497
-
498
- - [RustaSea framework](https://github.com/rustasea/framework) — An expressive, Laravel-inspired web framework for Rust, with Rust-native safety, performance, and concurrency.
499
- - [RustaSea skeleton](https://github.com/rustasea/rustasea) — The RustaSea application skeleton (Blade variant), scaffolded with `cargo rustasea new`.
500
-
501
484
  ## Links
502
485
 
486
+ - [npm package](https://www.npmjs.com/package/@joaogsbarbosa/opencode-9router)
503
487
  - [OpenCode Plugin Docs](https://opencode.ai/docs/plugins/)
504
488
  - [OpenCode Custom Provider](https://opencode.ai/docs/providers/#custom-provider)
505
489
  - [9Router GitHub](https://github.com/decolua/9router)
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@joaogsbarbosa/opencode-9router",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "OpenCode plugin provider for 9Router — FREE AI Router & Token Saver. 40+ providers, 100+ models.",
5
- "author": "vheins",
5
+ "author": "joaogsbarbosa",
6
6
  "keywords": [
7
7
  "opencode",
8
8
  "9router",
@@ -35,7 +35,6 @@
35
35
  "dist",
36
36
  "server.js",
37
37
  "README.md",
38
- "README.id.md",
39
38
  "LICENSE"
40
39
  ],
41
40
  "scripts": {
package/README.id.md DELETED
@@ -1,498 +0,0 @@
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)