0
10
近 7 天 2
20.3
生态多维模型
3 个月前
2026-04-26
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-key-model-router@0.1.3"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-key-model-router@0.1.3"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-key-model-routeropencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
OpenCode plugin: include a short sigil + key anywhere in a user message to pick which provider/model OpenCode should use for that turn. The tag is removed before the text is sent to the model. The chosen model is remembered for the rest of the session until you use @reset or change the key again.
This plugin does not ship model defaults. Configure every model key explicitly for the providers and models available in your OpenCode setup.
Install
From the published package (after you publish to npm, or with bun add to a monorepo):
Add to opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": [
[
"opencode-key-model-router",
{
"sigil": "@",
"debug": false,
"keys": {
"fast": "cerebral/glm-4.5",
"deep": "anthropic/claude-opus-4-5-20250929",
"gpt": "openai/gpt-4o"
}
}
]
]
}
plugin accepts either a string package name, or a tuple ["name", { options }] (see the OpenCode v2 Config type: plugin is an array of string | [string, object]). Options are passed as the second argument to the plugin.
From a local build while developing this repo:
{
"plugin": [
[
"file:///absolute/path/to/opencode-key-model-router/dist/index.js",
{ "debug": true }
]
]
}
Use an absolute file:// URL. Restart OpenCode after changing the config.
Usage
@fast explain what a PRNG is— use thefastmodel, strip the tag, keep using it on later turns.Explain what a PRNG is @fast— same behavior; keys can appear at the start, middle, or end of a text message.Just the question, no prefix— if you already chose a key earlier in the session, the same model is applied again (no need to repeat@fastevery time).@deep refactor this module— switch to thedeepmodel for the session.@reset— clear the sticky choice for this session; the next turn follows OpenCode’s default model again. The word@resetis stripped from the message.
Keys must be at least 2 characters, [a-zA-Z0-9_]{2,32} immediately after the sigil. The plugin scans text parts in order and uses the first configured key it finds.
Built-in keys
reset: always recognized (no need to add it tokeys). Clears in-memory session routing and restores the default model for that message.- All model-switching names come only from your
keysobject.
Develop
bun install
bun run build # emits dist/
bun test
License
MIT