dsh-modpack-kit 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -92,6 +92,41 @@ window.__ModuleLoader__.load({
92
92
  return () => packStore.subs.delete(fn)
93
93
  }
94
94
 
95
+ // 插件市场的 AI 搜索:市场新版本用 POST /dsh-market/ai-search,让「你在 DSH 里配的模型」从目录里挑插件。
96
+ // 我们不重复实现模型调用:旧版市场(或没装)没有这条路由,界面自动退回纯关键词搜索。
97
+ const AI_SEARCH_KEY = "dsh-modpack-kit:ai-search"
98
+ function readAiSearchPref() {
99
+ try { return window.localStorage.getItem(AI_SEARCH_KEY) === "1" } catch (e) { return false }
100
+ }
101
+ function writeAiSearchPref(on) {
102
+ try { window.localStorage.setItem(AI_SEARCH_KEY, on ? "1" : "0") } catch (e) { /* 存不了不影响本场 */ }
103
+ }
104
+ let aiProbe = null
105
+ function marketAiSearchReady() {
106
+ if (!aiProbe) {
107
+ aiProbe = fetch("/dsh-market/ai-search", { method: "GET", credentials: "same-origin" })
108
+ .then((res) => res.status === 405 || res.status === 200)
109
+ .catch(() => false)
110
+ }
111
+ return aiProbe
112
+ }
113
+ async function callMarketAiSearch(query) {
114
+ const res = await fetch("/dsh-market/ai-search", {
115
+ method: "POST",
116
+ credentials: "same-origin",
117
+ headers: { "content-type": "application/json" },
118
+ body: JSON.stringify({ query }),
119
+ })
120
+ let body = null
121
+ try { body = await res.json() } catch (e) { body = null }
122
+ if (!res.ok || !body || !body.result) {
123
+ const error = new Error((body && body.error) || ("AI 搜索没有返回结果(HTTP " + res.status + ")"))
124
+ error.code = (body && body.code) || (res.status === 409 ? "no-model" : "model-failed")
125
+ throw error
126
+ }
127
+ return body.result
128
+ }
129
+
95
130
  // 已导入的整合包:可以同时留好几份,各自显示名字 / 作者 / 描述,切页签也还在
96
131
  const importStore = { value: [], subs: new Set() }
97
132
  function readImports() {
@@ -166,6 +201,72 @@ window.__ModuleLoader__.load({
166
201
  return data
167
202
  }
168
203
 
204
+ // 插件市场的侧栏入口(/dsh-market/sidebar-entry):本条开关就是替市场把 enabled 关掉。
205
+ // 市场那一行是它自己的偏好,存在 profile 的 .dsh-market/state.json 里;我们只写这一个键。
206
+ const MARKET_SIDEBAR_ROUTE = "/dsh-market/sidebar-entry"
207
+ async function readMarketSidebar() {
208
+ try {
209
+ const res = await fetch(MARKET_SIDEBAR_ROUTE, { headers: { Accept: "application/json" }, credentials: "same-origin" })
210
+ if (!res.ok) return null
211
+ const data = await res.json()
212
+ return data && typeof data.enabled === "boolean" ? data : null
213
+ } catch (e) { return null }
214
+ }
215
+ async function writeMarketSidebar(enabled) {
216
+ const res = await fetch(MARKET_SIDEBAR_ROUTE, {
217
+ method: "POST",
218
+ headers: { "Content-Type": "application/json" },
219
+ credentials: "same-origin",
220
+ body: JSON.stringify({ enabled: enabled === true }),
221
+ })
222
+ let data = null
223
+ try { data = await res.json() } catch (e) { data = null }
224
+ if (!res.ok) {
225
+ const error = new Error((data && (data.error || data.message)) || ("插件市场拒绝了这次修改(HTTP " + res.status + ")"))
226
+ error.status = res.status
227
+ throw error
228
+ }
229
+ return data
230
+ }
231
+
232
+ // 开机把市场的侧栏入口关一次:插件加载时拉 /status 顺带执行,不必等用户点开某一栏。
233
+ let marketSidebarForced = false
234
+ async function enforceMarketSidebarOff() {
235
+ if (marketSidebarForced) return
236
+ const current = await readMarketSidebar()
237
+ if (!current) return
238
+ if (current.enabled !== true) { marketSidebarForced = true; return }
239
+ try { await writeMarketSidebar(false); marketSidebarForced = true } catch (e) { marketSidebarForced = true }
240
+ }
241
+
242
+ // 解除卡顿插件(dsh-unlag):装了才有按钮。只读它的 /state;按一次要带它要的头。
243
+ const UNLAG_STATE_ROUTE = "/dsh-unlag/state"
244
+ async function detectUnlag() {
245
+ try {
246
+ const res = await fetch(UNLAG_STATE_ROUTE, { headers: { Accept: "application/json" }, credentials: "same-origin" })
247
+ if (!res.ok) return null
248
+ const data = await res.json()
249
+ return data && typeof data.version === "string" ? data : null
250
+ } catch (e) { return null }
251
+ }
252
+ async function pressUnlag() {
253
+ const requestId = "modpack-" + Date.now().toString(36) + "-" + Math.random().toString(36).slice(2, 8)
254
+ const res = await fetch("/dsh-unlag/reload?requestId=" + encodeURIComponent(requestId), {
255
+ method: "POST",
256
+ headers: { "Content-Type": "application/json", "x-dsh-unlag": "1" },
257
+ credentials: "same-origin",
258
+ body: JSON.stringify({}),
259
+ })
260
+ let data = null
261
+ try { data = await res.json() } catch (e) { data = null }
262
+ if (!res.ok) {
263
+ const error = new Error((data && (data.status || data.message || data.error)) || ("解除卡顿拒绝了这次请求(HTTP " + res.status + ")"))
264
+ error.status = res.status
265
+ throw error
266
+ }
267
+ return data
268
+ }
269
+
169
270
  // 宿主有没有原生的目录选择器:有就能点「浏览文件夹…」,没有就退回手填
170
271
  let pickDirectoryHost = null
171
272
 
@@ -223,7 +324,7 @@ window.__ModuleLoader__.load({
223
324
  }
224
325
 
225
326
  function Switch(props) {
226
- return h("label", { style: { display: "inline-flex", gap: "6px", alignItems: "center", fontSize: "12.5px", cursor: props.disabled ? "not-allowed" : "pointer", opacity: props.disabled ? 0.45 : 1 } },
327
+ return h("label", { title: props.title || undefined, style: { display: "inline-flex", gap: "6px", alignItems: "center", fontSize: "12.5px", cursor: props.disabled ? "not-allowed" : "pointer", opacity: props.disabled ? 0.45 : 1 } },
227
328
  h("input", { type: "checkbox", checked: !!props.checked, disabled: !!props.disabled, onChange: (e) => props.onChange(e.target.checked) }),
228
329
  props.label)
229
330
  }
@@ -376,18 +477,78 @@ window.__ModuleLoader__.load({
376
477
 
377
478
  // 进度窗:可以拖,拖过的位置记在浏览器本地;没有任务时自动收起,只留一枚唤出按钮。
378
479
  const DOCK_POS_KEY = "dsh-modpack-kit:dock-pos"
480
+ // localStorage 里只存相对坐标(fx/fy,0~1),换窗口大小时按比例还原一次;
481
+ // 界面上的位置一律用像素,并且不存任何「算出来的高度 / 要不要向上长」这类状态。
379
482
  function readDockPos() {
380
483
  try {
381
484
  const raw = typeof localStorage !== "undefined" ? localStorage.getItem(DOCK_POS_KEY) : null
382
485
  if (!raw) return null
383
486
  const parsed = JSON.parse(raw)
384
487
  if (!parsed || typeof parsed !== "object") return null
385
- if (!Number.isFinite(Number(parsed.x)) || !Number.isFinite(Number(parsed.y))) return null
386
- return { x: Math.max(0, Math.round(Number(parsed.x))), y: Math.max(0, Math.round(Number(parsed.y))) }
488
+ if (Number.isFinite(Number(parsed.fx)) && Number.isFinite(Number(parsed.fy))) {
489
+ return { fx: Math.max(0, Math.min(1, Number(parsed.fx))), fy: Math.max(0, Math.min(1, Number(parsed.fy))) }
490
+ }
491
+ // 老版本存的是像素:按当前视口折算成相对坐标,迁移一次就够了
492
+ if (Number.isFinite(Number(parsed.x)) && Number.isFinite(Number(parsed.y))) {
493
+ const vp = viewportSize()
494
+ return { fx: Math.max(0, Math.min(1, Number(parsed.x) / vp.width)), fy: Math.max(0, Math.min(1, Number(parsed.y) / vp.height)) }
495
+ }
496
+ return null
387
497
  } catch { return null }
388
498
  }
389
499
  function writeDockPos(pos) {
390
- try { if (typeof localStorage !== "undefined" && pos) localStorage.setItem(DOCK_POS_KEY, JSON.stringify(pos)) } catch { /* 存不了就算了,不影响本场使用 */ }
500
+ try {
501
+ if (typeof localStorage === "undefined" || !pos) return
502
+ const vp = viewportSize()
503
+ localStorage.setItem(DOCK_POS_KEY, JSON.stringify({
504
+ fx: Math.max(0, Math.min(1, Number(pos.x) / vp.width)),
505
+ fy: Math.max(0, Math.min(1, Number(pos.y) / vp.height)),
506
+ }))
507
+ } catch { /* 存不了就算了,不影响本场使用 */ }
508
+ }
509
+ // 召回:把存在浏览器里的位置清掉,回到默认的右下角
510
+ function clearDockPos() {
511
+ try {
512
+ if (typeof localStorage !== 'undefined') localStorage.removeItem(DOCK_POS_KEY)
513
+ } catch { /* 清不掉也没关系,下一次拖动会覆盖 */ }
514
+ }
515
+ // DSH 顶栏 / 标签行大约占这么高:窗口别停在那上面,否则会盖住界面的按钮
516
+ const DOCK_TOP_INSET = 56
517
+ const DOCK_MARGIN = 12 // 离视口边缘至少留这么宽
518
+ const DOCK_MIN_LEFT = 4
519
+ const DOCK_W = 300 // 收起、展开同一个宽度,简单可预期
520
+ const DOCK_OPEN_MAX_H = 420 // 展开时最高这么多,再多就在窗里滚动
521
+ const DOCK_HEAD_H = 44 // 标题行的占位高度:夹边只按它算,展开多高由可用空间决定
522
+ const clampNum = (value, min, max) => Math.max(min, Math.min(value, max))
523
+ // 和布局有关的只有这一件事:把像素位置夹回可见区。
524
+ // 没有「自动判定向上/向下」、也没有自动算高度——拖到哪就是哪,超出才夹回来,默认落右下角。
525
+ function clampDockPos(pos, viewport, size) {
526
+ const vw = Math.max(1, Number(viewport && viewport.width) || 0)
527
+ const vh = Math.max(1, Number(viewport && viewport.height) || 0)
528
+ const w = Math.max(1, Number(size && size.w) || DOCK_W)
529
+ const h = Math.max(1, Number(size && size.h) || 44)
530
+ const x = pos && Number.isFinite(Number(pos.x)) ? Number(pos.x) : vw - w - DOCK_MARGIN
531
+ const y = pos && Number.isFinite(Number(pos.y)) ? Number(pos.y) : vh - h - DOCK_MARGIN
532
+ return {
533
+ x: Math.round(clampNum(x, DOCK_MIN_LEFT, Math.max(DOCK_MIN_LEFT, vw - w - DOCK_MIN_LEFT))),
534
+ y: Math.round(clampNum(y, DOCK_TOP_INSET, Math.max(DOCK_TOP_INSET, vh - h - DOCK_MIN_LEFT))),
535
+ }
536
+ }
537
+ // 存下来的相对坐标 -> 像素(窗口大小变了就按比例落回去)
538
+ function dockFromFractions(saved, viewport) {
539
+ if (!saved) return null
540
+ const vw = Math.max(1, Number(viewport && viewport.width) || 0)
541
+ const vh = Math.max(1, Number(viewport && viewport.height) || 0)
542
+ return { x: clampNum(Number(saved.fx) || 0, 0, 1) * vw, y: clampNum(Number(saved.fy) || 0, 0, 1) * vh }
543
+ }
544
+ // 召回:标签行那个显眼按钮通过它把进度窗叫回默认位置
545
+ const dockReset = { subs: new Set() }
546
+ function requestDockReset() {
547
+ for (const fn of Array.from(dockReset.subs)) { try { fn() } catch { /* 某个订阅坏了不该影响别的 */ } }
548
+ }
549
+ function subscribeDockReset(fn) {
550
+ dockReset.subs.add(fn)
551
+ return () => { dockReset.subs.delete(fn) }
391
552
  }
392
553
  function viewportSize() {
393
554
  const width = typeof window !== "undefined" && Number(window.innerWidth) ? Number(window.innerWidth) : 1280
@@ -403,13 +564,26 @@ window.__ModuleLoader__.load({
403
564
  useEffect(() => {
404
565
  setCleared((prev) => (prev.length === 0 ? prev : prev.filter((id) => given.some((job) => job.id === id))))
405
566
  }, [given])
406
- const [pos, setPos] = useState(readDockPos())
567
+ const [pos, setPos] = useState(() => dockFromFractions(readDockPos(), viewportSize()))
407
568
  const [pinned, setPinned] = useState(false) // 手动唤出:没有任务时也显示
408
569
  const [hidden, setHidden] = useState(false) // 手动收起:连进行中的也先藏起来
409
570
  const [open, setOpen] = useState(false)
410
571
  const [dockMsg, setDockMsg] = useState("")
411
572
  const dragRef = useRef(null)
412
573
  const boxRef = useRef(null)
574
+ const headerRef = useRef(null)
575
+ const pillRef = useRef(null)
576
+ // 窗口大小变了要重算贴边位置,所以留一个 tick 触发重渲染
577
+ const [, setViewportTick] = useState(0)
578
+ // 标签行的「召回」把窗口叫回右下角默认位置
579
+ useEffect(() => subscribeDockReset(() => {
580
+ // 召回是「兜底入口」:任何一步出错都不能把整个面板带崩,所以逐条 try 住
581
+ try { clearDockPos() } catch { /* 清不掉照样能显示 */ }
582
+ setPos(null)
583
+ setOpen(false)
584
+ setHidden(false)
585
+ setPinned(true)
586
+ }), [])
413
587
  const running = jobs.filter((job) => job.status === "running")
414
588
  const visible = !hidden && (pinned || running.length > 0)
415
589
 
@@ -418,12 +592,19 @@ window.__ModuleLoader__.load({
418
592
  if (running.length > 0) { setHidden(false) }
419
593
  }, [running.length])
420
594
 
421
- const startDrag = (event) => {
595
+ useEffect(() => {
596
+ if (typeof window === "undefined" || typeof window.addEventListener !== "function") return undefined
597
+ const onResize = () => setViewportTick((n) => n + 1)
598
+ window.addEventListener("resize", onResize)
599
+ return () => { window.removeEventListener("resize", onResize) }
600
+ }, [])
601
+ // 最小化的胶囊自己也是一个按钮,所以这一路要放行:不然 pointer 事件会被当成「按在按钮上」直接丢掉。
602
+ const startDrag = (event, element, allowOnButton) => {
422
603
  if (!event || typeof event.clientX !== "number") return
423
604
  // 按在按钮上就别当拖动:否则指针捕获会把 click 抢走,按钮点不到,
424
605
  // 而且抬手时还会顺带把窗口展开/收起(就是「判定重叠」那个毛病)
425
- if (event.target && typeof event.target.closest === "function" && event.target.closest("button")) return
426
- const el = boxRef.current
606
+ if (!allowOnButton && event.target && typeof event.target.closest === "function" && event.target.closest("button")) return
607
+ const el = element || boxRef.current
427
608
  const rect = el && el.getBoundingClientRect ? el.getBoundingClientRect() : { left: 0, top: 0, width: 0, height: 0 }
428
609
  dragRef.current = {
429
610
  dx: event.clientX - rect.left,
@@ -442,12 +623,13 @@ window.__ModuleLoader__.load({
442
623
  const moveDrag = (event) => {
443
624
  const drag = dragRef.current
444
625
  if (!drag || !event || typeof event.clientX !== "number") return
445
- const { width, height } = viewportSize()
446
- const left = Math.min(Math.max(4, event.clientX - drag.dx), Math.max(4, width - drag.width - 4))
447
- const top = Math.min(Math.max(4, event.clientY - drag.dy), Math.max(4, height - drag.height - 4))
448
- if (Math.abs(left - drag.startX) > 3 || Math.abs(top - drag.startY) > 3) drag.moved = true
449
- drag.last = { x: Math.round(left), y: Math.round(top) }
450
- setPos(drag.last)
626
+ const vp = viewportSize()
627
+ // 就用指针位移 + 起手时的窗口尺寸,别在拖动过程中再引用任何会被自己改掉的布局值
628
+ const size = { w: drag.width || DOCK_W, h: DOCK_HEAD_H }
629
+ const next = clampDockPos({ x: event.clientX - drag.dx, y: event.clientY - drag.dy }, vp, size)
630
+ if (Math.abs(next.x - drag.startX) > 3 || Math.abs(next.y - drag.startY) > 3) drag.moved = true
631
+ drag.last = next
632
+ setPos(next)
451
633
  }
452
634
  const endDrag = () => {
453
635
  const drag = dragRef.current
@@ -457,12 +639,30 @@ window.__ModuleLoader__.load({
457
639
  if (drag.last) writeDockPos(drag.last)
458
640
  return
459
641
  }
460
- // 没拖动就是点了一下标题:展开 / 收起
461
- setOpen((prev) => !prev)
642
+ // 没拖动就是点了一下标题:展开 / 收起。
643
+ // 不预算任何尺寸与位置:点一下只是开/关,位置永远由 pos + clampDockPos 决定,不会跳。
644
+ setOpen(!open)
645
+ }
646
+ // 胶囊抬手:拖过就记住位置,没拖就是「打开」
647
+ const endPillDrag = () => {
648
+ const drag = dragRef.current
649
+ if (!drag) return
650
+ dragRef.current = null
651
+ if (drag.moved) {
652
+ if (drag.last) writeDockPos(drag.last)
653
+ return
654
+ }
655
+ setPinned(true)
656
+ setHidden(false)
462
657
  }
463
658
 
464
659
  if (!visible) {
465
- const anchor = pos || null
660
+ const vp = viewportSize()
661
+ const pillW = 132
662
+ const pillH = 42
663
+ // 胶囊也用相对坐标现算:换窗口大小它跟着走
664
+ const pillAt = clampDockPos(pos, vp, { w: pillW, h: pillH })
665
+ const pillPos = { left: pillAt.x + "px", top: pillAt.y + "px" }
466
666
  const summonStyle = {
467
667
  position: "fixed",
468
668
  zIndex: 70,
@@ -475,12 +675,22 @@ window.__ModuleLoader__.load({
475
675
  background: "var(--dsw-alias-surface-1, rgba(24,26,31,.97))",
476
676
  color: "var(--dsw-alias-label-primary)",
477
677
  boxShadow: "0 6px 18px rgba(0,0,0,.28)",
478
- cursor: "pointer",
678
+ cursor: pos ? "grab" : "pointer",
479
679
  fontSize: "12px",
480
- ...(anchor ? { left: anchor.x + "px", top: anchor.y + "px" } : { right: "16px", bottom: "16px" }),
680
+ touchAction: "none",
681
+ userSelect: "none",
682
+ ...pillPos,
481
683
  }
482
684
  const badge = running.length || jobs.length
483
- return h("button", { style: summonStyle, title: "打开整合包进度窗", onClick: () => { setPinned(true); setHidden(false) } },
685
+ return h("button", {
686
+ ref: pillRef,
687
+ style: summonStyle,
688
+ title: pos ? "打开整合包进度窗(按住可以拖到别处)" : "打开整合包进度窗(按住可以拖到别处)",
689
+ onPointerDown: (event) => startDrag(event, pillRef.current, true),
690
+ onPointerMove: moveDrag,
691
+ onPointerUp: endPillDrag,
692
+ onPointerCancel: endPillDrag,
693
+ },
484
694
  h("span", { style: { width: "7px", height: "7px", borderRadius: "99px", background: running.length ? "#4C7DF0" : "rgba(127,163,245,.5)" } }),
485
695
  "进度",
486
696
  badge ? h("span", { style: { ...hint, marginLeft: "0", fontVariantNumeric: "tabular-nums" } }, String(badge)) : null)
@@ -529,14 +739,20 @@ window.__ModuleLoader__.load({
529
739
  // 只要有一条不是「在跑」或「停在风险点」,就给清空入口(状态再怪也算收尾)
530
740
  const finished = jobs.filter((job) => job.status !== "running" && job.status !== "paused")
531
741
 
742
+ // 一帧算完全部布局:位置、宽度、高度、向上还是向下,全部来自当前视口 + 量出来的尺寸。
743
+ // 夹边永远只按「标题行 + 固定宽度」算,所以展开不会把窗口顶上去(高度自己缩,位置不动)
744
+ const vp = viewportSize()
745
+ const placed = clampDockPos(pos, vp, { w: DOCK_W, h: DOCK_HEAD_H })
746
+ const dockPos = { left: placed.x + "px", top: placed.y + "px" }
747
+ const openMaxH = Math.max(160, Math.min(DOCK_OPEN_MAX_H, vp.height - placed.y - DOCK_MARGIN))
532
748
  return h("div", {
533
749
  ref: boxRef,
534
750
  style: {
535
751
  position: "fixed",
536
752
  zIndex: 70,
537
- ...(pos ? { left: pos.x + "px", top: pos.y + "px" } : { right: "16px", bottom: "16px" }),
538
- width: open ? "380px" : "288px",
539
- maxHeight: open ? "58vh" : "none",
753
+ ...dockPos,
754
+ width: DOCK_W + "px",
755
+ maxHeight: open ? openMaxH + "px" : "none",
540
756
  overflow: "auto",
541
757
  boxSizing: "border-box",
542
758
  padding: "10px 12px",
@@ -550,6 +766,7 @@ window.__ModuleLoader__.load({
550
766
  },
551
767
  },
552
768
  h("div", {
769
+ ref: headerRef,
553
770
  style: { display: "flex", alignItems: "center", gap: "8px", cursor: "grab", userSelect: "none", touchAction: "none" },
554
771
  title: "按住可以拖动;点一下展开或收起",
555
772
  onPointerDown: startDrag,
@@ -636,6 +853,10 @@ window.__ModuleLoader__.load({
636
853
  const [category, setCategory] = useState("all")
637
854
  const [search, setSearch] = useState({ items: [], total: 0, page: 0, hasMore: false, error: "" })
638
855
  const [searching, setSearching] = useState(false)
856
+ const [aiOn, setAiOn] = useState(readAiSearchPref)
857
+ const [aiReady, setAiReady] = useState(null)
858
+ const [aiBusy, setAiBusy] = useState(false)
859
+ const [aiRun, setAiRun] = useState(null)
639
860
  const [syncing, setSyncing] = useState("")
640
861
  const [options, setOptions] = useState(() => (draft.options ? { ...draft.options } : {
641
862
  strategy: "full",
@@ -743,6 +964,42 @@ window.__ModuleLoader__.load({
743
964
  return () => { alive = false; clearTimeout(timer) }
744
965
  }, [query, category, active, pageSize])
745
966
 
967
+ // AI 搜索:开着才探一次路由(旧版插件市场没有这条,就不显示开关)
968
+ useEffect(() => {
969
+ let alive = true
970
+ marketAiSearchReady().then((ok) => { if (alive) setAiReady(ok) })
971
+ return () => { alive = false }
972
+ }, [])
973
+
974
+ // 只在按回车或点「AI 来找」时调用:花的是主人自己的 token
975
+ const runAi = async () => {
976
+ const text = query.trim()
977
+ if (!text || aiBusy) return
978
+ setAiBusy(true)
979
+ setAiRun(null)
980
+ try {
981
+ const result = await callMarketAiSearch(text)
982
+ const picks = (Array.isArray(result.picks) ? result.picks : []).filter((item) => item && item.name)
983
+ setAiRun({ query: text, intro: result.intro || "", model: result.model || "", picks, error: "", code: "" })
984
+ if (picks.length) {
985
+ try {
986
+ const look = await api("/catalog/lookup", { names: picks.map((item) => item.name) })
987
+ if (look && look.ok) setMarketInfo((prev) => ({ ...prev, ...(look.items || {}) }))
988
+ } catch (e) { /* 版本信息补不上不影响结果 */ }
989
+ }
990
+ } catch (e) {
991
+ setAiRun({ query: text, intro: "", model: "", picks: [], error: e.message || String(e), code: e.code || "" })
992
+ } finally {
993
+ setAiBusy(false)
994
+ }
995
+ }
996
+ const toggleAi = () => {
997
+ const next = !aiOn
998
+ setAiOn(next)
999
+ writeAiSearchPref(next)
1000
+ if (!next) setAiRun(null)
1001
+ }
1002
+
746
1003
  const loadMore = async () => {
747
1004
  if (searching || !search.hasMore) return
748
1005
  setSearching(true)
@@ -1093,7 +1350,16 @@ window.__ModuleLoader__.load({
1093
1350
  h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
1094
1351
  h("div", { style: row },
1095
1352
  h("div", { style: strong }, "选择插件"),
1096
- h("input", { style: { ...input, flex: "1 1 200px" }, placeholder: "搜索插件名 / 描述(在插件市场目录里搜)", value: query, onChange: (e) => setQuery(e.target.value) }),
1353
+ h("input", {
1354
+ style: { ...input, flex: "1 1 200px" },
1355
+ placeholder: aiOn && aiReady ? "用一句话描述你要的插件(回车让 AI 在目录里挑)" : "搜索插件名 / 描述(在插件市场目录里搜)",
1356
+ value: query,
1357
+ onChange: (e) => setQuery(e.target.value),
1358
+ onKeyDown: (e) => { if (e.key === "Enter" && aiOn && aiReady) { e.preventDefault(); runAi() } },
1359
+ }),
1360
+ aiReady === true ? h("button", { style: aiOn ? chipOn : btn, onClick: toggleAi, title: "只调用插件市场提供的 AI 搜索接口:真正花的是你在「设置 → 模型」里配的那把 Key——请求由市场发出、扣你的额度,本插件既不读也不存 Key,只发这一次请求" }, aiOn ? "AI 搜索:开" : "AI 搜索:关") : null,
1361
+ aiOn && aiReady ? h("button", { style: btn, disabled: aiBusy || query.trim() === "", onClick: runAi }, aiBusy ? "AI 正在挑…" : "AI 来找") : null,
1362
+ aiOn && aiReady ? h("div", { style: { ...hint, width: "100%" } }, "AI 搜索的 token 消耗记在插件市场那边:它拿你在「设置 → 模型」里配的模型去问,本插件只把问题转过去、把结果拿回来,不读也不存你的 Key。") : null,
1097
1363
  active ? h("button", { style: btn, onClick: () => { setQuery(""); setCategory("all") } }, "回到已装") : null,
1098
1364
  h("button", { style: btn, onClick: addAllLocal, title: "把本机已装的全部插件加入选择(默认插件预设,可逐个改成自定义配置)" }, "全部加入"),
1099
1365
  h("button", { style: btn, disabled: picked.length === 0, onClick: clearSelected, title: "清空当前选择" }, "清除选择"),
@@ -1113,6 +1379,26 @@ window.__ModuleLoader__.load({
1113
1379
  onClick: () => setCategory(c.id),
1114
1380
  title: "只看「" + c.label + "」" + (c.count ? ",市场内 " + c.count + " 个" : ""),
1115
1381
  }, c.label + (c.count ? " " + c.count : "")))) : null,
1382
+ aiReady === false ? h("div", { style: hint }, "当前装的插件市场没有 AI 搜索(旧版本或未安装):这里只做关键词搜索。装新版 dshmarket 后开关会自动出现。") : null,
1383
+ aiRun ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "6px", borderColor: aiRun.error ? "#ff6b6b" : "var(--dsw-alias-border-l2)" } },
1384
+ h("div", { style: row },
1385
+ h("div", { style: strong }, aiRun.error ? "AI 搜索没成功" : "AI 挑的插件"),
1386
+ h("span", { style: hint }, aiRun.model ? "模型:" + aiRun.model : ""),
1387
+ h("button", { style: btn, onClick: () => setAiRun(null) }, "收起")),
1388
+ aiRun.error ? h("div", { style: { ...hint, color: "#ff6b6b" } }, aiRun.error + (aiRun.code === "no-model" ? " 先在「设置 → 模型」里配一个模型再试。" : "")) : null,
1389
+ aiRun.intro ? h("div", { style: hint }, aiRun.intro) : null,
1390
+ aiRun.picks.length === 0 && !aiRun.error ? h("div", { style: hint }, "这次没挑出合适的插件,换个说法再试。") : null,
1391
+ aiRun.picks.map((item) => {
1392
+ const meta = marketInfo[item.name] || {}
1393
+ const on = Boolean(selected[item.name])
1394
+ const entry = { name: item.name, installed: false, hasMarket: true, marketVersion: meta.version || "", version: meta.version || "" }
1395
+ return h("div", { key: item.name, style: { display: "flex", gap: "8px", alignItems: "flex-start", padding: "6px 2px", borderTop: "0.5px solid var(--dsw-alias-border-l2)" } },
1396
+ h("input", { type: "checkbox", checked: on, onChange: () => toggle(entry), style: { marginTop: "3px" } }),
1397
+ h("div", { style: { flex: "1 1 auto", minWidth: 0 } },
1398
+ h("div", { style: { ...strong, fontSize: "12.5px" } }, item.name + (meta.version ? " · v" + meta.version : "")),
1399
+ h("div", { style: hint }, item.description || ""),
1400
+ item.why ? h("div", { style: { ...hint, color: "var(--dsw-alias-label-tertiary, #8b8f99)" } }, "为什么:" + item.why) : null))
1401
+ })) : null,
1116
1402
  search.error ? h("div", { style: { ...hint, color: "#ffb020" } }, search.error) : null,
1117
1403
  h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", maxHeight: "320px", overflow: "auto" } },
1118
1404
  rows.length === 0
@@ -1604,6 +1890,7 @@ window.__ModuleLoader__.load({
1604
1890
  // 记录用本地状态:删一条不用整页重读,删完立刻看到结果
1605
1891
  const [history, setHistory] = useState((((props.status || {}).history) || []).slice())
1606
1892
  const [historyMsg, setHistoryMsg] = useState("")
1893
+ const [marketSidebarMsg, setMarketSidebarMsg] = useState("")
1607
1894
  const dropHistory = async (item, all) => {
1608
1895
  setHistoryMsg("")
1609
1896
  try {
@@ -1632,6 +1919,20 @@ window.__ModuleLoader__.load({
1632
1919
  } finally { setBusy(false) }
1633
1920
  }
1634
1921
  const setField = (key, value) => setCfg((prev) => ({ ...(prev || {}), [key]: value }))
1922
+ // 打开就替市场把侧栏入口关掉;关掉就还回去。市场没装就只提示,不报错。
1923
+ const toggleMarketSidebar = async (on) => {
1924
+ setMarketSidebarMsg("")
1925
+ setField("forceHideMarketSidebar", on)
1926
+ await patch({ forceHideMarketSidebar: on })
1927
+ const current = await readMarketSidebar()
1928
+ if (!current) { setMarketSidebarMsg("没装插件市场(dshmarket),或者在旧版本上没有这个入口。"); return }
1929
+ try {
1930
+ await writeMarketSidebar(!on)
1931
+ setMarketSidebarMsg(on ? "已关掉:市场侧栏那一行现在不显示。" : "已恢复:市场侧栏那一行按它的设置显示。")
1932
+ } catch (e) {
1933
+ setMarketSidebarMsg((e && e.message) || String(e))
1934
+ }
1935
+ }
1635
1936
  // 体积上限按 MB 输:先把输入框里的原始文本存着,点「保存数值」才换算成字节,
1636
1937
  // 这样不会每敲一个数字就四舍五入一次(以前会越打越多,最后存成 25 GB 这种值)。
1637
1938
  const [limitDraft, setLimitDraft] = useState(String(Math.round(((props.status && props.status.config && props.status.config.maxPackBytes) || 256 * 1048576) / 1048576)))
@@ -1772,6 +2073,15 @@ window.__ModuleLoader__.load({
1772
2073
  h(Switch, { checked: cfg.showInSettings !== false, disabled: placementLocked("showInSettings"), label: "在设置里显示(插件设置页内一栏「整合包」)" + (placementLocked("showInSettings") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInSettings", v) }),
1773
2074
  h(Switch, { checked: cfg.showInSidebar !== false, disabled: placementLocked("showInSidebar"), label: "在侧边栏显示(左侧栏「整合包」入口)" + (placementLocked("showInSidebar") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInSidebar", v) }),
1774
2075
  h(Switch, { checked: cfg.showInPluginsTab === true, disabled: placementLocked("showInPluginsTab"), label: "在插件页内显示(与插件市场同一位置,单开一栏「整合包」)" + (placementLocked("showInPluginsTab") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInPluginsTab", v) })),
2076
+ h("div", { style: { ...hint, borderTop: "0.5px solid var(--dsw-alias-border-l2)", paddingTop: "8px", marginTop: "2px" } }, "插件市场自己那一行(与上面整合包的入口无关):"),
2077
+ h(Switch, {
2078
+ checked: cfg.forceHideMarketSidebar === true,
2079
+ label: "强制关闭侧栏里的插件市场显示",
2080
+ title: "每次开机强制显示还关不掉很烦吧",
2081
+ onChange: (v) => toggleMarketSidebar(v),
2082
+ }),
2083
+ h("div", { style: hint }, "只关市场自己的,不动整合包:改的是它存在 .dsh-market/state.json 里的 sidebarEntry,不动它的安装,也不动整合包的入口。"),
2084
+ marketSidebarMsg ? h("div", { style: hint }, marketSidebarMsg) : null,
1775
2085
  saved ? h("span", { style: hint }, saved) : null),
1776
2086
  h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
1777
2087
  h("div", { style: strong }, "插件目录(分类 · 搜索 · 分页)"),
@@ -1801,6 +2111,35 @@ window.__ModuleLoader__.load({
1801
2111
  const embedded = surface === "plugins"
1802
2112
  const [packResult, setPackResult] = useState(() => readPackValue())
1803
2113
  const [focus, setFocus] = useState(0)
2114
+ const [unlag, setUnlag] = useState(null)
2115
+ const [unlagMsg, setUnlagMsg] = useState("")
2116
+ // 解除卡顿是别人家的插件:有就出按钮,没有就什么都不显示。
2117
+ useEffect(() => {
2118
+ let alive = true
2119
+ detectUnlag().then((data) => { if (alive) setUnlag(data) })
2120
+ return () => { alive = false }
2121
+ }, [])
2122
+ const pressUnlagNow = async () => {
2123
+ setUnlagMsg("正在让解除卡顿整理…")
2124
+ try {
2125
+ const data = await pressUnlag()
2126
+ const status = data && (data.status || data.verdict)
2127
+ setUnlagMsg(status ? ("解除卡顿:" + status) : "已请求,稍等一下看结果")
2128
+ } catch (e) {
2129
+ setUnlagMsg((e && e.message) || String(e))
2130
+ }
2131
+ }
2132
+ // 开机把市场的侧栏入口按设置再关一次:市场自己每次启动都会把它打开。
2133
+ const forceHideMarket = !!(status && status.config && status.config.forceHideMarketSidebar === true)
2134
+ useEffect(() => {
2135
+ if (!forceHideMarket) return
2136
+ let alive = true
2137
+ readMarketSidebar().then((data) => {
2138
+ if (!alive || !data || data.enabled !== true) return
2139
+ writeMarketSidebar(false).catch(() => {})
2140
+ })
2141
+ return () => { alive = false }
2142
+ }, [forceHideMarket])
1804
2143
  useEffect(() => subscribePack((value) => { setPackResult(value) }), [])
1805
2144
  const savePackResult = (value) => {
1806
2145
  setPackValue(value)
@@ -1814,6 +2153,42 @@ window.__ModuleLoader__.load({
1814
2153
  setTab("pack")
1815
2154
  setFocus((n) => n + 1)
1816
2155
  }
2156
+ const [refreshing, setRefreshing] = useState(false)
2157
+ const [refreshedAt, setRefreshedAt] = useState(0)
2158
+ const [refreshMsg, setRefreshMsg] = useState("")
2159
+ const [refreshNote, setRefreshNote] = useState("")
2160
+ // 刷新只管整合包自己:重读本插件看到的状态,再把三个面板重挂一次让它们各自重新取数。
2161
+ // 不碰别的插件,也不调「解除卡顿」——那个插件有自己的按钮,各管各的。
2162
+ const doRefresh = async () => {
2163
+ if (refreshing) return
2164
+ setRefreshing(true)
2165
+ setRefreshMsg("")
2166
+ setRefreshNote("")
2167
+ try {
2168
+ if (typeof props.onRefresh === "function") await props.onRefresh()
2169
+ setRefreshNote("已重新读取整合包自己的状态")
2170
+ setRefreshedAt(Date.now())
2171
+ } catch (e) {
2172
+ setRefreshMsg("刷新失败:" + String((e && e.message) || e))
2173
+ } finally {
2174
+ setRefreshing(false)
2175
+ }
2176
+ }
2177
+ const gen = props.gen || 0
2178
+ const refreshBtn = h("button", {
2179
+ type: "button",
2180
+ style: chipBtn,
2181
+ disabled: refreshing,
2182
+ title: "只刷新整合包自己:重新读一遍插件列表、市场目录与进度窗,再把三个面板重挂一次;不调用别的插件",
2183
+ onClick: doRefresh,
2184
+ }, refreshing ? "刷新中…" : (refreshMsg ? "刷新失败" : refreshedAt ? "刷新 ✓" : "刷新"))
2185
+ // 拖到角上挡住界面时用这个:位置清掉、回到右下角默认位,并且强制显示
2186
+ const recallBtn = h("button", {
2187
+ type: "button",
2188
+ style: { ...chipBtn, background: "#4C7DF0", borderColor: "#4C7DF0", color: "#fff", fontWeight: 600 },
2189
+ title: "把进度窗叫回右下角的默认位置(拖到角落挡住了界面就用这个)",
2190
+ onClick: () => { requestDockReset() },
2191
+ }, "召回进度窗")
1817
2192
  const tabs = [
1818
2193
  ["pack", "打包"],
1819
2194
  ["install", "安装 / 导入"],
@@ -1833,11 +2208,26 @@ window.__ModuleLoader__.load({
1833
2208
  }, text)
1834
2209
 
1835
2210
  const panels = [
1836
- tab === "pack" ? h(PackPanel, { status, jobs, result: packResult, setResult: savePackResult, focus }) : null,
1837
- tab === "install" ? h(InstallPanel, { status }) : null,
1838
- tab === "settings" ? h(SettingsPanel, { status }) : null,
2211
+ tab === "pack" ? h(PackPanel, { key: "pack-" + gen, status, jobs, result: packResult, setResult: savePackResult, focus }) : null,
2212
+ tab === "install" ? h(InstallPanel, { key: "install-" + gen, status }) : null,
2213
+ tab === "settings" ? h(SettingsPanel, { key: "settings-" + gen, status }) : null,
1839
2214
  ]
1840
2215
  const footNote = h("div", { style: hint }, "说明:整合包只打包你选择的插件与必要配置。打包与安装安全检测在内存中进行,命中原文不落盘;请遵守插件作者许可证与你所在地区的法律法规。")
2216
+ const unlagNode = unlag
2217
+ ? h("div", { style: row },
2218
+ h("button", {
2219
+ type: "button",
2220
+ style: chipBtn,
2221
+ title: "来自插件市场的 dsh-unlag@" + (unlag.version || "?") + "(不是本插件的功能:装了才有)",
2222
+ onClick: pressUnlagNow,
2223
+ }, "解除卡顿"),
2224
+ unlagMsg ? h("span", { style: hint }, unlagMsg) : null)
2225
+ : null
2226
+ useEffect(() => {
2227
+ if (!refreshedAt) return undefined
2228
+ const timer = setTimeout(() => { setRefreshedAt(0); setRefreshNote("") }, 2400)
2229
+ return () => clearTimeout(timer)
2230
+ }, [refreshedAt])
1841
2231
  const envLine = h("span", { style: { ...hint, marginLeft: "auto" } },
1842
2232
  status ? ("DSH " + (status.dshVersion || "?") + " · 已装 " + ((status.installed || []).length) + " 个 · v" + (status.pluginVersion || "?")) : "读取环境…")
1843
2233
 
@@ -1854,7 +2244,9 @@ window.__ModuleLoader__.load({
1854
2244
  },
1855
2245
  },
1856
2246
  h("div", { style: { maxWidth: "1020px", margin: "0 auto", width: "100%", display: "flex", flexDirection: "column", gap: "10px" } },
1857
- h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)), envLine),
2247
+ h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)), envLine, refreshNote ? h("span", { style: hint }, refreshNote) : null, refreshMsg ? h("span", { style: { ...hint, color: "#ff6b6b" } }, refreshMsg) : null, recallBtn, refreshBtn),
2248
+ unlagNode,
2249
+ unlagNode,
1858
2250
  panels,
1859
2251
  footNote,
1860
2252
  h(RepoFooter, null)),
@@ -1868,8 +2260,8 @@ window.__ModuleLoader__.load({
1868
2260
  h("div", { style: { maxWidth: "1020px", margin: "0 auto", display: "flex", flexDirection: "column", gap: "14px" } },
1869
2261
  h("div", { style: { display: "flex", alignItems: "baseline", gap: "10px", flexWrap: "wrap" } },
1870
2262
  h("h2", { style: { margin: 0, fontSize: "20px", fontWeight: 600 } }, "整合包"),
1871
- h("span", { style: hint }, "把多个插件打成一个 .dshpack:完整版自带本体,轻量版联网取包")),
1872
- h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)), envLine),
2263
+ h("span", { style: hint }, ((status && status.config && status.config.tagline) || "谁说 dsh 不能整整合包呢?(你说这几个插件整一块不牛逼坏了)"))),
2264
+ h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)), envLine, refreshNote ? h("span", { style: hint }, refreshNote) : null, refreshMsg ? h("span", { style: { ...hint, color: "#ff6b6b" } }, refreshMsg) : null, recallBtn, refreshBtn),
1873
2265
  panels,
1874
2266
  footNote,
1875
2267
  h(RepoFooter, null)),
@@ -1889,6 +2281,7 @@ window.__ModuleLoader__.load({
1889
2281
  const [status, setStatus] = useState(null)
1890
2282
  const [error, setError] = useState("")
1891
2283
  const [tries, setTries] = useState(0)
2284
+ const [gen, setGen] = useState(0)
1892
2285
  const alive = useRef(true)
1893
2286
  useEffect(() => () => { alive.current = false }, [])
1894
2287
  // 宿主刚起来、会话还在建的时候,第一次可能拿不到状态(401/网络没就绪)。
@@ -1925,7 +2318,18 @@ window.__ModuleLoader__.load({
1925
2318
  return h("div", { style: { padding: "20px 24px", color: "var(--dsw-alias-label-tertiary, #8b909b)", fontSize: "13px" } },
1926
2319
  tries > 0 ? "整合包:还在连 DSH 本体…(自动重试 " + tries + " 次)" : "整合包:读取环境…")
1927
2320
  }
1928
- return h(Home, { status, surface: (props && props.surface) || "sidebar" })
2321
+ // 手动刷新:先重读 status,再把下面几个面板整体重挂一次(gen+1)。
2322
+ // 只重读 status 是不够的:面板里的插件清单、市场信息、目录分页都是挂载时拉一次,
2323
+ // 不重挂就不会重新取,看起来就像「按了没反应」。
2324
+ return h(Home, {
2325
+ status,
2326
+ surface: (props && props.surface) || "sidebar",
2327
+ gen,
2328
+ onRefresh: async () => {
2329
+ await load(3)
2330
+ setGen((n) => n + 1)
2331
+ },
2332
+ })
1929
2333
  }
1930
2334
 
1931
2335
  const inject = ["slots"]
@@ -1984,6 +2388,7 @@ window.__ModuleLoader__.load({
1984
2388
  try {
1985
2389
  const data = await api("/status")
1986
2390
  if (data && data.ok && data.placements) setPlacement(data.placements)
2391
+ if (data && data.config && data.config.forceHideMarketSidebar === true) enforceMarketSidebarOff()
1987
2392
  } catch (e) {
1988
2393
  if (left > 0) setTimeout(() => { refreshPlacement(left - 1) }, 700 * (3 - left))
1989
2394
  }