@cortexkit/opencode-antigravity-auth 3.0.20 → 3.0.22

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 (107) hide show
  1. package/dist/cli.js +354 -278
  2. package/dist/cli.js.map +3 -3
  3. package/dist/cli.meta.json +66 -21
  4. package/dist/index.js +841 -392
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +123 -28
  7. package/dist/server.js +860 -411
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/claustrum/custody.js +25 -0
  11. package/dist/src/common-auth-embedded/claustrum/hub.js +20 -1
  12. package/dist/src/common-auth-embedded/claustrum/insula.js +6 -0
  13. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +2 -2
  14. package/dist/src/common-auth-embedded/fs/with-lock.js +37 -10
  15. package/dist/src/common-auth-embedded/quota/format.d.ts +9 -4
  16. package/dist/src/common-auth-embedded/quota/format.js +45 -26
  17. package/dist/src/common-auth-embedded/quota-sidebar/index.d.ts +86 -0
  18. package/dist/src/common-auth-embedded/quota-sidebar/index.tsx +654 -0
  19. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +62 -0
  20. package/dist/src/common-auth-embedded/routing-accessor/index.js +128 -0
  21. package/dist/src/common-auth-embedded/source-output.json +69 -29
  22. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  23. package/dist/src/ga/tui/host-ga.js +2 -2
  24. package/dist/src/ga/tui/host-ga.js.map +1 -1
  25. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  26. package/dist/src/plugin/index.d.ts.map +1 -1
  27. package/dist/src/plugin/index.js +2 -0
  28. package/dist/src/plugin/index.js.map +1 -1
  29. package/dist/src/plugin/request.d.ts.map +1 -1
  30. package/dist/src/plugin/request.js +1 -0
  31. package/dist/src/plugin/request.js.map +1 -1
  32. package/dist/src/plugin/shared/request-services.d.ts +6 -0
  33. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  34. package/dist/src/plugin/shared/request-services.js +89 -2
  35. package/dist/src/plugin/shared/request-services.js.map +1 -1
  36. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  37. package/dist/src/plugin/shared/vault-request-credentials.js +4 -0
  38. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  39. package/dist/src/plugin/shared/vault-routing-purpose.d.ts +12 -0
  40. package/dist/src/plugin/shared/vault-routing-purpose.d.ts.map +1 -0
  41. package/dist/src/plugin/shared/vault-routing-purpose.js +18 -0
  42. package/dist/src/plugin/shared/vault-routing-purpose.js.map +1 -0
  43. package/dist/src/plugin/shared/vault-routing.d.ts +36 -0
  44. package/dist/src/plugin/shared/vault-routing.d.ts.map +1 -0
  45. package/dist/src/plugin/shared/vault-routing.js +213 -0
  46. package/dist/src/plugin/shared/vault-routing.js.map +1 -0
  47. package/dist/src/plugin/types.d.ts +1 -0
  48. package/dist/src/plugin/types.d.ts.map +1 -1
  49. package/dist/src/tui/quota-layout.d.ts +4 -58
  50. package/dist/src/tui/quota-layout.d.ts.map +1 -1
  51. package/dist/src/tui/quota-layout.js +4 -90
  52. package/dist/src/tui/quota-layout.js.map +1 -1
  53. package/dist/src/tui/sidebar-frame.d.ts +4 -34
  54. package/dist/src/tui/sidebar-frame.d.ts.map +1 -1
  55. package/dist/src/tui/sidebar-frame.js +93 -167
  56. package/dist/src/tui/sidebar-frame.js.map +1 -1
  57. package/dist/src/tui.js +2 -2
  58. package/dist/src/tui.js.map +1 -1
  59. package/dist/tui-build-map.json +31 -17
  60. package/dist/tui-ga-build-map.json +32 -17
  61. package/dist/types/src/common-auth-embedded/quota/format.d.ts +9 -4
  62. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +62 -0
  63. package/dist/types/src/plugin/index.d.ts.map +1 -1
  64. package/dist/types/src/plugin/request.d.ts.map +1 -1
  65. package/dist/types/src/plugin/shared/request-services.d.ts +6 -0
  66. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  67. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  68. package/dist/types/src/plugin/shared/vault-routing-purpose.d.ts +12 -0
  69. package/dist/types/src/plugin/shared/vault-routing-purpose.d.ts.map +1 -0
  70. package/dist/types/src/plugin/shared/vault-routing.d.ts +36 -0
  71. package/dist/types/src/plugin/shared/vault-routing.d.ts.map +1 -0
  72. package/dist/types/src/plugin/types.d.ts +1 -0
  73. package/dist/types/src/plugin/types.d.ts.map +1 -1
  74. package/package.json +2 -2
  75. package/src/common-auth-embedded/claustrum/custody.js +25 -0
  76. package/src/common-auth-embedded/claustrum/hub.js +20 -1
  77. package/src/common-auth-embedded/claustrum/insula.js +6 -0
  78. package/src/common-auth-embedded/fs/refresh-file-lock.js +2 -2
  79. package/src/common-auth-embedded/fs/with-lock.js +37 -10
  80. package/src/common-auth-embedded/quota/format.d.ts +9 -4
  81. package/src/common-auth-embedded/quota/format.js +45 -26
  82. package/src/common-auth-embedded/quota-sidebar/index.d.ts +86 -0
  83. package/src/common-auth-embedded/quota-sidebar/index.tsx +654 -0
  84. package/src/common-auth-embedded/routing-accessor/index.d.ts +62 -0
  85. package/src/common-auth-embedded/routing-accessor/index.js +128 -0
  86. package/src/common-auth-embedded/source-output.json +69 -29
  87. package/src/tui-compiled/common-auth-embedded/quota/format.js +45 -26
  88. package/src/tui-compiled/common-auth-embedded/quota-sidebar/index.js +683 -0
  89. package/src/tui-compiled/tui/quota-layout.js +5 -330
  90. package/src/tui-compiled/tui/sidebar-frame.js +243 -467
  91. package/src/tui-compiled/tui.js +2 -2
  92. package/src/tui-ga-compiled/host-ga.js +2 -2
  93. package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +45 -26
  94. package/src/tui-ga-compiled/shared/ced204104a639c9c-sidebar-frame.js +243 -467
  95. package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +5 -330
  96. package/src/tui-ga-compiled/shared/e4ec36f367492969-index.js +683 -0
  97. package/src/tui-ga-raw/host-ga.tsx +2 -2
  98. package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +45 -26
  99. package/src/tui-ga-raw/shared/ced204104a639c9c-sidebar-frame.tsx +214 -400
  100. package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +10 -301
  101. package/src/tui-ga-raw/shared/e4ec36f367492969-index.tsx +654 -0
  102. package/src/tui-raw/common-auth-embedded/quota/format.js +45 -26
  103. package/src/tui-raw/common-auth-embedded/quota-sidebar/index.tsx +654 -0
  104. package/src/tui-raw/tui/quota-layout.tsx +10 -301
  105. package/src/tui-raw/tui/sidebar-frame.tsx +214 -400
  106. package/src/tui-raw/tui.tsx +2 -2
  107. package/src/tui.tsx +2 -2
