@simplexai/localmodels-darwin-arm64 0.1.0-dev.36 → 0.1.0-dev.38

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.
Files changed (134) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +132 -110
  3. package/kit.py +1 -0
  4. package/modules/localmodels/__init__.py +1 -1
  5. package/modules/localmodels/__main__.py +9 -3
  6. package/modules/localmodels/bifrost_checks.py +9 -6
  7. package/modules/localmodels/bifrost_config.py +203 -0
  8. package/modules/localmodels/bifrost_datasheet.py +12 -2
  9. package/modules/localmodels/budget.py +13 -2
  10. package/modules/localmodels/catalog.json +137 -2
  11. package/modules/localmodels/catalog.py +70 -321
  12. package/modules/localmodels/catalog_add.py +2 -8
  13. package/modules/localmodels/catalog_recipes.py +352 -0
  14. package/modules/localmodels/cli_parser.py +4 -1
  15. package/modules/localmodels/console.py +5 -4
  16. package/modules/localmodels/contracts.py +13 -3
  17. package/modules/localmodels/debug_cli.py +158 -0
  18. package/modules/localmodels/debug_mode.py +727 -0
  19. package/modules/localmodels/debug_stub_server.py +192 -0
  20. package/modules/localmodels/decode_calibration.json +1 -1
  21. package/modules/localmodels/decode_calibration.py +34 -17
  22. package/modules/localmodels/gateway.py +21 -155
  23. package/modules/localmodels/gateway_accept.py +201 -0
  24. package/modules/localmodels/gateway_bifrost.py +30 -193
  25. package/modules/localmodels/gateway_cli.py +15 -6
  26. package/modules/localmodels/gateway_foundations.py +2 -4
  27. package/modules/localmodels/gateway_probe.py +0 -1
  28. package/modules/localmodels/gateway_server.py +2 -3
  29. package/modules/localmodels/gpu_specs.py +12 -0
  30. package/modules/localmodels/guard.py +2 -7
  31. package/modules/localmodels/harness.py +16 -129
  32. package/modules/localmodels/harness_cleanup.py +135 -0
  33. package/modules/localmodels/harness_gateway.py +16 -14
  34. package/modules/localmodels/harness_probe.py +12 -4
  35. package/modules/localmodels/hosts.py +25 -2
  36. package/modules/localmodels/http_local.py +59 -0
  37. package/modules/localmodels/install.py +23 -8
  38. package/modules/localmodels/library_gateway.py +20 -9
  39. package/modules/localmodels/library_jobs.py +125 -28
  40. package/modules/localmodels/library_model.py +10 -0
  41. package/modules/localmodels/library_pricing.py +29 -22
  42. package/modules/localmodels/library_serve.py +17 -1
  43. package/modules/localmodels/library_state.py +15 -2
  44. package/modules/localmodels/library_status.py +30 -0
  45. package/modules/localmodels/llm_rank.py +185 -39
  46. package/modules/localmodels/probe.py +108 -174
  47. package/modules/localmodels/process_identity.py +120 -154
  48. package/modules/localmodels/process_windows.py +86 -0
  49. package/modules/localmodels/recommend.py +6 -3
  50. package/modules/localmodels/recommend_cli.py +14 -6
  51. package/modules/localmodels/remote_ops.py +65 -0
  52. package/modules/localmodels/remote_ops_service.py +14 -2
  53. package/modules/localmodels/runtime_args.py +10 -3
  54. package/modules/localmodels/runtime_auth.py +5 -9
  55. package/modules/localmodels/runtime_cli.py +128 -129
  56. package/modules/localmodels/runtime_discovery.py +84 -0
  57. package/modules/localmodels/runtime_install.py +101 -0
  58. package/modules/localmodels/runtime_releases.py +302 -0
  59. package/modules/localmodels/search_server.py +5 -1
  60. package/modules/localmodels/service_stop.py +8 -108
  61. package/modules/localmodels/service_upgrade.py +394 -63
  62. package/modules/localmodels/services_cli.py +24 -14
  63. package/modules/localmodels/setup_inspection.py +97 -9
  64. package/modules/localmodels/setup_text.py +7 -0
  65. package/modules/localmodels/sizecalc.py +0 -1
  66. package/modules/localmodels/stack.py +45 -235
  67. package/modules/localmodels/stack_arena.py +732 -0
  68. package/modules/localmodels/stack_args.py +21 -12
  69. package/modules/localmodels/stack_auto.py +384 -3
  70. package/modules/localmodels/stack_aux_gpu.py +4 -3
  71. package/modules/localmodels/stack_capacity.py +138 -0
  72. package/modules/localmodels/stack_cleanup.py +9 -4
  73. package/modules/localmodels/stack_cli.py +288 -0
  74. package/modules/localmodels/stack_compose.py +63 -30
  75. package/modules/localmodels/stack_console.py +9 -6
  76. package/modules/localmodels/stack_hardware.py +95 -265
  77. package/modules/localmodels/stack_hardware_text.py +263 -0
  78. package/modules/localmodels/stack_journal.py +3 -9
  79. package/modules/localmodels/stack_ledger.py +48 -18
  80. package/modules/localmodels/stack_lifecycle.py +33 -312
  81. package/modules/localmodels/stack_llm_ram.py +16 -6
  82. package/modules/localmodels/stack_mcp.py +729 -0
  83. package/modules/localmodels/stack_memory.py +0 -2
  84. package/modules/localmodels/stack_picks.py +62 -15
  85. package/modules/localmodels/stack_plan.py +19 -1
  86. package/modules/localmodels/stack_preflight.py +11 -19
  87. package/modules/localmodels/stack_progress.py +9 -1
  88. package/modules/localmodels/stack_remove.py +373 -0
  89. package/modules/localmodels/stack_route.py +101 -17
  90. package/modules/localmodels/stack_run.py +29 -0
  91. package/modules/localmodels/stack_suite.py +21 -10
  92. package/modules/localmodels/stack_summary.py +14 -0
  93. package/modules/localmodels/stack_try.py +238 -24
  94. package/modules/localmodels/stack_try_client.py +53 -15
  95. package/modules/localmodels/stack_try_docs.py +2 -2
  96. package/modules/localmodels/stack_view.py +24 -171
  97. package/modules/localmodels/stack_view_access.py +114 -1
  98. package/modules/localmodels/stack_view_agent.py +3 -13
  99. package/modules/localmodels/stack_view_hub.py +9 -10
  100. package/modules/localmodels/stack_view_llm.py +1 -1
  101. package/modules/localmodels/stack_view_sandbox.py +2 -2
  102. package/modules/localmodels/stack_view_schema.py +183 -0
  103. package/modules/localmodels/stack_view_serve.py +7 -1
  104. package/modules/localmodels/stack_view_service.py +1 -2
  105. package/modules/localmodels/stack_view_text.py +13 -9
  106. package/modules/localmodels/stack_warm.py +48 -4
  107. package/modules/localmodels/stack_warm_store.py +517 -0
  108. package/modules/localmodels/tools.json +32 -18
  109. package/modules/localmodels/transport.py +38 -13
  110. package/modules/localmodels/tui.py +28 -4
  111. package/modules/localmodels/tui_dialogs.py +136 -0
  112. package/modules/localmodels/tui_modals.py +279 -0
  113. package/modules/localmodels/tui_screen.py +113 -154
  114. package/modules/localmodels/tui_views.py +134 -203
  115. package/modules/localmodels/web/index.html +510 -101
  116. package/modules/localmodels/web/sizecalc/app.js +363 -10
  117. package/modules/localmodels/web/sizecalc/page.html +27 -3
  118. package/modules/localmodels/web/view/fleet.html +11 -2
  119. package/modules/localmodels/web/view/fleet.js +191 -17
  120. package/modules/localmodels/web/view/i18n.js +3 -2
  121. package/modules/localmodels/web/view/index.html +1 -1
  122. package/modules/localmodels/web/view/nav.js +22 -3
  123. package/modules/localmodels/web/view/view.css +63 -18
  124. package/modules/localmodels/web/view/view.js +169 -32
  125. package/modules/localmodels/windows_job.py +69 -0
  126. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/METADATA +1 -1
  127. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/RECORD +128 -106
  128. package/package.json +1 -1
  129. package/tool.json +1 -1
  130. package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
  131. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/WHEEL +0 -0
  132. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/entry_points.txt +0 -0
  133. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/NOTICE +0 -0
  134. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -14,6 +14,7 @@
14
14
  -->
15
15
  <style>
