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
@@ -0,0 +1,293 @@
1
+ import { expect, spyOn } from 'bun:test'
2
+ import { act, useLayoutEffect } from 'react'
3
+ import type { ReactNode } from 'react'
4
+ import * as layoutEffect from '@base-ui/utils/useIsoLayoutEffect'
5
+ import { Router } from 'wouter'
6
+ import { memoryLocation } from 'wouter/memory-location'
7
+ import { parseHTML } from 'linkedom'
8
+ import { QueryClient, QueryClientProvider, notifyManager } from '@tanstack/react-query'
9
+ import * as config from '@/client/api/app-config'
10
+ import { publishUsers } from '@/client/features/collab/host-state'
11
+ import { AccountProvider, useAccount } from './account-provider'
12
+ import { sessionQuery, teamQuery } from './api'
13
+ import type { CloudSession, CloudTeam } from './api'
14
+
15
+ const session: CloudSession = {
16
+ user: { id: 'me', name: 'Alex', email: 'alex@example.com', isAnonymous: false }
17
+ }
18
+ export const ownerTeam: CloudTeam = {
19
+ id: 'team',
20
+ name: 'Team',
21
+ role: 'owner',
22
+ members: [
23
+ {
24
+ id: 'member-me',
25
+ userId: 'me',
26
+ name: 'Alex',
27
+ email: 'alex@example.com',
28
+ role: 'owner',
29
+ me: true
30
+ },
31
+ {
32
+ id: 'member-ada',
33
+ userId: 'ada',
34
+ name: 'Ada',
35
+ email: 'ada@example.com',
36
+ role: 'admin',
37
+ me: false
38
+ }
39
+ ],
40
+ invitations: [
41
+ { id: 'invite-1', email: 'grace@example.com', role: 'admin', expiresAt: '2030-01-01' }
42
+ ]
43
+ }
44
+ let cleanup = async () => {}
45
+ export const cleanupAccount = () => cleanup()
46
+
47
+ export type AccountFixtureOptions = {
48
+ children?: ReactNode
49
+ role?: string
50
+ anonymous?: boolean
51
+ signedOut?: boolean
52
+ demo?: boolean
53
+ failTeam?: boolean
54
+ environment?: 'local' | 'cloud'
55
+ failSession?: boolean
56
+ loadingSession?: boolean
57
+ pendingMutation?: boolean
58
+ pendingMutationPaths?: string[]
59
+ injected?: boolean
60
+ loadingTeam?: boolean
61
+ }
62
+ export async function mountAccount({
63
+ children = <AccountProbe />,
64
+ role = 'owner',
65
+ anonymous = false,
66
+ signedOut = false,
67
+ demo = false,
68
+ failTeam = false,
69
+ environment = 'cloud',
70
+ failSession = false,
71
+ loadingSession = false,
72
+ pendingMutation = false,
73
+ pendingMutationPaths = [],
74
+ injected = true,
75
+ loadingTeam = false
76
+ }: AccountFixtureOptions = {}) {
77
+ const { window, document } = parseHTML('<html><body><div id="root"></div></body></html>')
78
+ Object.defineProperty(document, 'oninput', { value: null, configurable: true })
79
+ const navigations: string[] = []
80
+ Object.defineProperty(window, 'location', {
81
+ configurable: true,
82
+ value: {
83
+ assign: (href: string) => navigations.push(href),
84
+ replace: (href: string) => navigations.push(href)
85
+ }
86
+ })
87
+ const globals = {
88
+ window,
89
+ document,
90
+ HTMLElement: window.HTMLElement,
91
+ Element: window.Element,
92
+ requestAnimationFrame: (callback: FrameRequestCallback) =>
93
+ Number(setTimeout(() => callback(performance.now()), 0)),
94
+ cancelAnimationFrame: (id: number) => clearTimeout(id),
95
+ getComputedStyle: (element: HTMLElement) =>
96
+ new Proxy(element.style, { get: (style, key) => Reflect.get(style, key) ?? '' }),
97
+ Node: window.Node,
98
+ KeyboardEvent: class extends window.Event {},
99
+ FocusEvent: class extends window.Event {},
100
+ MouseEvent: class extends window.Event {},
101
+ IS_REACT_ACT_ENVIRONMENT: true
102
+ }
103
+ const descriptors = new Map(
104
+ Object.keys(globals).map(key => [key, Object.getOwnPropertyDescriptor(globalThis, key)])
105
+ )
106
+ for (const [key, value] of Object.entries(globals))
107
+ Object.defineProperty(globalThis, key, { configurable: true, value })
108
+ // Base UI was imported before this fixture installed a DOM. Enable its browser effects.
109
+ const layoutEffectSpy = spyOn(layoutEffect, 'useIsoLayoutEffect').mockImplementation(
110
+ useLayoutEffect
111
+ )
112
+ const configSpy = spyOn(config, 'useAppConfig').mockReturnValue({
113
+ environment,
114
+ demo,
115
+ demoInstallUrl: '/',
116
+ experimental: { collab: true }
117
+ })
118
+ let cloudSession: CloudSession = signedOut
119
+ ? null
120
+ : { user: { ...session!.user, isAnonymous: anonymous } }
121
+ let team: CloudTeam = structuredClone({ ...ownerTeam, role })
122
+ const failures = { signOut: false, mutation: false, team: failTeam, session: failSession }
123
+ const mutationRequest = Promise.withResolvers<void>()
124
+ const teamResponse = Promise.withResolvers<Response>()
125
+ const calls: { path: string; body?: Record<string, string> }[] = []
126
+ const fetchSpy = spyOn(globalThis, 'fetch').mockImplementation(
127
+ Object.assign(
128
+ async (input: RequestInfo | URL, init?: RequestInit) => {
129
+ const path = String(input)
130
+ const body = init?.body
131
+ ? (JSON.parse(String(init.body)) as Record<string, string>)
132
+ : undefined
133
+ calls.push({ path, body })
134
+ if (path.endsWith('/get-session')) {
135
+ if (loadingSession) return new Promise<Response>(() => {})
136
+ return failures.session
137
+ ? Response.json({ error: 'Session unavailable' }, { status: 503 })
138
+ : Response.json(cloudSession)
139
+ }
140
+ if (path.endsWith('/organization')) {
141
+ if (loadingTeam) return teamResponse.promise
142
+ return failures.team
143
+ ? Response.json({ error: 'Team unavailable' }, { status: 503 })
144
+ : Response.json(team)
145
+ }
146
+ if (path.endsWith('/sign-out')) {
147
+ if (failures.signOut)
148
+ return Response.json({ error: 'Try signing out again.' }, { status: 503 })
149
+ cloudSession = null
150
+ return Response.json({ success: true })
151
+ }
152
+ if (
153
+ pendingMutation &&
154
+ (pendingMutationPaths.length === 0 ||
155
+ pendingMutationPaths.some(suffix => path.endsWith(suffix)))
156
+ )
157
+ await mutationRequest.promise
158
+ if (failures.mutation)
159
+ return Response.json({ error: 'Only the owner can do that.' }, { status: 403 })
160
+ if (path.endsWith('/profile')) {
161
+ cloudSession = { user: { ...session!.user, name: body!.name! } }
162
+ team.members[0]!.name = body!.name!
163
+ return Response.json({ success: true, name: body!.name })
164
+ }
165
+ if (path.endsWith('/members/remove'))
166
+ team.members = team.members.filter(member => member.id !== body!.memberId)
167
+ if (path.endsWith('/cancel')) team.invitations = []
168
+ if (path.endsWith('/invite'))
169
+ team.invitations.push({
170
+ id: 'invite-new',
171
+ email: body!.email!,
172
+ role: 'admin',
173
+ expiresAt: '2030-01-01'
174
+ })
175
+ return Response.json({ success: true })
176
+ },
177
+ { preconnect: fetch.preconnect }
178
+ )
179
+ )
180
+ const qc = new QueryClient({
181
+ defaultOptions: { queries: { retry: false }, mutations: { retry: false } }
182
+ })
183
+ if (!failSession && !loadingSession)
184
+ qc.setQueryData(sessionQuery.queryKey, structuredClone(cloudSession))
185
+ if (!failTeam && !loadingTeam)
186
+ qc.setQueryData(teamQuery(cloudSession?.user.id).queryKey, structuredClone(team))
187
+ publishUsers({ users: [] })
188
+ if (injected)
189
+ publishUsers({
190
+ me: 'me',
191
+ users: [
192
+ {
193
+ id: 'me',
194
+ name: 'Alex',
195
+ email: 'alex@example.com',
196
+ color: 'blue',
197
+ avatar: 'https://example.com/avatar.png'
198
+ },
199
+ { id: 'ada', name: 'Ada', email: 'ada@example.com', color: 'cyan' }
200
+ ]
201
+ })
202
+ const { createRoot } = await import('react-dom/client')
203
+ const root = createRoot(document.getElementById('root')!)
204
+ notifyManager.setNotifyFunction(callback => {
205
+ act(callback)
206
+ })
207
+ const location = memoryLocation({ path: '/settings', record: true })
208
+ await act(async () =>
209
+ root.render(
210
+ <QueryClientProvider client={qc}>
211
+ <Router hook={location.hook}>
212
+ <AccountProvider>{children}</AccountProvider>
213
+ </Router>
214
+ </QueryClientProvider>
215
+ )
216
+ )
217
+ async function settle() {
218
+ await act(async () => {
219
+ await new Promise(resolve => setTimeout(resolve, 5))
220
+ })
221
+ }
222
+ cleanup = async () => {
223
+ await act(async () => root.unmount())
224
+ qc.clear()
225
+ publishUsers({ users: [] })
226
+ layoutEffectSpy.mockRestore()
227
+ configSpy.mockRestore()
228
+ fetchSpy.mockRestore()
229
+ notifyManager.setNotifyFunction(callback => callback())
230
+ for (const [key, descriptor] of descriptors) {
231
+ if (descriptor) Object.defineProperty(globalThis, key, descriptor)
232
+ else Reflect.deleteProperty(globalThis, key)
233
+ }
234
+ }
235
+ return {
236
+ document,
237
+ window,
238
+ calls,
239
+ failures,
240
+ mutationRequest,
241
+ teamResponse,
242
+ qc,
243
+ navigations,
244
+ location,
245
+ settle,
246
+ async click(label: string) {
247
+ const button = [...document.querySelectorAll<HTMLElement>('button, [role="menuitem"]')].find(
248
+ button => button.getAttribute('aria-label') === label || button.textContent === label
249
+ )
250
+ expect(button).toBeDefined()
251
+ await act(async () => {
252
+ const event = new window.Event('mousedown', { bubbles: true, cancelable: true })
253
+ Object.defineProperty(event, 'button', { value: 0 })
254
+ button!.dispatchEvent(event)
255
+ button!.click()
256
+ })
257
+ await settle()
258
+ },
259
+ async type(input: HTMLInputElement, value: string) {
260
+ await act(async () => {
261
+ input.type = input.id === 'invite-email' ? 'email' : 'text'
262
+ // React may have loaded before a DOM in the full suite; also exercise its
263
+ // legacy input-event fallback through real focus and keyboard events.
264
+ Object.assign(input, { attachEvent() {}, detachEvent() {} })
265
+ input.dispatchEvent(new window.Event('focusin', { bubbles: true }))
266
+ Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')!.set!.call(
267
+ input,
268
+ value
269
+ )
270
+ input.dispatchEvent(new window.Event('input', { bubbles: true }))
271
+ input.dispatchEvent(new window.Event('keyup', { bubbles: true }))
272
+ })
273
+ }
274
+ }
275
+ }
276
+
277
+ type AccountProbeProps = { children?: ReactNode }
278
+ export function AccountProbe({ children }: AccountProbeProps) {
279
+ const account = useAccount()
280
+ return (
281
+ <>
282
+ <p data-account-status>{account.status}</p>
283
+ <p data-account-name>{account.profile?.name}</p>
284
+ {account.status === 'ready' && children}
285
+ {account.registered && (
286
+ <button disabled={account.signOut.isPending} onClick={() => account.signOut.mutate()}>
287
+ Sign out
288
+ </button>
289
+ )}
290
+ {account.signOut.error && <p role="alert">{account.signOut.error.message}</p>}
291
+ </>
292
+ )
293
+ }
@@ -0,0 +1,142 @@
1
+ import { queryOptions } from '@tanstack/react-query'
2
+ import { jsonRequest } from '@/client/api/http'
3
+ import { isRecord, isUserProfile } from '@/lib/collab/protocol'
4
+
5
+ export type CloudSession = {
6
+ user: { id: string; email: string; name: string; isAnonymous: boolean }
7
+ } | null
8
+ export type TeamMember = {
9
+ id: string
10
+ userId: string
11
+ email: string
12
+ name: string
13
+ role: string
14
+ me: boolean
15
+ }
16
+ export type TeamInvitation = { id: string; email: string; role: string; expiresAt: string }
17
+ export type CloudTeam = {
18
+ id: string
19
+ name: string
20
+ role: string
21
+ members: TeamMember[]
22
+ invitations: TeamInvitation[]
23
+ }
24
+
25
+ export const accountKeys = {
26
+ all: ['account'] as const,
27
+ session: ['account', 'session'] as const,
28
+ team: ['account', 'team'] as const
29
+ }
30
+
31
+ export class CloudApiError extends Error {
32
+ constructor(
33
+ message: string,
34
+ readonly status: number
35
+ ) {
36
+ super(message)
37
+ }
38
+ }
39
+
40
+ export async function cloudRequest(path: string, init?: RequestInit): Promise<Response> {
41
+ const response = await fetch(`/cloud/api/auth/${path}`, { ...init, credentials: 'same-origin' })
42
+ if (!response.ok) {
43
+ const body: unknown = await response.json().catch(() => undefined)
44
+ const message = isRecord(body)
45
+ ? [body.error, body.message].find(
46
+ (value): value is string => typeof value === 'string' && value.trim().length > 0
47
+ )
48
+ : undefined
49
+ throw new CloudApiError(
50
+ message ?? 'Couldn’t complete this request. Try again.',
51
+ response.status
52
+ )
53
+ }
54
+ return response
55
+ }
56
+
57
+ function validProfile(id: unknown, name: unknown, email: unknown): boolean {
58
+ return (
59
+ typeof id === 'string' &&
60
+ id === id.trim() &&
61
+ typeof name === 'string' &&
62
+ typeof email === 'string' &&
63
+ isUserProfile({ id, name: name.trim() || undefined, email, color: 'blue' })
64
+ )
65
+ }
66
+
67
+ function parseSession(value: unknown): CloudSession {
68
+ if (value === null) return null
69
+ if (
70
+ !isRecord(value) ||
71
+ !isRecord(value.user) ||
72
+ !validProfile(value.user.id, value.user.name, value.user.email) ||
73
+ typeof value.user.isAnonymous !== 'boolean'
74
+ )
75
+ throw new Error('Invalid account response')
76
+ return value as NonNullable<CloudSession>
77
+ }
78
+
79
+ function parseTeam(value: unknown): CloudTeam {
80
+ if (
81
+ !isRecord(value) ||
82
+ typeof value.id !== 'string' ||
83
+ typeof value.name !== 'string' ||
84
+ typeof value.role !== 'string' ||
85
+ !Array.isArray(value.members) ||
86
+ !Array.isArray(value.invitations) ||
87
+ !value.members.every(
88
+ member =>
89
+ isRecord(member) &&
90
+ typeof member.id === 'string' &&
91
+ validProfile(member.userId, member.name, member.email) &&
92
+ typeof member.role === 'string' &&
93
+ typeof member.me === 'boolean'
94
+ ) ||
95
+ !value.invitations.every(
96
+ invitation =>
97
+ isRecord(invitation) &&
98
+ validProfile(invitation.id, '', invitation.email) &&
99
+ typeof invitation.role === 'string' &&
100
+ typeof invitation.expiresAt === 'string' &&
101
+ Number.isFinite(Date.parse(invitation.expiresAt))
102
+ )
103
+ )
104
+ throw new Error('Invalid users response')
105
+ const team = value as CloudTeam
106
+ if (
107
+ new Set(team.members.map(member => member.userId)).size !== team.members.length ||
108
+ new Set(team.members.map(member => member.id)).size !== team.members.length ||
109
+ new Set(team.invitations.map(invitation => invitation.id)).size !== team.invitations.length
110
+ )
111
+ throw new Error('Invalid users response')
112
+ return team
113
+ }
114
+
115
+ export const sessionQuery = queryOptions({
116
+ queryKey: accountKeys.session,
117
+ queryFn: async ({ signal }) => {
118
+ const response = await cloudRequest('get-session', { signal })
119
+ return parseSession(await response.json())
120
+ },
121
+ retry: false,
122
+ staleTime: 30_000
123
+ })
124
+ export const teamQuery = (userId?: string) =>
125
+ queryOptions({
126
+ queryKey: [...accountKeys.team, userId],
127
+ queryFn: async ({ signal }) => {
128
+ const response = await cloudRequest('organization', { signal })
129
+ return parseTeam(await response.json())
130
+ },
131
+ retry: false,
132
+ staleTime: 30_000
133
+ })
134
+ export const updateCloudName = (name: string) =>
135
+ cloudRequest('profile', jsonRequest('POST', { name }))
136
+ export const signOutCloud = () => cloudRequest('sign-out', jsonRequest('POST'))
137
+ export const inviteMember = (email: string) =>
138
+ cloudRequest('invite', jsonRequest('POST', { email }))
139
+ export const cancelInvitation = (id: string) =>
140
+ cloudRequest(`invitation/${encodeURIComponent(id)}/cancel`, jsonRequest('POST'))
141
+ export const removeMember = (memberId: string) =>
142
+ cloudRequest('members/remove', jsonRequest('POST', { memberId }))
@@ -0,0 +1,23 @@
1
+ import { getCurrentUser, getDirectory, publishUsers } from '@/client/features/collab/host-state'
2
+ import type { CloudSession, CloudTeam } from './api'
3
+
4
+ // The session identifies the viewer. Keep the injected directory until the team
5
+ // request resolves, and preserve known avatar and color information by user id.
6
+ export function syncCloudIdentity(session: CloudSession, team?: CloudTeam): void {
7
+ if (!session || session.user.isAnonymous) {
8
+ publishUsers({ users: [] })
9
+ return
10
+ }
11
+ const { id, name, email } = session.user
12
+ const sameAccount = getCurrentUser()?.id === id
13
+ const known = new Map((getDirectory() ?? []).map(user => [user.id, user]))
14
+ const users =
15
+ team?.members.map(user => ({
16
+ ...known.get(user.userId),
17
+ id: user.userId,
18
+ name: user.name,
19
+ email: user.email
20
+ })) ?? (sameAccount ? [...known.values()] : [])
21
+ const profile = { ...known.get(id), id, name, email }
22
+ publishUsers({ me: id, users: [...users.filter(user => user.id !== id), profile] })
23
+ }
@@ -32,7 +32,7 @@ export function useSaveAppletThumbnails(workspaceId: string) {
32
32
  ),
