moi-computer 0.12.1-next.1 → 0.12.1-next.3

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.
Files changed (123) hide show
  1. package/client/AGENTS.md +3 -2
  2. package/client/api/app-config.ts +3 -9
  3. package/client/api/workspace-keys.ts +2 -1
  4. package/client/app/app-provider.tsx +25 -0
  5. package/client/app/app-router.tsx +2 -0
  6. package/client/app/routes/settings-route.tsx +10 -0
  7. package/client/app/routes/workspace-route.tsx +4 -0
  8. package/client/app/shell/sidebar-layout.tsx +38 -51
  9. package/client/dev/index.html +5 -5
  10. package/client/features/account/account-menu.tsx +96 -0
  11. package/client/features/account/account-provider.tsx +142 -0
  12. package/client/features/account/account-test-utils.tsx +293 -0
  13. package/client/features/account/api.ts +142 -0
  14. package/client/features/account/identity.ts +23 -0
  15. package/client/features/applets/api.ts +1 -1
  16. package/client/features/chat/connection/chat-frames.ts +2 -2
  17. package/client/features/chat/sessions/api.ts +1 -1
  18. package/client/features/chat/use-chat.ts +1 -1
  19. package/client/features/collab/applet-api.ts +15 -14
  20. package/client/features/collab/components/cursors.tsx +61 -24
  21. package/client/features/collab/components/presence-avatars.tsx +25 -12
  22. package/client/features/collab/components/presence-frame.tsx +20 -24
  23. package/client/features/collab/components/presence-group.tsx +15 -7
  24. package/client/features/collab/components/user-avatar-group.tsx +21 -8
  25. package/client/features/collab/components/user-avatar.tsx +38 -7
  26. package/client/features/collab/components/user.tsx +31 -12
  27. package/client/features/collab/host-state.ts +24 -7
  28. package/client/features/collab/local-user.ts +1 -1
  29. package/client/features/collab/proxy-user.ts +4 -9
  30. package/client/features/collab/users.ts +0 -5
  31. package/client/features/collab/workspace-users-menu.tsx +3 -3
  32. package/client/features/demo/demo-dialog.tsx +25 -79
  33. package/client/features/dev/collab/collab-playground.tsx +7 -7
  34. package/client/features/dev/collab/local-user-settings.tsx +7 -53
  35. package/client/features/dev/workspace-setup-preview.tsx +43 -16
  36. package/client/features/harness/device-login-steps.tsx +2 -2
  37. package/client/features/home/api.ts +29 -9
  38. package/client/features/home/home-page.tsx +7 -4
  39. package/client/features/scratchpad/scratchpad.tsx +3 -6
  40. package/client/features/settings/api.ts +14 -8
  41. package/client/features/settings/connectors-settings.tsx +3 -3
  42. package/client/features/settings/environment-settings.tsx +3 -3
  43. package/client/features/settings/general-settings.tsx +1 -1
  44. package/client/features/settings/profile-settings.tsx +95 -0
  45. package/client/features/settings/settings-page.tsx +44 -0
  46. package/client/features/settings/settings-section.tsx +26 -0
  47. package/client/features/settings/users-settings.tsx +195 -0
  48. package/client/features/update/update-control.tsx +1 -1
  49. package/client/features/workspace/add/create-workspace-dialog.tsx +5 -2
  50. package/client/features/workspace/api.ts +12 -16
  51. package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
  52. package/client/features/workspace/setup/workspace-setup.tsx +2 -1
  53. package/client/features/workspace/workspace-content.tsx +12 -52
  54. package/client/features/workspace/workspace-frame.tsx +76 -0
  55. package/client/features/workspace/workspace-layout-context.tsx +2 -0
  56. package/client/features/workspace/workspace-pending-screen.tsx +26 -0
  57. package/client/features/workspace/workspace-screen.tsx +3 -3
  58. package/client/index.html +28 -9
  59. package/client/index.tsx +7 -2
  60. package/client/lib/browser-tab-id.ts +4 -0
  61. package/client/lib/user-display-name.ts +6 -0
  62. package/client/main.tsx +12 -6
  63. package/client/runtime/app-context.ts +20 -0
  64. package/client/runtime/use-workspace-events.ts +29 -153
  65. package/client/runtime/workspace-events.ts +151 -0
  66. package/dist/chunk-20ynagd4.js +2 -0
  67. package/dist/chunk-42tde9a6.js +1 -0
  68. package/dist/chunk-9w543s0r.js +2 -0
  69. package/dist/{chunk-q0gbdts4.js → chunk-a5372n61.js} +71 -71
  70. package/dist/chunk-aja9y1vn.js +68 -0
  71. package/dist/chunk-fvcvrh3d.css +1 -0
  72. package/dist/chunk-gtfjw3nx.js +1 -0
  73. package/dist/{chunk-hvh9f5h0.js → chunk-j39y2aky.js} +1 -1
  74. package/dist/chunk-pja30km3.js +1 -0
  75. package/dist/{chunk-d7cbm65e.js → chunk-rm894bc2.js} +1 -1
  76. package/dist/chunk-tevvtfbk.js +10 -0
  77. package/dist/{chunk-jvyvwwv3.js → chunk-tgt9zd0r.js} +1 -1
  78. package/dist/chunk-tv5k5z00.js +1 -0
  79. package/dist/chunk-zq2ae5dx.js +2 -0
  80. package/dist/index.html +29 -10
  81. package/lib/ids.ts +2 -2
  82. package/lib/types.ts +1 -1
  83. package/package.json +1 -1
  84. package/server/api/index.ts +43 -28
  85. package/server/app-config.ts +7 -0
  86. package/server/applets/thumbnails.ts +8 -5
  87. package/server/harness/codex/thread-list.ts +4 -0
  88. package/server/static.ts +4 -2
  89. package/server/vendor.ts +23 -30
  90. package/server/web.ts +4 -2
  91. package/server/workspaces/init.ts +0 -10
  92. package/server/workspaces/layout.ts +11 -6
  93. package/server/workspaces/registry.ts +31 -9
  94. package/dist/chunk-08ndj2rg.js +0 -2
  95. package/dist/chunk-2x040tmg.js +0 -68
  96. package/dist/chunk-3smxq0ts.js +0 -1
  97. package/dist/chunk-68ch5hs8.js +0 -2
  98. package/dist/chunk-9vg3xa81.js +0 -2
  99. package/dist/chunk-c2p00p9j.css +0 -1
  100. package/dist/chunk-cs833y9j.js +0 -1
  101. package/dist/chunk-nwevqe86.js +0 -10
  102. package/dist/chunk-rt30jbcm.js +0 -1
  103. package/dist/chunk-y5y3kj67.js +0 -1
  104. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-dom-client.js +0 -0
  105. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-dom.js +0 -0
  106. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-jsx-dev-runtime.js +0 -0
  107. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-jsx-runtime.js +0 -0
  108. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react.js +0 -0
  109. /package/client/vendor/react/{development → 19.2.4/development}/react-dom-client.js +0 -0
  110. /package/client/vendor/react/{development → 19.2.4/development}/react-dom.js +0 -0
  111. /package/client/vendor/react/{development → 19.2.4/development}/react-jsx-dev-runtime.js +0 -0
  112. /package/client/vendor/react/{development → 19.2.4/development}/react-jsx-runtime.js +0 -0
  113. /package/client/vendor/react/{development → 19.2.4/development}/react.js +0 -0
  114. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-dom-client.js +0 -0
  115. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-dom.js +0 -0
  116. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-jsx-dev-runtime.js +0 -0
  117. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-jsx-runtime.js +0 -0
  118. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react.js +0 -0
  119. /package/client/vendor/react/{production → 19.2.4/production}/react-dom-client.js +0 -0
  120. /package/client/vendor/react/{production → 19.2.4/production}/react-dom.js +0 -0
  121. /package/client/vendor/react/{production → 19.2.4/production}/react-jsx-dev-runtime.js +0 -0
  122. /package/client/vendor/react/{production → 19.2.4/production}/react-jsx-runtime.js +0 -0
  123. /package/client/vendor/react/{production → 19.2.4/production}/react.js +0 -0
