Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/tui/src/feature-plugins/sidebar/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { AssistantMessage } from "@opencode-ai/sdk/v2"
import type { TuiPlugin, TuiPluginApi } from "@opencode-ai/plugin/tui"
import type { BuiltinTuiPlugin } from "../builtins"
import { createMemo } from "solid-js"
import { useLocal } from "../../context/local"

const id = "internal:sidebar-context"

Expand All @@ -11,6 +12,7 @@ const money = new Intl.NumberFormat("en-US", {
})

function View(props: { api: TuiPluginApi; session_id: string }) {
const local = useLocal()
const theme = () => props.api.theme.current
const msg = createMemo(() => props.api.state.session.messages(props.session_id))
const session = createMemo(() => props.api.state.session.get(props.session_id))
Expand All @@ -27,7 +29,12 @@ function View(props: { api: TuiPluginApi; session_id: string }) {

const tokens =
last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write
const model = props.api.state.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
// Prefer the currently selected model so the limit reflects a mid-session
// model switch; fall back to the model of the last assistant message.
const selected = local.model.current()
const providerID = selected?.providerID ?? last.providerID
const modelID = selected?.modelID ?? last.modelID
const model = props.api.state.provider.find((item) => item.id === providerID)?.models[modelID]
return {
tokens,
percent: model?.limit.context ? Math.round((tokens / model.limit.context) * 100) : null,
Expand Down
Loading