33
33
  onSuccess: () => {
34
34
  queryClient.invalidateQueries({ queryKey: workspaceKeys.appletThumbnails(workspaceId) })
35
- queryClient.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
35
+ queryClient.invalidateQueries({ queryKey: workspaceKeys.previews })
36
36
  }
37
37
  })
38
38
  }
@@ -99,7 +99,7 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
99
99
  if (!cachedSession) {
100
100
  queryClient?.invalidateQueries({ queryKey: sessionsKey })
101
101
  }
102
- queryClient?.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
102
+ queryClient?.invalidateQueries({ queryKey: workspaceKeys.previews })
103
103
  return
104
104
  }
105
105
  if (data.type === 'sessions_changed' || data.type === 'session_archived') {
@@ -108,7 +108,7 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
108
108
  applyArchivedSession(queryClient, workspaceId, data.sessionId)
109
109
  const sessionsKey = workspaceKeys.sessions(workspaceId)
110
110
  queryClient?.invalidateQueries({ queryKey: sessionsKey })
111
- queryClient?.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
111
+ queryClient?.invalidateQueries({ queryKey: workspaceKeys.previews })
112
112
  if (typeof data.sessionId === 'string')
113
113
  queryClient?.invalidateQueries({
114
114
  queryKey: workspaceKeys.session(workspaceId, data.sessionId)
@@ -129,7 +129,7 @@ export function useArchiveWorkspaceSession(workspaceId: string) {
129
129
  ),
130
130
  onSuccess: (_, sessionId) => {
131
131
  applyArchivedSession(queryClient, workspaceId, sessionId)
132
- queryClient.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
132
+ queryClient.invalidateQueries({ queryKey: workspaceKeys.previews })
133
133
  }
134
134
  })
135
135
  }
