@cortexkit/opencode-openai-auth 1.8.4 → 1.8.5

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 (47) hide show
  1. package/dist/bin.js +2 -2
  2. package/dist/{codex-request-C78nXs79.d.ts → codex-request-By530v1D.d.ts} +2 -1
  3. package/dist/{index-hvmj07f7.js → index-8x42xzxb.js} +20 -20
  4. package/dist/{index-t8248wa4.js → index-a7xv52hy.js} +1 -1
  5. package/dist/{index-k7zb6wa7.js → index-g5hv0tda.js} +1 -1
  6. package/dist/{index-pg5c6by3.js → index-jh90fx7y.js} +1 -1
  7. package/dist/index-n12zjwh9.js +8 -0
  8. package/dist/{index-e7gekawr.js → index-rmc6hwg6.js} +1 -1
  9. package/dist/{index-nsdjapq1.js → index-zah8t2d2.js} +1 -1
  10. package/dist/{index-1htk005d.js → index-zf649dj2.js} +1 -1
  11. package/dist/index-zne9tzy9.js +91 -0
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/rpc/port-file.js +1 -1
  15. package/dist/rpc/protocol.js +1 -1
  16. package/dist/rpc/rpc-client.js +1 -1
  17. package/dist/sidebar-state.js +1 -1
  18. package/dist/tui-preferences.js +1 -1
  19. package/dist/tui.d.ts +1 -20
  20. package/dist/v2/server.d.ts +1 -1
  21. package/dist/v2/server.js +2 -2
  22. package/package.json +2 -2
  23. package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +20 -6
  24. package/src/tui-compiled/raw/shared/169b2b4bf30909bc-consumer.js +25 -0
  25. package/src/tui-compiled/raw/shared/30f5bc480f31f51c-roster.js +1 -1
  26. package/src/tui-compiled/raw/shared/352d228be2832bd4-hub.js +55 -5
  27. package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +1 -1
  28. package/src/tui-compiled/raw/shared/549daf371622c304-index.tsx +497 -0
  29. package/src/tui-compiled/raw/shared/7c97ac0cec074ae7-format.js +208 -0
  30. package/src/tui-compiled/raw/shared/b4ad0d49429f0096-map.js +98 -0
  31. package/src/tui-compiled/raw/shared/b717cdcce3966455-projection.js +90 -0
  32. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +3 -1
  33. package/src/tui-compiled/raw/tui.tsx +233 -634
  34. package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +20 -6
  35. package/src/tui-compiled/runtime/shared/169b2b4bf30909bc-consumer.js +25 -0
  36. package/src/tui-compiled/runtime/shared/30f5bc480f31f51c-roster.js +1 -1
  37. package/src/tui-compiled/runtime/shared/352d228be2832bd4-hub.js +55 -5
  38. package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +1 -1
  39. package/src/tui-compiled/runtime/shared/549daf371622c304-index.js +550 -0
  40. package/src/tui-compiled/runtime/shared/7c97ac0cec074ae7-format.js +208 -0
  41. package/src/tui-compiled/runtime/shared/b4ad0d49429f0096-map.js +98 -0
  42. package/src/tui-compiled/runtime/shared/b717cdcce3966455-projection.js +90 -0
  43. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +3 -1
  44. package/src/tui-compiled/runtime/tui.js +258 -879
  45. package/dist/index-a5h82jha.js +0 -8
  46. package/dist/index-kemp2vh4.js +0 -91
  47. /package/dist/{index-hnmbhgk4.js → index-95s2mw9w.js} +0 -0
@@ -8,6 +8,15 @@ import {
8
8
  quotaTextParts,
9
9
  quotaWindowParts,
10
10
  } from "./shared/d5a8f1061ee2f114-index.js"
11
+ import {
12
+ type AccountView,
13
+ type Tone as FrameTone,
14
+ type PaceView,
15
+ SidebarFrame,
16
+ SidebarSection,
17
+ SidebarStatRow,
18
+ SidebarTextRow,
19
+ } from "./shared/549daf371622c304-index.tsx"
11
20
  import type { Plugin } from "@opencode/plugin/tui"
