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
@@ -0,0 +1,101 @@
1
+ import { useLocation } from 'wouter'
2
+ import { parseRemoteWorkspaceTarget, workspaceAddress } from '@/lib/workspace-config'
3
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
4
+ import { useAppConfig } from '@/client/api/app-config'
5
+ import { jsonRequest } from '@/client/api/http'
6
+ import { Button } from '@/client/components/ui/button'
7
+ import { cloudRequest } from '@/client/features/account/api'
8
+
9
+ type WorkspaceInvitation = {
10
+ id: string
11
+ workspaceName: string
12
+ inviter: { name: string }
13
+ }
14
+ const invitationsKey = ['workspace-invitations']
15
+
16
+ export function WorkspaceInvitations() {
17
+ const cloud = useAppConfig().environment === 'cloud'
18
+ const query = useQuery({
19
+ queryKey: invitationsKey,
20
+ enabled: cloud,
21
+ queryFn: async () =>
22
+ (await (await cloudRequest('/api/workspaces/invitations')).json()) as {
23
+ invitations: WorkspaceInvitation[]
24
+ },
25
+ staleTime: 60_000,
26
+ refetchOnWindowFocus: true,
27
+ retry: false
28
+ })
29
+ if (!cloud || query.data?.invitations.length === 0) return null
30
+ return (
31
+ <section className="mb-8">
32
+ <h2 className="mb-4 text-sm font-medium">Invitations</h2>
33
+ {query.isPending ? (
34
+ <p className="text-sm text-muted-foreground">Loading invitations…</p>
35
+ ) : query.isError ? (
36
+ <div role="alert">
37
+ <p className="text-sm text-muted-foreground">{query.error.message}</p>
38
+ <Button variant="ghost" onClick={() => void query.refetch()}>
39
+ Retry
40
+ </Button>
41
+ </div>
42
+ ) : (
43
+ <ul className="border-t border-border">
44
+ {query.data.invitations.map(invitation => (
45
+ <InvitationRow key={invitation.id} invitation={invitation} />
46
+ ))}
47
+ </ul>
48
+ )}
49
+ </section>
50
+ )
51
+ }
52
+
53
+ type InvitationRowProps = { invitation: WorkspaceInvitation }
54
+ function InvitationRow({ invitation }: InvitationRowProps) {
55
+ const client = useQueryClient()
56
+ const [, navigate] = useLocation()
57
+ const accept = useMutation({
58
+ mutationFn: async () => {
59
+ const response = await cloudRequest(
60
+ `/api/invitations/${encodeURIComponent(invitation.id)}/accept`,
61
+ jsonRequest('POST', {})
62
+ )
63
+ const { remote } = (await response.json()) as { remote: unknown }
64
+ return parseRemoteWorkspaceTarget(remote)
65
+ },
66
+ onSuccess: remote => {
67
+ void client.invalidateQueries({ queryKey: invitationsKey })
68
+ void client.invalidateQueries({ queryKey: ['shared-workspaces'] })
69
+ navigate(`/workspace/${workspaceAddress(remote.workspace_id, remote.user_id)}`)
70
+ }
71
+ })
72
+ return (
73
+ <li className="border-b border-border px-1 py-3">
74
+ <div className="flex items-center gap-2">
75
+ <div className="min-w-0 flex-1">
76
+ <p className="truncate text-sm font-medium">{invitation.workspaceName}</p>
77
+ <p className="text-xs text-muted-foreground">Invited by {invitation.inviter.name}</p>
78
+ </div>
79
+ <Button
80
+ variant="outline"
81
+ size="sm"
82
+ disabled={accept.isPending || accept.isSuccess}
83
+ onClick={() => accept.mutate()}
84
+ >
85
+ {accept.isPending
86
+ ? 'Accepting…'
87
+ : accept.isSuccess
88
+ ? 'Accepted'
89
+ : accept.isError
90
+ ? 'Try again'
91
+ : 'Accept'}
92
+ </Button>
93
+ </div>
94
+ {accept.isError && (
95
+ <p role="alert" className="mt-2 text-sm text-destructive">
96
+ {accept.error.message}
97
+ </p>
98
+ )}
99
+ </li>
100
+ )
101
+ }
@@ -5,16 +5,17 @@ import {
5
5
  removeWorkspaceMembers,
6
6
  clearWorkspaceMembers,
7
7
  getWorkspaceMembersRevision
8
- } from '../workspace-members/store'
8
+ } from '../collab/members/store'
9
9
  import type { Identity } from './types'
