@simplexai/localmodels-win32-x64 0.1.0-dev.63 → 0.1.0-dev.65

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 (142) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +140 -130
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +2 -2
  5. package/modules/localmodels/app.py +15 -2
  6. package/modules/localmodels/approval.py +5 -3
  7. package/modules/localmodels/bifrost_checks.py +2 -1
  8. package/modules/localmodels/catalog.json +36 -0
  9. package/modules/localmodels/catalog.py +28 -5
  10. package/modules/localmodels/catalog_recipes.py +40 -1
  11. package/modules/localmodels/component.py +1 -1
  12. package/modules/localmodels/context_policy.py +7 -2
  13. package/modules/localmodels/custom_probe.py +5 -5
  14. package/modules/localmodels/debug_mode.py +85 -103
  15. package/modules/localmodels/deploy.py +129 -18
  16. package/modules/localmodels/deployment_lifecycle.py +167 -0
  17. package/modules/localmodels/download-mirrors.json +126 -6
  18. package/modules/localmodels/draft_spec.py +164 -0
  19. package/modules/localmodels/engine_adapters/__init__.py +4 -0
  20. package/modules/localmodels/engine_adapters/auxiliary.py +27 -0
  21. package/modules/localmodels/engine_adapters/base.py +40 -0
  22. package/modules/localmodels/engine_adapters/strata_poly.py +57 -0
  23. package/modules/localmodels/engine_adapters/suite_plan.py +394 -0
  24. package/modules/localmodels/engines-prism-b12178-03ec600.json +7 -7
  25. package/modules/localmodels/gateway.py +124 -13
  26. package/modules/localmodels/gateway_accept.py +1 -6
  27. package/modules/localmodels/gateway_cli.py +13 -24
  28. package/modules/localmodels/gateway_ops.py +185 -0
  29. package/modules/localmodels/gateway_server.py +3 -2
  30. package/modules/localmodels/harness.py +13 -16
  31. package/modules/localmodels/harness_core.py +4 -9
  32. package/modules/localmodels/harness_gateway.py +4 -3
  33. package/modules/localmodels/hosts.py +22 -34
  34. package/modules/localmodels/install.py +15 -0
  35. package/modules/localmodels/library_convert.py +5 -11
  36. package/modules/localmodels/library_custom.py +6 -6
  37. package/modules/localmodels/library_elastic.py +24 -127
  38. package/modules/localmodels/library_jobs.py +14 -5
  39. package/modules/localmodels/library_order.py +4 -3
  40. package/modules/localmodels/library_poly.py +5 -4
  41. package/modules/localmodels/library_pricing.py +80 -255
  42. package/modules/localmodels/library_serve.py +13 -14
  43. package/modules/localmodels/library_smoke.py +8 -1
  44. package/modules/localmodels/library_status.py +16 -16
  45. package/modules/localmodels/llm_rank.py +1 -1
  46. package/modules/localmodels/magpie_legacy.py +160 -0
  47. package/modules/localmodels/magpie_setup.py +6 -1
  48. package/modules/localmodels/memcalc_cli.py +2 -2
  49. package/modules/localmodels/pi_profile.py +3 -7
  50. package/modules/localmodels/plan_envelope.py +1 -1
  51. package/modules/localmodels/planning/__init__.py +3 -0
  52. package/modules/localmodels/{budget.py → planning/budget.py} +48 -30
  53. package/modules/localmodels/{stack_llm_ram.py → planning/llm_ram.py} +11 -1
  54. package/modules/localmodels/{memcalc_load.py → planning/memcalc_load.py} +1 -1
  55. package/modules/localmodels/planning/memory_pools.py +403 -0
  56. package/modules/localmodels/{sizecalc.py → planning/sizecalc.py} +1 -1
  57. package/modules/localmodels/recommend.py +1 -1
  58. package/modules/localmodels/recommend_cli.py +3 -4
  59. package/modules/localmodels/residency_host.py +1 -1
  60. package/modules/localmodels/service_control.py +4 -4
  61. package/modules/localmodels/service_deployment.py +3 -2
  62. package/modules/localmodels/service_wiring.py +17 -19
  63. package/modules/localmodels/setup_inspection.py +1 -1
  64. package/modules/localmodels/setup_inspection_harness.py +1 -1
  65. package/modules/localmodels/setup_upgrade.py +3 -12
  66. package/modules/localmodels/sizecalc_cli.py +10 -2
  67. package/modules/localmodels/speech_admission.py +1 -1
  68. package/modules/localmodels/speech_jobs.py +2 -1
  69. package/modules/localmodels/speech_model.py +2 -0
  70. package/modules/localmodels/speech_server.py +130 -9
  71. package/modules/localmodels/speech_state.py +11 -0
  72. package/modules/localmodels/speech_worker_sensevoice.py +38 -0
  73. package/modules/localmodels/speech_workers.py +5 -1
  74. package/modules/localmodels/stack.py +4 -9
  75. package/modules/localmodels/stack_arena.py +2 -2
  76. package/modules/localmodels/stack_auto.py +5 -5
  77. package/modules/localmodels/stack_aux_gpu.py +5 -3
  78. package/modules/localmodels/stack_binding.py +24 -143
  79. package/modules/localmodels/stack_capacity.py +1 -1
  80. package/modules/localmodels/stack_card.py +3 -3
  81. package/modules/localmodels/stack_cleanup.py +6 -5
  82. package/modules/localmodels/stack_client_settings.py +9 -2
  83. package/modules/localmodels/stack_compose.py +43 -6
  84. package/modules/localmodels/stack_console.py +2 -2
  85. package/modules/localmodels/stack_debug.py +1 -1
  86. package/modules/localmodels/stack_decision.py +1 -1
  87. package/modules/localmodels/stack_doctor.py +10 -7
  88. package/modules/localmodels/stack_down.py +3 -3
  89. package/modules/localmodels/stack_gpu_memory.py +1 -1
  90. package/modules/localmodels/stack_hardware.py +3 -3
  91. package/modules/localmodels/stack_hardware_text.py +1 -1
  92. package/modules/localmodels/stack_ledger.py +2 -1
  93. package/modules/localmodels/stack_lifecycle.py +7 -7
  94. package/modules/localmodels/stack_mcp.py +1 -1
  95. package/modules/localmodels/stack_memory.py +4 -4
  96. package/modules/localmodels/stack_mlx.py +1 -1
  97. package/modules/localmodels/stack_plan.py +18 -13
  98. package/modules/localmodels/stack_ports.py +2 -2
  99. package/modules/localmodels/stack_preflight.py +4 -3
  100. package/modules/localmodels/stack_remove.py +13 -6
  101. package/modules/localmodels/stack_review.py +3 -5
  102. package/modules/localmodels/stack_rollback.py +1 -1
  103. package/modules/localmodels/stack_route.py +5 -4
  104. package/modules/localmodels/stack_run.py +16 -0
  105. package/modules/localmodels/stack_suite.py +14 -6
  106. package/modules/localmodels/stack_summary.py +1 -1
  107. package/modules/localmodels/stack_try.py +10 -14
  108. package/modules/localmodels/stack_up.py +25 -39
  109. package/modules/localmodels/stack_update.py +2 -1
  110. package/modules/localmodels/stack_verify.py +4 -30
  111. package/modules/localmodels/stack_view.py +6 -4
  112. package/modules/localmodels/stack_view_apply.py +2 -2
  113. package/modules/localmodels/stack_view_llm.py +12 -7
  114. package/modules/localmodels/stack_view_text.py +2 -6
  115. package/modules/localmodels/stack_view_tick.py +2 -2
  116. package/modules/localmodels/stack_view_words.py +5 -2
  117. package/modules/localmodels/stack_warm.py +7 -4
  118. package/modules/localmodels/stack_whatif.py +1 -1
  119. package/modules/localmodels/suite.py +6 -334
  120. package/modules/localmodels/tui_views.py +28 -7
  121. package/modules/localmodels/web/index.html +595 -226
  122. package/modules/localmodels/web/sizecalc/app.js +34 -40
  123. package/modules/localmodels/web/sizecalc/calc.js +3 -3
  124. package/modules/localmodels/web/sizecalc/page.html +4 -3
  125. package/modules/localmodels/web/view/fleet.html +18 -3
  126. package/modules/localmodels/web/view/fleet.js +135 -14
  127. package/modules/localmodels/web/view/i18n.js +4 -0
  128. package/modules/localmodels/web/view/index.html +16 -0
  129. package/modules/localmodels/web/view/nav.js +49 -0
  130. package/modules/localmodels/web/view/theme.js +1 -1
  131. package/modules/localmodels/web/view/view.css +51 -15
  132. package/modules/localmodels/web/view/view.js +22 -4
  133. package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/METADATA +1 -1
  134. package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/RECORD +137 -127
  135. package/package.json +1 -1
  136. package/tool.json +1 -1
  137. package/modules/localmodels/library_vram.py +0 -123
  138. /package/modules/localmodels/{memcalc.py → planning/memcalc.py} +0 -0
  139. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/WHEEL +0 -0
  140. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/entry_points.txt +0 -0
  141. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/NOTICE +0 -0
  142. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -5,6 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
