opencode-models-usage-plugin 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ja.md CHANGED
@@ -78,7 +78,7 @@ OpenCode のサイドバーで、現在のセッションツリー(再帰的
78
78
  "opencode-models-usage-plugin/tui"
79
79
  ],
80
80
  "plugin_enabled": {
81
- "local:session-model-usage": true
81
+ "session-model-usage": true
82
82
  }
83
83
  }
84
84
  ```
@@ -88,7 +88,7 @@ OpenCode のサイドバーで、現在のセッションツリー(再帰的
88
88
  ### 方法 2: CLI でワンコマンドインストール
89
89
 
90
90
  ```bash
91
- opencode plugin opencode-models-usage-plugin/tui --global
91
+ opencode plugin opencode-models-usage-plugin --global
92
92
  ```
93
93
 
94
94
  このコマンドでプラグインのインストールとグローバル設定の更新を自動で行えます。
package/README.ko.md CHANGED
@@ -78,7 +78,7 @@ OpenCode 사이드바에서 현재 세션 트리(재귀적인 하위 세션 포
78
78
  "opencode-models-usage-plugin/tui"
79
79
  ],
80
80
  "plugin_enabled": {
81
- "local:session-model-usage": true
81
+ "session-model-usage": true
82
82
  }
83
83
  }
84
84
  ```
@@ -88,7 +88,7 @@ OpenCode 사이드바에서 현재 세션 트리(재귀적인 하위 세션 포
88
88
  ### 방법 2: CLI 한 줄로 설치하기
89
89
 
90
90
  ```bash
91
- opencode plugin opencode-models-usage-plugin/tui --global
91
+ opencode plugin opencode-models-usage-plugin --global
92
92
  ```
93
93
 
94
94
  이 명령은 플러그인을 설치하고 전역 설정도 자동으로 갱신합니다.
package/README.md CHANGED
@@ -87,7 +87,7 @@ Add the following:
87
87
  "opencode-models-usage-plugin/tui"
88
88
  ],
89
89
  "plugin_enabled": {
90
- "local:session-model-usage": true
90
+ "session-model-usage": true
91
91
  }
92
92
  }
93
93
  ```
@@ -97,7 +97,7 @@ Save the file and restart OpenCode. The plugin will be installed automatically v
97
97
  ### Method 2: One-click install via CLI
98
98
 
99
99
  ```bash
100
- opencode plugin opencode-models-usage-plugin/tui --global
100
+ opencode plugin opencode-models-usage-plugin --global
101
101
  ```
102
102
 
103
103
  This command installs the plugin and updates your global config automatically.
package/README.zh-CN.md CHANGED
@@ -88,7 +88,7 @@
88
88
  "opencode-models-usage-plugin/tui"
89
89
  ],
90
90
  "plugin_enabled": {
91
- "local:session-model-usage": true
91
+ "session-model-usage": true
92
92
  }
93
93
  }
94
94
  ```
@@ -98,7 +98,7 @@
98
98
  ### 方式二:CLI 一键安装(最便捷)
99
99
 
100
100
  ```bash
101
- opencode plugin opencode-models-usage-plugin/tui --global
101
+ opencode plugin opencode-models-usage-plugin --global
102
102
  ```
103
103
 
104
104
  这条命令会自动安装插件,并更新全局配置。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-models-usage-plugin",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Show per-model usage, live TPS, tokens, and cost in the OpenCode sidebar.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/tui.tsx CHANGED
@@ -6,7 +6,7 @@ import { For, Show, createEffect, createMemo, createSignal, onCleanup, onMount }
6
6
 
7
7
  import { getSessionUsage, type SessionMessageLike, type LiveTpsState } from "./session-usage"
8
8
 
9
- const pluginID = "local:session-model-usage"
9
+ const pluginID = "session-model-usage"
10
10
 
11
11
  const isRecord = (value: unknown): value is Record<string, unknown> =>