@@ -1,52 +1,37 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
2
 
3
- /**
4
- * The Antigravity sidebar frame, shared by the OpenCode 1 sidebar (`tui.tsx`)
5
- * and the OpenCode 2 sidebar (`ga/tui/host-ga.tsx`): the padded
6
- * panel, the clickable `▼`/`▶` header badge with the optional plugin version
7
- * at the right, one line per account when collapsed, and the
8
- * `Quota`, `Routing` and `Health` sections when expanded.
9
- *
10
- * Each renderer reads its own data source (the sidebar file, or the
11
- * location's `state` answer), maps its own host theme onto `FrameTheme` and
12
- * owns its own collapse state; everything drawn is decided here, so a change
13
- * of shape is made once for both hosts.
14
- *
15
- * This module stays inside both TUI import graphs: besides Solid and
16
- * OpenTUI it imports only the pure quota and sidebar-projection helpers and
17
- * the shared layouts. No sidebar file, preferences file, RPC, account
18
- * store, OAuth, token or host SDK module, no Node built-in, and nothing
19
- * that writes to the terminal.
20
- */
3
+ /** Plugin-owned projection and Routing/Health sections for the shared quota frame. */
21
4
 
22
5
  import type { RGBA } from "@opentui/core"
23
6
  import { createMemo, createSignal, For, type JSX, Show } from "solid-js"
