opencode-visual-cache 1.6.2 → 1.7.0-beta.1

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.
Files changed (62) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +247 -247
  3. package/README_EN.md +247 -247
  4. package/dist/_version.d.ts +1 -1
  5. package/dist/_version.js +1 -1
  6. package/dist/core/color.d.ts +37 -0
  7. package/dist/core/color.js +108 -0
  8. package/dist/core/currency.d.ts +17 -0
  9. package/dist/core/currency.js +43 -0
  10. package/dist/core/estimate.d.ts +1 -0
  11. package/dist/core/estimate.js +40 -0
  12. package/dist/core/format.d.ts +15 -0
  13. package/dist/core/format.js +90 -0
  14. package/dist/core/index.d.ts +5 -0
  15. package/dist/core/index.js +5 -0
  16. package/dist/core/types.d.ts +17 -0
  17. package/dist/core/types.js +1 -0
  18. package/dist/index.js +12 -818
  19. package/dist/panel/TokenCachePanel.d.ts +10 -0
  20. package/dist/panel/TokenCachePanel.js +549 -0
  21. package/dist/panel/panel-api.d.ts +119 -0
  22. package/dist/panel/panel-api.js +1 -0
  23. package/dist/tui.js +223 -209
  24. package/dist/v2/commands.d.ts +10 -0
  25. package/dist/v2/commands.js +490 -0
  26. package/dist/v2/data.d.ts +27 -0
  27. package/dist/v2/data.js +103 -0
  28. package/dist/v2/index.d.ts +4 -0
  29. package/dist/v2/index.js +163 -0
  30. package/dist/v2/sidebar.d.ts +6 -0
  31. package/dist/v2/sidebar.js +36 -0
  32. package/dist/v2/status.d.ts +14 -0
  33. package/dist/v2/status.js +83 -0
  34. package/dist/v2/theme.d.ts +8 -0
  35. package/dist/v2/theme.js +16 -0
  36. package/dist/v2/types.d.ts +219 -0
  37. package/dist/v2/types.js +6 -0
  38. package/dist/v2/v2-panel-api.d.ts +8 -0
  39. package/dist/v2/v2-panel-api.js +176 -0
  40. package/dist/v2.js +2941 -0
  41. package/package.json +72 -67
  42. package/src/_version.ts +1 -1
  43. package/src/balance-providers.ts +153 -153
  44. package/src/core/color.ts +108 -0
  45. package/src/core/currency.ts +46 -0
  46. package/src/core/estimate.ts +36 -0
  47. package/src/core/format.ts +81 -0
  48. package/src/core/index.ts +5 -0
  49. package/src/core/types.ts +17 -0
  50. package/src/i18n.ts +380 -380
  51. package/src/index.tsx +1035 -2120
  52. package/src/panel/TokenCachePanel.tsx +776 -0
  53. package/src/panel/panel-api.ts +104 -0
  54. package/src/server.ts +10 -10
  55. package/src/v2/commands.ts +471 -0
  56. package/src/v2/data.ts +112 -0
  57. package/src/v2/index.tsx +184 -0
  58. package/src/v2/sidebar.tsx +69 -0
  59. package/src/v2/status.tsx +96 -0
  60. package/src/v2/theme.ts +19 -0
  61. package/src/v2/types.ts +159 -0
  62. package/src/v2/v2-panel-api.ts +177 -0