16
16
  :root {
17
+ color-scheme: light dark;
17
18
  --bg: #fbfbfc;
18
19
  --sidebar-bg: #f4f5f7;
19
20
  --fg: #1f2329;
@@ -30,7 +31,7 @@
30
31
  --primary-hover: #084fd6;
31
32
  --primary-soft: rgba(10, 92, 245, .10);
32
33
  --primary-fg: #ffffff;
33
- --success: #047857;
34
+ --success: #036c4e;
34
35
  --success-soft: rgba(16, 185, 129, .10);
35
36
  --warn: #985100;
36
37
  --warn-soft: rgba(245, 158, 11, .12);
@@ -40,8 +41,10 @@
40
41
  --caption-size: 12px;
41
42
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
42
43
  }
44
+ :root[data-theme="light"] { color-scheme: light; }
43
45
  @media (prefers-color-scheme: dark) {
44
46
  :root:not([data-theme="light"]) {
47
+ color-scheme: dark;
45
48
  --bg: #17181b; --sidebar-bg: #1d1f23; --fg: #e8eaed; --text-secondary: #c4c8cf;
46
49
  --text-tertiary: #9aa0a8; --muted-fg: #a1a7b0; --muted-bg: #2a2d33; --border: #2c2f35;
47
50
  --stroke: #3a3e45; --nav-active: #283244; --nav-active-border: #34425a; --nav-hover: #25282e;
@@ -51,6 +54,7 @@
51
54
  }
52
55
  }
53
56
  :root[data-theme="dark"] {
57
+ color-scheme: dark;
54
58
  --bg: #17181b; --sidebar-bg: #1d1f23; --fg: #e8eaed; --text-secondary: #c4c8cf;
55
59
  --text-tertiary: #9aa0a8; --muted-fg: #a1a7b0; --muted-bg: #2a2d33; --border: #2c2f35;
56
60
  --stroke: #3a3e45; --nav-active: #283244; --nav-active-border: #34425a; --nav-hover: #25282e;
@@ -83,22 +87,38 @@ svg.i.xs { width: 12px; height: 12px; }
83
87
  background: var(--sidebar-bg);
84
88
  border-right: 1px solid var(--border);
85
89
  display: flex; flex-direction: column;
86
- padding: 12px 10px 8px 4px;
90
+ padding: 12px 10px 10px 8px;
87
91
  min-height: 0;
88
92
  }
93
+ .nav-list { display: grid; gap: 2px; }
89
94
  .nav-item {
90
95
  display: flex; align-items: center; gap: 8px;
91
- min-height: 28px; width: 100%;
92
- padding: 0 8px 0 12px;
93
- border: 1px solid transparent; border-radius: 4px;
94
- background: var(--nav-active); text-align: left;
95
- color: var(--fg);
96
+ min-height: 30px; width: 100%;
97
+ padding: 0 8px 0 10px;
98
+ border: 1px solid transparent; border-radius: 5px;
99
+ background: transparent; text-align: left; text-decoration: none;
100
+ color: var(--text-secondary);
96
101
  }
102
+ a.nav-item:hover { background: var(--nav-hover); color: var(--fg); }
103
+ .nav-item[aria-current="page"] { background: var(--nav-active); border-color: var(--nav-active-border); color: var(--fg); font-weight: 500; }
97
104
  .nav-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
105
+ .sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); display: grid; gap: 8px; }
106
+ .cross-links { display: grid; gap: 2px; }
107
+ .theme-btn {
108
+ display: inline-flex; align-items: center; gap: 8px;
109
+ width: 100%; min-height: 30px; padding: 0 10px;
110
+ border: 1px solid var(--border); border-radius: 5px;
111
+ background: var(--bg); color: var(--text-secondary);
112
+ font-size: 12px; cursor: pointer; text-align: left;
113
+ }
114
+ .theme-btn:hover { background: var(--nav-hover); color: var(--fg); }
98
115
 
99
116
  .main { position: relative; min-height: 0; display: flex; flex-direction: column; }
100
- .scroll { flex: 1; overflow-y: auto; padding: 24px 70px 80px 57px; }
101
- .page-title { margin: 0 0 14px; font-size: 16px; font-weight: 600; }
117
+ .scroll { flex: 1; overflow-y: auto; padding: 24px 70px 80px 57px; scroll-behavior: smooth; }
118
+ .page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
119
+ .page-title { margin: 0; font-size: 16px; font-weight: 600; }
120
+ .mobile-theme-btn { display: none; }
121
+ .setup-guide, .section { scroll-margin-top: 16px; }
102
122
 
103
123
  /* ── Settings primitives (primitives.tsx) ── */
104
124
  .section { margin-bottom: 24px; }
@@ -116,6 +136,7 @@ svg.i.xs { width: 12px; height: 12px; }
116
136
  .pill svg { width: 12px; height: 12px; }
117
137
  .pill.primary { background: var(--primary-soft); color: var(--primary); }
118
138
  .recommended-model .pill.primary { background: transparent; }
139
+ .recommended-model .pill:not(.primary) { background: var(--bg); }
119
140
  .pill.success { background: var(--success-soft); color: var(--success); }
120
141
  .pill.warn { background: var(--warn-soft); color: var(--warn); }
121
142
  .pill.destructive { background: var(--danger-soft); color: var(--danger); }
