@cortexkit/opencode-antigravity-auth 3.0.37 → 3.0.39
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/README.md +1 -1
- package/dist/cli.js +608 -321
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +106 -38
- package/dist/index.js +815 -386
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +122 -46
- package/dist/server.js +1056 -492
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/auth-method-labels.d.ts +2 -0
- package/dist/src/auth-method-labels.d.ts.map +1 -1
- package/dist/src/auth-method-labels.js +2 -0
- package/dist/src/auth-method-labels.js.map +1 -1
- package/dist/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
- package/dist/src/common-auth-embedded/claustrum/availability.js +9 -1
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
- package/dist/src/common-auth-embedded/claustrum/custody.js +89 -31
- package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
- package/dist/src/common-auth-embedded/claustrum/enrollment.js +33 -2
- package/dist/src/common-auth-embedded/claustrum/host.js +11 -7
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
- package/dist/src/common-auth-embedded/fs/lock-record.js +55 -0
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
- package/dist/src/common-auth-embedded/fs/with-lock.js +19 -13
- package/dist/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
- package/dist/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
- package/dist/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
- package/dist/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
- package/dist/src/common-auth-embedded/routing-accessor/index.js +136 -5
- package/dist/src/common-auth-embedded/setup/enroll.js +2 -1
- package/dist/src/common-auth-embedded/setup/types.d.ts +1 -0
- package/dist/src/common-auth-embedded/source-output.json +72 -64
- package/dist/src/ga/server/auth.js +1 -1
- package/dist/src/ga/server/auth.js.map +1 -1
- package/dist/src/ga/server/pool-login.d.ts +9 -0
- package/dist/src/ga/server/pool-login.d.ts.map +1 -1
- package/dist/src/ga/server/pool-login.js +155 -73
- package/dist/src/ga/server/pool-login.js.map +1 -1
- package/dist/src/ga/tui/host-ga.d.ts +27 -3
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +168 -22
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/logging/provider-key-policy.d.ts +2 -0
- package/dist/src/logging/provider-key-policy.d.ts.map +1 -1
- package/dist/src/logging/provider-key-policy.js +5 -1
- package/dist/src/logging/provider-key-policy.js.map +1 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.js +1 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/ga-location-services.d.ts +1 -0
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +81 -10
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/logger.d.ts.map +1 -1
- package/dist/src/plugin/logger.js +2 -1
- package/dist/src/plugin/logger.js.map +1 -1
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +3 -1
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/setup.d.ts.map +1 -1
- package/dist/src/setup.js +2 -0
- package/dist/src/setup.js.map +1 -1
- package/dist/src/tui/file-logger.d.ts.map +1 -1
- package/dist/src/tui/file-logger.js +2 -1
- package/dist/src/tui/file-logger.js.map +1 -1
- package/dist/tui-build-map.json +27 -13
- package/dist/tui-ga-build-map.json +23 -9
- package/dist/types/src/auth-method-labels.d.ts +2 -0
- package/dist/types/src/auth-method-labels.d.ts.map +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
- package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +1 -0
- package/dist/types/src/ga/server/pool-login.d.ts +9 -0
- package/dist/types/src/ga/server/pool-login.d.ts.map +1 -1
- package/dist/types/src/logging/provider-key-policy.d.ts +2 -0
- package/dist/types/src/logging/provider-key-policy.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts +1 -0
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/logger.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/setup.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
- package/src/common-auth-embedded/claustrum/availability.js +9 -1
- package/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
- package/src/common-auth-embedded/claustrum/custody.js +89 -31
- package/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
- package/src/common-auth-embedded/claustrum/enrollment.js +33 -2
- package/src/common-auth-embedded/claustrum/host.js +11 -7
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/src/common-auth-embedded/claustrum/index.js +1 -1
- package/src/common-auth-embedded/fs/lock-record.js +55 -0
- package/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
- package/src/common-auth-embedded/fs/with-lock.js +19 -13
- package/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
- package/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
- package/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
- package/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
- package/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
- package/src/common-auth-embedded/routing-accessor/index.js +136 -5
- package/src/common-auth-embedded/setup/enroll.js +2 -1
- package/src/common-auth-embedded/setup/types.d.ts +1 -0
- package/src/common-auth-embedded/source-output.json +72 -64
- package/src/tui/file-logger.ts +5 -1
- package/src/tui-compiled/common-auth-embedded/quota-sidebar/index.js +36 -674
- package/src/tui-compiled/logging/provider-key-policy.js +4 -1
- package/src/tui-compiled/shared/a75d0d866c227b3f-index.js +678 -0
- package/src/tui-compiled/tui/file-logger.js +5 -1
- package/src/tui-ga-compiled/host-ga.js +148 -23
- package/src/tui-ga-compiled/shared/a75d0d866c227b3f-index.js +678 -0
- package/src/tui-ga-compiled/shared/e4ec36f367492969-index.js +36 -674
- package/src/tui-ga-raw/host-ga.tsx +199 -24
- package/src/tui-ga-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
- package/src/tui-ga-raw/shared/e4ec36f367492969-index.tsx +49 -607
- package/src/tui-raw/common-auth-embedded/quota-sidebar/index.tsx +49 -607
- package/src/tui-raw/logging/provider-key-policy.js +4 -1
- package/src/tui-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
- package/src/tui-raw/tui/file-logger.js +5 -1
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
import type { RGBA } from "@opentui/core"
|
|
2
|
+
import type { JSX } from "@opentui/solid"
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
createMemo,
|
|
6
|
+
createSignal,
|
|
7
|
+
For,
|
|
8
|
+
Index,
|
|
9
|
+
mergeProps,
|
|
10
|
+
Show,
|
|
11
|
+
useContext,
|
|
12
|
+
} from "solid-js"
|
|
13
|
+
|
|
14
|
+
export type Tone =
|
|
15
|
+
| 'text'
|
|
16
|
+
| 'textMuted'
|
|
17
|
+
| 'accent'
|
|
18
|
+
| 'success'
|
|
19
|
+
| 'warning'
|
|
20
|
+
| 'error'
|
|
21
|
+
|
|
22
|
+
/** `background` is the badge's text colour when drawn on `accent`; nothing else uses it. */
|
|
23
|
+
export type SidebarTheme = Readonly<
|
|
24
|
+
Partial<
|
|
25
|
+
Record<Tone | 'background' | 'borderActive', RGBA | string | undefined>
|
|
26
|
+
>
|
|
27
|
+
>
|
|
28
|
+
|
|
29
|
+
export interface SidebarAppearance {
|
|
30
|
+
barWidth: number
|
|
31
|
+
barFilledChar: string
|
|
32
|
+
barEmptyChar: string
|
|
33
|
+
warnThreshold: number
|
|
34
|
+
errorThreshold: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface PaceView {
|
|
38
|
+
text: string
|
|
39
|
+
tone: Tone
|
|
40
|
+
/** The elapsed-window percentage, not the difference from usage. */
|
|
41
|
+
overlay?: { kind: 'reserve' | 'deficit'; percent: number }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface QuotaGroupView {
|
|
45
|
+
title?: string
|
|
46
|
+
rows: readonly { part: SidebarWindowPart; pace?: PaceView }[]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface SidebarWindowPart {
|
|
50
|
+
kind: 'window' | 'budget'
|
|
51
|
+
/** Unknown windows have no dated percentage; budgets retain their own wording. */
|
|
52
|
+
reading: 'known' | 'unknown'
|
|
53
|
+
/** The display name of a quota window, or `credits` for the budget. */
|
|
54
|
+
name: string
|
|
55
|
+
/**
|
|
56
|
+
* The label the narrow line gives this item: an account-wide window keeps
|
|
57
|
+
* its name (`5h`), a model-scoped window reads as its model's short name
|
|
58
|
+
* (`Fa` for Fable, extended until names in the same reading differ), and
|
|
59
|
+
* the budget reads `cr`. For layouts too narrow for the full name.
|
|
60
|
+
*/
|
|
61
|
+
short: string
|
|
62
|
+
/** The shared figure wording, including `credits` for budget figures. */
|
|
63
|
+
figure: string
|
|
64
|
+
/** The unrounded remaining percentage, clamped to 0–100, when known. */
|
|
65
|
+
remainingPercent?: number
|
|
66
|
+
/** A bare relative reset span such as `4d`, only when the reset is future. */
|
|
67
|
+
resetIn?: string
|
|
68
|
+
/** The reading time, omitted for a window with no reading. */
|
|
69
|
+
checkedAt?: number
|
|
70
|
+
/** Whether the reset followed this reading and has arrived by `now`. */
|
|
71
|
+
resetSinceReading: boolean
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface AccountView {
|
|
75
|
+
id: string
|
|
76
|
+
label: string
|
|
77
|
+
titleSuffix?: string
|
|
78
|
+
status: { text: string; tone: Tone }
|
|
79
|
+
blocked: boolean
|
|
80
|
+
indicatorTone: Tone
|
|
81
|
+
/**
|
|
82
|
+
* Whether any window has a known reading. Without one, the collapsed row
|
|
83
|
+
* shows `emptyQuotaText.collapsed` instead of `collapsedQuotaText`.
|
|
84
|
+
*/
|
|
85
|
+
hasQuota: boolean
|
|
86
|
+
/** The collapsed row's quota text, already narrowed. */
|
|
87
|
+
collapsedQuotaText?: string
|
|
88
|
+
/** The age line under the windows, such as `checked 4m ago`. */
|
|
89
|
+
quotaAge?: string
|
|
90
|
+
groups: readonly QuotaGroupView[]
|
|
91
|
+
emptyQuotaText?: { expanded: string; collapsed: string }
|
|
92
|
+
/** Presentation decided by the plugin, never inferred from status or freshness. */
|
|
93
|
+
collapsed?: { quotaTone?: Tone; muted?: boolean }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface SidebarFrameProps {
|
|
97
|
+
header: { badge: string; version?: string }
|
|
98
|
+
accounts: readonly AccountView[]
|
|
99
|
+
theme?: SidebarTheme
|
|
100
|
+
appearance: SidebarAppearance
|
|
101
|
+
showQuota: boolean
|
|
102
|
+
now: number
|
|
103
|
+
collapsed: boolean
|
|
104
|
+
onToggle: () => void
|
|
105
|
+
beforeQuota?: (account: AccountView) => JSX.Element
|
|
106
|
+
afterQuota?: (account: AccountView) => JSX.Element
|
|
107
|
+
sections?: () => JSX.Element
|
|
108
|
+
collapsedSections?: () => JSX.Element
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type FrameContextProps = Omit<SidebarFrameProps, 'theme'> & {
|
|
112
|
+
theme: SidebarTheme
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const FrameContext = createContext<FrameContextProps>()
|
|
116
|
+
|
|
117
|
+
function frameContext(): FrameContextProps {
|
|
118
|
+
const context = useContext(FrameContext)
|
|
119
|
+
if (!context)
|
|
120
|
+
throw new Error('Sidebar primitives must be inside SidebarFrame')
|
|
121
|
+
return context
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function displayWidth(text: string): number {
|
|
125
|
+
const bun = (
|
|
126
|
+
globalThis as { Bun?: { stringWidth?: (text: string) => number } }
|
|
127
|
+
).Bun
|
|
128
|
+
return bun?.stringWidth ? bun.stringWidth(text) : Array.from(text).length
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function fitText(text: string, columns: number): string {
|
|
132
|
+
if (displayWidth(text) <= columns) return text
|
|
133
|
+
if (columns < 1) return ''
|
|
134
|
+
let kept = ''
|
|
135
|
+
let used = 0
|
|
136
|
+
for (const char of text) {
|
|
137
|
+
const width = displayWidth(char)
|
|
138
|
+
if (used + width > columns - 1) break
|
|
139
|
+
kept += char
|
|
140
|
+
used += width
|
|
141
|
+
}
|
|
142
|
+
return `${kept}\u2026`
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** A heading and its plugin-owned rows, with the frame's section spacing. */
|
|
146
|
+
export function SidebarSection(props: {
|
|
147
|
+
title: string
|
|
148
|
+
children?: JSX.Element
|
|
149
|
+
}) {
|
|
150
|
+
const context = frameContext()
|
|
151
|
+
return (
|
|
152
|
+
<>
|
|
153
|
+
<box width='100%' marginTop={1}>
|
|
154
|
+
<text fg={context.theme.text}>
|
|
155
|
+
<b>{props.title}</b>
|
|
156
|
+
</text>
|
|
157
|
+
</box>
|
|
158
|
+
{props.children}
|
|
159
|
+
</>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Keep labels whole and reserve one blank cell before an ellipsized value. */
|
|
164
|
+
export function SidebarStatRow(props: {
|
|
165
|
+
label: string
|
|
166
|
+
value: string
|
|
167
|
+
tone?: Tone
|
|
168
|
+
}) {
|
|
169
|
+
const context = frameContext()
|
|
170
|
+
const [width, setWidth] = createSignal(0)
|
|
171
|
+
let row: { width: number } | undefined
|
|
172
|
+
const value = () =>
|
|
173
|
+
width() <= 0
|
|
174
|
+
? props.value
|
|
175
|
+
: fitText(props.value, width() - displayWidth(props.label) - 1)
|
|
176
|
+
return (
|
|
177
|
+
<box
|
|
178
|
+
ref={(element: { width: number }) => {
|
|
179
|
+
row = element
|
|
180
|
+
}}
|
|
181
|
+
onSizeChange={() => setWidth(row?.width ?? 0)}
|
|
182
|
+
width='100%'
|
|
183
|
+
flexDirection='row'
|
|
184
|
+
justifyContent='space-between'
|
|
185
|
+
columnGap={1}
|
|
186
|
+
>
|
|
187
|
+
<text fg={context.theme.textMuted} wrapMode='none' flexShrink={0}>
|
|
188
|
+
{props.label}
|
|
189
|
+
</text>
|
|
190
|
+
<text
|
|
191
|
+
fg={context.theme[props.tone ?? 'text']}
|
|
192
|
+
wrapMode='none'
|
|
193
|
+
flexShrink={1}
|
|
194
|
+
>
|
|
195
|
+
<b>{value()}</b>
|
|
196
|
+
</text>
|
|
197
|
+
</box>
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function SidebarTextRow(props: {
|
|
202
|
+
text: string
|
|
203
|
+
tone?: Tone
|
|
204
|
+
wrapMode?: JSX.IntrinsicElements['text']['wrapMode']
|
|
205
|
+
}) {
|
|
206
|
+
const context = frameContext()
|
|
207
|
+
return (
|
|
208
|
+
<text
|
|
209
|
+
fg={context.theme[props.tone ?? 'textMuted']}
|
|
210
|
+
wrapMode={props.wrapMode}
|
|
211
|
+
>
|
|
212
|
+
{props.text}
|
|
213
|
+
</text>
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function usageTone(used: number, appearance: SidebarAppearance): Tone {
|
|
218
|
+
if (used >= appearance.errorThreshold) return 'error'
|
|
219
|
+
if (used >= appearance.warnThreshold) return 'warning'
|
|
220
|
+
return 'success'
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function barSegments(
|
|
224
|
+
used: number,
|
|
225
|
+
appearance: SidebarAppearance,
|
|
226
|
+
pace?: PaceView,
|
|
227
|
+
) {
|
|
228
|
+
const width = appearance.barWidth
|
|
229
|
+
const cells = (pct: number) =>
|
|
230
|
+
Math.max(0, Math.min(Math.round((pct / 100) * width), width))
|
|
231
|
+
const usedCells = cells(used)
|
|
232
|
+
const tone = usageTone(used, appearance)
|
|
233
|
+
// Keep the overlay's slot even when empty so live pacing changes reuse nodes.
|
|
234
|
+
const plain = [
|
|
235
|
+
{ text: appearance.barFilledChar.repeat(usedCells), tone },
|
|
236
|
+
{ text: '', tone },
|
|
237
|
+
{ text: appearance.barEmptyChar.repeat(width - usedCells), tone },
|
|
238
|
+
]
|
|
239
|
+
const overlay = pace?.overlay
|
|
240
|
+
if (!overlay) return plain
|
|
241
|
+
const paceCells = cells(overlay.percent)
|
|
242
|
+
const lo = Math.min(usedCells, paceCells)
|
|
243
|
+
const hi = Math.max(usedCells, paceCells)
|
|
244
|
+
if (lo === hi) return plain
|
|
245
|
+
return [
|
|
246
|
+
{ text: appearance.barFilledChar.repeat(lo), tone },
|
|
247
|
+
{
|
|
248
|
+
text: (overlay.kind === 'deficit' ? '\u2593' : '\u2592').repeat(hi - lo),
|
|
249
|
+
tone:
|
|
250
|
+
overlay.kind === 'deficit' ? ('error' as const) : ('success' as const),
|
|
251
|
+
},
|
|
252
|
+
{ text: appearance.barEmptyChar.repeat(width - hi), tone },
|
|
253
|
+
]
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function QuotaRow(props: {
|
|
257
|
+
part: SidebarWindowPart
|
|
258
|
+
pace?: PaceView
|
|
259
|
+
labelWidth: number
|
|
260
|
+
barCells: number
|
|
261
|
+
resetWidth: number
|
|
262
|
+
showReset: boolean
|
|
263
|
+
}) {
|
|
264
|
+
const context = frameContext()
|
|
265
|
+
const [columns, setColumns] = createSignal(0)
|
|
266
|
+
let row: { width: number } | undefined
|
|
267
|
+
const label = () =>
|
|
268
|
+
props.part.name +
|
|
269
|
+
' '.repeat(Math.max(0, props.labelWidth - displayWidth(props.part.name)))
|
|
270
|
+
const figure = () =>
|
|
271
|
+
` ${props.part.kind === 'budget' && props.part.figure.startsWith(`${props.part.name} `) ? props.part.figure.slice(props.part.name.length + 1) : props.part.figure}`
|
|
272
|
+
const hasReading = () => props.part.reading === 'known'
|
|
273
|
+
const used = () => 100 - (props.part.remainingPercent ?? 100)
|
|
274
|
+
// Size notifications can recompute an unchanged fit after text has been flushed
|
|
275
|
+
// for the frame. Keep equal segments, and update fixed slots in place when the
|
|
276
|
+
// bar changes, rather than replacing text nodes during layout.
|
|
277
|
+
const segments = createMemo(
|
|
278
|
+
() =>
|
|
279
|
+
hasReading()
|
|
280
|
+
? barSegments(
|
|
281
|
+
used(),
|
|
282
|
+
{ ...context.appearance, barWidth: props.barCells },
|
|
283
|
+
props.pace,
|
|
284
|
+
)
|
|
285
|
+
: [],
|
|
286
|
+
undefined,
|
|
287
|
+
{
|
|
288
|
+
equals: (previous, next) =>
|
|
289
|
+
previous.length === next.length &&
|
|
290
|
+
previous.every(
|
|
291
|
+
(segment, index) =>
|
|
292
|
+
segment.text === next[index]?.text &&
|
|
293
|
+
segment.tone === next[index]?.tone,
|
|
294
|
+
),
|
|
295
|
+
},
|
|
296
|
+
)
|
|
297
|
+
const paceLine = () => {
|
|
298
|
+
const text = props.pace?.text
|
|
299
|
+
if (!text || columns() <= 0) return text
|
|
300
|
+
return fitText(text, columns() - props.labelWidth)
|
|
301
|
+
}
|
|
302
|
+
return (
|
|
303
|
+
<>
|
|
304
|
+
<box
|
|
305
|
+
ref={(element: { width: number }) => {
|
|
306
|
+
row = element
|
|
307
|
+
}}
|
|
308
|
+
onSizeChange={() => setColumns(row?.width ?? 0)}
|
|
309
|
+
width='100%'
|
|
310
|
+
flexDirection='row'
|
|
311
|
+
justifyContent='space-between'
|
|
312
|
+
>
|
|
313
|
+
<box
|
|
314
|
+
flexDirection='row'
|
|
315
|
+
flexShrink={props.part.resetSinceReading ? 1 : 0}
|
|
316
|
+
>
|
|
317
|
+
<Show when={props.labelWidth > 0}>
|
|
318
|
+
<text fg={context.theme.textMuted} wrapMode='none' flexShrink={0}>
|
|
319
|
+
{label()}
|
|
320
|
+
</text>
|
|
321
|
+
</Show>
|
|
322
|
+
<Show
|
|
323
|
+
when={hasReading()}
|
|
324
|
+
fallback={
|
|
325
|
+
<text fg={context.theme.textMuted} wrapMode='none'>
|
|
326
|
+
no reading
|
|
327
|
+
</text>
|
|
328
|
+
}
|
|
329
|
+
>
|
|
330
|
+
<Show
|
|
331
|
+
when={!props.part.resetSinceReading}
|
|
332
|
+
fallback={
|
|
333
|
+
<text fg={context.theme.textMuted} wrapMode='none'>
|
|
334
|
+
reset since last check
|
|
335
|
+
</text>
|
|
336
|
+
}
|
|
337
|
+
>
|
|
338
|
+
<Show when={props.barCells > 0}>
|
|
339
|
+
{/* Text nodes clear omitted theme colours; empty slots must not reserve a cell. */}
|
|
340
|
+
<Index each={segments()}>
|
|
341
|
+
{(segment) => (
|
|
342
|
+
<text
|
|
343
|
+
fg={context.theme[segment().tone]}
|
|
344
|
+
wrapMode='none'
|
|
345
|
+
width={segment().text ? undefined : 0}
|
|
346
|
+
>
|
|
347
|
+
{segment().text}
|
|
348
|
+
</text>
|
|
349
|
+
)}
|
|
350
|
+
</Index>
|
|
351
|
+
</Show>
|
|
352
|
+
<text
|
|
353
|
+
fg={context.theme[usageTone(used(), context.appearance)]}
|
|
354
|
+
wrapMode='none'
|
|
355
|
+
>
|
|
356
|
+
{figure()}
|
|
357
|
+
</text>
|
|
358
|
+
</Show>
|
|
359
|
+
</Show>
|
|
360
|
+
</box>
|
|
361
|
+
<Show
|
|
362
|
+
when={
|
|
363
|
+
hasReading() && props.showReset && !props.part.resetSinceReading
|
|
364
|
+
}
|
|
365
|
+
>
|
|
366
|
+
<box
|
|
367
|
+
width={props.resetWidth}
|
|
368
|
+
flexShrink={0}
|
|
369
|
+
flexDirection='row'
|
|
370
|
+
justifyContent='flex-end'
|
|
371
|
+
>
|
|
372
|
+
<Show when={props.part.resetIn}>
|
|
373
|
+
<text fg={context.theme.textMuted} wrapMode='none'>
|
|
374
|
+
{props.part.resetIn}
|
|
375
|
+
</text>
|
|
376
|
+
</Show>
|
|
377
|
+
</box>
|
|
378
|
+
</Show>
|
|
379
|
+
</box>
|
|
380
|
+
{/* A changed fitted line needs a fresh text node to draw at its new width. */}
|
|
381
|
+
<Show
|
|
382
|
+
when={hasReading() && !props.part.resetSinceReading && paceLine()}
|
|
383
|
+
keyed
|
|
384
|
+
>
|
|
385
|
+
{(line: string) => (
|
|
386
|
+
<box width='100%' flexDirection='row'>
|
|
387
|
+
<Show when={props.labelWidth > 0}>
|
|
388
|
+
<text fg={context.theme.textMuted}>
|
|
389
|
+
{''.padEnd(props.labelWidth)}
|
|
390
|
+
</text>
|
|
391
|
+
</Show>
|
|
392
|
+
<text
|
|
393
|
+
fg={context.theme[props.pace?.tone ?? 'textMuted']}
|
|
394
|
+
wrapMode='none'
|
|
395
|
+
>
|
|
396
|
+
{line}
|
|
397
|
+
</text>
|
|
398
|
+
</box>
|
|
399
|
+
)}
|
|
400
|
+
</Show>
|
|
401
|
+
</>
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function CollapsedAccountRow(props: { account: AccountView }) {
|
|
406
|
+
const context = frameContext()
|
|
407
|
+
const [width, setWidth] = createSignal(0)
|
|
408
|
+
let row: { width: number } | undefined
|
|
409
|
+
const hasQuota = () => props.account.hasQuota
|
|
410
|
+
const text = () =>
|
|
411
|
+
hasQuota()
|
|
412
|
+
? (props.account.collapsedQuotaText ?? '')
|
|
413
|
+
: (props.account.emptyQuotaText?.collapsed ?? '\u2014')
|
|
414
|
+
// Reserve an ellipsis, a separator and the trailing indicator before keeping quota.
|
|
415
|
+
const showQuota = () => width() <= 0 || displayWidth(text()) + 4 <= width()
|
|
416
|
+
const label = () => {
|
|
417
|
+
if (width() <= 0) return props.account.label
|
|
418
|
+
return fitText(
|
|
419
|
+
props.account.label,
|
|
420
|
+
width() - (showQuota() ? displayWidth(text()) + 3 : 2),
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
const muted = () => props.account.collapsed?.muted ?? false
|
|
424
|
+
const quotaTone = () =>
|
|
425
|
+
muted() ? 'textMuted' : (props.account.collapsed?.quotaTone ?? 'success')
|
|
426
|
+
return (
|
|
427
|
+
<box
|
|
428
|
+
ref={(element: { width: number }) => {
|
|
429
|
+
row = element
|
|
430
|
+
}}
|
|
431
|
+
onSizeChange={() => setWidth(row?.width ?? 0)}
|
|
432
|
+
width='100%'
|
|
433
|
+
flexDirection='row'
|
|
434
|
+
justifyContent='space-between'
|
|
435
|
+
columnGap={label() ? 1 : 0}
|
|
436
|
+
>
|
|
437
|
+
<Show when={label()}>
|
|
438
|
+
<text
|
|
439
|
+
fg={context.theme[muted() ? 'textMuted' : 'text']}
|
|
440
|
+
wrapMode='none'
|
|
441
|
+
flexShrink={1}
|
|
442
|
+
>
|
|
443
|
+
{label()}
|
|
444
|
+
</text>
|
|
445
|
+
</Show>
|
|
446
|
+
<box flexDirection='row' flexShrink={0}>
|
|
447
|
+
<Show when={showQuota()}>
|
|
448
|
+
<Show
|
|
449
|
+
when={hasQuota() && !muted()}
|
|
450
|
+
fallback={<text fg={context.theme.textMuted}>{text()}</text>}
|
|
451
|
+
>
|
|
452
|
+
<text fg={context.theme[quotaTone()]}>
|
|
453
|
+
<b>{text()}</b>
|
|
454
|
+
</text>
|
|
455
|
+
</Show>
|
|
456
|
+
</Show>
|
|
457
|
+
<text fg={context.theme[props.account.indicatorTone]}>
|
|
458
|
+
{showQuota() ? ' ' : ''}
|
|
459
|
+
{props.account.blocked ? '\u2298' : '\u25cf'}
|
|
460
|
+
</text>
|
|
461
|
+
</box>
|
|
462
|
+
</box>
|
|
463
|
+
)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function AccountBlock(props: { account: AccountView; marginTop: number }) {
|
|
467
|
+
const context = frameContext()
|
|
468
|
+
const [columns, setColumns] = createSignal(0)
|
|
469
|
+
let block: { width: number } | undefined
|
|
470
|
+
const rows = () => props.account.groups.flatMap((group) => group.rows)
|
|
471
|
+
const labelWidth = () =>
|
|
472
|
+
Math.max(
|
|
473
|
+
0,
|
|
474
|
+
...rows().map(({ part }) =>
|
|
475
|
+
part.name ? Math.max(3, displayWidth(part.name) + 1) : 0,
|
|
476
|
+
),
|
|
477
|
+
)
|
|
478
|
+
const resetWidth = () =>
|
|
479
|
+
Math.max(
|
|
480
|
+
0,
|
|
481
|
+
...rows().map(({ part }) =>
|
|
482
|
+
part.reading === 'unknown' || part.resetSinceReading
|
|
483
|
+
? 0
|
|
484
|
+
: displayWidth(part.resetIn ?? ''),
|
|
485
|
+
),
|
|
486
|
+
)
|
|
487
|
+
const figureWidth = createMemo(() =>
|
|
488
|
+
Math.max(
|
|
489
|
+
10,
|
|
490
|
+
...rows()
|
|
491
|
+
.filter(
|
|
492
|
+
({ part }) => part.reading === 'known' && !part.resetSinceReading,
|
|
493
|
+
)
|
|
494
|
+
.map(({ part }) =>
|
|
495
|
+
displayWidth(
|
|
496
|
+
` ${part.kind === 'budget' && part.figure.startsWith(`${part.name} `) ? part.figure.slice(part.name.length + 1) : part.figure}`,
|
|
497
|
+
),
|
|
498
|
+
),
|
|
499
|
+
),
|
|
500
|
+
)
|
|
501
|
+
const fit = (rowLabelWidth: number) => {
|
|
502
|
+
const desired = context.appearance.barWidth
|
|
503
|
+
// Four cells still distinguish quarters of a window without sacrificing its reset.
|
|
504
|
+
const minimum = Math.min(4, desired)
|
|
505
|
+
if (columns() <= 0)
|
|
506
|
+
return { barCells: desired, showReset: resetWidth() > 0 }
|
|
507
|
+
const room = columns() - rowLabelWidth - figureWidth()
|
|
508
|
+
const withReset = room - resetWidth() - 1
|
|
509
|
+
const showReset = resetWidth() > 0 && withReset >= minimum
|
|
510
|
+
const available = showReset ? withReset : room
|
|
511
|
+
return {
|
|
512
|
+
barCells: available >= minimum ? Math.min(desired, available) : 0,
|
|
513
|
+
showReset,
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const label = () => {
|
|
517
|
+
const full = `${props.account.label}${props.account.titleSuffix ? ` · ${props.account.titleSuffix}` : ''}`
|
|
518
|
+
return columns() <= 0
|
|
519
|
+
? full
|
|
520
|
+
: fitText(full, columns() - displayWidth(props.account.status.text) - 1)
|
|
521
|
+
}
|
|
522
|
+
const age = () => props.account.quotaAge
|
|
523
|
+
const hasRows = () =>
|
|
524
|
+
props.account.groups.some((group) => group.rows.length > 0)
|
|
525
|
+
return (
|
|
526
|
+
<box
|
|
527
|
+
ref={(element: { width: number }) => {
|
|
528
|
+
block = element
|
|
529
|
+
}}
|
|
530
|
+
onSizeChange={() => setColumns(block?.width ?? 0)}
|
|
531
|
+
width='100%'
|
|
532
|
+
flexDirection='column'
|
|
533
|
+
marginTop={props.marginTop}
|
|
534
|
+
>
|
|
535
|
+
<box
|
|
536
|
+
width='100%'
|
|
537
|
+
flexDirection='row'
|
|
538
|
+
justifyContent='space-between'
|
|
539
|
+
columnGap={1}
|
|
540
|
+
>
|
|
541
|
+
<text fg={context.theme.text} wrapMode='none' flexShrink={1}>
|
|
542
|
+
<b>{label()}</b>
|
|
543
|
+
</text>
|
|
544
|
+
<text
|
|
545
|
+
fg={context.theme[props.account.status.tone]}
|
|
546
|
+
wrapMode='none'
|
|
547
|
+
flexShrink={0}
|
|
548
|
+
>
|
|
549
|
+
<b>{props.account.status.text}</b>
|
|
550
|
+
</text>
|
|
551
|
+
</box>
|
|
552
|
+
{context.beforeQuota?.(props.account)}
|
|
553
|
+
<Show
|
|
554
|
+
when={hasRows()}
|
|
555
|
+
fallback={
|
|
556
|
+
<SidebarTextRow
|
|
557
|
+
text={props.account.emptyQuotaText?.expanded ?? '\u2014'}
|
|
558
|
+
wrapMode='none'
|
|
559
|
+
/>
|
|
560
|
+
}
|
|
561
|
+
>
|
|
562
|
+
<For each={props.account.groups}>
|
|
563
|
+
{(group) => (
|
|
564
|
+
<>
|
|
565
|
+
<Show when={group.title}>
|
|
566
|
+
<SidebarTextRow
|
|
567
|
+
text={group.title ?? ''}
|
|
568
|
+
tone='text'
|
|
569
|
+
wrapMode='none'
|
|
570
|
+
/>
|
|
571
|
+
</Show>
|
|
572
|
+
<For each={group.rows}>
|
|
573
|
+
{(row) => {
|
|
574
|
+
const rowLabelWidth = () => (row.part.name ? labelWidth() : 0)
|
|
575
|
+
const rowFit = createMemo(() => fit(rowLabelWidth()))
|
|
576
|
+
return (
|
|
577
|
+
<QuotaRow
|
|
578
|
+
part={row.part}
|
|
579
|
+
pace={row.pace}
|
|
580
|
+
labelWidth={rowLabelWidth()}
|
|
581
|
+
barCells={rowFit().barCells}
|
|
582
|
+
resetWidth={resetWidth()}
|
|
583
|
+
showReset={rowFit().showReset}
|
|
584
|
+
/>
|
|
585
|
+
)
|
|
586
|
+
}}
|
|
587
|
+
</For>
|
|
588
|
+
</>
|
|
589
|
+
)}
|
|
590
|
+
</For>
|
|
591
|
+
</Show>
|
|
592
|
+
<Show when={age()}>
|
|
593
|
+
{(text: () => string) => (
|
|
594
|
+
<SidebarTextRow text={text()} wrapMode='none' />
|
|
595
|
+
)}
|
|
596
|
+
</Show>
|
|
597
|
+
{context.afterQuota?.(props.account)}
|
|
598
|
+
</box>
|
|
599
|
+
)
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** Borderless, controlled presentation; host registration and provider policy stay in the plugin. */
|
|
603
|
+
export function SidebarFrame(props: SidebarFrameProps) {
|
|
604
|
+
const hasData = () => props.accounts.length > 0
|
|
605
|
+
const headerLabel = () =>
|
|
606
|
+
!hasData()
|
|
607
|
+
? props.header.badge
|
|
608
|
+
: `${props.collapsed ? '\u25b6' : '\u25bc'} ${props.header.badge}`
|
|
609
|
+
// Missing semantic colors inherit normal text; an unset palette uses terminal defaults.
|
|
610
|
+
const context = mergeProps(props, {
|
|
611
|
+
get theme(): SidebarTheme {
|
|
612
|
+
const theme = props.theme
|
|
613
|
+
return {
|
|
614
|
+
...theme,
|
|
615
|
+
textMuted: theme?.textMuted ?? theme?.text,
|
|
616
|
+
accent: theme?.accent ?? theme?.text,
|
|
617
|
+
success: theme?.success ?? theme?.text,
|
|
618
|
+
warning: theme?.warning ?? theme?.text,
|
|
619
|
+
error: theme?.error ?? theme?.text,
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
})
|
|
623
|
+
// Inverting an incomplete badge palette can put light text on a light background.
|
|
624
|
+
const invertBadge = () =>
|
|
625
|
+
props.theme?.accent !== undefined && props.theme?.background !== undefined
|
|
626
|
+
return (
|
|
627
|
+
<FrameContext.Provider value={context}>
|
|
628
|
+
<box width='100%' flexDirection='column'>
|
|
629
|
+
{/* Blocked accounts retain their own indicators; the header always keeps its version. */}
|
|
630
|
+
{/* biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI terminal widgets do not have DOM roles */}
|
|
631
|
+
<box
|
|
632
|
+
width='100%'
|
|
633
|
+
flexDirection='row'
|
|
634
|
+
justifyContent='space-between'
|
|
635
|
+
alignItems='center'
|
|
636
|
+
onMouseDown={() => {
|
|
637
|
+
if (hasData()) props.onToggle()
|
|
638
|
+
}}
|
|
639
|
+
>
|
|
640
|
+
<box
|
|
641
|
+
paddingLeft={1}
|
|
642
|
+
paddingRight={1}
|
|
643
|
+
backgroundColor={invertBadge() ? props.theme?.accent : undefined}
|
|
644
|
+
>
|
|
645
|
+
<text
|
|
646
|
+
fg={
|
|
647
|
+
invertBadge() ? props.theme?.background : context.theme.accent
|
|
648
|
+
}
|
|
649
|
+
>
|
|
650
|
+
<b>{headerLabel()}</b>
|
|
651
|
+
</text>
|
|
652
|
+
</box>
|
|
653
|
+
<Show when={props.header.version}>
|
|
654
|
+
<text fg={context.theme.textMuted}>{props.header.version}</text>
|
|
655
|
+
</Show>
|
|
656
|
+
</box>
|
|
657
|
+
<Show when={props.collapsed && hasData()}>
|
|
658
|
+
<For each={props.accounts}>
|
|
659
|
+
{(account) => <CollapsedAccountRow account={account} />}
|
|
660
|
+
</For>
|
|
661
|
+
{props.collapsedSections?.()}
|
|
662
|
+
</Show>
|
|
663
|
+
<Show when={!props.collapsed || !hasData()}>
|
|
664
|
+
<Show when={props.showQuota && hasData()}>
|
|
665
|
+
<SidebarSection title='Quota'>
|
|
666
|
+
<For each={props.accounts}>
|
|
667
|
+
{(account, index) => (
|
|
668
|
+
<AccountBlock
|
|
669
|
+
account={account}
|
|
670
|
+
marginTop={index() === 0 ? 0 : 1}
|
|
671
|
+
/>
|
|
672
|
+
)}
|
|
673
|
+
</For>
|
|
674
|
+
</SidebarSection>
|
|
675
|
+
</Show>
|
|
676
|
+
{props.sections?.()}
|
|
677
|
+
</Show>
|
|
678
|
+
</box>
|
|
679
|
+
</FrameContext.Provider>
|
|
680
|
+
)
|
|
681
|
+
}
|