@simplexai/localmodels-linux-arm64 0.1.0-dev.103 → 0.1.0-dev.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/{modules/simplex_localmodels-0.1.0.dev103.dist-info/licenses/NOTICE → NOTICE} +42 -13
- package/README.md +10 -0
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +126 -127
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/catalog.json +130 -127
- package/modules/localmodels/catalog.py +7 -3
- package/modules/localmodels/catalog_recipes.py +3 -3
- package/modules/localmodels/cli_parser.py +3 -3
- package/modules/localmodels/component.py +1 -1
- package/modules/localmodels/console.py +1 -1
- package/modules/localmodels/context_policy.py +6 -5
- package/modules/localmodels/debug_cli.py +0 -12
- package/modules/localmodels/debug_mode.py +0 -6
- package/modules/localmodels/decode_calibration.json +3 -4
- package/modules/localmodels/decode_calibration.py +5 -2
- package/modules/localmodels/deployment_lifecycle.py +1 -1
- package/modules/localmodels/download-mirrors.json +1 -1
- package/modules/localmodels/engine_adapters/base.py +11 -1
- package/modules/localmodels/engine_adapters/strata_poly.py +65 -3
- package/modules/localmodels/engine_adapters/suite_plan.py +57 -20
- package/modules/localmodels/engines-b11583.json +6 -26
- package/modules/localmodels/engines-b12588-mix-c0c3de8.json +3 -15
- package/modules/localmodels/engines-b12757-mix-ef2df21.json +3 -15
- package/modules/localmodels/engines-prism-b12178-03ec600.json +3 -15
- package/modules/localmodels/engines-speechcpp-v0.11.3.json +4 -20
- package/modules/localmodels/engines-strata-0.1.47.json +1 -5
- package/modules/localmodels/engines-strata-0.1.49.2.json +1 -5
- package/modules/localmodels/engines-strata-0.1.59.1.json +1 -5
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +6 -30
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +129 -0
- package/modules/localmodels/engines-whisper-b5454.json +6 -30
- package/modules/localmodels/engines.json +13 -61
- package/modules/localmodels/estimator.py +10 -5
- package/modules/localmodels/gpu_specs.py +1 -1
- package/modules/localmodels/hosts.py +12 -16
- package/modules/localmodels/kokoro-tts-0.6.1.txt +1 -1
- package/modules/localmodels/library_elastic.py +135 -6
- package/modules/localmodels/library_kept.py +9 -1
- package/modules/localmodels/library_model.py +28 -1
- package/modules/localmodels/library_poly.py +109 -11
- package/modules/localmodels/library_pricing.py +12 -3
- package/modules/localmodels/library_serve.py +134 -67
- package/modules/localmodels/library_smoke.py +63 -5
- package/modules/localmodels/library_state.py +3 -2
- package/modules/localmodels/library_status.py +8 -1
- package/modules/localmodels/llm_rank.py +13 -8
- package/modules/localmodels/metal.py +1 -2
- package/modules/localmodels/plan_envelope.py +29 -11
- package/modules/localmodels/planning/budget.py +14 -12
- package/modules/localmodels/planning/memory_pools.py +7 -1
- package/modules/localmodels/privacy_acceptance.py +6 -5
- package/modules/localmodels/py.typed +0 -0
- package/modules/localmodels/quant_formats.py +1 -1
- package/modules/localmodels/recommend_cli.py +1 -1
- package/modules/localmodels/remote_ops_launchd.py +8 -1
- package/modules/localmodels/runtime_process.py +1 -1
- package/modules/localmodels/service_deployment.py +2 -4
- package/modules/localmodels/service_probe.py +59 -13
- package/modules/localmodels/setup_inspection.py +72 -70
- package/modules/localmodels/setup_text.py +7 -56
- package/modules/localmodels/sidecar_downloads.py +34 -0
- package/modules/localmodels/sidecar_http.py +61 -5
- package/modules/localmodels/sidecar_state.py +52 -2
- package/modules/localmodels/speech_admission.py +20 -4
- package/modules/localmodels/speech_catalog.py +23 -0
- package/modules/localmodels/speech_cli.py +10 -2
- package/modules/localmodels/speech_jobs.py +42 -17
- package/modules/localmodels/speech_server.py +182 -81
- package/modules/localmodels/speech_state.py +4 -1
- package/modules/localmodels/speech_workers.py +11 -0
- package/modules/localmodels/stack.py +1 -1
- package/modules/localmodels/stack_args.py +6 -6
- package/modules/localmodels/stack_auto.py +1 -1
- package/modules/localmodels/stack_aux_gpu.py +1 -1
- package/modules/localmodels/stack_cleanup.py +21 -18
- package/modules/localmodels/stack_cli.py +6 -2
- package/modules/localmodels/stack_compose.py +11 -4
- package/modules/localmodels/stack_debug.py +1 -2
- package/modules/localmodels/stack_decision.py +4 -4
- package/modules/localmodels/stack_doctor.py +2 -2
- package/modules/localmodels/stack_events.py +1 -1
- package/modules/localmodels/stack_gpu_memory.py +1 -1
- package/modules/localmodels/stack_hardware.py +3 -3
- package/modules/localmodels/stack_mcp.py +1 -2
- package/modules/localmodels/stack_picks.py +1 -1
- package/modules/localmodels/stack_plan.py +9 -9
- package/modules/localmodels/stack_ports.py +31 -4
- package/modules/localmodels/stack_rollback.py +1 -1
- package/modules/localmodels/stack_run.py +1 -1
- package/modules/localmodels/stack_suite.py +61 -12
- package/modules/localmodels/stack_view_agent.py +1 -1
- package/modules/localmodels/stack_view_serve.py +0 -2
- package/modules/localmodels/stack_view_words.py +2 -2
- package/modules/localmodels/stack_warm.py +2 -2
- package/modules/localmodels/stack_whatif.py +524 -41
- package/modules/localmodels/stack_whatif_html.py +903 -0
- package/modules/localmodels/startlux-decide-83fe6c7d.txt +2 -2
- package/modules/localmodels/{strata-poly-serve-0.2.20-poly.7.txt → strata-poly-serve-0.2.20-poly.9.txt} +1 -1
- package/modules/localmodels/strata_poly_server.py +114 -3
- package/modules/localmodels/suite.py +137 -5
- package/modules/localmodels/tts_admission.py +2 -17
- package/modules/localmodels/tts_catalog.py +29 -1
- package/modules/localmodels/tts_cli.py +23 -4
- package/modules/localmodels/tts_http.py +10 -4
- package/modules/localmodels/tts_jobs.py +49 -19
- package/modules/localmodels/tts_server.py +1 -1
- package/modules/localmodels/tts_sidecar.py +66 -28
- package/modules/localmodels/tts_state.py +7 -2
- package/modules/localmodels/vision.py +5 -3
- package/modules/localmodels/web/view/ASSET-SOURCES.md +4 -7
- package/modules/localmodels/web/view/view.css +0 -1
- package/modules/localmodels/web/view/view.js +2 -5
- package/modules/localmodels/web/whatif/app.js +730 -0
- package/modules/localmodels/web/whatif/page.html +1172 -0
- package/modules/localmodels/web/whatif/sim.js +303 -0
- package/modules/localmodels/windows_job.py +179 -11
- package/modules/simplex_localmodels-0.1.0.dev104.dist-info/METADATA +14 -0
- package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/RECORD +118 -114
- package/modules/simplex_localmodels-0.1.0.dev104.dist-info/licenses/LICENSE +201 -0
- package/modules/simplex_localmodels-0.1.0.dev104.dist-info/licenses/NOTICE +126 -0
- package/package.json +11 -2
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.7.json +0 -94
- package/modules/localmodels/fixtures/stack-research-demo-plan.json +0 -1059
- package/modules/localmodels/stack_research.py +0 -716
- package/modules/localmodels/stack_research_demo.py +0 -125
- package/modules/localmodels/stack_research_plan.py +0 -146
- package/modules/localmodels/web/index.html +0 -2605
- package/modules/localmodels/web/sizecalc/app.js +0 -1306
- package/modules/localmodels/web/sizecalc/calc.js +0 -269
- package/modules/localmodels/web/sizecalc/page.html +0 -520
- package/modules/localmodels/web/view/logo-claude.svg +0 -3
- package/modules/localmodels/web/view/logo-codex.png +0 -0
- package/modules/simplex_localmodels-0.1.0.dev103.dist-info/METADATA +0 -9
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -1,2605 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<meta name="color-scheme" content="light dark">
|
|
7
|
-
<title>本地模型设置</title>
|
|
8
|
-
<script data-theme-init>try{var t=localStorage.getItem('localmodels.theme')||localStorage.getItem('lm-theme')||localStorage.getItem('lm-sizecalc-theme');if(t==='light'||t==='dark')document.documentElement.dataset.theme=t;}catch(e){}</script>
|
|
9
|
-
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='14' fill='%231c1c21'/%3E%3Cg fill='none' stroke-linejoin='round' stroke-width='3.6'%3E%3Cpath d='M32 12 13 21.5 32 31l19-9.5L32 12Z' stroke='%238b85ff' fill='%238b85ff' fill-opacity='.18'/%3E%3Cpath d='m13 32 19 9.5L51 32' stroke='%232dd4bf'/%3E%3Cpath d='m13 42 19 9.5L51 42' stroke='%23fb923c'/%3E%3C/g%3E%3C/svg%3E">
|
|
10
|
-
<!--
|
|
11
|
-
本地模型设置页,served by `python3 -m localmodels serve`; every value comes from /api.
|
|
12
|
-
Layout, primitives and Chinese copy follow Hermes Desktop「设置 → 提供方 → 本地模型」
|
|
13
|
-
(NousResearch/hermes-agent, MIT License, Copyright (c) 2025 Nous Research,
|
|
14
|
-
commit 7cc3fb8cb55898747dd1dfa56fda3e16ebba028e: apps/desktop/src/app/settings/local-models-*.tsx,
|
|
15
|
-
primitives.tsx, i18n/zh_local_models.ts). The device section and the deploy plan dialog are ours.
|
|
16
|
-
-->
|
|
17
|
-
<style>
|
|
18
|
-
:root {
|
|
19
|
-
color-scheme: light dark;
|
|
20
|
-
--bg: #f4f4f6;
|
|
21
|
-
--card: #ffffff;
|
|
22
|
-
--card-2: #f9f9fb;
|
|
23
|
-
--sidebar-bg: #f4f4f6;
|
|
24
|
-
--fg: #1c1c21;
|
|
25
|
-
--text-secondary: #4a4a53;
|
|
26
|
-
--text-tertiary: #5e5e68;
|
|
27
|
-
--muted-fg: #5e5e68;
|
|
28
|
-
--muted-bg: #f1f1f4;
|
|
29
|
-
--border: #e3e3e8;
|
|
30
|
-
--stroke: #d4d4dc;
|
|
31
|
-
--nav-active: #ffffff;
|
|
32
|
-
--nav-active-border: #e3e3e8;
|
|
33
|
-
--nav-hover: rgba(28, 28, 33, .045);
|
|
34
|
-
--primary: #4f46e5;
|
|
35
|
-
--primary-hover: #4338ca;
|
|
36
|
-
--primary-soft: #eeedfd;
|
|
37
|
-
--primary-fg: #ffffff;
|
|
38
|
-
--success: #16713c;
|
|
39
|
-
--success-soft: rgba(22, 113, 60, .10);
|
|
40
|
-
--warn: #985100;
|
|
41
|
-
--warn-soft: rgba(152, 81, 0, .11);
|
|
42
|
-
--danger: #d70015;
|
|
43
|
-
--danger-soft: rgba(215, 0, 21, .10);
|
|
44
|
-
--tip-bg: #1c1c21;
|
|
45
|
-
--tip-fg: #f4f4f6;
|
|
46
|
-
--tip-border: rgba(255, 255, 255, .12);
|
|
47
|
-
--text-size: 13px;
|
|
48
|
-
--caption-size: 12px;
|
|
49
|
-
--shadow: 0 1px 2px rgba(20, 22, 30, .06);
|
|
50
|
-
--shadow-lg: 0 16px 44px rgba(20, 22, 30, .16), 0 2px 8px rgba(20, 22, 30, .06);
|
|
51
|
-
}
|
|
52
|
-
:root[data-theme="light"] { color-scheme: light; }
|
|
53
|
-
@media (prefers-color-scheme: dark) {
|
|
54
|
-
:root:not([data-theme="light"]) {
|
|
55
|
-
color-scheme: dark;
|
|
56
|
-
--bg: #121215; --card: #1b1b1e; --card-2: #232327; --sidebar-bg: #121215;
|
|
57
|
-
--fg: #ececf0; --text-secondary: #c2c2c9; --text-tertiary: #aaaab4; --muted-fg: #aaaab4;
|
|
58
|
-
--muted-bg: #2e2e33; --border: #34343a; --stroke: #42424a;
|
|
59
|
-
--nav-active: #232327; --nav-active-border: #34343a; --nav-hover: rgba(236, 236, 240, .06);
|
|
60
|
-
--primary: #9b95ff; --primary-hover: #b2adff; --primary-soft: #2e2b52; --primary-fg: #121215;
|
|
61
|
-
--success: #4ade80; --success-soft: rgba(74, 222, 128, .12);
|
|
62
|
-
--warn: #fdba74; --warn-soft: rgba(253, 186, 116, .13);
|
|
63
|
-
--danger: #fb7185; --danger-soft: rgba(251, 113, 133, .13);
|
|
64
|
-
--tip-bg: #2a2a30; --tip-fg: #ececf0; --tip-border: #44444e;
|
|
65
|
-
--shadow: 0 1px 2px rgba(0, 0, 0, .28);
|
|
66
|
-
--shadow-lg: 0 18px 48px rgba(0, 0, 0, .55);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
:root[data-theme="dark"] {
|
|
70
|
-
color-scheme: dark;
|
|
71
|
-
--bg: #121215; --card: #1b1b1e; --card-2: #232327; --sidebar-bg: #121215;
|
|
72
|
-
--fg: #ececf0; --text-secondary: #c2c2c9; --text-tertiary: #aaaab4; --muted-fg: #aaaab4;
|
|
73
|
-
--muted-bg: #2e2e33; --border: #34343a; --stroke: #42424a;
|
|
74
|
-
--nav-active: #232327; --nav-active-border: #34343a; --nav-hover: rgba(236, 236, 240, .06);
|
|
75
|
-
--primary: #9b95ff; --primary-hover: #b2adff; --primary-soft: #2e2b52; --primary-fg: #121215;
|
|
76
|
-
--success: #4ade80; --success-soft: rgba(74, 222, 128, .12);
|
|
77
|
-
--warn: #fdba74; --warn-soft: rgba(253, 186, 116, .13);
|
|
78
|
-
--danger: #fb7185; --danger-soft: rgba(251, 113, 133, .13);
|
|
79
|
-
--tip-bg: #2a2a30; --tip-fg: #ececf0; --tip-border: #44444e;
|
|
80
|
-
--shadow: 0 1px 2px rgba(0, 0, 0, .28);
|
|
81
|
-
--shadow-lg: 0 18px 48px rgba(0, 0, 0, .55);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
* { box-sizing: border-box; }
|
|
85
|
-
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
|
|
86
|
-
#plan-title:focus, #remove-title:focus { outline: none; }
|
|
87
|
-
#shortcuts-title:focus { outline: none; }
|
|
88
|
-
html, body { height: 100%; margin: 0; }
|
|
89
|
-
body {
|
|
90
|
-
background: var(--bg);
|
|
91
|
-
color: var(--fg);
|
|
92
|
-
font: var(--text-size)/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
|
|
93
|
-
-webkit-font-smoothing: antialiased;
|
|
94
|
-
overflow: hidden;
|
|
95
|
-
}
|
|
96
|
-
button { font: inherit; color: inherit; }
|
|
97
|
-
svg.i { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
|
98
|
-
svg.i.sm { width: 14px; height: 14px; }
|
|
99
|
-
svg.i.xs { width: 12px; height: 12px; }
|
|
100
|
-
.spin { animation: spin 1s linear infinite; }
|
|
101
|
-
@keyframes spin { to { transform: rotate(360deg); } }
|
|
102
|
-
|
|
103
|
-
/* ── Shell ── */
|
|
104
|
-
.window { display: grid; grid-template-columns: 212px minmax(0, 1fr); height: 100vh; }
|
|
105
|
-
.sidebar {
|
|
106
|
-
background: var(--sidebar-bg);
|
|
107
|
-
border-right: 1px solid var(--border);
|
|
108
|
-
display: flex; flex-direction: column; gap: 8px;
|
|
109
|
-
padding: 12px 10px;
|
|
110
|
-
min-height: 0;
|
|
111
|
-
}
|
|
112
|
-
.nav-list { display: grid; gap: 2px; }
|
|
113
|
-
.sidebar-nav { align-content: start; flex: 1; min-height: 0; overflow-y: auto; }
|
|
114
|
-
.nav-item {
|
|
115
|
-
display: flex; align-items: center; gap: 8px;
|
|
116
|
-
min-height: 32px; width: 100%;
|
|
117
|
-
padding: 0 10px;
|
|
118
|
-
border: 1px solid transparent; border-radius: 8px;
|
|
119
|
-
background: transparent; text-align: left; text-decoration: none;
|
|
120
|
-
color: var(--text-secondary); cursor: pointer;
|
|
121
|
-
transition: background .15s, color .15s, border-color .15s;
|
|
122
|
-
}
|
|
123
|
-
.nav-item svg { color: var(--muted-fg); transition: color .15s; }
|
|
124
|
-
.nav-item:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--nav-hover); color: var(--fg); }
|
|
125
|
-
.nav-item:disabled, .nav-item[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
|
|
126
|
-
.nav-item[aria-current="page"],
|
|
127
|
-
.nav-item[aria-current="location"] {
|
|
128
|
-
background: var(--nav-active); border-color: var(--nav-active-border);
|
|
129
|
-
color: var(--fg); font-weight: 560; box-shadow: var(--shadow);
|
|
130
|
-
}
|
|
131
|
-
.sidebar > .nav-item[aria-current="page"] {
|
|
132
|
-
background: transparent; border-color: transparent; box-shadow: none;
|
|
133
|
-
font-weight: 600; color: var(--fg);
|
|
134
|
-
}
|
|
135
|
-
.sidebar > .nav-item[aria-current="page"]:hover { background: var(--nav-hover); }
|
|
136
|
-
.nav-item[aria-current="page"] svg,
|
|
137
|
-
.nav-item[aria-current="location"] svg { color: var(--primary); }
|
|
138
|
-
.nav-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
139
|
-
.nav-badge {
|
|
140
|
-
padding: 2px 6px; border-radius: 99px;
|
|
141
|
-
background: var(--muted-bg); color: var(--muted-fg);
|
|
142
|
-
font-size: 10.5px; font-weight: 500; line-height: 1.2; white-space: nowrap;
|
|
143
|
-
font-variant-numeric: tabular-nums;
|
|
144
|
-
}
|
|
145
|
-
.nav-item[aria-current="location"] .nav-badge { background: var(--primary-soft); color: var(--primary); }
|
|
146
|
-
.nav-divider { height: 1px; background: var(--border); margin: 6px 4px; }
|
|
147
|
-
.nav-group-title { font-size: 10.5px; font-weight: 600; color: var(--text-tertiary); padding: 4px 10px 2px; letter-spacing: .03em; }
|
|
148
|
-
.kbd-badge {
|
|
149
|
-
display: inline-flex; align-items: center; justify-content: center;
|
|
150
|
-
min-width: 18px; height: 18px; padding: 0 4px;
|
|
151
|
-
border-radius: 4px; border: 1px solid var(--stroke);
|
|
152
|
-
background: var(--muted-bg); color: var(--muted-fg);
|
|
153
|
-
font: 10px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
|
|
154
|
-
}
|
|
155
|
-
.nav-item .kbd-badge { margin-left: auto; }
|
|
156
|
-
.shortcuts-table { width: 100%; border-collapse: collapse; margin: 4px 0 8px; font-size: 12px; }
|
|
157
|
-
.shortcuts-table tr { border-bottom: 1px solid var(--border); }
|
|
158
|
-
.shortcuts-table tr:last-child { border-bottom: none; }
|
|
159
|
-
.shortcuts-table td { padding: 8px 6px; }
|
|
160
|
-
.shortcuts-table td:first-child { width: 120px; font-weight: 500; }
|
|
161
|
-
.view-hint {
|
|
162
|
-
display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
|
|
163
|
-
margin: 10px 0 0; padding: 8px 12px;
|
|
164
|
-
border-radius: 8px; border: 1px solid var(--border);
|
|
165
|
-
background: var(--card-2); color: var(--text-secondary); font-size: 12px;
|
|
166
|
-
}
|
|
167
|
-
.view-hint a { color: var(--primary); text-decoration: none; font-weight: 550; }
|
|
168
|
-
.view-hint a:hover { text-decoration: underline; }
|
|
169
|
-
.sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); display: grid; gap: 8px; }
|
|
170
|
-
.cross-links { display: grid; gap: 2px; }
|
|
171
|
-
.theme-btn {
|
|
172
|
-
display: inline-flex; align-items: center; gap: 8px;
|
|
173
|
-
width: 100%; min-height: 32px; padding: 0 10px;
|
|
174
|
-
border: 1px solid var(--border); border-radius: 8px;
|
|
175
|
-
background: var(--card); color: var(--text-secondary);
|
|
176
|
-
font-size: 12px; cursor: pointer; text-align: left;
|
|
177
|
-
transition: background .15s, color .15s;
|
|
178
|
-
}
|
|
179
|
-
.theme-btn:hover { background: var(--nav-hover); color: var(--fg); }
|
|
180
|
-
|
|
181
|
-
.main { position: relative; min-height: 0; display: flex; flex-direction: column; }
|
|
182
|
-
.mobile-nav { display: none; }
|
|
183
|
-
.scroll { flex: 1; overflow-y: auto; padding: 24px 36px 80px; scroll-behavior: smooth; }
|
|
184
|
-
.page-head, #page { max-width: 1080px; margin-left: auto; margin-right: auto; }
|
|
185
|
-
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 auto 16px; }
|
|
186
|
-
.page-title { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
|
|
187
|
-
.setup-guide, .section { scroll-margin-top: 16px; }
|
|
188
|
-
|
|
189
|
-
/* ── Settings primitives (primitives.tsx) ── */
|
|
190
|
-
.section {
|
|
191
|
-
margin-bottom: 16px; padding: 16px 18px;
|
|
192
|
-
background: var(--card); border: 1px solid var(--border); border-radius: 12px;
|
|
193
|
-
}
|
|
194
|
-
.section-heading { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-weight: 600; font-size: 14px; }
|
|
195
|
-
.section-heading > svg { color: var(--muted-fg); }
|
|
196
|
-
.section-heading .aside { margin-left: auto; display: flex; align-items: center; gap: 6px; font-weight: 400; }
|
|
197
|
-
|
|
198
|
-
.active-strip {
|
|
199
|
-
display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
|
|
200
|
-
margin-bottom: 16px; padding: 10px 14px; border-radius: 10px;
|
|
201
|
-
background: var(--card); border: 1px solid var(--border);
|
|
202
|
-
}
|
|
203
|
-
.active-strip.is-ready {
|
|
204
|
-
background: color-mix(in srgb, var(--success-soft) 55%, var(--card));
|
|
205
|
-
border-color: color-mix(in srgb, var(--success) 35%, var(--border));
|
|
206
|
-
}
|
|
207
|
-
.active-strip-main { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; min-width: 0; flex: 1 1 260px; }
|
|
208
|
-
.active-strip-ep { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
|
|
209
|
-
.active-strip-name { font-weight: 550; color: var(--fg); font-size: 12px; }
|
|
210
|
-
.active-strip-ep code {
|
|
211
|
-
padding: 2px 7px; border-radius: 5px;
|
|
212
|
-
background: var(--card); border: 1px solid var(--border); color: var(--fg);
|
|
213
|
-
overflow-wrap: anywhere;
|
|
214
|
-
}
|
|
215
|
-
.active-strip-link {
|
|
216
|
-
font-size: 12px; font-weight: 550; color: var(--primary); text-decoration: none;
|
|
217
|
-
white-space: nowrap; flex-shrink: 0;
|
|
218
|
-
}
|
|
219
|
-
.active-strip-link:hover { text-decoration: underline; }
|
|
220
|
-
|
|
221
|
-
.pill {
|
|
222
|
-
display: inline-flex; align-items: center; gap: 4px;
|
|
223
|
-
width: fit-content; flex-shrink: 0;
|
|
224
|
-
padding: 3px 7px; border-radius: 5px;
|
|
225
|
-
font-size: 11px; font-weight: 500; line-height: 1.1; white-space: nowrap;
|
|
226
|
-
font-variant-numeric: tabular-nums;
|
|
227
|
-
background: var(--muted-bg); color: var(--muted-fg);
|
|
228
|
-
}
|
|
229
|
-
.pill svg { width: 12px; height: 12px; }
|
|
230
|
-
.pill.primary { background: var(--primary-soft); color: var(--primary); }
|
|
231
|
-
.recommended-model .pill.primary { background: var(--primary); color: var(--primary-fg); }
|
|
232
|
-
.recommended-model .pill:not(.primary):not(.success):not(.warn):not(.destructive) { background: var(--card); border: 1px solid var(--border); }
|
|
233
|
-
.pill.success { background: var(--success-soft); color: var(--success); }
|
|
234
|
-
.pill.warn { background: var(--warn-soft); color: var(--warn); }
|
|
235
|
-
.pill.destructive { background: var(--danger-soft); color: var(--danger); }
|
|
236
|
-
|
|
237
|
-
.row { display: grid; gap: 12px; padding: 12px 0; grid-template-columns: minmax(0, 1fr) minmax(15rem, 22rem); align-items: center; }
|
|
238
|
-
.row + .row { border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
|
|
239
|
-
.row-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 550; color: var(--fg); font-size: var(--text-size); }
|
|
240
|
-
.row-desc { margin-top: 4px; font-size: var(--caption-size); line-height: 1.55; color: var(--text-tertiary); }
|
|
241
|
-
.row-action { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
|
|
242
|
-
.pills { margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
|
243
|
-
.rows { display: grid; }
|
|
244
|
-
.setup-guide { background: var(--card); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 16px; }
|
|
245
|
-
.setup-guide-summary {
|
|
246
|
-
display: flex; align-items: center; justify-content: space-between; gap: 12px;
|
|
247
|
-
padding: 13px 18px; cursor: pointer; font-weight: 600; color: var(--fg); list-style: none;
|
|
248
|
-
}
|
|
249
|
-
.setup-guide-summary::-webkit-details-marker { display: none; }
|
|
250
|
-
.setup-guide-summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 10px; }
|
|
251
|
-
.setup-guide-toggle { display: inline-flex; align-items: center; color: var(--muted-fg); flex-shrink: 0; }
|
|
252
|
-
.setup-guide-toggle svg { transition: transform .15s; }
|
|
253
|
-
.setup-guide[open] .setup-guide-toggle svg { transform: rotate(90deg); }
|
|
254
|
-
.setup-guide-body { padding: 4px 18px 16px; border-top: 1px solid var(--border); }
|
|
255
|
-
.setup-guide p { margin: 8px 0 0; color: var(--text-secondary); }
|
|
256
|
-
.install-command { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0; }
|
|
257
|
-
.setup-guide code { overflow-wrap: anywhere; }
|
|
258
|
-
.install-command code {
|
|
259
|
-
user-select: all; padding: 5px 10px; border-radius: 7px;
|
|
260
|
-
background: var(--muted-bg); border: 1px solid var(--border); color: var(--fg);
|
|
261
|
-
}
|
|
262
|
-
.inline-cmd { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; vertical-align: baseline; }
|
|
263
|
-
.inline-cmd code {
|
|
264
|
-
padding: 1px 6px; border-radius: 5px;
|
|
265
|
-
background: var(--muted-bg); border: 1px solid var(--border); color: var(--fg);
|
|
266
|
-
}
|
|
267
|
-
.recommended-model {
|
|
268
|
-
padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--primary) 42%, var(--border));
|
|
269
|
-
border-radius: 10px; background: color-mix(in srgb, var(--primary-soft) 55%, var(--card));
|
|
270
|
-
}
|
|
271
|
-
.recommended-model .row { padding: 8px 0; }
|
|
272
|
-
.recommendation-note { margin: 0 0 6px; color: var(--text-secondary); font-size: var(--caption-size); }
|
|
273
|
-
.recommendation-note:last-child { margin: 6px 0 0; }
|
|
274
|
-
.model-alternatives { margin-top: 12px; }
|
|
275
|
-
.model-alternatives summary { cursor: pointer; padding: 8px 0; color: var(--text-secondary); font-weight: 500; }
|
|
276
|
-
.model-alternatives summary:hover { color: var(--fg); }
|
|
277
|
-
.model-alternatives summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
|
|
278
|
-
.model-alternatives > .hint { margin-bottom: 8px; }
|
|
279
|
-
.catalog-toolbar {
|
|
280
|
-
display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
|
|
281
|
-
margin: 8px 0 10px; padding: 6px 8px;
|
|
282
|
-
border: 1px solid var(--border); border-radius: 9px; background: var(--card-2);
|
|
283
|
-
}
|
|
284
|
-
.catalog-search { flex: 1 1 200px; margin: 0; background: var(--card); }
|
|
285
|
-
.filter-chip {
|
|
286
|
-
display: inline-flex; align-items: center; gap: 6px;
|
|
287
|
-
height: 30px; padding: 0 10px; border-radius: 99px;
|
|
288
|
-
border: 1px solid var(--stroke); background: var(--card);
|
|
289
|
-
color: var(--text-secondary); font-size: 12px; cursor: pointer; user-select: none;
|
|
290
|
-
transition: border-color .15s, background .15s, color .15s;
|
|
291
|
-
}
|
|
292
|
-
.filter-chip:hover { border-color: var(--primary); color: var(--fg); }
|
|
293
|
-
.filter-chip:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 500; }
|
|
294
|
-
.filter-chip input { margin: 0; accent-color: var(--primary); }
|
|
295
|
-
.catalog-empty { padding: 12px 0; }
|
|
296
|
-
|
|
297
|
-
.btn {
|
|
298
|
-
display: inline-flex; align-items: center; justify-content: center; gap: 6px;
|
|
299
|
-
height: 28px; padding: 0 10px; border-radius: 7px;
|
|
300
|
-
border: 1px solid transparent; cursor: pointer; white-space: nowrap;
|
|
301
|
-
font-size: 12px; font-weight: 500;
|
|
302
|
-
transition: background .15s, border-color .15s, color .15s, opacity .15s;
|
|
303
|
-
}
|
|
304
|
-
.btn svg { width: 14px; height: 14px; }
|
|
305
|
-
.btn.primary { background: var(--primary); color: var(--primary-fg); }
|
|
306
|
-
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
|
|
307
|
-
.btn.danger { background: var(--danger); color: #ffffff; }
|
|
308
|
-
.btn.danger:hover:not(:disabled) { opacity: .9; }
|
|
309
|
-
.btn.outline { background: var(--card); border-color: var(--stroke); color: var(--fg); box-shadow: var(--shadow); }
|
|
310
|
-
.btn.outline:hover:not(:disabled) { background: var(--nav-hover); }
|
|
311
|
-
.btn.ghost { background: none; color: var(--text-secondary); }
|
|
312
|
-
.btn.ghost:hover:not(:disabled) { background: var(--nav-hover); color: var(--fg); }
|
|
313
|
-
.btn.icon { width: 28px; padding: 0; }
|
|
314
|
-
.btn.sm { height: 22px; padding: 0 7px; font-size: 11px; gap: 4px; border-radius: 5px; }
|
|
315
|
-
.btn.sm svg { width: 12px; height: 12px; }
|
|
316
|
-
.btn.lg { height: 34px; padding: 0 14px; font-size: 13px; }
|
|
317
|
-
.btn.is-copied { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, var(--border)); }
|
|
318
|
-
.btn:disabled { opacity: .5; cursor: not-allowed; }
|
|
319
|
-
.btn.mobile-theme-btn { display: none; }
|
|
320
|
-
|
|
321
|
-
.error-card {
|
|
322
|
-
display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px;
|
|
323
|
-
margin-bottom: 16px; padding: 14px 16px; border-radius: 12px;
|
|
324
|
-
background: var(--card); border: 1px solid color-mix(in srgb, var(--danger) 42%, var(--border));
|
|
325
|
-
box-shadow: inset 3px 0 0 var(--danger);
|
|
326
|
-
}
|
|
327
|
-
.error-card-body { display: grid; gap: 4px; min-width: 0; flex: 1 1 240px; }
|
|
328
|
-
.error-card-title { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--danger); }
|
|
329
|
-
.error-card-msg { margin: 0; font-size: 12px; color: var(--text-secondary); white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
330
|
-
|
|
331
|
-
.hw { display: flex; flex-wrap: wrap; align-items: center; column-gap: 20px; row-gap: 6px; padding: 4px 0; font-size: var(--caption-size); color: var(--muted-fg); font-variant-numeric: tabular-nums; }
|
|
332
|
-
.hw span { display: inline-flex; align-items: center; gap: 6px; }
|
|
333
|
-
|
|
334
|
-
.progress { height: 5px; border-radius: 99px; background: var(--muted-bg); overflow: hidden; box-shadow: inset 0 0 0 1px var(--border); position: relative; }
|
|
335
|
-
.progress > div { height: 100%; background: var(--primary); border-radius: inherit; transition: width .3s; }
|
|
336
|
-
.progress.indeterminate > div { width: 38%; animation: progress-slide 1.4s ease-in-out infinite; }
|
|
337
|
-
@keyframes progress-slide {
|
|
338
|
-
0% { transform: translateX(-110%); }
|
|
339
|
-
100% { transform: translateX(300%); }
|
|
340
|
-
}
|
|
341
|
-
.progress-text { font-size: 11.5px; color: var(--muted-fg); font-variant-numeric: tabular-nums; }
|
|
342
|
-
.job-done-line { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
|
343
|
-
.below { margin-top: 8px; display: grid; gap: 5px; }
|
|
344
|
-
|
|
345
|
-
.hint { font-size: 12px; color: var(--muted-fg); margin: 0; }
|
|
346
|
-
.refresh-banner {
|
|
347
|
-
display: flex; align-items: center; gap: 8px;
|
|
348
|
-
margin: 0 0 10px; padding: 7px 11px; border-radius: 8px;
|
|
349
|
-
background: var(--primary-soft); color: var(--primary);
|
|
350
|
-
border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--border));
|
|
351
|
-
font-size: 12px; font-weight: 500;
|
|
352
|
-
}
|
|
353
|
-
.busy-note { display: flex; gap: 8px; align-items: flex-start; margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--fg); border: 1px solid color-mix(in srgb, var(--warn) 28%, var(--border)); }
|
|
354
|
-
.search-field { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px; margin: 8px 0; color: var(--muted-fg); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; transition: border-color .15s, box-shadow .15s; }
|
|
355
|
-
.search-field input { flex: 1; border: 0; outline: 0; background: none; color: var(--fg); font: inherit; font-size: 12px; min-width: 0; }
|
|
356
|
-
.search-field input::placeholder { color: var(--muted-fg); opacity: 1; }
|
|
357
|
-
.search-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 18%, transparent); }
|
|
358
|
-
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace; font-size: 12px; }
|
|
359
|
-
.row-desc .mono { overflow-wrap: anywhere; }
|
|
360
|
-
.status-line { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted-fg); margin: 8px 0; }
|
|
361
|
-
|
|
362
|
-
/* Tooltip (Tip) */
|
|
363
|
-
[data-tip] { position: relative; }
|
|
364
|
-
.tip {
|
|
365
|
-
position: fixed; z-index: 50; max-width: 280px; pointer-events: none;
|
|
366
|
-
padding: 6px 9px; border-radius: 7px; font-size: 11.5px; line-height: 1.45;
|
|
367
|
-
background: var(--tip-bg); color: var(--tip-fg);
|
|
368
|
-
border: 1px solid var(--tip-border);
|
|
369
|
-
box-shadow: 0 8px 24px rgba(0, 0, 0, .26);
|
|
370
|
-
opacity: 0; transition: opacity .12s; overflow-wrap: anywhere;
|
|
371
|
-
}
|
|
372
|
-
.tip.show { opacity: 1; }
|
|
373
|
-
|
|
374
|
-
/* Toasts */
|
|
375
|
-
.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
|
|
376
|
-
.toast {
|
|
377
|
-
display: flex; align-items: flex-start; gap: 10px;
|
|
378
|
-
min-width: 240px; max-width: 380px; padding: 10px 12px; border-radius: 9px;
|
|
379
|
-
background: var(--card); border: 1px solid var(--border); border-left: 3px solid var(--primary);
|
|
380
|
-
box-shadow: var(--shadow-lg); font-size: 12px;
|
|
381
|
-
}
|
|
382
|
-
.toast--success { border-left-color: var(--success); }
|
|
383
|
-
.toast--error { border-left-color: var(--danger); }
|
|
384
|
-
.toast-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
|
385
|
-
.toast b { display: block; font-weight: 600; margin-bottom: 2px; color: var(--fg); }
|
|
386
|
-
.toast--error b { color: var(--danger); }
|
|
387
|
-
.toast-close {
|
|
388
|
-
display: inline-flex; align-items: center; justify-content: center;
|
|
389
|
-
width: 20px; height: 20px; padding: 0; border: 0; border-radius: 5px;
|
|
390
|
-
background: transparent; color: var(--muted-fg); cursor: pointer; flex-shrink: 0;
|
|
391
|
-
}
|
|
392
|
-
.toast-close:hover { background: var(--nav-hover); color: var(--fg); }
|
|
393
|
-
|
|
394
|
-
/* Devices (localmodels extension) */
|
|
395
|
-
.devices { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
396
|
-
.device-item { display: inline-flex; align-items: stretch; gap: 0; max-width: 100%; }
|
|
397
|
-
.device-item .device { border-top-right-radius: 0; border-bottom-right-radius: 0; }
|
|
398
|
-
.device-remove-btn {
|
|
399
|
-
display: inline-flex; align-items: center; justify-content: center;
|
|
400
|
-
padding: 0 9px; border: 1px solid var(--border); border-left: 0;
|
|
401
|
-
border-radius: 0 8px 8px 0; background: var(--card-2); color: var(--muted-fg);
|
|
402
|
-
font-size: 11.5px; cursor: pointer; white-space: nowrap;
|
|
403
|
-
transition: background .15s, color .15s;
|
|
404
|
-
}
|
|
405
|
-
.device-remove-btn:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
|
|
406
|
-
.device-remove-btn:disabled { opacity: .5; cursor: not-allowed; }
|
|
407
|
-
.device {
|
|
408
|
-
display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center;
|
|
409
|
-
min-width: 190px; max-width: 300px; padding: 8px 12px;
|
|
410
|
-
border: 1px solid var(--border); border-radius: 8px; background: var(--card-2);
|
|
411
|
-
cursor: pointer; text-align: left; transition: background .15s, border-color .15s;
|
|
412
|
-
}
|
|
413
|
-
.device:hover { background: var(--nav-hover); }
|
|
414
|
-
.device.active { border-color: var(--primary); background: color-mix(in srgb, var(--primary-soft) 50%, var(--card)); box-shadow: 0 0 0 1px var(--primary) inset; }
|
|
415
|
-
.device svg { grid-row: span 2; color: var(--muted-fg); }
|
|
416
|
-
.device.active svg { color: var(--primary); }
|
|
417
|
-
.device-name { font-weight: 550; }
|
|
418
|
-
.device-meta { font-size: 11px; color: var(--muted-fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
419
|
-
.device-confirm-bar {
|
|
420
|
-
display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
|
|
421
|
-
margin-top: 10px; padding: 9px 12px; border-radius: 8px;
|
|
422
|
-
background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
|
|
423
|
-
font-size: 12px; color: var(--fg);
|
|
424
|
-
}
|
|
425
|
-
.device-confirm-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
|
|
426
|
-
.add-panel { margin-top: 12px; padding: 12px 14px; border: 1px dashed var(--stroke); border-radius: 9px; background: var(--card-2); }
|
|
427
|
-
.add-form { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
|
|
428
|
-
.add-form input, .plan-form input, .plan-form select {
|
|
429
|
-
flex: 1; height: 30px; padding: 0 9px; border: 1px solid var(--stroke); border-radius: 7px;
|
|
430
|
-
background: var(--card); color: var(--fg); font: inherit; font-size: 12px; min-width: 0;
|
|
431
|
-
}
|
|
432
|
-
.add-error { margin: 8px 0; }
|
|
433
|
-
.discover-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0 4px; font-size: 11.5px; color: var(--muted-fg); }
|
|
434
|
-
.discover-empty { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 7px; background: var(--card); border: 1px solid var(--border); font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
|
|
435
|
-
.candidates { display: grid; gap: 2px; max-height: 260px; overflow-y: auto; }
|
|
436
|
-
.candidate { display: grid; grid-template-columns: minmax(0, 14rem) minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 4px 0; font-size: 12px; }
|
|
437
|
-
.candidate.offline { opacity: .55; }
|
|
438
|
-
.candidate-meta { color: var(--muted-fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
439
|
-
.gpus { display: grid; gap: 8px; margin-top: 10px; }
|
|
440
|
-
.gpu { display: grid; grid-template-columns: minmax(0, 22rem) 140px auto auto; gap: 12px; align-items: center; font-size: 12px; color: var(--muted-fg); }
|
|
441
|
-
.gpu-name { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
442
|
-
.gpu-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
443
|
-
.gpu-bar { height: 5px; border-radius: 99px; background: var(--muted-bg); overflow: hidden; box-shadow: inset 0 0 0 1px var(--border); }
|
|
444
|
-
.gpu-bar > span { display: block; height: 100%; background: var(--primary); }
|
|
445
|
-
.gpu-bar.busy > span { background: var(--warn); }
|
|
446
|
-
.gpu-meta { font-variant-numeric: tabular-nums; }
|
|
447
|
-
.gpu-meta.warn { color: var(--warn); font-weight: 500; }
|
|
448
|
-
.live-status { color: var(--text-secondary); }
|
|
449
|
-
.error-text { color: var(--danger); font-size: 12px; white-space: pre-wrap; }
|
|
450
|
-
.dialog::backdrop { background: rgba(15, 18, 24, .42); backdrop-filter: blur(2px); }
|
|
451
|
-
.dialog {
|
|
452
|
-
width: min(760px, calc(100% - 32px)); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
|
|
453
|
-
margin: auto; padding: 0; flex-direction: column;
|
|
454
|
-
background: var(--card); color: var(--fg); border: 1px solid var(--border); border-radius: 12px;
|
|
455
|
-
box-shadow: var(--shadow-lg);
|
|
456
|
-
}
|
|
457
|
-
.dialog.dialog-sm { width: min(460px, calc(100% - 32px)); }
|
|
458
|
-
.dialog[open] { display: flex; }
|
|
459
|
-
.dialog-head { display: flex; align-items: center; gap: 8px; padding: 13px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
|
|
460
|
-
.dialog-head b { flex: 1; font-weight: 600; }
|
|
461
|
-
.dialog-body { flex: 1 1 auto; min-height: 0; padding: 14px 16px; overflow-y: auto; font-size: 12px; }
|
|
462
|
-
.remove-desc { margin: 0 0 6px; font-size: 13px; color: var(--fg); }
|
|
463
|
-
.dialog-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 16px; padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
|
|
464
|
-
.foot-summary { flex: 1 1 18rem; min-width: 0; margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; font-size: 11.5px; color: var(--text-secondary); }
|
|
465
|
-
.foot-summary li { overflow-wrap: anywhere; }
|
|
466
|
-
.foot-summary .warn { color: var(--warn); }
|
|
467
|
-
.foot-summary .danger { color: var(--danger); font-weight: 500; }
|
|
468
|
-
.foot-actions { display: flex; gap: 8px; margin-left: auto; }
|
|
469
|
-
.stale-hint { margin: 0 0 12px; padding: 8px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 12px; font-weight: 500; }
|
|
470
|
-
.dialog.stale .dialog-body > :not(.stale-hint):not(.gate-top), .dialog.stale .foot-summary { opacity: .4; }
|
|
471
|
-
.plan-form { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) auto; gap: 10px 12px; align-items: end; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--card-2); font-size: 11.5px; color: var(--text-tertiary); flex-shrink: 0; }
|
|
472
|
-
.plan-form label { display: grid; gap: 4px; min-width: 0; }
|
|
473
|
-
.plan-form label:nth-child(1) { grid-column: 1 / 3; }
|
|
474
|
-
.plan-form input, .plan-form select { width: 100%; min-width: 0; }
|
|
475
|
-
.plan-form [data-action="replan"] { height: 30px; justify-self: end; }
|
|
476
|
-
.plan dl, dl.plan { display: grid; grid-template-columns: 5.5em minmax(0, 1fr); gap: 8px 12px; margin: 0; }
|
|
477
|
-
dl.plan dt { color: var(--muted-fg); }
|
|
478
|
-
dl.plan dd { margin: 0; min-width: 0; }
|
|
479
|
-
dl.plan ul { margin: 0 0 4px; padding-left: 16px; }
|
|
480
|
-
.plan-file-item .btn.sm { margin-left: 4px; vertical-align: middle; }
|
|
481
|
-
dl.plan pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 11px/1.5 ui-monospace, Consolas, monospace; background: var(--muted-bg); padding: 6px 8px; border-radius: 6px; }
|
|
482
|
-
.code-box { display: grid; gap: 6px; }
|
|
483
|
-
.code-box-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
|
|
484
|
-
.warnings { margin: 12px 0 0; padding: 8px 12px; list-style: none; background: var(--warn-soft); color: var(--warn); border-radius: 8px; display: grid; gap: 4px; }
|
|
485
|
-
.warnings li { display: flex; gap: 6px; align-items: center; }
|
|
486
|
-
.gate { margin: 0 0 12px; padding: 9px 12px; border-radius: 8px; display: grid; gap: 6px; }
|
|
487
|
-
.gate.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--border)); }
|
|
488
|
-
.gate.danger { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); }
|
|
489
|
-
.gate p { margin: 0; }
|
|
490
|
-
.gate ul { margin: 0; padding-left: 16px; }
|
|
491
|
-
.gate label { display: flex; gap: 6px; align-items: center; color: var(--fg); }
|
|
492
|
-
dl.plan dt.changed { color: var(--warn); font-weight: 600; }
|
|
493
|
-
dl.plan dd.changed { box-shadow: inset 2px 0 var(--warn); padding-left: 8px; }
|
|
494
|
-
@media (max-width: 760px) {
|
|
495
|
-
.window { grid-template-columns: minmax(0, 1fr); }
|
|
496
|
-
.main { min-width: 0; }
|
|
497
|
-
.sidebar { display: none; }
|
|
498
|
-
.btn.mobile-theme-btn { display: inline-flex; }
|
|
499
|
-
.mobile-nav {
|
|
500
|
-
display: flex; align-items: center; gap: 6px;
|
|
501
|
-
padding: 8px 14px; overflow-x: auto; scrollbar-width: none;
|
|
502
|
-
background: color-mix(in srgb, var(--bg) 92%, transparent);
|
|
503
|
-
backdrop-filter: blur(10px);
|
|
504
|
-
border-bottom: 1px solid var(--border);
|
|
505
|
-
position: sticky; top: 0; z-index: 20; flex-shrink: 0;
|
|
506
|
-
}
|
|
507
|
-
.mobile-nav::-webkit-scrollbar { display: none; }
|
|
508
|
-
.mobile-nav-item {
|
|
509
|
-
display: inline-flex; align-items: center; gap: 5px;
|
|
510
|
-
height: 28px; padding: 0 10px; border-radius: 7px;
|
|
511
|
-
border: 1px solid transparent; background: transparent;
|
|
512
|
-
color: var(--text-secondary); font-size: 12px; text-decoration: none;
|
|
513
|
-
white-space: nowrap; flex-shrink: 0; cursor: pointer;
|
|
514
|
-
}
|
|
515
|
-
.mobile-nav-item[aria-current="page"],
|
|
516
|
-
.mobile-nav-item[aria-current="location"] {
|
|
517
|
-
background: var(--card); border-color: var(--border); color: var(--fg); font-weight: 560;
|
|
518
|
-
box-shadow: var(--shadow);
|
|
519
|
-
}
|
|
520
|
-
.mobile-nav-item:disabled, .mobile-nav-item[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
|
|
521
|
-
.mobile-cross-links { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
|
|
522
|
-
.mobile-cross-links:empty { display: none; }
|
|
523
|
-
.mobile-cross-links::before { content: ""; width: 1px; height: 14px; background: var(--border); margin: 0 2px; }
|
|
524
|
-
.scroll { padding: 16px 16px 60px; }
|
|
525
|
-
.section { padding: 14px; }
|
|
526
|
-
.row { grid-template-columns: 1fr; }
|
|
527
|
-
.row-action { justify-content: flex-start; }
|
|
528
|
-
.candidate, .gpu { grid-template-columns: 1fr; gap: 4px; }
|
|
529
|
-
dl.plan { grid-template-columns: 1fr; }
|
|
530
|
-
.dialog { width: calc(100% - 20px); max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); }
|
|
531
|
-
.plan-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 8px 12px; }
|
|
532
|
-
.plan-form label:nth-child(1) { grid-column: 1 / -1; }
|
|
533
|
-
.plan-form [data-action="replan"] { grid-column: 1 / -1; justify-self: start; }
|
|
534
|
-
.dialog-body { min-height: 150px; padding: 12px; }
|
|
535
|
-
.dialog-foot { padding: 10px 12px; }
|
|
536
|
-
}
|
|
537
|
-
@media (prefers-reduced-motion: reduce) {
|
|
538
|
-
.scroll { scroll-behavior: auto; }
|
|
539
|
-
.spin { animation: none; }
|
|
540
|
-
.progress.indeterminate > div { animation: none; width: 100%; opacity: .45; transform: none; }
|
|
541
|
-
.progress > div, .tip, .setup-guide-toggle svg, .nav-item, .btn { transition: none; }
|
|
542
|
-
}
|
|
543
|
-
</style>
|
|
544
|
-
</head>
|
|
545
|
-
<body>
|
|
546
|
-
<div class="window">
|
|
547
|
-
<aside class="sidebar" aria-label="当前设置">
|
|
548
|
-
<div class="nav-item active" aria-current="page"><span data-icon="cpu" data-size="sm"></span><span class="label">单模型设置</span></div>
|
|
549
|
-
<nav id="sidebar-nav" class="nav-list sidebar-nav" aria-label="页面导航">
|
|
550
|
-
<a class="nav-item" href="#setup-guide" data-action="jump-section" data-arg="setup-guide" aria-current="location"><span data-icon="info" data-size="sm"></span><span class="label">快速开始</span></a>
|
|
551
|
-
<a class="nav-item" href="#sec-devices" data-action="jump-section" data-arg="sec-devices"><span data-icon="network" data-size="sm"></span><span class="label">设备</span></a>
|
|
552
|
-
<a class="nav-item" href="#sec-models" data-action="jump-section" data-arg="sec-models"><span data-icon="download" data-size="sm"></span><span class="label">单模型目录</span></a>
|
|
553
|
-
<a class="nav-item" href="#sec-runtime" data-action="jump-section" data-arg="sec-runtime"><span data-icon="zap" data-size="sm"></span><span class="label">本地运行时</span></a>
|
|
554
|
-
<a class="nav-item" href="#sec-hardware" data-action="jump-section" data-arg="sec-hardware"><span data-icon="monitor" data-size="sm"></span><span class="label">本机配置</span></a>
|
|
555
|
-
</nav>
|
|
556
|
-
<div class="sidebar-foot">
|
|
557
|
-
<button type="button" class="theme-btn" data-action="cycle-theme" aria-label="切换外观主题">
|
|
558
|
-
<span class="theme-icon" data-icon="sun" data-size="sm"></span><span class="theme-label">跟随系统</span>
|
|
559
|
-
</button>
|
|
560
|
-
</div>
|
|
561
|
-
</aside>
|
|
562
|
-
<main class="main">
|
|
563
|
-
<nav id="mobile-bar" class="mobile-nav" aria-label="页面导航">
|
|
564
|
-
<button type="button" class="mobile-nav-item" data-action="jump-section" data-arg="setup-guide" data-nav-top aria-current="location">总览</button>
|
|
565
|
-
<a class="mobile-nav-item" href="#sec-devices" data-action="jump-section" data-arg="sec-devices">设备</a>
|
|
566
|
-
<a class="mobile-nav-item" href="#sec-models" data-action="jump-section" data-arg="sec-models">单模型目录</a>
|
|
567
|
-
<a class="mobile-nav-item" href="#sec-runtime" data-action="jump-section" data-arg="sec-runtime">本地运行时</a>
|
|
568
|
-
<a class="mobile-nav-item" href="#sec-hardware" data-action="jump-section" data-arg="sec-hardware">本机配置</a>
|
|
569
|
-
<span class="mobile-cross-links"></span>
|
|
570
|
-
</nav>
|
|
571
|
-
<div class="scroll">
|
|
572
|
-
<div class="page-head">
|
|
573
|
-
<h1 class="page-title">本地模型设置</h1>
|
|
574
|
-
<button type="button" class="btn outline mobile-theme-btn" data-action="cycle-theme" aria-label="切换外观主题">
|
|
575
|
-
<span class="theme-icon" data-icon="sun" data-size="sm"></span><span class="theme-label">跟随系统</span>
|
|
576
|
-
</button>
|
|
577
|
-
</div>
|
|
578
|
-
<div id="page"></div>
|
|
579
|
-
</div>
|
|
580
|
-
</main>
|
|
581
|
-
</div>
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
<div id="dialog-root"></div>
|
|
585
|
-
<div id="confirm-dialog-root"></div>
|
|
586
|
-
<div id="shortcuts-dialog-root"></div>
|
|
587
|
-
<div class="tip" id="tip" role="tooltip"></div>
|
|
588
|
-
<div class="toasts" id="toasts" role="status" aria-live="polite"></div>
|
|
589
|
-
|
|
590
|
-
<script>
|
|
591
|
-
'use strict'
|
|
592
|
-
|
|
593
|
-
// ── Icons (lucide geometry, 24×24 stroke) ──
|
|
594
|
-
const ICONS = {
|
|
595
|
-
chevronRight: '<path d="m9 18 6-6-6-6"/>',
|
|
596
|
-
box: '<path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/>',
|
|
597
|
-
monitor: '<rect width="20" height="14" x="2" y="3" rx="2"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/>',
|
|
598
|
-
zap: '<path d="M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"/>',
|
|
599
|
-
cpu: '<rect width="16" height="16" x="4" y="4" rx="2"/><rect width="6" height="6" x="9" y="9" rx="1"/><path d="M15 2v2"/><path d="M15 20v2"/><path d="M2 15h2"/><path d="M2 9h2"/><path d="M20 15h2"/><path d="M20 9h2"/><path d="M9 2v2"/><path d="M9 20v2"/>',
|
|
600
|
-
archive: '<rect width="20" height="5" x="2" y="3" rx="1"/><path d="M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8"/><path d="M10 12h4"/>',
|
|
601
|
-
network: '<rect x="16" y="16" width="6" height="6" rx="1"/><rect x="2" y="16" width="6" height="6" rx="1"/><rect x="9" y="2" width="6" height="6" rx="1"/><path d="M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3"/><path d="M12 12V8"/>',
|
|
602
|
-
grid: '<rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/>',
|
|
603
|
-
info: '<circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/>',
|
|
604
|
-
search: '<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>',
|
|
605
|
-
x: '<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',
|
|
606
|
-
download: '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" x2="12" y1="15" y2="3"/>',
|
|
607
|
-
refresh: '<path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M8 16H3v5"/>',
|
|
608
|
-
checkCircle: '<circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/>',
|
|
609
|
-
check: '<path d="M20 6 9 17l-5-5"/>',
|
|
610
|
-
package: '<path d="M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z"/><path d="M12 22V12"/><path d="m3.3 7 7.703 4.734a2 2 0 0 0 1.994 0L20.7 7"/><path d="m7.5 4.27 9 5.15"/>',
|
|
611
|
-
loader: '<path d="M21 12a9 9 0 1 1-6.219-8.56"/>',
|
|
612
|
-
stop: '<rect width="14" height="14" x="5" y="5" rx="2" fill="currentColor"/>',
|
|
613
|
-
trash: '<path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/>',
|
|
614
|
-
sun: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>',
|
|
615
|
-
moon: '<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>',
|
|
616
|
-
copy: '<rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>',
|
|
617
|
-
alertTriangle: '<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><path d="M12 9v4"/><path d="M12 17h.01"/>',
|
|
618
|
-
activity: '<path d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"/>',
|
|
619
|
-
command: '<path d="M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3"/>'
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
function icon(name, size = '', extra = '') {
|
|
623
|
-
return `<svg class="i ${size} ${extra}" viewBox="0 0 24 24" aria-hidden="true">${ICONS[name]}</svg>`
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
function hydrateIcons(root = document) {
|
|
627
|
-
root.querySelectorAll('[data-icon]').forEach(el => {
|
|
628
|
-
el.insertAdjacentHTML('afterbegin', icon(el.dataset.icon, el.dataset.size || ''))
|
|
629
|
-
el.removeAttribute('data-icon')
|
|
630
|
-
})
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
const esc = s => String(s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c])
|
|
634
|
-
|
|
635
|
-
// ── API ──
|
|
636
|
-
async function api(path, options = {}) {
|
|
637
|
-
const init = { method: options.method || 'GET', headers: {} }
|
|
638
|
-
if (options.body !== undefined) {
|
|
639
|
-
init.headers['Content-Type'] = 'application/json'
|
|
640
|
-
init.body = JSON.stringify(options.body)
|
|
641
|
-
}
|
|
642
|
-
if (options.signal) init.signal = options.signal
|
|
643
|
-
const res = await fetch(`/api/${path}`, init)
|
|
644
|
-
const data = await res.json().catch(() => ({}))
|
|
645
|
-
if (!res.ok) throw Object.assign(new Error(data.error || `HTTP ${res.status}`), { status: res.status, data })
|
|
646
|
-
return data
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
// ── Copy (zh_local_models.ts where Hermes has it) ──
|
|
650
|
-
const copy = {
|
|
651
|
-
devicesTitle: '设备',
|
|
652
|
-
addDevice: '添加设备',
|
|
653
|
-
closeAddDevice: '收起',
|
|
654
|
-
addDeviceHint: '通过 SSH 连接(使用本机 ~/.ssh/config 与密钥,不会弹出密码输入)。候选来自 ssh_config、Tailscale 与局域网 mDNS。',
|
|
655
|
-
addDevicePlaceholder: 'SSH 别名或 user@host',
|
|
656
|
-
reprobe: '重新检测',
|
|
657
|
-
probing: '正在检测…',
|
|
658
|
-
runtimeTitle: '本地运行时',
|
|
659
|
-
noDeployments: '尚未部署模型',
|
|
660
|
-
noDeploymentsDetail: (tag, b) => `部署时会安装固定版本 llama.cpp ${tag}(${b} 后端),并校验 SHA256。`,
|
|
661
|
-
pinnedPresentDetail: (tag, b) => `固定版本 llama.cpp ${tag}(${b} 后端)已在本机;部署时校验 SHA256 后沿用,不再安装。`,
|
|
662
|
-
noPinnedEngine: '本机没有可用的固定版本 llama.cpp 预编译包;部署计划会说明原因。',
|
|
663
|
-
existingEngine: '已发现 llama.cpp 引擎',
|
|
664
|
-
detectedServer: '检测到运行中的 llama-server',
|
|
665
|
-
hardwareTitle: '本机配置',
|
|
666
|
-
vram: l => `${l} 显存`,
|
|
667
|
-
ram: l => `${l} 内存`,
|
|
668
|
-
modelsTitle: '单模型目录',
|
|
669
|
-
recommended: '推荐',
|
|
670
|
-
noRecommendationTitle: '此设备暂无自动推荐模型',
|
|
671
|
-
noRecommendationDetail: '当前设备事实下没有可自动推荐的模型;不代表其他候选已通过本机验收。可展开目录查看,或在目标设备终端运行完整安装命令检查套件计划。',
|
|
672
|
-
deployAction: s => (s ? `部署 · ${s}` : '部署'),
|
|
673
|
-
replanAction: s => (s ? `重新配置 · ${s}` : '重新配置'),
|
|
674
|
-
pillFitsGpu: '完全在 GPU 上运行',
|
|
675
|
-
pillFitsBusy: '容量够 · 卡上有其他程序',
|
|
676
|
-
pillFitsBusyTip: '按这张卡的总容量能完全放进显存;它现在还跑着其他程序。部署时按当前空闲显存重新计划:放得下时要在计划里确认共用,放不下时计划会说明',
|
|
677
|
-
allBusy: free => `每张卡上现在都有其他程序(空闲最多 ${free})。下面按显卡容量列出能装什么;部署时按当前空闲显存重新计划,放得下要确认共用,放不下会在计划里说明。`,
|
|
678
|
-
pillUsesRam: '使用系统内存',
|
|
679
|
-
pillUnavailable: '不可用',
|
|
680
|
-
fitReasons: new Map([['insufficient-memory', '超出本机内存'], ['unsupported-platform', '平台不支持'], ['unsupported-runtime', '此部署方式不支持']]),
|
|
681
|
-
pillFullContext: m => `完整 ${m} 上下文`,
|
|
682
|
-
pillFullContextTip: '从一开始就以模型的完整上下文窗口运行',
|
|
683
|
-
pillUpTo: m => `最高 ${m} 上下文`,
|
|
684
|
-
pillGrowsTip: '随着对话需要更多空间自动增长',
|
|
685
|
-
pillVision: '识图',
|
|
686
|
-
pillCandidate: '候选',
|
|
687
|
-
pillCandidateTip: '目录候选:还没有通过本工具的整套验收,自动推荐不会选它',
|
|
688
|
-
pillDeprecated: '已弃用',
|
|
689
|
-
pillDeprecatedTip: '已有更好的替代,保留只为已经装好的部署;新装请选其他模型',
|
|
690
|
-
pillOtherPlatform: names => `仅在 ${names} 验证`,
|
|
691
|
-
pillOtherPlatformTip: '目录只在这些平台上验收过它,本机平台没有验收记录',
|
|
692
|
-
pillSplit: '多卡切分',
|
|
693
|
-
stopServer: '关闭',
|
|
694
|
-
startServer: '开启',
|
|
695
|
-
removeAction: '移除部署',
|
|
696
|
-
status: '状态',
|
|
697
|
-
planTitle: '部署计划',
|
|
698
|
-
confirmDeploy: '确认部署',
|
|
699
|
-
shareAndDeploy: '共用 GPU 并部署',
|
|
700
|
-
planChanged: '已按当前主机重新生成计划,下面是新计划;检查后再确认部署。变化项:',
|
|
701
|
-
planKeys: { model: '模型', files: '文件', engine: '引擎', placement: '位置', launch: '上下文与启动参数', service: '服务', endpoint: '地址' },
|
|
702
|
-
gpuOccupied: '计划使用的 GPU 已被其他程序占用,未执行:',
|
|
703
|
-
gpuOccupiedAtPlan: '计划使用的 GPU 上有其他程序;部署前须勾选共用(部署时会再次检查):',
|
|
704
|
-
shareConsent: '我确认与占用这些 GPU 的程序共用(显存不足时两边都可能失败)',
|
|
705
|
-
cancel: '取消',
|
|
706
|
-
steps: { engine: '引擎', download: '下载模型', install: '安装服务', start: '启动', verify: '就绪验证' }
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
const gb = n => `${(n / (1 << 30)).toFixed(1)} GB`
|
|
710
|
-
const k = n => `${Math.floor(n / 1024)}K`
|
|
711
|
-
const THEME_KEY = 'localmodels.theme'
|
|
712
|
-
const THEME_CYCLE = ['auto', 'light', 'dark']
|
|
713
|
-
const THEME_LABEL = { auto: '跟随系统', light: '浅色', dark: '深色' }
|
|
714
|
-
const NAV_ITEMS = [
|
|
715
|
-
{ id: 'setup-guide', mobile: '总览', label: '快速开始', icon: 'info', always: true },
|
|
716
|
-
{ id: 'sec-devices', mobile: '设备', label: '设备', icon: 'network', always: true },
|
|
717
|
-
{ id: 'sec-models', mobile: '单模型目录', label: '单模型目录', icon: 'download' },
|
|
718
|
-
{ id: 'sec-runtime', mobile: '本地运行时', label: '本地运行时', icon: 'zap' },
|
|
719
|
-
{ id: 'sec-hardware', mobile: '本机配置', label: '本机配置', icon: 'monitor' }
|
|
720
|
-
]
|
|
721
|
-
|
|
722
|
-
// ── State ──
|
|
723
|
-
const state = {
|
|
724
|
-
devices: [],
|
|
725
|
-
selected: localStorageGet('localmodels.device') || 'local',
|
|
726
|
-
theme: currentTheme(),
|
|
727
|
-
activeSection: 'setup-guide',
|
|
728
|
-
catalog: null,
|
|
729
|
-
deployments: [],
|
|
730
|
-
loading: false,
|
|
731
|
-
reprobing: false,
|
|
732
|
-
error: null,
|
|
733
|
-
adding: false,
|
|
734
|
-
addingDevice: false,
|
|
735
|
-
addingTarget: '',
|
|
736
|
-
addTargetInput: '',
|
|
737
|
-
addError: null,
|
|
738
|
-
discoverError: null,
|
|
739
|
-
candidates: null,
|
|
740
|
-
confirmRemoveDevice: null,
|
|
741
|
-
removingDevice: null,
|
|
742
|
-
planning: null, // { model_id, plan_id, plan, options, error, errorTitle, busy, deploying, changed, occupied, share }
|
|
743
|
-
confirmRemove: null, // { name, busy }
|
|
744
|
-
shortcutsOpen: false,
|
|
745
|
-
modelQuery: '',
|
|
746
|
-
fitsOnly: false,
|
|
747
|
-
jobs: {}, // model id -> job
|
|
748
|
-
serviceBusy: {},
|
|
749
|
-
guideOpen: null,
|
|
750
|
-
crossLinks: []
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
function localStorageGet(key) {
|
|
754
|
-
try { return localStorage.getItem(key) } catch { return null }
|
|
755
|
-
}
|
|
756
|
-
function localStorageSet(key, value) {
|
|
757
|
-
try { localStorage.setItem(key, value) } catch { /* private window */ }
|
|
758
|
-
}
|
|
759
|
-
function localStorageRemove(key) {
|
|
760
|
-
try { localStorage.removeItem(key) } catch { /* private window */ }
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
function currentTheme() {
|
|
764
|
-
const saved = localStorageGet(THEME_KEY) || localStorageGet('lm-theme') || localStorageGet('lm-sizecalc-theme')
|
|
765
|
-
return saved === 'light' || saved === 'dark' ? saved : 'auto'
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
function effectiveTheme(mode) {
|
|
769
|
-
if (mode === 'light' || mode === 'dark') return mode
|
|
770
|
-
return typeof matchMedia === 'function' && matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
function updateThemeButtons(mode) {
|
|
774
|
-
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return
|
|
775
|
-
const next = THEME_LABEL[mode] ? mode : 'auto'
|
|
776
|
-
const iconName = effectiveTheme(next) === 'dark' ? 'moon' : 'sun'
|
|
777
|
-
const label = THEME_LABEL[next]
|
|
778
|
-
document.querySelectorAll('[data-action="cycle-theme"]').forEach(btn => {
|
|
779
|
-
btn.title = `当前主题:${label}(点击切换)`
|
|
780
|
-
btn.setAttribute('aria-label', `切换外观主题(当前:${label})`)
|
|
781
|
-
const labelEl = btn.querySelector('.theme-label')
|
|
782
|
-
if (labelEl) labelEl.textContent = label
|
|
783
|
-
const iconWrap = btn.querySelector('.theme-icon')
|
|
784
|
-
if (iconWrap) {
|
|
785
|
-
iconWrap.dataset.icon = iconName
|
|
786
|
-
iconWrap.innerHTML = icon(iconName, iconWrap.dataset.size || 'sm')
|
|
787
|
-
}
|
|
788
|
-
})
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
function applyTheme(mode) {
|
|
792
|
-
const next = THEME_LABEL[mode] ? mode : 'auto'
|
|
793
|
-
if (typeof document !== 'undefined' && document.documentElement?.dataset) {
|
|
794
|
-
if (next === 'light' || next === 'dark') document.documentElement.dataset.theme = next
|
|
795
|
-
else delete document.documentElement.dataset.theme
|
|
796
|
-
}
|
|
797
|
-
updateThemeButtons(next)
|
|
798
|
-
return next
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
function initTheme() {
|
|
802
|
-
state.theme = applyTheme(currentTheme())
|
|
803
|
-
if (typeof matchMedia === 'function') {
|
|
804
|
-
const mq = matchMedia('(prefers-color-scheme: dark)')
|
|
805
|
-
mq.addEventListener?.('change', () => {
|
|
806
|
-
if (state.theme === 'auto') updateThemeButtons('auto')
|
|
807
|
-
})
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
function navBadge(id) {
|
|
812
|
-
if (id === 'sec-devices') return state.devices.length ? String(state.devices.length) : ''
|
|
813
|
-
if (id === 'sec-models') return state.catalog ? String(state.catalog.models.length) : ''
|
|
814
|
-
if (id === 'sec-runtime') {
|
|
815
|
-
if (state.deployments.length) return String(state.deployments.length)
|
|
816
|
-
return state.catalog?.facts?.engines?.length ? '就绪' : ''
|
|
817
|
-
}
|
|
818
|
-
if (id === 'sec-hardware') {
|
|
819
|
-
const count = state.catalog?.facts?.gpus?.length
|
|
820
|
-
return count ? `${count} GPU` : ''
|
|
821
|
-
}
|
|
822
|
-
return ''
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
function navItemLabel(item) {
|
|
826
|
-
const titles = sectionTitles()
|
|
827
|
-
if (item.id === 'sec-runtime') return titles.runtime
|
|
828
|
-
if (item.id === 'sec-hardware') return titles.hardware
|
|
829
|
-
return item.label
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
function mobileItemLabel(item) {
|
|
833
|
-
const titles = sectionTitles()
|
|
834
|
-
if (item.id === 'sec-runtime') return titles.runtime
|
|
835
|
-
if (item.id === 'sec-hardware') return titles.hardware
|
|
836
|
-
return item.mobile
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
function syncActiveNav(nextId) {
|
|
840
|
-
if (!nextId) return
|
|
841
|
-
state.activeSection = nextId
|
|
842
|
-
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return
|
|
843
|
-
document.querySelectorAll('[data-action="jump-section"]').forEach(el => {
|
|
844
|
-
const disabled = el.disabled || el.getAttribute?.('aria-disabled') === 'true'
|
|
845
|
-
const active = el.dataset.arg === nextId && !disabled
|
|
846
|
-
if (active) el.setAttribute('aria-current', 'location')
|
|
847
|
-
else el.removeAttribute('aria-current')
|
|
848
|
-
})
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
function renderChrome() {
|
|
852
|
-
if (typeof document === 'undefined') return
|
|
853
|
-
const hasCat = Boolean(state.catalog)
|
|
854
|
-
const nav = document.getElementById('sidebar-nav')
|
|
855
|
-
if (nav && nav.nodeType === 1) {
|
|
856
|
-
const mainItems = NAV_ITEMS.map((item, idx) => {
|
|
857
|
-
const disabled = !item.always && !hasCat
|
|
858
|
-
const active = state.activeSection === item.id && !disabled
|
|
859
|
-
const label = navItemLabel(item)
|
|
860
|
-
const badge = navBadge(item.id)
|
|
861
|
-
return `<a class="nav-item" href="#${item.id}" data-action="jump-section" data-arg="${item.id}" title="${esc(label)}(快捷键 ${idx + 1})"${active ? ' aria-current="location"' : ''}${disabled ? ' aria-disabled="true" tabindex="-1"' : ''}>${icon(item.icon, 'sm')}<span class="label">${esc(label)}</span>${badge ? `<span class="nav-badge">${esc(badge)}</span>` : ''}</a>`
|
|
862
|
-
}).join('')
|
|
863
|
-
const tools = `
|
|
864
|
-
<div class="nav-divider" role="separator"></div>
|
|
865
|
-
<div class="nav-group-title">全景与工具</div>
|
|
866
|
-
<a class="nav-item" href="http://127.0.0.1:18490/" target="_blank" rel="noopener noreferrer" title="若本机已运行 stack view --web,直接打开整栈监控看板(默认端口 18490)">
|
|
867
|
-
${icon('activity', 'sm')}
|
|
868
|
-
<span class="label">Stack 全景看板</span>
|
|
869
|
-
<span class="nav-badge">:18490</span>
|
|
870
|
-
</a>
|
|
871
|
-
<button type="button" class="nav-item" data-action="copy-text" data-arg="python3 -m localmodels sizecalc --html" title="复制模型体量计算器命令">
|
|
872
|
-
${icon('copy', 'sm')}
|
|
873
|
-
<span class="label">体量计算器命令</span>
|
|
874
|
-
</button>
|
|
875
|
-
<button type="button" class="nav-item" data-action="open-shortcuts" title="键盘快捷键指南(? 键)">
|
|
876
|
-
${icon('command', 'sm')}
|
|
877
|
-
<span class="label">快捷键指南</span>
|
|
878
|
-
<kbd class="kbd-badge">?</kbd>
|
|
879
|
-
</button>
|
|
880
|
-
`
|
|
881
|
-
nav.innerHTML = mainItems + tools
|
|
882
|
-
}
|
|
883
|
-
const mobileBar = document.getElementById('mobile-bar')
|
|
884
|
-
if (mobileBar && mobileBar.nodeType === 1) {
|
|
885
|
-
const mobileLinks = NAV_ITEMS.map(item => {
|
|
886
|
-
const disabled = !item.always && !hasCat
|
|
887
|
-
const active = state.activeSection === item.id && !disabled
|
|
888
|
-
const label = mobileItemLabel(item)
|
|
889
|
-
if (item.id === 'setup-guide') {
|
|
890
|
-
return `<button type="button" class="mobile-nav-item" data-action="jump-section" data-arg="${item.id}" data-nav-top${active ? ' aria-current="location"' : ''}>${esc(label)}</button>`
|
|
891
|
-
}
|
|
892
|
-
return `<a class="mobile-nav-item" href="#${item.id}" data-action="jump-section" data-arg="${item.id}"${active ? ' aria-current="location"' : ''}${disabled ? ' aria-disabled="true" tabindex="-1"' : ''}>${esc(label)}</a>`
|
|
893
|
-
}).join('')
|
|
894
|
-
const crossHtml = validCrossLinks().map(item => `<a class="mobile-nav-item" href="${esc(item.url)}">${esc(item.label)}</a>`).join('')
|
|
895
|
-
mobileBar.innerHTML = `${mobileLinks}<span class="mobile-cross-links">${crossHtml}</span>`
|
|
896
|
-
}
|
|
897
|
-
updateThemeButtons(state.theme)
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
// ── Components (primitives.tsx) ──
|
|
901
|
-
function pill(tone, body, tip) {
|
|
902
|
-
const safeTip = tip ? esc(tip) : ''
|
|
903
|
-
return `<span class="pill ${tone}"${safeTip ? ` data-tip="${safeTip}" title="${safeTip}"` : ''}>${body}</span>`
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
function btn({ variant = 'outline', label = '', iconName, action, arg = '', disabled = false, tip, spin = false, extra = '', attrs = '' }) {
|
|
907
|
-
return `<button type="button" class="btn ${variant} ${extra}" data-action="${action}" data-arg="${esc(arg)}"${disabled ? ' disabled' : ''}${tip ? ` data-tip="${esc(tip)}"` : ''}${attrs}>${iconName ? icon(iconName, '', spin ? 'spin' : '') : ''}${label}</button>`
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
// A tip is also the element's description and shows on keyboard focus inside dialogs and on controls;
|
|
911
|
-
// read-only pills outside dialogs keep native `title` tooltips without adding redundant tab stops.
|
|
912
|
-
let tipIds = 0
|
|
913
|
-
function describeTips(root) {
|
|
914
|
-
if (!root || typeof root.querySelectorAll !== 'function') return
|
|
915
|
-
root.querySelectorAll('[data-tip]:not([aria-describedby])').forEach(el => {
|
|
916
|
-
const inDialog = Boolean(el.closest?.('[role="dialog"]'))
|
|
917
|
-
const isReadOnlyPill = !inDialog && Boolean(el.classList?.contains('pill'))
|
|
918
|
-
if (isReadOnlyPill) {
|
|
919
|
-
if (!el.getAttribute('title')) el.setAttribute('title', el.dataset.tip)
|
|
920
|
-
return
|
|
921
|
-
}
|
|
922
|
-
const note = document.createElement('span')
|
|
923
|
-
note.id = `tip-${++tipIds}`
|
|
924
|
-
note.hidden = true
|
|
925
|
-
note.textContent = el.dataset.tip
|
|
926
|
-
el.after(note)
|
|
927
|
-
el.setAttribute('aria-describedby', note.id)
|
|
928
|
-
if (el.matches('button')) {
|
|
929
|
-
if (!el.textContent.trim()) el.setAttribute('aria-label', el.dataset.tip)
|
|
930
|
-
} else {
|
|
931
|
-
if (inDialog && el.hasAttribute?.('title')) el.removeAttribute('title')
|
|
932
|
-
el.tabIndex = 0
|
|
933
|
-
}
|
|
934
|
-
})
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
function listRow({ title, desc = '', action = '', below = '' }) {
|
|
938
|
-
return `<div class="row"><div style="min-width:0"><div class="row-title">${title}</div>${desc ? `<div class="row-desc">${desc}</div>` : ''}${below}</div>${action ? `<div class="row-action">${action}</div>` : ''}</div>`
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
function section({ iconName, title, meta, aside = '', id = '' }, body) {
|
|
942
|
-
return `<section class="section"${id ? ` id="${id}"` : ''}><h2 class="section-heading">${icon(iconName)}<span>${esc(title)}</span>${meta ? pill('', esc(meta)) : ''}${aside ? `<span class="aside">${aside}</span>` : ''}</h2>${body}</section>`
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
function selectedHostLabel() {
|
|
946
|
-
const dev = state.devices.find(d => d.id === state.selected)
|
|
947
|
-
return dev?.label || dev?.facts?.hostname || state.catalog?.facts?.hostname || state.selected
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
function sectionTitles() {
|
|
951
|
-
if (!state.selected || state.selected === 'local') {
|
|
952
|
-
return { runtime: copy.runtimeTitle, hardware: copy.hardwareTitle }
|
|
953
|
-
}
|
|
954
|
-
const host = selectedHostLabel()
|
|
955
|
-
return {
|
|
956
|
-
runtime: `运行状态 · ${host}`,
|
|
957
|
-
hardware: `主机配置 · ${host}`
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
function syncSectionNavLabels() {
|
|
962
|
-
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return
|
|
963
|
-
const titles = sectionTitles()
|
|
964
|
-
for (const [href, text] of [['#sec-runtime', titles.runtime], ['#sec-hardware', titles.hardware]]) {
|
|
965
|
-
document.querySelectorAll(`.nav-list .nav-item[href="${href}"] .label`).forEach(el => {
|
|
966
|
-
el.textContent = text
|
|
967
|
-
if (el.parentElement) el.parentElement.title = text
|
|
968
|
-
})
|
|
969
|
-
document.querySelectorAll(`.mobile-nav .mobile-nav-item[href="${href}"]`).forEach(el => {
|
|
970
|
-
el.textContent = text
|
|
971
|
-
})
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
function shortenGpuName(name) {
|
|
976
|
-
return String(name || 'GPU').replace(/^NVIDIA (GeForce )?/i, '').trim() || 'GPU'
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
function formatGpuSummary(gpus) {
|
|
980
|
-
const counts = new Map()
|
|
981
|
-
for (const g of gpus) {
|
|
982
|
-
const short = shortenGpuName(g?.name)
|
|
983
|
-
counts.set(short, (counts.get(short) || 0) + 1)
|
|
984
|
-
}
|
|
985
|
-
const groups = [...counts.entries()].map(([name, count]) => count > 1 ? `${count}× ${name}` : name)
|
|
986
|
-
return groups.length <= 2 ? groups.join(' + ') : `${groups[0]} 等 ${gpus.length} 张卡`
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
function summarizeGpus(f) {
|
|
990
|
-
if (!f?.gpus?.length) {
|
|
991
|
-
return f ? (f.platform === 'darwin' ? 'Apple 统一内存' : '无独立 GPU') : '未检测'
|
|
992
|
-
}
|
|
993
|
-
return formatGpuSummary(f.gpus)
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
function serviceBusyKey(devId, name) {
|
|
997
|
-
return `${devId}:${name}`
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
// ── Sections ──
|
|
1001
|
-
function guideIsOpen() {
|
|
1002
|
-
if (typeof state.guideOpen === 'boolean') return state.guideOpen
|
|
1003
|
-
const collapsed = localStorageGet('localmodels.guideCollapsed')
|
|
1004
|
-
if (state.deployments.length > 0) return collapsed === '0'
|
|
1005
|
-
return collapsed !== '1'
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
function setupGuide() {
|
|
1009
|
-
const open = guideIsOpen()
|
|
1010
|
-
return `<details id="setup-guide" class="setup-guide"${open ? ' open' : ''} aria-labelledby="setup-title">
|
|
1011
|
-
<summary id="setup-title" class="setup-guide-summary"><span>单模型设置 · 快速上手与完整套件安装命令</span><span class="setup-guide-toggle">${icon('chevronRight', 'sm')}</span></summary>
|
|
1012
|
-
<div class="setup-guide-body">
|
|
1013
|
-
<p>本页只部署一个模型,不会安装完整套件。首次使用、希望装好后直接开始任务?请在<strong>要安装的设备终端</strong>运行:</p>
|
|
1014
|
-
<div class="install-command"><code class="mono">python3 -m localmodels install</code>${btn({ label: '复制完整安装命令', action: 'copy-install' })}</div>
|
|
1015
|
-
<p>完整安装:检测设备 → 生成套件计划 → 确认一次 → 安装并验收。最终组件与资源需求以计划为准;复制命令不会执行安装。</p>
|
|
1016
|
-
<p>装好后,运行 <span class="inline-cmd"><code class="mono">python3 -m localmodels stack status</code>${btn({ variant: 'ghost sm', label: '复制', iconName: 'copy', action: 'copy-cmd', arg: 'python3 -m localmodels stack status', attrs: ' aria-label="复制 stack status 命令"' })}</span> 检查各组件状态;运行 <span class="inline-cmd"><code class="mono">python3 -m localmodels stack clients</code>${btn({ variant: 'ghost sm', label: '复制', iconName: 'copy', action: 'copy-cmd', arg: 'python3 -m localmodels stack clients', attrs: ' aria-label="复制 stack clients 命令"' })}</span> 查看客户端接入方式。</p>
|
|
1017
|
-
<div class="view-hint">
|
|
1018
|
-
<span>已安装完整套件?运行 <code class="mono">python3 -m localmodels stack view --web</code> 开启全景看板(默认 <a href="http://127.0.0.1:18490/" target="_blank" rel="noopener noreferrer">127.0.0.1:18490 ↗</a>)。</span>
|
|
1019
|
-
${btn({ variant: 'ghost sm', label: '复制看板命令', iconName: 'copy', action: 'copy-text', arg: 'python3 -m localmodels stack view --web', attrs: ' aria-label="复制 stack view --web 命令"' })}
|
|
1020
|
-
</div>
|
|
1021
|
-
</div>
|
|
1022
|
-
</details>`
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
function activeDeploymentsStrip() {
|
|
1026
|
-
const list = state.deployments || []
|
|
1027
|
-
if (!list.length) return ''
|
|
1028
|
-
const ready = list.filter(r => {
|
|
1029
|
-
const live = r.liveState ?? null
|
|
1030
|
-
return live === 'running' || (live == null && r.ok)
|
|
1031
|
-
})
|
|
1032
|
-
const total = list.length
|
|
1033
|
-
const summaryPill = ready.length
|
|
1034
|
-
? pill('success', `${icon('checkCircle', 'xs')}已就绪 ${ready.length}${ready.length < total ? ` / ${total}` : ''}`)
|
|
1035
|
-
: pill(list.some(r => r.liveState === 'failed' || !r.ok) ? 'destructive' : 'warn', `已部署 ${total}(未运行)`)
|
|
1036
|
-
const endpoints = ready
|
|
1037
|
-
.map(r => {
|
|
1038
|
-
const url = r.plan?.endpoint?.base_url
|
|
1039
|
-
if (!url) return ''
|
|
1040
|
-
const label = r.plan?.model?.display_name || r.plan?.name || ''
|
|
1041
|
-
return `<span class="active-strip-ep">${label ? `<span class="active-strip-name">${esc(label)}</span>` : ''}<code class="mono">${esc(url)}</code>${btn({ variant: 'outline sm', label: '复制地址', iconName: 'copy', action: 'copy-endpoint', arg: url })}</span>`
|
|
1042
|
-
})
|
|
1043
|
-
.filter(Boolean)
|
|
1044
|
-
.join('')
|
|
1045
|
-
const fallbackNote = !endpoints && !ready.length
|
|
1046
|
-
? '<span class="hint">当前服务未运行,可前往运行时区查看状态或开启。</span>'
|
|
1047
|
-
: ''
|
|
1048
|
-
return `<div class="active-strip${ready.length ? ' is-ready' : ''}" id="active-deployments" role="region" aria-label="当前部署摘要">
|
|
1049
|
-
<div class="active-strip-main">${summaryPill}${endpoints || fallbackNote}</div>
|
|
1050
|
-
<a class="active-strip-link" href="#sec-runtime">查看详情 →</a>
|
|
1051
|
-
</div>`
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
function deviceSection() {
|
|
1055
|
-
const chips = state.devices.map(d => {
|
|
1056
|
-
const f = d.facts
|
|
1057
|
-
const gpus = summarizeGpus(f)
|
|
1058
|
-
const displayLabel = d.id === 'local' && d.label === 'this computer' ? '本机' : d.label
|
|
1059
|
-
const metaText = f ? `${f.hostname} · ${gpus}` : gpus
|
|
1060
|
-
const chipBtn = `<button type="button" class="device${d.id === state.selected ? ' active' : ''}" data-action="select-device" data-arg="${esc(d.id)}" aria-pressed="${d.id === state.selected}">
|
|
1061
|
-
${icon(d.id === 'local' ? 'monitor' : 'network', 'sm')}
|
|
1062
|
-
<span class="device-name">${esc(displayLabel)}</span>
|
|
1063
|
-
<span class="device-meta" title="${esc(metaText)}">${esc(metaText)}</span>
|
|
1064
|
-
</button>`
|
|
1065
|
-
if (d.id === 'local') return chipBtn
|
|
1066
|
-
return `<div class="device-item">${chipBtn}<button type="button" class="device-remove-btn" data-action="ask-remove-device" data-arg="${esc(d.id)}" aria-label="移除设备 ${esc(displayLabel)}"${state.removingDevice === d.id ? ' disabled' : ''}>移除</button></div>`
|
|
1067
|
-
}).join('')
|
|
1068
|
-
let body = `<div class="devices">${chips}</div>`
|
|
1069
|
-
const pendingRemove = state.confirmRemoveDevice && state.devices.find(d => d.id === state.confirmRemoveDevice && d.id !== 'local')
|
|
1070
|
-
if (pendingRemove) {
|
|
1071
|
-
const busy = state.removingDevice === pendingRemove.id
|
|
1072
|
-
body += `<div class="device-confirm-bar" role="alert"><span>将从设备列表移除「${esc(pendingRemove.label)}」(不会停止远端主机上正在运行的服务)。</span><div class="device-confirm-actions">${btn({ variant: 'outline', label: copy.cancel, action: 'cancel-remove-device', disabled: busy })}${btn({ variant: 'danger', label: busy ? '移除中…' : '确认移除', iconName: busy ? 'loader' : 'trash', spin: busy, action: 'remove-device', arg: pendingRemove.id, disabled: busy })}</div></div>`
|
|
1073
|
-
}
|
|
1074
|
-
if (state.adding) body += addDevicePanel()
|
|
1075
|
-
const aside = btn({ label: state.adding ? copy.closeAddDevice : copy.addDevice, iconName: state.adding ? 'x' : 'search', action: 'toggle-add', attrs: ` aria-expanded="${state.adding}"` })
|
|
1076
|
-
return section({ id: 'sec-devices', iconName: 'network', title: copy.devicesTitle, meta: String(state.devices.length), aside }, body)
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
function addDevicePanel() {
|
|
1080
|
-
const busy = Boolean(state.addingDevice)
|
|
1081
|
-
let html = `<div class="add-panel"><p class="hint">${copy.addDeviceHint}</p>
|
|
1082
|
-
<form class="add-form" data-form="add-device">
|
|
1083
|
-
<input name="target" value="${esc(state.addTargetInput || '')}" placeholder="${copy.addDevicePlaceholder}" autocomplete="off"${busy ? ' disabled' : ''} required>
|
|
1084
|
-
${btn({ variant: 'primary', label: busy ? '连接检测中…' : '连接并检测', iconName: busy ? 'loader' : 'zap', spin: busy, action: 'submit-add', disabled: busy })}
|
|
1085
|
-
</form>`
|
|
1086
|
-
if (state.addError) {
|
|
1087
|
-
html += `<div class="gate danger add-error" role="alert"><b>添加设备失败</b><p>${esc(state.addError)}</p></div>`
|
|
1088
|
-
}
|
|
1089
|
-
if (state.candidates === null) {
|
|
1090
|
-
html += `<p class="status-line">${icon('loader', 'xs', 'spin')}正在发现局域网设备…</p>`
|
|
1091
|
-
} else if (state.discoverError) {
|
|
1092
|
-
html += `<div class="discover-empty" role="alert"><span>自动发现失败:${esc(state.discoverError)}</span>${btn({ variant: 'outline', label: '重试发现', iconName: 'refresh', action: 'rediscover' })}</div>`
|
|
1093
|
-
} else if (!state.candidates.length) {
|
|
1094
|
-
html += `<div class="discover-empty"><span>未自动发现候选主机,可在上方直接输入 SSH 别名或 user@host。</span>${btn({ variant: 'ghost', label: '重新扫描', iconName: 'refresh', action: 'rediscover' })}</div>`
|
|
1095
|
-
} else {
|
|
1096
|
-
const known = new Set(state.devices.map(d => d.target))
|
|
1097
|
-
html += `<div class="discover-head"><span>已发现候选主机(${state.candidates.length})</span>${btn({ variant: 'ghost', label: '重新扫描', iconName: 'refresh', action: 'rediscover', disabled: busy })}</div>`
|
|
1098
|
-
html += '<div class="candidates">' + state.candidates.map(c => {
|
|
1099
|
-
const target = c.ssh_target || c.address
|
|
1100
|
-
const added = known.has(target)
|
|
1101
|
-
const connecting = busy && state.addingTarget === target
|
|
1102
|
-
return `<div class="candidate${c.online === false ? ' offline' : ''}">
|
|
1103
|
-
<span class="mono">${esc(c.label)}</span>
|
|
1104
|
-
<span class="candidate-meta">${esc(c.address)}${c.port !== 22 ? ':' + c.port : ''} · ${esc((c.sources || []).join(' + '))}${c.os ? ' · ' + esc(c.os) : ''}${c.online === false ? ' · 离线' : ''}</span>
|
|
1105
|
-
${btn({ variant: 'ghost', label: connecting ? '连接中…' : added ? '已添加' : '添加', iconName: connecting ? 'loader' : undefined, spin: connecting, action: 'add-candidate', arg: JSON.stringify({ target, label: c.label }), disabled: added || busy })}
|
|
1106
|
-
</div>`
|
|
1107
|
-
}).join('') + '</div>'
|
|
1108
|
-
}
|
|
1109
|
-
return html + '</div>'
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
function runtimeSection(facts, cat) {
|
|
1113
|
-
const engines = facts?.engines || []
|
|
1114
|
-
const servers = (facts?.llama_servers || []).filter(s => s.verified)
|
|
1115
|
-
const backend = cat.placements?.[0]?.backend || 'cpu'
|
|
1116
|
-
const aside = state.deployments.some(r => r.ok) ? pill('primary', `已部署 · ${backend}`) : engines.length ? pill('primary', `就绪 · ${backend}`) : ''
|
|
1117
|
-
let body = ''
|
|
1118
|
-
for (const rec of state.deployments) {
|
|
1119
|
-
const p = rec.plan
|
|
1120
|
-
const busy = state.serviceBusy[serviceBusyKey(state.selected, p.name)]
|
|
1121
|
-
const status = rec.liveStatus
|
|
1122
|
-
const live = rec.liveState ?? null
|
|
1123
|
-
const showCopy = p.endpoint?.base_url && (live === 'running' || (live == null && rec.ok))
|
|
1124
|
-
const showStart = live === 'stopped' || live === 'failed' || live == null
|
|
1125
|
-
const showStop = live === 'running' || (live == null && rec.ok)
|
|
1126
|
-
const startVariant = live === 'stopped' || live === 'failed' || (live == null && !rec.ok) ? 'primary' : 'outline'
|
|
1127
|
-
const statusBadge = live === 'failed'
|
|
1128
|
-
? pill('destructive', '异常')
|
|
1129
|
-
: !rec.ok
|
|
1130
|
-
? pill('destructive', '失败')
|
|
1131
|
-
: live === 'stopped'
|
|
1132
|
-
? pill('warn', '已停止')
|
|
1133
|
-
: pill('success', '已就绪')
|
|
1134
|
-
const desc = `${esc(p.model.display_name)} · ${esc(p.placement.label)} · ${k(p.launch.window)} 上下文 · <span class="mono">${esc(p.endpoint.base_url)}</span>`
|
|
1135
|
-
+ (rec.ok ? '' : `<br><span class="error-text">${esc(rec.error || '部署未完成')}</span>`)
|
|
1136
|
-
+ (status ? `<br><span class="live-status">${esc(status)}</span>` : '')
|
|
1137
|
-
body += listRow({
|
|
1138
|
-
title: `<span class="mono" style="font-weight:500">${esc(p.service.name)}</span>${statusBadge}`,
|
|
1139
|
-
desc,
|
|
1140
|
-
action: [
|
|
1141
|
-
showCopy ? btn({ variant: 'ghost', label: '复制地址', iconName: 'copy', action: 'copy-endpoint', arg: p.endpoint.base_url, disabled: Boolean(busy), attrs: ` aria-label="复制服务端点 ${esc(p.endpoint.base_url)}"` }) : '',
|
|
1142
|
-
btn({ variant: 'ghost', label: copy.status, iconName: busy === 'status' ? 'loader' : 'refresh', spin: busy === 'status', action: 'service', arg: `${p.name}:status`, disabled: Boolean(busy) }),
|
|
1143
|
-
showStart ? btn({ variant: startVariant, label: copy.startServer, iconName: busy === 'start' ? 'loader' : 'zap', spin: busy === 'start', action: 'service', arg: `${p.name}:start`, disabled: Boolean(busy) }) : '',
|
|
1144
|
-
showStop ? btn({ label: copy.stopServer, iconName: busy === 'stop' ? 'loader' : 'stop', spin: busy === 'stop', action: 'service', arg: `${p.name}:stop`, disabled: Boolean(busy) }) : '',
|
|
1145
|
-
btn({ variant: 'ghost icon', iconName: 'trash', action: 'service', arg: `${p.name}:remove`, disabled: Boolean(busy), tip: copy.removeAction })
|
|
1146
|
-
].filter(Boolean).join('')
|
|
1147
|
-
})
|
|
1148
|
-
}
|
|
1149
|
-
for (const s of servers) {
|
|
1150
|
-
body += listRow({ title: copy.detectedServer, desc: `端口 ${s.port} · ${esc(s.build_info)} · ${esc(s.model_path || '路由模式')}${s.n_ctx ? ` · ${k(s.n_ctx)} 上下文` : ''}` })
|
|
1151
|
-
}
|
|
1152
|
-
for (const e of engines) {
|
|
1153
|
-
body += listRow({ title: copy.existingEngine, desc: `<span class="mono">${esc(e.path)}</span> · ${esc(e.build || e.version || '版本未知')}${e.commit ? ' · ' + esc(e.commit) : ''}` })
|
|
1154
|
-
}
|
|
1155
|
-
if (!state.deployments.length) {
|
|
1156
|
-
// engine_pin: the build a deploy installs on this host (engines.json) and whether it is here.
|
|
1157
|
-
const pin = cat.engine_pin
|
|
1158
|
-
const detail = !pin ? copy.noPinnedEngine
|
|
1159
|
-
: pin.present ? copy.pinnedPresentDetail(pin.tag, pin.backend) : copy.noDeploymentsDetail(pin.tag, pin.backend)
|
|
1160
|
-
body += listRow({ title: copy.noDeployments, desc: esc(detail) })
|
|
1161
|
-
}
|
|
1162
|
-
return section({ id: 'sec-runtime', iconName: 'zap', title: sectionTitles().runtime, meta: engines[0]?.build || '', aside }, body)
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
function hardwareSection(facts) {
|
|
1166
|
-
const f = facts || {}
|
|
1167
|
-
const gpus = f.gpus || []
|
|
1168
|
-
let body = ''
|
|
1169
|
-
if (state.reprobing) {
|
|
1170
|
-
body += `<div class="refresh-banner" role="status" aria-live="polite">${icon('loader', 'xs', 'spin')}<span>正在重新检测设备硬件…</span></div>`
|
|
1171
|
-
}
|
|
1172
|
-
body += `<div class="hw">
|
|
1173
|
-
<span>${icon('box', 'sm')}${esc(f.hostname || '未知主机')} · ${esc(f.os?.distro || f.platform || '未知系统')}</span>
|
|
1174
|
-
${f.ram ? `<span>${icon('package', 'sm')}${copy.ram(gb(f.ram.total_bytes))}(可用 ${gb(f.ram.available_bytes)})</span>` : ''}
|
|
1175
|
-
${f.nvidia ? `<span>${icon('zap', 'sm')}驱动 ${esc(f.nvidia.driver_version)} · CUDA ${esc(f.nvidia.cuda_version)}</span>` : ''}
|
|
1176
|
-
${f.disk?.free_bytes != null ? `<span>${icon('archive', 'sm')}模型目录剩余 ${gb(f.disk.free_bytes)}</span>` : ''}
|
|
1177
|
-
</div>`
|
|
1178
|
-
if (gpus.length) {
|
|
1179
|
-
body += '<div class="gpus">' + gpus.map(g => {
|
|
1180
|
-
const usedPct = g.total_bytes ? Math.max(0, Math.min(100, Math.round((1 - g.free_bytes / g.total_bytes) * 100))) : 0
|
|
1181
|
-
const usedBytes = Math.max(0, (g.total_bytes || 0) - (g.free_bytes || 0))
|
|
1182
|
-
const busy = g.free_bytes < g.total_bytes * 0.9
|
|
1183
|
-
const util = g.utilization_gpu ?? g.util_percent
|
|
1184
|
-
return `<div class="gpu"><span class="gpu-name" title="GPU ${g.index} · ${esc(g.name)}">${icon('cpu', 'sm')}<span class="gpu-label">GPU ${g.index} · ${esc(g.name)}</span></span>
|
|
1185
|
-
<span class="gpu-bar${busy ? ' busy' : ''}"><span style="width:${usedPct}%"></span></span>
|
|
1186
|
-
<span class="gpu-meta${usedPct >= 85 ? ' warn' : ''}">已用 ${gb(usedBytes)} / ${gb(g.total_bytes)} (${usedPct}%) · 空闲 ${gb(g.free_bytes)}${util != null ? ` · 利用率 ${esc(util)}%` : ''}</span>${busy ? pill('warn', '占用中', '其他进程正在使用这张卡的显存;部署会优先选择空闲卡') : ''}</div>`
|
|
1187
|
-
}).join('') + '</div>'
|
|
1188
|
-
} else {
|
|
1189
|
-
body += `<p class="hint">${f.gpu_vendor_class === 'apple_silicon' ? '统一内存:按系统内存的 80% 计价' : '未发现 NVIDIA GPU:按 CPU + 内存计价'}</p>`
|
|
1190
|
-
}
|
|
1191
|
-
const collected = f.collected_at ? new Date(f.collected_at) : null
|
|
1192
|
-
const collectedStr = collected && !Number.isNaN(collected.getTime()) ? collected.toLocaleString() : ''
|
|
1193
|
-
if (collectedStr) body += `<p class="hint" style="margin-top:6px">检测于 ${esc(collectedStr)}</p>`
|
|
1194
|
-
const aside = btn({ variant: 'ghost', label: state.loading ? copy.probing : copy.reprobe, iconName: state.loading ? 'loader' : 'refresh', spin: state.loading, action: 'reprobe', disabled: state.loading })
|
|
1195
|
-
return section({ id: 'sec-hardware', iconName: 'monitor', title: sectionTitles().hardware, aside }, body)
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
|
-
function jobBelow(job) {
|
|
1199
|
-
if (!job) return ''
|
|
1200
|
-
const p = job.progress
|
|
1201
|
-
const pct = p?.total ? Math.min(100, (p.done / p.total) * 100) : null
|
|
1202
|
-
const stepName = copy.steps[job.step] || job.step || '准备'
|
|
1203
|
-
let text = `${stepName}`
|
|
1204
|
-
if (p?.total) text += ` · ${esc(p.file || '')} · ${gb(p.done)} / ${gb(p.total)}${p.bytes_per_s ? ` · ${(p.bytes_per_s / 1048576).toFixed(1)} MB/s` : ''}${p.phase === 'verify' ? ' · 校验 SHA256' : ''}`
|
|
1205
|
-
else if (p?.phase === 'loading') text += ' · 正在加载模型'
|
|
1206
|
-
const last = job.events?.filter(e => e.event === 'log').slice(-1)[0]
|
|
1207
|
-
if (job.state === 'error') text = `<span class="error-text">失败(${esc(stepName)}):${esc(job.error || '')}</span>`
|
|
1208
|
-
if (job.state === 'done') {
|
|
1209
|
-
const url = job.record?.plan?.endpoint?.base_url || ''
|
|
1210
|
-
text = url
|
|
1211
|
-
? `<span class="job-done-line">已就绪 · <span class="mono">${esc(url)}</span>${btn({ variant: 'ghost sm', label: '复制地址', iconName: 'copy', action: 'copy-endpoint', arg: url })}</span>`
|
|
1212
|
-
: '已就绪'
|
|
1213
|
-
}
|
|
1214
|
-
const bar = job.state === 'running'
|
|
1215
|
-
? pct == null
|
|
1216
|
-
? '<div class="progress indeterminate"><div></div></div>'
|
|
1217
|
-
: `<div class="progress"><div style="width:${pct}%"></div></div>`
|
|
1218
|
-
: ''
|
|
1219
|
-
return `<div class="below">${bar}<div class="progress-text">${text}${job.state === 'running' && last ? ` · ${esc(last.message)}` : ''}</div></div>`
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
// The catalog rows price each card's capacity, not its free memory now (budget.placements);
|
|
1223
|
-
// a row on a card someone else is using says so instead of promising it runs there.
|
|
1224
|
-
function busyCard(m) {
|
|
1225
|
-
const pl = m.placement && (state.catalog.placements || []).find(p => p.id === m.placement.id)
|
|
1226
|
-
return Boolean(pl && pl.busy)
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
function catalogRow(m, shared, recommended = false) {
|
|
1230
|
-
const job = state.jobs[m.id]
|
|
1231
|
-
const deployed = state.deployments.find(r => r.plan?.model?.id === m.id && r.ok)
|
|
1232
|
-
let action
|
|
1233
|
-
if (job && job.state === 'running') {
|
|
1234
|
-
action = btn({ label: copy.steps[job.step] || '准备', iconName: 'loader', spin: true, action: 'noop', disabled: true })
|
|
1235
|
-
} else {
|
|
1236
|
-
action = (deployed ? pill('primary', `${icon('check')}已部署`, deployed.plan?.endpoint?.base_url) : '')
|
|
1237
|
-
+ (m.status === 'deprecated' ? '' : btn({
|
|
1238
|
-
variant: recommended && !deployed ? 'primary' : 'outline',
|
|
1239
|
-
label: deployed ? copy.replanAction(m.size_label) : copy.deployAction(m.size_label),
|
|
1240
|
-
iconName: deployed ? 'refresh' : 'download',
|
|
1241
|
-
action: 'plan',
|
|
1242
|
-
arg: m.id,
|
|
1243
|
-
disabled: !m.fits
|
|
1244
|
-
}))
|
|
1245
|
-
}
|
|
1246
|
-
const fitTip = [m.quant_reason, m.fit_summary].filter(Boolean).join('。') || undefined
|
|
1247
|
-
const fitPill = !m.fits
|
|
1248
|
-
? pill('destructive', `${icon('cpu')}${copy.fitReasons.get(m.fit_reason) || copy.pillUnavailable}`, m.fit_detail || m.fit_summary)
|
|
1249
|
-
: m.spilled
|
|
1250
|
-
? pill('warn', `${icon('cpu')}${copy.pillUsesRam}`, fitTip)
|
|
1251
|
-
: busyCard(m)
|
|
1252
|
-
? pill('warn', `${icon('cpu')}${copy.pillFitsBusy}`, copy.pillFitsBusyTip)
|
|
1253
|
-
: pill('success', `${icon('cpu')}${copy.pillFitsGpu}`, fitTip)
|
|
1254
|
-
const full = m.fits && m.start_window && m.start_window >= m.native_context
|
|
1255
|
-
const ctxPill = full
|
|
1256
|
-
? pill(m.spilled ? '' : 'success', copy.pillFullContext(m.native_context_label), copy.pillFullContextTip)
|
|
1257
|
-
: pill('', copy.pillUpTo(m.native_context_label), m.fits ? copy.pillGrowsTip : undefined)
|
|
1258
|
-
// A pooled label names its cards in brackets, ASCII "2-GPU layer split (GPU 0,1)" or full-width.
|
|
1259
|
-
const cards = m.placement?.label.match(/[((]([^))]*)[))]/)?.[1]
|
|
1260
|
-
const where = m.placement ? pill(m.placement.pooled ? 'warn' : '', esc(m.placement.pooled ? (cards ? `${copy.pillSplit} · ${cards}` : copy.pillSplit) : m.placement.label.split(' · ')[0]), m.placement.pooled ? '单卡放不下,按层切分到多张卡;显存估算未经实测校准' : '部署时会选择空闲显存最多的同型号卡') : ''
|
|
1261
|
-
const desc = `${esc(m.description)}<span class="pills">${fitPill}${ctxPill}${m.vision ? pill('', copy.pillVision) : ''}${where}${m.quant && !shared ? pill('', esc(m.quant)) : ''}</span>`
|
|
1262
|
-
const recTip = state.catalog.recommendation?.reason_text
|
|
1263
|
-
const status = statusPill(m, state.catalog.facts?.platform)
|
|
1264
|
-
// Builds of one model share a display name; the quant tells the rows apart at a glance.
|
|
1265
|
-
const name = shared && m.quant ? `${m.display_name} · ${m.quant}` : m.display_name
|
|
1266
|
-
const title = `${esc(name)}${recommended ? pill('primary', copy.recommended, recTip) : ''}${status}`
|
|
1267
|
-
return listRow({ title, desc, action, below: jobBelow(job) })
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
const PLATFORM_NAMES = { linux: 'Linux', darwin: 'macOS', win32: 'Windows' }
|
|
1271
|
-
|
|
1272
|
-
// 0 validated on this platform, 1 candidate or validated elsewhere, 2 deprecated.
|
|
1273
|
-
function statusRank(m, platform) {
|
|
1274
|
-
if (m.status === 'deprecated') return 2
|
|
1275
|
-
if (m.status !== 'validated') return 1
|
|
1276
|
-
return m.validated_on?.length && !m.validated_on.includes(platform) ? 1 : 0
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
function statusPill(m, platform) {
|
|
1280
|
-
if (m.status === 'deprecated') return pill('destructive', copy.pillDeprecated, copy.pillDeprecatedTip)
|
|
1281
|
-
if (m.status !== 'validated') return pill('', copy.pillCandidate, copy.pillCandidateTip)
|
|
1282
|
-
if (statusRank(m, platform) === 0) return ''
|
|
1283
|
-
const names = m.validated_on.map(v => PLATFORM_NAMES[v] || v).join('、')
|
|
1284
|
-
return pill('warn', copy.pillOtherPlatform(names), copy.pillOtherPlatformTip)
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
function catalogPartition(cat) {
|
|
1288
|
-
const recommended = cat.facts && cat.models.find(m => m.recommended && m.id === cat.recommendation?.id && m.status !== 'deprecated')
|
|
1289
|
-
const rank = m => (m.fits && !m.spilled ? 0 : m.fits ? 1 : 2)
|
|
1290
|
-
const platform = cat.facts?.platform
|
|
1291
|
-
// Deprecated rows sink whatever they fit; otherwise what fits comes first, validated ahead.
|
|
1292
|
-
const key = m => (m.status === 'deprecated' ? 6 : 0) + rank(m) * 2 + Math.min(statusRank(m, platform), 1)
|
|
1293
|
-
const rows = [...cat.models].sort((a, b) => key(a) - key(b))
|
|
1294
|
-
const named = rows.reduce((n, m) => n.set(m.display_name, (n.get(m.display_name) || 0) + 1), new Map())
|
|
1295
|
-
const alternatives = rows.filter(m => m !== recommended)
|
|
1296
|
-
return { recommended, named, alternatives }
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
function filterAlternatives(alternatives) {
|
|
1300
|
-
const query = (state.modelQuery || '').trim().toLowerCase()
|
|
1301
|
-
return alternatives.filter(m => {
|
|
1302
|
-
if (state.fitsOnly && (!m.fits || m.status === 'deprecated')) return false
|
|
1303
|
-
if (!query) return true
|
|
1304
|
-
return [
|
|
1305
|
-
m.id,
|
|
1306
|
-
m.display_name,
|
|
1307
|
-
m.quant,
|
|
1308
|
-
m.description,
|
|
1309
|
-
m.fit_summary,
|
|
1310
|
-
m.quant_reason
|
|
1311
|
-
].some(v => v && String(v).toLowerCase().includes(query))
|
|
1312
|
-
})
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
function alternativeRowsHtml(cat, partition = catalogPartition(cat)) {
|
|
1316
|
-
const filtered = filterAlternatives(partition.alternatives)
|
|
1317
|
-
return filtered.length
|
|
1318
|
-
? `<div class="rows">${filtered.map(m => catalogRow(m, partition.named.get(m.display_name) > 1)).join('')}</div>`
|
|
1319
|
-
: '<p class="hint catalog-empty">未找到匹配的模型。</p>'
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
function refreshCatalogResults() {
|
|
1323
|
-
if (!state.catalog || typeof document === 'undefined' || typeof document.querySelector !== 'function') return false
|
|
1324
|
-
const container = document.querySelector('.model-alternatives-list')
|
|
1325
|
-
if (!container) return false
|
|
1326
|
-
const partition = catalogPartition(state.catalog)
|
|
1327
|
-
const filtered = filterAlternatives(partition.alternatives)
|
|
1328
|
-
container.innerHTML = filtered.length
|
|
1329
|
-
? `<div class="rows">${filtered.map(m => catalogRow(m, partition.named.get(m.display_name) > 1)).join('')}</div>`
|
|
1330
|
-
: '<p class="hint catalog-empty">未找到匹配的模型。</p>'
|
|
1331
|
-
describeTips(container)
|
|
1332
|
-
const countEl = document.querySelector('.catalog-match-count')
|
|
1333
|
-
if (countEl) {
|
|
1334
|
-
const active = Boolean((state.modelQuery || '').trim() || state.fitsOnly)
|
|
1335
|
-
countEl.hidden = !active
|
|
1336
|
-
countEl.textContent = active ? `匹配 ${filtered.length} / ${partition.alternatives.length}` : ''
|
|
1337
|
-
}
|
|
1338
|
-
return true
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
function modelsSection(cat) {
|
|
1342
|
-
let body = ''
|
|
1343
|
-
const partition = catalogPartition(cat)
|
|
1344
|
-
const { recommended, named, alternatives } = partition
|
|
1345
|
-
if (!recommended) {
|
|
1346
|
-
body += listRow({ title: copy.noRecommendationTitle, desc: copy.noRecommendationDetail })
|
|
1347
|
-
}
|
|
1348
|
-
const gpuPlacements = (cat.placements || []).filter(p => p.gpu_indices && p.gpu_indices.length && !p.uma)
|
|
1349
|
-
if (gpuPlacements.length && gpuPlacements.every(p => p.busy)) {
|
|
1350
|
-
const free = Math.max(...(cat.facts?.gpus || []).map(g => g.free_bytes))
|
|
1351
|
-
body += `<p class="hint busy-note">${icon('cpu', 'sm')}${esc(copy.allBusy(gb(free)))}</p>`
|
|
1352
|
-
}
|
|
1353
|
-
if (recommended) {
|
|
1354
|
-
body += `<div class="recommended-model"><p class="recommendation-note">此设备的单模型推荐 · 下一步:点击「部署」查看计划,确认后才执行。仅部署此模型不等于完整套件就绪。</p>${catalogRow(recommended, named.get(recommended.display_name) > 1, true)}${cat.recommendation.reason_text ? `<p class="recommendation-note">推荐依据:${esc(cat.recommendation.reason_text)}</p>` : ''}</div>`
|
|
1355
|
-
}
|
|
1356
|
-
const filterActive = Boolean((state.modelQuery || '').trim() || state.fitsOnly)
|
|
1357
|
-
if (alternatives.length) {
|
|
1358
|
-
const filtered = filterAlternatives(alternatives)
|
|
1359
|
-
const toolbar = `<div class="catalog-toolbar">
|
|
1360
|
-
<label class="search-field catalog-search">${icon('search', 'sm')}<input type="search" name="model-query" value="${esc(state.modelQuery || '')}" placeholder="搜索模型名称、量化格式或说明…" aria-label="搜索模型目录"></label>
|
|
1361
|
-
<label class="filter-chip"><input type="checkbox" name="fits-only" data-action="toggle-fits-only"${state.fitsOnly ? ' checked' : ''}>仅看本机可用</label>
|
|
1362
|
-
<span class="hint catalog-match-count"${filterActive ? '' : ' hidden'}>${filterActive ? `匹配 ${filtered.length} / ${alternatives.length}` : ''}</span>
|
|
1363
|
-
</div>`
|
|
1364
|
-
const rowsHtml = filtered.length
|
|
1365
|
-
? `<div class="rows">${filtered.map(m => catalogRow(m, named.get(m.display_name) > 1)).join('')}</div>`
|
|
1366
|
-
: '<p class="hint catalog-empty">未找到匹配的模型。</p>'
|
|
1367
|
-
body += `<details class="model-alternatives"${filterActive ? ' open' : ''}><summary>${recommended ? '其他模型与历史条目' : '查看模型目录'}(${alternatives.length})</summary><p class="hint">候选与仅在其他平台验证的条目不代表本机已通过验收。已弃用条目仅供查询,已有部署可在「${esc(sectionTitles().runtime)}」管理。</p>${toolbar}<div class="model-alternatives-list">${rowsHtml}</div></details>`
|
|
1368
|
-
}
|
|
1369
|
-
return section({ id: 'sec-models', iconName: 'download', title: copy.modelsTitle, meta: String(cat.models.length) }, body)
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
function validPort(value) {
|
|
1373
|
-
const raw = String(value ?? '').trim()
|
|
1374
|
-
if (!/^\d+$/.test(raw)) return false
|
|
1375
|
-
const n = Number(raw)
|
|
1376
|
-
return Number.isInteger(n) && n >= 1024 && n <= 65535
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
function planOptionsChanged(pl) {
|
|
1380
|
-
if (!pl.plan || !pl.plannedOptions) return false
|
|
1381
|
-
return Object.keys(pl.options).some(key => {
|
|
1382
|
-
if (key === 'port') {
|
|
1383
|
-
const a = pl.options.port
|
|
1384
|
-
const b = pl.plannedOptions.port
|
|
1385
|
-
if (validPort(a) && validPort(b)) return Number(a) !== Number(b)
|
|
1386
|
-
return String(a ?? '').trim() !== String(b ?? '').trim()
|
|
1387
|
-
}
|
|
1388
|
-
return pl.options[key] !== pl.plannedOptions[key]
|
|
1389
|
-
})
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
function planDeployDisabled(pl) {
|
|
1393
|
-
return Boolean(!pl.plan || pl.busy || !validPort(pl.options?.port) || planOptionsChanged(pl) || (pl.occupied?.length && !pl.share))
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
|
-
// What confirming does, beside the button: the TUI's confirmation lines from the same plan
|
|
1397
|
-
// fields, then any context or memory downgrade and the share consent the button waits for.
|
|
1398
|
-
function planSummary(pl) {
|
|
1399
|
-
const p = pl.plan
|
|
1400
|
-
if (!p) return ''
|
|
1401
|
-
const s = p.service || {}
|
|
1402
|
-
const lines = [
|
|
1403
|
-
['', `下载 ${gb(p.model.download_bytes)}(${(p.files || []).length} 个文件,已校验的跳过)`]
|
|
1404
|
-
]
|
|
1405
|
-
if (s.deploy_dir) lines.push(['', `写入 ${s.deploy_dir},服务 ${s.name}`])
|
|
1406
|
-
else if (s.name) lines.push(['', `服务 ${s.name}`])
|
|
1407
|
-
const listen = s.bind != null && s.port != null ? `${s.bind}:${s.port}` : (p.endpoint?.base_url || '')
|
|
1408
|
-
if (s.kind && listen) lines.push(['', `启动 ${s.kind} 服务,监听 ${listen}`])
|
|
1409
|
-
const native = state.catalog?.models?.find(m => m.id === pl.model_id)?.native_context
|
|
1410
|
-
if (native && p.launch.window < native) lines.push(['warn', `上下文 ${k(p.launch.window)}(模型最高 ${k(native)})`])
|
|
1411
|
-
if (p.launch.spilled) lines.push(['warn', `${gb(p.launch.spill_bytes)} 权重放到系统内存,解码更慢`])
|
|
1412
|
-
if (pl.occupied?.length && !pl.share) lines.push(['danger', '与其他程序共用 GPU:勾选上方的共用确认后才能部署'])
|
|
1413
|
-
return `<ul class="foot-summary" id="plan-summary" aria-label="确认后将执行">${lines.map(([tone, text]) => `<li${tone ? ` class="${tone}"` : ''}>${esc(text)}</li>`).join('')}</ul>`
|
|
1414
|
-
}
|
|
1415
|
-
|
|
1416
|
-
function planDialog() {
|
|
1417
|
-
const pl = state.planning
|
|
1418
|
-
if (!pl) return ''
|
|
1419
|
-
let body
|
|
1420
|
-
if (pl.busy && !pl.plan) {
|
|
1421
|
-
body = `<p class="status-line">${icon('loader', 'xs', 'spin')}正在重新检测主机并生成计划(读取当前空闲显存、解析 Hugging Face 文件哈希)…</p>`
|
|
1422
|
-
} else if (pl.error && !pl.plan) {
|
|
1423
|
-
if (pl.conflict) {
|
|
1424
|
-
const conflict = pl.conflict
|
|
1425
|
-
body = `<div class="gate warn" role="alert"><b>当前显卡有其他服务</b>
|
|
1426
|
-
<span>可换空闲显卡;如确需共用,先在“位置”选择具体显卡,点击“重新计划”,再按批准流程确认共用。生成计划不代表已授权,不会停止已有服务。</span>
|
|
1427
|
-
<b>${esc(conflict.label)}</b><ul>${(conflict.occupants || []).map(occupant => `<li>${esc(occupant)}</li>`).join('')}</ul>
|
|
1428
|
-
${(conflict.gpus || []).map(gpu => `<span>GPU ${esc(gpu.index)} · ${esc(gpu.name)} · 已用 ${gb(gpu.used_bytes)} · 可用 ${gb(gpu.free_bytes)} · 总计 ${gb(gpu.total_bytes)}</span>`).join('')}
|
|
1429
|
-
<span>来源:本次计划的主机检测(${esc(conflict.collected_at || '未知时间')});重新计划时会再次检查。</span></div>
|
|
1430
|
-
<details><summary>原始诊断</summary><p class="error-text">${esc(pl.error)}</p></details>`
|
|
1431
|
-
} else {
|
|
1432
|
-
body = `<div class="gate danger" role="alert"><b>${esc(pl.errorTitle || '无法生成部署计划')}</b><p>${esc(pl.error)}</p></div>`
|
|
1433
|
-
}
|
|
1434
|
-
} else {
|
|
1435
|
-
const p = pl.plan
|
|
1436
|
-
const changed = pl.changed || []
|
|
1437
|
-
const mark = (...keys) => keys.some(key => changed.includes(key)) ? ' class="changed"' : ''
|
|
1438
|
-
const row = (keys, label, value) => `<dt${mark(...keys)}>${label}</dt><dd${mark(...keys)}>${value}</dd>`
|
|
1439
|
-
const planFiles = p.files || []
|
|
1440
|
-
const files = planFiles.map(f => `<li class="plan-file-item"><span class="mono">${esc(f.local_name)}</span> · ${gb(f.size_bytes)}${f.sha256 ? ` · <span class="mono" data-tip="${esc(f.sha256)}">sha256 ${esc(f.sha256.slice(0, 12))}…</span>${btn({ variant: 'ghost sm', label: '复制 SHA256', iconName: 'copy', action: 'copy-sha256', arg: f.sha256, attrs: ` aria-label="复制 SHA256(${esc(f.local_name)})"` })}` : ''}</li>`).join('')
|
|
1441
|
-
let fileOrigin = ''
|
|
1442
|
-
try { if (planFiles[0]?.url) fileOrigin = new URL(planFiles[0].url).origin } catch { /* ignore invalid url */ }
|
|
1443
|
-
const engine = p.engine.source === 'release'
|
|
1444
|
-
? `llama.cpp ${esc(p.engine.build)}(${esc(p.engine.backend)}${p.engine.min_cuda ? ' · CUDA ' + esc(p.engine.min_cuda) : ''})官方预编译包,SHA256 固定`
|
|
1445
|
-
: `复用 <span class="mono">${esc(p.engine.binary)}</span>`
|
|
1446
|
-
body = ''
|
|
1447
|
-
if (pl.error) {
|
|
1448
|
-
body += `<div class="gate danger gate-top" role="alert"><b>${esc(pl.errorTitle || '部署失败')}</b><p>${esc(pl.error)}</p></div>`
|
|
1449
|
-
}
|
|
1450
|
-
if (changed.length) {
|
|
1451
|
-
body += `<div class="gate warn"><b>${esc(pl.refusal)}</b><span>${copy.planChanged}${changed.map(key => `<span class="mono">${esc(key)}</span>(${esc(copy.planKeys[key] || key)})`).join('、')}</span></div>`
|
|
1452
|
-
}
|
|
1453
|
-
if (pl.occupied?.length) {
|
|
1454
|
-
body += `<div class="gate danger" role="alert"><b>${pl.occupiedAt === 'plan' ? copy.gpuOccupiedAtPlan : copy.gpuOccupied}</b><ul>${pl.occupied.map(b => `<li>${esc(b)}</li>`).join('')}</ul>
|
|
1455
|
-
<label><input type="checkbox" data-action="toggle-share"${pl.share ? ' checked' : ''}>${copy.shareConsent}</label></div>`
|
|
1456
|
-
}
|
|
1457
|
-
const placementGpus = p.placement?.gpus || []
|
|
1458
|
-
const launchReasons = p.launch?.reasons || []
|
|
1459
|
-
const serviceArgv = p.service?.argv || []
|
|
1460
|
-
const fullCmd = serviceArgv.join(' ')
|
|
1461
|
-
const launchArgs = serviceArgv.slice(1).join(' ')
|
|
1462
|
-
const launchActions = [
|
|
1463
|
-
launchArgs ? btn({ variant: 'ghost sm', label: '复制参数', iconName: 'copy', action: 'copy-text', arg: launchArgs, attrs: ' aria-label="复制启动参数"' }) : '',
|
|
1464
|
-
fullCmd ? btn({ variant: 'ghost sm', label: '复制命令', iconName: 'copy', action: 'copy-cmd', arg: fullCmd }) : ''
|
|
1465
|
-
].filter(Boolean).join('')
|
|
1466
|
-
const launchHtml = `<div class="code-box">${launchActions ? `<div class="code-box-actions">${launchActions}</div>` : ''}<pre>${esc(launchArgs)}</pre></div>`
|
|
1467
|
-
const warnings = p.warnings || []
|
|
1468
|
-
body += `<dl class="plan">
|
|
1469
|
-
<dt>主机</dt><dd>${esc(p.hostname)}(${esc(p.host)})</dd>
|
|
1470
|
-
${row(['placement'], '位置', `${esc(p.placement.label)}${placementGpus.length ? ` · <span class="mono">${esc(placementGpus.map(g => g.uuid).join(', '))}</span>` : ''}`)}
|
|
1471
|
-
${row(['launch'], '上下文', `${k(p.launch.window)}${p.launch.spilled ? ` · ${gb(p.launch.spill_bytes)} 权重放到系统内存` : ' · 全部在 GPU'}${launchReasons.length ? ` · <span class="hint">${esc(launchReasons.join(';'))}</span>` : ''}`)}
|
|
1472
|
-
${row(['engine'], '引擎', engine)}
|
|
1473
|
-
${row(['model', 'files'], '文件', `<ul>${files}</ul>共 ${gb(p.model.download_bytes)}${fileOrigin ? `,下载源 <span class="mono">${esc(fileOrigin)}</span>` : ''}`)}
|
|
1474
|
-
${row(['service', 'endpoint'], '服务', `${esc(p.service.kind)} · <span class="mono">${esc(p.service.name)}</span> · ${esc(p.endpoint.base_url)}`)}
|
|
1475
|
-
${row(['launch', 'service'], '启动参数', launchHtml)}
|
|
1476
|
-
</dl>`
|
|
1477
|
-
if (warnings.length) body += `<ul class="warnings">${warnings.map(w => `<li>${icon('info', 'xs')}${esc(w)}</li>`).join('')}</ul>`
|
|
1478
|
-
}
|
|
1479
|
-
const o = pl.options
|
|
1480
|
-
const placements = state.catalog?.placements || []
|
|
1481
|
-
const deploying = Boolean(pl.deploying)
|
|
1482
|
-
const replanning = Boolean(pl.busy && !deploying)
|
|
1483
|
-
const stale = planOptionsChanged(pl)
|
|
1484
|
-
const formDisabled = deploying ? ' disabled' : ''
|
|
1485
|
-
const form = `<form class="plan-form" data-form="replan">
|
|
1486
|
-
<label>位置<select name="placement_id"${formDisabled}>
|
|
1487
|
-
<option value="auto"${o.placement_id === 'auto' ? ' selected' : ''}>自动(空闲显存最多)</option>
|
|
1488
|
-
${placements.map(p => `<option value="${esc(p.id)}"${o.placement_id === p.id ? ' selected' : ''}>${esc(p.label)}${p.busy ? '(占用中)' : ''}</option>`).join('')}
|
|
1489
|
-
</select></label>
|
|
1490
|
-
<label>端口<input name="port" type="number" min="1024" max="65535" value="${esc(o.port)}"${formDisabled}></label>
|
|
1491
|
-
<label>监听<select name="bind"${formDisabled}><option value="127.0.0.1"${o.bind === '127.0.0.1' ? ' selected' : ''}>仅本机(SSH 隧道访问)</option><option value="0.0.0.0"${o.bind === '0.0.0.0' ? ' selected' : ''}>局域网(API 密钥保护)</option></select></label>
|
|
1492
|
-
<label>下载源<select name="hf_download_endpoint"${formDisabled}><option value="https://huggingface.co"${o.hf_download_endpoint === 'https://huggingface.co' ? ' selected' : ''}>huggingface.co</option><option value="https://hf-mirror.com"${o.hf_download_endpoint === 'https://hf-mirror.com' ? ' selected' : ''}>hf-mirror.com</option></select></label>
|
|
1493
|
-
${btn({ variant: stale ? 'primary' : 'outline', label: replanning ? '重新计划中…' : '重新计划', iconName: replanning ? 'loader' : 'refresh', spin: replanning, action: 'replan', disabled: Boolean(pl.busy) })}
|
|
1494
|
-
</form>`
|
|
1495
|
-
return `<dialog class="dialog${stale ? ' stale' : ''}" role="dialog" aria-modal="true" aria-labelledby="plan-title" data-action="close-plan-backdrop">
|
|
1496
|
-
<div class="dialog-head">${icon('download')}<b id="plan-title" tabindex="-1">${copy.planTitle} · ${esc(pl.display_name)}</b><button type="button" class="btn ghost icon" data-action="close-plan" aria-label="关闭部署计划"${deploying ? ' disabled' : ''}>${icon('x')}</button></div>
|
|
1497
|
-
${form}
|
|
1498
|
-
<div class="dialog-body"><p class="stale-hint" role="status" data-plan-options-changed${stale ? '' : ' hidden'}>参数已更改,下面是旧计划;请点击“重新计划”后再确认部署。</p>${body}</div>
|
|
1499
|
-
<div class="dialog-foot">${planSummary(pl)}<div class="foot-actions">${btn({ label: copy.cancel, action: 'close-plan', disabled: deploying })}${btn({ variant: 'primary lg', label: deploying ? '部署中…' : (pl.occupied?.length ? copy.shareAndDeploy : copy.confirmDeploy), iconName: deploying ? 'loader' : 'zap', spin: deploying, action: 'deploy', disabled: planDeployDisabled(pl), attrs: pl.plan ? ' aria-describedby="plan-summary"' : '' })}</div></div>
|
|
1500
|
-
</dialog>`
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
function confirmRemoveDialog() {
|
|
1504
|
-
const cr = state.confirmRemove
|
|
1505
|
-
if (!cr) return ''
|
|
1506
|
-
const rec = (state.deployments || []).find(r => r.plan?.name === cr.name)
|
|
1507
|
-
const modelName = rec?.plan?.model?.display_name || ''
|
|
1508
|
-
const deployDir = rec?.plan?.service?.deploy_dir || ''
|
|
1509
|
-
const details = [
|
|
1510
|
-
modelName ? `<p class="hint">模型:${esc(modelName)}</p>` : '',
|
|
1511
|
-
deployDir ? `<p class="hint">目录:<span class="mono" style="overflow-wrap:anywhere">${esc(deployDir)}</span></p>` : ''
|
|
1512
|
-
].filter(Boolean).join('')
|
|
1513
|
-
const errBlock = cr.error
|
|
1514
|
-
? `<div class="gate danger" role="alert" style="margin:10px 0 0"><b>移除失败</b><p class="error-text">${esc(cr.error)}</p></div>`
|
|
1515
|
-
: ''
|
|
1516
|
-
return `<dialog class="dialog dialog-sm" role="dialog" aria-modal="true" aria-labelledby="remove-title" data-action="close-remove-backdrop">
|
|
1517
|
-
<div class="dialog-head">${icon('alertTriangle')}<b id="remove-title" tabindex="-1">移除部署 · ${esc(cr.name)}</b><button type="button" class="btn ghost icon" data-action="close-remove" aria-label="关闭移除确认"${cr.busy ? ' disabled' : ''}>${icon('x')}</button></div>
|
|
1518
|
-
<div class="dialog-body">
|
|
1519
|
-
<p class="remove-desc">将停止并移除服务 <span class="mono">${esc(cr.name)}</span>。</p>
|
|
1520
|
-
<p class="hint">已下载的模型文件和 llama.cpp 引擎压缩包会继续保留在主机磁盘上,不会被删除。</p>
|
|
1521
|
-
${details ? `<div style="margin-top:8px;display:grid;gap:2px">${details}</div>` : ''}
|
|
1522
|
-
${errBlock}
|
|
1523
|
-
</div>
|
|
1524
|
-
<div class="dialog-foot"><div class="foot-actions">${btn({ label: copy.cancel, action: 'close-remove', disabled: Boolean(cr.busy) })}${btn({ variant: 'danger lg', label: cr.busy ? '正在移除…' : (cr.error ? '重试移除' : '确认移除'), iconName: cr.busy ? 'loader' : 'trash', spin: Boolean(cr.busy), action: 'confirm-remove', disabled: Boolean(cr.busy) })}</div></div>
|
|
1525
|
-
</dialog>`
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
function shortcutsDialog() {
|
|
1529
|
-
if (!state.shortcutsOpen) return ''
|
|
1530
|
-
return `<dialog class="dialog dialog-sm" role="dialog" aria-modal="true" aria-labelledby="shortcuts-title" data-action="close-shortcuts-backdrop">
|
|
1531
|
-
<div class="dialog-head">${icon('command')}<b id="shortcuts-title" tabindex="-1">键盘快捷键指南</b><button type="button" class="btn ghost icon" data-action="close-shortcuts" aria-label="关闭快捷键指南">${icon('x')}</button></div>
|
|
1532
|
-
<div class="dialog-body">
|
|
1533
|
-
<table class="shortcuts-table">
|
|
1534
|
-
<tbody>
|
|
1535
|
-
<tr><td><kbd class="kbd-badge">/</kbd></td><td>快速聚焦模型目录搜索框</td></tr>
|
|
1536
|
-
<tr><td><kbd class="kbd-badge">1</kbd> ~ <kbd class="kbd-badge">5</kbd></td><td>快速跳转页面分区(快速开始 / 设备 / 目录 / 运行时 / 配置)</td></tr>
|
|
1537
|
-
<tr><td><kbd class="kbd-badge">T</kbd></td><td>快速循环切换外观主题(跟随系统 / 浅色 / 深色)</td></tr>
|
|
1538
|
-
<tr><td><kbd class="kbd-badge">?</kbd></td><td>打开 / 关闭本快捷键指南</td></tr>
|
|
1539
|
-
<tr><td><kbd class="kbd-badge">Esc</kbd></td><td>关闭当前打开的弹窗与对话框</td></tr>
|
|
1540
|
-
</tbody>
|
|
1541
|
-
</table>
|
|
1542
|
-
</div>
|
|
1543
|
-
<div class="dialog-foot">
|
|
1544
|
-
<div class="foot-actions">
|
|
1545
|
-
<button type="button" class="btn primary" data-action="close-shortcuts">知道了</button>
|
|
1546
|
-
</div>
|
|
1547
|
-
</div>
|
|
1548
|
-
</dialog>`
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
// ── Render ──
|
|
1552
|
-
let renderedPlanning = null
|
|
1553
|
-
let renderedRemove = null
|
|
1554
|
-
let planTrigger = null
|
|
1555
|
-
let removeTrigger = null
|
|
1556
|
-
let shortcutsTrigger = null
|
|
1557
|
-
|
|
1558
|
-
function hasDedicatedConfirmRoot() {
|
|
1559
|
-
const dedicated = typeof document !== 'undefined' ? document.getElementById('confirm-dialog-root') : null
|
|
1560
|
-
return Boolean(dedicated && typeof dedicated.querySelector === 'function')
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
function renderRemoveDialog() {
|
|
1564
|
-
const root = hasDedicatedConfirmRoot()
|
|
1565
|
-
? document.getElementById('confirm-dialog-root')
|
|
1566
|
-
: document.getElementById('dialog-root')
|
|
1567
|
-
if (!root || typeof root.querySelector !== 'function') return
|
|
1568
|
-
const dialog = root.querySelector('dialog')
|
|
1569
|
-
if (!state.confirmRemove) {
|
|
1570
|
-
if (!dialog || !renderedRemove) return
|
|
1571
|
-
dialog.close()
|
|
1572
|
-
root.replaceChildren()
|
|
1573
|
-
if (removeTrigger?.deviceId === state.selected) {
|
|
1574
|
-
const trigger = !removeTrigger.succeeded
|
|
1575
|
-
? [...document.querySelectorAll('[data-action="service"]')]
|
|
1576
|
-
.find(button => button.dataset.arg === `${removeTrigger.name}:remove` && !button.disabled)
|
|
1577
|
-
: null
|
|
1578
|
-
if (trigger) {
|
|
1579
|
-
trigger.focus()
|
|
1580
|
-
} else {
|
|
1581
|
-
const runtimeSec = document.getElementById('sec-runtime')
|
|
1582
|
-
if (runtimeSec) {
|
|
1583
|
-
if (!runtimeSec.hasAttribute?.('tabindex')) runtimeSec.setAttribute?.('tabindex', '-1')
|
|
1584
|
-
runtimeSec.focus?.()
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
renderedRemove = null
|
|
1589
|
-
removeTrigger = null
|
|
1590
|
-
return
|
|
1591
|
-
}
|
|
1592
|
-
if (!dialog || renderedRemove !== state.confirmRemove) {
|
|
1593
|
-
dialog?.close()
|
|
1594
|
-
root.innerHTML = confirmRemoveDialog()
|
|
1595
|
-
const opened = root.querySelector('dialog')
|
|
1596
|
-
describeTips(opened)
|
|
1597
|
-
opened.showModal()
|
|
1598
|
-
opened.querySelector('#remove-title').focus()
|
|
1599
|
-
renderedRemove = state.confirmRemove
|
|
1600
|
-
return
|
|
1601
|
-
}
|
|
1602
|
-
const focused = document.activeElement
|
|
1603
|
-
const focusedAction = focused?.dataset.action
|
|
1604
|
-
const focusedSection = focused?.closest('.dialog-foot') ? '.dialog-foot' : '.dialog-body'
|
|
1605
|
-
const next = document.createElement('template')
|
|
1606
|
-
next.innerHTML = confirmRemoveDialog()
|
|
1607
|
-
for (const selector of ['.dialog-body', '.dialog-foot']) {
|
|
1608
|
-
dialog.querySelector(selector).replaceChildren(...next.content.querySelector(selector).childNodes)
|
|
1609
|
-
}
|
|
1610
|
-
const closeBtn = dialog.querySelector('.dialog-head [data-action="close-remove"]')
|
|
1611
|
-
if (closeBtn) closeBtn.disabled = Boolean(state.confirmRemove.busy)
|
|
1612
|
-
describeTips(dialog)
|
|
1613
|
-
if (!dialog.contains(document.activeElement) || document.activeElement?.disabled) {
|
|
1614
|
-
const replacement = focusedAction && dialog.querySelector(`${focusedSection} [data-action="${focusedAction}"]`)
|
|
1615
|
-
if (replacement && !replacement.disabled) replacement.focus()
|
|
1616
|
-
else dialog.querySelector('#remove-title').focus()
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
function renderShortcutsDialog() {
|
|
1621
|
-
const root = typeof document !== 'undefined' ? document.getElementById('shortcuts-dialog-root') : null
|
|
1622
|
-
if (!root || typeof root.querySelector !== 'function') return
|
|
1623
|
-
const dialog = root.querySelector('dialog')
|
|
1624
|
-
if (!state.shortcutsOpen) {
|
|
1625
|
-
if (!dialog) return
|
|
1626
|
-
dialog.close()
|
|
1627
|
-
root.replaceChildren()
|
|
1628
|
-
shortcutsTrigger?.focus?.()
|
|
1629
|
-
shortcutsTrigger = null
|
|
1630
|
-
return
|
|
1631
|
-
}
|
|
1632
|
-
if (!dialog) {
|
|
1633
|
-
shortcutsTrigger = document.activeElement
|
|
1634
|
-
root.innerHTML = shortcutsDialog()
|
|
1635
|
-
const opened = root.querySelector('dialog')
|
|
1636
|
-
describeTips(opened)
|
|
1637
|
-
opened.showModal()
|
|
1638
|
-
opened.querySelector('#shortcuts-title')?.focus()
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
function renderPlanDialog() {
|
|
1643
|
-
if (!hasDedicatedConfirmRoot() && !state.planning && (state.confirmRemove || renderedRemove)) {
|
|
1644
|
-
renderRemoveDialog()
|
|
1645
|
-
return
|
|
1646
|
-
}
|
|
1647
|
-
const root = document.getElementById('dialog-root')
|
|
1648
|
-
if (!root || typeof root.querySelector !== 'function') return
|
|
1649
|
-
const dialog = root.querySelector('dialog')
|
|
1650
|
-
if (!state.planning) {
|
|
1651
|
-
if (!dialog) return
|
|
1652
|
-
dialog.close()
|
|
1653
|
-
root.replaceChildren()
|
|
1654
|
-
if (planTrigger?.deviceId === state.selected) {
|
|
1655
|
-
const trigger = [...document.querySelectorAll('[data-action="plan"]')]
|
|
1656
|
-
.find(button => button.dataset.arg === planTrigger.modelId && !button.disabled)
|
|
1657
|
-
trigger?.focus()
|
|
1658
|
-
}
|
|
1659
|
-
renderedPlanning = null
|
|
1660
|
-
planTrigger = null
|
|
1661
|
-
return
|
|
1662
|
-
}
|
|
1663
|
-
if (!dialog || renderedPlanning !== state.planning) {
|
|
1664
|
-
dialog?.close()
|
|
1665
|
-
root.innerHTML = planDialog()
|
|
1666
|
-
const opened = root.querySelector('dialog')
|
|
1667
|
-
describeTips(opened)
|
|
1668
|
-
opened.showModal()
|
|
1669
|
-
opened.querySelector('#plan-title').focus()
|
|
1670
|
-
renderedPlanning = state.planning
|
|
1671
|
-
return
|
|
1672
|
-
}
|
|
1673
|
-
const focused = document.activeElement
|
|
1674
|
-
const focusedAction = focused?.dataset.action
|
|
1675
|
-
const focusedSection = focused?.closest('.dialog-foot') ? '.dialog-foot' : '.dialog-body'
|
|
1676
|
-
const next = document.createElement('template')
|
|
1677
|
-
next.innerHTML = planDialog()
|
|
1678
|
-
for (const selector of ['.dialog-body', '.dialog-foot']) {
|
|
1679
|
-
dialog.querySelector(selector).replaceChildren(...next.content.querySelector(selector).childNodes)
|
|
1680
|
-
}
|
|
1681
|
-
const deploying = Boolean(state.planning.deploying)
|
|
1682
|
-
const replanning = Boolean(state.planning.busy && !deploying)
|
|
1683
|
-
const stale = planOptionsChanged(state.planning)
|
|
1684
|
-
const replanBtn = dialog.querySelector('[data-action="replan"]')
|
|
1685
|
-
if (replanBtn) {
|
|
1686
|
-
replanBtn.disabled = Boolean(state.planning.busy)
|
|
1687
|
-
replanBtn.classList.toggle('primary', stale)
|
|
1688
|
-
replanBtn.classList.toggle('outline', !stale)
|
|
1689
|
-
replanBtn.innerHTML = `${icon(replanning ? 'loader' : 'refresh', '', replanning ? 'spin' : '')}${replanning ? '重新计划中…' : '重新计划'}`
|
|
1690
|
-
}
|
|
1691
|
-
const headClose = dialog.querySelector('.dialog-head [data-action="close-plan"]')
|
|
1692
|
-
if (headClose) headClose.disabled = deploying
|
|
1693
|
-
dialog.querySelectorAll('.plan-form input, .plan-form select').forEach(ctrl => {
|
|
1694
|
-
ctrl.disabled = deploying
|
|
1695
|
-
})
|
|
1696
|
-
dialog.classList.toggle('stale', stale)
|
|
1697
|
-
describeTips(dialog)
|
|
1698
|
-
if (!dialog.contains(document.activeElement) || document.activeElement?.disabled) {
|
|
1699
|
-
const replacement = focusedAction && dialog.querySelector(`${focusedSection} [data-action="${focusedAction}"]`)
|
|
1700
|
-
if (replacement && !replacement.disabled) replacement.focus()
|
|
1701
|
-
else dialog.querySelector('#plan-title').focus()
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
function errorCard(message) {
|
|
1706
|
-
return `<div class="error-card" role="alert">
|
|
1707
|
-
<div class="error-card-body">
|
|
1708
|
-
<div class="error-card-title">${icon('info', 'sm')}<span>无法读取或检测设备</span></div>
|
|
1709
|
-
<p class="error-card-msg">${esc(message)}</p>
|
|
1710
|
-
</div>
|
|
1711
|
-
${btn({ variant: 'primary', label: state.loading ? copy.probing : '重试检测', iconName: state.loading ? 'loader' : 'refresh', spin: state.loading, action: 'reprobe', disabled: state.loading })}
|
|
1712
|
-
</div>`
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
|
-
function render() {
|
|
1716
|
-
const page = document.getElementById('page')
|
|
1717
|
-
const scrollBox = typeof document !== 'undefined' && typeof document.querySelector === 'function'
|
|
1718
|
-
? document.querySelector('.scroll')
|
|
1719
|
-
: null
|
|
1720
|
-
const prevScrollTop = scrollBox && state.catalog ? scrollBox.scrollTop : null
|
|
1721
|
-
const alternativesOpen = page.querySelector?.('.model-alternatives')?.open
|
|
1722
|
-
let html = setupGuide() + activeDeploymentsStrip() + deviceSection()
|
|
1723
|
-
if (state.error) {
|
|
1724
|
-
html += errorCard(state.error)
|
|
1725
|
-
}
|
|
1726
|
-
if (state.catalog) {
|
|
1727
|
-
const facts = state.catalog.facts
|
|
1728
|
-
html += modelsSection(state.catalog) + runtimeSection(facts, state.catalog) + hardwareSection(facts)
|
|
1729
|
-
} else if (state.loading) {
|
|
1730
|
-
html += `<p class="status-line">${icon('loader', 'xs', 'spin')}${copy.probing}</p>`
|
|
1731
|
-
}
|
|
1732
|
-
const active = document.activeElement
|
|
1733
|
-
const focused = active?.name
|
|
1734
|
-
const selStart = active && 'selectionStart' in active ? active.selectionStart : null
|
|
1735
|
-
const selEnd = active && 'selectionEnd' in active ? active.selectionEnd : null
|
|
1736
|
-
page.innerHTML = html
|
|
1737
|
-
if (alternativesOpen || (state.modelQuery || '').trim() || state.fitsOnly) page.querySelector?.('.model-alternatives')?.setAttribute('open', '')
|
|
1738
|
-
describeTips(page)
|
|
1739
|
-
renderChrome()
|
|
1740
|
-
syncSectionNavLabels()
|
|
1741
|
-
renderPlanDialog()
|
|
1742
|
-
if (hasDedicatedConfirmRoot()) renderRemoveDialog()
|
|
1743
|
-
renderShortcutsDialog()
|
|
1744
|
-
if (scrollBox && prevScrollTop != null && prevScrollTop > 0) {
|
|
1745
|
-
scrollBox.scrollTop = prevScrollTop
|
|
1746
|
-
}
|
|
1747
|
-
if (focused && !state.planning && !state.confirmRemove && !state.shortcutsOpen) {
|
|
1748
|
-
const next = document.querySelector(`[name="${focused}"]`)
|
|
1749
|
-
if (next) {
|
|
1750
|
-
next.focus()
|
|
1751
|
-
if (selStart != null && selEnd != null && typeof next.setSelectionRange === 'function') {
|
|
1752
|
-
try { next.setSelectionRange(selStart, selEnd) } catch { /* non-text inputs */ }
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
|
|
1758
|
-
// ── Actions ──
|
|
1759
|
-
function toast(message, title = '本地模型', tone = '') {
|
|
1760
|
-
const host = document.getElementById('toasts')
|
|
1761
|
-
if (!host || typeof host.append !== 'function') return
|
|
1762
|
-
const el = document.createElement('div')
|
|
1763
|
-
const isError = tone === 'error'
|
|
1764
|
-
el.className = tone ? `toast toast--${tone}` : 'toast'
|
|
1765
|
-
if (isError) {
|
|
1766
|
-
el.setAttribute('role', 'alert')
|
|
1767
|
-
el.setAttribute('aria-live', 'assertive')
|
|
1768
|
-
}
|
|
1769
|
-
el.innerHTML = `<div class="toast-body"><b>${esc(title)}</b><span>${esc(message)}</span></div><button type="button" class="toast-close" aria-label="关闭通知">${icon('x', 'xs')}</button>`
|
|
1770
|
-
const close = el.querySelector?.('.toast-close')
|
|
1771
|
-
const timer = setTimeout(() => el.remove(), isError ? 8000 : 4200)
|
|
1772
|
-
close?.addEventListener?.('click', () => { clearTimeout(timer); el.remove() })
|
|
1773
|
-
host.append(el)
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
|
-
async function copyText(text) {
|
|
1777
|
-
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
|
1778
|
-
try {
|
|
1779
|
-
await navigator.clipboard.writeText(text)
|
|
1780
|
-
return true
|
|
1781
|
-
} catch {
|
|
1782
|
-
// Fall back to execCommand on non-HTTPS LAN origins
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
if (typeof document !== 'undefined' && document.body && typeof document.execCommand === 'function') {
|
|
1786
|
-
const area = document.createElement('textarea')
|
|
1787
|
-
area.value = text
|
|
1788
|
-
area.setAttribute('readonly', '')
|
|
1789
|
-
area.style.cssText = 'position:fixed;top:-9999px;left:-9999px;opacity:0'
|
|
1790
|
-
document.body.appendChild(area)
|
|
1791
|
-
area.select()
|
|
1792
|
-
try {
|
|
1793
|
-
return Boolean(document.execCommand('copy'))
|
|
1794
|
-
} catch {
|
|
1795
|
-
return false
|
|
1796
|
-
} finally {
|
|
1797
|
-
area.remove()
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
return false
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
function flashCopiedButton(event) {
|
|
1804
|
-
const button = event?.target?.closest?.('button')
|
|
1805
|
-
if (!button || typeof button.innerHTML !== 'string') return
|
|
1806
|
-
if (!button.dataset.origHtml) button.dataset.origHtml = button.innerHTML
|
|
1807
|
-
button.innerHTML = `${icon('check', 'sm')}已复制`
|
|
1808
|
-
button.classList?.add('is-copied')
|
|
1809
|
-
clearTimeout(Number(button.dataset.copyTimer || 0))
|
|
1810
|
-
const timer = setTimeout(() => {
|
|
1811
|
-
if (button.dataset.origHtml) button.innerHTML = button.dataset.origHtml
|
|
1812
|
-
button.classList?.remove('is-copied')
|
|
1813
|
-
}, 1800)
|
|
1814
|
-
button.dataset.copyTimer = String(timer)
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1817
|
-
let loadSeq = 0
|
|
1818
|
-
let loadController = null
|
|
1819
|
-
let planSeq = 0
|
|
1820
|
-
let planController = null
|
|
1821
|
-
|
|
1822
|
-
async function loadDevices(signal) {
|
|
1823
|
-
const devices = await api('devices', signal ? { signal } : {})
|
|
1824
|
-
if (signal?.aborted) return
|
|
1825
|
-
state.devices = devices
|
|
1826
|
-
if (!state.devices.some(d => d.id === state.selected)) state.selected = 'local'
|
|
1827
|
-
}
|
|
1828
|
-
|
|
1829
|
-
async function loadDevice({ fresh = false } = {}) {
|
|
1830
|
-
const seq = ++loadSeq
|
|
1831
|
-
loadController?.abort()
|
|
1832
|
-
const controller = typeof AbortController !== 'undefined' ? new AbortController() : null
|
|
1833
|
-
loadController = controller
|
|
1834
|
-
const signal = controller?.signal
|
|
1835
|
-
const devId = state.selected
|
|
1836
|
-
const hadCatalog = Boolean(state.catalog)
|
|
1837
|
-
const prevStates = !fresh
|
|
1838
|
-
? new Map((state.deployments || []).filter(r => r.liveState != null && r.plan?.name).map(r => [r.plan.name, r.liveState]))
|
|
1839
|
-
: new Map()
|
|
1840
|
-
state.loading = true
|
|
1841
|
-
state.reprobing = Boolean(fresh && hadCatalog)
|
|
1842
|
-
state.error = null
|
|
1843
|
-
render()
|
|
1844
|
-
try {
|
|
1845
|
-
if (fresh) await api(`devices/${encodeURIComponent(devId)}/probe`, { method: 'POST', body: {}, ...(signal ? { signal } : {}) })
|
|
1846
|
-
if (seq !== loadSeq || devId !== state.selected) return
|
|
1847
|
-
const [cat, deployments] = await Promise.all([
|
|
1848
|
-
api(`devices/${encodeURIComponent(devId)}/catalog`, signal ? { signal } : {}),
|
|
1849
|
-
api(`devices/${encodeURIComponent(devId)}/deployments`, signal ? { signal } : {})
|
|
1850
|
-
])
|
|
1851
|
-
if (seq !== loadSeq || devId !== state.selected) return
|
|
1852
|
-
state.catalog = cat
|
|
1853
|
-
state.deployments = deployments.map(r => prevStates.has(r.plan?.name) ? { ...r, liveState: prevStates.get(r.plan.name) } : r)
|
|
1854
|
-
await loadDevices(signal)
|
|
1855
|
-
} catch (e) {
|
|
1856
|
-
if (seq === loadSeq && devId === state.selected) {
|
|
1857
|
-
state.error = e.message
|
|
1858
|
-
if (!hadCatalog) state.catalog = null
|
|
1859
|
-
else toast(e.message, '重新检测失败', 'error')
|
|
1860
|
-
}
|
|
1861
|
-
} finally {
|
|
1862
|
-
if (seq === loadSeq) {
|
|
1863
|
-
if (loadController === controller) loadController = null
|
|
1864
|
-
state.loading = false
|
|
1865
|
-
state.reprobing = false
|
|
1866
|
-
render()
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
async function makePlan() {
|
|
1872
|
-
const pl = state.planning
|
|
1873
|
-
const options = { ...pl.options }
|
|
1874
|
-
if (!validPort(options.port)) {
|
|
1875
|
-
Object.assign(pl, { busy: false, error: '端口须为 1024–65535 之间的整数。', errorTitle: '端口无效', conflict: null })
|
|
1876
|
-
render()
|
|
1877
|
-
return
|
|
1878
|
-
}
|
|
1879
|
-
const seq = ++planSeq
|
|
1880
|
-
planController?.abort()
|
|
1881
|
-
const controller = typeof AbortController !== 'undefined' ? new AbortController() : null
|
|
1882
|
-
planController = controller
|
|
1883
|
-
const signal = controller?.signal
|
|
1884
|
-
Object.assign(pl, { busy: true, error: null, errorTitle: null, conflict: null, changed: null, refusal: null, occupied: null, share: false })
|
|
1885
|
-
render()
|
|
1886
|
-
try {
|
|
1887
|
-
const body = { model_id: pl.model_id, ...options, port: Number(options.port) }
|
|
1888
|
-
const res = await api(`devices/${encodeURIComponent(state.selected)}/plan`, { method: 'POST', body, ...(signal ? { signal } : {}) })
|
|
1889
|
-
if (seq !== planSeq || state.planning !== pl) return
|
|
1890
|
-
pl.plan = res.plan
|
|
1891
|
-
pl.plan_id = res.plan_id
|
|
1892
|
-
pl.plannedOptions = options
|
|
1893
|
-
// The deploy gate refuses these cards without consent; ask now instead of after a 409.
|
|
1894
|
-
if (res.busy_gpus?.length) Object.assign(pl, { occupied: res.busy_gpus, occupiedAt: 'plan' })
|
|
1895
|
-
} catch (e) {
|
|
1896
|
-
if (seq !== planSeq || state.planning !== pl) return
|
|
1897
|
-
pl.error = e.message
|
|
1898
|
-
pl.conflict = e.data?.code === 'gpu_conflict' ? e.data.conflict : null
|
|
1899
|
-
pl.plan = null
|
|
1900
|
-
} finally {
|
|
1901
|
-
if (seq === planSeq) {
|
|
1902
|
-
if (planController === controller) planController = null
|
|
1903
|
-
pl.busy = false
|
|
1904
|
-
if (state.planning === pl) render()
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
|
|
1909
|
-
async function pollJob(modelId, jobId, deviceId) {
|
|
1910
|
-
let failures = 0
|
|
1911
|
-
for (;;) {
|
|
1912
|
-
let job
|
|
1913
|
-
try {
|
|
1914
|
-
job = await api(`jobs/${jobId}`)
|
|
1915
|
-
failures = 0
|
|
1916
|
-
} catch (e) {
|
|
1917
|
-
failures++
|
|
1918
|
-
if (failures <= 3) {
|
|
1919
|
-
await new Promise(r => setTimeout(r, failures * 1000))
|
|
1920
|
-
continue
|
|
1921
|
-
}
|
|
1922
|
-
const msg = `轮询部署状态失败(已重试 3 次):${e.message}`
|
|
1923
|
-
if (deviceId === state.selected) {
|
|
1924
|
-
const prev = state.jobs[modelId] || {}
|
|
1925
|
-
state.jobs[modelId] = { ...prev, state: 'error', error: msg }
|
|
1926
|
-
render()
|
|
1927
|
-
}
|
|
1928
|
-
toast(msg, '部署状态异常', 'error')
|
|
1929
|
-
return
|
|
1930
|
-
}
|
|
1931
|
-
if (deviceId === state.selected) {
|
|
1932
|
-
state.jobs[modelId] = job
|
|
1933
|
-
render()
|
|
1934
|
-
}
|
|
1935
|
-
if (job.state !== 'running') {
|
|
1936
|
-
const ok = job.state === 'done'
|
|
1937
|
-
toast(ok ? `${job.name} 已就绪` : `${job.name} 部署失败:${job.error || ''}`, '本地模型', ok ? 'success' : 'error')
|
|
1938
|
-
if (deviceId === state.selected) loadDevice()
|
|
1939
|
-
return
|
|
1940
|
-
}
|
|
1941
|
-
await new Promise(r => setTimeout(r, 1500))
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
|
-
async function loadCandidates() {
|
|
1946
|
-
state.candidates = null
|
|
1947
|
-
state.discoverError = null
|
|
1948
|
-
render()
|
|
1949
|
-
try {
|
|
1950
|
-
state.candidates = await api('discover')
|
|
1951
|
-
} catch (e) {
|
|
1952
|
-
state.candidates = []
|
|
1953
|
-
state.discoverError = e.message
|
|
1954
|
-
}
|
|
1955
|
-
render()
|
|
1956
|
-
}
|
|
1957
|
-
|
|
1958
|
-
let spyLockUntil = 0
|
|
1959
|
-
|
|
1960
|
-
function preferredScrollBehavior() {
|
|
1961
|
-
return typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth'
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
|
-
const ACTIONS = {
|
|
1965
|
-
noop() {},
|
|
1966
|
-
'scroll-top'() {
|
|
1967
|
-
ACTIONS['jump-section']('setup-guide')
|
|
1968
|
-
},
|
|
1969
|
-
async 'copy-install'(arg, event) {
|
|
1970
|
-
if (await copyText('python3 -m localmodels install')) {
|
|
1971
|
-
flashCopiedButton(event)
|
|
1972
|
-
toast('已复制完整安装命令;请在要安装的设备终端粘贴运行。', '本地模型', 'success')
|
|
1973
|
-
} else {
|
|
1974
|
-
toast('复制失败,请选中上方的完整安装命令手动复制。', '本地模型', 'error')
|
|
1975
|
-
}
|
|
1976
|
-
},
|
|
1977
|
-
async 'copy-text'(text, event) {
|
|
1978
|
-
if (!text) return
|
|
1979
|
-
if (await copyText(text)) {
|
|
1980
|
-
flashCopiedButton(event)
|
|
1981
|
-
toast('已复制到剪贴板', '本地模型', 'success')
|
|
1982
|
-
} else {
|
|
1983
|
-
toast('复制失败,请手动选中并复制。', '本地模型', 'error')
|
|
1984
|
-
}
|
|
1985
|
-
},
|
|
1986
|
-
async 'copy-cmd'(cmd, event) {
|
|
1987
|
-
if (await copyText(cmd)) {
|
|
1988
|
-
flashCopiedButton(event)
|
|
1989
|
-
toast(`已复制命令:${cmd}`, '本地模型', 'success')
|
|
1990
|
-
} else {
|
|
1991
|
-
toast(`复制失败,请手动复制命令:${cmd}`, '本地模型', 'error')
|
|
1992
|
-
}
|
|
1993
|
-
},
|
|
1994
|
-
async 'copy-sha256'(hash, event) {
|
|
1995
|
-
if (await copyText(hash)) {
|
|
1996
|
-
flashCopiedButton(event)
|
|
1997
|
-
toast(`已复制 SHA256:${hash.slice(0, 12)}…`, '本地模型', 'success')
|
|
1998
|
-
} else {
|
|
1999
|
-
toast('复制 SHA256 失败,请手动复制。', '本地模型', 'error')
|
|
2000
|
-
}
|
|
2001
|
-
},
|
|
2002
|
-
'select-device'(id) {
|
|
2003
|
-
if (id === state.selected) return
|
|
2004
|
-
state.selected = id
|
|
2005
|
-
state.confirmRemoveDevice = null
|
|
2006
|
-
localStorageSet('localmodels.device', id)
|
|
2007
|
-
state.catalog = null
|
|
2008
|
-
state.reprobing = false
|
|
2009
|
-
state.deployments = []
|
|
2010
|
-
state.jobs = {}
|
|
2011
|
-
state.confirmRemove = null
|
|
2012
|
-
loadDevice()
|
|
2013
|
-
},
|
|
2014
|
-
'ask-remove-device'(id) {
|
|
2015
|
-
if (!id || id === 'local') return
|
|
2016
|
-
state.confirmRemoveDevice = state.confirmRemoveDevice === id ? null : id
|
|
2017
|
-
render()
|
|
2018
|
-
},
|
|
2019
|
-
'cancel-remove-device'() {
|
|
2020
|
-
if (state.removingDevice) return
|
|
2021
|
-
state.confirmRemoveDevice = null
|
|
2022
|
-
render()
|
|
2023
|
-
},
|
|
2024
|
-
async 'remove-device'(id) {
|
|
2025
|
-
if (!id || id === 'local' || state.removingDevice) return
|
|
2026
|
-
state.removingDevice = id
|
|
2027
|
-
render()
|
|
2028
|
-
try {
|
|
2029
|
-
await api(`devices/${encodeURIComponent(id)}`, { method: 'DELETE' })
|
|
2030
|
-
state.confirmRemoveDevice = null
|
|
2031
|
-
await loadDevices()
|
|
2032
|
-
if (state.selected === id || !state.devices.some(d => d.id === state.selected)) {
|
|
2033
|
-
state.selected = 'local'
|
|
2034
|
-
localStorageSet('localmodels.device', 'local')
|
|
2035
|
-
state.catalog = null
|
|
2036
|
-
state.reprobing = false
|
|
2037
|
-
state.deployments = []
|
|
2038
|
-
state.jobs = {}
|
|
2039
|
-
await loadDevice()
|
|
2040
|
-
}
|
|
2041
|
-
toast('已移除设备记录(远端主机上的服务未受影响)。', '本地模型', 'success')
|
|
2042
|
-
} catch (e) {
|
|
2043
|
-
toast(e.message, '移除设备失败', 'error')
|
|
2044
|
-
} finally {
|
|
2045
|
-
state.removingDevice = null
|
|
2046
|
-
render()
|
|
2047
|
-
}
|
|
2048
|
-
},
|
|
2049
|
-
'set-theme'(theme) {
|
|
2050
|
-
state.theme = applyTheme(theme)
|
|
2051
|
-
localStorageSet(THEME_KEY, state.theme)
|
|
2052
|
-
renderChrome()
|
|
2053
|
-
},
|
|
2054
|
-
'cycle-theme'() {
|
|
2055
|
-
const idx = THEME_CYCLE.indexOf(state.theme)
|
|
2056
|
-
const next = THEME_CYCLE[(idx + 1) % THEME_CYCLE.length]
|
|
2057
|
-
ACTIONS['set-theme'](next)
|
|
2058
|
-
toast(`外观主题已切换为:${THEME_LABEL[next]}`)
|
|
2059
|
-
},
|
|
2060
|
-
'open-shortcuts'() {
|
|
2061
|
-
state.shortcutsOpen = true
|
|
2062
|
-
renderShortcutsDialog()
|
|
2063
|
-
},
|
|
2064
|
-
'close-shortcuts'() {
|
|
2065
|
-
state.shortcutsOpen = false
|
|
2066
|
-
renderShortcutsDialog()
|
|
2067
|
-
},
|
|
2068
|
-
'close-shortcuts-backdrop'(arg, event) {
|
|
2069
|
-
if (event?.target?.tagName !== 'DIALOG') return
|
|
2070
|
-
const bounds = event.target.getBoundingClientRect?.()
|
|
2071
|
-
if (!bounds || event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) ACTIONS['close-shortcuts']()
|
|
2072
|
-
},
|
|
2073
|
-
'jump-section'(id) {
|
|
2074
|
-
if (typeof document === 'undefined' || typeof document.getElementById !== 'function') return
|
|
2075
|
-
const scroller = typeof document.querySelector === 'function' ? document.querySelector('.scroll') : null
|
|
2076
|
-
if (!scroller) return
|
|
2077
|
-
const behavior = preferredScrollBehavior()
|
|
2078
|
-
if (id === 'setup-guide') {
|
|
2079
|
-
spyLockUntil = Date.now() + 500
|
|
2080
|
-
if (typeof location !== 'undefined' && location.hash) {
|
|
2081
|
-
try { history.replaceState(null, '', location.pathname + location.search) } catch { /* ignore */ }
|
|
2082
|
-
}
|
|
2083
|
-
scroller.scrollTo?.({ top: 0, behavior })
|
|
2084
|
-
syncActiveNav('setup-guide')
|
|
2085
|
-
return
|
|
2086
|
-
}
|
|
2087
|
-
const target = document.getElementById(id)
|
|
2088
|
-
if (!target) return
|
|
2089
|
-
spyLockUntil = Date.now() + 500
|
|
2090
|
-
syncActiveNav(id)
|
|
2091
|
-
const top = target.getBoundingClientRect().top - scroller.getBoundingClientRect().top + scroller.scrollTop - 16
|
|
2092
|
-
if (typeof scroller.scrollTo === 'function') scroller.scrollTo({ top: Math.max(0, top), behavior })
|
|
2093
|
-
else target.scrollIntoView?.({ behavior, block: 'start' })
|
|
2094
|
-
},
|
|
2095
|
-
'toggle-fits-only'(arg, event) {
|
|
2096
|
-
state.fitsOnly = Boolean(event?.target?.checked)
|
|
2097
|
-
if (refreshCatalogResults()) return
|
|
2098
|
-
render()
|
|
2099
|
-
},
|
|
2100
|
-
async 'copy-endpoint'(url, event) {
|
|
2101
|
-
if (await copyText(url)) {
|
|
2102
|
-
flashCopiedButton(event)
|
|
2103
|
-
toast(`已复制接口地址:${url}`, '本地模型', 'success')
|
|
2104
|
-
} else {
|
|
2105
|
-
toast(`复制失败,请手动复制地址:${url}`, '本地模型', 'error')
|
|
2106
|
-
}
|
|
2107
|
-
},
|
|
2108
|
-
async 'toggle-add'() {
|
|
2109
|
-
state.adding = !state.adding
|
|
2110
|
-
state.addError = null
|
|
2111
|
-
render()
|
|
2112
|
-
if (state.adding && state.candidates === null) {
|
|
2113
|
-
await loadCandidates()
|
|
2114
|
-
}
|
|
2115
|
-
},
|
|
2116
|
-
async rediscover() {
|
|
2117
|
-
await loadCandidates()
|
|
2118
|
-
},
|
|
2119
|
-
'submit-add'() {
|
|
2120
|
-
const input = document.querySelector('[data-form="add-device"] [name="target"]')
|
|
2121
|
-
const val = (input?.value ?? state.addTargetInput ?? '').trim()
|
|
2122
|
-
if (val) addDevice(val)
|
|
2123
|
-
},
|
|
2124
|
-
'add-candidate'(raw) {
|
|
2125
|
-
const c = JSON.parse(raw)
|
|
2126
|
-
addDevice(c.target, c.label)
|
|
2127
|
-
},
|
|
2128
|
-
reprobe() { loadDevice({ fresh: true }) },
|
|
2129
|
-
plan(modelId) {
|
|
2130
|
-
const m = state.catalog.models.find(x => x.id === modelId)
|
|
2131
|
-
planTrigger = { modelId, deviceId: state.selected }
|
|
2132
|
-
state.planning = { model_id: modelId, display_name: m.display_name, plan: null, plan_id: null, busy: false, deploying: false, error: null, errorTitle: null,
|
|
2133
|
-
options: { placement_id: 'auto', port: 18100, bind: '127.0.0.1', hf_download_endpoint: 'https://huggingface.co' } }
|
|
2134
|
-
makePlan()
|
|
2135
|
-
},
|
|
2136
|
-
replan() {
|
|
2137
|
-
makePlan()
|
|
2138
|
-
},
|
|
2139
|
-
'toggle-guide'(arg, event) {
|
|
2140
|
-
const next = event?.target && 'open' in event.target ? Boolean(event.target.open) : !guideIsOpen()
|
|
2141
|
-
state.guideOpen = next
|
|
2142
|
-
localStorageSet('localmodels.guideCollapsed', next ? '0' : '1')
|
|
2143
|
-
if (!event?.target || event.target.id !== 'setup-guide') render()
|
|
2144
|
-
},
|
|
2145
|
-
'close-plan'() {
|
|
2146
|
-
if (state.planning?.deploying) return
|
|
2147
|
-
planSeq++
|
|
2148
|
-
planController?.abort()
|
|
2149
|
-
planController = null
|
|
2150
|
-
state.planning = null
|
|
2151
|
-
render()
|
|
2152
|
-
},
|
|
2153
|
-
'close-plan-backdrop'(arg, event) {
|
|
2154
|
-
if (event.target.tagName !== 'DIALOG') return
|
|
2155
|
-
const bounds = event.target.getBoundingClientRect()
|
|
2156
|
-
if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) ACTIONS['close-plan']()
|
|
2157
|
-
},
|
|
2158
|
-
'toggle-share'(arg, event) {
|
|
2159
|
-
state.planning.share = event.target.checked
|
|
2160
|
-
render()
|
|
2161
|
-
},
|
|
2162
|
-
// The controller re-probes before executing: a changed plan comes back as the fresh plan to
|
|
2163
|
-
// review (its own plan_id), a busy GPU needs the share consent on the same plan_id.
|
|
2164
|
-
async deploy() {
|
|
2165
|
-
const pl = state.planning
|
|
2166
|
-
if (planDeployDisabled(pl)) return
|
|
2167
|
-
const deviceId = state.selected
|
|
2168
|
-
const body = { plan_id: pl.plan_id }
|
|
2169
|
-
if (pl.occupied?.length && pl.share) body.share_gpu = true
|
|
2170
|
-
pl.busy = true
|
|
2171
|
-
pl.deploying = true
|
|
2172
|
-
pl.error = null
|
|
2173
|
-
pl.errorTitle = null
|
|
2174
|
-
render()
|
|
2175
|
-
try {
|
|
2176
|
-
const job = await api(`devices/${encodeURIComponent(deviceId)}/deploy`, { method: 'POST', body })
|
|
2177
|
-
state.jobs[pl.model_id] = job
|
|
2178
|
-
if (state.planning === pl) state.planning = null
|
|
2179
|
-
pollJob(pl.model_id, job.id, deviceId)
|
|
2180
|
-
} catch (e) {
|
|
2181
|
-
const refusal = e.status === 409 ? e.data : null
|
|
2182
|
-
if (refusal?.changed) {
|
|
2183
|
-
Object.assign(pl, { plan: refusal.plan, plan_id: refusal.plan_id, changed: refusal.changed, refusal: refusal.error, occupied: null, share: false })
|
|
2184
|
-
} else if (refusal?.busy) {
|
|
2185
|
-
Object.assign(pl, { occupied: refusal.busy, occupiedAt: 'deploy', share: false, changed: null })
|
|
2186
|
-
} else {
|
|
2187
|
-
pl.error = e.message
|
|
2188
|
-
pl.errorTitle = '部署失败'
|
|
2189
|
-
}
|
|
2190
|
-
} finally {
|
|
2191
|
-
pl.busy = false
|
|
2192
|
-
pl.deploying = false
|
|
2193
|
-
render()
|
|
2194
|
-
}
|
|
2195
|
-
},
|
|
2196
|
-
async service(arg) {
|
|
2197
|
-
const [name, action] = arg.split(':')
|
|
2198
|
-
if (action === 'remove') {
|
|
2199
|
-
removeTrigger = { name, deviceId: state.selected }
|
|
2200
|
-
state.confirmRemove = { name, busy: false }
|
|
2201
|
-
render()
|
|
2202
|
-
return
|
|
2203
|
-
}
|
|
2204
|
-
await runServiceAction(name, action)
|
|
2205
|
-
},
|
|
2206
|
-
'close-remove'() {
|
|
2207
|
-
if (state.confirmRemove?.busy) return
|
|
2208
|
-
state.confirmRemove = null
|
|
2209
|
-
render()
|
|
2210
|
-
},
|
|
2211
|
-
'close-remove-backdrop'(arg, event) {
|
|
2212
|
-
if (event.target.tagName !== 'DIALOG') return
|
|
2213
|
-
const bounds = event.target.getBoundingClientRect()
|
|
2214
|
-
if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) ACTIONS['close-remove']()
|
|
2215
|
-
},
|
|
2216
|
-
async 'confirm-remove'() {
|
|
2217
|
-
const cr = state.confirmRemove
|
|
2218
|
-
if (!cr || cr.busy) return
|
|
2219
|
-
const devId = removeTrigger?.deviceId || state.selected
|
|
2220
|
-
cr.busy = true
|
|
2221
|
-
delete cr.error
|
|
2222
|
-
render()
|
|
2223
|
-
const result = await runServiceAction(cr.name, 'remove', devId)
|
|
2224
|
-
if (state.confirmRemove !== cr) return
|
|
2225
|
-
cr.busy = false
|
|
2226
|
-
if (result.ok) {
|
|
2227
|
-
if (removeTrigger) removeTrigger.succeeded = true
|
|
2228
|
-
state.confirmRemove = null
|
|
2229
|
-
} else {
|
|
2230
|
-
cr.error = result.error?.message || '移除部署失败'
|
|
2231
|
-
}
|
|
2232
|
-
render()
|
|
2233
|
-
}
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2236
|
-
const SERVICE_STATE_ZH = {
|
|
2237
|
-
active: '运行中',
|
|
2238
|
-
running: '运行中',
|
|
2239
|
-
inactive: '已停止',
|
|
2240
|
-
stopped: '已停止',
|
|
2241
|
-
failed: '失败',
|
|
2242
|
-
activating: '启动中',
|
|
2243
|
-
deactivating: '停止中',
|
|
2244
|
-
reloading: '重载中',
|
|
2245
|
-
unknown: '未知'
|
|
2246
|
-
}
|
|
2247
|
-
|
|
2248
|
-
function formatServiceHealth(health) {
|
|
2249
|
-
if (health === 'ok') return '健康'
|
|
2250
|
-
if (health === 'unreachable') return '未响应'
|
|
2251
|
-
return health || '未知'
|
|
2252
|
-
}
|
|
2253
|
-
|
|
2254
|
-
function formatServiceStatus(res) {
|
|
2255
|
-
const rawState = String(res?.state || 'unknown')
|
|
2256
|
-
const st = SERVICE_STATE_ZH[rawState.toLowerCase()] || rawState
|
|
2257
|
-
const hl = formatServiceHealth(res?.health)
|
|
2258
|
-
return `状态:${st} · 健康检查:${hl}`
|
|
2259
|
-
}
|
|
2260
|
-
|
|
2261
|
-
function inferLiveState(action, res) {
|
|
2262
|
-
if (action === 'start') return res?.ok !== false ? 'running' : null
|
|
2263
|
-
if (action === 'stop') return res?.ok !== false ? 'stopped' : null
|
|
2264
|
-
if (action === 'status' && res) {
|
|
2265
|
-
const raw = typeof res.state === 'string' ? res.state.toLowerCase() : ''
|
|
2266
|
-
if (raw === 'active' || raw === 'running') return 'running'
|
|
2267
|
-
if (raw === 'failed') return 'failed'
|
|
2268
|
-
if (raw === 'inactive' || raw === 'stopped' || raw === 'dead' || raw === 'exited') return 'stopped'
|
|
2269
|
-
if (typeof res.running === 'boolean') return res.running ? 'running' : 'stopped'
|
|
2270
|
-
if (typeof res.active === 'boolean') return res.active ? 'running' : 'stopped'
|
|
2271
|
-
}
|
|
2272
|
-
return null
|
|
2273
|
-
}
|
|
2274
|
-
|
|
2275
|
-
async function runServiceAction(name, action, devId = state.selected) {
|
|
2276
|
-
const busyKey = serviceBusyKey(devId, name)
|
|
2277
|
-
state.serviceBusy[busyKey] = action
|
|
2278
|
-
render()
|
|
2279
|
-
try {
|
|
2280
|
-
const res = await api(`devices/${encodeURIComponent(devId)}/deployments/${encodeURIComponent(name)}/${action}`, { method: 'POST', body: {} })
|
|
2281
|
-
if (res?.event === 'error') throw new Error(res.message)
|
|
2282
|
-
if (state.selected === devId) {
|
|
2283
|
-
const rec = state.deployments.find(r => r.plan?.name === name)
|
|
2284
|
-
if (rec) {
|
|
2285
|
-
rec.liveState = inferLiveState(action, res)
|
|
2286
|
-
if (action === 'status') rec.liveStatus = formatServiceStatus(res)
|
|
2287
|
-
else delete rec.liveStatus
|
|
2288
|
-
}
|
|
2289
|
-
}
|
|
2290
|
-
if (action !== 'status') toast(`${name}:${{ start: '已启动', stop: '已停止', remove: '已移除' }[action]}`, '本地模型', 'success')
|
|
2291
|
-
if (action !== 'status' && state.selected === devId) await loadDevice()
|
|
2292
|
-
return { ok: true, res }
|
|
2293
|
-
} catch (e) {
|
|
2294
|
-
toast(e.message, name, 'error')
|
|
2295
|
-
return { ok: false, error: e }
|
|
2296
|
-
} finally {
|
|
2297
|
-
delete state.serviceBusy[busyKey]
|
|
2298
|
-
render()
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
|
|
2302
|
-
async function addDevice(target, label) {
|
|
2303
|
-
if (state.addingDevice) return
|
|
2304
|
-
state.addingDevice = true
|
|
2305
|
-
state.addingTarget = target
|
|
2306
|
-
state.addError = null
|
|
2307
|
-
render()
|
|
2308
|
-
try {
|
|
2309
|
-
const dev = await api('devices', { method: 'POST', body: { target, label } })
|
|
2310
|
-
await loadDevices()
|
|
2311
|
-
state.adding = false
|
|
2312
|
-
state.addTargetInput = ''
|
|
2313
|
-
state.addError = null
|
|
2314
|
-
toast(`已添加设备 ${dev.label || target}`, '本地模型', 'success')
|
|
2315
|
-
ACTIONS['select-device'](dev.id)
|
|
2316
|
-
} catch (e) {
|
|
2317
|
-
state.addError = `${target}:${e.message}`
|
|
2318
|
-
} finally {
|
|
2319
|
-
state.addingDevice = false
|
|
2320
|
-
state.addingTarget = ''
|
|
2321
|
-
render()
|
|
2322
|
-
}
|
|
2323
|
-
}
|
|
2324
|
-
|
|
2325
|
-
function updatePlanOptions(event) {
|
|
2326
|
-
const pl = state.planning
|
|
2327
|
-
const field = event.target
|
|
2328
|
-
if (!pl || !field.closest('[data-form="replan"]') || !(field.name in pl.options)) return
|
|
2329
|
-
pl.options[field.name] = field.value
|
|
2330
|
-
const stale = planOptionsChanged(pl)
|
|
2331
|
-
const deployBtn = document.querySelector('[data-action="deploy"]')
|
|
2332
|
-
if (deployBtn) deployBtn.disabled = planDeployDisabled(pl)
|
|
2333
|
-
const staleHint = document.querySelector('[data-plan-options-changed]')
|
|
2334
|
-
if (staleHint) staleHint.hidden = !stale
|
|
2335
|
-
const dialog = document.querySelector('#dialog-root dialog')
|
|
2336
|
-
dialog?.classList?.toggle('stale', stale)
|
|
2337
|
-
const replanBtn = document.querySelector('[data-action="replan"]')
|
|
2338
|
-
replanBtn?.classList?.toggle('primary', stale)
|
|
2339
|
-
replanBtn?.classList?.toggle('outline', !stale)
|
|
2340
|
-
}
|
|
2341
|
-
|
|
2342
|
-
let composing = false
|
|
2343
|
-
|
|
2344
|
-
function handleModelQueryChange(value) {
|
|
2345
|
-
state.modelQuery = value
|
|
2346
|
-
if (refreshCatalogResults()) return
|
|
2347
|
-
render()
|
|
2348
|
-
}
|
|
2349
|
-
|
|
2350
|
-
function handleInput(event) {
|
|
2351
|
-
if (event.target?.name === 'model-query') {
|
|
2352
|
-
if (event.isComposing || composing) return
|
|
2353
|
-
handleModelQueryChange(event.target.value)
|
|
2354
|
-
return
|
|
2355
|
-
}
|
|
2356
|
-
if (event.target?.name === 'target' && event.target.closest?.('[data-form="add-device"]')) {
|
|
2357
|
-
state.addTargetInput = event.target.value
|
|
2358
|
-
return
|
|
2359
|
-
}
|
|
2360
|
-
updatePlanOptions(event)
|
|
2361
|
-
}
|
|
2362
|
-
|
|
2363
|
-
function safeCrossLinkUrl(url) {
|
|
2364
|
-
if (typeof url !== 'string') return null
|
|
2365
|
-
const trimmed = url.trim()
|
|
2366
|
-
if (!trimmed || trimmed === '#') return null
|
|
2367
|
-
if (trimmed.startsWith('/') && !trimmed.startsWith('//')) return trimmed
|
|
2368
|
-
try {
|
|
2369
|
-
const parsed = new URL(trimmed)
|
|
2370
|
-
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') return trimmed
|
|
2371
|
-
} catch { /* invalid URL */ }
|
|
2372
|
-
return null
|
|
2373
|
-
}
|
|
2374
|
-
|
|
2375
|
-
function validCrossLinks() {
|
|
2376
|
-
return (state.crossLinks || []).map(item => {
|
|
2377
|
-
const label = typeof item?.label === 'string' ? item.label.trim() : ''
|
|
2378
|
-
const url = safeCrossLinkUrl(item?.url)
|
|
2379
|
-
return label && url ? { label, url } : null
|
|
2380
|
-
}).filter(Boolean)
|
|
2381
|
-
}
|
|
2382
|
-
|
|
2383
|
-
function renderCrossLinks() {
|
|
2384
|
-
if (typeof document === 'undefined' || typeof document.querySelector !== 'function') return
|
|
2385
|
-
const valid = validCrossLinks()
|
|
2386
|
-
const mobileCross = document.querySelector('.mobile-cross-links')
|
|
2387
|
-
if (mobileCross) {
|
|
2388
|
-
mobileCross.innerHTML = valid.map(item => `<a class="mobile-nav-item" href="${esc(item.url)}">${esc(item.label)}</a>`).join('')
|
|
2389
|
-
}
|
|
2390
|
-
const foot = document.querySelector('.sidebar-foot')
|
|
2391
|
-
if (!foot) return
|
|
2392
|
-
foot.querySelector('.cross-links')?.remove()
|
|
2393
|
-
if (!valid.length) return
|
|
2394
|
-
const nav = document.createElement('nav')
|
|
2395
|
-
nav.className = 'cross-links'
|
|
2396
|
-
nav.setAttribute('aria-label', '切换页面')
|
|
2397
|
-
nav.innerHTML = valid.map(item => `<a class="nav-item" href="${esc(item.url)}">${icon('grid', 'sm')}<span class="label">${esc(item.label)}</span></a>`).join('')
|
|
2398
|
-
const themeBtn = foot.querySelector('.theme-btn')
|
|
2399
|
-
if (themeBtn) foot.insertBefore(nav, themeBtn)
|
|
2400
|
-
else foot.prepend(nav)
|
|
2401
|
-
}
|
|
2402
|
-
|
|
2403
|
-
async function loadCrossLinks() {
|
|
2404
|
-
if (typeof fetch !== 'function') return
|
|
2405
|
-
try {
|
|
2406
|
-
const res = await fetch('/__preview_links', { cache: 'no-store' })
|
|
2407
|
-
if (!res.ok) return
|
|
2408
|
-
const data = await res.json().catch(() => null)
|
|
2409
|
-
if (Array.isArray(data?.links)) {
|
|
2410
|
-
state.crossLinks = data.links
|
|
2411
|
-
renderCrossLinks()
|
|
2412
|
-
}
|
|
2413
|
-
} catch { /* served only under web_preview */ }
|
|
2414
|
-
}
|
|
2415
|
-
|
|
2416
|
-
function activeModal() {
|
|
2417
|
-
if (state.shortcutsOpen) return { close: () => ACTIONS['close-shortcuts'](), selector: '#shortcuts-dialog-root dialog' }
|
|
2418
|
-
if (state.confirmRemove) {
|
|
2419
|
-
return {
|
|
2420
|
-
close: () => ACTIONS['close-remove'](),
|
|
2421
|
-
selector: hasDedicatedConfirmRoot() ? '#confirm-dialog-root dialog' : '#dialog-root dialog'
|
|
2422
|
-
}
|
|
2423
|
-
}
|
|
2424
|
-
if (state.planning) return { close: () => ACTIONS['close-plan'](), selector: '#dialog-root dialog' }
|
|
2425
|
-
return null
|
|
2426
|
-
}
|
|
2427
|
-
|
|
2428
|
-
function detectVisibleSection() {
|
|
2429
|
-
const scroller = document.querySelector('.scroll')
|
|
2430
|
-
if (!scroller) return 'setup-guide'
|
|
2431
|
-
if (scroller.scrollTop <= 24) return 'setup-guide'
|
|
2432
|
-
const present = NAV_ITEMS.map(i => document.getElementById(i.id)).filter(Boolean)
|
|
2433
|
-
if (!present.length) return 'setup-guide'
|
|
2434
|
-
if (scroller.scrollTop + scroller.clientHeight >= scroller.scrollHeight - 16) {
|
|
2435
|
-
return present[present.length - 1].id
|
|
2436
|
-
}
|
|
2437
|
-
const topEdge = scroller.getBoundingClientRect().top + 96
|
|
2438
|
-
let current = present[0].id
|
|
2439
|
-
for (const el of present) {
|
|
2440
|
-
if (el.getBoundingClientRect().top <= topEdge) current = el.id
|
|
2441
|
-
}
|
|
2442
|
-
return current
|
|
2443
|
-
}
|
|
2444
|
-
|
|
2445
|
-
function initScrollSpy() {
|
|
2446
|
-
const scroller = document.querySelector('.scroll')
|
|
2447
|
-
if (!scroller) return
|
|
2448
|
-
let ticking = false
|
|
2449
|
-
scroller.addEventListener('scroll', () => {
|
|
2450
|
-
if (ticking) return
|
|
2451
|
-
ticking = true
|
|
2452
|
-
requestAnimationFrame(() => {
|
|
2453
|
-
ticking = false
|
|
2454
|
-
if (Date.now() < spyLockUntil) return
|
|
2455
|
-
syncActiveNav(detectVisibleSection())
|
|
2456
|
-
})
|
|
2457
|
-
}, { passive: true })
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
function focusCatalogSearch() {
|
|
2461
|
-
const details = typeof document.querySelector === 'function' ? document.querySelector('.model-alternatives') : null
|
|
2462
|
-
if (details && !details.open) details.open = true
|
|
2463
|
-
const searchInput = typeof document.querySelector === 'function' ? document.querySelector('.catalog-search input') : null
|
|
2464
|
-
if (!searchInput) return false
|
|
2465
|
-
searchInput.scrollIntoView?.({ behavior: preferredScrollBehavior(), block: 'center' })
|
|
2466
|
-
searchInput.focus?.()
|
|
2467
|
-
searchInput.select?.()
|
|
2468
|
-
return true
|
|
2469
|
-
}
|
|
2470
|
-
|
|
2471
|
-
document.addEventListener('compositionstart', e => {
|
|
2472
|
-
if (e.target?.name === 'model-query') composing = true
|
|
2473
|
-
})
|
|
2474
|
-
document.addEventListener('compositionend', e => {
|
|
2475
|
-
if (e.target?.name === 'model-query') {
|
|
2476
|
-
composing = false
|
|
2477
|
-
handleModelQueryChange(e.target.value)
|
|
2478
|
-
}
|
|
2479
|
-
})
|
|
2480
|
-
document.addEventListener('input', handleInput)
|
|
2481
|
-
document.addEventListener('change', updatePlanOptions)
|
|
2482
|
-
document.addEventListener('toggle', e => {
|
|
2483
|
-
if (e.target?.id === 'setup-guide') ACTIONS['toggle-guide'](null, e)
|
|
2484
|
-
}, true)
|
|
2485
|
-
document.addEventListener('cancel', e => {
|
|
2486
|
-
const modal = activeModal()
|
|
2487
|
-
if (!modal || !e.target?.closest?.('#dialog-root, #confirm-dialog-root, #shortcuts-dialog-root')) return
|
|
2488
|
-
e.preventDefault()
|
|
2489
|
-
modal.close()
|
|
2490
|
-
}, true)
|
|
2491
|
-
|
|
2492
|
-
document.addEventListener('click', e => {
|
|
2493
|
-
const el = e.target.closest('[data-action]')
|
|
2494
|
-
if (!el || el.disabled || el.getAttribute?.('aria-disabled') === 'true') {
|
|
2495
|
-
if (el?.getAttribute?.('aria-disabled') === 'true') e.preventDefault()
|
|
2496
|
-
return
|
|
2497
|
-
}
|
|
2498
|
-
if (el.tagName === 'BUTTON' || el.dataset.action === 'jump-section') e.preventDefault()
|
|
2499
|
-
ACTIONS[el.dataset.action]?.(el.dataset.arg, e)
|
|
2500
|
-
})
|
|
2501
|
-
document.addEventListener('submit', e => {
|
|
2502
|
-
e.preventDefault()
|
|
2503
|
-
if (e.target.dataset.form === 'add-device') ACTIONS['submit-add']()
|
|
2504
|
-
if (e.target.dataset.form === 'replan') ACTIONS.replan()
|
|
2505
|
-
})
|
|
2506
|
-
document.addEventListener('keydown', e => {
|
|
2507
|
-
const modal = activeModal()
|
|
2508
|
-
if (modal) {
|
|
2509
|
-
if (e.key === 'Escape') {
|
|
2510
|
-
e.preventDefault()
|
|
2511
|
-
modal.close()
|
|
2512
|
-
} else if (e.key === '?' && state.shortcutsOpen && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
2513
|
-
e.preventDefault()
|
|
2514
|
-
ACTIONS['close-shortcuts']()
|
|
2515
|
-
} else if (e.key === 'Tab') {
|
|
2516
|
-
const dialog = document.querySelector(modal.selector)
|
|
2517
|
-
if (!dialog) return
|
|
2518
|
-
const controls = [...dialog.querySelectorAll('button, input, select, [tabindex]')]
|
|
2519
|
-
.filter(control => !control.disabled && control.tabIndex >= 0 && control.getClientRects().length)
|
|
2520
|
-
const first = controls[0]
|
|
2521
|
-
const last = controls[controls.length - 1]
|
|
2522
|
-
if (e.shiftKey && (document.activeElement === first || !controls.includes(document.activeElement))) {
|
|
2523
|
-
e.preventDefault()
|
|
2524
|
-
last?.focus()
|
|
2525
|
-
} else if (!e.shiftKey && document.activeElement === last) {
|
|
2526
|
-
e.preventDefault()
|
|
2527
|
-
first?.focus()
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
return
|
|
2531
|
-
}
|
|
2532
|
-
const isEditing = ['INPUT', 'TEXTAREA', 'SELECT'].includes(document.activeElement?.tagName) || document.activeElement?.isContentEditable
|
|
2533
|
-
if (!isEditing && !e.isComposing && !composing && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
2534
|
-
if (e.key === '/') {
|
|
2535
|
-
if (focusCatalogSearch()) e.preventDefault()
|
|
2536
|
-
} else if (e.key >= '1' && e.key <= '5') {
|
|
2537
|
-
const idx = parseInt(e.key, 10) - 1
|
|
2538
|
-
if (idx >= 0 && idx < NAV_ITEMS.length) {
|
|
2539
|
-
e.preventDefault()
|
|
2540
|
-
ACTIONS['jump-section'](NAV_ITEMS[idx].id)
|
|
2541
|
-
}
|
|
2542
|
-
} else if (e.key === 't' || e.key === 'T') {
|
|
2543
|
-
e.preventDefault()
|
|
2544
|
-
ACTIONS['cycle-theme']()
|
|
2545
|
-
} else if (e.key === '?') {
|
|
2546
|
-
e.preventDefault()
|
|
2547
|
-
ACTIONS['open-shortcuts']()
|
|
2548
|
-
}
|
|
2549
|
-
}
|
|
2550
|
-
})
|
|
2551
|
-
|
|
2552
|
-
// Tooltip (Tip)
|
|
2553
|
-
const tipEl = document.getElementById('tip')
|
|
2554
|
-
function showTip(t) {
|
|
2555
|
-
if (!t || (t.classList?.contains('pill') && !t.closest('dialog') && t.hasAttribute('title'))) {
|
|
2556
|
-
tipEl.classList.remove('show')
|
|
2557
|
-
return
|
|
2558
|
-
}
|
|
2559
|
-
// A modal dialog sits in the top layer; a tip for something inside it must live there too.
|
|
2560
|
-
const layer = t.closest('dialog') || document.body
|
|
2561
|
-
if (tipEl.parentElement !== layer) layer.append(tipEl)
|
|
2562
|
-
tipEl.textContent = t.dataset.tip
|
|
2563
|
-
const r = t.getBoundingClientRect()
|
|
2564
|
-
tipEl.classList.add('show')
|
|
2565
|
-
const w = tipEl.offsetWidth
|
|
2566
|
-
const h = tipEl.offsetHeight
|
|
2567
|
-
const left = Math.max(8, Math.min(innerWidth - w - 8, r.left + r.width / 2 - w / 2))
|
|
2568
|
-
const top = r.bottom + h + 12 > innerHeight && r.top - h - 6 >= 8
|
|
2569
|
-
? r.top - h - 6
|
|
2570
|
-
: Math.max(8, Math.min(innerHeight - h - 8, r.bottom + 6))
|
|
2571
|
-
tipEl.style.left = `${left}px`
|
|
2572
|
-
tipEl.style.top = `${top}px`
|
|
2573
|
-
}
|
|
2574
|
-
document.addEventListener('mouseover', e => showTip(e.target.closest('[data-tip]')))
|
|
2575
|
-
document.addEventListener('focusin', e => showTip(e.target.closest('[data-tip]')))
|
|
2576
|
-
document.addEventListener('focusout', () => showTip(null))
|
|
2577
|
-
document.addEventListener('keydown', e => { if (e.key === 'Escape') showTip(null) })
|
|
2578
|
-
// A fixed tip would stay where its element was.
|
|
2579
|
-
document.addEventListener('scroll', () => showTip(null), true)
|
|
2580
|
-
|
|
2581
|
-
hydrateIcons()
|
|
2582
|
-
initTheme()
|
|
2583
|
-
const brandNavItem = document.querySelector('.sidebar > .nav-item[aria-current="page"]')
|
|
2584
|
-
if (brandNavItem) {
|
|
2585
|
-
brandNavItem.setAttribute('role', 'button')
|
|
2586
|
-
brandNavItem.tabIndex = 0
|
|
2587
|
-
brandNavItem.addEventListener('click', () => ACTIONS['jump-section']('setup-guide'))
|
|
2588
|
-
brandNavItem.addEventListener('keydown', e => {
|
|
2589
|
-
if (e.key === 'Enter' || e.key === ' ') {
|
|
2590
|
-
e.preventDefault()
|
|
2591
|
-
ACTIONS['jump-section']('setup-guide')
|
|
2592
|
-
}
|
|
2593
|
-
})
|
|
2594
|
-
}
|
|
2595
|
-
renderChrome()
|
|
2596
|
-
initScrollSpy()
|
|
2597
|
-
addEventListener('hashchange', () => {
|
|
2598
|
-
const id = location.hash.slice(1)
|
|
2599
|
-
if (NAV_ITEMS.some(item => item.id === id)) ACTIONS['jump-section'](id)
|
|
2600
|
-
})
|
|
2601
|
-
loadCrossLinks()
|
|
2602
|
-
loadDevices().then(() => loadDevice()).catch(e => { state.error = e.message; render() })
|
|
2603
|
-
</script>
|
|
2604
|
-
</body>
|
|
2605
|
-
</html>
|