npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jaquesyang/opencode-model-proxy-router

v0.0.2

Published

Opencode plugin that routes model API requests to different HTTP proxies by wrapping fetch, with hot-reload.

Readme

opencode-model-proxy-router

English | 简体中文

一个 Opencode 插件,通过包装 fetch 将模型 API 请求路由到不同的代理,支持热重载。

功能特性

  • 按精确模型 ID、前缀通配符或兜底默认规则路由请求
  • 按路由选择代理,自动回退到直连
  • 运行时学习 provider 基础 URL(chat.params),支持按 URL 路由
  • 热重载:无需重启即可生效的配置更新
  • 零运行时依赖

安装

通过 npm 安装(推荐)

npm install @jaquesyang/opencode-model-proxy-router
# 或
bun add @jaquesyang/opencode-model-proxy-router
pnpm add @jaquesyang/opencode-model-proxy-router
yarn add @jaquesyang/opencode-model-proxy-router

然后在 opencode.json(项目根目录或 ~/.config/opencode/opencode.json)中添加插件:

{
  "plugin": ["@jaquesyang/opencode-model-proxy-router"]
}

无需构建步骤 —— Opencode(Bun)可直接加载 .ts 文件。

本地插件(单文件)

将单个文件 model-proxy-router.ts 复制到插件目录即可:

  • 项目级:.opencode/plugins/
  • 全局:~/.config/opencode/plugins/

无需其他文件。

选项

通过元组形式覆盖配置文件路径(npm 与本地安装均适用):

{
  "plugin": [
    ["@jaquesyang/opencode-model-proxy-router", { "configPath": "/absolute/path.json" }]
  ]
}

配置

默认位置:~/.config/opencode/model-proxy-router.json

{
  "proxies": {
    "http1": "http://user:pass@host:port",
    "http2": "http://user:pass@host:port"
  },
  "default": "direct",
  "routes": {
    "opencode-go/muse-spark-1.2-contributor": "http1",
    "opencode/muse-spark-1.2-contributor-free": "http2",
    "opencode-go/*": "http1"
  }
}

参见 model-proxy-router.json.example

  • proxies — 命名的代理条目。键为任意标签,值为代理 URL。本插件仅支持 HTTP 代理(http:// / https://),不支持 SOCKS 代理(socks4:// / socks5://)—— 路由到 socks URL 的请求会以 UnsupportedProxyProtocol 报错。
  • default — 当没有路由匹配时使用的代理名称,或使用 "direct"(默认值)表示直连,不走代理。
  • routes — 将路由键映射到代理名称或内联代理 URL:
    • "provider/model" — 精确匹配 provider/model 及其不带 provider 前缀的模型 ID model
    • "prefix/*" — 通配符匹配所有以 prefix/ 开头的模型
    • 匹配优先级:精确匹配 → 通配符 → default

对于 URL 以已学习的 provider 基础 URL(例如 https://opencode.ai/zen/...)开头的请求,会优先按 provider 路由(provider/*provider/model → 不带 provider 前缀的模型 ID)。

调试

MODEL_PROXY_ROUTER_DEBUG=1 opencode

打印每次路由请求的解析代理,以及运行时学习到的 provider 基础 URL。

测试

npm test
# 或
node --test test.mjs