12
21
  import type {
13
22
  TuiPlugin,
@@ -15,15 +24,7 @@ import type {
15
24
  TuiPluginModule,
16
25
  } from "@opencode-ai/plugin/tui"
17
26
  import { RGBA } from "@opentui/core"
18
- import {
19
- createEffect,
20
- createMemo,
21
- createSignal,
22
- For,
23
- Index,
24
- onCleanup,
25
- Show,
26
- } from "solid-js"
27
+ import { createEffect, createSignal, For, onCleanup, Show } from "solid-js"
27
28
  import { createLogger } from "./logger.js"
28
29
  import { type ApplyRequest, isNotifyPayload } from "./rpc/protocol.js"
29
30
  import { createRpcClient, DEFAULT_RPC_TIMEOUT_MS } from "./rpc/rpc-client.js"
@@ -32,7 +33,6 @@ import {
32
33
  type AccountQuota,
33
34
  accountCreditsText,
34
35
  accountServesOnCredits,
35
- type CollapsedAccountLine,
36
36
  computeQuotaPacing,
37
37
  DEFAULT_SIDEBAR_STATE,
38
38
  displayWidth,
@@ -171,80 +171,46 @@ export function sidebarThemeFromHost(theme: SidebarHostTheme): ThemeCurrent {
171
171
  }
172
172
  }
173
173
 
174
- // Tone -> theme token. Theme tokens only — never hardcoded colors. Fallbacks
175
- // resolve to other theme tokens so the sidebar always tracks the active theme.
176
- function toneColor(theme: ThemeCurrent, tone: Tone): ThemeColor {
174
+ function usageTone(usedPct: number, appearance: AppearancePrefs): Tone {
175
+ if (usedPct < appearance.warnThreshold) return 'ok'
176
+ if (usedPct < appearance.errorThreshold) return 'warn'
177
+ return 'err'
178
+ }
179
+
180
+ function frameTone(tone: Tone): FrameTone {
177
181
  switch (tone) {
178
182
  case 'ok':
179
- return theme.success ?? theme.accent
183
+ return 'success'
180
184
  case 'warn':
181
- return theme.warning ?? theme.accent
185
+ return 'warning'
182
186
  case 'err':
183
- return theme.error ?? theme.accent
187
+ return 'error'
184
188
  case 'muted':
185
- return theme.textMuted ?? theme.text
186
- case 'accent':
187
- return theme.accent ?? theme.text
189
+ return 'textMuted'
188
190
  default:
189
- return theme.text
191
+ return tone
190
192
  }
191
193
  }
192
194
 
193
- function usageTone(usedPct: number, appearance: AppearancePrefs): Tone {
194
- if (usedPct < appearance.warnThreshold) return 'ok'
195
- if (usedPct < appearance.errorThreshold) return 'warn'
196
- return 'err'
197
- }
198
-
199
- interface BarSegment {
200
- text: string
201
- tone: Tone
202
- }
203
-
204
- const PACE_RESERVE_CHAR = '\u2592'
205
- const PACE_DEFICIT_CHAR = '\u2593'
206
-
207
- // Variant C pacing bar: normal fill up to min(used, pace), then a pace
208
- // segment covering the gap — headroom being banked (reserve, ok tone) or the
209
- // overshoot itself (deficit, err tone) — then empty cells. Without pacing the
210
- // bar renders as a single fill+empty pair, identical to the pre-pacing look.
211
- // Empty text nodes still occupy a phantom cell in the opentui flex row, so
212
- // zero-length segments are dropped from every return path (plain and pacing).
213
- function quotaBarSegments(
214
- usedPct: number,
215
- appearance: AppearancePrefs,
216
- pacing: QuotaPacing | null,
217
- ): BarSegment[] {
218
- const width = appearance.barWidth
219
- const cells = (pct: number) =>
220
- Math.max(0, Math.min(Math.round((pct / 100) * width), width))
221
- const usedCells = cells(usedPct)
222
- const fillTone = usageTone(usedPct, appearance)
223
- const plain: BarSegment[] = [
224
- { text: appearance.barFilledChar.repeat(usedCells), tone: fillTone },
225
- {
226
- text: appearance.barEmptyChar.repeat(width - usedCells),
227
- tone: fillTone,
195
+ function paceView(pacing: QuotaPacing | null): PaceView | undefined {
196
+ if (!pacing) return undefined
197
+ const pct = Math.round(Math.abs(pacing.deltaPercent))
198
+ const text =
199
+ pacing.state === 'on-pace'
200
+ ? ''
201
+ : pacing.state === 'reserve'
202
+ ? `reserve ${pct}% \u00b7 lasts`
203
+ : pacing.runsOutAt
204
+ ? `deficit ${pct}% \u00b7 out in ${formatResetIn(pacing.runsOutAt)}`
205
+ : `deficit ${pct}% \u00b7 lasts`
206
+ return {
207
+ text,
208
+ tone: pacing.state === 'deficit' ? 'warning' : 'textMuted',
209
+ overlay: {
210
+ kind: pacing.deltaPercent > 0 ? 'deficit' : 'reserve',
211
+ percent: pacing.pacePercent,
228
212
  },
229
- ]
230
- if (!pacing) return plain.filter((segment) => segment.text.length > 0)
231
- const paceCells = cells(pacing.pacePercent)
232
- const lo = Math.min(usedCells, paceCells)
233
- const hi = Math.max(usedCells, paceCells)
234
- if (hi === lo) return plain.filter((segment) => segment.text.length > 0)
235
- const overspent = usedCells > paceCells
236
- return (
237
- [
238
- { text: appearance.barFilledChar.repeat(lo), tone: fillTone },
239
- {
240
- text: (overspent ? PACE_DEFICIT_CHAR : PACE_RESERVE_CHAR).repeat(
241
- hi - lo,
242
- ),
243
- tone: overspent ? 'err' : 'ok',
244
- },
245
- { text: appearance.barEmptyChar.repeat(width - hi), tone: fillTone },
246
- ] as BarSegment[]
247
- ).filter((segment) => segment.text.length > 0)
213
+ }
248
214
  }
249
215
 
250
216
  export function formatResetIn(resetsAt: string | undefined): string {
@@ -275,67 +241,6 @@ function formatUntil(until: number | undefined): string {
275
241
  return rm > 0 ? `${hrs}h${rm}m` : `${hrs}h`
276
242
  }
277
243
 
278
- // --- Reusable components (aft-style) ---------------------------------------
279
-
280
- function SectionHeader(props: {
281
- theme: ThemeCurrent
282
- title: string
283
- marginTop?: number
284
- }) {
285
- return (
286
- <box width='100%' marginTop={props.marginTop ?? 1}>
287
- <text fg={props.theme.text}>
288
- <b>{props.title}</b>
289
- </text>
290
- </box>
291
- )
292
- }
293
-
294
- // A muted label left and a value right (route, health, killswitch). Like the
295
- // quota rows it stays on one line: it measures its own width and, when both do
296
- // not fit, cuts only the value (with …), keeping one blank cell after the
297
- // label.
298
- function StatRow(props: {
299
- theme: ThemeCurrent
300
- label: string
301
- value: string
302
- tone?: Tone
303
- }) {
304
- const [width, setWidth] = createSignal(0)
305
- let row: { width: number } | undefined
306
- const value = () => {
307
- const columns = width()
308
- if (columns <= 0) return props.value
309
- return fitCollapsedLabel(
310
- props.value,
311
- columns - displayWidth(props.label) - 1,
312
- )
313
- }
314
- return (
315
- <box
316
- ref={(element: { width: number }) => {
317
- row = element
318
- }}
319
- onSizeChange={() => setWidth(row?.width ?? 0)}
320
- width='100%'
321
- flexDirection='row'
322
- justifyContent='space-between'
323
- columnGap={1}
324
- >
325
- <text fg={props.theme.textMuted} wrapMode='none' flexShrink={0}>
326
- {props.label}
327
- </text>
328
- <text
329
- fg={toneColor(props.theme, props.tone ?? 'text')}
330
- wrapMode='none'
331
- flexShrink={1}
332
- >
333
- <b>{value()}</b>
334
- </text>
335
- </box>
336
- )
337
- }
338
-
339
244
  // One of an account's own rows under its quota bars (budget amounts, prepaid
340
245
  // credits, reset credits): muted label left, value right. Like the quota rows
341
246
  // it stays on one line: it measures its own width and, when both do not fit,
@@ -375,76 +280,6 @@ function AccountMetaRow(props: {
375
280
  )
376
281
  }
377
282
 
378
- // One account in the collapsed view: label left; narrow quota text and the
379
- // status dot right (red ⊘ when killed). The session's account keeps the
380
- // usage tone; other accounts, and any account whose reading is stale, are
381
- // drawn muted. The row measures its own width so only the label is cut (with
382
- // …) when the line does not fit; the quota text is never cut.
383
- function CollapsedAccountRow(props: {
384
- theme: ThemeCurrent
385
- line: CollapsedAccountLine
386
- tone: Tone
387
- }) {
388
- const [width, setWidth] = createSignal(0)
389
- let row: { width: number } | undefined
390
- const dim = () => props.line.stale || !props.line.active
391
- const label = () => {
392
- const columns = width()
393
- if (columns <= 0) return props.line.name
394
- // The value side is the text plus ` ●`, or a lone `—`; one column
395
- // separates it from the label.
396
- const value =
397
- props.line.text === null ? 1 : displayWidth(props.line.text) + 2
398
- return fitCollapsedLabel(props.line.name, columns - value - 1)
399
- }
400
- return (
401
- <box
402
- ref={(element: { width: number }) => {
403
- row = element
404
- }}
405
- onSizeChange={() => setWidth(row?.width ?? 0)}
406
- width='100%'
407
- flexDirection='row'
408
- justifyContent='space-between'
409
- >
410
- <text
411
- fg={toneColor(props.theme, dim() ? 'muted' : 'text')}
412
- wrapMode='none'
413
- flexShrink={1}
414
- >
415
- {label()}
416
- </text>
417
- <Show
418
- when={props.line.text !== null}
419
- fallback={<text fg={props.theme.textMuted}>{'\u2014'}</text>}
420
- >
421
- <box flexDirection='row' flexShrink={0}>
422
- <Show
423
- when={!dim()}
424
- fallback={
425
- <text fg={toneColor(props.theme, 'muted')}>
426
- {props.line.text}
427
- </text>
428
- }
429
- >
430
- <text fg={toneColor(props.theme, props.tone)}>
431
- <b>{props.line.text}</b>
432
- </text>
433
- </Show>
434
- <text
435
- fg={toneColor(
436
- props.theme,
437
- props.line.killed ? 'err' : dim() ? 'muted' : props.tone,
438
- )}
439
- >
440
- {props.line.killed ? ' \u2298' : ' \u25cf'}
441
- </text>
442
- </box>
443
- </Show>
444
- </box>
445
- )
446
- }
447
-
448
283
  export interface QuotaDisplayRow {
449
284
  key: 'primary' | 'secondary' | 'spendControl'
450
285
  label: string
@@ -650,266 +485,6 @@ export function getAccountMetadataRows(
650
485
  }
651
486
 
652
487
  /** The fewest cells a shortened quota bar keeps; below this it is dropped. */
653
- const MIN_QUOTA_BAR_CELLS = 3
654
-
655
- export interface QuotaRowFit {
656
- /** Cells of usage bar to draw; 0 draws no bar. */
657
- barCells: number
658
- showReset: boolean
659
- }
660
-
661
- /**
662
- * How an expanded quota row fits on one line `columns` cells wide. The row is
663
- * the padded label, the bar, the " N% left" figure and, at the right edge, the
664
- * reset time. When it does not fit, the reset time goes first, then the bar
665
- * shrinks (to no fewer than MIN_QUOTA_BAR_CELLS cells, else it is dropped).
666
- * The label and the figure are never cut. `columns` of 0 means the row has not
667
- * been measured yet, and everything is drawn.
668
- */
669
- export function fitQuotaRow(input: {
670
- columns: number
671
- label: string
672
- barWidth: number
673
- figure: string
674
- resetText?: string
675
- }): QuotaRowFit {
676
- const { columns, barWidth } = input
677
- const reset = input.resetText ? displayWidth(input.resetText) : 0
678
- if (columns <= 0) return { barCells: barWidth, showReset: reset > 0 }
679
- const fixed = displayWidth(input.label) + displayWidth(input.figure)
680
- // The reset sits at the right edge with at least one blank cell before it,
681
- // so it never runs into the figure.
682
- if (reset > 0 && fixed + barWidth + 1 + reset <= columns)
683
- return { barCells: barWidth, showReset: true }
684
- const room = columns - fixed
685
- if (room >= barWidth) return { barCells: barWidth, showReset: false }
686
- return {
687
- barCells: room >= MIN_QUOTA_BAR_CELLS ? room : 0,
688
- showReset: false,
689
- }
690
- }
691
-
692
- // Quota window row: muted label left, tone-colored usage bar and shared quota text.
693
- // When pacing data is present, the bar
694
- // gains a pace segment and an off-pace window adds a muted subline with the
695
- // reserve/deficit delta and the projected runout.
696
- // The row measures its own width and never wraps: fitQuotaRow decides what is
697
- // left out when it is too narrow, and the pacing subline is cut with ….
698
- function QuotaRow(props: {
699
- theme: ThemeCurrent
700
- appearance: AppearancePrefs
701
- label: string
702
- labelWidth: number
703
- text: string
704
- resetText?: string
705
- window: { usedPercent: number; resetsAt?: string } | undefined
706
- pacing: QuotaPacing | null
707
- }) {
708
- const used = () => props.window?.usedPercent ?? 0
709
- const [columns, setColumns] = createSignal(0)
710
- let row: { width: number } | undefined
711
- const label = () => props.label.padEnd(props.labelWidth)
712
- const figure = () => ` ${props.text.slice(props.label.length + 1)}`
713
- const fit = () =>
714
- fitQuotaRow({
715
- columns: columns(),
716
- label: label(),
717
- barWidth: props.appearance.barWidth,
718
- figure: figure(),
719
- resetText: props.resetText,
720
- })
721
- // Memos, so a new measured width that leaves the fit unchanged (as the
722
- // first measurement usually does) does not rebuild the bar's text nodes:
723
- // rebuilt nodes are blank until the next frame is drawn.
724
- const barCells = createMemo(() => fit().barCells)
725
- const showReset = createMemo(() => fit().showReset)
726
- const fittedPaceLine = () => {
727
- const line = paceLine()
728
- if (line === null || columns() <= 0) return line
729
- // The subline is indented by the label column; cut it to the rest.
730
- return fitCollapsedLabel(line, columns() - props.labelWidth)
731
- }
732
- const paceLine = () => {
733
- const pacing = props.pacing
734
- if (!pacing || pacing.state === 'on-pace') return null
735
- const pct = Math.round(Math.abs(pacing.deltaPercent))
736
- if (pacing.state === 'reserve') return `reserve ${pct}% \u00b7 lasts`
737
- return pacing.runsOutAt
738
- ? `deficit ${pct}% \u00b7 out in ${formatResetIn(pacing.runsOutAt)}`
739
- : `deficit ${pct}% \u00b7 lasts`
740
- }
741
- return (
742
- <Show
743
- when={props.window}
744
- fallback={
745
- <box width='100%' flexDirection='row'>
746
- <text fg={props.theme.textMuted}>
747
- {props.label.padEnd(props.labelWidth)}
748
- </text>
749
- <text fg={props.theme.textMuted}>{'\u2014'}</text>
750
- </box>
751
- }
752
- >
753
- {/* Bars show usage; the adjacent figure shows quota left, as in the dialog. */}
754
- <box
755
- ref={(element: { width: number }) => {
756
- row = element
757
- }}
758
- onSizeChange={() => setColumns(row?.width ?? 0)}
759
- width='100%'
760
- flexDirection='row'
761
- justifyContent='space-between'
762
- >
763
- <box flexDirection='row' flexShrink={0}>
764
- <text fg={props.theme.textMuted} wrapMode='none'>
765
- {label()}
766
- </text>
767
- <For
768
- each={quotaBarSegments(
769
- used(),
770
- { ...props.appearance, barWidth: barCells() },
771
- props.pacing,
772
- )}
773
- >
774
- {(segment) => (
775
- <text fg={toneColor(props.theme, segment.tone)} wrapMode='none'>
776
- {segment.text}
777
- </text>
778
- )}
779
- </For>
780
- <text
781
- fg={toneColor(props.theme, usageTone(used(), props.appearance))}
782
- wrapMode='none'
783
- >
784
- {figure()}
785
- </text>
786
- </box>
787
- <Show when={showReset()}>
788
- <text fg={props.theme.textMuted} wrapMode='none' flexShrink={0}>
789
- {props.resetText}
790
- </text>
791
- </Show>
792
- </box>
793
- {/* Keyed, so a cut to a new width draws a new text node: on Bun 1.3
794
- an existing node kept drawing the text it was created with. */}
795
- <Show when={fittedPaceLine()} keyed>
796
- {(line) => (
797
- <box width='100%' flexDirection='row'>
798
- <text fg={props.theme.textMuted}>
799
- {''.padEnd(props.labelWidth)}
800
- </text>
801
- <text
802
- fg={toneColor(
803
- props.theme,
804
- props.pacing?.state === 'deficit' ? 'warn' : 'muted',
805
- )}
806
- wrapMode='none'
807
- >
808
- {line}
809
- </text>
810
- </box>
811
- )}
812
- </Show>
813
- </Show>
814
- )
815
- }
816
-
817
- // Account block: header row (name + status word) then per-window quota rows.
818
- // Pacing is computed here — per window, against the wall clock at render time
819
- // (re-evaluated on every state poll) — and disabled by passing false.
820
- function AccountBlock(props: {
821
- theme: ThemeCurrent
822
- appearance: AppearancePrefs
823
- name: string
824
- quota: AccountQuota | null
825
- killed: boolean
826
- vaultState?: string
827
- hostDisabled?: boolean
828
- active: boolean
829
- pacingEnabled: boolean
830
- labelWidth: number
831
- resetCredits?: number
832
- marginTop?: number
833
- }) {
834
- const statusWord = () =>
835
- props.killed ? 'blocked' : props.active ? 'active' : 'idle'
836
- const statusTone = (): Tone =>
837
- props.killed ? 'err' : props.active ? 'ok' : 'muted'
838
- const rows = () =>
839
- buildQuotaRowsForDisplay(
840
- props.quota,
841
- Date.now(),
842
- props.pacingEnabled,
843
- props.labelWidth,
844
- )
845
- return (
846
- <box width='100%' flexDirection='column' marginTop={props.marginTop ?? 0}>
847
- <box width='100%' flexDirection='row' justifyContent='space-between'>
848
- <text fg={props.theme.text}>
849
- <b>{props.name}</b>
850
- </text>
851
- <text fg={toneColor(props.theme, statusTone())}>
852
- <b>{statusWord()}</b>
853
- </text>
854
- </box>
855
- <Show when={props.vaultState}>
856
- <text fg={props.theme.warning}>{props.vaultState}</text>
857
- </Show>
858
- <Show when={props.hostDisabled}>
859
- <text fg={props.theme.textMuted}>off in /openai</text>
860
- </Show>
861
- <Show
862
- when={isQuotaLoaded(props.quota)}
863
- fallback={<text fg={props.theme.textMuted}>{'checking\u2026'}</text>}
864
- >
865
- <Show
866
- when={rows().length > 0}
867
- fallback={<text fg={props.theme.textMuted}>{'\u2014'}</text>}
868
- >
869
- <For each={rows()}>
870
- {(row) => (
871
- <QuotaRow
872
- theme={props.theme}
873
- appearance={props.appearance}
874
- label={row.label}
875
- labelWidth={row.labelWidth}
876
- text={row.text}
877
- resetText={row.resetText}
878
- window={row.window}
879
- pacing={row.pacing}
880
- />
881
- )}
882
- </For>
883
- </Show>
884
- </Show>
885
- <For
886
- each={quotaTextParts(sidebarQuotaProjection(props.quota, Date.now()), {
887
- now: Date.now(),
888
- form: 'compact',
889
- }).filter((part) => part.startsWith('checked '))}
890
- >
891
- {(age) => <text fg={props.theme.textMuted}>{age}</text>}
892
- </For>
893
- <For
894
- each={getAccountMetadataRows(
895
- props.resetCredits,
896
- props.quota?.spendControl,
897
- accountCreditsText(props.quota),
898
- props.active && accountServesOnCredits(props.quota, Date.now()),
899
- )}
900
- >
901
- {(row) => (
902
- <AccountMetaRow
903
- theme={props.theme}
904
- label={row.label}
905
- value={row.value}
906
- />
907
- )}
908
- </For>
909
- </box>
910
- )
911
- }
912
-
913
488
  // --- State plumbing ---------------------------------------------------------
914
489
 
915
490
  export async function readStateFromFile(): Promise<SidebarState> {
@@ -1093,10 +668,6 @@ function QuotaSidebar(props: {
1093
668
  ? vaultAccounts().length > 0
1094
669
  : state().main?.quota != null || enabledFallbacks().length > 0
1095
670
 
1096
- const headerLabel = () => {
1097
- const name = prefs().header.label
1098
- return !hasData() ? name : collapsed() ? `\u25b6 ${name}` : `\u25bc ${name}`
1099
- }
1100
671
  const sessionRouting = () =>
1101
672
  resolveSessionSidebarRouting(state(), props.sessionId)
1102
673
  const sessionState = (): SidebarState => ({
@@ -1149,183 +720,211 @@ function QuotaSidebar(props: {
1149
720
  const degraded = () =>
1150
721
  killedNames().length > 0 || quotaBackedOff() || refreshBackedOff()
1151
722
 
1152
- return (
1153
- <box
1154
- width='100%'
1155
- flexDirection='column'
1156
- paddingTop={1}
1157
- paddingBottom={1}
1158
- paddingLeft={1}
1159
- paddingRight={1}
1160
- >
1161
- {/* Header: ▼/▶ OPENAI badge (click to collapse) + version. Blocked
1162
- accounts show on their own rows, so the header does not change. */}
1163
- {/* biome-ignore lint/a11y/noStaticElementInteractions: opentui renders to a terminal, not the DOM — ARIA roles do not apply */}
1164
- <box
1165
- width='100%'
1166
- flexDirection='row'
1167
- justifyContent='space-between'
1168
- alignItems='center'
1169
- onMouseDown={() => {
1170
- if (hasData()) props.controller.toggleCollapsed()
1171
- }}
1172
- >
1173
- <box paddingLeft={1} paddingRight={1} backgroundColor={theme().accent}>
1174
- <text fg={theme().background}>
1175
- <b>{headerLabel()}</b>
1176
- </text>
1177
- </box>
1178
- <Show when={prefs().header.showVersion && PLUGIN_VERSION !== ''}>
1179
- <text fg={theme().textMuted}>{`v${PLUGIN_VERSION}`}</text>
1180
- </Show>
1181
- </box>
1182
-
1183
- {/* Collapsed: one line per account, narrow quota text + dot (red ⊘ when killed) */}
1184
- <Show when={collapsed() && hasData()}>
1185
- <Index each={collapsedLines()}>
1186
- {(line) => (
1187
- <CollapsedAccountRow
1188
- theme={theme()}
1189
- line={line()}
1190
- tone={activeQuotaTone()}
1191
- />
1192
- )}
1193
- </Index>
1194
- </Show>
723
+ const allAccounts = () =>
724
+ vaultMode()
725
+ ? vaultAccounts().map((account) => ({
726
+ ...account,
727
+ label: account.label ?? account.id,
728
+ hostDisabled: !account.enabled,
729
+ }))
730
+ : [
731
+ {
732
+ id: 'main',
733
+ label: 'main',
734
+ quota: state().main?.quota ?? null,
735
+ killed: state().main?.killed ?? false,
736
+ resetCredits: state().main?.resetCredits,
737
+ vaultState: undefined,
738
+ hostDisabled: false,
739
+ },
740
+ ...enabledFallbacks().map((account) => ({
741
+ ...account,
742
+ label: account.label ?? account.id,
743
+ hostDisabled: false,
744
+ })),
745
+ ]
746
+ const accounts = (): AccountView[] => {
747
+ if (!hasData()) return []
748
+ const rawAccounts = allAccounts()
749
+ const selected = collapsed()
750
+ ? collapsedLines().flatMap((line) => {
751
+ const raw = rawAccounts.find((account) => account.id === line.id)
752
+ return raw ? [{ raw, muted: line.stale || !line.active }] : []
753
+ })
754
+ : rawAccounts
755
+ .filter(
756
+ (account) =>
757
+ vaultMode() ||
758
+ account.id === 'main' ||
759
+ prefs().sections.fallbackAccounts,
760
+ )
761
+ .map((raw) => ({ raw, muted: false }))
762
+ return selected.map(({ raw, muted }) => {
763
+ const active = sessionRouting().activeId === raw.id
764
+ const quota = sidebarQuotaProjection(raw.quota, Date.now())
765
+ const parts = quotaWindowParts(quota, {
766
+ now: Date.now(),
767
+ staleAfterMs: Number.POSITIVE_INFINITY,
768
+ }).windows
769
+ return {
770
+ id: raw.id,
771
+ label: raw.label,
772
+ status: {
773
+ text: raw.killed ? 'blocked' : active ? 'active' : 'idle',
774
+ tone: raw.killed ? 'error' : active ? 'success' : 'textMuted',
775
+ },
776
+ blocked: raw.killed,
777
+ indicatorTone: raw.killed
778
+ ? 'error'
779
+ : muted
780
+ ? 'textMuted'
781
+ : frameTone(activeQuotaTone()),
782
+ collapsed: { quotaTone: frameTone(activeQuotaTone()), muted },
783
+ quota,
784
+ groups: [
785
+ {
786
+ rows: buildQuotaRowsForDisplay(
787
+ raw.quota,
788
+ Date.now(),
789
+ prefs().sections.pacing,
790
+ ).flatMap((row) => {
791
+ const part = parts.find((part) => part.name === row.label)
792
+ if (!part) return []
793
+ return [
794
+ {
795
+ part: {
796
+ ...part,
797
+ // Hidden fallback rows still reserve their label column.
798
+ name: row.label.padEnd(quotaLabelWidth() - 1),
799
+ figure: row.text.slice(row.label.length + 1),
800
+ remainingPercent: 100 - row.window.usedPercent,
801
+ },
802
+ pace: paceView(row.pacing),
803
+ },
804
+ ]
805
+ }),
806
+ },
807
+ ],
808
+ emptyQuotaText: {
809
+ expanded: isQuotaLoaded(raw.quota) ? '\u2014' : 'checking\u2026',
810
+ collapsed: '\u2014',
811
+ },
812
+ }
813
+ })
814
+ }
1195
815
 
1196
- {/* Expanded: full sections. Also render when there's no data so the
1197
- sidebar can never go blank if data clears while collapsed. */}
1198
- <Show when={!collapsed() || !hasData()}>
1199
- <Show
1200
- when={hasData()}
1201
- fallback={
1202
- <box marginTop={1} width='100%'>
1203
- <text fg={theme().textMuted}>
1204
- {vaultMode()
1205
- ? state().vaultDiscovered === true
1206
- ? 'No vault accounts'
1207
- : "Waiting for the vault's first answer"
1208
- : 'Waiting for quota\u2026'}
1209
- </text>
1210
- </box>
1211
- }
1212
- >
1213
- {/* Quota */}
1214
- <Show when={prefs().sections.quota}>
1215
- <SectionHeader theme={theme()} title='Quota' />
1216
- <Show
1217
- when={!vaultMode()}
1218
- fallback={
1219
- <For each={vaultAccounts()}>
1220
- {(account, index) => (
1221
- <AccountBlock
1222
- theme={theme()}
1223
- appearance={prefs().appearance}
1224
- name={account.label ?? account.id}
1225
- quota={account.quota}
1226
- killed={account.killed}
1227
- vaultState={account.vaultState}
1228
- hostDisabled={!account.enabled}
1229
- active={sessionRouting().activeId === account.id}
1230
- pacingEnabled={prefs().sections.pacing}
1231
- labelWidth={quotaLabelWidth()}
1232
- resetCredits={account.resetCredits}
1233
- marginTop={index() === 0 ? 0 : 1}
1234
- />
1235
- )}
1236
- </For>
1237
- }
1238
- >
1239
- <AccountBlock
1240
- theme={theme()}
1241
- appearance={prefs().appearance}
1242
- name='main'
1243
- quota={state().main?.quota ?? null}
1244
- killed={state().main?.killed ?? false}
1245
- active={sessionRouting().activeId === 'main'}
1246
- pacingEnabled={prefs().sections.pacing}
1247
- labelWidth={quotaLabelWidth()}
1248
- resetCredits={state().main?.resetCredits}
1249
- />
1250
- <Show when={prefs().sections.fallbackAccounts}>
1251
- <For each={enabledFallbacks()}>
1252
- {(fb) => (
1253
- <AccountBlock
1254
- theme={theme()}
1255
- appearance={prefs().appearance}
1256
- name={fb.label ?? fb.id}
1257
- quota={fb.quota}
1258
- killed={fb.killed}
1259
- active={sessionRouting().activeId === fb.id}
1260
- pacingEnabled={prefs().sections.pacing}
1261
- labelWidth={quotaLabelWidth()}
1262
- resetCredits={fb.resetCredits}
1263
- marginTop={1}
1264
- />
1265
- )}
1266
- </For>
1267
- </Show>
816
+ return (
817
+ <SidebarFrame
818
+ header={{
819
+ badge: prefs().header.label,
820
+ version:
821
+ prefs().header.showVersion && PLUGIN_VERSION !== ''
822
+ ? `v${PLUGIN_VERSION}`
823
+ : undefined,
824
+ }}
825
+ accounts={accounts()}
826
+ theme={theme()}
827
+ appearance={prefs().appearance}
828
+ showQuota={prefs().sections.quota}
829
+ now={Date.now()}
830
+ collapsed={collapsed()}
831
+ onToggle={props.controller.toggleCollapsed}
832
+ beforeQuota={(account) => {
833
+ const raw = allAccounts().find((raw) => raw.id === account.id)
834
+ return (
835
+ <>
836
+ <Show when={raw?.vaultState}>
837
+ <SidebarTextRow text={raw?.vaultState ?? ''} tone='warning' />
1268
838
  </Show>
1269
- </Show>
1270
- </Show>
1271
-
1272
- {/* Routing */}
1273
- <Show when={prefs().sections.routing}>
1274
- <SectionHeader theme={theme()} title='Routing' />
1275
- <For each={buildRoutingRowsForDisplay(state(), props.sessionId)}>
839
+ <Show when={raw?.hostDisabled}>
840
+ <SidebarTextRow text='off in /openai' />
841
+ </Show>
842
+ </>
843
+ )
844
+ }}
845
+ afterQuota={(account) => {
846
+ const raw = allAccounts().find((raw) => raw.id === account.id)
847
+ return (
848
+ <For
849
+ each={getAccountMetadataRows(
850
+ raw?.resetCredits,
851
+ raw?.quota?.spendControl,
852
+ accountCreditsText(raw?.quota ?? null),
853
+ sessionRouting().activeId === account.id &&
854
+ accountServesOnCredits(raw?.quota ?? null, Date.now()),
855
+ )}
856
+ >
1276
857
  {(row) => (
1277
- <StatRow
858
+ <AccountMetaRow
1278
859
  theme={theme()}
1279
860
  label={row.label}
1280
861
  value={row.value}
1281
- tone={row.tone}
1282
862
  />
1283
863
  )}
1284
864
  </For>
1285
- </Show>
1286
-
1287
- {/* Plan and credits — whichever are present */}
1288
- <For each={getQuotaMetadataRows(state())}>
1289
- {(row) => (
1290
- <StatRow
1291
- theme={theme()}
1292
- label={row.label}
1293
- value={row.value}
1294
- tone='text'
1295
- />
1296
- )}
1297
- </For>
1298
-
1299
- {/* Health — only when something is wrong */}
1300
- <Show when={degraded() && prefs().sections.health}>
1301
- <SectionHeader theme={theme()} title='Health' />
1302
- <Show when={quotaBackedOff()}>
1303
- <StatRow
1304
- theme={theme()}
1305
- label='Quota API'
1306
- value={`backoff ${formatUntil(state().main?.quotaBackoffUntil)}`}
1307
- tone='warn'
1308
- />
865
+ )
866
+ }}
867
+ sections={() => (
868
+ <>
869
+ <Show when={!hasData()}>
870
+ <box marginTop={1} width='100%'>
871
+ <SidebarTextRow
872
+ text={
873
+ vaultMode()
874
+ ? state().vaultDiscovered === true
875
+ ? 'No vault accounts'
876
+ : "Waiting for the vault's first answer"
877
+ : 'Waiting for quota\u2026'
878
+ }
879
+ />
880
+ </box>
881
+ </Show>
882
+ <Show when={prefs().sections.routing}>
883
+ <SidebarSection title='Routing'>
884
+ <For each={buildRoutingRowsForDisplay(state(), props.sessionId)}>
885
+ {(row) => (
886
+ <SidebarStatRow
887
+ label={row.label}
888
+ value={row.value}
889
+ tone={frameTone(row.tone)}
890
+ />
891
+ )}
892
+ </For>
893
+ </SidebarSection>
894
+ </Show>
895
+ <For each={getQuotaMetadataRows(state())}>
896
+ {(row) => (
897
+ <SidebarStatRow label={row.label} value={row.value} tone='text' />
898
+ )}
899
+ </For>
900
+ <Show when={degraded() && prefs().sections.health}>
901
+ <SidebarSection title='Health'>
902
+ <Show when={quotaBackedOff()}>
903
+ <SidebarStatRow
904
+ label='Quota API'
905
+ value={`backoff ${formatUntil(state().main?.quotaBackoffUntil)}`}
906
+ tone='warning'
907
+ />
908
+ </Show>
909
+ <Show when={refreshBackedOff()}>
910
+ <SidebarStatRow
911
+ label='Token refresh'
912
+ value={`backoff ${formatUntil(state().main?.refreshBackoffUntil)}`}
913
+ tone='warning'
914
+ />
915
+ </Show>
916
+ </SidebarSection>
1309
917
  </Show>
1310
- <Show when={refreshBackedOff()}>
1311
- <StatRow
1312
- theme={theme()}
1313
- label='Token refresh'
1314
- value={`backoff ${formatUntil(state().main?.refreshBackoffUntil)}`}
1315
- tone='warn'
918
+ <Show when={killedNames().length > 0}>
919
+ <SidebarStatRow
920
+ label='Killswitch'
921
+ value={`${killedNames().join(', ')} blocked`}
922
+ tone='error'
1316
923
  />
1317
924
  </Show>
1318
- </Show>
1319
- <Show when={killedNames().length > 0}>
1320
- <StatRow
1321
- theme={theme()}
1322
- label='Killswitch'
1323
- value={`${killedNames().join(', ')} blocked`}
1324
- tone='err'
1325
- />
1326
- </Show>
1327
- </Show>
1328
- </box>
925
+ </>
926
+ )}
927
+ />
1329
928
  )
1330
929
  }
1331
930