6
  <meta name="color-scheme" content="light dark">
7
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>
8
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">
9
10
  <!--
10
11
  本地模型设置页,served by `python3 -m localmodels serve`; every value comes from /api.
@@ -83,6 +84,7 @@
83
84
  * { box-sizing: border-box; }
84
85
  :focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
85
86
  #plan-title:focus, #remove-title:focus { outline: none; }
87
+ #shortcuts-title:focus { outline: none; }
86
88
  html, body { height: 100%; margin: 0; }
87
89
  body {
88
90
  background: var(--bg);
@@ -103,11 +105,12 @@ svg.i.xs { width: 12px; height: 12px; }
103
105
  .sidebar {
104
106
  background: var(--sidebar-bg);
105
107
  border-right: 1px solid var(--border);
106
- display: flex; flex-direction: column;
108
+ display: flex; flex-direction: column; gap: 8px;
107
109
  padding: 12px 10px;
108
110
  min-height: 0;
109
111
  }
110
112
  .nav-list { display: grid; gap: 2px; }
113
+ .sidebar-nav { align-content: start; flex: 1; min-height: 0; overflow-y: auto; }
111
114
  .nav-item {
112
115
  display: flex; align-items: center; gap: 8px;
113
116
  min-height: 32px; width: 100%;
@@ -118,15 +121,51 @@ svg.i.xs { width: 12px; height: 12px; }
118
121
  transition: background .15s, color .15s, border-color .15s;
119
122
  }
120
123
  .nav-item svg { color: var(--muted-fg); transition: color .15s; }
121
- .nav-item:hover { background: var(--nav-hover); color: var(--fg); }
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; }
122
126
  .nav-item[aria-current="page"],
123
127
  .nav-item[aria-current="location"] {
124
128
  background: var(--nav-active); border-color: var(--nav-active-border);
125
129
  color: var(--fg); font-weight: 560; box-shadow: var(--shadow);
126
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); }
127
136
  .nav-item[aria-current="page"] svg,
128
137
  .nav-item[aria-current="location"] svg { color: var(--primary); }
129
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; }
130
169
  .sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); display: grid; gap: 8px; }
131
170
  .cross-links { display: grid; gap: 2px; }
132
171
  .theme-btn {
@@ -237,6 +276,23 @@ svg.i.xs { width: 12px; height: 12px; }
237
276
  .model-alternatives summary:hover { color: var(--fg); }
238
277
  .model-alternatives summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
239
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; }
240
296
 
241
297
  .btn {
242
298
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
@@ -398,11 +454,12 @@ svg.i.xs { width: 12px; height: 12px; }
398
454
  background: var(--card); color: var(--fg); border: 1px solid var(--border); border-radius: 12px;
399
455
  box-shadow: var(--shadow-lg);
400
456
  }