@@ -126,9 +147,18 @@ svg.i.xs { width: 12px; height: 12px; }
126
147
  .row-action { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
127
148
  .pills { margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
128
149
  .rows { display: grid; gap: 4px; }
129
- .setup-guide { padding: 14px 16px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 20px; }
130
- .setup-guide h1 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
131
- .setup-guide p { margin: 6px 0; color: var(--text-secondary); }
150
+ .setup-guide { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 20px; }
151
+ .setup-guide-summary {
152
+ display: flex; align-items: center; justify-content: space-between; gap: 12px;
153
+ padding: 12px 16px; cursor: pointer; font-weight: 600; color: var(--fg); list-style: none;
154
+ }
155
+ .setup-guide-summary::-webkit-details-marker { display: none; }
156
+ .setup-guide-summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
157
+ .setup-guide-toggle { display: inline-flex; align-items: center; color: var(--muted-fg); flex-shrink: 0; }
158
+ .setup-guide-toggle svg { transition: transform .15s; }
159
+ .setup-guide[open] .setup-guide-toggle svg { transform: rotate(90deg); }
160
+ .setup-guide-body { padding: 0 16px 14px; border-top: 1px solid var(--border); }
161
+ .setup-guide p { margin: 8px 0 0; color: var(--text-secondary); }
132
162
  .install-command { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
133
163
  .setup-guide code { overflow-wrap: anywhere; }
134
164
  .recommended-model { padding: 8px 12px; border: 1px solid var(--primary); border-radius: 8px; background: var(--primary-soft); }
@@ -140,6 +170,7 @@ svg.i.xs { width: 12px; height: 12px; }
140
170
  @media (max-width: 760px) {
141
171
  .window { grid-template-columns: 1fr; }
142
172
  .sidebar { display: none; }
173
+ .mobile-theme-btn { display: inline-flex; }
143
174
  .scroll { padding: 40px 16px 60px; }
144
175
  .row { grid-template-columns: 1fr; }
145
176
  .row-action { justify-content: flex-start; }
@@ -154,6 +185,8 @@ svg.i.xs { width: 12px; height: 12px; }
154
185
  .btn svg { width: 14px; height: 14px; }
155
186
  .btn.primary { background: var(--primary); color: var(--primary-fg); }
156
187
  .btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
188
+ .btn.danger { background: var(--danger); color: var(--primary-fg); }
189
+ .btn.danger:hover:not(:disabled) { opacity: .9; }
157
190
  .btn.outline { background: var(--bg); border-color: var(--stroke); color: var(--fg); box-shadow: var(--shadow); }
158
191
  .btn.outline:hover:not(:disabled) { background: var(--nav-hover); }
159
192
  .btn.ghost { background: none; color: var(--text-secondary); }
@@ -165,7 +198,7 @@ svg.i.xs { width: 12px; height: 12px; }
165
198
  .hw { display: flex; flex-wrap: wrap; align-items: center; column-gap: 20px; row-gap: 4px; padding: 4px 0; font-size: var(--caption-size); color: var(--muted-fg); }
166
199
  .hw span { display: inline-flex; align-items: center; gap: 6px; }
167
200
 
168
- .progress { height: 4px; border-radius: 99px; background: var(--muted-bg); overflow: hidden; }
201
+ .progress { height: 4px; border-radius: 99px; background: var(--muted-bg); overflow: hidden; box-shadow: inset 0 0 0 1px var(--border); }
169
202
  .progress > div { height: 100%; background: var(--primary); border-radius: inherit; transition: width .3s; }
170
203
  .progress.paused > div { background: var(--muted-fg); }
171
204
  .progress-text { font-size: 11px; color: var(--muted-fg); }
@@ -173,10 +206,10 @@ svg.i.xs { width: 12px; height: 12px; }
173
206
 
174
207
  .hint { font-size: 12px; color: var(--muted-fg); margin: 0; }
175
208
  .busy-note { display: flex; gap: 6px; align-items: flex-start; margin: 0 0 10px; padding: 8px 10px; border-radius: 8px; background: var(--warn-soft); color: var(--fg); }
176
- .search-field { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 2px; margin-top: 4px; color: var(--muted-fg); }
209
+ .search-field { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 4px; margin: 6px 0; color: var(--muted-fg); border-bottom: 1px solid var(--border); }
177
210
  .search-field input { flex: 1; border: 0; outline: 0; background: none; color: var(--fg); font: inherit; font-size: 12px; }
178
211
  .search-field input::placeholder { color: var(--muted-fg); opacity: 1; }
179
- .search-field:focus-within { box-shadow: inset 0 -1px 0 var(--stroke); }
212
+ .search-field:focus-within { border-bottom-color: var(--primary); box-shadow: inset 0 -1px 0 var(--primary); }
180
213
  .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
181
214
  .row-desc .mono { overflow-wrap: anywhere; }
182
215
  .files { margin-left: 16px; padding: 4px 0 4px 12px; border-left: 1px solid var(--border); display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 6px; }
@@ -201,21 +234,6 @@ svg.i.xs { width: 12px; height: 12px; }
201
234
  .toast { min-width: 240px; max-width: 360px; padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(16,24,40,.12); font-size: 12px; }
202
235
  .toast b { display: block; font-weight: 600; margin-bottom: 2px; }
203
236
 
204
- /* Quickstart hero (local-models-quickstart.tsx) */
205
- .hero { min-height: 60vh; display: flex; align-items: center; justify-content: center; }
206
- .hero-inner { width: 100%; max-width: 28rem; text-align: center; }
207
- .hero-icon { margin: 0 auto 20px; width: 56px; height: 56px; border-radius: 16px; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; }
208
- .hero-icon svg { width: 28px; height: 28px; }
209
- .hero h2 { margin: 0; font-size: 18px; font-weight: 600; }
210
- .hero p { margin: 8px 0 0; font-size: 13px; line-height: 1.55; color: var(--muted-fg); }
211
- .hero .actions { margin-top: 24px; display: flex; justify-content: center; gap: 12px; }
212
- .stages { margin-top: 20px; display: flex; justify-content: center; gap: 20px; font-size: 11.5px; }
213
- .stages span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-tertiary); }
214
- .stages .now { color: var(--fg); font-weight: 500; }
215
- .stages .later { opacity: .6; }
216
- .stages .dot { width: 6px; height: 6px; border-radius: 99px; background: currentColor; }
217
-
218
-
219
237
  /* Devices (localmodels extension) */
220
238
  .devices { display: flex; flex-wrap: wrap; gap: 8px; }
221
239
  .device { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; min-width: 200px; max-width: 320px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); cursor: pointer; text-align: left; }
@@ -235,11 +253,16 @@ svg.i.xs { width: 12px; height: 12px; }
235
253
  .gpu { display: grid; grid-template-columns: minmax(0, 22rem) 140px auto auto; gap: 12px; align-items: center; font-size: 12px; color: var(--muted-fg); }
236
254
  .gpu-name { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
237
255
  .gpu-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
238
- .gpu-bar { height: 4px; border-radius: 99px; background: var(--muted-bg); overflow: hidden; }
239
- .gpu-bar > span { display: block; height: 100%; background: var(--warn); }
256
+ .gpu-bar { height: 4px; border-radius: 99px; background: var(--muted-bg); overflow: hidden; box-shadow: inset 0 0 0 1px var(--border); }
257
+ .gpu-bar > span { display: block; height: 100%; background: var(--primary); }
258
+ .gpu-bar.busy > span { background: var(--warn); }
259
+ .gpu-meta { font-variant-numeric: tabular-nums; }
260
+ .gpu-meta.warn { color: var(--warn); font-weight: 500; }
261
+ .live-status { color: var(--text-secondary); }
240
262
  .error-text { color: var(--danger); font-size: 12px; white-space: pre-wrap; }
241
263
  .dialog::backdrop { background: rgba(15, 18, 24, .35); }
242
264
  .dialog { width: min(760px, calc(100% - 32px)); max-height: calc(100vh - 32px); margin: auto; padding: 0; flex-direction: column; background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
265
+ .dialog.dialog-sm { width: min(440px, calc(100% - 32px)); }
243
266
  .dialog[open] { display: flex; }
244
267
  .dialog-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
245
268
  .dialog-head b { flex: 1; font-weight: 600; }
@@ -262,8 +285,9 @@ dl.plan pre { margin: 0; white-space: pre-wrap; word-break: break-all; font: 11p
262
285
  .warnings { margin: 12px 0 0; padding: 8px 12px; list-style: none; background: var(--warn-soft); color: var(--warn); border-radius: 6px; display: grid; gap: 4px; }
263
286
  .warnings li { display: flex; gap: 6px; align-items: center; }
264
287
  .gate { margin: 0 0 12px; padding: 8px 12px; border-radius: 6px; display: grid; gap: 6px; }
265
- .gate.warn { background: var(--warn-soft); color: var(--warn); }
266
- .gate.danger { background: var(--danger-soft); color: var(--danger); }
288
+ .gate.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--border)); }
289
+ .gate.danger { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); }
290
+ .gate p { margin: 0; }
267
291
  .gate ul { margin: 0; padding-left: 16px; }
268
292
  .gate label { display: flex; gap: 6px; align-items: center; color: var(--fg); }
269
293
  dl.plan dt.changed { color: var(--warn); font-weight: 600; }
@@ -272,18 +296,37 @@ dl.plan dd.changed { box-shadow: inset 2px 0 var(--warn); padding-left: 8px; }
272
296
  .candidate, .gpu { grid-template-columns: 1fr; gap: 2px; }
273
297
  dl.plan { grid-template-columns: 1fr; }
274
298
  }
299
+ @media (prefers-reduced-motion: reduce) {
300
+ .scroll { scroll-behavior: auto; }
301
+ .spin { animation: none; }
302
+ .progress > div, .tip, .setup-guide-toggle svg { transition: none; }
303
+ }
275
304
  </style>
276
305
  </head>
277
306
  <body>
278
307
  <div class="window">
279
308
  <aside class="sidebar" aria-label="当前设置">
280
- <div class="nav-item" aria-current="page">
281
- <span data-icon="cpu"></span><span class="label">本地模型</span>
309
+ <nav class="nav-list" aria-label="页面导航">
310
+ <div class="nav-item active" aria-current="page"><span data-icon="cpu" data-size="sm"></span><span class="label">单模型设置</span></div>
311
+ <a class="nav-item" href="#sec-devices"><span data-icon="network" data-size="sm"></span><span class="label">设备</span></a>
312
+ <a class="nav-item" href="#sec-models"><span data-icon="download" data-size="sm"></span><span class="label">单模型目录</span></a>
313
+ <a class="nav-item" href="#sec-runtime"><span data-icon="zap" data-size="sm"></span><span class="label">本地运行时</span></a>
314
+ <a class="nav-item" href="#sec-hardware"><span data-icon="monitor" data-size="sm"></span><span class="label">本机配置</span></a>
315
+ </nav>
316
+ <div class="sidebar-foot">
317
+ <button type="button" class="theme-btn" data-action="cycle-theme" aria-label="切换外观主题">
318
+ <span class="theme-icon" data-icon="sun" data-size="sm"></span><span class="theme-label">跟随系统</span>
319
+ </button>
282
320
  </div>
283
321
  </aside>
284
322
  <main class="main">
285
323
  <div class="scroll">
286
- <h1 class="page-title">本地模型设置</h1>
324
+ <div class="page-head">
325
+ <h1 class="page-title">本地模型设置</h1>
326
+ <button type="button" class="btn outline mobile-theme-btn" data-action="cycle-theme" aria-label="切换外观主题">
327
+ <span class="theme-icon" data-icon="sun" data-size="sm"></span><span class="theme-label">跟随系统</span>
328
+ </button>
329
+ </div>
287
330
  <div id="page"></div>
288
331
  </div>
289
332
  </main>
@@ -336,7 +379,10 @@ const ICONS = {
336
379
  play: '<polygon points="6 3 20 12 6 21 6 3"/>',
337
380
  stop: '<rect width="14" height="14" x="5" y="5" rx="2" fill="currentColor"/>',
338
381
  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"/>',
339
- eject: '<path d="M5 18h14"/><path d="M12 5 5 14h14z"/>'
382
+ eject: '<path d="M5 18h14"/><path d="M12 5 5 14h14z"/>',
383
+ 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"/>',
384
+ moon: '<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>',
385
+ 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"/>'
340
386
  }
341
387
 