24
7
 
25
8
  import {
26
- formatQuota,
27
9
  isQuotaStale,
10
+ NO_QUOTA_READING,
28
11
  type ProjectedLimit,
29
12
  type ProjectedQuota,
13
+ type QuotaWindowPart,
30
14
  } from "./bf17cbee28e58197-index.js"
15
+ import {
16
+ type AccountView,
17
+ SidebarFrame,
18
+ SidebarSection,
19
+ SidebarTextRow,
20
+ type SidebarTheme,
21
+ type Tone,
22
+ } from "./e4ec36f367492969-index.tsx"
31
23
  import { formatResetIn, formatWait } from "./8ae1927e5910ea81-sidebar-projection.js"
32
24
  import {
33
- ASSUMED_CONTENT_WIDTH,
34
25
  accountWindows,
35
26
  DEFAULT_QUOTA_APPEARANCE,
36
- fitLabel,
37
27
  GROUP_NAMES,
38
28
  QUOTA_ORDER,
39
- QuotaAccountBlock,
40
29
  type QuotaAppearance,
41
30
  type QuotaLayoutAccount,
42
- type QuotaPalette,
43
- type QuotaTone,
44
31
  quotaTone,
45
32
  } from "./dd4c9e1a907f8ef0-quota-layout.tsx"
46
33
  import { routeLineFits } from "./6ca47cd4ec33fe72-route-layout.js"
47
34
 
48
- type Tone = QuotaTone
49
-
50
35
  // --- Theme -----------------------------------------------------------------
51
36
 
52
37
  /** A theme color; `undefined` leaves the host's default color in place. */
@@ -68,40 +53,11 @@ export interface FrameTheme {
68
53
  readonly error: FrameColor
69
54
  }
70
55
 
71
- // Every tone falls through to a sibling token, so a sparse custom theme still
72
- // renders readably.
73
- export function toneColor(theme: FrameTheme, tone: Tone): FrameColor {
74
- switch (tone) {
75
- case 'ok':
76
- return theme.success ?? theme.accent
77
- case 'warn':
78
- return theme.warning ?? theme.accent
79
- case 'err':
80
- return theme.error ?? theme.accent
81
- case 'muted':
82
- return theme.textMuted ?? theme.text
83
- case 'accent':
84
- return theme.accent ?? theme.text
85
- default:
86
- return theme.text
87
- }
88
- }
89
-
90
- // The shared quota layout reads its colors through this palette. Muted text
91
- // and the account label read `textMuted` and `text` straight from the theme,
92
- // without the `toneColor` fallback chain.
93
- export function themePalette(theme: () => FrameTheme): QuotaPalette {
94
- return {
95
- text: () => theme().text,
96
- muted: () => theme().textMuted,
97
- tone: (tone) => toneColor(theme(), tone),
98
- }
99
- }
100
-
101
56
  // --- Frame inputs ----------------------------------------------------------
102
57
 
103
58
  /** The account fields the frame reads: the quota layout's plus the state. */
