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

opencode-qimage

v0.1.0

Published

OpenCode plugin: image_gen / image_edit tools routed by provider/model

Readme

opencode-qimage

OpenCode 插件:给 agent 两个 tool,image_gen(文生图)和 image_edit(改图 / 参考合成)。按 provider/model 路由到 OpenAI、xAI Grok 或 OpenRouter 的图像 API。

凭证复用 OpenCode 已有的 provider.*.options(apiKey / baseURL),不另开一套 key。

第一版不做:ChatGPT OAuth、流式、Gemini 原生、视频。

安装

发布到 npm 之后,在 opencode.json 里写包名即可(见下方配置)。本地开发:

pnpm install
pnpm build

然后把 plugin 指向本目录(file: URL 或绝对路径)。改完配置或重新 build 后重启 OpenCode,插件才会重新加载。

配置

opencode.json 用 plugin tuple:

{
  "plugin": [
    [
      "opencode-qimage",
      {
        "default": "openai/gpt-image-2",
        "models": {
          "openai/gpt-image-2": { "type": "openai" },
          "xai/grok-imagine-image": { "type": "grok" },
          "openrouter/openai/gpt-image-2": {
            "type": "openrouter",
            "id": "openai/gpt-image-2"
          }
        }
      }
    ]
  ]
}
  • key = OpenCode 的 providerID/modelID(可含 /,按第一个 / 拆 provider)
  • id:发给上游的 model 名,缺省用 key 里 provider 之后的部分
  • 可选覆盖:generatePath / editPath、baseURL、apiKey(覆盖 provider 配置)
  • type 决定默认 path 和请求体,不是再写一套原生 SDK
  • 未登记的 model 会直接报错,必须写进 models

凭证解析顺序:模型条目覆盖 → config.provider[id].options(插件 config hook 捕获)→ 常见环境变量(OPENAI_API_KEY / XAI_API_KEY / OPENROUTER_API_KEY 以及对应 *_BASE_URL)。apiKey 支持 {env:VAR}。

baseURL 按 OpenCode 惯例带 /v1(如 https://api.openai.com/v1)。path 只拼相对后缀。

Type(端点方言)

| type | generate | edit | 体 | |------|----------|------|-----| | openai | {base}/images/generations | {base}/images/edits | gen JSON;edit multipart(一张用 image,多张用 image[],可选 mask) | | grok | 同上 | 同上 | 都是 JSON;edit 为 { image: { url, type: "image_url" } }(最多 3 张时用 images);size 映射到 aspect_ratio + resolution | | openrouter | {base}/images | 同一端点 | JSON;edit 用 input_references |

type: "openai" 也可配自定义 path,用来接 OpenAI 兼容网关。

path 覆盖示例

{
  "plugin": [
    [
      "opencode-qimage",
      {
        "default": "gateway/gpt-image-2",
        "models": {
          "gateway/gpt-image-2": {
            "type": "openai",
            "generatePath": "images/generations",
            "editPath": "images/edits",
            "baseURL": "https://my-gateway.example/v1"
          }
        }
      }
    ]
  ]
}

对应 provider 的 key 仍从 provider.gateway.options 或 GATEWAY_API_KEY 读取。

Tools

image_gen:文生图。参数:prompt、out、可选 model / size / quality。一次一张,落到磁盘。

image_edit:已有图 + prompt。参数:prompt、images[]、out、可选 model / size / quality / mask。mask 只发给 openai;grok / openrouter 忽略并在返回里说明。

没参考图用 gen;改图 / 参考合成用 edit。输出为写入后的绝对路径。响应是 url 则下载;是 b64_json 则解码。目标已存在则写成 -v2 / -v3,不覆盖。

size 是统一尺寸参数:openai 原样传(1024x1024 / auto / WIDTHxHEIGHT);grok / openrouter 在 adapter 里映射为 aspect_ratio + resolution。

请求超时默认 300s(图像生成经常超过 60s)。不流式。

开发

pnpm install
pnpm test
pnpm build

导出:

export default { id: "opencode-qimage", server: plugin } satisfies PluginModule