@lincyaw/dsh 0.2.0-rc.100 → 0.2.0-rc.101

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.
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "inputs": [
3
+ "src/client/startup.ts",
3
4
  "../kernel/src/contracts/service.ts",
4
5
  "../kernel/src/contracts/agent.ts",
5
6
  "../kernel/src/contracts/agent-activity.ts",
@@ -259,14 +260,17 @@
259
260
  "../workbench/src/authoring-window.ts",
260
261
  "../workbench/src/agent-activity-messages.ts",
261
262
  "../workbench/src/AgentActivityBar.tsx",
263
+ "../workbench/src/mcp-settings-messages.ts",
264
+ "../workbench/src/panels/McpSettingsPanel.tsx",
262
265
  "../workbench/src/index.ts",
266
+ "src/client/messages.ts",
267
+ "src/client/settings-launcher.tsx",
263
268
  "src/workspace-events.ts",
264
269
  "src/client/workspace-events.ts",
265
270
  "src/client/contract.ts",
266
271
  "src/client/author-settings.ts",
267
272
  "src/client/speech-settings.tsx",
268
273
  "src/client/settings-opener.ts",
269
- "src/client/messages.ts",
270
274
  "src/client/brand.tsx",
271
275
  "src/client/document-context.ts",
272
276
  "src/client/observable.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/dsh",
3
- "version": "0.2.0-rc.100",
3
+ "version": "0.2.0-rc.101",
4
4
  "description": "Presmium's bundle for DeepSeek Harness: the workbench of presmium studio, its host side (Presmium's tools, approvals, document context, skills and routes) and its client side (the root layout and the workbench's panels, precompiled) (experimental)",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -86,10 +86,10 @@
86
86
  "node-addon-require-builtin": "0.1.9",
87
87
  "ws": "8.22.0",
88
88
  "zod": "4.4.3",
89
- "@lincyaw/cli": "1.0.0-rc.101",
90
- "@lincyaw/mcp": "1.0.0-rc.101",
91
- "@lincyaw/kernel": "1.0.0-rc.101",
92
- "@lincyaw/skills": "1.0.0-rc.101"
89
+ "@lincyaw/cli": "1.0.0-rc.102",
90
+ "@lincyaw/mcp": "1.0.0-rc.102",
91
+ "@lincyaw/kernel": "1.0.0-rc.102",
92
+ "@lincyaw/skills": "1.0.0-rc.102"
93
93
  },
94
94
  "peerDependencies": {
95
95
  "@deepseek-ai/dsh": "0.2.1-alpha.4"
@@ -105,8 +105,8 @@
105
105
  "react": "18.3.1",
106
106
  "react-dom": "18.3.1",
107
107
  "react-resizable-panels": "^4.14.5",
108
- "@lincyaw/design": "1.0.0-rc.101",
109
- "@lincyaw/workbench": "0.2.0-rc.101"
108
+ "@lincyaw/design": "1.0.0-rc.102",
109
+ "@lincyaw/workbench": "0.2.0-rc.102"
110
110
  },
111
111
  "scripts": {}
112
112
  }
@@ -1,8 +1,10 @@
1
+ import { useStartupReady } from './startup.ts'
1
2
  import { Group, Panel, Separator, usePanelRef } from 'react-resizable-panels'
2
3
  import { AgentActivityBar, DocumentView, HomePanel, PmDialog, PmIcon, PmMenu, SHORTCUTS, useWorkbenchState, WorkbenchApprovals, WorkbenchProvider } from '@lincyaw/workbench'
3
4
  import type { Workbench } from '@lincyaw/workbench'