401
- .dialog.dialog-sm { width: min(440px, calc(100% - 32px)); }
457
+ .dialog.dialog-sm { width: min(460px, calc(100% - 32px)); }
402
458
  .dialog[open] { display: flex; }
403
459
  .dialog-head { display: flex; align-items: center; gap: 8px; padding: 13px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
404
460
  .dialog-head b { flex: 1; font-weight: 600; }
405
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); }
406
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; }
407
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); }
408
465
  .foot-summary li { overflow-wrap: anywhere; }
@@ -411,18 +468,19 @@ svg.i.xs { width: 12px; height: 12px; }
411
468
  .foot-actions { display: flex; gap: 8px; margin-left: auto; }
412
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; }
413
470
  .dialog.stale .dialog-body > :not(.stale-hint):not(.gate-top), .dialog.stale .foot-summary { opacity: .4; }
414
- .plan-form { display: flex; flex-wrap: wrap; gap: 10px; 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; }
415
- .plan-form label { display: grid; gap: 3px; flex: 1 1 135px; min-width: 0; }
416
- .plan-form label:has([name="port"]) { flex: 0 1 92px; }
417
- .plan-form label:has([name="bind"]) { flex: 1.35 1 172px; }
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; }
418
476
  .plan dl, dl.plan { display: grid; grid-template-columns: 5.5em minmax(0, 1fr); gap: 8px 12px; margin: 0; }
419
477
  dl.plan dt { color: var(--muted-fg); }
420
478
  dl.plan dd { margin: 0; min-width: 0; }
421
479
  dl.plan ul { margin: 0 0 4px; padding-left: 16px; }
422
480
  .plan-file-item .btn.sm { margin-left: 4px; vertical-align: middle; }
423
- dl.plan pre { margin: 0; white-space: pre-wrap; word-break: break-all; font: 11px/1.5 ui-monospace, Consolas, monospace; background: var(--muted-bg); padding: 6px 8px; border-radius: 6px; }
424
- .code-box { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
425
- .code-box pre { flex: 1 1 220px; min-width: 0; }
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; }
426
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; }
427
485
  .warnings li { display: flex; gap: 6px; align-items: center; }
428
486
  .gate { margin: 0 0 12px; padding: 9px 12px; border-radius: 8px; display: grid; gap: 6px; }
@@ -459,6 +517,7 @@ dl.plan dd.changed { box-shadow: inset 2px 0 var(--warn); padding-left: 8px; }
459
517
  background: var(--card); border-color: var(--border); color: var(--fg); font-weight: 560;
460
518
  box-shadow: var(--shadow);
461
519
  }
520
+ .mobile-nav-item:disabled, .mobile-nav-item[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
462
521
  .mobile-cross-links { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
463
522
  .mobile-cross-links:empty { display: none; }
464
523
  .mobile-cross-links::before { content: ""; width: 1px; height: 14px; background: var(--border); margin: 0 2px; }
@@ -470,6 +529,7 @@ dl.plan dd.changed { box-shadow: inset 2px 0 var(--warn); padding-left: 8px; }
470
529
  dl.plan { grid-template-columns: 1fr; }
471
530
  .dialog { width: calc(100% - 20px); max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); }
472
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; }
473
533
  .plan-form [data-action="replan"] { grid-column: 1 / -1; justify-self: start; }
474
534
  .dialog-body { min-height: 150px; padding: 12px; }
475
535
  .dialog-foot { padding: 10px 12px; }
@@ -485,12 +545,13 @@ dl.plan dd.changed { box-shadow: inset 2px 0 var(--warn); padding-left: 8px; }
485
545
  <body>
486
546
  <div class="window">
487
547
  <aside class="sidebar" aria-label="当前设置">
488
- <nav class="nav-list" aria-label="页面导航">
489
- <div class="nav-item active" aria-current="page"><span data-icon="cpu" data-size="sm"></span><span class="label">单模型设置</span></div>
490
- <a class="nav-item" href="#sec-devices"><span data-icon="network" data-size="sm"></span><span class="label">设备</span></a>
491
- <a class="nav-item" href="#sec-models"><span data-icon="download" data-size="sm"></span><span class="label">单模型目录</span></a>
492
- <a class="nav-item" href="#sec-runtime"><span data-icon="zap" data-size="sm"></span><span class="label">本地运行时</span></a>
493
- <a class="nav-item" href="#sec-hardware"><span data-icon="monitor" data-size="sm"></span><span class="label">本机配置</span></a>
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>
494
555
  </nav>
495
556
  <div class="sidebar-foot">
496
557
  <button type="button" class="theme-btn" data-action="cycle-theme" aria-label="切换外观主题">
@@ -499,12 +560,12 @@ dl.plan dd.changed { box-shadow: inset 2px 0 var(--warn); padding-left: 8px; }
499
560
  </div>
500
561
  </aside>
501
562
  <main class="main">
502
- <nav class="mobile-nav" aria-label="页面导航">
503
- <button type="button" class="mobile-nav-item" data-action="scroll-top" data-nav-top aria-current="location">总览</button>
504
- <a class="mobile-nav-item" href="#sec-devices">设备</a>
505
- <a class="mobile-nav-item" href="#sec-models">单模型目录</a>
506
- <a class="mobile-nav-item" href="#sec-runtime">本地运行时</a>
507
- <a class="mobile-nav-item" href="#sec-hardware">本机配置</a>
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>
508
569
  <span class="mobile-cross-links"></span>
509
570
  </nav>
510
571
  <div class="scroll">
@@ -521,6 +582,8 @@ dl.plan dd.changed { box-shadow: inset 2px 0 var(--warn); padding-left: 8px; }
521
582
 
522
583
 
523
584
  <div id="dialog-root"></div>
585
+ <div id="confirm-dialog-root"></div>
586
+ <div id="shortcuts-dialog-root"></div>
524
587
  <div class="tip" id="tip" role="tooltip"></div>
525
588
  <div class="toasts" id="toasts" role="status" aria-live="polite"></div>
526
589
 
