moi-computer 0.13.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 (91) hide show
  1. package/client/api/app-config.ts +0 -1
  2. package/client/api/query-client.ts +5 -0
  3. package/client/app/app-router.tsx +1 -1
  4. package/client/app/routes/workspace-route.tsx +5 -6
  5. package/client/features/account/account-provider.tsx +28 -77
  6. package/client/features/account/account-test-utils.tsx +103 -93
  7. package/client/features/account/api.ts +36 -111
  8. package/client/features/account/profile-actions.ts +31 -0
  9. package/client/features/app-settings/avatar-upload.tsx +62 -0
  10. package/client/features/app-settings/profile-settings.tsx +10 -0
  11. package/client/features/app-settings/settings-page.tsx +0 -4
  12. package/client/features/chat/applet-chat-intents.ts +4 -4
  13. package/client/features/chat/sessions/api.ts +5 -5
  14. package/client/features/chat/sessions/use-selected-session.ts +3 -3
  15. package/client/features/chat/use-chat.ts +4 -4
  16. package/client/features/collab/applet-api.ts +1 -1
  17. package/client/features/collab/components/cursors.tsx +6 -1
  18. package/client/features/collab/components/presence-avatars.tsx +1 -1
  19. package/client/features/collab/components/presence-frame.tsx +1 -1
  20. package/client/features/collab/components/presence-group.tsx +1 -1
  21. package/client/features/collab/components/presence-helpers.ts +2 -2
  22. package/client/features/collab/components/user-avatar-group.tsx +1 -1
  23. package/client/features/collab/components/user-avatar.tsx +1 -1
  24. package/client/features/collab/components/user.tsx +1 -1
  25. package/client/features/collab/host-state.ts +45 -85
  26. package/client/features/collab/index.ts +3 -3
  27. package/client/features/collab/members/api.ts +23 -0
  28. package/client/features/collab/members/hooks.ts +103 -0
  29. package/client/features/collab/members/keys.ts +6 -0
  30. package/client/features/collab/members/store.ts +123 -0
  31. package/client/features/collab/members/types.ts +53 -0
  32. package/client/features/collab/{client.ts → presence/client.ts} +38 -13
  33. package/client/features/collab/{hooks.tsx → presence/hooks.tsx} +9 -8
  34. package/client/features/collab/{provider.tsx → presence/provider.tsx} +1 -12
  35. package/client/features/collab/{users.ts → presence/users.ts} +19 -33
  36. package/client/features/collab/sharing/agent-invite.tsx +30 -0
  37. package/client/features/collab/sharing/workspace-members.tsx +277 -0
  38. package/client/features/collab/sharing/workspace-sharing-menu.tsx +179 -0
  39. package/client/features/collab/testing/component-fixtures.tsx +3 -3
  40. package/client/features/collab/testing/fake-engine.ts +15 -3
  41. package/client/features/dev/collab/collab-playground.tsx +2 -2
  42. package/client/features/dev/workspace-setup-mocks.ts +0 -1
  43. package/client/features/identity/host-api.ts +34 -0
  44. package/client/features/identity/store.ts +32 -0
  45. package/client/features/identity/types.ts +41 -0
  46. package/client/features/identity/use-identity.ts +6 -0
  47. package/client/features/views/use-view-actions.ts +3 -3
  48. package/client/features/workspace/browser-tab-state.ts +6 -6
  49. package/client/features/workspace/workspace-content.tsx +10 -6
  50. package/client/index.html +1 -1
  51. package/client/index.tsx +5 -9
  52. package/client/main.tsx +2 -2
  53. package/dist/{chunk-cqt3s31j.js → chunk-3smkkcfw.js} +86 -86
  54. package/dist/chunk-47h9c2qy.js +2 -0
  55. package/dist/chunk-8qed2gqp.js +75 -0
  56. package/dist/{chunk-bncc7heg.js → chunk-8zy3vesm.js} +1 -1
  57. package/dist/chunk-a47zy276.js +2 -0
  58. package/dist/chunk-g4c1nte9.css +1 -0
  59. package/dist/chunk-kcactdr4.js +2 -0
  60. package/dist/chunk-m8bhx6tw.js +1 -0
  61. package/dist/{chunk-58dyt9bk.js → chunk-pf19zcrn.js} +2 -2
  62. package/dist/{chunk-2y59vrxg.js → chunk-th91xfnp.js} +1 -1
  63. package/dist/chunk-ygzxah0e.js +1 -0
  64. package/dist/index.html +2 -2
  65. package/lib/types.ts +0 -1
  66. package/package.json +5 -4
  67. package/server/app-config.ts +2 -5
  68. package/server/applets/declarations.ts +6 -7
  69. package/server/cli/commands/init.ts +0 -11
  70. package/server/collab/config.ts +1 -5
  71. package/server/collab/manager.ts +5 -2
  72. package/server/collab/skill/index.ts +1 -47
  73. package/server/skills/template.ts +3 -2
  74. package/server/skills/update.ts +1 -1
  75. package/server/skills/workspace.ts +0 -2
  76. package/server/web.ts +1 -2
  77. package/server/workspaces/scaffold.ts +1 -0
  78. package/skill/SKILL.md +1 -1
  79. package/client/features/account/identity.ts +0 -23
  80. package/client/features/app-settings/users-settings.tsx +0 -195
  81. package/client/features/collab/workspace-users-menu.tsx +0 -190
  82. package/dist/chunk-dcmks9sm.js +0 -75
  83. package/dist/chunk-md45evr2.css +0 -1
  84. package/dist/chunk-n0nab26d.js +0 -1
  85. package/dist/chunk-nmzhgyp9.js +0 -2
  86. package/dist/chunk-q37knr3m.js +0 -2
  87. package/dist/chunk-s90m4qkz.js +0 -1
  88. package/dist/chunk-wjvd4byz.js +0 -2
  89. /package/client/features/collab/{presence-publisher.ts → presence/presence-publisher.ts} +0 -0
  90. /package/client/features/collab/{presence-target.ts → presence/presence-target.ts} +0 -0
  91. /package/client/features/collab/{store.ts → presence/store.ts} +0 -0
