@cortexkit/opencode-antigravity-auth 3.0.14 → 3.0.16

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