@mindstudio-ai/local-model-tunnel 0.3.3 → 0.4.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/dist/{chunk-V3RKCMCQ.js → chunk-44NXQXRB.js} +95 -78
- package/dist/chunk-44NXQXRB.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.js +1 -1
- package/dist/tui-BW6XKMWK.js +2596 -0
- package/dist/tui-BW6XKMWK.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-V3RKCMCQ.js.map +0 -1
- package/dist/tui-KQ4LWB4E.js +0 -1717
- package/dist/tui-KQ4LWB4E.js.map +0 -1
package/dist/tui-KQ4LWB4E.js
DELETED
|
@@ -1,1717 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TunnelRunner,
|
|
3
|
-
detectAllProviderStatuses,
|
|
4
|
-
discoverAllModels,
|
|
5
|
-
discoverAllModelsWithParameters,
|
|
6
|
-
getApiKey,
|
|
7
|
-
getConfigPath,
|
|
8
|
-
getEnvironment,
|
|
9
|
-
getProviderStatuses,
|
|
10
|
-
getSyncedModels,
|
|
11
|
-
pollDeviceAuth,
|
|
12
|
-
requestDeviceAuth,
|
|
13
|
-
requestEvents,
|
|
14
|
-
setApiKey,
|
|
15
|
-
syncLocalModel,
|
|
16
|
-
updateLocalModel,
|
|
17
|
-
verifyApiKey
|
|
18
|
-
} from "./chunk-V3RKCMCQ.js";
|
|
19
|
-
|
|
20
|
-
// src/tui/index.tsx
|
|
21
|
-
import { render } from "ink";
|
|
22
|
-
import { execFileSync, execSync } from "child_process";
|
|
23
|
-
|
|
24
|
-
// src/tui/App.tsx
|
|
25
|
-
import { useEffect as useEffect13, useCallback as useCallback10, useState as useState12 } from "react";
|
|
26
|
-
import { Box as Box8, useApp, useStdout as useStdout5 } from "ink";
|
|
27
|
-
|
|
28
|
-
// src/tui/components/Header.tsx
|
|
29
|
-
import os from "os";
|
|
30
|
-
import { Box, Text } from "ink";
|
|
31
|
-
import { createRequire } from "module";
|
|
32
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
33
|
-
var require2 = createRequire(import.meta.url);
|
|
34
|
-
var pkg = require2("../package.json");
|
|
35
|
-
var LogoString = ` .=+-. :++.
|
|
36
|
-
*@@@@@+ :%@@@@%:
|
|
37
|
-
.%@@@@@@#..@@@@@@@=
|
|
38
|
-
.*@@@@@@@--@@@@@@@#.**.
|
|
39
|
-
*@@@@@@@.-@@@@@@@@.#@@*
|
|
40
|
-
.#@@@@@@@-.@@@@@@@* #@@@@%.
|
|
41
|
-
=@@@@@@@-.@@@@@@@#.-@@@@@@+
|
|
42
|
-
:@@@@@@: +@@@@@#. .@@@@@@:
|
|
43
|
-
.++: .-*-. .++:`;
|
|
44
|
-
var getConnectionDisplay = (status) => {
|
|
45
|
-
switch (status) {
|
|
46
|
-
case "connected":
|
|
47
|
-
return { color: "green", text: "Connected to Cloud" };
|
|
48
|
-
case "connecting":
|
|
49
|
-
return { color: "yellow", text: "Connecting..." };
|
|
50
|
-
case "not_authenticated":
|
|
51
|
-
return { color: "yellow", text: "Not Authenticated" };
|
|
52
|
-
case "disconnected":
|
|
53
|
-
return { color: "red", text: "Disconnected" };
|
|
54
|
-
default:
|
|
55
|
-
return { color: "red", text: "Error" };
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
function Header({
|
|
59
|
-
connection,
|
|
60
|
-
environment,
|
|
61
|
-
configPath,
|
|
62
|
-
connectionError
|
|
63
|
-
}) {
|
|
64
|
-
const { color: connectionColor, text: connectionText } = getConnectionDisplay(connection);
|
|
65
|
-
return /* @__PURE__ */ jsxs(
|
|
66
|
-
Box,
|
|
67
|
-
{
|
|
68
|
-
flexDirection: "row",
|
|
69
|
-
alignItems: "center",
|
|
70
|
-
borderStyle: "round",
|
|
71
|
-
borderColor: "cyan",
|
|
72
|
-
paddingX: 1,
|
|
73
|
-
paddingY: 1,
|
|
74
|
-
width: "100%",
|
|
75
|
-
children: [
|
|
76
|
-
/* @__PURE__ */ jsx(Box, { paddingLeft: 3, children: /* @__PURE__ */ jsx(Text, { color: "cyan", children: LogoString }) }),
|
|
77
|
-
/* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginLeft: 4, children: [
|
|
78
|
-
/* @__PURE__ */ jsxs(Box, { children: [
|
|
79
|
-
/* @__PURE__ */ jsx(Text, { bold: true, color: "white", children: "MindStudio Local Tunnel" }),
|
|
80
|
-
environment !== "prod" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
81
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
82
|
-
/* @__PURE__ */ jsx(Text, { color: "yellow", bold: true, children: "[LOCAL]" })
|
|
83
|
-
] })
|
|
84
|
-
] }),
|
|
85
|
-
/* @__PURE__ */ jsxs(Text, { color: "gray", children: [
|
|
86
|
-
"v",
|
|
87
|
-
pkg.version
|
|
88
|
-
] }),
|
|
89
|
-
/* @__PURE__ */ jsxs(Text, { color: connectionColor, children: [
|
|
90
|
-
"\u25CF ",
|
|
91
|
-
connectionText
|
|
92
|
-
] }),
|
|
93
|
-
connectionError && /* @__PURE__ */ jsx(Text, { color: "red", children: connectionError }),
|
|
94
|
-
/* @__PURE__ */ jsxs(Text, { color: "gray", children: [
|
|
95
|
-
"Config: ",
|
|
96
|
-
configPath.replace(os.homedir(), "~")
|
|
97
|
-
] })
|
|
98
|
-
] })
|
|
99
|
-
]
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// src/tui/components/NavigationMenu.tsx
|
|
105
|
-
import { useState, useEffect } from "react";
|
|
106
|
-
import { Box as Box2, Text as Text2, useInput } from "ink";
|
|
107
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
108
|
-
function NavigationMenu({ items, onSelect, title }) {
|
|
109
|
-
const getDefaultIndex = () => {
|
|
110
|
-
const backIdx = items.findIndex((i) => i.id === "back");
|
|
111
|
-
if (backIdx >= 0) return backIdx;
|
|
112
|
-
const firstIdx = items.findIndex((i) => !i.disabled && !i.isSeparator);
|
|
113
|
-
return firstIdx >= 0 ? firstIdx : 0;
|
|
114
|
-
};
|
|
115
|
-
const [selectedIndex, setSelectedIndex] = useState(getDefaultIndex);
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
setSelectedIndex(getDefaultIndex());
|
|
118
|
-
}, [items]);
|
|
119
|
-
const findNextEnabled = (from, direction) => {
|
|
120
|
-
let idx = from;
|
|
121
|
-
for (let i = 0; i < items.length; i++) {
|
|
122
|
-
idx = (idx + direction + items.length) % items.length;
|
|
123
|
-
if (!items[idx].disabled && !items[idx].isSeparator) return idx;
|
|
124
|
-
}
|
|
125
|
-
return from;
|
|
126
|
-
};
|
|
127
|
-
useInput((input, key) => {
|
|
128
|
-
if (input === "q" || key.escape) {
|
|
129
|
-
const backItem = items.find((i) => i.id === "back");
|
|
130
|
-
if (backItem) {
|
|
131
|
-
onSelect("back");
|
|
132
|
-
} else if (input === "q") {
|
|
133
|
-
onSelect("quit");
|
|
134
|
-
}
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (key.upArrow) {
|
|
138
|
-
setSelectedIndex((prev) => findNextEnabled(prev, -1));
|
|
139
|
-
} else if (key.downArrow) {
|
|
140
|
-
setSelectedIndex((prev) => findNextEnabled(prev, 1));
|
|
141
|
-
} else if (key.return) {
|
|
142
|
-
const item = items[selectedIndex];
|
|
143
|
-
if (item && !item.disabled) {
|
|
144
|
-
onSelect(item.id);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
const separatorExtraLines = items.filter((item, idx) => item.isSeparator && idx > 0).length;
|
|
149
|
-
const menuHeight = items.length + 4 + separatorExtraLines;
|
|
150
|
-
return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", paddingX: 1, marginBottom: 1, borderStyle: "single", borderTop: true, borderBottom: false, borderLeft: false, borderRight: false, borderColor: "gray", children: [
|
|
151
|
-
/* @__PURE__ */ jsx2(Box2, { marginTop: 1, children: /* @__PURE__ */ jsx2(Text2, { color: "gray", children: title ?? "Actions" }) }),
|
|
152
|
-
/* @__PURE__ */ jsx2(Box2, { flexDirection: "column", children: items.map((item, index) => {
|
|
153
|
-
if (item.isSeparator) {
|
|
154
|
-
return /* @__PURE__ */ jsx2(Box2, { marginTop: index > 0 ? 1 : 0, children: item.label ? /* @__PURE__ */ jsx2(Text2, { bold: true, color: item.color ?? "gray", wrap: "truncate-end", children: item.label }) : null }, item.id);
|
|
155
|
-
}
|
|
156
|
-
const isSelected = index === selectedIndex;
|
|
157
|
-
const prefix = isSelected ? "\u276F" : " ";
|
|
158
|
-
if (item.disabled) {
|
|
159
|
-
return /* @__PURE__ */ jsx2(Box2, { children: /* @__PURE__ */ jsxs2(Text2, { color: "gray", wrap: "truncate-end", children: [
|
|
160
|
-
prefix,
|
|
161
|
-
" ",
|
|
162
|
-
item.label,
|
|
163
|
-
item.disabledReason ? ` (${item.disabledReason})` : ""
|
|
164
|
-
] }) }, item.id);
|
|
165
|
-
}
|
|
166
|
-
return /* @__PURE__ */ jsxs2(Box2, { children: [
|
|
167
|
-
/* @__PURE__ */ jsxs2(Text2, { color: isSelected ? "cyan" : "white", bold: isSelected, wrap: "truncate-end", children: [
|
|
168
|
-
prefix,
|
|
169
|
-
" ",
|
|
170
|
-
item.label
|
|
171
|
-
] }),
|
|
172
|
-
isSelected && /* @__PURE__ */ jsxs2(Text2, { color: "gray", wrap: "truncate-end", children: [
|
|
173
|
-
" - ",
|
|
174
|
-
item.description
|
|
175
|
-
] })
|
|
176
|
-
] }, item.id);
|
|
177
|
-
}) }),
|
|
178
|
-
/* @__PURE__ */ jsx2(Box2, { marginTop: 1, height: 1, children: /* @__PURE__ */ jsx2(Text2, { color: "gray", wrap: "truncate-end", children: items.some((i) => i.id === "back") ? "Up/Down Navigate \u2022 Enter Select \u2022 q/Esc Back" : "Up/Down Navigate \u2022 Enter Select \u2022 q Quit" }) })
|
|
179
|
-
] });
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// src/tui/hooks/useConnection.ts
|
|
183
|
-
import { useState as useState2, useEffect as useEffect2, useCallback } from "react";
|
|
184
|
-
function useConnection() {
|
|
185
|
-
const [status, setStatus] = useState2("connecting");
|
|
186
|
-
const [error, setError] = useState2(null);
|
|
187
|
-
const environment = getEnvironment();
|
|
188
|
-
const connect = useCallback(async () => {
|
|
189
|
-
setStatus("connecting");
|
|
190
|
-
setError(null);
|
|
191
|
-
const apiKey = getApiKey();
|
|
192
|
-
if (!apiKey) {
|
|
193
|
-
setStatus("not_authenticated");
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
try {
|
|
197
|
-
const isValid = await verifyApiKey();
|
|
198
|
-
if (isValid) {
|
|
199
|
-
setStatus("connected");
|
|
200
|
-
} else {
|
|
201
|
-
setStatus("not_authenticated");
|
|
202
|
-
}
|
|
203
|
-
} catch (err) {
|
|
204
|
-
setStatus("error");
|
|
205
|
-
setError(err instanceof Error ? err.message : "Connection failed");
|
|
206
|
-
}
|
|
207
|
-
}, []);
|
|
208
|
-
useEffect2(() => {
|
|
209
|
-
connect();
|
|
210
|
-
}, [connect]);
|
|
211
|
-
return {
|
|
212
|
-
status,
|
|
213
|
-
environment,
|
|
214
|
-
error,
|
|
215
|
-
retry: connect
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/tui/hooks/useProviders.ts
|
|
220
|
-
import { useState as useState3, useEffect as useEffect3, useCallback as useCallback2 } from "react";
|
|
221
|
-
function useProviders(pollInterval = 1e4) {
|
|
222
|
-
const [providers, setProviders] = useState3([]);
|
|
223
|
-
const [loading, setLoading] = useState3(true);
|
|
224
|
-
const refresh = useCallback2(async () => {
|
|
225
|
-
try {
|
|
226
|
-
const statuses = await getProviderStatuses();
|
|
227
|
-
setProviders(statuses);
|
|
228
|
-
} catch {
|
|
229
|
-
} finally {
|
|
230
|
-
setLoading(false);
|
|
231
|
-
}
|
|
232
|
-
}, []);
|
|
233
|
-
useEffect3(() => {
|
|
234
|
-
refresh();
|
|
235
|
-
const interval = setInterval(refresh, pollInterval);
|
|
236
|
-
return () => clearInterval(interval);
|
|
237
|
-
}, [refresh, pollInterval]);
|
|
238
|
-
return {
|
|
239
|
-
providers,
|
|
240
|
-
loading,
|
|
241
|
-
refresh
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// src/tui/hooks/useModels.ts
|
|
246
|
-
import { useState as useState4, useEffect as useEffect4, useCallback as useCallback3 } from "react";
|
|
247
|
-
function useModels() {
|
|
248
|
-
const [models, setModels] = useState4([]);
|
|
249
|
-
const [warnings, setWarnings] = useState4([]);
|
|
250
|
-
const [loading, setLoading] = useState4(true);
|
|
251
|
-
const refresh = useCallback3(async () => {
|
|
252
|
-
setLoading(true);
|
|
253
|
-
try {
|
|
254
|
-
const discoveredModels = await discoverAllModels();
|
|
255
|
-
setModels(discoveredModels.filter((m) => !m.statusHint));
|
|
256
|
-
setWarnings(discoveredModels.filter((m) => !!m.statusHint));
|
|
257
|
-
} catch {
|
|
258
|
-
} finally {
|
|
259
|
-
setLoading(false);
|
|
260
|
-
}
|
|
261
|
-
}, []);
|
|
262
|
-
useEffect4(() => {
|
|
263
|
-
refresh();
|
|
264
|
-
}, [refresh]);
|
|
265
|
-
return {
|
|
266
|
-
models,
|
|
267
|
-
warnings,
|
|
268
|
-
loading,
|
|
269
|
-
refresh
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// src/tui/hooks/useRequests.ts
|
|
274
|
-
import { useState as useState5, useEffect as useEffect5, useCallback as useCallback4, useRef } from "react";
|
|
275
|
-
function useRequests(maxHistory = 50) {
|
|
276
|
-
const [requests, setRequests] = useState5([]);
|
|
277
|
-
const requestsRef = useRef(/* @__PURE__ */ new Map());
|
|
278
|
-
useEffect5(() => {
|
|
279
|
-
const interval = setInterval(() => {
|
|
280
|
-
setRequests((prev) => {
|
|
281
|
-
const hasActive = prev.some((r) => r.status === "processing");
|
|
282
|
-
return hasActive ? [...prev] : prev;
|
|
283
|
-
});
|
|
284
|
-
}, 1e3);
|
|
285
|
-
return () => clearInterval(interval);
|
|
286
|
-
}, []);
|
|
287
|
-
useEffect5(() => {
|
|
288
|
-
const unsubStart = requestEvents.onStart((event) => {
|
|
289
|
-
const entry = {
|
|
290
|
-
id: event.id,
|
|
291
|
-
modelId: event.modelId,
|
|
292
|
-
requestType: event.requestType,
|
|
293
|
-
status: "processing",
|
|
294
|
-
startTime: event.timestamp
|
|
295
|
-
};
|
|
296
|
-
requestsRef.current.set(event.id, entry);
|
|
297
|
-
setRequests((prev) => [...prev, entry].slice(-maxHistory));
|
|
298
|
-
});
|
|
299
|
-
const unsubProgress = requestEvents.onProgress((event) => {
|
|
300
|
-
const existing = requestsRef.current.get(event.id);
|
|
301
|
-
if (existing && existing.status === "processing") {
|
|
302
|
-
const updated = {
|
|
303
|
-
...existing,
|
|
304
|
-
...event.content !== void 0 && { content: event.content },
|
|
305
|
-
...event.step !== void 0 && { step: event.step },
|
|
306
|
-
...event.totalSteps !== void 0 && { totalSteps: event.totalSteps }
|
|
307
|
-
};
|
|
308
|
-
requestsRef.current.set(event.id, updated);
|
|
309
|
-
setRequests(
|
|
310
|
-
(prev) => prev.map((r) => r.id === event.id ? updated : r)
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
const unsubComplete = requestEvents.onComplete((event) => {
|
|
315
|
-
const existing = requestsRef.current.get(event.id);
|
|
316
|
-
if (existing) {
|
|
317
|
-
const updated = {
|
|
318
|
-
...existing,
|
|
319
|
-
status: event.success ? "completed" : "failed",
|
|
320
|
-
endTime: Date.now(),
|
|
321
|
-
duration: event.duration,
|
|
322
|
-
result: event.result,
|
|
323
|
-
error: event.error
|
|
324
|
-
};
|
|
325
|
-
requestsRef.current.set(event.id, updated);
|
|
326
|
-
setRequests(
|
|
327
|
-
(prev) => prev.map((r) => r.id === event.id ? updated : r)
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
return () => {
|
|
332
|
-
unsubStart();
|
|
333
|
-
unsubProgress();
|
|
334
|
-
unsubComplete();
|
|
335
|
-
};
|
|
336
|
-
}, [maxHistory]);
|
|
337
|
-
const activeCount = requests.filter((r) => r.status === "processing").length;
|
|
338
|
-
const clear = useCallback4(() => {
|
|
339
|
-
requestsRef.current.clear();
|
|
340
|
-
setRequests([]);
|
|
341
|
-
}, []);
|
|
342
|
-
return {
|
|
343
|
-
requests,
|
|
344
|
-
activeCount,
|
|
345
|
-
clear
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// src/tui/hooks/useRegisteredModels.ts
|
|
350
|
-
import { useState as useState6, useEffect as useEffect6, useCallback as useCallback5 } from "react";
|
|
351
|
-
function useSyncedModels(connectionStatus) {
|
|
352
|
-
const [syncedNames, setSyncedNames] = useState6(
|
|
353
|
-
/* @__PURE__ */ new Set()
|
|
354
|
-
);
|
|
355
|
-
const refresh = useCallback5(async () => {
|
|
356
|
-
if (connectionStatus !== "connected") {
|
|
357
|
-
setSyncedNames(/* @__PURE__ */ new Set());
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
try {
|
|
361
|
-
const models = await getSyncedModels();
|
|
362
|
-
setSyncedNames(new Set(models.map((m) => m.name)));
|
|
363
|
-
} catch {
|
|
364
|
-
}
|
|
365
|
-
}, [connectionStatus]);
|
|
366
|
-
useEffect6(() => {
|
|
367
|
-
refresh();
|
|
368
|
-
}, [refresh]);
|
|
369
|
-
return {
|
|
370
|
-
syncedNames,
|
|
371
|
-
refresh
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// src/tui/pages/DashboardPage.tsx
|
|
376
|
-
import { useMemo } from "react";
|
|
377
|
-
import { Box as Box4, Text as Text4, useStdout as useStdout2 } from "ink";
|
|
378
|
-
import Spinner2 from "ink-spinner";
|
|
379
|
-
|
|
380
|
-
// src/tui/components/RequestLog.tsx
|
|
381
|
-
import { Box as Box3, Text as Text3, useStdout } from "ink";
|
|
382
|
-
import Spinner from "ink-spinner";
|
|
383
|
-
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
384
|
-
function formatTime(timestamp) {
|
|
385
|
-
const date = new Date(timestamp);
|
|
386
|
-
return date.toLocaleTimeString("en-US", {
|
|
387
|
-
hour12: false,
|
|
388
|
-
hour: "2-digit",
|
|
389
|
-
minute: "2-digit",
|
|
390
|
-
second: "2-digit"
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
function formatDuration(ms) {
|
|
394
|
-
if (ms < 1e3) return `${ms}ms`;
|
|
395
|
-
return `${(ms / 1e3).toFixed(1)}s`;
|
|
396
|
-
}
|
|
397
|
-
function getRequestTypeLabel(type) {
|
|
398
|
-
switch (type) {
|
|
399
|
-
case "llm_chat":
|
|
400
|
-
return { label: "text", color: "gray" };
|
|
401
|
-
case "image_generation":
|
|
402
|
-
return { label: "image", color: "gray" };
|
|
403
|
-
case "video_generation":
|
|
404
|
-
return { label: "video", color: "gray" };
|
|
405
|
-
default:
|
|
406
|
-
return { label: type, color: "gray" };
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
function snippetLine(content, maxWidth) {
|
|
410
|
-
const flat = content.replace(/\s+/g, " ").trim();
|
|
411
|
-
if (flat.length <= maxWidth) return flat;
|
|
412
|
-
return "\u2026" + flat.slice(-(maxWidth - 1));
|
|
413
|
-
}
|
|
414
|
-
function RequestItem({ request, width }) {
|
|
415
|
-
const time = formatTime(request.startTime);
|
|
416
|
-
const typeLabel = getRequestTypeLabel(request.requestType);
|
|
417
|
-
const snippetIndent = " ";
|
|
418
|
-
const snippetWidth = width - snippetIndent.length - 2;
|
|
419
|
-
if (request.status === "processing") {
|
|
420
|
-
const elapsed = Date.now() - request.startTime;
|
|
421
|
-
const snippet = request.content && request.requestType === "llm_chat" ? snippetLine(request.content, snippetWidth) : null;
|
|
422
|
-
const stepProgress = request.step !== void 0 && request.totalSteps ? `Step ${request.step}/${request.totalSteps}` : null;
|
|
423
|
-
return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "column", children: [
|
|
424
|
-
/* @__PURE__ */ jsxs3(Box3, { children: [
|
|
425
|
-
/* @__PURE__ */ jsx3(Text3, { color: "cyan", children: /* @__PURE__ */ jsx3(Spinner, { type: "dots" }) }),
|
|
426
|
-
/* @__PURE__ */ jsxs3(Text3, { color: "gray", children: [
|
|
427
|
-
" ",
|
|
428
|
-
time,
|
|
429
|
-
" "
|
|
430
|
-
] }),
|
|
431
|
-
/* @__PURE__ */ jsx3(Text3, { color: "white", children: request.modelId }),
|
|
432
|
-
/* @__PURE__ */ jsx3(Text3, { color: "gray", children: " " }),
|
|
433
|
-
/* @__PURE__ */ jsx3(Text3, { color: typeLabel.color, children: typeLabel.label }),
|
|
434
|
-
/* @__PURE__ */ jsxs3(Text3, { color: "gray", children: [
|
|
435
|
-
" ",
|
|
436
|
-
formatDuration(elapsed),
|
|
437
|
-
"..."
|
|
438
|
-
] })
|
|
439
|
-
] }),
|
|
440
|
-
snippet && /* @__PURE__ */ jsxs3(Text3, { color: "gray", wrap: "truncate-end", children: [
|
|
441
|
-
snippetIndent,
|
|
442
|
-
snippet
|
|
443
|
-
] }),
|
|
444
|
-
stepProgress && /* @__PURE__ */ jsxs3(Text3, { color: "gray", children: [
|
|
445
|
-
snippetIndent,
|
|
446
|
-
stepProgress
|
|
447
|
-
] })
|
|
448
|
-
] });
|
|
449
|
-
}
|
|
450
|
-
if (request.status === "completed") {
|
|
451
|
-
const duration = request.duration ? formatDuration(request.duration) : "";
|
|
452
|
-
let resultInfo = "";
|
|
453
|
-
if (request.result?.chars) {
|
|
454
|
-
resultInfo = ` \xB7 ${request.result.chars} chars`;
|
|
455
|
-
} else if (request.result?.imageSize) {
|
|
456
|
-
resultInfo = ` \xB7 ${Math.round(request.result.imageSize / 1024)}KB`;
|
|
457
|
-
} else if (request.result?.videoSize) {
|
|
458
|
-
resultInfo = ` \xB7 ${Math.round(request.result.videoSize / 1024 / 1024)}MB`;
|
|
459
|
-
}
|
|
460
|
-
const snippet = request.content && request.requestType === "llm_chat" ? snippetLine(request.content, snippetWidth) : null;
|
|
461
|
-
return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "column", children: [
|
|
462
|
-
/* @__PURE__ */ jsxs3(Box3, { children: [
|
|
463
|
-
/* @__PURE__ */ jsx3(Text3, { color: "green", children: "\u2713" }),
|
|
464
|
-
/* @__PURE__ */ jsxs3(Text3, { color: "gray", children: [
|
|
465
|
-
" ",
|
|
466
|
-
time,
|
|
467
|
-
" "
|
|
468
|
-
] }),
|
|
469
|
-
/* @__PURE__ */ jsx3(Text3, { color: "white", children: request.modelId }),
|
|
470
|
-
/* @__PURE__ */ jsx3(Text3, { color: "gray", children: " " }),
|
|
471
|
-
/* @__PURE__ */ jsx3(Text3, { color: typeLabel.color, children: typeLabel.label }),
|
|
472
|
-
/* @__PURE__ */ jsxs3(Text3, { color: "gray", children: [
|
|
473
|
-
" ",
|
|
474
|
-
duration,
|
|
475
|
-
resultInfo
|
|
476
|
-
] })
|
|
477
|
-
] }),
|
|
478
|
-
snippet && /* @__PURE__ */ jsxs3(Text3, { color: "gray", wrap: "truncate-end", children: [
|
|
479
|
-
snippetIndent,
|
|
480
|
-
snippet
|
|
481
|
-
] })
|
|
482
|
-
] });
|
|
483
|
-
}
|
|
484
|
-
return /* @__PURE__ */ jsx3(Box3, { flexDirection: "column", children: /* @__PURE__ */ jsxs3(Box3, { children: [
|
|
485
|
-
/* @__PURE__ */ jsx3(Text3, { color: "red", children: "\u25CF" }),
|
|
486
|
-
/* @__PURE__ */ jsxs3(Text3, { color: "gray", children: [
|
|
487
|
-
" ",
|
|
488
|
-
time,
|
|
489
|
-
" "
|
|
490
|
-
] }),
|
|
491
|
-
/* @__PURE__ */ jsx3(Text3, { color: "white", children: request.modelId }),
|
|
492
|
-
/* @__PURE__ */ jsx3(Text3, { color: "gray", children: " " }),
|
|
493
|
-
/* @__PURE__ */ jsx3(Text3, { color: typeLabel.color, children: typeLabel.label }),
|
|
494
|
-
/* @__PURE__ */ jsxs3(Text3, { color: "red", children: [
|
|
495
|
-
" ",
|
|
496
|
-
request.error || "Failed"
|
|
497
|
-
] })
|
|
498
|
-
] }) });
|
|
499
|
-
}
|
|
500
|
-
function RequestLog({ requests, maxVisible = 8, hasModels = true }) {
|
|
501
|
-
const { stdout } = useStdout();
|
|
502
|
-
const width = stdout?.columns ?? 80;
|
|
503
|
-
const activeRequests = requests.filter((r) => r.status === "processing");
|
|
504
|
-
const completedRequests = requests.filter((r) => r.status !== "processing");
|
|
505
|
-
const itemLines = (r) => {
|
|
506
|
-
if (r.requestType === "llm_chat" && r.content) return 2;
|
|
507
|
-
if (r.status === "processing" && r.step !== void 0) return 2;
|
|
508
|
-
return 1;
|
|
509
|
-
};
|
|
510
|
-
let completedToShow = [];
|
|
511
|
-
let linesUsed = activeRequests.reduce((sum, r) => sum + itemLines(r), 0);
|
|
512
|
-
for (let i = completedRequests.length - 1; i >= 0 && linesUsed < maxVisible; i--) {
|
|
513
|
-
const r = completedRequests[i];
|
|
514
|
-
const lines = itemLines(r);
|
|
515
|
-
if (linesUsed + lines <= maxVisible) {
|
|
516
|
-
completedToShow.unshift(r);
|
|
517
|
-
linesUsed += lines;
|
|
518
|
-
} else {
|
|
519
|
-
break;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
const visibleRequests = [...completedToShow, ...activeRequests];
|
|
523
|
-
return /* @__PURE__ */ jsxs3(
|
|
524
|
-
Box3,
|
|
525
|
-
{
|
|
526
|
-
flexDirection: "column",
|
|
527
|
-
flexGrow: 1,
|
|
528
|
-
width: "100%",
|
|
529
|
-
paddingX: 1,
|
|
530
|
-
marginTop: 1,
|
|
531
|
-
children: [
|
|
532
|
-
/* @__PURE__ */ jsxs3(Box3, { children: [
|
|
533
|
-
/* @__PURE__ */ jsx3(Text3, { bold: true, underline: true, color: "white", children: "Generation Requests" }),
|
|
534
|
-
activeRequests.length > 0 && /* @__PURE__ */ jsxs3(Text3, { color: "cyan", children: [
|
|
535
|
-
" (",
|
|
536
|
-
activeRequests.length,
|
|
537
|
-
" active)"
|
|
538
|
-
] })
|
|
539
|
-
] }),
|
|
540
|
-
requests.length === 0 ? /* @__PURE__ */ jsx3(Box3, { marginTop: 1, flexDirection: "column", children: /* @__PURE__ */ jsx3(Text3, { color: "gray", children: hasModels ? "Tunnel is live \u2014 requests will appear here when models are used in MindStudio" : "Start a model to begin receiving generation requests." }) }) : /* @__PURE__ */ jsx3(Box3, { flexDirection: "column", marginTop: 1, children: visibleRequests.map((request) => /* @__PURE__ */ jsx3(RequestItem, { request, width }, request.id)) })
|
|
541
|
-
]
|
|
542
|
-
}
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
// src/tui/hooks/useSetupProviders.ts
|
|
547
|
-
import { useState as useState7, useEffect as useEffect7, useCallback as useCallback6 } from "react";
|
|
548
|
-
function useSetupProviders() {
|
|
549
|
-
const [providers, setProviders] = useState7([]);
|
|
550
|
-
const [loading, setLoading] = useState7(true);
|
|
551
|
-
const refresh = useCallback6(async () => {
|
|
552
|
-
setLoading(true);
|
|
553
|
-
const statuses = await detectAllProviderStatuses();
|
|
554
|
-
setProviders(statuses);
|
|
555
|
-
setLoading(false);
|
|
556
|
-
}, []);
|
|
557
|
-
useEffect7(() => {
|
|
558
|
-
refresh();
|
|
559
|
-
}, [refresh]);
|
|
560
|
-
return { providers, loading, refresh };
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// src/tui/pages/DashboardPage.tsx
|
|
564
|
-
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
565
|
-
function getWorkflowCount(model) {
|
|
566
|
-
const param = model.parameters?.find((p) => p.type === "comfyWorkflow");
|
|
567
|
-
if (!param) return null;
|
|
568
|
-
return param.comfyWorkflowOptions.availableWorkflows.length;
|
|
569
|
-
}
|
|
570
|
-
function getCapabilityLabel(capability) {
|
|
571
|
-
switch (capability) {
|
|
572
|
-
case "text":
|
|
573
|
-
return { label: "Text Generation", color: "gray" };
|
|
574
|
-
case "image":
|
|
575
|
-
return { label: "Image Generation", color: "gray" };
|
|
576
|
-
case "video":
|
|
577
|
-
return { label: "Video Generation", color: "gray" };
|
|
578
|
-
default:
|
|
579
|
-
return { label: capability, color: "gray" };
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
function DashboardPage({
|
|
583
|
-
requests,
|
|
584
|
-
models,
|
|
585
|
-
modelWarnings = [],
|
|
586
|
-
syncedNames,
|
|
587
|
-
modelsLoading,
|
|
588
|
-
onNavigate
|
|
589
|
-
}) {
|
|
590
|
-
const { stdout } = useStdout2();
|
|
591
|
-
const { providers, loading: setupLoading } = useSetupProviders();
|
|
592
|
-
const installedProviders = providers.filter(({ status }) => status.installed);
|
|
593
|
-
const provNameWidth = Math.max(
|
|
594
|
-
...installedProviders.map((p) => p.provider.displayName.length),
|
|
595
|
-
8
|
|
596
|
-
);
|
|
597
|
-
const provStatusWidth = "Local Server Running".length;
|
|
598
|
-
const allModelNames = new Set(models.map((m) => m.name));
|
|
599
|
-
const unavailableSynced = [...syncedNames].filter(
|
|
600
|
-
(name) => !allModelNames.has(name)
|
|
601
|
-
);
|
|
602
|
-
const menuItems = useMemo(() => {
|
|
603
|
-
return [
|
|
604
|
-
{
|
|
605
|
-
id: "register",
|
|
606
|
-
label: "Sync Models",
|
|
607
|
-
description: "Sync models with MindStudio Cloud"
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
id: "refresh",
|
|
611
|
-
label: "Refresh Providers",
|
|
612
|
-
description: "Re-detect local AI providers and models"
|
|
613
|
-
},
|
|
614
|
-
{
|
|
615
|
-
id: "setup",
|
|
616
|
-
label: "Manage Providers",
|
|
617
|
-
description: "Manage local AI providers"
|
|
618
|
-
},
|
|
619
|
-
{
|
|
620
|
-
id: "auth",
|
|
621
|
-
label: "Re-authenticate",
|
|
622
|
-
description: "Re-authenticate with MindStudio"
|
|
623
|
-
},
|
|
624
|
-
{
|
|
625
|
-
id: "quit",
|
|
626
|
-
label: "Exit",
|
|
627
|
-
description: "Quit the application"
|
|
628
|
-
}
|
|
629
|
-
];
|
|
630
|
-
}, []);
|
|
631
|
-
const termHeight = (stdout?.rows ?? 24) - 4;
|
|
632
|
-
const headerLines = 14;
|
|
633
|
-
const providerContentLines = setupLoading ? 1 : installedProviders.length === 0 ? 2 : installedProviders.length;
|
|
634
|
-
const providersLines = 3 + providerContentLines;
|
|
635
|
-
const modelContentLines = modelsLoading ? 1 : models.length === 0 && unavailableSynced.length === 0 && modelWarnings.length === 0 ? 2 : models.length + modelWarnings.length + (unavailableSynced.length > 0 ? 1 + unavailableSynced.length : 0);
|
|
636
|
-
const modelsLines = 3 + modelContentLines;
|
|
637
|
-
const requestLogOverhead = 3;
|
|
638
|
-
const menuLines = menuItems.length + 6;
|
|
639
|
-
const usedLines = headerLines + providersLines + modelsLines + requestLogOverhead + menuLines;
|
|
640
|
-
const maxVisible = Math.max(3, termHeight - usedLines);
|
|
641
|
-
return /* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", flexGrow: 1, children: [
|
|
642
|
-
/* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", paddingX: 1, marginTop: 1, children: [
|
|
643
|
-
/* @__PURE__ */ jsx4(Text4, { bold: true, color: "white", underline: true, children: "Providers" }),
|
|
644
|
-
setupLoading ? /* @__PURE__ */ jsxs4(Box4, { marginTop: 1, children: [
|
|
645
|
-
/* @__PURE__ */ jsx4(Text4, { color: "cyan", children: /* @__PURE__ */ jsx4(Spinner2, { type: "dots" }) }),
|
|
646
|
-
/* @__PURE__ */ jsx4(Text4, { children: " Detecting providers..." })
|
|
647
|
-
] }) : installedProviders.length === 0 ? /* @__PURE__ */ jsxs4(Box4, { marginTop: 1, flexDirection: "column", children: [
|
|
648
|
-
/* @__PURE__ */ jsx4(Text4, { color: "yellow", children: "No providers installed." }),
|
|
649
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: 'Use "Manage Providers" below to install one.' })
|
|
650
|
-
] }) : /* @__PURE__ */ jsx4(Box4, { flexDirection: "column", marginTop: 1, children: installedProviders.map(({ provider, status }) => {
|
|
651
|
-
const url = provider.baseUrl;
|
|
652
|
-
const statusColor = status.running ? "green" : "yellow";
|
|
653
|
-
const statusText = status.running ? "Local Server Running" : "Installed (not running)";
|
|
654
|
-
return /* @__PURE__ */ jsxs4(Box4, { children: [
|
|
655
|
-
/* @__PURE__ */ jsx4(Text4, { color: "white", children: provider.displayName.padEnd(provNameWidth + 2) }),
|
|
656
|
-
/* @__PURE__ */ jsx4(Text4, { color: statusColor, children: statusText.padEnd(provStatusWidth + 2) }),
|
|
657
|
-
status.running && /* @__PURE__ */ jsx4(Text4, { color: "gray", children: url })
|
|
658
|
-
] }, provider.name);
|
|
659
|
-
}) })
|
|
660
|
-
] }),
|
|
661
|
-
/* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", paddingX: 1, marginTop: 1, children: [
|
|
662
|
-
/* @__PURE__ */ jsx4(Text4, { bold: true, color: "white", underline: true, children: "Models" }),
|
|
663
|
-
modelsLoading ? /* @__PURE__ */ jsxs4(Box4, { marginTop: 1, children: [
|
|
664
|
-
/* @__PURE__ */ jsx4(Text4, { color: "cyan", children: /* @__PURE__ */ jsx4(Spinner2, { type: "dots" }) }),
|
|
665
|
-
/* @__PURE__ */ jsx4(Text4, { children: " Discovering models..." })
|
|
666
|
-
] }) : models.length === 0 && unavailableSynced.length === 0 && modelWarnings.length === 0 ? /* @__PURE__ */ jsxs4(Box4, { marginTop: 1, flexDirection: "column", children: [
|
|
667
|
-
/* @__PURE__ */ jsx4(Text4, { color: "yellow", children: "No models found." }),
|
|
668
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: "Download models using your provider (e.g., ollama pull llama3.2)" })
|
|
669
|
-
] }) : /* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", marginTop: 1, children: [
|
|
670
|
-
models.map((model) => {
|
|
671
|
-
const cap = getCapabilityLabel(model.capability);
|
|
672
|
-
const isSynced = syncedNames.has(model.name);
|
|
673
|
-
const displayProvider = providers.find((p) => p.provider.name === model.provider)?.provider.displayName ?? model.provider;
|
|
674
|
-
const workflowCount = getWorkflowCount(model);
|
|
675
|
-
const workflowSuffix = workflowCount !== null ? ` (${workflowCount} workflow${workflowCount !== 1 ? "s" : ""}, ${isSynced ? workflowCount : 0} synced)` : "";
|
|
676
|
-
return /* @__PURE__ */ jsxs4(Box4, { children: [
|
|
677
|
-
/* @__PURE__ */ jsx4(Text4, { color: isSynced ? "green" : "gray", children: isSynced ? "\u25CF" : "\u25CB" }),
|
|
678
|
-
/* @__PURE__ */ jsx4(Text4, { color: "white", children: ` ${model.name}` }),
|
|
679
|
-
workflowSuffix && /* @__PURE__ */ jsx4(Text4, { color: "gray", children: workflowSuffix }),
|
|
680
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: " - " }),
|
|
681
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: displayProvider }),
|
|
682
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: " - " }),
|
|
683
|
-
/* @__PURE__ */ jsx4(Text4, { color: cap.color, children: cap.label })
|
|
684
|
-
] }, `${model.provider}:${model.name}`);
|
|
685
|
-
}),
|
|
686
|
-
modelWarnings.map((warning) => {
|
|
687
|
-
const displayProvider = providers.find((p) => p.provider.name === warning.provider)?.provider.displayName ?? warning.provider;
|
|
688
|
-
return /* @__PURE__ */ jsxs4(Box4, { children: [
|
|
689
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: "\u25CB" }),
|
|
690
|
-
/* @__PURE__ */ jsx4(Text4, { color: "white", children: ` ${warning.name}` }),
|
|
691
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: " - " }),
|
|
692
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: displayProvider }),
|
|
693
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: " - " }),
|
|
694
|
-
/* @__PURE__ */ jsx4(Text4, { color: "yellow", children: warning.statusHint })
|
|
695
|
-
] }, `${warning.provider}:${warning.name}`);
|
|
696
|
-
}),
|
|
697
|
-
unavailableSynced.length > 0 && /* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", marginTop: models.length > 0 ? 1 : 0, children: [
|
|
698
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: "Synced but not currently available:" }),
|
|
699
|
-
unavailableSynced.map((name) => /* @__PURE__ */ jsxs4(Box4, { children: [
|
|
700
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: "\u25CB" }),
|
|
701
|
-
/* @__PURE__ */ jsx4(Text4, { color: "gray", children: ` ${name}` })
|
|
702
|
-
] }, name))
|
|
703
|
-
] })
|
|
704
|
-
] })
|
|
705
|
-
] }),
|
|
706
|
-
/* @__PURE__ */ jsx4(
|
|
707
|
-
RequestLog,
|
|
708
|
-
{
|
|
709
|
-
requests,
|
|
710
|
-
maxVisible,
|
|
711
|
-
hasModels: models.length > 0
|
|
712
|
-
}
|
|
713
|
-
),
|
|
714
|
-
/* @__PURE__ */ jsx4(NavigationMenu, { items: menuItems, onSelect: onNavigate })
|
|
715
|
-
] });
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
// src/tui/pages/RegisterPage.tsx
|
|
719
|
-
import { useEffect as useEffect9 } from "react";
|
|
720
|
-
import { Box as Box5, Text as Text5 } from "ink";
|
|
721
|
-
import Spinner3 from "ink-spinner";
|
|
722
|
-
|
|
723
|
-
// src/tui/hooks/useRegister.ts
|
|
724
|
-
import { useState as useState8, useCallback as useCallback7, useRef as useRef2, useEffect as useEffect8 } from "react";
|
|
725
|
-
var MODEL_TYPE_MAP = {
|
|
726
|
-
text: "llm_chat",
|
|
727
|
-
image: "image_generation",
|
|
728
|
-
video: "video_generation"
|
|
729
|
-
};
|
|
730
|
-
function useSync() {
|
|
731
|
-
const [status, setStatus] = useState8("idle");
|
|
732
|
-
const [progress, setProgress] = useState8({
|
|
733
|
-
current: 0,
|
|
734
|
-
total: 0
|
|
735
|
-
});
|
|
736
|
-
const [syncedModels, setSyncedModels] = useState8(
|
|
737
|
-
[]
|
|
738
|
-
);
|
|
739
|
-
const [error, setError] = useState8(null);
|
|
740
|
-
const cancelledRef = useRef2(false);
|
|
741
|
-
useEffect8(() => {
|
|
742
|
-
return () => {
|
|
743
|
-
cancelledRef.current = true;
|
|
744
|
-
};
|
|
745
|
-
}, []);
|
|
746
|
-
const cancel = useCallback7(() => {
|
|
747
|
-
cancelledRef.current = true;
|
|
748
|
-
setStatus("idle");
|
|
749
|
-
}, []);
|
|
750
|
-
const startSync = useCallback7(() => {
|
|
751
|
-
cancelledRef.current = false;
|
|
752
|
-
setError(null);
|
|
753
|
-
setSyncedModels([]);
|
|
754
|
-
const run = async () => {
|
|
755
|
-
try {
|
|
756
|
-
setStatus("discovering");
|
|
757
|
-
const localModels = await discoverAllModelsWithParameters();
|
|
758
|
-
if (cancelledRef.current) return;
|
|
759
|
-
if (localModels.length === 0) {
|
|
760
|
-
setError("No local models found.");
|
|
761
|
-
setStatus("error");
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
const existingSynced = await getSyncedModels();
|
|
765
|
-
if (cancelledRef.current) return;
|
|
766
|
-
const remoteByName = new Map(
|
|
767
|
-
existingSynced.map((m) => [m.name, m.id])
|
|
768
|
-
);
|
|
769
|
-
setStatus("syncing");
|
|
770
|
-
setProgress({ current: 0, total: localModels.length });
|
|
771
|
-
for (let i = 0; i < localModels.length; i++) {
|
|
772
|
-
if (cancelledRef.current) return;
|
|
773
|
-
const model = localModels[i];
|
|
774
|
-
const modelType = MODEL_TYPE_MAP[model.capability];
|
|
775
|
-
const existingId = remoteByName.get(model.name);
|
|
776
|
-
if (existingId) {
|
|
777
|
-
await updateLocalModel({
|
|
778
|
-
modelId: existingId,
|
|
779
|
-
modelName: model.name,
|
|
780
|
-
provider: model.provider,
|
|
781
|
-
modelType,
|
|
782
|
-
parameters: model.parameters
|
|
783
|
-
});
|
|
784
|
-
} else {
|
|
785
|
-
await syncLocalModel({
|
|
786
|
-
modelName: model.name,
|
|
787
|
-
provider: model.provider,
|
|
788
|
-
modelType,
|
|
789
|
-
parameters: model.parameters
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
setProgress({ current: i + 1, total: localModels.length });
|
|
793
|
-
}
|
|
794
|
-
if (cancelledRef.current) return;
|
|
795
|
-
const finalModels = localModels.map((m) => ({
|
|
796
|
-
name: m.name,
|
|
797
|
-
provider: m.provider,
|
|
798
|
-
capability: m.capability,
|
|
799
|
-
isNew: !remoteByName.has(m.name)
|
|
800
|
-
}));
|
|
801
|
-
setSyncedModels(finalModels);
|
|
802
|
-
setStatus("done");
|
|
803
|
-
} catch (err) {
|
|
804
|
-
if (!cancelledRef.current) {
|
|
805
|
-
setError(err instanceof Error ? err.message : "Sync failed");
|
|
806
|
-
setStatus("error");
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
run();
|
|
811
|
-
}, []);
|
|
812
|
-
return {
|
|
813
|
-
status,
|
|
814
|
-
progress,
|
|
815
|
-
syncedModels,
|
|
816
|
-
error,
|
|
817
|
-
startSync,
|
|
818
|
-
cancel
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
// src/tui/pages/RegisterPage.tsx
|
|
823
|
-
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
824
|
-
function SyncPage() {
|
|
825
|
-
const { status, progress, syncedModels, error, startSync, cancel } = useSync();
|
|
826
|
-
useEffect9(() => {
|
|
827
|
-
startSync();
|
|
828
|
-
return () => cancel();
|
|
829
|
-
}, []);
|
|
830
|
-
if (status === "idle") {
|
|
831
|
-
return /* @__PURE__ */ jsx5(Box5, { flexDirection: "column", marginTop: 1, paddingX: 1, children: /* @__PURE__ */ jsx5(Box5, { marginTop: 1, children: /* @__PURE__ */ jsx5(Text5, { color: "gray", children: "Starting model sync..." }) }) });
|
|
832
|
-
}
|
|
833
|
-
if (status === "error") {
|
|
834
|
-
return /* @__PURE__ */ jsx5(Box5, { flexDirection: "column", marginTop: 1, paddingX: 1, children: /* @__PURE__ */ jsx5(Box5, { marginTop: 1, children: /* @__PURE__ */ jsxs5(Text5, { color: "red", children: [
|
|
835
|
-
"Sync failed: ",
|
|
836
|
-
error
|
|
837
|
-
] }) }) });
|
|
838
|
-
}
|
|
839
|
-
if (status === "discovering") {
|
|
840
|
-
return /* @__PURE__ */ jsx5(Box5, { flexDirection: "column", marginTop: 1, paddingX: 1, children: /* @__PURE__ */ jsxs5(Box5, { marginTop: 1, children: [
|
|
841
|
-
/* @__PURE__ */ jsx5(Text5, { color: "cyan", children: /* @__PURE__ */ jsx5(Spinner3, { type: "dots" }) }),
|
|
842
|
-
/* @__PURE__ */ jsx5(Text5, { children: " Discovering local models..." })
|
|
843
|
-
] }) });
|
|
844
|
-
}
|
|
845
|
-
if (status === "syncing") {
|
|
846
|
-
return /* @__PURE__ */ jsx5(Box5, { flexDirection: "column", marginTop: 1, paddingX: 1, children: /* @__PURE__ */ jsxs5(Box5, { marginTop: 1, children: [
|
|
847
|
-
/* @__PURE__ */ jsx5(Text5, { color: "cyan", children: /* @__PURE__ */ jsx5(Spinner3, { type: "dots" }) }),
|
|
848
|
-
/* @__PURE__ */ jsxs5(Text5, { children: [
|
|
849
|
-
" ",
|
|
850
|
-
"Syncing ",
|
|
851
|
-
progress.current,
|
|
852
|
-
"/",
|
|
853
|
-
progress.total,
|
|
854
|
-
" models..."
|
|
855
|
-
] })
|
|
856
|
-
] }) });
|
|
857
|
-
}
|
|
858
|
-
const newModels = syncedModels.filter((m) => m.isNew);
|
|
859
|
-
const resyncedModels = syncedModels.filter((m) => !m.isNew);
|
|
860
|
-
return /* @__PURE__ */ jsxs5(Box5, { flexDirection: "column", marginTop: 1, paddingX: 1, children: [
|
|
861
|
-
newModels.length > 0 && /* @__PURE__ */ jsxs5(Box5, { flexDirection: "column", marginTop: 1, children: [
|
|
862
|
-
/* @__PURE__ */ jsxs5(Text5, { color: "green", children: [
|
|
863
|
-
"Synced ",
|
|
864
|
-
newModels.length,
|
|
865
|
-
" new model",
|
|
866
|
-
newModels.length !== 1 ? "s" : "",
|
|
867
|
-
":"
|
|
868
|
-
] }),
|
|
869
|
-
newModels.map((m) => /* @__PURE__ */ jsxs5(Box5, { children: [
|
|
870
|
-
/* @__PURE__ */ jsx5(Text5, { color: "green", children: " \u2713 " }),
|
|
871
|
-
/* @__PURE__ */ jsxs5(Text5, { children: [
|
|
872
|
-
m.name,
|
|
873
|
-
" "
|
|
874
|
-
] }),
|
|
875
|
-
/* @__PURE__ */ jsxs5(Text5, { color: "gray", children: [
|
|
876
|
-
"[",
|
|
877
|
-
m.provider,
|
|
878
|
-
"]"
|
|
879
|
-
] })
|
|
880
|
-
] }, m.name))
|
|
881
|
-
] }),
|
|
882
|
-
resyncedModels.length > 0 && /* @__PURE__ */ jsxs5(Box5, { flexDirection: "column", marginTop: 1, children: [
|
|
883
|
-
/* @__PURE__ */ jsxs5(Text5, { color: "green", children: [
|
|
884
|
-
"Resynced ",
|
|
885
|
-
resyncedModels.length,
|
|
886
|
-
" existing model",
|
|
887
|
-
resyncedModels.length !== 1 ? "s" : "",
|
|
888
|
-
":"
|
|
889
|
-
] }),
|
|
890
|
-
resyncedModels.map((m) => /* @__PURE__ */ jsxs5(Box5, { children: [
|
|
891
|
-
/* @__PURE__ */ jsx5(Text5, { color: "green", children: " \u2713 " }),
|
|
892
|
-
/* @__PURE__ */ jsxs5(Text5, { children: [
|
|
893
|
-
m.name,
|
|
894
|
-
" "
|
|
895
|
-
] }),
|
|
896
|
-
/* @__PURE__ */ jsxs5(Text5, { color: "gray", children: [
|
|
897
|
-
"[",
|
|
898
|
-
m.provider,
|
|
899
|
-
"]"
|
|
900
|
-
] })
|
|
901
|
-
] }, m.name))
|
|
902
|
-
] })
|
|
903
|
-
] });
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
// src/tui/pages/SetupPage.tsx
|
|
907
|
-
import { useState as useState9, useMemo as useMemo3, useEffect as useEffect10 } from "react";
|
|
908
|
-
import { Box as Box6, Text as Text7, useInput as useInput2, useStdout as useStdout4 } from "ink";
|
|
909
|
-
import Spinner4 from "ink-spinner";
|
|
910
|
-
|
|
911
|
-
// src/tui/components/MarkdownText.tsx
|
|
912
|
-
import { useMemo as useMemo2 } from "react";
|
|
913
|
-
import { Text as Text6, useStdout as useStdout3 } from "ink";
|
|
914
|
-
import chalk from "chalk";
|
|
915
|
-
import { marked } from "marked";
|
|
916
|
-
import { markedTerminal } from "marked-terminal";
|
|
917
|
-
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
918
|
-
var codeStyle = chalk.cyan;
|
|
919
|
-
var identity = (s) => s;
|
|
920
|
-
function renderMarkdown(content, width) {
|
|
921
|
-
marked.use(
|
|
922
|
-
markedTerminal({
|
|
923
|
-
width,
|
|
924
|
-
codespan: codeStyle,
|
|
925
|
-
link: identity,
|
|
926
|
-
href: identity
|
|
927
|
-
})
|
|
928
|
-
);
|
|
929
|
-
marked.use({
|
|
930
|
-
renderer: {
|
|
931
|
-
code({ text }) {
|
|
932
|
-
const lines = text.trim().split("\n").map((l) => " " + codeStyle(l)).join("\n");
|
|
933
|
-
return lines + "\n\n";
|
|
934
|
-
},
|
|
935
|
-
link({ href, text }) {
|
|
936
|
-
if (text && text !== href) {
|
|
937
|
-
return `${text} (${href})`;
|
|
938
|
-
}
|
|
939
|
-
return href;
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
return marked.parse(content).trimEnd();
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
// src/tui/pages/SetupPage.tsx
|
|
947
|
-
import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
948
|
-
function ProviderDetailView({
|
|
949
|
-
provider,
|
|
950
|
-
onBack
|
|
951
|
-
}) {
|
|
952
|
-
const [scrollOffset, setScrollOffset] = useState9(0);
|
|
953
|
-
const { stdout } = useStdout4();
|
|
954
|
-
const termHeight = (stdout?.rows ?? 24) - 4;
|
|
955
|
-
const headerHeight = 14;
|
|
956
|
-
const footerLines = 6;
|
|
957
|
-
const contentPadding = 2;
|
|
958
|
-
const viewHeight = termHeight - headerHeight - footerLines - contentPadding;
|
|
959
|
-
const contentWidth = (stdout?.columns ?? 80) - 4;
|
|
960
|
-
const renderedLines = useMemo3(() => {
|
|
961
|
-
const rendered = renderMarkdown(provider.readme, contentWidth);
|
|
962
|
-
return rendered.split("\n");
|
|
963
|
-
}, [provider.readme, contentWidth]);
|
|
964
|
-
const maxScroll = Math.max(0, renderedLines.length - viewHeight);
|
|
965
|
-
useInput2((input, key) => {
|
|
966
|
-
if (input === "q" || key.escape || key.return) {
|
|
967
|
-
onBack();
|
|
968
|
-
return;
|
|
969
|
-
}
|
|
970
|
-
if (key.upArrow) {
|
|
971
|
-
setScrollOffset((prev) => Math.max(0, prev - 1));
|
|
972
|
-
} else if (key.downArrow) {
|
|
973
|
-
setScrollOffset((prev) => Math.min(maxScroll, prev + 1));
|
|
974
|
-
}
|
|
975
|
-
});
|
|
976
|
-
const visibleContent = renderedLines.slice(scrollOffset, scrollOffset + viewHeight).join("\n");
|
|
977
|
-
const scrollbar = useMemo3(() => {
|
|
978
|
-
if (maxScroll === 0) return null;
|
|
979
|
-
const thumbSize = Math.max(
|
|
980
|
-
1,
|
|
981
|
-
Math.round(viewHeight / renderedLines.length * viewHeight)
|
|
982
|
-
);
|
|
983
|
-
const thumbPos = Math.round(
|
|
984
|
-
scrollOffset / maxScroll * (viewHeight - thumbSize)
|
|
985
|
-
);
|
|
986
|
-
return Array.from(
|
|
987
|
-
{ length: viewHeight },
|
|
988
|
-
(_, i) => i >= thumbPos && i < thumbPos + thumbSize
|
|
989
|
-
);
|
|
990
|
-
}, [scrollOffset, maxScroll, viewHeight, renderedLines.length]);
|
|
991
|
-
return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
|
|
992
|
-
/* @__PURE__ */ jsxs6(Box6, { height: viewHeight, children: [
|
|
993
|
-
/* @__PURE__ */ jsx7(
|
|
994
|
-
Box6,
|
|
995
|
-
{
|
|
996
|
-
flexDirection: "column",
|
|
997
|
-
paddingX: 1,
|
|
998
|
-
paddingY: 1,
|
|
999
|
-
flexGrow: 1,
|
|
1000
|
-
overflow: "hidden",
|
|
1001
|
-
children: /* @__PURE__ */ jsx7(Text7, { children: visibleContent })
|
|
1002
|
-
}
|
|
1003
|
-
),
|
|
1004
|
-
scrollbar && /* @__PURE__ */ jsx7(Box6, { flexDirection: "column", children: scrollbar.map((isThumb, i) => /* @__PURE__ */ jsx7(
|
|
1005
|
-
Text7,
|
|
1006
|
-
{
|
|
1007
|
-
color: isThumb ? "cyan" : "gray",
|
|
1008
|
-
dimColor: !isThumb,
|
|
1009
|
-
children: isThumb ? "\u2503" : "\u2502"
|
|
1010
|
-
},
|
|
1011
|
-
i
|
|
1012
|
-
)) })
|
|
1013
|
-
] }),
|
|
1014
|
-
/* @__PURE__ */ jsxs6(
|
|
1015
|
-
Box6,
|
|
1016
|
-
{
|
|
1017
|
-
flexDirection: "column",
|
|
1018
|
-
paddingX: 1,
|
|
1019
|
-
borderStyle: "single",
|
|
1020
|
-
borderTop: true,
|
|
1021
|
-
borderBottom: false,
|
|
1022
|
-
borderLeft: false,
|
|
1023
|
-
borderRight: false,
|
|
1024
|
-
borderColor: "gray",
|
|
1025
|
-
children: [
|
|
1026
|
-
/* @__PURE__ */ jsx7(Box6, { marginTop: 1, children: /* @__PURE__ */ jsx7(Text7, { color: "gray", children: "Actions" }) }),
|
|
1027
|
-
/* @__PURE__ */ jsxs6(Box6, { children: [
|
|
1028
|
-
/* @__PURE__ */ jsxs6(Text7, { color: "cyan", bold: true, children: [
|
|
1029
|
-
"\u276F",
|
|
1030
|
-
" Back"
|
|
1031
|
-
] }),
|
|
1032
|
-
/* @__PURE__ */ jsx7(Text7, { color: "gray", children: " - Return to providers" })
|
|
1033
|
-
] }),
|
|
1034
|
-
/* @__PURE__ */ jsx7(Box6, { marginTop: 1, height: 1, children: /* @__PURE__ */ jsxs6(Text7, { color: "gray", wrap: "truncate-end", children: [
|
|
1035
|
-
"Up/Down Scroll ",
|
|
1036
|
-
"\u2022",
|
|
1037
|
-
" Enter/q/Esc Back",
|
|
1038
|
-
maxScroll > 0 && ` \u2022 ${Math.round(scrollOffset / maxScroll * 100)}%`
|
|
1039
|
-
] }) })
|
|
1040
|
-
]
|
|
1041
|
-
}
|
|
1042
|
-
)
|
|
1043
|
-
] });
|
|
1044
|
-
}
|
|
1045
|
-
function SetupPage({ onBack }) {
|
|
1046
|
-
const { providers, loading } = useSetupProviders();
|
|
1047
|
-
const [selectedProvider, setSelectedProvider] = useState9(null);
|
|
1048
|
-
const running = useMemo3(
|
|
1049
|
-
() => providers.filter((p) => p.status.running),
|
|
1050
|
-
[providers]
|
|
1051
|
-
);
|
|
1052
|
-
const installed = useMemo3(
|
|
1053
|
-
() => providers.filter((p) => p.status.installed && !p.status.running),
|
|
1054
|
-
[providers]
|
|
1055
|
-
);
|
|
1056
|
-
const notInstalled = useMemo3(
|
|
1057
|
-
() => providers.filter((p) => !p.status.installed),
|
|
1058
|
-
[providers]
|
|
1059
|
-
);
|
|
1060
|
-
const allProviders = useMemo3(
|
|
1061
|
-
() => [...running, ...installed, ...notInstalled],
|
|
1062
|
-
[running, installed, notInstalled]
|
|
1063
|
-
);
|
|
1064
|
-
const totalItems = allProviders.length + 1;
|
|
1065
|
-
const backIndex = allProviders.length;
|
|
1066
|
-
const [cursorIndex, setCursorIndex] = useState9(backIndex);
|
|
1067
|
-
useEffect10(() => {
|
|
1068
|
-
setCursorIndex(backIndex);
|
|
1069
|
-
}, [backIndex]);
|
|
1070
|
-
useInput2((input, key) => {
|
|
1071
|
-
if (selectedProvider) return;
|
|
1072
|
-
if (input === "q" || key.escape) {
|
|
1073
|
-
onBack();
|
|
1074
|
-
return;
|
|
1075
|
-
}
|
|
1076
|
-
if (key.upArrow) {
|
|
1077
|
-
setCursorIndex((prev) => Math.max(0, prev - 1));
|
|
1078
|
-
} else if (key.downArrow) {
|
|
1079
|
-
setCursorIndex((prev) => Math.min(totalItems - 1, prev + 1));
|
|
1080
|
-
} else if (key.return) {
|
|
1081
|
-
if (cursorIndex === backIndex) {
|
|
1082
|
-
onBack();
|
|
1083
|
-
} else if (allProviders[cursorIndex]) {
|
|
1084
|
-
setSelectedProvider(allProviders[cursorIndex].provider.name);
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
});
|
|
1088
|
-
if (selectedProvider) {
|
|
1089
|
-
const found = providers.find((p) => p.provider.name === selectedProvider);
|
|
1090
|
-
if (found) {
|
|
1091
|
-
return /* @__PURE__ */ jsx7(
|
|
1092
|
-
ProviderDetailView,
|
|
1093
|
-
{
|
|
1094
|
-
provider: found.provider,
|
|
1095
|
-
onBack: () => setSelectedProvider(null)
|
|
1096
|
-
}
|
|
1097
|
-
);
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
return /* @__PURE__ */ jsx7(Box6, { flexDirection: "column", flexGrow: 1, children: /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", paddingX: 1, marginTop: 1, children: [
|
|
1101
|
-
/* @__PURE__ */ jsx7(Text7, { bold: true, color: "white", underline: true, children: "Manage Providers" }),
|
|
1102
|
-
/* @__PURE__ */ jsx7(Text7, { color: "gray", children: "Select a provider to view its setup guide." }),
|
|
1103
|
-
loading ? /* @__PURE__ */ jsxs6(Box6, { marginTop: 1, children: [
|
|
1104
|
-
/* @__PURE__ */ jsx7(Text7, { color: "cyan", children: /* @__PURE__ */ jsx7(Spinner4, { type: "dots" }) }),
|
|
1105
|
-
/* @__PURE__ */ jsx7(Text7, { children: " Detecting providers..." })
|
|
1106
|
-
] }) : /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", marginTop: 1, children: [
|
|
1107
|
-
running.length > 0 && /* @__PURE__ */ jsxs6(Fragment2, { children: [
|
|
1108
|
-
/* @__PURE__ */ jsx7(Text7, { bold: true, color: "green", children: "Running" }),
|
|
1109
|
-
running.map(({ provider }, i) => {
|
|
1110
|
-
const index = i;
|
|
1111
|
-
const isSelected = index === cursorIndex;
|
|
1112
|
-
return /* @__PURE__ */ jsxs6(
|
|
1113
|
-
Box6,
|
|
1114
|
-
{
|
|
1115
|
-
flexDirection: "column",
|
|
1116
|
-
marginTop: i > 0 ? 1 : 0,
|
|
1117
|
-
children: [
|
|
1118
|
-
/* @__PURE__ */ jsx7(Box6, { children: /* @__PURE__ */ jsxs6(
|
|
1119
|
-
Text7,
|
|
1120
|
-
{
|
|
1121
|
-
color: isSelected ? "cyan" : "white",
|
|
1122
|
-
bold: isSelected,
|
|
1123
|
-
children: [
|
|
1124
|
-
isSelected ? "\u276F" : " ",
|
|
1125
|
-
" ",
|
|
1126
|
-
"\u25CF",
|
|
1127
|
-
" ",
|
|
1128
|
-
provider.displayName
|
|
1129
|
-
]
|
|
1130
|
-
}
|
|
1131
|
-
) }),
|
|
1132
|
-
/* @__PURE__ */ jsxs6(Text7, { color: "gray", wrap: "wrap", children: [
|
|
1133
|
-
" ",
|
|
1134
|
-
provider.description
|
|
1135
|
-
] })
|
|
1136
|
-
]
|
|
1137
|
-
},
|
|
1138
|
-
provider.name
|
|
1139
|
-
);
|
|
1140
|
-
})
|
|
1141
|
-
] }),
|
|
1142
|
-
installed.length > 0 && /* @__PURE__ */ jsxs6(
|
|
1143
|
-
Box6,
|
|
1144
|
-
{
|
|
1145
|
-
flexDirection: "column",
|
|
1146
|
-
marginTop: running.length > 0 ? 1 : 0,
|
|
1147
|
-
children: [
|
|
1148
|
-
/* @__PURE__ */ jsx7(Text7, { bold: true, color: "yellow", children: "Installed" }),
|
|
1149
|
-
installed.map(({ provider, status }, i) => {
|
|
1150
|
-
const index = running.length + i;
|
|
1151
|
-
const isSelected = index === cursorIndex;
|
|
1152
|
-
return /* @__PURE__ */ jsxs6(
|
|
1153
|
-
Box6,
|
|
1154
|
-
{
|
|
1155
|
-
flexDirection: "column",
|
|
1156
|
-
marginTop: i > 0 ? 1 : 0,
|
|
1157
|
-
children: [
|
|
1158
|
-
/* @__PURE__ */ jsx7(Box6, { children: /* @__PURE__ */ jsxs6(
|
|
1159
|
-
Text7,
|
|
1160
|
-
{
|
|
1161
|
-
color: isSelected ? "cyan" : "white",
|
|
1162
|
-
bold: isSelected,
|
|
1163
|
-
children: [
|
|
1164
|
-
isSelected ? "\u276F" : " ",
|
|
1165
|
-
" ",
|
|
1166
|
-
"\u25CB",
|
|
1167
|
-
" ",
|
|
1168
|
-
provider.displayName
|
|
1169
|
-
]
|
|
1170
|
-
}
|
|
1171
|
-
) }),
|
|
1172
|
-
/* @__PURE__ */ jsxs6(Text7, { color: "gray", wrap: "wrap", children: [
|
|
1173
|
-
" ",
|
|
1174
|
-
provider.description
|
|
1175
|
-
] })
|
|
1176
|
-
]
|
|
1177
|
-
},
|
|
1178
|
-
provider.name
|
|
1179
|
-
);
|
|
1180
|
-
})
|
|
1181
|
-
]
|
|
1182
|
-
}
|
|
1183
|
-
),
|
|
1184
|
-
notInstalled.length > 0 && /* @__PURE__ */ jsxs6(
|
|
1185
|
-
Box6,
|
|
1186
|
-
{
|
|
1187
|
-
flexDirection: "column",
|
|
1188
|
-
marginTop: running.length > 0 || installed.length > 0 ? 1 : 0,
|
|
1189
|
-
children: [
|
|
1190
|
-
/* @__PURE__ */ jsx7(Text7, { bold: true, color: "gray", children: "Not Installed" }),
|
|
1191
|
-
notInstalled.map(({ provider }, i) => {
|
|
1192
|
-
const index = running.length + installed.length + i;
|
|
1193
|
-
const isSelected = index === cursorIndex;
|
|
1194
|
-
return /* @__PURE__ */ jsxs6(
|
|
1195
|
-
Box6,
|
|
1196
|
-
{
|
|
1197
|
-
flexDirection: "column",
|
|
1198
|
-
marginTop: i > 0 ? 1 : 0,
|
|
1199
|
-
children: [
|
|
1200
|
-
/* @__PURE__ */ jsx7(Box6, { children: /* @__PURE__ */ jsxs6(
|
|
1201
|
-
Text7,
|
|
1202
|
-
{
|
|
1203
|
-
color: isSelected ? "cyan" : "white",
|
|
1204
|
-
bold: isSelected,
|
|
1205
|
-
children: [
|
|
1206
|
-
isSelected ? "\u276F" : " ",
|
|
1207
|
-
" ",
|
|
1208
|
-
provider.displayName
|
|
1209
|
-
]
|
|
1210
|
-
}
|
|
1211
|
-
) }),
|
|
1212
|
-
/* @__PURE__ */ jsxs6(Text7, { color: "gray", wrap: "wrap", children: [
|
|
1213
|
-
" ",
|
|
1214
|
-
provider.description
|
|
1215
|
-
] })
|
|
1216
|
-
]
|
|
1217
|
-
},
|
|
1218
|
-
provider.name
|
|
1219
|
-
);
|
|
1220
|
-
})
|
|
1221
|
-
]
|
|
1222
|
-
}
|
|
1223
|
-
),
|
|
1224
|
-
/* @__PURE__ */ jsx7(Box6, { marginTop: 1, children: /* @__PURE__ */ jsxs6(
|
|
1225
|
-
Text7,
|
|
1226
|
-
{
|
|
1227
|
-
color: cursorIndex === backIndex ? "cyan" : "white",
|
|
1228
|
-
bold: cursorIndex === backIndex,
|
|
1229
|
-
children: [
|
|
1230
|
-
cursorIndex === backIndex ? "\u276F" : " ",
|
|
1231
|
-
" Back"
|
|
1232
|
-
]
|
|
1233
|
-
}
|
|
1234
|
-
) })
|
|
1235
|
-
] }),
|
|
1236
|
-
/* @__PURE__ */ jsx7(Box6, { marginTop: 1, children: /* @__PURE__ */ jsxs6(Text7, { color: "gray", children: [
|
|
1237
|
-
"Up/Down Navigate ",
|
|
1238
|
-
"\u2022",
|
|
1239
|
-
" Enter Select ",
|
|
1240
|
-
"\u2022",
|
|
1241
|
-
" q/Esc Back"
|
|
1242
|
-
] }) })
|
|
1243
|
-
] }) });
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
// src/tui/pages/OnboardingPage.tsx
|
|
1247
|
-
import { useEffect as useEffect12, useCallback as useCallback9, useState as useState11, useMemo as useMemo4 } from "react";
|
|
1248
|
-
import { Box as Box7, Text as Text8, useInput as useInput3 } from "ink";
|
|
1249
|
-
import Spinner5 from "ink-spinner";
|
|
1250
|
-
import chalk2 from "chalk";
|
|
1251
|
-
|
|
1252
|
-
// src/tui/hooks/useAuth.ts
|
|
1253
|
-
import { useState as useState10, useCallback as useCallback8, useRef as useRef3, useEffect as useEffect11 } from "react";
|
|
1254
|
-
import open from "open";
|
|
1255
|
-
var POLL_INTERVAL = 2e3;
|
|
1256
|
-
var MAX_ATTEMPTS = 30;
|
|
1257
|
-
function useAuth() {
|
|
1258
|
-
const [status, setStatus] = useState10("idle");
|
|
1259
|
-
const [authUrl, setAuthUrl] = useState10(null);
|
|
1260
|
-
const [timeRemaining, setTimeRemaining] = useState10(0);
|
|
1261
|
-
const cancelledRef = useRef3(false);
|
|
1262
|
-
const timerRef = useRef3(null);
|
|
1263
|
-
useEffect11(() => {
|
|
1264
|
-
return () => {
|
|
1265
|
-
cancelledRef.current = true;
|
|
1266
|
-
if (timerRef.current) clearInterval(timerRef.current);
|
|
1267
|
-
};
|
|
1268
|
-
}, []);
|
|
1269
|
-
const cancel = useCallback8(() => {
|
|
1270
|
-
cancelledRef.current = true;
|
|
1271
|
-
if (timerRef.current) {
|
|
1272
|
-
clearInterval(timerRef.current);
|
|
1273
|
-
timerRef.current = null;
|
|
1274
|
-
}
|
|
1275
|
-
setStatus("idle");
|
|
1276
|
-
setAuthUrl(null);
|
|
1277
|
-
setTimeRemaining(0);
|
|
1278
|
-
}, []);
|
|
1279
|
-
const startAuth = useCallback8(() => {
|
|
1280
|
-
cancelledRef.current = false;
|
|
1281
|
-
const run = async () => {
|
|
1282
|
-
try {
|
|
1283
|
-
const { url, token } = await requestDeviceAuth();
|
|
1284
|
-
if (cancelledRef.current) return;
|
|
1285
|
-
setAuthUrl(url);
|
|
1286
|
-
setStatus("waiting");
|
|
1287
|
-
const totalTime = MAX_ATTEMPTS * POLL_INTERVAL / 1e3;
|
|
1288
|
-
setTimeRemaining(totalTime);
|
|
1289
|
-
timerRef.current = setInterval(() => {
|
|
1290
|
-
setTimeRemaining((prev) => {
|
|
1291
|
-
const next = prev - 1;
|
|
1292
|
-
if (next <= 0 && timerRef.current) {
|
|
1293
|
-
clearInterval(timerRef.current);
|
|
1294
|
-
timerRef.current = null;
|
|
1295
|
-
}
|
|
1296
|
-
return Math.max(0, next);
|
|
1297
|
-
});
|
|
1298
|
-
}, 1e3);
|
|
1299
|
-
await open(url);
|
|
1300
|
-
for (let i = 0; i < MAX_ATTEMPTS; i++) {
|
|
1301
|
-
await new Promise((r) => setTimeout(r, POLL_INTERVAL));
|
|
1302
|
-
if (cancelledRef.current) return;
|
|
1303
|
-
const result = await pollDeviceAuth(token);
|
|
1304
|
-
if (result.status === "completed" && result.apiKey) {
|
|
1305
|
-
if (timerRef.current) clearInterval(timerRef.current);
|
|
1306
|
-
setApiKey(result.apiKey);
|
|
1307
|
-
setStatus("success");
|
|
1308
|
-
return;
|
|
1309
|
-
}
|
|
1310
|
-
if (result.status === "expired") {
|
|
1311
|
-
if (timerRef.current) clearInterval(timerRef.current);
|
|
1312
|
-
setStatus("expired");
|
|
1313
|
-
return;
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
if (!cancelledRef.current) {
|
|
1317
|
-
setStatus("timeout");
|
|
1318
|
-
}
|
|
1319
|
-
} catch {
|
|
1320
|
-
if (!cancelledRef.current) {
|
|
1321
|
-
setStatus("expired");
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
};
|
|
1325
|
-
run();
|
|
1326
|
-
}, []);
|
|
1327
|
-
return {
|
|
1328
|
-
status,
|
|
1329
|
-
authUrl,
|
|
1330
|
-
timeRemaining,
|
|
1331
|
-
startAuth,
|
|
1332
|
-
cancel
|
|
1333
|
-
};
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
// src/tui/pages/OnboardingPage.tsx
|
|
1337
|
-
import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1338
|
-
var SHIMMER_SPEED = 35;
|
|
1339
|
-
function useShimmerLogo() {
|
|
1340
|
-
const [frame, setFrame] = useState11(0);
|
|
1341
|
-
const lines = useMemo4(() => LogoString.split("\n"), []);
|
|
1342
|
-
const totalChars = useMemo4(() => {
|
|
1343
|
-
let count = 0;
|
|
1344
|
-
for (const line of lines) {
|
|
1345
|
-
for (const ch of line) {
|
|
1346
|
-
if (ch !== " " && ch !== " ") count++;
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
return count;
|
|
1350
|
-
}, [lines]);
|
|
1351
|
-
const cycleLength = totalChars + 40;
|
|
1352
|
-
useEffect12(() => {
|
|
1353
|
-
const interval = setInterval(() => {
|
|
1354
|
-
setFrame((f) => (f + 1) % cycleLength);
|
|
1355
|
-
}, SHIMMER_SPEED);
|
|
1356
|
-
return () => clearInterval(interval);
|
|
1357
|
-
}, [cycleLength]);
|
|
1358
|
-
return useMemo4(() => {
|
|
1359
|
-
const sweepPos = frame;
|
|
1360
|
-
const holdEnd = totalChars + 20;
|
|
1361
|
-
let charIdx = 0;
|
|
1362
|
-
return lines.map((line) => {
|
|
1363
|
-
let result = "";
|
|
1364
|
-
for (let i = 0; i < line.length; i++) {
|
|
1365
|
-
const ch = line[i];
|
|
1366
|
-
if (ch === " " || ch === " ") {
|
|
1367
|
-
result += ch;
|
|
1368
|
-
continue;
|
|
1369
|
-
}
|
|
1370
|
-
let brightness;
|
|
1371
|
-
if (sweepPos <= totalChars) {
|
|
1372
|
-
const lag = charIdx;
|
|
1373
|
-
const t = sweepPos - lag;
|
|
1374
|
-
brightness = t <= 0 ? 0.1 : Math.min(1, t / 8);
|
|
1375
|
-
} else if (sweepPos <= holdEnd) {
|
|
1376
|
-
brightness = 1;
|
|
1377
|
-
} else {
|
|
1378
|
-
const fadeProgress = (sweepPos - holdEnd) / (cycleLength - holdEnd);
|
|
1379
|
-
brightness = Math.max(0.1, 1 - fadeProgress);
|
|
1380
|
-
}
|
|
1381
|
-
if (brightness >= 0.9) {
|
|
1382
|
-
result += chalk2.cyanBright.bold(ch);
|
|
1383
|
-
} else if (brightness >= 0.6) {
|
|
1384
|
-
result += chalk2.cyan(ch);
|
|
1385
|
-
} else if (brightness >= 0.3) {
|
|
1386
|
-
result += chalk2.rgb(0, 100, 120)(ch);
|
|
1387
|
-
} else {
|
|
1388
|
-
result += chalk2.rgb(0, 50, 60)(ch);
|
|
1389
|
-
}
|
|
1390
|
-
charIdx++;
|
|
1391
|
-
}
|
|
1392
|
-
return result;
|
|
1393
|
-
}).join("\n");
|
|
1394
|
-
}, [frame, lines, totalChars, cycleLength]);
|
|
1395
|
-
}
|
|
1396
|
-
function OnboardingPage({ onComplete }) {
|
|
1397
|
-
const {
|
|
1398
|
-
status: authStatus,
|
|
1399
|
-
authUrl,
|
|
1400
|
-
timeRemaining,
|
|
1401
|
-
startAuth,
|
|
1402
|
-
cancel: cancelAuth
|
|
1403
|
-
} = useAuth();
|
|
1404
|
-
const shimmerLogo = useShimmerLogo();
|
|
1405
|
-
useEffect12(() => {
|
|
1406
|
-
if (authStatus === "success") {
|
|
1407
|
-
const timer = setTimeout(() => onComplete(), 1500);
|
|
1408
|
-
return () => clearTimeout(timer);
|
|
1409
|
-
}
|
|
1410
|
-
}, [authStatus, onComplete]);
|
|
1411
|
-
useEffect12(() => {
|
|
1412
|
-
return () => cancelAuth();
|
|
1413
|
-
}, []);
|
|
1414
|
-
const handleAction = useCallback9(() => {
|
|
1415
|
-
cancelAuth();
|
|
1416
|
-
startAuth();
|
|
1417
|
-
}, [cancelAuth, startAuth]);
|
|
1418
|
-
const canAct = authStatus === "idle" || authStatus === "expired" || authStatus === "timeout";
|
|
1419
|
-
useInput3((_input, key) => {
|
|
1420
|
-
if (canAct && !key.ctrl) {
|
|
1421
|
-
handleAction();
|
|
1422
|
-
}
|
|
1423
|
-
});
|
|
1424
|
-
return /* @__PURE__ */ jsxs7(Box7, { flexDirection: "column", flexGrow: 1, children: [
|
|
1425
|
-
/* @__PURE__ */ jsx8(Box7, { flexGrow: 1 }),
|
|
1426
|
-
/* @__PURE__ */ jsxs7(Box7, { flexDirection: "column", alignItems: "center", children: [
|
|
1427
|
-
/* @__PURE__ */ jsx8(Text8, { children: shimmerLogo }),
|
|
1428
|
-
/* @__PURE__ */ jsx8(Box7, { flexDirection: "column", alignItems: "center", marginTop: 2, children: /* @__PURE__ */ jsx8(Text8, { bold: true, color: "white", children: "MindStudio Local Tunnel" }) }),
|
|
1429
|
-
/* @__PURE__ */ jsxs7(Box7, { flexDirection: "column", alignItems: "center", children: [
|
|
1430
|
-
authStatus === "idle" && /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
1431
|
-
/* @__PURE__ */ jsx8(Text8, { color: "gray", children: "Connect your MindStudio account to get started." }),
|
|
1432
|
-
/* @__PURE__ */ jsx8(Box7, { marginTop: 1, children: /* @__PURE__ */ jsx8(Text8, { color: "cyan", bold: true, children: "Press any key to Connect Account" }) })
|
|
1433
|
-
] }),
|
|
1434
|
-
(authStatus === "expired" || authStatus === "timeout") && /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
1435
|
-
/* @__PURE__ */ jsx8(Text8, { color: "red", children: authStatus === "expired" ? "Authorization expired." : "Authorization timed out." }),
|
|
1436
|
-
/* @__PURE__ */ jsx8(Box7, { marginTop: 1, children: /* @__PURE__ */ jsx8(Text8, { color: "cyan", bold: true, children: "Press any key to Try Again" }) })
|
|
1437
|
-
] }),
|
|
1438
|
-
authStatus === "waiting" && /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
1439
|
-
/* @__PURE__ */ jsxs7(Box7, { children: [
|
|
1440
|
-
/* @__PURE__ */ jsx8(Text8, { color: "cyan", children: /* @__PURE__ */ jsx8(Spinner5, { type: "dots" }) }),
|
|
1441
|
-
/* @__PURE__ */ jsxs7(Text8, { children: [
|
|
1442
|
-
" ",
|
|
1443
|
-
"Waiting for browser authorization... (",
|
|
1444
|
-
timeRemaining,
|
|
1445
|
-
"s remaining)"
|
|
1446
|
-
] })
|
|
1447
|
-
] }),
|
|
1448
|
-
authUrl && /* @__PURE__ */ jsxs7(Box7, { flexDirection: "column", alignItems: "center", marginTop: 1, children: [
|
|
1449
|
-
/* @__PURE__ */ jsx8(Text8, { color: "gray", children: "If browser didn't open, visit:" }),
|
|
1450
|
-
/* @__PURE__ */ jsx8(Text8, { color: "cyan", children: authUrl })
|
|
1451
|
-
] })
|
|
1452
|
-
] }),
|
|
1453
|
-
authStatus === "success" && /* @__PURE__ */ jsxs7(Text8, { color: "green", children: [
|
|
1454
|
-
"\u2713",
|
|
1455
|
-
" Authenticated!"
|
|
1456
|
-
] })
|
|
1457
|
-
] })
|
|
1458
|
-
] }),
|
|
1459
|
-
/* @__PURE__ */ jsx8(Box7, { flexGrow: 1 })
|
|
1460
|
-
] });
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
// src/tui/App.tsx
|
|
1464
|
-
import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1465
|
-
function App({ runner }) {
|
|
1466
|
-
const { exit } = useApp();
|
|
1467
|
-
const { stdout } = useStdout5();
|
|
1468
|
-
const {
|
|
1469
|
-
status: connectionStatus,
|
|
1470
|
-
environment,
|
|
1471
|
-
error: connectionError,
|
|
1472
|
-
retry: retryConnection
|
|
1473
|
-
} = useConnection();
|
|
1474
|
-
const { refresh: refreshProviders } = useProviders();
|
|
1475
|
-
const {
|
|
1476
|
-
models,
|
|
1477
|
-
warnings: modelWarnings,
|
|
1478
|
-
loading: modelsLoading,
|
|
1479
|
-
refresh: refreshModels
|
|
1480
|
-
} = useModels();
|
|
1481
|
-
const { requests } = useRequests();
|
|
1482
|
-
const { syncedNames, refresh: refreshSynced } = useSyncedModels(connectionStatus);
|
|
1483
|
-
const shouldOnboard = getApiKey() === void 0;
|
|
1484
|
-
const [page, setPage] = useState12(
|
|
1485
|
-
shouldOnboard ? "onboarding" : "dashboard"
|
|
1486
|
-
);
|
|
1487
|
-
useEffect13(() => {
|
|
1488
|
-
if (page === "dashboard") {
|
|
1489
|
-
refreshAll();
|
|
1490
|
-
}
|
|
1491
|
-
}, [page]);
|
|
1492
|
-
useEffect13(() => {
|
|
1493
|
-
if (connectionStatus === "connected" && models.length > 0) {
|
|
1494
|
-
runner.start(models.map((m) => m.name));
|
|
1495
|
-
}
|
|
1496
|
-
}, [connectionStatus, models, runner]);
|
|
1497
|
-
useEffect13(() => () => runner.stop(), [runner]);
|
|
1498
|
-
const refreshAll = useCallback10(async () => {
|
|
1499
|
-
await Promise.all([
|
|
1500
|
-
refreshProviders(),
|
|
1501
|
-
refreshModels(),
|
|
1502
|
-
refreshSynced()
|
|
1503
|
-
]);
|
|
1504
|
-
}, [refreshProviders, refreshModels, refreshSynced]);
|
|
1505
|
-
const handleQuit = useCallback10(() => {
|
|
1506
|
-
runner.stop();
|
|
1507
|
-
exit();
|
|
1508
|
-
}, [runner, exit]);
|
|
1509
|
-
const handleOnboardingComplete = useCallback10(() => {
|
|
1510
|
-
retryConnection();
|
|
1511
|
-
refreshAll();
|
|
1512
|
-
setPage("dashboard");
|
|
1513
|
-
}, [retryConnection, refreshAll]);
|
|
1514
|
-
const handleNavigate = useCallback10(
|
|
1515
|
-
(id) => {
|
|
1516
|
-
switch (id) {
|
|
1517
|
-
case "auth":
|
|
1518
|
-
setPage("onboarding");
|
|
1519
|
-
break;
|
|
1520
|
-
case "register":
|
|
1521
|
-
setPage("sync");
|
|
1522
|
-
break;
|
|
1523
|
-
case "setup":
|
|
1524
|
-
setPage("setup");
|
|
1525
|
-
break;
|
|
1526
|
-
case "refresh":
|
|
1527
|
-
refreshAll();
|
|
1528
|
-
break;
|
|
1529
|
-
case "quit":
|
|
1530
|
-
handleQuit();
|
|
1531
|
-
break;
|
|
1532
|
-
}
|
|
1533
|
-
},
|
|
1534
|
-
[refreshModels, refreshSynced, refreshAll, handleQuit]
|
|
1535
|
-
);
|
|
1536
|
-
const subpageMenuItems = [
|
|
1537
|
-
{ id: "back", label: "Back", description: "Return to dashboard" }
|
|
1538
|
-
];
|
|
1539
|
-
const handleSubpageNavigate = useCallback10(
|
|
1540
|
-
(id) => {
|
|
1541
|
-
if (id === "back") {
|
|
1542
|
-
setPage("dashboard");
|
|
1543
|
-
} else {
|
|
1544
|
-
handleNavigate(id);
|
|
1545
|
-
}
|
|
1546
|
-
},
|
|
1547
|
-
[handleNavigate]
|
|
1548
|
-
);
|
|
1549
|
-
const termHeight = (stdout?.rows ?? 24) - 4;
|
|
1550
|
-
return /* @__PURE__ */ jsx9(Box8, { flexDirection: "column", height: termHeight, overflow: "hidden", children: page === "onboarding" ? /* @__PURE__ */ jsx9(OnboardingPage, { onComplete: handleOnboardingComplete }) : /* @__PURE__ */ jsxs8(Fragment4, { children: [
|
|
1551
|
-
/* @__PURE__ */ jsx9(
|
|
1552
|
-
Header,
|
|
1553
|
-
{
|
|
1554
|
-
connection: connectionStatus,
|
|
1555
|
-
environment,
|
|
1556
|
-
configPath: getConfigPath(),
|
|
1557
|
-
connectionError
|
|
1558
|
-
}
|
|
1559
|
-
),
|
|
1560
|
-
page === "dashboard" && /* @__PURE__ */ jsx9(
|
|
1561
|
-
DashboardPage,
|
|
1562
|
-
{
|
|
1563
|
-
requests,
|
|
1564
|
-
models,
|
|
1565
|
-
modelWarnings,
|
|
1566
|
-
syncedNames,
|
|
1567
|
-
modelsLoading,
|
|
1568
|
-
onNavigate: handleNavigate
|
|
1569
|
-
}
|
|
1570
|
-
),
|
|
1571
|
-
page === "setup" && /* @__PURE__ */ jsx9(SetupPage, { onBack: () => setPage("dashboard") }),
|
|
1572
|
-
page === "sync" && /* @__PURE__ */ jsx9(SyncPage, {}),
|
|
1573
|
-
page !== "dashboard" && page !== "setup" && /* @__PURE__ */ jsx9(Box8, { flexGrow: 1 }),
|
|
1574
|
-
page !== "dashboard" && page !== "setup" && /* @__PURE__ */ jsx9(
|
|
1575
|
-
NavigationMenu,
|
|
1576
|
-
{
|
|
1577
|
-
items: subpageMenuItems,
|
|
1578
|
-
onSelect: handleSubpageNavigate
|
|
1579
|
-
}
|
|
1580
|
-
)
|
|
1581
|
-
] }) });
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
// src/update.ts
|
|
1585
|
-
import { createRequire as createRequire2 } from "module";
|
|
1586
|
-
var require3 = createRequire2(import.meta.url);
|
|
1587
|
-
var pkg2 = require3("../package.json");
|
|
1588
|
-
function getCurrentVersion() {
|
|
1589
|
-
return pkg2.version;
|
|
1590
|
-
}
|
|
1591
|
-
async function fetchLatestVersion() {
|
|
1592
|
-
try {
|
|
1593
|
-
const res = await fetch(
|
|
1594
|
-
"https://registry.npmjs.org/@mindstudio-ai/local-model-tunnel/latest",
|
|
1595
|
-
{ signal: AbortSignal.timeout(5e3) }
|
|
1596
|
-
);
|
|
1597
|
-
if (!res.ok) return null;
|
|
1598
|
-
const data = await res.json();
|
|
1599
|
-
return data.version ?? null;
|
|
1600
|
-
} catch {
|
|
1601
|
-
return null;
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
function isNewerVersion(current, latest) {
|
|
1605
|
-
const currentParts = current.split(".").map(Number);
|
|
1606
|
-
const latestParts = latest.split(".").map(Number);
|
|
1607
|
-
for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
|
|
1608
|
-
const c = currentParts[i] ?? 0;
|
|
1609
|
-
const l = latestParts[i] ?? 0;
|
|
1610
|
-
if (l > c) return true;
|
|
1611
|
-
if (l < c) return false;
|
|
1612
|
-
}
|
|
1613
|
-
return false;
|
|
1614
|
-
}
|
|
1615
|
-
async function checkForUpdate() {
|
|
1616
|
-
const currentVersion = getCurrentVersion();
|
|
1617
|
-
const latestVersion = await fetchLatestVersion();
|
|
1618
|
-
if (!latestVersion) return null;
|
|
1619
|
-
if (!isNewerVersion(currentVersion, latestVersion)) return null;
|
|
1620
|
-
return { currentVersion, latestVersion };
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
|
-
// src/tui/components/UpdatePrompt.tsx
|
|
1624
|
-
import { Box as Box9, Text as Text9, useInput as useInput4 } from "ink";
|
|
1625
|
-
import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1626
|
-
function UpdatePrompt({
|
|
1627
|
-
currentVersion,
|
|
1628
|
-
latestVersion,
|
|
1629
|
-
onChoice
|
|
1630
|
-
}) {
|
|
1631
|
-
useInput4((input) => {
|
|
1632
|
-
if (input.toLowerCase() === "y") {
|
|
1633
|
-
onChoice(true);
|
|
1634
|
-
} else {
|
|
1635
|
-
onChoice(false);
|
|
1636
|
-
}
|
|
1637
|
-
});
|
|
1638
|
-
return /* @__PURE__ */ jsxs9(Box9, { flexDirection: "column", paddingY: 1, paddingX: 2, children: [
|
|
1639
|
-
/* @__PURE__ */ jsxs9(Text9, { children: [
|
|
1640
|
-
/* @__PURE__ */ jsx10(Text9, { color: "yellow", bold: true, children: "Update available:" }),
|
|
1641
|
-
/* @__PURE__ */ jsxs9(Text9, { children: [
|
|
1642
|
-
" ",
|
|
1643
|
-
"v",
|
|
1644
|
-
currentVersion,
|
|
1645
|
-
" ",
|
|
1646
|
-
"\u2192",
|
|
1647
|
-
" v",
|
|
1648
|
-
latestVersion
|
|
1649
|
-
] })
|
|
1650
|
-
] }),
|
|
1651
|
-
/* @__PURE__ */ jsx10(Box9, { marginTop: 1, children: /* @__PURE__ */ jsxs9(Text9, { children: [
|
|
1652
|
-
"Press ",
|
|
1653
|
-
/* @__PURE__ */ jsx10(Text9, { bold: true, color: "cyan", children: "y" }),
|
|
1654
|
-
" to update, any other key to skip"
|
|
1655
|
-
] }) })
|
|
1656
|
-
] });
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
// src/tui/index.tsx
|
|
1660
|
-
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
1661
|
-
async function promptForUpdate(currentVersion, latestVersion) {
|
|
1662
|
-
return new Promise((resolve) => {
|
|
1663
|
-
const { unmount } = render(
|
|
1664
|
-
/* @__PURE__ */ jsx11(
|
|
1665
|
-
UpdatePrompt,
|
|
1666
|
-
{
|
|
1667
|
-
currentVersion,
|
|
1668
|
-
latestVersion,
|
|
1669
|
-
onChoice: (shouldUpdate) => {
|
|
1670
|
-
unmount();
|
|
1671
|
-
resolve(shouldUpdate);
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
),
|
|
1675
|
-
{ exitOnCtrlC: true }
|
|
1676
|
-
);
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
async function startTUI() {
|
|
1680
|
-
console.clear();
|
|
1681
|
-
const update = await checkForUpdate();
|
|
1682
|
-
if (update) {
|
|
1683
|
-
const shouldUpdate = await promptForUpdate(
|
|
1684
|
-
update.currentVersion,
|
|
1685
|
-
update.latestVersion
|
|
1686
|
-
);
|
|
1687
|
-
if (shouldUpdate) {
|
|
1688
|
-
console.log("\nUpdating to v" + update.latestVersion + "...\n");
|
|
1689
|
-
try {
|
|
1690
|
-
execSync("npm install -g @mindstudio-ai/local-model-tunnel@latest", {
|
|
1691
|
-
stdio: "inherit"
|
|
1692
|
-
});
|
|
1693
|
-
console.log("\nRestarting...\n");
|
|
1694
|
-
execFileSync(process.execPath, process.argv.slice(1), {
|
|
1695
|
-
stdio: "inherit"
|
|
1696
|
-
});
|
|
1697
|
-
} catch {
|
|
1698
|
-
console.error("\nUpdate failed. Continuing with current version.\n");
|
|
1699
|
-
}
|
|
1700
|
-
return;
|
|
1701
|
-
}
|
|
1702
|
-
console.clear();
|
|
1703
|
-
}
|
|
1704
|
-
const runner = new TunnelRunner();
|
|
1705
|
-
const { waitUntilExit } = render(
|
|
1706
|
-
/* @__PURE__ */ jsx11(App, { runner }),
|
|
1707
|
-
{
|
|
1708
|
-
exitOnCtrlC: true
|
|
1709
|
-
}
|
|
1710
|
-
);
|
|
1711
|
-
await waitUntilExit();
|
|
1712
|
-
runner.stop();
|
|
1713
|
-
}
|
|
1714
|
-
export {
|
|
1715
|
-
startTUI
|
|
1716
|
-
};
|
|
1717
|
-
//# sourceMappingURL=tui-KQ4LWB4E.js.map
|