opencode-cache-hit 0.1.0 → 0.2.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.
@@ -10,14 +10,14 @@ import {
10
10
  import { computeHitBarWidth, visualWidth } from "./tui-panel/layout.ts"
11
11
  import { buildPanelPalette, type PanelPalette } from "./tui-panel/palette.ts"
12
12
  import type { PanelLayout } from "./tui-panel/use-panel-layout.ts"
13
- import type { AssistantMessage, SessionSnapshot, SubAgentSummary } from "./types.ts"
13
+ import type { AssistantMessage, ProviderInfo, SessionSnapshot, SubAgentSummary } from "./types.ts"
14
14
  import {
15
15
  cacheHitRatio,
16
- combinedCacheHitRatio,
17
16
  computePerCallHitTrend,
18
17
  mainSessionHasStats,
19
18
  shortModelName,
20
19
  } from "./stats.ts"
20
+ import { computePricing, type PricingInfo } from "./pricing.ts"
21
21
 
22
22
  function activeLang(display: DisplayConfig) {
23
23
  return display.lang === "auto" ? resolveLang("auto") : display.lang
@@ -35,6 +35,7 @@ export function useCacheHitMetrics(props: {
35
35
  messages: Accessor<AssistantMessage[]>
36
36
  main: Accessor<SessionSnapshot>
37
37
  subAgents: Accessor<SubAgentSummary[]>
38
+ providers: Accessor<ReadonlyArray<ProviderInfo>>
38
39
  layout: PanelLayout
39
40
  }) {
40
41
  const pal = createMemo(() => buildPanelPalette(props.theme()))
@@ -44,12 +45,10 @@ export function useCacheHitMetrics(props: {
44
45
  const main = createMemo(() => props.main())
45
46
  const perCall = createMemo(() => computePerCallHitTrend(props.messages()))
46
47
  const sessionRatio = createMemo(() => cacheHitRatio(main().cacheRead, main().input))
47
- const combinedRatio = createMemo(() => combinedCacheHitRatio(main(), subs()))
48
48
 
49
- const showCombinedHit = createMemo(() => {
50
- if (subs().length === 0) return false
51
- return Math.abs(combinedRatio() - sessionRatio()) >= 0.0005
52
- })
49
+ const pricing = createMemo<PricingInfo>(() =>
50
+ computePricing(props.providers(), main().providerID, main().model, main().cacheRead),
51
+ )
53
52
 
54
53
  const mainHasStats = createMemo(() => mainSessionHasStats(main()))
55
54
  const hasData = createMemo(() => mainHasStats() || subs().length > 0)
@@ -85,9 +84,9 @@ export function useCacheHitMetrics(props: {
85
84
  main,
86
85
  mainHasStats,
87
86
  perCall,
87
+ pricing,
88
88
  sessionPct: createMemo(() => formatRatioAsPercent(sessionRatio())),
89
- combinedPct: createMemo(() => formatRatioAsPercent(combinedRatio())),
90
- showCombinedHit,
89
+
91
90
  hasData,
92
91
  trendLabel,
93
92
  bar,
package/src/widget.tsx CHANGED
@@ -1,10 +1,11 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
2
  import { createMemo, createSignal, Show, type Accessor } from "solid-js"
3
- import type { DisplayConfig } from "./plugin-config.ts"
4
- import type { AssistantMessage, SessionSnapshot, SubAgentSummary } from "./types.ts"
3
+ import type { DisplayConfig, CacheTTLConfig } from "./plugin-config.ts"
4
+ import type { AssistantMessage, ProviderInfo, SessionSnapshot, SubAgentSummary } from "./types.ts"
5
5
  import { PLUGIN_VERSION } from "./version.ts"
6
6
  import { AgentsView } from "./agents-view.tsx"
7
7
  import { MainSessionView } from "./main-session-view.tsx"
8
+
8
9
  import { useCacheHitMetrics } from "./use-cache-hit-metrics.ts"
9
10
  import {
10
11
  createPanelLayout,
@@ -22,10 +23,13 @@ export function CacheHitSidebar(props: {
22
23
  sessionId: Accessor<string>
23
24
  theme: Record<string, unknown>
24
25
  display: DisplayConfig
26
+ cacheTTL: CacheTTLConfig
25
27
  messages: Accessor<AssistantMessage[]>
26
28
  main: Accessor<SessionSnapshot>
27
29
  subAgents: Accessor<SubAgentSummary[]>
30
+ providers: Accessor<ReadonlyArray<ProviderInfo>>
28
31
  formatCost: (amount: number) => string
32
+ formatRate: (perMillion: number) => string
29
33
  }) {
30
34
  const [panelOpen, setPanelOpen] = createSignal(true)
31
35
  const detail = createSectionFold(true)
@@ -41,6 +45,7 @@ export function CacheHitSidebar(props: {
41
45
  messages: props.messages,
42
46
  main: props.main,
43
47
  subAgents: props.subAgents,
48
+ providers: props.providers,
44
49
  layout,
45
50
  })
46
51
 
@@ -96,6 +101,9 @@ export function CacheHitSidebar(props: {
96
101
  detail={detail}
97
102
  model={model}
98
103
  formatCost={props.formatCost}
104
+ formatRate={props.formatRate}
105
+ cacheTTL={props.cacheTTL}
106
+ messages={props.messages}
99
107
  />
100
108
  <Show when={m.subs().length > 0}>
101
109
  <TuiSection
@@ -106,7 +114,7 @@ export function CacheHitSidebar(props: {
106
114
  suffix={agentsSuffix()}
107
115
  onToggle={agents.toggle}
108
116
  >
109
- <AgentsView m={m} layout={layout} formatCost={props.formatCost} />
117
+ <AgentsView m={m} layout={layout} providers={props.providers()} formatCost={props.formatCost} />
110
118
  </TuiSection>
111
119
  </Show>
112
120
  </Show>