@cortexkit/opencode-openai-auth 1.8.4 → 1.8.6
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/bin.js +2 -2
- package/dist/{codex-request-C78nXs79.d.ts → codex-request-By530v1D.d.ts} +2 -1
- package/dist/{index-k7zb6wa7.js → index-25p8t63g.js} +1 -1
- package/dist/{index-hvmj07f7.js → index-a8wbqm6a.js} +20 -20
- package/dist/{index-pg5c6by3.js → index-jh90fx7y.js} +1 -1
- package/dist/index-n12zjwh9.js +8 -0
- package/dist/{index-e7gekawr.js → index-pnvp8hvs.js} +1 -1
- package/dist/{index-t8248wa4.js → index-v6jcz0hz.js} +21 -21
- package/dist/{index-nsdjapq1.js → index-zah8t2d2.js} +1 -1
- package/dist/{index-1htk005d.js → index-zf649dj2.js} +1 -1
- package/dist/index-zne9tzy9.js +91 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/tui-preferences.js +1 -1
- package/dist/tui.d.ts +1 -20
- package/dist/v2/server.d.ts +1 -1
- package/dist/v2/server.js +2 -2
- package/package.json +2 -2
- package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +20 -6
- package/src/tui-compiled/raw/shared/169b2b4bf30909bc-consumer.js +25 -0
- package/src/tui-compiled/raw/shared/30f5bc480f31f51c-roster.js +1 -1
- package/src/tui-compiled/raw/shared/352d228be2832bd4-hub.js +55 -5
- package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +1 -1
- package/src/tui-compiled/raw/shared/549daf371622c304-index.tsx +497 -0
- package/src/tui-compiled/raw/shared/7c97ac0cec074ae7-format.js +208 -0
- package/src/tui-compiled/raw/shared/b4ad0d49429f0096-map.js +98 -0
- package/src/tui-compiled/raw/shared/b717cdcce3966455-projection.js +90 -0
- package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +3 -1
- package/src/tui-compiled/raw/tui.tsx +233 -634
- package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +20 -6
- package/src/tui-compiled/runtime/shared/169b2b4bf30909bc-consumer.js +25 -0
- package/src/tui-compiled/runtime/shared/30f5bc480f31f51c-roster.js +1 -1
- package/src/tui-compiled/runtime/shared/352d228be2832bd4-hub.js +55 -5
- package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +1 -1
- package/src/tui-compiled/runtime/shared/549daf371622c304-index.js +550 -0
- package/src/tui-compiled/runtime/shared/7c97ac0cec074ae7-format.js +208 -0
- package/src/tui-compiled/runtime/shared/b4ad0d49429f0096-map.js +98 -0
- package/src/tui-compiled/runtime/shared/b717cdcce3966455-projection.js +90 -0
- package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +3 -1
- package/src/tui-compiled/runtime/tui.js +258 -879
- package/dist/index-a5h82jha.js +0 -8
- package/dist/index-kemp2vh4.js +0 -91
- /package/dist/{index-hnmbhgk4.js → index-95s2mw9w.js} +0 -0
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// never replaces a view another process committed after this hub listed.
|
|
13
13
|
import { createHash } from "node:crypto";
|
|
14
14
|
import { readdir, stat } from "node:fs/promises";
|
|
15
|
-
import { dirname, join } from "node:path";
|
|
15
|
+
import { dirname, join, resolve } from "node:path";
|
|
16
16
|
import { createLogger } from "./cc9e0702a752cea7-index.js";
|
|
17
17
|
import { combineAbortSignals } from "./6371b24a0573d79e-any-signal.js";
|
|
18
18
|
import { ClaustrumUnreachableError } from "./94f53cfd572ba4bb-availability.js";
|
|
@@ -23,6 +23,8 @@ import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
|
|
|
23
23
|
import { DEFAULT_ROUTE_PREFIX, decodedVaultRoster, forgetPendingVaultDiscovery, isVaultRosterLockRefusal, readVaultRoster, refreshVaultRoster, vaultRosterSeed, } from "./30f5bc480f31f51c-roster.js";
|
|
24
24
|
import { drainShutdown, shutdownWarning } from "./a670cb7f5987bc1b-shutdown.js";
|
|
25
25
|
import { SAFETY_POLL_MS } from "./dc9290c2a7552ba6-watch.js";
|
|
26
|
+
/** Published rosters are shared only in memory; file locks still order commits. */
|
|
27
|
+
const sharedRosters = new Map();
|
|
26
28
|
/** Lowercase ASCII, safe as a file name on every OS. */
|
|
27
29
|
const FILE_ID = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
28
30
|
/** Device names Windows reserves in every directory, with any extension. */
|
|
@@ -250,9 +252,11 @@ export class ClaustrumDiscoveryHub {
|
|
|
250
252
|
watchMode: () => this.watchState(),
|
|
251
253
|
keptReceiptState: () => this.keptReceiptState(),
|
|
252
254
|
retainUnion: () => this.#retainUnion(),
|
|
255
|
+
publishRoster: (roster) => this.#publishRoster(entry, roster),
|
|
253
256
|
forget: (credentialId) => this.#current?.custody?.forget(credentialId),
|
|
254
257
|
detach: () => {
|
|
255
258
|
entry.closed = true;
|
|
259
|
+
entry.releaseRoster?.();
|
|
256
260
|
},
|
|
257
261
|
};
|
|
258
262
|
const consumerOptions = {
|
|
@@ -265,14 +269,58 @@ export class ClaustrumDiscoveryHub {
|
|
|
265
269
|
}),
|
|
266
270
|
...(this.#options.mapAccount && { mapAccount: this.#options.mapAccount }),
|
|
267
271
|
...(options.onRoster && { onRoster: options.onRoster }),
|
|
272
|
+
...(options.onDiscovery && { onDiscovery: options.onDiscovery }),
|
|
268
273
|
...(options.onError && { onError: options.onError }),
|
|
269
274
|
logger: options.logger ?? this.#logger,
|
|
270
275
|
...(this.#options.now && { now: this.#options.now }),
|
|
271
276
|
};
|
|
272
277
|
const { consumer, hooks } = createHubMember(port, consumerOptions);
|
|
273
278
|
entry.hooks = hooks;
|
|
279
|
+
const path = resolve(entry.path);
|
|
280
|
+
const subscribers = sharedRosters.get(path) ?? new Set();
|
|
281
|
+
const install = (roster) => {
|
|
282
|
+
// A peer cannot reactivate an off or closed member, or install routes
|
|
283
|
+
// that collide with this plugin instance's local pool.
|
|
284
|
+
if (entry.closed ||
|
|
285
|
+
this.#active !== true ||
|
|
286
|
+
!this.#current ||
|
|
287
|
+
!this.#live(this.#current) ||
|
|
288
|
+
!hooks.roster() ||
|
|
289
|
+
this.#collides(hooks, roster))
|
|
290
|
+
return;
|
|
291
|
+
entry.seen = JSON.stringify(decodedVaultRoster(roster));
|
|
292
|
+
hooks.install(roster);
|
|
293
|
+
if (roster.view !== this.#committed?.view)
|
|
294
|
+
entry.pending ??= { failures: 0, wait: 0 };
|
|
295
|
+
this.#retainUnion();
|
|
296
|
+
};
|
|
297
|
+
subscribers.add(install);
|
|
298
|
+
entry.receiveRoster = install;
|
|
299
|
+
sharedRosters.set(path, subscribers);
|
|
300
|
+
let subscribed = true;
|
|
301
|
+
entry.releaseRoster = () => {
|
|
302
|
+
if (!subscribed)
|
|
303
|
+
return;
|
|
304
|
+
subscribed = false;
|
|
305
|
+
subscribers.delete(install);
|
|
306
|
+
if (!subscribers.size)
|
|
307
|
+
sharedRosters.delete(path);
|
|
308
|
+
};
|
|
274
309
|
return consumer;
|
|
275
310
|
}
|
|
311
|
+
#publishRoster(entry, roster) {
|
|
312
|
+
const generation = this.#current;
|
|
313
|
+
if (entry.closed || !generation || !this.#live(generation))
|
|
314
|
+
return;
|
|
315
|
+
entry.seen = JSON.stringify(decodedVaultRoster(roster));
|
|
316
|
+
entry.hooks?.install(roster);
|
|
317
|
+
for (const install of sharedRosters.get(resolve(entry.path)) ?? []) {
|
|
318
|
+
if (!this.#live(generation))
|
|
319
|
+
return;
|
|
320
|
+
if (install !== entry.receiveRoster)
|
|
321
|
+
install(roster);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
276
324
|
// --- leases ---
|
|
277
325
|
#startGeneration() {
|
|
278
326
|
const generation = {
|
|
@@ -582,6 +630,8 @@ export class ClaustrumDiscoveryHub {
|
|
|
582
630
|
}));
|
|
583
631
|
run.promise = promise;
|
|
584
632
|
this.#run = run;
|
|
633
|
+
for (const entry of this.#open())
|
|
634
|
+
entry.hooks?.discovery(promise);
|
|
585
635
|
return promise;
|
|
586
636
|
}
|
|
587
637
|
/**
|
|
@@ -681,9 +731,7 @@ export class ClaustrumDiscoveryHub {
|
|
|
681
731
|
continue;
|
|
682
732
|
}
|
|
683
733
|
// The push: memory holds the committed roster before refresh resolves.
|
|
684
|
-
entry
|
|
685
|
-
if (!entry.closed)
|
|
686
|
-
hooks.install(roster);
|
|
734
|
+
this.#publishRoster(entry, roster);
|
|
687
735
|
}
|
|
688
736
|
if (!this.#live(generation))
|
|
689
737
|
return undefined;
|
|
@@ -850,7 +898,7 @@ export class ClaustrumDiscoveryHub {
|
|
|
850
898
|
}
|
|
851
899
|
const before = enabledRows(memory);
|
|
852
900
|
entry.seen = content;
|
|
853
|
-
|
|
901
|
+
this.#publishRoster(entry, file);
|
|
854
902
|
if (enabledRows(hooks.roster()) !== before)
|
|
855
903
|
this.#retainUnion();
|
|
856
904
|
}
|
|
@@ -1013,6 +1061,8 @@ export class ClaustrumDiscoveryHub {
|
|
|
1013
1061
|
if (this.#shutdown.signal.aborted)
|
|
1014
1062
|
return;
|
|
1015
1063
|
this.#shutdown.abort(closed('Claustrum discovery hub is closed'));
|
|
1064
|
+
for (const entry of this.#members.values())
|
|
1065
|
+
entry.releaseRoster?.();
|
|
1016
1066
|
if (this.#timer)
|
|
1017
1067
|
(this.#options.clearTimeoutImpl ?? clearTimeout)(this.#timer);
|
|
1018
1068
|
this.#timer = undefined;
|
|
@@ -0,0 +1,497 @@
|
|
|
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
|
+
Show,
|
|
9
|
+
useContext,
|
|
10
|
+
} from "solid-js"
|
|
11
|
+
import type { QuotaWindowPart } from "./7c97ac0cec074ae7-format.js"
|
|
12
|
+
import { formatQuota, quotaWindowParts } from "./7c97ac0cec074ae7-format.js"
|
|
13
|
+
import type { ProjectedQuota } from "./b717cdcce3966455-projection.js"
|
|
14
|
+
|
|
15
|
+
export type Tone =
|
|
16
|
+
| 'text'
|
|
17
|
+
| 'textMuted'
|
|
18
|
+
| 'accent'
|
|
19
|
+
| 'success'
|
|
20
|
+
| 'warning'
|
|
21
|
+
| 'error'
|
|
22
|
+
|
|
23
|
+
export type SidebarTheme = Readonly<
|
|
24
|
+
Record<Tone | 'background' | 'borderActive', RGBA>
|
|
25
|
+
>
|
|
26
|
+
|
|
27
|
+
export interface SidebarAppearance {
|
|
28
|
+
barWidth: number
|
|
29
|
+
barFilledChar: string
|
|
30
|
+
barEmptyChar: string
|
|
31
|
+
warnThreshold: number
|
|
32
|
+
errorThreshold: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PaceView {
|
|
36
|
+
text: string
|
|
37
|
+
tone: Tone
|
|
38
|
+
/** The elapsed-window percentage, not the difference from usage. */
|
|
39
|
+
overlay?: { kind: 'reserve' | 'deficit'; percent: number }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface QuotaGroupView {
|
|
43
|
+
title?: string
|
|
44
|
+
rows: readonly { part: QuotaWindowPart; pace?: PaceView }[]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface AccountView {
|
|
48
|
+
id: string
|
|
49
|
+
label: string
|
|
50
|
+
titleSuffix?: string
|
|
51
|
+
status: { text: string; tone: Tone }
|
|
52
|
+
blocked: boolean
|
|
53
|
+
indicatorTone: Tone
|
|
54
|
+
quota: ProjectedQuota | undefined
|
|
55
|
+
groups: readonly QuotaGroupView[]
|
|
56
|
+
emptyQuotaText?: { expanded: string; collapsed: string }
|
|
57
|
+
/** Presentation decided by the plugin, never inferred from status or freshness. */
|
|
58
|
+
collapsed?: { quotaTone?: Tone; muted?: boolean }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface SidebarFrameProps {
|
|
62
|
+
header: { badge: string; version?: string }
|
|
63
|
+
accounts: readonly AccountView[]
|
|
64
|
+
theme: SidebarTheme
|
|
65
|
+
appearance: SidebarAppearance
|
|
66
|
+
showQuota: boolean
|
|
67
|
+
now: number
|
|
68
|
+
collapsed: boolean
|
|
69
|
+
onToggle: () => void
|
|
70
|
+
beforeQuota?: (account: AccountView) => JSX.Element
|
|
71
|
+
afterQuota?: (account: AccountView) => JSX.Element
|
|
72
|
+
sections?: () => JSX.Element
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const FrameContext = createContext<SidebarFrameProps>()
|
|
76
|
+
|
|
77
|
+
function frameContext(): SidebarFrameProps {
|
|
78
|
+
const context = useContext(FrameContext)
|
|
79
|
+
if (!context)
|
|
80
|
+
throw new Error('Sidebar primitives must be inside SidebarFrame')
|
|
81
|
+
return context
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function displayWidth(text: string): number {
|
|
85
|
+
const bun = (
|
|
86
|
+
globalThis as { Bun?: { stringWidth?: (text: string) => number } }
|
|
87
|
+
).Bun
|
|
88
|
+
return bun?.stringWidth ? bun.stringWidth(text) : Array.from(text).length
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function fitText(text: string, columns: number): string {
|
|
92
|
+
if (displayWidth(text) <= columns) return text
|
|
93
|
+
if (columns < 1) return ''
|
|
94
|
+
let kept = ''
|
|
95
|
+
let used = 0
|
|
96
|
+
for (const char of text) {
|
|
97
|
+
const width = displayWidth(char)
|
|
98
|
+
if (used + width > columns - 1) break
|
|
99
|
+
kept += char
|
|
100
|
+
used += width
|
|
101
|
+
}
|
|
102
|
+
return `${kept}\u2026`
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** A heading and its plugin-owned rows, with the frame's section spacing. */
|
|
106
|
+
export function SidebarSection(props: {
|
|
107
|
+
title: string
|
|
108
|
+
children?: JSX.Element
|
|
109
|
+
}) {
|
|
110
|
+
const context = frameContext()
|
|
111
|
+
return (
|
|
112
|
+
<>
|
|
113
|
+
<box width='100%' marginTop={1}>
|
|
114
|
+
<text fg={context.theme.text}>
|
|
115
|
+
<b>{props.title}</b>
|
|
116
|
+
</text>
|
|
117
|
+
</box>
|
|
118
|
+
{props.children}
|
|
119
|
+
</>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Keep labels whole and reserve one blank cell before an ellipsized value. */
|
|
124
|
+
export function SidebarStatRow(props: {
|
|
125
|
+
label: string
|
|
126
|
+
value: string
|
|
127
|
+
tone?: Tone
|
|
128
|
+
}) {
|
|
129
|
+
const context = frameContext()
|
|
130
|
+
const [width, setWidth] = createSignal(0)
|
|
131
|
+
let row: { width: number } | undefined
|
|
132
|
+
const value = () =>
|
|
133
|
+
width() <= 0
|
|
134
|
+
? props.value
|
|
135
|
+
: fitText(props.value, width() - displayWidth(props.label) - 1)
|
|
136
|
+
return (
|
|
137
|
+
<box
|
|
138
|
+
ref={(element: { width: number }) => {
|
|
139
|
+
row = element
|
|
140
|
+
}}
|
|
141
|
+
onSizeChange={() => setWidth(row?.width ?? 0)}
|
|
142
|
+
width='100%'
|
|
143
|
+
flexDirection='row'
|
|
144
|
+
justifyContent='space-between'
|
|
145
|
+
columnGap={1}
|
|
146
|
+
>
|
|
147
|
+
<text fg={context.theme.textMuted} wrapMode='none' flexShrink={0}>
|
|
148
|
+
{props.label}
|
|
149
|
+
</text>
|
|
150
|
+
<text
|
|
151
|
+
fg={context.theme[props.tone ?? 'text']}
|
|
152
|
+
wrapMode='none'
|
|
153
|
+
flexShrink={1}
|
|
154
|
+
>
|
|
155
|
+
<b>{value()}</b>
|
|
156
|
+
</text>
|
|
157
|
+
</box>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function SidebarTextRow(props: { text: string; tone?: Tone }) {
|
|
162
|
+
const context = frameContext()
|
|
163
|
+
return <text fg={context.theme[props.tone ?? 'textMuted']}>{props.text}</text>
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function usageTone(used: number, appearance: SidebarAppearance): Tone {
|
|
167
|
+
if (used >= appearance.errorThreshold) return 'error'
|
|
168
|
+
if (used >= appearance.warnThreshold) return 'warning'
|
|
169
|
+
return 'success'
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function barSegments(
|
|
173
|
+
used: number,
|
|
174
|
+
appearance: SidebarAppearance,
|
|
175
|
+
pace?: PaceView,
|
|
176
|
+
) {
|
|
177
|
+
const width = appearance.barWidth
|
|
178
|
+
const cells = (pct: number) =>
|
|
179
|
+
Math.max(0, Math.min(Math.round((pct / 100) * width), width))
|
|
180
|
+
const usedCells = cells(used)
|
|
181
|
+
const tone = usageTone(used, appearance)
|
|
182
|
+
const plain = [
|
|
183
|
+
{ text: appearance.barFilledChar.repeat(usedCells), tone },
|
|
184
|
+
{ text: appearance.barEmptyChar.repeat(width - usedCells), tone },
|
|
185
|
+
]
|
|
186
|
+
const overlay = pace?.overlay
|
|
187
|
+
if (!overlay) return plain.filter((segment) => segment.text.length > 0)
|
|
188
|
+
const paceCells = cells(overlay.percent)
|
|
189
|
+
const lo = Math.min(usedCells, paceCells)
|
|
190
|
+
const hi = Math.max(usedCells, paceCells)
|
|
191
|
+
if (lo === hi) return plain.filter((segment) => segment.text.length > 0)
|
|
192
|
+
return [
|
|
193
|
+
{ text: appearance.barFilledChar.repeat(lo), tone },
|
|
194
|
+
{
|
|
195
|
+
text: (overlay.kind === 'deficit' ? '\u2593' : '\u2592').repeat(hi - lo),
|
|
196
|
+
tone:
|
|
197
|
+
overlay.kind === 'deficit' ? ('error' as const) : ('success' as const),
|
|
198
|
+
},
|
|
199
|
+
{ text: appearance.barEmptyChar.repeat(width - hi), tone },
|
|
200
|
+
].filter((segment) => segment.text.length > 0)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function QuotaRow(props: {
|
|
204
|
+
part: QuotaWindowPart
|
|
205
|
+
pace?: PaceView
|
|
206
|
+
labelWidth: number
|
|
207
|
+
}) {
|
|
208
|
+
const context = frameContext()
|
|
209
|
+
const [columns, setColumns] = createSignal(0)
|
|
210
|
+
let row: { width: number } | undefined
|
|
211
|
+
const label = () => props.part.name.padEnd(props.labelWidth)
|
|
212
|
+
const figure = () =>
|
|
213
|
+
` ${props.part.kind === 'budget' && props.part.figure.startsWith(`${props.part.name} `) ? props.part.figure.slice(props.part.name.length + 1) : props.part.figure}`
|
|
214
|
+
const reset = () =>
|
|
215
|
+
props.part.resetIn ?? (props.part.resetSinceReading ? 'reset' : undefined)
|
|
216
|
+
const used = () => 100 - (props.part.remainingPercent ?? 100)
|
|
217
|
+
const fit = () => {
|
|
218
|
+
const barWidth = context.appearance.barWidth
|
|
219
|
+
const resetWidth = displayWidth(reset() ?? '')
|
|
220
|
+
if (columns() <= 0) return { barCells: barWidth, showReset: resetWidth > 0 }
|
|
221
|
+
const fixed = displayWidth(label()) + displayWidth(figure())
|
|
222
|
+
if (resetWidth > 0 && fixed + barWidth + 1 + resetWidth <= columns())
|
|
223
|
+
return { barCells: barWidth, showReset: true }
|
|
224
|
+
const room = columns() - fixed
|
|
225
|
+
return {
|
|
226
|
+
barCells: room >= barWidth ? barWidth : room >= 3 ? room : 0,
|
|
227
|
+
showReset: false,
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// Stable fits keep existing bar nodes alive through the first measurement.
|
|
231
|
+
const barCells = createMemo(() => fit().barCells)
|
|
232
|
+
const showReset = createMemo(() => fit().showReset)
|
|
233
|
+
const paceLine = () => {
|
|
234
|
+
const text = props.pace?.text
|
|
235
|
+
if (!text || columns() <= 0) return text
|
|
236
|
+
return fitText(text, columns() - props.labelWidth)
|
|
237
|
+
}
|
|
238
|
+
return (
|
|
239
|
+
<>
|
|
240
|
+
<box
|
|
241
|
+
ref={(element: { width: number }) => {
|
|
242
|
+
row = element
|
|
243
|
+
}}
|
|
244
|
+
onSizeChange={() => setColumns(row?.width ?? 0)}
|
|
245
|
+
width='100%'
|
|
246
|
+
flexDirection='row'
|
|
247
|
+
justifyContent='space-between'
|
|
248
|
+
>
|
|
249
|
+
<box flexDirection='row' flexShrink={0}>
|
|
250
|
+
<text fg={context.theme.textMuted} wrapMode='none'>
|
|
251
|
+
{label()}
|
|
252
|
+
</text>
|
|
253
|
+
<For
|
|
254
|
+
each={barSegments(
|
|
255
|
+
used(),
|
|
256
|
+
{ ...context.appearance, barWidth: barCells() },
|
|
257
|
+
props.pace,
|
|
258
|
+
)}
|
|
259
|
+
>
|
|
260
|
+
{(segment) => (
|
|
261
|
+
<text fg={context.theme[segment.tone]} wrapMode='none'>
|
|
262
|
+
{segment.text}
|
|
263
|
+
</text>
|
|
264
|
+
)}
|
|
265
|
+
</For>
|
|
266
|
+
<text
|
|
267
|
+
fg={context.theme[usageTone(used(), context.appearance)]}
|
|
268
|
+
wrapMode='none'
|
|
269
|
+
>
|
|
270
|
+
{figure()}
|
|
271
|
+
</text>
|
|
272
|
+
</box>
|
|
273
|
+
<Show when={showReset()}>
|
|
274
|
+
<text fg={context.theme.textMuted} wrapMode='none' flexShrink={0}>
|
|
275
|
+
{reset()}
|
|
276
|
+
</text>
|
|
277
|
+
</Show>
|
|
278
|
+
</box>
|
|
279
|
+
{/* A changed fitted line needs a fresh text node to draw at its new width. */}
|
|
280
|
+
<Show when={paceLine()} keyed>
|
|
281
|
+
{(line: string) => (
|
|
282
|
+
<box width='100%' flexDirection='row'>
|
|
283
|
+
<text fg={context.theme.textMuted}>
|
|
284
|
+
{''.padEnd(props.labelWidth)}
|
|
285
|
+
</text>
|
|
286
|
+
<text
|
|
287
|
+
fg={context.theme[props.pace?.tone ?? 'textMuted']}
|
|
288
|
+
wrapMode='none'
|
|
289
|
+
>
|
|
290
|
+
{line}
|
|
291
|
+
</text>
|
|
292
|
+
</box>
|
|
293
|
+
)}
|
|
294
|
+
</Show>
|
|
295
|
+
</>
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function CollapsedAccountRow(props: { account: AccountView }) {
|
|
300
|
+
const context = frameContext()
|
|
301
|
+
const [width, setWidth] = createSignal(0)
|
|
302
|
+
let row: { width: number } | undefined
|
|
303
|
+
const hasQuota = () =>
|
|
304
|
+
quotaWindowParts(props.account.quota, { now: context.now }).windows.length >
|
|
305
|
+
0
|
|
306
|
+
const text = () =>
|
|
307
|
+
hasQuota()
|
|
308
|
+
? formatQuota(props.account.quota, { now: context.now, form: 'narrow' })
|
|
309
|
+
: null
|
|
310
|
+
const label = () => {
|
|
311
|
+
if (width() <= 0) return props.account.label
|
|
312
|
+
const value =
|
|
313
|
+
text() === null
|
|
314
|
+
? displayWidth(props.account.emptyQuotaText?.collapsed ?? '\u2014')
|
|
315
|
+
: displayWidth(text() ?? '') + 2
|
|
316
|
+
return fitText(props.account.label, width() - value - 1)
|
|
317
|
+
}
|
|
318
|
+
const muted = () => props.account.collapsed?.muted ?? false
|
|
319
|
+
const quotaTone = () =>
|
|
320
|
+
muted() ? 'textMuted' : (props.account.collapsed?.quotaTone ?? 'success')
|
|
321
|
+
return (
|
|
322
|
+
<box
|
|
323
|
+
ref={(element: { width: number }) => {
|
|
324
|
+
row = element
|
|
325
|
+
}}
|
|
326
|
+
onSizeChange={() => setWidth(row?.width ?? 0)}
|
|
327
|
+
width='100%'
|
|
328
|
+
flexDirection='row'
|
|
329
|
+
justifyContent='space-between'
|
|
330
|
+
>
|
|
331
|
+
<text
|
|
332
|
+
fg={context.theme[muted() ? 'textMuted' : 'text']}
|
|
333
|
+
wrapMode='none'
|
|
334
|
+
flexShrink={1}
|
|
335
|
+
>
|
|
336
|
+
{label()}
|
|
337
|
+
</text>
|
|
338
|
+
<Show
|
|
339
|
+
when={text() !== null}
|
|
340
|
+
fallback={
|
|
341
|
+
<text fg={context.theme.textMuted}>
|
|
342
|
+
{props.account.emptyQuotaText?.collapsed ?? '\u2014'}
|
|
343
|
+
</text>
|
|
344
|
+
}
|
|
345
|
+
>
|
|
346
|
+
<box flexDirection='row' flexShrink={0}>
|
|
347
|
+
<Show
|
|
348
|
+
when={!muted()}
|
|
349
|
+
fallback={<text fg={context.theme.textMuted}>{text()}</text>}
|
|
350
|
+
>
|
|
351
|
+
<text fg={context.theme[quotaTone()]}>
|
|
352
|
+
<b>{text()}</b>
|
|
353
|
+
</text>
|
|
354
|
+
</Show>
|
|
355
|
+
<text fg={context.theme[props.account.indicatorTone]}>
|
|
356
|
+
{props.account.blocked ? ' \u2298' : ' \u25cf'}
|
|
357
|
+
</text>
|
|
358
|
+
</box>
|
|
359
|
+
</Show>
|
|
360
|
+
</box>
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function AccountBlock(props: {
|
|
365
|
+
account: AccountView
|
|
366
|
+
labelWidth: number
|
|
367
|
+
marginTop: number
|
|
368
|
+
}) {
|
|
369
|
+
const context = frameContext()
|
|
370
|
+
const age = () =>
|
|
371
|
+
quotaWindowParts(props.account.quota, { now: context.now }).age
|
|
372
|
+
const hasRows = () =>
|
|
373
|
+
props.account.groups.some((group) => group.rows.length > 0)
|
|
374
|
+
return (
|
|
375
|
+
<box width='100%' flexDirection='column' marginTop={props.marginTop}>
|
|
376
|
+
<box width='100%' flexDirection='row' justifyContent='space-between'>
|
|
377
|
+
<text fg={context.theme.text}>
|
|
378
|
+
<b>
|
|
379
|
+
{props.account.label}
|
|
380
|
+
{props.account.titleSuffix ? ` · ${props.account.titleSuffix}` : ''}
|
|
381
|
+
</b>
|
|
382
|
+
</text>
|
|
383
|
+
<text fg={context.theme[props.account.status.tone]}>
|
|
384
|
+
<b>{props.account.status.text}</b>
|
|
385
|
+
</text>
|
|
386
|
+
</box>
|
|
387
|
+
{context.beforeQuota?.(props.account)}
|
|
388
|
+
<Show
|
|
389
|
+
when={hasRows()}
|
|
390
|
+
fallback={
|
|
391
|
+
<SidebarTextRow
|
|
392
|
+
text={props.account.emptyQuotaText?.expanded ?? '\u2014'}
|
|
393
|
+
/>
|
|
394
|
+
}
|
|
395
|
+
>
|
|
396
|
+
<For each={props.account.groups}>
|
|
397
|
+
{(group) => (
|
|
398
|
+
<>
|
|
399
|
+
<Show when={group.title}>
|
|
400
|
+
<SidebarTextRow text={group.title ?? ''} tone='text' />
|
|
401
|
+
</Show>
|
|
402
|
+
<For each={group.rows}>
|
|
403
|
+
{(row) => (
|
|
404
|
+
<QuotaRow
|
|
405
|
+
part={row.part}
|
|
406
|
+
pace={row.pace}
|
|
407
|
+
labelWidth={props.labelWidth}
|
|
408
|
+
/>
|
|
409
|
+
)}
|
|
410
|
+
</For>
|
|
411
|
+
</>
|
|
412
|
+
)}
|
|
413
|
+
</For>
|
|
414
|
+
</Show>
|
|
415
|
+
<Show when={age()}>
|
|
416
|
+
{(text: () => string) => <SidebarTextRow text={text()} />}
|
|
417
|
+
</Show>
|
|
418
|
+
{context.afterQuota?.(props.account)}
|
|
419
|
+
</box>
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** Borderless, controlled presentation; host registration and provider policy stay in the plugin. */
|
|
424
|
+
export function SidebarFrame(props: SidebarFrameProps) {
|
|
425
|
+
const hasData = () => props.accounts.length > 0
|
|
426
|
+
const headerLabel = () =>
|
|
427
|
+
!hasData()
|
|
428
|
+
? props.header.badge
|
|
429
|
+
: `${props.collapsed ? '\u25b6' : '\u25bc'} ${props.header.badge}`
|
|
430
|
+
const labelWidth = () =>
|
|
431
|
+
Math.max(
|
|
432
|
+
3,
|
|
433
|
+
...props.accounts.flatMap((account) =>
|
|
434
|
+
account.groups.flatMap((group) =>
|
|
435
|
+
group.rows.map((row) => row.part.name.length + 1),
|
|
436
|
+
),
|
|
437
|
+
),
|
|
438
|
+
)
|
|
439
|
+
return (
|
|
440
|
+
<FrameContext.Provider value={props}>
|
|
441
|
+
<box
|
|
442
|
+
width='100%'
|
|
443
|
+
flexDirection='column'
|
|
444
|
+
paddingTop={1}
|
|
445
|
+
paddingBottom={1}
|
|
446
|
+
paddingLeft={1}
|
|
447
|
+
paddingRight={1}
|
|
448
|
+
>
|
|
449
|
+
{/* Blocked accounts retain their own indicators; the header always keeps its version. */}
|
|
450
|
+
{/* biome-ignore lint/a11y/noStaticElementInteractions: OpenTUI terminal widgets do not have DOM roles */}
|
|
451
|
+
<box
|
|
452
|
+
width='100%'
|
|
453
|
+
flexDirection='row'
|
|
454
|
+
justifyContent='space-between'
|
|
455
|
+
alignItems='center'
|
|
456
|
+
onMouseDown={() => {
|
|
457
|
+
if (hasData()) props.onToggle()
|
|
458
|
+
}}
|
|
459
|
+
>
|
|
460
|
+
<box
|
|
461
|
+
paddingLeft={1}
|
|
462
|
+
paddingRight={1}
|
|
463
|
+
backgroundColor={props.theme.accent}
|
|
464
|
+
>
|
|
465
|
+
<text fg={props.theme.background}>
|
|
466
|
+
<b>{headerLabel()}</b>
|
|
467
|
+
</text>
|
|
468
|
+
</box>
|
|
469
|
+
<Show when={props.header.version}>
|
|
470
|
+
<text fg={props.theme.textMuted}>{props.header.version}</text>
|
|
471
|
+
</Show>
|
|
472
|
+
</box>
|
|
473
|
+
<Show when={props.collapsed && hasData()}>
|
|
474
|
+
<For each={props.accounts}>
|
|
475
|
+
{(account) => <CollapsedAccountRow account={account} />}
|
|
476
|
+
</For>
|
|
477
|
+
</Show>
|
|
478
|
+
<Show when={!props.collapsed || !hasData()}>
|
|
479
|
+
<Show when={props.showQuota && hasData()}>
|
|
480
|
+
<SidebarSection title='Quota'>
|
|
481
|
+
<For each={props.accounts}>
|
|
482
|
+
{(account, index) => (
|
|
483
|
+
<AccountBlock
|
|
484
|
+
account={account}
|
|
485
|
+
labelWidth={labelWidth()}
|
|
486
|
+
marginTop={index() === 0 ? 0 : 1}
|
|
487
|
+
/>
|
|
488
|
+
)}
|
|
489
|
+
</For>
|
|
490
|
+
</SidebarSection>
|
|
491
|
+
</Show>
|
|
492
|
+
{props.sections?.()}
|
|
493
|
+
</Show>
|
|
494
|
+
</box>
|
|
495
|
+
</FrameContext.Provider>
|
|
496
|
+
)
|
|
497
|
+
}
|