10
- import type { WorkspaceMembers, WorkspaceMembersSnapshot } from '../workspace-members/types'
10
+ import type { WorkspaceMembers, WorkspaceMembersSnapshot } from '../collab/members/types'
11
11
 
12
12
  export type IdentityHostApi = {
13
13
  identity: { set: (identity: Identity | null) => void; getRevision: () => number }
14
14
  workspaceMembers: {
15
- set: (workspaceId: string, data: WorkspaceMembers) => void
15
+ // Workspaces are named by address: `workspaceId`, or `ownerId:workspaceId` when shared.
16
+ set: (address: string, data: WorkspaceMembers) => void
16
17
  setAll: (workspaces: WorkspaceMembersSnapshot[]) => void
17
- remove: (workspaceId: string) => void
18
+ remove: (address: string) => void
18
19
  clear: () => void
19
20
  getRevision: () => number
20
21
  }
@@ -1,5 +1,3 @@
1
- import { queryClient } from '@/client/api/query-client'
2
- import { memberKeys } from '../workspace-members/keys'
3
1
  import { identityKey, parseIdentity } from './types'
4
2
  import type { Identity } from './types'
5
3
 
@@ -21,11 +19,7 @@ export function subscribeIdentity(listener: () => void) {
21
19
  export function setIdentity(value: Identity | null): void {
22
20
  const next = value === null ? null : parseIdentity(value)
23
21
  const changedAccount = (current && identityKey(current)) !== (next && identityKey(next))
24
- if (changedAccount) {
25
- accountGeneration++
26
- void queryClient.cancelQueries({ queryKey: memberKeys.all })
27
- queryClient.removeQueries({ queryKey: memberKeys.all })
28
- }
22
+ if (changedAccount) accountGeneration++
29
23
  identityRevision++
30
24
  current = next
31
25
  listeners.forEach(listener => listener())
@@ -15,7 +15,7 @@ export function AgentSetupStep({ onComplete }: AgentSetupStepProps) {
15
15
  if (harness) onComplete(harness)
16
16
  }, [harness, onComplete])
17
17
  if (!harness) return <ChooseAgent onSelect={setHarness} />
18
- return <HarnessLoginPanel type={harness} onConnected={onConnected} />
18
+ return <HarnessLoginPanel harness={harness} onConnected={onConnected} />
19
19
  }
20
20
 
21
21
  type ChooseAgentProps = { onSelect: (harness: OnboardingHarness) => void }
@@ -26,12 +26,12 @@ function ChooseAgent({ onSelect }: ChooseAgentProps) {
26
26
  const retry = useRetryHarnessStatus()
27
27
  if (installed.isPending || installed.error)
28
28
  return <OnboardingStatus error={installed.error ?? undefined} onRetry={() => retry.mutate()} />
29
- const options = (['claude-code', 'codex'] as const).map(type => ({
30
- type,
31
- description: harnessDescription[type],
32
- disabled: !canInstall && installed.data[type].availability.status === 'unavailable',
29
+ const options = (['claude-code', 'codex'] as const).map(harness => ({
30
+ harness,
31
+ description: harnessDescription[harness],
32
+ disabled: !canInstall && installed.data[harness].availability.status === 'unavailable',
33
33
  disabledReason:
34
- canInstall || installed.data[type].availability.status !== 'unavailable'
34
+ canInstall || installed.data[harness].availability.status !== 'unavailable'
35
35
  ? undefined
36
36
  : 'This agent is not installed on your computer'
37
37
  }))
@@ -48,8 +48,8 @@ function ChooseAgent({ onSelect }: ChooseAgentProps) {
48
48
  mode="action"
49
49
  cardClassName="h-36"
50
50
  disabled={false}
51
- onTypeChange={type => {
52
- if (type === 'claude-code' || type === 'codex') onSelect(type)
51
+ onHarnessChange={harness => {
52
+ if (harness === 'claude-code' || harness === 'codex') onSelect(harness)
53
53
  }}
54
54
  />
55
55
  </OnboardingScreen>
@@ -1,5 +1,6 @@
1
1
  import { useState } from 'react'
2
2
  import { Redirect } from 'wouter'
3
+ import { homePath } from '@/client/api/app-config'
3
4
  import { useSaveAppSettings } from '@/client/features/app-settings/api'
4
5
  import type { OnboardingHarness } from '@/lib/onboarding'
5
6
  import { useOnboardingSettings } from './api'
@@ -10,14 +11,14 @@ import { WorkspaceSetupStep } from './workspace-setup-step'
10
11
  export function OnboardingPage() {
11
12
  const onboarding = useOnboardingSettings()
12
13
  const save = useSaveAppSettings()
13
- const [destination, setDestination] = useState('/')
14
+ const [destination, setDestination] = useState(homePath)
14
15
  const [harness, setHarness] = useState<OnboardingHarness>()
15
16
  if (onboarding.loading || onboarding.error)
16
17
  return <OnboardingStatus error={onboarding.error || undefined} onRetry={onboarding.retry} />
17
18
  if (!onboarding.enabled || !onboarding.data?.showOnboarding) return <Redirect to={destination} />
18
19
 
19
20
  function finish(workspaceId?: string) {
20
- setDestination(workspaceId ? `/workspace/${workspaceId}/overview` : '/')
21
+ setDestination(workspaceId ? `/workspace/${workspaceId}/overview` : homePath())
21
22
  save.mutate({ showOnboarding: false })
22
23
  }
23
24
  if (!harness) return <AgentSetupStep onComplete={setHarness} />
@@ -57,7 +57,7 @@ export function WorkspaceSetupStep({
57
57
  }
58
58
  const workspaces = await requestJson<WorkspaceEntry[]>('/api/workspaces')
59
59
  if (workspaces.length > 0) return
60
- const entry = await createWorkspace.mutateAsync({ type: harness })
60
+ const entry = await createWorkspace.mutateAsync({ harness: harness })
61
61
  return entry.id
62
62
  },
63
63
  onSuccess: id => onFinish(id)
@@ -11,13 +11,11 @@ import { withDefaultWidgets } from '@/lib/default-widgets'
11
11
  import type { WidgetInfo } from '@/lib/types'
12
12
 
13
13
  export function useWidgets(workspaceId: string) {
14
- const { layout, setLayout } = useWorkspaceLayoutCtx()
14
+ const { layout, setLayout, apiBase } = useWorkspaceLayoutCtx()
15
15
  const query = useQuery<WidgetInfo[]>({
16
16
  queryKey: workspaceKeys.widgets(workspaceId),
17
17
  queryFn: async () => {
18
- const data = await requestJson<{ widgets: WidgetInfo[] }>(
19
- `/api/workspaces/${workspaceId}/widgets`
20
- )
18
+ const data = await requestJson<{ widgets: WidgetInfo[] }>(`${apiBase}/widgets`)
21
19
  return data.widgets
22
20
  },
23
21
  ...WORKSPACE_RESOURCE_OPTIONS
@@ -26,5 +24,5 @@ export function useWidgets(workspaceId: string) {
26
24
 
27
25
  useGridReconcile(workspaceId, query.data ? widgets : undefined, layout, setLayout)
28
26
 
29
- return { ...query, data: widgets }
27
+ return { ...query, data: widgets, hasData: query.data !== undefined }
30
28
  }
@@ -8,7 +8,7 @@ import { ViewsWidget } from './views-widget'
8
8
  export type DefaultWidgetRenderContext = {
9
9
  views: ViewInfo[]
10
10
  onOpenView: (viewId: string) => void
11
- onCreateView: () => void
11
+ onCreateView?: () => void
12
12
  showOnboarding: boolean
13
13
  }
14
14
 
@@ -208,7 +208,7 @@ function ViewItem({ view, Icon, onOpen }: ViewItemProps) {
208
208
  type ViewsWidgetProps = {
209
209
  views: ViewInfo[]
210
210
  onOpenView: (viewId: string) => void
211
- onCreateView: () => void
211
+ onCreateView?: () => void
212
212
  showOnboarding: boolean
213
213
  }
214
214
 
@@ -234,7 +234,7 @@ export function ViewsWidget({ views, onOpenView, onCreateView, showOnboarding }:
234
234
  onOpen={() => onOpenView(view.id)}
235
235
  />
236
236
  ))}
237
- <NewViewButton outlined={empty} onClick={onCreateView} />
237
+ {onCreateView && <NewViewButton outlined={empty} onClick={onCreateView} />}
238
238
  </div>
239
239
  {empty && showOnboarding && (
240
240
  <p className="relative mr-8 ml-auto max-w-56 text-right text-sm text-muted-foreground">
@@ -46,7 +46,7 @@ const ROW_SPAN: Record<number, string> = {
46
46
  type HiddenPanelProps = {
47
47
  items: GridItem[]
48
48
  renderItem: (id: string) => ReactNode
49
- onCreateWidget: () => void
49
+ onCreateWidget?: () => void
50
50
  onClose: () => void
51
51
  onRestore: (id: string) => void
52
52
  ref?: Ref<HTMLDivElement>
@@ -67,10 +67,12 @@ export function HiddenPanel({
67
67
  ref={ref}
68
68
  title="Widgets"
69
69
  actions={
70
- <Button type="button" variant="secondary" size="sm" onClick={onCreateWidget}>
71
- <IconPlus data-icon="inline-start" stroke={1.75} />
72
- New widget
73
- </Button>
70
+ onCreateWidget && (
71
+ <Button type="button" variant="secondary" size="sm" onClick={onCreateWidget}>
72
+ <IconPlus data-icon="inline-start" stroke={1.75} />
73
+ New widget
74
+ </Button>
75
+ )
74
76
  }
75
77
  onClose={onClose}
76
78
  className="max-h-[60vh]"
@@ -32,7 +32,7 @@ import { WorkspaceName } from './workspace-name'
32
32
  import { WidgetCanvas } from './widget-canvas'
33
33
 
34
34
  type NoWidgetsCreatedProps = {
35
- onCreateWidget: () => void
35
+ onCreateWidget?: () => void
36
36
  showOnboarding: boolean
37
37
  }
38
38
 
@@ -53,18 +53,20 @@ function NoWidgetsCreated({ onCreateWidget, showOnboarding }: NoWidgetsCreatedPr
53
53
  </div>
54
54
  )}
55
55
  </div>
56
- <Button
57
- type="button"
58
- variant="outline"
59
- className={cn(
60
- 'absolute inset-0 m-auto h-fit w-fit',
61
- 'flex-col gap-1 rounded-2xl border-0 py-4 pr-8 pl-8! text-xs shadow-sm transition-shadow duration-300 ease-out squircle hover:bg-background hover:shadow-lg [&_svg]:size-8'
62
- )}
63
- onClick={onCreateWidget}
64
- >
65
- <IconPlus data-icon="inline-start" stroke={1.5} />
66
- New widget
67
- </Button>
56
+ {onCreateWidget && (
57
+ <Button
58
+ type="button"
59
+ variant="outline"
60
+ className={cn(
61
+ 'absolute inset-0 m-auto h-fit w-fit',
62
+ 'flex-col gap-1 rounded-2xl border-0 py-4 pr-8 pl-8! text-xs shadow-sm transition-shadow duration-300 ease-out squircle hover:bg-background hover:shadow-lg [&_svg]:size-8'
63
+ )}
64
+ onClick={onCreateWidget}
65
+ >
66
+ <IconPlus data-icon="inline-start" stroke={1.5} />
67
+ New widget
68
+ </Button>
69
+ )}
68
70
  </div>
69
71
  )
70
72
  }
@@ -166,8 +168,8 @@ function usePanelHeight() {
166
168
  }
167
169
 
168
170
  type OverviewProps = {
169
- onCreateWidget: () => void
170
- onCreateView: () => void
171
+ onCreateWidget?: () => void
172
+ onCreateView?: () => void
171
173
  onOpenView: (viewId: string) => void
172
174
  customizing: boolean
173
175
  theming: boolean
@@ -231,7 +233,7 @@ export function Overview({
231
233
  showOnboarding
232
234
  })
233
235
  if (defaultWidget) return defaultWidget
234
- return <WidgetShell name={id} />
236
+ return <WidgetShell name={id} revision={widgetById.get(id)?.revision} />
235
237
  }
236
238
 
237
239
  function hide(id: string) {
@@ -7,7 +7,7 @@ import { WorkspaceIconPicker } from '@/client/features/workspace/settings/worksp
7
7
  import { useWorkspaceLayoutCtx } from '@/client/features/workspace/workspace-layout-context'
8
8
 
9
9
  export function WorkspaceName() {
10
- const { layout, name, provider, workspaceId } = useWorkspaceLayoutCtx()
10
+ const { layout, name, harness, workspaceId } = useWorkspaceLayoutCtx()
11
11
  const workspaceName = name ?? 'Workspace'
12
12
  const saveName = useSaveWorkspaceName(workspaceId)
13
13
  const [nameDraft, setNameDraft] = useState(workspaceName)
@@ -24,7 +24,7 @@ export function WorkspaceName() {
24
24
  <WorkspaceIdentity
25
25
  name={nameDraft}
26
26
  icon={layout.icon}
27
- workspaceType={provider}
27
+ harness={harness}
28
28
  workspaceTheme={layout.theme}
29
29
  onNameChange={setNameDraft}
30
30
  onNameCommit={commitName}
@@ -1,3 +1,4 @@
1
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/workspace-layout-context'
1
2
  import { useCallback, useRef, useState } from 'react'
2
3
 
3
4
  import {
@@ -71,8 +72,8 @@ function makeExecutor(editor: Editor) {
71
72
  // the record; `resolve` maps it back to the serving URL at render time. Legacy
72
73
  // snapshots still holding data URLs pass through `resolve` untouched (the
73
74
  // server extracts them to files on the next save). See server/scratchpad/assets.ts.
74
- function makeAssetStore(workspaceId: string): TLAssetStore {
75
- const base = `/api/workspaces/${workspaceId}/scratchpad/assets`
75
+ function makeAssetStore(apiBase: string): TLAssetStore {
76
+ const base = `${apiBase}/scratchpad/assets`
76
77
  return {
77
78
  async upload(_asset, file) {
78
79
  const res = await fetch(base, {
@@ -188,6 +189,7 @@ export function Scratchpad() {
188
189
  }
189
190
 
190
191
  function WorkspaceScratchpad({ workspaceId }: { workspaceId: string }) {
192
+ const { apiBase } = useWorkspaceLayoutCtx()
191
193
  const editorRef = useRef<Editor | null>(null)
192
194
  // The whole scratchpad region (canvas + tool bar + style bar). Focus is driven
193
195
  // off whether a pointerdown lands inside this, so clicking a tool keeps the
@@ -201,10 +203,10 @@ function WorkspaceScratchpad({ workspaceId }: { workspaceId: string }) {
201
203
  const applyingRemote = useRef(false)
202
204
  // Reactive handle to the mounted editor, used to render the custom tool bar.
203
205
  const [editor, setEditor] = useState<Editor | null>(null)
204
- const { loaded, snapshot, skew, flagSkew } = useScratchpadSnapshot(workspaceId)
206
+ const { loaded, snapshot, skew, flagSkew } = useScratchpadSnapshot()
205
207
  // This keyed component gives each workspace one stable asset store. A fresh
206
208
  // identity makes <Tldraw> remount the editor and drop unsaved edits.
207
- const [assetStore] = useState<TLAssetStore>(() => makeAssetStore(workspaceId))
209
+ const [assetStore] = useState<TLAssetStore>(() => makeAssetStore(apiBase))
208
210
 
209
211
  const save = useCallback(() => {
210
212
  const editor = editorRef.current
@@ -215,12 +217,12 @@ function WorkspaceScratchpad({ workspaceId }: { workspaceId: string }) {
215
217
  } catch {
216
218
  return
217
219
  }
218
- void fetch(`/api/workspaces/${workspaceId}/scratchpad`, {
220
+ void fetch(`${apiBase}/scratchpad`, {
219
221
  method: 'PUT',
220
222
  headers: { 'Content-Type': 'application/json' },
221
223
  body: JSON.stringify({ document, origin: BROWSER_TAB_ID })
222
224
  }).catch(() => {})
223
- }, [workspaceId])
225
+ }, [apiBase])
224
226
 
225
227
  // A remote save (another tab, or an agent draw landing in another tab) — pull
226
228
  // the new snapshot and load it into the live store. Skip our own echo. The
@@ -232,7 +234,7 @@ function WorkspaceScratchpad({ workspaceId }: { workspaceId: string }) {
232
234
  if (e.type !== 'scratchpad:updated' || e.workspaceId !== workspaceId) return
233
235
  if (e.origin && e.origin === BROWSER_TAB_ID) return
234
236
  if (!editorRef.current) return
235
- fetch(`/api/workspaces/${workspaceId}/scratchpad`)
237
+ fetch(`${apiBase}/scratchpad`)
236
238
  .then(r => r.json())
237
239
  .then((d: ScratchpadFetch) => {
238
240
  const editor = editorRef.current
@@ -1,3 +1,5 @@
1
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/workspace-layout-context'
2
+ import { requestJson } from '@/client/api/http'
1
3
  import { useCallback, useEffect, useState } from 'react'
2
4
 
3
5
  import { IconVersions } from '@tabler/icons-react'
@@ -53,18 +55,18 @@ export function detectScratchpadSkew(
53
55
  return { newer: false, writer, detail: 'The saved snapshot failed to load.' }
54
56
  }
55
57
 
56
- export function useScratchpadSnapshot(workspaceId: string): {
58
+ export function useScratchpadSnapshot(): {
57
59
  loaded: boolean
58
60
  snapshot: TLEditorSnapshot['document'] | undefined
59
61
  skew: ScratchpadSkew | null
60
62
  flagSkew: (skew: ScratchpadSkew) => void
61
63
  } {
64
+ const { apiBase } = useWorkspaceLayoutCtx()
62
65
  const [result, setResult] = useState<SnapshotResult | null>(null)
63
66
 
64
67
  useEffect(() => {
65
68
  let cancelled = false
66
- fetch(`/api/workspaces/${workspaceId}/scratchpad`)
67
- .then(response => response.json())
69
+ requestJson<ScratchpadFetch>(`${apiBase}/scratchpad`)
68
70
  .then((data: ScratchpadFetch) => {
69
71
  if (cancelled) return
70
72
  let snapshot: TLEditorSnapshot['document'] | undefined
@@ -76,12 +78,18 @@ export function useScratchpadSnapshot(workspaceId: string): {
76
78
  setResult({ snapshot, skew })
77
79
  })
78
80
  .catch(() => {
79
- if (!cancelled) setResult({ skew: null })
81
+ if (!cancelled)
82
+ setResult({
83
+ skew: {
84
+ newer: false,
85
+ detail: 'Couldn’t load the canvas. Reopen Scratchpad to try again.'
86
+ }
87
+ })
80
88
  })
81
89
  return () => {
82
90
  cancelled = true
83
91
  }
84
- }, [workspaceId])
92
+ }, [apiBase])
85
93
 
86
94
  const flagSkew = useCallback((skew: ScratchpadSkew) => {
87
95
  setResult(previous => ({ snapshot: previous?.snapshot, skew }))
@@ -1,9 +1,9 @@
1
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/workspace-layout-context'
1
2
  import type { SpeedMode } from '@/lib/types'
2
3
  import type {
3
4
  CompiledView,
4
5
  MessageAttachment,
5
6
  PendingView,
6
- SelectedSessionScope,
7
7
  ViewInfo,
8
8
  WorkspaceState
9
9
  } from '@/lib/types'
@@ -19,11 +19,10 @@ import { useWorkspaceEvent } from '@/client/runtime/use-workspace-events'
19
19
 
20
20
  // Compiled views from `.moi/views/`. Build and layout events refetch the list;
21
21
  // mounts within 30 s reuse it.
22
- export function compiledViewsOptions(workspaceId: string) {
22
+ export function compiledViewsOptions(workspaceId: string, apiBase: string) {
23
23
  return {
24
24
  queryKey: workspaceKeys.views(workspaceId),
25
- queryFn: async () =>
26
- (await requestJson<{ views: CompiledView[] }>(`/api/workspaces/${workspaceId}/views`)).views,
25
+ queryFn: async () => (await requestJson<{ views: CompiledView[] }>(`${apiBase}/views`)).views,
27
26
  staleTime: 30_000,
28
27
  gcTime: 5 * 60_000,
29
28
  refetchOnMount: true,
@@ -58,6 +57,7 @@ export function getCachedViews(
58
57
  const selectPendingViews = (state: WorkspaceState) => state.pendingViews
59
58
 
60
59
  export function useViews(workspaceId: string) {
60
+ const { apiBase } = useWorkspaceLayoutCtx()
61
61
  const queryClient = useQueryClient()
62
62
  useWorkspaceEvent(event => {
63
63
  if (event.type === 'view-layout:updated' && event.workspaceId === workspaceId) {
@@ -72,10 +72,16 @@ export function useViews(workspaceId: string) {
72
72
  void queryClient.invalidateQueries({ queryKey: workspaceKeys.sessions(workspaceId) })
73
73
  }
74
74
  })
75
- const compiled = useQuery(compiledViewsOptions(workspaceId))
75
+ const compiled = useQuery(compiledViewsOptions(workspaceId, apiBase))
76
76
  const pending = useWorkspaceState(workspaceId, selectPendingViews)
77
77
  const data = useMemo(() => mergeViews(compiled.data, pending.data), [compiled.data, pending.data])
78
- return { data, isLoading: compiled.isLoading || pending.isLoading }
78
+ return {
79
+ data,
80
+ isLoading: compiled.isLoading || pending.isLoading,
81
+ isError: compiled.isError || pending.isError,
82
+ isFetching: compiled.isFetching || pending.isFetching,
83
+ refetch: () => Promise.all([compiled.refetch(), pending.refetch()])
84
+ }
79
85
  }
80
86
  function useViewMutation<T, Input>(workspaceId: string, mutationFn: (input: Input) => Promise<T>) {
81
87
  const queryClient = useQueryClient()
@@ -84,39 +90,51 @@ function useViewMutation<T, Input>(workspaceId: string, mutationFn: (input: Inpu
84
90
  onSuccess: () => queryClient.invalidateQueries({ queryKey: workspaceKeys.views(workspaceId) })
85
91
  })
86
92
  }
93
+ // A view still being built lives in this Moi's state, next to the chat building
94
+ // it. A compiled view lives with the workspace's owner.
95
+ function useViewBase(workspaceId: string) {
96
+ const { apiBase } = useWorkspaceLayoutCtx()
97
+ const queryClient = useQueryClient()
98
+ const local = `/api/workspaces/${workspaceId}`
99
+ return {
100
+ local,
101
+ forView: (viewId: string) =>
102
+ getCachedWorkspaceState(queryClient, workspaceId)?.pendingViews[viewId] ? local : apiBase
103
+ }
104
+ }
87
105
  export function useRenameView(workspaceId: string) {
106
+ const base = useViewBase(workspaceId)
88
107
  return useViewMutation(workspaceId, ({ viewId, title }: { viewId: string; title: string }) =>
89
108
  requestJson<ViewInfo>(
90
- `/api/workspaces/${workspaceId}/views/${encodeURIComponent(viewId)}`,
109
+ `${base.forView(viewId)}/views/${encodeURIComponent(viewId)}`,
91
110
  jsonRequest('PATCH', { title }),
92
111
  'Couldn’t rename view'
93
112
  )
94
113
  )
95
114
  }
96
115
  export function useDeleteView(workspaceId: string) {
116
+ const base = useViewBase(workspaceId)
97
117
  return useViewMutation(workspaceId, (viewId: string) =>
98
118
  requestVoid(
99
- `/api/workspaces/${workspaceId}/views/${encodeURIComponent(viewId)}`,
119
+ `${base.forView(viewId)}/views/${encodeURIComponent(viewId)}`,
100
120
  { method: 'DELETE' },
101
121
  'Couldn’t delete view'
102
122
  )
103
123
  )
104
124
  }
105
125
  export function useCreateView(workspaceId: string) {
126
+ const { local } = useViewBase(workspaceId)
106
127
  return useViewMutation(workspaceId, () =>
107
- requestJson<PendingView>(
108
- `/api/workspaces/${workspaceId}/views`,
109
- jsonRequest('POST'),
110
- 'Couldn’t create view'
111
- )
128
+ requestJson<PendingView>(`${local}/views`, jsonRequest('POST'), 'Couldn’t create view')
112
129
  )
113
130
  }
114
131
  export function useSaveViewDraft(workspaceId: string) {
132
+ const { local } = useViewBase(workspaceId)
115
133
  return useViewMutation(
116
134
  workspaceId,
117
135
  ({ viewId, requirements }: { viewId: string; requirements: string }) =>
118
136
  requestJson<PendingView>(
119
- `/api/workspaces/${workspaceId}/views/${viewId}`,
137
+ `${local}/views/${viewId}`,
120
138
  jsonRequest('PATCH', { requirements }),
121
139
  'Couldn’t save view requirements'
122
140
  )
@@ -127,7 +145,6 @@ export type SubmitViewInput = {
127
145
  requirements: string
128
146
  sessionId: string
129
147
  optimisticId: string
130
- selectedSessionScope?: SelectedSessionScope
131
148
  attachments?: MessageAttachment[]
132
149
  model?: string
133
150
  effort?: string
@@ -135,9 +152,10 @@ export type SubmitViewInput = {
135
152
  stream?: boolean
136
153
  }
137
154
  export function useSubmitView(workspaceId: string) {
155
+ const { local } = useViewBase(workspaceId)
138
156
  return useViewMutation(workspaceId, ({ viewId, ...input }: SubmitViewInput) =>
139
157
  requestJson<{ viewId: string; sessionId: string }>(
140
- `/api/workspaces/${workspaceId}/views/${viewId}/submit`,
158
+ `${local}/views/${viewId}/submit`,
141
159
  jsonRequest('POST', input),
142
160
  'Couldn’t start view chat'
143
161
  )