@linxin666/dsh-remote-web-ui 0.1.10 → 0.1.12
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/README.md +17 -6
- package/lib/client.js +404 -15
- package/lib/client.js.map +1 -1
- package/lib/index.js +406 -17
- package/lib/types/client/RemoteEntry.d.ts.map +1 -1
- package/lib/types/client/RemoteEntry.js +9 -7
- package/lib/types/client/UpdateEntry.d.ts +14 -0
- package/lib/types/client/UpdateEntry.d.ts.map +1 -0
- package/lib/types/client/UpdateEntry.js +68 -0
- package/lib/types/client/UpdatePanel.d.ts +40 -0
- package/lib/types/client/UpdatePanel.d.ts.map +1 -0
- package/lib/types/client/UpdatePanel.js +82 -0
- package/lib/types/client/index.d.ts +15 -1
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/index.js +2 -1
- package/lib/types/client/locales.d.ts +56 -0
- package/lib/types/client/locales.d.ts.map +1 -1
- package/lib/types/client/locales.js +58 -0
- package/lib/types/client/update-api.d.ts +19 -0
- package/lib/types/client/update-api.d.ts.map +1 -0
- package/lib/types/client/update-api.js +27 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +45 -1
- package/lib/types/routes.d.ts +15 -0
- package/lib/types/routes.d.ts.map +1 -1
- package/lib/types/routes.js +1 -1
- package/lib/types/update-routes.d.ts +30 -0
- package/lib/types/update-routes.d.ts.map +1 -0
- package/lib/types/update-routes.js +52 -0
- package/lib/types/update.d.ts +191 -0
- package/lib/types/update.d.ts.map +1 -0
- package/lib/types/update.js +333 -0
- package/package.json +2 -2
- package/src/client/RemoteEntry.tsx +12 -7
- package/src/client/UpdateEntry.tsx +96 -0
- package/src/client/UpdatePanel.tsx +203 -0
- package/src/client/index.ts +17 -2
- package/src/client/locales.ts +58 -0
- package/src/client/remote.module.css +109 -0
- package/src/client/update-api.ts +29 -0
- package/src/index.ts +51 -1
- package/src/routes.ts +1 -1
- package/src/update-routes.ts +71 -0
- package/src/update.ts +435 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sidebar update seat: the download trigger beside the remote-control
|
|
3
|
+
* trigger plus the update panel modal. Owns the flow — probe the registry
|
|
4
|
+
* on open, auto-run the update when a newer release exists, report the
|
|
5
|
+
* outcome (restart hint on success, translated failure on error).
|
|
6
|
+
* Component-local state per the client stack rules.
|
|
7
|
+
*/
|
|
8
|
+
import { useCallback, useEffect, useRef, useState } from "react"
|
|
9
|
+
import { createPortal } from "react-dom"
|
|
10
|
+
import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
|
|
11
|
+
import { IconDownloadOutline16 } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
12
|
+
import type { UpdateStatus } from '../update.ts'
|
|
13
|
+
import { fetchUpdateStatus, runUpdate } from "./update-api.ts"
|
|
14
|
+
import { UpdatePanel, type UpdateView } from "./UpdatePanel.tsx"
|
|
15
|
+
import css from "./remote.module.css"
|
|
16
|
+
|
|
17
|
+
/** Entry props: the sidebar column state + the standard locale seat. */
|
|
18
|
+
export interface UpdateEntryProps {
|
|
19
|
+
/** Whether the sidebar renders wide content (false = 56px rail). */
|
|
20
|
+
wide: boolean
|
|
21
|
+
t: TranslateNS<'remote'>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Render the update trigger and panel.
|
|
26
|
+
* @param props - column state and locale seat.
|
|
27
|
+
* @returns the entry element tree.
|
|
28
|
+
*/
|
|
29
|
+
export function UpdateEntry({ wide, t }: UpdateEntryProps) {
|
|
30
|
+
const [open, setOpen] = useState(false)
|
|
31
|
+
const [view, setView] = useState<UpdateView>({ kind: "checking" })
|
|
32
|
+
const runToken = useRef(0)
|
|
33
|
+
|
|
34
|
+
const check = useCallback(async (): Promise<void> => {
|
|
35
|
+
setView({ kind: "checking" })
|
|
36
|
+
let status: UpdateStatus
|
|
37
|
+
try {
|
|
38
|
+
status = await fetchUpdateStatus()
|
|
39
|
+
} catch {
|
|
40
|
+
setView({ kind: "error", message: t("update.offline"), detail: t("update.offlineDetail") })
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
if (status.error === "registry-unreachable") {
|
|
44
|
+
setView({ kind: "result", status })
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
setView({ kind: "result", status })
|
|
48
|
+
// Auto-update: an npm install with a newer release proceeds without a
|
|
49
|
+
// second confirmation — clicking the update trigger is the intent.
|
|
50
|
+
if (status.mode !== "npm" || !status.outdated) return
|
|
51
|
+
setView({ kind: "updating", status })
|
|
52
|
+
const token = ++runToken.current
|
|
53
|
+
try {
|
|
54
|
+
const result = await runUpdate()
|
|
55
|
+
if (token !== runToken.current) return
|
|
56
|
+
setView({ kind: "done", result })
|
|
57
|
+
} catch {
|
|
58
|
+
if (token !== runToken.current) return
|
|
59
|
+
setView({ kind: "error", message: t("update.error"), detail: t("update.offlineDetail") })
|
|
60
|
+
}
|
|
61
|
+
}, [t])
|
|
62
|
+
|
|
63
|
+
const openPanel = useCallback((): void => {
|
|
64
|
+
setOpen(true)
|
|
65
|
+
void check()
|
|
66
|
+
}, [check])
|
|
67
|
+
|
|
68
|
+
const closePanel = useCallback((): void => {
|
|
69
|
+
runToken.current++
|
|
70
|
+
setOpen(false)
|
|
71
|
+
}, [])
|
|
72
|
+
|
|
73
|
+
// Unmount safety: an in-flight update must not land on a dead component.
|
|
74
|
+
useEffect(() => () => { runToken.current++ }, [])
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
<button
|
|
79
|
+
type="button"
|
|
80
|
+
className={css.trigger}
|
|
81
|
+
data-wide={wide ? undefined : "rail"}
|
|
82
|
+
aria-label={t("update.label")}
|
|
83
|
+
title={t("update.label")}
|
|
84
|
+
onClick={openPanel}
|
|
85
|
+
>
|
|
86
|
+
<IconDownloadOutline16 size={wide ? 16 : 18} />
|
|
87
|
+
</button>
|
|
88
|
+
{open && createPortal((
|
|
89
|
+
<div className={css.overlay} role="presentation">
|
|
90
|
+
<div className={css.mask} aria-hidden="true" onClick={closePanel} />
|
|
91
|
+
<UpdatePanel t={t} view={view} onClose={closePanel} onRecheck={() => { void check() }} />
|
|
92
|
+
</div>
|
|
93
|
+
), document.body)}
|
|
94
|
+
</>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The update panel body: check progress, version comparison, the
|
|
3
|
+
* auto-update in-flight state, and the outcome (restart hint on success,
|
|
4
|
+
* translated failure on error). Pure presentation — all state arrives
|
|
5
|
+
* through props from the entry behavior component.
|
|
6
|
+
*/
|
|
7
|
+
import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
|
|
8
|
+
import { IconCloseOutline16, IconRefreshOutline16 } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
9
|
+
import type { UpdateRunResult, UpdateStatus } from '../update.ts'
|
|
10
|
+
import css from "./remote.module.css"
|
|
11
|
+
|
|
12
|
+
/** The panel view state, owned by the entry component. */
|
|
13
|
+
export type UpdateView =
|
|
14
|
+
| { kind: 'checking' }
|
|
15
|
+
| { kind: 'result'; status: UpdateStatus }
|
|
16
|
+
| { kind: 'updating'; status: UpdateStatus }
|
|
17
|
+
| { kind: 'done'; result: UpdateRunResult }
|
|
18
|
+
| { kind: 'error'; message: string; detail?: string }
|
|
19
|
+
|
|
20
|
+
/** Full panel props: copy + view state + actions. */
|
|
21
|
+
export interface UpdatePanelProps {
|
|
22
|
+
t: TranslateNS<'remote'>
|
|
23
|
+
view: UpdateView
|
|
24
|
+
onClose(): void
|
|
25
|
+
/** Re-run the check from a terminal state. */
|
|
26
|
+
onRecheck(): void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The anchor package name (aggregate first) for copy purposes. */
|
|
30
|
+
function anchorName(status: UpdateStatus | undefined): string | undefined {
|
|
31
|
+
return status?.anchor ?? status?.packages[0]?.name
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The latest npm release of the anchor, for reference copy. */
|
|
35
|
+
function anchorLatest(status: UpdateStatus | undefined): string | undefined {
|
|
36
|
+
return status?.packages[0]?.latest
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Render the update panel.
|
|
41
|
+
* @param props - copy, view state, and actions.
|
|
42
|
+
* @returns the panel element tree.
|
|
43
|
+
*/
|
|
44
|
+
export function UpdatePanel({ t, view, onClose, onRecheck }: UpdatePanelProps) {
|
|
45
|
+
const status = view.kind === "result" || view.kind === "updating" ? view.status : undefined
|
|
46
|
+
const title = view.kind === "done" && view.result.ok ? t("update.done") : t("update.title")
|
|
47
|
+
const subtitle = subtitleOf(t, view)
|
|
48
|
+
return (
|
|
49
|
+
<div className={css.panel} role="dialog" aria-modal="true" aria-label={title}>
|
|
50
|
+
<div className={css.header}>
|
|
51
|
+
<div className={css.heading}>
|
|
52
|
+
<h2 className={css.title}>{title}</h2>
|
|
53
|
+
{subtitle !== undefined && <p className={css.subtitle}>{subtitle}</p>}
|
|
54
|
+
</div>
|
|
55
|
+
<button type="button" className={css.close} aria-label={t("update.close")} onClick={onClose}>
|
|
56
|
+
<IconCloseOutline16 />
|
|
57
|
+
</button>
|
|
58
|
+
</div>
|
|
59
|
+
{view.kind === "checking" && <p className={css.updateStatus}>{t("update.checking")}</p>}
|
|
60
|
+
{view.kind === "result" && status !== undefined && <ResultBody t={t} status={status} />}
|
|
61
|
+
{view.kind === "updating" && status !== undefined && (
|
|
62
|
+
<div>
|
|
63
|
+
<p className={css.updateStatus}>
|
|
64
|
+
{t("update.updating", { name: anchorName(status) ?? "", version: anchorLatest(status) ?? "" })}
|
|
65
|
+
</p>
|
|
66
|
+
<PackageList status={status} />
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
69
|
+
{view.kind === "done" && <DoneBody t={t} result={view.result} />}
|
|
70
|
+
{view.kind === "error" && (
|
|
71
|
+
<div>
|
|
72
|
+
<p className={css.updateError}>{view.message}</p>
|
|
73
|
+
{view.detail !== undefined && <pre className={css.updateOutput}>{view.detail}</pre>}
|
|
74
|
+
</div>
|
|
75
|
+
)}
|
|
76
|
+
{(view.kind === "done" || view.kind === "error") && (
|
|
77
|
+
<div className={css.updateActions}>
|
|
78
|
+
<button type="button" className={css.updateRetry} onClick={onRecheck}>
|
|
79
|
+
<IconRefreshOutline16 /> {t("update.retry")}
|
|
80
|
+
</button>
|
|
81
|
+
</div>
|
|
82
|
+
)}
|
|
83
|
+
</div>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The subtitle copy per view state (absent on plain results). */
|
|
88
|
+
function subtitleOf(t: TranslateNS<"remote">, view: UpdateView): string | undefined {
|
|
89
|
+
switch (view.kind) {
|
|
90
|
+
case "checking":
|
|
91
|
+
return t("update.checking")
|
|
92
|
+
case "updating":
|
|
93
|
+
return t("update.updatingTitle")
|
|
94
|
+
case "result":
|
|
95
|
+
return undefined
|
|
96
|
+
case "done":
|
|
97
|
+
return view.result.ok ? t("update.doneDetail") : t("update.error")
|
|
98
|
+
case "error":
|
|
99
|
+
// The error body below carries the message; no subtitle duplication.
|
|
100
|
+
return undefined
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The checked result body: mode banner + version list. */
|
|
105
|
+
function ResultBody({ t, status }: { t: TranslateNS<"remote">; status: UpdateStatus }) {
|
|
106
|
+
const anchor = anchorName(status)
|
|
107
|
+
const latest = anchorLatest(status)
|
|
108
|
+
if (status.mode === "link") {
|
|
109
|
+
return (
|
|
110
|
+
<div>
|
|
111
|
+
<p className={css.updateStatus}>{t("update.linkMode")}</p>
|
|
112
|
+
<p className={css.updateDetail}>{t("update.linkModeDetail", { version: latest ?? "-" })}</p>
|
|
113
|
+
</div>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
if (status.mode === "missing") {
|
|
117
|
+
return (
|
|
118
|
+
<div>
|
|
119
|
+
<p className={css.updateStatus}>{t("update.missing")}</p>
|
|
120
|
+
<p className={css.updateDetail}>{t("update.missingDetail")}</p>
|
|
121
|
+
</div>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
if (status.error === "registry-unreachable") {
|
|
125
|
+
return (
|
|
126
|
+
<div>
|
|
127
|
+
<p className={css.updateStatus}>{t("update.offline")}</p>
|
|
128
|
+
<p className={css.updateDetail}>{t("update.offlineDetail")}</p>
|
|
129
|
+
</div>
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
if (status.outdated) {
|
|
133
|
+
return (
|
|
134
|
+
<div>
|
|
135
|
+
<p className={css.updateStatus}>{t("update.found")}</p>
|
|
136
|
+
<p className={css.updateDetail}>
|
|
137
|
+
{anchor !== undefined ? t("update.foundDetail", { name: anchor, version: latest ?? "" }) : ""}
|
|
138
|
+
</p>
|
|
139
|
+
</div>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
return (
|
|
143
|
+
<div>
|
|
144
|
+
<p className={css.updateStatus}>{t("update.upToDate")}</p>
|
|
145
|
+
{anchor !== undefined && latest !== undefined && (
|
|
146
|
+
<p className={css.updateDetail}>{t("update.upToDateDetail", { name: anchor, version: latest })}</p>
|
|
147
|
+
)}
|
|
148
|
+
<PackageList status={status} />
|
|
149
|
+
</div>
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The per-package current → latest comparison list. */
|
|
154
|
+
function PackageList({ status }: { status: UpdateStatus }) {
|
|
155
|
+
if (status.packages.length === 0) return null
|
|
156
|
+
return (
|
|
157
|
+
<ul className={css.updateList}>
|
|
158
|
+
{status.packages.map(packageStatus => (
|
|
159
|
+
<li key={packageStatus.name} className={css.updateListItem}>
|
|
160
|
+
<span className={css.updateListName}>{packageStatus.name}</span>
|
|
161
|
+
<span className={css.updateListVersions}>
|
|
162
|
+
{packageStatus.current}
|
|
163
|
+
{packageStatus.latest !== undefined && packageStatus.latest !== packageStatus.current && (
|
|
164
|
+
<> → {packageStatus.latest}</>
|
|
165
|
+
)}
|
|
166
|
+
</span>
|
|
167
|
+
</li>
|
|
168
|
+
))}
|
|
169
|
+
</ul>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The outcome body: success + restart hint, or the translated failure. */
|
|
174
|
+
function DoneBody({ t, result }: { t: TranslateNS<"remote">; result: UpdateRunResult }) {
|
|
175
|
+
if (result.ok) {
|
|
176
|
+
// The title already reads "Update complete"; the body carries the details.
|
|
177
|
+
return (
|
|
178
|
+
<div>
|
|
179
|
+
<p className={css.updateDetail}>{t("update.doneDetail")}</p>
|
|
180
|
+
<p className={css.updateDetail}>{t("update.restartHint")}</p>
|
|
181
|
+
</div>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
const message = errorMessageOf(t, result)
|
|
185
|
+
return (
|
|
186
|
+
<div>
|
|
187
|
+
<p className={css.updateError}>{message}</p>
|
|
188
|
+
{result.output.trim() !== "" && <pre className={css.updateOutput}>{result.output.trim()}</pre>}
|
|
189
|
+
</div>
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Translate a structured failure code; fall back to the raw message. */
|
|
194
|
+
function errorMessageOf(t: TranslateNS<"remote">, result: UpdateRunResult): string {
|
|
195
|
+
switch (result.errorCode) {
|
|
196
|
+
case "pnpm-missing": return t("update.error.pnpmMissing")
|
|
197
|
+
case "timeout": return t("update.error.timeout")
|
|
198
|
+
case "not-found": return t("update.error.notFound")
|
|
199
|
+
case "link": return t("update.error.link")
|
|
200
|
+
case "pnpm-failed": return t("update.error.pnpmFailed", { code: String(result.exitCode ?? "?") })
|
|
201
|
+
default: return result.error ?? t("update.error.unknown")
|
|
202
|
+
}
|
|
203
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { createElement } from 'react'
|
|
10
10
|
import { createRoot } from 'react-dom/client'
|
|
11
|
-
import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client'
|
|
11
|
+
import type { ClientContext, SettingsScope, SettingsScopeSpec } from '@deepseek-ai/dsh-client-runtime/client'
|
|
12
12
|
// Type-only: pulls the locale plugin's Context merge (ctx.locale) and the
|
|
13
13
|
// ui-sidebar SlotMap merge (the 'sidebar.remote' hole).
|
|
14
14
|
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
|
@@ -30,6 +30,8 @@ export type { PanelState, RemotePanelProps } from './RemotePanel.tsx'
|
|
|
30
30
|
export type { PairFailedNoticeProps } from './PairFailedNotice.tsx'
|
|
31
31
|
export type { RemoteKey } from './locales.ts'
|
|
32
32
|
export type { RemoteSettingsCardFace, RemoteSettingsCardState } from './RemoteSettingsCard.tsx'
|
|
33
|
+
export type { UpdateEntryProps } from './UpdateEntry.tsx'
|
|
34
|
+
export type { UpdatePanelProps, UpdateView } from './UpdatePanel.tsx'
|
|
33
35
|
|
|
34
36
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
35
37
|
interface LocaleNamespaceMap {
|
|
@@ -66,6 +68,18 @@ export interface SettingsPluginItemOwnerProps {
|
|
|
66
68
|
children?: never
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
declare module '@deepseek-ai/cordis' {
|
|
72
|
+
interface Context {
|
|
73
|
+
/**
|
|
74
|
+
* Optional rc.6 compatibility binder provided by dsh-web-ui-settings;
|
|
75
|
+
* absent when that group plugin is not installed, so callers fall back to
|
|
76
|
+
* the official settings scope.
|
|
77
|
+
*/
|
|
78
|
+
webUiSettings?: { bind<S>(spec: SettingsScopeSpec<S>): SettingsScope<S> }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
69
83
|
/** Dictionary namespace owned by this plugin. */
|
|
70
84
|
const NS = 'remote'
|
|
71
85
|
|
|
@@ -86,7 +100,8 @@ export function apply(ctx: ClientContext): void {
|
|
|
86
100
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'remote-web-ui: dictionaries')
|
|
87
101
|
|
|
88
102
|
const t = ctx.locale.bind(NS)
|
|
89
|
-
const
|
|
103
|
+
const binder = ctx.get('webUiSettings') ?? ctx.settingsScope
|
|
104
|
+
const settingsScope = binder.bind<RemoteSettings>({ namespace: REMOTE_WEB_UI_NS })
|
|
90
105
|
const enabled = (): boolean => {
|
|
91
106
|
const snapshot = settingsScope.getSnapshot()
|
|
92
107
|
return snapshot.status === 'ready'
|
package/src/client/locales.ts
CHANGED
|
@@ -70,6 +70,35 @@ export const zh = {
|
|
|
70
70
|
'settings.unsaved': '未保存',
|
|
71
71
|
'settings.saveFailed': '部署未接受这些值,已保留供你修改。',
|
|
72
72
|
'settings.invalidNumber': '请输入数字,留空则使用默认值。',
|
|
73
|
+
// 更新面板(侧边栏更新按钮)。
|
|
74
|
+
'update.label': '检查更新',
|
|
75
|
+
'update.title': '检查更新',
|
|
76
|
+
'update.checking': '正在检查远程仓库中的新版本…',
|
|
77
|
+
'update.upToDate': '当前已是最新版本',
|
|
78
|
+
'update.upToDateDetail': '{name} 已是最新版本 v{version}。',
|
|
79
|
+
'update.found': '发现新版本',
|
|
80
|
+
'update.foundDetail': '{name} 有新版本 v{version},正在自动更新…',
|
|
81
|
+
'update.updating': '正在更新 {name} 至 v{version},可能需要 1-2 分钟…',
|
|
82
|
+
'update.updatingTitle': '正在自动更新…',
|
|
83
|
+
'update.done': '更新完成',
|
|
84
|
+
'update.doneDetail': '所有组件已更新到最新版本。',
|
|
85
|
+
'update.restartHint': '请重启 dsh web 使新版本生效:在终端按 Ctrl+C 停止后重新运行 dsh web。',
|
|
86
|
+
'update.linkMode': '当前为本地开发模式',
|
|
87
|
+
'update.linkModeDetail': 'dsh-web-ui 通过本地链接安装(开发模式),无法自动更新。npm 上最新版本:{version}。请在仓库中执行 git pull 更新。',
|
|
88
|
+
'update.missing': '未找到 dsh-web-ui 安装',
|
|
89
|
+
'update.missingDetail': '无法定位已安装的 dsh-web-ui 聚合包。请先运行 dsh plugin --profile <profile> add @linxin666/dsh-web-ui-all。',
|
|
90
|
+
'update.offline': '无法连接更新源',
|
|
91
|
+
'update.offlineDetail': '网络不可用或更新服务异常,请稍后重试。',
|
|
92
|
+
'update.error': '更新失败',
|
|
93
|
+
'update.packages': '组件版本',
|
|
94
|
+
'update.retry': '重新检查',
|
|
95
|
+
'update.close': '关闭更新面板',
|
|
96
|
+
'update.error.pnpmMissing': '未找到 pnpm,请先安装 pnpm(brew install pnpm 或 corepack enable)。',
|
|
97
|
+
'update.error.timeout': '更新超时,已终止安装进程,请重试。',
|
|
98
|
+
'update.error.notFound': '未找到 dsh-web-ui 聚合包安装,无法更新。',
|
|
99
|
+
'update.error.link': '当前为本地开发模式(链接安装),无法自动更新。',
|
|
100
|
+
'update.error.pnpmFailed': '更新执行失败(pnpm 退出码 {code}),详见下方输出。',
|
|
101
|
+
'update.error.unknown': '更新失败,请重试。',
|
|
73
102
|
} satisfies Record<string, string>
|
|
74
103
|
|
|
75
104
|
/** The remote namespace key union. */
|
|
@@ -148,4 +177,33 @@ export const en = {
|
|
|
148
177
|
'settings.unsaved': 'Unsaved',
|
|
149
178
|
'settings.saveFailed': 'The deployment did not accept these values; they were left for you to correct.',
|
|
150
179
|
'settings.invalidNumber': 'Enter a number, or leave blank to use the default.',
|
|
180
|
+
// Update panel (the sidebar update trigger).
|
|
181
|
+
'update.label': 'Check for updates',
|
|
182
|
+
'update.title': 'Check for updates',
|
|
183
|
+
'update.checking': 'Checking the remote repository for newer releases…',
|
|
184
|
+
'update.upToDate': 'Everything is up to date',
|
|
185
|
+
'update.upToDateDetail': '{name} is at the latest version v{version}.',
|
|
186
|
+
'update.found': 'A new version is available',
|
|
187
|
+
'update.foundDetail': '{name} has a newer release v{version}; updating automatically…',
|
|
188
|
+
'update.updating': 'Updating {name} to v{version}; this may take 1-2 minutes…',
|
|
189
|
+
'update.updatingTitle': 'Updating automatically…',
|
|
190
|
+
'update.done': 'Update complete',
|
|
191
|
+
'update.doneDetail': 'All components are up to date.',
|
|
192
|
+
'update.restartHint': 'Restart dsh web for the new version to take effect: stop it with Ctrl+C in the terminal, then run dsh web again.',
|
|
193
|
+
'update.linkMode': 'Local development mode',
|
|
194
|
+
'update.linkModeDetail': 'dsh-web-ui is installed via a local link (development mode) and cannot be updated remotely. Latest npm release: {version}. Run git pull in the repository to update.',
|
|
195
|
+
'update.missing': 'dsh-web-ui not found',
|
|
196
|
+
'update.missingDetail': 'Could not locate the installed dsh-web-ui aggregate package. Install it with: dsh plugin --profile <profile> add @linxin666/dsh-web-ui-all',
|
|
197
|
+
'update.offline': 'Cannot reach the update source',
|
|
198
|
+
'update.offlineDetail': 'The network is unavailable or the update service is failing; try again later.',
|
|
199
|
+
'update.error': 'Update failed',
|
|
200
|
+
'update.packages': 'Component versions',
|
|
201
|
+
'update.retry': 'Check again',
|
|
202
|
+
'update.close': 'Close update panel',
|
|
203
|
+
'update.error.pnpmMissing': 'pnpm was not found. Install it first (brew install pnpm or corepack enable).',
|
|
204
|
+
'update.error.timeout': 'The update timed out and the install process was killed; try again.',
|
|
205
|
+
'update.error.notFound': 'The dsh-web-ui aggregate package is not installed; nothing to update.',
|
|
206
|
+
'update.error.link': 'Local development mode (link install) — automatic update is unavailable.',
|
|
207
|
+
'update.error.pnpmFailed': 'The update failed (pnpm exited with code {code}); see the output below.',
|
|
208
|
+
'update.error.unknown': 'Update failed; try again.',
|
|
151
209
|
} satisfies Record<RemoteKey, string>
|
|
@@ -420,3 +420,112 @@
|
|
|
420
420
|
transition: none;
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
|
+
|
|
424
|
+
/* Footer seat row: the update trigger sits LEFT of the remote trigger in wide
|
|
425
|
+
mode; the rail stacks them with the update circle below the remote circle
|
|
426
|
+
(mirroring the settings circle keeping its bottom anchor). */
|
|
427
|
+
.entryRow {
|
|
428
|
+
flex: none;
|
|
429
|
+
display: flex;
|
|
430
|
+
align-items: center;
|
|
431
|
+
gap: 6px;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.entryRow[data-rail='rail'] {
|
|
435
|
+
flex-direction: column-reverse;
|
|
436
|
+
gap: 4px;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/* ── update panel extras ─────────────────────────────────────────────── */
|
|
440
|
+
|
|
441
|
+
.updateStatus {
|
|
442
|
+
margin: 0;
|
|
443
|
+
font-weight: 600;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
.updateDetail {
|
|
447
|
+
margin: 6px 0 0;
|
|
448
|
+
color: var(--dsw-alias-label-secondary);
|
|
449
|
+
font-size: 13px;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
.updateError {
|
|
453
|
+
margin: 0;
|
|
454
|
+
color: var(--dsw-alias-text-danger, var(--dsw-alias-label-primary));
|
|
455
|
+
font-weight: 600;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
.updateOutput {
|
|
459
|
+
max-height: 180px;
|
|
460
|
+
margin: 10px 0 0;
|
|
461
|
+
overflow: auto;
|
|
462
|
+
padding: 10px 12px;
|
|
463
|
+
border-radius: 10px;
|
|
464
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
465
|
+
color: var(--dsw-alias-label-secondary);
|
|
466
|
+
font-size: 12px;
|
|
467
|
+
line-height: 18px;
|
|
468
|
+
white-space: pre-wrap;
|
|
469
|
+
word-break: break-all;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
.updateList {
|
|
473
|
+
margin: 12px 0 0;
|
|
474
|
+
padding: 0;
|
|
475
|
+
list-style: none;
|
|
476
|
+
display: flex;
|
|
477
|
+
flex-direction: column;
|
|
478
|
+
gap: 6px;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
.updateListItem {
|
|
482
|
+
display: flex;
|
|
483
|
+
align-items: baseline;
|
|
484
|
+
justify-content: space-between;
|
|
485
|
+
gap: 12px;
|
|
486
|
+
font-size: 13px;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
.updateListName {
|
|
490
|
+
min-width: 0;
|
|
491
|
+
overflow: hidden;
|
|
492
|
+
text-overflow: ellipsis;
|
|
493
|
+
white-space: nowrap;
|
|
494
|
+
color: var(--dsw-alias-label-primary);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
.updateListVersions {
|
|
498
|
+
flex: none;
|
|
499
|
+
color: var(--dsw-alias-label-secondary);
|
|
500
|
+
font-variant-numeric: tabular-nums;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
.updateActions {
|
|
504
|
+
display: flex;
|
|
505
|
+
justify-content: flex-end;
|
|
506
|
+
margin-top: 16px;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
.updateRetry {
|
|
510
|
+
display: inline-flex;
|
|
511
|
+
align-items: center;
|
|
512
|
+
gap: 6px;
|
|
513
|
+
border: none;
|
|
514
|
+
border-radius: 10px;
|
|
515
|
+
padding: 8px 14px;
|
|
516
|
+
background: var(--dsw-alias-interactive-bg-hover);
|
|
517
|
+
color: var(--dsw-alias-label-primary);
|
|
518
|
+
font-size: 13px;
|
|
519
|
+
cursor: pointer;
|
|
520
|
+
transition: background-color 120ms ease, color 120ms ease;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
.updateRetry:hover {
|
|
524
|
+
background: var(--dsw-alias-interactive-bg-active);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
@media (prefers-reduced-motion: reduce) {
|
|
528
|
+
.updateRetry {
|
|
529
|
+
transition: none;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side wire helpers for the /api/update surface. Plain fetch over
|
|
3
|
+
* same-origin /api like the pairing client; the host half enforces the
|
|
4
|
+
* loopback-only fence and owns the pnpm run.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { UpdateRunResult, UpdateStatus } from '../update.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Probe the update status: install mode, owning profile, and the
|
|
11
|
+
* current-vs-latest comparison for every family package.
|
|
12
|
+
* @returns the status snapshot.
|
|
13
|
+
*/
|
|
14
|
+
export async function fetchUpdateStatus(): Promise<UpdateStatus> {
|
|
15
|
+
const response = await fetch('/api/update/status')
|
|
16
|
+
if (!response.ok) throw new Error('update status unavailable')
|
|
17
|
+
return await response.json() as UpdateStatus
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Run the update (pnpm update in the owning profile). Blocks until pnpm
|
|
22
|
+
* exits — the panel shows an in-flight state meanwhile.
|
|
23
|
+
* @returns the run outcome.
|
|
24
|
+
*/
|
|
25
|
+
export async function runUpdate(): Promise<UpdateRunResult> {
|
|
26
|
+
const response = await fetch('/api/update/run', { method: 'POST' })
|
|
27
|
+
if (!response.ok) throw new Error('update run unavailable')
|
|
28
|
+
return await response.json() as UpdateRunResult
|
|
29
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* phone-side pair/accept + deep-link flow.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import { createRequire } from 'node:module'
|
|
11
12
|
import { setInterval as nodeSetInterval } from 'node:timers'
|
|
12
13
|
import type { IncomingMessage } from 'node:http'
|
|
13
14
|
import type { Context } from '@deepseek-ai/cordis'
|
|
@@ -16,11 +17,20 @@ import z from 'schemastery'
|
|
|
16
17
|
import type {} from '@deepseek-ai/dsh-host-webserver'
|
|
17
18
|
import { PairingService } from './pairing.ts'
|
|
18
19
|
import { makeGateListener } from './gate.ts'
|
|
19
|
-
import { makeRoutes } from './routes.ts'
|
|
20
|
+
import { isTrustedApiRequest, makeRoutes } from './routes.ts'
|
|
20
21
|
import { makeMobileRoutes } from './mobile-routes.ts'
|
|
21
22
|
import { makeMobileApiRoutes } from './mobile-api.ts'
|
|
22
23
|
import { lanIPv4Addresses } from './lan.ts'
|
|
23
24
|
import { TunnelManager, type TunnelInfo } from './tunnel.ts'
|
|
25
|
+
import {
|
|
26
|
+
checkUpdates,
|
|
27
|
+
fetchLatestVersion,
|
|
28
|
+
resolveAnchorManifest,
|
|
29
|
+
resolveUpdateTarget,
|
|
30
|
+
runUpdate,
|
|
31
|
+
type UpdateRunResult,
|
|
32
|
+
} from './update.ts'
|
|
33
|
+
import { makeUpdateRoutes } from './update-routes.ts'
|
|
24
34
|
|
|
25
35
|
declare module '@deepseek-ai/cordis' {
|
|
26
36
|
interface Events {
|
|
@@ -215,10 +225,50 @@ export function apply(ctx: Context, config?: Config): void {
|
|
|
215
225
|
if (apiProxy === undefined) {
|
|
216
226
|
console.warn('remote-web-ui: apiProxy service unavailable — the mobile data channel is disabled')
|
|
217
227
|
}
|
|
228
|
+
// ── remote update ────────────────────────────────────────────────────────
|
|
229
|
+
// The dsh-web-ui self-update surface: probe the npm registry for family
|
|
230
|
+
// releases and run `pnpm update` in the owning profile. Resolutions anchor
|
|
231
|
+
// on the host process's own module graph, so the update always targets the
|
|
232
|
+
// profile the running web GUI was booted from. The probe path resolves once
|
|
233
|
+
// (the anchor stays the same package across updates); versions are re-read
|
|
234
|
+
// from disk per check.
|
|
235
|
+
const requireFromHost = createRequire(import.meta.url)
|
|
236
|
+
const anchorManifestPath = resolveAnchorManifest(specifier => requireFromHost.resolve(specifier))
|
|
237
|
+
const updateRoutes = makeUpdateRoutes({
|
|
238
|
+
// Control endpoints are host-surface only: a LAN/phone origin must never
|
|
239
|
+
// trigger a real install on this machine.
|
|
240
|
+
fence: request => isTrustedApiRequest(request, []),
|
|
241
|
+
check: () => checkUpdates({
|
|
242
|
+
anchorManifestPath,
|
|
243
|
+
resolve: specifier => {
|
|
244
|
+
try {
|
|
245
|
+
return requireFromHost.resolve(specifier)
|
|
246
|
+
} catch {
|
|
247
|
+
return undefined
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
fetchLatest: name => fetchLatestVersion(name, fetch),
|
|
251
|
+
}),
|
|
252
|
+
run: async (): Promise<UpdateRunResult> => {
|
|
253
|
+
const target = resolveUpdateTarget({ anchorManifestPath })
|
|
254
|
+
if ('error' in target) {
|
|
255
|
+
const code = target.error
|
|
256
|
+
return {
|
|
257
|
+
ok: false,
|
|
258
|
+
exitCode: null,
|
|
259
|
+
output: '',
|
|
260
|
+
error: code === 'not-found' ? 'dsh-web-ui aggregate not installed' : 'local link install — update unavailable',
|
|
261
|
+
errorCode: code,
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return runUpdate({ profileDir: target.profileDir, packages: target.packages })
|
|
265
|
+
},
|
|
266
|
+
})
|
|
218
267
|
const routes = [
|
|
219
268
|
...makeRoutes({ service, lanAddresses }),
|
|
220
269
|
...makeMobileRoutes(),
|
|
221
270
|
...(apiProxy !== undefined ? makeMobileApiRoutes({ service, apiProxy }) : []),
|
|
271
|
+
...updateRoutes,
|
|
222
272
|
]
|
|
223
273
|
const gate = makeGateListener(service, () => resolve().requirePairingForLan, () => resolve().enabled)
|
|
224
274
|
ctx.effect(() => ctx.on('api/gate', gate), 'remote-web-ui: api gate')
|
package/src/routes.ts
CHANGED
|
@@ -27,7 +27,7 @@ import { isLoopbackClient, readCookie } from './gate.ts'
|
|
|
27
27
|
* @returns true when the Host is ours (loopback or trusted) and any attached
|
|
28
28
|
* browser markers are same-origin.
|
|
29
29
|
*/
|
|
30
|
-
function isTrustedApiRequest(request: IncomingMessage, trustedHosts: readonly string[]): boolean {
|
|
30
|
+
export function isTrustedApiRequest(request: IncomingMessage, trustedHosts: readonly string[]): boolean {
|
|
31
31
|
const host = request.headers.host
|
|
32
32
|
if (typeof host !== 'string') return false
|
|
33
33
|
let hostUrl: URL
|