dsh-update-status 0.1.0

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/lib/client.js ADDED
@@ -0,0 +1,1416 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-update-status",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ module.exports;
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ //#region src/shared/channels.ts
8
+ const CHANNEL_ORDER = {
9
+ latest: 0,
10
+ next: 1,
11
+ alpha: 2
12
+ };
13
+ /**
14
+ * Reduce raw dist-tags to user-meaningful choices without losing Host facts.
15
+ * The selected channel and stable return path are mandatory; other rows must
16
+ * represent a version that differs from both the running DSH and earlier rows.
17
+ */
18
+ function visibleChannelReleases(status) {
19
+ const ordered = [...status.channels].sort((left, right) => CHANNEL_ORDER[left.channel] - CHANNEL_ORDER[right.channel]);
20
+ const mandatory = /* @__PURE__ */ new Set(["latest", status.channel]);
21
+ const visible = ordered.filter((release) => mandatory.has(release.channel));
22
+ const seenVersions = new Set(visible.map((release) => release.version).filter((version) => version !== null));
23
+ for (const release of ordered) {
24
+ if (mandatory.has(release.channel) || release.version === null || release.version === status.currentVersion) continue;
25
+ if (seenVersions.has(release.version)) continue;
26
+ visible.push(release);
27
+ seenVersions.add(release.version);
28
+ }
29
+ return visible.sort((left, right) => CHANNEL_ORDER[left.channel] - CHANNEL_ORDER[right.channel]);
30
+ }
31
+ //#endregion
32
+ //#region src/shared/types.ts
33
+ /**
34
+ * JSON-only contract shared by the Host and Web halves.
35
+ *
36
+ * The static package uses the authenticated Connection RPC channel because
37
+ * `harness.handle` / `host.call` are dynamic-Cordis-only closure APIs in DSH
38
+ * 0.1.2-rc.1. The endpoint vocabulary remains deliberately small and private
39
+ * to this plugin channel.
40
+ */
41
+ const PLUGIN_ID$1 = "dsh-update-status";
42
+ const PACKAGE_NAME = "@deepseek-ai/dsh";
43
+ const UPDATE_STATUS_CHANNEL = "/dsh-update-status";
44
+ /** Exact DSH release this Phase-1 bundle declares compatible in package.json. */
45
+ const STATIC_COMPATIBLE_VERSION = "0.1.2-rc.1";
46
+ const RELEASE_CHANNELS = [
47
+ "latest",
48
+ "next",
49
+ "alpha"
50
+ ];
51
+ const MAX_CACHE_TTL_MINUTES = 1440;
52
+ function isCacheTtlMinutes(value) {
53
+ return typeof value === "number" && Number.isInteger(value) && value >= 30 && value <= 1440;
54
+ }
55
+ const UPDATE_ENDPOINTS = {
56
+ getStatus: "get-status",
57
+ checkUpdate: "check-update"
58
+ };
59
+ function isReleaseChannel(value) {
60
+ return value === "latest" || value === "next" || value === "alpha";
61
+ }
62
+ //#endregion
63
+ //#region src/shared/semver.ts
64
+ const SEMVER = /^(?:v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
65
+ function parseSemver(value) {
66
+ const match = SEMVER.exec(value.trim());
67
+ if (match === null) return void 0;
68
+ const major = Number(match[1]);
69
+ const minor = Number(match[2]);
70
+ const patch = Number(match[3]);
71
+ if (!Number.isSafeInteger(major) || !Number.isSafeInteger(minor) || !Number.isSafeInteger(patch)) return void 0;
72
+ return {
73
+ major,
74
+ minor,
75
+ patch,
76
+ prerelease: match[4] === void 0 ? [] : match[4].split(".")
77
+ };
78
+ }
79
+ //#endregion
80
+ //#region src/shared/preview-guidance.ts
81
+ /** Pinned guidance only: never execute a command or mutate the followed channel. */
82
+ function previewCommand(status, version) {
83
+ if (version === null || version.trim() !== version || parseSemver(version) === void 0) return null;
84
+ if (status.installKind === "npm-global") return `npm install -g ${PACKAGE_NAME}@${version}`;
85
+ if (status.installKind === "pnpm-global") return `pnpm add -g ${PACKAGE_NAME}@${version}`;
86
+ return null;
87
+ }
88
+ //#endregion
89
+ //#region src/client/i18n.ts
90
+ const DICTIONARY = {
91
+ "brand.status": {
92
+ zh: "DSH 版本状态",
93
+ en: "DSH version status"
94
+ },
95
+ "brand.checking": {
96
+ zh: "正在检查版本",
97
+ en: "Checking version"
98
+ },
99
+ "brand.update": {
100
+ zh: "有可用更新",
101
+ en: "Update available"
102
+ },
103
+ "brand.current": {
104
+ zh: "已是最新或尚未发现更新",
105
+ en: "Up to date or no update found"
106
+ },
107
+ "brand.problem": {
108
+ zh: "检查遇到问题",
109
+ en: "Check encountered a problem"
110
+ },
111
+ "footer.status": {
112
+ zh: "打开 DSH 版本状态",
113
+ en: "Open DSH version status"
114
+ },
115
+ "panel.title": {
116
+ zh: "DSH 更新状态",
117
+ en: "DSH update status"
118
+ },
119
+ "panel.close": {
120
+ zh: "关闭",
121
+ en: "Close"
122
+ },
123
+ "panel.cacheDuration": {
124
+ zh: "缓存时长",
125
+ en: "Cache duration"
126
+ },
127
+ "panel.minutes": {
128
+ zh: "分钟",
129
+ en: "minutes"
130
+ },
131
+ "panel.cacheHint": {
132
+ zh: "到期后在下次打开或读取状态时检查;不会后台轮询。点击“检查更新”会立即检查。",
133
+ en: "After expiry, DSH checks only on the next status read; there is no background polling. “Check for updates” checks immediately."
134
+ },
135
+ "panel.cacheReadonly": {
136
+ zh: "此连接的缓存设置为只读。",
137
+ en: "This connection’s cache setting is read-only."
138
+ },
139
+ "panel.current": {
140
+ zh: "当前运行版本",
141
+ en: "Current running version"
142
+ },
143
+ "panel.latest": {
144
+ zh: "所选通道版本",
145
+ en: "Selected channel version"
146
+ },
147
+ "panel.channels": {
148
+ zh: "可用发布通道",
149
+ en: "Available release channels"
150
+ },
151
+ "panel.compatVerified": {
152
+ zh: "已验证兼容",
153
+ en: "Verified compatible"
154
+ },
155
+ "panel.compatUnverified": {
156
+ zh: "尚未验证兼容",
157
+ en: "Compatibility unverified"
158
+ },
159
+ "panel.compatIncompatible": {
160
+ zh: "已知不兼容",
161
+ en: "Known incompatible"
162
+ },
163
+ "panel.selectChannel": {
164
+ zh: "选择此通道",
165
+ en: "Select channel"
166
+ },
167
+ "panel.selectedChannel": {
168
+ zh: "已选择",
169
+ en: "Selected"
170
+ },
171
+ "panel.notChecked": {
172
+ zh: "尚未取得",
173
+ en: "Not available yet"
174
+ },
175
+ "panel.available": {
176
+ zh: "发现新版本",
177
+ en: "Update available"
178
+ },
179
+ "panel.currentState": {
180
+ zh: "未发现可用更新",
181
+ en: "No update found"
182
+ },
183
+ "panel.cached": {
184
+ zh: "来自 Host 缓存",
185
+ en: "From Host cache"
186
+ },
187
+ "panel.live": {
188
+ zh: "刚从 npm registry 检查",
189
+ en: "Checked npm registry now"
190
+ },
191
+ "panel.checkedAt": {
192
+ zh: "上次检查",
193
+ en: "Last checked"
194
+ },
195
+ "panel.publishedAt": {
196
+ zh: "发布时间",
197
+ en: "Published"
198
+ },
199
+ "panel.check": {
200
+ zh: "检查更新",
201
+ en: "Check for updates"
202
+ },
203
+ "panel.checking": {
204
+ zh: "检查中…",
205
+ en: "Checking…"
206
+ },
207
+ "panel.switchingChannel": {
208
+ zh: "正在切换通道…",
209
+ en: "Switching channel…"
210
+ },
211
+ "panel.releaseNotes": {
212
+ zh: "发布说明",
213
+ en: "Release notes"
214
+ },
215
+ "panel.command": {
216
+ zh: "升级命令",
217
+ en: "Upgrade command"
218
+ },
219
+ "panel.copy": {
220
+ zh: "复制命令",
221
+ en: "Copy command"
222
+ },
223
+ "panel.copied": {
224
+ zh: "已复制",
225
+ en: "Copied"
226
+ },
227
+ "panel.copyFallback": {
228
+ zh: "浏览器未允许复制;已选中文本,请长按或复制。",
229
+ en: "Clipboard unavailable; the command is selected for long-press or copy."
230
+ },
231
+ "panel.commandNote": {
232
+ zh: "仅复制,不会执行。请在运行 DSH 的那台电脑的终端执行;完成后由你自行重启 DSH。",
233
+ en: "Copy only — nothing runs here. Execute it in a terminal on the computer running DSH, then restart DSH yourself."
234
+ },
235
+ "panel.readOnly": {
236
+ zh: "阶段 1 仅提示:本插件不会安装、重启、回滚或替换任何文件。",
237
+ en: "Phase 1 is advisory only: this plugin never installs, restarts, rolls back, or replaces files."
238
+ },
239
+ "panel.error": {
240
+ zh: "检查提示",
241
+ en: "Check notice"
242
+ },
243
+ "panel.static": {
244
+ zh: "此连接只显示静态版本;请在运行 DSH 的本机打开侧栏查看完整更新信息。",
245
+ en: "This connection shows only the static version. Open the sidebar on the computer running DSH for full update details."
246
+ },
247
+ "preview.open": {
248
+ zh: "查看预览版升级方式",
249
+ en: "View preview upgrade instructions"
250
+ },
251
+ "preview.close": {
252
+ zh: "收起升级说明",
253
+ en: "Hide upgrade instructions"
254
+ },
255
+ "preview.follow": {
256
+ zh: "关注通道只影响检查结果,不代表已安装或已切换版本。",
257
+ en: "Following a channel only changes update checks, not the installed version."
258
+ },
259
+ "preview.target": {
260
+ zh: "目标版本",
261
+ en: "Target version"
262
+ },
263
+ "preview.risk": {
264
+ zh: "预览版本可能不稳定,插件兼容性尚需确认。执行前请保存工作、备份配置并结束运行中的任务;安装后需手动重启 DSH。此页面不会安装或重启。",
265
+ en: "Preview builds may be unstable and plugin compatibility needs checking. Save work, back up configuration and finish active tasks before executing. Restart DSH manually afterwards. This page never installs or restarts."
266
+ },
267
+ "preview.unavailable": {
268
+ zh: "暂无可确认的预览目标,请先检查更新。",
269
+ en: "No confirmed preview target. Check for updates first."
270
+ },
271
+ "preview.manual": {
272
+ zh: "当前安装方式无法安全生成命令,请先确认安装来源;源码安装需按其构建说明操作。",
273
+ en: "Cannot safely generate a command for this installation. Confirm its source; source checkouts require their build instructions."
274
+ },
275
+ "preview.same": {
276
+ zh: "此目标与当前运行版本相同,无需重复安装。",
277
+ en: "This target is already running; no reinstall is needed."
278
+ },
279
+ "settings.title": {
280
+ zh: "版本与更新",
281
+ en: "Version & updates"
282
+ },
283
+ "settings.sidebar": {
284
+ zh: "在侧栏显示版本状态入口",
285
+ en: "Show the version-status entry in the sidebar"
286
+ },
287
+ "settings.sidebarHint": {
288
+ zh: "关闭后不再渲染品牌 Badge 和收起轨道兜底入口。不会执行或安排升级。",
289
+ en: "When off, the brand badge and collapsed-rail fallback are not rendered. No update is run or scheduled."
290
+ },
291
+ "settings.channel": {
292
+ zh: "关注发布通道",
293
+ en: "Release channel to follow"
294
+ },
295
+ "settings.channelLatest": {
296
+ zh: "稳定版(latest,推荐)",
297
+ en: "Stable (latest, recommended)"
298
+ },
299
+ "settings.channelNext": {
300
+ zh: "候选版(next)",
301
+ en: "Release candidate (next)"
302
+ },
303
+ "settings.channelAlpha": {
304
+ zh: "预览版(alpha)",
305
+ en: "Preview (alpha)"
306
+ },
307
+ "settings.channelHint": {
308
+ zh: "预览通道可能包含未稳定接口或插件兼容性变化。这里只检查并生成命令,不会安装。",
309
+ en: "Preview channels may contain unstable APIs or plugin compatibility changes. This only checks and generates a command; it never installs."
310
+ },
311
+ "settings.readonly": {
312
+ zh: "此连接的设置为只读;显示状态不受影响。",
313
+ en: "Settings are read-only on this connection; status display is unchanged."
314
+ }
315
+ };
316
+ function languageOf() {
317
+ try {
318
+ return navigator.language.toLowerCase().startsWith("zh") ? "zh" : "en";
319
+ } catch {
320
+ return "en";
321
+ }
322
+ }
323
+ function t(key) {
324
+ const entry = DICTIONARY[key];
325
+ if (entry === void 0) return key;
326
+ return entry[languageOf()] ?? entry.en;
327
+ }
328
+ //#endregion
329
+ //#region src/client/react.ts
330
+ const React = require("react");
331
+ React.createElement;
332
+ //#endregion
333
+ //#region src/client/components.tsx
334
+ function useObservable(store) {
335
+ return React.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
336
+ }
337
+ function timeText(value) {
338
+ if (value === null) return null;
339
+ try {
340
+ return new Intl.DateTimeFormat(void 0, {
341
+ dateStyle: "medium",
342
+ timeStyle: "short"
343
+ }).format(new Date(value));
344
+ } catch {
345
+ return value;
346
+ }
347
+ }
348
+ function shortVersion(value) {
349
+ if (value.length <= 16) return value;
350
+ return value.slice(0, 15) + "…";
351
+ }
352
+ function channelLabel(channel) {
353
+ if (channel === "latest") return t("settings.channelLatest");
354
+ if (channel === "next") return t("settings.channelNext");
355
+ return t("settings.channelAlpha");
356
+ }
357
+ function compatibilityLabel(value) {
358
+ if (value === "verified") return t("panel.compatVerified");
359
+ if (value === "incompatible") return t("panel.compatIncompatible");
360
+ return t("panel.compatUnverified");
361
+ }
362
+ /** Persists a cache policy only; it never schedules a browser or Host timer. */
363
+ function CacheTtlControl({ preferences }) {
364
+ const snapshot = useObservable(preferences);
365
+ const [draft, setDraft] = React.useState(String(snapshot.cacheTtlMinutes));
366
+ React.useEffect(() => {
367
+ setDraft(String(snapshot.cacheTtlMinutes));
368
+ }, [snapshot.cacheTtlMinutes]);
369
+ const save = () => {
370
+ const value = Number(draft);
371
+ if (isCacheTtlMinutes(value)) preferences.setCacheTtlMinutes(value);
372
+ else setDraft(String(snapshot.cacheTtlMinutes));
373
+ };
374
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
375
+ className: "dus-cache-setting",
376
+ children: [
377
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
378
+ className: "dus-cache-field",
379
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("panel.cacheDuration") }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
380
+ className: "dus-cache-input-wrap",
381
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
382
+ className: "dus-cache-input",
383
+ type: "number",
384
+ inputMode: "numeric",
385
+ min: 30,
386
+ max: MAX_CACHE_TTL_MINUTES,
387
+ step: 1,
388
+ value: draft,
389
+ disabled: !snapshot.writable,
390
+ "aria-describedby": "dus-cache-hint",
391
+ onChange: (event) => {
392
+ setDraft(event.currentTarget.value);
393
+ },
394
+ onBlur: save,
395
+ onKeyDown: (event) => {
396
+ if (event.key === "Enter") event.currentTarget.blur();
397
+ if (event.key === "Escape") {
398
+ setDraft(String(snapshot.cacheTtlMinutes));
399
+ event.currentTarget.blur();
400
+ }
401
+ }
402
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("panel.minutes") })]
403
+ })]
404
+ }),
405
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
406
+ className: "dus-cache-hint",
407
+ id: "dus-cache-hint",
408
+ children: t("panel.cacheHint")
409
+ }),
410
+ !snapshot.writable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
411
+ className: "dus-cache-hint",
412
+ children: t("panel.cacheReadonly")
413
+ })
414
+ ]
415
+ });
416
+ }
417
+ function visualState(status, loading, error) {
418
+ if (loading) return "loading";
419
+ if (error !== null || status?.warning !== null) return status?.hasUpdate === true ? "update" : "problem";
420
+ return status?.hasUpdate === true ? "update" : "current";
421
+ }
422
+ function badgeLabel(status, loading, error) {
423
+ const state = visualState(status, loading, error);
424
+ if (state === "loading") return t("brand.checking");
425
+ if (state === "update") return t("brand.update");
426
+ if (state === "problem") return t("brand.problem");
427
+ return t("brand.current");
428
+ }
429
+ /** Occupies ONLY sidebar.brand.name; the official fish mark stays untouched. */
430
+ function BrandName({ ui }) {
431
+ const preferences = useObservable(ui.preferences);
432
+ const snapshot = useObservable(ui.status);
433
+ if (!preferences.sidebarEnabled) return null;
434
+ const state = visualState(snapshot.status, snapshot.loading, snapshot.error);
435
+ const version = snapshot.status?.currentVersion ?? "…";
436
+ const activate = (event) => {
437
+ event.preventDefault();
438
+ event.stopPropagation();
439
+ const target = event.currentTarget;
440
+ if (target instanceof HTMLElement) target.blur();
441
+ if (ui.canManage) ui.panel.toggle("brand");
442
+ };
443
+ const onKeyDown = (event) => {
444
+ if (event.key !== "Enter" && event.key !== " ") return;
445
+ activate(event);
446
+ };
447
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
448
+ className: "dus-brand-name",
449
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
450
+ className: "dus-brand-deepseek",
451
+ children: "DeepSeek"
452
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
453
+ className: "dus-badge",
454
+ "data-update": snapshot.status?.hasUpdate === true || void 0,
455
+ "data-error": state === "problem" || void 0,
456
+ role: ui.canManage ? "button" : void 0,
457
+ tabIndex: ui.canManage ? 0 : void 0,
458
+ "aria-label": badgeLabel(snapshot.status, snapshot.loading, snapshot.error),
459
+ "aria-disabled": ui.canManage ? void 0 : true,
460
+ title: badgeLabel(snapshot.status, snapshot.loading, snapshot.error),
461
+ onClick: ui.canManage ? activate : void 0,
462
+ onKeyDown: ui.canManage ? onKeyDown : void 0,
463
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
464
+ className: "dus-badge-version",
465
+ children: shortVersion(version)
466
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
467
+ className: "dus-dot",
468
+ "data-update": snapshot.status?.hasUpdate === true || void 0,
469
+ "data-loading": snapshot.loading || void 0,
470
+ "aria-hidden": "true"
471
+ })]
472
+ })]
473
+ });
474
+ }
475
+ /** List-slot fallback: it deliberately disappears while the name badge is wide. */
476
+ function FooterAction({ wide, ui }) {
477
+ const preferences = useObservable(ui.preferences);
478
+ const snapshot = useObservable(ui.status);
479
+ if (wide === true || !preferences.sidebarEnabled) return null;
480
+ const state = visualState(snapshot.status, snapshot.loading, snapshot.error);
481
+ const label = badgeLabel(snapshot.status, snapshot.loading, snapshot.error);
482
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
483
+ className: "dus-footer-button",
484
+ type: "button",
485
+ "aria-label": t("footer.status"),
486
+ title: label,
487
+ disabled: !ui.canManage,
488
+ onClick: () => {
489
+ ui.panel.toggle("rail");
490
+ },
491
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
492
+ className: "dus-footer-icon",
493
+ "aria-hidden": "true",
494
+ children: "↟"
495
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
496
+ className: "dus-dot dus-footer-dot",
497
+ "data-update": snapshot.status?.hasUpdate === true || void 0,
498
+ "data-loading": state === "loading" || void 0
499
+ })]
500
+ });
501
+ }
502
+ function statusSummary(status, loading, error) {
503
+ if (loading && status === null) return {
504
+ kind: "warning",
505
+ text: t("brand.checking")
506
+ };
507
+ if (error !== null) return {
508
+ kind: "error",
509
+ text: error
510
+ };
511
+ if (status?.hasUpdate === true) return {
512
+ kind: "update",
513
+ text: t("panel.available")
514
+ };
515
+ if (status?.warning !== null && status?.warning !== void 0) return {
516
+ kind: "warning",
517
+ text: status.warning
518
+ };
519
+ return {
520
+ kind: "ok",
521
+ text: t("panel.currentState")
522
+ };
523
+ }
524
+ function selectCommand(element) {
525
+ if (element === null) return;
526
+ try {
527
+ const selection = window.getSelection();
528
+ if (selection === null) return;
529
+ const range = document.createRange();
530
+ range.selectNodeContents(element);
531
+ selection.removeAllRanges();
532
+ selection.addRange(range);
533
+ element.focus();
534
+ } catch {}
535
+ }
536
+ /** Full detail is only opened from a loopback/local DSH UI surface. */
537
+ function UpdatePanel({ ui }) {
538
+ const panel = useObservable(ui.panel);
539
+ const preferences = useObservable(ui.preferences);
540
+ const snapshot = useObservable(ui.status);
541
+ const commandRef = React.useRef(null);
542
+ const dialogRef = React.useRef(null);
543
+ const [copyMessage, setCopyMessage] = React.useState(null);
544
+ const visible = panel.open && preferences.sidebarEnabled && ui.canManage;
545
+ React.useLayoutEffect(() => {
546
+ if (!visible) return void 0;
547
+ const dialog = dialogRef.current;
548
+ if (dialog === null) return void 0;
549
+ try {
550
+ if (!dialog.open) dialog.showModal();
551
+ } catch {
552
+ dialog.setAttribute("open", "");
553
+ }
554
+ return () => {
555
+ if (dialog.open) dialog.close();
556
+ };
557
+ }, [visible]);
558
+ React.useEffect(() => {
559
+ if (!panel.open) return void 0;
560
+ const onKeyDown = (event) => {
561
+ if (event.key === "Escape") ui.panel.close();
562
+ };
563
+ window.addEventListener("keydown", onKeyDown);
564
+ return () => {
565
+ window.removeEventListener("keydown", onKeyDown);
566
+ };
567
+ }, [panel.open, ui.panel]);
568
+ if (!visible) return null;
569
+ const status = snapshot.status;
570
+ const summary = statusSummary(status, snapshot.loading, snapshot.error);
571
+ const switchingChannel = status !== null && status.channel !== preferences.channel;
572
+ const command = switchingChannel ? t("panel.switchingChannel") : status?.upgradeCommand ?? "—";
573
+ const copy = async () => {
574
+ setCopyMessage(null);
575
+ try {
576
+ if (!navigator.clipboard?.writeText) throw new Error("Clipboard API unavailable");
577
+ await navigator.clipboard.writeText(command);
578
+ setCopyMessage(t("panel.copied"));
579
+ } catch {
580
+ selectCommand(commandRef.current);
581
+ setCopyMessage(t("panel.copyFallback"));
582
+ }
583
+ };
584
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("dialog", {
585
+ ref: dialogRef,
586
+ className: "dus-overlay-root",
587
+ "aria-label": t("panel.title"),
588
+ onCancel: (event) => {
589
+ event.preventDefault();
590
+ ui.panel.close();
591
+ },
592
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
593
+ className: "dus-backdrop",
594
+ onClick: () => {
595
+ ui.panel.close();
596
+ }
597
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
598
+ className: "dus-panel",
599
+ "data-origin": panel.origin,
600
+ role: "dialog",
601
+ "aria-modal": "true",
602
+ "aria-label": t("panel.title"),
603
+ onClick: (event) => {
604
+ event.stopPropagation();
605
+ },
606
+ children: [
607
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
608
+ className: "dus-panel-head",
609
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
610
+ className: "dus-panel-title",
611
+ children: t("panel.title")
612
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
613
+ className: "dus-close",
614
+ type: "button",
615
+ "aria-label": t("panel.close"),
616
+ onClick: () => {
617
+ ui.panel.close();
618
+ },
619
+ children: "×"
620
+ })]
621
+ }),
622
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CacheTtlControl, { preferences: ui.preferences }),
623
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
624
+ className: "dus-state",
625
+ "data-kind": summary.kind,
626
+ children: summary.text
627
+ }),
628
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
629
+ className: "dus-metadata",
630
+ children: [
631
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
632
+ className: "dus-metadata-row",
633
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
634
+ className: "dus-meta-label",
635
+ children: t("panel.current")
636
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
637
+ className: "dus-meta-value",
638
+ children: status?.currentVersion ?? "…"
639
+ })]
640
+ }),
641
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
642
+ className: "dus-metadata-row",
643
+ children: [
644
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
645
+ className: "dus-meta-label",
646
+ children: [
647
+ t("panel.latest"),
648
+ " · ",
649
+ status === null ? "latest" : channelLabel(status.channel)
650
+ ]
651
+ }),
652
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
653
+ className: "dus-meta-value",
654
+ children: status?.latestVersion ?? t("panel.notChecked")
655
+ }),
656
+ status?.publishedAt !== null && status?.publishedAt !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
657
+ className: "dus-meta-sub",
658
+ children: [
659
+ t("panel.publishedAt"),
660
+ ": ",
661
+ timeText(status.publishedAt)
662
+ ]
663
+ })
664
+ ]
665
+ }),
666
+ status?.checkedAt !== null && status?.checkedAt !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
667
+ className: "dus-metadata-row",
668
+ children: [
669
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
670
+ className: "dus-meta-label",
671
+ children: t("panel.checkedAt")
672
+ }),
673
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
674
+ className: "dus-meta-value",
675
+ children: timeText(status.checkedAt)
676
+ }),
677
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
678
+ className: "dus-meta-sub",
679
+ children: status.cached ? t("panel.cached") : t("panel.live")
680
+ })
681
+ ]
682
+ })
683
+ ]
684
+ }),
685
+ status !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
686
+ className: "dus-channel-list",
687
+ "aria-label": t("panel.channels"),
688
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
689
+ className: "dus-command-label",
690
+ children: t("panel.channels")
691
+ }), visibleChannelReleases(status).map((release) => {
692
+ const selected = release.channel === preferences.channel;
693
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
694
+ className: "dus-channel-row",
695
+ "data-selected": selected || void 0,
696
+ children: [
697
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: channelLabel(release.channel) }),
698
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: release.version ?? "—" }),
699
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
700
+ className: "dus-channel-compat",
701
+ "data-compatibility": release.compatibility,
702
+ children: compatibilityLabel(release.compatibility)
703
+ }),
704
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
705
+ className: "dus-channel-action",
706
+ type: "button",
707
+ disabled: selected || !preferences.writable || release.version === null,
708
+ "aria-label": `${selected ? t("panel.selectedChannel") : t("panel.selectChannel")}: ${channelLabel(release.channel)}`,
709
+ onClick: () => {
710
+ ui.preferences.setChannel(release.channel);
711
+ },
712
+ children: selected ? t("panel.selectedChannel") : t("panel.selectChannel")
713
+ })
714
+ ]
715
+ }, release.channel);
716
+ })]
717
+ }),
718
+ status?.warning !== null && status?.warning !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
719
+ className: "dus-warning",
720
+ children: [
721
+ t("panel.error"),
722
+ ": ",
723
+ status.warning
724
+ ]
725
+ }),
726
+ snapshot.error !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
727
+ className: "dus-warning",
728
+ children: [
729
+ t("panel.error"),
730
+ ": ",
731
+ snapshot.error
732
+ ]
733
+ }),
734
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
735
+ className: "dus-actions",
736
+ children: [
737
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
738
+ className: "dus-action",
739
+ type: "button",
740
+ disabled: snapshot.loading,
741
+ onClick: () => {
742
+ ui.status.refresh(void 0, preferences.cacheTtlMinutes);
743
+ },
744
+ children: snapshot.loading ? t("panel.checking") : t("panel.check")
745
+ }),
746
+ status !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
747
+ className: "dus-action",
748
+ href: status.changelogUrl,
749
+ target: "_blank",
750
+ rel: "noreferrer",
751
+ children: t("panel.releaseNotes")
752
+ }),
753
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
754
+ className: "dus-action",
755
+ type: "button",
756
+ disabled: switchingChannel || status === null,
757
+ onClick: () => {
758
+ copy();
759
+ },
760
+ children: t("panel.copy")
761
+ })
762
+ ]
763
+ }),
764
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
765
+ className: "dus-command-label",
766
+ children: t("panel.command")
767
+ }),
768
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
769
+ ref: commandRef,
770
+ className: "dus-command",
771
+ tabIndex: 0,
772
+ children: command
773
+ }),
774
+ copyMessage !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
775
+ className: "dus-copy-message",
776
+ role: "status",
777
+ children: copyMessage
778
+ }),
779
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
780
+ className: "dus-note",
781
+ children: t("panel.commandNote")
782
+ }),
783
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
784
+ className: "dus-note",
785
+ children: t("panel.readOnly")
786
+ })
787
+ ]
788
+ })]
789
+ });
790
+ }
791
+ /** Separate setting page: disables only this plugin's own rendering. */
792
+ function UpdateSettings({ ui }) {
793
+ const preferences = useObservable(ui.preferences);
794
+ const snapshot = useObservable(ui.status);
795
+ const [showGuidance, setShowGuidance] = React.useState(false);
796
+ const previews = snapshot.status?.channels.filter((release) => release.channel !== "latest") ?? [];
797
+ const channelOptions = snapshot.status === null ? [{ channel: preferences.channel }] : visibleChannelReleases(snapshot.status);
798
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
799
+ className: "dus-settings",
800
+ children: [
801
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
802
+ className: "dus-settings-heading",
803
+ children: t("settings.title")
804
+ }),
805
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
806
+ className: "dus-settings-card",
807
+ children: [
808
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
809
+ className: "dus-settings-toggle",
810
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
811
+ type: "checkbox",
812
+ checked: preferences.sidebarEnabled,
813
+ disabled: !preferences.writable,
814
+ onChange: (event) => {
815
+ ui.preferences.setSidebarEnabled(event.currentTarget.checked);
816
+ }
817
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("settings.sidebar") })]
818
+ }),
819
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
820
+ className: "dus-settings-hint",
821
+ children: t("settings.sidebarHint")
822
+ }),
823
+ !preferences.writable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
824
+ className: "dus-settings-hint",
825
+ children: t("settings.readonly")
826
+ })
827
+ ]
828
+ }),
829
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
830
+ className: "dus-settings-card",
831
+ children: [
832
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
833
+ className: "dus-settings-field",
834
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("settings.channel") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
835
+ className: "dus-channel-select",
836
+ value: preferences.channel,
837
+ disabled: !preferences.writable,
838
+ onChange: (event) => {
839
+ ui.preferences.setChannel(event.currentTarget.value);
840
+ },
841
+ children: channelOptions.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
842
+ value: option.channel,
843
+ children: channelLabel(option.channel)
844
+ }, option.channel))
845
+ })]
846
+ }),
847
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
848
+ className: "dus-settings-hint",
849
+ children: t("settings.channelHint")
850
+ }),
851
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
852
+ className: "dus-settings-hint",
853
+ children: [
854
+ t("panel.current"),
855
+ ": ",
856
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: snapshot.status?.currentVersion ?? "…" })
857
+ ]
858
+ }),
859
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
860
+ className: "dus-settings-hint",
861
+ children: t("preview.follow")
862
+ }),
863
+ ui.canManage && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
864
+ className: "dus-action",
865
+ type: "button",
866
+ "aria-expanded": showGuidance,
867
+ onClick: () => {
868
+ setShowGuidance(!showGuidance);
869
+ },
870
+ children: t(showGuidance ? "preview.close" : "preview.open")
871
+ }),
872
+ ui.canManage && showGuidance && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
873
+ "aria-label": t("preview.open"),
874
+ children: [
875
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
876
+ className: "dus-warning",
877
+ children: t("preview.risk")
878
+ }),
879
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
880
+ className: "dus-action",
881
+ type: "button",
882
+ disabled: snapshot.loading,
883
+ onClick: () => {
884
+ ui.status.refresh(void 0, preferences.cacheTtlMinutes);
885
+ },
886
+ children: t(snapshot.loading ? "panel.checking" : "panel.check")
887
+ }),
888
+ snapshot.error !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
889
+ role: "alert",
890
+ children: snapshot.error
891
+ }),
892
+ previews.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("preview.unavailable") }),
893
+ previews.map((release) => {
894
+ const status = snapshot.status;
895
+ const command = previewCommand(status, release.version);
896
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
897
+ className: "dus-settings-card",
898
+ children: [
899
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { children: [
900
+ channelLabel(release.channel),
901
+ " · ",
902
+ t("preview.target"),
903
+ ": ",
904
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: release.version ?? t("panel.notChecked") })
905
+ ] }),
906
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: compatibilityLabel(release.compatibility) }),
907
+ release.version === null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("preview.unavailable") }) : release.version === status.currentVersion ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("preview.same") }) : command !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("panel.command") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
908
+ className: "dus-command",
909
+ tabIndex: 0,
910
+ children: command
911
+ })] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("preview.manual") })
912
+ ]
913
+ }, release.channel);
914
+ }),
915
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
916
+ className: "dus-note",
917
+ children: t("panel.commandNote")
918
+ })
919
+ ]
920
+ })
921
+ ]
922
+ })
923
+ ]
924
+ });
925
+ }
926
+ //#endregion
927
+ //#region src/client/contract.ts
928
+ /** Minimal structural client faces — runtime services stay owned by DSH. */
929
+ function errorMessage(error) {
930
+ return (error instanceof Error ? error.message : String(error)).replace(/\s+/g, " ").trim().slice(0, 220) || "unknown error";
931
+ }
932
+ function stringOrNull(value) {
933
+ return typeof value === "string" ? value : null;
934
+ }
935
+ /** Reject malformed RPC output before it reaches a slot component. */
936
+ function updateStatusOf(value) {
937
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
938
+ const record = value;
939
+ if (typeof record.currentVersion !== "string" || typeof record.hasUpdate !== "boolean" || typeof record.cached !== "boolean" || typeof record.installKind !== "string" || typeof record.upgradeCommand !== "string" || typeof record.releaseUrl !== "string" || typeof record.changelogUrl !== "string" || typeof record.packageName !== "string" || !isReleaseChannel(record.channel) || !Array.isArray(record.channels) || record.canApplyInPlace !== false) return void 0;
940
+ if (!(record.installKind === "npm-global" || record.installKind === "pnpm-global" || record.installKind === "source-checkout" || record.installKind === "unknown")) return void 0;
941
+ const latestVersion = record.latestVersion === null ? null : stringOrNull(record.latestVersion);
942
+ const checkedAt = record.checkedAt === null ? null : stringOrNull(record.checkedAt);
943
+ const warning = record.warning === null ? null : stringOrNull(record.warning);
944
+ const publishedAt = record.publishedAt === null ? null : stringOrNull(record.publishedAt);
945
+ if (record.latestVersion !== null && latestVersion === null || record.checkedAt !== null && checkedAt === null || record.warning !== null && warning === null || record.publishedAt !== null && publishedAt === null) return void 0;
946
+ const channels = [];
947
+ for (const raw of record.channels) {
948
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
949
+ const item = raw;
950
+ const version = item.version === null ? null : stringOrNull(item.version);
951
+ const channelPublishedAt = item.publishedAt === null ? null : stringOrNull(item.publishedAt);
952
+ if (!isReleaseChannel(item.channel) || item.version !== null && version === null || item.publishedAt !== null && channelPublishedAt === null || item.compatibility !== "verified" && item.compatibility !== "unverified" && item.compatibility !== "incompatible") return void 0;
953
+ channels.push({
954
+ channel: item.channel,
955
+ version,
956
+ publishedAt: channelPublishedAt,
957
+ compatibility: item.compatibility
958
+ });
959
+ }
960
+ return {
961
+ currentVersion: record.currentVersion,
962
+ latestVersion,
963
+ hasUpdate: record.hasUpdate,
964
+ cached: record.cached,
965
+ checkedAt,
966
+ warning,
967
+ installKind: record.installKind,
968
+ upgradeCommand: record.upgradeCommand,
969
+ releaseUrl: record.releaseUrl,
970
+ changelogUrl: record.changelogUrl,
971
+ publishedAt,
972
+ packageName: record.packageName,
973
+ channel: record.channel,
974
+ channels,
975
+ canApplyInPlace: false
976
+ };
977
+ }
978
+ //#endregion
979
+ //#region src/client/stores.ts
980
+ /** Small observable stores shared by the independent sidebar and overlay slots. */
981
+ const INITIAL_STATUS = {
982
+ status: null,
983
+ loading: true,
984
+ error: null
985
+ };
986
+ var StatusStore = class {
987
+ connection;
988
+ snapshot;
989
+ allowRequests;
990
+ listeners = /* @__PURE__ */ new Set();
991
+ inFlight;
992
+ stopped = false;
993
+ constructor(connection, staticVersion = null) {
994
+ this.connection = connection;
995
+ this.allowRequests = staticVersion === null;
996
+ this.snapshot = staticVersion === null ? INITIAL_STATUS : {
997
+ status: {
998
+ currentVersion: staticVersion,
999
+ latestVersion: null,
1000
+ hasUpdate: false,
1001
+ cached: true,
1002
+ checkedAt: null,
1003
+ warning: null,
1004
+ installKind: "unknown",
1005
+ upgradeCommand: "",
1006
+ releaseUrl: "",
1007
+ changelogUrl: "",
1008
+ publishedAt: null,
1009
+ packageName: "@deepseek-ai/dsh",
1010
+ channel: "latest",
1011
+ channels: RELEASE_CHANNELS.map((channel) => ({
1012
+ channel,
1013
+ version: null,
1014
+ publishedAt: null,
1015
+ compatibility: "unverified"
1016
+ })),
1017
+ canApplyInPlace: false
1018
+ },
1019
+ loading: false,
1020
+ error: null
1021
+ };
1022
+ }
1023
+ getSnapshot = () => this.snapshot;
1024
+ subscribe = (listener) => {
1025
+ this.listeners.add(listener);
1026
+ return () => {
1027
+ this.listeners.delete(listener);
1028
+ };
1029
+ };
1030
+ /** First mount reads the Host's cached status; it never starts a browser timer. */
1031
+ async load(cacheTtlMinutes = 360) {
1032
+ if (this.allowRequests) await this.request(false, this.snapshot.status?.channel ?? "latest", cacheTtlMinutes);
1033
+ }
1034
+ /** User gesture only: force the Host to bypass TTL (while retaining single-flight). */
1035
+ async refresh(channel = this.snapshot.status?.channel ?? "latest", cacheTtlMinutes = 360) {
1036
+ if (this.allowRequests) await this.request(true, channel, cacheTtlMinutes);
1037
+ }
1038
+ /** Channel selection re-projects the Host cache; it is not a forced refresh. */
1039
+ async selectChannel(channel, cacheTtlMinutes = 360) {
1040
+ if (!this.allowRequests) return;
1041
+ for (let attempts = 0; attempts < 3 && !this.stopped && this.snapshot.status?.channel !== channel; attempts += 1) {
1042
+ const pending = this.inFlight;
1043
+ if (pending !== void 0 && !await pending) return;
1044
+ if (this.stopped || this.snapshot.status?.channel === channel) return;
1045
+ if (!await this.request(false, channel, cacheTtlMinutes)) return;
1046
+ }
1047
+ }
1048
+ stop() {
1049
+ this.stopped = true;
1050
+ this.listeners.clear();
1051
+ }
1052
+ publish(next) {
1053
+ if (this.stopped) return;
1054
+ this.snapshot = next;
1055
+ for (const listener of this.listeners) listener();
1056
+ }
1057
+ request(force, channel, cacheTtlMinutes) {
1058
+ if (this.inFlight !== void 0) return this.inFlight;
1059
+ const rpc = this.connection.rpc;
1060
+ if (rpc === void 0 || typeof rpc.call !== "function") {
1061
+ this.publish({
1062
+ ...this.snapshot,
1063
+ loading: false,
1064
+ error: "DSH connection RPC is unavailable"
1065
+ });
1066
+ return Promise.resolve(false);
1067
+ }
1068
+ this.publish({
1069
+ ...this.snapshot,
1070
+ loading: true,
1071
+ error: null
1072
+ });
1073
+ const run = (async () => {
1074
+ try {
1075
+ const endpoint = force ? UPDATE_ENDPOINTS.checkUpdate : UPDATE_ENDPOINTS.getStatus;
1076
+ const ttl = isCacheTtlMinutes(cacheTtlMinutes) ? cacheTtlMinutes : 360;
1077
+ const raw = await rpc.call(UPDATE_STATUS_CHANNEL, endpoint, force ? {
1078
+ force: true,
1079
+ channel,
1080
+ cacheTtlMinutes: ttl
1081
+ } : {
1082
+ channel,
1083
+ cacheTtlMinutes: ttl
1084
+ });
1085
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) throw new Error("invalid update-status RPC response");
1086
+ const envelope = raw;
1087
+ if (envelope.ok !== true) throw new Error(typeof envelope.error?.message === "string" ? envelope.error.message : "update-status RPC failed");
1088
+ const status = updateStatusOf(envelope.value);
1089
+ if (status === void 0) throw new Error("invalid update-status payload");
1090
+ this.publish({
1091
+ status,
1092
+ loading: false,
1093
+ error: null
1094
+ });
1095
+ return true;
1096
+ } catch (error) {
1097
+ this.publish({
1098
+ ...this.snapshot,
1099
+ loading: false,
1100
+ error: errorMessage(error)
1101
+ });
1102
+ return false;
1103
+ }
1104
+ })();
1105
+ this.inFlight = run;
1106
+ run.finally(() => {
1107
+ if (this.inFlight === run) this.inFlight = void 0;
1108
+ });
1109
+ return run;
1110
+ }
1111
+ };
1112
+ const INITIAL_PREFERENCES = {
1113
+ sidebarEnabled: true,
1114
+ channel: "latest",
1115
+ cacheTtlMinutes: 360,
1116
+ writable: false,
1117
+ status: "loading"
1118
+ };
1119
+ var PreferencesStore = class {
1120
+ snapshot = INITIAL_PREFERENCES;
1121
+ listeners = /* @__PURE__ */ new Set();
1122
+ scope;
1123
+ getSnapshot = () => this.snapshot;
1124
+ subscribe = (listener) => {
1125
+ this.listeners.add(listener);
1126
+ return () => {
1127
+ this.listeners.delete(listener);
1128
+ };
1129
+ };
1130
+ attach(scope) {
1131
+ this.scope = scope;
1132
+ const sync = () => {
1133
+ const raw = scope.getSnapshot();
1134
+ const value = raw.value !== null && typeof raw.value === "object" && !Array.isArray(raw.value) ? raw.value : {};
1135
+ const status = raw.status === "ready" || raw.status === "unavailable" ? raw.status : "loading";
1136
+ this.publish({
1137
+ sidebarEnabled: value.sidebarEnabled !== false,
1138
+ channel: isReleaseChannel(value.channel) ? value.channel : "latest",
1139
+ cacheTtlMinutes: isCacheTtlMinutes(value.cacheTtlMinutes) ? value.cacheTtlMinutes : 360,
1140
+ writable: raw.writable === true,
1141
+ status
1142
+ });
1143
+ };
1144
+ sync();
1145
+ return scope.subscribe(sync);
1146
+ }
1147
+ setSidebarEnabled(enabled) {
1148
+ const previous = this.snapshot;
1149
+ this.publish({
1150
+ ...previous,
1151
+ sidebarEnabled: enabled
1152
+ });
1153
+ const scope = this.scope;
1154
+ if (scope === void 0 || !previous.writable) return;
1155
+ scope.set("sidebarEnabled", enabled).catch(() => {
1156
+ try {
1157
+ const raw = scope.getSnapshot();
1158
+ const value = raw.value !== null && typeof raw.value === "object" && !Array.isArray(raw.value) ? raw.value : {};
1159
+ this.publish({
1160
+ sidebarEnabled: value.sidebarEnabled !== false,
1161
+ channel: isReleaseChannel(value.channel) ? value.channel : "latest",
1162
+ cacheTtlMinutes: isCacheTtlMinutes(value.cacheTtlMinutes) ? value.cacheTtlMinutes : 360,
1163
+ writable: raw.writable === true,
1164
+ status: raw.status === "ready" || raw.status === "unavailable" ? raw.status : "loading"
1165
+ });
1166
+ } catch {
1167
+ this.publish(previous);
1168
+ }
1169
+ });
1170
+ }
1171
+ setChannel(channel) {
1172
+ const previous = this.snapshot;
1173
+ this.publish({
1174
+ ...previous,
1175
+ channel
1176
+ });
1177
+ const scope = this.scope;
1178
+ if (scope === void 0 || !previous.writable) return;
1179
+ scope.set("channel", channel).catch(() => {
1180
+ this.publish(previous);
1181
+ });
1182
+ }
1183
+ setCacheTtlMinutes(cacheTtlMinutes) {
1184
+ if (!isCacheTtlMinutes(cacheTtlMinutes)) return;
1185
+ const previous = this.snapshot;
1186
+ this.publish({
1187
+ ...previous,
1188
+ cacheTtlMinutes
1189
+ });
1190
+ const scope = this.scope;
1191
+ if (scope === void 0 || !previous.writable) return;
1192
+ scope.set("cacheTtlMinutes", cacheTtlMinutes).catch(() => {
1193
+ this.publish(previous);
1194
+ });
1195
+ }
1196
+ publish(next) {
1197
+ const previous = this.snapshot;
1198
+ if (previous.sidebarEnabled === next.sidebarEnabled && previous.channel === next.channel && previous.cacheTtlMinutes === next.cacheTtlMinutes && previous.writable === next.writable && previous.status === next.status) return;
1199
+ this.snapshot = next;
1200
+ for (const listener of this.listeners) listener();
1201
+ }
1202
+ };
1203
+ /** Open state also retains its trigger, so the desktop card sits beside it. */
1204
+ var PanelStore = class {
1205
+ snapshot = {
1206
+ open: false,
1207
+ origin: "brand"
1208
+ };
1209
+ listeners = /* @__PURE__ */ new Set();
1210
+ getSnapshot = () => this.snapshot;
1211
+ subscribe = (listener) => {
1212
+ this.listeners.add(listener);
1213
+ return () => {
1214
+ this.listeners.delete(listener);
1215
+ };
1216
+ };
1217
+ toggle(origin) {
1218
+ const open = !(this.snapshot.open && this.snapshot.origin === origin);
1219
+ this.set({
1220
+ open,
1221
+ origin
1222
+ });
1223
+ }
1224
+ close() {
1225
+ this.set({
1226
+ ...this.snapshot,
1227
+ open: false
1228
+ });
1229
+ }
1230
+ set(next) {
1231
+ if (this.snapshot.open === next.open && this.snapshot.origin === next.origin) return;
1232
+ this.snapshot = next;
1233
+ for (const listener of this.listeners) listener();
1234
+ }
1235
+ };
1236
+ /** The one namespace name used by Host registration and browser binding. */
1237
+ const SETTINGS_NAMESPACE = PLUGIN_ID$1;
1238
+ //#endregion
1239
+ //#region src/client/styles.ts
1240
+ /** Plugin-owned CSS only; no shell DOM selection or official SVG manipulation. */
1241
+ const UPDATE_STATUS_CSS = `
1242
+ .dus-brand-name{align-items:center;gap:8px;min-width:0;width:100%;display:flex}
1243
+ .dus-brand-deepseek{font-size:15px;font-weight:650;letter-spacing:-.015em;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1244
+ .dus-badge{align-items:center;gap:5px;background:var(--dsw-alias-button-floating-fill);border:1px solid var(--dsw-alias-border-l2);border-radius:999px;color:var(--dsw-alias-label-secondary);cursor:pointer;display:inline-flex;flex:0 0 auto;font-size:11px;font-variant-numeric:tabular-nums;line-height:20px;max-width:132px;outline:none;padding:0 8px;touch-action:manipulation;user-select:none}
1245
+ .dus-badge:focus-visible,.dus-footer-button:focus-visible,.dus-action:focus-visible,.dus-close:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}
1246
+ .dus-badge:hover{background:var(--dsw-alias-button-floating-hover)}
1247
+ .dus-badge[data-update=true]{border-color:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-state-business-primary)}
1248
+ .dus-badge[data-error=true]{border-color:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-state-error-primary)}
1249
+ .dus-badge-version{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1250
+ .dus-dot{background:currentColor;border-radius:50%;display:inline-block;flex:0 0 auto;height:6px;width:6px}
1251
+ .dus-dot[data-update=true]{animation:dus-pulse 1.5s ease-in-out infinite;background:var(--dsw-alias-state-warn-primary)}
1252
+ .dus-dot[data-loading=true]{animation:dus-pulse .9s ease-in-out infinite}
1253
+ @keyframes dus-pulse{0%,100%{opacity:.45;transform:scale(.82)}50%{opacity:1;transform:scale(1.15)}}
1254
+ @media (prefers-reduced-motion:reduce){.dus-dot[data-update=true],.dus-dot[data-loading=true]{animation:none}}
1255
+ .dus-footer-button{align-items:center;background:transparent;border:0;border-radius:10px;color:var(--dsw-alias-label-secondary);cursor:pointer;display:flex;height:44px;justify-content:center;min-height:44px;min-width:44px;padding:0;position:relative;touch-action:manipulation;width:44px}
1256
+ .dus-footer-button:hover{background:var(--dsw-alias-button-floating-hover);color:var(--dsw-alias-label-primary)}
1257
+ .dus-footer-icon{font-size:18px;line-height:1}
1258
+ .dus-footer-dot{border:1.5px solid var(--dsw-specific-sidebar-fill);position:absolute;right:9px;top:9px}
1259
+ .dus-overlay-root{background:transparent;border:0;color:inherit;height:100dvh;inset:0;margin:0;max-height:none;max-width:none;padding:0;pointer-events:none;position:fixed;width:100vw}
1260
+ .dus-overlay-root::backdrop{background:transparent}
1261
+ .dus-backdrop{background:transparent;inset:0;pointer-events:auto;position:absolute}
1262
+ .dus-panel{background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);border-radius:14px;box-shadow:var(--dsw-elevation-panel);box-sizing:border-box;color:var(--dsw-alias-label-primary);max-height:min(640px,calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));overflow:auto;padding:14px;pointer-events:auto;position:absolute;top:12px;width:min(390px,calc(100vw - 24px));z-index:1}
1263
+ .dus-panel[data-origin=brand]{left:min(292px,calc(100vw - 402px))}
1264
+ .dus-panel[data-origin=rail]{left:min(68px,calc(100vw - 402px))}
1265
+ .dus-panel-head{align-items:center;display:flex;gap:8px;justify-content:space-between;margin-bottom:12px}
1266
+ .dus-panel-title{font-size:14px;font-weight:650}
1267
+ .dus-close{align-items:center;background:transparent;border:0;border-radius:8px;color:inherit;cursor:pointer;display:inline-flex;font-size:20px;height:32px;justify-content:center;line-height:1;min-height:32px;min-width:32px;padding:0;touch-action:manipulation;width:32px}
1268
+ .dus-close:hover,.dus-action:hover{background:var(--dsw-alias-button-floating-hover)}
1269
+ .dus-cache-setting{border:1px solid var(--dsw-alias-border-l2);border-radius:9px;margin:0 0 12px;padding:9px}
1270
+ .dus-cache-field{align-items:center;display:flex;font-size:12px;font-weight:600;gap:10px;justify-content:space-between}
1271
+ .dus-cache-input-wrap{align-items:center;display:flex;gap:6px;font-size:11px;font-weight:400}
1272
+ .dus-cache-input{background:var(--dsw-specific-input-major);border:1px solid var(--dsw-alias-border-l2);border-radius:7px;color:inherit;font:inherit;min-height:30px;padding:0 7px;text-align:right;width:72px}
1273
+ .dus-cache-input:focus{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}
1274
+ .dus-cache-input:disabled{cursor:not-allowed;opacity:.55}
1275
+ .dus-cache-hint{color:var(--dsw-alias-label-secondary);font-size:11px;line-height:1.4;margin:7px 0 0}
1276
+ .dus-state{border-radius:9px;color:var(--dsw-alias-label-primary);font-size:12px;line-height:1.45;margin:0 0 12px;padding:8px 9px}
1277
+ .dus-state[data-kind=update],.dus-state[data-kind=warning]{background:var(--dsw-alias-state-warn-tertiary)}
1278
+ .dus-state[data-kind=ok]{background:var(--dsw-alias-state-success-tertiary)}
1279
+ .dus-state[data-kind=error]{background:var(--dsw-alias-bg-layer-3)}
1280
+ .dus-metadata{display:grid;gap:9px;margin:0 0 12px}
1281
+ .dus-metadata-row{align-items:baseline;display:grid;gap:8px;grid-template-columns:minmax(0,1fr) auto}
1282
+ .dus-meta-label{color:var(--dsw-alias-label-secondary);font-size:12px}
1283
+ .dus-meta-value{font-family:var(--dsw-font-family-mono,ui-monospace,SFMono-Regular,Menlo,monospace);font-size:12px;max-width:210px;overflow-wrap:anywhere;text-align:right}
1284
+ .dus-meta-sub{color:var(--dsw-alias-label-secondary);font-size:11px;grid-column:1 / -1}
1285
+ .dus-warning{border-left:2px solid var(--dsw-alias-state-warn-primary);color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.45;margin:0 0 12px;padding-left:8px}
1286
+ .dus-actions{display:flex;flex-wrap:wrap;gap:8px;margin:0 0 12px}
1287
+ .dus-action{background:var(--dsw-alias-button-floating-fill);border:1px solid var(--dsw-alias-border-l2);border-radius:8px;color:inherit;cursor:pointer;font-size:12px;line-height:30px;min-height:32px;padding:0 10px;touch-action:manipulation}
1288
+ .dus-action:disabled{cursor:wait;opacity:.65}
1289
+ .dus-command-label{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;margin:0 0 6px}
1290
+ .dus-command{background:var(--dsw-specific-input-major);border:1px solid var(--dsw-alias-border-l2);border-radius:8px;display:block;font-family:var(--dsw-font-family-mono,ui-monospace,SFMono-Regular,Menlo,monospace);font-size:11px;line-height:1.5;margin:0;overflow-wrap:anywhere;padding:9px;tab-size:2;user-select:text;white-space:pre-wrap}
1291
+ .dus-command:focus{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}
1292
+ .dus-note{color:var(--dsw-alias-label-secondary);font-size:11px;line-height:1.45;margin:8px 0 0}
1293
+ .dus-copy-message{color:var(--dsw-alias-state-business-primary);font-size:11px;margin:7px 0 0}
1294
+ .dus-settings{display:grid;gap:14px;max-width:640px;padding:4px 0}
1295
+ .dus-settings-heading{font-size:16px;font-weight:650;margin:0}
1296
+ .dus-settings-card{border:1px solid var(--dsw-alias-border-l2);border-radius:10px;padding:12px}
1297
+ .dus-settings-toggle{align-items:flex-start;cursor:pointer;display:flex;gap:10px;font-size:13px;line-height:1.4}
1298
+ .dus-settings-toggle input{accent-color:var(--dsw-alias-state-business-primary);height:18px;margin:0;min-height:18px;min-width:18px;width:18px}
1299
+ .dus-settings-field{display:grid;font-size:13px;font-weight:600;gap:8px}
1300
+ .dus-channel-select{background:var(--dsw-specific-input-major);border:1px solid var(--dsw-alias-border-l2);border-radius:8px;color:inherit;font:inherit;min-height:40px;padding:0 10px;width:100%}
1301
+ .dus-channel-list{border-top:1px solid var(--dsw-alias-border-l2);margin:12px 0 0;padding-top:2px}
1302
+ .dus-channel-row{align-items:center;display:grid;font-size:11px;gap:8px;grid-template-columns:minmax(0,1fr) auto;line-height:1.4;padding:6px 0}
1303
+ .dus-channel-row[data-selected=true]{color:var(--dsw-alias-state-business-primary)}
1304
+ .dus-channel-row code{font-size:11px}
1305
+ .dus-channel-compat{color:var(--dsw-alias-label-secondary)}
1306
+ .dus-channel-action{background:transparent;border:1px solid var(--dsw-alias-border-l2);border-radius:7px;color:inherit;cursor:pointer;font-size:11px;justify-self:end;min-height:32px;padding:0 9px}
1307
+ .dus-channel-action:disabled{cursor:default;opacity:.55}
1308
+ .dus-channel-action:not(:disabled):hover{background:var(--dsw-alias-button-floating-hover)}
1309
+ .dus-channel-compat[data-compatibility=verified]{color:var(--dsw-alias-state-success-primary)}
1310
+ .dus-channel-compat[data-compatibility=incompatible]{color:var(--dsw-alias-state-error-primary)}
1311
+ .dus-settings-hint{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.45;margin:8px 0 0}
1312
+ @media (max-width:640px),(hover:none) and (pointer:coarse){.dus-panel[data-origin]{border-bottom:0;border-bottom-left-radius:0;border-bottom-right-radius:0;bottom:0;left:0;right:0;max-height:min(78dvh,calc(100dvh - env(safe-area-inset-top)));padding:16px max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));position:fixed;top:auto;width:100vw}.dus-footer-button{height:48px;min-height:48px;min-width:48px;width:48px}.dus-badge{line-height:24px;min-height:28px}.dus-action{min-height:40px;line-height:38px}.dus-close{height:40px;min-height:40px;min-width:40px;width:40px}}
1313
+ `;
1314
+ //#endregion
1315
+ //#region src/client/index.ts
1316
+ const PLUGIN_ID = "dsh-update-status";
1317
+ const CSS_TAG_ID = `${PLUGIN_ID}/styles`;
1318
+ function installStyles() {
1319
+ if (typeof document === "undefined") return () => {};
1320
+ if (document.querySelector(`style[data-plugin-css="${CSS_TAG_ID}"]`) !== null) return () => {};
1321
+ const tag = document.createElement("style");
1322
+ tag.dataset.plugin = PLUGIN_ID;
1323
+ tag.dataset.pluginCss = CSS_TAG_ID;
1324
+ tag.textContent = UPDATE_STATUS_CSS;
1325
+ document.head.appendChild(tag);
1326
+ return () => {
1327
+ const live = document.querySelector(`style[data-plugin-css="${CSS_TAG_ID}"]`);
1328
+ if (live?.parentNode !== void 0 && live?.parentNode !== null) live.parentNode.removeChild(live);
1329
+ };
1330
+ }
1331
+ function connectionOf(ctx) {
1332
+ try {
1333
+ const candidate = ctx.get("connection");
1334
+ return candidate !== null && typeof candidate === "object" ? candidate : {};
1335
+ } catch {
1336
+ return {};
1337
+ }
1338
+ }
1339
+ function apply(ctx) {
1340
+ const connection = connectionOf(ctx);
1341
+ const canManage = connection.isLoopback === true;
1342
+ const status = new StatusStore(connection, canManage ? null : STATIC_COMPATIBLE_VERSION);
1343
+ const preferences = new PreferencesStore();
1344
+ const ui = {
1345
+ status,
1346
+ preferences,
1347
+ panel: new PanelStore(),
1348
+ canManage
1349
+ };
1350
+ ctx.effect(() => {
1351
+ const disposeStyles = installStyles();
1352
+ if (canManage) status.load(preferences.getSnapshot().cacheTtlMinutes);
1353
+ return () => {
1354
+ status.stop();
1355
+ disposeStyles();
1356
+ };
1357
+ }, "dsh-update-status: style and first status read");
1358
+ ctx.inject(["settingsScope"], (raw) => {
1359
+ const binder = raw.settingsScope;
1360
+ if (binder === null || typeof binder !== "object" || typeof binder.bind !== "function") return;
1361
+ try {
1362
+ const scope = binder.bind({ namespace: SETTINGS_NAMESPACE });
1363
+ ctx.effect(() => {
1364
+ const detach = preferences.attach(scope);
1365
+ let selected = status.getSnapshot().status?.channel ?? "latest";
1366
+ const syncPreferences = () => {
1367
+ const next = preferences.getSnapshot();
1368
+ if (next.channel !== selected) {
1369
+ selected = next.channel;
1370
+ status.selectChannel(selected, next.cacheTtlMinutes);
1371
+ }
1372
+ };
1373
+ syncPreferences();
1374
+ const unsubscribe = preferences.subscribe(syncPreferences);
1375
+ return () => {
1376
+ unsubscribe();
1377
+ detach();
1378
+ };
1379
+ }, "dsh-update-status: sidebar and channel preferences");
1380
+ } catch {}
1381
+ });
1382
+ ctx.slots.inject("sidebar.brand.name", () => ctx.slots.register({
1383
+ name: "sidebar.brand.name",
1384
+ priority: -10
1385
+ }, () => BrandName({ ui })));
1386
+ ctx.slots.inject("sidebar.footer.action", () => ctx.slots.register({
1387
+ name: "sidebar.footer.action",
1388
+ id: "dsh-update-status",
1389
+ order: 40
1390
+ }, (props) => FooterAction({
1391
+ wide: props.wide,
1392
+ ui
1393
+ })));
1394
+ ctx.slots.inject("shell.overlay", () => ctx.slots.register({
1395
+ name: "shell.overlay",
1396
+ id: "dsh-update-status",
1397
+ order: 40
1398
+ }, () => UpdatePanel({ ui })));
1399
+ ctx.slots.inject("settings.section", () => ctx.slots.register({
1400
+ name: "settings.section",
1401
+ id: "dsh-update-status",
1402
+ order: 80,
1403
+ label: () => t("settings.title")
1404
+ }, () => UpdateSettings({ ui })));
1405
+ }
1406
+ module.exports = {
1407
+ name: PLUGIN_ID,
1408
+ inject: ["slots", "connection"],
1409
+ apply
1410
+ };
1411
+ //#endregion
1412
+ return module.exports;
1413
+ }
1414
+ });
1415
+
1416
+ //# sourceMappingURL=client.js.map