342
388
  function icon(name, size = '', extra = '') {
@@ -359,6 +405,7 @@ async function api(path, options = {}) {
359
405
  init.headers['Content-Type'] = 'application/json'
360
406
  init.body = JSON.stringify(options.body)
361
407
  }
408
+ if (options.signal) init.signal = options.signal
362
409
  const res = await fetch(`/api/${path}`, init)
363
410
  const data = await res.json().catch(() => ({}))
364
411
  if (!res.ok) throw Object.assign(new Error(data.error || `HTTP ${res.status}`), { status: res.status, data })
@@ -438,8 +485,12 @@ const state = {
438
485
  adding: false,
439
486
  candidates: null,
440
487
  planning: null, // { model_id, plan_id, plan, options, error, busy, changed, occupied, share }
488
+ confirmRemove: null, // { name, busy }
489
+ modelQuery: '',
441
490
  jobs: {}, // model id -> job
442
- serviceBusy: {}
491
+ serviceBusy: {},
492
+ guideOpen: null,
493
+ crossLinks: []
443
494
  }
444
495
 
445
496
  function localStorageGet(key) {
@@ -448,6 +499,58 @@ function localStorageGet(key) {
448
499
  function localStorageSet(key, value) {
449
500
  try { localStorage.setItem(key, value) } catch { /* private window */ }
450
501
  }
502
+ function localStorageRemove(key) {
503
+ try { localStorage.removeItem(key) } catch { /* private window */ }
504
+ }
505
+
506
+ const THEME_KEY = 'localmodels.theme'
507
+ const THEME_CYCLE = ['auto', 'light', 'dark']
508
+ const THEME_LABEL = { auto: '跟随系统', light: '浅色', dark: '深色' }
509
+
510
+ function currentTheme() {
511
+ const saved = localStorageGet(THEME_KEY)
512
+ return saved === 'light' || saved === 'dark' ? saved : 'auto'
513
+ }
514
+
515
+ function effectiveTheme(mode) {
516
+ if (mode === 'light' || mode === 'dark') return mode
517
+ return typeof matchMedia === 'function' && matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
518
+ }
519
+
520
+ function updateThemeButtons(mode) {
521
+ if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return
522
+ const iconName = effectiveTheme(mode) === 'dark' ? 'moon' : 'sun'
523
+ const label = THEME_LABEL[mode] || THEME_LABEL.auto
524
+ document.querySelectorAll('[data-action="cycle-theme"]').forEach(btn => {
525
+ btn.title = `当前主题:${label}(点击切换)`
526
+ btn.setAttribute('aria-label', `切换外观主题(当前:${label})`)
527
+ const labelEl = btn.querySelector('.theme-label')
528
+ if (labelEl) labelEl.textContent = label
529
+ const iconWrap = btn.querySelector('.theme-icon')
530
+ if (iconWrap) {
531
+ iconWrap.dataset.icon = iconName
532
+ iconWrap.innerHTML = icon(iconName, iconWrap.dataset.size || 'sm')
533
+ }
534
+ })
535
+ }
536
+
537
+ function applyTheme(mode) {
538
+ if (typeof document !== 'undefined' && document.documentElement) {
539
+ if (mode === 'light' || mode === 'dark') document.documentElement.dataset.theme = mode
540
+ else delete document.documentElement.dataset.theme
541
+ }
542
+ updateThemeButtons(mode)
543
+ }
544
+
545
+ function initTheme() {
546
+ applyTheme(currentTheme())
547
+ if (typeof matchMedia === 'function') {
548
+ const mq = matchMedia('(prefers-color-scheme: dark)')
549
+ mq.addEventListener?.('change', () => {
550
+ if (currentTheme() === 'auto') updateThemeButtons('auto')
551
+ })
552
+ }
553
+ }
451
554
 
452
555
  // ── Components (primitives.tsx) ──
453
556
  function pill(tone, body, tip) {
@@ -486,30 +589,41 @@ function section({ iconName, title, meta, aside = '', id = '' }, body) {
486
589
  }
487
590
 
488
591
  // ── Sections ──
592
+ function guideIsOpen() {
593
+ if (typeof state.guideOpen === 'boolean') return state.guideOpen
594
+ const collapsed = localStorageGet('localmodels.guideCollapsed')
595
+ if (state.deployments.length > 0) return collapsed === '0'
596
+ return collapsed !== '1'
597
+ }
598
+
489
599
  function setupGuide() {
490
- return `<section class="setup-guide" aria-labelledby="setup-title">
491
- <h1 id="setup-title">单模型设置</h1>
492
- <p>本页只部署一个模型,不会安装完整套件。首次使用、希望装好后直接开始任务?请在<strong>要安装的设备终端</strong>运行:</p>
493
- <div class="install-command"><code class="mono">python3 -m localmodels install</code>${btn({ label: '复制完整安装命令', action: 'copy-install' })}</div>
494
- <p>完整安装:检测设备 → 生成套件计划 → 确认一次 → 安装并验收。最终组件与资源需求以计划为准;复制命令不会执行安装。</p>
495
- <p>装好后,运行 <code class="mono">python3 -m localmodels stack status</code> 检查各组件状态;运行 <code class="mono">python3 -m localmodels stack clients</code> 查看客户端接入方式。</p>
496
- </section>`
600
+ const open = guideIsOpen()
601
+ return `<details id="setup-guide" class="setup-guide"${open ? ' open' : ''} aria-labelledby="setup-title">
602
+ <summary id="setup-title" class="setup-guide-summary"><span>单模型设置 · 快速上手与完整套件安装命令</span><span class="setup-guide-toggle">${icon('chevronRight', 'sm')}</span></summary>
603
+ <div class="setup-guide-body">
604
+ <p>本页只部署一个模型,不会安装完整套件。首次使用、希望装好后直接开始任务?请在<strong>要安装的设备终端</strong>运行:</p>
605
+ <div class="install-command"><code class="mono">python3 -m localmodels install</code>${btn({ label: '复制完整安装命令', action: 'copy-install' })}</div>
606
+ <p>完整安装:检测设备 → 生成套件计划 → 确认一次 → 安装并验收。最终组件与资源需求以计划为准;复制命令不会执行安装。</p>
607
+ <p>装好后,运行 <code class="mono">python3 -m localmodels stack status</code> 检查各组件状态;运行 <code class="mono">python3 -m localmodels stack clients</code> 查看客户端接入方式。</p>
608
+ </div>
609
+ </details>`
497
610
  }
498
611
 
499
612
  function deviceSection() {
500
613
  const chips = state.devices.map(d => {
501
614
  const f = d.facts
502
615
  const gpus = f?.gpus?.length ? `${f.gpus.length}× ${f.gpus[0].name.replace(/^NVIDIA (GeForce )?/, '')}` : f ? (f.platform === 'darwin' ? 'Apple 统一内存' : '无独立 GPU') : '未检测'
616
+ const displayLabel = d.id === 'local' && d.label === 'this computer' ? '本机' : d.label
503
617
  return `<button class="device${d.id === state.selected ? ' active' : ''}" data-action="select-device" data-arg="${esc(d.id)}" aria-pressed="${d.id === state.selected}">
504
618
  ${icon(d.id === 'local' ? 'monitor' : 'network', 'sm')}
505
- <span class="device-name">${esc(d.label)}</span>
619
+ <span class="device-name">${esc(displayLabel)}</span>
506
620
  <span class="device-meta">${esc(f ? `${f.hostname} · ${gpus}` : gpus)}</span>
507
621
  </button>`
508
622
  }).join('')
509
623
  let body = `<div class="devices">${chips}</div>`
510
624
  if (state.adding) body += addDevicePanel()
511
625
  const aside = btn({ label: state.adding ? copy.closeAddDevice : copy.addDevice, iconName: state.adding ? 'x' : 'search', action: 'toggle-add', attrs: ` aria-expanded="${state.adding}"` })
512
- return section({ iconName: 'network', title: copy.devicesTitle, meta: String(state.devices.length), aside }, body)
626
+ return section({ id: 'sec-devices', iconName: 'network', title: copy.devicesTitle, meta: String(state.devices.length), aside }, body)
513
627
  }
514
628
 
515
629
  function addDevicePanel() {
@@ -545,18 +659,24 @@ function runtimeSection(facts, cat) {
545
659
  const p = rec.plan
546
660
  const busy = state.serviceBusy[p.name]
547
661
  const status = rec.liveStatus
662
+ const live = rec.liveState ?? null
663
+ const showCopy = p.endpoint?.base_url && (live === 'running' || (live == null && rec.ok))
664
+ const showStart = live === 'stopped' || live == null
665
+ const showStop = live === 'running' || (live == null && rec.ok)
666
+ const startVariant = live === 'stopped' || (live == null && !rec.ok) ? 'primary' : 'outline'
548
667
  const desc = `${esc(p.model.display_name)} · ${esc(p.placement.label)} · ${k(p.launch.window)} 上下文 · <span class="mono">${esc(p.endpoint.base_url)}</span>`
549
668
  + (rec.ok ? '' : `<br><span class="error-text">${esc(rec.error || '部署未完成')}</span>`)
550
- + (status ? `<br>${esc(status)}` : '')
669
+ + (status ? `<br><span class="live-status">${esc(status)}</span>` : '')
551
670
  body += listRow({
552
671
  title: `<span class="mono" style="font-weight:500">${esc(p.service.name)}</span>${pill(rec.ok ? 'success' : 'destructive', rec.ok ? '已就绪' : '失败')}`,
553
672
  desc,
554
673
  action: [
674
+ showCopy ? btn({ variant: 'ghost', label: '复制地址', iconName: 'copy', action: 'copy-endpoint', arg: p.endpoint.base_url, disabled: Boolean(busy) }) : '',
555
675
  btn({ variant: 'ghost', label: copy.status, iconName: busy === 'status' ? 'loader' : 'refresh', spin: busy === 'status', action: 'service', arg: `${p.name}:status`, disabled: Boolean(busy) }),
556
- btn({ label: copy.startServer, iconName: busy === 'start' ? 'loader' : 'zap', spin: busy === 'start', action: 'service', arg: `${p.name}:start`, disabled: Boolean(busy) }),
557
- btn({ label: copy.stopServer, iconName: busy === 'stop' ? 'loader' : 'stop', spin: busy === 'stop', action: 'service', arg: `${p.name}:stop`, disabled: Boolean(busy) }),
676
+ showStart ? btn({ variant: startVariant, label: copy.startServer, iconName: busy === 'start' ? 'loader' : 'zap', spin: busy === 'start', action: 'service', arg: `${p.name}:start`, disabled: Boolean(busy) }) : '',
677
+ showStop ? btn({ label: copy.stopServer, iconName: busy === 'stop' ? 'loader' : 'stop', spin: busy === 'stop', action: 'service', arg: `${p.name}:stop`, disabled: Boolean(busy) }) : '',
558
678
  btn({ variant: 'ghost icon', iconName: 'trash', action: 'service', arg: `${p.name}:remove`, disabled: Boolean(busy), tip: copy.removeAction })
559
- ].join('')
679
+ ].filter(Boolean).join('')
560
680
  })
561
681
  }
562
682
  for (const s of servers) {
@@ -572,7 +692,7 @@ function runtimeSection(facts, cat) {
572
692
  : pin.present ? copy.pinnedPresentDetail(pin.tag, pin.backend) : copy.noDeploymentsDetail(pin.tag, pin.backend)
573
693
  body += listRow({ title: copy.noDeployments, desc: esc(detail) })
574
694
  }
575
- return section({ iconName: 'zap', title: copy.runtimeTitle, meta: engines[0]?.build || '', aside }, body)
695
+ return section({ id: 'sec-runtime', iconName: 'zap', title: copy.runtimeTitle, meta: engines[0]?.build || '', aside }, body)
576
696
  }
577
697
 
578
698
  function hardwareSection(facts) {
@@ -585,18 +705,20 @@ function hardwareSection(facts) {
585
705
  </div>`
586
706
  if (gpus.length) {
587
707
  body += '<div class="gpus">' + gpus.map(g => {
588
- const usedPct = Math.round((1 - g.free_bytes / g.total_bytes) * 100)
708
+ const usedPct = g.total_bytes ? Math.max(0, Math.min(100, Math.round((1 - g.free_bytes / g.total_bytes) * 100))) : 0
709
+ const usedBytes = Math.max(0, (g.total_bytes || 0) - (g.free_bytes || 0))
589
710
  const busy = g.free_bytes < g.total_bytes * 0.9
711
+ const util = g.utilization_gpu ?? g.util_percent
590
712
  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>
591
- <span class="gpu-bar"><span style="width:${usedPct}%"></span></span>
592
- <span class="gpu-meta">${copy.vram(gb(g.total_bytes))} · 空闲 ${gb(g.free_bytes)}</span>${busy ? pill('warn', '占用中', '其他进程正在使用这张卡的显存;部署会优先选择空闲卡') : ''}</div>`
713
+ <span class="gpu-bar${busy ? ' busy' : ''}"><span style="width:${usedPct}%"></span></span>
714
+ <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>`
593
715
  }).join('') + '</div>'
594
716
  } else {
595
717
  body += `<p class="hint">${facts.gpu_vendor_class === 'apple_silicon' ? '统一内存:按系统内存的 80% 计价' : '未发现 NVIDIA GPU:按 CPU + 内存计价'}</p>`
596
718
  }
597
719
  body += `<p class="hint" style="margin-top:6px">检测于 ${esc(new Date(facts.collected_at).toLocaleString())}</p>`
598
720
  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 })
599
- return section({ iconName: 'monitor', title: copy.hardwareTitle, aside }, body)
721
+ return section({ id: 'sec-hardware', iconName: 'monitor', title: copy.hardwareTitle, aside }, body)
600
722
  }
601
723
 
602
724
  function jobBelow(job) {
@@ -690,11 +812,25 @@ function modelsSection(cat) {
690
812
  if (recommended) {
691
813
  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>`
692
814
  }
815
+ const query = (state.modelQuery || '').trim().toLowerCase()
693
816
  const alternatives = rows.filter(m => m !== recommended)
817
+ const matches = m => !query || [
818
+ m.id,
819
+ m.display_name,
820
+ m.quant,
821
+ m.description,
822
+ m.fit_summary,
823
+ m.quant_reason
824
+ ].some(v => v && String(v).toLowerCase().includes(query))
825
+ const filtered = alternatives.filter(matches)
694
826
  if (alternatives.length) {
695
- body += `<details class="model-alternatives"><summary>${recommended ? '其他模型与历史条目' : '查看模型目录'}(${alternatives.length})</summary><p class="hint">候选与仅在其他平台验证的条目不代表本机已通过验收。已弃用条目仅供查询,已有部署可在「本地运行时」管理。</p><div class="rows">${alternatives.map(m => catalogRow(m, named.get(m.display_name) > 1)).join('')}</div></details>`
827
+ const searchBox = `<label class="search-field">${icon('search', 'sm')}<input type="search" name="model-query" value="${esc(state.modelQuery || '')}" placeholder="搜索模型名称、量化格式或说明…" aria-label="搜索模型目录"></label>`
828
+ const rowsHtml = filtered.length
829
+ ? `<div class="rows">${filtered.map(m => catalogRow(m, named.get(m.display_name) > 1)).join('')}</div>`
830
+ : '<p class="hint">未找到匹配的模型。</p>'
831
+ body += `<details class="model-alternatives"${query ? ' open' : ''}><summary>${recommended ? '其他模型与历史条目' : '查看模型目录'}(${alternatives.length})</summary><p class="hint">候选与仅在其他平台验证的条目不代表本机已通过验收。已弃用条目仅供查询,已有部署可在「本地运行时」管理。</p>${searchBox}${rowsHtml}</details>`
696
832
  }
697
- return section({ iconName: 'download', title: copy.modelsTitle, meta: String(cat.models.length) }, body)
833
+ return section({ id: 'sec-models', iconName: 'download', title: copy.modelsTitle, meta: String(cat.models.length) }, body)
698
834
  }
699
835
 
700
836
  function planOptionsChanged(pl) {
@@ -739,7 +875,7 @@ function planDialog() {
739
875
  <span>来源:本次计划的主机检测(${esc(conflict.collected_at)});重新计划时会再次检查。</span></div>
740
876
  <details><summary>原始诊断</summary><p class="error-text">${esc(pl.error)}</p></details>`
741
877
  } else {
742
- body = `<p class="error-text">${esc(pl.error)}</p>`
878
+ body = `<div class="gate danger" role="alert"><b>无法生成部署计划</b><p>${esc(pl.error)}</p></div>`
743
879
  }
744
880
  } else {
745
881
  const p = pl.plan
@@ -755,7 +891,7 @@ function planDialog() {
755
891
  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>`
756
892
  }
757
893
  if (pl.occupied?.length) {
758
- body += `<div class="gate danger"><b>${pl.occupiedAt === 'plan' ? copy.gpuOccupiedAtPlan : copy.gpuOccupied}</b><ul>${pl.occupied.map(b => `<li>${esc(b)}</li>`).join('')}</ul>
894
+ 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>
759
895
  <label><input type="checkbox" data-action="toggle-share"${pl.share ? ' checked' : ''}>${copy.shareConsent}</label></div>`
760
896
  }
761
897
  body += `<dl class="plan">
@@ -768,7 +904,7 @@ function planDialog() {
768
904
  ${row(['launch', 'service'], '启动参数', `<pre>${esc(p.service.argv.slice(1).join(' '))}</pre>`)}
769
905
  </dl>`
770
906
  if (p.warnings.length) body += `<ul class="warnings">${p.warnings.map(w => `<li>${icon('info', 'xs')}${esc(w)}</li>`).join('')}</ul>`
771
- if (pl.error) body += `<p class="error-text">${esc(pl.error)}</p>`
907
+ if (pl.error) body += `<div class="gate danger" role="alert"><b>部署失败</b><p>${esc(pl.error)}</p></div>`
772
908
  }
773
909
  const o = pl.options
774
910
  const placements = state.catalog.placements
@@ -791,34 +927,88 @@ function planDialog() {
791
927
  </dialog>`
792
928
  }
793
929
 
930
+ function confirmRemoveDialog() {
931
+ const cr = state.confirmRemove
932
+ if (!cr) return ''
933
+ return `<dialog class="dialog dialog-sm" role="dialog" aria-modal="true" aria-labelledby="remove-title" data-action="close-remove-backdrop">
934
+ <div class="dialog-head">${icon('trash')}<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>
935
+ <div class="dialog-body"><p style="margin:0;color:var(--text-secondary)">将停止并移除服务 <span class="mono">${esc(cr.name)}</span>;已下载的模型文件和引擎会保留在主机上。</p></div>
936
+ <div class="dialog-foot"><div class="foot-actions">${btn({ label: copy.cancel, action: 'close-remove', disabled: cr.busy })}${btn({ variant: 'danger lg', label: cr.busy ? '正在移除…' : '确认移除', iconName: cr.busy ? 'loader' : 'trash', spin: cr.busy, action: 'confirm-remove', disabled: cr.busy })}</div></div>
937
+ </dialog>`
938
+ }
939
+
794
940
  // ── Render ──
941
+ let renderedModal = null
795
942
  let renderedPlanning = null
943
+ let renderedRemove = null
796
944
  let planTrigger = null
945
+ let removeTrigger = null
797
946
 
798
947
  function renderPlanDialog() {
799
948
  const root = document.getElementById('dialog-root')
800
949
  const dialog = root.querySelector('dialog')
801
- if (!state.planning) {
950
+ const mode = state.planning ? 'plan' : state.confirmRemove ? 'remove' : null
951
+ if (!mode) {
802
952
  if (!dialog) return
803
953
  dialog.close()
804
954
  root.replaceChildren()
805
- if (planTrigger?.deviceId === state.selected) {
955
+ if (renderedModal === 'plan' && planTrigger?.deviceId === state.selected) {
806
956
  const trigger = [...document.querySelectorAll('[data-action="plan"]')]
807
957
  .find(button => button.dataset.arg === planTrigger.modelId && !button.disabled)
808
958
  trigger?.focus()
959
+ } else if (renderedModal === 'remove' && removeTrigger?.deviceId === state.selected) {
960
+ const trigger = [...document.querySelectorAll('[data-action="service"]')]
961
+ .find(button => button.dataset.arg === `${removeTrigger.name}:remove` && !button.disabled)
962
+ trigger?.focus()
809
963
  }
964
+ renderedModal = null
810
965
  renderedPlanning = null
966
+ renderedRemove = null
811
967
  planTrigger = null
968
+ removeTrigger = null
812
969
  return
813
970
  }
814
- if (!dialog || renderedPlanning !== state.planning) {
971
+ if (mode === 'remove') {
972
+ if (!dialog || renderedModal !== 'remove' || renderedRemove !== state.confirmRemove) {
973
+ dialog?.close()
974
+ root.innerHTML = confirmRemoveDialog()
975
+ const opened = root.querySelector('dialog')
976
+ describeTips(opened)
977
+ opened.showModal()
978
+ opened.querySelector('#remove-title').focus()
979
+ renderedModal = 'remove'
980
+ renderedRemove = state.confirmRemove
981
+ renderedPlanning = null
982
+ return
983
+ }
984
+ const focused = document.activeElement
985
+ const focusedAction = focused?.dataset.action
986
+ const focusedSection = focused?.closest('.dialog-foot') ? '.dialog-foot' : '.dialog-body'
987
+ const next = document.createElement('template')
988
+ next.innerHTML = confirmRemoveDialog()
989
+ for (const selector of ['.dialog-body', '.dialog-foot']) {
990
+ dialog.querySelector(selector).replaceChildren(...next.content.querySelector(selector).childNodes)
991
+ }
992
+ const closeBtn = dialog.querySelector('.dialog-head [data-action="close-remove"]')
993
+ if (closeBtn) closeBtn.disabled = Boolean(state.confirmRemove.busy)
994
+ describeTips(dialog)
995
+ if (!dialog.contains(document.activeElement) || document.activeElement.disabled) {
996
+ const replacement = focusedAction && dialog.querySelector(`${focusedSection} [data-action="${focusedAction}"]`)
997
+ if (replacement && !replacement.disabled) replacement.focus()
998
+ else dialog.querySelector('#remove-title').focus()
999
+ }
1000
+ return
1001
+ }
1002
+ if (!dialog || renderedModal !== 'plan' || renderedPlanning !== state.planning) {
815
1003
  dialog?.close()
816
1004
  root.innerHTML = planDialog()
817
1005
  const opened = root.querySelector('dialog')
818
1006
  describeTips(opened)
819
1007
  opened.showModal()
820
1008
  opened.querySelector('#plan-title').focus()
1009
+ renderedModal = 'plan'
821
1010
  renderedPlanning = state.planning
1011
+ renderedRemove = null
822
1012
  return
823
1013
  }
824
1014
  const focused = document.activeElement
@@ -852,12 +1042,23 @@ function render() {
852
1042
  } else if (state.loading) {
853
1043
  html += `<p class="status-line">${icon('loader', 'xs', 'spin')}${copy.probing}</p>`
854
1044
  }
855
- const focused = document.activeElement?.name
1045
+ const active = document.activeElement
1046
+ const focused = active?.name
1047
+ const selStart = active && 'selectionStart' in active ? active.selectionStart : null
1048
+ const selEnd = active && 'selectionEnd' in active ? active.selectionEnd : null
856
1049
  page.innerHTML = html
857
- if (alternativesOpen) page.querySelector('.model-alternatives')?.setAttribute('open', '')
1050
+ if (alternativesOpen || (state.modelQuery || '').trim()) page.querySelector('.model-alternatives')?.setAttribute('open', '')
858
1051
  describeTips(page)
859
1052
  renderPlanDialog()
860
- if (focused && !state.planning) document.querySelector(`[name="${focused}"]`)?.focus()
1053
+ if (focused && !state.planning && !state.confirmRemove) {
1054
+ const next = document.querySelector(`[name="${focused}"]`)
1055
+ if (next) {
1056
+ next.focus()
1057
+ if (selStart != null && selEnd != null && typeof next.setSelectionRange === 'function') {
1058
+ try { next.setSelectionRange(selStart, selEnd) } catch { /* non-text inputs */ }
1059
+ }
1060
+ }
1061
+ }
861
1062
  }
862
1063
 
863
1064
  // ── Actions ──
@@ -869,56 +1070,84 @@ function toast(message, title = '本地模型') {
869
1070
  setTimeout(() => el.remove(), 4200)
870
1071
  }
871
1072
 
872
- async function loadDevices() {
873
- state.devices = await api('devices')
1073
+ let loadSeq = 0
1074
+ let loadController = null
1075
+ let planSeq = 0
1076
+ let planController = null
1077
+
1078
+ async function loadDevices(signal) {
1079
+ const devices = await api('devices', signal ? { signal } : {})
1080
+ if (signal?.aborted) return
1081
+ state.devices = devices
874
1082
  if (!state.devices.some(d => d.id === state.selected)) state.selected = 'local'
875
1083
  }
876
1084
 
877
1085
  async function loadDevice({ fresh = false } = {}) {
878
- const id = state.selected
1086
+ const seq = ++loadSeq
1087
+ loadController?.abort()
1088
+ const controller = typeof AbortController !== 'undefined' ? new AbortController() : null
1089
+ loadController = controller
1090
+ const signal = controller?.signal
1091
+ const devId = state.selected
1092
+ const prevStates = !fresh
1093
+ ? new Map((state.deployments || []).filter(r => r.liveState != null && r.plan?.name).map(r => [r.plan.name, r.liveState]))
1094
+ : new Map()
879
1095
  state.loading = true
880
1096
  state.error = null
881
1097
  if (fresh) state.catalog = null
882
1098
  render()
883
1099
  try {
884
- if (fresh) await api(`devices/${encodeURIComponent(id)}/probe`, { method: 'POST', body: {} })
1100
+ if (fresh) await api(`devices/${encodeURIComponent(devId)}/probe`, { method: 'POST', body: {}, ...(signal ? { signal } : {}) })
1101
+ if (seq !== loadSeq || devId !== state.selected) return
885
1102
  const [cat, deployments] = await Promise.all([
886
- api(`devices/${encodeURIComponent(id)}/catalog`),
887
- api(`devices/${encodeURIComponent(id)}/deployments`)
1103
+ api(`devices/${encodeURIComponent(devId)}/catalog`, signal ? { signal } : {}),
1104
+ api(`devices/${encodeURIComponent(devId)}/deployments`, signal ? { signal } : {})
888
1105
  ])
889
- if (id !== state.selected) return
1106
+ if (seq !== loadSeq || devId !== state.selected) return
890
1107
  state.catalog = cat
891
- state.deployments = deployments
892
- await loadDevices()
1108
+ state.deployments = deployments.map(r => prevStates.has(r.plan?.name) ? { ...r, liveState: prevStates.get(r.plan.name) } : r)
1109
+ await loadDevices(signal)
893
1110
  } catch (e) {
894
- if (id === state.selected) { state.error = e.message; state.catalog = null }
1111
+ if (seq === loadSeq && devId === state.selected) { state.error = e.message; state.catalog = null }
895
1112
  } finally {
896
- state.loading = false
897
- render()
1113
+ if (seq === loadSeq) {
1114
+ if (loadController === controller) loadController = null
1115
+ state.loading = false
1116
+ render()
1117
+ }
898
1118
  }
899
1119
  }
900
1120
 
901
1121
  async function makePlan() {
1122
+ const seq = ++planSeq
1123
+ planController?.abort()
1124
+ const controller = typeof AbortController !== 'undefined' ? new AbortController() : null
1125
+ planController = controller
1126
+ const signal = controller?.signal
902
1127
  const pl = state.planning
903
1128
  const options = { ...pl.options }
904
1129
  Object.assign(pl, { busy: true, error: null, conflict: null, changed: null, refusal: null, occupied: null, share: false })
905
1130
  render()
906
1131
  try {
907
1132
  const body = { model_id: pl.model_id, ...options, port: Number(options.port) }
908
- const res = await api(`devices/${encodeURIComponent(state.selected)}/plan`, { method: 'POST', body })
909
- if (state.planning !== pl) return
1133
+ const res = await api(`devices/${encodeURIComponent(state.selected)}/plan`, { method: 'POST', body, ...(signal ? { signal } : {}) })
1134
+ if (seq !== planSeq || state.planning !== pl) return
910
1135
  pl.plan = res.plan
911
1136
  pl.plan_id = res.plan_id
912
1137
  pl.plannedOptions = options
913
1138
  // The deploy gate refuses these cards without consent; ask now instead of after a 409.
914
1139
  if (res.busy_gpus?.length) Object.assign(pl, { occupied: res.busy_gpus, occupiedAt: 'plan' })
915
1140
  } catch (e) {
1141
+ if (seq !== planSeq || state.planning !== pl) return
916
1142
  pl.error = e.message
917
1143
  pl.conflict = e.data?.code === 'gpu_conflict' ? e.data.conflict : null
918
1144
  pl.plan = null
919
1145
  } finally {
920
- pl.busy = false
921
- render()
1146
+ if (seq === planSeq) {
1147
+ if (planController === controller) planController = null
1148
+ pl.busy = false
1149
+ if (state.planning === pl) render()
1150
+ }
922
1151
  }
923
1152
  }
924
1153
 
@@ -956,8 +1185,25 @@ const ACTIONS = {
956
1185
  state.catalog = null
957
1186
  state.deployments = []
958
1187
  state.jobs = {}
1188
+ state.confirmRemove = null
959
1189
  loadDevice()
960
1190
  },
1191
+ 'cycle-theme'() {
1192
+ const idx = THEME_CYCLE.indexOf(currentTheme())
1193
+ const next = THEME_CYCLE[(idx + 1) % THEME_CYCLE.length]
1194
+ if (next === 'auto') localStorageRemove(THEME_KEY)
1195
+ else localStorageSet(THEME_KEY, next)
1196
+ applyTheme(next)
1197
+ toast(`外观主题已切换为:${THEME_LABEL[next]}`)
1198
+ },
1199
+ async 'copy-endpoint'(url) {
1200
+ try {
1201
+ await navigator.clipboard.writeText(url)
1202
+ toast(`已复制接口地址:${url}`)
1203
+ } catch {
1204
+ toast(`复制失败,请手动复制地址:${url}`)
1205
+ }
1206
+ },
961
1207
  async 'toggle-add'() {
962
1208
  state.adding = !state.adding
963
1209
  render()
@@ -985,7 +1231,19 @@ const ACTIONS = {
985
1231
  replan() {
986
1232
  makePlan()
987
1233
  },
988
- 'close-plan'() { state.planning = null; render() },
1234
+ 'toggle-guide'(arg, event) {
1235
+ const next = event?.target && 'open' in event.target ? Boolean(event.target.open) : !guideIsOpen()
1236
+ state.guideOpen = next
1237
+ localStorageSet('localmodels.guideCollapsed', next ? '0' : '1')
1238
+ if (!event?.target || event.target.id !== 'setup-guide') render()
1239
+ },
1240
+ 'close-plan'() {
1241
+ planSeq++
1242
+ planController?.abort()
1243
+ planController = null
1244
+ state.planning = null
1245
+ render()
1246
+ },
989
1247
  'close-plan-backdrop'(arg, event) {
990
1248
  if (event.target.tagName !== 'DIALOG') return
991
1249
  const bounds = event.target.getBoundingClientRect()
@@ -1027,25 +1285,98 @@ const ACTIONS = {
1027
1285
  },
1028
1286
  async service(arg) {
1029
1287
  const [name, action] = arg.split(':')
1030
- if (action === 'remove' && !confirm(`停止并移除部署 ${name}?模型文件和引擎会保留在主机上。`)) return
1031
- state.serviceBusy[name] = action
1288
+ if (action === 'remove') {
1289
+ removeTrigger = { name, deviceId: state.selected }
1290
+ state.confirmRemove = { name, busy: false }
1291
+ render()
1292
+ return
1293
+ }
1294
+ await runServiceAction(name, action)
1295
+ },
1296
+ 'close-remove'() {
1297
+ if (state.confirmRemove?.busy) return
1298
+ state.confirmRemove = null
1299
+ render()
1300
+ },
1301
+ 'close-remove-backdrop'(arg, event) {
1302
+ if (event.target.tagName !== 'DIALOG') return
1303
+ const bounds = event.target.getBoundingClientRect()
1304
+ if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) ACTIONS['close-remove']()
1305
+ },
1306
+ async 'confirm-remove'() {
1307
+ const cr = state.confirmRemove
1308
+ if (!cr || cr.busy) return
1309
+ cr.busy = true
1032
1310
  render()
1033
1311
  try {
1034
- const res = await api(`devices/${encodeURIComponent(state.selected)}/deployments/${encodeURIComponent(name)}/${action}`, { method: 'POST', body: {} })
1035
- if (res.event === 'error') throw new Error(res.message)
1036
- const rec = state.deployments.find(r => r.plan.name === name)
1037
- if (action === 'status' && rec) rec.liveStatus = `服务 ${res.state} · health ${res.health}`
1038
- else toast(`${name}:${{ start: '已启动', stop: '已停止', remove: '已移除' }[action]}`)
1039
- if (action !== 'status') await loadDevice()
1040
- } catch (e) {
1041
- toast(e.message, name)
1312
+ await runServiceAction(cr.name, 'remove')
1042
1313
  } finally {
1043
- delete state.serviceBusy[name]
1314
+ if (state.confirmRemove === cr) state.confirmRemove = null
1044
1315
  render()
1045
1316
  }
1046
1317
  }
1047
1318
  }
1048
1319
 
1320
+ const SERVICE_STATE_ZH = {
1321
+ active: '运行中',
1322
+ running: '运行中',
1323
+ inactive: '已停止',
1324
+ stopped: '已停止',
1325
+ failed: '失败',
1326
+ activating: '启动中',
1327
+ deactivating: '停止中',
1328
+ reloading: '重载中',
1329
+ unknown: '未知'
1330
+ }
1331
+
1332
+ function formatServiceHealth(health) {
1333
+ if (health === 'ok') return '健康'
1334
+ if (health === 'unreachable') return '未响应'
1335
+ return health || '未知'
1336
+ }
1337
+
1338
+ function formatServiceStatus(res) {
1339
+ const rawState = String(res?.state || 'unknown')
1340
+ const st = SERVICE_STATE_ZH[rawState.toLowerCase()] || rawState
1341
+ const hl = formatServiceHealth(res?.health)
1342
+ return `状态:${st} · 健康检查:${hl}`
1343
+ }
1344
+
1345
+ function inferLiveState(action, res) {
1346
+ if (action === 'start') return res?.ok !== false ? 'running' : null
1347
+ if (action === 'stop') return res?.ok !== false ? 'stopped' : null
1348
+ if (action === 'status' && res) {
1349
+ const raw = typeof res.state === 'string' ? res.state.toLowerCase() : ''
1350
+ if (raw === 'active' || raw === 'running') return 'running'
1351
+ if (raw === 'inactive' || raw === 'stopped' || raw === 'failed' || raw === 'dead' || raw === 'exited') return 'stopped'
1352
+ if (typeof res.running === 'boolean') return res.running ? 'running' : 'stopped'
1353
+ if (typeof res.active === 'boolean') return res.active ? 'running' : 'stopped'
1354
+ }
1355
+ return null
1356
+ }
1357
+
1358
+ async function runServiceAction(name, action) {
1359
+ state.serviceBusy[name] = action
1360
+ render()
1361
+ try {
1362
+ const res = await api(`devices/${encodeURIComponent(state.selected)}/deployments/${encodeURIComponent(name)}/${action}`, { method: 'POST', body: {} })
1363
+ if (res?.event === 'error') throw new Error(res.message)
1364
+ const rec = state.deployments.find(r => r.plan.name === name)
1365
+ if (rec) {
1366
+ rec.liveState = inferLiveState(action, res)
1367
+ if (action === 'status') rec.liveStatus = formatServiceStatus(res)
1368
+ else delete rec.liveStatus
1369
+ }
1370
+ if (action !== 'status') toast(`${name}:${{ start: '已启动', stop: '已停止', remove: '已移除' }[action]}`)
1371
+ if (action !== 'status') await loadDevice()
1372
+ } catch (e) {
1373
+ toast(e.message, name)
1374
+ } finally {
1375
+ delete state.serviceBusy[name]
1376
+ render()
1377
+ }
1378
+ }
1379
+
1049
1380
  async function addDevice(target, label) {
1050
1381
  toast(`正在通过 SSH 检测 ${target}…`)
1051
1382
  try {
@@ -1068,8 +1399,65 @@ function updatePlanOptions(event) {
1068
1399
  document.querySelector('#dialog-root dialog').classList.toggle('stale', planOptionsChanged(pl))
1069
1400
  }
1070
1401
 
1071
- document.addEventListener('input', updatePlanOptions)
1402
+ function handleInput(event) {
1403
+ if (event.target?.name === 'model-query') {
1404
+ state.modelQuery = event.target.value
1405
+ render()
1406
+ return
1407
+ }
1408
+ updatePlanOptions(event)
1409
+ }
1410
+
1411
+ function safeCrossLinkUrl(url) {
1412
+ if (typeof url !== 'string') return null
1413
+ const trimmed = url.trim()
1414
+ if (!trimmed || trimmed === '#') return null
1415
+ if (trimmed.startsWith('/') && !trimmed.startsWith('//')) return trimmed
1416
+ try {
1417
+ const parsed = new URL(trimmed)
1418
+ if (parsed.protocol === 'http:' || parsed.protocol === 'https:') return trimmed
1419
+ } catch { /* invalid URL */ }
1420
+ return null
1421
+ }
1422
+
1423
+ function renderCrossLinks() {
1424
+ if (typeof document === 'undefined' || typeof document.querySelector !== 'function') return
1425
+ const foot = document.querySelector('.sidebar-foot')
1426
+ if (!foot) return
1427
+ foot.querySelector('.cross-links')?.remove()
1428
+ const valid = (state.crossLinks || []).map(item => {
1429
+ const label = typeof item?.label === 'string' ? item.label.trim() : ''
1430
+ const url = safeCrossLinkUrl(item?.url)
1431
+ return label && url ? { label, url } : null
1432
+ }).filter(Boolean)
1433
+ if (!valid.length) return
1434
+ const nav = document.createElement('nav')
1435
+ nav.className = 'cross-links'
1436
+ nav.setAttribute('aria-label', '切换页面')
1437
+ 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('')
1438
+ const themeBtn = foot.querySelector('.theme-btn')
1439
+ if (themeBtn) foot.insertBefore(nav, themeBtn)
1440
+ else foot.prepend(nav)
1441
+ }
1442
+
1443
+ async function loadCrossLinks() {
1444
+ if (typeof fetch !== 'function') return
1445
+ try {
1446
+ const res = await fetch('/__preview_links', { cache: 'no-store' })
1447
+ if (!res.ok) return
1448
+ const data = await res.json().catch(() => null)
1449
+ if (Array.isArray(data?.links)) {
1450
+ state.crossLinks = data.links
1451
+ renderCrossLinks()
1452
+ }
1453
+ } catch { /* served only under web_preview */ }
1454
+ }
1455
+
1456
+ document.addEventListener('input', handleInput)
1072
1457
  document.addEventListener('change', updatePlanOptions)
1458
+ document.addEventListener('toggle', e => {
1459
+ if (e.target?.id === 'setup-guide') ACTIONS['toggle-guide'](null, e)
1460
+ }, true)
1073
1461
 
1074
1462
  document.addEventListener('click', e => {
1075
1463
  const el = e.target.closest('[data-action]')
@@ -1083,12 +1471,14 @@ document.addEventListener('submit', e => {
1083
1471
  if (e.target.dataset.form === 'replan') ACTIONS.replan()
1084
1472
  })
1085
1473
  document.addEventListener('keydown', e => {
1086
- if (!state.planning) return
1474
+ if (!state.planning && !state.confirmRemove) return
1087
1475
  if (e.key === 'Escape') {
1088
1476
  e.preventDefault()
1089
- ACTIONS['close-plan']()
1477
+ if (state.confirmRemove) ACTIONS['close-remove']()
1478
+ else ACTIONS['close-plan']()
1090
1479
  } else if (e.key === 'Tab') {
1091
1480
  const dialog = document.querySelector('#dialog-root dialog')
1481
+ if (!dialog) return
1092
1482
  const controls = [...dialog.querySelectorAll('button, input, select, [tabindex]')]
1093
1483
  .filter(control => !control.disabled && control.tabIndex >= 0 && control.getClientRects().length)
1094
1484
  const first = controls[0]
@@ -1114,8 +1504,13 @@ function showTip(t) {
1114
1504
  const r = t.getBoundingClientRect()
1115
1505
  tipEl.classList.add('show')
1116
1506
  const w = tipEl.offsetWidth
1117
- tipEl.style.left = `${Math.max(8, Math.min(innerWidth - w - 8, r.left + r.width / 2 - w / 2))}px`
1118
- tipEl.style.top = `${r.bottom + 6}px`
1507
+ const h = tipEl.offsetHeight
1508
+ const left = Math.max(8, Math.min(innerWidth - w - 8, r.left + r.width / 2 - w / 2))
1509
+ const top = r.bottom + h + 12 > innerHeight && r.top - h - 6 >= 8
1510
+ ? r.top - h - 6
1511
+ : Math.max(8, Math.min(innerHeight - h - 8, r.bottom + 6))
1512
+ tipEl.style.left = `${left}px`
1513
+ tipEl.style.top = `${top}px`
1119
1514
  }
1120
1515
  document.addEventListener('mouseover', e => showTip(e.target.closest('[data-tip]')))
1121
1516
  document.addEventListener('focusin', e => showTip(e.target.closest('[data-tip]')))
@@ -1125,6 +1520,20 @@ document.addEventListener('keydown', e => { if (e.key === 'Escape') showTip(null
1125
1520
  document.addEventListener('scroll', () => showTip(null), true)
1126
1521
 
1127
1522
  hydrateIcons()
1523
+ initTheme()
1524
+ const navLinks = [...document.querySelectorAll('.nav-list .nav-item')]
1525
+ function syncNavCurrent(targetHash) {
1526
+ const activeHash = targetHash || location.hash || '#setup-guide'
1527
+ const matched = navLinks.some(a => a.getAttribute('href') === activeHash)
1528
+ navLinks.forEach((a, i) => {
1529
+ if ((matched && a.getAttribute('href') === activeHash) || (!matched && i === 0)) a.setAttribute('aria-current', 'location')
1530
+ else a.removeAttribute('aria-current')
1531
+ })
1532
+ }
1533
+ navLinks.forEach(a => a.addEventListener('click', () => syncNavCurrent(a.getAttribute('href'))))
1534
+ addEventListener('hashchange', () => syncNavCurrent())
1535
+ syncNavCurrent()
1536
+ loadCrossLinks()
1128
1537
  loadDevices().then(() => loadDevice()).catch(e => { state.error = e.message; render() })
1129
1538
  </script>
1130
1539
  </body>