opencode-visual-cache 1.2.12 → 1.2.14

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Hotakus
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hotakus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1 +1 @@
1
- export declare const PLUGIN_VERSION = "1.2.12";
1
+ export declare const PLUGIN_VERSION = "1.2.14";
package/dist/_version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // auto-generated
2
- export const PLUGIN_VERSION = "1.2.12";
2
+ export const PLUGIN_VERSION = "1.2.14";
package/dist/index.js CHANGED
@@ -348,7 +348,21 @@ function TokenCachePanel(props) {
348
348
  void partVersion();
349
349
  // 自然追踪 messages 和 provider(SDK 数据就绪时自动重新执行)
350
350
  const msgs = props.api.state.session.messages(sid);
351
- let input = 0, read = 0, write = 0, output = 0, cost = 0, pid = "", mid = "";
351
+ const session = typeof props.api.state.session.get === "function"
352
+ ? props.api.state.session.get(sid)
353
+ : undefined;
354
+ // 累计值优先使用 Session 聚合字段(数据库级,不受 sync 层 limit:100 截断)
355
+ // 若字段不存在(旧版本 SDK),降级到消息遍历累加
356
+ let input = session?.tokens?.input ?? 0;
357
+ let read = session?.tokens?.cache?.read ?? 0;
358
+ let write = session?.tokens?.cache?.write ?? 0;
359
+ let output = session?.tokens?.output ?? 0;
360
+ let cost = session?.cost ?? 0;
361
+ let pid = session?.model?.providerID ?? "";
362
+ let mid = session?.model?.id ?? "";
363
+ const fallbackTokens = session?.tokens == null;
364
+ const fallbackCost = session?.cost == null;
365
+ const fallbackModel = !pid || !mid;
352
366
  let prevMsgHitRate = -1, lastMsgHitRate = -1;
353
367
  for (const msg of msgs) {
354
368
  if (msg.role !== "assistant")
@@ -361,12 +375,16 @@ function TokenCachePanel(props) {
361
375
  prevMsgHitRate = lastMsgHitRate;
362
376
  lastMsgHitRate = (mrt / mit) * 100;
363
377
  }
364
- input += num(t.input);
365
- read += num(t.cache?.read);
366
- write += num(t.cache?.write);
367
- output += num(t.output);
368
- cost += num(msg.cost);
369
- if (msg.providerID && msg.modelID) {
378
+ if (fallbackTokens) {
379
+ input += num(t.input);
380
+ read += num(t.cache?.read);
381
+ write += num(t.cache?.write);
382
+ output += num(t.output);
383
+ }
384
+ if (fallbackCost) {
385
+ cost += num(msg.cost);
386
+ }
387
+ if (fallbackModel && msg.providerID && msg.modelID) {
370
388
  pid = msg.providerID;
371
389
  mid = msg.modelID;
372
390
  }
@@ -397,7 +415,7 @@ function TokenCachePanel(props) {
397
415
  let hasDistData = false;
398
416
  const loadedSkills = new Map();
399
417
  try {
400
- const session = props.api.state.session.get(sid), cfg = props.api.state.config;
418
+ const cfg = props.api.state.config;
401
419
  const agentName = String(session?.agent ?? cfg?.default_agent ?? "build");
402
420
  const agents = cfg?.agent;
403
421
  const agentCfg = agents?.[agentName];
package/package.json CHANGED
@@ -1,58 +1,62 @@
1
- {
2
- "name": "opencode-visual-cache",
3
- "version": "1.2.12",
4
- "description": "OpenCode TUI plugin displaying real-time token cache hit rate in the sidebar",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
- },
13
- "./tui": {
14
- "import": "./src/index.tsx",
15
- "config": {
16
- "enabled": true
17
- }
18
- }
19
- },
20
- "files": [
21
- "dist",
22
- "src",
23
- "install.mjs",
24
- "README.md",
25
- "README_EN.md"
26
- ],
27
- "bin": {
28
- "opencode-visual-cache": "install.mjs"
29
- },
30
- "scripts": {
31
- "build": "tsc",
32
- "typecheck": "tsc --noEmit",
33
- "version": "node -e \"require('fs').writeFileSync('src/_version.ts','// auto-generated\\nexport const PLUGIN_VERSION='+JSON.stringify(require('./package.json').version)+';\\n')\"",
34
- "prepublishOnly": "tsc"
35
- },
36
- "keywords": [
37
- "opencode",
38
- "opencode-plugin",
39
- "tui",
40
- "token",
41
- "cache-hit-rate",
42
- "cost-tracking"
43
- ],
44
- "license": "MIT",
45
- "peerDependencies": {
46
- "@opencode-ai/plugin": ">=1.14.0",
47
- "@opencode-ai/sdk": ">=1.14.0",
48
- "@opentui/core": ">=0.2.0",
49
- "@opentui/solid": ">=0.2.0",
50
- "solid-js": ">=1.9.0"
51
- },
52
- "devDependencies": {
53
- "@opencode-ai/plugin": "^1.14.50",
54
- "@opencode-ai/sdk": "^1.14.50",
55
- "tsx": "^4.22.3",
56
- "typescript": "^5.8.0"
57
- }
58
- }
1
+ {
2
+ "name": "opencode-visual-cache",
3
+ "version": "1.2.14",
4
+ "description": "OpenCode TUI plugin displaying real-time token cache hit rate in the sidebar",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./tui": {
14
+ "import": "./src/index.tsx",
15
+ "config": {
16
+ "enabled": true
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "src",
23
+ "install.mjs",
24
+ "README.md",
25
+ "README_EN.md"
26
+ ],
27
+ "bin": {
28
+ "opencode-visual-cache": "install.mjs"
29
+ },
30
+ "scripts": {
31
+ "build": "tsc",
32
+ "typecheck": "tsc --noEmit",
33
+ "version": "node -e \"require('fs').writeFileSync('src/_version.ts','// auto-generated\\nexport const PLUGIN_VERSION='+JSON.stringify(require('./package.json').version)+';\\n')\"",
34
+ "prepublishOnly": "tsc"
35
+ },
36
+ "keywords": [
37
+ "opencode",
38
+ "opencode-plugin",
39
+ "tui",
40
+ "token",
41
+ "cache-hit-rate",
42
+ "cost-tracking"
43
+ ],
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/Hotakus/opencode-visual-cache.git"
47
+ },
48
+ "license": "MIT",
49
+ "peerDependencies": {
50
+ "@opencode-ai/plugin": ">=1.14.0",
51
+ "@opencode-ai/sdk": ">=1.14.0",
52
+ "@opentui/core": ">=0.2.0",
53
+ "@opentui/solid": ">=0.2.0",
54
+ "solid-js": ">=1.9.0"
55
+ },
56
+ "devDependencies": {
57
+ "@opencode-ai/plugin": "^1.14.50",
58
+ "@opencode-ai/sdk": "^1.14.50",
59
+ "tsx": "^4.22.3",
60
+ "typescript": "^5.8.0"
61
+ }
62
+ }
package/src/_version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // auto-generated
2
- export const PLUGIN_VERSION="1.2.12";
2
+ export const PLUGIN_VERSION="1.2.14";