4
5
  import { useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
5
6
  import type { ReactNode, RefObject } from 'react'
7
+ import { openMcpSettings } from './settings-opener.ts'
6
8
  import { Logo } from './brand.tsx'
7
9
  import { mainViewAgentSession } from './document-context.ts'
8
10
  import { centreMinWidth, clamp, CONVERSATION_MAX, CONVERSATION_MIN, singlePaneWidth, RIGHTBAR_MAX_RATIO, RIGHTBAR_MIN, rightbarRoom, SIDE_COLLAPSE, SIDE_MAX, SIDE_MIN } from './layout.ts'
@@ -136,6 +138,7 @@ function RootLayout({ useStore, useSessions, usePanelInfo, actions, renderSlot,
136
138
  const info = useStore(state => state.layoutInfo)
137
139
  const activePanel = usePanelInfo(panel => panel.activePanelId)
138
140
  const t = useClientMessages(workbench)
141
+ useStartupReady(workbench)
139
142
  const document_ = useWorkbenchState(state => state.document)
140
143
  const retainedDocument = useRef(false)
141
144
  if (document_ !== undefined) retainedDocument.current = true
@@ -318,15 +321,14 @@ function AppBar({ workbench, info, actions, activePanel, globalPanels, pane, nar
318
321
  {working && <span className="pmw-appbar__busy" aria-hidden="true" />}
319
322
  </button>
320
323
  <span className="pmw-appbar__divider" aria-hidden="true" />
321
- {more.length > 0 && (
322
- <span className="pmw-appbar__more" data-activity="more">
323
- <PmMenu label={t.more} items={more} onSelect={(id) => {
324
- actions.selectPanel(activePanel === id ? null : id)
325
- if (narrow) actions.showNarrowPane('documents')
326
- }} />
327
- </span>
328
- )}
329
- <button type="button" className="pmw-appbar__button" data-activity="settings" aria-label={t.settings} title={t.settings} onClick={openSettings}><PmIcon name="sliders" /></button>
324
+ <span className="pmw-appbar__more" data-activity="settings">
325
+ <PmMenu label={t.settings} icon="sliders" items={[{ id: 'presmium-settings', label: t.preferences }, { id: 'presmium-mcp', label: t.mcp }, ...more]} onSelect={id => {
326
+ if (id === 'presmium-settings') { openSettings(); return }
327
+ if (id === 'presmium-mcp') { if (!openMcpSettings()) openSettings(); return }
328
+ actions.selectPanel(activePanel === id ? null : id)
329
+ if (narrow) actions.showNarrowPane('documents')
330
+ }} />
331
+ </span>
330
332
  <button type="button" className="pmw-appbar__button" data-activity="help" aria-label={t.help} title={t.help} onClick={openHelp}><PmIcon name="help" /></button>
331
333
  </nav>
332
334
  )
@@ -1,3 +1,4 @@
1
+ import { useStartupReady } from './startup.ts'
1
2
  import { AgentActivityBar, DocumentView, HistoryPanel, HomePanel, PreviewPanel, useWorkbench, useWorkbenchState, WorkbenchProvider, WorkbenchApprovals } from '@lincyaw/workbench'
2
3
  import type { Workbench } from '@lincyaw/workbench'
3
4
  import { useRef } from 'react'
@@ -11,6 +12,7 @@ export const FALLBACK_PANEL = 'presmium'
11
12
 
12
13
  function Centre() {
13
14
  const workbench = useWorkbench()
15
+ useStartupReady(workbench)
14
16
  const document_ = useWorkbenchState(state => state.document)
15
17
  const retainedDocument = useRef(false)
16
18
  if (document_ !== undefined) retainedDocument.current = true
@@ -1,3 +1,4 @@
1
+ import { openAppSettings, registerSettingsLauncher } from './settings-launcher.tsx'
1
2
  import { connectAgentActivity, connectAuthoringClient, connectAuthoringWindow, localeOf, Workbench, workspaceClient } from '@lincyaw/workbench'
2
3
  import type { Locale } from '@lincyaw/workbench'
3
4
  import { workspaceSubscriptions } from './workspace-events.ts'
@@ -76,6 +77,8 @@ export function apply(ctx: DshClientContext): void {
76
77
  }, 'presmium: light and dark')
77
78
 
78
79
  if (nativeLayout) {
80
+ // Its default conversation view does not mount HomePanel, so the host owns this first read.
81
+ void workbench.loadDocuments()
79
82
  registerFallbackLayout(ctx, workbench)
80
83
  } else {
81
84
  ctx.effect(() => {
@@ -103,10 +106,7 @@ export function apply(ctx: DshClientContext): void {
103
106
  subscribe: listener => instance.subscribe(listener),
104
107
  })
105
108
  showEditor = () => layout.showDocument()
106
- const openSettings = () => {
107
- const triggers = document.querySelectorAll<HTMLElement>('[data-pmw-slot="sidebar"] button[aria-haspopup="dialog"]')
108
- triggers[triggers.length - 1]?.click()
109
- }
109
+ const openSettings = openAppSettings
110
110
  const disposePanelInfo = ctx.slots.provideRoot({ hooks: { panelInfo: layout.panelInfo } })
111
111
  const disposeRoot = ctx.slots.register({ name: 'root', locale: 'common', children: {
112
112
  ...ROOT_CHILDREN,
@@ -150,6 +150,7 @@ export function apply(ctx: DshClientContext): void {
150
150
  }
151
151
  registerBrand(ctx, workbench)
152
152
  registerAuthorSettings(ctx)
153
+ registerSettingsLauncher(ctx, workbench)
153
154
  registerSpeechSettings(ctx, workbench)
154
155
  ctx.inject(['layout'], inner => inner.effect(() => connectLaunchTarget(workbench,
155
156
  () => nativeLayout ? () => {} : restoreRootReturnPoint(workbench, reload.point),
@@ -17,6 +17,8 @@ const zh = {
17
17
  preview: '文稿',
18
18
  history: '版本历史',
19
19
  settings: '设置',
20
+ preferences: '通用设置',
21
+ mcp: 'MCP 连接',
20
22
  help: '帮助',
21
23
  close: '关闭',
22
24
  toggleSide: '显示或隐藏对话记录',
@@ -89,6 +91,8 @@ const en: ClientMessages = {
89
91
  preview: 'Document',
90
92
  history: 'Version History',
91
93
  settings: 'Settings',
94
+ preferences: 'General Settings',
95
+ mcp: 'MCP Connection',
92
96
  help: 'Help',
93
97
  close: 'Close',
94
98
  toggleSide: 'Show or Hide Chat History',
@@ -221,7 +221,7 @@ export function RuntimeDiagnosticsNotice({ workbench, fatal = false }: { workben
221
221
  export class WorkbenchRuntimeBoundary extends Component<{ workbench: Workbench, children: ReactNode }, { failed: boolean }> {
222
222
  state = { failed: false }
223
223
  static getDerivedStateFromError() { return { failed: true } }
224
- componentDidCatch(error: Error): void { runtimeDiagnostics(this.props.workbench).capture(error) }
224
+ componentDidCatch(error: Error): void { runtimeDiagnostics(this.props.workbench).capture(error); window.dispatchEvent(new Event('presmium:startup-failed')) }
225
225
  render() {
226
226
  return this.state.failed ? <main className="pmw-runtime-fallback pm-ui"><RuntimeDiagnosticsNotice workbench={this.props.workbench} fatal /></main> : this.props.children
227
227
  }
@@ -0,0 +1,19 @@
1
+ import { useStartupReady } from './startup.ts'
2
+ import { useLayoutEffect } from 'react'
3
+ import { PmIconButton } from '@lincyaw/workbench'
4
+ import type { Workbench } from '@lincyaw/workbench'
5
+ import { CLIENT_MESSAGES } from './messages.ts'
6
+
7
+ let current: (() => void) | undefined
8
+ /** Public settings.launcher contract; no hidden sidebar DOM or dependency internals. */
9
+ export function openAppSettings(): void { current?.() }
10
+ export function registerSettingsLauncher(ctx: DshClientContext, workbench: Workbench): void {
11
+ ctx.effect(() => ctx.slots.inject('settings.launcher', () => ctx.slots.register({ name: 'settings.launcher' }, function SettingsLauncher({ openSettings }: { openSettings(): void }) {
12
+ useStartupReady(workbench)
13
+ useLayoutEffect(() => {
14
+ current = openSettings
15
+ return () => { if (current === openSettings) current = undefined }
16
+ }, [openSettings])
17
+ return <PmIconButton icon="sliders" label={CLIENT_MESSAGES[workbench.state.locale].settings} onClick={openSettings} />
18
+ })), 'presmium: settings launcher')
19
+ }
@@ -24,3 +24,9 @@ export function openSpeechSettings(): boolean {
24
24
  remembered('presmium-speech')
25
25
  return true
26
26
  }
27
+
28
+ export function openMcpSettings(): boolean {
29
+ if (!remembered) return false
30
+ remembered('presmium-mcp')
31
+ return true
32
+ }
@@ -1,7 +1,8 @@
1
- import { SpeechSettingsPanel, SPEECH_SETTINGS_MESSAGES, WorkbenchProvider } from '@lincyaw/workbench'
1
+ import { McpSettingsPanel, MCP_SETTINGS_MESSAGES, SpeechSettingsPanel, SPEECH_SETTINGS_MESSAGES, WorkbenchProvider } from '@lincyaw/workbench'
2
2
  import type { Workbench } from '@lincyaw/workbench'
3
3
 
4
4
  /** The framework owns Settings navigation; Presmium owns its operator service page. */
5
5
  export function registerSpeechSettings(ctx: DshClientContext, workbench: Workbench): void {
6
+ ctx.effect(() => ctx.slots.inject('settings.section', () => ctx.slots.register({ name: 'settings.section', id: 'presmium-mcp', order: 40, label: () => MCP_SETTINGS_MESSAGES[workbench.state.locale].title }, () => <WorkbenchProvider workbench={workbench}><McpSettingsPanel /></WorkbenchProvider>)), 'presmium: MCP connection settings')
6
7
  ctx.effect(() => ctx.slots.inject('settings.section', () => ctx.slots.register({ name: 'settings.section', id: 'presmium-speech', order: 30, label: () => SPEECH_SETTINGS_MESSAGES[workbench.state.locale].title }, () => <WorkbenchProvider workbench={workbench}><SpeechSettingsPanel /></WorkbenchProvider>)), 'presmium: voice service settings')
7
8
  }
@@ -0,0 +1,47 @@
1
+ .pm-startup {
2
+ position: fixed;
3
+ inset: 0;
4
+ width: 100%;
5
+ height: 100%;
6
+ max-width: none;
7
+ max-height: none;
8
+ margin: 0;
9
+ border: 0;
10
+ z-index: var(--pm-z-startup);
11
+ display: grid;
12
+ place-items: center;
13
+ box-sizing: border-box;
14
+ padding: var(--pm-space-6);
15
+ background: var(--pm-color-bg);
16
+ color: var(--pm-color-ink);
17
+ font-family: var(--pm-font-sans);
18
+ font-size: var(--pm-text-sm);
19
+ }
20
+ .pm-startup__content {
21
+ display: grid;
22
+ justify-items: center;
23
+ gap: var(--pm-space-3);
24
+ max-width: var(--pm-dialog-width);
25
+ text-align: center;
26
+ }
27
+ .pm-startup__brand {
28
+ display: flex;
29
+ align-items: center;
30
+ gap: var(--pm-space-3);
31
+ margin: 0;
32
+ font-size: var(--pm-text-lg);
33
+ font-weight: var(--pm-weight-semibold);
34
+ }
35
+ .pm-startup__brand svg { width: var(--pm-size-logo); height: var(--pm-size-logo); }
36
+ .pm-startup__status, .pm-startup__actions {
37
+ display: flex;
38
+ align-items: center;
39
+ justify-content: center;
40
+ flex-wrap: wrap;
41
+ gap: var(--pm-space-2);
42
+ }
43
+ .pm-startup__status { margin: 0; color: var(--pm-color-muted); }
44
+ .pm-startup__status svg { width: var(--pm-size-icon); height: var(--pm-size-icon); }
45
+
46
+ .pm-startup__spinner { display: inline-flex; }
47
+ .pm-startup:target { display: none; }
@@ -0,0 +1,17 @@
1
+ import { useEffect, useSyncExternalStore } from 'react'
2
+ import type { Workbench } from '@lincyaw/workbench'
3
+
4
+ /** A committed shell plus its usable document list ends the product startup screen; AI history is independent. */
5
+ export function useStartupReady(workbench: Workbench): void {
6
+ const ready = useSyncExternalStore(workbench.subscribe, () => Boolean(workbench.state.documents || workbench.state.documentsFailure))
7
+ const locale = useSyncExternalStore(workbench.subscribe, () => workbench.state.locale)
8
+ const dark = useSyncExternalStore(workbench.subscribe, () => workbench.state.isDark)
9
+ useEffect(() => {
10
+ if (!ready) return
11
+ try {
12
+ localStorage.setItem('presmium.startup.locale', locale)
13
+ localStorage.setItem('presmium.startup.dark', String(dark))
14
+ } catch { /* Storage is optional. */ }
15
+ window.dispatchEvent(new Event('presmium:workspace-ready'))
16
+ }, [ready, locale, dark])
17
+ }
@@ -166,16 +166,32 @@ export function writeProfile(dshHome: string, name: string, carrier: Carrier, bu
166
166
  const dir = join(dshHome, 'profiles', name)
167
167
  mkdirSync(join(dir, 'node_modules', '@lincyaw'), { recursive: true })
168
168
  mkdirSync(join(dshHome, 'agents'), { recursive: true })
169
- writeFileSync(join(dir, 'package.json'), `${JSON.stringify({
169
+ const writeChanged = (file: string, content: string) => {
170
+ if (!existsSync(file) || readFileSync(file, 'utf8') !== content) writeFileSync(file, content)
171
+ }
172
+ const manifestFile = join(dir, 'package.json')
173
+ const saved = existsSync(manifestFile) ? JSON.parse(readFileSync(manifestFile, 'utf8')) : {}
174
+ if (!saved || typeof saved !== 'object' || Array.isArray(saved)) throw new TypeError('Invalid profile package manifest')
175
+ const required = ['@deepseek-ai/dsh-base', CARRIERS[carrier], PACKAGE_NAME]
176
+ const extra = Array.isArray(saved.dsh?.profile?.bundles) ? saved.dsh.profile.bundles.filter((bundle: unknown) => typeof bundle === 'string' && !required.includes(bundle) && !Object.values(CARRIERS).includes(bundle as string)) : []
177
+ writeChanged(manifestFile, `${JSON.stringify({
178
+ ...saved,
170
179
  name: `dsh-profile-${name}`,
171
180
  private: true,
172
- dependencies: {},
173
- dsh: { profile: { bundles: ['@deepseek-ai/dsh-base', CARRIERS[carrier], PACKAGE_NAME] } },
181
+ dependencies: saved.dependencies ?? {},
182
+ dsh: { ...saved.dsh, profile: { ...saved.dsh?.profile, bundles: [...required, ...extra] } },
174
183
  }, null, 2)}\n`)
175
- writeFileSync(join(dir, 'cordis.yml'), '# The profile root: an empty entry list; the tree is composed from the bundles and the patches.\n[]\n')
184
+ const root = join(dir, 'cordis.yml')
185
+ // The Host normalizes this root's comments; keep its file and the author's installed plugins intact.
186
+ if (!existsSync(root)) writeFileSync(root, '# The profile root: an empty entry list; the tree is composed from the bundles and the patches.\n[]\n')
176
187
  if (!existsSync(join(dir, 'cordis.patch.yml'))) writeFileSync(join(dir, 'cordis.patch.yml'), '# Your patch layer for this profile (Presmium\'s settings are passed with --patch after it).\n[]\n')
177
188
  const link = join(dir, 'node_modules', PACKAGE_NAME)
178
- rmSync(link, { force: true, recursive: true })
179
- symlinkSync(realpathSync(bundle), link, 'junction')
189
+ const target = realpathSync(bundle)
190
+ let current: string | undefined
191
+ try { current = realpathSync(link) } catch {}
192
+ if (current !== target) {
193
+ rmSync(link, { force: true, recursive: true })
194
+ symlinkSync(target, link, 'junction')
195
+ }
180
196
  return dir
181
197
  }
@@ -5,6 +5,7 @@ export const name = 'presmium-routes'
5
5
  export const inject = ['presmium', 'connection']
6
6
 
7
7
  export const ROUTES: Record<string, string> = Object.fromEntries([
8
+ ['mcp-settings', `${WORKSPACE_ROUTES}mcp-settings`],
8
9
  ['speech-settings', `${WORKSPACE_ROUTES}speech-settings`],
9
10
  ...['project/capabilities', 'project/plan', 'project/apply', 'documents', 'document', 'document/capabilities', 'document/outline', 'document/part', 'document/page/plan', 'document/page/apply', 'document/action/plan', 'document/action/impact', 'document/action/apply', 'document/asset', 'document/events', 'document/change', 'document/image', 'document/audio', 'document/recording/adopt', 'document/media-clip', 'files', 'source', 'source/create', 'source/transaction', 'changes', 'changes/commit', 'changes/discard', 'revisions', 'revisions/revert', 'history/list', 'history/file', 'history/undo', 'history/redo',
10
11
  'document/media-clip/validate', 'document/transcription/capabilities', 'document/transcription', 'document/transcription/result', 'document/transcription/cancel',
@@ -0,0 +1,73 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { readFileSync } from 'node:fs'
3
+ import { createRequire } from 'node:module'
4
+ import { brandMarkup, iconMarkup } from '@lincyaw/design'
5
+ import { STARTUP_MESSAGES } from '../startup-messages.ts'
6
+
7
+ const require = createRequire(import.meta.url)
8
+ let assets: { css: string, script: string, version: string } | undefined
9
+ export function startupAssets(): { css: string, script: string, version: string } {
10
+ if (!assets) {
11
+ const css = readFileSync(require.resolve('@lincyaw/design/tokens.css'), 'utf8') + '\n'
12
+ + readFileSync(require.resolve('@lincyaw/design/components.css'), 'utf8') + '\n'
13
+ + readFileSync(new URL('../client/startup.css', import.meta.url), 'utf8')
14
+ const script = `(${installStartup.toString()})(${JSON.stringify(STARTUP_MESSAGES)})`
15
+ assets = { css, script, version: createHash('sha256').update(css).update(script).digest('hex').slice(0, 16) }
16
+ }
17
+ return assets
18
+ }
19
+
20
+ /** Runs before the framework entry. Only our own ready event hands over the page; there is no timed dismissal. */
21
+ function installStartup(catalog: typeof STARTUP_MESSAGES) {
22
+ const cover = document.getElementById('presmium-startup') as HTMLDialogElement
23
+ const message = cover.querySelector<HTMLElement>('[data-startup-message]')!
24
+ const retry = cover.querySelector<HTMLButtonElement>('[data-startup-retry]')!
25
+ const retrySlot = retry.parentElement!
26
+ const spinner = cover.querySelector<HTMLElement>('[data-startup-spinner]')!
27
+ const details = cover.querySelector<HTMLAnchorElement>('[data-startup-details]')!
28
+ let language = document.documentElement.lang || navigator.language
29
+ let dark = matchMedia('(prefers-color-scheme: dark)').matches
30
+ try {
31
+ language = localStorage.getItem('presmium.startup.locale') || language
32
+ const saved = localStorage.getItem('presmium.startup.dark')
33
+ if (saved !== null) dark = saved === 'true'
34
+ } catch { /* Startup works without browser storage. */ }
35
+ document.documentElement.classList.toggle('dark', dark)
36
+ const t = catalog[language.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en']
37
+ message.textContent = t.opening; retry.textContent = t.retry; details.textContent = t.details
38
+ // Browser-owned modal isolation never overwrites the framework's own inert/aria ownership.
39
+ if (typeof cover.showModal === 'function') { if (cover.open) cover.close(); cover.showModal() }
40
+ cover.addEventListener('cancel', event => event.preventDefault())
41
+ let ended = false
42
+ const release = () => {
43
+ if (ended) return
44
+ ended = true; clearTimeout(timer)
45
+ window.removeEventListener('error', failed, true)
46
+ window.removeEventListener('unhandledrejection', failed)
47
+ window.removeEventListener('presmium:workspace-ready', ready)
48
+ window.removeEventListener('presmium:startup-failed', failed)
49
+ if (cover.open) cover.close()
50
+ cover.remove()
51
+ }
52
+ const ready = () => {
53
+ document.documentElement.dataset.pmStartupReadyMs = String(Math.round(performance.now()))
54
+ release()
55
+ }
56
+ const failed = () => { if (ended) return; message.textContent = t.failed; retrySlot.hidden = false; spinner.hidden = true; message.setAttribute('role', 'alert') }
57
+ const timer = window.setTimeout(() => { if (!ended) { message.textContent = t.slow; retrySlot.hidden = false } }, 30_000)
58
+ retry.addEventListener('click', () => location.reload())
59
+ // The untouched framework report is an explicit diagnostic escape, including an early boot/import failure.
60
+ details.addEventListener('click', event => { event.preventDefault(); release() })
61
+ window.addEventListener('presmium:workspace-ready', ready)
62
+ window.addEventListener('presmium:startup-failed', failed)
63
+ window.addEventListener('error', failed, true)
64
+ window.addEventListener('unhandledrejection', failed)
65
+ }
66
+
67
+ export function startupIndex(html: string): string {
68
+ const { version } = startupAssets()
69
+ const initial = STARTUP_MESSAGES[/<html[^>]*lang=["']zh/i.test(html) ? 'zh-CN' : 'en']
70
+ const cover = `<dialog open id="presmium-startup" class="pm-startup pm-ui" aria-labelledby="presmium-startup-title"><div class="pm-startup__content"><h1 id="presmium-startup-title" class="pm-startup__brand">${brandMarkup()}<span>Presmium Studio</span></h1><p class="pm-startup__status" role="status" aria-live="polite"><span data-startup-spinner aria-hidden="true"><span class="pm-ui-loading pm-startup__spinner">${iconMarkup('loading')}</span></span><span data-startup-message>${initial.opening}</span></p><div class="pm-startup__actions"><span hidden><button type="button" class="pm-ui-button pm-ui-button--ghost" data-density="compact" data-startup-retry>${initial.retry}</button></span><a href="#presmium-startup" class="pm-ui-button pm-ui-button--ghost" data-density="compact" data-startup-details>${initial.details}</a></div></div></dialog>`
71
+ return html.replace('</head>', `<link rel="stylesheet" href="api/presmium/startup.css?v=${version}"></head>`)
72
+ .replace(/<body([^>]*)>/, `<body$1>${cover}<script src="api/presmium/startup.js?v=${version}"></script>`)
73
+ }
@@ -1,3 +1,4 @@
1
+ import { startupAssets, startupIndex } from './startup.ts'
1
2
  import { LOCAL_AUTHOR } from '@lincyaw/kernel'
2
3
  import type { DshContext, DshOtelScalar } from './dsh-types.ts'
3
4
  import type { OperationClient, OperationRecord, PresmiumTelemetry } from './telemetry.ts'
@@ -8,10 +9,10 @@ export const inject = ['presmium', 'connection', 'webServer', 'presmiumTelemetry
8
9
  const ICON = `data:image/svg+xml,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="7" fill="#0F5F5C"/><path d="M11 8h7.5a6.5 6.5 0 0 1 0 13H15v4h-4zM15 12v5h3.5a2.5 2.5 0 0 0 0-5z" fill="#F7F5F0" fill-rule="evenodd"/></svg>')}`
9
10
 
10
11
  export function brandIndex(html: string): string {
11
- return html
12
+ return startupIndex(html
12
13
  .replace(/<title>[^<]*<\/title>/, '<title>Presmium</title>')
13
14
  .replace(/<link rel="(?:icon|manifest)"[^>]*>\s*/g, '')
14
- .replace('</head>', `<link rel="icon" type="image/svg+xml" href="${ICON}" />\n</head>`)
15
+ .replace('</head>', `<link rel="icon" type="image/svg+xml" href="${ICON}" />\n</head>`))
15
16
  }
16
17
 
17
18
  interface WebServer {
@@ -48,6 +49,12 @@ export function readOperations(body: unknown): { client: OperationClient, record
48
49
 
49
50
  export function apply(ctx: DshContext & { webServer: WebServer, presmiumTelemetry: PresmiumTelemetry }): void {
50
51
  ctx.effect(() => ctx.webServer.tapIndex(brandIndex))
52
+ ctx.connection.fetch.register({ path: '/api/presmium/startup.js', methods: ['GET'], requestBody: 'buffered', async fetch() {
53
+ return new Response(startupAssets().script, { headers: { 'content-type': 'text/javascript; charset=utf-8', 'cache-control': 'public, max-age=31536000, immutable' } })
54
+ } })
55
+ ctx.connection.fetch.register({ path: '/api/presmium/startup.css', methods: ['GET'], requestBody: 'buffered', async fetch() {
56
+ return new Response(startupAssets().css, { headers: { 'content-type': 'text/css; charset=utf-8', 'cache-control': 'public, max-age=31536000, immutable' } })
57
+ } })
51
58
  ctx.connection.fetch.register({
52
59
  path: '/api/presmium/context', methods: ['POST'], requestBody: 'buffered',
53
60
  async fetch(request) {
@@ -0,0 +1,15 @@
1
+ const zh = {
2
+ opening: '正在打开工作区…',
3
+ failed: '无法打开工作区。可以重试,或查看详细信息。',
4
+ slow: '打开工作区所需时间较长,你可以继续等待或重试。',
5
+ retry: '重试', details: '详细信息',
6
+ }
7
+ export const STARTUP_MESSAGES = {
8
+ 'zh-CN': zh,
9
+ en: {
10
+ opening: 'Opening your workspace…',
11
+ failed: 'The workspace could not open. Retry or view details.',
12
+ slow: 'Opening the workspace is taking longer than usual. You can keep waiting or retry.',
13
+ retry: 'Retry', details: 'Details',
14
+ } satisfies typeof zh,
15
+ }