@simplexai/localmodels-darwin-arm64 0.1.0-dev.47 → 0.1.0-dev.49
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/bootstrap.identity +1 -1
- package/bootstrap.sha256 +55 -51
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/budget.py +40 -14
- package/modules/localmodels/catalog.json +57 -34
- package/modules/localmodels/debug_mode.py +25 -0
- package/modules/localmodels/deploy.py +3 -0
- package/modules/localmodels/engines-b12588-mix-c0c3de8.json +13 -1
- package/modules/localmodels/engines.py +31 -6
- package/modules/localmodels/library_jobs.py +22 -1
- package/modules/localmodels/library_model.py +38 -2
- package/modules/localmodels/library_pricing.py +261 -78
- package/modules/localmodels/library_serve.py +20 -4
- package/modules/localmodels/library_status.py +19 -11
- package/modules/localmodels/library_vram.py +123 -0
- package/modules/localmodels/llm_rank.py +28 -1
- package/modules/localmodels/probe.py +39 -37
- package/modules/localmodels/process_identity.py +26 -33
- package/modules/localmodels/process_identity_darwin.py +189 -0
- package/modules/localmodels/process_identity_linux.py +62 -30
- package/modules/localmodels/recommend.py +3 -1
- package/modules/localmodels/remote_ops_service.py +15 -46
- package/modules/localmodels/service_probe.py +1 -1
- package/modules/localmodels/setup_inspection.py +14 -1
- package/modules/localmodels/setup_text.py +15 -3
- package/modules/localmodels/setup_upgrade.py +145 -0
- package/modules/localmodels/stack_binding.py +59 -12
- package/modules/localmodels/stack_compose.py +5 -1
- package/modules/localmodels/stack_hardware.py +5 -2
- package/modules/localmodels/stack_route.py +5 -1
- package/modules/localmodels/stack_suite.py +1 -1
- package/modules/localmodels/stack_view_access.py +238 -58
- package/modules/localmodels/stack_view_hub.py +12 -7
- package/modules/localmodels/stack_view_serve.py +13 -6
- package/modules/localmodels/transport.py +3 -1
- package/modules/localmodels/tui.py +4 -1
- package/modules/localmodels/tui_dialogs.py +42 -9
- package/modules/localmodels/tui_modals.py +63 -16
- package/modules/localmodels/tui_screen.py +80 -53
- package/modules/localmodels/tui_views.py +36 -6
- package/modules/localmodels/web/index.html +996 -300
- package/modules/localmodels/web/sizecalc/app.js +616 -88
- package/modules/localmodels/web/sizecalc/page.html +239 -106
- package/modules/localmodels/web/view/fleet.js +25 -2
- package/modules/localmodels/web/view/nav.js +19 -3
- package/modules/localmodels/web/view/view.css +110 -22
- package/modules/localmodels/web/view/view.js +40 -22
- package/modules/localmodels/win_probe.py +187 -0
- package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/RECORD +52 -48
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -27,7 +27,7 @@ _SPECIAL = {
|
|
|
27
27
|
curses.KEY_END: "end",
|
|
28
28
|
curses.KEY_ENTER: "enter",
|
|
29
29
|
curses.KEY_BACKSPACE: "backspace",
|
|
30
|
-
curses.KEY_DC: "
|
|
30
|
+
curses.KEY_DC: "delete",
|
|
31
31
|
curses.KEY_BTAB: "btab",
|
|
32
32
|
curses.KEY_RESIZE: "resize",
|
|
33
33
|
}
|
|
@@ -38,6 +38,9 @@ _CONTROL = {
|
|
|
38
38
|
"\x1b": "esc",
|
|
39
39
|
"\x7f": "backspace",
|
|
40
40
|
"\b": "backspace",
|
|
41
|
+
"\x01": "ctrl+a",
|
|
42
|
+
"\x05": "ctrl+e",
|
|
43
|
+
"\x15": "ctrl+u",
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
|
|
@@ -8,13 +8,8 @@ from pathlib import Path
|
|
|
8
8
|
|
|
9
9
|
from localmodels import approval, deploy, discovery, hosts, stack, tui_views
|
|
10
10
|
from localmodels.records import FinishedRecord, Plan
|
|
11
|
-
from localmodels.tui_modals import CODE_CHARS,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def help_modal(pages: list[Line]) -> Confirm:
|
|
15
|
-
return Confirm(
|
|
16
|
-
"按键说明", HELP + pages, accept=lambda: None, hint="Enter/Esc 关闭", cancel_note=""
|
|
17
|
-
)
|
|
11
|
+
from localmodels.tui_modals import CODE_CHARS, Confirm, Field, Form, Picker, pad
|
|
12
|
+
from localmodels.tui_modals import help_modal as help_modal
|
|
18
13
|
|
|
19
14
|
|
|
20
15
|
def add_device_modal(
|
|
@@ -35,6 +30,23 @@ def add_device_modal(
|
|
|
35
30
|
)
|
|
36
31
|
|
|
37
32
|
|
|
33
|
+
def parse_device_form(values: dict[str, str | bool]) -> tuple[str, str | None, int | None]:
|
|
34
|
+
target, label, port = (str(values[k]).strip() for k in ("target", "label", "port"))
|
|
35
|
+
if not target:
|
|
36
|
+
raise ValueError("需要 SSH 目标")
|
|
37
|
+
if port and not port.isdigit():
|
|
38
|
+
raise ValueError(f"端口必须是数字:{port}")
|
|
39
|
+
return target, label or None, int(port) if port else None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def remove_device_modal(dev_id: str, accept: Callable[[], None]) -> Confirm:
|
|
43
|
+
return Confirm(
|
|
44
|
+
f"移除设备 {dev_id}?",
|
|
45
|
+
[("只删除登记,不连接主机,不停止它上面的服务。", "text")],
|
|
46
|
+
accept,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
38
50
|
def discover_picker(found: list[discovery.Candidate], choose: Callable[[int], None]) -> Picker:
|
|
39
51
|
rows = [
|
|
40
52
|
f"{pad(c.label, 32)}{pad(f'{c.address}:{c.port}', 24)}"
|
|
@@ -64,6 +76,20 @@ def plan_modal(
|
|
|
64
76
|
)
|
|
65
77
|
|
|
66
78
|
|
|
79
|
+
def parse_plan_options(values: dict[str, str | bool]) -> deploy.PlanOptions:
|
|
80
|
+
text = {k: str(v).strip() for k, v in values.items()}
|
|
81
|
+
if not text["port"].isdigit():
|
|
82
|
+
raise ValueError(f"端口必须是数字:{text['port']}")
|
|
83
|
+
return deploy.PlanOptions(
|
|
84
|
+
model_id=text["model_id"],
|
|
85
|
+
placement_id=text["placement_id"] or "auto",
|
|
86
|
+
port=int(text["port"]),
|
|
87
|
+
bind=text["bind"] or "127.0.0.1",
|
|
88
|
+
hf_download_endpoint=text["hf_download_endpoint"] or deploy.HF_API,
|
|
89
|
+
engine_path=text["engine_path"] or None,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
67
93
|
def deploy_confirm_modal(
|
|
68
94
|
device: str,
|
|
69
95
|
plan: Plan,
|
|
@@ -88,10 +114,17 @@ def remove_service_modal(record: FinishedRecord, accept: Callable[[], None]) ->
|
|
|
88
114
|
)
|
|
89
115
|
|
|
90
116
|
|
|
91
|
-
def stack_form_modal(
|
|
117
|
+
def stack_form_modal(
|
|
118
|
+
submit: Callable[[dict[str, str | bool]], None],
|
|
119
|
+
current: tuple[Path, stack.StackPlan] | stack.StackPlan | None = None,
|
|
120
|
+
) -> Form:
|
|
121
|
+
options = stack.default_options()
|
|
122
|
+
plan = current[1] if isinstance(current, tuple) else current
|
|
123
|
+
if plan is not None:
|
|
124
|
+
options.update(plan["options"])
|
|
92
125
|
return Form(
|
|
93
126
|
"生成本机 Agent 套件计划",
|
|
94
|
-
tui_views.stack_form_fields(
|
|
127
|
+
tui_views.stack_form_fields(options),
|
|
95
128
|
submit,
|
|
96
129
|
note="只读:探测本机并保存计划文件;与 stack plan 相同。套件只针对本机。",
|
|
97
130
|
)
|
|
@@ -8,7 +8,7 @@ from __future__ import annotations
|
|
|
8
8
|
|
|
9
9
|
import re
|
|
10
10
|
from collections.abc import Callable
|
|
11
|
-
from dataclasses import dataclass
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
12
|
from typing import Literal
|
|
13
13
|
|
|
14
14
|
from localmodels import console
|
|
@@ -83,26 +83,61 @@ class Form:
|
|
|
83
83
|
note: str = ""
|
|
84
84
|
index: int = 0
|
|
85
85
|
scroll: int = 0
|
|
86
|
+
error: str = ""
|
|
87
|
+
cursors: dict[int, int] = field(default_factory=dict)
|
|
88
|
+
|
|
89
|
+
def cursor_pos(self, index: int | None = None) -> int:
|
|
90
|
+
idx = self.index if index is None else index
|
|
91
|
+
val = self.fields[idx].value
|
|
92
|
+
if isinstance(val, bool):
|
|
93
|
+
return 0
|
|
94
|
+
return max(0, min(self.cursors.get(idx, len(val)), len(val)))
|
|
95
|
+
|
|
96
|
+
def _edit_text(self, current: Field, key: str) -> None:
|
|
97
|
+
if isinstance(current.value, bool):
|
|
98
|
+
return
|
|
99
|
+
text = current.value
|
|
100
|
+
pos = self.cursor_pos()
|
|
101
|
+
if key == "left":
|
|
102
|
+
pos = max(0, pos - 1)
|
|
103
|
+
elif key == "right":
|
|
104
|
+
pos = min(len(text), pos + 1)
|
|
105
|
+
elif key in ("home", "ctrl+a", "\x01"):
|
|
106
|
+
pos = 0
|
|
107
|
+
elif key in ("end", "ctrl+e", "\x05"):
|
|
108
|
+
pos = len(text)
|
|
109
|
+
elif key in ("ctrl+u", "\x15"):
|
|
110
|
+
current.value, pos = "", 0
|
|
111
|
+
elif key == "backspace":
|
|
112
|
+
if pos > 0:
|
|
113
|
+
current.value = text[: pos - 1] + text[pos:]
|
|
114
|
+
pos -= 1
|
|
115
|
+
elif key == "delete":
|
|
116
|
+
if pos < len(text):
|
|
117
|
+
current.value = text[:pos] + text[pos + 1 :]
|
|
118
|
+
elif len(key) == 1 and key.isprintable():
|
|
119
|
+
current.value = text[:pos] + key + text[pos:]
|
|
120
|
+
pos += 1
|
|
121
|
+
self.cursors[self.index] = pos
|
|
86
122
|
|
|
87
123
|
def key(self, key: str) -> Outcome:
|
|
88
124
|
current = self.fields[self.index]
|
|
125
|
+
if key == "enter":
|
|
126
|
+
return "finish"
|
|
127
|
+
self.error = ""
|
|
89
128
|
if key in ("up", "down", "tab", "btab"):
|
|
90
129
|
step = 1 if key in ("down", "tab") else -1
|
|
91
130
|
self.index = (self.index + step) % len(self.fields)
|
|
92
131
|
elif key in ("pgup", "pgdn"):
|
|
93
132
|
step = -5 if key == "pgup" else 5
|
|
94
133
|
self.index = max(0, min(len(self.fields) - 1, self.index + step))
|
|
95
|
-
elif key in ("home", "end"):
|
|
96
|
-
self.index = 0 if key == "home" else len(self.fields) - 1
|
|
97
|
-
elif key == "enter":
|
|
98
|
-
return "finish"
|
|
99
134
|
elif isinstance(current.value, bool):
|
|
100
135
|
if key == " ":
|
|
101
136
|
current.value = not current.value
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
current
|
|
137
|
+
elif key in ("home", "end"):
|
|
138
|
+
self.index = 0 if key == "home" else len(self.fields) - 1
|
|
139
|
+
else:
|
|
140
|
+
self._edit_text(current, key)
|
|
106
141
|
return "open"
|
|
107
142
|
|
|
108
143
|
def finish(self) -> None:
|
|
@@ -130,7 +165,9 @@ class Confirm:
|
|
|
130
165
|
return "finish" if key in ("y", "enter") else "close" if key == "n" else "open"
|
|
131
166
|
if key == "enter":
|
|
132
167
|
return "finish" if self.typed.strip() == self.code else "mismatch"
|
|
133
|
-
if key
|
|
168
|
+
if key in ("ctrl+u", "\x15"):
|
|
169
|
+
self.typed = ""
|
|
170
|
+
elif key == "backspace":
|
|
134
171
|
self.typed = self.typed[:-1]
|
|
135
172
|
elif len(key) == 1:
|
|
136
173
|
self.typed += key
|
|
@@ -162,8 +199,11 @@ class Picker:
|
|
|
162
199
|
Modal = Form | Confirm | Picker
|
|
163
200
|
|
|
164
201
|
HELP: list[Line] = [
|
|
165
|
-
("1-7 / Tab 切换页面;↑↓ / j k / PgUp PgDn 选择或滚动;? 帮助;q 退出", "text"),
|
|
166
|
-
(
|
|
202
|
+
("1-7 / ←→ / Tab 切换页面;↑↓ / j k / PgUp PgDn 选择或滚动;? 帮助;q 退出", "text"),
|
|
203
|
+
(
|
|
204
|
+
"对话框:Enter 确认或提交,Esc 取消;表单中 ↑↓ 切换字段,←→/Home/End 移动光标,空格切换开关,Ctrl+U 清空",
|
|
205
|
+
"text",
|
|
206
|
+
),
|
|
167
207
|
("", "text"),
|
|
168
208
|
("只读:探测、推荐、生成计划。会改动主机的操作都要先确认:", "text"),
|
|
169
209
|
(" 部署:输入 yes(所选 GPU 已被占用时输入 share);执行前重新探测核对计划", "dim"),
|
|
@@ -225,15 +265,22 @@ def modal_lines(modal: Modal | None, cols: int, height: int | None = None) -> li
|
|
|
225
265
|
head: list[Line] = [(modal.title, "title")]
|
|
226
266
|
if modal.note:
|
|
227
267
|
head += [(part, "dim") for part in wrap(modal.note, cols)]
|
|
268
|
+
if modal.error:
|
|
269
|
+
head += [(part, "error") for part in wrap(f"输入有误:{modal.error}", cols)]
|
|
228
270
|
head.append(("", "text"))
|
|
229
271
|
labels = max(width(f.label) for f in modal.fields) + 2 # every label whole
|
|
230
272
|
rows: list[Line] = []
|
|
231
273
|
for i, f in enumerate(modal.fields):
|
|
232
|
-
|
|
233
|
-
|
|
274
|
+
if isinstance(f.value, bool):
|
|
275
|
+
shown = "[x]" if f.value else "[ ]"
|
|
276
|
+
elif i == modal.index:
|
|
277
|
+
pos = modal.cursor_pos(i)
|
|
278
|
+
shown = f"{f.value[:pos]}▏{f.value[pos:]}"
|
|
279
|
+
else:
|
|
280
|
+
shown = f.value
|
|
234
281
|
rows.append(
|
|
235
282
|
(
|
|
236
|
-
f" {pad(f.label, labels)}{
|
|
283
|
+
f" {pad(f.label, labels)}{shown}",
|
|
237
284
|
"select" if i == modal.index else "text",
|
|
238
285
|
)
|
|
239
286
|
)
|
|
@@ -273,7 +320,7 @@ def modal_lines(modal: Modal | None, cols: int, height: int | None = None) -> li
|
|
|
273
320
|
def modal_keys(modal: Modal) -> str:
|
|
274
321
|
"""The open dialog's keys, shown once in the footer."""
|
|
275
322
|
if isinstance(modal, Form):
|
|
276
|
-
return "↑↓ 切换字段 空格 切换开关 Enter 提交 Esc 取消"
|
|
323
|
+
return "↑↓ 切换字段 ←→ 移动光标 空格 切换开关 Ctrl+U 清空 Enter 提交 Esc 取消"
|
|
277
324
|
if isinstance(modal, Confirm):
|
|
278
325
|
return modal.hint if modal.code is None else f"输入 {modal.code} 后 Enter 确认 Esc 取消"
|
|
279
326
|
return "↑↓ 选择 Enter 打开 Esc 取消"
|
|
@@ -28,12 +28,11 @@ from localmodels import (
|
|
|
28
28
|
tui_dialogs,
|
|
29
29
|
tui_views,
|
|
30
30
|
)
|
|
31
|
-
from localmodels.budget import gib
|
|
32
31
|
from localmodels.probe import HostFacts
|
|
33
32
|
from localmodels.recommend import CatalogRow, HostCatalog
|
|
34
33
|
from localmodels.records import Device, FinishedRecord, Plan, ProgressEvent
|
|
35
34
|
from localmodels.tui_modals import (
|
|
36
|
-
|
|
35
|
+
Form,
|
|
37
36
|
Line,
|
|
38
37
|
Modal,
|
|
39
38
|
Picker,
|
|
@@ -53,6 +52,7 @@ from localmodels.tui_views import (
|
|
|
53
52
|
model_detail,
|
|
54
53
|
models_view,
|
|
55
54
|
plan_view,
|
|
55
|
+
progress_text,
|
|
56
56
|
services_view,
|
|
57
57
|
stack_view,
|
|
58
58
|
text_window,
|
|
@@ -102,8 +102,10 @@ class Tui:
|
|
|
102
102
|
self.modal: Modal | None = None
|
|
103
103
|
self.status: Line = ("", "dim")
|
|
104
104
|
self.busy: str | None = None
|
|
105
|
+
self._job_gen = 0
|
|
105
106
|
self.quit = False
|
|
106
107
|
self._quit_armed = False
|
|
108
|
+
self._page_step = 10
|
|
107
109
|
|
|
108
110
|
# -- state -------------------------------------------------------------------------------
|
|
109
111
|
|
|
@@ -115,6 +117,8 @@ class Tui:
|
|
|
115
117
|
self.devices = hosts.devices()
|
|
116
118
|
|
|
117
119
|
def _select(self, dev_id: str) -> None:
|
|
120
|
+
if dev_id != self.device:
|
|
121
|
+
self.model_query = ""
|
|
118
122
|
self.device = dev_id
|
|
119
123
|
self.facts = hosts.load_facts(dev_id)
|
|
120
124
|
self.catalog = None
|
|
@@ -143,10 +147,8 @@ class Tui:
|
|
|
143
147
|
|
|
144
148
|
def _event(self, step: str, event: ProgressEvent) -> None:
|
|
145
149
|
if event.get("event") == "progress":
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
rate = f" {gib(event['bytes_per_s'])}/s" if event.get("bytes_per_s") else ""
|
|
149
|
-
self.progress = f"[{step}] {event.get('file', '')}{share}{rate}"
|
|
150
|
+
if self.busy is not None:
|
|
151
|
+
self.progress = progress_text(step, event)
|
|
150
152
|
return
|
|
151
153
|
self._log(f"[{step}] {event_text(event)}")
|
|
152
154
|
|
|
@@ -170,6 +172,8 @@ class Tui:
|
|
|
170
172
|
if self.busy:
|
|
171
173
|
self.flash(f"「{self.busy}」进行中,请等它结束", "warn")
|
|
172
174
|
return
|
|
175
|
+
self._job_gen += 1
|
|
176
|
+
gen = self._job_gen
|
|
173
177
|
self.busy, self.progress = label, ""
|
|
174
178
|
self._log(f"▶ {label}")
|
|
175
179
|
self.flash(f"{label}…", "dim")
|
|
@@ -178,22 +182,37 @@ class Tui:
|
|
|
178
182
|
try:
|
|
179
183
|
result = work()
|
|
180
184
|
except Exception as exc: # shown to the operator; the UI keeps running
|
|
181
|
-
self.inbox.put(functools.partial(self._failed, label, exc, failed))
|
|
185
|
+
self.inbox.put(functools.partial(self._failed, gen, label, exc, failed))
|
|
182
186
|
else:
|
|
183
|
-
self.inbox.put(functools.partial(self._finished, done, result))
|
|
187
|
+
self.inbox.put(functools.partial(self._finished, gen, done, result))
|
|
184
188
|
|
|
185
189
|
self.spawn(body)
|
|
186
190
|
|
|
187
|
-
def _finished(self, done: Callable[[T], None], result: T) -> None:
|
|
191
|
+
def _finished(self, gen: int, done: Callable[[T], None], result: T) -> None:
|
|
192
|
+
if gen != self._job_gen:
|
|
193
|
+
return
|
|
188
194
|
self.busy, self.progress = None, ""
|
|
189
195
|
done(result)
|
|
190
196
|
|
|
191
|
-
def _failed(
|
|
197
|
+
def _failed(
|
|
198
|
+
self, gen: int, label: str, exc: Exception, failed: Callable[[Exception], bool]
|
|
199
|
+
) -> None:
|
|
200
|
+
if gen != self._job_gen:
|
|
201
|
+
return
|
|
192
202
|
self.busy, self.progress = None, ""
|
|
193
203
|
self._log(f"✗ {label}:{error_text(exc)}")
|
|
194
204
|
if not failed(exc):
|
|
195
205
|
self.flash(f"{label}失败:{error_text(exc)}", "error")
|
|
196
206
|
|
|
207
|
+
def _cancel_task(self) -> None:
|
|
208
|
+
if not self.busy:
|
|
209
|
+
return
|
|
210
|
+
label = self.busy
|
|
211
|
+
self._job_gen += 1
|
|
212
|
+
self.busy, self.progress, self._quit_armed = None, "", False
|
|
213
|
+
self._log(f"⊘ 已请求取消任务:{label}")
|
|
214
|
+
self.flash("已请求取消任务", "warn")
|
|
215
|
+
|
|
197
216
|
# -- keys --------------------------------------------------------------------------------
|
|
198
217
|
|
|
199
218
|
def handle(self, key: str) -> None:
|
|
@@ -214,8 +233,8 @@ class Tui:
|
|
|
214
233
|
self._help()
|
|
215
234
|
elif len(key) == 1 and key.isdigit() and 1 <= int(key) <= len(TABS):
|
|
216
235
|
self._switch(int(key) - 1)
|
|
217
|
-
elif key in ("tab", "btab"):
|
|
218
|
-
self._switch((self.tab + (1 if key
|
|
236
|
+
elif key in ("tab", "btab", "right", "left"):
|
|
237
|
+
self._switch((self.tab + (1 if key in ("tab", "right") else -1)) % len(TABS))
|
|
219
238
|
elif nav in ("up", "down", "pgup", "pgdn", "home", "end"):
|
|
220
239
|
self._move(nav)
|
|
221
240
|
elif key in (actions := self._actions()):
|
|
@@ -254,7 +273,15 @@ class Tui:
|
|
|
254
273
|
self.quit = True
|
|
255
274
|
|
|
256
275
|
def _move(self, key: str) -> None:
|
|
257
|
-
|
|
276
|
+
page = self._page_step
|
|
277
|
+
step = {
|
|
278
|
+
"up": -1,
|
|
279
|
+
"down": 1,
|
|
280
|
+
"pgup": -page,
|
|
281
|
+
"pgdn": page,
|
|
282
|
+
"home": -(1 << 30),
|
|
283
|
+
"end": 1 << 30,
|
|
284
|
+
}
|
|
258
285
|
delta = step[key] if self.tab != TASK else -step[key]
|
|
259
286
|
cursor = max(0, self.cursor[self.tab] + delta)
|
|
260
287
|
if self.tab in LIST_TABS:
|
|
@@ -314,18 +341,23 @@ class Tui:
|
|
|
314
341
|
("r", ("刷新计划", lambda: self._load_stack(force=True), has_stack)),
|
|
315
342
|
("A", ("确认并执行", self._confirm_stack, has_stack)),
|
|
316
343
|
],
|
|
317
|
-
TASK: [
|
|
344
|
+
TASK: [
|
|
345
|
+
(
|
|
346
|
+
"c",
|
|
347
|
+
("取消任务", self._cancel_task, True)
|
|
348
|
+
if self.busy
|
|
349
|
+
else ("清空日志", self._clear_log, bool(self.log)),
|
|
350
|
+
)
|
|
351
|
+
],
|
|
318
352
|
}
|
|
319
353
|
return dict(by_tab[tab])
|
|
320
354
|
|
|
321
355
|
def _help(self) -> None:
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
pages.append((f" {tab + 1} {name} {keys}", "text"))
|
|
328
|
-
self.modal = tui_dialogs.help_modal(pages)
|
|
356
|
+
tab_actions = [
|
|
357
|
+
(name, [(k, label) for k, (label, _, _) in self._actions(tab).items()])
|
|
358
|
+
for tab, name in enumerate(TABS)
|
|
359
|
+
]
|
|
360
|
+
self.modal = tui_dialogs.help_modal(tab_actions)
|
|
329
361
|
|
|
330
362
|
def _modal_key(self, key: str) -> None:
|
|
331
363
|
modal = self.modal
|
|
@@ -334,11 +366,28 @@ class Tui:
|
|
|
334
366
|
outcome = "close" if key == "esc" else modal.key(key)
|
|
335
367
|
if outcome == "mismatch":
|
|
336
368
|
self.flash(f"输入与 {getattr(modal, 'code', '')} 不一致,未执行", "warn")
|
|
369
|
+
elif outcome == "finish":
|
|
370
|
+
try:
|
|
371
|
+
modal.finish()
|
|
372
|
+
except ValueError as exc:
|
|
373
|
+
msg = error_text(exc)
|
|
374
|
+
if isinstance(modal, Form):
|
|
375
|
+
modal.error = msg
|
|
376
|
+
self.flash(msg, "warn")
|
|
377
|
+
else:
|
|
378
|
+
if self.modal is modal:
|
|
379
|
+
self.modal = None
|
|
380
|
+
self.flash(msg, "error")
|
|
381
|
+
except (OSError, KeyError, TypeError) as exc:
|
|
382
|
+
if self.modal is modal:
|
|
383
|
+
self.modal = None
|
|
384
|
+
self.flash(error_text(exc), "error")
|
|
385
|
+
else:
|
|
386
|
+
if self.modal is modal:
|
|
387
|
+
self.modal = None
|
|
337
388
|
elif outcome != "open":
|
|
338
389
|
self.modal = None
|
|
339
|
-
if
|
|
340
|
-
self._guarded(modal.finish)
|
|
341
|
-
elif key == "esc":
|
|
390
|
+
if key == "esc":
|
|
342
391
|
self.flash(getattr(modal, "cancel_note", "已取消"), "dim")
|
|
343
392
|
|
|
344
393
|
# -- devices and facts --------------------------------------------------------------------
|
|
@@ -377,13 +426,7 @@ class Tui:
|
|
|
377
426
|
self.modal = tui_dialogs.add_device_modal(self._add_device, target, label, port)
|
|
378
427
|
|
|
379
428
|
def _add_device(self, values: dict[str, str | bool]) -> None:
|
|
380
|
-
target, label, port = (
|
|
381
|
-
if not target:
|
|
382
|
-
self.flash("需要 SSH 目标", "warn")
|
|
383
|
-
return
|
|
384
|
-
if port and not port.isdigit():
|
|
385
|
-
self.flash(f"端口必须是数字:{port}", "warn")
|
|
386
|
-
return
|
|
429
|
+
target, label, port = tui_dialogs.parse_device_form(values)
|
|
387
430
|
|
|
388
431
|
def done(added: tuple[Device, HostFacts]) -> None:
|
|
389
432
|
self._reload_devices()
|
|
@@ -392,7 +435,7 @@ class Tui:
|
|
|
392
435
|
|
|
393
436
|
self._run(
|
|
394
437
|
f"添加并探测 {target}",
|
|
395
|
-
lambda: app.register_device(target, label
|
|
438
|
+
lambda: app.register_device(target, label, port),
|
|
396
439
|
done,
|
|
397
440
|
)
|
|
398
441
|
|
|
@@ -427,11 +470,7 @@ class Tui:
|
|
|
427
470
|
self.cursor[DEVICES] = 0
|
|
428
471
|
self.flash(f"已移除 {dev['id']};缓存事实与部署记录仍在 {hosts.state_dir()}", "ok")
|
|
429
472
|
|
|
430
|
-
self.modal =
|
|
431
|
-
f"移除设备 {dev['id']}?",
|
|
432
|
-
[("只删除登记,不连接主机,不停止它上面的服务。", "text")],
|
|
433
|
-
remove,
|
|
434
|
-
)
|
|
473
|
+
self.modal = tui_dialogs.remove_device_modal(dev["id"], remove)
|
|
435
474
|
|
|
436
475
|
# -- recommendation, plan and deployment ----------------------------------------------------
|
|
437
476
|
|
|
@@ -463,19 +502,7 @@ class Tui:
|
|
|
463
502
|
self.modal = tui_dialogs.plan_modal(self.device, dict(row), self._plan)
|
|
464
503
|
|
|
465
504
|
def _plan(self, values: dict[str, str | bool]) -> None:
|
|
466
|
-
|
|
467
|
-
if not text["port"].isdigit():
|
|
468
|
-
self.flash(f"端口必须是数字:{text['port']}", "warn")
|
|
469
|
-
return
|
|
470
|
-
options = deploy.PlanOptions(
|
|
471
|
-
model_id=text["model_id"],
|
|
472
|
-
placement_id=text["placement_id"] or "auto",
|
|
473
|
-
port=int(text["port"]),
|
|
474
|
-
bind=text["bind"] or "127.0.0.1",
|
|
475
|
-
hf_download_endpoint=text["hf_download_endpoint"] or deploy.HF_API,
|
|
476
|
-
engine_path=text["engine_path"] or None,
|
|
477
|
-
)
|
|
478
|
-
self._build_plan(self.device, options)
|
|
505
|
+
self._build_plan(self.device, tui_dialogs.parse_plan_options(values))
|
|
479
506
|
|
|
480
507
|
def _build_plan(self, dev_id: str, options: deploy.PlanOptions) -> None:
|
|
481
508
|
def build() -> Plan:
|
|
@@ -572,7 +599,7 @@ class Tui:
|
|
|
572
599
|
# -- stack -------------------------------------------------------------------------------
|
|
573
600
|
|
|
574
601
|
def _stack_form(self) -> None:
|
|
575
|
-
self.modal = tui_dialogs.stack_form_modal(self._stack_plan)
|
|
602
|
+
self.modal = tui_dialogs.stack_form_modal(self._stack_plan, self.stack_plan)
|
|
576
603
|
|
|
577
604
|
def _build_stack(self, label: str, options: stack.StackOptions) -> None:
|
|
578
605
|
def build() -> tuple[Path, stack.StackPlan]:
|
|
@@ -598,8 +625,7 @@ class Tui:
|
|
|
598
625
|
def _stack_plan(self, values: dict[str, str | bool]) -> None:
|
|
599
626
|
options, error = tui_dialogs.parse_stack_options(values)
|
|
600
627
|
if error or options is None:
|
|
601
|
-
|
|
602
|
-
return
|
|
628
|
+
raise ValueError(error or "选项无效")
|
|
603
629
|
self._build_stack("生成套件计划", options)
|
|
604
630
|
|
|
605
631
|
def _show_stack_plan(self, saved: tuple[Path, stack.StackPlan]) -> None:
|
|
@@ -665,6 +691,7 @@ class Tui:
|
|
|
665
691
|
shown = [(k, label) for k, (label, _, offered) in self._actions().items() if offered]
|
|
666
692
|
keys = footer_keys(shown)
|
|
667
693
|
height = max(0, rows - 5)
|
|
694
|
+
self._page_step = max(1, height - 2)
|
|
668
695
|
body = (
|
|
669
696
|
modal_lines(self.modal, cols, height)
|
|
670
697
|
if self.modal is not None
|
|
@@ -45,6 +45,13 @@ def event_text(event: ProgressEvent) -> str:
|
|
|
45
45
|
return event.get("message") or json.dumps(event, ensure_ascii=False)
|
|
46
46
|
|
|
47
47
|
|
|
48
|
+
def progress_text(step: str, event: ProgressEvent) -> str:
|
|
49
|
+
done, total = event.get("done", 0), event.get("total")
|
|
50
|
+
share = f" {done * 100 // total}%" if total else ""
|
|
51
|
+
rate = f" {gib(event['bytes_per_s'])}/s" if event.get("bytes_per_s") else ""
|
|
52
|
+
return f"[{step}] {event.get('file', '')}{share}{rate}"
|
|
53
|
+
|
|
54
|
+
|
|
48
55
|
def footer_keys(shown: list[tuple[str, str]]) -> str:
|
|
49
56
|
"""The footer's keys: the page's offered actions, then help and quit."""
|
|
50
57
|
keys = " ".join(f"{key_label(k)} {label}" for k, label in shown)
|
|
@@ -121,12 +128,35 @@ def text_window(
|
|
|
121
128
|
lines: list[Line], offset: int, from_bottom: bool, cols: int, height: int
|
|
122
129
|
) -> tuple[list[Line], int]:
|
|
123
130
|
"""A text page in ``height`` rows, scrolled ``offset`` rows from the top (or, for a log,
|
|
124
|
-
from the bottom); returns the rows and the offset clamped to the text
|
|
131
|
+
from the bottom); returns the rows and the offset clamped to the text, with a scroll
|
|
132
|
+
position indicator on the last row when lines lie off-screen."""
|
|
133
|
+
if height <= 0:
|
|
134
|
+
return [], 0
|
|
125
135
|
wrapped = [(part, style) for text, style in lines for part in wrap(text, cols)]
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
total = len(wrapped)
|
|
137
|
+
if total <= height:
|
|
138
|
+
return wrapped, 0
|
|
139
|
+
if height == 1:
|
|
140
|
+
last = total - 1
|
|
141
|
+
offset = max(0, min(offset, last))
|
|
142
|
+
start = last - offset if from_bottom else offset
|
|
143
|
+
return wrapped[start : start + 1], offset
|
|
144
|
+
visible = height - 1
|
|
145
|
+
last = max(0, total - visible)
|
|
146
|
+
offset = max(0, min(offset, last))
|
|
128
147
|
start = last - offset if from_bottom else offset
|
|
129
|
-
|
|
148
|
+
shown = wrapped[start : start + visible]
|
|
149
|
+
arrows = ("▲" if start > 0 else "") + ("▼" if start + visible < total else "")
|
|
150
|
+
if start == 0:
|
|
151
|
+
pct = 0
|
|
152
|
+
elif start >= last:
|
|
153
|
+
pct = 100
|
|
154
|
+
else:
|
|
155
|
+
pct = max(1, min(99, round(start * 100 / last)))
|
|
156
|
+
indicator = clip(
|
|
157
|
+
f"{arrows} 第 {start + 1}-{start + len(shown)}/{total} 行 [{pct}% · ↑/↓ 滚动]", cols
|
|
158
|
+
)
|
|
159
|
+
return [*shown, (indicator, "dim")], offset
|
|
130
160
|
|
|
131
161
|
|
|
132
162
|
def deploy_confirm_body(plan: Plan, device: str, busy: list[str]) -> list[Line]:
|
|
@@ -184,12 +214,12 @@ def stack_form_fields(o: stack.StackOptions) -> list[Field]:
|
|
|
184
214
|
Field("decision_port", "决策模型端口(0 为自动)", str(o["decision_port"])),
|
|
185
215
|
Field("share_gpu", "与已占用 GPU 的进程共用", o["share_gpu"]),
|
|
186
216
|
Field("aux", "选装 embedding、reranker、STT(默认不装)", o["aux"]),
|
|
187
|
-
Field("tts", "调试 TTS(可选,默认不装)", False),
|
|
217
|
+
Field("tts", "调试 TTS(可选,默认不装)", bool(o.get("tts", False))),
|
|
188
218
|
Field("suite_memory", "套件内存上限", o["suite_memory"]),
|
|
189
219
|
Field("conversation_cache", "LLM 会话缓存(auto / off / MiB)", o["conversation_cache"]),
|
|
190
220
|
Field("hf_endpoint", "权重下载源", o["hf_endpoint"]),
|
|
191
221
|
Field("base_dir", "引擎、权重与部署目录", o["base_dir"]),
|
|
192
|
-
Field("reuse_from", "复用目录(逗号分隔,可空)", ""),
|
|
222
|
+
Field("reuse_from", "复用目录(逗号分隔,可空)", ", ".join(o.get("reuse_from") or ())),
|
|
193
223
|
]
|
|
194
224
|
|
|
195
225
|
|