moi-computer 0.11.1-next.4 → 0.12.0

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 (131) hide show
  1. package/client/api/app-config.ts +7 -4
  2. package/client/app/AppRouter.tsx +2 -2
  3. package/client/app/routes/WorkspaceRoute.tsx +27 -19
  4. package/client/features/applets/{AppletMount.tsx → AppletContainer.tsx} +7 -5
  5. package/client/features/applets/WidgetShell.tsx +3 -3
  6. package/client/features/applets/applet-cache.ts +3 -5
  7. package/client/features/applets/applet-runtime.ts +27 -12
  8. package/client/features/applets/applet-thumbnail.ts +2 -1
  9. package/client/features/chat/applet-chat-intents.ts +14 -6
  10. package/client/features/chat/composer/attachments/draft-attachments.ts +21 -4
  11. package/client/features/chat/messages/MarkdownContent.tsx +5 -2
  12. package/client/features/chat/sessions/browser-tab-state.ts +18 -0
  13. package/client/features/chat/sessions/useSelectedSession.ts +55 -21
  14. package/client/features/chat/useChat.ts +4 -0
  15. package/client/features/collab/applet-api.ts +34 -0
  16. package/client/features/collab/client.ts +239 -0
  17. package/client/features/collab/components/cursors.tsx +199 -0
  18. package/client/features/collab/components/presence-avatars.tsx +61 -0
  19. package/client/features/collab/components/presence-frame.tsx +126 -0
  20. package/client/features/collab/components/presence-group.tsx +23 -0
  21. package/client/features/collab/components/presence-helpers.ts +50 -0
  22. package/client/features/collab/components/user-avatar-group.tsx +22 -0
  23. package/client/features/collab/components/user-avatar.tsx +40 -0
  24. package/client/features/collab/components/user.tsx +50 -0
  25. package/client/features/collab/hooks.tsx +164 -0
  26. package/client/features/collab/host-state.ts +254 -0
  27. package/client/features/collab/index.ts +5 -0
  28. package/client/features/collab/local-user.ts +46 -0
  29. package/client/features/collab/presence-publisher.ts +30 -0
  30. package/client/features/collab/presence-target.ts +8 -0
  31. package/client/features/collab/provider.tsx +79 -0
  32. package/client/features/collab/proxy-user.ts +35 -0
  33. package/client/features/collab/store.ts +156 -0
  34. package/client/features/collab/testing/component-fixtures.tsx +54 -0
  35. package/client/features/collab/testing/fake-engine.ts +129 -0
  36. package/client/features/collab/users.ts +106 -0
  37. package/client/features/collab/workspace-users-menu.tsx +194 -0
  38. package/client/features/connectors/mcp-icons.ts +0 -2
  39. package/client/features/dev/DevIndexPage.tsx +5 -0
  40. package/client/features/dev/DevRoutes.tsx +16 -4
  41. package/client/features/dev/collab/collab-page.tsx +24 -0
  42. package/client/features/dev/collab/collab-playground.tsx +614 -0
  43. package/client/features/dev/collab/local-user-settings.tsx +166 -0
  44. package/client/features/dev/collab/playground-room.ts +33 -0
  45. package/client/features/dev/{UiComponentsPage.tsx → ui-components/ui-components-page.tsx} +1 -1
  46. package/client/features/overview/WidgetCanvas.tsx +3 -1
  47. package/client/features/views/ViewManager.tsx +12 -7
  48. package/client/features/views/api.ts +2 -2
  49. package/client/features/views/useViewBuilderActions.ts +3 -0
  50. package/client/features/workspace/WorkspaceContext.tsx +1 -1
  51. package/client/features/workspace/WorkspaceLayoutContext.tsx +8 -2
  52. package/client/features/workspace/WorkspaceScreen.tsx +19 -11
  53. package/client/features/workspace/WorkspaceTabs.tsx +3 -3
  54. package/client/features/workspace/api.ts +2 -1
  55. package/client/features/workspace/browser-tab-state.ts +44 -0
  56. package/client/features/workspace/layout-save.ts +13 -0
  57. package/client/features/workspace/moi-context.ts +2 -1
  58. package/client/features/workspace/useWorkspaceNavigation.ts +20 -8
  59. package/client/index.css +45 -0
  60. package/client/index.tsx +9 -4
  61. package/client/main.tsx +1 -11
  62. package/client/theme.css +4 -1
  63. package/dist/chunk-2jncyq65.js +1 -0
  64. package/dist/{chunk-brr0zbeh.js → chunk-3a48fyf7.js} +2 -2
  65. package/dist/{chunk-tzz101ea.js → chunk-97eg9mjn.js} +1 -1
  66. package/dist/chunk-e2q5ken7.js +68 -0
  67. package/dist/{chunk-zs4mte79.js → chunk-efdyz6xp.js} +1 -1
  68. package/dist/chunk-h2kj1ysj.js +1 -0
  69. package/dist/chunk-jf6czgrz.js +2 -0
  70. package/dist/chunk-nez8sdta.js +1 -0
  71. package/dist/chunk-nzwgm8vc.css +1 -0
  72. package/dist/chunk-ph0h6h86.js +1 -0
  73. package/dist/chunk-ryg9z3kn.js +10 -0
  74. package/dist/chunk-tpn177bt.js +2 -0
  75. package/dist/chunk-vfpsc75k.js +2 -0
  76. package/dist/{chunk-m1fvqssh.js → chunk-z3byfve5.js} +2 -2
  77. package/dist/index.html +1 -1
  78. package/lib/collab/colors.ts +30 -0
  79. package/lib/collab/protocol.ts +84 -0
  80. package/lib/collab/types.ts +52 -0
  81. package/lib/experimental.ts +14 -0
  82. package/lib/moi-context.ts +11 -3
  83. package/lib/navigation.ts +25 -5
  84. package/lib/types.ts +20 -33
  85. package/package.json +2 -2
  86. package/server/AGENTS.md +1 -1
  87. package/server/api.ts +28 -5
  88. package/server/app-config.ts +127 -34
  89. package/server/applet-typecheck.ts +8 -3
  90. package/server/applets/applet-css.ts +1 -1
  91. package/server/applets/build-applet.ts +9 -3
  92. package/server/applets/declarations/base.d.ts +75 -0
  93. package/server/applets/declarations/collab.d.ts +88 -0
  94. package/server/applets/declarations.ts +46 -0
  95. package/server/applets/index.ts +8 -8
  96. package/server/applets/runtime/collab.ts +94 -0
  97. package/server/applets/runtime/moi.ts +12 -19
  98. package/server/applets/runtime/rpc.ts +2 -4
  99. package/server/chat-selection.ts +22 -0
  100. package/server/cli.ts +86 -21
  101. package/server/collab/cloudflare-access.ts +78 -0
  102. package/server/collab/config.ts +18 -0
  103. package/server/collab/manager.ts +407 -0
  104. package/server/collab/service.ts +136 -0
  105. package/server/collab/skill/index.ts +53 -0
  106. package/server/collab/worker-messages.ts +10 -0
  107. package/server/collab/worker.ts +52 -0
  108. package/server/layout.ts +10 -3
  109. package/server/moi-scaffold.ts +55 -84
  110. package/server/preview.ts +1 -1
  111. package/server/skill-update.ts +7 -9
  112. package/server/skills-template.ts +14 -2
  113. package/server/web.ts +65 -17
  114. package/server/workspace-init.ts +6 -3
  115. package/ui-components/avatar.tsx +24 -11
  116. package/ui-components/button.tsx +9 -9
  117. package/ui-components/docs/avatar.md +11 -30
  118. package/workspace/.claude/skills/moi-workspace/SKILL.md +14 -11
  119. package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +262 -0
  120. package/workspace/.claude/skills/moi-workspace/references/INTENTS.md +10 -7
  121. package/client/assets/mcp/agentation.png +0 -0
  122. package/dist/agentation-4s0nn45p.png +0 -0
  123. package/dist/chunk-2gs8jjx4.css +0 -1
  124. package/dist/chunk-7vvg5fyz.js +0 -68
  125. package/dist/chunk-94m3q9ce.js +0 -1
  126. package/dist/chunk-by2wqgak.js +0 -1
  127. package/dist/chunk-p34hvqt3.js +0 -1
  128. package/dist/chunk-p83f0jnj.js +0 -2
  129. package/dist/chunk-xg01f6pn.js +0 -10
  130. /package/client/features/dev/{UiComponentPreviews.tsx → ui-components/ui-component-previews.tsx} +0 -0
  131. /package/server/applets/{runtime/base.ts → api-base.ts} +0 -0
