moi-computer 0.13.1-next.0 → 0.13.1-next.1

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 (82) hide show
  1. package/client/api/app-config.ts +0 -1
  2. package/client/app/routes/workspace-route.tsx +4 -7
  3. package/client/features/account/account-test-utils.tsx +13 -5
  4. package/client/features/account/api.ts +4 -2
  5. package/client/features/account/profile-actions.ts +1 -1
  6. package/client/features/app-settings/avatar-upload.tsx +62 -0
  7. package/client/features/app-settings/profile-settings.tsx +10 -0
  8. package/client/features/chat/applet-chat-intents.ts +4 -4
  9. package/client/features/chat/sessions/api.ts +5 -5
  10. package/client/features/chat/sessions/use-selected-session.ts +3 -3
  11. package/client/features/chat/use-chat.ts +4 -4
  12. package/client/features/collab/applet-api.ts +1 -1
  13. package/client/features/collab/components/cursors.tsx +6 -1
  14. package/client/features/collab/components/presence-avatars.tsx +1 -1
  15. package/client/features/collab/components/presence-frame.tsx +1 -1
  16. package/client/features/collab/components/presence-group.tsx +1 -1
  17. package/client/features/collab/components/presence-helpers.ts +2 -2
  18. package/client/features/collab/components/user-avatar-group.tsx +1 -1
  19. package/client/features/collab/components/user-avatar.tsx +1 -1
  20. package/client/features/collab/components/user.tsx +1 -1
  21. package/client/features/collab/index.ts +3 -3
  22. package/client/features/{workspace-members → collab/members}/api.ts +6 -3
  23. package/client/features/{workspace-members → collab/members}/hooks.ts +11 -35
  24. package/client/features/{workspace-members → collab/members}/store.ts +4 -4
  25. package/client/features/{workspace-members → collab/members}/types.ts +2 -2
  26. package/client/features/collab/{client.ts → presence/client.ts} +2 -2
  27. package/client/features/collab/{provider.tsx → presence/provider.tsx} +1 -12
  28. package/client/features/collab/{users.ts → presence/users.ts} +19 -21
  29. package/client/features/collab/sharing/agent-invite.tsx +30 -0
  30. package/client/features/collab/sharing/workspace-members.tsx +277 -0
  31. package/client/features/collab/sharing/workspace-sharing-menu.tsx +179 -0
  32. package/client/features/collab/testing/component-fixtures.tsx +3 -3
  33. package/client/features/collab/testing/fake-engine.ts +2 -2
  34. package/client/features/dev/collab/collab-playground.tsx +2 -2
  35. package/client/features/dev/dev-index-page.tsx +0 -6
  36. package/client/features/dev/dev-routes.tsx +0 -2
  37. package/client/features/dev/workspace-setup-mocks.ts +0 -1
  38. package/client/features/identity/host-api.ts +2 -2
  39. package/client/features/identity/store.ts +1 -1
  40. package/client/features/views/use-view-actions.ts +3 -3
  41. package/client/features/workspace/browser-tab-state.ts +6 -6
  42. package/client/features/workspace/workspace-content.tsx +10 -6
  43. package/dist/{chunk-00s35r33.js → chunk-3smkkcfw.js} +76 -76
  44. package/dist/chunk-47h9c2qy.js +2 -0
  45. package/dist/chunk-8qed2gqp.js +75 -0
  46. package/dist/{chunk-7rz6g7g7.js → chunk-8zy3vesm.js} +1 -1
  47. package/dist/{chunk-s5s1vzdw.js → chunk-a47zy276.js} +2 -2
  48. package/dist/chunk-g4c1nte9.css +1 -0
  49. package/dist/chunk-kcactdr4.js +2 -0
  50. package/dist/chunk-m8bhx6tw.js +1 -0
  51. package/dist/{chunk-svxhxfeq.js → chunk-pf19zcrn.js} +2 -2
  52. package/dist/{chunk-kdgk4dac.js → chunk-th91xfnp.js} +1 -1
  53. package/dist/chunk-ygzxah0e.js +1 -0
  54. package/dist/index.html +1 -1
  55. package/lib/types.ts +0 -1
  56. package/package.json +1 -1
  57. package/server/app-config.ts +2 -7
  58. package/server/applets/declarations.ts +6 -7
  59. package/server/cli/commands/init.ts +0 -11
  60. package/server/collab/config.ts +1 -5
  61. package/server/collab/manager.ts +5 -2
  62. package/server/collab/skill/index.ts +1 -47
  63. package/server/skills/template.ts +3 -2
  64. package/server/skills/update.ts +1 -1
  65. package/server/skills/workspace.ts +0 -2
  66. package/server/web.ts +1 -2
  67. package/server/workspaces/scaffold.ts +1 -0
  68. package/skill/SKILL.md +1 -1
  69. package/client/features/collab/workspace-users-menu.tsx +0 -190
  70. package/client/features/dev/cloud-avatar-upload.tsx +0 -58
  71. package/client/features/dev/cloud-page.tsx +0 -363
  72. package/dist/chunk-af2jyddf.js +0 -2
  73. package/dist/chunk-cekekc3f.css +0 -1
  74. package/dist/chunk-ep5vh16c.js +0 -75
  75. package/dist/chunk-t0r0bds1.js +0 -1
  76. package/dist/chunk-vp2qzc0d.js +0 -1
  77. package/dist/chunk-wz5qv1bn.js +0 -2
  78. /package/client/features/{workspace-members → collab/members}/keys.ts +0 -0
  79. /package/client/features/collab/{hooks.tsx → presence/hooks.tsx} +0 -0
  80. /package/client/features/collab/{presence-publisher.ts → presence/presence-publisher.ts} +0 -0
  81. /package/client/features/collab/{presence-target.ts → presence/presence-target.ts} +0 -0
  82. /package/client/features/collab/{store.ts → presence/store.ts} +0 -0
