Tps
Display request-level session and per-model TPS metrics in the OpenCode TUI sidebar.
0
81
近 7 天 11
29.6
生态多维模型
1 个月前
2026-08-20
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@nextzhou/opencode-tps@0.2.0"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@nextzhou/opencode-tps@0.2.0"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @nextzhou/opencode-tpsOpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
An OpenCode TUI plugin that displays request-level session and per-model tokens-per-second (TPS) metrics in the sidebar.
Features
- Weighted throughput across all model requests in the session
- Separate metrics by provider, model, and variant
- Output and reasoning token accounting
- Time to first token included
- Tool execution and inter-request waiting excluded
- Historical session estimates after restart
- No telemetry or network requests
Requirements
- OpenCode
>=1.18.0 <2
Installation
Install the plugin globally from npm:
opencode plugin @nextzhou/opencode-tps -g
Start or restart OpenCode, then press Ctrl+X, followed by lowercase b, to open the sidebar. This is the default sidebar_toggle keybinding and may differ if you customized tui.json.
Upgrade
Replace an existing installation with the latest published version:
opencode plugin @nextzhou/opencode-tps -g --force
Load a Local Checkout
For local development, add the project directory to the plugin array in your global tui.json:
{
"$schema": "https://opencode.ai/tui.json",
"plugin": ["/absolute/path/to/opencode-tps"]
}
Metric
The plugin calculates weighted throughput by aggregating tokens and request durations. It never averages individual request TPS values:
TPS = sum(output tokens + reasoning tokens) / sum(model request durations)
A request duration begins at session.next.step.started and ends at the latest text, reasoning, or tool-input end event for that model request. This includes request startup and time to first token. Step completion and tool-result timestamps are deliberately not used, so tool execution and waiting between model requests are excluded.
When precise stream events are unavailable for an older message, the plugin estimates its request window from the assistant message creation timestamp through the final persisted text or reasoning part. Pure tool-call historical steps without those timestamps are omitted.
Development
Development requires Bun 1.3.14.
bun install --frozen-lockfile
bun run check
bun run pack:check
Individual commands:
bun run format
bun run lint
bun run typecheck
bun test
bun run build
Project Structure
src/tui.ts OpenCode event adapter and sidebar renderer
src/session-tps-state.ts Framework-independent TPS tracking and aggregation
tests/ Behavior tests
docs/requirements.md Product scope and metric contract
docs/releasing.md npm release process
License
同类生态推荐
Token Metrics
opencode-token-metrics
Live tokens-per-second meter for the OpenCode TUI prompt.
Headsup
@banburist/opencode-headsup
Live inference telemetry pinned to the OpenCode 2 sidebar.
Oc Usage
@taraksh011/oc-usage
OpenCode plugin — live token usage, cost, and TPS display