moi-computer 0.3.0-next.0 → 0.3.0-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/bunfig.toml +5 -1
- package/client/AGENTS.md +15 -0
- package/client/accept-hmr-dependencies.ts +22 -0
- package/client/api/http.ts +31 -0
- package/client/api/query-options.ts +6 -0
- package/client/api/workspace-keys.ts +17 -0
- package/client/app/AppRouter.tsx +35 -0
- package/client/app/routes/HomeRoute.tsx +13 -0
- package/client/app/routes/WorkspaceRoute.tsx +89 -0
- package/client/app/shell/SidebarLayout.tsx +191 -0
- package/client/assets.d.ts +9 -0
- package/client/components/playground/PixelPainter.tsx +10 -21
- package/client/components/playground/PlaygroundPage.tsx +9 -11
- package/client/components/playground/ToolCallsPage.tsx +9 -11
- package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +1 -1
- package/client/components/shared/PanelHeader.tsx +9 -0
- package/client/components/shared/ReorderableList.tsx +199 -0
- package/client/components/ui/button.tsx +10 -7
- package/client/components/ui/collapsible.tsx +15 -0
- package/client/components/ui/dialog.tsx +2 -2
- package/client/components/ui/dropdown-menu.tsx +5 -5
- package/client/components/ui/hover-card.tsx +1 -1
- package/client/components/ui/popover.tsx +1 -1
- package/client/components/ui/skeleton.tsx +13 -0
- package/client/components/ui/tooltip.tsx +1 -1
- package/client/externalize-react.ts +7 -1
- package/client/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
- package/client/{components → features/applets}/WidgetShell.tsx +1 -1
- package/client/{hooks → features/applets}/useApplet.ts +6 -7
- package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +29 -23
- package/client/features/chat/ChatPanel.tsx +188 -0
- package/client/{components → features/chat}/ChatPopup.tsx +23 -12
- package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
- package/client/{components → features/chat}/ModelPicker.tsx +68 -17
- package/client/{components → features/chat}/ThreadSelector.tsx +11 -9
- package/client/{components → features/chat}/TurnView.tsx +16 -9
- package/client/features/chat/api.ts +78 -0
- package/client/features/chat/chat-connection.ts +107 -0
- package/client/features/chat/chat-frames.ts +131 -0
- package/client/{lib → features/chat}/preview-turn.ts +1 -1
- package/client/{components → features/chat}/tool-group/ReadImagePreview.tsx +1 -1
- package/client/{components → features/chat}/tool-group/SubagentCard.tsx +12 -10
- package/client/{components → features/chat}/tool-group/TimelineRow.tsx +5 -5
- package/client/{components → features/chat}/tool-group/ToolCallGroup.tsx +12 -4
- package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
- package/client/{hooks → features/chat}/useChat.ts +7 -11
- package/client/features/connectors/ConnectorsPage.tsx +92 -0
- package/client/features/connectors/McpMenu.tsx +162 -0
- package/client/features/connectors/api.ts +28 -0
- package/client/features/home/CreateWorkspaceDialog.tsx +224 -0
- package/client/features/home/HomePage.tsx +220 -0
- package/client/{components → features/home}/WorkspacePreview.tsx +2 -2
- package/client/features/home/api.ts +148 -0
- package/client/features/home/workspace-presentation.tsx +44 -0
- package/client/features/scratchpad/Scratchpad.tsx +312 -0
- package/client/features/scratchpad/ScratchpadControls.tsx +503 -0
- package/client/features/scratchpad/useScratchpadSnapshot.tsx +115 -0
- package/client/features/settings/EnvironmentSettings.tsx +149 -0
- package/client/features/settings/GeneralSettings.tsx +90 -0
- package/client/{components → features}/settings/IconPicker.tsx +73 -222
- package/client/features/settings/SettingsLayout.tsx +53 -0
- package/client/{components → features}/settings/WorkspaceSettings.tsx +12 -16
- package/client/features/settings/api.ts +88 -0
- package/client/features/settings/icon-picker-options.ts +161 -0
- package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
- package/client/{components → features/widgets}/HiddenPanel.tsx +3 -3
- package/client/{components → features/widgets}/WidgetFrame.tsx +3 -8
- package/client/{components → features/widgets}/WidgetGrid.tsx +2 -9
- package/client/features/widgets/Widgets.tsx +215 -0
- package/client/{lib/grid-pack.ts → features/widgets/grid.ts} +7 -1
- package/client/{hooks → features/widgets}/useGridReconcile.ts +1 -1
- package/client/{components → features/workspace}/CustomizePanel.tsx +5 -6
- package/client/{lib → features/workspace}/WorkspaceLayoutContext.tsx +15 -8
- package/client/features/workspace/WorkspaceScreen.tsx +536 -0
- package/client/features/workspace/WorkspaceTabs.tsx +205 -0
- package/client/features/workspace/api.ts +56 -0
- package/client/features/workspace/useFitsSplitLayout.ts +37 -0
- package/client/global.d.ts +5 -0
- package/client/index.css +6 -10
- package/client/index.html +1 -1
- package/client/index.tsx +14 -31
- package/client/lib/ws-url.ts +10 -0
- package/client/main.tsx +2 -2
- package/client/runtime/hmr-watchdog.ts +39 -0
- package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +11 -7
- package/client/store/ui.ts +5 -1
- package/client/theme.css +0 -2
- package/dist/chunk-11cab5dq.css +1 -0
- package/dist/chunk-23cgr1tz.css +1 -0
- package/dist/chunk-3hy3qy6d.js +10 -0
- package/dist/chunk-c4j722at.js +546 -0
- package/dist/chunk-dyfaffyz.js +119 -0
- package/dist/chunk-kpe40hm8.js +1 -0
- package/dist/chunk-p68fnz3q.js +2 -0
- package/dist/chunk-pcnahct1.js +5 -0
- package/dist/chunk-tqd3pkg8.css +1 -0
- package/dist/chunk-ty6dvda0.js +1 -0
- package/dist/index.html +2 -2
- package/lib/types.ts +18 -7
- package/lib/workspace-name.ts +14 -0
- package/package.json +3 -2
- package/server/api.ts +127 -17
- package/server/applets.ts +84 -8
- package/server/cli.ts +11 -5
- package/server/layout.ts +38 -7
- package/server/mcp.ts +72 -15
- package/server/moi-scaffold.ts +55 -10
- package/server/registry.ts +16 -0
- package/server/views.ts +0 -0
- package/server/web.ts +1 -0
- package/server/widgets.ts +3 -2
- package/server/workspace-init.ts +5 -19
- package/tsconfig.json +1 -1
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +1 -1
- package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
- package/client/api/workspaces.ts +0 -427
- package/client/components/App.tsx +0 -41
- package/client/components/ChatPanel.tsx +0 -275
- package/client/components/HomePage.tsx +0 -17
- package/client/components/McpMenu.tsx +0 -125
- package/client/components/Scratchpad.tsx +0 -935
- package/client/components/Widgets.tsx +0 -132
- package/client/components/WorkspacesPage.tsx +0 -245
- package/client/components/layout/SidebarLayout.tsx +0 -258
- package/client/components/routes/workspace/[id].tsx +0 -675
- package/client/components/routes/workspace/create.tsx +0 -155
- package/client/components/settings/SettingsPages.tsx +0 -255
- package/client/hooks/useFitsSidebar.ts +0 -34
- package/client/lib/connection.ts +0 -237
- package/dist/chunk-07qf2tv1.css +0 -1
- package/dist/chunk-c3zjp9ez.js +0 -672
- /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
- /package/client/{lib → features/applets}/applet-cache.ts +0 -0
- /package/client/{components → features/chat}/ShimmerText.tsx +0 -0
- /package/client/{store/live.ts → features/chat/chat-store.ts} +0 -0
- /package/client/{lib → features/chat}/group-turns.ts +0 -0
- /package/client/{components → features/chat}/tool-group/CodeBlock.tsx +0 -0
- /package/client/{components → features/chat}/tool-group/Collapse.tsx +0 -0
- /package/client/{components → features/chat}/tool-group/detect.ts +0 -0
- /package/client/{components → features/chat}/tool-group/fixtures.ts +0 -0
- /package/client/{components → features/chat}/tool-group/format.ts +0 -0
- /package/client/{components → features/chat}/tool-group/index.ts +0 -0
- /package/client/{lib → features/chat}/uploads.ts +0 -0
- /package/client/{hooks → features/chat}/useStickToBottom.ts +0 -0
- /package/client/{components → features/connectors}/IconMcp.tsx +0 -0
- /package/client/{lib → features/connectors}/mcp-icons.ts +0 -0
- /package/client/{lib → features/scratchpad}/scratch-executor.ts +0 -0
- /package/client/{lib → features/settings}/render-icon.ts +0 -0
- /package/client/{lib → features/workspace}/WorkspaceContext.tsx +0 -0
- /package/client/{hooks → features/workspace}/useWorkspaceTheme.ts +0 -0
|
@@ -1,675 +0,0 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
|
|
3
|
-
import { AnimatePresence, motion } from "motion/react";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
IconAppWindow,
|
|
7
|
-
IconArtboard,
|
|
8
|
-
IconDots,
|
|
9
|
-
IconLayoutDashboard,
|
|
10
|
-
IconLayoutGrid,
|
|
11
|
-
IconMessageCircle,
|
|
12
|
-
IconPalette,
|
|
13
|
-
IconPlus,
|
|
14
|
-
} from "@tabler/icons-react";
|
|
15
|
-
import { useQueryClient } from "@tanstack/react-query";
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
useWorkspaceSessions,
|
|
19
|
-
useWorkspaceViews,
|
|
20
|
-
useWorkspaceWidgets,
|
|
21
|
-
workspaceKeys,
|
|
22
|
-
} from "@/client/api/workspaces";
|
|
23
|
-
import { ChatPanel } from "@/client/components/ChatPanel";
|
|
24
|
-
import { ChatPopup } from "@/client/components/ChatPopup";
|
|
25
|
-
import { McpMenu } from "@/client/components/McpMenu";
|
|
26
|
-
import { Scratchpad } from "@/client/components/Scratchpad";
|
|
27
|
-
import { WidgetErrorBoundary } from "@/client/components/WidgetErrorBoundary";
|
|
28
|
-
import { type WidgetMode, Widgets } from "@/client/components/Widgets";
|
|
29
|
-
import {
|
|
30
|
-
PanelHeader,
|
|
31
|
-
PROVIDER_ICON,
|
|
32
|
-
SidebarLayout,
|
|
33
|
-
SidebarToggle,
|
|
34
|
-
} from "@/client/components/layout/SidebarLayout";
|
|
35
|
-
import { LedLogo } from "@/client/components/playground/LedLogo";
|
|
36
|
-
import { Button } from "@/client/components/ui/button";
|
|
37
|
-
import {
|
|
38
|
-
DropdownMenu,
|
|
39
|
-
DropdownMenuCheckboxItem,
|
|
40
|
-
DropdownMenuContent,
|
|
41
|
-
DropdownMenuItem,
|
|
42
|
-
DropdownMenuSeparator,
|
|
43
|
-
DropdownMenuTrigger,
|
|
44
|
-
} from "@/client/components/ui/dropdown-menu";
|
|
45
|
-
import { Tooltip, TooltipContent, TooltipTrigger } from "@/client/components/ui/tooltip";
|
|
46
|
-
import { WorkspaceSettings } from "@/client/components/settings/WorkspaceSettings";
|
|
47
|
-
import { useChat } from "@/client/hooks/useChat";
|
|
48
|
-
import { useAppletCacheInvalidation, useView } from "@/client/hooks/useApplet";
|
|
49
|
-
import { useFitsSidebar } from "@/client/hooks/useFitsSidebar";
|
|
50
|
-
import { useGridReconcile } from "@/client/hooks/useGridReconcile";
|
|
51
|
-
import { useMeiEvent } from "@/client/hooks/useMeiEvents";
|
|
52
|
-
import { useWorkspaceTheme } from "@/client/hooks/useWorkspaceTheme";
|
|
53
|
-
import { Workspace } from "@/client/lib/WorkspaceContext";
|
|
54
|
-
import {
|
|
55
|
-
WorkspaceLayoutProvider,
|
|
56
|
-
useWorkspaceLayoutCtx,
|
|
57
|
-
} from "@/client/lib/WorkspaceLayoutContext";
|
|
58
|
-
import { cn } from "@/client/lib/cn";
|
|
59
|
-
import { liveStore } from "@/client/store/live";
|
|
60
|
-
import type { ChatDisplay, SessionInfo, ViewInfo, WidgetInfo } from "@/lib/types";
|
|
61
|
-
|
|
62
|
-
// Tab label for a view: its configured title, or the file-name id as fallback.
|
|
63
|
-
const viewLabel = (v: ViewInfo) => v.config.title || v.id;
|
|
64
|
-
|
|
65
|
-
type WorkspaceRouteProps = {
|
|
66
|
-
id: string;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// Route component for `/workspace/:id` — provides workspace id + layout context,
|
|
70
|
-
// then loads. Layout and widgets are React Query resources; chat (sessions,
|
|
71
|
-
// events, websocket) still runs on the Zustand stores, seeded from the sessions
|
|
72
|
-
// query below.
|
|
73
|
-
export function WorkspaceRoute({ id }: WorkspaceRouteProps) {
|
|
74
|
-
return (
|
|
75
|
-
<Workspace id={id}>
|
|
76
|
-
<WorkspaceLayoutProvider id={id}>
|
|
77
|
-
<WorkspaceLoader id={id} />
|
|
78
|
-
</WorkspaceLayoutProvider>
|
|
79
|
-
</Workspace>
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
type WorkspaceLoaderProps = {
|
|
84
|
-
id: string;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
function WorkspaceLoader({ id }: WorkspaceLoaderProps) {
|
|
88
|
-
const qc = useQueryClient();
|
|
89
|
-
const { layout, setLayout, isLoading: layoutLoading } = useWorkspaceLayoutCtx();
|
|
90
|
-
const widgets = useWorkspaceWidgets(id);
|
|
91
|
-
const views = useWorkspaceViews(id);
|
|
92
|
-
const sessions = useWorkspaceSessions(id);
|
|
93
|
-
|
|
94
|
-
// Keep the grid balanced as widgets come and go. (Theme is applied inside
|
|
95
|
-
// WorkspaceView, scoped to the panel — see useWorkspaceTheme there.)
|
|
96
|
-
useGridReconcile(id, widgets.data, layout, setLayout);
|
|
97
|
-
|
|
98
|
-
// Invalidate the shared applet module cache on every rebuild, even for views /
|
|
99
|
-
// widgets whose tab is currently backgrounded — so switching to them later
|
|
100
|
-
// loads the fresh bundle instead of a stale cached module.
|
|
101
|
-
useAppletCacheInvalidation();
|
|
102
|
-
|
|
103
|
-
// Server-pushed changes invalidate the matching query so the next render
|
|
104
|
-
// revalidates (theme re-applies; the grid reconcile places any new widget).
|
|
105
|
-
useMeiEvent((e) => {
|
|
106
|
-
if (e.type === "theme:updated" || e.type === "workspace:updated") {
|
|
107
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.layout(id) });
|
|
108
|
-
} else if (e.type === "widget-layout:updated") {
|
|
109
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.widgets(id) });
|
|
110
|
-
} else if (e.type === "view-layout:updated") {
|
|
111
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.views(id) });
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// Fresh visit (nothing cached) → centered MOI logo in the panel. Switch-back
|
|
116
|
-
// shows cached data immediately while it revalidates, so no loader then.
|
|
117
|
-
const fresh = layoutLoading || widgets.isLoading;
|
|
118
|
-
|
|
119
|
-
// Chat state lives in app-level stores (RQ cache + live store), not here, so
|
|
120
|
-
// navigation never discards an in-flight run — we just seed the active thread.
|
|
121
|
-
return (
|
|
122
|
-
<>
|
|
123
|
-
<SeedActiveSession workspaceId={id} sessions={sessions.data} />
|
|
124
|
-
<SidebarLayout>
|
|
125
|
-
{fresh ? (
|
|
126
|
-
<div className="flex h-full items-center justify-center">
|
|
127
|
-
<LedLogo sprite="moi" effect="chaos" />
|
|
128
|
-
</div>
|
|
129
|
-
) : (
|
|
130
|
-
<WorkspaceView widgets={widgets.data ?? []} views={views.data ?? []} />
|
|
131
|
-
)}
|
|
132
|
-
</SidebarLayout>
|
|
133
|
-
</>
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
type SeedActiveSessionProps = {
|
|
138
|
-
workspaceId: string;
|
|
139
|
-
sessions: SessionInfo[] | undefined;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// Picks an active thread once the sessions query resolves. A workspace with no
|
|
143
|
-
// active selection yet gets the most recent thread; it also re-selects if the
|
|
144
|
-
// current one vanished from the list. Keyed per workspace in the live store, so
|
|
145
|
-
// the choice persists across navigation.
|
|
146
|
-
function SeedActiveSession({ workspaceId, sessions }: SeedActiveSessionProps) {
|
|
147
|
-
useEffect(() => {
|
|
148
|
-
if (!sessions) return;
|
|
149
|
-
const active = liveStore.getState().activeByWorkspace[workspaceId] ?? null;
|
|
150
|
-
const stillValid = active && sessions.some((s) => s.sessionId === active);
|
|
151
|
-
if (!stillValid) liveStore.getState().setActive(workspaceId, sessions[0]?.sessionId ?? null);
|
|
152
|
-
}, [workspaceId, sessions]);
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const ACTION_VARIANTS = {
|
|
157
|
-
from: { opacity: 0, scale: 0.8, filter: "blur(4px)" },
|
|
158
|
-
to: { opacity: 1, scale: 1, filter: "blur(0px)" },
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// A nav target: a fixed tab, or a view id. The `(string & {})` keeps editor
|
|
162
|
-
// autocomplete for the fixed keys while still accepting arbitrary view ids.
|
|
163
|
-
// Held in WorkspaceView's local state (transient — never persisted): "chat"
|
|
164
|
-
// shows the chat fullscreen; "widgets" / "canvas" / a view id fill the main area
|
|
165
|
-
// with the chat in its persisted position beside it.
|
|
166
|
-
type WorkspaceNav = "chat" | "widgets" | "canvas" | (string & {});
|
|
167
|
-
|
|
168
|
-
type WorkspaceTabsProps = {
|
|
169
|
-
active: WorkspaceNav;
|
|
170
|
-
onSelect: (nav: WorkspaceNav) => void;
|
|
171
|
-
views: ViewInfo[];
|
|
172
|
-
onCreateView: () => void;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// Shared geometry for every header tab. The active outline uses an inset shadow
|
|
176
|
-
// (not a border) so the box keeps the exact h-7 footprint — no 1px layout shift.
|
|
177
|
-
// Labels never wrap and the leading icon never shrinks, so a long view name keeps
|
|
178
|
-
// its full footprint. No color transition: switching tabs swaps the bg/border
|
|
179
|
-
// instantly.
|
|
180
|
-
const TAB_BASE =
|
|
181
|
-
"inline-flex h-7 cursor-pointer items-center gap-1.5 rounded-md px-2.5 text-sm font-medium whitespace-nowrap [&_svg]:size-[18px] [&_svg]:shrink-0";
|
|
182
|
-
|
|
183
|
-
// Square (w = h) geometry modifier for icon-only triggers.
|
|
184
|
-
const ICON_TAB_SQUARE = "size-7 justify-center px-0";
|
|
185
|
-
|
|
186
|
-
// Labeled tabs (and the chat icon) keep a constant foreground text color; only
|
|
187
|
-
// the background and (when active) the inset-shadow border change between states.
|
|
188
|
-
const tabClass = (isActive: boolean) =>
|
|
189
|
-
cn(
|
|
190
|
-
TAB_BASE,
|
|
191
|
-
"text-foreground",
|
|
192
|
-
isActive ? "bg-muted shadow-[inset_0_0_0_1px_var(--border)]" : "hover:bg-muted/60",
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
// The "…" overflow trigger stays gray until active/hovered — it doesn't follow
|
|
196
|
-
// the always-foreground rule the labeled tabs use.
|
|
197
|
-
const iconTabClass = (isActive: boolean) =>
|
|
198
|
-
cn(
|
|
199
|
-
TAB_BASE,
|
|
200
|
-
ICON_TAB_SQUARE,
|
|
201
|
-
isActive
|
|
202
|
-
? "bg-muted text-foreground shadow-[inset_0_0_0_1px_var(--border)]"
|
|
203
|
-
: "text-muted-foreground hover:bg-muted/60 hover:text-foreground",
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
// A collapsible tab. `kind` groups the overflow menu: predefined tabs (widgets,
|
|
207
|
-
// canvas) sit above the custom views, separated by a divider.
|
|
208
|
-
type TabItem = {
|
|
209
|
-
key: WorkspaceNav;
|
|
210
|
-
Icon: typeof IconMessageCircle;
|
|
211
|
-
label: string;
|
|
212
|
-
kind: "fixed" | "view";
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
type OverflowTabsProps = {
|
|
216
|
-
tabs: TabItem[];
|
|
217
|
-
active: WorkspaceNav;
|
|
218
|
-
onSelect: (nav: WorkspaceNav) => void;
|
|
219
|
-
onCreateView: () => void;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
// A horizontal strip of tabs that fills its available width and folds whatever
|
|
223
|
-
// doesn't fit into a trailing "…" menu, recomputing on resize. It measures each
|
|
224
|
-
// tab's natural width with a hidden mirror row (container queries can't see
|
|
225
|
-
// variable label widths), tracks its own width via a ResizeObserver, then shows
|
|
226
|
-
// as many tabs as fit and hides the rest — rightmost first — into the menu.
|
|
227
|
-
function OverflowTabs({ tabs, active, onSelect, onCreateView }: OverflowTabsProps) {
|
|
228
|
-
const rootRef = useRef<HTMLDivElement>(null);
|
|
229
|
-
const mirrorRefs = useRef<(HTMLButtonElement | null)[]>([]);
|
|
230
|
-
const menuRef = useRef<HTMLButtonElement>(null);
|
|
231
|
-
const [avail, setAvail] = useState(0);
|
|
232
|
-
const [widths, setWidths] = useState<{ items: number[]; menu: number }>({ items: [], menu: 0 });
|
|
233
|
-
|
|
234
|
-
// Re-measure natural widths whenever the set of tabs (or their labels) changes.
|
|
235
|
-
const sig = tabs.map((t) => `${t.key}:${t.label}`).join("|");
|
|
236
|
-
useLayoutEffect(() => {
|
|
237
|
-
setWidths({
|
|
238
|
-
items: tabs.map((_, i) => mirrorRefs.current[i]?.offsetWidth ?? 0),
|
|
239
|
-
menu: menuRef.current?.offsetWidth ?? 0,
|
|
240
|
-
});
|
|
241
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
242
|
-
}, [sig]);
|
|
243
|
-
|
|
244
|
-
// Track the strip's available width (it grows to fill the header's slack).
|
|
245
|
-
useLayoutEffect(() => {
|
|
246
|
-
const el = rootRef.current;
|
|
247
|
-
if (!el) return;
|
|
248
|
-
const update = () => setAvail(el.clientWidth);
|
|
249
|
-
update();
|
|
250
|
-
const ro = new ResizeObserver(update);
|
|
251
|
-
ro.observe(el);
|
|
252
|
-
return () => ro.disconnect();
|
|
253
|
-
}, []);
|
|
254
|
-
|
|
255
|
-
// How many tabs fit: the "…" trigger is always reserved, then add tabs L→R
|
|
256
|
-
// while they fit. GAP mirrors the `gap-1` (4px) between buttons.
|
|
257
|
-
const visibleCount = useMemo(() => {
|
|
258
|
-
const GAP = 4;
|
|
259
|
-
if (!avail || widths.items.length !== tabs.length) return tabs.length;
|
|
260
|
-
let used = widths.menu;
|
|
261
|
-
let count = 0;
|
|
262
|
-
for (const w of widths.items) {
|
|
263
|
-
if (used + w + GAP <= avail) {
|
|
264
|
-
used += w + GAP;
|
|
265
|
-
count++;
|
|
266
|
-
} else break;
|
|
267
|
-
}
|
|
268
|
-
return count;
|
|
269
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
270
|
-
}, [avail, widths, tabs.length]);
|
|
271
|
-
|
|
272
|
-
const overflow = tabs.slice(visibleCount);
|
|
273
|
-
const overflowFixed = overflow.filter((t) => t.kind === "fixed");
|
|
274
|
-
const overflowViews = overflow.filter((t) => t.kind === "view");
|
|
275
|
-
// The "…" trigger lights up when one of the folded-away tabs is the active one.
|
|
276
|
-
const overflowActive = overflow.some((t) => t.key === active);
|
|
277
|
-
|
|
278
|
-
const menuItem = ({ key, Icon, label }: TabItem) => (
|
|
279
|
-
<DropdownMenuCheckboxItem
|
|
280
|
-
key={key}
|
|
281
|
-
checked={active === key}
|
|
282
|
-
closeOnClick
|
|
283
|
-
onClick={() => onSelect(key)}
|
|
284
|
-
>
|
|
285
|
-
<Icon stroke={1.75} />
|
|
286
|
-
{label}
|
|
287
|
-
</DropdownMenuCheckboxItem>
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
return (
|
|
291
|
-
<div ref={rootRef} className="relative flex min-w-0 flex-1 items-center gap-1">
|
|
292
|
-
{/* Hidden mirror: every tab + the menu trigger at natural width, laid out
|
|
293
|
-
but invisible and out of flow, read via the refs above. */}
|
|
294
|
-
<div
|
|
295
|
-
aria-hidden
|
|
296
|
-
className="pointer-events-none invisible absolute left-0 top-0 flex items-center gap-1"
|
|
297
|
-
>
|
|
298
|
-
{tabs.map(({ key, Icon, label }, i) => (
|
|
299
|
-
<button
|
|
300
|
-
key={key}
|
|
301
|
-
ref={(el) => {
|
|
302
|
-
mirrorRefs.current[i] = el;
|
|
303
|
-
}}
|
|
304
|
-
type="button"
|
|
305
|
-
className={tabClass(false)}
|
|
306
|
-
>
|
|
307
|
-
<Icon stroke={1.75} />
|
|
308
|
-
{label}
|
|
309
|
-
</button>
|
|
310
|
-
))}
|
|
311
|
-
<button ref={menuRef} type="button" className={iconTabClass(false)}>
|
|
312
|
-
<IconDots stroke={1.75} />
|
|
313
|
-
</button>
|
|
314
|
-
</div>
|
|
315
|
-
|
|
316
|
-
{tabs.slice(0, visibleCount).map(({ key, Icon, label }) => (
|
|
317
|
-
<button
|
|
318
|
-
key={key}
|
|
319
|
-
type="button"
|
|
320
|
-
className={tabClass(active === key)}
|
|
321
|
-
onClick={() => onSelect(key)}
|
|
322
|
-
>
|
|
323
|
-
<Icon stroke={1.75} />
|
|
324
|
-
{label}
|
|
325
|
-
</button>
|
|
326
|
-
))}
|
|
327
|
-
|
|
328
|
-
<DropdownMenu>
|
|
329
|
-
<DropdownMenuTrigger
|
|
330
|
-
render={
|
|
331
|
-
<button type="button" className={iconTabClass(overflowActive)} aria-label="More views">
|
|
332
|
-
<IconDots stroke={1.75} />
|
|
333
|
-
</button>
|
|
334
|
-
}
|
|
335
|
-
/>
|
|
336
|
-
<DropdownMenuContent align="start" className="min-w-48">
|
|
337
|
-
{overflowFixed.map(menuItem)}
|
|
338
|
-
{overflowFixed.length > 0 && overflowViews.length > 0 && <DropdownMenuSeparator />}
|
|
339
|
-
{overflowViews.map(menuItem)}
|
|
340
|
-
{overflow.length > 0 && <DropdownMenuSeparator />}
|
|
341
|
-
<DropdownMenuItem onClick={onCreateView}>
|
|
342
|
-
<IconPlus stroke={1.75} />
|
|
343
|
-
Create View
|
|
344
|
-
</DropdownMenuItem>
|
|
345
|
-
</DropdownMenuContent>
|
|
346
|
-
</DropdownMenu>
|
|
347
|
-
</div>
|
|
348
|
-
);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// The workspace nav: a pinned fullscreen-chat icon, then the collapsible strip of
|
|
352
|
-
// Widgets / Scratchpad / view tabs, which folds overflow into a "…" menu.
|
|
353
|
-
function WorkspaceTabs({ active, onSelect, views, onCreateView }: WorkspaceTabsProps) {
|
|
354
|
-
const tabs: TabItem[] = [
|
|
355
|
-
{ key: "widgets", Icon: IconLayoutGrid, label: "Widgets", kind: "fixed" },
|
|
356
|
-
{ key: "canvas", Icon: IconArtboard, label: "Scratchpad", kind: "fixed" },
|
|
357
|
-
...views.map(
|
|
358
|
-
(v): TabItem => ({ key: v.id, Icon: IconAppWindow, label: viewLabel(v), kind: "view" }),
|
|
359
|
-
),
|
|
360
|
-
];
|
|
361
|
-
|
|
362
|
-
return (
|
|
363
|
-
<div className="flex min-w-0 flex-1 items-center gap-1">
|
|
364
|
-
<Tooltip delay={50}>
|
|
365
|
-
<TooltipTrigger
|
|
366
|
-
render={
|
|
367
|
-
<button
|
|
368
|
-
type="button"
|
|
369
|
-
className={cn(tabClass(active === "chat"), ICON_TAB_SQUARE, "shrink-0")}
|
|
370
|
-
onClick={() => onSelect("chat")}
|
|
371
|
-
aria-label="Open fullscreen chat"
|
|
372
|
-
>
|
|
373
|
-
<IconMessageCircle stroke={1.75} />
|
|
374
|
-
</button>
|
|
375
|
-
}
|
|
376
|
-
/>
|
|
377
|
-
<TooltipContent>Open fullscreen chat</TooltipContent>
|
|
378
|
-
</Tooltip>
|
|
379
|
-
<OverflowTabs tabs={tabs} active={active} onSelect={onSelect} onCreateView={onCreateView} />
|
|
380
|
-
</div>
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
type ViewAppProps = {
|
|
385
|
-
view: ViewInfo;
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
// A view — an agent-defined app — mounted full-area. The bundle owns its own
|
|
389
|
-
// layout + scroll, so we give it a plain filled box and fade it in (mirroring
|
|
390
|
-
// WidgetShell, but full-area instead of a grid cell).
|
|
391
|
-
function ViewApp({ view }: ViewAppProps) {
|
|
392
|
-
const bundle = useView(view.id);
|
|
393
|
-
|
|
394
|
-
return (
|
|
395
|
-
<div className="relative min-h-0 flex-1 overflow-hidden">
|
|
396
|
-
<AnimatePresence mode="wait" initial={false}>
|
|
397
|
-
{bundle.status === "ready" && (
|
|
398
|
-
<motion.div
|
|
399
|
-
key={bundle.version}
|
|
400
|
-
className="absolute inset-0 overflow-auto"
|
|
401
|
-
initial={{ opacity: 0, filter: "blur(4px)" }}
|
|
402
|
-
animate={{ opacity: 1, filter: "blur(0px)" }}
|
|
403
|
-
exit={{ opacity: 0, filter: "blur(4px)" }}
|
|
404
|
-
transition={{ duration: 0.3, ease: "easeInOut" }}
|
|
405
|
-
>
|
|
406
|
-
<WidgetErrorBoundary name={view.id} resetKey={bundle.version}>
|
|
407
|
-
<bundle.Component />
|
|
408
|
-
</WidgetErrorBoundary>
|
|
409
|
-
</motion.div>
|
|
410
|
-
)}
|
|
411
|
-
{bundle.status === "error" && (
|
|
412
|
-
<motion.p
|
|
413
|
-
key={`err-${bundle.version}`}
|
|
414
|
-
className="text-destructive absolute inset-0 p-4 text-xs"
|
|
415
|
-
initial={{ opacity: 0 }}
|
|
416
|
-
animate={{ opacity: 1 }}
|
|
417
|
-
exit={{ opacity: 0 }}
|
|
418
|
-
transition={{ duration: 0.3, ease: "easeInOut" }}
|
|
419
|
-
>
|
|
420
|
-
{bundle.error}
|
|
421
|
-
</motion.p>
|
|
422
|
-
)}
|
|
423
|
-
</AnimatePresence>
|
|
424
|
-
</div>
|
|
425
|
-
);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
type WidgetActionsProps = {
|
|
429
|
-
mode: WidgetMode;
|
|
430
|
-
onMode: (mode: WidgetMode) => void;
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
// Widget controls — live in the page header (right side), always visible.
|
|
434
|
-
function WidgetActions({ mode, onMode }: WidgetActionsProps) {
|
|
435
|
-
return (
|
|
436
|
-
<AnimatePresence mode="popLayout" initial={false}>
|
|
437
|
-
{mode !== "idle" ? (
|
|
438
|
-
<motion.div
|
|
439
|
-
key="done"
|
|
440
|
-
variants={ACTION_VARIANTS}
|
|
441
|
-
initial="from"
|
|
442
|
-
animate="to"
|
|
443
|
-
exit="from"
|
|
444
|
-
transition={{ type: "spring", duration: 0.3, bounce: 0 }}
|
|
445
|
-
>
|
|
446
|
-
<Button onClick={() => onMode("idle")}>Done</Button>
|
|
447
|
-
</motion.div>
|
|
448
|
-
) : (
|
|
449
|
-
<motion.div
|
|
450
|
-
key="actions"
|
|
451
|
-
className="flex items-center gap-1"
|
|
452
|
-
variants={ACTION_VARIANTS}
|
|
453
|
-
initial="from"
|
|
454
|
-
animate="to"
|
|
455
|
-
exit="from"
|
|
456
|
-
transition={{ type: "spring", duration: 0.3, bounce: 0 }}
|
|
457
|
-
>
|
|
458
|
-
<Button
|
|
459
|
-
variant="ghost"
|
|
460
|
-
className="h-7 text-muted-foreground @max-3xl:px-1.5! [&_svg]:size-[18px]"
|
|
461
|
-
onClick={() => onMode("customizing")}
|
|
462
|
-
>
|
|
463
|
-
<IconPalette stroke={1.75} />
|
|
464
|
-
<span className="@max-3xl:hidden">Customize</span>
|
|
465
|
-
</Button>
|
|
466
|
-
<Button
|
|
467
|
-
variant="ghost"
|
|
468
|
-
className="h-7 text-muted-foreground @max-3xl:px-1.5! [&_svg]:size-[18px]"
|
|
469
|
-
onClick={() => onMode("editing")}
|
|
470
|
-
>
|
|
471
|
-
<IconLayoutDashboard stroke={1.75} />
|
|
472
|
-
<span className="@max-3xl:hidden">Edit widgets</span>
|
|
473
|
-
</Button>
|
|
474
|
-
</motion.div>
|
|
475
|
-
)}
|
|
476
|
-
</AnimatePresence>
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
type WorkspaceViewProps = {
|
|
481
|
-
widgets: WidgetInfo[];
|
|
482
|
-
views: ViewInfo[];
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
function WorkspaceView({ widgets, views }: WorkspaceViewProps) {
|
|
486
|
-
const {
|
|
487
|
-
view,
|
|
488
|
-
previewTurn,
|
|
489
|
-
sessionId,
|
|
490
|
-
processing,
|
|
491
|
-
error,
|
|
492
|
-
send,
|
|
493
|
-
stop,
|
|
494
|
-
switchThread,
|
|
495
|
-
dismissError,
|
|
496
|
-
} = useChat();
|
|
497
|
-
const { layout, setLayout, name, icon, provider } = useWorkspaceLayoutCtx();
|
|
498
|
-
const { ref: rowRef, fits: canFitSidebar } = useFitsSidebar<HTMLDivElement>();
|
|
499
|
-
const [widgetMode, setWidgetMode] = useState<WidgetMode>("idle");
|
|
500
|
-
// Two orthogonal, transient local bits: which body is selected (a fixed tab or
|
|
501
|
-
// a view id), and whether the chat is fullscreen. Fullscreen overrides (never
|
|
502
|
-
// persists) the chat's dock position, and toggling it keeps the body beneath.
|
|
503
|
-
const [bodyTab, setBodyTab] = useState<string>("widgets");
|
|
504
|
-
const [fullscreen, setFullscreen] = useState(false);
|
|
505
|
-
|
|
506
|
-
// Theme is scoped to this wrapper, not :root — the sidebar keeps the default
|
|
507
|
-
// tokens. The floating chat portals into the same element so it inherits them.
|
|
508
|
-
const themeRef = useRef<HTMLDivElement>(null);
|
|
509
|
-
useWorkspaceTheme(layout.theme, themeRef);
|
|
510
|
-
|
|
511
|
-
const hasWidgets = widgets.length > 0;
|
|
512
|
-
// The persisted position switch (sidebar ⇄ floating) only matters with widgets
|
|
513
|
-
// to dock beside; a solo chat is always fullscreen.
|
|
514
|
-
const canChangeChatMode = hasWidgets;
|
|
515
|
-
|
|
516
|
-
// How the chat is shown: fullscreen (the chat view, or a solo chat), otherwise
|
|
517
|
-
// its persisted position — sidebar, or floating (also the fallback when a
|
|
518
|
-
// docked sidebar no longer fits). Fullscreen never touches the saved position.
|
|
519
|
-
const display: ChatDisplay =
|
|
520
|
-
!hasWidgets || fullscreen
|
|
521
|
-
? "fullscreen"
|
|
522
|
-
: layout.chatMode === "floating" || !canFitSidebar
|
|
523
|
-
? "floating"
|
|
524
|
-
: "sidebar";
|
|
525
|
-
|
|
526
|
-
// The nav highlights whatever fills the main area.
|
|
527
|
-
const activeNav: WorkspaceNav = display === "fullscreen" ? "chat" : bodyTab;
|
|
528
|
-
|
|
529
|
-
// Nav tabs: "chat" goes fullscreen; a body tab (widgets / canvas / view id)
|
|
530
|
-
// leaves fullscreen and shows it.
|
|
531
|
-
const selectNav = (v: WorkspaceNav) => {
|
|
532
|
-
if (v === "chat") setFullscreen(true);
|
|
533
|
-
else {
|
|
534
|
-
setBodyTab(v);
|
|
535
|
-
setFullscreen(false);
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
// "Create View" is a no-op for now — views are authored by the agent via the
|
|
540
|
-
// CLI (`.moi/views/<name>.tsx` + `moi bundle`), not from the UI.
|
|
541
|
-
const createView = () => {};
|
|
542
|
-
// The active view, when a view (not a fixed tab) fills the main area.
|
|
543
|
-
const activeView = views.find((v) => v.id === bodyTab);
|
|
544
|
-
|
|
545
|
-
// If the active view's file was deleted (its bundle vanished from the list),
|
|
546
|
-
// `bodyTab` dangles — fall back to the widget grid so nothing renders blank.
|
|
547
|
-
const isViewTab = bodyTab !== "widgets" && bodyTab !== "canvas";
|
|
548
|
-
useEffect(() => {
|
|
549
|
-
if (isViewTab && !activeView) setBodyTab("widgets");
|
|
550
|
-
}, [isViewTab, activeView]);
|
|
551
|
-
|
|
552
|
-
// The chat-mode picker switches the display: fullscreen is the transient view;
|
|
553
|
-
// sidebar/floating persist the dock position (and leave fullscreen).
|
|
554
|
-
const handleModeChange = canChangeChatMode
|
|
555
|
-
? (mode: ChatDisplay) => {
|
|
556
|
-
if (mode === "fullscreen") setFullscreen(true);
|
|
557
|
-
else {
|
|
558
|
-
setLayout({ chatMode: mode });
|
|
559
|
-
setFullscreen(false);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
: undefined;
|
|
563
|
-
|
|
564
|
-
const chatPanel = (
|
|
565
|
-
<ChatPanel
|
|
566
|
-
view={view}
|
|
567
|
-
previewTurn={previewTurn}
|
|
568
|
-
sessionId={sessionId}
|
|
569
|
-
processing={processing}
|
|
570
|
-
error={error}
|
|
571
|
-
onDismissError={dismissError}
|
|
572
|
-
send={send}
|
|
573
|
-
stop={stop}
|
|
574
|
-
chatMode={display}
|
|
575
|
-
onSwitchThread={switchThread}
|
|
576
|
-
onModeChange={handleModeChange}
|
|
577
|
-
onCollapse={() => setLayout({ chatMode: "floating" })}
|
|
578
|
-
/>
|
|
579
|
-
);
|
|
580
|
-
|
|
581
|
-
return (
|
|
582
|
-
// Themed wrapper: scoped CSS vars (bg/fg/font) live here so the panel — and
|
|
583
|
-
// the portaled floating chat — pick up the workspace theme, while the
|
|
584
|
-
// sidebar outside stays default.
|
|
585
|
-
<div
|
|
586
|
-
ref={themeRef}
|
|
587
|
-
className="bg-background text-foreground flex h-full min-h-0 flex-col font-sans"
|
|
588
|
-
>
|
|
589
|
-
{/* One shared header always sits atop the main content area, whose body is
|
|
590
|
-
the chat (fullscreen), the widget grid, or the scratchpad per the active
|
|
591
|
-
nav. A docked chat is an extra column beside it. rowRef stays mounted so
|
|
592
|
-
the sidebar-fit measurement (full panel width) survives mode switches. */}
|
|
593
|
-
<div ref={rowRef} className="flex min-h-0 flex-1">
|
|
594
|
-
<div
|
|
595
|
-
className={cn(
|
|
596
|
-
"flex min-h-0 flex-1 flex-col",
|
|
597
|
-
// Border + min width only while a chat docks beside the main area.
|
|
598
|
-
display !== "fullscreen" && "border-border min-w-[var(--column-w)] border-r",
|
|
599
|
-
)}
|
|
600
|
-
>
|
|
601
|
-
<PanelHeader>
|
|
602
|
-
<SidebarToggle />
|
|
603
|
-
<img
|
|
604
|
-
src={icon ?? PROVIDER_ICON[provider ?? "claude-code"]}
|
|
605
|
-
alt=""
|
|
606
|
-
className="size-5 shrink-0 rounded-[4px]"
|
|
607
|
-
/>
|
|
608
|
-
{name && <span className="text-foreground truncate text-sm font-medium">{name}</span>}
|
|
609
|
-
{hasWidgets ? (
|
|
610
|
-
<>
|
|
611
|
-
<span className="text-muted-foreground/40 select-none text-sm">/</span>
|
|
612
|
-
{/* The tabs strip grows to fill the header's slack and measures
|
|
613
|
-
its own width to fold overflow into the "…" menu, so it owns
|
|
614
|
-
the spacer role here. */}
|
|
615
|
-
<WorkspaceTabs
|
|
616
|
-
active={activeNav}
|
|
617
|
-
onSelect={selectNav}
|
|
618
|
-
views={views}
|
|
619
|
-
onCreateView={createView}
|
|
620
|
-
/>
|
|
621
|
-
</>
|
|
622
|
-
) : (
|
|
623
|
-
<div className="flex-1" />
|
|
624
|
-
)}
|
|
625
|
-
{activeNav === "widgets" && <WidgetActions mode={widgetMode} onMode={setWidgetMode} />}
|
|
626
|
-
<McpMenu />
|
|
627
|
-
<WorkspaceSettings />
|
|
628
|
-
</PanelHeader>
|
|
629
|
-
|
|
630
|
-
{activeNav === "chat" ? (
|
|
631
|
-
<div className="flex min-h-0 flex-1 flex-col overflow-hidden">{chatPanel}</div>
|
|
632
|
-
) : activeNav === "widgets" ? (
|
|
633
|
-
<Widgets mode={widgetMode} widgets={widgets} />
|
|
634
|
-
) : activeNav === "canvas" ? (
|
|
635
|
-
<Scratchpad />
|
|
636
|
-
) : activeView ? (
|
|
637
|
-
<ViewApp view={activeView} />
|
|
638
|
-
) : null}
|
|
639
|
-
</div>
|
|
640
|
-
|
|
641
|
-
{display === "sidebar" && (
|
|
642
|
-
// Docked chat: caps at --chat-max on big screens (grow 0), shrinks down
|
|
643
|
-
// to --chat-min before the fit check flips it to floating.
|
|
644
|
-
<div className="flex min-h-0 min-w-[var(--chat-min)] flex-[0_1_var(--chat-max)] flex-col overflow-hidden">
|
|
645
|
-
<div className="flex min-h-0 w-full flex-1 flex-col">{chatPanel}</div>
|
|
646
|
-
</div>
|
|
647
|
-
)}
|
|
648
|
-
</div>
|
|
649
|
-
|
|
650
|
-
{display === "floating" && (
|
|
651
|
-
<ChatPopup
|
|
652
|
-
defaultOpen={layout.chatMode === "floating" && canFitSidebar}
|
|
653
|
-
container={themeRef}
|
|
654
|
-
>
|
|
655
|
-
{(onClose) => (
|
|
656
|
-
<ChatPanel
|
|
657
|
-
view={view}
|
|
658
|
-
previewTurn={previewTurn}
|
|
659
|
-
sessionId={sessionId}
|
|
660
|
-
processing={processing}
|
|
661
|
-
error={error}
|
|
662
|
-
onDismissError={dismissError}
|
|
663
|
-
send={send}
|
|
664
|
-
stop={stop}
|
|
665
|
-
chatMode={display}
|
|
666
|
-
onSwitchThread={switchThread}
|
|
667
|
-
onModeChange={handleModeChange}
|
|
668
|
-
onClose={onClose}
|
|
669
|
-
/>
|
|
670
|
-
)}
|
|
671
|
-
</ChatPopup>
|
|
672
|
-
)}
|
|
673
|
-
</div>
|
|
674
|
-
);
|
|
675
|
-
}
|