opencode-visual-cache 1.2.12 → 1.2.13
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/dist/_version.d.ts +1 -1
- package/dist/_version.js +1 -1
- package/dist/index.js +24 -8
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/index.tsx +26 -5
package/dist/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PLUGIN_VERSION = "1.2.
|
|
1
|
+
export declare const PLUGIN_VERSION = "1.2.13";
|
package/dist/_version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// auto-generated
|
|
2
|
-
export const PLUGIN_VERSION = "1.2.
|
|
2
|
+
export const PLUGIN_VERSION = "1.2.13";
|
package/dist/index.js
CHANGED
|
@@ -348,7 +348,19 @@ function TokenCachePanel(props) {
|
|
|
348
348
|
void partVersion();
|
|
349
349
|
// 自然追踪 messages 和 provider(SDK 数据就绪时自动重新执行)
|
|
350
350
|
const msgs = props.api.state.session.messages(sid);
|
|
351
|
-
|
|
351
|
+
const session = props.api.state.session.get(sid);
|
|
352
|
+
// 累计值优先使用 Session 聚合字段(数据库级,不受 sync 层 limit:100 截断)
|
|
353
|
+
// 若字段不存在(旧版本 SDK),降级到消息遍历累加
|
|
354
|
+
let input = session?.tokens?.input ?? 0;
|
|
355
|
+
let read = session?.tokens?.cache?.read ?? 0;
|
|
356
|
+
let write = session?.tokens?.cache?.write ?? 0;
|
|
357
|
+
let output = session?.tokens?.output ?? 0;
|
|
358
|
+
let cost = session?.cost ?? 0;
|
|
359
|
+
let pid = session?.model?.providerID ?? "";
|
|
360
|
+
let mid = session?.model?.id ?? "";
|
|
361
|
+
const fallbackTokens = session?.tokens == null;
|
|
362
|
+
const fallbackCost = session?.cost == null;
|
|
363
|
+
const fallbackModel = !pid || !mid;
|
|
352
364
|
let prevMsgHitRate = -1, lastMsgHitRate = -1;
|
|
353
365
|
for (const msg of msgs) {
|
|
354
366
|
if (msg.role !== "assistant")
|
|
@@ -361,12 +373,16 @@ function TokenCachePanel(props) {
|
|
|
361
373
|
prevMsgHitRate = lastMsgHitRate;
|
|
362
374
|
lastMsgHitRate = (mrt / mit) * 100;
|
|
363
375
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
376
|
+
if (fallbackTokens) {
|
|
377
|
+
input += num(t.input);
|
|
378
|
+
read += num(t.cache?.read);
|
|
379
|
+
write += num(t.cache?.write);
|
|
380
|
+
output += num(t.output);
|
|
381
|
+
}
|
|
382
|
+
if (fallbackCost) {
|
|
383
|
+
cost += num(msg.cost);
|
|
384
|
+
}
|
|
385
|
+
if (fallbackModel && msg.providerID && msg.modelID) {
|
|
370
386
|
pid = msg.providerID;
|
|
371
387
|
mid = msg.modelID;
|
|
372
388
|
}
|
|
@@ -397,7 +413,7 @@ function TokenCachePanel(props) {
|
|
|
397
413
|
let hasDistData = false;
|
|
398
414
|
const loadedSkills = new Map();
|
|
399
415
|
try {
|
|
400
|
-
const
|
|
416
|
+
const cfg = props.api.state.config;
|
|
401
417
|
const agentName = String(session?.agent ?? cfg?.default_agent ?? "build");
|
|
402
418
|
const agents = cfg?.agent;
|
|
403
419
|
const agentCfg = agents?.[agentName];
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// auto-generated
|
|
2
|
-
export const PLUGIN_VERSION="1.2.
|
|
2
|
+
export const PLUGIN_VERSION="1.2.13";
|
package/src/index.tsx
CHANGED
|
@@ -431,16 +431,37 @@ function TokenCachePanel(props: {
|
|
|
431
431
|
|
|
432
432
|
// 自然追踪 messages 和 provider(SDK 数据就绪时自动重新执行)
|
|
433
433
|
const msgs = props.api.state.session.messages(sid) as Message[]
|
|
434
|
-
|
|
434
|
+
const session = props.api.state.session.get(sid)
|
|
435
|
+
|
|
436
|
+
// 累计值优先使用 Session 聚合字段(数据库级,不受 sync 层 limit:100 截断)
|
|
437
|
+
// 若字段不存在(旧版本 SDK),降级到消息遍历累加
|
|
438
|
+
let input = session?.tokens?.input ?? 0
|
|
439
|
+
let read = session?.tokens?.cache?.read ?? 0
|
|
440
|
+
let write = session?.tokens?.cache?.write ?? 0
|
|
441
|
+
let output = session?.tokens?.output ?? 0
|
|
442
|
+
let cost = session?.cost ?? 0
|
|
443
|
+
let pid = session?.model?.providerID ?? ""
|
|
444
|
+
let mid = session?.model?.id ?? ""
|
|
445
|
+
|
|
446
|
+
const fallbackTokens = session?.tokens == null
|
|
447
|
+
const fallbackCost = session?.cost == null
|
|
448
|
+
const fallbackModel = !pid || !mid
|
|
449
|
+
|
|
435
450
|
let prevMsgHitRate = -1, lastMsgHitRate = -1
|
|
436
451
|
for (const msg of msgs) {
|
|
437
452
|
if (msg.role !== "assistant") continue
|
|
438
453
|
const t = (msg as AssistantMessage).tokens; if (!t) continue
|
|
439
454
|
const mit = num(t.input) + num(t.cache?.read), mrt = num(t.cache?.read)
|
|
440
455
|
if (mit > 0) { prevMsgHitRate = lastMsgHitRate; lastMsgHitRate = (mrt / mit) * 100 }
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
456
|
+
if (fallbackTokens) {
|
|
457
|
+
input += num(t.input); read += num(t.cache?.read); write += num(t.cache?.write); output += num(t.output)
|
|
458
|
+
}
|
|
459
|
+
if (fallbackCost) {
|
|
460
|
+
cost += num((msg as AssistantMessage).cost)
|
|
461
|
+
}
|
|
462
|
+
if (fallbackModel && (msg as AssistantMessage).providerID && (msg as AssistantMessage).modelID) {
|
|
463
|
+
pid = (msg as AssistantMessage).providerID; mid = (msg as AssistantMessage).modelID
|
|
464
|
+
}
|
|
444
465
|
}
|
|
445
466
|
let saved = 0, inputRate = 0, cacheReadRate = 0, cacheWriteRate = 0
|
|
446
467
|
if (read > 0 && pid && mid) for (const provider of props.api.state.provider) {
|
|
@@ -462,7 +483,7 @@ function TokenCachePanel(props: {
|
|
|
462
483
|
let hasDistData = false
|
|
463
484
|
const loadedSkills = new Map<string, { name: string; tokens: number }>()
|
|
464
485
|
try {
|
|
465
|
-
const
|
|
486
|
+
const cfg = props.api.state.config as Record<string, unknown>
|
|
466
487
|
const agentName = String(session?.agent ?? (cfg as any)?.default_agent ?? "build")
|
|
467
488
|
const agents = cfg?.agent as Record<string, unknown> | undefined
|
|
468
489
|
const agentCfg = agents?.[agentName] as Record<string, unknown> | undefined
|