opencode-models-usage-plugin 1.0.1 → 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/package.json +1 -1
- package/src/tui.tsx +25 -11
package/package.json
CHANGED
package/src/tui.tsx
CHANGED
|
@@ -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 ?
|
|
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
|
|
249
|
-
<text fg=
|
|
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
|
|
253
|
-
<text fg=
|
|
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
|
|
257
|
-
<text fg=
|
|
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
|
|
261
|
-
<text fg=
|
|
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
|
|
265
|
-
<text fg=
|
|
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: {
|