@@ -0,0 +1,166 @@
1
+ import { useState, useSyncExternalStore } from 'react'
2
+
3
+ import { IconArrowsShuffle } from '@tabler/icons-react'
4
+
5
+ import { Button } from '@/client/components/ui/button'
6
+ import { Input } from '@/client/components/ui/input'
7
+ import { useAppConfig } from '@/client/api/app-config'
8
+ import { USER_COLORS } from '@/lib/collab/colors'
9
+ import type { UserProfile } from '@/lib/collab/types'
10
+ import { User } from '@/client/features/collab/components/user'
11
+ import { UserAvatar } from '@/client/features/collab/components/user-avatar'
12
+ import { randomLocalUser } from '@/client/features/collab/local-user'
13
+ import {
14
+ getCurrentUser,
15
+ getCurrentUserSource,
16
+ setLocalUser,
17
+ subscribeCurrentUserStore
18
+ } from '@/client/features/collab/host-state'
19
+
20
+ export function LocalUserSettings() {
21
+ const { experimental } = useAppConfig()
22
+ const source = useSyncExternalStore(
23
+ subscribeCurrentUserStore,
24
+ getCurrentUserSource,
25
+ getCurrentUserSource
26
+ )
27
+ const profile = useSyncExternalStore(subscribeCurrentUserStore, getCurrentUser, getCurrentUser)
28
+ if (source === 'external') return null
29
+ if (source === 'cloudflare-access') return <AccessUser profile={profile} />
30
+ if (profile) return <LocalUserEditor key={profile.id} profile={profile} />
31
+ return (
32
+ <section aria-labelledby="local-user-title" className="flex flex-col gap-5">
33
+ <h2 id="local-user-title" className="text-base font-medium">
34
+ Local user
35
+ </h2>
36
+ <p className="text-sm text-muted-foreground">
37
+ {experimental.collab ? (
38
+ 'Couldn’t resolve your user identity. Reload moi to try again.'
39
+ ) : (
40
+ <>
41
+ Start moi with <code className="font-mono">--experimental-collab</code> to create a
42
+ local user automatically. The playground below uses its own sample users.
43
+ </>
44
+ )}
45
+ </p>
46
+ </section>
47
+ )
48
+ }
49
+
50
+ type AccessUserProps = { profile: UserProfile | undefined }
51
+
52
+ // Behind Cloudflare Access the profile is inherited, so there is nothing to edit.
53
+ // Access profiles carry no name, so the label is the email, as in workspaces.
54
+ function AccessUser({ profile }: AccessUserProps) {
55
+ return (
56
+ <section aria-labelledby="access-user-title" className="flex flex-col gap-5">
57
+ <header>
58
+ <h2 id="access-user-title" className="text-base font-medium">
59
+ Cloudflare Access user
60
+ </h2>
61
+ <p className="mt-1 text-sm text-muted-foreground">
62
+ {profile
63
+ ? 'This server uses your Cloudflare Access account. You appear by your email, with a color picked from your Access user ID.'
64
+ : 'This server uses Cloudflare Access, but this page wasn’t opened through it. Open moi at its Cloudflare Access address to appear in workspaces.'}
65
+ </p>
66
+ </header>
67
+ {profile && <User id={profile.id} />}
68
+ </section>
69
+ )
70
+ }
71
+
72
+ type LocalUserEditorProps = { profile: UserProfile }
73
+
74
+ function LocalUserEditor({ profile }: LocalUserEditorProps) {
75
+ // Keep raw input so normalization doesn't eat spaces while a name is being typed.
76
+ const [name, setName] = useState(profile.name ?? '')
77
+
78
+ return (
79
+ <section aria-labelledby="local-user-title" className="flex flex-col gap-5">
80
+ <header>
81
+ <h2 id="local-user-title" className="text-base font-medium">
82
+ Local user
83
+ </h2>
84
+ <p className="mt-1 text-sm text-muted-foreground">
85
+ Edit the local user for this browser tab. Changes save immediately. To test with two
86
+ users, open moi in another browser tab.
87
+ </p>
88
+ </header>
89
+ <div className="flex flex-col gap-5">
90
+ <div className="flex flex-col items-start gap-5 sm:flex-row">
91
+ <div
92
+ data-collab-color={profile.color}
93
+ role="img"
94
+ aria-label="Local user preview"
95
+ className="size-16 shrink-0 overflow-hidden rounded-full"
96
+ >
97
+ <UserAvatar id={profile.id} className="data-[size=default]:size-full" />
98
+ </div>
99
+ <div className="flex w-full max-w-sm min-w-0 flex-col gap-4">
100
+ <label className="flex flex-col gap-1.5 text-sm">
101
+ Name (optional)
102
+ <Input
103
+ value={name}
104
+ maxLength={80}
105
+ placeholder="Type a name"
106
+ autoComplete="off"
107
+ spellCheck={false}
108
+ onChange={event => {
109
+ setName(event.target.value)
110
+ setLocalUser({ ...profile, name: event.target.value })
111
+ }}
112
+ />
113
+ </label>
114
+ <div className="flex flex-col gap-1.5 text-sm">
115
+ <span id="collab-color-label">Color</span>
116
+ <div
117
+ role="radiogroup"
118
+ aria-labelledby="collab-color-label"
119
+ className="flex flex-wrap gap-2"
120
+ >
121
+ {USER_COLORS.map(color => (
122
+ <label key={color} data-collab-color={color} className="cursor-pointer">
123
+ <input
124
+ type="radio"
125
+ name="color"
126
+ value={color}
127
+ aria-label={color[0].toUpperCase() + color.slice(1)}
128
+ checked={profile.color === color}
129
+ onChange={() => setLocalUser({ ...profile, color })}
130
+ className="peer sr-only"
131
+ />
132
+ <svg
133
+ viewBox="0 0 24 24"
134
+ aria-hidden="true"
135
+ className="size-6 rounded-full ring-foreground ring-offset-2 ring-offset-background transition-shadow peer-checked:ring-2 peer-focus-visible:ring-2 peer-focus-visible:ring-ring"
136
+ >
137
+ <circle cx="12" cy="12" r="12" className="fill-collab" />
138
+ </svg>
139
+ </label>
140
+ ))}
141
+ </div>
142
+ </div>
143
+ <div className="flex flex-wrap gap-2">
144
+ <Button
145
+ type="button"
146
+ variant="secondary"
147
+ size="sm"
148
+ onClick={() => {
149
+ const next = randomLocalUser({ name, color: profile.color })
150
+ setName(next.name)
151
+ setLocalUser({ ...profile, ...next })
152
+ }}
153
+ >
154
+ <IconArrowsShuffle stroke={1.75} />
155
+ Randomize
156
+ </Button>
157
+ </div>
158
+ </div>
159
+ </div>
160
+ <p className="text-sm text-muted-foreground">
161
+ Your user is saved in this browser tab. The playground below uses its own sample users.
162
+ </p>
163
+ </div>
164
+ </section>
165
+ )
166
+ }
@@ -0,0 +1,33 @@
1
+ import type { Connection } from '@/lib/collab/types'
2
+ import type { FakeEngine } from '@/client/features/collab/testing/fake-engine'
3
+
4
+ // Relay each participant's own connection, just as a room would broadcast it.
5
+ export function connectPlaygroundParticipants(
6
+ rooms: readonly FakeEngine[],
7
+ background: readonly Connection[] = []
8
+ ): () => void {
9
+ const snapshots = new Map<FakeEngine, string>()
10
+ const sync = (source: FakeEngine) => {
11
+ const state = source.getSnapshot()
12
+ const own = state.connections.find(connection => connection.connectionId === state.connectionId)
13
+ const snapshot = JSON.stringify(own)
14
+ if (snapshots.get(source) === snapshot) return
15
+ // Cache before broadcasting: peers announce their new snapshots synchronously.
16
+ snapshots.set(source, snapshot)
17
+ for (const room of rooms) {
18
+ const peers = rooms
19
+ .filter(peer => peer !== room)
20
+ .flatMap(peer => {
21
+ const state = peer.getSnapshot()
22
+ const own = state.connections.find(
23
+ connection => connection.connectionId === state.connectionId
24
+ )
25
+ return own ? [{ ...own, connectionId: `preview:${own.userId}` }] : []
26
+ })
27
+ room.setOtherConnections([...background, ...peers])
28
+ }
29
+ }
30
+ const unsubscribe = rooms.map(room => room.subscribe(() => sync(room)))
31
+ rooms.forEach(sync)
32
+ return () => unsubscribe.forEach(dispose => dispose())
33
+ }
@@ -4,7 +4,7 @@ import { Link } from 'wouter'
4
4
 
