opencode-brl-cost 0.1.0 → 0.1.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 (2) hide show
  1. package/index.tsx +7 -36
  2. package/package.json +2 -2
package/index.tsx CHANGED
@@ -1,6 +1,5 @@
1
- /** @jsxImportSource @opentui/solid */
2
- import { createSignal } from "solid-js"
3
1
  import type { TuiPlugin, TuiPluginModule } from "@opencode-ai/plugin/tui"
2
+ import type { Session } from "@opencode-ai/sdk/v2"
4
3
 
5
4
  const BRL_PER_USD = 5
6
5
 
@@ -13,9 +12,6 @@ const formatBRL = (usd: number) => {
13
12
  }
14
13
 
15
14
  const tui: TuiPlugin = async (api) => {
16
- const [cost, setCost] = createSignal<string | undefined>(undefined)
17
- const [busy, setBusy] = createSignal(false)
18
-
19
15
  const currentSessionID = (): string | undefined => {
20
16
  const route = api.route.current
21
17
  return route.name === "session" && typeof route.params?.sessionID === "string"
@@ -23,45 +19,20 @@ const tui: TuiPlugin = async (api) => {
23
19
  : undefined
24
20
  }
25
21
 
26
- const refresh = async () => {
22
+ const currentCostBRL = (): string => {
27
23
  const sessionID = currentSessionID()
28
- if (!sessionID) {
29
- setCost(undefined)
30
- return
31
- }
32
-
33
- // Prefer the live SDK session (server truth, has cost); fall back to the store.
34
- let usd: number | undefined
35
- try {
36
- const res = await api.client.session.get({ sessionID }, { throwOnError: true })
37
- usd = res.data?.cost
38
- } catch {
39
- const session = api.state.session.get(sessionID)
40
- usd = session?.cost
41
- }
42
- setCost(typeof usd === "number" ? formatBRL(usd) : undefined)
24
+ if (!sessionID) return formatBRL(0)
25
+ const session = api.state.session.get(sessionID) as Session | undefined
26
+ return formatBRL(typeof session?.cost === "number" ? session.cost : 0)
43
27
  }
44
28
 
45
- void refresh()
46
-
47
- api.event.on("session.updated", (event) => {
48
- if (event.properties.sessionID === currentSessionID()) void refresh()
49
- })
50
- api.event.on("session.idle", (event) => {
51
- if (event.properties.sessionID === currentSessionID()) void refresh()
52
- })
53
- api.event.on("tui.session.select", (event) => {
54
- if (event.properties.sessionID === currentSessionID()) void refresh()
55
- })
56
-
57
29
  api.slots.register({
58
30
  slots: {
59
31
  app_bottom(ctx) {
60
32
  const theme = ctx.theme.current
61
- const value = cost() ?? formatBRL(0)
62
33
  return (
63
- <box flexDirection="row" justifyContent="flex-end" paddingRight={2} gap={1}>
64
- <text fg={theme.textMuted}>{value}</text>
34
+ <box flexDirection="row" justifyContent="flex-end" paddingRight={2}>
35
+ <text fg={theme.textMuted}>{currentCostBRL()}</text>
65
36
  </box>
66
37
  )
67
38
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-brl-cost",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "OpenCode TUI plugin that shows the session cost in Brazilian Reais (R$)",
5
5
  "type": "module",
6
6
  "main": "./index.tsx",
@@ -30,4 +30,4 @@
30
30
  "solid-js": "^1.8.0",
31
31
  "typescript": "5.8.2"
32
32
  }
33
- }
33
+ }