@@ -36,7 +36,6 @@ import { ViewManager } from '@/client/features/views/view-manager'
36
36
  import { getViewIcon, getViewLabel } from '@/client/features/views/view-presentation'
37
37
  import { useViewActions } from '@/client/features/views/use-view-actions'
38
38
  import { useViewDrafts } from '@/client/features/views/use-view-drafts'
39
- import { useFitsSplitLayout } from '@/client/features/workspace/use-fits-split-layout'
40
39
  import { useWorkspaceComposerState } from '@/client/features/chat/composer/use-workspace-composer-state'
41
40
  import { resolveWorkspaceTheme } from '@/lib/themes'
42
41
  import {
@@ -48,7 +47,6 @@ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/workspace-lay
48
47
  import { WorkspaceMenu } from '@/client/features/workspace/workspace-menu'
49
48
  import { effectiveOpenTabs, tabAvailable } from '@/client/features/workspace/tab-resolution'
50
49
  import { useWorkspaceNavigation } from '@/client/features/workspace/use-workspace-navigation'
51
- import { cn } from '@/client/lib/cn'
52
50
  import { useWorkspaceEvent } from '@/client/runtime/use-workspace-events'
53
51
  import { useUiStore } from '@/client/store/ui'
54
52
  import {
@@ -58,17 +56,10 @@ import {
58
56
  } from '@/client/features/workspace/workspace-tabs'
59
57
  import { isDefaultWidget } from '@/lib/default-widgets'
60
58
  import { composerDraftKey, draftSessionId } from '@/lib/session-drafts'
61
- import type {
62
- CompiledView,
63
- LayoutMode,
64
- PendingView,
65
- ViewInfo,
66
- WidgetInfo,
67
- WorkspaceTabId
68
- } from '@/lib/types'
59
+ import type { CompiledView, PendingView, ViewInfo, WidgetInfo, WorkspaceTabId } from '@/lib/types'
69
60
  import { viewIdFromTab, viewTabId } from '@/lib/workspace-tabs'
70
61
 
71
- import { WorkspaceSplitLayout } from './workspace-split-layout'
62
+ import { WorkspaceFrame, WorkspacePane, useWorkspaceFrame } from './workspace-frame'
72
63
  import { UnavailablePage } from './unavailable-page'
73
64
 
74
65
  const Scratchpad = lazy(() =>
@@ -124,20 +115,15 @@ function tabItemFor(
124
115
  }
125
116
 
126
117
  export function WorkspaceContent({ widgets, views: allViews }: WorkspaceContentProps) {
127
- const { layout, setLayout, workspaceId } = useWorkspaceLayoutCtx()
118
+ const { layout, workspaceId } = useWorkspaceLayoutCtx()
128
119
  const theme = resolveWorkspaceTheme(layout.theme)
129
120
  const viewActions = useViewActions()
130
- const {
131
- ref: rowRef,
132
- fits: canUseSplit,
133
- constraints: splitLayoutConstraints
134
- } = useFitsSplitLayout<HTMLDivElement>()
121
+ const frame = useWorkspaceFrame()
122
+ const { mode, canUseSplit, setMode } = frame
135
123
  const [widgetMode, setWidgetMode] = useState<WidgetMode>('idle')
136
124
  const [floatingChatOpen, setFloatingChatOpen] = useState(false)
137
125
  const [chatFocusRequest, setChatFocusRequest] = useState(0)
138
126
  const pendingViewRefs = useRef(new Map<string, PendingViewHandle>())
139
- const dockedChatWidth = useUiStore(state => state.dockedChatWidth)
140
- const setDockedChatWidth = useUiStore(state => state.setDockedChatWidth)
141
127
  const sessionActivity = useLive(state => state.activity)
142
128
  const views = allViews.filter((view): view is CompiledView => view.status === 'compiled')
143
129
  const pendingViews = allViews.filter((view): view is PendingView => view.status !== 'compiled')
@@ -151,9 +137,6 @@ export function WorkspaceContent({ widgets, views: allViews }: WorkspaceContentP
151
137
  const hasAppletWidgets = widgets.some(widget => !isDefaultWidget(widget.id))
152
138
  const hasWorkspaceApplets = hasAppletWidgets || views.length > 0
153
139
 
154
- // Split needs enough row width; the saved mode remains the user's intent.
155
- const wantsSplit = layout.layoutMode === 'split'
156
- const mode: LayoutMode = wantsSplit && canUseSplit ? 'split' : 'fullscreen'
157
140
  const revealChat = useCallback(() => {
158
141
  setFloatingChatOpen(true)
159
142
  setChatFocusRequest(request => request + 1)
@@ -207,10 +190,6 @@ export function WorkspaceContent({ widgets, views: allViews }: WorkspaceContentP
207
190
  const openTabIds = effectiveOpenTabs(tabsState, allViews)
208
191
  const openSet = new Set(tabsState.open)
209
192
 
210
- const setMode = (m: LayoutMode) => {
211
- setLayout({ layoutMode: m })
212
- }
213
-
214
193
  const canCloseTabs = openTabIds.length > 1
215
194
  const tabItems = openTabIds
216
195
  .map(tab =>
@@ -462,12 +441,7 @@ export function WorkspaceContent({ widgets, views: allViews }: WorkspaceContentP
462
441
  )
463
442
 
464
443
  const workspacePanel = (
465
- <div
466
- className={cn(
467
- '@container/workspace relative flex h-full min-h-0 min-w-0 flex-1 flex-col-reverse overflow-hidden bg-background shadow-md transition-[border-radius,background-color] duration-100 ease-out motion-reduce:transition-none',
468
- mode === 'split' && 'rounded-xl'
469
- )}
470
- >
444
+ <WorkspacePane mode={mode}>
471
445
  <div className="relative flex min-h-0 flex-1">
472
446
  <div
473
447
  ref={annotationTargetRef}
@@ -590,30 +564,16 @@ export function WorkspaceContent({ widgets, views: allViews }: WorkspaceContentP
590
564
  </Tooltip>
591
565
  )}
592
566
  </PanelHeader>
593
- </div>
567
+ </WorkspacePane>
594
568
  )
595
569
 
596
570
  return (
597
- <div
571
+ <WorkspaceFrame
572
+ frame={frame}
573
+ workspace={workspacePanel}
574
+ chat={dockedChat}
598
575
  onClick={onNavigationClick}
599
- className="relative flex h-full min-h-0 flex-col font-sans text-foreground"
600
576
  >
601
- <div ref={rowRef} className="flex min-h-0 flex-1">
602
- {canUseSplit && splitLayoutConstraints ? (
603
- <WorkspaceSplitLayout
604
- {...splitLayoutConstraints}
605
- workspace={workspacePanel}
606
- chat={dockedChat}
607
- open={mode === 'split'}
608
- chatWidth={dockedChatWidth}
609
- onCollapse={() => setMode('fullscreen')}
610
- onChatWidthChange={setDockedChatWidth}
611
- />
612
- ) : (
613
- workspacePanel
614
- )}
615
- </div>
616
-
617
577
  {mode === 'fullscreen' && (
618
578
  <ChatPopup
619
579
  agent={theme.agent}
@@ -636,6 +596,6 @@ export function WorkspaceContent({ widgets, views: allViews }: WorkspaceContentP
636
596
  )}
637
597
  </ChatPopup>
638
598
  )}
639
- </div>
599
+ </WorkspaceFrame>
640
600
  )
641
601
  }
@@ -0,0 +1,76 @@
1
+ import type { MouseEventHandler, ReactNode } from 'react'
2
+
3
+ import { cn } from '@/client/lib/cn'
4
+ import { useUiStore } from '@/client/store/ui'
5
+ import type { LayoutMode } from '@/lib/types'
6
+
7
+ import { useFitsSplitLayout } from './use-fits-split-layout'
8
+ import { useWorkspaceLayoutCtx } from './workspace-layout-context'
9
+ import { WorkspaceSplitLayout } from './workspace-split-layout'
10
+
11
+ export function useWorkspaceFrame(expanded = false) {
12
+ const { layout, setLayout } = useWorkspaceLayoutCtx()
13
+ const { ref, fits, constraints } = useFitsSplitLayout<HTMLDivElement>()
14
+ const chatWidth = useUiStore(state => state.dockedChatWidth)
15
+ const setChatWidth = useUiStore(state => state.setDockedChatWidth)
16
+ const mode: LayoutMode =
17
+ !expanded && fits && layout.layoutMode === 'split' ? 'split' : 'fullscreen'
18
+ const setMode = (layoutMode: LayoutMode) => setLayout({ layoutMode })
19
+
20
+ return { ref, canUseSplit: fits, constraints, mode, setMode, chatWidth, setChatWidth }
21
+ }
22
+
23
+ type WorkspaceFrameProps = {
24
+ frame: ReturnType<typeof useWorkspaceFrame>
25
+ workspace: ReactNode
26
+ chat?: ReactNode
27
+ children?: ReactNode
28
+ onClick?: MouseEventHandler<HTMLDivElement>
29
+ }
30
+
31
+ // Loading and ready content share the same pane geometry and saved chat width.
32
+ export function WorkspaceFrame({ frame, workspace, chat, children, onClick }: WorkspaceFrameProps) {
33
+ const { ref, canUseSplit, constraints, mode, setMode, chatWidth, setChatWidth } = frame
34
+ return (
35
+ <div
36
+ onClick={onClick}
37
+ className="relative flex h-full min-h-0 flex-1 flex-col font-sans text-foreground"
38
+ >
39
+ <div ref={ref} className="flex min-h-0 flex-1">
40
+ {canUseSplit && constraints ? (
41
+ <WorkspaceSplitLayout
42
+ {...constraints}
43
+ workspace={workspace}
44
+ chat={chat}
45
+ open={mode === 'split'}
46
+ chatWidth={chatWidth}
47
+ onCollapse={() => setMode('fullscreen')}
48
+ onChatWidthChange={setChatWidth}
49
+ />
50
+ ) : (
51
+ workspace
52
+ )}
53
+ </div>
54
+ {children}
55
+ </div>
56
+ )
57
+ }
58
+
59
+ type WorkspacePaneProps = {
60
+ mode: LayoutMode
61
+ children: ReactNode
62
+ }
63
+
64
+ export function WorkspacePane({ mode, children }: WorkspacePaneProps) {
65
+ return (
66
+ <div
67
+ data-slot="workspace-pane"
68
+ className={cn(
69
+ '@container/workspace relative flex h-full min-h-0 min-w-0 flex-1 flex-col-reverse overflow-hidden bg-background shadow-md transition-[border-radius,background-color] duration-100 ease-out motion-reduce:transition-none',
70
+ mode === 'split' && 'rounded-xl'
71
+ )}
72
+ >
73
+ {children}
74
+ </div>
75
+ )
76
+ }
@@ -82,6 +82,8 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
82
82
  const key = workspaceKeys.layout(id)
83
83
  const prev = qc.getQueryData<WorkspaceLayoutResponse>(key)
84
84
  if (!prev) return
85
+ // A GET already in flight would land the pre-change layout over this edit.
86
+ void qc.cancelQueries({ queryKey: key })
85
87
  // Optimistic: the grid/theme reflects the change before the PUT lands.
86
88
  const next = { ...prev, ...update }
87
89
  qc.setQueryData<WorkspaceLayoutResponse>(key, next)
@@ -0,0 +1,26 @@
1
+ import type { ReactNode } from 'react'
2
+
3
+ import { WorkspaceSetupPanel } from './setup/workspace-setup-panel'
4
+ import { WorkspaceFrame, WorkspacePane, useWorkspaceFrame } from './workspace-frame'
5
+
6
+ type WorkspacePendingScreenProps = {
7
+ setupRequired?: boolean
8
+ children: ReactNode
9
+ }
10
+
11
+ export function WorkspacePendingScreen({
12
+ setupRequired = false,
13
+ children
14
+ }: WorkspacePendingScreenProps) {
15
+ const frame = useWorkspaceFrame(setupRequired)
16
+ return (
17
+ <WorkspaceFrame
18
+ frame={frame}
19
+ workspace={
20
+ <WorkspacePane mode={frame.mode}>
21
+ {setupRequired ? <WorkspaceSetupPanel>{children}</WorkspaceSetupPanel> : children}
22
+ </WorkspacePane>
23
+ }
24
+ />
25
+ )
26
+ }
@@ -2,8 +2,8 @@ import type { ViewInfo, WidgetInfo } from '@/lib/types'
2
2
 
3
3
  import { useWorkspaceLayoutCtx } from './workspace-layout-context'
4
4
  import { WorkspaceContent } from './workspace-content'
5
- import { WorkspaceSetupPanel } from './setup/workspace-setup-panel'
6
5
  import { useWorkspaceSetup } from './setup/workspace-setup'
6
+ import { WorkspacePendingScreen } from './workspace-pending-screen'
7
7
 
8
8
  type WorkspaceScreenProps = {
9
9
  contentPending: boolean
@@ -13,7 +13,7 @@ type WorkspaceScreenProps = {
13
13
 
14
14
  export function WorkspaceScreen({ contentPending, widgets, views }: WorkspaceScreenProps) {
15
15
  const { layout, workspaceId, name, provider } = useWorkspaceLayoutCtx()
16
- const { content, ready } = useWorkspaceSetup(workspaceId, contentPending, {
16
+ const { content, ready, setupRequired } = useWorkspaceSetup(workspaceId, contentPending, {
17
17
  name: name ?? 'Workspace',
18
18
  icon: layout.icon,
19
19
  workspaceType: provider,
@@ -23,6 +23,6 @@ export function WorkspaceScreen({ contentPending, widgets, views }: WorkspaceScr
23
23
  return ready ? (
24
24
  <WorkspaceContent widgets={widgets} views={views} />
25
25
  ) : (
26
- <WorkspaceSetupPanel>{content}</WorkspaceSetupPanel>
26
+ <WorkspacePendingScreen setupRequired={setupRequired}>{content}</WorkspacePendingScreen>
27
27
  )
28
28
  }
package/client/index.html CHANGED
@@ -20,21 +20,40 @@
20
20
  }
21
21
  </style>
22
22
  <link rel="icon" type="image/png" href="./assets/favicon.png" />
23
- <!-- React is vendored locally (client/vendor/react, generated by
24
- scripts/build-vendor.ts) and served by the /vendor/react route, so moi
25
- runs fully offline — no CDN fetch. The server picks the development or
26
- production build per environment behind these stable URLs. -->
23
+ <!-- React is vendored locally (client/vendor/react/<version>, generated by
24
+ scripts/build-vendor.ts, which also rewrites these URLs) and served by
25
+ the /vendor/react route, so moi runs fully offline — no CDN fetch. The
26
+ version and build mode in the path let the browser cache them forever;
27
+ this source names the development build and scripts/build-client.ts
28
+ switches it to production in dist/. -->
27
29
  <script type="importmap">
28
30
  {
29
31
  "imports": {
30
- "react": "/vendor/react/react.js",
31
- "react/jsx-runtime": "/vendor/react/react-jsx-runtime.js",
32
- "react/jsx-dev-runtime": "/vendor/react/react-jsx-dev-runtime.js",
33
- "react-dom": "/vendor/react/react-dom.js",
34
- "react-dom/client": "/vendor/react/react-dom-client.js"
32
+ "react": "/vendor/react/19.2.4/development/react.js",
33
+ "react/jsx-runtime": "/vendor/react/19.2.4/development/react-jsx-runtime.js",
34
+ "react/jsx-dev-runtime": "/vendor/react/19.2.4/development/react-jsx-dev-runtime.js",
35
+ "react-dom": "/vendor/react/19.2.4/development/react-dom.js",
36
+ "react-dom/client": "/vendor/react/19.2.4/development/react-dom-client.js"
35
37
  }
36
38
  }
37
39
  </script>
40
+ <!-- Fetch React (the wrappers and the _impl files they import) as soon as
41
+ the HTML is parsed, instead of two round trips later when the preload
42
+ script below gets to run. Must stay after the importmap: a module
43
+ fetch that starts before the map is parsed disables the map. -->
44
+ <link rel="modulepreload" href="/vendor/react/19.2.4/development/react.js" />
45
+ <link rel="modulepreload" href="/vendor/react/19.2.4/development/_impl/react.js" />
46
+ <link rel="modulepreload" href="/vendor/react/19.2.4/development/react-jsx-runtime.js" />
47
+ <link rel="modulepreload" href="/vendor/react/19.2.4/development/_impl/react-jsx-runtime.js" />
48
+ <link rel="modulepreload" href="/vendor/react/19.2.4/development/react-jsx-dev-runtime.js" />
49
+ <link
50
+ rel="modulepreload"
51
+ href="/vendor/react/19.2.4/development/_impl/react-jsx-dev-runtime.js"
52
+ />
53
+ <link rel="modulepreload" href="/vendor/react/19.2.4/development/react-dom.js" />
54
+ <link rel="modulepreload" href="/vendor/react/19.2.4/development/_impl/react-dom.js" />
55
+ <link rel="modulepreload" href="/vendor/react/19.2.4/development/react-dom-client.js" />
56
+ <link rel="modulepreload" href="/vendor/react/19.2.4/development/_impl/react-dom-client.js" />
38
57
  <link rel="stylesheet" href="./index.css" />
39
58
  </head>
40
59
  <body>
package/client/index.tsx CHANGED
@@ -4,7 +4,11 @@ import './structured-clone-shim'
4
4
  import 'blobatar/motion.css'
5
5
  import './index.css'
6
6
 
7
- import { initializeLocalUser, installHostApi } from './features/collab/host-state'
7
+ import {
8
+ initializeLocalUser,
9
+ installHostApi,
10
+ subscribeLocalProfileStorage
11
+ } from './features/collab/host-state'
8
12
 
9
13
  import { startHmrWatchdog } from './runtime/hmr-watchdog'
10
14
 
@@ -27,6 +31,7 @@ if (import.meta.hot) {
27
31
  // script runs right after this bundle and calls `window.moi.collab.publishUsers`
28
32
  // straight away, before the async startup below has finished.
29
33
  installHostApi()
34
+ subscribeLocalProfileStorage()
30
35
 
31
36
  export async function init(el: HTMLElement) {
32
37
  // Startup config and any proxy-verified user load in parallel with the
@@ -36,7 +41,7 @@ export async function init(el: HTMLElement) {
36
41
  import('./api/app-config').then(m => m.loadAppConfig()),
37
42
  import('./features/collab/proxy-user').then(m => m.loadProxyUser())
38
43
  ])
39
- initializeLocalUser(config?.experimental.collab === true, proxyUser)
44
+ initializeLocalUser(config?.environment === 'local' && !config.demo, proxyUser)
40
45
  mount(el)
41
46
  }
42
47
 
@@ -0,0 +1,4 @@
1
+ // Unique per browser tab (page load). Writes send it as `origin`; the server echoes it on the
2
+ // resulting broadcast so the writing tab can skip its own echo (it already shows
3
+ // the change optimistically, and a refetch could land an older value over it).
4
+ export const BROWSER_TAB_ID = Math.random().toString(36).slice(2)
@@ -0,0 +1,6 @@
1
+ import type { UserProfile } from '@/lib/collab/types'
2
+
3
+ // Presentation only: keep the supplied profile unchanged in applet APIs.
4
+ export function userDisplayName(user: UserProfile): string {
5
+ return user.name?.trim() || user.email?.trim() || user.id
6
+ }
package/client/main.tsx CHANGED
@@ -6,6 +6,8 @@ import { Toaster } from '@/client/components/ui/toast'
6
6
  import { TooltipProvider } from '@/client/components/ui/tooltip'
7
7
  import { installAppletErrorHook } from '@/client/features/applets/applet-log'
8
8
  import { initConnection } from '@/client/features/chat/connection/chat-connection'
9
+ import { AccountProvider } from '@/client/features/account/account-provider'
10
+ import { AppProvider } from './app/app-provider'
9
11
  import { AppRouter } from './app/app-router'
10
12
 
11
13
  const queryClient = new QueryClient()
@@ -23,12 +25,16 @@ export function mount(el: HTMLElement) {
23
25
  function Root() {
24
26
  return (
25
27
  <QueryClientProvider client={queryClient}>
26
- <TooltipProvider>
27
- <Router>
28
- <AppRouter />
29
- </Router>
30
- <Toaster />
31
- </TooltipProvider>
28
+ <AppProvider>
29
+ <TooltipProvider>
30
+ <Router>
31
+ <AccountProvider>
32
+ <AppRouter />
33
+ </AccountProvider>
34
+ </Router>
35
+ <Toaster />
36
+ </TooltipProvider>
37
+ </AppProvider>
32
38
  </QueryClientProvider>
33
39
  )
34
40
  }
@@ -0,0 +1,20 @@
1
+ import { createContext, useContext } from 'react'
2
+
3
+ import type { WorkspaceEventsClient } from './workspace-events'
4
+
5
+ // App-wide state that lives exactly as long as the app: created by
6
+ // `AppProvider` (app/app-provider.tsx) when the app mounts and shut down when
7
+ // it unmounts. Put things here that must survive route switches but not the
8
+ // app itself.
9
+ export type AppContextValue = {
10
+ // The page's workspace events socket.
11
+ events: WorkspaceEventsClient
12
+ }
13
+
14
+ export const AppContext = createContext<AppContextValue | undefined>(undefined)
15
+
16
+ // Undefined outside `AppProvider` (isolated sandboxes, component tests);
17
+ // callers treat that as "no app-wide services" and do nothing.
18
+ export function useAppContext(): AppContextValue | undefined {
19
+ return useContext(AppContext)
20
+ }
@@ -1,142 +1,19 @@
1
1
  import { useEffect } from 'react'
2
- import type { NavigationRequest } from '@/lib/navigation'
3
2
 
4
3
  import { useLatestRef } from '@/client/lib/use-latest-ref'
5
- import { wsUrl } from '@/client/lib/ws-url'
6
- import type { AppSettings, HarnessAvailability, ViewInfo, WidgetInfo } from '@/lib/types'
7
4
 
8
- export type WorkspaceEvent =
9
- | { type: 'widget:updated'; name: string }
10
- | { type: 'widget-layout:updated'; widgets: WidgetInfo[] }
11
- // `moi refresh` — cache-bust and re-fetch applets without a rebuild. `only`
12
- // narrows to one kind; absent means both widgets and views.
13
- | { type: 'applets:refresh'; only?: 'widgets' | 'views' }
14
- | { type: 'view:updated'; name: string }
15
- | { type: 'view-layout:updated'; views: ViewInfo[] }
16
- | { type: 'view:deleted'; workspaceId: string; name: string }
17
- | { type: 'views:changed'; workspaceId: string }
18
- | { type: 'selected-session:updated'; workspaceId: string; sessionId: string | null }
19
- | { type: 'theme:updated' }
20
- | { type: 'workspace:updated' }
21
- // The registry list changed (reorder, create) without touching any open
22
- // workspace's layout — clients refetch just the sidebar list.
23
- | { type: 'workspaces-list:updated' }
24
- // A workspace's env changed outside the UI — refetch the env view.
25
- | { type: 'env:updated'; workspaceId: string }
26
- // Workspace readiness changed. Patch its cache without a refetch.
27
- | {
28
- type: 'harness:updated'
29
- workspaceId: string
30
- availability: HarnessAvailability
31
- }
32
- // The Scratchpad canvas for `workspaceId` was saved — open tabs reload from
33
- // disk. `origin` is the tab that wrote it, so that tab can skip its own echo.
34
- | { type: 'scratchpad:updated'; workspaceId: string; origin?: string }
35
- // App settings changed (PATCH /api/settings from any client) — carries the
36
- // new value so caches update without a refetch.
37
- | { type: 'settings:updated'; settings: AppSettings }
38
- | NavigationRequest
39
-
40
- type WorkspaceEventHandler = (event: WorkspaceEvent) => void
41
-
42
- const listeners = new Set<WorkspaceEventHandler>()
43
- // Fired when the socket comes back after a drop — for the SPA that means the
44
- // server restarted (it holds the connection for its whole lifetime), so
45
- // restart-scoped state such as the startup config can refetch.
46
- const reconnectListeners = new Set<() => void>()
47
- let everConnected = false
48
- let ws: WebSocket | null = null
49
- let connecting = false
50
-
51
- // Reconnect delay grows exponentially on repeated drops so a downed server
52
- // doesn't get hammered with a request every 2s; resets once a connection
53
- // actually opens.
54
- const RECONNECT_BASE_DELAY_MS = 1000
55
- const RECONNECT_MAX_DELAY_MS = 30_000
56
- let reconnectAttempt = 0
57
-
58
- function scheduleReconnect() {
59
- const delay = Math.min(RECONNECT_BASE_DELAY_MS * 2 ** reconnectAttempt, RECONNECT_MAX_DELAY_MS)
60
- reconnectAttempt++
61
- setTimeout(ensureConnection, delay)
62
- }
63
-
64
- function ensureConnection() {
65
- if (ws || connecting) return
66
- connecting = true
5
+ import { useAppContext } from './app-context'
6
+ import type { WorkspaceEventHandler } from './workspace-events'
67
7
 
68
- const socket = new WebSocket(wsUrl('/api/workspaces/ws'))
69
-
70
- socket.onopen = () => {
71
- ws = socket
72
- connecting = false
73
- reconnectAttempt = 0
74
- sendNavigationPresence()
75
- if (everConnected) for (const handler of reconnectListeners) handler()
76
- everConnected = true
77
- }
78
-
79
- socket.onmessage = event => {
80
- try {
81
- const data = JSON.parse(event.data) as WorkspaceEvent
82
- for (const handler of listeners) handler(data)
83
- } catch {}
84
- }
85
-
86
- socket.onclose = () => {
87
- ws = null
88
- connecting = false
89
- // Reconnect with backoff if there are still listeners
90
- if (listeners.size > 0) {
91
- scheduleReconnect()
92
- }
93
- }
94
-
95
- socket.onerror = () => {
96
- socket.close()
97
- }
98
- }
99
-
100
- // Subscribe to reconnects; returns the unsubscribe. Only fires while some
101
- // component holds the events socket open via useWorkspaceEvent (the app shell
102
- // always does).
103
- export function onWorkspaceEventsReconnect(handler: () => void): () => void {
104
- reconnectListeners.add(handler)
105
- return () => {
106
- reconnectListeners.delete(handler)
107
- }
108
- }
8
+ export type { WorkspaceEvent, WorkspaceEventHandler } from './workspace-events'
109
9
 
10
+ // Listen to the app's workspace events. Subscribing never opens or closes the
11
+ // socket — `AppProvider` owns that — so a route switch that briefly leaves
12
+ // nothing subscribed costs nothing. A no-op outside `AppProvider`.
110
13
  export function useWorkspaceEvent(handler: WorkspaceEventHandler) {
14
+ const events = useAppContext()?.events
111
15
  const handlerRef = useLatestRef(handler)
112
-
113
- useEffect(() => {
114
- const wrapped: WorkspaceEventHandler = e => handlerRef.current(e)
115
- listeners.add(wrapped)
116
- ensureConnection()
117
-
118
- return () => {
119
- listeners.delete(wrapped)
120
- // Close WS if no more listeners
121
- if (listeners.size === 0 && ws) {
122
- ws.close()
123
- ws = null
124
- }
125
- }
126
- }, [handlerRef])
127
- }
128
-
129
- let navigationWorkspace: string | null = null
130
-
131
- function sendNavigationPresence() {
132
- if (ws?.readyState !== WebSocket.OPEN) return
133
- ws.send(
134
- JSON.stringify({
135
- type: 'navigation:presence',
136
- workspaceId: navigationWorkspace,
137
- focused: document.visibilityState === 'visible' && document.hasFocus()
138
- })
139
- )
16
+ useEffect(() => events?.subscribe(event => handlerRef.current(event)), [events, handlerRef])
140
17
  }
141
18
 
142
19
  // This hook owns presence for the displayed workspace, including reconnects.
@@ -145,36 +22,35 @@ export function useNavigationClient(
145
22
  workspaceId: string,
146
23
  navigate: (href: string) => void | Promise<void>
147
24
  ) {
25
+ const events = useAppContext()?.events
26
+
148
27
  useEffect(() => {
149
- navigationWorkspace = workspaceId
150
- sendNavigationPresence()
151
- window.addEventListener('focus', sendNavigationPresence)
152
- document.addEventListener('visibilitychange', sendNavigationPresence)
28
+ if (!events) return
29
+ events.setNavigationWorkspace(workspaceId)
30
+ const sendPresence = () => events.sendNavigationPresence()
31
+ window.addEventListener('focus', sendPresence)
32
+ document.addEventListener('visibilitychange', sendPresence)
153
33
  return () => {
154
- navigationWorkspace = null
155
- sendNavigationPresence()
156
- window.removeEventListener('focus', sendNavigationPresence)
157
- document.removeEventListener('visibilitychange', sendNavigationPresence)
34
+ events.setNavigationWorkspace(undefined)
35
+ window.removeEventListener('focus', sendPresence)
36
+ document.removeEventListener('visibilitychange', sendPresence)
158
37
  }
159
- }, [workspaceId])
38
+ }, [events, workspaceId])
160
39
 
161
40
  useWorkspaceEvent(async event => {
162
- if (event.type !== 'navigation:request' || event.workspaceId !== workspaceId) return
163
- const socket = ws
41
+ if (!events || event.type !== 'navigation:request' || event.workspaceId !== workspaceId) return
164
42
  try {
165
- if (navigationWorkspace !== workspaceId) throw new Error('The browser switched workspaces.')
43
+ if (events.navigationWorkspace !== workspaceId) {
44
+ throw new Error('The browser switched workspaces.')
45
+ }
166
46
  await navigate(event.href)
167
- socket?.send(
168
- JSON.stringify({ type: 'navigation:result', requestId: event.requestId, ok: true })
169
- )
47
+ events.send({ type: 'navigation:result', requestId: event.requestId, ok: true })
170
48
  } catch (error) {
171
- socket?.send(
172
- JSON.stringify({
173
- type: 'navigation:result',
174
- requestId: event.requestId,
175
- error: error instanceof Error ? error.message : 'Navigation failed'
176
- })
177
- )
49
+ events.send({
50
+ type: 'navigation:result',
51
+ requestId: event.requestId,
52
+ error: error instanceof Error ? error.message : 'Navigation failed'
53
+ })
178
54
  }
179
55
  })
180
56
  }