moi-computer 0.12.1-next.1 → 0.12.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/AGENTS.md +3 -2
- package/client/api/app-config.ts +3 -9
- package/client/api/workspace-keys.ts +2 -1
- package/client/app/app-provider.tsx +25 -0
- package/client/app/routes/workspace-route.tsx +4 -0
- package/client/app/shell/sidebar-layout.tsx +19 -13
- package/client/dev/index.html +5 -5
- package/client/features/applets/api.ts +1 -1
- package/client/features/chat/connection/chat-frames.ts +2 -2
- package/client/features/chat/sessions/api.ts +1 -1
- package/client/features/chat/use-chat.ts +1 -1
- package/client/features/collab/host-state.ts +24 -7
- package/client/features/collab/local-user.ts +1 -1
- package/client/features/collab/proxy-user.ts +4 -9
- package/client/features/demo/demo-dialog.tsx +25 -79
- package/client/features/dev/workspace-setup-preview.tsx +43 -16
- package/client/features/harness/device-login-steps.tsx +2 -2
- package/client/features/home/api.ts +29 -9
- package/client/features/home/home-page.tsx +7 -4
- package/client/features/scratchpad/scratchpad.tsx +3 -6
- package/client/features/settings/api.ts +14 -8
- package/client/features/workspace/api.ts +12 -16
- package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
- package/client/features/workspace/setup/workspace-setup.tsx +2 -1
- package/client/features/workspace/workspace-content.tsx +12 -52
- package/client/features/workspace/workspace-frame.tsx +76 -0
- package/client/features/workspace/workspace-layout-context.tsx +2 -0
- package/client/features/workspace/workspace-pending-screen.tsx +26 -0
- package/client/features/workspace/workspace-screen.tsx +3 -3
- package/client/index.html +28 -9
- package/client/index.tsx +7 -2
- package/client/lib/browser-tab-id.ts +4 -0
- package/client/main.tsx +9 -6
- package/client/runtime/app-context.ts +20 -0
- package/client/runtime/use-workspace-events.ts +29 -153
- package/client/runtime/workspace-events.ts +151 -0
- package/dist/chunk-00rh9df4.js +2 -0
- package/dist/chunk-4nh7y1hq.css +1 -0
- package/dist/{chunk-jvyvwwv3.js → chunk-am4agx6v.js} +1 -1
- package/dist/chunk-hbpdv7vd.js +1 -0
- package/dist/chunk-hmka9rt5.js +2 -0
- package/dist/chunk-mjjregkn.js +10 -0
- package/dist/chunk-vt6zybej.js +2 -0
- package/dist/chunk-wbkwf6cc.js +68 -0
- package/dist/chunk-xjyfyz64.js +1 -0
- package/dist/{chunk-q0gbdts4.js → chunk-y8nbwp21.js} +71 -71
- package/dist/chunk-ysfdcew7.js +1 -0
- package/dist/index.html +29 -10
- package/lib/ids.ts +2 -2
- package/package.json +1 -1
- package/server/api/index.ts +41 -22
- package/server/applets/thumbnails.ts +8 -5
- package/server/harness/codex/thread-list.ts +4 -0
- package/server/static.ts +4 -2
- package/server/vendor.ts +23 -30
- package/server/web.ts +3 -2
- package/server/workspaces/layout.ts +11 -6
- package/dist/chunk-08ndj2rg.js +0 -2
- package/dist/chunk-2x040tmg.js +0 -68
- package/dist/chunk-3smxq0ts.js +0 -1
- package/dist/chunk-68ch5hs8.js +0 -2
- package/dist/chunk-9vg3xa81.js +0 -2
- package/dist/chunk-c2p00p9j.css +0 -1
- package/dist/chunk-cs833y9j.js +0 -1
- package/dist/chunk-nwevqe86.js +0 -10
- package/dist/chunk-y5y3kj67.js +0 -1
- /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-dom-client.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-dom.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-jsx-dev-runtime.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-jsx-runtime.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/_impl/react.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/react-dom-client.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/react-dom.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/react-jsx-dev-runtime.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/react-jsx-runtime.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/react.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-dom-client.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-dom.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-jsx-dev-runtime.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-jsx-runtime.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/_impl/react.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/react-dom-client.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/react-dom.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/react-jsx-dev-runtime.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/react-jsx-runtime.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/react.js +0 -0
package/client/AGENTS.md
CHANGED
|
@@ -19,9 +19,9 @@ Before editing host-app UI, read `../DESIGN.md` and the relevant rules in `../.a
|
|
|
19
19
|
|
|
20
20
|
## Vendored React
|
|
21
21
|
|
|
22
|
-
React is not bundled into the app. It ships as locally-vendored ESM in `vendor/react
|
|
22
|
+
React is not bundled into the app. It ships as locally-vendored ESM in `vendor/react/<version>/` (development and production builds, generated by `scripts/build-vendor.ts`) and is served at `/vendor/react/<version>/<mode>/*`, so Moi runs fully offline — no CDN fetch. The version and build mode in the URL are why the server serves these files as `immutable` in every mode, and why a prebuilt `moi` and `bun run dev` on one port cannot poison each other's cache; the shell (`index.html`) and hashed chunks carry their own cache headers, so nothing unhashed is ever given a `max-age`.
|
|
23
23
|
|
|
24
|
-
- An importmap in `index.html` maps `react`, `react-dom`, and the jsx runtimes to the `/vendor/react/*` URLs. A preload script in the same file imports them, stores the modules on `globalThis.__esm`, and only then calls `__init` to mount the app — this load order is load-bearing.
|
|
24
|
+
- An importmap in `index.html` maps `react`, `react-dom`, and the jsx runtimes to the `/vendor/react/<version>/development/*` URLs (`bun run vendor:react` rewrites the version on a bump; `scripts/build-client.ts` switches the mode to `production` in `dist/`). A preload script in the same file imports them, stores the modules on `globalThis.__esm`, and only then calls `__init` to mount the app — this load order is load-bearing.
|
|
25
25
|
- `externalize-react.ts` is a Bun bundler plugin that replaces those specifiers in bundled code with reads from `globalThis.__esm`. The point is ONE shared React instance across the host app and every applet/widget bundle (which resolve the same importmap); bundling React in would give each its own copy and break hooks.
|
|
26
26
|
- `structured-clone-shim.ts` must be the first import in `index.tsx`, before any tldraw module loads.
|
|
27
27
|
- HMR works across the bundle/vendor boundary; the `import.meta.hot.accept()` in `externalize-react.ts` is what stops every edit from escalating to a full page reload. See the comment in `index.tsx` before touching any of this.
|
|
@@ -34,6 +34,7 @@ React is not bundled into the app. It ships as locally-vendored ESM in `vendor/r
|
|
|
34
34
|
- `components/ui/` contains host facades for shared UI primitives. `components/shared/` contains reusable app components with no feature knowledge.
|
|
35
35
|
- `api/` contains shared request helpers, query keys, and query policies. Feature endpoints stay in the feature's `api.ts`.
|
|
36
36
|
- `runtime/` contains browser-wide lifecycle code such as HMR and shared workspace events.
|
|
37
|
+
- `app/app-provider.tsx` owns app-wide services that live exactly as long as the app, such as the workspace events socket; `runtime/app-context.ts` exposes them to hooks. Put state there when it must survive route switches. Hooks that read it do nothing outside the provider, so sandboxes and component tests open no connections.
|
|
37
38
|
- `lib/` contains small feature-neutral utilities. Do not use it as a catch-all for components or feature state.
|
|
38
39
|
- App code may compose features. Shared components and primitives must not import from `features/` or `app/`.
|
|
39
40
|
- Keep tests next to the code they cover. Extract a component, hook, or pure helper when a file starts mixing multiple responsibilities.
|
package/client/api/app-config.ts
CHANGED
|
@@ -3,15 +3,13 @@ import { useSyncExternalStore } from 'react'
|
|
|
3
3
|
import type { ClientAppConfig } from '@/lib/types'
|
|
4
4
|
import { EXPERIMENTAL_DEFAULTS } from '@/lib/experimental'
|
|
5
5
|
|
|
6
|
-
import { onWorkspaceEventsReconnect } from '@/client/runtime/use-workspace-events'
|
|
7
|
-
|
|
8
6
|
import { requestJson } from './http'
|
|
9
7
|
|
|
10
8
|
// Startup config (GET /api/config): frozen for the server process lifetime,
|
|
11
9
|
// so it is fetched once before the app mounts (see init() in index.tsx) and
|
|
12
10
|
// read synchronously everywhere after that — no query, no loading states.
|
|
13
|
-
//
|
|
14
|
-
//
|
|
11
|
+
// Only a server restart can change it, and a restart is picked up on the next
|
|
12
|
+
// page load.
|
|
15
13
|
|
|
16
14
|
const DEFAULTS: ClientAppConfig = {
|
|
17
15
|
environment: 'local',
|
|
@@ -43,11 +41,7 @@ async function fetchAppConfig(): Promise<ClientAppConfig | undefined> {
|
|
|
43
41
|
// Called once from init() before the app mounts; never rejects, so a config
|
|
44
42
|
// hiccup cannot block the app from starting.
|
|
45
43
|
export async function loadAppConfig(): Promise<ClientAppConfig | undefined> {
|
|
46
|
-
|
|
47
|
-
onWorkspaceEventsReconnect(() => {
|
|
48
|
-
void fetchAppConfig()
|
|
49
|
-
})
|
|
50
|
-
return config
|
|
44
|
+
return fetchAppConfig()
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
export function useAppConfig(): ClientAppConfig {
|
|
@@ -2,7 +2,8 @@ export const workspaceKeys = {
|
|
|
2
2
|
all: ['workspaces'] as const,
|
|
3
3
|
discover: ['workspaces', 'discover'] as const,
|
|
4
4
|
creationInfo: ['workspaces', 'creation-info'] as const,
|
|
5
|
-
|
|
5
|
+
// Every workspace's home-card preview, fetched in one batch.
|
|
6
|
+
previews: ['workspaces', 'previews'] as const,
|
|
6
7
|
layout: (id: string) => ['workspaces', 'layout', id] as const,
|
|
7
8
|
widgets: (id: string) => ['workspaces', 'widgets', id] as const,
|
|
8
9
|
appletThumbnails: (id: string) => ['workspaces', 'applet-thumbnails', id] as const,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ReactNode, useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { wsUrl } from '@/client/lib/ws-url'
|
|
4
|
+
import { AppContext, type AppContextValue } from '@/client/runtime/app-context'
|
|
5
|
+
import { WorkspaceEventsClient } from '@/client/runtime/workspace-events'
|
|
6
|
+
|
|
7
|
+
type AppProviderProps = {
|
|
8
|
+
children: ReactNode
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// App-wide services, mounted once at the root (main.tsx). Opens the workspace
|
|
12
|
+
// events socket when the app mounts and closes it when the app unmounts, so
|
|
13
|
+
// the connection outlives every route.
|
|
14
|
+
export function AppProvider({ children }: AppProviderProps) {
|
|
15
|
+
const [value] = useState<AppContextValue>(() => ({
|
|
16
|
+
events: new WorkspaceEventsClient(wsUrl('/api/workspaces/ws'))
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
value.events.connect()
|
|
21
|
+
return () => value.events.close()
|
|
22
|
+
}, [value])
|
|
23
|
+
|
|
24
|
+
return <AppContext value={value}>{children}</AppContext>
|
|
25
|
+
}
|
|
@@ -16,6 +16,7 @@ import { WorkspaceScreen } from '@/client/features/workspace/workspace-screen'
|
|
|
16
16
|
import { useViews } from '@/client/features/views/api'
|
|
17
17
|
import { useWidgets } from '@/client/features/overview/api'
|
|
18
18
|
import { useWorkspaceEvent } from '@/client/runtime/use-workspace-events'
|
|
19
|
+
import { BROWSER_TAB_ID } from '@/client/lib/browser-tab-id'
|
|
19
20
|
|
|
20
21
|
type WorkspaceRouteProps = {
|
|
21
22
|
id: string
|
|
@@ -49,6 +50,9 @@ function WorkspaceContent({ id }: WorkspaceRouteProps) {
|
|
|
49
50
|
|
|
50
51
|
useWorkspaceEvent(event => {
|
|
51
52
|
if (event.type === 'theme:updated' || event.type === 'workspace:updated') {
|
|
53
|
+
// Skip our own save: the cache already holds it, and the refetch could
|
|
54
|
+
// land an older value over a newer optimistic change.
|
|
55
|
+
if (event.origin === BROWSER_TAB_ID) return
|
|
52
56
|
queryClient.invalidateQueries({ queryKey: workspaceKeys.layout(id) })
|
|
53
57
|
} else if (event.type === 'widget-layout:updated' || event.type === 'widget:updated') {
|
|
54
58
|
// widget:updated too: a rebundle bumps the widget's content revision, and
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { type ReactNode } from 'react'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
IconAlertSquareRoundedFilled,
|
|
5
|
-
IconMessage2Share,
|
|
6
|
-
IconPlus,
|
|
7
|
-
IconSmartHome
|
|
8
|
-
} from '@tabler/icons-react'
|
|
3
|
+
import { IconMessage2Share, IconPlus, IconSandbox, IconSmartHome } from '@tabler/icons-react'
|
|
9
4
|
import { useQueryClient } from '@tanstack/react-query'
|
|
10
5
|
import { Link, useLocation } from 'wouter'
|
|
11
6
|
|
|
12
7
|
import { useAppConfig } from '@/client/api/app-config'
|
|
13
8
|
import { useReorderWorkspaces, useWorkspaces } from '@/client/features/home/api'
|
|
9
|
+
import { BROWSER_TAB_ID } from '@/client/lib/browser-tab-id'
|
|
14
10
|
import { UpdateButton, useUpdateControl } from '@/client/features/update/update-control'
|
|
15
11
|
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
16
12
|
import { useWorkspaceEvent } from '@/client/runtime/use-workspace-events'
|
|
@@ -63,6 +59,9 @@ export function SidebarLayout({ children, showWorkspaces = true }: SidebarLayout
|
|
|
63
59
|
e.type === 'theme:updated' ||
|
|
64
60
|
e.type === 'workspaces-list:updated'
|
|
65
61
|
) {
|
|
62
|
+
// Our own icon and order changes are already in the list cache. Own theme
|
|
63
|
+
// saves still refetch: only the layout cache holds those optimistically.
|
|
64
|
+
if (e.type !== 'theme:updated' && e.origin === BROWSER_TAB_ID) return
|
|
66
65
|
qc.invalidateQueries({ queryKey: workspaceKeys.all, exact: true })
|
|
67
66
|
}
|
|
68
67
|
})
|
|
@@ -152,13 +151,20 @@ function SidebarFooterAction() {
|
|
|
152
151
|
|
|
153
152
|
if (demo) {
|
|
154
153
|
return (
|
|
155
|
-
<
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
154
|
+
<Tooltip>
|
|
155
|
+
<DemoDialog
|
|
156
|
+
trigger={
|
|
157
|
+
<TooltipTrigger
|
|
158
|
+
render={
|
|
159
|
+
<Button size="icon" aria-label="Set up Moi">
|
|
160
|
+
<IconSandbox stroke={1.5} />
|
|
161
|
+
</Button>
|
|
162
|
+
}
|
|
163
|
+
/>
|
|
164
|
+
}
|
|
165
|
+
/>
|
|
166
|
+
<TooltipContent side="right">Set up Moi</TooltipContent>
|
|
167
|
+
</Tooltip>
|
|
162
168
|
)
|
|
163
169
|
}
|
|
164
170
|
|
package/client/dev/index.html
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
<script type="importmap">
|
|
10
10
|
{
|
|
11
11
|
"imports": {
|
|
12
|
-
"react": "/vendor/react/react.js",
|
|
13
|
-
"react/jsx-runtime": "/vendor/react/react-jsx-runtime.js",
|
|
14
|
-
"react/jsx-dev-runtime": "/vendor/react/react-jsx-dev-runtime.js",
|
|
15
|
-
"react-dom": "/vendor/react/react-dom.js",
|
|
16
|
-
"react-dom/client": "/vendor/react/react-dom-client.js"
|
|
12
|
+
"react": "/vendor/react/19.2.4/development/react.js",
|
|
13
|
+
"react/jsx-runtime": "/vendor/react/19.2.4/development/react-jsx-runtime.js",
|
|
14
|
+
"react/jsx-dev-runtime": "/vendor/react/19.2.4/development/react-jsx-dev-runtime.js",
|
|
15
|
+
"react-dom": "/vendor/react/19.2.4/development/react-dom.js",
|
|
16
|
+
"react-dom/client": "/vendor/react/19.2.4/development/react-dom-client.js"
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
</script>
|
|
@@ -32,7 +32,7 @@ export function useSaveAppletThumbnails(workspaceId: string) {
|
|
|
32
32
|
),
|
|
33
33
|
onSuccess: () => {
|
|
34
34
|
queryClient.invalidateQueries({ queryKey: workspaceKeys.appletThumbnails(workspaceId) })
|
|
35
|
-
queryClient.invalidateQueries({ queryKey: workspaceKeys.
|
|
35
|
+
queryClient.invalidateQueries({ queryKey: workspaceKeys.previews })
|
|
36
36
|
}
|
|
37
37
|
})
|
|
38
38
|
}
|
|
@@ -99,7 +99,7 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
|
|
|
99
99
|
if (!cachedSession) {
|
|
100
100
|
queryClient?.invalidateQueries({ queryKey: sessionsKey })
|
|
101
101
|
}
|
|
102
|
-
queryClient?.invalidateQueries({ queryKey: workspaceKeys.
|
|
102
|
+
queryClient?.invalidateQueries({ queryKey: workspaceKeys.previews })
|
|
103
103
|
return
|
|
104
104
|
}
|
|
105
105
|
if (data.type === 'sessions_changed' || data.type === 'session_archived') {
|
|
@@ -108,7 +108,7 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
|
|
|
108
108
|
applyArchivedSession(queryClient, workspaceId, data.sessionId)
|
|
109
109
|
const sessionsKey = workspaceKeys.sessions(workspaceId)
|
|
110
110
|
queryClient?.invalidateQueries({ queryKey: sessionsKey })
|
|
111
|
-
queryClient?.invalidateQueries({ queryKey: workspaceKeys.
|
|
111
|
+
queryClient?.invalidateQueries({ queryKey: workspaceKeys.previews })
|
|
112
112
|
if (typeof data.sessionId === 'string')
|
|
113
113
|
queryClient?.invalidateQueries({
|
|
114
114
|
queryKey: workspaceKeys.session(workspaceId, data.sessionId)
|
|
@@ -129,7 +129,7 @@ export function useArchiveWorkspaceSession(workspaceId: string) {
|
|
|
129
129
|
),
|
|
130
130
|
onSuccess: (_, sessionId) => {
|
|
131
131
|
applyArchivedSession(queryClient, workspaceId, sessionId)
|
|
132
|
-
queryClient.invalidateQueries({ queryKey: workspaceKeys.
|
|
132
|
+
queryClient.invalidateQueries({ queryKey: workspaceKeys.previews })
|
|
133
133
|
}
|
|
134
134
|
})
|
|
135
135
|
}
|
|
@@ -187,7 +187,7 @@ export function useChat(address: WorkspaceTabAddress) {
|
|
|
187
187
|
})
|
|
188
188
|
finishComposerSend(workspaceId, ready)
|
|
189
189
|
if (isNew) {
|
|
190
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.
|
|
190
|
+
qc.invalidateQueries({ queryKey: workspaceKeys.previews })
|
|
191
191
|
}
|
|
192
192
|
},
|
|
193
193
|
[
|
|
@@ -19,8 +19,7 @@ export type HostApi = { publishUsers: (next: HostUsers) => void }
|
|
|
19
19
|
// Who supplies the current user: local setup, an outer host, or an auth proxy.
|
|
20
20
|
export type CurrentUserSource = 'local' | 'external' | AuthProvider
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
const PROFILE_KEY = 'moi:collab:dev-profile'
|
|
22
|
+
const PROFILE_KEY = 'moi:local-profile'
|
|
24
23
|
const NO_USERS: readonly UserProfile[] = Object.freeze([])
|
|
25
24
|
let currentUser: UserProfile | undefined
|
|
26
25
|
let currentUserSource: CurrentUserSource | undefined
|
|
@@ -138,7 +137,7 @@ export function setProxyUserState({ provider, profile }: ProxyUserState): void {
|
|
|
138
137
|
|
|
139
138
|
function persistLocalUser(): void {
|
|
140
139
|
try {
|
|
141
|
-
|
|
140
|
+
localStorage.setItem(PROFILE_KEY, JSON.stringify(currentUser))
|
|
142
141
|
} catch {
|
|
143
142
|
/* Private browsing. */
|
|
144
143
|
}
|
|
@@ -156,17 +155,17 @@ export function setLocalUser(next: UserProfile): void {
|
|
|
156
155
|
|
|
157
156
|
// Called after startup config and proxy identity settle, before React mounts.
|
|
158
157
|
// A host that has already published keeps the viewer it chose, signed in or not.
|
|
159
|
-
export function initializeLocalUser(
|
|
160
|
-
if (!
|
|
158
|
+
export function initializeLocalUser(local: boolean, proxyUser: ProxyUserState | undefined): void {
|
|
159
|
+
if (!local || !proxyUser || proxyUser.provider !== undefined || currentUserSource !== undefined)
|
|
161
160
|
return
|
|
162
161
|
try {
|
|
163
|
-
const saved =
|
|
162
|
+
const saved = localStorage.getItem(PROFILE_KEY)
|
|
164
163
|
if (saved) {
|
|
165
164
|
setLocalUser(JSON.parse(saved) as UserProfile)
|
|
166
165
|
return
|
|
167
166
|
}
|
|
168
167
|
} catch {
|
|
169
|
-
|
|
168
|
+
// Invalid or unavailable storage starts a fresh local profile.
|
|
170
169
|
}
|
|
171
170
|
setLocalUser(createLocalUser())
|
|
172
171
|
}
|
|
@@ -181,3 +180,21 @@ export function installHostApi(): void {
|
|
|
181
180
|
const api: HostApi = { publishUsers }
|
|
182
181
|
host.moi.collab = api
|
|
183
182
|
}
|
|
183
|
+
|
|
184
|
+
// Storage events update this tab without writing back and triggering another event.
|
|
185
|
+
export function receiveLocalProfile(event: Pick<StorageEvent, 'key' | 'newValue'>): void {
|
|
186
|
+
if (event.key !== PROFILE_KEY || !event.newValue || currentUserSource !== 'local') return
|
|
187
|
+
try {
|
|
188
|
+
const profile = normalizeUserProfile(JSON.parse(event.newValue) as UserProfile)
|
|
189
|
+
if (sameProfile(profile, currentUser)) return
|
|
190
|
+
currentUser = profile
|
|
191
|
+
listeners.forEach(listener => listener())
|
|
192
|
+
} catch {
|
|
193
|
+
// Ignore corrupt values from other tabs.
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function subscribeLocalProfileStorage(): () => void {
|
|
198
|
+
window.addEventListener('storage', receiveLocalProfile)
|
|
199
|
+
return () => window.removeEventListener('storage', receiveLocalProfile)
|
|
200
|
+
}
|
|
@@ -40,7 +40,7 @@ export function localUserProfile(id: string, draft: LocalUserDraft): UserProfile
|
|
|
40
40
|
return { id, ...(name ? { name } : {}), color: draft.color }
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// The id stays with the
|
|
43
|
+
// The id stays with the browser through renames, so peers keep seeing one user.
|
|
44
44
|
export function createLocalUser(): UserProfile {
|
|
45
45
|
return localUserProfile(`local-${crypto.randomUUID().slice(0, 8)}`, randomLocalUser())
|
|
46
46
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ProxyUserState } from '@/lib/collab/types'
|
|
2
2
|
|
|
3
3
|
import { requestJson } from '@/client/api/http'
|
|
4
|
-
import { onWorkspaceEventsReconnect } from '@/client/runtime/use-workspace-events'
|
|
5
4
|
|
|
6
5
|
import { setProxyUserState } from './host-state'
|
|
7
6
|
|
|
@@ -23,13 +22,9 @@ async function fetchProxyUser(): Promise<ProxyUserState | undefined> {
|
|
|
23
22
|
} catch {}
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
// Loaded before the app mounts, like startup config, so workspaces
|
|
27
|
-
// between shared and browser-tab navigation with the inherited user
|
|
28
|
-
// in place.
|
|
25
|
+
// Loaded once before the app mounts, like startup config, so workspaces
|
|
26
|
+
// choose between shared and browser-tab navigation with the inherited user
|
|
27
|
+
// already in place.
|
|
29
28
|
export async function loadProxyUser(): Promise<ProxyUserState | undefined> {
|
|
30
|
-
|
|
31
|
-
onWorkspaceEventsReconnect(() => {
|
|
32
|
-
void fetchProxyUser()
|
|
33
|
-
})
|
|
34
|
-
return state
|
|
29
|
+
return fetchProxyUser()
|
|
35
30
|
}
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type MouseEvent as ReactMouseEvent,
|
|
3
|
-
type ReactElement,
|
|
4
|
-
useEffect,
|
|
5
|
-
useRef,
|
|
6
|
-
useState
|
|
7
|
-
} from 'react'
|
|
1
|
+
import { type MouseEvent as ReactMouseEvent, type ReactElement, useRef } from 'react'
|
|
8
2
|
|
|
9
3
|
import {
|
|
4
|
+
IconArrowRight,
|
|
10
5
|
IconArrowUpRight,
|
|
11
|
-
|
|
12
|
-
IconCopy,
|
|
13
|
-
IconFolderOpen,
|
|
6
|
+
IconBrowserPlus,
|
|
14
7
|
IconMessageChatbot,
|
|
15
8
|
IconX
|
|
16
9
|
} from '@tabler/icons-react'
|
|
17
10
|
|
|
18
11
|
import claudeIcon from '@/client/assets/claude.svg'
|
|
19
12
|
import floppyDisk from '@/client/assets/floppy-disk.webp'
|
|
20
|
-
import hermesIcon from '@/client/assets/hermes.png'
|
|
21
13
|
import openaiIcon from '@/client/assets/openai.svg'
|
|
22
|
-
import openclawIcon from '@/client/assets/openclaw.svg'
|
|
23
14
|
import { Button, buttonVariants } from '@/client/components/ui/button'
|
|
24
15
|
import {
|
|
25
16
|
Dialog,
|
|
@@ -31,11 +22,6 @@ import {
|
|
|
31
22
|
} from '@/client/components/ui/dialog'
|
|
32
23
|
import { useAppConfig } from '@/client/api/app-config'
|
|
33
24
|
|
|
34
|
-
// The canonical setup prompt from moi.computer — pasted into any agent, it
|
|
35
|
-
// fetches INSTALL.md and walks itself through the install.
|
|
36
|
-
const AGENT_COMMAND =
|
|
37
|
-
'Set up the Moi workspace for this project. Fetch https://moi.computer/INSTALL.md, and follow the steps.'
|
|
38
|
-
|
|
39
25
|
type DemoDialogProps = {
|
|
40
26
|
// Trigger-owned (uncontrolled) or controlled via open/onOpenChange — the
|
|
41
27
|
// create-workspace buttons use the former, programmatic opens the latter.
|
|
@@ -45,7 +31,7 @@ type DemoDialogProps = {
|
|
|
45
31
|
}
|
|
46
32
|
|
|
47
33
|
// Shown in the cloud demo wherever a workspace would be created: the demo is
|
|
48
|
-
// limited to its built-in workspaces,
|
|
34
|
+
// limited to its built-in workspaces, with login opening the full app.
|
|
49
35
|
export function DemoDialog({ trigger, open, onOpenChange }: DemoDialogProps) {
|
|
50
36
|
return (
|
|
51
37
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
@@ -91,7 +77,7 @@ function FloppyArtwork({ demoInstallUrl }: FloppyArtworkProps) {
|
|
|
91
77
|
href={demoInstallUrl}
|
|
92
78
|
target="_blank"
|
|
93
79
|
rel="noreferrer"
|
|
94
|
-
className="group absolute top-1/2 left-1/2 w-
|
|
80
|
+
className="group absolute top-1/2 left-1/2 w-40 -translate-x-1/2 -translate-y-1/2 rotate-4 [transform:translate3d(var(--floppy-x,0px),var(--floppy-y,0px),0)] rounded-lg transition-transform duration-150 ease-out will-change-transform outline-none focus-visible:ring-3 focus-visible:ring-ring/50 motion-reduce:transform-none motion-reduce:transition-none md:w-36"
|
|
95
81
|
>
|
|
96
82
|
<img src={floppyDisk} alt="" className="w-full drop-shadow-xl" />
|
|
97
83
|
<div
|
|
@@ -108,28 +94,8 @@ function FloppyArtwork({ demoInstallUrl }: FloppyArtworkProps) {
|
|
|
108
94
|
)
|
|
109
95
|
}
|
|
110
96
|
|
|
111
|
-
function useCopyCommand() {
|
|
112
|
-
const [copied, setCopied] = useState(false)
|
|
113
|
-
|
|
114
|
-
useEffect(() => {
|
|
115
|
-
if (!copied) return
|
|
116
|
-
const t = setTimeout(() => setCopied(false), 1500)
|
|
117
|
-
return () => clearTimeout(t)
|
|
118
|
-
}, [copied])
|
|
119
|
-
|
|
120
|
-
const copy = () => {
|
|
121
|
-
navigator.clipboard
|
|
122
|
-
?.writeText(AGENT_COMMAND)
|
|
123
|
-
.then(() => setCopied(true))
|
|
124
|
-
.catch(() => {})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return { copied, copy }
|
|
128
|
-
}
|
|
129
|
-
|
|
130
97
|
function DemoDialogContent() {
|
|
131
98
|
const { demoInstallUrl } = useAppConfig()
|
|
132
|
-
const { copied, copy } = useCopyCommand()
|
|
133
99
|
|
|
134
100
|
return (
|
|
135
101
|
<DialogContent
|
|
@@ -157,21 +123,20 @@ function DemoDialogContent() {
|
|
|
157
123
|
<div className="relative grid max-h-[calc(100dvh-2rem)] overflow-y-auto md:grid-cols-[3fr_2fr] md:overflow-visible">
|
|
158
124
|
<div className="rounded-xl bg-background p-6 text-foreground shadow-sm md:p-8">
|
|
159
125
|
<div className="flex flex-col gap-0.5">
|
|
160
|
-
<DialogTitle>
|
|
126
|
+
<DialogTitle>Set up your personal Moi</DialogTitle>
|
|
161
127
|
<DialogDescription className="mt-1">
|
|
162
|
-
This is a demo
|
|
163
|
-
agent.
|
|
128
|
+
This is a demo workspace. Sign in and connect your agent to unlock all features.
|
|
164
129
|
</DialogDescription>
|
|
165
130
|
</div>
|
|
166
131
|
|
|
167
132
|
<ul className="mt-4 flex flex-col gap-3">
|
|
168
133
|
<li className="flex items-center gap-3">
|
|
169
|
-
<
|
|
134
|
+
<IconBrowserPlus
|
|
170
135
|
stroke={0.75}
|
|
171
136
|
className="mt-0.5 size-8 shrink-0 text-muted-foreground"
|
|
172
137
|
/>
|
|
173
138
|
<span className="text-sm text-foreground">
|
|
174
|
-
|
|
139
|
+
Create as many workspaces, views, and widgets as you want
|
|
175
140
|
</span>
|
|
176
141
|
</li>
|
|
177
142
|
<li className="flex items-center gap-3">
|
|
@@ -179,45 +144,26 @@ function DemoDialogContent() {
|
|
|
179
144
|
stroke={0.75}
|
|
180
145
|
className="mt-0.5 size-8 shrink-0 text-muted-foreground"
|
|
181
146
|
/>
|
|
182
|
-
<span className="
|
|
183
|
-
|
|
184
|
-
<span className="inline-flex items-
|
|
185
|
-
<img src={claudeIcon} alt="" className="size-3.5 object-contain" />
|
|
186
|
-
Claude
|
|
187
|
-
</span>
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
Hermes,
|
|
195
|
-
</span>
|
|
196
|
-
<span className="inline-flex items-center gap-1 font-medium">
|
|
197
|
-
<img src={openclawIcon} alt="" className="size-3.5 object-contain" />
|
|
198
|
-
OpenClaw,
|
|
199
|
-
</span>
|
|
200
|
-
<span>and more</span>
|
|
147
|
+
<span className="text-sm text-foreground">
|
|
148
|
+
Build with{' '}
|
|
149
|
+
<span className="inline-flex items-baseline gap-1">
|
|
150
|
+
<img src={claudeIcon} alt="" className="size-3.5 self-center object-contain" />
|
|
151
|
+
<strong className="font-medium">Claude</strong>
|
|
152
|
+
</span>{' '}
|
|
153
|
+
or{' '}
|
|
154
|
+
<span className="inline-flex items-baseline gap-1">
|
|
155
|
+
<img src={openaiIcon} alt="" className="size-3.5 self-center object-contain" />
|
|
156
|
+
<strong className="font-medium">ChatGPT</strong>
|
|
157
|
+
</span>{' '}
|
|
158
|
+
using your subscription and app connectors
|
|
201
159
|
</span>
|
|
202
160
|
</li>
|
|
203
161
|
</ul>
|
|
204
162
|
|
|
205
|
-
<
|
|
206
|
-
|
|
207
|
-
<
|
|
208
|
-
|
|
209
|
-
{AGENT_COMMAND}
|
|
210
|
-
</code>
|
|
211
|
-
<Button type="button" onClick={copy} className="absolute right-4 -bottom-4">
|
|
212
|
-
{copied ? (
|
|
213
|
-
<IconCheck data-icon="inline-start" stroke={1.5} />
|
|
214
|
-
) : (
|
|
215
|
-
<IconCopy data-icon="inline-start" stroke={1.5} />
|
|
216
|
-
)}
|
|
217
|
-
{copied ? 'Copied' : 'Copy prompt'}
|
|
218
|
-
</Button>
|
|
219
|
-
</div>
|
|
220
|
-
</div>
|
|
163
|
+
<Button render={<a href="/cloud/login" />} className="mt-6">
|
|
164
|
+
Sign in
|
|
165
|
+
<IconArrowRight data-icon="inline-end" stroke={1.5} />
|
|
166
|
+
</Button>
|
|
221
167
|
</div>
|
|
222
168
|
|
|
223
169
|
<FloppyArtwork demoInstallUrl={demoInstallUrl} />
|
|
@@ -15,7 +15,9 @@ import {
|
|
|
15
15
|
} from '@/client/components/ui/dialog'
|
|
16
16
|
import { TooltipProvider } from '@/client/components/ui/tooltip'
|
|
17
17
|
import { Toaster } from '@/client/components/ui/toast'
|
|
18
|
-
import {
|
|
18
|
+
import { WorkspacePendingScreen } from '@/client/features/workspace/workspace-pending-screen'
|
|
19
|
+
import { WorkspaceLayoutContext } from '@/client/features/workspace/workspace-layout-context'
|
|
20
|
+
import { createDefaultWorkspaceLayout } from '@/lib/workspace-layout'
|
|
19
21
|
import { useWorkspaceSetup } from '@/client/features/workspace/setup/workspace-setup'
|
|
20
22
|
import { WorkspaceWelcomeState } from '@/client/features/workspace/setup/workspace-welcome-state'
|
|
21
23
|
import { WorkspaceLoadingState } from '@/client/features/workspace/setup/workspace-recovery-states'
|
|
@@ -50,6 +52,7 @@ type SetupPreviewProps = {
|
|
|
50
52
|
function SetupPreview({ mocks, client, environment, harness, scenario }: SetupPreviewProps) {
|
|
51
53
|
const [provider, setProvider] = useState<'browser' | 'code' | 'closed'>()
|
|
52
54
|
const [deviceCode, setDeviceCode] = useState('')
|
|
55
|
+
const [layout, setLayout] = useState(createDefaultWorkspaceLayout)
|
|
53
56
|
const auth = useHarnessAuth(harness)
|
|
54
57
|
const pendingId = auth.data?.login?.state === 'pending' ? auth.data.login.id : undefined
|
|
55
58
|
// Both local harnesses open the browser automatically.
|
|
@@ -112,20 +115,44 @@ function SetupPreview({ mocks, client, environment, harness, scenario }: SetupPr
|
|
|
112
115
|
</Button>
|
|
113
116
|
))}
|
|
114
117
|
</div>
|
|
118
|
+
<div className="flex flex-wrap gap-2" role="group" aria-label="Layout">
|
|
119
|
+
{(['split', 'fullscreen'] as const).map(layoutMode => (
|
|
120
|
+
<Button
|
|
121
|
+
key={layoutMode}
|
|
122
|
+
size="sm"
|
|
123
|
+
variant={layout.layoutMode === layoutMode ? 'default' : 'secondary'}
|
|
124
|
+
onClick={() => setLayout(current => ({ ...current, layoutMode }))}
|
|
125
|
+
>
|
|
126
|
+
{layoutMode === 'split' ? 'Split' : 'Fullscreen'}
|
|
127
|
+
</Button>
|
|
128
|
+
))}
|
|
129
|
+
</div>
|
|
115
130
|
</header>
|
|
116
|
-
<
|
|
117
|
-
{
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
<WorkspaceLayoutContext
|
|
132
|
+
value={{
|
|
133
|
+
workspaceId: PREVIEW_WORKSPACE_ID,
|
|
134
|
+
layout,
|
|
135
|
+
setLayout: update => setLayout(current => ({ ...current, ...update })),
|
|
136
|
+
name: 'My workspace',
|
|
137
|
+
cwd: null,
|
|
138
|
+
provider: harness,
|
|
139
|
+
isLoading: false
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
<main className="flex min-h-0 flex-1 overflow-y-auto bg-muted">
|
|
143
|
+
{scenario === 'welcome' ? (
|
|
144
|
+
<WorkspacePendingScreen setupRequired>
|
|
145
|
+
<WorkspaceWelcomeState name="My workspace" workspaceType={harness} />
|
|
146
|
+
</WorkspacePendingScreen>
|
|
147
|
+
) : scenario === 'loading' ? (
|
|
148
|
+
<WorkspacePendingScreen>
|
|
149
|
+
<WorkspaceLoadingState />
|
|
150
|
+
</WorkspacePendingScreen>
|
|
151
|
+
) : (
|
|
152
|
+
<SetupScreen />
|
|
153
|
+
)}
|
|
154
|
+
</main>
|
|
155
|
+
</WorkspaceLayoutContext>
|
|
129
156
|
<Dialog
|
|
130
157
|
open={providerPage !== 'closed'}
|
|
131
158
|
onOpenChange={open => !open && setProvider('closed')}
|
|
@@ -172,7 +199,7 @@ function SetupPreview({ mocks, client, environment, harness, scenario }: SetupPr
|
|
|
172
199
|
|
|
173
200
|
function SetupScreen() {
|
|
174
201
|
const [path] = useLocation()
|
|
175
|
-
const { content, ready } = useWorkspaceSetup(PREVIEW_WORKSPACE_ID)
|
|
202
|
+
const { content, ready, setupRequired } = useWorkspaceSetup(PREVIEW_WORKSPACE_ID)
|
|
176
203
|
if (ready) return null
|
|
177
204
|
return path === '/' ? (
|
|
178
205
|
<div
|
|
@@ -182,7 +209,7 @@ function SetupScreen() {
|
|
|
182
209
|
Workspace removed
|
|
183
210
|
</div>
|
|
184
211
|
) : (
|
|
185
|
-
<
|
|
212
|
+
<WorkspacePendingScreen setupRequired={setupRequired}>{content}</WorkspacePendingScreen>
|
|
186
213
|
)
|
|
187
214
|
}
|
|
188
215
|
|
|
@@ -86,9 +86,9 @@ export function DeviceLoginSteps({ code, url }: DeviceLoginStepsProps) {
|
|
|
86
86
|
<li className="flex flex-col items-start gap-3 lg:items-center">
|
|
87
87
|
<IconCircleNumber3 size={24} stroke={1.5} className="shrink-0" />
|
|
88
88
|
<div className="flex min-w-0 flex-col items-start gap-3 lg:items-center">
|
|
89
|
-
<p>Sign
|
|
89
|
+
<p>Sign in to ChatGPT, paste the code, and then come back to Moi</p>
|
|
90
90
|
<a href={url} target="_blank" rel="noopener noreferrer" className={buttonVariants()}>
|
|
91
|
-
Open
|
|
91
|
+
Open ChatGPT
|
|
92
92
|
</a>
|
|
93
93
|
</div>
|
|
94
94
|
</li>
|