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

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 (230) hide show
  1. package/client/api/app-config.ts +12 -2
  2. package/client/api/http.ts +11 -1
  3. package/client/app/app-router.tsx +3 -2
  4. package/client/app/routes/home-route.tsx +1 -1
  5. package/client/app/routes/workspace-registration.tsx +68 -0
  6. package/client/app/routes/workspace-route.tsx +37 -13
  7. package/client/app/shell/sidebar-layout.tsx +10 -5
  8. package/client/components/shared/workspace-icon.tsx +8 -17
  9. package/client/features/account/account-test-utils.tsx +18 -4
  10. package/client/features/account/api.ts +10 -8
  11. package/client/features/account/profile-actions.ts +5 -7
  12. package/client/features/app-settings/avatar-upload.tsx +62 -0
  13. package/client/features/app-settings/profile-settings.tsx +10 -0
  14. package/client/features/app-settings/settings-page.tsx +2 -1
  15. package/client/features/applets/api.ts +6 -6
  16. package/client/features/applets/applet-cache.ts +6 -5
  17. package/client/features/applets/applet-log.ts +2 -1
  18. package/client/features/applets/applet-runtime.ts +2 -1
  19. package/client/features/applets/use-applet.ts +73 -18
  20. package/client/features/applets/widget-shell.tsx +4 -2
  21. package/client/features/chat/applet-chat-intents.ts +5 -13
  22. package/client/features/chat/chat-popup.tsx +8 -4
  23. package/client/features/chat/chat-send.ts +2 -2
  24. package/client/features/chat/composer/model-order.ts +4 -4
  25. package/client/features/chat/composer/model-picker.tsx +12 -10
  26. package/client/features/chat/composer/use-workspace-composer-state.tsx +1 -1
  27. package/client/features/chat/sessions/api.ts +11 -28
  28. package/client/features/chat/sessions/use-selected-session.ts +18 -100
  29. package/client/features/chat/use-chat.ts +8 -12
  30. package/client/features/collab/applet-api.ts +1 -1
  31. package/client/features/collab/components/cursors.tsx +6 -1
  32. package/client/features/collab/components/presence-avatars.tsx +1 -1
  33. package/client/features/collab/components/presence-frame.tsx +1 -1
  34. package/client/features/collab/components/presence-group.tsx +1 -1
  35. package/client/features/collab/components/presence-helpers.ts +2 -2
  36. package/client/features/collab/components/user-avatar-group.tsx +1 -1
  37. package/client/features/collab/components/user-avatar.tsx +1 -1
  38. package/client/features/collab/components/user.tsx +1 -1
  39. package/client/features/collab/index.ts +3 -3
  40. package/client/features/collab/members/api.ts +17 -0
  41. package/client/features/collab/members/hooks.ts +97 -0
  42. package/client/features/collab/members/store.ts +148 -0
  43. package/client/features/{workspace-members → collab/members}/types.ts +7 -5
  44. package/client/features/collab/{client.ts → presence/client.ts} +4 -5
  45. package/client/features/collab/{hooks.tsx → presence/hooks.tsx} +1 -1
  46. package/client/features/collab/{provider.tsx → presence/provider.tsx} +1 -12
  47. package/client/features/collab/{users.ts → presence/users.ts} +19 -21
  48. package/client/features/collab/proxy-user.ts +1 -3
  49. package/client/features/collab/sharing/agent-invite.tsx +30 -0
  50. package/client/features/collab/sharing/workspace-members.tsx +269 -0
  51. package/client/features/collab/sharing/workspace-sharing-menu.tsx +179 -0
  52. package/client/features/collab/testing/component-fixtures.tsx +3 -3
  53. package/client/features/collab/testing/fake-engine.ts +2 -2
  54. package/client/features/dev/chat-states-page.tsx +3 -1
  55. package/client/features/dev/collab/collab-playground.tsx +2 -2
  56. package/client/features/dev/dev-index-page.tsx +0 -6
  57. package/client/features/dev/dev-routes.tsx +0 -2
  58. package/client/features/dev/harness-debug-page.tsx +7 -7
  59. package/client/features/dev/workspace-setup-mocks.ts +1 -2
  60. package/client/features/dev/workspace-setup-preview.tsx +6 -4
  61. package/client/features/harness/api.ts +13 -10
  62. package/client/features/harness/harness-login-panel.tsx +9 -5
  63. package/client/features/harness/harness-presentation.ts +4 -4
  64. package/client/features/harness/harness-selector.tsx +13 -13
  65. package/client/features/harness/use-harness-login.ts +5 -5
  66. package/client/features/home/api.ts +38 -2
  67. package/client/features/home/home-page.tsx +43 -13
  68. package/client/features/home/shared-workspaces.tsx +70 -0
  69. package/client/features/home/workspace-invitations.tsx +101 -0
  70. package/client/features/identity/host-api.ts +5 -4
  71. package/client/features/identity/store.ts +1 -7
  72. package/client/features/onboarding/agent-setup-step.tsx +8 -8
  73. package/client/features/onboarding/onboarding-page.tsx +3 -2
  74. package/client/features/onboarding/workspace-setup-step.tsx +1 -1
  75. package/client/features/overview/api.ts +3 -5
  76. package/client/features/overview/default/registry.tsx +1 -1
  77. package/client/features/overview/default/views-widget.tsx +2 -2
  78. package/client/features/overview/hidden-panel.tsx +7 -5
  79. package/client/features/overview/overview.tsx +18 -16
  80. package/client/features/overview/workspace-name.tsx +2 -2
  81. package/client/features/scratchpad/scratchpad.tsx +9 -7
  82. package/client/features/scratchpad/use-scratchpad-snapshot.tsx +13 -5
  83. package/client/features/views/api.ts +34 -16
  84. package/client/features/views/use-view-actions.ts +10 -20
  85. package/client/features/views/view-manager.tsx +1 -1
  86. package/client/features/views/view-submission.ts +2 -21
  87. package/client/features/workspace/add/api.ts +5 -4
  88. package/client/features/workspace/add/create-workspace-dialog.tsx +12 -9
  89. package/client/features/workspace/add/import-workspace-dialog.tsx +7 -7
  90. package/client/features/workspace/add/use-workspace-import.ts +10 -10
  91. package/client/features/workspace/add/workspace-agent-options.ts +21 -20
  92. package/client/features/workspace/add/workspace-agent-selector.tsx +11 -11
  93. package/client/features/workspace/api.ts +60 -13
  94. package/client/features/workspace/harness-transition.ts +7 -13
  95. package/client/features/workspace/remote.ts +25 -0
  96. package/client/features/workspace/settings/api.ts +7 -12
  97. package/client/features/workspace/settings/connectors-settings.tsx +3 -3
  98. package/client/features/workspace/settings/general-settings.tsx +8 -8
  99. package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
  100. package/client/features/workspace/setup/workspace-recovery-states.tsx +43 -14
  101. package/client/features/workspace/setup/workspace-setup.tsx +6 -6
  102. package/client/features/workspace/tab-resolution.ts +2 -2
  103. package/client/features/workspace/use-workspace-navigation.ts +7 -4
  104. package/client/features/workspace/workspace-content.tsx +32 -26
  105. package/client/features/workspace/workspace-frame.tsx +13 -26
  106. package/client/features/workspace/workspace-layout-context.tsx +45 -12
  107. package/client/features/workspace/workspace-menu.tsx +2 -2
  108. package/client/features/workspace/workspace-pane.tsx +22 -0
  109. package/client/features/workspace/workspace-pending-screen.tsx +1 -1
  110. package/client/features/workspace/workspace-preferences.ts +34 -0
  111. package/client/features/workspace/workspace-presentation.tsx +12 -16
  112. package/client/features/workspace/workspace-screen.tsx +2 -2
  113. package/client/features/workspace/workspace-state.ts +2 -1
  114. package/client/features/workspace/workspace-tabs.tsx +1 -1
  115. package/client/features/workspace/workspace-test-utils.ts +23 -0
  116. package/client/runtime/use-workspace-events.ts +14 -0
  117. package/client/runtime/workspace-events.ts +9 -9
  118. package/client/store/ui.ts +29 -9
  119. package/dist/chunk-44khk4sp.js +2 -0
  120. package/dist/chunk-ba6mz56s.js +72 -0
  121. package/dist/chunk-ec5ennpv.js +1 -0
  122. package/dist/chunk-ectsnw81.js +2 -0
  123. package/dist/chunk-en7w5ypg.js +1 -0
  124. package/dist/chunk-f695wcx5.js +5 -0
  125. package/dist/chunk-kffcah9w.css +1 -0
  126. package/dist/{chunk-kdgk4dac.js → chunk-n0fawy9x.js} +1 -1
  127. package/dist/chunk-pdt9hxfw.js +2 -0
  128. package/dist/chunk-rmd0ctfx.js +546 -0
  129. package/dist/chunk-zv22wv0g.js +1 -0
  130. package/dist/index.html +1 -1
  131. package/lib/harness-instructions.ts +4 -4
  132. package/lib/harness-types.ts +13 -0
  133. package/lib/types.ts +34 -50
  134. package/lib/workspace-config.ts +48 -0
  135. package/lib/workspace-layout.ts +2 -4
  136. package/package.json +4 -2
  137. package/server/README.md +29 -27
  138. package/server/api/harnesses.ts +5 -5
  139. package/server/api/index.ts +170 -68
  140. package/server/app-config.ts +2 -7
  141. package/server/applets/declarations.ts +6 -7
  142. package/server/applets/index.ts +15 -9
  143. package/server/applets/views.ts +2 -17
  144. package/server/applets/widgets.ts +3 -2
  145. package/server/cli/commands/config.ts +8 -20
  146. package/server/cli/commands/hermes.ts +2 -2
  147. package/server/cli/commands/init.ts +96 -64
  148. package/server/cli/commands/openclaw.ts +2 -2
  149. package/server/cli/commands/refresh.ts +10 -1
  150. package/server/cli/commands/remote.ts +228 -0
  151. package/server/cli/commands/skill.ts +4 -4
  152. package/server/cli/commands/tabs.ts +5 -12
  153. package/server/cli/control.ts +35 -4
  154. package/server/cli/index.ts +10 -6
  155. package/server/cli/remote-command.ts +77 -0
  156. package/server/cli/remote-control.ts +70 -0
  157. package/server/cli/remote-operations.ts +244 -0
  158. package/server/collab/config.ts +4 -8
  159. package/server/collab/manager.ts +5 -2
  160. package/server/collab/skill/index.ts +4 -50
  161. package/server/control.ts +38 -11
  162. package/server/harness/acp/session.ts +4 -4
  163. package/server/harness/auth.ts +26 -31
  164. package/server/harness/claude-code/index.ts +1 -1
  165. package/server/harness/codex/discovery.ts +1 -1
  166. package/server/harness/codex/session.ts +1 -1
  167. package/server/harness/detect.ts +14 -19
  168. package/server/harness/executable.ts +10 -10
  169. package/server/harness/hermes/NOTES.md +2 -2
  170. package/server/harness/hermes/index.ts +1 -1
  171. package/server/harness/install.ts +11 -11
  172. package/server/harness/openclaw/index.ts +1 -1
  173. package/server/harness/registry.ts +7 -6
  174. package/server/harness/types.ts +4 -4
  175. package/server/onboarding/jobs.ts +1 -1
  176. package/server/operations/commands.ts +46 -0
  177. package/server/operations/files.ts +148 -0
  178. package/server/operations/server.ts +206 -0
  179. package/server/remote/agent.ts +103 -0
  180. package/server/remote/client.ts +665 -0
  181. package/server/remote/workspace.ts +34 -0
  182. package/server/scratchpad/document.ts +32 -12
  183. package/server/scratchpad/executor.ts +16 -7
  184. package/server/sessions/config.ts +8 -5
  185. package/server/sessions/pending-views.ts +16 -0
  186. package/server/sessions/view-sessions.ts +10 -12
  187. package/server/skills/locations.ts +4 -4
  188. package/server/skills/template.ts +3 -2
  189. package/server/skills/update.ts +12 -12
  190. package/server/skills/version.ts +7 -7
  191. package/server/skills/workspace.ts +13 -13
  192. package/server/web.ts +12 -10
  193. package/server/workspace-state/file.ts +2 -0
  194. package/server/workspace-state/index.ts +0 -4
  195. package/server/workspaces/api.ts +28 -0
  196. package/server/workspaces/change-harness.ts +15 -26
  197. package/server/workspaces/import.ts +4 -4
  198. package/server/workspaces/init.ts +15 -13
  199. package/server/workspaces/layout.ts +60 -66
  200. package/server/workspaces/registry.ts +43 -18
  201. package/server/workspaces/scaffold.ts +1 -0
  202. package/server/workspaces/shared.ts +74 -0
  203. package/server/workspaces/tabs.ts +6 -12
  204. package/skill/SKILL.md +24 -4
  205. package/client/api/app-ui-keys.ts +0 -6
  206. package/client/features/chat/sessions/browser-tab-state.ts +0 -43
  207. package/client/features/collab/workspace-users-menu.tsx +0 -190
  208. package/client/features/dev/cloud-avatar-upload.tsx +0 -58
  209. package/client/features/dev/cloud-page.tsx +0 -363
  210. package/client/features/workspace/browser-tab-state.ts +0 -51
  211. package/client/features/workspace/layout-save.ts +0 -13
  212. package/client/features/workspace-members/api.ts +0 -20
  213. package/client/features/workspace-members/hooks.ts +0 -127
  214. package/client/features/workspace-members/keys.ts +0 -6
  215. package/client/features/workspace-members/store.ts +0 -123
  216. package/dist/chunk-00s35r33.js +0 -546
  217. package/dist/chunk-7rz6g7g7.js +0 -1
  218. package/dist/chunk-af2jyddf.js +0 -2
  219. package/dist/chunk-cekekc3f.css +0 -1
  220. package/dist/chunk-ep5vh16c.js +0 -75
  221. package/dist/chunk-s5s1vzdw.js +0 -2
  222. package/dist/chunk-svxhxfeq.js +0 -2
  223. package/dist/chunk-t0r0bds1.js +0 -1
  224. package/dist/chunk-vp2qzc0d.js +0 -1
  225. package/dist/chunk-wz5qv1bn.js +0 -2
  226. package/lib/workspace-types.ts +0 -13
  227. package/server/workspace-state/legacy-migration.ts +0 -79
  228. /package/client/features/collab/{presence-publisher.ts → presence/presence-publisher.ts} +0 -0
  229. /package/client/features/collab/{presence-target.ts → presence/presence-target.ts} +0 -0
  230. /package/client/features/collab/{store.ts → presence/store.ts} +0 -0
