Files
deepseek-harness/apps/web/src/main.ts
T
07akioni 93b832f1b0 Merge pull request #4459 from deepseek-harness/feat/desktop-onboarding
feat(desktop): add device-local account onboarding
2026-09-23 22:21:18 +08:00

41 lines
1.8 KiB
TypeScript

/** Browser entry for the Web client. */
import '@deepseek-ai/dsh-client-ui-theme/brand-font.css'
import { AppWebEntry, applyIndexInjections } from '@deepseek-ai/dsh-client-web'
interface DesktopBootGlobal {
dshDesktopBoot?: {
failed(message: string): Promise<void>
ready(): Promise<{ injections: Parameters<typeof applyIndexInjections>[0]; streamBaseUrl: string }>
}
}
const desktop = (globalThis as DesktopBootGlobal).dshDesktopBoot
const reportFailure = (reason: unknown): void => {
if (desktop === undefined) throw reason
void desktop.failed(reason instanceof Error ? reason.message : String(reason)).catch(console.error)
}
try {
const el = document.getElementById('root')
if (el === null) throw new Error('web app: missing #root')
const entry = new AppWebEntry(el)
if (desktop !== undefined) {
const gate = (globalThis as { __DSH_BOOT_READY__?: PromiseWithResolvers<void> }).__DSH_BOOT_READY__
if (gate === undefined) throw new Error('desktop web: boot readiness is missing')
void desktop.ready().then(async ({ injections, streamBaseUrl }) => {
const transport = globalThis as { __DSH_TRANSPORT__?: { ownsHost: boolean; streamBaseUrl: string } }
transport.__DSH_TRANSPORT__ = { ownsHost: true, streamBaseUrl }
await applyIndexInjections(injections, src => new Promise<void>((resolve, reject) => {
const script = document.createElement('script')
script.src = src
script.onload = () => { resolve() }
script.onerror = () => { reject(new Error(`desktop web: failed to load ${src}`)) }
document.head.append(script)
}))
gate.resolve()
}).catch((error: unknown) => { gate.reject(error) })
}
void entry.run(desktop === undefined ? undefined : reportFailure)
} catch (reason) {
reportFailure(reason)
}