opencode-visual-cache 1.2.13 → 1.2.15-beta.0

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.
@@ -1 +1 @@
1
- export declare const PLUGIN_VERSION = "1.2.13";
1
+ export declare const PLUGIN_VERSION = "1.2.15-beta.0";
package/dist/_version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // auto-generated
2
- export const PLUGIN_VERSION = "1.2.13";
2
+ export const PLUGIN_VERSION = "1.2.15-beta.0";
package/dist/index.js CHANGED
@@ -348,7 +348,9 @@ function TokenCachePanel(props) {
348
348
  void partVersion();
349
349
  // 自然追踪 messages 和 provider(SDK 数据就绪时自动重新执行)
350
350
  const msgs = props.api.state.session.messages(sid);
351
- const session = props.api.state.session.get(sid);
351
+ const session = typeof props.api.state.session.get === "function"
352
+ ? props.api.state.session.get(sid)
353
+ : undefined;
352
354
  // 累计值优先使用 Session 聚合字段(数据库级,不受 sync 层 limit:100 截断)
353
355
  // 若字段不存在(旧版本 SDK),降级到消息遍历累加
354
356
  let input = session?.tokens?.input ?? 0;
@@ -388,7 +390,7 @@ function TokenCachePanel(props) {
388
390
  }
389
391
  }
390
392
  let saved = 0, inputRate = 0, cacheReadRate = 0, cacheWriteRate = 0;
391
- if (read > 0 && pid && mid)
393
+ if (read > 0 && pid && mid && Array.isArray(props.api.state.provider))
392
394
  for (const provider of props.api.state.provider) {
393
395
  if (provider.id !== pid)
394
396
  continue;
@@ -637,8 +639,9 @@ function TokenCachePanel(props) {
637
639
  };
638
640
  const unsubPart = props.api.event.on("message.part.updated", () => { bumpPartVersion(); setRefreshTick(v => v + 1); });
639
641
  const unsubMsg = props.api.event.on("message.updated", () => { bumpPartVersion(); setRefreshTick(v => v + 1); });
642
+ const unsubSession = props.api.event.on("session.updated", () => { setRefreshTick(v => v + 1); });
640
643
  setRefreshTick(v => v + 1);
641
- onCleanup(() => { clearTimeout(partTimer); unsubPart(); unsubMsg(); });
644
+ onCleanup(() => { clearTimeout(partTimer); unsubPart(); unsubMsg(); unsubSession(); });
642
645
  });
643
646
  // ── colours ──
644
647
  // Pull from the current theme, auto-desaturate if too punchy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-visual-cache",
3
- "version": "1.2.13",
3
+ "version": "1.2.15-beta.0",
4
4
  "description": "OpenCode TUI plugin displaying real-time token cache hit rate in the sidebar",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -11,7 +11,7 @@
11
11
  "types": "./dist/index.d.ts"
12
12
  },
13
13
  "./tui": {
14
- "import": "./src/index.tsx",
14
+ "import": "./dist/tui.js",
15
15
  "config": {
16
16
  "enabled": true
17
17
  }
@@ -28,7 +28,8 @@
28
28
  "opencode-visual-cache": "install.mjs"
29
29
  },
30
30
  "scripts": {
31
- "build": "tsc",
31
+ "build": "tsc && node build.tui.mjs",
32
+ "build:tui": "node build.tui.mjs",
32
33
  "typecheck": "tsc --noEmit",
33
34
  "version": "node -e \"require('fs').writeFileSync('src/_version.ts','// auto-generated\\nexport const PLUGIN_VERSION='+JSON.stringify(require('./package.json').version)+';\\n')\"",
34
35
  "prepublishOnly": "tsc"
@@ -41,6 +42,10 @@
41
42
  "cache-hit-rate",
42
43
  "cost-tracking"
43
44
  ],
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/Hotakus/opencode-visual-cache.git"
48
+ },
44
49
  "license": "MIT",
45
50
  "peerDependencies": {
46
51
  "@opencode-ai/plugin": ">=1.14.0",
@@ -52,6 +57,8 @@
52
57
  "devDependencies": {
53
58
  "@opencode-ai/plugin": "^1.14.50",
54
59
  "@opencode-ai/sdk": "^1.14.50",
60
+ "esbuild": "^0.25.0",
61
+ "esbuild-plugin-solid": "^0.5.0",
55
62
  "tsx": "^4.22.3",
56
63
  "typescript": "^5.8.0"
57
64
  }
package/src/_version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // auto-generated
2
- export const PLUGIN_VERSION="1.2.13";
2
+ export const PLUGIN_VERSION="1.2.15-beta.0";
package/src/index.tsx CHANGED
@@ -431,7 +431,9 @@ function TokenCachePanel(props: {
431
431
 
432
432
  // 自然追踪 messages 和 provider(SDK 数据就绪时自动重新执行)
433
433
  const msgs = props.api.state.session.messages(sid) as Message[]
434
- const session = props.api.state.session.get(sid)
434
+ const session = typeof props.api.state.session.get === "function"
435
+ ? props.api.state.session.get(sid)
436
+ : undefined
435
437
 
436
438
  // 累计值优先使用 Session 聚合字段(数据库级,不受 sync 层 limit:100 截断)
437
439
  // 若字段不存在(旧版本 SDK),降级到消息遍历累加
@@ -464,7 +466,7 @@ function TokenCachePanel(props: {
464
466
  }
465
467
  }
466
468
  let saved = 0, inputRate = 0, cacheReadRate = 0, cacheWriteRate = 0
467
- if (read > 0 && pid && mid) for (const provider of props.api.state.provider) {
469
+ if (read > 0 && pid && mid && Array.isArray(props.api.state.provider)) for (const provider of props.api.state.provider) {
468
470
  if (provider.id !== pid) continue
469
471
  const model = provider.models[mid]; if (!model?.cost) continue
470
472
  inputRate = num(model.cost.input); cacheReadRate = num(model.cost.cache?.read); cacheWriteRate = num(model.cost.cache?.write)
@@ -662,8 +664,9 @@ function TokenCachePanel(props: {
662
664
  }
663
665
  const unsubPart = props.api.event.on("message.part.updated", () => { bumpPartVersion(); setRefreshTick(v => v + 1) })
664
666
  const unsubMsg = props.api.event.on("message.updated", () => { bumpPartVersion(); setRefreshTick(v => v + 1) })
667
+ const unsubSession = props.api.event.on("session.updated", () => { setRefreshTick(v => v + 1) })
665
668
  setRefreshTick(v => v + 1)
666
- onCleanup(() => { clearTimeout(partTimer); unsubPart(); unsubMsg() })
669
+ onCleanup(() => { clearTimeout(partTimer); unsubPart(); unsubMsg(); unsubSession() })
667
670
  })
668
671
 
669
672
  // ── colours ──
@@ -938,7 +941,7 @@ function TokenCachePanel(props: {
938
941
  </Show>
939
942
  </Show>
940
943
  </Show>
941
- </box>
944
+ </box>
942
945
  )
943
946
  }
944
947