main.ts 1.3 KB

1234567891011121314151617181920212223242526272829
  1. /** Browser entry for the Web client. */
  2. import { AppWebEntry, applyIndexInjections } from '@deepseek-ai/dsh-client-web'
  3. const el = document.getElementById('root')
  4. if (el === null) throw new Error('web app: missing #root')
  5. const entry = new AppWebEntry(el)
  6. interface DesktopBootGlobal {
  7. dshDesktopBoot?: {
  8. ready(): Promise<{ injections: Parameters<typeof applyIndexInjections>[0]; streamBaseUrl: string }>
  9. }
  10. }
  11. const desktop = (globalThis as DesktopBootGlobal).dshDesktopBoot
  12. if (desktop !== undefined) {
  13. const gate = (globalThis as { __DSH_BOOT_READY__?: PromiseWithResolvers<void> }).__DSH_BOOT_READY__
  14. if (gate === undefined) throw new Error('desktop web: boot readiness is missing')
  15. void desktop.ready().then(async ({ injections, streamBaseUrl }) => {
  16. const transport = globalThis as { __DSH_TRANSPORT__?: { ownsHost: boolean; streamBaseUrl: string } }
  17. transport.__DSH_TRANSPORT__ = { ownsHost: true, streamBaseUrl }
  18. await applyIndexInjections(injections, src => new Promise<void>((resolve, reject) => {
  19. const script = document.createElement('script')
  20. script.src = src
  21. script.onload = () => { resolve() }
  22. script.onerror = () => { reject(new Error(`desktop web: failed to load ${src}`)) }
  23. document.head.append(script)
  24. }))
  25. gate.resolve()
  26. }).catch((error: unknown) => { gate.reject(error) })
  27. }
  28. void entry.run()