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

luoer-ai-switch

v0.1.2

Published

A small local web UI for switching OpenCode providers.

Readme

AI Switch

npm version license

一个尽量简单的本地 Web 工具,用来管理 OpenCode 的中转站配置。npm 包名:luoer-ai-switch。

dashboard

当前功能

  • 自动读取 ~/.config/opencode/opencode.json
  • 支持 OPENCODE_CONFIG 自定义路径
  • 通过表单加入 OpenCode provider、npm SDK、模型和自定义 headers
  • 从 OpenAI 兼容的 /models 接口自动拉取模型列表
  • 按模型 ID 匹配本地维护的能力目录,补全已确认的上下文、输出和 variants
  • 直接编辑完整 JSON 配置
  • 每次保存前自动备份
  • 查看和恢复历史备份
  • 服务仅监听 127.0.0.1

界面

| 中转站管理 | JSON 编辑器 | 版本历史 | |---|---|---| | providers | json | history |

本地运行

需要 Node.js 18 或更高版本。

npm install
npm run dev

浏览器会自动打开 http://127.0.0.1:3456。

不自动打开浏览器:

AI_SWITCH_NO_OPEN=1 npm run dev

指定端口:

AI_SWITCH_PORT=4567 npm run dev

构建和命令行测试

npm run build
npm link
luoer-ai-switch --help

发布和 npx 使用

发布到 npm(prepublishOnly 会自动执行完整构建):

npm publish

发布后用户无需安装,直接运行:

npx luoer-ai-switch
npx luoer-ai-switch --port 4567
npx luoer-ai-switch --no-open

命令行参数

| 参数 | 说明 | |---|---| | --port <n> | 服务端口(默认 3456) | | --no-open | 不自动打开浏览器 | | -v, --version | 显示版本号 | | -h, --help | 显示帮助 |

服务仅监听 127.0.0.1。配置路径默认 ~/.config/opencode/opencode.json,可用 OPENCODE_CONFIG 环境变量覆盖。

配置和备份位置

默认配置:~/.config/opencode/opencode.json

AI Switch 应用数据目录由 env-paths 按操作系统决定。macOS 通常是 ~/Library/Preferences/ai-switch/,Linux 通常是 ~/.config/ai-switch/,Windows 通常是 %APPDATA%/ai-switch/。

版本目录位于应用数据目录下的 versions/,管理记录位于 state.json。

如果设置了 OPENCODE_CONFIG,只会改变 OpenCode 配置文件位置,不会改变 AI Switch 自己的数据目录。

OpenCode 配置格式

生成的 provider 结构遵循 OpenCode 官方配置格式:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "my-relay": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "My AI Provider",
      "options": {
        "baseURL": "https://example.com/v1",
        "apiKey": "sk-example",
        "headers": {
          "Authorization": "Bearer custom-token"
        }
      },
      "models": {
        "claude-sonnet-4-5": {
          "name": "claude-sonnet-4-5"
        }
      }
    }
  }
}

参考:OpenCode Providers 文档

模型拉取要求中转站提供 OpenAI 兼容的 GET {baseURL}/models 接口。接口只负责发现模型 ID;AI Switch 再用 src/model-catalog.json 中的精确 ID 目录补全能力参数。未匹配的 ID 只导入名称,不会猜测参数。目录内容可审阅和更新。API Key 和自定义 headers 仅由本地服务用于该请求。

每个模型都会补全并可在抽屉中调整能力参数,按 OpenCode 的真实 schema 写入:

  • tool_call:是否支持工具调用(对应能力目录里的 tools)
  • modalities.input / modalities.output:模型接受的输入/输出模态(text、image、video、pdf、audio)
  • limit.context / limit.output:上下文与单次输出 token 上限

License

MIT © loreluo2077