Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opencode-show-image

OpenCode 自定义工具:在对话中展示图片(本地路径或远程 URL),无需模型支持视觉输入。通过本机 HTTP 服务注册短 URL,AI 复制 Markdown 图片行到回复,用户即可在对话流中看到图片。

An OpenCode custom tool that displays images (local path or remote URL) in the conversation without requiring vision-capable models. Registers a short URL via a local HTTP server; the AI copies the Markdown image line into its reply so the user sees the image inline.

功能 / Features

  • 展示本地图片:path 参数(绝对路径或相对会话目录)
  • 展示远程图片:url 参数(自动下载到本地)
  • 自定义图注:caption 参数(Markdown alt 文本)
  • 本机预览服务:http://127.0.0.1:端口/img/<token> 短 URL,仅几十字节
  • 注册表持久化:重启 opencode 后历史图片 URL 仍可访问
  • 支持格式:png / jpg / jpeg / gif / webp / svg / bmp / avif / ico

与其他方案对比 / Compared to alternatives

项目 方向 说明
rezrov/opencode-image 终端内渲染(TUI) 需图形终端,Python 实现,仅 CLI 场景
@sami7786/opencode-image-proxy 让模型看图(vision proxy) 已归档,方向相反
opencode #9539(官方进行中) 工具返回图片附件 官方原生方案,尚未发布

本工具展示对象是用户(对话流内嵌展示),不依赖视觉模型、不依赖终端能力,桌面版 / 网页版通用。即使官方后续支持工具附件,本工具仍是无模型依赖的最简方案。

安装 / Installation

本工具依赖两个文件,需分别放置:

~/.config/opencode/
├── tools/
│   └── show-image.ts      ← 工具本体
└── lib/
    └── img-server.ts      ← 共享依赖(本机预览服务)
# Windows
copy show-image.ts %USERPROFILE%\.config\opencode\tools\show-image.ts
copy img-server.ts %USERPROFILE%\.config\opencode\lib\img-server.ts
# macOS / Linux
cp show-image.ts ~/.config/opencode/tools/show-image.ts
cp img-server.ts ~/.config/opencode/lib/img-server.ts

注意:img-server.ts 必须放在 lib/(或任何 tools/ 之外的目录),否则会被 opencode 当作独立工具注册而报错。show-image.ts 中的 ./img-server.ts 相对路径会自动解析到 lib/ 下的文件。

重启 opencode 生效。

使用示例 / Usage

展示图片 C:\Users\me\screenshot.png
展示图片 https://example.com/logo.png,图注"项目 Logo"

工具输出会指示 AI 原样复制 Markdown 图片行到回复正文,用户即可在对话流中看到图片。

工作原理 / How it works

  1. 工具启动一个本机 HTTP 服务(127.0.0.1,端口 18923–18943 自动探测)
  2. 图片注册为短 URL:http://127.0.0.1:端口/img/<token>
  3. 工具输出指示 AI 复制 ![图注](短URL) 到回复
  4. 桌面端 Markdown 渲染直接加载本地图片,用户看到图

无需模型支持视觉输入,base64 不经过对话上下文。

与 generate-image 的关系 / Relation to generate-image

img-server.ts 是共享模块,同时被图片生成工具(generate-image)复用。本仓库提供的是独立副本;如果你同时使用 generate-image,两者共用同一个 lib/img-server.ts 即可(同进程加载 + Node 模块缓存 ⇒ 服务单例天然共享)。

License

MIT

About

OpenCode custom tool to display images inline in conversation via a local preview server. No vision-capable models needed.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages