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

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 (205) hide show
  1. package/client/api/app-config.ts +12 -1
  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 +33 -6
  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 +15 -9
  10. package/client/features/account/api.ts +6 -6
  11. package/client/features/account/profile-actions.ts +5 -7
  12. package/client/features/app-settings/settings-page.tsx +2 -1
  13. package/client/features/applets/api.ts +6 -6
  14. package/client/features/applets/applet-cache.ts +6 -5
  15. package/client/features/applets/applet-log.ts +2 -1
  16. package/client/features/applets/applet-runtime.ts +2 -1
  17. package/client/features/applets/use-applet.ts +73 -18
  18. package/client/features/applets/widget-shell.tsx +4 -2
  19. package/client/features/chat/applet-chat-intents.ts +5 -13
  20. package/client/features/chat/chat-popup.tsx +8 -4
  21. package/client/features/chat/chat-send.ts +2 -2
  22. package/client/features/chat/composer/model-order.ts +4 -4
  23. package/client/features/chat/composer/model-picker.tsx +12 -10
  24. package/client/features/chat/composer/use-workspace-composer-state.tsx +1 -1
  25. package/client/features/chat/sessions/api.ts +11 -28
  26. package/client/features/chat/sessions/use-selected-session.ts +14 -109
  27. package/client/features/chat/use-chat.ts +8 -12
  28. package/client/features/collab/members/api.ts +4 -10
  29. package/client/features/collab/members/hooks.ts +32 -38
  30. package/client/features/collab/members/store.ts +96 -71
  31. package/client/features/collab/members/types.ts +5 -3
  32. package/client/features/collab/presence/client.ts +2 -3
  33. package/client/features/collab/presence/hooks.tsx +1 -1
  34. package/client/features/collab/proxy-user.ts +1 -3
  35. package/client/features/collab/sharing/workspace-members.tsx +0 -8
  36. package/client/features/dev/chat-states-page.tsx +3 -1
  37. package/client/features/dev/harness-debug-page.tsx +7 -7
  38. package/client/features/dev/workspace-setup-mocks.ts +1 -1
  39. package/client/features/dev/workspace-setup-preview.tsx +6 -4
  40. package/client/features/harness/api.ts +13 -10
  41. package/client/features/harness/harness-login-panel.tsx +9 -5
  42. package/client/features/harness/harness-presentation.ts +4 -4
  43. package/client/features/harness/harness-selector.tsx +13 -13
  44. package/client/features/harness/use-harness-login.ts +5 -5
  45. package/client/features/home/api.ts +38 -2
  46. package/client/features/home/home-page.tsx +43 -13
  47. package/client/features/home/shared-workspaces.tsx +70 -0
  48. package/client/features/home/workspace-invitations.tsx +101 -0
  49. package/client/features/identity/host-api.ts +3 -2
  50. package/client/features/identity/store.ts +1 -7
  51. package/client/features/onboarding/agent-setup-step.tsx +8 -8
  52. package/client/features/onboarding/onboarding-page.tsx +3 -2
  53. package/client/features/onboarding/workspace-setup-step.tsx +1 -1
  54. package/client/features/overview/api.ts +3 -5
  55. package/client/features/overview/default/registry.tsx +1 -1
  56. package/client/features/overview/default/views-widget.tsx +2 -2
  57. package/client/features/overview/hidden-panel.tsx +7 -5
  58. package/client/features/overview/overview.tsx +18 -16
  59. package/client/features/overview/workspace-name.tsx +2 -2
  60. package/client/features/scratchpad/scratchpad.tsx +9 -7
  61. package/client/features/scratchpad/use-scratchpad-snapshot.tsx +13 -5
  62. package/client/features/views/api.ts +66 -23
  63. package/client/features/views/use-view-actions.ts +10 -41
  64. package/client/features/views/view-manager.tsx +1 -1
  65. package/client/features/views/view-submission.ts +2 -21
  66. package/client/features/workspace/add/api.ts +5 -4
  67. package/client/features/workspace/add/create-workspace-dialog.tsx +12 -9
  68. package/client/features/workspace/add/import-workspace-dialog.tsx +7 -7
  69. package/client/features/workspace/add/use-workspace-import.ts +10 -10
  70. package/client/features/workspace/add/workspace-agent-options.ts +21 -20
  71. package/client/features/workspace/add/workspace-agent-selector.tsx +11 -11
  72. package/client/features/workspace/api.ts +60 -13
  73. package/client/features/workspace/harness-transition.ts +7 -13
  74. package/client/features/workspace/remote.ts +25 -0
  75. package/client/features/workspace/settings/api.ts +7 -12
  76. package/client/features/workspace/settings/connectors-settings.tsx +3 -3
  77. package/client/features/workspace/settings/general-settings.tsx +8 -8
  78. package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
  79. package/client/features/workspace/setup/workspace-recovery-states.tsx +43 -14
  80. package/client/features/workspace/setup/workspace-setup.tsx +6 -6
  81. package/client/features/workspace/tab-resolution.ts +1 -8
  82. package/client/features/workspace/use-workspace-navigation.ts +11 -7
  83. package/client/features/workspace/workspace-content.tsx +24 -31
  84. package/client/features/workspace/workspace-frame.tsx +13 -26
  85. package/client/features/workspace/workspace-layout-context.tsx +45 -12
  86. package/client/features/workspace/workspace-menu.tsx +2 -2
  87. package/client/features/workspace/workspace-pane.tsx +22 -0
  88. package/client/features/workspace/workspace-pending-screen.tsx +1 -1
  89. package/client/features/workspace/workspace-preferences.ts +91 -0
  90. package/client/features/workspace/workspace-presentation.tsx +12 -16
  91. package/client/features/workspace/workspace-screen.tsx +2 -2
  92. package/client/features/workspace/workspace-state.ts +42 -16
  93. package/client/features/workspace/workspace-tabs.tsx +1 -1
  94. package/client/features/workspace/workspace-test-utils.ts +23 -0
  95. package/client/runtime/use-workspace-events.ts +14 -0
  96. package/client/runtime/workspace-events.ts +9 -9
  97. package/client/store/ui.ts +24 -9
  98. package/client/store/workspace-session.ts +30 -0
  99. package/dist/chunk-0h4zypgf.js +1 -0
  100. package/dist/chunk-1tksq43z.js +72 -0
  101. package/dist/chunk-6gxf0xr8.js +5 -0
  102. package/dist/chunk-a865c7x4.js +1 -0
  103. package/dist/chunk-f44cs6mw.js +2 -0
  104. package/dist/chunk-h3qag4a6.js +2 -0
  105. package/dist/chunk-kffcah9w.css +1 -0
  106. package/dist/chunk-q2tpy0h7.js +2 -0
  107. package/dist/chunk-r95acex1.js +546 -0
  108. package/dist/chunk-w5h9grdr.js +1 -0
  109. package/dist/{chunk-th91xfnp.js → chunk-xj1pjhng.js} +1 -1
  110. package/dist/index.html +1 -1
  111. package/lib/harness-instructions.ts +4 -4
  112. package/lib/harness-types.ts +13 -0
  113. package/lib/moi-context.ts +19 -5
  114. package/lib/types.ts +38 -54
  115. package/lib/workspace-config.ts +48 -0
  116. package/lib/workspace-layout.ts +5 -24
  117. package/package.json +5 -2
  118. package/server/AGENTS.md +1 -1
  119. package/server/README.md +36 -31
  120. package/server/api/harnesses.ts +5 -5
  121. package/server/api/index.ts +268 -162
  122. package/server/applets/index.ts +15 -9
  123. package/server/applets/views.ts +2 -17
  124. package/server/applets/widgets.ts +3 -2
  125. package/server/cli/commands/config.ts +8 -20
  126. package/server/cli/commands/hermes.ts +2 -2
  127. package/server/cli/commands/init.ts +102 -54
  128. package/server/cli/commands/openclaw.ts +2 -2
  129. package/server/cli/commands/refresh.ts +10 -1
  130. package/server/cli/commands/remote.ts +330 -0
  131. package/server/cli/commands/skill.ts +4 -4
  132. package/server/cli/commands/tabs.ts +5 -12
  133. package/server/cli/control.ts +35 -4
  134. package/server/cli/index.ts +10 -6
  135. package/server/cli/remote-command.ts +77 -0
  136. package/server/cli/remote-control.ts +73 -0
  137. package/server/cli/remote-operations.ts +247 -0
  138. package/server/collab/config.ts +3 -3
  139. package/server/collab/skill/index.ts +3 -3
  140. package/server/control.ts +47 -12
  141. package/server/harness/acp/session.ts +4 -4
  142. package/server/harness/auth.ts +26 -31
  143. package/server/harness/claude-code/index.ts +1 -1
  144. package/server/harness/codex/discovery.ts +1 -1
  145. package/server/harness/codex/session.ts +1 -1
  146. package/server/harness/detect.ts +14 -19
  147. package/server/harness/executable.ts +10 -10
  148. package/server/harness/hermes/NOTES.md +2 -2
  149. package/server/harness/hermes/index.ts +1 -1
  150. package/server/harness/install.ts +11 -11
  151. package/server/harness/openclaw/index.ts +1 -1
  152. package/server/harness/registry.ts +7 -6
  153. package/server/harness/types.ts +4 -4
  154. package/server/onboarding/jobs.ts +2 -2
  155. package/server/operations/commands.ts +46 -0
  156. package/server/operations/files.ts +148 -0
  157. package/server/operations/server.ts +206 -0
  158. package/server/remote/agent.ts +103 -0
  159. package/server/remote/broker-client.ts +76 -0
  160. package/server/remote/broker.ts +81 -0
  161. package/server/remote/client.ts +725 -0
  162. package/server/remote/errors.ts +2 -0
  163. package/server/remote/routes.ts +121 -0
  164. package/server/remote/workspace.ts +34 -0
  165. package/server/scratchpad/document.ts +33 -12
  166. package/server/scratchpad/executor.ts +16 -7
  167. package/server/sessions/config.ts +8 -5
  168. package/server/sessions/pending-views.ts +17 -0
  169. package/server/sessions/send-message.ts +102 -0
  170. package/server/sessions/view-sessions.ts +9 -101
  171. package/server/skills/locations.ts +4 -4
  172. package/server/skills/update.ts +11 -11
  173. package/server/skills/version.ts +7 -7
  174. package/server/skills/workspace.ts +13 -11
  175. package/server/web.ts +13 -9
  176. package/server/workspace-state/file.ts +4 -0
  177. package/server/workspace-state/index.ts +0 -4
  178. package/server/workspaces/api.ts +24 -0
  179. package/server/workspaces/change-harness.ts +15 -26
  180. package/server/workspaces/import.ts +4 -4
  181. package/server/workspaces/init.ts +15 -13
  182. package/server/workspaces/layout.ts +60 -66
  183. package/server/workspaces/registry.ts +43 -18
  184. package/server/workspaces/shared.ts +74 -0
  185. package/server/workspaces/tabs.ts +5 -12
  186. package/skill/SKILL.md +80 -19
  187. package/skill/references/SCRATCHPAD.md +4 -0
  188. package/skill/references/UI-COMPONENTS.md +1 -1
  189. package/client/api/app-ui-keys.ts +0 -6
  190. package/client/features/chat/sessions/browser-tab-state.ts +0 -43
  191. package/client/features/collab/members/keys.ts +0 -6
  192. package/client/features/workspace/browser-tab-state.ts +0 -51
  193. package/client/features/workspace/layout-save.ts +0 -13
  194. package/dist/chunk-3smkkcfw.js +0 -546
  195. package/dist/chunk-47h9c2qy.js +0 -2
  196. package/dist/chunk-8qed2gqp.js +0 -75
  197. package/dist/chunk-8zy3vesm.js +0 -1
  198. package/dist/chunk-a47zy276.js +0 -2
  199. package/dist/chunk-g4c1nte9.css +0 -1
  200. package/dist/chunk-kcactdr4.js +0 -2
  201. package/dist/chunk-m8bhx6tw.js +0 -1
  202. package/dist/chunk-pf19zcrn.js +0 -2
  203. package/dist/chunk-ygzxah0e.js +0 -1
  204. package/lib/workspace-types.ts +0 -13
  205. package/server/workspace-state/legacy-migration.ts +0 -79
@@ -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
+ }
@@ -12,9 +12,10 @@ import type { WorkspaceMembers, WorkspaceMembersSnapshot } from '../collab/membe
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 '../collab/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,10 @@
1
+ import { viewTabId } from '@/lib/workspace-tabs'
2
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/workspace-layout-context'
1
3
  import type { SpeedMode } from '@/lib/types'
2
4
  import type {
3
5
  CompiledView,
4
6
  MessageAttachment,
5
7
  PendingView,
6
- SelectedSessionScope,
7
8
  ViewInfo,
8
9
  WorkspaceState
9
10
  } from '@/lib/types'
@@ -13,17 +14,17 @@ import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
13
14
  import { workspaceKeys } from '@/client/api/workspace-keys'
14
15
  import {
15
16
  getCachedWorkspaceState,
16
- useWorkspaceState
17
+ useWorkspaceState,
18
+ useWorkspaceStateWrite
17
19
  } from '@/client/features/workspace/workspace-state'
18
20
  import { useWorkspaceEvent } from '@/client/runtime/use-workspace-events'
19
21
 
20
22
  // Compiled views from `.moi/views/`. Build and layout events refetch the list;
21
23
  // mounts within 30 s reuse it.
22
- export function compiledViewsOptions(workspaceId: string) {
24
+ export function compiledViewsOptions(workspaceId: string, apiBase: string) {
23
25
  return {
24
26
  queryKey: workspaceKeys.views(workspaceId),
25
- queryFn: async () =>
26
- (await requestJson<{ views: CompiledView[] }>(`/api/workspaces/${workspaceId}/views`)).views,
27
+ queryFn: async () => (await requestJson<{ views: CompiledView[] }>(`${apiBase}/views`)).views,
27
28
  staleTime: 30_000,
28
29
  gcTime: 5 * 60_000,
29
30
  refetchOnMount: true,
@@ -58,6 +59,7 @@ export function getCachedViews(
58
59
  const selectPendingViews = (state: WorkspaceState) => state.pendingViews
59
60
 
60
61
  export function useViews(workspaceId: string) {
62
+ const { apiBase } = useWorkspaceLayoutCtx()
61
63
  const queryClient = useQueryClient()
62
64
  useWorkspaceEvent(event => {
63
65
  if (event.type === 'view-layout:updated' && event.workspaceId === workspaceId) {
@@ -72,10 +74,16 @@ export function useViews(workspaceId: string) {
72
74
  void queryClient.invalidateQueries({ queryKey: workspaceKeys.sessions(workspaceId) })
73
75
  }
74
76
  })
75
- const compiled = useQuery(compiledViewsOptions(workspaceId))
77
+ const compiled = useQuery(compiledViewsOptions(workspaceId, apiBase))
76
78
  const pending = useWorkspaceState(workspaceId, selectPendingViews)
77
79
  const data = useMemo(() => mergeViews(compiled.data, pending.data), [compiled.data, pending.data])
78
- return { data, isLoading: compiled.isLoading || pending.isLoading }
80
+ return {
81
+ data,
82
+ isLoading: compiled.isLoading || pending.isLoading,
83
+ isError: compiled.isError || pending.isError,
84
+ isFetching: compiled.isFetching || pending.isFetching,
85
+ refetch: () => Promise.all([compiled.refetch(), pending.refetch()])
86
+ }
79
87
  }
80
88
  function useViewMutation<T, Input>(workspaceId: string, mutationFn: (input: Input) => Promise<T>) {
81
89
  const queryClient = useQueryClient()
@@ -84,39 +92,51 @@ function useViewMutation<T, Input>(workspaceId: string, mutationFn: (input: Inpu
84
92
  onSuccess: () => queryClient.invalidateQueries({ queryKey: workspaceKeys.views(workspaceId) })
85
93
  })
86
94
  }
95
+ // A view still being built lives in this Moi's state, next to the chat building
96
+ // it. A compiled view lives with the workspace's owner.
97
+ function useViewBase(workspaceId: string) {
98
+ const { apiBase } = useWorkspaceLayoutCtx()
99
+ const queryClient = useQueryClient()
100
+ const local = `/api/workspaces/${workspaceId}`
101
+ return {
102
+ local,
103
+ forView: (viewId: string) =>
104
+ getCachedWorkspaceState(queryClient, workspaceId)?.pendingViews[viewId] ? local : apiBase
105
+ }
106
+ }
87
107
  export function useRenameView(workspaceId: string) {
108
+ const base = useViewBase(workspaceId)
88
109
  return useViewMutation(workspaceId, ({ viewId, title }: { viewId: string; title: string }) =>
89
110
  requestJson<ViewInfo>(
90
- `/api/workspaces/${workspaceId}/views/${encodeURIComponent(viewId)}`,
111
+ `${base.forView(viewId)}/views/${encodeURIComponent(viewId)}`,
91
112
  jsonRequest('PATCH', { title }),
92
113
  'Couldn’t rename view'
93
114
  )
94
115
  )
95
116
  }
96
117
  export function useDeleteView(workspaceId: string) {
118
+ const base = useViewBase(workspaceId)
97
119
  return useViewMutation(workspaceId, (viewId: string) =>
98
120
  requestVoid(
99
- `/api/workspaces/${workspaceId}/views/${encodeURIComponent(viewId)}`,
121
+ `${base.forView(viewId)}/views/${encodeURIComponent(viewId)}`,
100
122
  { method: 'DELETE' },
101
123
  'Couldn’t delete view'
102
124
  )
103
125
  )
104
126
  }
105
127
  export function useCreateView(workspaceId: string) {
128
+ const { local } = useViewBase(workspaceId)
106
129
  return useViewMutation(workspaceId, () =>
107
- requestJson<PendingView>(
108
- `/api/workspaces/${workspaceId}/views`,
109
- jsonRequest('POST'),
110
- 'Couldn’t create view'
111
- )
130
+ requestJson<PendingView>(`${local}/views`, jsonRequest('POST'), 'Couldn’t create view')
112
131
  )
113
132
  }
114
133
  export function useSaveViewDraft(workspaceId: string) {
134
+ const { local } = useViewBase(workspaceId)
115
135
  return useViewMutation(
116
136
  workspaceId,
117
137
  ({ viewId, requirements }: { viewId: string; requirements: string }) =>
118
138
  requestJson<PendingView>(
119
- `/api/workspaces/${workspaceId}/views/${viewId}`,
139
+ `${local}/views/${viewId}`,
120
140
  jsonRequest('PATCH', { requirements }),
121
141
  'Couldn’t save view requirements'
122
142
  )
@@ -127,7 +147,6 @@ export type SubmitViewInput = {
127
147
  requirements: string
128
148
  sessionId: string
129
149
  optimisticId: string
130
- selectedSessionScope?: SelectedSessionScope
131
150
  attachments?: MessageAttachment[]
132
151
  model?: string
133
152
  effort?: string
@@ -135,12 +154,36 @@ export type SubmitViewInput = {
135
154
  stream?: boolean
136
155
  }
137
156
  export function useSubmitView(workspaceId: string) {
138
- return useViewMutation(workspaceId, ({ viewId, ...input }: SubmitViewInput) =>
139
- requestJson<{ viewId: string; sessionId: string }>(
140
- `/api/workspaces/${workspaceId}/views/${viewId}/submit`,
141
- jsonRequest('POST', input),
142
- 'Couldn’t start view chat'
143
- )
144
- )
157
+ const { local } = useViewBase(workspaceId)
158
+ return useWorkspaceStateWrite<
159
+ SubmitViewInput,
160
+ {
161
+ viewId: string
162
+ sessionId: string
163
+ state: WorkspaceState
164
+ }
165
+ >(workspaceId, {
166
+ request: ({ viewId, ...input }) =>
167
+ requestJson(
168
+ `${local}/views/${viewId}/submit`,
169
+ jsonRequest('POST', input),
170
+ 'Couldn’t start view chat'
171
+ ),
172
+ optimistic: (draft, { viewId, sessionId, requirements }) => {
173
+ const tabId = viewTabId(viewId)
174
+ if (!draft.pinnedSessionId) {
175
+ draft.selected[tabId] = sessionId
176
+ draft.sessions[sessionId] = { ...draft.sessions[sessionId], tabId }
177
+ }
178
+ const view = draft.pendingViews[viewId]
179
+ if (view?.status === 'draft')
180
+ Object.assign(view, {
181
+ status: 'starting',
182
+ requirements,
183
+ buildSessionId: draft.pinnedSessionId ?? sessionId
184
+ })
185
+ },
186
+ errorTitle: 'Couldn’t start view chat'
187
+ })
145
188
  }
146
189
  export const useDiscardView = useDeleteView