moi-computer 0.0.1
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/LICENSE +95 -0
- package/README.md +71 -0
- package/bin/moi.mjs +25 -0
- package/bunfig.toml +3 -0
- package/client/CLAUDE.md +12 -0
- package/client/api/workspaces.ts +158 -0
- package/client/assets/claude.svg +3 -0
- package/client/assets/favicon.png +0 -0
- package/client/assets/hermes-nous.png +0 -0
- package/client/assets/mcp/.gitkeep +0 -0
- package/client/assets/mcp/atlassian.png +0 -0
- package/client/assets/mcp/discord.png +0 -0
- package/client/assets/mcp/figma.png +0 -0
- package/client/assets/mcp/github.png +0 -0
- package/client/assets/mcp/gitlab.png +0 -0
- package/client/assets/mcp/granola.png +0 -0
- package/client/assets/mcp/hubspot.png +0 -0
- package/client/assets/mcp/linear.png +0 -0
- package/client/assets/mcp/neon.png +0 -0
- package/client/assets/mcp/notion.png +0 -0
- package/client/assets/mcp/sentry.png +0 -0
- package/client/assets/mcp/slack.png +0 -0
- package/client/assets/mcp/stripe.png +0 -0
- package/client/assets/mcp/supabase.png +0 -0
- package/client/assets/mcp/vercel.png +0 -0
- package/client/assets/moi-logo.svg +11 -0
- package/client/assets/openclaw.svg +22 -0
- package/client/components/App.tsx +35 -0
- package/client/components/BottomPanel.tsx +33 -0
- package/client/components/ChatInput.tsx +62 -0
- package/client/components/ChatPanel.tsx +206 -0
- package/client/components/ChatPopup.tsx +60 -0
- package/client/components/CustomizePanel.tsx +117 -0
- package/client/components/HiddenPanel.tsx +79 -0
- package/client/components/HomePage.tsx +17 -0
- package/client/components/MarkdownContent.tsx +41 -0
- package/client/components/ThreadSelector.tsx +88 -0
- package/client/components/TurnView.tsx +618 -0
- package/client/components/WidgetErrorBoundary.tsx +46 -0
- package/client/components/WidgetFrame.tsx +66 -0
- package/client/components/WidgetGrid.tsx +113 -0
- package/client/components/WidgetShell.tsx +44 -0
- package/client/components/Widgets.tsx +132 -0
- package/client/components/WorkspacePreview.tsx +48 -0
- package/client/components/WorkspacesPage.tsx +237 -0
- package/client/components/layout/SidebarLayout.tsx +260 -0
- package/client/components/playground/LedLogo.tsx +181 -0
- package/client/components/playground/PixelPainter.tsx +105 -0
- package/client/components/playground/PlaygroundPage.tsx +71 -0
- package/client/components/routes/workspace/[id].tsx +282 -0
- package/client/components/ui/button.tsx +48 -0
- package/client/components/ui/dropdown-menu.tsx +257 -0
- package/client/components/ui/input.tsx +21 -0
- package/client/components/ui/popover.tsx +79 -0
- package/client/components/ui/textarea.tsx +18 -0
- package/client/externalize-react.ts +29 -0
- package/client/hooks/useChat.ts +88 -0
- package/client/hooks/useFitsSidebar.ts +34 -0
- package/client/hooks/useGridReconcile.ts +73 -0
- package/client/hooks/useMeiEvents.ts +66 -0
- package/client/hooks/useScrollFade.ts +38 -0
- package/client/hooks/useWidget.ts +72 -0
- package/client/hooks/useWidgetList.ts +30 -0
- package/client/hooks/useWorkspaceTheme.ts +76 -0
- package/client/index.css +182 -0
- package/client/index.html +43 -0
- package/client/index.tsx +19 -0
- package/client/lib/WorkspaceContext.tsx +24 -0
- package/client/lib/WorkspaceLayoutContext.tsx +92 -0
- package/client/lib/cn.ts +6 -0
- package/client/lib/grid-pack.ts +35 -0
- package/client/lib/group-turns.ts +44 -0
- package/client/lib/mcp-icons.ts +53 -0
- package/client/lib/ws.ts +129 -0
- package/client/main.tsx +23 -0
- package/client/store/chat.tsx +162 -0
- package/client/store/ui.ts +21 -0
- package/client/theme.css +66 -0
- package/lib/claude-adapter.ts +602 -0
- package/lib/format.ts +212 -0
- package/lib/themes.ts +89 -0
- package/lib/types.ts +144 -0
- package/package.json +117 -0
- package/server/CLAUDE.md +6 -0
- package/server/agent.ts +132 -0
- package/server/build-widget.ts +343 -0
- package/server/cli.ts +632 -0
- package/server/constants.ts +3 -0
- package/server/control.ts +98 -0
- package/server/functions-worker.ts +89 -0
- package/server/functions.ts +171 -0
- package/server/layout.ts +83 -0
- package/server/openclaw-adapter.ts +242 -0
- package/server/openclaw-gateway.ts +255 -0
- package/server/openclaw-session.ts +485 -0
- package/server/openclaw-strip.ts +134 -0
- package/server/openclaw.ts +206 -0
- package/server/registry.ts +150 -0
- package/server/skills-template.ts +21 -0
- package/server/state.ts +87 -0
- package/server/theme.ts +55 -0
- package/server/web.ts +321 -0
- package/server/widgets.ts +254 -0
- package/tsconfig.json +21 -0
- package/workspace/.claude/skills/widgets/DESIGN.md +630 -0
- package/workspace/.claude/skills/widgets/SKILL.md +176 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
import { motion } from 'motion/react'
|
|
4
|
+
|
|
5
|
+
import { IconMinus, IconPlus } from '@tabler/icons-react'
|
|
6
|
+
|
|
7
|
+
import { cn } from '@/client/lib/cn'
|
|
8
|
+
|
|
9
|
+
import { Button } from './ui/button'
|
|
10
|
+
|
|
11
|
+
type WidgetFrameProps = {
|
|
12
|
+
editing?: boolean
|
|
13
|
+
hidden?: boolean
|
|
14
|
+
onRemove?: () => void
|
|
15
|
+
children?: ReactNode
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function WidgetFrame({ editing, hidden, onRemove, children }: WidgetFrameProps) {
|
|
19
|
+
return (
|
|
20
|
+
<motion.div
|
|
21
|
+
variants={{
|
|
22
|
+
idle: { rotate: 0 },
|
|
23
|
+
wiggle: {
|
|
24
|
+
rotate: [0.5, -0.5],
|
|
25
|
+
transition: {
|
|
26
|
+
rotate: { repeat: Infinity, repeatType: 'reverse', duration: 0.15, ease: 'easeInOut' }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}}
|
|
30
|
+
animate={editing ? 'wiggle' : 'idle'}
|
|
31
|
+
transition={{ type: 'spring', duration: 0.35, bounce: 0 }}
|
|
32
|
+
className="group/widget relative size-full"
|
|
33
|
+
>
|
|
34
|
+
<div
|
|
35
|
+
className={cn(
|
|
36
|
+
'dark absolute inset-0 overflow-hidden rounded-2xl [corner-shape:superellipse(1.2)]',
|
|
37
|
+
// Outer drop shadow on the wrapper itself.
|
|
38
|
+
'shadow-[0_1px_2px_-1px_rgba(0,0,0,0.08),0_2px_4px_0_rgba(0,0,0,0.03)]',
|
|
39
|
+
// 1px inset stroke painted on a pseudo so it lands ON TOP of the
|
|
40
|
+
// widget content (e.g. coloured backgrounds) rather than being
|
|
41
|
+
// covered by the child filling the frame.
|
|
42
|
+
'after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit]',
|
|
43
|
+
"after:content-[''] after:[corner-shape:inherit]",
|
|
44
|
+
'after:shadow-[inset_0_0_0_1px_rgba(0,0,0,0.05)]',
|
|
45
|
+
'text-foreground',
|
|
46
|
+
editing && 'pointer-events-none'
|
|
47
|
+
)}
|
|
48
|
+
>
|
|
49
|
+
{children}
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
{editing && onRemove && (
|
|
53
|
+
<div className="absolute -right-2 -top-2 opacity-0 transition-opacity group-hover/widget:opacity-100">
|
|
54
|
+
<Button
|
|
55
|
+
size="icon-sm"
|
|
56
|
+
variant="outline"
|
|
57
|
+
className="size-7 rounded-full"
|
|
58
|
+
onClick={onRemove}
|
|
59
|
+
>
|
|
60
|
+
{hidden ? <IconPlus stroke={1.5} /> : <IconMinus stroke={1.5} />}
|
|
61
|
+
</Button>
|
|
62
|
+
</div>
|
|
63
|
+
)}
|
|
64
|
+
</motion.div>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { useCallback, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { motion } from 'motion/react'
|
|
5
|
+
|
|
6
|
+
import { GridLayout, type Layout, useContainerWidth, verticalCompactor } from 'react-grid-layout'
|
|
7
|
+
import 'react-grid-layout/css/styles.css'
|
|
8
|
+
import 'react-resizable/css/styles.css'
|
|
9
|
+
|
|
10
|
+
import { packItems } from '@/client/lib/grid-pack'
|
|
11
|
+
|
|
12
|
+
import { WidgetFrame } from './WidgetFrame'
|
|
13
|
+
|
|
14
|
+
export type GridItem = {
|
|
15
|
+
id: string
|
|
16
|
+
w: number
|
|
17
|
+
h: number
|
|
18
|
+
x?: number
|
|
19
|
+
y?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type WidgetGridProps = {
|
|
23
|
+
cols?: number
|
|
24
|
+
rowHeight?: number
|
|
25
|
+
gap?: number
|
|
26
|
+
items: GridItem[]
|
|
27
|
+
editing?: boolean
|
|
28
|
+
renderItem: (id: string) => ReactNode
|
|
29
|
+
onLayoutChange?: (items: GridItem[]) => void
|
|
30
|
+
onRemove?: (id: string) => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function WidgetGrid({
|
|
34
|
+
cols = 4,
|
|
35
|
+
rowHeight = 160,
|
|
36
|
+
gap = 8,
|
|
37
|
+
items,
|
|
38
|
+
editing,
|
|
39
|
+
renderItem,
|
|
40
|
+
onLayoutChange,
|
|
41
|
+
onRemove
|
|
42
|
+
}: WidgetGridProps) {
|
|
43
|
+
const [layout, setLayout] = useState<Layout>(() => packItems(items, []))
|
|
44
|
+
const [prevItems, setPrevItems] = useState(items)
|
|
45
|
+
|
|
46
|
+
// v2 replaces the WidthProvider HOC with this hook. `measureBeforeMount` holds
|
|
47
|
+
// the grid back until the container is measured, so it never flashes at the
|
|
48
|
+
// wrong width; `containerRef` goes on the wrapper, `width` feeds the grid.
|
|
49
|
+
const { width, containerRef, mounted } = useContainerWidth({ measureBeforeMount: true })
|
|
50
|
+
|
|
51
|
+
// Sync layout synchronously during render (not useEffect) so layoutId animations
|
|
52
|
+
// fire in the same React commit as the hidden panel unmount/mount
|
|
53
|
+
if (prevItems !== items) {
|
|
54
|
+
setPrevItems(items)
|
|
55
|
+
setLayout(prev => {
|
|
56
|
+
const prevMap = new Map(prev.map(l => [l.i, l]))
|
|
57
|
+
// Preserve x/y from RGL state but always take w/h from items (source of truth)
|
|
58
|
+
const kept = items
|
|
59
|
+
.filter(i => prevMap.has(i.id))
|
|
60
|
+
.map(i => ({ ...prevMap.get(i.id)!, w: i.w, h: i.h }))
|
|
61
|
+
const keptIds = new Set(kept.map(l => l.i))
|
|
62
|
+
const added = packItems(
|
|
63
|
+
items.filter(i => !keptIds.has(i.id)),
|
|
64
|
+
kept
|
|
65
|
+
)
|
|
66
|
+
return [...kept, ...added]
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const handleLayoutChange = useCallback(
|
|
71
|
+
(next: Layout) => {
|
|
72
|
+
setLayout(next)
|
|
73
|
+
onLayoutChange?.(
|
|
74
|
+
next.map(item => ({ id: item.i, w: item.w, h: item.h, x: item.x, y: item.y }))
|
|
75
|
+
)
|
|
76
|
+
},
|
|
77
|
+
[onLayoutChange]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div ref={containerRef}>
|
|
82
|
+
{mounted && (
|
|
83
|
+
<GridLayout
|
|
84
|
+
width={width}
|
|
85
|
+
layout={layout}
|
|
86
|
+
gridConfig={{ cols, rowHeight, margin: [gap, gap], containerPadding: [0, 0] }}
|
|
87
|
+
dragConfig={{ enabled: !!editing }}
|
|
88
|
+
resizeConfig={{ enabled: false }}
|
|
89
|
+
compactor={verticalCompactor}
|
|
90
|
+
onLayoutChange={handleLayoutChange}
|
|
91
|
+
>
|
|
92
|
+
{layout.map(item => (
|
|
93
|
+
// Container div: purely structural, owned by RGL for positioning
|
|
94
|
+
<div key={item.i}>
|
|
95
|
+
<motion.div
|
|
96
|
+
layoutId={item.i}
|
|
97
|
+
className="size-full"
|
|
98
|
+
transition={{ type: 'spring', duration: 0.35, bounce: 0 }}
|
|
99
|
+
>
|
|
100
|
+
<WidgetFrame
|
|
101
|
+
editing={editing}
|
|
102
|
+
onRemove={onRemove ? () => onRemove(item.i) : undefined}
|
|
103
|
+
>
|
|
104
|
+
{renderItem(item.i)}
|
|
105
|
+
</WidgetFrame>
|
|
106
|
+
</motion.div>
|
|
107
|
+
</div>
|
|
108
|
+
))}
|
|
109
|
+
</GridLayout>
|
|
110
|
+
)}
|
|
111
|
+
</div>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AnimatePresence, motion } from 'motion/react'
|
|
2
|
+
|
|
3
|
+
import { useWidget } from '@/client/hooks/useWidget'
|
|
4
|
+
|
|
5
|
+
import { WidgetErrorBoundary } from './WidgetErrorBoundary'
|
|
6
|
+
|
|
7
|
+
type WidgetShellProps = {
|
|
8
|
+
name: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function WidgetShell({ name }: WidgetShellProps) {
|
|
12
|
+
const widget = useWidget(name)
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
16
|
+
{widget.status === 'ready' && (
|
|
17
|
+
<motion.div
|
|
18
|
+
key={widget.version}
|
|
19
|
+
className="absolute inset-0"
|
|
20
|
+
initial={{ opacity: 0, filter: 'blur(4px)' }}
|
|
21
|
+
animate={{ opacity: 1, filter: 'blur(0px)' }}
|
|
22
|
+
exit={{ opacity: 0, filter: 'blur(4px)' }}
|
|
23
|
+
transition={{ duration: 0.45, ease: 'easeInOut' }}
|
|
24
|
+
>
|
|
25
|
+
<WidgetErrorBoundary name={name} resetKey={widget.version}>
|
|
26
|
+
<widget.Component />
|
|
27
|
+
</WidgetErrorBoundary>
|
|
28
|
+
</motion.div>
|
|
29
|
+
)}
|
|
30
|
+
{widget.status === 'error' && (
|
|
31
|
+
<motion.p
|
|
32
|
+
key={`err-${widget.version}`}
|
|
33
|
+
className="text-destructive absolute inset-0 p-4 text-xs"
|
|
34
|
+
initial={{ opacity: 0 }}
|
|
35
|
+
animate={{ opacity: 1 }}
|
|
36
|
+
exit={{ opacity: 0 }}
|
|
37
|
+
transition={{ duration: 0.45, ease: 'easeInOut' }}
|
|
38
|
+
>
|
|
39
|
+
{widget.error}
|
|
40
|
+
</motion.p>
|
|
41
|
+
)}
|
|
42
|
+
</AnimatePresence>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { AnimatePresence, LayoutGroup, motion } from 'motion/react'
|
|
4
|
+
|
|
5
|
+
import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
|
|
6
|
+
import { findFreePosition } from '@/client/lib/grid-pack'
|
|
7
|
+
import type { WidgetInfo } from '@/lib/types'
|
|
8
|
+
|
|
9
|
+
import { CustomizePanel } from './CustomizePanel'
|
|
10
|
+
import { HiddenPanel } from './HiddenPanel'
|
|
11
|
+
import type { GridItem } from './WidgetGrid'
|
|
12
|
+
import { WidgetGrid } from './WidgetGrid'
|
|
13
|
+
import { WidgetShell } from './WidgetShell'
|
|
14
|
+
|
|
15
|
+
export type WidgetMode = 'idle' | 'editing' | 'customizing'
|
|
16
|
+
|
|
17
|
+
function renderItem(id: string) {
|
|
18
|
+
return <WidgetShell name={id} />
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Tracks the rendered (border-box) height of whichever bottom panel is open, so
|
|
22
|
+
// the grid can reserve matching space below it and every card stays reachable.
|
|
23
|
+
function usePanelHeight() {
|
|
24
|
+
const [height, setHeight] = useState(0)
|
|
25
|
+
const ref = useCallback((node: HTMLDivElement | null) => {
|
|
26
|
+
if (!node) return
|
|
27
|
+
const ro = new ResizeObserver(([entry]) => {
|
|
28
|
+
const box = entry.borderBoxSize?.[0]
|
|
29
|
+
setHeight(box ? box.blockSize : entry.contentRect.height)
|
|
30
|
+
})
|
|
31
|
+
ro.observe(node)
|
|
32
|
+
return () => ro.disconnect()
|
|
33
|
+
}, [])
|
|
34
|
+
return [ref, height] as const
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type WidgetsProps = {
|
|
38
|
+
// Owned by the page (its header renders the controls); Widgets only reacts.
|
|
39
|
+
mode: WidgetMode
|
|
40
|
+
// Authoritative widget set from the widgets query; positions come from layout.
|
|
41
|
+
widgets: WidgetInfo[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function Widgets({ mode, widgets }: WidgetsProps) {
|
|
45
|
+
const { layout, setLayout } = useWorkspaceLayoutCtx()
|
|
46
|
+
|
|
47
|
+
const gridIds = new Set(layout.widgetGrid.map(g => g.i))
|
|
48
|
+
|
|
49
|
+
const visibleItems: GridItem[] = layout.widgetGrid
|
|
50
|
+
.filter(g => widgets.some(w => w.id === g.i))
|
|
51
|
+
.map(g => {
|
|
52
|
+
const widget = widgets.find(w => w.id === g.i)!
|
|
53
|
+
return { id: g.i, w: widget.config.colSpan, h: widget.config.rowSpan, x: g.x, y: g.y }
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const hiddenItems: GridItem[] = widgets
|
|
57
|
+
.filter(w => !gridIds.has(w.id))
|
|
58
|
+
.map(w => ({ id: w.id, w: w.config.colSpan, h: w.config.rowSpan }))
|
|
59
|
+
|
|
60
|
+
const [panelRef, panelHeight] = usePanelHeight()
|
|
61
|
+
const panelOpen = mode === 'customizing' || (mode === 'editing' && hiddenItems.length > 0)
|
|
62
|
+
|
|
63
|
+
function hide(id: string) {
|
|
64
|
+
setLayout({ widgetGrid: layout.widgetGrid.filter(g => g.i !== id) })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function restore(id: string) {
|
|
68
|
+
const widget = widgets.find(w => w.id === id)
|
|
69
|
+
if (!widget) return
|
|
70
|
+
const gridWithSizes = layout.widgetGrid.map(g => {
|
|
71
|
+
const w = widgets.find(w => w.id === g.i)
|
|
72
|
+
return { ...g, w: w?.config.colSpan ?? 1, h: w?.config.rowSpan ?? 1 }
|
|
73
|
+
})
|
|
74
|
+
const pos = findFreePosition(gridWithSizes, widget.config.colSpan, widget.config.rowSpan, 4)
|
|
75
|
+
setLayout({ widgetGrid: [...layout.widgetGrid, { i: id, x: pos.x, y: pos.y }] })
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (widgets.length === 0) {
|
|
79
|
+
return (
|
|
80
|
+
<div className="flex min-h-0 flex-1 items-center justify-center">
|
|
81
|
+
<p className="text-muted-foreground text-sm">No widgets found</p>
|
|
82
|
+
</div>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
// Working area: everything below the header. It scrolls, and it's the
|
|
88
|
+
// positioning context for the bottom panel (which is anchored to this box,
|
|
89
|
+
// not to the grid). The grid lives in a centered max-w container and grows
|
|
90
|
+
// to its natural height.
|
|
91
|
+
<div className="relative min-h-0 flex-1">
|
|
92
|
+
<LayoutGroup>
|
|
93
|
+
<div className="h-full overflow-y-auto px-[var(--page-pad)] pb-[calc(var(--page-pad)*2)] pt-[var(--page-pad)]">
|
|
94
|
+
{/* Bottom reservation = 2× page-pad (the pb above) + the open panel's
|
|
95
|
+
height (this margin), so the last cards scroll clear of it. */}
|
|
96
|
+
<motion.div
|
|
97
|
+
className="mx-auto w-full max-w-[var(--column-w)]"
|
|
98
|
+
animate={{ marginBottom: panelOpen ? panelHeight : 0 }}
|
|
99
|
+
transition={{ type: 'spring', duration: 0.3, bounce: 0 }}
|
|
100
|
+
>
|
|
101
|
+
<WidgetGrid
|
|
102
|
+
items={visibleItems}
|
|
103
|
+
editing={mode === 'editing'}
|
|
104
|
+
renderItem={renderItem}
|
|
105
|
+
onRemove={hide}
|
|
106
|
+
onLayoutChange={items =>
|
|
107
|
+
setLayout({
|
|
108
|
+
widgetGrid: items.map(i => ({ i: i.id, x: i.x ?? 0, y: i.y ?? 0 }))
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
/>
|
|
112
|
+
</motion.div>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<AnimatePresence>
|
|
116
|
+
{mode === 'editing' && hiddenItems.length > 0 && (
|
|
117
|
+
<HiddenPanel
|
|
118
|
+
ref={panelRef}
|
|
119
|
+
items={hiddenItems}
|
|
120
|
+
renderItem={renderItem}
|
|
121
|
+
onRestore={restore}
|
|
122
|
+
/>
|
|
123
|
+
)}
|
|
124
|
+
</AnimatePresence>
|
|
125
|
+
|
|
126
|
+
<AnimatePresence>
|
|
127
|
+
{mode === 'customizing' && <CustomizePanel ref={panelRef} />}
|
|
128
|
+
</AnimatePresence>
|
|
129
|
+
</LayoutGroup>
|
|
130
|
+
</div>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IconRobotFace } from '@tabler/icons-react'
|
|
2
|
+
|
|
3
|
+
import { useWorkspacePreview } from '@/client/api/workspaces'
|
|
4
|
+
|
|
5
|
+
type WorkspacePreviewProps = {
|
|
6
|
+
workspaceId: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function WorkspacePreview({ workspaceId }: WorkspacePreviewProps) {
|
|
10
|
+
const query = useWorkspacePreview(workspaceId)
|
|
11
|
+
|
|
12
|
+
const items = query.data?.items ?? []
|
|
13
|
+
const cols = query.data?.cols ?? 4
|
|
14
|
+
const rows = items.length ? Math.max(...items.map(i => i.y + i.h)) : 0
|
|
15
|
+
const hasItems = items.length > 0 && rows > 0
|
|
16
|
+
const isEmpty = query.data !== undefined && !hasItems
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className="bg-muted flex size-24 shrink-0 items-center justify-center rounded-lg p-2">
|
|
20
|
+
{hasItems && (
|
|
21
|
+
<svg
|
|
22
|
+
viewBox={`0 0 ${cols} ${rows}`}
|
|
23
|
+
preserveAspectRatio="none"
|
|
24
|
+
className="animate-in fade-in size-full duration-300"
|
|
25
|
+
>
|
|
26
|
+
{items.map((item, i) => (
|
|
27
|
+
<rect
|
|
28
|
+
key={i}
|
|
29
|
+
x={item.x + 0.06}
|
|
30
|
+
y={item.y + 0.06}
|
|
31
|
+
width={item.w - 0.12}
|
|
32
|
+
height={item.h - 0.12}
|
|
33
|
+
rx={0.12}
|
|
34
|
+
className="fill-muted-foreground/30"
|
|
35
|
+
/>
|
|
36
|
+
))}
|
|
37
|
+
</svg>
|
|
38
|
+
)}
|
|
39
|
+
{isEmpty && (
|
|
40
|
+
<IconRobotFace
|
|
41
|
+
size={20}
|
|
42
|
+
stroke={1.5}
|
|
43
|
+
className="text-muted-foreground/40 animate-in fade-in duration-300"
|
|
44
|
+
/>
|
|
45
|
+
)}
|
|
46
|
+
</div>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { IconDots, IconLoader2, IconPlus, IconTrash } from '@tabler/icons-react'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useAddWorkspace,
|
|
5
|
+
useDiscoveredWorkspaces,
|
|
6
|
+
useRemoveWorkspace,
|
|
7
|
+
useWorkspaces
|
|
8
|
+
} from '@/client/api/workspaces'
|
|
9
|
+
import claudeIcon from '@/client/assets/claude.svg'
|
|
10
|
+
import hermesIcon from '@/client/assets/hermes-nous.png'
|
|
11
|
+
import openclawIcon from '@/client/assets/openclaw.svg'
|
|
12
|
+
import { Button } from '@/client/components/ui/button'
|
|
13
|
+
import {
|
|
14
|
+
DropdownMenu,
|
|
15
|
+
DropdownMenuContent,
|
|
16
|
+
DropdownMenuItem,
|
|
17
|
+
DropdownMenuTrigger
|
|
18
|
+
} from '@/client/components/ui/dropdown-menu'
|
|
19
|
+
import { cn } from '@/client/lib/cn'
|
|
20
|
+
import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
|
|
21
|
+
|
|
22
|
+
import { WorkspacePreview } from './WorkspacePreview'
|
|
23
|
+
|
|
24
|
+
const typeIconSrc: Record<WorkspaceType, string> = {
|
|
25
|
+
'claude-code': claudeIcon,
|
|
26
|
+
openclaw: openclawIcon,
|
|
27
|
+
hermes: hermesIcon
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const typeLabel: Record<WorkspaceType, string> = {
|
|
31
|
+
'claude-code': 'Claude Code',
|
|
32
|
+
openclaw: 'OpenClaw',
|
|
33
|
+
hermes: 'Hermes'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function TypeIcon({ type, className }: { type: WorkspaceType; className?: string }) {
|
|
37
|
+
return (
|
|
38
|
+
<img
|
|
39
|
+
src={typeIconSrc[type]}
|
|
40
|
+
alt=""
|
|
41
|
+
aria-label={typeLabel[type]}
|
|
42
|
+
className={cn('size-4 shrink-0', className)}
|
|
43
|
+
/>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function WorkspacesPage() {
|
|
48
|
+
const workspacesQuery = useWorkspaces()
|
|
49
|
+
const discoveredQuery = useDiscoveredWorkspaces()
|
|
50
|
+
const importMutation = useAddWorkspace()
|
|
51
|
+
const removeMutation = useRemoveWorkspace()
|
|
52
|
+
|
|
53
|
+
if (workspacesQuery.isPending || discoveredQuery.isPending) {
|
|
54
|
+
return (
|
|
55
|
+
<div className="flex min-h-[50vh] items-center justify-center">
|
|
56
|
+
<IconLoader2 size={20} stroke={1.5} className="text-muted-foreground animate-spin" />
|
|
57
|
+
</div>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (workspacesQuery.isError || discoveredQuery.isError) {
|
|
62
|
+
return (
|
|
63
|
+
<div className="flex min-h-[50vh] items-center justify-center">
|
|
64
|
+
<p className="text-muted-foreground text-sm">Could not load workspaces.</p>
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const workspaces = workspacesQuery.data
|
|
70
|
+
const discovered = discoveredQuery.data
|
|
71
|
+
const count = workspaces.length
|
|
72
|
+
const importingPath =
|
|
73
|
+
importMutation.isPending && importMutation.variables ? importMutation.variables.path : null
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div className="mx-auto w-full max-w-3xl px-8 pb-16 pt-14">
|
|
77
|
+
{count > 0 && (
|
|
78
|
+
<div className="mb-10 grid grid-cols-2 gap-3">
|
|
79
|
+
{workspaces.map(ws => (
|
|
80
|
+
<WorkspaceCard
|
|
81
|
+
key={ws.id}
|
|
82
|
+
workspace={ws}
|
|
83
|
+
onRemove={entry => removeMutation.mutate(entry)}
|
|
84
|
+
/>
|
|
85
|
+
))}
|
|
86
|
+
</div>
|
|
87
|
+
)}
|
|
88
|
+
|
|
89
|
+
{count === 0 && discovered.length === 0 && (
|
|
90
|
+
<p className="text-muted-foreground mb-10 text-sm">
|
|
91
|
+
No workspaces yet. Run{' '}
|
|
92
|
+
<code className="bg-muted rounded px-1 py-0.5 font-mono text-xs">moi start</code> in a
|
|
93
|
+
project directory.
|
|
94
|
+
</p>
|
|
95
|
+
)}
|
|
96
|
+
|
|
97
|
+
{discovered.length > 0 && (
|
|
98
|
+
<section>
|
|
99
|
+
<div className="mb-4">
|
|
100
|
+
<h2 className="text-foreground mb-1.5 text-sm font-semibold">Found on your machine</h2>
|
|
101
|
+
<p className="text-muted-foreground text-xs">Discovered via Claude Code and OpenClaw</p>
|
|
102
|
+
</div>
|
|
103
|
+
<ul className="border-border border-t">
|
|
104
|
+
{discovered.map(item => (
|
|
105
|
+
<SuggestedRow
|
|
106
|
+
key={item.path}
|
|
107
|
+
suggestion={item}
|
|
108
|
+
onAdd={s => importMutation.mutate(s)}
|
|
109
|
+
loading={importingPath === item.path}
|
|
110
|
+
/>
|
|
111
|
+
))}
|
|
112
|
+
</ul>
|
|
113
|
+
</section>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
type WorkspaceCardProps = {
|
|
120
|
+
workspace: WorkspaceEntry
|
|
121
|
+
onRemove: (workspace: WorkspaceEntry) => void
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function WorkspaceCard({ workspace, onRemove }: WorkspaceCardProps) {
|
|
125
|
+
const name = displayName(workspace)
|
|
126
|
+
const meta = formatAddedAt(workspace.addedAt)
|
|
127
|
+
|
|
128
|
+
function handleRemove() {
|
|
129
|
+
const message = `Remove "${name}" from your workspaces?\n\nThis only removes it from your list. The folder and its sessions stay on disk — you can add it back any time.`
|
|
130
|
+
if (window.confirm(message)) onRemove(workspace)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<a
|
|
135
|
+
href={`/workspace/${workspace.id}`}
|
|
136
|
+
className={cn(
|
|
137
|
+
'border-border bg-card hover:bg-muted/40 group flex gap-3.5 rounded-xl border p-2',
|
|
138
|
+
'transition-colors'
|
|
139
|
+
)}
|
|
140
|
+
>
|
|
141
|
+
<WorkspacePreview workspaceId={workspace.id} />
|
|
142
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1.5 py-1 pl-1 pr-2">
|
|
143
|
+
<div className="flex items-start justify-between gap-2">
|
|
144
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
145
|
+
<TypeIcon type={workspace.type ?? 'claude-code'} />
|
|
146
|
+
<span className="text-foreground truncate text-sm font-semibold">{name}</span>
|
|
147
|
+
</div>
|
|
148
|
+
<DropdownMenu>
|
|
149
|
+
<DropdownMenuTrigger
|
|
150
|
+
render={
|
|
151
|
+
<Button
|
|
152
|
+
variant="ghost"
|
|
153
|
+
size="icon-sm"
|
|
154
|
+
onClick={e => {
|
|
155
|
+
e.preventDefault()
|
|
156
|
+
e.stopPropagation()
|
|
157
|
+
}}
|
|
158
|
+
className="text-muted-foreground -mr-1 -mt-0.5"
|
|
159
|
+
aria-label="More actions"
|
|
160
|
+
>
|
|
161
|
+
<IconDots stroke={1.5} />
|
|
162
|
+
</Button>
|
|
163
|
+
}
|
|
164
|
+
/>
|
|
165
|
+
<DropdownMenuContent align="end" sideOffset={4} className="min-w-40">
|
|
166
|
+
<DropdownMenuItem
|
|
167
|
+
variant="destructive"
|
|
168
|
+
onClick={e => {
|
|
169
|
+
e.preventDefault()
|
|
170
|
+
e.stopPropagation()
|
|
171
|
+
handleRemove()
|
|
172
|
+
}}
|
|
173
|
+
>
|
|
174
|
+
<IconTrash stroke={1.5} />
|
|
175
|
+
Remove
|
|
176
|
+
</DropdownMenuItem>
|
|
177
|
+
</DropdownMenuContent>
|
|
178
|
+
</DropdownMenu>
|
|
179
|
+
</div>
|
|
180
|
+
<div title={workspace.path} className="text-muted-foreground truncate font-mono text-xs">
|
|
181
|
+
{workspace.displayPath ?? workspace.path}
|
|
182
|
+
</div>
|
|
183
|
+
<div className="flex-1" />
|
|
184
|
+
<div className="text-muted-foreground text-xs">{meta}</div>
|
|
185
|
+
</div>
|
|
186
|
+
</a>
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
type SuggestedRowProps = {
|
|
191
|
+
suggestion: DiscoveredWorkspace
|
|
192
|
+
onAdd: (suggestion: DiscoveredWorkspace) => void
|
|
193
|
+
loading: boolean
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function SuggestedRow({ suggestion, onAdd, loading }: SuggestedRowProps) {
|
|
197
|
+
const { path, type } = suggestion
|
|
198
|
+
const name = displayName(suggestion)
|
|
199
|
+
return (
|
|
200
|
+
<li className="border-border flex items-center gap-3 border-b px-1 py-2.5">
|
|
201
|
+
<TypeIcon type={type} className="opacity-70" />
|
|
202
|
+
<span className="text-foreground/80 shrink-0 text-sm font-medium">{name}</span>
|
|
203
|
+
<span
|
|
204
|
+
title={path}
|
|
205
|
+
className="text-muted-foreground min-w-0 flex-1 truncate font-mono text-xs"
|
|
206
|
+
>
|
|
207
|
+
{suggestion.displayPath ?? path}
|
|
208
|
+
</span>
|
|
209
|
+
<Button variant="outline" size="sm" onClick={() => onAdd(suggestion)} disabled={loading}>
|
|
210
|
+
{loading ? (
|
|
211
|
+
<IconLoader2 stroke={1.5} className="animate-spin" />
|
|
212
|
+
) : (
|
|
213
|
+
<IconPlus stroke={1.5} />
|
|
214
|
+
)}
|
|
215
|
+
Add
|
|
216
|
+
</Button>
|
|
217
|
+
</li>
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function displayName(ws: Pick<WorkspaceEntry, 'name' | 'path' | 'type' | 'agentId'>): string {
|
|
222
|
+
if (ws.name) return ws.name
|
|
223
|
+
if (ws.type === 'openclaw') return ws.agentId ?? 'OpenClaw agent'
|
|
224
|
+
return ws.path.split('/').pop() || ws.path
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function formatAddedAt(iso: string): string {
|
|
228
|
+
const ms = Date.now() - new Date(iso).getTime()
|
|
229
|
+
const mins = Math.floor(ms / 60000)
|
|
230
|
+
if (mins < 1) return 'Added just now'
|
|
231
|
+
if (mins < 60) return `Added ${mins} min${mins === 1 ? '' : 's'} ago`
|
|
232
|
+
const hours = Math.floor(mins / 60)
|
|
233
|
+
if (hours < 24) return `Added ${hours} hour${hours === 1 ? '' : 's'} ago`
|
|
234
|
+
const days = Math.floor(hours / 24)
|
|
235
|
+
if (days < 30) return `Added ${days} day${days === 1 ? '' : 's'} ago`
|
|
236
|
+
return `Added ${new Date(iso).toLocaleDateString()}`
|
|
237
|
+
}
|