@@ -550,7 +613,10 @@ const ICONS = {
550
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"/>',
551
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"/>',
552
615
  moon: '<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>',
553
- 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"/>'
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"/>'
554
620
  }
555
621
 
556
622
  function icon(name, size = '', extra = '') {
@@ -604,6 +670,7 @@ const copy = {
604
670
  noRecommendationTitle: '此设备暂无自动推荐模型',
605
671
  noRecommendationDetail: '当前设备事实下没有可自动推荐的模型;不代表其他候选已通过本机验收。可展开目录查看,或在目标设备终端运行完整安装命令检查套件计划。',
606
672
  deployAction: s => (s ? `部署 · ${s}` : '部署'),
673
+ replanAction: s => (s ? `重新配置 · ${s}` : '重新配置'),
607
674
  pillFitsGpu: '完全在 GPU 上运行',
608
675
  pillFitsBusy: '容量够 · 卡上有其他程序',
609
676
  pillFitsBusyTip: '按这张卡的总容量能完全放进显存;它现在还跑着其他程序。部署时按当前空闲显存重新计划:放得下时要在计划里确认共用,放不下时计划会说明',
@@ -641,11 +708,23 @@ const copy = {
641
708
 
642
709
  const gb = n => `${(n / (1 << 30)).toFixed(1)} GB`
643
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
+ ]
644
721
 
645
722
  // ── State ──
646
723
  const state = {
647
724
  devices: [],
648
725
  selected: localStorageGet('localmodels.device') || 'local',
726
+ theme: currentTheme(),
727
+ activeSection: 'setup-guide',
649
728
  catalog: null,
650
729
  deployments: [],
651
730
  loading: false,
@@ -662,7 +741,9 @@ const state = {
662
741
  removingDevice: null,
663
742
  planning: null, // { model_id, plan_id, plan, options, error, errorTitle, busy, deploying, changed, occupied, share }
664
743
  confirmRemove: null, // { name, busy }
744
+ shortcutsOpen: false,
665
745
  modelQuery: '',
746
+ fitsOnly: false,
666
747
  jobs: {}, // model id -> job
667
748
  serviceBusy: {},
668
749
  guideOpen: null,
@@ -679,12 +760,8 @@ function localStorageRemove(key) {
679
760
  try { localStorage.removeItem(key) } catch { /* private window */ }
680
761
  }
681
762
 
682
- const THEME_KEY = 'localmodels.theme'
683
- const THEME_CYCLE = ['auto', 'light', 'dark']
684
- const THEME_LABEL = { auto: '跟随系统', light: '浅色', dark: '深色' }
685
-
686
763
  function currentTheme() {
687
- const saved = localStorageGet(THEME_KEY)
764
+ const saved = localStorageGet(THEME_KEY) || localStorageGet('lm-theme') || localStorageGet('lm-sizecalc-theme')
688
765
  return saved === 'light' || saved === 'dark' ? saved : 'auto'
689
766
  }
690
767
 
@@ -695,8 +772,9 @@ function effectiveTheme(mode) {
695
772
 
696
773
  function updateThemeButtons(mode) {
697
774
  if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return
698
- const iconName = effectiveTheme(mode) === 'dark' ? 'moon' : 'sun'
699
- const label = THEME_LABEL[mode] || THEME_LABEL.auto
775
+ const next = THEME_LABEL[mode] ? mode : 'auto'
776
+ const iconName = effectiveTheme(next) === 'dark' ? 'moon' : 'sun'
777
+ const label = THEME_LABEL[next]
700
778
  document.querySelectorAll('[data-action="cycle-theme"]').forEach(btn => {
701
779
  btn.title = `当前主题:${label}(点击切换)`
702
780
  btn.setAttribute('aria-label', `切换外观主题(当前:${label})`)
@@ -711,23 +789,114 @@ function updateThemeButtons(mode) {
711
789
  }
712
790
 
713
791
  function applyTheme(mode) {
714
- if (typeof document !== 'undefined' && document.documentElement) {
715
- if (mode === 'light' || mode === 'dark') document.documentElement.dataset.theme = 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
716
795
  else delete document.documentElement.dataset.theme
717
796
  }
718
- updateThemeButtons(mode)
797
+ updateThemeButtons(next)
798
+ return next
719
799
  }
720
800
 
721
801
  function initTheme() {
722
- applyTheme(currentTheme())
802
+ state.theme = applyTheme(currentTheme())
723
803
  if (typeof matchMedia === 'function') {
724
804
  const mq = matchMedia('(prefers-color-scheme: dark)')
725
805
  mq.addEventListener?.('change', () => {
726
- if (currentTheme() === 'auto') updateThemeButtons('auto')
806
+ if (state.theme === 'auto') updateThemeButtons('auto')
727
807
  })
728
808
  }
729
809
  }
730
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
+
731
900
  // ── Components (primitives.tsx) ──
732
901
  function pill(tone, body, tip) {
733
902
  const safeTip = tip ? esc(tip) : ''
@@ -813,7 +982,15 @@ function formatGpuSummary(gpus) {
813
982
  const short = shortenGpuName(g?.name)
814
983
  counts.set(short, (counts.get(short) || 0) + 1)
815
984
  }
816
- return [...counts.entries()].map(([name, count]) => count > 1 ? `${count}× ${name}` : name).join(' + ')
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)
817
994
  }
818
995
 
819
996
  function serviceBusyKey(devId, name) {
@@ -837,6 +1014,10 @@ function setupGuide() {
837
1014
  <div class="install-command"><code class="mono">python3 -m localmodels install</code>${btn({ label: '复制完整安装命令', action: 'copy-install' })}</div>
838
1015
  <p>完整安装:检测设备 → 生成套件计划 → 确认一次 → 安装并验收。最终组件与资源需求以计划为准;复制命令不会执行安装。</p>
839
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>
840
1021
  </div>
841
1022
  </details>`
842
1023
  }
@@ -873,7 +1054,7 @@ function activeDeploymentsStrip() {
873
1054
  function deviceSection() {
874
1055
  const chips = state.devices.map(d => {
875
1056
  const f = d.facts
876
- const gpus = f?.gpus?.length ? formatGpuSummary(f.gpus) : f ? (f.platform === 'darwin' ? 'Apple 统一内存' : '无独立 GPU') : '未检测'
1057
+ const gpus = summarizeGpus(f)
877
1058
  const displayLabel = d.id === 'local' && d.label === 'this computer' ? '本机' : d.label
878
1059
  const metaText = f ? `${f.hostname} · ${gpus}` : gpus
879
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}">
@@ -957,7 +1138,7 @@ function runtimeSection(facts, cat) {
957
1138
  title: `<span class="mono" style="font-weight:500">${esc(p.service.name)}</span>${statusBadge}`,
958
1139
  desc,
959
1140
  action: [
960
- showCopy ? btn({ variant: 'ghost', label: '复制地址', iconName: 'copy', action: 'copy-endpoint', arg: p.endpoint.base_url, disabled: Boolean(busy) }) : '',
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)}"` }) : '',
961
1142
  btn({ variant: 'ghost', label: copy.status, iconName: busy === 'status' ? 'loader' : 'refresh', spin: busy === 'status', action: 'service', arg: `${p.name}:status`, disabled: Boolean(busy) }),
962
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) }) : '',
963
1144
  showStop ? btn({ label: copy.stopServer, iconName: busy === 'stop' ? 'loader' : 'stop', spin: busy === 'stop', action: 'service', arg: `${p.name}:stop`, disabled: Boolean(busy) }) : '',
@@ -1053,7 +1234,14 @@ function catalogRow(m, shared, recommended = false) {
1053
1234
  action = btn({ label: copy.steps[job.step] || '准备', iconName: 'loader', spin: true, action: 'noop', disabled: true })
1054
1235
  } else {
1055
1236
  action = (deployed ? pill('primary', `${icon('check')}已部署`, deployed.plan?.endpoint?.base_url) : '')
1056
- + (m.status === 'deprecated' ? '' : btn({ variant: recommended ? 'primary' : 'outline', label: copy.deployAction(m.size_label), iconName: 'download', action: 'plan', arg: m.id, disabled: !m.fits }))
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
+ }))
1057
1245
  }
1058
1246
  const fitTip = [m.quant_reason, m.fit_summary].filter(Boolean).join('。') || undefined
1059
1247
  const fitPill = !m.fits
@@ -1108,20 +1296,46 @@ function catalogPartition(cat) {
1108
1296
  return { recommended, named, alternatives }
1109
1297
  }
1110
1298
 
1111
- function alternativeRowsHtml(cat, partition = catalogPartition(cat)) {
1299
+ function filterAlternatives(alternatives) {
1112
1300
  const query = (state.modelQuery || '').trim().toLowerCase()
1113
- const matches = m => !query || [
1114
- m.id,
1115
- m.display_name,
1116
- m.quant,
1117
- m.description,
1118
- m.fit_summary,
1119
- m.quant_reason
1120
- ].some(v => v && String(v).toLowerCase().includes(query))
1121
- const filtered = partition.alternatives.filter(matches)
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)
1122
1317
  return filtered.length
1123
1318
  ? `<div class="rows">${filtered.map(m => catalogRow(m, partition.named.get(m.display_name) > 1)).join('')}</div>`
1124
- : '<p class="hint">未找到匹配的模型。</p>'
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
1125
1339
  }
1126
1340
 
1127
1341
  function modelsSection(cat) {
@@ -1139,11 +1353,18 @@ function modelsSection(cat) {
1139
1353
  if (recommended) {
1140
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>`
1141
1355
  }
1142
- const query = (state.modelQuery || '').trim().toLowerCase()
1356
+ const filterActive = Boolean((state.modelQuery || '').trim() || state.fitsOnly)
1143
1357
  if (alternatives.length) {
1144
- const searchBox = `<label class="search-field">${icon('search', 'sm')}<input type="search" name="model-query" value="${esc(state.modelQuery || '')}" placeholder="搜索模型名称、量化格式或说明…" aria-label="搜索模型目录"></label>`
1145
- const rowsHtml = alternativeRowsHtml(cat, partition)
1146
- body += `<details class="model-alternatives"${query ? ' open' : ''}><summary>${recommended ? '其他模型与历史条目' : '查看模型目录'}(${alternatives.length})</summary><p class="hint">候选与仅在其他平台验证的条目不代表本机已通过验收。已弃用条目仅供查询,已有部署可在「${esc(sectionTitles().runtime)}」管理。</p>${searchBox}<div class="model-alternatives-list">${rowsHtml}</div></details>`
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>`
1147
1368
  }
1148
1369
  return section({ id: 'sec-models', iconName: 'download', title: copy.modelsTitle, meta: String(cat.models.length) }, body)
1149
1370
  }
@@ -1237,7 +1458,12 @@ function planDialog() {
1237
1458
  const launchReasons = p.launch?.reasons || []
1238
1459
  const serviceArgv = p.service?.argv || []
1239
1460
  const fullCmd = serviceArgv.join(' ')
1240
- const launchHtml = `<div class="code-box"><pre>${esc(serviceArgv.slice(1).join(' '))}</pre>${fullCmd ? btn({ variant: 'ghost sm', label: '复制命令', iconName: 'copy', action: 'copy-cmd', arg: fullCmd }) : ''}</div>`
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>`
1241
1467
  const warnings = p.warnings || []
1242
1468
  body += `<dl class="plan">
1243
1469
  <dt>主机</dt><dd>${esc(p.hostname)}(${esc(p.host)})</dd>
@@ -1277,37 +1503,74 @@ function planDialog() {
1277
1503
  function confirmRemoveDialog() {
1278
1504
  const cr = state.confirmRemove
1279
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('')
1280
1513
  const errBlock = cr.error
1281
1514
  ? `<div class="gate danger" role="alert" style="margin:10px 0 0"><b>移除失败</b><p class="error-text">${esc(cr.error)}</p></div>`
1282
1515
  : ''
1283
1516
  return `<dialog class="dialog dialog-sm" role="dialog" aria-modal="true" aria-labelledby="remove-title" data-action="close-remove-backdrop">
1284
- <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>
1285
- <div class="dialog-body"><p style="margin:0;color:var(--text-secondary)">将停止并移除服务 <span class="mono">${esc(cr.name)}</span>;已下载的模型文件和引擎会保留在主机上。</p>${errBlock}</div>
1286
- <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 ? '正在移除…' : (cr.error ? '重试移除' : '确认移除'), iconName: cr.busy ? 'loader' : 'trash', spin: cr.busy, action: 'confirm-remove', disabled: cr.busy })}</div></div>
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>
1287
1548
  </dialog>`
1288
1549
  }
1289
1550
 
1290
1551
  // ── Render ──
1291
- let renderedModal = null
1292
1552
  let renderedPlanning = null
1293
1553
  let renderedRemove = null
1294
1554
  let planTrigger = null
1295
1555
  let removeTrigger = null
1556
+ let shortcutsTrigger = null
1296
1557
 
1297
- function renderPlanDialog() {
1298
- const root = document.getElementById('dialog-root')
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')
1299
1567
  if (!root || typeof root.querySelector !== 'function') return
1300
1568
  const dialog = root.querySelector('dialog')
1301
- const mode = state.planning ? 'plan' : state.confirmRemove ? 'remove' : null
1302
- if (!mode) {
1303
- if (!dialog) return
1569
+ if (!state.confirmRemove) {
1570
+ if (!dialog || !renderedRemove) return
1304
1571
  dialog.close()
1305
1572
  root.replaceChildren()
1306
- if (renderedModal === 'plan' && planTrigger?.deviceId === state.selected) {
1307
- const trigger = [...document.querySelectorAll('[data-action="plan"]')]
1308
- .find(button => button.dataset.arg === planTrigger.modelId && !button.disabled)
1309
- trigger?.focus()
1310
- } else if (renderedModal === 'remove' && removeTrigger?.deviceId === state.selected) {
1573
+ if (removeTrigger?.deviceId === state.selected) {
1311
1574
  const trigger = !removeTrigger.succeeded
1312
1575
  ? [...document.querySelectorAll('[data-action="service"]')]
1313
1576
  .find(button => button.dataset.arg === `${removeTrigger.name}:remove` && !button.disabled)
@@ -1322,54 +1585,89 @@ function renderPlanDialog() {
1322
1585
  }
1323
1586
  }
1324
1587
  }
1325
- renderedModal = null
1326
- renderedPlanning = null
1327
1588
  renderedRemove = null
1328
- planTrigger = null
1329
1589
  removeTrigger = null
1330
1590
  return
1331
1591
  }
1332
- if (mode === 'remove') {
1333
- if (!dialog || renderedModal !== 'remove' || renderedRemove !== state.confirmRemove) {
1334
- dialog?.close()
1335
- root.innerHTML = confirmRemoveDialog()
1336
- const opened = root.querySelector('dialog')
1337
- describeTips(opened)
1338
- opened.showModal()
1339
- opened.querySelector('#remove-title').focus()
1340
- renderedModal = 'remove'
1341
- renderedRemove = state.confirmRemove
1342
- renderedPlanning = null
1343
- return
1344
- }
1345
- const focused = document.activeElement
1346
- const focusedAction = focused?.dataset.action
1347
- const focusedSection = focused?.closest('.dialog-foot') ? '.dialog-foot' : '.dialog-body'
1348
- const next = document.createElement('template')
1349
- next.innerHTML = confirmRemoveDialog()
1350
- for (const selector of ['.dialog-body', '.dialog-foot']) {
1351
- dialog.querySelector(selector).replaceChildren(...next.content.querySelector(selector).childNodes)
1352
- }
1353
- const closeBtn = dialog.querySelector('.dialog-head [data-action="close-remove"]')
1354
- if (closeBtn) closeBtn.disabled = Boolean(state.confirmRemove.busy)
1355
- describeTips(dialog)
1356
- if (!dialog.contains(document.activeElement) || document.activeElement?.disabled) {
1357
- const replacement = focusedAction && dialog.querySelector(`${focusedSection} [data-action="${focusedAction}"]`)
1358
- if (replacement && !replacement.disabled) replacement.focus()
1359
- else dialog.querySelector('#remove-title').focus()
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()
1360
1658
  }
1659
+ renderedPlanning = null
1660
+ planTrigger = null
1361
1661
  return
1362
1662
  }
1363
- if (!dialog || renderedModal !== 'plan' || renderedPlanning !== state.planning) {
1663
+ if (!dialog || renderedPlanning !== state.planning) {
1364
1664
  dialog?.close()
1365
1665
  root.innerHTML = planDialog()
1366
1666
  const opened = root.querySelector('dialog')
1367
1667
  describeTips(opened)
1368
1668
  opened.showModal()
1369
1669
  opened.querySelector('#plan-title').focus()
1370
- renderedModal = 'plan'
1371
1670
  renderedPlanning = state.planning
1372
- renderedRemove = null
1373
1671
  return
1374
1672
  }
1375
1673
  const focused = document.activeElement
@@ -1436,14 +1734,17 @@ function render() {
1436
1734
  const selStart = active && 'selectionStart' in active ? active.selectionStart : null
1437
1735
  const selEnd = active && 'selectionEnd' in active ? active.selectionEnd : null
1438
1736
  page.innerHTML = html
1439
- if (alternativesOpen || (state.modelQuery || '').trim()) page.querySelector?.('.model-alternatives')?.setAttribute('open', '')
1737
+ if (alternativesOpen || (state.modelQuery || '').trim() || state.fitsOnly) page.querySelector?.('.model-alternatives')?.setAttribute('open', '')
1440
1738
  describeTips(page)
1739
+ renderChrome()
1441
1740
  syncSectionNavLabels()
1442
1741
  renderPlanDialog()
1742
+ if (hasDedicatedConfirmRoot()) renderRemoveDialog()
1743
+ renderShortcutsDialog()
1443
1744
  if (scrollBox && prevScrollTop != null && prevScrollTop > 0) {
1444
1745
  scrollBox.scrollTop = prevScrollTop
1445
1746
  }
1446
- if (focused && !state.planning && !state.confirmRemove) {
1747
+ if (focused && !state.planning && !state.confirmRemove && !state.shortcutsOpen) {
1447
1748
  const next = document.querySelector(`[name="${focused}"]`)
1448
1749
  if (next) {
1449
1750
  next.focus()
@@ -1654,10 +1955,16 @@ async function loadCandidates() {
1654
1955
  render()
1655
1956
  }
1656
1957
 
1958
+ let spyLockUntil = 0
1959
+
1960
+ function preferredScrollBehavior() {
1961
+ return typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth'
1962
+ }
1963
+
1657
1964
  const ACTIONS = {
1658
1965
  noop() {},
1659
1966
  'scroll-top'() {
1660
- if (typeof scrollToTopNav === 'function') scrollToTopNav()
1967
+ ACTIONS['jump-section']('setup-guide')
1661
1968
  },
1662
1969
  async 'copy-install'(arg, event) {
1663
1970
  if (await copyText('python3 -m localmodels install')) {
@@ -1667,6 +1974,15 @@ const ACTIONS = {
1667
1974
  toast('复制失败,请选中上方的完整安装命令手动复制。', '本地模型', 'error')
1668
1975
  }
1669
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
+ },
1670
1986
  async 'copy-cmd'(cmd, event) {
1671
1987
  if (await copyText(cmd)) {
1672
1988
  flashCopiedButton(event)
@@ -1730,14 +2046,57 @@ const ACTIONS = {
1730
2046
  render()
1731
2047
  }
1732
2048
  },
2049
+ 'set-theme'(theme) {
2050
+ state.theme = applyTheme(theme)
2051
+ localStorageSet(THEME_KEY, state.theme)
2052
+ renderChrome()
2053
+ },
1733
2054
  'cycle-theme'() {
1734
- const idx = THEME_CYCLE.indexOf(currentTheme())
2055
+ const idx = THEME_CYCLE.indexOf(state.theme)
1735
2056
  const next = THEME_CYCLE[(idx + 1) % THEME_CYCLE.length]
1736
- if (next === 'auto') localStorageRemove(THEME_KEY)
1737
- else localStorageSet(THEME_KEY, next)
1738
- applyTheme(next)
2057
+ ACTIONS['set-theme'](next)
1739
2058
  toast(`外观主题已切换为:${THEME_LABEL[next]}`)
1740
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
+ },
1741
2100
  async 'copy-endpoint'(url, event) {
1742
2101
  if (await copyText(url)) {
1743
2102
  flashCopiedButton(event)
@@ -1984,14 +2343,7 @@ let composing = false
1984
2343
 
1985
2344
  function handleModelQueryChange(value) {
1986
2345
  state.modelQuery = value
1987
- const container = typeof document !== 'undefined' && typeof document.querySelector === 'function'
1988
- ? document.querySelector('.model-alternatives-list')
1989
- : null
1990
- if (container && state.catalog) {
1991
- container.innerHTML = alternativeRowsHtml(state.catalog)
1992
- describeTips(container)
1993
- return
1994
- }
2346
+ if (refreshCatalogResults()) return
1995
2347
  render()
1996
2348
  }
1997
2349
 
@@ -2020,13 +2372,17 @@ function safeCrossLinkUrl(url) {
2020
2372
  return null
2021
2373
  }
2022
2374
 
2023
- function renderCrossLinks() {
2024
- if (typeof document === 'undefined' || typeof document.querySelector !== 'function') return
2025
- const valid = (state.crossLinks || []).map(item => {
2375
+ function validCrossLinks() {
2376
+ return (state.crossLinks || []).map(item => {
2026
2377
  const label = typeof item?.label === 'string' ? item.label.trim() : ''
2027
2378
  const url = safeCrossLinkUrl(item?.url)
2028
2379
  return label && url ? { label, url } : null
2029
2380
  }).filter(Boolean)
2381
+ }
2382
+
2383
+ function renderCrossLinks() {
2384
+ if (typeof document === 'undefined' || typeof document.querySelector !== 'function') return
2385
+ const valid = validCrossLinks()
2030
2386
  const mobileCross = document.querySelector('.mobile-cross-links')
2031
2387
  if (mobileCross) {
2032
2388
  mobileCross.innerHTML = valid.map(item => `<a class="mobile-nav-item" href="${esc(item.url)}">${esc(item.label)}</a>`).join('')
@@ -2057,6 +2413,61 @@ async function loadCrossLinks() {
2057
2413
  } catch { /* served only under web_preview */ }
2058
2414
  }
2059
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
+
2060
2471
  document.addEventListener('compositionstart', e => {
2061
2472
  if (e.target?.name === 'model-query') composing = true
2062
2473
  })
@@ -2072,15 +2483,19 @@ document.addEventListener('toggle', e => {
2072
2483
  if (e.target?.id === 'setup-guide') ACTIONS['toggle-guide'](null, e)
2073
2484
  }, true)
2074
2485
  document.addEventListener('cancel', e => {
2075
- if (e.target?.tagName === 'DIALOG' && (state.planning?.deploying || state.confirmRemove?.busy)) {
2076
- e.preventDefault()
2077
- }
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()
2078
2490
  }, true)
2079
2491
 
2080
2492
  document.addEventListener('click', e => {
2081
2493
  const el = e.target.closest('[data-action]')
2082
- if (!el || el.disabled) return
2083
- if (el.tagName === 'BUTTON') e.preventDefault()
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()
2084
2499
  ACTIONS[el.dataset.action]?.(el.dataset.arg, e)
2085
2500
  })
2086
2501
  document.addEventListener('submit', e => {
@@ -2089,24 +2504,47 @@ document.addEventListener('submit', e => {
2089
2504
  if (e.target.dataset.form === 'replan') ACTIONS.replan()
2090
2505
  })
2091
2506
  document.addEventListener('keydown', e => {
2092
- if (!state.planning && !state.confirmRemove) return
2093
- if (e.key === 'Escape') {
2094
- e.preventDefault()
2095
- if (state.confirmRemove) ACTIONS['close-remove']()
2096
- else ACTIONS['close-plan']()
2097
- } else if (e.key === 'Tab') {
2098
- const dialog = document.querySelector('#dialog-root dialog')
2099
- if (!dialog) return
2100
- const controls = [...dialog.querySelectorAll('button, input, select, [tabindex]')]
2101
- .filter(control => !control.disabled && control.tabIndex >= 0 && control.getClientRects().length)
2102
- const first = controls[0]
2103
- const last = controls[controls.length - 1]
2104
- if (e.shiftKey && (document.activeElement === first || !controls.includes(document.activeElement))) {
2507
+ const modal = activeModal()
2508
+ if (modal) {
2509
+ if (e.key === 'Escape') {
2105
2510
  e.preventDefault()
2106
- last?.focus()
2107
- } else if (!e.shiftKey && document.activeElement === last) {
2511
+ modal.close()
2512
+ } else if (e.key === '?' && state.shortcutsOpen && !e.ctrlKey && !e.metaKey && !e.altKey) {
2108
2513
  e.preventDefault()
2109
- first?.focus()
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']()
2110
2548
  }
2111
2549
  }
2112
2550
  })
@@ -2142,93 +2580,24 @@ document.addEventListener('scroll', () => showTip(null), true)
2142
2580
 
2143
2581
  hydrateIcons()
2144
2582
  initTheme()
2145
- const scrollEl = document.querySelector('.scroll')
2146
- const navLinks = [...document.querySelectorAll('.nav-list .nav-item')]
2147
- const mobileNavLinks = [...document.querySelectorAll('.mobile-nav .mobile-nav-item')]
2148
- const topNavItem = navLinks[0]
2149
- if (topNavItem) {
2150
- topNavItem.setAttribute('role', 'button')
2151
- topNavItem.tabIndex = 0
2152
- }
2153
- let spyLockUntil = 0
2154
- function syncNavCurrent(targetHash) {
2155
- const activeHash = targetHash || location.hash || '#setup-guide'
2156
- const matched = navLinks.some(a => a.getAttribute('href') === activeHash)
2157
- navLinks.forEach((a, i) => {
2158
- if ((matched && a.getAttribute('href') === activeHash) || (!matched && i === 0)) a.setAttribute('aria-current', 'location')
2159
- else a.removeAttribute('aria-current')
2160
- })
2161
- const mobileMatched = mobileNavLinks.some(a => a.getAttribute('href') === activeHash)
2162
- mobileNavLinks.forEach((a, i) => {
2163
- if ((mobileMatched && a.getAttribute('href') === activeHash) || (!mobileMatched && i === 0)) a.setAttribute('aria-current', 'location')
2164
- else a.removeAttribute('aria-current')
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
+ }
2165
2593
  })
2166
2594
  }
2167
- function scrollToTopNav() {
2168
- spyLockUntil = Date.now() + 500
2169
- if (location.hash) {
2170
- try { history.replaceState(null, '', location.pathname + location.search) } catch { /* ignore */ }
2171
- }
2172
- const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
2173
- scrollEl?.scrollTo?.({ top: 0, behavior: reduced ? 'auto' : 'smooth' })
2174
- syncNavCurrent('#setup-guide')
2175
- }
2176
- navLinks.forEach((item, i) => {
2177
- if (i === 0) {
2178
- item.addEventListener('click', scrollToTopNav)
2179
- item.addEventListener('keydown', e => {
2180
- if (e.key === 'Enter' || e.key === ' ') {
2181
- e.preventDefault()
2182
- scrollToTopNav()
2183
- }
2184
- })
2185
- } else {
2186
- item.addEventListener('click', () => {
2187
- spyLockUntil = Date.now() + 500
2188
- syncNavCurrent(item.getAttribute('href'))
2189
- })
2190
- }
2191
- })
2192
- mobileNavLinks.forEach(item => {
2193
- if (!item.hasAttribute('data-nav-top')) {
2194
- item.addEventListener('click', () => {
2195
- spyLockUntil = Date.now() + 500
2196
- syncNavCurrent(item.getAttribute('href'))
2197
- })
2198
- }
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)
2199
2600
  })
2200
- if (scrollEl) {
2201
- let spyScheduled = false
2202
- const sectionHashes = ['#sec-devices', '#sec-models', '#sec-runtime', '#sec-hardware']
2203
- const updateScrollSpy = () => {
2204
- spyScheduled = false
2205
- if (Date.now() < spyLockUntil) return
2206
- if (scrollEl.scrollTop <= 24) {
2207
- syncNavCurrent('#setup-guide')
2208
- return
2209
- }
2210
- const existing = sectionHashes.map(hash => ({ hash, el: document.querySelector(hash) })).filter(x => x.el)
2211
- if (!existing.length) return
2212
- if (scrollEl.scrollTop + scrollEl.clientHeight >= scrollEl.scrollHeight - 16) {
2213
- syncNavCurrent(existing[existing.length - 1].hash)
2214
- return
2215
- }
2216
- const topEdge = scrollEl.getBoundingClientRect().top
2217
- let current = '#setup-guide'
2218
- for (const item of existing) {
2219
- if (item.el.getBoundingClientRect().top - topEdge <= 96) current = item.hash
2220
- }
2221
- syncNavCurrent(current)
2222
- }
2223
- scrollEl.addEventListener('scroll', () => {
2224
- if (!spyScheduled) {
2225
- spyScheduled = true
2226
- requestAnimationFrame(updateScrollSpy)
2227
- }
2228
- }, { passive: true })
2229
- }
2230
- addEventListener('hashchange', () => syncNavCurrent())
2231
- syncNavCurrent()
2232
2601
  loadCrossLinks()
2233
2602
  loadDevices().then(() => loadDevice()).catch(e => { state.error = e.message; render() })
2234
2603
  </script>