opencode-models-manager 0.1.1 → 0.2.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 +20 -20
- package/README.md +16 -3
- package/package.json +6 -4
- package/src/models.ts +32 -21
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Felipe Gutiérrez
|
|
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
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Felipe Gutiérrez
|
|
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
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -19,13 +19,13 @@ This repo was created to provide a simple solution for managing AI models for ev
|
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
The `main` branch is the OpenCode v1 line and requires OpenCode 1.18.0 or later. It is not compatible with OpenCode v2.
|
|
23
23
|
|
|
24
24
|
```
|
|
25
25
|
opencode plugin opencode-models-manager@0.1.1
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
For OpenCode v2, use the `v2` branch until the 2.x package release is published.
|
|
29
29
|
|
|
30
30
|
Restart OpenCode after installation.
|
|
31
31
|
|
|
@@ -70,4 +70,17 @@ The `agent` section targets agents in `.opencode/agent` and the `commands` secti
|
|
|
70
70
|
|
|
71
71
|
Invalid entries are logged and skipped. Restart OpenCode after changing `models.json` so the config hook runs again.
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
## OpenCode v2
|
|
74
|
+
|
|
75
|
+
OpenCode v2 requires a default plugin definition object. The v2 implementation lives on the [`v2`](https://github.com/RainingDaemons/opencode-models-manager/tree/v2) branch and is versioned as `0.2.0`.
|
|
76
|
+
|
|
77
|
+
Use the v2 configuration key (`plugins`, plural):
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"$schema": "https://opencode.ai/config.json",
|
|
82
|
+
"plugins": ["opencode-models-manager@0.2.0"]
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Agent models in `.opencode/models.json` are supported. OpenCode v2 currently exposes an add-only command transform API, so it cannot update models on commands that were loaded from `.opencode/commands`; command entries are logged and skipped.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-models-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "OpenCode plugin — manage agent models from a single JSON file",
|
|
6
6
|
"author": "RainingDaemons",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"model-manager"
|
|
23
23
|
],
|
|
24
24
|
"engines": {
|
|
25
|
-
"opencode": ">=
|
|
25
|
+
"opencode": ">=2.0.0"
|
|
26
26
|
},
|
|
27
27
|
"main": "./src/models.ts",
|
|
28
28
|
"exports": {
|
|
@@ -34,11 +34,13 @@
|
|
|
34
34
|
"!test",
|
|
35
35
|
"!test/**"
|
|
36
36
|
],
|
|
37
|
-
"
|
|
38
|
-
"@
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^24.0.0",
|
|
39
|
+
"typescript": "^6.0.0"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
42
|
"test": "node --test test/models.test.ts",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
42
44
|
"logo": "node script/logo.mjs"
|
|
43
45
|
}
|
|
44
46
|
}
|
package/src/models.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs"
|
|
2
2
|
import path from "node:path"
|
|
3
|
-
import type { Plugin } from "@opencode-ai/plugin"
|
|
4
3
|
|
|
5
4
|
const CONFIG_FILE = path.join(".opencode", "models.json")
|
|
6
5
|
|
|
@@ -27,6 +26,14 @@ function isEntryName(name: string): boolean {
|
|
|
27
26
|
return name.trim() !== ""
|
|
28
27
|
}
|
|
29
28
|
|
|
29
|
+
function parseModelRef(value: string): { providerID: string; id: string } {
|
|
30
|
+
const separator = value.indexOf("/")
|
|
31
|
+
return {
|
|
32
|
+
providerID: value.slice(0, separator),
|
|
33
|
+
id: value.slice(separator + 1),
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
30
37
|
function loadSection(
|
|
31
38
|
file: string,
|
|
32
39
|
section: Section,
|
|
@@ -49,7 +56,7 @@ function loadSection(
|
|
|
49
56
|
return models
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
function loadModels(file: string): Models | null {
|
|
59
|
+
export function loadModels(file: string): Models | null {
|
|
53
60
|
let raw: string
|
|
54
61
|
try {
|
|
55
62
|
raw = readFileSync(file, "utf8")
|
|
@@ -102,30 +109,34 @@ function loadModels(file: string): Models | null {
|
|
|
102
109
|
return models
|
|
103
110
|
}
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
/**
|
|
113
|
+
* OpenCode v2 setup plugin.
|
|
114
|
+
*
|
|
115
|
+
* This intentionally has no package imports beyond Node built-ins: OpenCode
|
|
116
|
+
* 2.0 resolves local and package plugins independently of its own SDK modules.
|
|
117
|
+
*/
|
|
118
|
+
export default {
|
|
119
|
+
id: "opencode-models-manager",
|
|
120
|
+
async setup(ctx: any) {
|
|
121
|
+
const file = path.join(process.cwd(), CONFIG_FILE)
|
|
122
|
+
const models = loadModels(file)
|
|
110
123
|
if (!models) return
|
|
111
124
|
|
|
112
125
|
if (Object.keys(models.agent).length > 0) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
await ctx.agent.transform((editor: any) => {
|
|
127
|
+
for (const [name, model] of Object.entries(models.agent)) {
|
|
128
|
+
editor.update(name, (agent: any) => {
|
|
129
|
+
agent.model = parseModelRef(model)
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
await ctx.agent.reload()
|
|
117
134
|
}
|
|
118
135
|
|
|
119
136
|
if (Object.keys(models.command).length > 0) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (!command) {
|
|
124
|
-
console.error(`[model-manager] command "${name}" was not found`)
|
|
125
|
-
continue
|
|
126
|
-
}
|
|
127
|
-
cfg.command[name] = { ...command, model }
|
|
128
|
-
}
|
|
137
|
+
console.error(
|
|
138
|
+
`[model-manager] ${file} contains command models, but OpenCode v2 does not support updating existing command definitions; those entries were skipped`
|
|
139
|
+
)
|
|
129
140
|
}
|
|
130
141
|
},
|
|
131
|
-
}
|
|
142
|
+
}
|