12
12
  typeof value === "object" && value !== null
@@ -230,6 +230,7 @@ const SessionUsagePanel = (props: { api: TuiPluginApi; sessionID: string }) => {
230
230
  })
231
231
 
232
232
  const { usageMessages, liveTps } = useSessionMessages(props.api, activeSessionID)
233
+ const theme = () => props.api.theme.current
233
234
 
234
235
  const usage = createMemo(() => getSessionUsage(usageMessages(), props.api.state.provider, liveTps()))
235
236
 
@@ -242,27 +243,27 @@ const SessionUsagePanel = (props: { api: TuiPluginApi; sessionID: string }) => {
242
243
  <For each={usage().models}>
243
244
  {(model) => (
244
245
  <box flexDirection="column">
245
- <text fg={model.isLiveTps ? "yellow" : undefined}>● {model.label}</text>
246
+ <text fg={model.isLiveTps ? theme().warning : theme().text}>● {model.label}</text>
246
247
  <box flexDirection="column" paddingLeft={2}>
247
248
  <box flexDirection="row">
248
- <text>■ TPS </text>
249
- <text fg="gray">{model.isLiveTps && model.tps > 0 ? model.tps.toFixed(1) : "—"}</text>
249
+ <text fg={theme().text} width={18} flexShrink={0}>■ TPS</text>
250
+ <text fg={theme().textMuted}>{model.isLiveTps && model.tps > 0 ? model.tps.toFixed(1) : "—"}</text>
250
251
  </box>
251
252
  <box flexDirection="row">
252
- <text>■ Context Tokens </text>
253
- <text fg="gray">{model.contextTokens.toLocaleString("en-US")}</text>
253
+ <text fg={theme().text} width={18} flexShrink={0}>■ Context Tokens</text>
254
+ <text fg={theme().textMuted}>{model.contextTokens.toLocaleString("en-US")}</text>
254
255
  </box>
255
256
  <box flexDirection="row">
256
- <text>■ Session Tokens </text>
257
- <text fg="gray">{model.sessionTokens.toLocaleString("en-US")}</text>
257
+ <text fg={theme().text} width={18} flexShrink={0}>■ Session Tokens</text>
258
+ <text fg={theme().textMuted}>{model.sessionTokens.toLocaleString("en-US")}</text>
258
259
  </box>
259
260
  <box flexDirection="row">
260
- <text>■ Session Cached </text>
261
- <text fg="gray">{model.sessionCachedTokens.toLocaleString("en-US")}</text>
261
+ <text fg={theme().text} width={18} flexShrink={0}>■ Session Cached</text>
262
+ <text fg={theme().textMuted}>{model.sessionCachedTokens.toLocaleString("en-US")}</text>
262
263
  </box>
263
264
  <box flexDirection="row">
264
- <text>■ spent </text>
265
- <text fg="gray">${model.cost.toFixed(4)}</text>
265
+ <text fg={theme().text} width={18} flexShrink={0}>■ spent</text>
266
+ <text fg={theme().textMuted}>${model.cost.toFixed(4)}</text>
266
267
  </box>
267
268
  </box>
268
269
  </box>
@@ -273,7 +274,20 @@ const SessionUsagePanel = (props: { api: TuiPluginApi; sessionID: string }) => {
273
274
  )
274
275
  }
275
276
 
277
+ const globalKey = Symbol.for(`opencode-plugin-${pluginID}`)
278
+
276
279
  const tui: TuiPlugin = async (api) => {
280
+ const globalStore = globalThis as { [key: symbol]: boolean | undefined }
281
+
282
+ if (globalStore[globalKey]) {
283
+ return
284
+ }
285
+ globalStore[globalKey] = true
286
+
287
+ api.lifecycle.onDispose(() => {
288
+ globalStore[globalKey] = false
289
+ })
290
+
277
291
  api.slots.register({
278
292
  order: 150,
279
293
  slots: {