@@ -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 = {
@@ -47,7 +47,9 @@ export function parseWorkspaceMembers(value: unknown): WorkspaceMembers {
47
47
  throw new Error('Duplicate workspace member or invitation')
48
48
  return { members, invitations }
49
49
  }
50
- export function validWorkspaceId(id: string): string {
51
- if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(id)) throw new Error('Invalid workspace id')
52
- return id
50
+ // `workspaceId`, or `ownerId:workspaceId` for a workspace on someone else's machine.
51
+ export function validWorkspaceAddress(address: string): string {
52
+ if (!/^(?:[A-Za-z0-9_-]{1,64}:)?[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(address))
53
+ throw new Error('Invalid workspace id')
54
+ return address
53
55
  }
@@ -1,4 +1,5 @@
1
- import { getWorkspaceDirectory, subscribeWorkspaceDirectory } from '../workspace-members/store'
1
+ import { getWorkspaceApiBase } from '@/client/features/workspace/remote'
2
+ import { getWorkspaceDirectory, subscribeWorkspaceDirectory } from '../members/store'
2
3
  import { wsUrl } from '@/client/lib/ws-url'
3
4
  import { COLLAB_PROTOCOL_VERSION } from '@/lib/collab/protocol'
4
5
  import type {
@@ -9,7 +10,7 @@ import type {
9
10
  PresenceRegistration
10
11
  } from '@/lib/collab/types'
11
12
 
12
- import { getCurrentUser, subscribeCurrentUserStore, getCurrentUserSource } from './host-state'
13
+ import { getCurrentUser, subscribeCurrentUserStore, getCurrentUserSource } from '../host-state'
13
14
  import { CollabStore, DISCONNECTED_STATE } from './store'
14
15
  import type { ClientState, PresenceEntry } from './store'
15
16
 
@@ -160,9 +161,7 @@ export class CollabClient implements CollabEngineApi {
160
161
  if (this.socket) return
161
162
  clearTimeout(this.retry)
162
163
  this.store.connecting()
163
- const socket = new WebSocket(
164
- wsUrl(`/api/workspaces/${encodeURIComponent(this.workspaceId)}/collab/ws`)
165
- )
164
+ const socket = new WebSocket(wsUrl(`${getWorkspaceApiBase(this.workspaceId)}/collab`))
166
165
  this.socket = socket
167
166
  socket.onopen = () => {
168
167
  if (socket !== this.socket) return
@@ -36,7 +36,7 @@ function useUsersSource() {
36
36
  engine.getDirectory,
37
37
  engine.getDirectory
38
38
  )
39
- // Live connections describe activity; only the directory establishes membership.
39
+ // Membership supplies profiles, including users who are currently offline.
40
40
  const users = directory ?? EMPTY_USERS
41
41
  return { state, self, users, engine }
42
42
  }
@@ -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
- }
@@ -54,12 +54,11 @@ export function resolvePeers(
54
54
  export type WorkspaceUserInfo = {
55
55
  profile: UserProfile
56
56
  self: boolean
57
- pages: string[]
57
+ page: string | undefined
58
58
  status: UserStatus
59
59
  }
60
60
  export type CurrentUserContext = {
61
61
  currentUser: UserProfile | undefined
62
- connectionId: string | null
63
62
  page: string | null
64
63
  users: readonly UserProfile[]
65
64
  }
@@ -67,23 +66,22 @@ export function summarizeWorkspaceUsers(
67
66
  connections: Connection[],
68
67
  context: CurrentUserContext
69
68
  ): WorkspaceUserInfo[] {
70
- const users = [...context.users].sort(
71
- (a, b) => Number(b.id === context.currentUser?.id) - Number(a.id === context.currentUser?.id)
72
- )
73
- return users.map(profile => {
74
- const pages = new Set<string>()
75
- for (const connection of connections) {
76
- if (connection.userId !== profile.id || connection.connectionId === context.connectionId)
77
- continue
78
- if (connection.location) pages.add(connection.location.page)
79
- }
80
- const isSelf = profile.id === context.currentUser?.id
81
- if (isSelf && context.page) pages.add(context.page)
82
- return {
83
- profile,
84
- self: isSelf,
85
- pages: [...pages],
86
- status: userStatus(connections, profile.id)
87
- }
88
- })
69
+ return context.users
70
+ .map(profile => {
71
+ const isSelf = profile.id === context.currentUser?.id
72
+ const activeConnection = connections.find(
73
+ connection => connection.userId === profile.id && connection.location?.status === 'active'
74
+ )
75
+ return {
76
+ profile,
77
+ self: isSelf,
78
+ page: isSelf ? (context.page ?? undefined) : activeConnection?.location?.page,
79
+ status: userStatus(connections, profile.id)
80
+ }
81
+ })
82
+ .toSorted(
83
+ (a, b) =>
84
+ Number(b.self) - Number(a.self) ||
85
+ Number(b.status === 'active') - Number(a.status === 'active')
86
+ )
89
87
  }
@@ -22,9 +22,7 @@ async function fetchProxyUser(): Promise<ProxyUserState | undefined> {
22
22
  } catch {}
23
23
  }
24
24
 
25
- // Loaded once before the app mounts, like startup config, so workspaces
26
- // choose between shared and browser-tab navigation with the inherited user
27
- // already in place.
25
+ // Load the inherited identity before the app mounts.
28
26
  export async function loadProxyUser(): Promise<ProxyUserState | undefined> {
29
27
  return fetchProxyUser()
30
28
  }
@@ -0,0 +1,30 @@
1
+ import { useId } from 'react'
2
+ import { Button } from '@/client/components/ui/button'
3
+
4
+ export function AgentInvite() {
5
+ const headingId = useId()
6
+ const availabilityId = useId()
7
+ return (
8
+ <section
9
+ aria-labelledby={headingId}
10
+ className="flex flex-col gap-3 rounded-2xl bg-popover p-5 shadow-md"
11
+ >
12
+ <div className="flex items-start gap-3">
13
+ <div className="min-w-0 flex-1 space-y-1">
14
+ <h3 id={headingId} className="text-sm font-medium">
15
+ Invite your agent
16
+ </h3>
17
+ <p className="text-sm text-muted-foreground">
18
+ Give your agent a prompt to work in this workspace on your behalf
19
+ </p>
20
+ </div>
21
+ </div>
22
+ <Button variant="secondary" className="self-start" disabled aria-describedby={availabilityId}>
23
+ Copy prompt
24
+ </Button>
25
+ <span id={availabilityId} className="sr-only">
26
+ Agent invitations aren’t available yet
27
+ </span>
28
+ </section>
29
+ )
30
+ }
@@ -0,0 +1,269 @@
1
+ import { useState } from 'react'
2
+ import { IconX } from '@tabler/icons-react'
3
+ import { Button } from '@/client/components/ui/button'
4
+ import { Input } from '@/client/components/ui/input'
5
+ import { Spinner } from '@/client/components/ui/spinner'
6
+ import { PopoverTitle } from '@/client/components/ui/popover'
7
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
8
+ import { toast } from '@/client/components/ui/toast'
9
+ import { cn } from '@/client/lib/cn'
10
+ import { colorForId } from '@/lib/collab/colors'
11
+ import { CloudApiError } from '../../account/api'
12
+ import { useIdentity } from '../../identity/use-identity'
13
+ import { collabIdentityId, identityKey } from '../../identity/types'
14
+ import { getAccountGeneration } from '../../identity/store'
15
+ import { User } from '../components/user'
16
+ import {
17
+ type useWorkspaceMembers,
18
+ useMembershipAction,
19
+ type MembershipAction
20
+ } from '../members/hooks'
21
+ import type { WorkspaceMember, WorkspaceInvitation } from '../members/types'
22
+ import type { WorkspaceUserInfo } from '../presence/users'
23
+
24
+ export type WorkspaceMembersProps = {
25
+ workspaceId: string
26
+ users: WorkspaceUserInfo[]
27
+ membership: ReturnType<typeof useWorkspaceMembers>
28
+ }
29
+
30
+ export function WorkspaceMembers({ workspaceId, users, membership }: WorkspaceMembersProps) {
31
+ const identity = useIdentity()
32
+ const membersById =
33
+ membership.members &&
34
+ new Map(membership.members.map(member => [collabIdentityId(member), member]))
35
+ return (
36
+ <div className="flex flex-col rounded-2xl bg-popover p-5 shadow-md">
37
+ <PopoverTitle>Share this workspace</PopoverTitle>
38
+ <InviteForm
39
+ className="mt-3"
40
+ key={`${workspaceId}:${identity ? identityKey(identity) : ''}`}
41
+ workspaceId={workspaceId}
42
+ members={membership.members ?? []}
43
+ invitations={membership.invitations ?? []}
44
+ />
45
+ <MembersList
46
+ className="-mx-2 -my-1 mt-3"
47
+ workspaceId={workspaceId}
48
+ users={users}
49
+ membersById={membersById}
50
+ invitations={membership.invitations ?? []}
51
+ />
52
+ {membership.isPending && (
53
+ <div className="flex items-center justify-center py-6">
54
+ <Spinner className="text-muted-foreground" aria-label="Loading workspace members" />
55
+ </div>
56
+ )}
57
+ </div>
58
+ )
59
+ }
60
+
61
+ type InviteFormProps = {
62
+ className?: string
63
+ workspaceId: string
64
+ members: WorkspaceMember[]
65
+ invitations: WorkspaceInvitation[]
66
+ }
67
+
68
+ function InviteForm({ className, workspaceId, members, invitations }: InviteFormProps) {
69
+ const [email, setEmail] = useState('')
70
+ const invite = useMembershipAction(workspaceId)
71
+ async function submit() {
72
+ const address = email.trim().toLowerCase()
73
+ if (!address || invite.isPending) return
74
+ const generation = getAccountGeneration()
75
+ setEmail('')
76
+ const existingMember = members.some(
77
+ member => member.type === 'user' && member.email.trim().toLowerCase() === address
78
+ )
79
+ const existingInvitation = invitations.some(
80
+ invitation => invitation.email.trim().toLowerCase() === address
81
+ )
82
+ if (existingMember || existingInvitation) {
83
+ toast.add({
84
+ title: existingMember
85
+ ? 'The user is already in this workspace'
86
+ : 'The user is already invited',
87
+ type: 'info'
88
+ })
89
+ return
90
+ }
91
+ try {
92
+ await invite.mutateAsync({ type: 'invite', email: address })
93
+ if (generation !== getAccountGeneration()) return
94
+ toast.add({ title: 'Invitation sent', description: `Sent to ${address}`, type: 'success' })
95
+ } catch (error) {
96
+ if (generation !== getAccountGeneration()) return
97
+ if (
98
+ error instanceof CloudApiError &&
99
+ (error.code === 'ALREADY_MEMBER' ||
100
+ error.code === 'ALREADY_OWNER' ||
101
+ error.code === 'ALREADY_INVITED')
102
+ ) {
103
+ toast.add({
104
+ title:
105
+ error.code === 'ALREADY_INVITED'
106
+ ? 'The user is already invited'
107
+ : 'The user is already in this workspace',
108
+ type: 'info'
109
+ })
110
+ return
111
+ }
112
+ setEmail(email)
113
+ toast.add({
114
+ title: 'Couldn’t send invitation',
115
+ description: error instanceof Error ? error.message : 'Try again',
116
+ type: 'error'
117
+ })
118
+ }
119
+ }
120
+ return (
121
+ <form
122
+ className={cn('flex', className)}
123
+ onSubmit={event => {
124
+ event.preventDefault()
125
+ void submit()
126
+ }}
127
+ >
128
+ <Input
129
+ id="invite-email"
130
+ type="email"
131
+ aria-label="Email"
132
+ placeholder="Email"
133
+ autoComplete="off"
134
+ className="min-w-0 flex-1"
135
+ value={email}
136
+ onChange={event => setEmail(event.target.value)}
137
+ disabled={invite.isPending}
138
+ />
139
+ <Button className="ms-2" type="submit" disabled={invite.isPending || !email.trim()}>
140
+ Invite
141
+ </Button>
142
+ </form>
143
+ )
144
+ }
145
+
146
+ type MembersListProps = {
147
+ className?: string
148
+ workspaceId: string
149
+ membersById?: Map<string, WorkspaceMember>
150
+ invitations: WorkspaceInvitation[]
151
+ users: WorkspaceUserInfo[]
152
+ }
153
+
154
+ function MembersList({
155
+ className,
156
+ workspaceId,
157
+ membersById,
158
+ invitations,
159
+ users
160
+ }: MembersListProps) {
161
+ return (
162
+ <ul
163
+ aria-label="Who has access"
164
+ className={cn('flex max-h-80 scroll-fade flex-col gap-0.5 overflow-y-auto', className)}
165
+ >
166
+ {users.map(user => (
167
+ <MemberRow
168
+ key={user.profile.id}
169
+ user={user}
170
+ workspaceId={workspaceId}
171
+ membershipId={membersById?.get(user.profile.id)?.membershipId}
172
+ />
173
+ ))}
174
+ {invitations.map(invitation => (
175
+ <InvitationRow key={invitation.id} workspaceId={workspaceId} invitation={invitation} />
176
+ ))}
177
+ </ul>
178
+ )
179
+ }
180
+
181
+ type MemberRowProps = {
182
+ user: WorkspaceUserInfo
183
+ workspaceId: string
184
+ membershipId?: string
185
+ }
186
+
187
+ function MemberRow({ user, workspaceId, membershipId }: MemberRowProps) {
188
+ return (
189
+ <li className="flex min-w-0 items-center gap-2 px-2 py-1">
190
+ <User
191
+ profile={user.profile}
192
+ className="flex-1"
193
+ size="sm"
194
+ showYouLabel={user.self}
195
+ description={user.profile.email}
196
+ />
197
+ {membershipId && (
198
+ <RemoveButton workspaceId={workspaceId} action={{ type: 'remove', membershipId }} />
199
+ )}
200
+ </li>
201
+ )
202
+ }
203
+
204
+ type InvitationRowProps = { workspaceId: string; invitation: WorkspaceInvitation }
205
+ function InvitationRow({ workspaceId, invitation }: InvitationRowProps) {
206
+ return (
207
+ <li className="flex min-w-0 items-center gap-2 px-2 py-1">
208
+ <User
209
+ className="flex-1 text-muted-foreground **:data-[slot=avatar]:opacity-30"
210
+ size="sm"
211
+ profile={{
212
+ id: invitation.id,
213
+ email: invitation.email,
214
+ color: colorForId(invitation.email)
215
+ }}
216
+ description={invitation.email}
217
+ />
218
+ <RemoveButton
219
+ workspaceId={workspaceId}
220
+ disabled={invitation.pending}
221
+ action={{ type: 'revoke', invitationId: invitation.id }}
222
+ />
223
+ </li>
224
+ )
225
+ }
226
+
227
+ type RemoveButtonProps = {
228
+ workspaceId: string
229
+ action: Exclude<MembershipAction, { type: 'invite' }>
230
+ disabled?: boolean
231
+ }
232
+
233
+ function RemoveButton({ workspaceId, action, disabled }: RemoveButtonProps) {
234
+ const mutation = useMembershipAction(workspaceId)
235
+ const label = action.type === 'remove' ? 'Remove' : 'Revoke invitation'
236
+ async function submit() {
237
+ if (mutation.isPending || disabled) return
238
+ const generation = getAccountGeneration()
239
+ try {
240
+ await mutation.mutateAsync(action)
241
+ } catch (error) {
242
+ if (generation !== getAccountGeneration()) return
243
+ toast.add({
244
+ title: action.type === 'remove' ? 'Couldn’t remove member' : 'Couldn’t revoke invitation',
245
+ description: error instanceof Error ? error.message : 'Try again',
246
+ type: 'error'
247
+ })
248
+ }
249
+ }
250
+ return (
251
+ <Tooltip>
252
+ <TooltipTrigger
253
+ render={
254
+ <Button
255
+ variant="ghost"
256
+ size="icon-sm"
257
+ className="shrink-0 text-muted-foreground"
258
+ aria-label={label}
259
+ disabled={disabled || mutation.isPending}
260
+ onClick={() => void submit()}
261
+ />
262
+ }
263
+ >
264
+ <IconX stroke={1.75} />
265
+ </TooltipTrigger>
266
+ <TooltipContent>{label}</TooltipContent>
267
+ </Tooltip>
268
+ )
269
+ }
@@ -0,0 +1,179 @@
1
+ import { useRef, useState } from 'react'
2
+ import { IconChevronDown } from '@tabler/icons-react'
3
+ import { useRouter } from 'wouter'
4
+ import { usePathname } from 'wouter/use-browser-location'
5
+ import { Button } from '@/client/components/ui/button'
6
+ import { Popover, PopoverContent, PopoverTrigger } from '@/client/components/ui/popover'
7
+ import type { Icon as TabIcon } from '@tabler/icons-react'
8
+ import type { WorkspaceTabId } from '@/lib/types'
9
+ import { tabFromPath } from '@/lib/workspace-tabs'
10
+ import { userDisplayName } from '@/client/lib/user-display-name'
11
+ import { Tooltip, TooltipTrigger, TooltipContent } from '@/client/components/ui/tooltip'
12
+ import { UserAvatar } from '../components/user-avatar'
13
+ import { AvatarGroup, AvatarGroupCount } from '@/ui-components/avatar'
14
+ import { useWorkspaceMembers } from '../members/hooks'
15
+ import { collabIdentityId } from '../../identity/types'
16
+ import { pageFromPath } from '../presence/provider'
17
+ import { useConnectionState, useWorkspaceUsers, useMe } from '../presence/hooks'
18
+ import { summarizeWorkspaceUsers, type WorkspaceUserInfo } from '../presence/users'
19
+ import { WorkspaceMembers } from './workspace-members'
20
+ // import { AgentInvite } from './agent-invite'
21
+
22
+ export type TabInfo = { label: string; Icon: TabIcon }
23
+ type WorkspaceSharingMenuProps = {
24
+ workspaceId: string
25
+ describeTab: (tab: WorkspaceTabId) => TabInfo | null
26
+ onOpenTab: (tab: WorkspaceTabId) => void
27
+ }
28
+ export function WorkspaceSharingMenu({
29
+ workspaceId,
30
+ describeTab,
31
+ onOpenTab
32
+ }: WorkspaceSharingMenuProps) {
33
+ const state = useConnectionState()
34
+ const workspaceUsers = useWorkspaceUsers()
35
+ const currentUser = useMe()
36
+ const router = useRouter()
37
+ const page = pageFromPath(usePathname(router), workspaceId, router.base)
38
+ const membership = useWorkspaceMembers(workspaceId)
39
+ const memberIds = membership.members && new Set(membership.members.map(collabIdentityId))
40
+ const members = memberIds
41
+ ? workspaceUsers.filter(user => user.id === currentUser?.id || memberIds.has(user.id))
42
+ : workspaceUsers
43
+ const users = summarizeWorkspaceUsers(state.connections, {
44
+ currentUser,
45
+ users:
46
+ membership.isSuccess && currentUser && !members.some(user => user.id === currentUser.id)
47
+ ? [currentUser, ...members]
48
+ : members,
49
+ page
50
+ })
51
+ const active = users.filter(user => user.status === 'active')
52
+ const shown = active.slice(0, 4).toReversed()
53
+ const hidden = active.length - shown.length
54
+ const [open, setOpen] = useState(false)
55
+ const headerRef = useRef<HTMLDivElement>(null)
56
+
57
+ return (
58
+ <Popover
59
+ open={open}
60
+ onOpenChange={(nextOpen, details) => {
61
+ // Sibling avatar controls handle their own clicks, including toggling sharing.
62
+ if (
63
+ details.reason === 'outside-press' &&
64
+ details.event.target instanceof Node &&
65
+ headerRef.current?.contains(details.event.target)
66
+ ) {
67
+ details.cancel()
68
+ return
69
+ }
70
+ setOpen(nextOpen)
71
+ }}
72
+ >
73
+ <div ref={headerRef} className="group/sharing relative inline-flex items-center rounded-full">
74
+ <PopoverTrigger
75
+ render={
76
+ <Button
77
+ variant="ghost"
78
+ size="sm"
79
+ aria-label="Users in this workspace"
80
+ className="absolute inset-0 h-full w-full justify-end gap-0.5 rounded-full pr-1 pl-1 group-hover/sharing:bg-accent data-popup-open:bg-accent"
81
+ />
82
+ }
83
+ >
84
+ <IconChevronDown stroke={2.5} className="size-3! text-muted-foreground" />
85
+ </PopoverTrigger>
86
+ <div className="pointer-events-none flex h-7 items-center gap-0.5 px-1">
87
+ <AvatarGroup>
88
+ {hidden > 0 && (
89
+ <Button
90
+ variant={null}
91
+ size="icon-xs"
92
+ data-slot="avatar"
93
+ data-size="xs"
94
+ className="pointer-events-auto relative size-5 rounded-full p-0"
95
+ aria-label={`${hidden} more active users`}
96
+ onClick={() => setOpen(value => !value)}
97
+ >
98
+ <AvatarGroupCount size="xs">+{hidden}</AvatarGroupCount>
99
+ </Button>
100
+ )}
101
+ {shown.map(user => (
102
+ <MemberAvatar
103
+ key={user.profile.id}
104
+ user={user}
105
+ page={page}
106
+ describeTab={describeTab}
107
+ onToggleSharing={() => setOpen(value => !value)}
108
+ onOpenTab={tab => {
109
+ setOpen(false)
110
+ onOpenTab(tab)
111
+ }}
112
+ />
113
+ ))}
114
+ </AvatarGroup>
115
+ <span aria-hidden="true" className="size-3" />
116
+ </div>
117
+ </div>
118
+ <PopoverContent
119
+ initialFocus={false}
120
+ align="end"
121
+ className="w-96 max-w-[calc(100vw-2rem)] gap-2 bg-transparent p-0 shadow-none"
122
+ >
123
+ <WorkspaceMembers workspaceId={workspaceId} users={users} membership={membership} />
124
+ {/* Enable once agent invitations are functional and the card is polished. */}
125
+ {/* <AgentInvite /> */}
126
+ </PopoverContent>
127
+ </Popover>
128
+ )
129
+ }
130
+
131
+ type MemberAvatarProps = Pick<WorkspaceSharingMenuProps, 'describeTab' | 'onOpenTab'> & {
132
+ user: WorkspaceUserInfo
133
+ page: string
134
+ onToggleSharing: () => void
135
+ }
136
+
137
+ function MemberAvatar({ user, page, describeTab, onOpenTab, onToggleSharing }: MemberAvatarProps) {
138
+ const tab = user.page ? tabFromPath(user.page) : null
139
+ const info = tab ? describeTab(tab) : null
140
+ const name = userDisplayName(user.profile)
141
+ return (
142
+ <div data-slot="avatar" data-size="xs" className="relative size-5 shrink-0">
143
+ <Tooltip>
144
+ <TooltipTrigger
145
+ render={
146
+ <Button
147
+ variant={null}
148
+ size="icon-xs"
149
+ data-slot="avatar"
150
+ data-size="xs"
151
+ className="pointer-events-auto relative size-5 rounded-full p-0"
152
+ aria-label={user.self ? `${name} (You), open sharing` : name}
153
+ onClick={() => {
154
+ if (user.self) onToggleSharing()
155
+ else if (tab && info && tab !== page) {
156
+ onOpenTab(tab)
157
+ }
158
+ }}
159
+ />
160
+ }
161
+ >
162
+ <UserAvatar profile={user.profile} size="xs" />
163
+ </TooltipTrigger>
164
+ <TooltipContent className="flex-col gap-1 text-center">
165
+ <div>
166
+ {name}
167
+ {user.self ? ' (You)' : ''}
168
+ </div>
169
+ {info && (
170
+ <div className="flex items-center justify-center gap-0.5 text-muted-foreground">
171
+ <info.Icon size={12} stroke={1.75} />
172
+ {info.label}
173
+ </div>
174
+ )}
175
+ </TooltipContent>
176
+ </Tooltip>
177
+ </div>
178
+ )
179
+ }
@@ -3,9 +3,9 @@ import { renderToStaticMarkup } from 'react-dom/server'
3
3
 
4
4
  import type { PresenceRegistration, UserProfile } from '@/lib/collab/types'
5
5
 
6
- import { AppletPresenceProvider, CollabContext } from '../provider'
7
- import { presenceChannels } from '../hooks'
8
- import { presenceTarget } from '../presence-target'
6
+ import { AppletPresenceProvider, CollabContext } from '../presence/provider'
7
+ import { presenceChannels } from '../presence/hooks'
8
+ import { presenceTarget } from '../presence/presence-target'
9
9
  import { createFakeEngine } from './fake-engine'
10
10
  import type { FakeEngine } from './fake-engine'
11
11
 
@@ -1,8 +1,8 @@
1
1
  import type { UserProfile, Connection, PresenceRegistration } from '@/lib/collab/types'
2
2
  import { COLLAB_PROTOCOL_VERSION } from '@/lib/collab/protocol'
3
- import type { CollabEngineApi } from '../client'
3
+ import type { CollabEngineApi } from '../presence/client'
4
4
  import { normalizeUserProfile } from '../host-state'
5
- import { CollabStore } from '../store'
5
+ import { CollabStore } from '../presence/store'
6
6
 
7
7
  function normalizeUsers(users: readonly UserProfile[]): readonly UserProfile[] {
8
8
  if (!Array.isArray(users)) throw new Error('Users must be an array.')
@@ -59,8 +59,10 @@ const layoutCtxValue: WorkspaceLayoutContextValue = {
59
59
  setLayout: () => {},
60
60
  name: 'moi',
61
61
  cwd: DEV_CWD,
62
- provider: 'openclaw',
62
+ harness: 'openclaw',
63
63
  workspaceId: DEV_WORKSPACE_ID,
64
+ apiBase: '/api/workspaces/test',
65
+ isRemote: false,
64
66
  isLoading: false
65
67
  }
66
68
 
@@ -44,8 +44,8 @@ import {
44
44
  usePublishPresence,
45
45
  useUser,
46
46
  useWorkspaceUsers
47
- } from '@/client/features/collab/hooks'
48
- import { AppletPresenceProvider, CollabContext } from '@/client/features/collab/provider'
47
+ } from '@/client/features/collab/presence/hooks'
48
+ import { AppletPresenceProvider, CollabContext } from '@/client/features/collab/presence/provider'
49
49
  import { connectPlaygroundParticipants } from './playground-room'
50
50
 
51
51
  const YOU: UserProfile = {