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,119 @@
1
+ import type { TuiThemeCurrent } from "@opencode-ai/plugin/tui";
2
+ import type { BalanceEntry } from "../balance-providers";
3
+ import type { LangCode } from "../i18n";
4
+ /** 会话信息(面板消费的字段;SDK Session 类型过严,用宽松接口) */
5
+ export interface PanelSession {
6
+ id: string;
7
+ title?: string;
8
+ agent?: string;
9
+ model?: {
10
+ providerID?: string;
11
+ id?: string;
12
+ };
13
+ tokens?: {
14
+ input?: number;
15
+ output?: number;
16
+ reasoning?: number;
17
+ cache?: {
18
+ read?: number;
19
+ write?: number;
20
+ };
21
+ };
22
+ cost?: number;
23
+ [key: string]: unknown;
24
+ }
25
+ /**
26
+ * Panel API 契约:TokenCachePanel 消费的宿主 API 子集。
27
+ * V1(TuiPluginApi)天然满足;V2(opencode2 context)由 v2-panel-api 适配实现。
28
+ */
29
+ export interface PanelApi {
30
+ kv: {
31
+ ready: boolean;
32
+ get<T>(key: string, fallback?: T): T | undefined;
33
+ set(key: string, value: unknown): void | Promise<void>;
34
+ };
35
+ state: {
36
+ session: {
37
+ get(id: string): PanelSession | undefined;
38
+ /** V1 返回 sdk/v2 的 Message、V2 返回 SessionMessageInfo——统一放宽 */
39
+ messages(id: string): readonly any[];
40
+ };
41
+ provider: readonly Record<string, any>[];
42
+ config: any;
43
+ part(messageID: string): readonly any[];
44
+ path: {
45
+ directory: string;
46
+ };
47
+ };
48
+ event: {
49
+ on(type: string, handler: (event: unknown) => void): () => void;
50
+ };
51
+ renderer: {
52
+ terminalWidth: number;
53
+ };
54
+ keys: {
55
+ formatBindings(binding: unknown): string | undefined;
56
+ };
57
+ tuiConfig: {
58
+ keybinds: {
59
+ get(command: string): unknown;
60
+ };
61
+ };
62
+ }
63
+ export interface BalanceState {
64
+ status: "idle" | "loading" | "ok" | "error";
65
+ data: BalanceEntry[] | null;
66
+ lastFetch: number;
67
+ error?: string;
68
+ key?: string;
69
+ }
70
+ /** Signals shared between the TUI component and slash commands.
71
+ * Created in the `tui` function scope so they do not survive module reload —
72
+ * the component re-creates them on mount and restores user config from kv. */
73
+ export interface PanelSignals {
74
+ currencySymbol: () => string;
75
+ setCurrencySymbol: (v: string) => void;
76
+ exchangeRate: () => number;
77
+ setExchangeRate: (v: number) => void;
78
+ langCode: () => LangCode;
79
+ setLangCode: (v: LangCode) => void;
80
+ sectionDetail: () => boolean;
81
+ setSectionDetail: (v: boolean) => void;
82
+ sectionModel: () => boolean;
83
+ setSectionModel: (v: boolean) => void;
84
+ sectionDist: () => boolean;
85
+ setSectionDist: (v: boolean) => void;
86
+ sectionSkills: () => boolean;
87
+ setSectionSkills: (v: boolean) => void;
88
+ sectionBalance: () => boolean;
89
+ setSectionBalance: (v: boolean) => void;
90
+ /** Bottom status bar (prompt hint line) visibility. */
91
+ sectionBottom: () => boolean;
92
+ setSectionBottom: (v: boolean) => void;
93
+ /** Increment to force a balance re-fetch. */
94
+ balanceRefresh: () => number;
95
+ setBalanceRefresh: (v: number) => void;
96
+ /** Currently selected balance provider id (e.g. "deepseek"). */
97
+ balanceProviderId: () => string;
98
+ setBalanceProviderId: (v: string) => void;
99
+ /** Auto-switch to the session's provider for balance display. Manual switch disables it. */
100
+ autoBalance: () => boolean;
101
+ setAutoBalance: (v: boolean) => void;
102
+ /** True when the session's provider has no balance adapter (auto mode). Suppresses balance polling. */
103
+ balanceUnsupported: () => boolean;
104
+ setBalanceUnsupported: (v: boolean) => void;
105
+ /** Shared balance query state — single source of truth for sidebar and bottom bar. */
106
+ balanceState: () => BalanceState;
107
+ /** Preferred currency code for balance display (CNY / USD / …). Empty = first entry. */
108
+ balanceCurrency: () => string;
109
+ setBalanceCurrency: (v: string) => void;
110
+ borderVisible: () => boolean;
111
+ setBorderVisible: (v: boolean) => void;
112
+ /** When set, the panel renders stats for this session instead of the main one. */
113
+ overrideSessionId: () => string | undefined;
114
+ setOverrideSessionId: (v: string | undefined) => void;
115
+ /** True while our sidebar panel is mounted — host sidebar is visible (occupies 42 cols). */
116
+ sidebarVisible: () => boolean;
117
+ setSidebarVisible: (v: boolean) => void;
118
+ }
119
+ export type { TuiThemeCurrent };
@@ -0,0 +1 @@
1
+ export {};