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.
- package/client/api/app-config.ts +12 -2
- package/client/api/http.ts +11 -1
- package/client/app/app-router.tsx +3 -2
- package/client/app/routes/home-route.tsx +1 -1
- package/client/app/routes/workspace-registration.tsx +68 -0
- package/client/app/routes/workspace-route.tsx +37 -13
- package/client/app/shell/sidebar-layout.tsx +10 -5
- package/client/components/shared/workspace-icon.tsx +8 -17
- package/client/features/account/account-test-utils.tsx +18 -4
- package/client/features/account/api.ts +10 -8
- package/client/features/account/profile-actions.ts +5 -7
- package/client/features/app-settings/avatar-upload.tsx +62 -0
- package/client/features/app-settings/profile-settings.tsx +10 -0
- package/client/features/app-settings/settings-page.tsx +2 -1
- package/client/features/applets/api.ts +6 -6
- package/client/features/applets/applet-cache.ts +6 -5
- package/client/features/applets/applet-log.ts +2 -1
- package/client/features/applets/applet-runtime.ts +2 -1
- package/client/features/applets/use-applet.ts +73 -18
- package/client/features/applets/widget-shell.tsx +4 -2
- package/client/features/chat/applet-chat-intents.ts +5 -13
- package/client/features/chat/chat-popup.tsx +8 -4
- package/client/features/chat/chat-send.ts +2 -2
- package/client/features/chat/composer/model-order.ts +4 -4
- package/client/features/chat/composer/model-picker.tsx +12 -10
- package/client/features/chat/composer/use-workspace-composer-state.tsx +1 -1
- package/client/features/chat/sessions/api.ts +11 -28
- package/client/features/chat/sessions/use-selected-session.ts +18 -100
- package/client/features/chat/use-chat.ts +8 -12
- package/client/features/collab/applet-api.ts +1 -1
- package/client/features/collab/components/cursors.tsx +6 -1
- package/client/features/collab/components/presence-avatars.tsx +1 -1
- package/client/features/collab/components/presence-frame.tsx +1 -1
- package/client/features/collab/components/presence-group.tsx +1 -1
- package/client/features/collab/components/presence-helpers.ts +2 -2
- package/client/features/collab/components/user-avatar-group.tsx +1 -1
- package/client/features/collab/components/user-avatar.tsx +1 -1
- package/client/features/collab/components/user.tsx +1 -1
- package/client/features/collab/index.ts +3 -3
- package/client/features/collab/members/api.ts +17 -0
- package/client/features/collab/members/hooks.ts +97 -0
- package/client/features/collab/members/store.ts +148 -0
- package/client/features/{workspace-members → collab/members}/types.ts +7 -5
- package/client/features/collab/{client.ts → presence/client.ts} +4 -5
- package/client/features/collab/{hooks.tsx → presence/hooks.tsx} +1 -1
- package/client/features/collab/{provider.tsx → presence/provider.tsx} +1 -12
- package/client/features/collab/{users.ts → presence/users.ts} +19 -21
- package/client/features/collab/proxy-user.ts +1 -3
- package/client/features/collab/sharing/agent-invite.tsx +30 -0
- package/client/features/collab/sharing/workspace-members.tsx +269 -0
- package/client/features/collab/sharing/workspace-sharing-menu.tsx +179 -0
- package/client/features/collab/testing/component-fixtures.tsx +3 -3
- package/client/features/collab/testing/fake-engine.ts +2 -2
- package/client/features/dev/chat-states-page.tsx +3 -1
- package/client/features/dev/collab/collab-playground.tsx +2 -2
- package/client/features/dev/dev-index-page.tsx +0 -6
- package/client/features/dev/dev-routes.tsx +0 -2
- package/client/features/dev/harness-debug-page.tsx +7 -7
- package/client/features/dev/workspace-setup-mocks.ts +1 -2
- package/client/features/dev/workspace-setup-preview.tsx +6 -4
- package/client/features/harness/api.ts +13 -10
- package/client/features/harness/harness-login-panel.tsx +9 -5
- package/client/features/harness/harness-presentation.ts +4 -4
- package/client/features/harness/harness-selector.tsx +13 -13
- package/client/features/harness/use-harness-login.ts +5 -5
- package/client/features/home/api.ts +38 -2
- package/client/features/home/home-page.tsx +43 -13
- package/client/features/home/shared-workspaces.tsx +70 -0
- package/client/features/home/workspace-invitations.tsx +101 -0
- package/client/features/identity/host-api.ts +5 -4
- package/client/features/identity/store.ts +1 -7
- package/client/features/onboarding/agent-setup-step.tsx +8 -8
- package/client/features/onboarding/onboarding-page.tsx +3 -2
- package/client/features/onboarding/workspace-setup-step.tsx +1 -1
- package/client/features/overview/api.ts +3 -5
- package/client/features/overview/default/registry.tsx +1 -1
- package/client/features/overview/default/views-widget.tsx +2 -2
- package/client/features/overview/hidden-panel.tsx +7 -5
- package/client/features/overview/overview.tsx +18 -16
- package/client/features/overview/workspace-name.tsx +2 -2
- package/client/features/scratchpad/scratchpad.tsx +9 -7
- package/client/features/scratchpad/use-scratchpad-snapshot.tsx +13 -5
- package/client/features/views/api.ts +34 -16
- package/client/features/views/use-view-actions.ts +10 -20
- package/client/features/views/view-manager.tsx +1 -1
- package/client/features/views/view-submission.ts +2 -21
- package/client/features/workspace/add/api.ts +5 -4
- package/client/features/workspace/add/create-workspace-dialog.tsx +12 -9
- package/client/features/workspace/add/import-workspace-dialog.tsx +7 -7
- package/client/features/workspace/add/use-workspace-import.ts +10 -10
- package/client/features/workspace/add/workspace-agent-options.ts +21 -20
- package/client/features/workspace/add/workspace-agent-selector.tsx +11 -11
- package/client/features/workspace/api.ts +60 -13
- package/client/features/workspace/harness-transition.ts +7 -13
- package/client/features/workspace/remote.ts +25 -0
- package/client/features/workspace/settings/api.ts +7 -12
- package/client/features/workspace/settings/connectors-settings.tsx +3 -3
- package/client/features/workspace/settings/general-settings.tsx +8 -8
- package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
- package/client/features/workspace/setup/workspace-recovery-states.tsx +43 -14
- package/client/features/workspace/setup/workspace-setup.tsx +6 -6
- package/client/features/workspace/tab-resolution.ts +2 -2
- package/client/features/workspace/use-workspace-navigation.ts +7 -4
- package/client/features/workspace/workspace-content.tsx +32 -26
- package/client/features/workspace/workspace-frame.tsx +13 -26
- package/client/features/workspace/workspace-layout-context.tsx +45 -12
- package/client/features/workspace/workspace-menu.tsx +2 -2
- package/client/features/workspace/workspace-pane.tsx +22 -0
- package/client/features/workspace/workspace-pending-screen.tsx +1 -1
- package/client/features/workspace/workspace-preferences.ts +34 -0
- package/client/features/workspace/workspace-presentation.tsx +12 -16
- package/client/features/workspace/workspace-screen.tsx +2 -2
- package/client/features/workspace/workspace-state.ts +2 -1
- package/client/features/workspace/workspace-tabs.tsx +1 -1
- package/client/features/workspace/workspace-test-utils.ts +23 -0
- package/client/runtime/use-workspace-events.ts +14 -0
- package/client/runtime/workspace-events.ts +9 -9
- package/client/store/ui.ts +29 -9
- package/dist/chunk-44khk4sp.js +2 -0
- package/dist/chunk-ba6mz56s.js +72 -0
- package/dist/chunk-ec5ennpv.js +1 -0
- package/dist/chunk-ectsnw81.js +2 -0
- package/dist/chunk-en7w5ypg.js +1 -0
- package/dist/chunk-f695wcx5.js +5 -0
- package/dist/chunk-kffcah9w.css +1 -0
- package/dist/{chunk-kdgk4dac.js → chunk-n0fawy9x.js} +1 -1
- package/dist/chunk-pdt9hxfw.js +2 -0
- package/dist/chunk-rmd0ctfx.js +546 -0
- package/dist/chunk-zv22wv0g.js +1 -0
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +4 -4
- package/lib/harness-types.ts +13 -0
- package/lib/types.ts +34 -50
- package/lib/workspace-config.ts +48 -0
- package/lib/workspace-layout.ts +2 -4
- package/package.json +4 -2
- package/server/README.md +29 -27
- package/server/api/harnesses.ts +5 -5
- package/server/api/index.ts +170 -68
- package/server/app-config.ts +2 -7
- package/server/applets/declarations.ts +6 -7
- package/server/applets/index.ts +15 -9
- package/server/applets/views.ts +2 -17
- package/server/applets/widgets.ts +3 -2
- package/server/cli/commands/config.ts +8 -20
- package/server/cli/commands/hermes.ts +2 -2
- package/server/cli/commands/init.ts +96 -64
- package/server/cli/commands/openclaw.ts +2 -2
- package/server/cli/commands/refresh.ts +10 -1
- package/server/cli/commands/remote.ts +228 -0
- package/server/cli/commands/skill.ts +4 -4
- package/server/cli/commands/tabs.ts +5 -12
- package/server/cli/control.ts +35 -4
- package/server/cli/index.ts +10 -6
- package/server/cli/remote-command.ts +77 -0
- package/server/cli/remote-control.ts +70 -0
- package/server/cli/remote-operations.ts +244 -0
- package/server/collab/config.ts +4 -8
- package/server/collab/manager.ts +5 -2
- package/server/collab/skill/index.ts +4 -50
- package/server/control.ts +38 -11
- package/server/harness/acp/session.ts +4 -4
- package/server/harness/auth.ts +26 -31
- package/server/harness/claude-code/index.ts +1 -1
- package/server/harness/codex/discovery.ts +1 -1
- package/server/harness/codex/session.ts +1 -1
- package/server/harness/detect.ts +14 -19
- package/server/harness/executable.ts +10 -10
- package/server/harness/hermes/NOTES.md +2 -2
- package/server/harness/hermes/index.ts +1 -1
- package/server/harness/install.ts +11 -11
- package/server/harness/openclaw/index.ts +1 -1
- package/server/harness/registry.ts +7 -6
- package/server/harness/types.ts +4 -4
- package/server/onboarding/jobs.ts +1 -1
- package/server/operations/commands.ts +46 -0
- package/server/operations/files.ts +148 -0
- package/server/operations/server.ts +206 -0
- package/server/remote/agent.ts +103 -0
- package/server/remote/client.ts +665 -0
- package/server/remote/workspace.ts +34 -0
- package/server/scratchpad/document.ts +32 -12
- package/server/scratchpad/executor.ts +16 -7
- package/server/sessions/config.ts +8 -5
- package/server/sessions/pending-views.ts +16 -0
- package/server/sessions/view-sessions.ts +10 -12
- package/server/skills/locations.ts +4 -4
- package/server/skills/template.ts +3 -2
- package/server/skills/update.ts +12 -12
- package/server/skills/version.ts +7 -7
- package/server/skills/workspace.ts +13 -13
- package/server/web.ts +12 -10
- package/server/workspace-state/file.ts +2 -0
- package/server/workspace-state/index.ts +0 -4
- package/server/workspaces/api.ts +28 -0
- package/server/workspaces/change-harness.ts +15 -26
- package/server/workspaces/import.ts +4 -4
- package/server/workspaces/init.ts +15 -13
- package/server/workspaces/layout.ts +60 -66
- package/server/workspaces/registry.ts +43 -18
- package/server/workspaces/scaffold.ts +1 -0
- package/server/workspaces/shared.ts +74 -0
- package/server/workspaces/tabs.ts +6 -12
- package/skill/SKILL.md +24 -4
- package/client/api/app-ui-keys.ts +0 -6
- package/client/features/chat/sessions/browser-tab-state.ts +0 -43
- package/client/features/collab/workspace-users-menu.tsx +0 -190
- package/client/features/dev/cloud-avatar-upload.tsx +0 -58
- package/client/features/dev/cloud-page.tsx +0 -363
- package/client/features/workspace/browser-tab-state.ts +0 -51
- package/client/features/workspace/layout-save.ts +0 -13
- package/client/features/workspace-members/api.ts +0 -20
- package/client/features/workspace-members/hooks.ts +0 -127
- package/client/features/workspace-members/keys.ts +0 -6
- package/client/features/workspace-members/store.ts +0 -123
- package/dist/chunk-00s35r33.js +0 -546
- package/dist/chunk-7rz6g7g7.js +0 -1
- package/dist/chunk-af2jyddf.js +0 -2
- package/dist/chunk-cekekc3f.css +0 -1
- package/dist/chunk-ep5vh16c.js +0 -75
- package/dist/chunk-s5s1vzdw.js +0 -2
- package/dist/chunk-svxhxfeq.js +0 -2
- package/dist/chunk-t0r0bds1.js +0 -1
- package/dist/chunk-vp2qzc0d.js +0 -1
- package/dist/chunk-wz5qv1bn.js +0 -2
- package/lib/workspace-types.ts +0 -13
- package/server/workspace-state/legacy-migration.ts +0 -79
- /package/client/features/collab/{presence-publisher.ts → presence/presence-publisher.ts} +0 -0
- /package/client/features/collab/{presence-target.ts → presence/presence-target.ts} +0 -0
- /package/client/features/collab/{store.ts → presence/store.ts} +0 -0
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
import { Link } from 'wouter'
|
|
3
|
-
import { IconArrowLeft, IconMail, IconUserPlus } from '@tabler/icons-react'
|
|
4
|
-
import { Button } from '@/client/components/ui/button'
|
|
5
|
-
import { Input } from '@/client/components/ui/input'
|
|
6
|
-
import { Skeleton } from '@/client/components/ui/skeleton'
|
|
7
|
-
import { Alert, AlertDescription } from '@/ui-components/alert'
|
|
8
|
-
import { Badge } from '@/ui-components/badge'
|
|
9
|
-
import {
|
|
10
|
-
AlertDialog,
|
|
11
|
-
AlertDialogAction,
|
|
12
|
-
AlertDialogCancel,
|
|
13
|
-
AlertDialogContent,
|
|
14
|
-
AlertDialogDescription,
|
|
15
|
-
AlertDialogFooter,
|
|
16
|
-
AlertDialogHeader,
|
|
17
|
-
AlertDialogTitle
|
|
18
|
-
} from '@/ui-components/alert-dialog'
|
|
19
|
-
import {
|
|
20
|
-
Select,
|
|
21
|
-
SelectContent,
|
|
22
|
-
SelectItem,
|
|
23
|
-
SelectTrigger,
|
|
24
|
-
SelectValue
|
|
25
|
-
} from '@/ui-components/select'
|
|
26
|
-
import { useAppConfig } from '@/client/api/app-config'
|
|
27
|
-
import { UserAvatar } from '../collab/components/user-avatar'
|
|
28
|
-
import { normalizeUserProfile } from '../collab/host-state'
|
|
29
|
-
import { collabIdentityId } from '../identity/types'
|
|
30
|
-
import { useIdentity } from '../identity/use-identity'
|
|
31
|
-
import { useWorkspaces } from '../home/api'
|
|
32
|
-
import {
|
|
33
|
-
useWorkspaceMembers,
|
|
34
|
-
useInviteMember,
|
|
35
|
-
useRemoveMember,
|
|
36
|
-
useRevokeInvitation
|
|
37
|
-
} from '../workspace-members/hooks'
|
|
38
|
-
import type { WorkspaceMember } from '../workspace-members/types'
|
|
39
|
-
import { CloudAvatarUpload } from './cloud-avatar-upload'
|
|
40
|
-
|
|
41
|
-
export function CloudPage() {
|
|
42
|
-
const { environment } = useAppConfig()
|
|
43
|
-
if (environment !== 'cloud')
|
|
44
|
-
return (
|
|
45
|
-
<main className="mx-auto max-w-xl space-y-4 px-6 py-10 text-sm">
|
|
46
|
-
<h1 className="text-xl font-medium">Share workspace</h1>
|
|
47
|
-
<p className="text-muted-foreground">
|
|
48
|
-
Workspace sharing is available when you sign in to Moi Run
|
|
49
|
-
</p>
|
|
50
|
-
<Button variant="outline" nativeButton={false} render={<Link href="/" />}>
|
|
51
|
-
Back to workspaces
|
|
52
|
-
</Button>
|
|
53
|
-
</main>
|
|
54
|
-
)
|
|
55
|
-
return <WorkspaceSharing />
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function WorkspaceSharing() {
|
|
59
|
-
const workspaces = useWorkspaces()
|
|
60
|
-
const [selected, setSelected] = useState<string>()
|
|
61
|
-
const workspace = workspaces.data?.find(item => item.id === selected) ?? workspaces.data?.[0]
|
|
62
|
-
const name = workspace?.name || 'Workspace'
|
|
63
|
-
return (
|
|
64
|
-
<main className="mx-auto flex max-w-xl flex-col gap-8 px-5 py-8 text-sm sm:px-6 sm:py-12">
|
|
65
|
-
<header className="space-y-5">
|
|
66
|
-
<Button
|
|
67
|
-
variant="ghost"
|
|
68
|
-
size="sm"
|
|
69
|
-
className="-ml-2 w-fit"
|
|
70
|
-
nativeButton={false}
|
|
71
|
-
render={<Link href="/" />}
|
|
72
|
-
>
|
|
73
|
-
<IconArrowLeft stroke={1.75} /> Workspaces
|
|
74
|
-
</Button>
|
|
75
|
-
<div className="space-y-2">
|
|
76
|
-
<h1 className="text-xl font-medium">Share workspace</h1>
|
|
77
|
-
<p className="text-muted-foreground">Invite people to work alongside you</p>
|
|
78
|
-
</div>
|
|
79
|
-
</header>
|
|
80
|
-
<section className="space-y-2" aria-label="Choose workspace">
|
|
81
|
-
<label className="font-medium" id="sharing-workspace-label">
|
|
82
|
-
Workspace
|
|
83
|
-
</label>
|
|
84
|
-
{workspaces.isError ? (
|
|
85
|
-
<Alert variant="destructive">
|
|
86
|
-
<AlertDescription>{workspaces.error.message}</AlertDescription>
|
|
87
|
-
</Alert>
|
|
88
|
-
) : workspaces.isPending ? (
|
|
89
|
-
<Skeleton className="h-10 w-full" />
|
|
90
|
-
) : !workspace ? (
|
|
91
|
-
<p className="text-muted-foreground">Create a workspace to invite people</p>
|
|
92
|
-
) : (
|
|
93
|
-
<Select value={workspace.id} onValueChange={value => setSelected(value ?? undefined)}>
|
|
94
|
-
<SelectTrigger className="w-full" aria-labelledby="sharing-workspace-label">
|
|
95
|
-
<SelectValue>{name}</SelectValue>
|
|
96
|
-
</SelectTrigger>
|
|
97
|
-
<SelectContent align="start">
|
|
98
|
-
{workspaces.data.map(item => (
|
|
99
|
-
<SelectItem key={item.id} value={item.id}>
|
|
100
|
-
{item.name || 'Workspace'}
|
|
101
|
-
</SelectItem>
|
|
102
|
-
))}
|
|
103
|
-
</SelectContent>
|
|
104
|
-
</Select>
|
|
105
|
-
)}
|
|
106
|
-
</section>
|
|
107
|
-
{workspace && (
|
|
108
|
-
<SharingMembers key={workspace.id} workspaceId={workspace.id} workspaceName={name} />
|
|
109
|
-
)}
|
|
110
|
-
</main>
|
|
111
|
-
)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
type SharingMembersProps = { workspaceId: string; workspaceName: string }
|
|
115
|
-
type Removal =
|
|
116
|
-
| { type: 'member'; id: string; name: string }
|
|
117
|
-
| { type: 'invitation'; id: string; email: string }
|
|
118
|
-
function SharingMembers({ workspaceId, workspaceName }: SharingMembersProps) {
|
|
119
|
-
const identity = useIdentity()
|
|
120
|
-
const snapshot = useWorkspaceMembers(workspaceId)
|
|
121
|
-
const invite = useInviteMember(workspaceId)
|
|
122
|
-
const remove = useRemoveMember(workspaceId)
|
|
123
|
-
const revoke = useRevokeInvitation(workspaceId)
|
|
124
|
-
const [email, setEmail] = useState('')
|
|
125
|
-
const [removal, setRemoval] = useState<Removal>()
|
|
126
|
-
const [notice, setNotice] = useState<string>()
|
|
127
|
-
const removing = remove.isPending || revoke.isPending
|
|
128
|
-
const removalError = remove.error ?? revoke.error
|
|
129
|
-
async function sendInvitation() {
|
|
130
|
-
setNotice(undefined)
|
|
131
|
-
try {
|
|
132
|
-
await invite.mutateAsync({ email })
|
|
133
|
-
setEmail('')
|
|
134
|
-
setNotice(`Invitation sent to ${email.trim().toLowerCase()}`)
|
|
135
|
-
} catch {
|
|
136
|
-
/* Keep the address so the invitation can be retried. */
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function chooseRemoval(next: Removal) {
|
|
140
|
-
remove.reset()
|
|
141
|
-
revoke.reset()
|
|
142
|
-
setRemoval(next)
|
|
143
|
-
}
|
|
144
|
-
async function confirmRemoval() {
|
|
145
|
-
if (!removal) return
|
|
146
|
-
try {
|
|
147
|
-
if (removal.type === 'member') await remove.mutateAsync({ membershipId: removal.id })
|
|
148
|
-
else await revoke.mutateAsync({ invitationId: removal.id })
|
|
149
|
-
setNotice(removal.type === 'member' ? 'Member removed' : 'Invitation revoked')
|
|
150
|
-
setRemoval(undefined)
|
|
151
|
-
} catch {
|
|
152
|
-
/* The dialog keeps the error visible and allows retry. */
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const inviteError = invite.error ?? snapshot.error
|
|
156
|
-
return (
|
|
157
|
-
<>
|
|
158
|
-
<section className="space-y-3" aria-labelledby="invite-heading">
|
|
159
|
-
<h2 className="font-medium" id="invite-heading">
|
|
160
|
-
Invite someone
|
|
161
|
-
</h2>
|
|
162
|
-
<form
|
|
163
|
-
className="flex flex-col gap-2 sm:flex-row"
|
|
164
|
-
onSubmit={event => {
|
|
165
|
-
event.preventDefault()
|
|
166
|
-
void sendInvitation()
|
|
167
|
-
}}
|
|
168
|
-
>
|
|
169
|
-
<Input
|
|
170
|
-
type="email"
|
|
171
|
-
required
|
|
172
|
-
aria-label="Email address"
|
|
173
|
-
placeholder="Email address"
|
|
174
|
-
autoComplete="email"
|
|
175
|
-
value={email}
|
|
176
|
-
className="min-w-0 flex-1"
|
|
177
|
-
onChange={event => {
|
|
178
|
-
setEmail(event.target.value)
|
|
179
|
-
setNotice(undefined)
|
|
180
|
-
}}
|
|
181
|
-
disabled={invite.isPending || !snapshot.data}
|
|
182
|
-
/>
|
|
183
|
-
<Button type="submit" disabled={invite.isPending || !snapshot.data || !email.trim()}>
|
|
184
|
-
<IconUserPlus stroke={1.5} /> {invite.isPending ? 'Sending…' : 'Send invite'}
|
|
185
|
-
</Button>
|
|
186
|
-
</form>
|
|
187
|
-
<p className="text-muted-foreground">
|
|
188
|
-
Members can view and edit everything in this workspace
|
|
189
|
-
</p>
|
|
190
|
-
{notice && <p role="status">{notice}</p>}
|
|
191
|
-
{inviteError && (
|
|
192
|
-
<Alert variant="destructive">
|
|
193
|
-
<AlertDescription>{inviteError.message}</AlertDescription>
|
|
194
|
-
</Alert>
|
|
195
|
-
)}
|
|
196
|
-
{snapshot.isError && (
|
|
197
|
-
<Button size="sm" variant="outline" onClick={() => void snapshot.refetch()}>
|
|
198
|
-
Try again
|
|
199
|
-
</Button>
|
|
200
|
-
)}
|
|
201
|
-
</section>
|
|
202
|
-
<section aria-labelledby="members-heading" className="space-y-3">
|
|
203
|
-
<h2 id="members-heading" className="flex items-center gap-2 font-medium">
|
|
204
|
-
Members{' '}
|
|
205
|
-
{snapshot.members && (
|
|
206
|
-
<span className="font-normal text-muted-foreground">{snapshot.members.length}</span>
|
|
207
|
-
)}
|
|
208
|
-
</h2>
|
|
209
|
-
{snapshot.isPending ? (
|
|
210
|
-
<div className="space-y-4" aria-label="Loading members">
|
|
211
|
-
{[0, 1].map(row => (
|
|
212
|
-
<div key={row} className="flex items-center gap-3">
|
|
213
|
-
<Skeleton className="size-8 rounded-full" />
|
|
214
|
-
<Skeleton className="h-4 w-40" />
|
|
215
|
-
</div>
|
|
216
|
-
))}
|
|
217
|
-
</div>
|
|
218
|
-
) : (
|
|
219
|
-
<ul className="divide-y divide-border">
|
|
220
|
-
{snapshot.members?.map(member => {
|
|
221
|
-
const isMe = identity?.type === member.type && identity.id === member.id
|
|
222
|
-
const displayName = member.name || (member.type === 'user' ? member.email : 'Agent')
|
|
223
|
-
return (
|
|
224
|
-
<li
|
|
225
|
-
key={`${member.type}:${member.id}`}
|
|
226
|
-
className="flex min-w-0 items-center gap-3 py-3"
|
|
227
|
-
>
|
|
228
|
-
{isMe && identity?.type === 'user' ? (
|
|
229
|
-
<CloudAvatarUpload>
|
|
230
|
-
<MemberAvatar member={{ ...member, ...identity }} />
|
|
231
|
-
</CloudAvatarUpload>
|
|
232
|
-
) : (
|
|
233
|
-
<MemberAvatar member={member} />
|
|
234
|
-
)}
|
|
235
|
-
<div className="min-w-0 flex-1">
|
|
236
|
-
<p className="truncate font-medium">
|
|
237
|
-
{displayName}
|
|
238
|
-
{isMe && <span className="font-normal text-muted-foreground"> (you)</span>}
|
|
239
|
-
</p>
|
|
240
|
-
{member.type === 'user' && (
|
|
241
|
-
<p className="truncate text-muted-foreground">{member.email}</p>
|
|
242
|
-
)}
|
|
243
|
-
{member.type === 'agent' && <p className="text-muted-foreground">Agent</p>}
|
|
244
|
-
</div>
|
|
245
|
-
{!member.membershipId ? (
|
|
246
|
-
<Badge variant="secondary">Owner</Badge>
|
|
247
|
-
) : (
|
|
248
|
-
<Button
|
|
249
|
-
size="sm"
|
|
250
|
-
variant="ghost"
|
|
251
|
-
onClick={() =>
|
|
252
|
-
chooseRemoval({
|
|
253
|
-
type: 'member',
|
|
254
|
-
id: member.membershipId!,
|
|
255
|
-
name: displayName
|
|
256
|
-
})
|
|
257
|
-
}
|
|
258
|
-
>
|
|
259
|
-
Remove
|
|
260
|
-
</Button>
|
|
261
|
-
)}
|
|
262
|
-
</li>
|
|
263
|
-
)
|
|
264
|
-
})}
|
|
265
|
-
</ul>
|
|
266
|
-
)}
|
|
267
|
-
</section>
|
|
268
|
-
{!!snapshot.invitations?.length && (
|
|
269
|
-
<section aria-labelledby="invitations-heading" className="space-y-3">
|
|
270
|
-
<h2 id="invitations-heading" className="flex items-center gap-2 font-medium">
|
|
271
|
-
Pending invitations{' '}
|
|
272
|
-
<span className="font-normal text-muted-foreground">{snapshot.invitations.length}</span>
|
|
273
|
-
</h2>
|
|
274
|
-
<ul className="divide-y divide-border">
|
|
275
|
-
{snapshot.invitations.map(invitation => (
|
|
276
|
-
<li key={invitation.id} className="flex min-w-0 items-center gap-3 py-3">
|
|
277
|
-
<span className="flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground">
|
|
278
|
-
<IconMail size={16} stroke={1.75} />
|
|
279
|
-
</span>
|
|
280
|
-
<div className="min-w-0 flex-1">
|
|
281
|
-
<p className="truncate font-medium">{invitation.email}</p>
|
|
282
|
-
<p className="text-muted-foreground">
|
|
283
|
-
{invitation.pending
|
|
284
|
-
? 'Sending invitation…'
|
|
285
|
-
: `Invited · Expires ${new Date(invitation.expiresAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })}`}
|
|
286
|
-
</p>
|
|
287
|
-
</div>
|
|
288
|
-
{!invitation.pending && (
|
|
289
|
-
<Button
|
|
290
|
-
size="sm"
|
|
291
|
-
variant="ghost"
|
|
292
|
-
onClick={() =>
|
|
293
|
-
chooseRemoval({
|
|
294
|
-
type: 'invitation',
|
|
295
|
-
id: invitation.id,
|
|
296
|
-
email: invitation.email
|
|
297
|
-
})
|
|
298
|
-
}
|
|
299
|
-
>
|
|
300
|
-
Revoke
|
|
301
|
-
</Button>
|
|
302
|
-
)}
|
|
303
|
-
</li>
|
|
304
|
-
))}
|
|
305
|
-
</ul>
|
|
306
|
-
</section>
|
|
307
|
-
)}
|
|
308
|
-
<AlertDialog
|
|
309
|
-
open={!!removal}
|
|
310
|
-
onOpenChange={open => {
|
|
311
|
-
if (!open && !removing) setRemoval(undefined)
|
|
312
|
-
}}
|
|
313
|
-
>
|
|
314
|
-
<AlertDialogContent>
|
|
315
|
-
<AlertDialogHeader>
|
|
316
|
-
<AlertDialogTitle>
|
|
317
|
-
{removal?.type === 'member' ? `Remove ${removal.name}?` : 'Revoke invitation?'}
|
|
318
|
-
</AlertDialogTitle>
|
|
319
|
-
<AlertDialogDescription>
|
|
320
|
-
{removal?.type === 'member'
|
|
321
|
-
? `They’ll lose access to ${workspaceName}. You can invite them again later.`
|
|
322
|
-
: `The invitation for ${removal?.email ?? ''} will no longer work.`}
|
|
323
|
-
</AlertDialogDescription>
|
|
324
|
-
</AlertDialogHeader>
|
|
325
|
-
{removalError && (
|
|
326
|
-
<Alert variant="destructive">
|
|
327
|
-
<AlertDescription>{removalError.message}</AlertDescription>
|
|
328
|
-
</Alert>
|
|
329
|
-
)}
|
|
330
|
-
<AlertDialogFooter>
|
|
331
|
-
<AlertDialogCancel disabled={removing}>Cancel</AlertDialogCancel>
|
|
332
|
-
<AlertDialogAction
|
|
333
|
-
variant="destructive"
|
|
334
|
-
disabled={removing}
|
|
335
|
-
onClick={() => void confirmRemoval()}
|
|
336
|
-
>
|
|
337
|
-
{removing
|
|
338
|
-
? 'Saving…'
|
|
339
|
-
: removal?.type === 'member'
|
|
340
|
-
? 'Remove member'
|
|
341
|
-
: 'Revoke invitation'}
|
|
342
|
-
</AlertDialogAction>
|
|
343
|
-
</AlertDialogFooter>
|
|
344
|
-
</AlertDialogContent>
|
|
345
|
-
</AlertDialog>
|
|
346
|
-
</>
|
|
347
|
-
)
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
type MemberAvatarProps = { member: WorkspaceMember }
|
|
351
|
-
function MemberAvatar({ member }: MemberAvatarProps) {
|
|
352
|
-
return (
|
|
353
|
-
<UserAvatar
|
|
354
|
-
profile={normalizeUserProfile({
|
|
355
|
-
id: collabIdentityId(member),
|
|
356
|
-
name: member.name || undefined,
|
|
357
|
-
avatar: member.avatar,
|
|
358
|
-
email: member.type === 'user' ? member.email : undefined
|
|
359
|
-
})}
|
|
360
|
-
size="default"
|
|
361
|
-
/>
|
|
362
|
-
)
|
|
363
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import type { WorkspaceTabsState } from '@/lib/types'
|
|
4
|
-
import { normalizeWorkspaceTabs } from '@/lib/workspace-layout'
|
|
5
|
-
import { useCollabEnabled } from '@/client/features/collab'
|
|
6
|
-
import { useWorkspaceLayoutCtx } from './workspace-layout-context'
|
|
7
|
-
|
|
8
|
-
const keyFor = (workspaceId: string) => `moi:collab:${workspaceId}:tabs`
|
|
9
|
-
|
|
10
|
-
export function readWorkspaceTabs(
|
|
11
|
-
workspaceId: string,
|
|
12
|
-
defaults: WorkspaceTabsState
|
|
13
|
-
): WorkspaceTabsState {
|
|
14
|
-
try {
|
|
15
|
-
const saved = sessionStorage.getItem(keyFor(workspaceId))
|
|
16
|
-
return saved ? normalizeWorkspaceTabs(JSON.parse(saved)) : defaults
|
|
17
|
-
} catch {
|
|
18
|
-
return defaults
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function writeWorkspaceTabs(workspaceId: string, tabs: WorkspaceTabsState): void {
|
|
23
|
-
try {
|
|
24
|
-
sessionStorage.setItem(keyFor(workspaceId), JSON.stringify(tabs))
|
|
25
|
-
} catch {
|
|
26
|
-
// The hook retains its in-memory selection when browser storage is denied.
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function useWorkspaceTabs() {
|
|
31
|
-
const { workspaceId, layout, setLayout } = useWorkspaceLayoutCtx()
|
|
32
|
-
const enabled = useCollabEnabled()
|
|
33
|
-
const defaults = useMemo(() => normalizeWorkspaceTabs(layout.tabs), [layout.tabs])
|
|
34
|
-
const [local, setLocal] = useState<WorkspaceTabsState>(() =>
|
|
35
|
-
enabled ? readWorkspaceTabs(workspaceId, defaults) : defaults
|
|
36
|
-
)
|
|
37
|
-
const setTabs = useCallback(
|
|
38
|
-
(tabs: WorkspaceTabsState) => {
|
|
39
|
-
const next = normalizeWorkspaceTabs(tabs)
|
|
40
|
-
if (enabled) {
|
|
41
|
-
setLocal(next)
|
|
42
|
-
writeWorkspaceTabs(workspaceId, next)
|
|
43
|
-
} else {
|
|
44
|
-
setLayout({ tabs: next })
|
|
45
|
-
}
|
|
46
|
-
return next
|
|
47
|
-
},
|
|
48
|
-
[enabled, setLayout, workspaceId]
|
|
49
|
-
)
|
|
50
|
-
return [enabled ? local : defaults, setTabs] as const
|
|
51
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { WorkspaceLayout, WorkspaceLayoutSave } from '@/lib/types'
|
|
2
|
-
|
|
3
|
-
// Unrelated edits must omit tabs from the PUT. Keep the last explicit tab edit
|
|
4
|
-
// through the debounce window, even if a refetch replaces the optimistic cache.
|
|
5
|
-
export function accumulateLayoutSave(
|
|
6
|
-
next: WorkspaceLayout,
|
|
7
|
-
update: Partial<WorkspaceLayout>,
|
|
8
|
-
pending: WorkspaceLayoutSave | null
|
|
9
|
-
): WorkspaceLayoutSave {
|
|
10
|
-
const { tabs: _tabs, ...layout } = next
|
|
11
|
-
const tabs = update.tabs ?? pending?.tabs
|
|
12
|
-
return tabs === undefined ? layout : { ...layout, tabs }
|
|
13
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { cloudRequest } from '../account/api'
|
|
2
|
-
import { jsonRequest } from '@/client/api/http'
|
|
3
|
-
import { parseWorkspaceMembers, validWorkspaceId } from './types'
|
|
4
|
-
|
|
5
|
-
const workspaceMembersPath = (id: string) =>
|
|
6
|
-
`workspaces/${encodeURIComponent(validWorkspaceId(id))}`
|
|
7
|
-
export async function fetchWorkspaceMembers(id: string, signal?: AbortSignal) {
|
|
8
|
-
const response = await cloudRequest(`${workspaceMembersPath(id)}/members`, { signal })
|
|
9
|
-
return parseWorkspaceMembers(await response.json())
|
|
10
|
-
}
|
|
11
|
-
export const inviteWorkspaceMember = (id: string, email: string) =>
|
|
12
|
-
cloudRequest(`${workspaceMembersPath(id)}/invitations`, jsonRequest('POST', { email }))
|
|
13
|
-
export const removeWorkspaceMember = (id: string, membershipId: string) =>
|
|
14
|
-
cloudRequest(`${workspaceMembersPath(id)}/members/${encodeURIComponent(membershipId)}`, {
|
|
15
|
-
method: 'DELETE'
|
|
16
|
-
})
|
|
17
|
-
export const revokeWorkspaceInvitation = (id: string, invitationId: string) =>
|
|
18
|
-
cloudRequest(`${workspaceMembersPath(id)}/invitations/${encodeURIComponent(invitationId)}`, {
|
|
19
|
-
method: 'DELETE'
|
|
20
|
-
})
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { useMutation, useMutationState, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
-
import { getAccountGeneration } from '../identity/store'
|
|
3
|
-
import { useIdentity } from '../identity/use-identity'
|
|
4
|
-
import { ownerOnlyWorkspaceMembers } from './store'
|
|
5
|
-
import { memberKeys } from './keys'
|
|
6
|
-
import { identityKey } from '../identity/types'
|
|
7
|
-
import {
|
|
8
|
-
fetchWorkspaceMembers,
|
|
9
|
-
inviteWorkspaceMember,
|
|
10
|
-
removeWorkspaceMember,
|
|
11
|
-
revokeWorkspaceInvitation
|
|
12
|
-
} from './api'
|
|
13
|
-
import type { WorkspaceMembers } from './types'
|
|
14
|
-
|
|
15
|
-
export type MembershipAction =
|
|
16
|
-
| { type: 'invite'; email: string }
|
|
17
|
-
| { type: 'remove'; membershipId: string }
|
|
18
|
-
| { type: 'revoke'; invitationId: string }
|
|
19
|
-
|
|
20
|
-
type PendingAction = { id: number; action: MembershipAction }
|
|
21
|
-
export function applyPendingMembership(
|
|
22
|
-
data: WorkspaceMembers | undefined,
|
|
23
|
-
actions: PendingAction[]
|
|
24
|
-
) {
|
|
25
|
-
if (!data) return undefined
|
|
26
|
-
let { members, invitations } = data
|
|
27
|
-
for (const { id, action } of actions) {
|
|
28
|
-
if (action.type === 'remove')
|
|
29
|
-
members = members.filter(member => member.membershipId !== action.membershipId)
|
|
30
|
-
else if (action.type === 'revoke')
|
|
31
|
-
invitations = invitations.filter(invitation => invitation.id !== action.invitationId)
|
|
32
|
-
else if (!invitations.some(invitation => invitation.email === action.email))
|
|
33
|
-
invitations = [
|
|
34
|
-
...invitations,
|
|
35
|
-
{ id: `pending:${id}`, email: action.email, expiresAt: '', pending: true }
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
return { members, invitations }
|
|
39
|
-
}
|
|
40
|
-
export function useWorkspaceMembers(workspaceId: string | undefined) {
|
|
41
|
-
const identity = useIdentity()
|
|
42
|
-
const accountId = identity ? identityKey(identity) : undefined
|
|
43
|
-
const enabled = !!workspaceId && identity?.type === 'user' && !identity.isAnonymous
|
|
44
|
-
const accountGeneration = getAccountGeneration()
|
|
45
|
-
const mutationKey = ['workspace-members-action', accountGeneration, workspaceId]
|
|
46
|
-
const query = useQuery({
|
|
47
|
-
queryKey: memberKeys.workspace(accountId, workspaceId ?? ''),
|
|
48
|
-
initialData: ownerOnlyWorkspaceMembers,
|
|
49
|
-
queryFn: async ({ signal }) => {
|
|
50
|
-
const snapshot = await fetchWorkspaceMembers(workspaceId!, signal)
|
|
51
|
-
if (signal.aborted || accountGeneration !== getAccountGeneration())
|
|
52
|
-
throw new Error('Identity changed')
|
|
53
|
-
return snapshot
|
|
54
|
-
},
|
|
55
|
-
enabled,
|
|
56
|
-
retry: false,
|
|
57
|
-
staleTime: 30_000
|
|
58
|
-
})
|
|
59
|
-
const pending = useMutationState({
|
|
60
|
-
filters: { mutationKey, status: 'pending', exact: true },
|
|
61
|
-
select: mutation => ({
|
|
62
|
-
id: mutation.state.submittedAt,
|
|
63
|
-
action: mutation.state.variables as MembershipAction
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
const data = applyPendingMembership(query.data, pending)
|
|
67
|
-
return { ...query, data, members: data?.members, invitations: data?.invitations }
|
|
68
|
-
}
|
|
69
|
-
function useMembershipAction(workspaceId: string) {
|
|
70
|
-
const identity = useIdentity()
|
|
71
|
-
const accountId = identity ? identityKey(identity) : undefined
|
|
72
|
-
const accountGeneration = getAccountGeneration()
|
|
73
|
-
const client = useQueryClient()
|
|
74
|
-
return useMutation({
|
|
75
|
-
mutationKey: ['workspace-members-action', accountGeneration, workspaceId],
|
|
76
|
-
mutationFn: async (action: MembershipAction) => {
|
|
77
|
-
if (
|
|
78
|
-
!identity ||
|
|
79
|
-
identity.type !== 'user' ||
|
|
80
|
-
identity.isAnonymous ||
|
|
81
|
-
accountGeneration !== getAccountGeneration()
|
|
82
|
-
)
|
|
83
|
-
throw new Error('Sign in to manage workspace members')
|
|
84
|
-
if (action.type === 'invite') return inviteWorkspaceMember(workspaceId, action.email)
|
|
85
|
-
if (action.type === 'remove') return removeWorkspaceMember(workspaceId, action.membershipId)
|
|
86
|
-
return revokeWorkspaceInvitation(workspaceId, action.invitationId)
|
|
87
|
-
},
|
|
88
|
-
onSuccess: async () => {
|
|
89
|
-
if (accountGeneration !== getAccountGeneration()) return
|
|
90
|
-
// Keep the optimistic overlay until the canonical snapshot has caught up.
|
|
91
|
-
await client.invalidateQueries({
|
|
92
|
-
queryKey: memberKeys.workspace(accountId, workspaceId),
|
|
93
|
-
exact: true
|
|
94
|
-
})
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
}
|
|
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,6 +0,0 @@
|
|
|
1
|
-
export const memberKeys = {
|
|
2
|
-
all: ['workspace-members'] as const,
|
|
3
|
-
account: (accountId: string | undefined) => [...memberKeys.all, accountId ?? 'unknown'] as const,
|
|
4
|
-
workspace: (accountId: string | undefined, workspaceId: string) =>
|
|
5
|
-
[...memberKeys.account(accountId), workspaceId] as const
|
|
6
|
-
}
|