@@ -0,0 +1,81 @@
1
+ /** CJK characters occupy 2 terminal columns; padEnd/padStart count
2
+ * string length (=1 per char), which breaks alignment with mixed text. */
3
+
4
+ export function charColumns(c: string): number {
5
+ const code = c.codePointAt(0) ?? 0
6
+ if (code < 0x20) return 0 // control
7
+ if (code < 0x7F) return 1 // ASCII
8
+ if (code < 0xA0) return 0 // C1 controls
9
+ // East-Asian wide / fullwidth ranges
10
+ if ((code >= 0x1100 && code <= 0x115F) || // Hangul Jamo
11
+ (code >= 0x2E80 && code <= 0xA4CF) || // CJK Radicals … Yi
12
+ (code >= 0xAC00 && code <= 0xD7A3) || // Hangul
13
+ (code >= 0xF900 && code <= 0xFAFF) || // CJK Compat
14
+ (code >= 0xFE10 && code <= 0xFE6F) || // Vertical / Compat
15
+ (code >= 0xFF01 && code <= 0xFF60) || // Fullwidth
16
+ (code >= 0xFFE0 && code <= 0xFFE6) || // Fullwidth signs
17
+ (code >= 0x1F300 && code <= 0x1F64F) || // Misc Symbols (emoji)
18
+ (code >= 0x20000 && code <= 0x3FFFD)) // SIP / TIP
19
+ return 2
20
+ return 1
21
+ }
22
+
23
+ export function visualWidth(s: string): number {
24
+ let w = 0; for (const c of s) w += charColumns(c); return w
25
+ }
26
+
27
+ export function visualPadEnd(s: string, cols: number): string {
28
+ const pad = cols - visualWidth(s)
29
+ return pad > 0 ? s + " ".repeat(pad) : s
30
+ }
31
+
32
+ /** Truncate `s` to fit within `maxCols` visual columns, appending "…" when cut. */
33
+ export function truncateVisual(s: string, maxCols: number): string {
34
+ if (visualWidth(s) <= maxCols) return s
35
+ let result = "", w = 0
36
+ for (const c of s) {
37
+ const cw = charColumns(c)
38
+ if (w + cw > maxCols - 1) { result += "\u2026"; break }
39
+ result += c; w += cw
40
+ }
41
+ return result
42
+ }
43
+
44
+ export function progressBar(percent: number, width: number): string {
45
+ const clamped = Math.max(0, Math.min(100, percent))
46
+ const filled = Math.round((clamped / 100) * width)
47
+ const empty = Math.max(0, width - filled)
48
+ return "\u2588".repeat(filled) + "\u2591".repeat(empty)
49
+ }
50
+
51
+ export function fmt(n: number): string {
52
+ if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + "M"
53
+ if (n >= 10_000) return (n / 1_000).toFixed(1) + "K"
54
+ return n.toLocaleString("en-US")
55
+ }
56
+
57
+ export function num(v: unknown): number {
58
+ return typeof v === "number" && Number.isFinite(v) ? v : 0
59
+ }
60
+
61
+ export function fmtCost(n: number, symbol = "$", rate = 1): string {
62
+ const v = n * rate
63
+ if (v >= 1) return symbol + v.toFixed(2)
64
+ if (v >= 0.01) return symbol + v.toFixed(3)
65
+ return symbol + v.toFixed(4)
66
+ }
67
+
68
+ /** 紧凑数字缩写(底部状态栏用):1234 → "1.2K",1234567 → "1.2M"。 */
69
+ export function fmtCompact(n: number): string {
70
+ if (n >= 1e6) return (n / 1e6).toFixed(1) + "M"
71
+ if (n >= 1e3) return (n / 1e3).toFixed(1) + "K"
72
+ return String(Math.round(n))
73
+ }
74
+
75
+ /** 余额数值格式化:≥1 或 0 显示固定 2 位小数;小额(<1)保留精度(最多 6 位),避免抹成 0.00。 */
76
+ export function formatBalanceAmount(total: string): string {
77
+ const n = parseFloat(total)
78
+ if (!Number.isFinite(n)) return total
79
+ if (n === 0 || n >= 1) return n.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })
80
+ return n.toLocaleString("en-US", { maximumFractionDigits: 6 })
81
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./color"
2
+ export * from "./currency"
3
+ export * from "./estimate"
4
+ export * from "./format"
5
+ export * from "./types"
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Token distribution breakdown for a session round.
3
+ * Pure data model shared by V1/V2 shells.
4
+ */
5
+ export interface TokenDist {
6
+ system: number // UserMessage.system
7
+ user: number // user message text/file parts
8
+ agent: number // task tool input prompt/description (sub-agent delegation)
9
+ toolCall: number // ToolPart.input (actual tool params)
10
+ toolResult: number // ToolPart completed output / error
11
+ output: number // AssistantMessage.tokens.output (API exact, reasoning excluded)
12
+ reasoning: number // AssistantMessage.tokens.reasoning (API exact)
13
+ apiOutput: number // StepFinishPart.tokens.output (API exact, preferred)
14
+ apiInput: number // API exact total input context (input + cache read + cache write)
15
+ stepCost: number // last step-finish part cost (USD) in the current round
16
+ stepCount: number // step-finish parts count across the current round (parentID chain)
17
+ }