@@ -187,7 +187,7 @@ export function useChat(address: WorkspaceTabAddress) {
187
187
  })
188
188
  finishComposerSend(workspaceId, ready)
189
189
  if (isNew) {
190
- qc.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
190
+ qc.invalidateQueries({ queryKey: workspaceKeys.previews })
191
191
  }
192
192
  },
193
193
  [
@@ -1,11 +1,11 @@
1
1
  import type * as CollabApi from 'moi/collab'
2
- import { UserAvatarGroup } from './components/user-avatar-group'
3
- import { User } from './components/user'
4
- import { UserAvatar } from './components/user-avatar'
5
- import { Cursors } from './components/cursors'
6
- import { PresenceFrame } from './components/presence-frame'
7
- import { PresenceGroup } from './components/presence-group'
8
- import { PresenceAvatars } from './components/presence-avatars'
2
+ import { UserAvatarGroupContainer } from './components/user-avatar-group'
3
+ import { UserContainer } from './components/user'
4
+ import { UserAvatarContainer } from './components/user-avatar'
5
+ import { CursorsContainer } from './components/cursors'
6
+ import { PresenceFrameContainer } from './components/presence-frame'
7
+ import { PresenceGroupContainer } from './components/presence-group'
8
+ import { PresenceAvatarsContainer } from './components/presence-avatars'
9
9
  import {
10
10
  useMe,
11
11
  usePeers,
@@ -17,14 +17,15 @@ import {
17
17
 
18
18
  export type AppletCollabApi = typeof CollabApi
19
19
 
20
+ // SDK components resolve collaboration data; host UI can import the plain components.
20
21
  export const appletCollabApi = {
21
- Cursors,
22
- User,
23
- UserAvatar,
24
- UserAvatarGroup,
25
- PresenceFrame,
26
- PresenceAvatars,
27
- PresenceGroup,
22
+ Cursors: CursorsContainer,
23
+ User: UserContainer,
24
+ UserAvatar: UserAvatarContainer,
25
+ UserAvatarGroup: UserAvatarGroupContainer,
26
+ PresenceFrame: PresenceFrameContainer,
27
+ PresenceAvatars: PresenceAvatarsContainer,
28
+ PresenceGroup: PresenceGroupContainer,
28
29
  useMe,
29
30
  usePeers,
30
31
  useUser,