@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.
- package/dist/cli.js +257 -57
- package/dist/cli.js.map +3 -3
- package/dist/cli.meta.json +11 -11
- package/dist/index.js +468 -90
- package/dist/index.js.map +3 -3
- package/dist/index.meta.json +14 -14
- package/dist/server.js +499 -95
- package/dist/server.js.map +3 -3
- package/dist/server.meta.json +1 -1
- package/dist/src/ga/tui/host-ga.d.ts +55 -2
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +73 -43
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +49 -5
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +33 -13
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +97 -44
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/storage.d.ts +17 -0
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js +44 -10
- package/dist/src/plugin/storage.js.map +1 -1
- package/dist/src/runtime-paths.d.ts +2 -1
- package/dist/src/runtime-paths.d.ts.map +1 -1
- package/dist/src/runtime-paths.js +5 -5
- package/dist/src/runtime-paths.js.map +1 -1
- package/dist/src/tui/quota-layout.d.ts +1 -1
- package/dist/src/tui/quota-layout.js +1 -1
- package/dist/src/tui/sidebar-frame.d.ts +109 -0
- package/dist/src/tui/sidebar-frame.d.ts.map +1 -0
- package/dist/src/tui/sidebar-frame.js +244 -0
- package/dist/src/tui/sidebar-frame.js.map +1 -0
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +11 -251
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +120 -92
- package/dist/tui-ga-build-map.json +22 -8
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +33 -13
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/storage.d.ts +17 -0
- package/dist/types/src/plugin/storage.d.ts.map +1 -1
- package/dist/types/src/runtime-paths.d.ts +2 -1
- package/dist/types/src/runtime-paths.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/tui/entry.mjs +19 -1
- package/src/tui-compiled/sidebar-projection.js +119 -0
- package/src/tui-compiled/tui/quota-layout.js +1 -1
- package/src/tui-compiled/tui/sidebar-frame.js +657 -0
- package/src/tui-compiled/tui.js +25 -606
- package/src/tui-ga-compiled/host-ga.js +116 -124
- package/src/tui-ga-compiled/shared/ced204104a639c9c-sidebar-frame.js +657 -0
- package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +1 -1
- package/src/tui-ga-raw/host-ga.tsx +157 -95
- package/src/tui-ga-raw/shared/ced204104a639c9c-sidebar-frame.tsx +603 -0
- package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +1 -1
- package/src/tui-raw/sidebar-projection.js +119 -0
- package/src/tui-raw/tui/quota-layout.tsx +1 -1
- package/src/tui-raw/tui/sidebar-frame.tsx +603 -0
- package/src/tui-raw/tui.tsx +25 -523
- package/src/tui.tsx +25 -523
package/src/tui-raw/tui.tsx
CHANGED
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
* column with a labelled header badge, a Quota section that lists one
|
|
9
9
|
* `AccountBlock` per visible account, a Routing section that surfaces the
|
|
10
10
|
* most recent session route, and a Health section that only appears when
|
|
11
|
-
* something is wrong. The
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* something is wrong. The frame itself lives in `tui/sidebar-frame.tsx`,
|
|
12
|
+
* shared with the OpenCode 2 sidebar; this file reads the sidebar file and
|
|
13
|
+
* the preferences and hands them to it. The Antigravity data model is
|
|
14
|
+
* richer than the Claude/Codex one (per-account Gemini + Non-Gemini quota
|
|
15
|
+
* pools, a health score, and per-session routing decisions), so the fleet
|
|
16
|
+
* components are adapted rather than copied verbatim:
|
|
15
17
|
*
|
|
16
18
|
* - The quota rows come from `tui/quota-layout.tsx`, shared with the
|
|
17
19
|
* OpenCode 2 sidebar: each window reads `remainingPercent + resetAt` from
|
|
@@ -48,49 +50,19 @@ import type {
|
|
|
48
50
|
TuiThemeCurrent,
|
|
49
51
|
} from "@opencode-ai/plugin/tui"
|
|
50
52
|
import { createSlot } from "@opentui/solid"
|
|
51
|
-
import {
|
|
52
|
-
createMemo,
|
|
53
|
-
createSignal,
|
|
54
|
-
For,
|
|
55
|
-
type JSX,
|
|
56
|
-
onCleanup,
|
|
57
|
-
onMount,
|
|
58
|
-
Show,
|
|
59
|
-
} from "solid-js"
|
|
53
|
+
import { createSignal, type JSX, onCleanup, onMount } from "solid-js"
|
|
60
54
|
|
|
61
|
-
import {
|
|
62
|
-
formatQuota,
|
|
63
|
-
isQuotaStale,
|
|
64
|
-
type ProjectedLimit,
|
|
65
|
-
type ProjectedQuota,
|
|
66
|
-
} from "./common-auth-embedded/quota/index.js"
|
|
67
55
|
import { getRpcDir } from "./rpc/rpc-dir.js"
|
|
68
|
-
import {
|
|
69
|
-
readSidebarState,
|
|
70
|
-
type SidebarAccountState,
|
|
71
|
-
type SidebarStateV1,
|
|
72
|
-
} from "./sidebar-state.js"
|
|
56
|
+
import { readSidebarState, type SidebarStateV1 } from "./sidebar-state.js"
|
|
73
57
|
import { createTuiFileLogger, type TuiLogger } from "./tui/file-logger.js"
|
|
74
58
|
import {
|
|
75
59
|
createV1MenuTransport,
|
|
76
60
|
dispatchV1Notification,
|
|
77
61
|
type V1Notification,
|
|
78
62
|
} from "./tui/host-v1.tsx"
|
|
79
|
-
import {
|
|
80
|
-
ASSUMED_CONTENT_WIDTH,
|
|
81
|
-
accountWindows,
|
|
82
|
-
fitLabel,
|
|
83
|
-
GROUP_NAMES,
|
|
84
|
-
QUOTA_ORDER,
|
|
85
|
-
QuotaAccountBlock,
|
|
86
|
-
type QuotaPalette,
|
|
87
|
-
type QuotaTone,
|
|
88
|
-
quotaTone,
|
|
89
|
-
} from "./tui/quota-layout.tsx"
|
|
90
|
-
import { routeLineFits } from "./tui/route-layout.js"
|
|
63
|
+
import { type FrameRoute, SidebarFrame } from "./tui/sidebar-frame.tsx"
|
|
91
64
|
import {
|
|
92
65
|
type AntigravityAuthTuiPrefs,
|
|
93
|
-
type AppearancePrefs,
|
|
94
66
|
computeEffectiveOrder,
|
|
95
67
|
DEFAULT_PREFS,
|
|
96
68
|
DEFAULT_SLOT_ORDER,
|
|
@@ -106,8 +78,6 @@ const ID = 'cortexkit.antigravity-auth'
|
|
|
106
78
|
const POLL_INTERVAL_MS = 2000
|
|
107
79
|
const RPC_POLL_MS = 500
|
|
108
80
|
|
|
109
|
-
const SINGLE_BORDER = { type: 'single' } as any
|
|
110
|
-
|
|
111
81
|
// Read package metadata from either the raw src/ entry or its generated
|
|
112
82
|
// src/tui-compiled/ counterpart. Avoid a JSON import because package.json sits
|
|
113
83
|
// outside the declaration build's rootDir.
|
|
@@ -153,8 +123,9 @@ const MAX_NOTIFICATION_CURSORS = 256
|
|
|
153
123
|
//
|
|
154
124
|
// The sidebar pulls its colors from the live host theme (`api.theme.current`
|
|
155
125
|
// — a Solid-friendly getter that re-emits when the user switches theme).
|
|
156
|
-
//
|
|
157
|
-
//
|
|
126
|
+
// `tui/sidebar-frame.tsx` reads every color from this theme: tone colors
|
|
127
|
+
// through `toneColor(theme, tone)` with its sibling-token `??` fallbacks,
|
|
128
|
+
// the rest straight from their theme field. So the sidebar tracks the
|
|
158
129
|
// active theme and never hardcodes an ANSI literal.
|
|
159
130
|
//
|
|
160
131
|
// `FALLBACK_THEME` is the safety net for tests and any future host that
|
|
@@ -162,9 +133,7 @@ const MAX_NOTIFICATION_CURSORS = 256
|
|
|
162
133
|
// uses are populated; the rest of the TuiThemeCurrent fields are left
|
|
163
134
|
// undefined and the `??` chain in `toneColor` falls through cleanly.
|
|
164
135
|
|
|
165
|
-
type Tone = QuotaTone
|
|
166
136
|
type Theme = TuiThemeCurrent
|
|
167
|
-
type ThemeColor = Theme['text']
|
|
168
137
|
|
|
169
138
|
const FALLBACK_THEME = {
|
|
170
139
|
primary: '#3b82f6',
|
|
@@ -222,36 +191,6 @@ const FALLBACK_THEME = {
|
|
|
222
191
|
thinkingOpacity: 0.6,
|
|
223
192
|
} as unknown as Theme
|
|
224
193
|
|
|
225
|
-
// Mirror the fleet siblings' tone chain: every tone falls through to a
|
|
226
|
-
// sibling token, so a sparse custom theme still renders readably.
|
|
227
|
-
function toneColor(theme: Theme, tone: Tone): ThemeColor {
|
|
228
|
-
switch (tone) {
|
|
229
|
-
case 'ok':
|
|
230
|
-
return theme.success ?? theme.accent
|
|
231
|
-
case 'warn':
|
|
232
|
-
return theme.warning ?? theme.accent
|
|
233
|
-
case 'err':
|
|
234
|
-
return theme.error ?? theme.accent
|
|
235
|
-
case 'muted':
|
|
236
|
-
return theme.textMuted ?? theme.text
|
|
237
|
-
case 'accent':
|
|
238
|
-
return theme.accent ?? theme.text
|
|
239
|
-
default:
|
|
240
|
-
return theme.text
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// The shared quota layout reads its colors through this palette. Muted text
|
|
245
|
-
// and the account label read `textMuted` and `text` straight from the theme,
|
|
246
|
-
// without the `toneColor` fallback chain.
|
|
247
|
-
function themePalette(theme: () => Theme): QuotaPalette {
|
|
248
|
-
return {
|
|
249
|
-
text: () => theme().text,
|
|
250
|
-
muted: () => theme().textMuted,
|
|
251
|
-
tone: (tone) => toneColor(theme(), tone),
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
194
|
export interface SidebarPanelProps {
|
|
256
195
|
/** Override the file the TUI polls. Defaults to `getSidebarStateFile()`. */
|
|
257
196
|
stateFile?: string
|
|
@@ -395,28 +334,6 @@ function getSidebarController(): SidebarController {
|
|
|
395
334
|
return sidebarController
|
|
396
335
|
}
|
|
397
336
|
|
|
398
|
-
// --- Shared helpers (fleet shape, antigravity data) ------------------------
|
|
399
|
-
|
|
400
|
-
// Render a "reset in Nm/Nh/NdNh" string from an epoch-ms reset time.
|
|
401
|
-
// Empty string when no resetAt is cached. The fleet's `formatResetIn`
|
|
402
|
-
// reads ISO strings; Antigravity persists resetAt as a numeric epoch, so
|
|
403
|
-
// the wrapper adapts to that without changing the shape of the output.
|
|
404
|
-
function formatResetIn(resetAt: number | undefined, now: () => number): string {
|
|
405
|
-
if (!resetAt) return ''
|
|
406
|
-
const ms = resetAt - now()
|
|
407
|
-
if (ms <= 0) return 'now'
|
|
408
|
-
const mins = Math.floor(ms / 60_000)
|
|
409
|
-
if (mins < 60) return `${mins}m`
|
|
410
|
-
const hrs = Math.floor(mins / 60)
|
|
411
|
-
if (hrs < 24) {
|
|
412
|
-
const rm = mins % 60
|
|
413
|
-
return rm > 0 ? `${hrs}h${rm}m` : `${hrs}h`
|
|
414
|
-
}
|
|
415
|
-
const days = Math.floor(hrs / 24)
|
|
416
|
-
const rh = hrs % 24
|
|
417
|
-
return rh > 0 ? `${days}d${rh}h` : `${days}d`
|
|
418
|
-
}
|
|
419
|
-
|
|
420
337
|
function formatError(value: unknown): string {
|
|
421
338
|
if (value instanceof Error) return value.message
|
|
422
339
|
try {
|
|
@@ -426,161 +343,6 @@ function formatError(value: unknown): string {
|
|
|
426
343
|
}
|
|
427
344
|
}
|
|
428
345
|
|
|
429
|
-
// --- Fleet components (adapted to antigravity data) ------------------------
|
|
430
|
-
|
|
431
|
-
// Section header — fleet pattern: bold title, themed text color, top margin
|
|
432
|
-
// for vertical breathing room between sections.
|
|
433
|
-
function SectionHeader(props: {
|
|
434
|
-
theme: () => Theme
|
|
435
|
-
title: string
|
|
436
|
-
}): JSX.Element {
|
|
437
|
-
return (
|
|
438
|
-
<box width='100%' marginTop={1}>
|
|
439
|
-
<text fg={toneColor(props.theme(), 'text')}>
|
|
440
|
-
<b>{props.title}</b>
|
|
441
|
-
</text>
|
|
442
|
-
</box>
|
|
443
|
-
)
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// Fleet StatRow: muted label left, value (optionally tone-tinted, bold)
|
|
447
|
-
// right. Mirrors the layout the Claude/Codex sidebars use for routing
|
|
448
|
-
// rows, plan rows, and "resets N" rows.
|
|
449
|
-
function StatRow(props: {
|
|
450
|
-
theme: () => Theme
|
|
451
|
-
label: string
|
|
452
|
-
value: string
|
|
453
|
-
tone?: Tone
|
|
454
|
-
}): JSX.Element {
|
|
455
|
-
return (
|
|
456
|
-
<box width='100%' flexDirection='row' justifyContent='space-between'>
|
|
457
|
-
<text fg={props.theme().textMuted}>{props.label}</text>
|
|
458
|
-
<text fg={toneColor(props.theme(), props.tone ?? 'text')}>
|
|
459
|
-
<b>{props.value}</b>
|
|
460
|
-
</text>
|
|
461
|
-
</box>
|
|
462
|
-
)
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// Fleet CollapsedRow: muted label left, caller-supplied value right. The
|
|
466
|
-
// collapsed view renders one row for every visible account. The caller sizes
|
|
467
|
-
// both sides to the measured width, so neither side may wrap.
|
|
468
|
-
function CollapsedRow(props: {
|
|
469
|
-
theme: () => Theme
|
|
470
|
-
label: string
|
|
471
|
-
children: JSX.Element
|
|
472
|
-
}): JSX.Element {
|
|
473
|
-
return (
|
|
474
|
-
<box width='100%' flexDirection='row' justifyContent='space-between'>
|
|
475
|
-
<text flexShrink={0} wrapMode='none' fg={props.theme().textMuted}>
|
|
476
|
-
{props.label}
|
|
477
|
-
</text>
|
|
478
|
-
{props.children}
|
|
479
|
-
</box>
|
|
480
|
-
)
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// One account in the Quota section: the shared quota block, with the status
|
|
484
|
-
// word computed from the sidebar file's account state. Status word priorities
|
|
485
|
-
// (first match wins):
|
|
486
|
-
// - `off` when the account is disabled
|
|
487
|
-
// - `cooling <wait>` when cooldownUntil is still in the future
|
|
488
|
-
// - `active` when current === true
|
|
489
|
-
// - `idle` for the fallback (current === false) case
|
|
490
|
-
function AccountBlock(props: {
|
|
491
|
-
theme: () => Theme
|
|
492
|
-
appearance: AppearancePrefs
|
|
493
|
-
account: SidebarAccountState
|
|
494
|
-
now: () => number
|
|
495
|
-
width: () => number
|
|
496
|
-
active?: boolean
|
|
497
|
-
marginTop?: number
|
|
498
|
-
}): JSX.Element {
|
|
499
|
-
const active = () => props.active ?? props.account.current
|
|
500
|
-
const cooldownMs = (): number => {
|
|
501
|
-
const cd = props.account.cooldownUntil
|
|
502
|
-
if (typeof cd !== 'number') return 0
|
|
503
|
-
return Math.max(0, cd - props.now())
|
|
504
|
-
}
|
|
505
|
-
const statusWord = (): string => {
|
|
506
|
-
if (!props.account.enabled) return 'off'
|
|
507
|
-
if (cooldownMs() > 0) return `cooling ${formatWait(cooldownMs())}`
|
|
508
|
-
return active() ? 'active' : 'idle'
|
|
509
|
-
}
|
|
510
|
-
const statusTone = (): Tone => {
|
|
511
|
-
if (!props.account.enabled) return 'muted'
|
|
512
|
-
if (cooldownMs() > 0) return 'warn'
|
|
513
|
-
return active() ? 'ok' : 'muted'
|
|
514
|
-
}
|
|
515
|
-
return (
|
|
516
|
-
<QuotaAccountBlock
|
|
517
|
-
palette={themePalette(props.theme)}
|
|
518
|
-
appearance={props.appearance}
|
|
519
|
-
account={props.account}
|
|
520
|
-
status={statusWord()}
|
|
521
|
-
statusTone={statusTone()}
|
|
522
|
-
now={props.now}
|
|
523
|
-
width={props.width}
|
|
524
|
-
marginTop={props.marginTop}
|
|
525
|
-
/>
|
|
526
|
-
)
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// Sidebar snapshots store quota values as percentages and epoch-millisecond
|
|
530
|
-
// reset times. Adapt those values to the shared projection so common-auth, not
|
|
531
|
-
// the renderer, decides how the narrow line reads.
|
|
532
|
-
function sidebarQuotaProjection(
|
|
533
|
-
account: SidebarAccountState,
|
|
534
|
-
now: number,
|
|
535
|
-
): ProjectedQuota | undefined {
|
|
536
|
-
const limits: ProjectedLimit[] = []
|
|
537
|
-
for (const { key, reading } of accountWindows(account, now)) {
|
|
538
|
-
const { checkedAt, remainingPercent, resetAt, window } = reading
|
|
539
|
-
if (
|
|
540
|
-
typeof checkedAt !== 'number' ||
|
|
541
|
-
!Number.isFinite(checkedAt) ||
|
|
542
|
-
checkedAt < 0 ||
|
|
543
|
-
!Number.isFinite(remainingPercent)
|
|
544
|
-
)
|
|
545
|
-
continue
|
|
546
|
-
const resetsAt =
|
|
547
|
-
typeof resetAt === 'number' &&
|
|
548
|
-
Number.isFinite(resetAt) &&
|
|
549
|
-
Math.abs(resetAt) <= 8.64e15
|
|
550
|
-
? new Date(resetAt).toISOString()
|
|
551
|
-
: undefined
|
|
552
|
-
limits.push({
|
|
553
|
-
scope: key,
|
|
554
|
-
label: GROUP_NAMES[key],
|
|
555
|
-
kind: 'reading',
|
|
556
|
-
checkedAt,
|
|
557
|
-
remainingPercent: Math.max(0, Math.min(100, remainingPercent)),
|
|
558
|
-
...(window
|
|
559
|
-
? { windowMinutes: window === 'weekly' ? 7 * 24 * 60 : 5 * 60 }
|
|
560
|
-
: {}),
|
|
561
|
-
...(resetsAt ? { resetsAt } : {}),
|
|
562
|
-
})
|
|
563
|
-
}
|
|
564
|
-
if (limits.length === 0) return undefined
|
|
565
|
-
return {
|
|
566
|
-
scope: 'all',
|
|
567
|
-
limits,
|
|
568
|
-
checkedAt: Math.min(...limits.map((limit) => limit.checkedAt)),
|
|
569
|
-
groups: QUOTA_ORDER.map((scope) => ({
|
|
570
|
-
scope,
|
|
571
|
-
label: GROUP_NAMES[scope],
|
|
572
|
-
})),
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
function formatWait(ms: number): string {
|
|
577
|
-
const seconds = Math.ceil(ms / 1000)
|
|
578
|
-
if (seconds < 60) return `${seconds}s`
|
|
579
|
-
const minutes = Math.floor(seconds / 60)
|
|
580
|
-
const remaining = seconds % 60
|
|
581
|
-
return remaining > 0 ? `${minutes}m ${remaining}s` : `${minutes}m`
|
|
582
|
-
}
|
|
583
|
-
|
|
584
346
|
// --- SidebarPanel ----------------------------------------------------------
|
|
585
347
|
|
|
586
348
|
export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
|
|
@@ -625,27 +387,9 @@ export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
|
|
|
625
387
|
onCleanup(() => clearInterval(interval))
|
|
626
388
|
})
|
|
627
389
|
|
|
628
|
-
const hasData = () => state().loaded.accounts.length > 0
|
|
629
|
-
const backoffActive = () => {
|
|
630
|
-
const until = state().loaded.quotaBackoffUntil
|
|
631
|
-
return typeof until === 'number' && until > now()
|
|
632
|
-
}
|
|
633
390
|
const lastError = () => state().lastError ?? state().loaded.lastError
|
|
634
|
-
const degraded = () => backoffActive() || !!lastError()
|
|
635
|
-
// Honors sections.fallbackAccounts. Both the expanded (AccountBlock list)
|
|
636
|
-
// and the collapsed (CollapsedRow list) paths use the same filter so the
|
|
637
|
-
// user sees the same account set in either mode.
|
|
638
|
-
const visibleAccounts = () => {
|
|
639
|
-
const showFallback = prefs().sections.fallbackAccounts
|
|
640
|
-
if (showFallback) return state().loaded.accounts
|
|
641
|
-
return state().loaded.accounts.filter((account) => account.current)
|
|
642
|
-
}
|
|
643
391
|
|
|
644
|
-
const currentRoute = (): {
|
|
645
|
-
strategy?: 'sticky' | 'round-robin' | 'hybrid'
|
|
646
|
-
family: string
|
|
647
|
-
style: string
|
|
648
|
-
} | null => {
|
|
392
|
+
const currentRoute = (): FrameRoute | null => {
|
|
649
393
|
const routes = state().loaded.activeRouting
|
|
650
394
|
const entry = props.sessionId
|
|
651
395
|
? routes[props.sessionId]
|
|
@@ -658,261 +402,19 @@ export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
|
|
|
658
402
|
}
|
|
659
403
|
}
|
|
660
404
|
|
|
661
|
-
// The route on one `Route <value>` line when it fits, else one line per
|
|
662
|
-
// part with the strategy last.
|
|
663
|
-
const routeValue = (route: {
|
|
664
|
-
strategy?: string
|
|
665
|
-
family: string
|
|
666
|
-
style: string
|
|
667
|
-
}): string =>
|
|
668
|
-
`${route.strategy ? `${route.strategy} · ` : ''}${route.family}: ${route.style}`
|
|
669
|
-
const routeLines = (route: {
|
|
670
|
-
strategy?: string
|
|
671
|
-
family: string
|
|
672
|
-
style: string
|
|
673
|
-
}): string[] =>
|
|
674
|
-
[`${route.family}: ${route.style}`, route.strategy ?? ''].filter(
|
|
675
|
-
(line) => line !== '',
|
|
676
|
-
)
|
|
677
|
-
|
|
678
|
-
// The width available to content: the header row spans the panel inside
|
|
679
|
-
// its border and padding. Layout reports it during a render pass, so the
|
|
680
|
-
// signal is updated afterwards rather than rebuilding rows mid-pass.
|
|
681
|
-
const [contentWidth, setContentWidth] = createSignal(ASSUMED_CONTENT_WIDTH)
|
|
682
|
-
let headerRow: { width: number } | undefined
|
|
683
|
-
const measureContentWidth = (): void => {
|
|
684
|
-
const width = headerRow?.width
|
|
685
|
-
if (typeof width !== 'number' || width <= 0) return
|
|
686
|
-
queueMicrotask(() => {
|
|
687
|
-
if (width !== contentWidth()) setContentWidth(width)
|
|
688
|
-
})
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
// Header badge: ▼/▶ {label}. The fleet shows the version string on the
|
|
692
|
-
// right when no degraded state is present; the antigravity adapter keeps
|
|
693
|
-
// that right-alignment and surfaces `degraded` as a "LIMITED" badge
|
|
694
|
-
// instead of the "1/1 ready" count the previous revision rendered.
|
|
695
|
-
const headerLabel = () => {
|
|
696
|
-
const name = prefs().header.label
|
|
697
|
-
return !hasData() ? name : collapsed() ? `\u25b6 ${name}` : `\u25bc ${name}`
|
|
698
|
-
}
|
|
699
|
-
|
|
700
405
|
return (
|
|
701
|
-
<
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
{
|
|
712
|
-
|
|
713
|
-
ref={(element) => {
|
|
714
|
-
headerRow = element
|
|
715
|
-
}}
|
|
716
|
-
onSizeChange={measureContentWidth}
|
|
717
|
-
width='100%'
|
|
718
|
-
flexDirection='row'
|
|
719
|
-
justifyContent='space-between'
|
|
720
|
-
alignItems='center'
|
|
721
|
-
onMouseDown={() => {
|
|
722
|
-
// Mirror the fleet guard: only toggle when there is data to expand
|
|
723
|
-
// into. Without this a click on the empty-awaiting header would just
|
|
724
|
-
// toggle the affordance for nothing.
|
|
725
|
-
if (hasData()) controller.toggleCollapsed()
|
|
726
|
-
}}
|
|
727
|
-
>
|
|
728
|
-
<box paddingLeft={1} paddingRight={1} backgroundColor={theme().accent}>
|
|
729
|
-
<text fg={theme().background}>
|
|
730
|
-
<b>{headerLabel()}</b>
|
|
731
|
-
</text>
|
|
732
|
-
</box>
|
|
733
|
-
<Show
|
|
734
|
-
when={degraded()}
|
|
735
|
-
fallback={
|
|
736
|
-
<Show when={prefs().header.showVersion && PLUGIN_VERSION !== ''}>
|
|
737
|
-
<text fg={theme().textMuted}>{`v${PLUGIN_VERSION}`}</text>
|
|
738
|
-
</Show>
|
|
739
|
-
}
|
|
740
|
-
>
|
|
741
|
-
<box
|
|
742
|
-
paddingLeft={1}
|
|
743
|
-
paddingRight={1}
|
|
744
|
-
backgroundColor={theme().warning}
|
|
745
|
-
>
|
|
746
|
-
<text fg={theme().background}>
|
|
747
|
-
<b>{'LIMITED'}</b>
|
|
748
|
-
</text>
|
|
749
|
-
</box>
|
|
750
|
-
</Show>
|
|
751
|
-
</box>
|
|
752
|
-
|
|
753
|
-
{/* Collapsed: one measured, non-wrapping row for each visible account. */}
|
|
754
|
-
<Show when={collapsed() && hasData()}>
|
|
755
|
-
<For each={visibleAccounts()}>
|
|
756
|
-
{(account) => {
|
|
757
|
-
const unavailable = () =>
|
|
758
|
-
!account.enabled ||
|
|
759
|
-
(account.cooldownUntil != null && account.cooldownUntil > now())
|
|
760
|
-
const line = createMemo(() => {
|
|
761
|
-
const currentTime = now()
|
|
762
|
-
const projection = sidebarQuotaProjection(account, currentTime)
|
|
763
|
-
const text = formatQuota(projection, {
|
|
764
|
-
now: currentTime,
|
|
765
|
-
form: 'narrow',
|
|
766
|
-
})
|
|
767
|
-
const remaining = projection?.limits.length
|
|
768
|
-
? Math.min(
|
|
769
|
-
...projection.limits.map(
|
|
770
|
-
(limit) => limit.remainingPercent ?? 100,
|
|
771
|
-
),
|
|
772
|
-
)
|
|
773
|
-
: undefined
|
|
774
|
-
const tone =
|
|
775
|
-
remaining === undefined
|
|
776
|
-
? 'muted'
|
|
777
|
-
: quotaTone(100 - remaining, prefs().appearance)
|
|
778
|
-
const stale = isQuotaStale(projection, { now: currentTime })
|
|
779
|
-
const dot = unavailable() ? ' ⊘' : ' ●'
|
|
780
|
-
const width = contentWidth()
|
|
781
|
-
// Keep a complete shared line or omit it; a partial quota can
|
|
782
|
-
// make an account look as if it has less remaining.
|
|
783
|
-
const showQuota = text.length <= width
|
|
784
|
-
const showDot =
|
|
785
|
-
dot.length <= width &&
|
|
786
|
-
(!showQuota || text.length + dot.length <= width)
|
|
787
|
-
const rightWidth =
|
|
788
|
-
(showQuota ? text.length : 0) + (showDot ? dot.length : 0)
|
|
789
|
-
const labelWidth = Math.max(0, width - rightWidth - 1)
|
|
790
|
-
return {
|
|
791
|
-
dot,
|
|
792
|
-
label: fitLabel(account.label, labelWidth),
|
|
793
|
-
showDot,
|
|
794
|
-
showQuota,
|
|
795
|
-
stale,
|
|
796
|
-
text,
|
|
797
|
-
tone,
|
|
798
|
-
}
|
|
799
|
-
})
|
|
800
|
-
const quotaColor = () =>
|
|
801
|
-
line().stale ? theme().textMuted : toneColor(theme(), line().tone)
|
|
802
|
-
const dotColor = () =>
|
|
803
|
-
line().stale
|
|
804
|
-
? theme().textMuted
|
|
805
|
-
: toneColor(theme(), unavailable() ? 'err' : line().tone)
|
|
806
|
-
return (
|
|
807
|
-
<CollapsedRow theme={theme} label={line().label}>
|
|
808
|
-
<box flexDirection='row' flexShrink={0}>
|
|
809
|
-
<Show when={line().showQuota}>
|
|
810
|
-
<text flexShrink={0} wrapMode='none' fg={quotaColor()}>
|
|
811
|
-
<b>{line().text}</b>
|
|
812
|
-
</text>
|
|
813
|
-
</Show>
|
|
814
|
-
<Show when={line().showDot}>
|
|
815
|
-
<text flexShrink={0} wrapMode='none' fg={dotColor()}>
|
|
816
|
-
{line().dot}
|
|
817
|
-
</text>
|
|
818
|
-
</Show>
|
|
819
|
-
</box>
|
|
820
|
-
</CollapsedRow>
|
|
821
|
-
)
|
|
822
|
-
}}
|
|
823
|
-
</For>
|
|
824
|
-
</Show>
|
|
825
|
-
|
|
826
|
-
{/* Expanded: full sections. Also render when there's no data so the
|
|
827
|
-
sidebar can never go blank if data clears while collapsed. */}
|
|
828
|
-
<Show when={!collapsed() || !hasData()}>
|
|
829
|
-
<Show
|
|
830
|
-
when={hasData()}
|
|
831
|
-
fallback={
|
|
832
|
-
<box marginTop={1} width='100%'>
|
|
833
|
-
<text fg={theme().textMuted}>{'Waiting for quota\u2026'}</text>
|
|
834
|
-
</box>
|
|
835
|
-
}
|
|
836
|
-
>
|
|
837
|
-
{/* Quota */}
|
|
838
|
-
<Show when={prefs().sections.quota}>
|
|
839
|
-
<SectionHeader theme={theme} title='Quota' />
|
|
840
|
-
<For each={visibleAccounts()}>
|
|
841
|
-
{(account, index) => (
|
|
842
|
-
<AccountBlock
|
|
843
|
-
theme={theme}
|
|
844
|
-
appearance={prefs().appearance}
|
|
845
|
-
account={account}
|
|
846
|
-
now={now}
|
|
847
|
-
width={contentWidth}
|
|
848
|
-
marginTop={index() === 0 ? 0 : 1}
|
|
849
|
-
/>
|
|
850
|
-
)}
|
|
851
|
-
</For>
|
|
852
|
-
</Show>
|
|
853
|
-
|
|
854
|
-
{/* Routing: the session's route, or one dim line before its first request. */}
|
|
855
|
-
<Show when={prefs().sections.routing}>
|
|
856
|
-
<SectionHeader theme={theme} title='Routing' />
|
|
857
|
-
<Show
|
|
858
|
-
when={currentRoute()}
|
|
859
|
-
fallback={
|
|
860
|
-
<text wrapMode='none' fg={theme().textMuted}>
|
|
861
|
-
{'No request yet'}
|
|
862
|
-
</text>
|
|
863
|
-
}
|
|
864
|
-
>
|
|
865
|
-
{(route) => (
|
|
866
|
-
<Show
|
|
867
|
-
when={routeLineFits(
|
|
868
|
-
'Route',
|
|
869
|
-
routeValue(route()),
|
|
870
|
-
contentWidth(),
|
|
871
|
-
)}
|
|
872
|
-
fallback={
|
|
873
|
-
<For each={routeLines(route())}>
|
|
874
|
-
{(line) => (
|
|
875
|
-
<text wrapMode='none' fg={toneColor(theme(), 'accent')}>
|
|
876
|
-
<b>{line}</b>
|
|
877
|
-
</text>
|
|
878
|
-
)}
|
|
879
|
-
</For>
|
|
880
|
-
}
|
|
881
|
-
>
|
|
882
|
-
<StatRow
|
|
883
|
-
theme={theme}
|
|
884
|
-
label='Route'
|
|
885
|
-
value={routeValue(route())}
|
|
886
|
-
tone='accent'
|
|
887
|
-
/>
|
|
888
|
-
</Show>
|
|
889
|
-
)}
|
|
890
|
-
</Show>
|
|
891
|
-
</Show>
|
|
892
|
-
|
|
893
|
-
{/* Health — only when something is wrong AND sections.health is true */}
|
|
894
|
-
<Show when={degraded() && prefs().sections.health}>
|
|
895
|
-
<SectionHeader theme={theme} title='Health' />
|
|
896
|
-
<Show when={backoffActive()}>
|
|
897
|
-
<StatRow
|
|
898
|
-
theme={theme}
|
|
899
|
-
label='Quota API'
|
|
900
|
-
value={`backoff ${formatResetIn(state().loaded.quotaBackoffUntil, now)}`}
|
|
901
|
-
tone='warn'
|
|
902
|
-
/>
|
|
903
|
-
</Show>
|
|
904
|
-
<Show when={lastError()}>
|
|
905
|
-
<StatRow
|
|
906
|
-
theme={theme}
|
|
907
|
-
label='Last error'
|
|
908
|
-
value={lastError() ?? ''}
|
|
909
|
-
tone='err'
|
|
910
|
-
/>
|
|
911
|
-
</Show>
|
|
912
|
-
</Show>
|
|
913
|
-
</Show>
|
|
914
|
-
</Show>
|
|
915
|
-
</box>
|
|
406
|
+
<SidebarFrame
|
|
407
|
+
theme={theme}
|
|
408
|
+
settings={prefs}
|
|
409
|
+
version={PLUGIN_VERSION}
|
|
410
|
+
collapsed={collapsed}
|
|
411
|
+
onToggleCollapsed={controller.toggleCollapsed}
|
|
412
|
+
accounts={() => state().loaded.accounts}
|
|
413
|
+
route={currentRoute}
|
|
414
|
+
quotaBackoffUntil={() => state().loaded.quotaBackoffUntil}
|
|
415
|
+
lastError={lastError}
|
|
416
|
+
now={now}
|
|
417
|
+
/>
|
|
916
418
|
)
|
|
917
419
|
}
|
|
918
420
|
|