@@ -12,7 +12,6 @@ import { requestJson } from './http'
12
12
 
13
13
  const DEFAULTS: ClientAppConfig = {
14
14
  environment: 'local',
15
- collab: false,
16
15
  demo: false,
17
16
  demoInstallUrl: 'https://moi.computer'
18
17
  }
@@ -1,7 +1,7 @@
1
- import { useWorkspaceMembers } from '@/client/features/workspace-members/hooks'
1
+ import { useWorkspaceMembers } from '@/client/features/collab/members/hooks'
2
2
  import { useWorkspaceHarnessChanges } from '@/client/features/workspace/harness-transition'
3
3
  import { useWorkspaceTheme } from '@/client/runtime/workspace-theme'
4
- import { CollabProvider, useCollabEnabled } from '@/client/features/collab'
4
+ import { CollabProvider } from '@/client/features/collab'
5
5
  import { useQueryClient } from '@tanstack/react-query'
6
6
 
7
7
  import { workspaceKeys } from '@/client/api/workspace-keys'
@@ -28,13 +28,13 @@ type WorkspaceRouteProps = {
28
28
  // are decoded exactly once; the route only owns the workspace ID.
29
29
  export function WorkspaceRoute({ id }: WorkspaceRouteProps) {
30
30
  useWorkspaceMembers(id)
31
- const { collab } = useAppConfig()
31
+ const { environment } = useAppConfig()
32
32
 
33
33
  return (
34
34
  <SidebarLayout>
35
35
  <Workspace id={id}>
36
36
  <WorkspaceLayoutProvider id={id}>
37
- <CollabProvider workspaceId={id} enabled={collab}>
37
+ <CollabProvider workspaceId={id} enabled={environment === 'cloud'}>
38
38
  <WorkspaceContent id={id} />
39
39
  </CollabProvider>
40
40
  </WorkspaceLayoutProvider>
@@ -44,7 +44,6 @@ export function WorkspaceRoute({ id }: WorkspaceRouteProps) {
44
44
  }
45
45
 
46
46
  function WorkspaceContent({ id }: WorkspaceRouteProps) {
47
- const collabEnabled = useCollabEnabled()
48
47
  const queryClient = useQueryClient()
49
48
  const [selectedSessionId] = useSelectedSession()
50
49
  const { isLoading: layoutLoading, layout, provider } = useWorkspaceLayoutCtx()
@@ -75,9 +74,7 @@ function WorkspaceContent({ id }: WorkspaceRouteProps) {
75
74
  layoutLoading || selectedSessionId === undefined || widgets.isLoading || views.isLoading
76
75
 
77
76
  return (
78
- // Reset the screen when switching between shared and browser tab state.
79
77
  <WorkspaceScreen
80
- key={collabEnabled ? 'browser-tab' : 'shared'}
81
78
  contentPending={contentPending}
82
79
  widgets={widgets.data}
83
80
  views={views.data ?? []}
@@ -9,7 +9,7 @@ import { QueryClientProvider, notifyManager } from '@tanstack/react-query'
9
9
  import * as config from '@/client/api/app-config'
10
10
  import { AccountProvider, useAccount } from './account-provider'
11
11
  import { queryClient } from '@/client/api/query-client'
12
- import type { WorkspaceMembers } from '../workspace-members/types'
12
+ import type { WorkspaceMembers } from '../collab/members/types'
13
13
  import { setIdentity } from '../identity/store'
14
14
  import type { Identity } from '../identity/types'
15
15
 
@@ -32,6 +32,7 @@ export type AccountFixtureOptions = {
32
32
  environment?: 'local' | 'cloud'
33
33
  failSession?: boolean
34
34
  loadingSession?: boolean
35
+ pendingMembership?: boolean
35
36
  pendingMutation?: boolean
36
37
  pendingMutationPaths?: string[]
37
38
  injected?: boolean
@@ -44,6 +45,7 @@ export async function mountAccount({
44
45
  environment = 'cloud',
45
46
  failSession = false,
46
47
  loadingSession = false,
48
+ pendingMembership = false,
47
49
  pendingMutation = false,
48
50
  pendingMutationPaths = [],
49
51
  injected = true
@@ -54,6 +56,7 @@ export async function mountAccount({
54
56
  Object.defineProperty(window, 'location', {
55
57
  configurable: true,
56
58
  value: {
59
+ pathname: '/settings',
57
60
  assign: (href: string) => navigations.push(href),
58
61
  replace: (href: string) => navigations.push(href)
59
62
  }
@@ -87,14 +90,14 @@ export async function mountAccount({
87
90
  const configSpy = spyOn(config, 'useAppConfig').mockReturnValue({
88
91
  environment,
89
92
  demo,
90
- collab: false,
91
93
  demoInstallUrl: '/'
92
94
  })
93
95
  let cloudSession: Identity | null = signedOut
94
96
  ? null
95
97
  : { ...session, type: 'user', email: 'alex@example.com', isAnonymous: anonymous }
96
- const failures = { signOut: false, mutation: false, session: failSession }
98
+ const failures = { signOut: false, mutation: false, session: failSession, membership: false }
97
99
  const mutationRequest = Promise.withResolvers<void>()
100
+ const membershipRequest = Promise.withResolvers<void>()
98
101
  let membership: WorkspaceMembers = {
99
102
  members: [{ ...session, membershipId: 'member-me' }],
100
103
  invitations: []
@@ -123,8 +126,12 @@ export async function mountAccount({
123
126
  ? Response.json(cloudSession)
124
127
  : Response.json({ error: 'No session' }, { status: 401 })
125
128
  }
126
- if (path.endsWith('/members') && (!init?.method || init.method === 'GET'))
127
- return Response.json(membership)
129
+ if (path.endsWith('/members') && (!init?.method || init.method === 'GET')) {
130
+ if (pendingMembership) await membershipRequest.promise
131
+ return failures.membership
132
+ ? Response.json({ error: 'Members unavailable' }, { status: 503 })
133
+ : Response.json(membership)
134
+ }
128
135
  if (path.endsWith('/sign-out')) {
129
136
  if (failures.signOut)
130
137
  return Response.json({ error: 'Try signing out again.' }, { status: 503 })
@@ -238,6 +245,7 @@ export async function mountAccount({
238
245
  calls,
239
246
  failures,
240
247
  mutationRequest,
248
+ membershipRequest,
241
249
  qc,
242
250
  setMembership: (next: WorkspaceMembers) => {
243
251
  membership = next
@@ -12,7 +12,8 @@ export const accountKeys = {
12
12
  export class CloudApiError extends Error {
13
13
  constructor(
14
14
  message: string,
15
- readonly status: number
15
+ readonly status: number,
16
+ readonly code?: string
16
17
  ) {
17
18
  super(message)
18
19
  }
@@ -28,7 +29,8 @@ export async function cloudRequest(path: string, init?: RequestInit): Promise<Re
28
29
  : undefined
29
30
  throw new CloudApiError(
30
31
  message ?? 'Couldn’t complete this request. Try again.',
31
- response.status
32
+ response.status,
33
+ isRecord(body) && typeof body.code === 'string' ? body.code : undefined
32
34
  )
33
35
  }
34
36
  return response
@@ -2,7 +2,7 @@ import { queryClient } from '@/client/api/query-client'
2
2
  import { getIdentity, setIdentity, getAccountGeneration } from '../identity/store'
3
3
  import { identityKey } from '../identity/types'
4
4
  import type { Identity } from '../identity/types'
5
- import { memberKeys } from '../workspace-members/keys'
5
+ import { memberKeys } from '../collab/members/keys'
6
6
 
7
7
  export async function saveCloudProfile(field: 'name' | 'avatar', update: () => Promise<Identity>) {
8
8
  const before = getIdentity()
@@ -0,0 +1,62 @@
1
+ import { useRef, type ReactNode } from 'react'
2
+ import { useMutation } from '@tanstack/react-query'
3
+ import { IconCamera, IconLoader } from '@tabler/icons-react'
4
+ import { Button } from '@/client/components/ui/button'
5
+ import { cn } from '@/client/lib/cn'
6
+ import { toast } from '@/client/components/ui/toast'
7
+ import { useAccount } from '../account/account-provider'
8
+
9
+ type AvatarUploadProps = { children: ReactNode }
10
+
11
+ export function AvatarUpload({ children }: AvatarUploadProps) {
12
+ const account = useAccount()
13
+ const input = useRef<HTMLInputElement>(null)
14
+ const upload = useMutation({
15
+ mutationFn: (file: File) => account.saveAvatar(file),
16
+ onSuccess: () => toast.add({ title: 'Avatar updated', type: 'success' }),
17
+ onError: error =>
18
+ toast.add({ title: 'Couldn’t update avatar', description: error.message, type: 'error' })
19
+ })
20
+
21
+ return (
22
+ <div className="flex items-start">
23
+ <input
24
+ ref={input}
25
+ type="file"
26
+ accept="image/*"
27
+ aria-label="Choose an avatar file"
28
+ className="hidden"
29
+ disabled={upload.isPending}
30
+ onChange={event => {
31
+ const file = event.currentTarget.files?.[0]
32
+ event.currentTarget.value = ''
33
+ if (file) upload.mutate(file)
34
+ }}
35
+ />
36
+ <Button
37
+ variant="ghost"
38
+ size="icon"
39
+ className="group/avatar relative size-16 overflow-hidden rounded-full p-0"
40
+ aria-label="Change your avatar"
41
+ aria-busy={upload.isPending}
42
+ disabled={upload.isPending || !account.registered}
43
+ onClick={() => input.current?.click()}
44
+ >
45
+ {children}
46
+ <span
47
+ aria-hidden="true"
48
+ className={cn(
49
+ 'pointer-events-none absolute inset-0 flex items-center justify-center rounded-full bg-background/70 opacity-0 transition-opacity group-hover/avatar:opacity-100 group-focus-visible/avatar:opacity-100',
50
+ upload.isPending && 'opacity-100'
51
+ )}
52
+ >
53
+ {upload.isPending ? (
54
+ <IconLoader size={20} className="animate-spin" stroke={1.5} />
55
+ ) : (
56
+ <IconCamera size={20} stroke={1.5} />
57
+ )}
58
+ </span>
59
+ </Button>
60
+ </div>
61
+ )
62
+ }
@@ -4,6 +4,7 @@ import { Field, FieldGroup, FieldLabel } from '@/ui-components/field'
4
4
  import { Input } from '@/client/components/ui/input'
5
5
  import { toast } from '@/client/components/ui/toast'
6
6
  import { useAccount } from '../account/account-provider'
7
+ import { UserAvatar } from '../collab/components/user-avatar'
7
8
  import { SettingsSection } from './settings-section'
8
9
 
9
10
  export function ProfileSettings() {
@@ -12,6 +13,15 @@ export function ProfileSettings() {
12
13
  return (
13
14
  <SettingsSection title="Profile">
14
15
  <FieldGroup>
16
+ {account.registered && (
17
+ <Field>
18
+ <FieldLabel>Avatar</FieldLabel>
19
+ {/* Restore AvatarUpload once the cloud API stores uploaded images. */}
20
+ <div>
21
+ <UserAvatar profile={account.profile} className="size-16!" />
22
+ </div>
23
+ </Field>
24
+ )}
15
25
  <NameField
16
26
  key={account.profile.id}
17
27
  name={account.profile.name ?? ''}
@@ -14,7 +14,7 @@ import { useLayoutEffect } from 'react'
14
14
  import { useQueryClient, type QueryClient } from '@tanstack/react-query'
15
15
  import { toast } from '@/client/components/ui/toast'
16
16
  import { cachedSelectedSession } from '@/client/features/chat/sessions/use-selected-session'
17
- import { useCollabEnabled } from '@/client/features/collab'
17
+ import { useAppConfig } from '@/client/api/app-config'
18
18
  import { useLatestRef } from '@/client/lib/use-latest-ref'
19
19
  import type { SelectedSessionScope, WorkspaceTabId } from '@/lib/types'
20
20
  import { useCurrentTabId } from './sessions/use-selected-session'
@@ -153,14 +153,14 @@ export function useAppletChatMessage(options: Omit<UseAppletChatMessageOptions,
153
153
  const workspaceId = useWorkspaceId()
154
154
  const queryClient = useQueryClient()
155
155
  const tabId = useCurrentTabId()
156
- const collabEnabled = useCollabEnabled()
156
+ const cloud = useAppConfig().environment === 'cloud'
157
157
  const latest = useLatestRef({ ...options, tabId })
158
158
  useLayoutEffect(() => {
159
159
  const handler = createAppletMessageHandler(
160
160
  workspaceId,
161
161
  queryClient,
162
162
  () => latest.current,
163
- collabEnabled ? 'browser-tab' : 'shared'
163
+ cloud ? 'browser-tab' : 'shared'
164
164
  )
165
165
  const unsubscribe = appletRuntime(workspaceId).on('sendChatMessage', event => {
166
166
  void handler.handle(event)
@@ -169,7 +169,7 @@ export function useAppletChatMessage(options: Omit<UseAppletChatMessageOptions,
169
169
  unsubscribe()
170
170
  handler.dispose()
171
171
  }
172
- }, [workspaceId, queryClient, latest, tabId, collabEnabled])
172
+ }, [workspaceId, queryClient, latest, tabId, cloud])
173
173
  }
174
174
 
175
175
  export function useAppletChatAttachment(sessionId: string | null, revealChat: () => void): void {
@@ -12,7 +12,7 @@ import {
12
12
  usePinnedSession,
13
13
  useSelectedSession
14
14
  } from './use-selected-session'
15
- import { useCollabEnabled } from '@/client/features/collab'
15
+ import { useAppConfig } from '@/client/api/app-config'
16
16
  import { useLatestRef } from '@/client/lib/use-latest-ref'
17
17
  import { useWorkspaceId } from '@/client/features/workspace/workspace-context'
18
18
  import {
@@ -70,10 +70,10 @@ export function useWorkspaceSessions(workspaceId: string): { data: SessionInfo[]
70
70
  export function useSelectLinkedChat() {
71
71
  const workspaceId = useWorkspaceId()
72
72
  const queryClient = useQueryClient()
73
- const collabEnabled = useCollabEnabled()
73
+ const cloud = useAppConfig().environment === 'cloud'
74
74
  const [, , selectSessionForTab] = useSelectedSession()
75
75
  const { unpinAsync } = usePinnedSession()
76
- const stateRef = useLatestRef({ collabEnabled, selectSessionForTab, unpinAsync })
76
+ const stateRef = useLatestRef({ cloud, selectSessionForTab, unpinAsync })
77
77
  // Stable so selection updates do not restart a pending chat link.
78
78
  return useCallback(
79
79
  async (
@@ -81,7 +81,7 @@ export function useSelectLinkedChat() {
81
81
  tab: WorkspaceTabId,
82
82
  signal: AbortSignal
83
83
  ): Promise<WorkspaceTabId | undefined> => {
84
- const { collabEnabled, selectSessionForTab, unpinAsync } = stateRef.current
84
+ const { cloud, selectSessionForTab, unpinAsync } = stateRef.current
85
85
  signal.throwIfAborted()
86
86
  let sessions =
87
87
  queryClient.getQueryData<SessionSummary[]>(workspaceKeys.sessions(workspaceId)) ?? []
@@ -96,7 +96,7 @@ export function useSelectLinkedChat() {
96
96
  const state = await queryClient.ensureQueryData(
97
97
  workspaceStateOptions(queryClient, workspaceId)
98
98
  )
99
- if (collabEnabled) await queryClient.ensureQueryData(browserTabSelectionOptions(workspaceId))
99
+ if (cloud) await queryClient.ensureQueryData(browserTabSelectionOptions(workspaceId))
100
100
  signal.throwIfAborted()
101
101
  const pinned = state.pinnedSessionId
102
102
  const destination =
@@ -9,7 +9,7 @@ import {
9
9
  writeSelectedSession,
10
10
  type BrowserTabSelection
11
11
  } from '@/client/features/chat/sessions/browser-tab-state'
12
- import { useCollabEnabled } from '@/client/features/collab'
12
+ import { useAppConfig } from '@/client/api/app-config'
13
13
  import { useWorkspaceId } from '@/client/features/workspace/workspace-context'
14
14
  import {
15
15
  changeWorkspaceStateCache,
@@ -193,8 +193,8 @@ export function useSelectedSession(explicitTabId?: WorkspaceTabId): SelectedSess
193
193
  const routeTabId = useCurrentTabId()
194
194
  const tabId = explicitTabId ?? routeTabId
195
195
  const workspaceId = useWorkspaceId()
196
- const collabEnabled = useCollabEnabled()
197
- const scope: SelectedSessionScope = collabEnabled ? 'browser-tab' : 'shared'
196
+ const cloud = useAppConfig().environment === 'cloud'
197
+ const scope: SelectedSessionScope = cloud ? 'browser-tab' : 'shared'
198
198
  const queryClient = useQueryClient()
199
199
  const state = useWorkspaceState(workspaceId).data
200
200
  const local = useQuery({
@@ -6,7 +6,7 @@ import { workspaceKeys } from '@/client/api/workspace-keys'
6
6
  import { useSessionState, useSessionView } from '@/client/features/chat/sessions/api'
7
7
  import { useWorkspaceHarness } from '@/client/features/workspace/api'
8
8
  import { useSelectedSession } from '@/client/features/chat/sessions/use-selected-session'
9
- import { useCollabEnabled } from '@/client/features/collab'
9
+ import { useAppConfig } from '@/client/api/app-config'
10
10
  import {
11
11
  type WorkspaceTabAddress,
12
12
  useMoiUserMessageContext
@@ -53,7 +53,7 @@ export function useChat(address: WorkspaceTabAddress) {
53
53
  const qc = useQueryClient()
54
54
  const { layout } = useWorkspaceLayoutCtx()
55
55
  const [selectedSession, selectSession] = useSelectedSession(address.activeTab)
56
- const collabEnabled = useCollabEnabled()
56
+ const cloud = useAppConfig().environment === 'cloud'
57
57
  const modelsData = useWorkspaceHarness(workspaceId).data
58
58
  // A newly forked/native session can precede the provider's session listing.
59
59
  // Archive explicitly clears selection; a stale catalog must not do so.
@@ -171,7 +171,7 @@ export function useChat(address: WorkspaceTabAddress) {
171
171
  content: text,
172
172
  sessionId: sid,
173
173
  isNew,
174
- selectedSessionScope: collabEnabled ? 'browser-tab' : 'shared',
174
+ selectedSessionScope: cloud ? 'browser-tab' : 'shared',
175
175
  optimisticId,
176
176
  model,
177
177
  effort,
@@ -199,7 +199,7 @@ export function useChat(address: WorkspaceTabAddress) {
199
199
  sessionConfig?.effort,
200
200
  sessionConfig?.speedMode,
201
201
  selectSession,
202
- collabEnabled,
202
+ cloud,
203
203
  modelsData
204
204
  ]
205
205
  )
@@ -13,7 +13,7 @@ import {
13
13
  usePublishPresence,
14
14
  useUser,
15
15
  useWorkspaceUsers
16
- } from './hooks'
16
+ } from './presence/hooks'
17
17
 
18
18
  export type AppletCollabApi = typeof CollabApi
19
19
 
@@ -8,7 +8,12 @@ import { IconPointer2 } from '@tabler/icons-react'
8
8
  import { cn } from '@/client/lib/cn'
9
9
  import { Badge } from '@/ui-components/badge'
10
10
 
11
- import { presenceChannels, usePresenceChannel, usePresencePublisher, useUsers } from '../hooks'
11
+ import {
12
+ presenceChannels,
13
+ usePresenceChannel,
14
+ usePresencePublisher,
15
+ useUsers
16
+ } from '../presence/hooks'
12
17
  import { userDisplayName } from '@/client/lib/user-display-name'
13
18
  import { hasPresence } from './presence-helpers'
14
19
 
@@ -5,7 +5,7 @@ import type { HTMLAttributes, ReactNode, Ref } from 'react'
5
5
  import { motion } from 'motion/react'
6
6
  import { cn } from '@/client/lib/cn'
7
7
  import { PresenceGroupContext, usePresenceTarget, useTargetPresence } from './presence-helpers'
8
- import { useUsers } from '../hooks'
8
+ import { useUsers } from '../presence/hooks'
9
9
  import { UserAvatar } from './user-avatar'
10
10
 
11
11
  export function PresenceAvatarsContainer({
@@ -5,7 +5,7 @@ import type { HTMLAttributes, ReactNode, Ref } from 'react'
5
5
  import { cn } from '@/client/lib/cn'
6
6
  import type { UserColor } from '@/lib/collab/colors'
7
7
  import { Badge } from '@/ui-components/badge'
8
- import { useUsers } from '../hooks'
8
+ import { useUsers } from '../presence/hooks'
9
9
  import { userDisplayName } from '@/client/lib/user-display-name'
10
10
  import { usePresenceTarget, useTargetPresence } from './presence-helpers'
11
11
 
@@ -2,7 +2,7 @@ import type { PresenceGroupProps as PresenceGroupContainerProps } from 'moi/coll
2
2
  import type { ReactNode } from 'react'
3
3
  import { useContext, useId, useMemo } from 'react'
4
4
  import { LayoutGroup, MotionConfig } from 'motion/react'
5
- import { presenceTarget } from '../presence-target'
5
+ import { presenceTarget } from '../presence/presence-target'
6
6
  import { PresenceGroupContext } from './presence-helpers'
7
7
 
8
8
  export function PresenceGroupContainer({ id, children }: PresenceGroupContainerProps) {
@@ -1,8 +1,8 @@
1
1
  import type { JsonValue } from 'moi'
2
2
  import { createContext, useContext, useLayoutEffect, useRef } from 'react'
3
3
  import type { FocusEvent } from 'react'
4
- import { presenceChannels, usePresenceChannel, usePresencePublisher } from '../hooks'
5
- import { presenceTarget } from '../presence-target'
4
+ import { presenceChannels, usePresenceChannel, usePresencePublisher } from '../presence/hooks'
5
+ import { presenceTarget } from '../presence/presence-target'
6
6
 
7
7
  export const hasPresence = (value: JsonValue) => value !== false && value !== null
8
8
 
@@ -3,7 +3,7 @@ import type { UserProfile } from '@/lib/collab/types'
3
3
  import { AvatarGroup as AvatarGroupPrimitive, AvatarGroupCount } from '@/ui-components/avatar'
4
4
  import { UserAvatar } from './user-avatar'
5
5
  import type { UserAvatarProps } from './user-avatar'
6
- import { useUsers } from '../hooks'
6
+ import { useUsers } from '../presence/hooks'
7
7
 
8
8
  export function UserAvatarGroupContainer({ ids, ...props }: UserAvatarGroupContainerProps) {
9
9
  const users = useUsers([...new Set(ids)])
@@ -5,7 +5,7 @@ import { Blobatar } from '@blobatar/react'
5
5
  import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from '@/ui-components/avatar'
6
6
  import { cn } from '@/client/lib/cn'
7
7
  import { userDisplayName } from '@/client/lib/user-display-name'
8
- import { useUser } from '../hooks'
8
+ import { useUser } from '../presence/hooks'
9
9
 
10
10
  export function UserAvatarContainer({
11
11
  id,
@@ -4,7 +4,7 @@ import type { UserProfile } from '@/lib/collab/types'
4
4
  import { cn } from '@/client/lib/cn'
5
5
  import { UserAvatar } from './user-avatar'
6
6
  import { userDisplayName } from '@/client/lib/user-display-name'
7
- import { useMe, useUser } from '../hooks'
7
+ import { useMe, useUser } from '../presence/hooks'
8
8
 
9
9
  export function UserContainer({ id, showStatusBadge, showYouLabel, ...props }: UserContainerProps) {
10
10
  const user = useUser(id)
@@ -1,5 +1,5 @@
1
- export { CollabProvider, AppletPresenceProvider, useCollabEnabled } from './provider'
2
- export { WorkspaceUsersMenu } from './workspace-users-menu'
3
- export type { TabInfo } from './workspace-users-menu'
1
+ export { CollabProvider, AppletPresenceProvider } from './presence/provider'
2
+ export { WorkspaceSharingMenu } from './sharing/workspace-sharing-menu'
3
+ export type { TabInfo } from './sharing/workspace-sharing-menu'
4
4
  export { appletCollabApi } from './applet-api'
5
5
  export type { AppletCollabApi } from './applet-api'
@@ -1,4 +1,4 @@
1
- import { cloudRequest } from '../account/api'
1
+ import { cloudRequest } from '../../account/api'
2
2
  import { jsonRequest } from '@/client/api/http'
3
3
  import { parseWorkspaceMembers, validWorkspaceId } from './types'
4
4
 
@@ -8,8 +8,11 @@ export async function fetchWorkspaceMembers(id: string, signal?: AbortSignal) {
8
8
  const response = await cloudRequest(`${workspaceMembersPath(id)}/members`, { signal })
9
9
  return parseWorkspaceMembers(await response.json())
10
10
  }
11
- export const inviteWorkspaceMember = (id: string, email: string) =>
12
- cloudRequest(`${workspaceMembersPath(id)}/invitations`, jsonRequest('POST', { email }))
11
+ export const inviteWorkspaceMember = (id: string, email: string, workspaceName?: string) =>
12
+ cloudRequest(
13
+ `${workspaceMembersPath(id)}/invitations`,
14
+ jsonRequest('POST', { email, workspaceName })
15
+ )
13
16
  export const removeWorkspaceMember = (id: string, membershipId: string) =>
14
17
  cloudRequest(`${workspaceMembersPath(id)}/members/${encodeURIComponent(membershipId)}`, {
15
18
  method: 'DELETE'
@@ -1,9 +1,10 @@
1
1
  import { useMutation, useMutationState, useQuery, useQueryClient } from '@tanstack/react-query'
2
- import { getAccountGeneration } from '../identity/store'
3
- import { useIdentity } from '../identity/use-identity'
2
+ import { useWorkspaces } from '../../home/api'
3
+ import { getAccountGeneration } from '../../identity/store'
4
+ import { useIdentity } from '../../identity/use-identity'
4
5
  import { ownerOnlyWorkspaceMembers } from './store'
5
6
  import { memberKeys } from './keys'
6
- import { identityKey } from '../identity/types'
7
+ import { identityKey } from '../../identity/types'
7
8
  import {
8
9
  fetchWorkspaceMembers,
9
10
  inviteWorkspaceMember,
@@ -66,7 +67,9 @@ export function useWorkspaceMembers(workspaceId: string | undefined) {
66
67
  const data = applyPendingMembership(query.data, pending)
67
68
  return { ...query, data, members: data?.members, invitations: data?.invitations }
68
69
  }
69
- function useMembershipAction(workspaceId: string) {
70
+ export function useMembershipAction(workspaceId: string) {
71
+ const workspaces = useWorkspaces()
72
+
70
73
  const identity = useIdentity()
71
74
  const accountId = identity ? identityKey(identity) : undefined
72
75
  const accountGeneration = getAccountGeneration()
@@ -81,7 +84,10 @@ function useMembershipAction(workspaceId: string) {
81
84
  accountGeneration !== getAccountGeneration()
82
85
  )
83
86
  throw new Error('Sign in to manage workspace members')
84
- if (action.type === 'invite') return inviteWorkspaceMember(workspaceId, action.email)
87
+ if (action.type === 'invite') {
88
+ const name = workspaces.data?.find(workspace => workspace.id === workspaceId)?.name
89
+ return inviteWorkspaceMember(workspaceId, action.email, name?.trim() || undefined)
90
+ }
85
91
  if (action.type === 'remove') return removeWorkspaceMember(workspaceId, action.membershipId)
86
92
  return revokeWorkspaceInvitation(workspaceId, action.invitationId)
87
93
  },
@@ -95,33 +101,3 @@ function useMembershipAction(workspaceId: string) {
95
101
  }
96
102
  })
97
103
  }
98
- export function useInviteMember(workspaceId: string) {
99
- const mutation = useMembershipAction(workspaceId)
100
- return {
101
- ...mutation,
102
- mutate: ({ email }: { email: string }) =>
103
- mutation.mutate({ type: 'invite', email: email.trim().toLowerCase() }),
104
- mutateAsync: ({ email }: { email: string }) =>
105
- mutation.mutateAsync({ type: 'invite', email: email.trim().toLowerCase() })
106
- }
107
- }
108
- export function useRemoveMember(workspaceId: string) {
109
- const mutation = useMembershipAction(workspaceId)
110
- return {
111
- ...mutation,
112
- mutate: ({ membershipId }: { membershipId: string }) =>
113
- mutation.mutate({ type: 'remove', membershipId }),
114
- mutateAsync: ({ membershipId }: { membershipId: string }) =>
115
- mutation.mutateAsync({ type: 'remove', membershipId })
116
- }
117
- }
118
- export function useRevokeInvitation(workspaceId: string) {
119
- const mutation = useMembershipAction(workspaceId)
120
- return {
121
- ...mutation,
122
- mutate: ({ invitationId }: { invitationId: string }) =>
123
- mutation.mutate({ type: 'revoke', invitationId }),
124
- mutateAsync: ({ invitationId }: { invitationId: string }) =>
125
- mutation.mutateAsync({ type: 'revoke', invitationId })
126
- }
127
- }
@@ -1,9 +1,9 @@
1
1
  import { memberKeys } from './keys'
2
2
  import { queryClient } from '@/client/api/query-client'
3
- import { getIdentity, getAccountGeneration } from '../identity/store'
4
- import type { Identity } from '../identity/types'
5
- import { collabIdentityId, identityKey } from '../identity/types'
6
- import { normalizeUserProfile } from '../collab/host-state'
3
+ import { getIdentity, getAccountGeneration } from '../../identity/store'
4
+ import type { Identity } from '../../identity/types'
5
+ import { collabIdentityId, identityKey } from '../../identity/types'
6
+ import { normalizeUserProfile } from '../host-state'
7
7
  import type { UserProfile } from '@/lib/collab/types'
8
8
  import { parseWorkspaceMembers, validWorkspaceId } from './types'
9
9
  import type { WorkspaceMembers, WorkspaceMembersSnapshot } from './types'
@@ -1,6 +1,6 @@
1
1
  import { isRecord } from '@/lib/collab/protocol'
2
- import { identityKey, parseIdentity } from '../identity/types'
3
- import type { Identity } from '../identity/types'
2
+ import { identityKey, parseIdentity } from '../../identity/types'
3
+ import type { Identity } from '../../identity/types'
4
4
 
5
5
  export type WorkspaceMember = Identity & { membershipId?: string }
6
6
  export type WorkspaceInvitation = {
@@ -1,4 +1,4 @@
1
- import { getWorkspaceDirectory, subscribeWorkspaceDirectory } from '../workspace-members/store'
1
+ import { getWorkspaceDirectory, subscribeWorkspaceDirectory } from '../members/store'
2
2
  import { wsUrl } from '@/client/lib/ws-url'
3
3
  import { COLLAB_PROTOCOL_VERSION } from '@/lib/collab/protocol'
4
4
  import type {
@@ -9,7 +9,7 @@ import type {
9
9
  PresenceRegistration
10
10
  } from '@/lib/collab/types'
11
11
 
12
- import { getCurrentUser, subscribeCurrentUserStore, getCurrentUserSource } from './host-state'
12
+ import { getCurrentUser, subscribeCurrentUserStore, getCurrentUserSource } from '../host-state'
13
13
  import { CollabStore, DISCONNECTED_STATE } from './store'
14
14
  import type { ClientState, PresenceEntry } from './store'
15
15
 
@@ -1,4 +1,4 @@
1
- import { createContext, useContext, useEffect, useMemo, useSyncExternalStore } from 'react'
1
+ import { createContext, useContext, useEffect, useMemo } from 'react'
2
2
  import type { ReactNode } from 'react'
3
3
  import { useRouter } from 'wouter'
4
4
  import { usePathname } from 'wouter/use-browser-location'
@@ -66,14 +66,3 @@ export function useCollabEngine(): CollabEngineApi {
66
66
  export function useAppletPresence(): AppletPresence | null {
67
67
  return useContext(AppletPresenceContext)
68
68
  }
69
-
70
- // Collab controls and browser-tab selection require both runtime support and a current user.
71
- export function useCollabEnabled(): boolean {
72
- const engine = useCollabEngine()
73
- const currentUser = useSyncExternalStore(
74
- engine.subscribeCurrentUser,
75
- engine.getCurrentUser,
76
- engine.getCurrentUser
77
- )
78
- return engine.enabled && currentUser !== undefined
79
- }