104
59
  export interface FrameAccount extends QuotaLayoutAccount {
60
+ readonly id: string
105
61
  readonly enabled: boolean
106
62
  readonly current: boolean
107
63
  readonly cooldownUntil?: number
@@ -145,103 +101,6 @@ export const DEFAULT_FRAME_SETTINGS: FrameSettings = {
145
101
  appearance: DEFAULT_QUOTA_APPEARANCE,
146
102
  }
147
103
 
148
- // --- Rows ------------------------------------------------------------------
149
-
150
- // Section header: bold title, themed text color, top margin for vertical
151
- // breathing room between sections.
152
- export function SectionHeader(props: {
153
- theme: () => FrameTheme
154
- title: string
155
- }): JSX.Element {
156
- return (
157
- <box width='100%' marginTop={1}>
158
- <text fg={toneColor(props.theme(), 'text')}>
159
- <b>{props.title}</b>
160
- </text>
161
- </box>
162
- )
163
- }
164
-
165
- // Muted label left, value (optionally tone-tinted, bold) right, for the
166
- // routing and health rows.
167
- export function StatRow(props: {
168
- theme: () => FrameTheme
169
- label: string
170
- value: string
171
- tone?: Tone
172
- }): JSX.Element {
173
- return (
174
- <box width='100%' flexDirection='row' justifyContent='space-between'>
175
- <text fg={props.theme().textMuted}>{props.label}</text>
176
- <text fg={toneColor(props.theme(), props.tone ?? 'text')}>
177
- <b>{props.value}</b>
178
- </text>
179
- </box>
180
- )
181
- }
182
-
183
- // Muted label left, caller-supplied value right. The collapsed view renders
184
- // one row for every visible account. The caller sizes both sides to the
185
- // measured width, so neither side may wrap.
186
- function CollapsedRow(props: {
187
- theme: () => FrameTheme
188
- label: string
189
- children: JSX.Element
190
- }): JSX.Element {
191
- return (
192
- <box width='100%' flexDirection='row' justifyContent='space-between'>
193
- <text flexShrink={0} wrapMode='none' fg={props.theme().textMuted}>
194
- {props.label}
195
- </text>
196
- {props.children}
197
- </box>
198
- )
199
- }
200
-
201
- // One account in the Quota section: the shared quota block, with the status
202
- // word computed from the account state. Status word priorities (first match
203
- // wins):
204
- // - `off` when the account is disabled
205
- // - `cooling <wait>` when cooldownUntil is still in the future
206
- // - `active` when current === true
207
- // - `idle` for the fallback (current === false) case
208
- function AccountBlock(props: {
209
- theme: () => FrameTheme
210
- appearance: QuotaAppearance
211
- account: FrameAccount
212
- now: () => number
213
- width: () => number
214
- marginTop?: number
215
- }): JSX.Element {
216
- const cooldownMs = (): number => {
217
- const cd = props.account.cooldownUntil
218
- if (typeof cd !== 'number') return 0
219
- return Math.max(0, cd - props.now())
220
- }
221
- const statusWord = (): string => {
222
- if (!props.account.enabled) return 'off'
223
- if (cooldownMs() > 0) return `cooling ${formatWait(cooldownMs())}`
224
- return props.account.current ? 'active' : 'idle'
225
- }
226
- const statusTone = (): Tone => {
227
- if (!props.account.enabled) return 'muted'
228
- if (cooldownMs() > 0) return 'warn'
229
- return props.account.current ? 'ok' : 'muted'
230
- }
231
- return (
232
- <QuotaAccountBlock
233
- palette={themePalette(props.theme)}
234
- appearance={props.appearance}
235
- account={props.account}
236
- status={statusWord()}
237
- statusTone={statusTone()}
238
- now={props.now}
239
- width={props.width}
240
- marginTop={props.marginTop}
241
- />
242
- )
243
- }
244
-
245
104
  // Stored quota values are percentages and epoch-millisecond reset times.
246
105
  // Adapt them to the shared projection so common-auth, not the renderer,
247
106
  // decides how the narrow line reads.
@@ -289,82 +148,68 @@ export function sidebarQuotaProjection(
289
148
  }
290
149
  }
291
150
 