5
5
  import { Button } from '@/client/components/ui/button'
6
6
  import registry from '@/registry.json'
7
- import { UI_COMPONENT_PREVIEWS } from './UiComponentPreviews'
7
+ import { UI_COMPONENT_PREVIEWS } from './ui-component-previews'
8
8
 
9
9
  const registryItems = registry.items.filter(item => item.type === 'registry:ui')
10
10
 
@@ -7,6 +7,8 @@ import { GridLayout, type Layout, useContainerWidth, verticalCompactor } from 'r
7
7
  import 'react-grid-layout/css/styles.css'
8
8
  import 'react-resizable/css/styles.css'
9
9
 
10
+ import { appletId } from '@/client/features/applets/applet-cache'
11
+
10
12
  import { packItems } from './grid'
11
13
  import type { GridPosition, PositionedGridItem } from './grid'
12
14
  import { WidgetFrame } from './WidgetFrame'
@@ -103,7 +105,7 @@ function WidgetGrid({
103
105
  <div key={item.i}>
104
106
  <motion.div
105
107
  layoutId={item.i}
106
- data-applet-thumbnail={`widget:${item.i}`}
108
+ data-applet-thumbnail={appletId('widgets', item.i)}
107
109
  className="size-full"
108
110
  transition={WIDGET_LAYOUT_TRANSITION}
109
111
  >
@@ -16,7 +16,7 @@
16
16
  import { Activity, type ComponentType, memo, useCallback, useEffect, useState } from 'react'
17
17
 
18
18
  import { Spinner } from '@/client/components/ui/spinner'
19
- import { appletScope, appletStyleKey } from '@/client/features/applets/applet-cache'
19
+ import { appletId, appletStyleKey } from '@/client/features/applets/applet-cache'
20
20
  import { useAppletStyle } from '@/client/features/applets/applet-styles'
21
21
  import { useAppletThumbnails } from '@/client/features/applets/applet-thumbnail'
22
22
  import {
@@ -25,6 +25,7 @@ import {
25
25
  useView
26
26
  } from '@/client/features/applets/useApplet'
27
27
  import { WidgetErrorBoundary } from '@/client/features/applets/WidgetErrorBoundary'
28
+ import { AppletPresenceProvider } from '@/client/features/collab'
28
29
  import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
29
30
  import { cn } from '@/client/lib/cn'
30
31
  import { useLatestRef } from '@/client/lib/use-latest-ref'
@@ -181,7 +182,7 @@ function ViewSlot({ view, active, params }: ViewSlotProps) {
181
182
  build={current}
182
183
  params={shownParams}
183
184
  entering={outgoing !== null}
184
- thumbnailTarget
185
+ current
185
186
  />
186
187
  </Activity>
187
188
  )}
@@ -196,7 +197,8 @@ type ViewFrameProps = {
196
197
  // Play the rebuild dissolve. Set on the incoming build only, and only while
197
198
  // the build it replaced is still rendered underneath it.
198
199
  entering?: boolean
199
- thumbnailTarget?: boolean
200
+ // The current build owns thumbnails and presence during a rebuild.
201
+ current?: boolean
200
202
  }
201
203
 
202
204
  // One build of one view, in its style scope. Frames stack absolutely, so during
@@ -204,13 +206,14 @@ type ViewFrameProps = {
204
206
  //
205
207
  // The frame itself never scrolls; a child does. Applet-scoped overlays portal
206
208
  // into this root and position against it.
207
- function ViewFrame({ view, build, params, entering, thumbnailTarget }: ViewFrameProps) {
209
+ function ViewFrame({ view, build, params, entering, current = false }: ViewFrameProps) {
208
210
  const workspaceId = useWorkspaceId()
211
+ const id = appletId('views', view.id)
209
212
 
210
213
  return (
211
214
  <div
212
- data-applet-thumbnail={thumbnailTarget ? `view:${view.id}` : undefined}
213
- data-applet={appletScope('views', view.id)}
215
+ data-applet-thumbnail={current ? id : undefined}
216
+ data-applet={id}
214
217
  className={cn(
215
218
  // Keep applet z-indexes inside the view. Host overlays render after this
216
219
  // frame and should always stack above the view as a single unit.
@@ -225,7 +228,9 @@ function ViewFrame({ view, build, params, entering, thumbnailTarget }: ViewFrame
225
228
  workspaceId={workspaceId}
226
229
  resetKey={build.version}
227
230
  >
228
- <build.Component params={params} />
231
+ <AppletPresenceProvider appletId={id} active={current}>
232
+ <build.Component params={params} />
233
+ </AppletPresenceProvider>
229
234
  </WidgetErrorBoundary>
230
235
  </div>
231
236
  </div>
@@ -1,4 +1,3 @@
1
- import type { MessageAttachment } from '@/lib/types'
2
1
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
3
2
 
4
3
  import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
@@ -6,7 +5,7 @@ import { WORKSPACE_RESOURCE_OPTIONS } from '@/client/api/query-options'
6
5
  import { workspaceKeys } from '@/client/api/workspace-keys'
7
6
  import { APP_ICON_IDS } from '@/client/lib/app-icon-registry'
8
7
  import { useWorkspaceEvent } from '@/client/runtime/useWorkspaceEvents'
9
- import type { ViewBuilder, ViewInfo } from '@/lib/types'
8
+ import type { MessageAttachment, SelectedSessionScope, ViewBuilder, ViewInfo } from '@/lib/types'
10
9
 
11
10
  export function useViews(workspaceId: string) {
12
11
  return useQuery<ViewInfo[]>({
@@ -114,6 +113,7 @@ export type SubmitViewBuilderInput = {
114
113
  builderId: string
115
114
  requirements: string
116
115
  optimisticId: string
116
+ selectedSessionScope?: SelectedSessionScope
117
117
  attachments?: MessageAttachment[]
118
118
  model?: string
119
119
  effort?: string
@@ -9,6 +9,7 @@ import {
9
9
  } from '@/client/features/chat/chat-send'
10
10
  import { liveStore } from '@/client/features/chat/chat-store'
11
11
  import { useSelectedSession } from '@/client/features/chat/sessions/useSelectedSession'
12
+ import { useCollabEnabled } from '@/client/features/collab'
12
13
  import { useWorkspaceAgent } from '@/client/features/workspace/api'
13
14
  import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
14
15
  import {
@@ -23,6 +24,7 @@ export function useViewBuilderActions() {
23
24
  const queryClient = useQueryClient()
24
25
  const { workspaceId, layout } = useWorkspaceLayoutCtx()
25
26
  const [, selectSession] = useSelectedSession()
27
+ const collabEnabled = useCollabEnabled()
26
28
  const modelData = useWorkspaceAgent(workspaceId).data
27
29
  const createMutation = useCreateViewBuilder(workspaceId)
28
30
  const saveMutation = useSaveViewBuilder(workspaceId)
@@ -70,6 +72,7 @@ export function useViewBuilderActions() {
70
72
  builderId: builder.id,
71
73
  requirements: text,
72
74
  optimisticId,
75
+ selectedSessionScope: collabEnabled ? 'browser-tab' : 'shared',
73
76
  ...(attachments.length > 0
74
77
  ? {
75
78
  attachments: prepared.attachments
@@ -15,7 +15,7 @@ type WorkspaceProps = {
15
15
  // Data loading lives in React Query now (see WorkspaceLayoutProvider and the
16
16
  // useWorkspace* query hooks) — this only carries the id. Applet bundles no
17
17
  // longer read a window global for their workspace: the serve route bakes the
18
- // API base into each bundle's RPC/fileUrl calls.
18
+ // API base into each bundle's RPC/resolveUrl calls.
19
19
  export function Workspace({ id, children }: WorkspaceProps) {
20
20
  return <WorkspaceContext value={id}>{children}</WorkspaceContext>
21
21
  }
@@ -9,9 +9,11 @@ import {
9
9
  } from '@/client/features/workspace/api'
10
10
  import { workspaceKeys } from '@/client/api/workspace-keys'
11
11
  import { useLatestRef } from '@/client/lib/use-latest-ref'
12
- import type { WorkspaceLayout, WorkspaceType } from '@/lib/types'
12
+ import type { WorkspaceLayout, WorkspaceLayoutSave, WorkspaceType } from '@/lib/types'
13
13
  import { createDefaultWorkspaceLayout } from '@/lib/workspace-layout'
14
14
 
15
+ import { accumulateLayoutSave } from './layout-save'
16
+
15
17
  export type WorkspaceLayoutContextValue = {
16
18
  // The persisted layout (widget grid, layout mode, theme). Falls back to an
17
19
  // empty default while the query is still loading.
@@ -73,6 +75,7 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
73
75
  // reconcile), so reach the latest mutate via a ref instead of closing over it.
74
76
  const saveRef = useLatestRef(save.mutate)
75
77
  const timer = useRef<ReturnType<typeof setTimeout> | null>(null)
78
+ const pendingSave = useRef<WorkspaceLayoutSave | null>(null)
76
79
 
77
80
  const setLayout = useCallback(
78
81
  (update: Partial<WorkspaceLayout>) => {
@@ -82,6 +85,7 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
82
85
  // Optimistic: the grid/theme reflects the change before the PUT lands.
83
86
  const next = { ...prev, ...update }
84
87
  qc.setQueryData<WorkspaceLayoutResponse>(key, next)
88
+ pendingSave.current = accumulateLayoutSave(stripMeta(next), update, pendingSave.current)
85
89
 
86
90
  if (timer.current) clearTimeout(timer.current)
87
91
  // Persist the value captured at call time, NOT the cache at fire time: a
@@ -92,7 +96,9 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
92
96
  // optimistic write.
93
97
  timer.current = setTimeout(() => {
94
98
  timer.current = null
95
- saveRef.current(stripMeta(next))
99
+ const payload = pendingSave.current
100
+ pendingSave.current = null
101
+ if (payload) saveRef.current(payload)
96
102
  }, 600)
97
103
  },
98
104
  [id, qc, saveRef]
@@ -21,6 +21,7 @@ import type { WelcomeDestination } from '@/client/features/chat/messages/ChatEmp
21
21
  import { ChatPopup } from '@/client/features/chat/ChatPopup'
22
22
  import { ThemePanel } from '@/client/features/workspace/ThemePanel'
23
23
  import { Overview } from '@/client/features/overview/Overview'
24
+ import { WorkspaceUsersMenu } from '@/client/features/collab'
24
25
  import { PanelHeader } from '@/client/components/shared/PanelHeader'
25
26
  import { WorkspaceIcon } from '@/client/components/shared/WorkspaceIcon'
26
27
  import { Button } from '@/client/components/ui/button'
@@ -245,9 +246,11 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
245
246
  // Split needs the open set to decide whether it's available at all, and the
246
247
  // navigation hook needs split to resolve the active tab — so the open set is
247
248
  // derived from the raw layout here, before either.
248
- const openTabIds = effectiveOpenTabs(normalizeTabsState(layout.tabs), views, builders)
249
- const nonAgentOpenTabs = openTabIds.filter(tab => tab !== 'agent')
250
- const hasWorkspaceContent = nonAgentOpenTabs.length > 0
249
+ const hasWorkspaceContent = effectiveOpenTabs(
250
+ normalizeTabsState(layout.tabs),
251
+ views,
252
+ builders
253
+ ).some(tab => tab !== 'agent')
251
254
  const hasAppletWidgets = widgets.some(widget => !isDefaultWidget(widget.id))
252
255
  const hasWorkspaceApplets = hasAppletWidgets || views.length > 0
253
256
 
@@ -300,6 +303,8 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
300
303
  }
301
304
  )
302
305
 
306
+ const openTabIds = effectiveOpenTabs(tabsState, views, builders)
307
+ const nonAgentOpenTabs = openTabIds.filter(tab => tab !== 'agent')
303
308
  const openSet = new Set(tabsState.open)
304
309
 
305
310
  // Entering split with the agent tab on screen needs no special-casing
@@ -358,13 +363,11 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
358
363
  const open = tabsState.open.filter(tab => tabAvailable(tab, views, builders))
359
364
  if (open.length === tabsState.open.length) return
360
365
  const nextOpen = effectiveOpenTabs(tabsState, views, builders)
361
- setLayout({
362
- tabs: {
363
- open: nextOpen,
364
- active: nextOpen.includes(tabsState.active) ? tabsState.active : nextOpen[0]
365
- }
366
+ setTabs({
367
+ open: nextOpen,
368
+ active: nextOpen.includes(tabsState.active) ? tabsState.active : nextOpen[0]
366
369
  })
367
- }, [builders, setLayout, tabsState, views])
370
+ }, [builders, setTabs, tabsState, views])
368
371
 
369
372
  useEffect(() => {
370
373
  const replacements = new Map<WorkspaceTabId, WorkspaceTabId>()
@@ -398,8 +401,8 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
398
401
  }
399
402
  if (!changed) return
400
403
  const active = replacements.get(tabsState.active) ?? tabsState.active
401
- setLayout({ tabs: { open: open.length > 0 ? open : ['overview'], active } })
402
- }, [activeTab, builders, navigateToTab, setLayout, tabsState, views])
404
+ setTabs({ open: open.length > 0 ? open : ['overview'], active })
405
+ }, [activeTab, builders, navigateToTab, setTabs, tabsState, views])
403
406
 
404
407
  useEffect(() => {
405
408
  if (mode !== 'fullscreen' || activeTab === 'agent') {
@@ -748,6 +751,11 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
748
751
  onReorder={reorderTabs}
749
752
  />
750
753
  </div>
754
+ <WorkspaceUsersMenu
755
+ workspaceId={workspaceId}
756
+ describeTab={tab => tabItemFor(tab, views, builders, false, false, () => false)}
757
+ onOpenTab={openTab}
758
+ />
751
759
  {hasWorkspaceContent && canUseSplit && mode === 'fullscreen' && (
752
760
  <Tooltip>
753
761
  <TooltipTrigger
@@ -135,9 +135,9 @@ function WorkspaceTab(props: WorkspaceTabProps) {
135
135
  )}
136
136
  >
137
137
  {tab.loading ? (
138
- <Spinner data-icon="inline-start" />
138
+ <Spinner data-icon="inline-start" className="shrink-0" />
139
139
  ) : (
140
- <tab.Icon data-icon="inline-start" stroke={2} />
140
+ <tab.Icon data-icon="inline-start" stroke={2} className="size-4 shrink-0" />
141
141
  )}
142
142
  <span
143
143
  className={cn(
@@ -166,7 +166,7 @@ function WorkspaceTab(props: WorkspaceTabProps) {
166
166
  }
167
167
  }
168
168
  >
169
- <IconX stroke={1.75} />
169
+ <IconX stroke={1.75} className="size-4 shrink-0" />
170
170
  </div>
171
171
  )}
172
172
  </button>
@@ -10,6 +10,7 @@ import type {
10
10
  HarnessLogin,
11
11
  WorkspaceAgent,
12
12
  WorkspaceLayout,
13
+ WorkspaceLayoutSave,
13
14
  WorkspaceSkillsStatus,
14
15
  WorkspaceSkillsUpdateFailure,
15
16
  WorkspaceType
@@ -122,7 +123,7 @@ export function useUpdateWorkspaceSkills(workspaceId: string) {
122
123
 
123
124
  export function useSaveLayout(workspaceId: string) {
124
125
  const queryClient = useQueryClient()
125
- return useMutation<void, Error, WorkspaceLayout>({
126
+ return useMutation<void, Error, WorkspaceLayoutSave>({
126
127
  mutationFn: layout =>
127
128
  requestVoid(
128
129
  `/api/workspaces/${workspaceId}`,
@@ -0,0 +1,44 @@
1
+ import { useCallback, useState } from 'react'
2
+
3
+ import type { WorkspaceTabsState } from '@/lib/types'
4
+ import { normalizeWorkspaceTabs } from '@/lib/workspace-layout'
5
+
6
+ const keyFor = (workspaceId: string) => `moi:collab:${workspaceId}:tabs`
7
+
8
+ export function readWorkspaceTabs(
9
+ workspaceId: string,
10
+ defaults: WorkspaceTabsState
11
+ ): WorkspaceTabsState {
12
+ try {
13
+ const saved = sessionStorage.getItem(keyFor(workspaceId))
14
+ return saved ? normalizeWorkspaceTabs(JSON.parse(saved)) : defaults
15
+ } catch {
16
+ return defaults
17
+ }
18
+ }
19
+
20
+ export function writeWorkspaceTabs(workspaceId: string, tabs: WorkspaceTabsState): void {
21
+ try {
22
+ sessionStorage.setItem(keyFor(workspaceId), JSON.stringify(tabs))
23
+ } catch {
24
+ // The hook retains its in-memory selection when browser storage is denied.
25
+ }
26
+ }
27
+
28
+ export function useWorkspaceTabs(
29
+ workspaceId: string,
30
+ enabled: boolean,
31
+ defaults: WorkspaceTabsState
32
+ ) {
33
+ const [local, setLocal] = useState<WorkspaceTabsState>(() =>
34
+ enabled ? readWorkspaceTabs(workspaceId, defaults) : defaults
35
+ )
36
+ const setTabs = useCallback(
37
+ (tabs: WorkspaceTabsState) => {
38
+ setLocal(tabs)
39
+ writeWorkspaceTabs(workspaceId, tabs)
40
+ },
41
+ [workspaceId]
42
+ )
43
+ return [enabled ? local : defaults, setTabs] as const
44
+ }
@@ -0,0 +1,13 @@
1
+ import type { WorkspaceLayout, WorkspaceLayoutSave } from '@/lib/types'
2
+
3
+ // Unrelated edits must omit tabs from the PUT. Keep the last explicit tab edit
4
+ // through the debounce window, even if a refetch replaces the optimistic cache.
5
+ export function accumulateLayoutSave(
6
+ next: WorkspaceLayout,
7
+ update: Partial<WorkspaceLayout>,
8
+ pending: WorkspaceLayoutSave | null
9
+ ): WorkspaceLayoutSave {
10
+ const { tabs: _tabs, ...layout } = next
11
+ const tabs = update.tabs ?? pending?.tabs
12
+ return tabs === undefined ? layout : { ...layout, tabs }
13
+ }
@@ -1,7 +1,8 @@
1
1
  // Central assembly of the moi context sent with every chat message — the one
2
2
  // place that snapshots the workspace's primary UI state (active tab, view
3
3
  // titles) and drains queued one-shot directives. The structured `MoiContext`
4
- // travels to the server as-is; harnesses render it (lib/moi-context.ts).
4
+ // travels to the server, which adds server-owned fields before harnesses render
5
+ // it (lib/moi-context.ts).
5
6
  //
6
7
  // Quick API:
7
8
  //
@@ -6,6 +6,8 @@ import { usePathname, useSearch } from 'wouter/use-browser-location'
6
6
  import { toast } from '@/client/components/ui/toast'
7
7
  import { reportAppletError } from '@/client/features/applets/applet-log'
8
8
  import { useAppletEvent } from '@/client/features/applets/applet-runtime'
9
+ import { useCollabEnabled } from '@/client/features/collab'
10
+ import { useWorkspaceTabs } from '@/client/features/workspace/browser-tab-state'
9
11
  import { normalizeTabsState, resolveActiveTab, tabAvailable } from './tab-resolution'
10
12
  import { useWorkspaceLayoutCtx } from './WorkspaceLayoutContext'
11
13
  import { useLatestRef } from '@/client/lib/use-latest-ref'
@@ -17,7 +19,7 @@ import {
17
19
  legacyTabFromPath,
18
20
  parseMoiHref,
19
21
  readViewParams,
20
- resolveWorkspaceHref,
22
+ resolveUrl,
21
23
  tabFromPath,
22
24
  workspacePath
23
25
  } from '@/lib/navigation'
@@ -31,6 +33,7 @@ type UseWorkspaceNavigationOptions = { views: ViewInfo[]; builders: ViewBuilder[
31
33
 
32
34
  export function useWorkspaceNavigation({ views, builders, split }: UseWorkspaceNavigationOptions) {
33
35
  const { layout, setLayout, workspaceId } = useWorkspaceLayoutCtx()
36
+ const collabEnabled = useCollabEnabled()
34
37
  const [, navigate] = useLocation()
35
38
  const router = useRouter()
36
39
  const { base } = router
@@ -39,7 +42,12 @@ export function useWorkspaceNavigation({ views, builders, split }: UseWorkspaceN
39
42
  const path = usePathname(router).slice(workspacePath(workspaceId, base).length + 1)
40
43
  const search = canonicalSearch(useSearch(router))
41
44
  const appletParams = useMemo(() => readViewParams(search), [search])
42
- const tabsState = normalizeTabsState(layout.tabs)
45
+ const [workspaceTabs, setLocalTabs] = useWorkspaceTabs(
46
+ workspaceId,
47
+ collabEnabled,
48
+ normalizeTabsState(layout.tabs)
49
+ )
50
+ const tabsState = normalizeTabsState(workspaceTabs)
43
51
  const tabsStateRef = useLatestRef(tabsState)
44
52
  const remembered = useMemo(() => {
45
53
  let entries = rememberedAddresses.get(workspaceId)
@@ -56,9 +64,10 @@ export function useWorkspaceNavigation({ views, builders, split }: UseWorkspaceN
56
64
  const setTabs = useCallback(
57
65
  (tabs: WorkspaceTabsState) => {
58
66
  tabsStateRef.current = tabs
59
- setLayout({ tabs })
67
+ if (collabEnabled) setLocalTabs(tabs)
68
+ else setLayout({ tabs })
60
69
  },
61
- [setLayout, tabsStateRef]
70
+ [setLayout, tabsStateRef, collabEnabled, setLocalTabs]
62
71
  )
63
72
 
64
73
  const go = useCallback(
@@ -79,17 +88,20 @@ export function useWorkspaceNavigation({ views, builders, split }: UseWorkspaceN
79
88
 
80
89
  const navigateHref = useCallback(
81
90
  (href: string) => {
82
- if (!href.startsWith('moi:')) {
83
- const target = resolveWorkspaceHref(workspaceId, href, base)
91
+ const target = resolveUrl(href, {
92
+ apiBase: `/api/workspaces/${encodeURIComponent(workspaceId)}`,
93
+ workspacePath: workspacePath(workspaceId)
94
+ })
95
+ if (href.startsWith('moi:/files/') || !href.startsWith('moi:')) {
84
96
  window.location.assign(target)
85
97
  return
86
98
  }
87
99
  const address = parseMoiHref(href)
88
100
  if (!tabAvailable(address.tab, views, builders))
89
101
  throw new Error('This destination is unavailable in this workspace')
90
- go(addressPath(workspaceId, address))
102
+ go(target)
91
103
  },
92
- [base, builders, go, views, workspaceId]
104
+ [builders, go, views, workspaceId]
93
105
  )
94
106
 
95
107
  const reportError = useCallback(