opencode-openai-session-router 0.0.0-stage → 0.1.0
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/LICENSE +674 -0
- package/README.md +217 -2
- package/dist/accounts.d.ts +31 -0
- package/dist/bun.lock.txt +671 -0
- package/dist/chunks/index-85yd61pa.js +29 -0
- package/dist/chunks/index-n7sr1hee.js +803 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1842 -0
- package/dist/network.d.ts +8 -0
- package/dist/panel-contract.d.ts +14 -0
- package/dist/persistence.d.ts +40 -0
- package/dist/relay-protocol.d.ts +86 -0
- package/dist/relay.d.ts +50 -0
- package/dist/retry-control.d.ts +41 -0
- package/dist/router.d.ts +55 -0
- package/dist/rpc.d.ts +98 -0
- package/dist/rpc.js +7 -0
- package/dist/runtime.d.ts +94 -0
- package/dist/settings.d.ts +32 -0
- package/dist/sidebar-colors.d.ts +10 -0
- package/dist/sidebar-model.d.ts +82 -0
- package/dist/sidebar.d.ts +33 -0
- package/dist/sidebar.js +12 -0
- package/dist/tui.d.ts +3 -0
- package/dist/tui.js +25 -0
- package/package.json +52 -4
- package/scripts/build.ts +39 -0
- package/src/accounts.ts +130 -0
- package/src/index.ts +203 -0
- package/src/network.ts +25 -0
- package/src/panel-contract.ts +15 -0
- package/src/persistence.ts +96 -0
- package/src/relay-protocol.ts +157 -0
- package/src/relay.ts +593 -0
- package/src/retry-control.ts +92 -0
- package/src/router.ts +156 -0
- package/src/rpc.ts +28 -0
- package/src/runtime.ts +319 -0
- package/src/settings.ts +68 -0
- package/src/sidebar-colors.ts +132 -0
- package/src/sidebar-model.ts +257 -0
- package/src/sidebar.tsx +438 -0
- package/src/tui.tsx +12 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +16 -0
package/src/sidebar.tsx
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { usePlugin } from "@opencode/plugin/tui";
|
|
2
|
+
import { createEffect, createMemo, createSignal, For, onCleanup, Show, untrack } from "solid-js";
|
|
3
|
+
import type { AgentInfo, SessionInfo } from "@opencode/client";
|
|
4
|
+
import {
|
|
5
|
+
acceptSnapshotEvent,
|
|
6
|
+
acceptSnapshotFetch,
|
|
7
|
+
beginSnapshotRequest,
|
|
8
|
+
BASELINE_CHILDREN,
|
|
9
|
+
createPrimaryClickHandler,
|
|
10
|
+
initialSnapshotEpochState,
|
|
11
|
+
moreCount,
|
|
12
|
+
nextVisibleChildren,
|
|
13
|
+
navigateSidebarRow,
|
|
14
|
+
projectSidebar,
|
|
15
|
+
requestRoutingToggle,
|
|
16
|
+
type PrimaryPointerEvent,
|
|
17
|
+
snapshotRequestIsAuthoritative,
|
|
18
|
+
toggleSidebarCollapsed,
|
|
19
|
+
} from "./sidebar-model";
|
|
20
|
+
import type { SidebarAgent, SidebarRow, SnapshotEpochState } from "./sidebar-model";
|
|
21
|
+
import { categoricalAgentPalette, resolveAgentColor, resolveHoverBackground, themeColor } from "./sidebar-colors";
|
|
22
|
+
import type { SidebarColor } from "./sidebar-colors";
|
|
23
|
+
import { RouterRpc } from "./rpc";
|
|
24
|
+
|
|
25
|
+
const COLORS = {
|
|
26
|
+
green: "#168a58",
|
|
27
|
+
red: "#bd4650",
|
|
28
|
+
slate: "#7f8da3",
|
|
29
|
+
white: "#ffffff",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function pointerWithinRenderable(
|
|
33
|
+
currentTarget: {
|
|
34
|
+
readonly screenX: number;
|
|
35
|
+
readonly screenY: number;
|
|
36
|
+
readonly width: number;
|
|
37
|
+
readonly height: number;
|
|
38
|
+
} | null,
|
|
39
|
+
x: number,
|
|
40
|
+
y: number,
|
|
41
|
+
): boolean {
|
|
42
|
+
if (!currentTarget) return false;
|
|
43
|
+
return x >= currentTarget.screenX &&
|
|
44
|
+
x < currentTarget.screenX + currentTarget.width &&
|
|
45
|
+
y >= currentTarget.screenY &&
|
|
46
|
+
y < currentTarget.screenY + currentTarget.height;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function SessionSidebar(props: { sessionID: string }) {
|
|
50
|
+
const ctx = usePlugin();
|
|
51
|
+
const [visibleChildren, setVisibleChildren] = createSignal(BASELINE_CHILDREN);
|
|
52
|
+
const [listCollapsed, setListCollapsed] = createSignal(false);
|
|
53
|
+
const [epochState, setEpochState] = createSignal<SnapshotEpochState>(initialSnapshotEpochState());
|
|
54
|
+
const [rpcError, setRpcError] = createSignal(false);
|
|
55
|
+
const [toggleError, setToggleError] = createSignal(false);
|
|
56
|
+
const [togglePending, setTogglePending] = createSignal(false);
|
|
57
|
+
const [sessionTree, setSessionTree] = createSignal<SessionInfo[]>([]);
|
|
58
|
+
const [isRoot, setIsRoot] = createSignal(false);
|
|
59
|
+
const [treeError, setTreeError] = createSignal(false);
|
|
60
|
+
let locationEpoch = 0;
|
|
61
|
+
type RootLocation = { readonly directory: string };
|
|
62
|
+
const [rootLocation, setRootLocation] = createSignal<RootLocation | undefined>(undefined, {
|
|
63
|
+
equals: (a, b) => a?.directory === b?.directory,
|
|
64
|
+
});
|
|
65
|
+
const rootID = () => props.sessionID;
|
|
66
|
+
const theme = () => ctx.theme as unknown;
|
|
67
|
+
const muted = createMemo(() => themeColor(theme(), [["text", "muted"], ["text", "subdued"]], COLORS.slate));
|
|
68
|
+
const accent = createMemo(() => themeColor(theme(), [["hue", "interactive", 200]], "#54b8d4"));
|
|
69
|
+
const hoverBackground = createMemo(() => resolveHoverBackground(theme()));
|
|
70
|
+
const palette = createMemo(() => categoricalAgentPalette(
|
|
71
|
+
(ctx.theme as unknown as { categorical?: unknown } | undefined)?.categorical,
|
|
72
|
+
));
|
|
73
|
+
const agents = createMemo<SidebarAgent[]>(() => {
|
|
74
|
+
const location = ctx.location ?? ctx.data.location.default();
|
|
75
|
+
return (ctx.data.location.agent.list(location) ?? [])
|
|
76
|
+
.map((agent: AgentInfo) => ({
|
|
77
|
+
id: agent.id,
|
|
78
|
+
name: agent.name,
|
|
79
|
+
color: agent.color,
|
|
80
|
+
hidden: agent.hidden,
|
|
81
|
+
}));
|
|
82
|
+
});
|
|
83
|
+
const agentColor = (agentID: string) => resolveAgentColor(agentID, agents(), palette(), muted());
|
|
84
|
+
|
|
85
|
+
// Plugin Data is a cache, not a guaranteed session index.
|
|
86
|
+
createEffect(() => {
|
|
87
|
+
const sessionID = props.sessionID;
|
|
88
|
+
let disposed = false;
|
|
89
|
+
let requestID = 0;
|
|
90
|
+
let reloadQueued = false;
|
|
91
|
+
setVisibleChildren(BASELINE_CHILDREN);
|
|
92
|
+
setListCollapsed(false);
|
|
93
|
+
setIsRoot(false);
|
|
94
|
+
setRootLocation(undefined);
|
|
95
|
+
setTreeError(false);
|
|
96
|
+
setSessionTree([]);
|
|
97
|
+
const load = async () => {
|
|
98
|
+
const currentRequest = ++requestID;
|
|
99
|
+
const isCurrent = () => !disposed && currentRequest === requestID;
|
|
100
|
+
try {
|
|
101
|
+
let active = await ctx.client.session.get({ sessionID });
|
|
102
|
+
if (!isCurrent()) return;
|
|
103
|
+
const seen = new Set<string>([active.id]);
|
|
104
|
+
while (active.parentID && !seen.has(active.parentID)) {
|
|
105
|
+
seen.add(active.parentID);
|
|
106
|
+
active = await ctx.client.session.get({ sessionID: active.parentID });
|
|
107
|
+
if (!isCurrent()) return;
|
|
108
|
+
}
|
|
109
|
+
if (active.id !== sessionID || active.parentID) return;
|
|
110
|
+
const sessionLocation = active.location as RootLocation;
|
|
111
|
+
setRootLocation({ directory: sessionLocation.directory });
|
|
112
|
+
setIsRoot(true);
|
|
113
|
+
setSessionTree((previous) => previous.some((item) => item.id === active.id)
|
|
114
|
+
? previous.map((item) => item.id === active.id ? active : item)
|
|
115
|
+
: [active, ...previous]);
|
|
116
|
+
setTreeError(false);
|
|
117
|
+
const collected = new Map<string, SessionInfo>([[active.id, active]]);
|
|
118
|
+
const pending = [active.id];
|
|
119
|
+
while (pending.length) {
|
|
120
|
+
const parentID = pending.pop()!;
|
|
121
|
+
let cursor: string | undefined;
|
|
122
|
+
do {
|
|
123
|
+
const page = await ctx.client.session.list({ parentID, order: "desc", limit: 100, cursor });
|
|
124
|
+
if (!isCurrent()) return;
|
|
125
|
+
for (const child of page.data) {
|
|
126
|
+
if (!collected.has(child.id)) {
|
|
127
|
+
collected.set(child.id, child);
|
|
128
|
+
pending.push(child.id);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
cursor = page.cursor.next ?? undefined;
|
|
132
|
+
} while (cursor);
|
|
133
|
+
}
|
|
134
|
+
if (!isCurrent()) return;
|
|
135
|
+
setSessionTree([...collected.values()]);
|
|
136
|
+
setTreeError(false);
|
|
137
|
+
} catch {
|
|
138
|
+
if (isCurrent()) setTreeError(true);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
void load();
|
|
142
|
+
const queueLoad = () => {
|
|
143
|
+
if (disposed || reloadQueued) return;
|
|
144
|
+
reloadQueued = true;
|
|
145
|
+
queueMicrotask(() => {
|
|
146
|
+
reloadQueued = false;
|
|
147
|
+
if (!disposed) void load();
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
const offEvents = ctx.data.listen(({ details }) => {
|
|
151
|
+
let eventSessionID: string;
|
|
152
|
+
let parentID: string | undefined;
|
|
153
|
+
if (details.type === "session.created") {
|
|
154
|
+
eventSessionID = details.data.sessionID;
|
|
155
|
+
parentID = details.data.parentID;
|
|
156
|
+
} else if (
|
|
157
|
+
details.type === "session.deleted" ||
|
|
158
|
+
details.type === "session.moved" ||
|
|
159
|
+
details.type === "session.execution.started" ||
|
|
160
|
+
details.type === "session.execution.succeeded" ||
|
|
161
|
+
details.type === "session.execution.failed" ||
|
|
162
|
+
details.type === "session.execution.interrupted"
|
|
163
|
+
) {
|
|
164
|
+
eventSessionID = details.data.sessionID;
|
|
165
|
+
} else {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const knownIDs = new Set(sessionTree().map((item) => item.id));
|
|
169
|
+
if (eventSessionID === sessionID || knownIDs.has(eventSessionID) || knownIDs.has(parentID ?? "")) {
|
|
170
|
+
queueLoad();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
onCleanup(() => { disposed = true; offEvents(); });
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Subscribe before fetching. Revision checks prevent a late initial snapshot
|
|
177
|
+
// from replacing a newer live event.
|
|
178
|
+
createEffect(() => {
|
|
179
|
+
if (!isRoot()) return;
|
|
180
|
+
const location = rootLocation();
|
|
181
|
+
if (!location) return;
|
|
182
|
+
setVisibleChildren(BASELINE_CHILDREN);
|
|
183
|
+
setEpochState(initialSnapshotEpochState());
|
|
184
|
+
setRpcError(false);
|
|
185
|
+
setToggleError(false);
|
|
186
|
+
setTogglePending(false);
|
|
187
|
+
const rpc = ctx.client.rpc(RouterRpc);
|
|
188
|
+
let disposed = false;
|
|
189
|
+
const lifecycle = ++locationEpoch;
|
|
190
|
+
const refresh = () => {
|
|
191
|
+
let requestToken = 0;
|
|
192
|
+
const before = untrack(epochState);
|
|
193
|
+
setEpochState((state) => {
|
|
194
|
+
const next = beginSnapshotRequest(state);
|
|
195
|
+
requestToken = next.requestToken;
|
|
196
|
+
return next;
|
|
197
|
+
});
|
|
198
|
+
void rpc.snapshot({}, { location: { directory: location.directory } }).then((value) => {
|
|
199
|
+
if (disposed) return;
|
|
200
|
+
let accepted = false;
|
|
201
|
+
setEpochState((state) => {
|
|
202
|
+
const next = acceptSnapshotFetch(state, value, requestToken);
|
|
203
|
+
accepted = next !== state;
|
|
204
|
+
return next;
|
|
205
|
+
});
|
|
206
|
+
if (accepted) setRpcError(false);
|
|
207
|
+
}).catch(() => {
|
|
208
|
+
if (!disposed && snapshotRequestIsAuthoritative(epochState(), requestToken, before.snapshot?.instanceID, before.snapshot?.revision)) {
|
|
209
|
+
setRpcError(true);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
const off = rpc.events.on("changed", (event) => {
|
|
214
|
+
if (disposed) return;
|
|
215
|
+
const eventLocation = event.location as RootLocation;
|
|
216
|
+
if (eventLocation.directory !== location.directory) return;
|
|
217
|
+
setEpochState((state) => acceptSnapshotEvent(state, event.data));
|
|
218
|
+
setRpcError(false);
|
|
219
|
+
});
|
|
220
|
+
const offConnected = ctx.data.on("server.connected", refresh);
|
|
221
|
+
refresh();
|
|
222
|
+
onCleanup(() => {
|
|
223
|
+
disposed = true;
|
|
224
|
+
if (locationEpoch === lifecycle) locationEpoch++;
|
|
225
|
+
off();
|
|
226
|
+
offConnected();
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
const rows = createMemo(() => {
|
|
231
|
+
const accounts = new Map<string, number | null>(
|
|
232
|
+
(epochState().snapshot?.assignments ?? []).map((item) => [item.sessionID, item.accountIndex]),
|
|
233
|
+
);
|
|
234
|
+
return projectSidebar(rootID(), sessionTree(), accounts, visibleChildren(), agents());
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const toggleRouting = () => {
|
|
238
|
+
const snapshot = epochState().snapshot;
|
|
239
|
+
const location = rootLocation();
|
|
240
|
+
if (!snapshot || !location) return;
|
|
241
|
+
const operationEpoch = locationEpoch;
|
|
242
|
+
setToggleError(false);
|
|
243
|
+
let requestToken = 0;
|
|
244
|
+
void requestRoutingToggle({
|
|
245
|
+
snapshot,
|
|
246
|
+
directory: location.directory,
|
|
247
|
+
isPending: togglePending,
|
|
248
|
+
setPending: setTogglePending,
|
|
249
|
+
isCurrent: () => locationEpoch === operationEpoch &&
|
|
250
|
+
untrack(rootLocation)?.directory === location.directory,
|
|
251
|
+
setEnabled: (enabled, directory) => {
|
|
252
|
+
setEpochState((state) => {
|
|
253
|
+
const next = beginSnapshotRequest(state);
|
|
254
|
+
requestToken = next.requestToken;
|
|
255
|
+
return next;
|
|
256
|
+
});
|
|
257
|
+
return ctx.client.rpc(RouterRpc).setEnabled({ enabled }, { location: { directory } });
|
|
258
|
+
},
|
|
259
|
+
accept: (value) => {
|
|
260
|
+
setEpochState((state) => {
|
|
261
|
+
const next = acceptSnapshotFetch(state, value, requestToken);
|
|
262
|
+
if (next !== state) setRpcError(false);
|
|
263
|
+
return next;
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
fail: () => setToggleError(true),
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
return (
|
|
271
|
+
<Show when={isRoot()}>
|
|
272
|
+
<SidebarView
|
|
273
|
+
getRows={() => rows().rows}
|
|
274
|
+
totalChildren={rows().totalChildren}
|
|
275
|
+
visibleChildren={visibleChildren()}
|
|
276
|
+
collapsed={listCollapsed()}
|
|
277
|
+
enabled={epochState().snapshot?.enabled}
|
|
278
|
+
togglePending={togglePending()}
|
|
279
|
+
treeError={treeError()}
|
|
280
|
+
rpcError={rpcError()}
|
|
281
|
+
toggleError={toggleError()}
|
|
282
|
+
accent={accent()}
|
|
283
|
+
muted={muted()}
|
|
284
|
+
hoverBackground={hoverBackground()}
|
|
285
|
+
rowColor={(row) => agentColor(
|
|
286
|
+
sessionTree().find((session) => session.id === row.sessionID)?.agent ?? row.agent,
|
|
287
|
+
)}
|
|
288
|
+
onCollapse={() => setListCollapsed(toggleSidebarCollapsed(listCollapsed()))}
|
|
289
|
+
onToggle={toggleRouting}
|
|
290
|
+
onNavigate={(sessionID) => ctx.ui.router.navigate({ type: "session", sessionID })}
|
|
291
|
+
onMore={() => setVisibleChildren((count) => nextVisibleChildren(count, rows().totalChildren))}
|
|
292
|
+
onLess={() => setVisibleChildren(BASELINE_CHILDREN)}
|
|
293
|
+
/>
|
|
294
|
+
</Show>
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
interface SidebarViewProps {
|
|
299
|
+
readonly getRows: () => readonly SidebarRow[];
|
|
300
|
+
readonly totalChildren: number;
|
|
301
|
+
readonly visibleChildren: number;
|
|
302
|
+
readonly collapsed: boolean;
|
|
303
|
+
readonly enabled?: boolean;
|
|
304
|
+
readonly togglePending: boolean;
|
|
305
|
+
readonly treeError: boolean;
|
|
306
|
+
readonly rpcError: boolean;
|
|
307
|
+
readonly toggleError: boolean;
|
|
308
|
+
readonly accent: SidebarColor;
|
|
309
|
+
readonly muted: SidebarColor;
|
|
310
|
+
readonly hoverBackground: SidebarColor;
|
|
311
|
+
readonly rowColor: (row: SidebarRow) => SidebarColor;
|
|
312
|
+
readonly onCollapse: () => void;
|
|
313
|
+
readonly onToggle: () => void;
|
|
314
|
+
readonly onNavigate: (sessionID: string) => void;
|
|
315
|
+
readonly onMore: () => void;
|
|
316
|
+
readonly onLess: () => void;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export function SidebarView(props: SidebarViewProps) {
|
|
320
|
+
const clicks = createPrimaryClickHandler((target) => {
|
|
321
|
+
if (target === "collapse") props.onCollapse();
|
|
322
|
+
else if (target === "toggle") props.onToggle();
|
|
323
|
+
else if (target === "more") props.onMore();
|
|
324
|
+
else if (target === "less") props.onLess();
|
|
325
|
+
else if (target.startsWith("row:")) props.onNavigate(target.slice(4));
|
|
326
|
+
});
|
|
327
|
+
const statusColor = () => props.enabled === undefined
|
|
328
|
+
? "#626a78"
|
|
329
|
+
: props.enabled ? COLORS.green : COLORS.red;
|
|
330
|
+
const controlDown = (target: string, event: PrimaryPointerEvent) => clicks.down(target, event);
|
|
331
|
+
const controlUp = (target: string, event: PrimaryPointerEvent) => clicks.up(target, event);
|
|
332
|
+
const controlOut = (target: string, event: PrimaryPointerEvent & {
|
|
333
|
+
readonly currentTarget: { readonly screenX: number; readonly screenY: number; readonly width: number; readonly height: number } | null;
|
|
334
|
+
}) => {
|
|
335
|
+
if (!pointerWithinRenderable(event.currentTarget, event.x, event.y)) clicks.cancel(target, event);
|
|
336
|
+
};
|
|
337
|
+
const rows = () => props.getRows();
|
|
338
|
+
return (
|
|
339
|
+
<box
|
|
340
|
+
flexDirection="column"
|
|
341
|
+
paddingTop={1}
|
|
342
|
+
paddingBottom={1}
|
|
343
|
+
border={["left"]}
|
|
344
|
+
paddingLeft={1}
|
|
345
|
+
paddingRight={1}
|
|
346
|
+
onMouseUp={clicks.cancelAll}
|
|
347
|
+
onMouseOut={(event) => {
|
|
348
|
+
if (!pointerWithinRenderable(event.currentTarget, event.x, event.y)) clicks.cancelAll(event);
|
|
349
|
+
}}
|
|
350
|
+
>
|
|
351
|
+
<box flexDirection="row" justifyContent="space-between">
|
|
352
|
+
<box
|
|
353
|
+
flexDirection="row"
|
|
354
|
+
onMouseDown={(event) => controlDown("collapse", event)}
|
|
355
|
+
onMouseUp={(event) => controlUp("collapse", event)}
|
|
356
|
+
onMouseDrag={(event) => clicks.cancel("collapse", event)}
|
|
357
|
+
onMouseOut={(event) => controlOut("collapse", event)}
|
|
358
|
+
>
|
|
359
|
+
<text selectable={false} fg={props.accent}>{props.collapsed ? "›" : "⌄"}</text>
|
|
360
|
+
<text selectable={false} fg={props.accent}> ACCOUNT ROUTER · {rows().length}</text>
|
|
361
|
+
</box>
|
|
362
|
+
<box
|
|
363
|
+
backgroundColor={statusColor()}
|
|
364
|
+
paddingLeft={1}
|
|
365
|
+
paddingRight={1}
|
|
366
|
+
onMouseDown={(event) => controlDown("toggle", event)}
|
|
367
|
+
onMouseUp={(event) => controlUp("toggle", event)}
|
|
368
|
+
onMouseDrag={(event) => clicks.cancel("toggle", event)}
|
|
369
|
+
onMouseOut={(event) => controlOut("toggle", event)}
|
|
370
|
+
>
|
|
371
|
+
<text selectable={false} fg={COLORS.white}>
|
|
372
|
+
{props.togglePending ? "WAIT…" : props.enabled === undefined ? "…" : props.enabled ? "ON" : "OFF"}
|
|
373
|
+
</text>
|
|
374
|
+
</box>
|
|
375
|
+
</box>
|
|
376
|
+
<Show when={!props.collapsed}>
|
|
377
|
+
<box flexDirection="column">
|
|
378
|
+
<For each={rows()}>{(row) => {
|
|
379
|
+
const [hovered, setHovered] = createSignal(false);
|
|
380
|
+
const target = `row:${row.sessionID}`;
|
|
381
|
+
onCleanup(() => clicks.invalidate(target));
|
|
382
|
+
return (
|
|
383
|
+
<box
|
|
384
|
+
flexDirection="row"
|
|
385
|
+
backgroundColor={hovered() ? props.hoverBackground : undefined}
|
|
386
|
+
onMouseDown={(event) => clicks.down(target, event)}
|
|
387
|
+
onMouseUp={(event) => clicks.up(target, event)}
|
|
388
|
+
onMouseDrag={(event) => clicks.cancel(target, event)}
|
|
389
|
+
onMouseOver={() => setHovered(true)}
|
|
390
|
+
onMouseOut={(event) => {
|
|
391
|
+
if (!pointerWithinRenderable(event.currentTarget, event.x, event.y)) {
|
|
392
|
+
clicks.cancel(target, event);
|
|
393
|
+
setHovered(false);
|
|
394
|
+
}
|
|
395
|
+
}}
|
|
396
|
+
>
|
|
397
|
+
<text
|
|
398
|
+
width={3}
|
|
399
|
+
flexShrink={0}
|
|
400
|
+
wrapMode="none"
|
|
401
|
+
truncate
|
|
402
|
+
fg={row.accountIndex === null ? props.muted : props.accent}
|
|
403
|
+
>{row.accountIndex === null ? "—" : `${row.accountIndex}`}</text>
|
|
404
|
+
<text flexGrow={1} minWidth={0} wrapMode="none" truncate fg={props.rowColor(row)}>{row.title}</text>
|
|
405
|
+
</box>
|
|
406
|
+
);
|
|
407
|
+
}}</For>
|
|
408
|
+
<box flexDirection="row" alignItems="center" paddingTop={1}>
|
|
409
|
+
<box
|
|
410
|
+
onMouseDown={(event) => controlDown("more", event)}
|
|
411
|
+
onMouseUp={(event) => controlUp("more", event)}
|
|
412
|
+
onMouseDrag={(event) => clicks.cancel("more", event)}
|
|
413
|
+
onMouseOut={(event) => controlOut("more", event)}
|
|
414
|
+
>
|
|
415
|
+
<Show when={moreCount(props.totalChildren, props.visibleChildren) > 0}>
|
|
416
|
+
<text selectable={false} fg={props.accent}>Show {moreCount(props.totalChildren, props.visibleChildren)} more</text>
|
|
417
|
+
</Show>
|
|
418
|
+
</box>
|
|
419
|
+
<box flexGrow={1} />
|
|
420
|
+
<Show when={props.visibleChildren > BASELINE_CHILDREN}>
|
|
421
|
+
<box
|
|
422
|
+
onMouseDown={(event) => controlDown("less", event)}
|
|
423
|
+
onMouseUp={(event) => controlUp("less", event)}
|
|
424
|
+
onMouseDrag={(event) => clicks.cancel("less", event)}
|
|
425
|
+
onMouseOut={(event) => controlOut("less", event)}
|
|
426
|
+
><text selectable={false} fg={props.muted}>Show less</text></box>
|
|
427
|
+
</Show>
|
|
428
|
+
</box>
|
|
429
|
+
</box>
|
|
430
|
+
</Show>
|
|
431
|
+
<Show when={props.treeError}><text fg={COLORS.red}>Session list could not be loaded.</text></Show>
|
|
432
|
+
<Show when={props.rpcError}><text fg="#f59e0b">Router status could not be updated.</text></Show>
|
|
433
|
+
<Show when={props.toggleError}>
|
|
434
|
+
<text fg="#f59e0b">Could not save routing preference; live routing may already have changed.</text>
|
|
435
|
+
</Show>
|
|
436
|
+
</box>
|
|
437
|
+
);
|
|
438
|
+
}
|
package/src/tui.tsx
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Plugin } from "@opencode/plugin/tui";
|
|
2
|
+
import { SessionSidebar } from "./sidebar";
|
|
3
|
+
|
|
4
|
+
export default Plugin.define({
|
|
5
|
+
id: "opencode-openai-session-router",
|
|
6
|
+
setup(ctx) {
|
|
7
|
+
return ctx.ui.slot({
|
|
8
|
+
append: "sidebar.content",
|
|
9
|
+
render: ({ sessionID }) => <SessionSidebar sessionID={sessionID} />,
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2023",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"verbatimModuleSyntax": true,
|
|
11
|
+
"jsx": "preserve",
|
|
12
|
+
"jsxImportSource": "@opentui/solid",
|
|
13
|
+
"types": ["bun"]
|
|
14
|
+
},
|
|
15
|
+
"include": ["src", "test"]
|
|
16
|
+
}
|