@vheins/opencode-9router 0.5.0 → 0.5.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.md +54 -44
- package/dist/plugin.js +14 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,23 +9,16 @@ Mendaftarkan 9Router sebagai custom provider di OpenCode dengan auto-discovery m
|
|
|
9
9
|
```json
|
|
10
10
|
{
|
|
11
11
|
"$schema": "https://opencode.ai/config.json",
|
|
12
|
-
"plugin": ["@vheins/opencode-9router@
|
|
13
|
-
"provider": {
|
|
14
|
-
"9router": {
|
|
15
|
-
"npm": "@ai-sdk/openai-compatible",
|
|
16
|
-
"name": "9Router",
|
|
17
|
-
"options": {
|
|
18
|
-
"baseURL": "https://model.idsolutions.id/v1"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
12
|
+
"plugin": ["@vheins/opencode-9router@0.5.0"]
|
|
22
13
|
}
|
|
23
14
|
```
|
|
24
15
|
|
|
25
|
-
1. Tambahkan plugin
|
|
16
|
+
1. Tambahkan plugin ke `opencode.json`
|
|
26
17
|
2. Restart OpenCode
|
|
27
18
|
3. `/models` → pilih model 9Router
|
|
28
19
|
|
|
20
|
+
Plugin akan auto-discover models dari `http://localhost:20128` (default).
|
|
21
|
+
|
|
29
22
|
## Features
|
|
30
23
|
|
|
31
24
|
- **Auto-discover models** — Models dari 9Router otomatis terdeteksi saat startup
|
|
@@ -40,11 +33,22 @@ Mendaftarkan 9Router sebagai custom provider di OpenCode dengan auto-discovery m
|
|
|
40
33
|
```json
|
|
41
34
|
{
|
|
42
35
|
"$schema": "https://opencode.ai/config.json",
|
|
43
|
-
"plugin": ["@vheins/opencode-9router@
|
|
36
|
+
"plugin": ["@vheins/opencode-9router@0.5.0"]
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Tidak perlu mendefinisikan provider secara manual — plugin mendaftarkannya otomatis.
|
|
41
|
+
|
|
42
|
+
### Custom Base URL
|
|
43
|
+
|
|
44
|
+
Jika 9Router berjalan di host/port berbeda, tambahkan provider config:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"$schema": "https://opencode.ai/config.json",
|
|
49
|
+
"plugin": ["@vheins/opencode-9router@0.5.0"],
|
|
44
50
|
"provider": {
|
|
45
51
|
"9router": {
|
|
46
|
-
"npm": "@ai-sdk/openai-compatible",
|
|
47
|
-
"name": "9Router",
|
|
48
52
|
"options": {
|
|
49
53
|
"baseURL": "https://model.idsolutions.id/v1"
|
|
50
54
|
}
|
|
@@ -53,47 +57,53 @@ Mendaftarkan 9Router sebagai custom provider di OpenCode dengan auto-discovery m
|
|
|
53
57
|
}
|
|
54
58
|
```
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### Local file
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
cp src/plugin.ts .opencode/plugins/9router-provider.ts
|
|
62
|
-
cp src/constants.ts .opencode/plugins/constants.ts
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Usage
|
|
66
|
-
|
|
67
|
-
### 1. Configure provider
|
|
60
|
+
### With API Key
|
|
68
61
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"$schema": "https://opencode.ai/config.json",
|
|
65
|
+
"plugin": ["@vheins/opencode-9router@0.5.0"],
|
|
66
|
+
"provider": {
|
|
67
|
+
"9router": {
|
|
68
|
+
"options": {
|
|
69
|
+
"baseURL": "https://model.idsolutions.id/v1",
|
|
70
|
+
"apiKey": "your-api-key-here"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
77
75
|
```
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
Ubah `baseURL` di provider config sesuai kebutuhan:
|
|
77
|
+
Atau pakai environment variable:
|
|
82
78
|
|
|
83
79
|
```json
|
|
84
80
|
{
|
|
85
81
|
"provider": {
|
|
86
82
|
"9router": {
|
|
87
|
-
"npm": "@ai-sdk/openai-compatible",
|
|
88
|
-
"name": "9Router",
|
|
89
83
|
"options": {
|
|
90
|
-
"baseURL": "
|
|
84
|
+
"baseURL": "https://model.idsolutions.id/v1",
|
|
85
|
+
"apiKey": "{env:ROUTER_API_KEY}"
|
|
91
86
|
}
|
|
92
87
|
}
|
|
93
88
|
}
|
|
94
89
|
}
|
|
95
90
|
```
|
|
96
91
|
|
|
92
|
+
```bash
|
|
93
|
+
export ROUTER_API_KEY=your-api-key-here
|
|
94
|
+
opencode
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Usage
|
|
98
|
+
|
|
99
|
+
### Select model
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
/models
|
|
103
|
+
→ Find 9Router provider
|
|
104
|
+
→ Pick any model (e.g., kr/claude-sonnet-4.5, cc/claude-opus-4-7)
|
|
105
|
+
```
|
|
106
|
+
|
|
97
107
|
## Model Prefixes
|
|
98
108
|
|
|
99
109
|
| Prefix | Provider | Tier |
|
|
@@ -115,17 +125,17 @@ Ubah `baseURL` di provider config sesuai kebutuhan:
|
|
|
115
125
|
## How It Works
|
|
116
126
|
|
|
117
127
|
```
|
|
118
|
-
opencode.json "plugin": ["@vheins/opencode-9router@
|
|
128
|
+
opencode.json "plugin": ["@vheins/opencode-9router@0.5.0"]
|
|
119
129
|
↓
|
|
120
130
|
Bun installs package from npm
|
|
121
131
|
↓
|
|
122
132
|
Plugin loads at startup:
|
|
123
|
-
1. Read provider config
|
|
133
|
+
1. Read baseURL from provider config (or use default http://localhost:20128)
|
|
124
134
|
2. Try GET /v1/models from baseURL (3s timeout)
|
|
125
135
|
3. If OK → register live models
|
|
126
|
-
4. If fail → log
|
|
136
|
+
4. If fail → log warning, no models registered
|
|
127
137
|
↓
|
|
128
|
-
config hook updates provider with discovered models
|
|
138
|
+
config hook creates/updates provider "9router" with discovered models
|
|
129
139
|
↓
|
|
130
140
|
Provider "9router" appears in /models
|
|
131
141
|
```
|
package/dist/plugin.js
CHANGED
|
@@ -52,34 +52,27 @@ export const NineRouterPlugin = async ({ client }) => {
|
|
|
52
52
|
};
|
|
53
53
|
return {
|
|
54
54
|
config: async (config) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
const existingProvider = config.provider[PLUGIN_NAME];
|
|
60
|
-
if (!existingProvider) {
|
|
61
|
-
await log("info", "9Router provider not configured. Add it to opencode.json provider section.");
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const options = existingProvider.options;
|
|
65
|
-
const baseURL = options?.baseURL;
|
|
66
|
-
if (!baseURL) {
|
|
67
|
-
await log("warn", "9Router provider missing baseURL option.");
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
55
|
+
const existingProvider = config.provider?.[PLUGIN_NAME];
|
|
56
|
+
const options = existingProvider?.options;
|
|
57
|
+
const baseURL = options?.baseURL ?? DEFAULT_BASE_URL;
|
|
70
58
|
const normalizedURL = normalizeBaseURL(baseURL);
|
|
71
59
|
const apiURL = ensureAPIPath(normalizedURL);
|
|
72
60
|
const discovered = await discoverModels(normalizedURL);
|
|
61
|
+
config.provider ??= {};
|
|
62
|
+
config.provider[PLUGIN_NAME] = {
|
|
63
|
+
npm: "@ai-sdk/openai-compatible",
|
|
64
|
+
name: PROVIDER_DISPLAY_NAME,
|
|
65
|
+
options: {
|
|
66
|
+
...options,
|
|
67
|
+
baseURL: apiURL,
|
|
68
|
+
},
|
|
69
|
+
models: discovered ?? {},
|
|
70
|
+
};
|
|
73
71
|
if (discovered) {
|
|
74
|
-
config.provider[PLUGIN_NAME] = {
|
|
75
|
-
...existingProvider,
|
|
76
|
-
options: { ...options, baseURL: apiURL },
|
|
77
|
-
models: discovered,
|
|
78
|
-
};
|
|
79
72
|
await log("info", `Discovered ${Object.keys(discovered).length} models from ${apiURL}`);
|
|
80
73
|
}
|
|
81
74
|
else {
|
|
82
|
-
await log("
|
|
75
|
+
await log("warn", `Failed to discover models from ${apiURL}. Check if 9Router is running and accessible.`);
|
|
83
76
|
}
|
|
84
77
|
},
|
|
85
78
|
};
|