@@ -1,44 +1,25 @@
1
1
  import { queryOptions } from '@tanstack/react-query'
2
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
- }
3
+ import { isRecord } from '@/lib/collab/protocol'
4
+ import { parseIdentity } from '../identity/types'
5
+ import { getIdentityRevision, setIdentity } from '../identity/store'
6
+ import type { Identity } from '../identity/types'
24
7
 
25
8
  export const accountKeys = {
26
9
  all: ['account'] as const,
27
- session: ['account', 'session'] as const,
28
- team: ['account', 'team'] as const
10
+ identityRefresh: ['account', 'identity-refresh'] as const
29
11
  }
30
-
31
12
  export class CloudApiError extends Error {
32
13
  constructor(
33
14
  message: string,
34
- readonly status: number
15
+ readonly status: number,
16
+ readonly code?: string
35
17
  ) {
36
18
  super(message)
37
19
  }
38
20
  }
39
-
40
21
  export async function cloudRequest(path: string, init?: RequestInit): Promise<Response> {
41
- const response = await fetch(`/cloud/api/auth/${path}`, { ...init, credentials: 'same-origin' })
22
+ const response = await fetch(`/cloud/api/${path}`, { ...init, credentials: 'same-origin' })
42
23
  if (!response.ok) {
43
24
  const body: unknown = await response.json().catch(() => undefined)
44
25
  const message = isRecord(body)
@@ -48,95 +29,39 @@ export async function cloudRequest(path: string, init?: RequestInit): Promise<Re
48
29
  : undefined
49
30
  throw new CloudApiError(
50
31
  message ?? 'Couldn’t complete this request. Try again.',
51
- response.status
32
+ response.status,
33
+ isRecord(body) && typeof body.code === 'string' ? body.code : undefined
52
34
  )
53
35
  }
54
36
  return response
55
37
  }
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())
38
+ // React Query tracks refresh status only. Identity itself lives in the identity store.
39
+ export const identityRefreshQuery = queryOptions({
40
+ queryKey: accountKeys.identityRefresh,
41
+ queryFn: async ({ signal }): Promise<true> => {
42
+ const identityRevision = getIdentityRevision()
43
+ let identity: Identity | null
44
+ try {
45
+ identity = parseIdentity(await (await cloudRequest('me', { signal })).json())
46
+ } catch (error) {
47
+ if (!(error instanceof CloudApiError) || error.status !== 401) throw error
48
+ identity = null
49
+ }
50
+ // A pushed identity or account switch wins over an older request.
51
+ if (!signal.aborted && getIdentityRevision() === identityRevision) setIdentity(identity)
52
+ return true
120
53
  },
121
54
  retry: false,
122
55
  staleTime: 30_000
123
56
  })
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 }))
57
+ type ProfilePatch = { name: string }
58
+ export const updateCloudProfile = async (patch: ProfilePatch) =>
59
+ parseIdentity(await (await cloudRequest('me', jsonRequest('PATCH', patch))).json())
60
+ export async function uploadCloudAvatar(file: File) {
61
+ const body = new FormData()
62
+ body.set('file', file)
63
+ return parseIdentity(await (await cloudRequest('me/avatar', { method: 'PUT', body })).json())
64
+ }
65
+ export const removeCloudAvatar = async () =>
66
+ parseIdentity(await (await cloudRequest('me/avatar', { method: 'DELETE' })).json())
67
+ export const signOutCloud = () => cloudRequest('auth/sign-out', jsonRequest('POST'))
@@ -0,0 +1,31 @@
1
+ import { queryClient } from '@/client/api/query-client'
2
+ import { getIdentity, setIdentity, getAccountGeneration } from '../identity/store'
3
+ import { identityKey } from '../identity/types'
4
+ import type { Identity } from '../identity/types'
5
+ import { memberKeys } from '../collab/members/keys'
6
+
7
+ export async function saveCloudProfile(field: 'name' | 'avatar', update: () => Promise<Identity>) {
8
+ const before = getIdentity()
9
+ const accountGeneration = getAccountGeneration()
10
+ if (!before || before.type !== 'user' || before.isAnonymous)
11
+ throw new Error('Sign in to change your profile')
12
+ const saved = await update()
13
+ const current = getIdentity()
14
+ if (
15
+ accountGeneration !== getAccountGeneration() ||
16
+ !current ||
17
+ current.type !== 'user' ||
18
+ current.id !== before.id
19
+ )
20
+ throw new Error('Your account changed. Reload Moi to try again.')
21
+ // A newer server-pushed value wins. Apply only fields still equal to their original value.
22
+ setIdentity({
23
+ ...current,
24
+ ...(field === 'name' && current.name === before.name ? { name: saved.name } : {}),
25
+ ...(field === 'avatar' && current.avatar === before.avatar ? { avatar: saved.avatar } : {})
26
+ })
27
+ // Our identity write can supersede the event bridge's in-flight snapshot.
28
+ // Refresh active lists now and mark inactive lists stale for their next mount.
29
+ if (accountGeneration === getAccountGeneration())
30
+ await queryClient.invalidateQueries({ queryKey: memberKeys.account(identityKey(current)) })
31
+ }
@@ -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 ?? ''}
@@ -4,12 +4,9 @@ import { Button } from '@/client/components/ui/button'
4
4
  import { Skeleton } from '@/client/components/ui/skeleton'
5
5
  import { useAccount } from '../account/account-provider'
6
6
  import { ProfileSettings } from './profile-settings'
7
- import { UsersSettings } from './users-settings'
8
- import { useAppConfig } from '@/client/api/app-config'
9
7
  import { GeneralSettings } from './general-settings'
10
8
 
11
9
  export function SettingsPage() {
12
- const { collab } = useAppConfig()
13
10
  const account = useAccount()
14
11
  useEffect(() => {
15
12
  if (account.cloud && !account.demo && account.status === 'signed-out') {
@@ -38,7 +35,6 @@ export function SettingsPage() {
38
35
  ) : (
39
36
  <div className="flex w-full max-w-xl min-w-0 flex-col gap-4">
40
37
  <ProfileSettings />
41
- {collab && account.registered && <UsersSettings />}
42
38
  <GeneralSettings />
43
39
  </div>
44
40
  )}
@@ -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)