moi-computer 0.0.2 → 0.1.0
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/bin/moi.mjs +3 -1
- package/bunfig.toml +4 -0
- package/client/api/workspaces.ts +277 -6
- package/client/assets/mcp/agentation.png +0 -0
- package/client/assets/mcp/airtable.png +0 -0
- package/client/assets/mcp/apollo.png +0 -0
- package/client/assets/mcp/asana.png +0 -0
- package/client/assets/mcp/box.png +0 -0
- package/client/assets/mcp/chrome.svg +33 -0
- package/client/assets/mcp/clickup.png +0 -0
- package/client/assets/mcp/cloudflare.png +0 -0
- package/client/assets/mcp/context7.png +0 -0
- package/client/assets/mcp/datadog.png +0 -0
- package/client/assets/mcp/dropbox.png +0 -0
- package/client/assets/mcp/elevenlabs.png +0 -0
- package/client/assets/mcp/exa.png +0 -0
- package/client/assets/mcp/firecrawl.png +0 -0
- package/client/assets/mcp/gmail.png +0 -0
- package/client/assets/mcp/googlecalendar.png +0 -0
- package/client/assets/mcp/googledrive.png +0 -0
- package/client/assets/mcp/grafana.png +0 -0
- package/client/assets/mcp/huggingface.png +0 -0
- package/client/assets/mcp/intercom.png +0 -0
- package/client/assets/mcp/monday.png +0 -0
- package/client/assets/mcp/mongodb.png +0 -0
- package/client/assets/mcp/paper.png +0 -0
- package/client/assets/mcp/paypal.png +0 -0
- package/client/assets/mcp/perplexity.png +0 -0
- package/client/assets/mcp/postgresql.png +0 -0
- package/client/assets/mcp/posthog.png +0 -0
- package/client/assets/mcp/puppeteer.png +0 -0
- package/client/assets/mcp/railway.png +0 -0
- package/client/assets/mcp/redis.png +0 -0
- package/client/assets/mcp/salesforce.png +0 -0
- package/client/assets/mcp/shopify.png +0 -0
- package/client/assets/mcp/snowflake.png +0 -0
- package/client/assets/mcp/telegram.png +0 -0
- package/client/assets/mcp/twilio.png +0 -0
- package/client/assets/mcp/zapier.png +0 -0
- package/client/components/App.tsx +7 -1
- package/client/components/BottomPanel.tsx +2 -2
- package/client/components/ChatInput.tsx +195 -14
- package/client/components/ChatPanel.tsx +118 -49
- package/client/components/ChatPopup.tsx +2 -2
- package/client/components/CustomizePanel.tsx +8 -8
- package/client/components/HiddenPanel.tsx +1 -1
- package/client/components/HomePage.tsx +1 -1
- package/client/components/IconMcp.tsx +21 -0
- package/client/components/MarkdownContent.tsx +2 -2
- package/client/components/McpMenu.tsx +125 -0
- package/client/components/ModelPicker.tsx +147 -0
- package/client/components/Scratchpad.tsx +775 -0
- package/client/components/ShimmerText.tsx +20 -0
- package/client/components/ThreadSelector.tsx +2 -2
- package/client/components/TurnView.tsx +114 -534
- package/client/components/WidgetErrorBoundary.tsx +2 -2
- package/client/components/WidgetFrame.tsx +1 -1
- package/client/components/WidgetShell.tsx +2 -2
- package/client/components/Widgets.tsx +2 -2
- package/client/components/WorkspacePreview.tsx +3 -3
- package/client/components/WorkspacesPage.tsx +28 -20
- package/client/components/layout/SidebarLayout.tsx +24 -15
- package/client/components/playground/PixelPainter.tsx +2 -2
- package/client/components/playground/PlaygroundPage.tsx +1 -1
- package/client/components/playground/ToolCallsPage.tsx +81 -0
- package/client/components/routes/workspace/[id].tsx +534 -141
- package/client/components/routes/workspace/create.tsx +155 -0
- package/client/components/settings/IconPicker.tsx +590 -0
- package/client/components/settings/SettingsPages.tsx +307 -0
- package/client/components/settings/WorkspaceSettings.tsx +92 -0
- package/client/components/tool-group/CodeBlock.tsx +41 -0
- package/client/components/tool-group/Collapse.tsx +28 -0
- package/client/components/tool-group/ReadImagePreview.tsx +46 -0
- package/client/components/tool-group/SubagentCard.tsx +135 -0
- package/client/components/tool-group/TimelineRow.tsx +147 -0
- package/client/components/tool-group/ToolCallGroup.tsx +231 -0
- package/client/components/tool-group/ToolOutput.tsx +139 -0
- package/client/components/tool-group/detect.ts +93 -0
- package/client/components/tool-group/fixtures.ts +315 -0
- package/client/components/tool-group/format.ts +211 -0
- package/client/components/tool-group/index.ts +9 -0
- package/client/components/ui/button.tsx +4 -4
- package/client/components/ui/dialog.tsx +58 -0
- package/client/components/ui/dropdown-menu.tsx +9 -9
- package/client/components/ui/hover-card.tsx +44 -0
- package/client/components/ui/popover.tsx +1 -1
- package/client/components/ui/switch.tsx +23 -0
- package/client/components/ui/tooltip.tsx +54 -0
- package/client/externalize-react.ts +11 -5
- package/client/hooks/useApplet.ts +117 -0
- package/client/hooks/useChat.ts +162 -62
- package/client/hooks/useMeiEvents.ts +9 -2
- package/client/hooks/useStickToBottom.ts +86 -0
- package/client/hooks/useWorkspaceTheme.ts +8 -2
- package/client/index.css +49 -3
- package/client/index.html +22 -18
- package/client/index.tsx +29 -2
- package/client/lib/WorkspaceContext.tsx +5 -8
- package/client/lib/WorkspaceLayoutContext.tsx +30 -10
- package/client/lib/applet-cache.ts +54 -0
- package/client/lib/connection.ts +237 -0
- package/client/lib/flags.ts +10 -0
- package/client/lib/mcp-icons.ts +142 -10
- package/client/lib/preview-turn.ts +37 -0
- package/client/lib/render-icon.ts +173 -0
- package/client/lib/scratch-executor.ts +20 -0
- package/client/lib/uploads.ts +18 -0
- package/client/main.tsx +5 -0
- package/client/store/live.ts +282 -0
- package/client/structured-clone-shim.ts +14 -0
- package/client/theme.css +2 -2
- package/client/vendor/emojibase/en/data.json +1 -0
- package/client/vendor/emojibase/en/messages.json +1 -0
- package/client/vendor/react/development/_impl/react-dom-client.js +15871 -0
- package/client/vendor/react/development/_impl/react-dom.js +223 -0
- package/client/vendor/react/development/_impl/react-jsx-dev-runtime.js +256 -0
- package/client/vendor/react/development/_impl/react-jsx-runtime.js +260 -0
- package/client/vendor/react/development/_impl/react.js +863 -0
- package/client/vendor/react/development/react-dom-client.js +6 -0
- package/client/vendor/react/development/react-dom.js +17 -0
- package/client/vendor/react/development/react-jsx-dev-runtime.js +5 -0
- package/client/vendor/react/development/react-jsx-runtime.js +6 -0
- package/client/vendor/react/development/react.js +47 -0
- package/client/vendor/react/production/_impl/react-dom-client.js +10361 -0
- package/client/vendor/react/production/_impl/react-dom.js +184 -0
- package/client/vendor/react/production/_impl/react-jsx-dev-runtime.js +37 -0
- package/client/vendor/react/production/_impl/react-jsx-runtime.js +60 -0
- package/client/vendor/react/production/_impl/react.js +428 -0
- package/client/vendor/react/production/react-dom-client.js +6 -0
- package/client/vendor/react/production/react-dom.js +17 -0
- package/client/vendor/react/production/react-jsx-dev-runtime.js +5 -0
- package/client/vendor/react/production/react-jsx-runtime.js +6 -0
- package/client/vendor/react/production/react.js +47 -0
- package/dist/agentation-4s0nn45p.png +0 -0
- package/dist/airtable-hsa66v6q.png +0 -0
- package/dist/apollo-2ed5dy2d.png +0 -0
- package/dist/asana-tvgtwbx2.png +0 -0
- package/dist/atlassian-b3tq39hs.png +0 -0
- package/dist/box-w3n36t5g.png +0 -0
- package/dist/chrome-tspm94rw.svg +33 -0
- package/dist/chunk-kc6e9nd4.css +1 -0
- package/dist/chunk-yf3p7qg7.js +673 -0
- package/dist/claude-z2xnay0d.svg +3 -0
- package/dist/clickup-qqrqqvqb.png +0 -0
- package/dist/cloudflare-j9p931v6.png +0 -0
- package/dist/context7-8ht0xjfy.png +0 -0
- package/dist/datadog-70ne3yzt.png +0 -0
- package/dist/discord-vejhptwx.png +0 -0
- package/dist/dropbox-4m5s9mgr.png +0 -0
- package/dist/elevenlabs-2nzzej1t.png +0 -0
- package/dist/exa-qqj3vr0x.png +0 -0
- package/dist/favicon-nbmyjfjh.png +0 -0
- package/dist/figma-y9898rry.png +0 -0
- package/dist/firecrawl-w2t8nehx.png +0 -0
- package/dist/github-av5r5y3e.png +0 -0
- package/dist/gitlab-4pv5vm6b.png +0 -0
- package/dist/gmail-sg6a5v3x.png +0 -0
- package/dist/googlecalendar-nqhh2v7r.png +0 -0
- package/dist/googledrive-6s8xyab7.png +0 -0
- package/dist/grafana-1yfsnwr6.png +0 -0
- package/dist/granola-7j3b0nk2.png +0 -0
- package/dist/hermes-nous-pznd63x9.png +0 -0
- package/dist/hubspot-hghcmc2t.png +0 -0
- package/dist/huggingface-kxzaxj83.png +0 -0
- package/dist/index.html +47 -0
- package/dist/intercom-td763jt8.png +0 -0
- package/dist/linear-v9s3az2d.png +0 -0
- package/dist/monday-jdbs4wwf.png +0 -0
- package/dist/mongodb-emzxvhd5.png +0 -0
- package/dist/neon-zj4qar44.png +0 -0
- package/dist/notion-w034c0b8.png +0 -0
- package/dist/openclaw-a2pyfhpn.svg +22 -0
- package/dist/paper-zbt34fab.png +0 -0
- package/dist/paypal-kwwf7xsc.png +0 -0
- package/dist/perplexity-4y63rxvj.png +0 -0
- package/dist/postgresql-qsspbsr1.png +0 -0
- package/dist/posthog-sphppc4w.png +0 -0
- package/dist/puppeteer-2xjt1a9b.png +0 -0
- package/dist/railway-834de8d2.png +0 -0
- package/dist/redis-spm6w2m1.png +0 -0
- package/dist/salesforce-1mk56v4z.png +0 -0
- package/dist/sentry-hdwpmvek.png +0 -0
- package/dist/shopify-90dadaav.png +0 -0
- package/dist/slack-1c1wj62s.png +0 -0
- package/dist/snowflake-hfpykpgy.png +0 -0
- package/dist/stripe-zrfaqbj3.png +0 -0
- package/dist/supabase-4vg33zf2.png +0 -0
- package/dist/telegram-v6tjyrs7.png +0 -0
- package/dist/twilio-dpyjdwpj.png +0 -0
- package/dist/vercel-7d0ssw28.png +0 -0
- package/dist/zapier-p67qfch0.png +0 -0
- package/lib/attachment-note.ts +48 -0
- package/lib/claude-adapter.ts +219 -29
- package/lib/format.ts +32 -0
- package/lib/types.ts +314 -6
- package/package.json +21 -31
- package/server/CLAUDE.md +3 -0
- package/server/agent.ts +25 -118
- package/server/api.ts +593 -0
- package/server/applets.ts +396 -0
- package/server/build-applet.ts +580 -0
- package/server/cc-session.ts +611 -0
- package/server/cli-colors.ts +17 -0
- package/server/cli-ui.ts +52 -0
- package/server/cli.ts +970 -72
- package/server/control.ts +166 -19
- package/server/debug.ts +10 -0
- package/server/events.ts +24 -0
- package/server/functions-worker.ts +18 -2
- package/server/functions.ts +59 -12
- package/server/icon.ts +13 -0
- package/server/layout.ts +25 -3
- package/server/mcp.ts +125 -0
- package/server/moi-scaffold.ts +85 -0
- package/server/openclaw-session.ts +41 -10
- package/server/openclaw.ts +22 -0
- package/server/preview.ts +70 -0
- package/server/registry.ts +32 -2
- package/server/scratchpad-executor.ts +380 -0
- package/server/scratchpad-relay.ts +45 -0
- package/server/scratchpad.ts +171 -0
- package/server/skill-version.ts +146 -0
- package/server/skills-template.ts +6 -1
- package/server/state.ts +22 -36
- package/server/static.ts +23 -0
- package/server/status.ts +94 -0
- package/server/thread-config.ts +125 -0
- package/server/uploads.ts +0 -0
- package/server/vendor.ts +63 -0
- package/server/views.ts +0 -0
- package/server/web.ts +113 -223
- package/server/widgets.ts +52 -142
- package/server/workspace-config.ts +37 -0
- package/server/workspace-env.ts +407 -0
- package/server/workspace-init.ts +66 -0
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +109 -0
- package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +57 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +252 -0
- package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +22 -0
- package/client/hooks/useWidget.ts +0 -72
- package/client/hooks/useWidgetList.ts +0 -30
- package/client/lib/ws.ts +0 -129
- package/client/store/chat.tsx +0 -162
- package/server/build-widget.ts +0 -343
- package/workspace/.claude/skills/widgets/DESIGN.md +0 -630
- package/workspace/.claude/skills/widgets/SKILL.md +0 -176
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type RefObject, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
// Best-practice chat scroll behavior — "stick to bottom, but respect the user":
|
|
4
|
+
// • Pinned to the bottom by default: new content (new turns, streaming tokens,
|
|
5
|
+
// images loading) keeps the latest line in view.
|
|
6
|
+
// • The moment the user scrolls up, un-pin — never yank them back down while
|
|
7
|
+
// they read history.
|
|
8
|
+
// • Re-pin automatically when they scroll back to (near) the bottom.
|
|
9
|
+
// • `scrollToBottom()` for the "jump to latest" button and for send.
|
|
10
|
+
// • On mount and whenever `resetKey` changes (thread switch), jump to bottom.
|
|
11
|
+
//
|
|
12
|
+
// Content growth is followed via a ResizeObserver on the scroll content, so we
|
|
13
|
+
// don't depend on React deps to know when to scroll — it just works for any
|
|
14
|
+
// height change, including per-token streaming.
|
|
15
|
+
|
|
16
|
+
// Within this many px of the bottom still counts as "at the bottom" — covers
|
|
17
|
+
// sub-pixel rounding and lets a small overscroll keep the pin.
|
|
18
|
+
const STICK_THRESHOLD_PX = 48
|
|
19
|
+
|
|
20
|
+
type StickToBottom = {
|
|
21
|
+
// True when pinned to (near) the bottom — drives the jump-to-latest button.
|
|
22
|
+
atBottom: boolean
|
|
23
|
+
// Scroll to the bottom and re-pin. `smooth` for user-initiated jumps.
|
|
24
|
+
scrollToBottom: (behavior?: ScrollBehavior) => void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useStickToBottom(
|
|
28
|
+
scrollRef: RefObject<HTMLElement | null>,
|
|
29
|
+
resetKey?: unknown
|
|
30
|
+
): StickToBottom {
|
|
31
|
+
// Ref (not state) so the scroll/resize handlers read the latest value without
|
|
32
|
+
// re-subscribing; `atBottom` state mirrors it for rendering the button.
|
|
33
|
+
const pinnedRef = useRef(true)
|
|
34
|
+
const [atBottom, setAtBottom] = useState(true)
|
|
35
|
+
|
|
36
|
+
const setPinned = useCallback((pinned: boolean) => {
|
|
37
|
+
pinnedRef.current = pinned
|
|
38
|
+
setAtBottom(prev => (prev === pinned ? prev : pinned))
|
|
39
|
+
}, [])
|
|
40
|
+
|
|
41
|
+
const scrollToBottom = useCallback(
|
|
42
|
+
(behavior: ScrollBehavior = 'auto') => {
|
|
43
|
+
const el = scrollRef.current
|
|
44
|
+
if (!el) return
|
|
45
|
+
setPinned(true)
|
|
46
|
+
el.scrollTo({ top: el.scrollHeight, behavior })
|
|
47
|
+
},
|
|
48
|
+
[scrollRef, setPinned]
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
// Track whether the user is at the bottom. A programmatic scroll-to-bottom
|
|
52
|
+
// also fires this with distance ≈ 0, so pinned stays true — no fight.
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const el = scrollRef.current
|
|
55
|
+
if (!el) return
|
|
56
|
+
const onScroll = () => {
|
|
57
|
+
const distance = el.scrollHeight - el.scrollTop - el.clientHeight
|
|
58
|
+
setPinned(distance <= STICK_THRESHOLD_PX)
|
|
59
|
+
}
|
|
60
|
+
el.addEventListener('scroll', onScroll, { passive: true })
|
|
61
|
+
return () => el.removeEventListener('scroll', onScroll)
|
|
62
|
+
}, [scrollRef, setPinned])
|
|
63
|
+
|
|
64
|
+
// Follow content growth while pinned. Observing the content element catches
|
|
65
|
+
// every height change (new turns, streaming text, images) without React deps.
|
|
66
|
+
// Setting scrollTop doesn't change the observed size, so there's no RO loop.
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const el = scrollRef.current
|
|
69
|
+
if (!el) return
|
|
70
|
+
const content = el.firstElementChild ?? el
|
|
71
|
+
const ro = new ResizeObserver(() => {
|
|
72
|
+
if (pinnedRef.current) el.scrollTop = el.scrollHeight
|
|
73
|
+
})
|
|
74
|
+
ro.observe(content)
|
|
75
|
+
return () => ro.disconnect()
|
|
76
|
+
}, [scrollRef])
|
|
77
|
+
|
|
78
|
+
// Jump to bottom on mount and on thread switch (before paint, so no flash).
|
|
79
|
+
// If the new thread's content is still loading, the ResizeObserver above lands
|
|
80
|
+
// us at the bottom once it arrives (pin is set here).
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
scrollToBottom('auto')
|
|
83
|
+
}, [resetKey, scrollToBottom])
|
|
84
|
+
|
|
85
|
+
return { atBottom, scrollToBottom }
|
|
86
|
+
}
|
|
@@ -22,6 +22,11 @@ export function useWorkspaceTheme(
|
|
|
22
22
|
target: RefObject<HTMLElement | null>
|
|
23
23
|
) {
|
|
24
24
|
const font = theme?.font ?? 'default'
|
|
25
|
+
// Read the scoped color overrides up front so the color effect below depends
|
|
26
|
+
// on these exact values rather than the whole `theme` object (it accesses
|
|
27
|
+
// them via a dynamic key, which the deps linter can't see through).
|
|
28
|
+
const background = theme?.background
|
|
29
|
+
const foreground = theme?.foreground
|
|
25
30
|
|
|
26
31
|
useEffect(() => {
|
|
27
32
|
const el = target.current
|
|
@@ -58,8 +63,9 @@ export function useWorkspaceTheme(
|
|
|
58
63
|
useEffect(() => {
|
|
59
64
|
const el = target.current
|
|
60
65
|
if (!el) return
|
|
66
|
+
const overrides = { background, foreground }
|
|
61
67
|
for (const key of COLOR_OVERRIDES) {
|
|
62
|
-
const value =
|
|
68
|
+
const value = overrides[key]
|
|
63
69
|
if (value) {
|
|
64
70
|
el.style.setProperty(`--${key}`, value)
|
|
65
71
|
} else {
|
|
@@ -69,7 +75,7 @@ export function useWorkspaceTheme(
|
|
|
69
75
|
return () => {
|
|
70
76
|
for (const key of COLOR_OVERRIDES) el.style.removeProperty(`--${key}`)
|
|
71
77
|
}
|
|
72
|
-
}, [
|
|
78
|
+
}, [background, foreground, target])
|
|
73
79
|
|
|
74
80
|
// Drop the shared font <link> when the workspace unmounts.
|
|
75
81
|
useEffect(() => () => document.getElementById(FONT_LINK_ID)?.remove(), [])
|
package/client/index.css
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
padding: 0;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
@plugin
|
|
12
|
+
@plugin '@tailwindcss/typography';
|
|
13
13
|
|
|
14
14
|
@custom-variant dark (&:is(.dark *));
|
|
15
15
|
|
|
@@ -39,8 +39,9 @@
|
|
|
39
39
|
equivalents. (The app sidebar's own widths live in SidebarLayout.tsx.) */
|
|
40
40
|
--page-pad: 2rem; /* padding around the working area */
|
|
41
41
|
--column-w: 40rem; /* grid content width; also the widget area's min before the chat yields */
|
|
42
|
-
--chat-min:
|
|
43
|
-
--chat-max:
|
|
42
|
+
--chat-min: 380px; /* docked chat min width — narrower than this and it floats */
|
|
43
|
+
--chat-max: 460px; /* docked chat max width on wide screens */
|
|
44
|
+
--chat-max-container: 640px; /* contained ChatPanel: max width of the centered history + composer column */
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
@media (max-width: 1024px) {
|
|
@@ -134,6 +135,18 @@
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
|
|
138
|
+
/* Text shimmer — a brighter band sweeps left→right across muted text to signal
|
|
139
|
+
activity. Pair with `bg-clip-text text-transparent` and a 200%-wide gradient
|
|
140
|
+
whose highlight sits in the middle (see <ShimmerText>). */
|
|
141
|
+
@keyframes text-shimmer {
|
|
142
|
+
0% {
|
|
143
|
+
background-position: -100% center;
|
|
144
|
+
}
|
|
145
|
+
100% {
|
|
146
|
+
background-position: 100% center;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
137
150
|
@utility prose-inherit {
|
|
138
151
|
--tw-prose-body: inherit;
|
|
139
152
|
--tw-prose-headings: inherit;
|
|
@@ -170,6 +183,39 @@
|
|
|
170
183
|
mask-repeat: no-repeat;
|
|
171
184
|
}
|
|
172
185
|
|
|
186
|
+
/* Hide the scrollbar entirely (e.g. the MCP hover card, which signals overflow
|
|
187
|
+
with top/bottom mask fades instead — see useScrollFade + mask-fade-*). */
|
|
188
|
+
@utility scrollbar-none {
|
|
189
|
+
scrollbar-width: none;
|
|
190
|
+
&::-webkit-scrollbar {
|
|
191
|
+
display: none;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* Slim, unobtrusive scrollbar — keeps a clear scroll affordance while taming
|
|
196
|
+
the chunky macOS "always show" scrollbar (a transparent border insets the
|
|
197
|
+
thumb into a thin floating pill). */
|
|
198
|
+
@utility scrollbar-thin {
|
|
199
|
+
scrollbar-width: thin;
|
|
200
|
+
scrollbar-color: rgb(0 0 0 / 0.2) transparent;
|
|
201
|
+
&::-webkit-scrollbar {
|
|
202
|
+
width: 10px;
|
|
203
|
+
height: 10px;
|
|
204
|
+
}
|
|
205
|
+
&::-webkit-scrollbar-track {
|
|
206
|
+
background: transparent;
|
|
207
|
+
}
|
|
208
|
+
&::-webkit-scrollbar-thumb {
|
|
209
|
+
background-color: rgb(0 0 0 / 0.2);
|
|
210
|
+
border-radius: 9999px;
|
|
211
|
+
border: 3px solid transparent;
|
|
212
|
+
background-clip: padding-box;
|
|
213
|
+
}
|
|
214
|
+
&::-webkit-scrollbar-thumb:hover {
|
|
215
|
+
background-color: rgb(0 0 0 / 0.32);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
173
219
|
/* Tool details toggle */
|
|
174
220
|
details > summary {
|
|
175
221
|
list-style: none;
|
package/client/index.html
CHANGED
|
@@ -5,14 +5,18 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>moi.computer</title>
|
|
7
7
|
<link rel="icon" type="image/png" href="./assets/favicon.png" />
|
|
8
|
+
<!-- React is vendored locally (client/vendor/react, generated by
|
|
9
|
+
scripts/build-vendor.ts) and served by the /vendor/react route, so Moi
|
|
10
|
+
runs fully offline — no CDN fetch. The server picks the development or
|
|
11
|
+
production build per environment behind these stable URLs. -->
|
|
8
12
|
<script type="importmap">
|
|
9
13
|
{
|
|
10
14
|
"imports": {
|
|
11
|
-
"react": "
|
|
12
|
-
"react/jsx-runtime": "
|
|
13
|
-
"react/jsx-dev-runtime": "
|
|
14
|
-
"react-dom": "
|
|
15
|
-
"react-dom/client": "
|
|
15
|
+
"react": "/vendor/react/react.js",
|
|
16
|
+
"react/jsx-runtime": "/vendor/react/react-jsx-runtime.js",
|
|
17
|
+
"react/jsx-dev-runtime": "/vendor/react/react-jsx-dev-runtime.js",
|
|
18
|
+
"react-dom": "/vendor/react/react-dom.js",
|
|
19
|
+
"react-dom/client": "/vendor/react/react-dom-client.js"
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
22
|
</script>
|
|
@@ -23,20 +27,20 @@
|
|
|
23
27
|
<script type="module" src="./index.tsx"></script>
|
|
24
28
|
<script type="module">
|
|
25
29
|
const [react, jsxRuntime, jsxDevRuntime, reactDom, reactDomClient] = await Promise.all([
|
|
26
|
-
import(
|
|
27
|
-
import(
|
|
28
|
-
import(
|
|
29
|
-
import(
|
|
30
|
-
import(
|
|
31
|
-
])
|
|
30
|
+
import('react'),
|
|
31
|
+
import('react/jsx-runtime'),
|
|
32
|
+
import('react/jsx-dev-runtime'),
|
|
33
|
+
import('react-dom'),
|
|
34
|
+
import('react-dom/client')
|
|
35
|
+
])
|
|
32
36
|
globalThis.__esm = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
globalThis.__init(document.getElementById(
|
|
37
|
+
react: react,
|
|
38
|
+
'react/jsx-runtime': jsxRuntime,
|
|
39
|
+
'react/jsx-dev-runtime': jsxDevRuntime,
|
|
40
|
+
'react-dom': reactDom,
|
|
41
|
+
'react-dom/client': reactDomClient
|
|
42
|
+
}
|
|
43
|
+
globalThis.__init(document.getElementById('root'))
|
|
40
44
|
//# sourceURL=react-preload.js
|
|
41
45
|
</script>
|
|
42
46
|
</body>
|
package/client/index.tsx
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
|
+
// Must run before any tldraw module loads — see the file for why.
|
|
2
|
+
import './structured-clone-shim'
|
|
3
|
+
|
|
1
4
|
import './index.css'
|
|
2
5
|
|
|
3
|
-
// React is externalized to
|
|
4
|
-
// in index.html), so Bun's bundled Fast Refresh
|
|
6
|
+
// React is externalized to the locally-vendored ESM (see client/externalize-react.ts
|
|
7
|
+
// + the importmap in index.html → /vendor/react), so Bun's bundled Fast Refresh
|
|
8
|
+
// runtime isn't bound to the React
|
|
5
9
|
// instance that actually renders the app: it registers component families but
|
|
6
10
|
// performReactRefresh() no-ops, leaving stale modules mounted after an edit.
|
|
7
11
|
// Downgrade HMR to plain live-reload — every hot update triggers a full page
|
|
8
12
|
// reload, which re-fetches a clean bundle. Dead-code-eliminated in production.
|
|
9
13
|
if (import.meta.hot) {
|
|
10
14
|
import.meta.hot.on('bun:beforeUpdate', () => location.reload())
|
|
15
|
+
|
|
16
|
+
// Bun's HMR client (≤1.3.14) never re-arms `onclose` on the socket it
|
|
17
|
+
// creates while reconnecting, so the second disconnect in a tab's life
|
|
18
|
+
// (e.g. laptop sleep, then a dev-supervisor restart) silently kills
|
|
19
|
+
// live-reload and the tab serves a stale bundle forever. Watchdog: poll
|
|
20
|
+
// the shell and hard-reload when the served script generation no longer
|
|
21
|
+
// matches the one this page is running.
|
|
22
|
+
const devScript = document.querySelector<HTMLScriptElement>('[data-bun-dev-server-script]')
|
|
23
|
+
if (devScript) {
|
|
24
|
+
const scriptPath = new URL(devScript.src).pathname
|
|
25
|
+
const checkStale = async () => {
|
|
26
|
+
try {
|
|
27
|
+
const html = await (await fetch('/', { cache: 'no-store' })).text()
|
|
28
|
+
if (!html.includes(scriptPath)) location.reload()
|
|
29
|
+
} catch {
|
|
30
|
+
// server mid-restart — the next tick will catch it
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
setInterval(checkStale, 5_000)
|
|
34
|
+
document.addEventListener('visibilitychange', () => {
|
|
35
|
+
if (document.visibilityState === 'visible') checkStale()
|
|
36
|
+
})
|
|
37
|
+
}
|
|
11
38
|
}
|
|
12
39
|
|
|
13
40
|
export async function init(el: HTMLElement) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReactNode, createContext, useContext
|
|
1
|
+
import { type ReactNode, createContext, useContext } from 'react'
|
|
2
2
|
|
|
3
3
|
const WorkspaceContext = createContext<string>('default')
|
|
4
4
|
|
|
@@ -11,14 +11,11 @@ type WorkspaceProps = {
|
|
|
11
11
|
children: ReactNode
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// Provides the active workspace id to the tree (read by chat +
|
|
14
|
+
// Provides the active workspace id to the tree (read by chat + applet hooks).
|
|
15
15
|
// Data loading lives in React Query now (see WorkspaceLayoutProvider and the
|
|
16
|
-
// useWorkspace* query hooks) — this only carries the id.
|
|
16
|
+
// useWorkspace* query hooks) — this only carries the id. Applet bundles no
|
|
17
|
+
// longer read a window global for their workspace: the serve route bakes the
|
|
18
|
+
// API base into each bundle's RPC/fileUrl calls.
|
|
17
19
|
export function Workspace({ id, children }: WorkspaceProps) {
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
// Expose to widget RPC bundles
|
|
20
|
-
;(window as unknown as Record<string, unknown>).__MEI_WS__ = id
|
|
21
|
-
}, [id])
|
|
22
|
-
|
|
23
20
|
return <WorkspaceContext value={id}>{children}</WorkspaceContext>
|
|
24
21
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReactNode, createContext, useCallback, useContext, useRef } from 'react'
|
|
1
|
+
import { type ReactNode, createContext, useCallback, useContext, useMemo, useRef } from 'react'
|
|
2
2
|
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query'
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
useWorkspaceLayout,
|
|
9
9
|
workspaceKeys
|
|
10
10
|
} from '@/client/api/workspaces'
|
|
11
|
-
import type { WorkspaceLayout } from '@/lib/types'
|
|
11
|
+
import type { WorkspaceLayout, WorkspaceType } from '@/lib/types'
|
|
12
12
|
|
|
13
13
|
const DEFAULT_LAYOUT: WorkspaceLayout = {
|
|
14
14
|
version: 1,
|
|
@@ -25,7 +25,17 @@ type WorkspaceLayoutContextValue = {
|
|
|
25
25
|
setLayout: (update: Partial<WorkspaceLayout>) => void
|
|
26
26
|
// Workspace metadata that rides along on the layout endpoint.
|
|
27
27
|
name: string | null
|
|
28
|
+
// Custom workspace icon (base64 data URL), or null to use the provider icon.
|
|
29
|
+
icon: string | null
|
|
28
30
|
cwd: string | null
|
|
31
|
+
// The agent backend (claude-code / openclaw / hermes …). Exposed here so
|
|
32
|
+
// components like McpMenu read it from the shared layout query instead of
|
|
33
|
+
// spawning their own observer (a second observer that remounts would trigger
|
|
34
|
+
// `refetchOnMount` and clobber an in-flight optimistic layout update).
|
|
35
|
+
provider: WorkspaceType | null
|
|
36
|
+
// The workspace's registry id (the route param), so descendants can key
|
|
37
|
+
// their own queries (e.g. the model picker) without prop-drilling.
|
|
38
|
+
workspaceId: string
|
|
29
39
|
isLoading: boolean
|
|
30
40
|
}
|
|
31
41
|
|
|
@@ -40,7 +50,7 @@ export function useWorkspaceLayoutCtx(): WorkspaceLayoutContextValue {
|
|
|
40
50
|
// Strip the server-only metadata so what we PUT back (and expose as `layout`)
|
|
41
51
|
// is just the persisted `WorkspaceLayout`.
|
|
42
52
|
function stripMeta(data: WorkspaceLayoutResponse): WorkspaceLayout {
|
|
43
|
-
const { cwd: _cwd, name: _name, agentId: _agentId, ...layout } = data
|
|
53
|
+
const { cwd: _cwd, name: _name, provider: _provider, agentId: _agentId, ...layout } = data
|
|
44
54
|
return layout
|
|
45
55
|
}
|
|
46
56
|
|
|
@@ -80,13 +90,23 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
|
|
|
80
90
|
[id, qc]
|
|
81
91
|
)
|
|
82
92
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
// Memoized so the context value keeps a stable identity across unrelated
|
|
94
|
+
// renders — otherwise every consumer (WorkspaceView, Widgets, ModelPicker,
|
|
95
|
+
// TurnView, …) would re-render whenever this provider re-renders. `setLayout`
|
|
96
|
+
// is already stable; the rest derive from `query.data`.
|
|
97
|
+
const value = useMemo<WorkspaceLayoutContextValue>(
|
|
98
|
+
() => ({
|
|
99
|
+
layout: query.data ? stripMeta(query.data) : DEFAULT_LAYOUT,
|
|
100
|
+
setLayout,
|
|
101
|
+
name: query.data?.name ?? null,
|
|
102
|
+
icon: query.data?.icon ?? null,
|
|
103
|
+
cwd: query.data?.cwd ?? null,
|
|
104
|
+
provider: query.data?.provider ?? null,
|
|
105
|
+
workspaceId: id,
|
|
106
|
+
isLoading: query.isLoading
|
|
107
|
+
}),
|
|
108
|
+
[query.data, query.isLoading, setLayout, id]
|
|
109
|
+
)
|
|
90
110
|
|
|
91
111
|
return <WorkspaceLayoutContext value={value}>{children}</WorkspaceLayoutContext>
|
|
92
112
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Shared load cache for agent-authored applets (widgets / views).
|
|
2
|
+
//
|
|
3
|
+
// An applet is loaded as an ESM module via dynamic `import()`. The browser
|
|
4
|
+
// memoizes a module by its exact URL forever, so to pick up a rebuilt bundle the
|
|
5
|
+
// URL must change — we vary a `?v=<n>` per applet. The catch: a workspace shows
|
|
6
|
+
// one view (or the widget grid) at a time, so most applets are UNMOUNTED at any
|
|
7
|
+
// moment. If invalidation lived only in the mounted component, an applet rebuilt
|
|
8
|
+
// while its tab is in the background would never bump its version and would be
|
|
9
|
+
// served stale from cache on the next mount.
|
|
10
|
+
//
|
|
11
|
+
// So the cache + version registry live here, module-level and mount-independent:
|
|
12
|
+
// a workspace-wide listener invalidates on every `*:updated` event (see
|
|
13
|
+
// `useAppletCacheInvalidation`), and the per-applet hook invalidates the mounted
|
|
14
|
+
// one too. Either path bumps the version + drops the cached module, so the next
|
|
15
|
+
// load() fetches the rebuilt bundle.
|
|
16
|
+
export type AppletSegment = 'widgets' | 'views'
|
|
17
|
+
|
|
18
|
+
// `${segment}/${workspaceId}/${name}` — namespaced so a widget and a view (or
|
|
19
|
+
// two workspaces) sharing a name never collide.
|
|
20
|
+
export function appletKey(segment: AppletSegment, workspaceId: string, name: string): string {
|
|
21
|
+
return `${segment}/${workspaceId}/${name}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const versions = new Map<string, number>()
|
|
25
|
+
const moduleCache = new Map<string, Promise<unknown>>()
|
|
26
|
+
|
|
27
|
+
export function appletVersion(segment: AppletSegment, workspaceId: string, name: string): number {
|
|
28
|
+
return versions.get(appletKey(segment, workspaceId, name)) ?? 0
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// The cache-busting import URL for an applet's entry at its current version.
|
|
32
|
+
// Assets + chunks resolve module-relative from the entry (via import.meta.url),
|
|
33
|
+
// so they don't inherit `?v` and aren't re-fetched needlessly.
|
|
34
|
+
export function appletUrl(segment: AppletSegment, workspaceId: string, name: string): string {
|
|
35
|
+
return `/api/workspaces/${workspaceId}/${segment}/${name}/index.js?v=${appletVersion(segment, workspaceId, name)}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getCachedApplet(key: string): Promise<unknown> | undefined {
|
|
39
|
+
return moduleCache.get(key)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function setCachedApplet(key: string, mod: Promise<unknown>): void {
|
|
43
|
+
moduleCache.set(key, mod)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Drop the cached module and bump the load version for one applet, so the next
|
|
47
|
+
// load() — including a fresh mount of a previously-backgrounded tab — fetches the
|
|
48
|
+
// rebuilt bundle instead of the memoized old one. Safe (and intended) to call
|
|
49
|
+
// when nothing for this applet is mounted.
|
|
50
|
+
export function invalidateApplet(segment: AppletSegment, workspaceId: string, name: string): void {
|
|
51
|
+
const key = appletKey(segment, workspaceId, name)
|
|
52
|
+
moduleCache.delete(key)
|
|
53
|
+
versions.set(key, (versions.get(key) ?? 0) + 1)
|
|
54
|
+
}
|