moi-computer 0.3.0-next.1 → 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/main.tsx +2 -2
- package/client/runtime/hmr-watchdog.ts +39 -0
- package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +9 -6
- 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 +119 -14
- 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/web.ts +1 -0
- 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 -238
- package/dist/chunk-07qf2tv1.css +0 -1
- package/dist/chunk-w18801vn.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
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { IconPlus, IconX, type TablerIcon } from '@tabler/icons-react'
|
|
2
|
+
import { cva } from 'class-variance-authority'
|
|
3
|
+
|
|
4
|
+
import { ReorderableList } from '@/client/components/shared/ReorderableList'
|
|
5
|
+
import type { ReorderableRenderState } from '@/client/components/shared/ReorderableList'
|
|
6
|
+
import { Button, buttonVariants } from '@/client/components/ui/button'
|
|
7
|
+
import {
|
|
8
|
+
DropdownMenu,
|
|
9
|
+
DropdownMenuContent,
|
|
10
|
+
DropdownMenuGroup,
|
|
11
|
+
DropdownMenuItem,
|
|
12
|
+
DropdownMenuTrigger
|
|
13
|
+
} from '@/client/components/ui/dropdown-menu'
|
|
14
|
+
import { cn } from '@/client/lib/cn'
|
|
15
|
+
import type { WorkspaceTabId } from '@/lib/types'
|
|
16
|
+
|
|
17
|
+
export type WorkspaceTabItem = {
|
|
18
|
+
key: WorkspaceTabId
|
|
19
|
+
Icon: TablerIcon
|
|
20
|
+
label: string
|
|
21
|
+
closable?: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type CreateWorkspaceTabItem = {
|
|
25
|
+
key: string
|
|
26
|
+
Icon: TablerIcon
|
|
27
|
+
label: string
|
|
28
|
+
onClick: () => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type WorkspaceTabsProps = {
|
|
32
|
+
tabs: WorkspaceTabItem[]
|
|
33
|
+
active: WorkspaceTabId
|
|
34
|
+
createItems: CreateWorkspaceTabItem[]
|
|
35
|
+
onSelect: (tab: WorkspaceTabId) => void
|
|
36
|
+
onClose: (tab: WorkspaceTabId) => void
|
|
37
|
+
onReorder: (ordered: WorkspaceTabId[]) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const workspaceTabVariants = cva(
|
|
41
|
+
[buttonVariants({ variant: 'ghost', size: 'sm' }), 'group/tab min-w-0'],
|
|
42
|
+
{
|
|
43
|
+
variants: {
|
|
44
|
+
active: {
|
|
45
|
+
true: 'bg-accent text-accent-foreground'
|
|
46
|
+
},
|
|
47
|
+
dragging: {
|
|
48
|
+
true: 'invisible'
|
|
49
|
+
},
|
|
50
|
+
preview: {
|
|
51
|
+
true: 'cursor-grabbing ring-1 ring-border'
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
compoundVariants: [{ preview: true }]
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
function CreateTabMenu({ items }: { items: CreateWorkspaceTabItem[] }) {
|
|
59
|
+
return (
|
|
60
|
+
<DropdownMenu>
|
|
61
|
+
<DropdownMenuTrigger
|
|
62
|
+
render={
|
|
63
|
+
<Button
|
|
64
|
+
type="button"
|
|
65
|
+
variant="ghost"
|
|
66
|
+
size="icon-sm"
|
|
67
|
+
className="text-muted-foreground"
|
|
68
|
+
aria-label="Create tab"
|
|
69
|
+
>
|
|
70
|
+
<IconPlus stroke={1.75} />
|
|
71
|
+
</Button>
|
|
72
|
+
}
|
|
73
|
+
/>
|
|
74
|
+
<DropdownMenuContent align="start" className="min-w-48">
|
|
75
|
+
<DropdownMenuGroup>
|
|
76
|
+
{items.map(({ key, Icon, label, onClick }) => (
|
|
77
|
+
<DropdownMenuItem key={key} onClick={onClick}>
|
|
78
|
+
<Icon stroke={1.75} />
|
|
79
|
+
{label}
|
|
80
|
+
</DropdownMenuItem>
|
|
81
|
+
))}
|
|
82
|
+
</DropdownMenuGroup>
|
|
83
|
+
</DropdownMenuContent>
|
|
84
|
+
</DropdownMenu>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type WorkspaceTabBaseProps = {
|
|
89
|
+
tab: WorkspaceTabItem
|
|
90
|
+
active: boolean
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type WorkspaceTabProps = WorkspaceTabBaseProps &
|
|
94
|
+
(
|
|
95
|
+
| {
|
|
96
|
+
preview: true
|
|
97
|
+
state?: never
|
|
98
|
+
onSelect?: never
|
|
99
|
+
onClose?: never
|
|
100
|
+
}
|
|
101
|
+
| {
|
|
102
|
+
preview?: false
|
|
103
|
+
state: ReorderableRenderState
|
|
104
|
+
onSelect: (tab: WorkspaceTabId) => void
|
|
105
|
+
onClose: (tab: WorkspaceTabId) => void
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
function WorkspaceTab(props: WorkspaceTabProps) {
|
|
110
|
+
const { tab, active } = props
|
|
111
|
+
const preview = props.preview === true
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<button
|
|
115
|
+
type="button"
|
|
116
|
+
aria-hidden={preview || undefined}
|
|
117
|
+
aria-label={tab.label}
|
|
118
|
+
disabled={preview}
|
|
119
|
+
tabIndex={preview ? -1 : undefined}
|
|
120
|
+
onClick={props.preview ? undefined : () => props.onSelect(tab.key)}
|
|
121
|
+
className={workspaceTabVariants({
|
|
122
|
+
active,
|
|
123
|
+
dragging: props.preview ? false : props.state.isDragging,
|
|
124
|
+
preview
|
|
125
|
+
})}
|
|
126
|
+
{...(props.preview ? {} : props.state.dragHandleProps)}
|
|
127
|
+
>
|
|
128
|
+
<div
|
|
129
|
+
className={cn(
|
|
130
|
+
'flex items-center gap-1 overflow-hidden',
|
|
131
|
+
tab.closable && 'group-hover/tab:mr-3'
|
|
132
|
+
)}
|
|
133
|
+
>
|
|
134
|
+
<tab.Icon data-icon="inline-start" stroke={1.75} />
|
|
135
|
+
<span
|
|
136
|
+
className={cn(
|
|
137
|
+
'truncate',
|
|
138
|
+
tab.closable &&
|
|
139
|
+
'group-hover/tab:-mr-3 group-hover/tab:mask-r-from-[calc(100%-24px)] group-hover/tab:mask-r-to-[calc(100%-12px)]'
|
|
140
|
+
)}
|
|
141
|
+
>
|
|
142
|
+
{tab.label}
|
|
143
|
+
</span>
|
|
144
|
+
</div>
|
|
145
|
+
{tab.closable && (
|
|
146
|
+
<div
|
|
147
|
+
aria-label={`Close ${tab.label}`}
|
|
148
|
+
tabIndex={preview ? -1 : undefined}
|
|
149
|
+
className={cn(
|
|
150
|
+
'absolute right-2 hidden size-3 items-center justify-center text-muted-foreground group-hover/tab:flex hover:text-foreground',
|
|
151
|
+
preview && 'pointer-events-none'
|
|
152
|
+
)}
|
|
153
|
+
onClick={
|
|
154
|
+
props.preview
|
|
155
|
+
? undefined
|
|
156
|
+
: event => {
|
|
157
|
+
event.stopPropagation()
|
|
158
|
+
props.onClose(tab.key)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
>
|
|
162
|
+
<IconX stroke={1.75} />
|
|
163
|
+
</div>
|
|
164
|
+
)}
|
|
165
|
+
</button>
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function WorkspaceTabs({
|
|
170
|
+
tabs,
|
|
171
|
+
active,
|
|
172
|
+
createItems,
|
|
173
|
+
onSelect,
|
|
174
|
+
onClose,
|
|
175
|
+
onReorder
|
|
176
|
+
}: WorkspaceTabsProps) {
|
|
177
|
+
return (
|
|
178
|
+
<div className="flex min-w-0 flex-1 items-center gap-1">
|
|
179
|
+
<div className="scrollbar-none min-w-0 scroll-fade-x overflow-x-auto overflow-y-hidden [--scroll-fade-reveal:16px]">
|
|
180
|
+
<ReorderableList
|
|
181
|
+
items={tabs}
|
|
182
|
+
getId={tab => tab.key}
|
|
183
|
+
className="flex w-max items-center gap-1"
|
|
184
|
+
onReorder={ordered => onReorder(ordered as WorkspaceTabId[])}
|
|
185
|
+
renderPlaceholder={() => (
|
|
186
|
+
<div className="pointer-events-none absolute inset-0 rounded-xs bg-muted" />
|
|
187
|
+
)}
|
|
188
|
+
renderOverlay={tab => <WorkspaceTab tab={tab} active={active === tab.key} preview />}
|
|
189
|
+
renderItem={(tab, state) => (
|
|
190
|
+
<WorkspaceTab
|
|
191
|
+
tab={tab}
|
|
192
|
+
active={active === tab.key}
|
|
193
|
+
state={state}
|
|
194
|
+
onSelect={onSelect}
|
|
195
|
+
onClose={onClose}
|
|
196
|
+
/>
|
|
197
|
+
)}
|
|
198
|
+
/>
|
|
199
|
+
</div>
|
|
200
|
+
<div className="shrink-0">
|
|
201
|
+
<CreateTabMenu items={createItems} />
|
|
202
|
+
</div>
|
|
203
|
+
</div>
|
|
204
|
+
)
|
|
205
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query'
|
|
2
|
+
|
|
3
|
+
import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
|
|
4
|
+
import { WORKSPACE_RESOURCE_OPTIONS } from '@/client/api/query-options'
|
|
5
|
+
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
6
|
+
import type { ViewInfo, WidgetInfo, WorkspaceLayout, WorkspaceType } from '@/lib/types'
|
|
7
|
+
|
|
8
|
+
export type WorkspaceLayoutResponse = WorkspaceLayout & {
|
|
9
|
+
cwd: string
|
|
10
|
+
name: string
|
|
11
|
+
provider?: WorkspaceType
|
|
12
|
+
agentId?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useWorkspaceLayout(workspaceId: string) {
|
|
16
|
+
return useQuery<WorkspaceLayoutResponse>({
|
|
17
|
+
queryKey: workspaceKeys.layout(workspaceId),
|
|
18
|
+
queryFn: () => requestJson(`/api/workspaces/${workspaceId}`),
|
|
19
|
+
...WORKSPACE_RESOURCE_OPTIONS
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function useWorkspaceWidgets(workspaceId: string) {
|
|
24
|
+
return useQuery<WidgetInfo[]>({
|
|
25
|
+
queryKey: workspaceKeys.widgets(workspaceId),
|
|
26
|
+
queryFn: async () => {
|
|
27
|
+
const data = await requestJson<{ widgets: WidgetInfo[] }>(
|
|
28
|
+
`/api/workspaces/${workspaceId}/widgets`
|
|
29
|
+
)
|
|
30
|
+
return data.widgets
|
|
31
|
+
},
|
|
32
|
+
...WORKSPACE_RESOURCE_OPTIONS
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function useWorkspaceViews(workspaceId: string) {
|
|
37
|
+
return useQuery<ViewInfo[]>({
|
|
38
|
+
queryKey: workspaceKeys.views(workspaceId),
|
|
39
|
+
queryFn: async () => {
|
|
40
|
+
const data = await requestJson<{ views: ViewInfo[] }>(`/api/workspaces/${workspaceId}/views`)
|
|
41
|
+
return data.views
|
|
42
|
+
},
|
|
43
|
+
...WORKSPACE_RESOURCE_OPTIONS
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function useSaveLayout(workspaceId: string) {
|
|
48
|
+
return useMutation<void, Error, WorkspaceLayout>({
|
|
49
|
+
mutationFn: layout =>
|
|
50
|
+
requestVoid(
|
|
51
|
+
`/api/workspaces/${workspaceId}`,
|
|
52
|
+
jsonRequest('PUT', layout),
|
|
53
|
+
'Failed to save layout'
|
|
54
|
+
)
|
|
55
|
+
})
|
|
56
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
function tokenPx(name: string): number {
|
|
4
|
+
const root = document.documentElement
|
|
5
|
+
const raw = getComputedStyle(root).getPropertyValue(name).trim()
|
|
6
|
+
const value = Number.parseFloat(raw)
|
|
7
|
+
if (!Number.isFinite(value)) return 0
|
|
8
|
+
return raw.endsWith('rem') ? value * Number.parseFloat(getComputedStyle(root).fontSize) : value
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Observe the full workspace row, not either pane, so split-fit measurement does
|
|
12
|
+
// not oscillate when the chat column appears or disappears.
|
|
13
|
+
export function useFitsSplitLayout<T extends HTMLElement>() {
|
|
14
|
+
const ref = useRef<T>(null)
|
|
15
|
+
const [fits, setFits] = useState(false)
|
|
16
|
+
|
|
17
|
+
useLayoutEffect(() => {
|
|
18
|
+
const el = ref.current
|
|
19
|
+
if (!el) return
|
|
20
|
+
|
|
21
|
+
const update = (width: number) => {
|
|
22
|
+
const columnWidth = tokenPx('--column-w')
|
|
23
|
+
const chatMin = tokenPx('--chat-min')
|
|
24
|
+
setFits(width - chatMin >= columnWidth)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
update(el.getBoundingClientRect().width)
|
|
28
|
+
|
|
29
|
+
const ro = new ResizeObserver(([entry]) => {
|
|
30
|
+
if (entry) update(entry.contentRect.width)
|
|
31
|
+
})
|
|
32
|
+
ro.observe(el)
|
|
33
|
+
return () => ro.disconnect()
|
|
34
|
+
}, [])
|
|
35
|
+
|
|
36
|
+
return { ref, fits }
|
|
37
|
+
}
|
package/client/index.css
CHANGED
|
@@ -22,21 +22,19 @@
|
|
|
22
22
|
--popover-foreground: oklch(0.145 0 0);
|
|
23
23
|
--primary: oklch(0.205 0 0);
|
|
24
24
|
--primary-foreground: oklch(0.985 0 0);
|
|
25
|
-
--secondary: oklch(0.97 0 0);
|
|
26
|
-
--secondary-foreground: oklch(0.205 0 0);
|
|
27
25
|
--muted: oklch(0.97 0 0);
|
|
28
26
|
--muted-foreground: oklch(0.64 0 0);
|
|
29
|
-
--accent: oklch(0
|
|
27
|
+
--accent: oklch(0 0 0 / 0.07);
|
|
30
28
|
--accent-foreground: oklch(0.205 0 0);
|
|
31
29
|
--destructive: oklch(0.58 0.22 27);
|
|
32
|
-
--border: oklch(0
|
|
30
|
+
--border: oklch(0 0 0 / 0.07);
|
|
33
31
|
--input: oklch(0.922 0 0);
|
|
34
32
|
--ring: oklch(0.708 0 0);
|
|
35
33
|
--radius: 1rem;
|
|
36
34
|
|
|
37
35
|
/* Workspace page layout — single source of truth for the widget/chat panel.
|
|
38
|
-
Read by routes/workspace/[id].tsx
|
|
39
|
-
|
|
36
|
+
Read by routes/workspace/[id].tsx; don't hardcode equivalents. (The app
|
|
37
|
+
sidebar's own widths live in SidebarLayout.tsx.) */
|
|
40
38
|
--page-pad: 2rem; /* padding around the working area */
|
|
41
39
|
--column-w: 40rem; /* grid content width; also the widget area's min before the chat yields */
|
|
42
40
|
--chat-min: 380px; /* docked chat min width — narrower than this and it floats */
|
|
@@ -65,14 +63,12 @@
|
|
|
65
63
|
--popover-foreground: oklch(0.985 0 0);
|
|
66
64
|
--primary: oklch(0.985 0 0);
|
|
67
65
|
--primary-foreground: oklch(0.205 0 0);
|
|
68
|
-
--secondary: oklch(0.269 0 0);
|
|
69
|
-
--secondary-foreground: oklch(0.985 0 0);
|
|
70
66
|
--muted: oklch(0.269 0 0);
|
|
71
67
|
--muted-foreground: oklch(0.708 0 0);
|
|
72
|
-
--accent: oklch(0
|
|
68
|
+
--accent: oklch(1 0 0 / 0.1);
|
|
73
69
|
--accent-foreground: oklch(0.985 0 0);
|
|
74
70
|
--destructive: oklch(0.58 0.22 27);
|
|
75
|
-
--border: oklch(0
|
|
71
|
+
--border: oklch(1 0 0 / 0.1);
|
|
76
72
|
--input: oklch(0.35 0 0);
|
|
77
73
|
--ring: oklch(0.556 0 0);
|
|
78
74
|
}
|
package/client/index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>moi
|
|
6
|
+
<title>moi</title>
|
|
7
7
|
<link rel="icon" type="image/png" href="./assets/favicon.png" />
|
|
8
8
|
<!-- React is vendored locally (client/vendor/react, generated by
|
|
9
9
|
scripts/build-vendor.ts) and served by the /vendor/react route, so Moi
|
package/client/index.tsx
CHANGED
|
@@ -3,38 +3,21 @@ import './structured-clone-shim'
|
|
|
3
3
|
|
|
4
4
|
import './index.css'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
// + the importmap in index.html → /vendor/react), so Bun's bundled Fast Refresh
|
|
8
|
-
// runtime isn't bound to the React
|
|
9
|
-
// instance that actually renders the app: it registers component families but
|
|
10
|
-
// performReactRefresh() no-ops, leaving stale modules mounted after an edit.
|
|
11
|
-
// Downgrade HMR to plain live-reload — every hot update triggers a full page
|
|
12
|
-
// reload, which re-fetches a clean bundle. Dead-code-eliminated in production.
|
|
13
|
-
if (import.meta.hot) {
|
|
14
|
-
import.meta.hot.on('bun:beforeUpdate', () => location.reload())
|
|
6
|
+
import { startHmrWatchdog } from './runtime/hmr-watchdog'
|
|
15
7
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
}
|
|
8
|
+
// React Fast Refresh works here despite React being externalized to the
|
|
9
|
+
// locally-vendored ESM (client/externalize-react.ts + the importmap in
|
|
10
|
+
// index.html → /vendor/react): Bun's bundled refresh runtime wraps
|
|
11
|
+
// `__REACT_DEVTOOLS_GLOBAL_HOOK__` before the vendored react-dom registers,
|
|
12
|
+
// and the hook is a plain global, so the renderer link works across the
|
|
13
|
+
// bundle/vendor boundary. The one missing piece was that the externalized
|
|
14
|
+
// virtual modules (`esm:react/jsx-dev-runtime` etc.) were never hot-accepted,
|
|
15
|
+
// which made EVERY edit propagate to the entry and force a full reload —
|
|
16
|
+
// fixed by the `import.meta.hot.accept()` in externalize-react.ts. Component
|
|
17
|
+
// edits now apply in place; non-component modules (main.tsx, lib/*) still
|
|
18
|
+
// fall back to a full reload via Bun's runtime, which is correct.
|
|
19
|
+
if (import.meta.hot) {
|
|
20
|
+
startHmrWatchdog()
|
|
38
21
|
}
|
|
39
22
|
|
|
40
23
|
export async function init(el: HTMLElement) {
|
package/client/main.tsx
CHANGED
|
@@ -3,8 +3,8 @@ import { Agentation } from 'agentation'
|
|
|
3
3
|
import { createRoot } from 'react-dom/client'
|
|
4
4
|
import { Router } from 'wouter'
|
|
5
5
|
|
|
6
|
-
import { initConnection } from '
|
|
7
|
-
import { AppRouter } from './
|
|
6
|
+
import { initConnection } from '@/client/features/chat/chat-connection'
|
|
7
|
+
import { AppRouter } from './app/AppRouter'
|
|
8
8
|
|
|
9
9
|
const queryClient = new QueryClient()
|
|
10
10
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function startHmrWatchdog() {
|
|
2
|
+
if (!import.meta.hot) return
|
|
3
|
+
let lastEventAt = Date.now()
|
|
4
|
+
for (const event of ['bun:beforeUpdate', 'bun:afterUpdate', 'bun:ws:connect'] as const) {
|
|
5
|
+
import.meta.hot.on(event, () => (lastEventAt = Date.now()))
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const devScript = document.querySelector<HTMLScriptElement>('[data-bun-dev-server-script]')
|
|
9
|
+
if (!devScript) return
|
|
10
|
+
|
|
11
|
+
let baseline = new URL(devScript.src).pathname
|
|
12
|
+
let staleSince: number | null = null
|
|
13
|
+
|
|
14
|
+
const checkStale = async () => {
|
|
15
|
+
try {
|
|
16
|
+
const html = await (await fetch('/', { cache: 'no-store' })).text()
|
|
17
|
+
const current = html.match(/\/_bun\/client\/index-[0-9a-f]+\.js/)?.[0]
|
|
18
|
+
if (!current || current === baseline) {
|
|
19
|
+
staleSince = null
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
staleSince ??= Date.now()
|
|
24
|
+
if (lastEventAt >= staleSince - 5_000) {
|
|
25
|
+
baseline = current
|
|
26
|
+
staleSince = null
|
|
27
|
+
} else if (Date.now() - staleSince > 10_000) {
|
|
28
|
+
location.reload()
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
// The server may be between supervisor restarts. The next check retries.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
setInterval(checkStale, 5_000)
|
|
36
|
+
document.addEventListener('visibilitychange', () => {
|
|
37
|
+
if (document.visibilityState === 'visible') checkStale()
|
|
38
|
+
})
|
|
39
|
+
}
|
|
@@ -3,7 +3,7 @@ import { useEffect, useRef } from 'react'
|
|
|
3
3
|
import { wsUrl } from '@/client/lib/ws-url'
|
|
4
4
|
import type { ViewInfo, WidgetInfo } from '@/lib/types'
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export type WorkspaceEvent =
|
|
7
7
|
| { type: 'widget:updated'; name: string }
|
|
8
8
|
| { type: 'widget-layout:updated'; widgets: WidgetInfo[] }
|
|
9
9
|
| { type: 'widgets:refresh' }
|
|
@@ -11,15 +11,18 @@ export type MeiEvent =
|
|
|
11
11
|
| { type: 'view-layout:updated'; views: ViewInfo[] }
|
|
12
12
|
| { type: 'theme:updated' }
|
|
13
13
|
| { type: 'workspace:updated' }
|
|
14
|
+
// The registry list changed (reorder, create) without touching any open
|
|
15
|
+
// workspace's layout — clients refetch just the sidebar list.
|
|
16
|
+
| { type: 'workspaces-list:updated' }
|
|
14
17
|
// A workspace's env changed outside the UI — refetch the env view.
|
|
15
18
|
| { type: 'env:updated'; workspaceId: string }
|
|
16
19
|
// The Scratchpad canvas for `workspaceId` was saved — open tabs reload from
|
|
17
20
|
// disk. `origin` is the tab that wrote it, so that tab can skip its own echo.
|
|
18
21
|
| { type: 'scratchpad:updated'; workspaceId: string; origin?: string }
|
|
19
22
|
|
|
20
|
-
type
|
|
23
|
+
type WorkspaceEventHandler = (event: WorkspaceEvent) => void
|
|
21
24
|
|
|
22
|
-
const listeners = new Set<
|
|
25
|
+
const listeners = new Set<WorkspaceEventHandler>()
|
|
23
26
|
let ws: WebSocket | null = null
|
|
24
27
|
let connecting = false
|
|
25
28
|
|
|
@@ -36,7 +39,7 @@ function ensureConnection() {
|
|
|
36
39
|
|
|
37
40
|
socket.onmessage = event => {
|
|
38
41
|
try {
|
|
39
|
-
const data = JSON.parse(event.data) as
|
|
42
|
+
const data = JSON.parse(event.data) as WorkspaceEvent
|
|
40
43
|
for (const handler of listeners) handler(data)
|
|
41
44
|
} catch {}
|
|
42
45
|
}
|
|
@@ -55,12 +58,12 @@ function ensureConnection() {
|
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
export function
|
|
61
|
+
export function useWorkspaceEvent(handler: WorkspaceEventHandler) {
|
|
59
62
|
const handlerRef = useRef(handler)
|
|
60
63
|
handlerRef.current = handler
|
|
61
64
|
|
|
62
65
|
useEffect(() => {
|
|
63
|
-
const wrapped:
|
|
66
|
+
const wrapped: WorkspaceEventHandler = e => handlerRef.current(e)
|
|
64
67
|
listeners.add(wrapped)
|
|
65
68
|
ensureConnection()
|
|
66
69
|
|
package/client/store/ui.ts
CHANGED
|
@@ -5,16 +5,20 @@ import { persist } from 'zustand/middleware'
|
|
|
5
5
|
// survive reloads. Server-owned or per-workspace state does NOT belong here.
|
|
6
6
|
type UiStore = {
|
|
7
7
|
sidebarCollapsed: boolean
|
|
8
|
+
discoveredWorkspacesOpen: boolean
|
|
8
9
|
toggleSidebar: () => void
|
|
9
10
|
setSidebarCollapsed: (collapsed: boolean) => void
|
|
11
|
+
setDiscoveredWorkspacesOpen: (open: boolean) => void
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export const useUiStore = create<UiStore>()(
|
|
13
15
|
persist(
|
|
14
16
|
set => ({
|
|
15
17
|
sidebarCollapsed: false,
|
|
18
|
+
discoveredWorkspacesOpen: true,
|
|
16
19
|
toggleSidebar: () => set(s => ({ sidebarCollapsed: !s.sidebarCollapsed })),
|
|
17
|
-
setSidebarCollapsed: collapsed => set({ sidebarCollapsed: collapsed })
|
|
20
|
+
setSidebarCollapsed: collapsed => set({ sidebarCollapsed: collapsed }),
|
|
21
|
+
setDiscoveredWorkspacesOpen: open => set({ discoveredWorkspacesOpen: open })
|
|
18
22
|
}),
|
|
19
23
|
{ name: 'moi:ui' }
|
|
20
24
|
)
|
package/client/theme.css
CHANGED
|
@@ -25,8 +25,6 @@
|
|
|
25
25
|
--color-popover-foreground: var(--popover-foreground);
|
|
26
26
|
--color-primary: var(--primary);
|
|
27
27
|
--color-primary-foreground: var(--primary-foreground);
|
|
28
|
-
--color-secondary: var(--secondary);
|
|
29
|
-
--color-secondary-foreground: var(--secondary-foreground);
|
|
30
28
|
--color-muted: var(--muted);
|
|
31
29
|
--color-muted-foreground: var(--muted-foreground);
|
|
32
30
|
--color-accent: var(--accent);
|