@thelioo/opencode-balancer 0.1.3 → 0.1.4
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/INSTALL.txt +16 -7
- package/README.md +24 -45
- package/dist/core/accounts.d.ts +14 -0
- package/dist/core/accounts.js +260 -0
- package/dist/core/accounts.js.map +1 -0
- package/dist/core/database.d.ts +4 -0
- package/dist/core/database.js +69 -0
- package/dist/core/database.js.map +1 -0
- package/dist/core/events.d.ts +18 -0
- package/dist/core/events.js +39 -0
- package/dist/core/events.js.map +1 -0
- package/dist/core/native-auth-suppression.d.ts +3 -0
- package/dist/core/native-auth-suppression.js +19 -0
- package/dist/core/native-auth-suppression.js.map +1 -0
- package/dist/core/native-connect.d.ts +4 -0
- package/dist/core/native-connect.js +19 -0
- package/dist/core/native-connect.js.map +1 -0
- package/dist/core/path.d.ts +4 -0
- package/dist/core/path.js +26 -0
- package/dist/core/path.js.map +1 -0
- package/dist/core/pending.d.ts +9 -0
- package/dist/core/pending.js +237 -0
- package/dist/core/pending.js.map +1 -0
- package/dist/core/priority.d.ts +20 -0
- package/dist/core/priority.js +120 -0
- package/dist/core/priority.js.map +1 -0
- package/dist/core/schema.d.ts +2 -0
- package/dist/core/schema.js +265 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/time.d.ts +1 -0
- package/dist/core/time.js +4 -0
- package/dist/core/time.js.map +1 -0
- package/dist/core/types.d.ts +59 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/usage/index.d.ts +4 -0
- package/dist/core/usage/index.js +16 -0
- package/dist/core/usage/index.js.map +1 -0
- package/dist/core/usage/providers/copilot.d.ts +2 -0
- package/dist/core/usage/providers/copilot.js +169 -0
- package/dist/core/usage/providers/copilot.js.map +1 -0
- package/dist/core/usage/providers/openai.d.ts +2 -0
- package/dist/core/usage/providers/openai.js +133 -0
- package/dist/core/usage/providers/openai.js.map +1 -0
- package/dist/core/usage/redact.d.ts +3 -0
- package/dist/core/usage/redact.js +67 -0
- package/dist/core/usage/redact.js.map +1 -0
- package/dist/core/usage/store.d.ts +4 -0
- package/dist/core/usage/store.js +31 -0
- package/dist/core/usage/store.js.map +1 -0
- package/dist/core/usage/types.d.ts +21 -0
- package/dist/core/usage/types.js +2 -0
- package/dist/core/usage/types.js.map +1 -0
- package/dist/index.d.ts +1 -37
- package/dist/index.js +1 -60
- package/dist/index.js.map +1 -1
- package/dist/server/auth-watcher.d.ts +31 -0
- package/dist/server/auth-watcher.js +227 -0
- package/dist/server/auth-watcher.js.map +1 -0
- package/dist/server/commands.d.ts +2 -0
- package/dist/server/commands.js +46 -0
- package/dist/server/commands.js.map +1 -0
- package/dist/server/fetch-patch.d.ts +3 -0
- package/dist/server/fetch-patch.js +118 -0
- package/dist/server/fetch-patch.js.map +1 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +94 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/native.d.ts +6 -0
- package/dist/server/native.js +35 -0
- package/dist/server/native.js.map +1 -0
- package/dist/server/request-balancer.d.ts +16 -0
- package/dist/server/request-balancer.js +43 -0
- package/dist/server/request-balancer.js.map +1 -0
- package/dist/tui/actions.d.ts +41 -0
- package/dist/tui/actions.js +88 -0
- package/dist/tui/actions.js.map +1 -0
- package/dist/tui/actions.ts +140 -0
- package/dist/tui/balancer-bar-sync.d.ts +19 -0
- package/dist/tui/balancer-bar-sync.js +45 -0
- package/dist/tui/balancer-bar-sync.js.map +1 -0
- package/dist/tui/balancer-bar-sync.ts +56 -0
- package/dist/tui/components/alias-dialog.d.ts +4 -0
- package/dist/tui/components/alias-dialog.js +57 -0
- package/dist/tui/components/alias-dialog.js.map +1 -0
- package/dist/tui/components/alias-dialog.tsx +72 -0
- package/dist/tui/components/dashboard.d.ts +12 -0
- package/dist/tui/components/dashboard.js +201 -0
- package/dist/tui/components/dashboard.js.map +1 -0
- package/dist/tui/components/dashboard.tsx +393 -0
- package/dist/tui/components/priority-screen.d.ts +9 -0
- package/dist/tui/components/priority-screen.js +120 -0
- package/dist/tui/components/priority-screen.js.map +1 -0
- package/dist/tui/components/priority-screen.tsx +302 -0
- package/dist/tui/components/provider-model-dialog.d.ts +13 -0
- package/dist/tui/components/provider-model-dialog.js +45 -0
- package/dist/tui/components/provider-model-dialog.js.map +1 -0
- package/dist/tui/components/provider-model-dialog.tsx +71 -0
- package/dist/tui/components/rename-dialog.d.ts +4 -0
- package/dist/tui/components/rename-dialog.js +24 -0
- package/dist/tui/components/rename-dialog.js.map +1 -0
- package/dist/tui/components/rename-dialog.tsx +40 -0
- package/dist/tui/components/sidebar.d.ts +10 -0
- package/dist/tui/components/sidebar.js +27 -0
- package/dist/tui/components/sidebar.js.map +1 -0
- package/dist/tui/components/sidebar.tsx +97 -0
- package/dist/tui/components/status-indicator.d.ts +9 -0
- package/dist/tui/components/status-indicator.js +59 -0
- package/dist/tui/components/status-indicator.js.map +1 -0
- package/dist/tui/components/status-indicator.tsx +78 -0
- package/dist/tui/components/usage-bar.d.ts +8 -0
- package/dist/tui/components/usage-bar.js +7 -0
- package/dist/tui/components/usage-bar.js.map +1 -0
- package/dist/tui/components/usage-bar.tsx +13 -0
- package/dist/tui/components/usage-display.d.ts +10 -0
- package/dist/tui/components/usage-display.js +32 -0
- package/dist/tui/components/usage-display.js.map +1 -0
- package/dist/tui/components/usage-display.tsx +29 -0
- package/dist/tui/connect.d.ts +30 -0
- package/dist/tui/connect.js +73 -0
- package/dist/tui/connect.js.map +1 -0
- package/dist/tui/connect.ts +100 -0
- package/dist/tui/dashboard-keys.d.ts +45 -0
- package/dist/tui/dashboard-keys.js +44 -0
- package/dist/tui/dashboard-keys.js.map +1 -0
- package/dist/tui/dashboard-keys.ts +60 -0
- package/dist/tui/native-model-apply.d.ts +21 -0
- package/dist/tui/native-model-apply.js +53 -0
- package/dist/tui/native-model-apply.js.map +1 -0
- package/dist/tui/native-model-apply.ts +73 -0
- package/dist/tui/priority-keys.d.ts +40 -0
- package/dist/tui/priority-keys.js +38 -0
- package/dist/tui/priority-keys.js.map +1 -0
- package/dist/tui/priority-keys.ts +59 -0
- package/dist/tui/provider-models.d.ts +19 -0
- package/dist/tui/provider-models.js +17 -0
- package/dist/tui/provider-models.js.map +1 -0
- package/dist/tui/provider-models.ts +36 -0
- package/dist/tui/responsive.d.ts +9 -0
- package/dist/tui/responsive.js +13 -0
- package/dist/tui/responsive.js.map +1 -0
- package/dist/tui/responsive.ts +16 -0
- package/dist/tui/selection-colors.d.ts +10 -0
- package/dist/tui/selection-colors.js +38 -0
- package/dist/tui/selection-colors.js.map +1 -0
- package/dist/tui/selection-colors.ts +45 -0
- package/dist/tui/state.d.ts +14 -0
- package/dist/tui/state.js +46 -0
- package/dist/tui/state.js.map +1 -0
- package/dist/tui/state.ts +65 -0
- package/dist/tui/status-format.d.ts +15 -0
- package/dist/tui/status-format.js +17 -0
- package/dist/tui/status-format.js.map +1 -0
- package/dist/tui/status-format.ts +29 -0
- package/dist/tui/tui.d.ts +7 -0
- package/dist/tui/tui.js +120 -0
- package/dist/tui/tui.js.map +1 -0
- package/dist/tui/tui.tsx +142 -0
- package/dist/tui/usage-auto-refresh.d.ts +16 -0
- package/dist/tui/usage-auto-refresh.js +46 -0
- package/dist/tui/usage-auto-refresh.js.map +1 -0
- package/dist/tui/usage-auto-refresh.ts +64 -0
- package/dist/tui/usage-format.d.ts +2 -0
- package/dist/tui/usage-format.js +17 -0
- package/dist/tui/usage-format.js.map +1 -0
- package/dist/tui/usage-format.ts +14 -0
- package/package.json +10 -3
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "@opentui/solid/jsx-runtime";
|
|
2
|
+
import { createMemo, createSignal, For, onCleanup, onMount, Show } from "solid-js";
|
|
3
|
+
import { listAccounts } from "../../core/accounts";
|
|
4
|
+
import { getBalancingEnabled, setBalancingEnabled } from "../../core/priority";
|
|
5
|
+
import { getUsageSnapshot } from "../../core/usage/store";
|
|
6
|
+
import { dashboardSelectionMarker, moveDashboardFocus, reduceDashboardKey } from "../dashboard-keys";
|
|
7
|
+
import { dashboardContentHeight, dashboardLayoutMode } from "../responsive";
|
|
8
|
+
import { selectedRowColors } from "../selection-colors";
|
|
9
|
+
import { UsageSnapshotBar } from "./usage-display";
|
|
10
|
+
export function Dashboard(props) {
|
|
11
|
+
const theme = () => props.api.theme.current;
|
|
12
|
+
const selectedColors = () => selectedRowColors(theme());
|
|
13
|
+
const [confirmAccount, setConfirmAccount] = createSignal();
|
|
14
|
+
const [accounts, setAccounts] = createSignal(listAccounts(props.state.db));
|
|
15
|
+
const [balancing, setBalancing] = createSignal(getBalancingEnabled(props.state.db));
|
|
16
|
+
const [usage, setUsage] = createSignal({});
|
|
17
|
+
const [cursor, setCursor] = createSignal(0);
|
|
18
|
+
const [headerCursor, setHeaderCursor] = createSignal(0);
|
|
19
|
+
const [focusArea, setFocusArea] = createSignal("content");
|
|
20
|
+
const layoutMode = () => dashboardLayoutMode({
|
|
21
|
+
width: props.api.renderer.width,
|
|
22
|
+
height: props.api.renderer.height,
|
|
23
|
+
});
|
|
24
|
+
const compact = () => layoutMode() === "compact";
|
|
25
|
+
const contentHeight = () => dashboardContentHeight({ height: props.api.renderer.height });
|
|
26
|
+
const headerActions = [
|
|
27
|
+
{ type: "close", key: "close", label: "close" },
|
|
28
|
+
{ type: "priority", key: "priority", label: "priority" },
|
|
29
|
+
];
|
|
30
|
+
const rows = createMemo(() => [
|
|
31
|
+
{ type: "balancing", key: "balancing" },
|
|
32
|
+
{ type: "connect", key: "connect" },
|
|
33
|
+
...accounts().map((account) => ({
|
|
34
|
+
type: "account",
|
|
35
|
+
key: `account:${account.providerID}/${account.alias}`,
|
|
36
|
+
providerID: account.providerID,
|
|
37
|
+
alias: account.alias,
|
|
38
|
+
})),
|
|
39
|
+
]);
|
|
40
|
+
const clampCursor = (value) => Math.max(0, Math.min(value, Math.max(0, rows().length - 1)));
|
|
41
|
+
const clampHeaderCursor = (value) => Math.max(0, Math.min(value, headerActions.length - 1));
|
|
42
|
+
const refreshDashboard = () => {
|
|
43
|
+
const nextAccounts = listAccounts(props.state.db);
|
|
44
|
+
setAccounts(nextAccounts);
|
|
45
|
+
setBalancing(getBalancingEnabled(props.state.db));
|
|
46
|
+
setUsage(Object.fromEntries(nextAccounts.map((account) => [
|
|
47
|
+
`${account.providerID}/${account.alias}`,
|
|
48
|
+
getUsageSnapshot(props.state.db, account.providerID, account.alias),
|
|
49
|
+
])));
|
|
50
|
+
setCursor((value) => clampCursor(value));
|
|
51
|
+
};
|
|
52
|
+
refreshDashboard();
|
|
53
|
+
const timer = setInterval(refreshDashboard, 500);
|
|
54
|
+
onCleanup(() => clearInterval(timer));
|
|
55
|
+
const Button = (buttonProps) => (_jsx("box", { onMouseUp: buttonProps.onClick, paddingLeft: 0, paddingRight: 0, children: _jsxs("text", { fg: buttonProps.danger ? theme().warning : theme().accent, wrapMode: "none", truncate: true, children: ["[ ", buttonProps.label, " ]"] }) }));
|
|
56
|
+
const Chip = (chipProps) => (_jsxs("text", { fg: chipProps.danger ? theme().warning : theme().accent, wrapMode: "none", children: ["[", chipProps.keyName, "] ", _jsx("span", { style: { fg: theme().textMuted }, children: chipProps.label })] }));
|
|
57
|
+
const SectionTitle = (sectionProps) => (_jsxs("box", { flexDirection: "row", gap: 1, height: 1, flexShrink: 0, children: [_jsx("text", { fg: theme().primary, wrapMode: "none", children: sectionProps.label }), _jsx("text", { fg: theme().textMuted, wrapMode: "none", children: sectionProps.count === undefined ? "" : `${sectionProps.count}` })] }));
|
|
58
|
+
const Row = (rowProps) => (_jsx("box", { flexDirection: "row", width: "100%", minWidth: 0, height: 1, flexShrink: 0, backgroundColor: rowProps.selected ? selectedColors().bg : undefined, onMouseUp: rowProps.onMouseUp, children: rowProps.children }));
|
|
59
|
+
const selected = (key) => focusArea() === "content" && rows()[cursor()]?.key === key;
|
|
60
|
+
const headerSelected = (key) => focusArea() === "header" && headerActions[headerCursor()]?.key === key;
|
|
61
|
+
const rowMarker = (key) => dashboardSelectionMarker({
|
|
62
|
+
focusedArea: focusArea(),
|
|
63
|
+
itemArea: "content",
|
|
64
|
+
selected: rows()[cursor()]?.key === key,
|
|
65
|
+
});
|
|
66
|
+
const headerMarker = (key) => dashboardSelectionMarker({
|
|
67
|
+
focusedArea: focusArea(),
|
|
68
|
+
itemArea: "header",
|
|
69
|
+
selected: headerActions[headerCursor()]?.key === key,
|
|
70
|
+
});
|
|
71
|
+
const current = () => rows()[cursor()];
|
|
72
|
+
const currentHeader = () => headerActions[headerCursor()];
|
|
73
|
+
const selectedLabel = () => {
|
|
74
|
+
const row = current();
|
|
75
|
+
if (focusArea() === "header")
|
|
76
|
+
return currentHeader()?.type ?? "header";
|
|
77
|
+
if (!row)
|
|
78
|
+
return "none";
|
|
79
|
+
if (row.type === "balancing")
|
|
80
|
+
return "balancing";
|
|
81
|
+
if (row.type === "connect")
|
|
82
|
+
return "connect";
|
|
83
|
+
if (row.type === "account")
|
|
84
|
+
return `account/${row.providerID}/${row.alias}`;
|
|
85
|
+
return "priority";
|
|
86
|
+
};
|
|
87
|
+
const selectedAction = () => {
|
|
88
|
+
if (focusArea() === "header") {
|
|
89
|
+
const action = currentHeader();
|
|
90
|
+
return action?.type === "close" ? "Enter closes dashboard" : "Enter opens provider priority matrix";
|
|
91
|
+
}
|
|
92
|
+
const row = current();
|
|
93
|
+
if (!row)
|
|
94
|
+
return "Enter opens selected item";
|
|
95
|
+
if (row.type === "balancing")
|
|
96
|
+
return "Enter/Space toggles automatic balancing";
|
|
97
|
+
if (row.type === "connect")
|
|
98
|
+
return "Enter/C connects a new provider";
|
|
99
|
+
if (confirmAccount() === `${row.providerID}/${row.alias}`)
|
|
100
|
+
return "Y confirms removal · N cancels";
|
|
101
|
+
return "R to rename · D requests removal confirmation";
|
|
102
|
+
};
|
|
103
|
+
const accountLabel = (account) => `${account.providerID}/${account.alias} (${account.authType})`;
|
|
104
|
+
const removeCurrent = () => {
|
|
105
|
+
const row = current();
|
|
106
|
+
if (row?.type === "account")
|
|
107
|
+
setConfirmAccount(`${row.providerID}/${row.alias}`);
|
|
108
|
+
};
|
|
109
|
+
const toggleBalancing = () => {
|
|
110
|
+
setBalancingEnabled(props.state.db, !balancing());
|
|
111
|
+
refreshDashboard();
|
|
112
|
+
props.state.refresh();
|
|
113
|
+
};
|
|
114
|
+
const confirmCurrent = () => {
|
|
115
|
+
const row = current();
|
|
116
|
+
if (row?.type === "account" && confirmAccount() === `${row.providerID}/${row.alias}`) {
|
|
117
|
+
setConfirmAccount(undefined);
|
|
118
|
+
props.removeAccount(row.providerID, row.alias);
|
|
119
|
+
refreshDashboard();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const runPrimary = () => {
|
|
123
|
+
if (focusArea() === "header") {
|
|
124
|
+
const action = currentHeader();
|
|
125
|
+
if (action?.type === "close")
|
|
126
|
+
return props.onBack();
|
|
127
|
+
return props.openPriority();
|
|
128
|
+
}
|
|
129
|
+
const row = current();
|
|
130
|
+
if (!row)
|
|
131
|
+
return;
|
|
132
|
+
if (row.type === "balancing")
|
|
133
|
+
return toggleBalancing();
|
|
134
|
+
if (row.type === "connect")
|
|
135
|
+
return props.openConnect();
|
|
136
|
+
if (row.type === "account")
|
|
137
|
+
return setConfirmAccount(`${row.providerID}/${row.alias}`);
|
|
138
|
+
};
|
|
139
|
+
const handleKey = (event) => {
|
|
140
|
+
if (props.api.ui.dialog.open)
|
|
141
|
+
return;
|
|
142
|
+
const intent = reduceDashboardKey({ name: event.name ?? "" });
|
|
143
|
+
switch (intent.type) {
|
|
144
|
+
case "move-cursor":
|
|
145
|
+
{
|
|
146
|
+
const next = moveDashboardFocus({ area: focusArea(), cursor: cursor(), rowCount: rows().length }, intent.delta);
|
|
147
|
+
setFocusArea(next.area);
|
|
148
|
+
setCursor(clampCursor(next.cursor));
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
case "move-header":
|
|
152
|
+
setFocusArea("header");
|
|
153
|
+
setHeaderCursor((value) => clampHeaderCursor(value + intent.delta));
|
|
154
|
+
return;
|
|
155
|
+
case "primary":
|
|
156
|
+
runPrimary();
|
|
157
|
+
return;
|
|
158
|
+
case "priority":
|
|
159
|
+
props.openPriority();
|
|
160
|
+
return;
|
|
161
|
+
case "connect":
|
|
162
|
+
props.openConnect();
|
|
163
|
+
return;
|
|
164
|
+
case "rename": {
|
|
165
|
+
const row = current();
|
|
166
|
+
if (row?.type === "account")
|
|
167
|
+
props.renameAccount(row.providerID, row.alias);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
case "remove":
|
|
171
|
+
removeCurrent();
|
|
172
|
+
return;
|
|
173
|
+
case "confirm":
|
|
174
|
+
confirmCurrent();
|
|
175
|
+
return;
|
|
176
|
+
case "cancel":
|
|
177
|
+
setConfirmAccount(undefined);
|
|
178
|
+
return;
|
|
179
|
+
case "back":
|
|
180
|
+
props.onBack();
|
|
181
|
+
return;
|
|
182
|
+
default:
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
let container;
|
|
187
|
+
onMount(() => container?.focus?.());
|
|
188
|
+
return (_jsxs("box", { ref: (ref) => (container = ref), focusable: true, onKeyDown: (event) => handleKey(event), flexDirection: "column", gap: 0, padding: 1, width: "100%", height: "100%", children: [_jsxs("box", { flexDirection: "column", gap: 0, paddingBottom: 1, flexShrink: 0, children: [_jsxs("text", { fg: theme().primary, wrapMode: "none", overflow: "hidden", truncate: true, children: ["opencode-balancer", compact() ? "" : " control center"] }), _jsx(Show, { when: !compact(), children: _jsx("text", { fg: theme().textMuted, wrapMode: "none", overflow: "hidden", truncate: true, children: "Manage accounts, usage, and provider failover." }) }), _jsx("box", { flexDirection: "row", gap: 1, height: 1, flexShrink: 0, children: _jsx(For, { each: headerActions, children: (action, index) => (_jsx("box", { height: 1, flexShrink: 0, backgroundColor: headerSelected(action.key) ? selectedColors().bg : undefined, onMouseUp: () => {
|
|
189
|
+
setFocusArea("header");
|
|
190
|
+
setHeaderCursor(index());
|
|
191
|
+
if (action.type === "close")
|
|
192
|
+
props.onBack();
|
|
193
|
+
else
|
|
194
|
+
props.openPriority();
|
|
195
|
+
}, children: _jsxs("text", { fg: headerSelected(action.key) ? selectedColors().fg : theme().accent, wrapMode: "none", children: [headerMarker(action.key), " [ ", action.label, " ]"] }) })) }) })] }), _jsxs("scrollbox", { height: contentHeight(), scrollbarOptions: { visible: false }, children: [_jsxs("box", { flexDirection: "column", gap: 0, paddingBottom: 1, onMouseUp: () => setCursor(0), children: [_jsx(SectionTitle, { label: "BALANCING" }), _jsx(Row, { selected: selected("balancing"), onMouseUp: toggleBalancing, children: _jsxs("text", { fg: selected("balancing") ? selectedColors().fg : balancing() ? theme().success : theme().textMuted, wrapMode: "none", overflow: "hidden", truncate: true, children: [rowMarker("balancing"), " Automatic balancing: ", balancing() ? "ON" : "OFF"] }) }), _jsx(Show, { when: !compact(), children: _jsx("text", { fg: theme().textMuted, wrapMode: "none", overflow: "hidden", truncate: true, children: "Enter/Space toggles provider failover. Priority config is in the header." }) })] }), _jsxs("box", { flexDirection: "column", gap: 0, paddingBottom: 1, children: [_jsx(SectionTitle, { label: "ACCOUNTS", count: accounts().length }), _jsxs("box", { flexDirection: "column", gap: 0, flexShrink: 0, onMouseUp: () => setCursor(rows().findIndex((row) => row.key === "connect")), children: [_jsx(Row, { selected: selected("connect"), onMouseUp: props.openConnect, children: _jsxs("text", { fg: selected("connect") ? selectedColors().fg : theme().accent, wrapMode: "none", overflow: "hidden", truncate: true, children: [rowMarker("connect"), " New account"] }) }), _jsx(Show, { when: selected("connect") && !compact(), children: _jsx("text", { fg: theme().textMuted, wrapMode: "none", overflow: "hidden", truncate: true, children: "action: Enter/C opens opencode provider connection" }) })] }), _jsx(Show, { when: accounts().length > 0, fallback: _jsx("text", { fg: theme().textMuted, children: "none" }), children: _jsx(For, { each: accounts(), children: (account) => (_jsxs("box", { flexDirection: "column", gap: 0, flexShrink: 0, onMouseUp: () => setCursor(rows().findIndex((row) => row.key === `account:${account.providerID}/${account.alias}`)), children: [_jsx(Row, { selected: selected(`account:${account.providerID}/${account.alias}`), children: _jsxs("text", { fg: selected(`account:${account.providerID}/${account.alias}`) ? selectedColors().fg : account.disabled ? theme().textMuted : theme().text, wrapMode: "none", overflow: "hidden", truncate: true, children: [rowMarker(`account:${account.providerID}/${account.alias}`), " ", accountLabel(account)] }) }), _jsx(Show, { when: !compact(), children: _jsx(UsageSnapshotBar, { theme: theme(), snapshot: usage()[`${account.providerID}/${account.alias}`], muted: !selected(`account:${account.providerID}/${account.alias}`) }) }), _jsx(Show, { when: confirmAccount() === `${account.providerID}/${account.alias}`, fallback: _jsx(Show, { when: selected(`account:${account.providerID}/${account.alias}`), children: _jsx("text", { fg: theme().textMuted, wrapMode: "none", overflow: "hidden", truncate: true, children: "action: press D to remove this account" }) }), children: _jsxs("box", { flexDirection: "row", gap: 1, children: [_jsx("text", { fg: theme().warning, wrapMode: "none", children: "confirm removal?" }), _jsx(Button, { label: "yes", danger: true, onClick: () => {
|
|
196
|
+
setConfirmAccount(undefined);
|
|
197
|
+
props.removeAccount(account.providerID, account.alias);
|
|
198
|
+
refreshDashboard();
|
|
199
|
+
} }), _jsx(Button, { label: "no", onClick: () => setConfirmAccount(undefined) })] }) })] })) }) })] })] }), _jsxs("box", { flexDirection: "column", gap: 0, children: [_jsx(Show, { when: !compact(), fallback: _jsx("text", { fg: theme().textMuted, wrapMode: "none", truncate: true, children: "\u2191\u2193 move \u00B7 Enter open \u00B7 Space toggle \u00B7 P priority \u00B7 Esc close" }), children: _jsxs("box", { flexDirection: "row", gap: 2, children: [_jsx(Chip, { keyName: "\u2191\u2193", label: "Move" }), _jsx(Chip, { keyName: "Enter", label: "Open" }), _jsx(Chip, { keyName: "Space", label: "Toggle" }), _jsx(Chip, { keyName: "C", label: "Connect" }), _jsx(Chip, { keyName: "P", label: "Priority" }), _jsx(Chip, { keyName: "R", label: "Rename" }), _jsx(Chip, { keyName: "D", label: "Remove", danger: true }), _jsx(Chip, { keyName: "Esc", label: "Close" })] }) }), _jsxs("text", { fg: theme().textMuted, wrapMode: "none", truncate: true, children: ["selected: ", selectedLabel(), " \u00B7 ", selectedAction()] })] })] }));
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=dashboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashboard.js","sourceRoot":"","sources":["../../../src/tui/components/dashboard.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,kBAAkB,EAA2B,MAAM,mBAAmB,CAAC;AAC9H,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAWnD,MAAM,UAAU,SAAS,CAAC,KAQzB;IACG,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC;IAC5C,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC,CAAC;IACxD,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,YAAY,EAAsB,CAAC;IAC/E,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;I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AAC,OAAO,EAAC,GAAG,EAAC,KAAK,EAAC,QAAQ,GAAG,EACnC,KAAC,IAAI,IAAC,OAAO,EAAC,GAAG,EAAC,KAAK,EAAC,QAAQ,EAAC,MAAM,SAAG,EAC1C,KAAC,IAAI,IAAC,OAAO,EAAC,KAAK,EAAC,KAAK,EAAC,OAAO,GAAG,IAClC,GACH,EACP,gBAAM,EAAE,EAAE,KAAK,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,EAAC,QAAQ,iCACtC,aAAa,EAAE,cAAK,cAAc,EAAE,IAC5C,IACL,IACJ,CACT,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
|
|
3
|
+
import type { TuiPluginApi } from "@opencode-ai/plugin/tui";
|
|
4
|
+
import { createMemo, createSignal, For, onCleanup, onMount, Show } from "solid-js";
|
|
5
|
+
import { listAccounts } from "../../core/accounts";
|
|
6
|
+
import { getBalancingEnabled, setBalancingEnabled } from "../../core/priority";
|
|
7
|
+
import { getUsageSnapshot } from "../../core/usage/store";
|
|
8
|
+
import type { ProviderUsageSnapshot } from "../../core/usage/types";
|
|
9
|
+
import { dashboardSelectionMarker, moveDashboardFocus, reduceDashboardKey, type DashboardFocusArea } from "../dashboard-keys";
|
|
10
|
+
import { dashboardContentHeight, dashboardLayoutMode } from "../responsive";
|
|
11
|
+
import { selectedRowColors } from "../selection-colors";
|
|
12
|
+
import type { BalancerTuiState } from "../state";
|
|
13
|
+
import { UsageSnapshotBar } from "./usage-display";
|
|
14
|
+
|
|
15
|
+
type KeyLike = { name?: string };
|
|
16
|
+
|
|
17
|
+
type DashboardRow =
|
|
18
|
+
| { type: "balancing"; key: string }
|
|
19
|
+
| { type: "connect"; key: string }
|
|
20
|
+
| { type: "account"; key: string; providerID: string; alias: string };
|
|
21
|
+
|
|
22
|
+
type HeaderAction = { type: "close" | "priority"; key: string; label: string };
|
|
23
|
+
|
|
24
|
+
export function Dashboard(props: {
|
|
25
|
+
api: TuiPluginApi;
|
|
26
|
+
state: BalancerTuiState;
|
|
27
|
+
onBack: () => void;
|
|
28
|
+
openPriority: () => void;
|
|
29
|
+
openConnect: () => void;
|
|
30
|
+
renameAccount: (providerID: string, alias: string) => void;
|
|
31
|
+
removeAccount: (providerID: string, alias: string) => void;
|
|
32
|
+
}) {
|
|
33
|
+
const theme = () => props.api.theme.current;
|
|
34
|
+
const selectedColors = () => selectedRowColors(theme());
|
|
35
|
+
const [confirmAccount, setConfirmAccount] = createSignal<string | undefined>();
|
|
36
|
+
const [accounts, setAccounts] = createSignal(listAccounts(props.state.db));
|
|
37
|
+
const [balancing, setBalancing] = createSignal(getBalancingEnabled(props.state.db));
|
|
38
|
+
const [usage, setUsage] = createSignal<Record<string, ProviderUsageSnapshot | undefined>>({});
|
|
39
|
+
const [cursor, setCursor] = createSignal(0);
|
|
40
|
+
const [headerCursor, setHeaderCursor] = createSignal(0);
|
|
41
|
+
const [focusArea, setFocusArea] = createSignal<DashboardFocusArea>("content");
|
|
42
|
+
const layoutMode = () =>
|
|
43
|
+
dashboardLayoutMode({
|
|
44
|
+
width: (props.api.renderer as unknown as { width?: number }).width,
|
|
45
|
+
height: (props.api.renderer as unknown as { height?: number }).height,
|
|
46
|
+
});
|
|
47
|
+
const compact = () => layoutMode() === "compact";
|
|
48
|
+
const contentHeight = () =>
|
|
49
|
+
dashboardContentHeight({ height: (props.api.renderer as unknown as { height?: number }).height });
|
|
50
|
+
const headerActions: HeaderAction[] = [
|
|
51
|
+
{ type: "close", key: "close", label: "close" },
|
|
52
|
+
{ type: "priority", key: "priority", label: "priority" },
|
|
53
|
+
];
|
|
54
|
+
const rows = createMemo<DashboardRow[]>(() => [
|
|
55
|
+
{ type: "balancing", key: "balancing" },
|
|
56
|
+
{ type: "connect", key: "connect" },
|
|
57
|
+
...accounts().map((account) => ({
|
|
58
|
+
type: "account" as const,
|
|
59
|
+
key: `account:${account.providerID}/${account.alias}`,
|
|
60
|
+
providerID: account.providerID,
|
|
61
|
+
alias: account.alias,
|
|
62
|
+
})),
|
|
63
|
+
]);
|
|
64
|
+
const clampCursor = (value: number) => Math.max(0, Math.min(value, Math.max(0, rows().length - 1)));
|
|
65
|
+
const clampHeaderCursor = (value: number) => Math.max(0, Math.min(value, headerActions.length - 1));
|
|
66
|
+
const refreshDashboard = () => {
|
|
67
|
+
const nextAccounts = listAccounts(props.state.db);
|
|
68
|
+
setAccounts(nextAccounts);
|
|
69
|
+
setBalancing(getBalancingEnabled(props.state.db));
|
|
70
|
+
setUsage(
|
|
71
|
+
Object.fromEntries(
|
|
72
|
+
nextAccounts.map((account) => [
|
|
73
|
+
`${account.providerID}/${account.alias}`,
|
|
74
|
+
getUsageSnapshot(props.state.db, account.providerID, account.alias),
|
|
75
|
+
]),
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
setCursor((value) => clampCursor(value));
|
|
79
|
+
};
|
|
80
|
+
refreshDashboard();
|
|
81
|
+
const timer = setInterval(refreshDashboard, 500);
|
|
82
|
+
onCleanup(() => clearInterval(timer));
|
|
83
|
+
const Button = (buttonProps: { label: string; danger?: boolean; onClick: () => void }) => (
|
|
84
|
+
<box onMouseUp={buttonProps.onClick} paddingLeft={0} paddingRight={0}>
|
|
85
|
+
<text fg={buttonProps.danger ? theme().warning : theme().accent} wrapMode="none" truncate>
|
|
86
|
+
[ {buttonProps.label} ]
|
|
87
|
+
</text>
|
|
88
|
+
</box>
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const Chip = (chipProps: { keyName: string; label: string; danger?: boolean }) => (
|
|
92
|
+
<text fg={chipProps.danger ? theme().warning : theme().accent} wrapMode="none">
|
|
93
|
+
[{chipProps.keyName}] <span style={{ fg: theme().textMuted }}>{chipProps.label}</span>
|
|
94
|
+
</text>
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const SectionTitle = (sectionProps: { label: string; count?: number }) => (
|
|
98
|
+
<box flexDirection="row" gap={1} height={1} flexShrink={0}>
|
|
99
|
+
<text fg={theme().primary} wrapMode="none">
|
|
100
|
+
{sectionProps.label}
|
|
101
|
+
</text>
|
|
102
|
+
<text fg={theme().textMuted} wrapMode="none">
|
|
103
|
+
{sectionProps.count === undefined ? "" : `${sectionProps.count}`}
|
|
104
|
+
</text>
|
|
105
|
+
</box>
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const Row = (rowProps: { selected?: boolean; onMouseUp?: () => void; children: unknown }) => (
|
|
109
|
+
<box
|
|
110
|
+
flexDirection="row"
|
|
111
|
+
width="100%"
|
|
112
|
+
minWidth={0}
|
|
113
|
+
height={1}
|
|
114
|
+
flexShrink={0}
|
|
115
|
+
backgroundColor={rowProps.selected ? selectedColors().bg : undefined}
|
|
116
|
+
onMouseUp={rowProps.onMouseUp}
|
|
117
|
+
>
|
|
118
|
+
{rowProps.children}
|
|
119
|
+
</box>
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const selected = (key: string) => focusArea() === "content" && rows()[cursor()]?.key === key;
|
|
123
|
+
const headerSelected = (key: string) => focusArea() === "header" && headerActions[headerCursor()]?.key === key;
|
|
124
|
+
const rowMarker = (key: string) =>
|
|
125
|
+
dashboardSelectionMarker({
|
|
126
|
+
focusedArea: focusArea(),
|
|
127
|
+
itemArea: "content",
|
|
128
|
+
selected: rows()[cursor()]?.key === key,
|
|
129
|
+
});
|
|
130
|
+
const headerMarker = (key: string) =>
|
|
131
|
+
dashboardSelectionMarker({
|
|
132
|
+
focusedArea: focusArea(),
|
|
133
|
+
itemArea: "header",
|
|
134
|
+
selected: headerActions[headerCursor()]?.key === key,
|
|
135
|
+
});
|
|
136
|
+
const current = () => rows()[cursor()];
|
|
137
|
+
const currentHeader = () => headerActions[headerCursor()];
|
|
138
|
+
const selectedLabel = () => {
|
|
139
|
+
const row = current();
|
|
140
|
+
if (focusArea() === "header") return currentHeader()?.type ?? "header";
|
|
141
|
+
if (!row) return "none";
|
|
142
|
+
if (row.type === "balancing") return "balancing";
|
|
143
|
+
if (row.type === "connect") return "connect";
|
|
144
|
+
if (row.type === "account") return `account/${row.providerID}/${row.alias}`;
|
|
145
|
+
return "priority";
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const selectedAction = () => {
|
|
149
|
+
if (focusArea() === "header") {
|
|
150
|
+
const action = currentHeader();
|
|
151
|
+
return action?.type === "close" ? "Enter closes dashboard" : "Enter opens provider priority matrix";
|
|
152
|
+
}
|
|
153
|
+
const row = current();
|
|
154
|
+
if (!row) return "Enter opens selected item";
|
|
155
|
+
if (row.type === "balancing") return "Enter/Space toggles automatic balancing";
|
|
156
|
+
if (row.type === "connect") return "Enter/C connects a new provider";
|
|
157
|
+
if (confirmAccount() === `${row.providerID}/${row.alias}`) return "Y confirms removal · N cancels";
|
|
158
|
+
return "R to rename · D requests removal confirmation";
|
|
159
|
+
};
|
|
160
|
+
const accountLabel = (account: { providerID: string; alias: string; authType: string }) =>
|
|
161
|
+
`${account.providerID}/${account.alias} (${account.authType})`;
|
|
162
|
+
const removeCurrent = () => {
|
|
163
|
+
const row = current();
|
|
164
|
+
if (row?.type === "account") setConfirmAccount(`${row.providerID}/${row.alias}`);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const toggleBalancing = () => {
|
|
168
|
+
setBalancingEnabled(props.state.db, !balancing());
|
|
169
|
+
refreshDashboard();
|
|
170
|
+
props.state.refresh();
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const confirmCurrent = () => {
|
|
174
|
+
const row = current();
|
|
175
|
+
if (row?.type === "account" && confirmAccount() === `${row.providerID}/${row.alias}`) {
|
|
176
|
+
setConfirmAccount(undefined);
|
|
177
|
+
props.removeAccount(row.providerID, row.alias);
|
|
178
|
+
refreshDashboard();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const runPrimary = () => {
|
|
183
|
+
if (focusArea() === "header") {
|
|
184
|
+
const action = currentHeader();
|
|
185
|
+
if (action?.type === "close") return props.onBack();
|
|
186
|
+
return props.openPriority();
|
|
187
|
+
}
|
|
188
|
+
const row = current();
|
|
189
|
+
if (!row) return;
|
|
190
|
+
if (row.type === "balancing") return toggleBalancing();
|
|
191
|
+
if (row.type === "connect") return props.openConnect();
|
|
192
|
+
if (row.type === "account") return setConfirmAccount(`${row.providerID}/${row.alias}`);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const handleKey = (event: KeyLike) => {
|
|
196
|
+
if (props.api.ui.dialog.open) return;
|
|
197
|
+
const intent = reduceDashboardKey({ name: event.name ?? "" });
|
|
198
|
+
switch (intent.type) {
|
|
199
|
+
case "move-cursor":
|
|
200
|
+
{
|
|
201
|
+
const next = moveDashboardFocus(
|
|
202
|
+
{ area: focusArea(), cursor: cursor(), rowCount: rows().length },
|
|
203
|
+
intent.delta,
|
|
204
|
+
);
|
|
205
|
+
setFocusArea(next.area);
|
|
206
|
+
setCursor(clampCursor(next.cursor));
|
|
207
|
+
}
|
|
208
|
+
return;
|
|
209
|
+
case "move-header":
|
|
210
|
+
setFocusArea("header");
|
|
211
|
+
setHeaderCursor((value) => clampHeaderCursor(value + intent.delta));
|
|
212
|
+
return;
|
|
213
|
+
case "primary":
|
|
214
|
+
runPrimary();
|
|
215
|
+
return;
|
|
216
|
+
case "priority":
|
|
217
|
+
props.openPriority();
|
|
218
|
+
return;
|
|
219
|
+
case "connect":
|
|
220
|
+
props.openConnect();
|
|
221
|
+
return;
|
|
222
|
+
case "rename": {
|
|
223
|
+
const row = current();
|
|
224
|
+
if (row?.type === "account") props.renameAccount(row.providerID, row.alias);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
case "remove":
|
|
228
|
+
removeCurrent();
|
|
229
|
+
return;
|
|
230
|
+
case "confirm":
|
|
231
|
+
confirmCurrent();
|
|
232
|
+
return;
|
|
233
|
+
case "cancel":
|
|
234
|
+
setConfirmAccount(undefined);
|
|
235
|
+
return;
|
|
236
|
+
case "back":
|
|
237
|
+
props.onBack();
|
|
238
|
+
return;
|
|
239
|
+
default:
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
let container: { focus?: () => void } | undefined;
|
|
245
|
+
onMount(() => container?.focus?.());
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<box
|
|
249
|
+
ref={(ref: unknown) => (container = ref as { focus?: () => void })}
|
|
250
|
+
focusable
|
|
251
|
+
onKeyDown={(event: KeyLike) => handleKey(event)}
|
|
252
|
+
flexDirection="column"
|
|
253
|
+
gap={0}
|
|
254
|
+
padding={1}
|
|
255
|
+
width="100%"
|
|
256
|
+
height="100%"
|
|
257
|
+
>
|
|
258
|
+
<box flexDirection="column" gap={0} paddingBottom={1} flexShrink={0}>
|
|
259
|
+
<text fg={theme().primary} wrapMode="none" overflow="hidden" truncate>
|
|
260
|
+
opencode-balancer{compact() ? "" : " control center"}
|
|
261
|
+
</text>
|
|
262
|
+
<Show when={!compact()}>
|
|
263
|
+
<text fg={theme().textMuted} wrapMode="none" overflow="hidden" truncate>
|
|
264
|
+
Manage accounts, usage, and provider failover.
|
|
265
|
+
</text>
|
|
266
|
+
</Show>
|
|
267
|
+
<box flexDirection="row" gap={1} height={1} flexShrink={0}>
|
|
268
|
+
<For each={headerActions}>
|
|
269
|
+
{(action, index) => (
|
|
270
|
+
<box
|
|
271
|
+
height={1}
|
|
272
|
+
flexShrink={0}
|
|
273
|
+
backgroundColor={headerSelected(action.key) ? selectedColors().bg : undefined}
|
|
274
|
+
onMouseUp={() => {
|
|
275
|
+
setFocusArea("header");
|
|
276
|
+
setHeaderCursor(index());
|
|
277
|
+
if (action.type === "close") props.onBack();
|
|
278
|
+
else props.openPriority();
|
|
279
|
+
}}
|
|
280
|
+
>
|
|
281
|
+
<text fg={headerSelected(action.key) ? selectedColors().fg : theme().accent} wrapMode="none">
|
|
282
|
+
{headerMarker(action.key)} [ {action.label} ]
|
|
283
|
+
</text>
|
|
284
|
+
</box>
|
|
285
|
+
)}
|
|
286
|
+
</For>
|
|
287
|
+
</box>
|
|
288
|
+
</box>
|
|
289
|
+
|
|
290
|
+
<scrollbox height={contentHeight()} scrollbarOptions={{ visible: false }}>
|
|
291
|
+
<box flexDirection="column" gap={0} paddingBottom={1} onMouseUp={() => setCursor(0)}>
|
|
292
|
+
<SectionTitle label="BALANCING" />
|
|
293
|
+
<Row selected={selected("balancing")} onMouseUp={toggleBalancing}>
|
|
294
|
+
<text fg={selected("balancing") ? selectedColors().fg : balancing() ? theme().success : theme().textMuted} wrapMode="none" overflow="hidden" truncate>
|
|
295
|
+
{rowMarker("balancing")} Automatic balancing: {balancing() ? "ON" : "OFF"}
|
|
296
|
+
</text>
|
|
297
|
+
</Row>
|
|
298
|
+
<Show when={!compact()}>
|
|
299
|
+
<text fg={theme().textMuted} wrapMode="none" overflow="hidden" truncate>
|
|
300
|
+
Enter/Space toggles provider failover. Priority config is in the header.
|
|
301
|
+
</text>
|
|
302
|
+
</Show>
|
|
303
|
+
</box>
|
|
304
|
+
|
|
305
|
+
<box flexDirection="column" gap={0} paddingBottom={1}>
|
|
306
|
+
<SectionTitle label="ACCOUNTS" count={accounts().length} />
|
|
307
|
+
<box flexDirection="column" gap={0} flexShrink={0} onMouseUp={() => setCursor(rows().findIndex((row) => row.key === "connect"))}>
|
|
308
|
+
<Row selected={selected("connect")} onMouseUp={props.openConnect}>
|
|
309
|
+
<text fg={selected("connect") ? selectedColors().fg : theme().accent} wrapMode="none" overflow="hidden" truncate>
|
|
310
|
+
{rowMarker("connect")} New account
|
|
311
|
+
</text>
|
|
312
|
+
</Row>
|
|
313
|
+
<Show when={selected("connect") && !compact()}>
|
|
314
|
+
<text fg={theme().textMuted} wrapMode="none" overflow="hidden" truncate>
|
|
315
|
+
action: Enter/C opens opencode provider connection
|
|
316
|
+
</text>
|
|
317
|
+
</Show>
|
|
318
|
+
</box>
|
|
319
|
+
<Show when={accounts().length > 0} fallback={<text fg={theme().textMuted}>none</text>}>
|
|
320
|
+
<For each={accounts()}>
|
|
321
|
+
{(account) => (
|
|
322
|
+
<box flexDirection="column" gap={0} flexShrink={0} onMouseUp={() => setCursor(rows().findIndex((row) => row.key === `account:${account.providerID}/${account.alias}`))}>
|
|
323
|
+
<Row selected={selected(`account:${account.providerID}/${account.alias}`)}>
|
|
324
|
+
<text fg={selected(`account:${account.providerID}/${account.alias}`) ? selectedColors().fg : account.disabled ? theme().textMuted : theme().text} wrapMode="none" overflow="hidden" truncate>
|
|
325
|
+
{rowMarker(`account:${account.providerID}/${account.alias}`)} {accountLabel(account)}
|
|
326
|
+
</text>
|
|
327
|
+
</Row>
|
|
328
|
+
<Show when={!compact()}>
|
|
329
|
+
<UsageSnapshotBar
|
|
330
|
+
theme={theme()}
|
|
331
|
+
snapshot={usage()[`${account.providerID}/${account.alias}`]}
|
|
332
|
+
muted={!selected(`account:${account.providerID}/${account.alias}`)}
|
|
333
|
+
/>
|
|
334
|
+
</Show>
|
|
335
|
+
<Show
|
|
336
|
+
when={confirmAccount() === `${account.providerID}/${account.alias}`}
|
|
337
|
+
fallback={
|
|
338
|
+
<Show when={selected(`account:${account.providerID}/${account.alias}`)}>
|
|
339
|
+
<text fg={theme().textMuted} wrapMode="none" overflow="hidden" truncate>
|
|
340
|
+
action: press D to remove this account
|
|
341
|
+
</text>
|
|
342
|
+
</Show>
|
|
343
|
+
}
|
|
344
|
+
>
|
|
345
|
+
<box flexDirection="row" gap={1}>
|
|
346
|
+
<text fg={theme().warning} wrapMode="none">confirm removal?</text>
|
|
347
|
+
<Button
|
|
348
|
+
label="yes"
|
|
349
|
+
danger
|
|
350
|
+
onClick={() => {
|
|
351
|
+
setConfirmAccount(undefined);
|
|
352
|
+
props.removeAccount(account.providerID, account.alias);
|
|
353
|
+
refreshDashboard();
|
|
354
|
+
}}
|
|
355
|
+
/>
|
|
356
|
+
<Button label="no" onClick={() => setConfirmAccount(undefined)} />
|
|
357
|
+
</box>
|
|
358
|
+
</Show>
|
|
359
|
+
</box>
|
|
360
|
+
)}
|
|
361
|
+
</For>
|
|
362
|
+
</Show>
|
|
363
|
+
</box>
|
|
364
|
+
|
|
365
|
+
</scrollbox>
|
|
366
|
+
|
|
367
|
+
<box flexDirection="column" gap={0}>
|
|
368
|
+
<Show
|
|
369
|
+
when={!compact()}
|
|
370
|
+
fallback={
|
|
371
|
+
<text fg={theme().textMuted} wrapMode="none" truncate>
|
|
372
|
+
↑↓ move · Enter open · Space toggle · P priority · Esc close
|
|
373
|
+
</text>
|
|
374
|
+
}
|
|
375
|
+
>
|
|
376
|
+
<box flexDirection="row" gap={2}>
|
|
377
|
+
<Chip keyName="↑↓" label="Move" />
|
|
378
|
+
<Chip keyName="Enter" label="Open" />
|
|
379
|
+
<Chip keyName="Space" label="Toggle" />
|
|
380
|
+
<Chip keyName="C" label="Connect" />
|
|
381
|
+
<Chip keyName="P" label="Priority" />
|
|
382
|
+
<Chip keyName="R" label="Rename" />
|
|
383
|
+
<Chip keyName="D" label="Remove" danger />
|
|
384
|
+
<Chip keyName="Esc" label="Close" />
|
|
385
|
+
</box>
|
|
386
|
+
</Show>
|
|
387
|
+
<text fg={theme().textMuted} wrapMode="none" truncate>
|
|
388
|
+
selected: {selectedLabel()} · {selectedAction()}
|
|
389
|
+
</text>
|
|
390
|
+
</box>
|
|
391
|
+
</box>
|
|
392
|
+
);
|
|
393
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
import type { TuiPluginApi } from "@opencode-ai/plugin/tui";
|
|
3
|
+
import type { BalancerTuiState } from "../state";
|
|
4
|
+
export declare function PriorityScreen(props: {
|
|
5
|
+
api: TuiPluginApi;
|
|
6
|
+
state: BalancerTuiState;
|
|
7
|
+
onBack: () => void;
|
|
8
|
+
openModelPicker: (providerID: string) => void;
|
|
9
|
+
}): any;
|