292
- // One account on one measured, non-wrapping line: the label, the shared
293
- // narrow quota text and a status dot (`⊘` while the account is off or
294
- // cooling). The quota text is shown whole or not at all; the label is cut
295
- // with `…` to make room.
296
- function CollapsedAccount(props: {
297
- theme: () => FrameTheme
298
- appearance: () => QuotaAppearance
299
- account: FrameAccount
300
- now: () => number
301
- width: () => number
302
- }): JSX.Element {
303
- const account = props.account
304
- const now = props.now
305
- const theme = props.theme
306
- const unavailable = () =>
307
- !account.enabled ||
308
- (account.cooldownUntil != null && account.cooldownUntil > now())
309
- const line = createMemo(() => {
310
- const currentTime = now()
311
- const projection = sidebarQuotaProjection(account, currentTime)
312
- const text = formatQuota(projection, {
313
- now: currentTime,
314
- form: 'narrow',
315
- })
316
- const remaining = projection?.limits.length
317
- ? Math.min(
318
- ...projection.limits.map((limit) => limit.remainingPercent ?? 100),
319
- )
320
- : undefined
321
- const tone =
322
- remaining === undefined
323
- ? 'muted'
324
- : quotaTone(100 - remaining, props.appearance())
325
- const stale = isQuotaStale(projection, { now: currentTime })
326
- const dot = unavailable() ? ' ⊘' : ' ●'
327
- const width = props.width()
328
- // Keep a complete shared line or omit it; a partial quota can make an
329
- // account look as if it has less remaining.
330
- const showQuota = text.length <= width
331
- const showDot =
332
- dot.length <= width && (!showQuota || text.length + dot.length <= width)
333
- const rightWidth =
334
- (showQuota ? text.length : 0) + (showDot ? dot.length : 0)
335
- const labelWidth = Math.max(0, width - rightWidth - 1)
336
- return {
337
- dot,
338
- label: fitLabel(account.label, labelWidth),
339
- showDot,
340
- showQuota,
341
- stale,
342
- text,
343
- tone,
344
- }
345
- })
346
- const quotaColor = () =>
347
- line().stale ? theme().textMuted : toneColor(theme(), line().tone)
348
- const dotColor = () =>
349
- line().stale
350
- ? theme().textMuted
351
- : toneColor(theme(), unavailable() ? 'err' : line().tone)
352
- return (
353
- <CollapsedRow theme={theme} label={line().label}>
354
- <box flexDirection='row' flexShrink={0}>
355
- <Show when={line().showQuota}>
356
- <text flexShrink={0} wrapMode='none' fg={quotaColor()}>
357
- <b>{line().text}</b>
358
- </text>
359
- </Show>
360
- <Show when={line().showDot}>
361
- <text flexShrink={0} wrapMode='none' fg={dotColor()}>
362
- {line().dot}
363
- </text>
364
- </Show>
365
- </box>
366
- </CollapsedRow>
367
- )
151
+ /** Preserve provider status and projection policy; the library owns all quota layout. */
152
+ function accountView(
153
+ account: FrameAccount,
154
+ now: number,
155
+ appearance: QuotaAppearance,
156
+ ): AccountView {
157
+ const cooldown = Math.max(0, (account.cooldownUntil ?? 0) - now)
158
+ const status: AccountView['status'] = !account.enabled
159
+ ? { text: 'off', tone: 'textMuted' }
160
+ : cooldown > 0
161
+ ? { text: `cooling ${formatWait(cooldown)}`, tone: 'warning' }
162
+ : account.current
163
+ ? { text: 'active', tone: 'success' }
164
+ : { text: 'idle', tone: 'textMuted' }
165
+ const quota = sidebarQuotaProjection(account, now)
166
+ const stale = isQuotaStale(quota, { now })
167
+ const remaining = quota?.limits.length
168
+ ? Math.min(...quota.limits.map((limit) => limit.remainingPercent ?? 100))
169
+ : undefined
170
+ const quotaColor =
171
+ remaining === undefined
172
+ ? 'textMuted'
173
+ : quotaTone(100 - remaining, appearance)
174
+ const blocked = !account.enabled || cooldown > 0
175
+ const windows = accountWindows(account, now)
176
+ return {
177
+ id: account.id,
178
+ label: account.label,
179
+ status,
180
+ blocked,
181
+ indicatorTone: stale ? 'textMuted' : blocked ? 'error' : quotaColor,
182
+ quota,
183
+ collapsed: {
184
+ quotaTone: quotaColor,
185
+ muted: stale || status.text !== 'active',
186
+ },
187
+ emptyQuotaText: { expanded: NO_QUOTA_READING, collapsed: NO_QUOTA_READING },
188
+ groups: QUOTA_ORDER.flatMap((key) => {
189
+ const rows = windows
190
+ .filter((window) => window.key === key)
191
+ .map(({ reading, text }) => {
192
+ const name =
193
+ text.name ||
194
+ (reading.window === 'weekly' ? '7d' : (reading.window ?? ''))
195
+ return {
196
+ part: {
197
+ kind: 'window',
198
+ reading: text.remaining === null ? 'unknown' : 'known',
199
+ name,
200
+ short: name,
201
+ figure: text.remaining === null ? 'no reading' : text.figure,
202
+ remainingPercent: text.remaining ?? undefined,
203
+ resetIn: text.reset || undefined,
204
+ checkedAt:
205
+ text.remaining === null ? undefined : reading.checkedAt,
206
+ resetSinceReading: text.resetSinceReading,
207
+ } satisfies QuotaWindowPart,
208
+ }
209
+ })
210
+ return rows.length ? [{ title: GROUP_NAMES[key], rows }] : []
211
+ }),
212
+ }
368
213
  }
369
214
 
370
215
  // --- Frame -----------------------------------------------------------------
@@ -386,196 +231,165 @@ export interface SidebarFrameProps {
386
231
  readonly now: () => number
387
232
  }
388
233
 
389
- export function SidebarFrame(props: SidebarFrameProps): JSX.Element {
390
- const theme = props.theme
234
+ function StatRow(props: {
235
+ theme: () => SidebarTheme
236
+ label: string
237
+ value: string
238
+ tone?: Tone
239
+ }): JSX.Element {
240
+ return (
241
+ <box width='100%' flexDirection='row' justifyContent='space-between'>
242
+ <text fg={props.theme().textMuted}>{props.label}</text>
243
+ <text fg={props.theme()[props.tone ?? 'text']}>
244
+ <b>{props.value}</b>
245
+ </text>
246
+ </box>
247
+ )
248
+ }
249
+
250
+ export function AntigravitySidebar(props: SidebarFrameProps): JSX.Element {
391
251
  const prefs = props.settings
392
- const collapsed = props.collapsed
393
252
  const now = props.now
394
-
395
253
  const hasData = () => props.accounts().length > 0
396
254
  const backoffActive = () => {
397
255
  const until = props.quotaBackoffUntil()
398
256
  return typeof until === 'number' && until > now()
399
257
  }
400
- const lastError = () => props.lastError()
401
- const degraded = () => backoffActive() || !!lastError()
402
- // Honors sections.fallbackAccounts. Both the expanded (AccountBlock list)
403
- // and the collapsed (CollapsedAccount list) paths use the same filter so
404
- // the user sees the same account set in either mode.
405
- const visibleAccounts = () => {
406
- const showFallback = prefs().sections.fallbackAccounts
407
- if (showFallback) return props.accounts()
408
- return props.accounts().filter((account) => account.current)
258
+ const visibleAccounts = createMemo(() =>
259
+ props
260
+ .accounts()
261
+ .filter((account) => prefs().sections.fallbackAccounts || account.current)
262
+ .map((account) => accountView(account, now(), prefs().appearance)),
263
+ )
264
+ const theme = (): SidebarTheme => {
265
+ const source = props.theme()
266
+ return {
267
+ ...source,
268
+ textMuted: source.textMuted ?? source.text,
269
+ accent: source.accent ?? source.text,
270
+ success: source.success ?? source.accent ?? source.text,
271
+ warning: source.warning ?? source.accent ?? source.text,
272
+ error: source.error ?? source.accent ?? source.text,
273
+ }
409
274
  }
410
275
 
411
- // The route on one `Route <value>` line when it fits, else one line per
412
- // part with the strategy last.
276
+ // Routing keeps whole parts on separate lines when the single stat row is too wide.
277
+ const [contentWidth, setContentWidth] = createSignal(28)
278
+ let sections: { width: number } | undefined
279
+ const measureContentWidth = () => {
280
+ const width = sections?.width
281
+ if (width && width !== contentWidth())
282
+ queueMicrotask(() => setContentWidth(width))
283
+ }
413
284
  const routeValue = (route: FrameRoute): string =>
414
285
  `${route.strategy ? `${route.strategy} · ` : ''}${route.family}: ${route.style}`
415
286
  const routeLines = (route: FrameRoute): string[] =>
416
- [`${route.family}: ${route.style}`, route.strategy ?? ''].filter(
417
- (line) => line !== '',
418
- )
419
-
420
- // The width available to content: the header row spans the panel inside
421
- // its padding. Layout reports it during a render pass, so the
422
- // signal is updated afterwards rather than rebuilding rows mid-pass.
423
- const [contentWidth, setContentWidth] = createSignal(ASSUMED_CONTENT_WIDTH)
424
- let headerRow: { width: number } | undefined
425
- const measureContentWidth = (): void => {
426
- const width = headerRow?.width
427
- if (typeof width !== 'number' || width <= 0) return
428
- queueMicrotask(() => {
429
- if (width !== contentWidth()) setContentWidth(width)
430
- })
431
- }
432
-
433
- // Header badge: ▼/▶ {label}, with the optional version at the right.
434
- const headerLabel = () => {
435
- const name = prefs().header.label
436
- return !hasData() ? name : collapsed() ? `\u25b6 ${name}` : `\u25bc ${name}`
437
- }
287
+ [`${route.family}: ${route.style}`, route.strategy ?? ''].filter(Boolean)
438
288
 
439
289
  return (
440
- <box
441
- width='100%'
442
- flexDirection='column'
443
- paddingTop={1}
444
- paddingBottom={1}
445
- paddingLeft={1}
446
- paddingRight={1}
447
- >
448
- {/* biome-ignore lint/a11y/noStaticElementInteractions: opentui renders to a terminal, not the DOM — ARIA roles do not apply */}
449
- <box
450
- ref={(element) => {
451
- headerRow = element
452
- }}
453
- onSizeChange={measureContentWidth}
454
- width='100%'
455
- flexDirection='row'
456
- justifyContent='space-between'
457
- alignItems='center'
458
- onMouseDown={() => {
459
- // Only toggle when there is data to expand into. Without this a
460
- // click on the empty-awaiting header would just toggle the
461
- // affordance for nothing.
462
- if (hasData()) props.onToggleCollapsed()
463
- }}
464
- >
465
- <box paddingLeft={1} paddingRight={1} backgroundColor={theme().accent}>
466
- <text fg={theme().background}>
467
- <b>{headerLabel()}</b>
468
- </text>
469
- </box>
470
- <Show when={prefs().header.showVersion && props.version !== ''}>
471
- <text fg={theme().textMuted}>{`v${props.version}`}</text>
472
- </Show>
473
- </box>
474
-
475
- {/* Collapsed: one measured, non-wrapping row for each visible account. */}
476
- <Show when={collapsed() && hasData()}>
477
- <For each={visibleAccounts()}>
478
- {(account) => (
479
- <CollapsedAccount
480
- theme={theme}
481
- appearance={() => prefs().appearance}
482
- account={account}
483
- now={now}
484
- width={contentWidth}
485
- />
486
- )}
487
- </For>
488
- </Show>
489
-
490
- {/* Expanded: full sections. Also render when there's no data so the
491
- sidebar can never go blank if data clears while collapsed. */}
492
- <Show when={!collapsed() || !hasData()}>
493
- <Show
494
- when={hasData()}
495
- fallback={
496
- <box marginTop={1} width='100%'>
497
- <text fg={theme().textMuted}>{'Waiting for quota\u2026'}</text>
498
- </box>
499
- }
500
- >
501
- {/* Quota */}
502
- <Show when={prefs().sections.quota}>
503
- <SectionHeader theme={theme} title='Quota' />
504
- <For each={visibleAccounts()}>
505
- {(account, index) => (
506
- <AccountBlock
507
- theme={theme}
508
- appearance={prefs().appearance}
509
- account={account}
510
- now={now}
511
- width={contentWidth}
512
- marginTop={index() === 0 ? 0 : 1}
513
- />
514
- )}
515
- </For>
516
- </Show>
517
-
518
- {/* Routing: the session's route, or one dim line before its first request. */}
519
- <Show when={prefs().sections.routing}>
520
- <SectionHeader theme={theme} title='Routing' />
290
+ <SidebarFrame
291
+ header={{
292
+ badge: prefs().header.label,
293
+ version:
294
+ prefs().header.showVersion && props.version
295
+ ? `v${props.version}`
296
+ : undefined,
297
+ }}
298
+ theme={theme()}
299
+ appearance={prefs().appearance}
300
+ accounts={visibleAccounts()}
301
+ showQuota={prefs().sections.quota}
302
+ now={now()}
303
+ collapsed={props.collapsed()}
304
+ onToggle={props.onToggleCollapsed}
305
+ sections={() => (
306
+ <Show when={!props.collapsed() || !hasData()}>
307
+ <box
308
+ width='100%'
309
+ flexDirection='column'
310
+ ref={(element) => {
311
+ sections = element
312
+ }}
313
+ onSizeChange={measureContentWidth}
314
+ >
521
315
  <Show
522
- when={props.route()}
316
+ when={hasData()}
523
317
  fallback={
524
- <text wrapMode='none' fg={theme().textMuted}>
525
- {'No request yet'}
526
- </text>
318
+ <box marginTop={1} width='100%'>
319
+ <SidebarTextRow text='Waiting for quota…' wrapMode='none' />
320
+ </box>
527
321
  }
528
322
  >
529
- {(route) => (
530
- <Show
531
- when={routeLineFits(
532
- 'Route',
533
- routeValue(route()),
534
- contentWidth(),
535
- )}
536
- fallback={
537
- <For each={routeLines(route())}>
538
- {(line) => (
539
- <text wrapMode='none' fg={toneColor(theme(), 'accent')}>
540
- <b>{line}</b>
541
- </text>
542
- )}
543
- </For>
544
- }
545
- >
546
- <StatRow
547
- theme={theme}
548
- label='Route'
549
- value={routeValue(route())}
550
- tone='accent'
551
- />
552
- </Show>
553
- )}
554
- </Show>
555
- </Show>
556
-
557
- {/* Health — only when something is wrong AND sections.health is true */}
558
- <Show when={degraded() && prefs().sections.health}>
559
- <SectionHeader theme={theme} title='Health' />
560
- <Show when={backoffActive()}>
561
- <StatRow
562
- theme={theme}
563
- label='Quota API'
564
- value={`backoff ${formatResetIn(props.quotaBackoffUntil(), now())}`}
565
- tone='warn'
566
- />
323
+ <Show
324
+ when={prefs().sections.quota && visibleAccounts().length === 0}
325
+ >
326
+ <SidebarSection title='Quota' />
327
+ </Show>
328
+ <Show when={prefs().sections.routing}>
329
+ <SidebarSection title='Routing'>
330
+ <Show
331
+ when={props.route()}
332
+ fallback={
333
+ <SidebarTextRow text='No request yet' wrapMode='none' />
334
+ }
335
+ >
336
+ {(route) => (
337
+ <Show
338
+ when={routeLineFits(
339
+ 'Route',
340
+ routeValue(route()),
341
+ contentWidth(),
342
+ )}
343
+ fallback={
344
+ <For each={routeLines(route())}>
345
+ {(line) => (
346
+ <text fg={theme().accent} wrapMode='none'>
347
+ <b>{line}</b>
348
+ </text>
349
+ )}
350
+ </For>
351
+ }
352
+ >
353
+ <StatRow
354
+ theme={theme}
355
+ label='Route'
356
+ value={routeValue(route())}
357
+ tone='accent'
358
+ />
359
+ </Show>
360
+ )}
361
+ </Show>
362
+ </SidebarSection>
363
+ </Show>
364
+ <Show
365
+ when={
366
+ (backoffActive() || !!props.lastError()) &&
367
+ prefs().sections.health
368
+ }
369
+ >
370
+ <SidebarSection title='Health'>
371
+ <Show when={backoffActive()}>
372
+ <StatRow
373
+ theme={theme}
374
+ label='Quota API'
375
+ value={`backoff ${formatResetIn(props.quotaBackoffUntil(), now())}`}
376
+ tone='warning'
377
+ />
378
+ </Show>
379
+ <Show when={props.lastError()}>
380
+ <StatRow
381
+ theme={theme}
382
+ label='Last error'
383
+ value={props.lastError() ?? ''}
384
+ tone='error'
385
+ />
386
+ </Show>
387
+ </SidebarSection>
388
+ </Show>
567
389
  </Show>
568
- <Show when={lastError()}>
569
- <StatRow
570
- theme={theme}
571
- label='Last error'
572
- value={lastError() ?? ''}
573
- tone='err'
574
- />
575
- </Show>
576
- </Show>
390
+ </box>
577
391
  </Show>
578
- </Show>
579
- </box>
392
+ )}
393
+ />
580
394
  )
581
395
  }