跳到主要内容
    ↑↓ 选择↵ 打开esc 关闭
    中文English
    MSR806

    Key Model Router

    v0.1.2模型接入
    @msr0806/opencode-key-model-router

    OpenCode plugin: prefix a message with @key to pick a model, strip the tag, and persist the choice for the session

    GitHub 星标

    0

    月装机量

    8

    近 7 天 1

    综合评分SCORE

    19.8

    生态多维模型

    最近提交

    3 个月前

    2026-04-26

    快速安装与配置

    opencode.json

    写入当前项目的 opencode.json,只对这个仓库生效。

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["@msr0806/opencode-key-model-router@0.1.2"]
    }

    opencode 启动时会通过内嵌运行时自动加载 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 the fast model, 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 @fast every time).
    • @deep refactor this module — switch to the deep model for the session.
    • @reset — clear the sticky choice for this session; the next turn follows OpenCode’s default model again. The word @reset is 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 to keys). Clears in-memory session routing and restores the default model for that message.
    • All model-switching names come only from your keys object.

    Develop

    bun install
    bun run build   # emits dist/
    bun test
    

    License

    MIT