Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opencode-helper

一个为 opencode.ai Zen 套餐提供实时用量与可用模型展示的 DeepSeek Harness(DSH) 动态插件。 A DeepSeek Harness (DSH) dynamic plugin that shows real-time opencode.ai Zen quota usage and available models.

DSH opencode


✨ Features / 功能

English

  1. Live quota & plan models (host.js) Polls opencode.ai every 30s, reads the available models of the current plan and three usage windows 5h / 1w / 1m:

    • Usage: GET https://opencode.ai/zen/go/v1/usage{ usage: { rolling, weekly, monthly: { status, percent, resetsAt } } }
    • Models: GET …/zen/go/v1/models (go family) / GET …/zen/v1/models (zen family)
    • API keys come from DSH credentials and never appear in any RPC payload.
  2. Settings → Models rows (client.jsocu-models) Compact inline usage mini-bars (5h / 1w / 1m) + plan model count in the free space between the provider name and its action buttons; hovering a row shows a full usage card (reset times + available models).

  3. Context ring (ContextMeter) (client.jsocu-ring) When the active model belongs to an opencode provider:

    • Hover: the native tooltip is suppressed and replaced by a DSH-styled usage bubble above the ring.
    • Click: the native panel stays, and the usage block is appended inside the panel's lower part (no layout reflow — space is reserved before the first paint via a MutationObserver).

    The progress bar color changes continuously with usage (green → amber → red via color-mix on theme tokens, theme-aware), and the ring keeps its stock behaviour for non-opencode models.

中文

  1. 实时用量与可用模型host.js) 每 30 秒轮询 opencode.ai,读取当前套餐的可模型列表与 5h / 1w / 1m 三档用量:

    • 用量:GET https://opencode.ai/zen/go/v1/usage{ usage: { rolling, weekly, monthly: { status, percent, resetsAt } } }
    • 模型:GET …/zen/go/v1/models(go 系)/ GET …/zen/v1/models(zen 系)
    • API key 经 DSH credentials 解析,不经过任何 RPC 返回。
  2. “设置 → 模型”行内用量client.jsocu-models) 在 provider 名称与操作按钮之间的空白处内联显示 5h / 1w / 1m 迷你用量条与套餐可用模型数; 悬停该行显示完整用量卡片(含重置时间与可用模型数)。

  3. 上下文圆圈(ContextMeter)client.jsocu-ring) 当当前模型属于 opencode 系 Provider 时:

    • 悬停:抑制原生 tooltip,改为在上方显示 DSH 风格的用量气泡;
    • 点击:保留原生面板,并把用量块追加进面板内部下方(用 MutationObserver 在首帧绘制前占位,面板布局不重排)。

    进度条颜色随用量连续渐变(绿 → 黄 → 红,基于主题 token 的 color-mix,明暗主题自适应); 非 opencode 模型时上下文保持原生行为不变。


🚀 Activate / 激活

DSH 动态插件仅在当前会话进程内生效(进程重启后丢失),应在 DSH GUI 中通过 Cordis 插件流程定义并运行。

# The plugin is distributed as host.js (Host half) + client.js (Client half).
# In DSH: define a dynamic plugin with the two halves below and run it.
#   code.host   = contents of host.js
#   code.client = contents of client.js

Prereguisites / 前置条件:

  • 本机可访问 https://opencode.ai
  • curl.exe(Windows 自带)或 curl,用于携带 Authorization 请求头(DSH 的 web.fetch 不允许自定义该头)。
  • 凭据写入 ~/.dsh/.credentials.yamlOPENCODE_GO_API_KEY / OPENCODE_API_KEY(或把 opencode 自身的 ~/.local/share/opencode/auth.json 内容写入 DSH 凭据)。

🧩 Provider 识别规则 / Provider detection

针对 settings → llm-pi-ai.providers 中每一项,命中以下任一即为“opencode 系”:

  • provider id 为 opencode / opencode-go
  • apiKeyEnvOPENCODE 开头;
  • baseURLopencode.ai

无任何匹配时回退扫描 OPENCODE_GO_API_KEY / OPENCODE_API_KEY 两个标准环境变量名。 相同 key 的多个 Provider 只抓取一次。


📁 Files / 文件

File Role
host.js Host half: polling fetch, snapshot cache, ocu/state RPC
client.js Client half: models-page inline bars + ring hover/click overlays

🏷 Topics / 标签

GitHub topics:deepseek-harness, deepseek, dsh, cordis, plugin, opencode, opencode-zen, llm, usage, javascript


📄 License

MIT(如需其他协议,在 issue 中说明即可 / open an issue to request a change)。

About

DeepSeek Harness (DSH) dynamic plugin: real-time opencode.ai Zen quota usage (5h/1w/1m) & plan models on settings rows and the context ring

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages