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,206 @@
|
|
|
1
|
+
import { type ReactNode, useEffect, useMemo } from 'react'
|
|
2
|
+
|
|
3
|
+
import { IconChevronsRight, IconSelector, IconX } from '@tabler/icons-react'
|
|
4
|
+
|
|
5
|
+
import { useScrollFade } from '@/client/hooks/useScrollFade'
|
|
6
|
+
import { cn } from '@/client/lib/cn'
|
|
7
|
+
import { groupTurns } from '@/client/lib/group-turns'
|
|
8
|
+
import type { ViewState } from '@/lib/types'
|
|
9
|
+
|
|
10
|
+
import { ChatInput } from './ChatInput'
|
|
11
|
+
import { ThreadSelector } from './ThreadSelector'
|
|
12
|
+
import { EmptyState, ThinkingIndicator, TurnView } from './TurnView'
|
|
13
|
+
import { Button } from './ui/button'
|
|
14
|
+
import {
|
|
15
|
+
DropdownMenu,
|
|
16
|
+
DropdownMenuContent,
|
|
17
|
+
DropdownMenuRadioGroup,
|
|
18
|
+
DropdownMenuRadioItem,
|
|
19
|
+
DropdownMenuTrigger
|
|
20
|
+
} from './ui/dropdown-menu'
|
|
21
|
+
|
|
22
|
+
export type ChatMode = 'sidebar' | 'floating'
|
|
23
|
+
|
|
24
|
+
type ChatModeIconProps = {
|
|
25
|
+
className?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function ChatModeIconSidebar({ className }: ChatModeIconProps) {
|
|
29
|
+
return (
|
|
30
|
+
<svg
|
|
31
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
32
|
+
width="24"
|
|
33
|
+
height="24"
|
|
34
|
+
viewBox="0 0 24 24"
|
|
35
|
+
fill="none"
|
|
36
|
+
strokeWidth="1.5"
|
|
37
|
+
className={className}
|
|
38
|
+
>
|
|
39
|
+
<rect x="1.75" y="3.75" width="20.5" height="16.5" rx="2.25" stroke="currentColor" />
|
|
40
|
+
<rect x="11.5" y="5.5" width="9" height="13" rx="1" fill="currentColor" />
|
|
41
|
+
</svg>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function ChatModeIconFloating({ className }: ChatModeIconProps) {
|
|
46
|
+
return (
|
|
47
|
+
<svg
|
|
48
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
49
|
+
width="24"
|
|
50
|
+
height="24"
|
|
51
|
+
viewBox="0 0 24 24"
|
|
52
|
+
fill="none"
|
|
53
|
+
strokeWidth="1.5"
|
|
54
|
+
className={className}
|
|
55
|
+
>
|
|
56
|
+
<rect x="1.75" y="3.75" width="20.5" height="16.5" rx="2.25" stroke="currentColor" />
|
|
57
|
+
<rect x="12.5" y="11.5" width="8" height="7" rx="1" fill="currentColor" />
|
|
58
|
+
</svg>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type ChatPanelProps = {
|
|
63
|
+
view: ViewState
|
|
64
|
+
input: string
|
|
65
|
+
setInput: (v: string) => void
|
|
66
|
+
processing: boolean
|
|
67
|
+
error?: string | null
|
|
68
|
+
onDismissError?: () => void
|
|
69
|
+
send: () => void
|
|
70
|
+
stop: () => void
|
|
71
|
+
chatMode: ChatMode
|
|
72
|
+
onSwitchThread: (sessionId: string | null) => void
|
|
73
|
+
onModeChange?: (mode: 'sidebar' | 'floating') => void
|
|
74
|
+
onCollapse?: () => void
|
|
75
|
+
onClose?: () => void
|
|
76
|
+
// Rendered at the start of the chat header. Solo mode passes the sidebar
|
|
77
|
+
// toggle here since there's no separate workspace header beside the chat.
|
|
78
|
+
leading?: ReactNode
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function ChatPanel({
|
|
82
|
+
view,
|
|
83
|
+
input,
|
|
84
|
+
setInput,
|
|
85
|
+
processing,
|
|
86
|
+
error,
|
|
87
|
+
onDismissError,
|
|
88
|
+
send,
|
|
89
|
+
stop,
|
|
90
|
+
chatMode,
|
|
91
|
+
onSwitchThread,
|
|
92
|
+
onModeChange,
|
|
93
|
+
onCollapse,
|
|
94
|
+
onClose,
|
|
95
|
+
leading
|
|
96
|
+
}: ChatPanelProps) {
|
|
97
|
+
const { ref: scrollRef, showTopFade, showBottomFade } = useScrollFade()
|
|
98
|
+
const turns = view.turns
|
|
99
|
+
// Visual grouping: fold consecutive tool-only assistant turns into one
|
|
100
|
+
// synthetic turn so OpenAI Codex–style traces (which serialize one
|
|
101
|
+
// assistant message per agent step) don't render with the wider
|
|
102
|
+
// inter-turn gap between every tool call. See `dev/turn-spacing.md`.
|
|
103
|
+
const groupedTurns = useMemo(() => groupTurns(turns), [turns])
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
const el = scrollRef.current
|
|
107
|
+
el?.scrollTo({ top: el.scrollHeight, behavior: 'instant' })
|
|
108
|
+
}, [scrollRef, turns])
|
|
109
|
+
|
|
110
|
+
const TriggerIcon = chatMode === 'sidebar' ? ChatModeIconSidebar : ChatModeIconFloating
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<div className="flex h-full flex-col">
|
|
114
|
+
<header className="flex items-center justify-between pb-2 pl-2">
|
|
115
|
+
<div className="flex min-w-0 items-center gap-2.5">
|
|
116
|
+
{leading}
|
|
117
|
+
<ThreadSelector onSwitch={onSwitchThread} />
|
|
118
|
+
</div>
|
|
119
|
+
<div className="flex items-center gap-0.5">
|
|
120
|
+
{onModeChange && (
|
|
121
|
+
<DropdownMenu>
|
|
122
|
+
<DropdownMenuTrigger
|
|
123
|
+
render={
|
|
124
|
+
<Button
|
|
125
|
+
className="pl-2! pr-1! gap-0"
|
|
126
|
+
variant="ghost"
|
|
127
|
+
aria-label="Switch chat mode"
|
|
128
|
+
>
|
|
129
|
+
<>
|
|
130
|
+
<TriggerIcon className="text-muted-foreground" />
|
|
131
|
+
<IconSelector className="size-4! text-muted-foreground/50" stroke={2} />
|
|
132
|
+
</>
|
|
133
|
+
</Button>
|
|
134
|
+
}
|
|
135
|
+
/>
|
|
136
|
+
<DropdownMenuContent align="end" className="min-w-40">
|
|
137
|
+
<DropdownMenuRadioGroup value={chatMode} onValueChange={onModeChange}>
|
|
138
|
+
<DropdownMenuRadioItem value="sidebar" closeOnClick>
|
|
139
|
+
<ChatModeIconSidebar />
|
|
140
|
+
Sidebar
|
|
141
|
+
</DropdownMenuRadioItem>
|
|
142
|
+
<DropdownMenuRadioItem value="floating" closeOnClick>
|
|
143
|
+
<ChatModeIconFloating />
|
|
144
|
+
Floating
|
|
145
|
+
</DropdownMenuRadioItem>
|
|
146
|
+
</DropdownMenuRadioGroup>
|
|
147
|
+
</DropdownMenuContent>
|
|
148
|
+
</DropdownMenu>
|
|
149
|
+
)}
|
|
150
|
+
{chatMode === 'sidebar' && onCollapse && (
|
|
151
|
+
<Button variant="ghost" size="icon" onClick={onCollapse} aria-label="Collapse chat">
|
|
152
|
+
{/* Tabler icon with double chevrons has a really weird optical size, hence the adjustments */}
|
|
153
|
+
<IconChevronsRight className="text-muted-foreground size-6!" stroke={1.5} />
|
|
154
|
+
</Button>
|
|
155
|
+
)}
|
|
156
|
+
{chatMode === 'floating' && onClose && (
|
|
157
|
+
<Button variant="ghost" size="icon" onClick={onClose} aria-label="Close chat">
|
|
158
|
+
<IconX className="text-muted-foreground" stroke={1.5} />
|
|
159
|
+
</Button>
|
|
160
|
+
)}
|
|
161
|
+
</div>
|
|
162
|
+
</header>
|
|
163
|
+
|
|
164
|
+
<div
|
|
165
|
+
ref={scrollRef}
|
|
166
|
+
className={cn(
|
|
167
|
+
'flex flex-1 flex-col gap-6 overflow-y-auto overscroll-contain px-2 pb-12 pt-4',
|
|
168
|
+
showTopFade && showBottomFade && 'mask-fade-y',
|
|
169
|
+
showTopFade && !showBottomFade && 'mask-fade-top',
|
|
170
|
+
!showTopFade && showBottomFade && 'mask-fade-bottom'
|
|
171
|
+
)}
|
|
172
|
+
>
|
|
173
|
+
{turns.length === 0 && !processing && <EmptyState />}
|
|
174
|
+
{groupedTurns.map(turn => (
|
|
175
|
+
<TurnView key={turn.id} turn={turn} />
|
|
176
|
+
))}
|
|
177
|
+
{processing && <ThinkingIndicator />}
|
|
178
|
+
</div>
|
|
179
|
+
|
|
180
|
+
<div>
|
|
181
|
+
{error && (
|
|
182
|
+
<div className="mb-2 flex items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-800">
|
|
183
|
+
<span className="flex-1 break-words">{error}</span>
|
|
184
|
+
{onDismissError && (
|
|
185
|
+
<button
|
|
186
|
+
type="button"
|
|
187
|
+
onClick={onDismissError}
|
|
188
|
+
className="text-red-600 hover:text-red-900"
|
|
189
|
+
aria-label="Dismiss error"
|
|
190
|
+
>
|
|
191
|
+
<IconX size={14} stroke={1.5} />
|
|
192
|
+
</button>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
)}
|
|
196
|
+
<ChatInput
|
|
197
|
+
value={input}
|
|
198
|
+
onChange={setInput}
|
|
199
|
+
onSend={send}
|
|
200
|
+
onStop={stop}
|
|
201
|
+
processing={processing}
|
|
202
|
+
/>
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
)
|
|
206
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ReactNode, RefObject } from 'react'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { motion } from 'motion/react'
|
|
5
|
+
|
|
6
|
+
import { IconRobotFace } from '@tabler/icons-react'
|
|
7
|
+
|
|
8
|
+
import { Button } from './ui/button'
|
|
9
|
+
import { Popover, PopoverContent, PopoverTrigger } from './ui/popover'
|
|
10
|
+
|
|
11
|
+
type ChatPopupProps = {
|
|
12
|
+
defaultOpen?: boolean
|
|
13
|
+
// Portal target for the floating chat — pass the themed workspace wrapper so
|
|
14
|
+
// the popup inherits its scoped CSS vars instead of landing on a bare body.
|
|
15
|
+
container?: RefObject<HTMLElement | null>
|
|
16
|
+
children: (onClose: () => void) => ReactNode
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ChatPopup({ defaultOpen = false, container, children }: ChatPopupProps) {
|
|
20
|
+
const [open, setOpen] = useState(defaultOpen)
|
|
21
|
+
const onClose = () => setOpen(false)
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Popover open={open} onOpenChange={o => setOpen(o)}>
|
|
25
|
+
<PopoverTrigger
|
|
26
|
+
render={
|
|
27
|
+
<div className="fixed bottom-4 right-4 sm:bottom-6 sm:right-6">
|
|
28
|
+
<motion.div
|
|
29
|
+
variants={{
|
|
30
|
+
from: { opacity: 0, scale: 0.8, filter: 'blur(4px)' },
|
|
31
|
+
to: { opacity: 1, scale: 1, filter: 'blur(0px)' },
|
|
32
|
+
invisible: { opacity: 0, scale: 1, filter: 'blur(4px)' }
|
|
33
|
+
}}
|
|
34
|
+
initial="from"
|
|
35
|
+
animate={open ? 'invisible' : 'to'}
|
|
36
|
+
transition={{ type: 'spring', duration: 0.3, delay: 0.2, bounce: 0 }}
|
|
37
|
+
>
|
|
38
|
+
{/* Floating over a themed workspace — pin to white so it stays
|
|
39
|
+
legible regardless of the active theme's --background. */}
|
|
40
|
+
<Button variant="outline" size="lg" className="bg-white hover:bg-white">
|
|
41
|
+
<IconRobotFace stroke={1.75} /> Agent
|
|
42
|
+
</Button>
|
|
43
|
+
</motion.div>
|
|
44
|
+
</div>
|
|
45
|
+
}
|
|
46
|
+
/>
|
|
47
|
+
<PopoverContent
|
|
48
|
+
side="top"
|
|
49
|
+
sideOffset={-48}
|
|
50
|
+
align="end"
|
|
51
|
+
alignOffset={-8}
|
|
52
|
+
className="flex h-[calc(100vh-2rem)] w-[min(440px,calc(100vw-1rem))] flex-col gap-0 rounded-3xl p-3 sm:h-[calc(100vh-8rem)] sm:w-[min(440px,calc(100vw-2rem))] sm:p-4"
|
|
53
|
+
keepMounted
|
|
54
|
+
container={container}
|
|
55
|
+
>
|
|
56
|
+
{children(onClose)}
|
|
57
|
+
</PopoverContent>
|
|
58
|
+
</Popover>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type Ref, useEffect } from 'react'
|
|
2
|
+
|
|
3
|
+
import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
|
|
4
|
+
import { cn } from '@/client/lib/cn'
|
|
5
|
+
import { COLOR_THEMES, type ColorThemeConfig, FONT_THEMES } from '@/lib/themes'
|
|
6
|
+
import type { ColorTheme, FontTheme } from '@/lib/types'
|
|
7
|
+
|
|
8
|
+
import { BottomPanel } from './BottomPanel'
|
|
9
|
+
|
|
10
|
+
const ALL_FONT_PREVIEW_ID = 'mei-font-previews'
|
|
11
|
+
const ALL_FONTS_QUERY = Object.values(FONT_THEMES)
|
|
12
|
+
.map(f => f.googleFontsQuery)
|
|
13
|
+
.filter(Boolean)
|
|
14
|
+
.join('&family=')
|
|
15
|
+
|
|
16
|
+
function usePreloadAllFonts() {
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (document.getElementById(ALL_FONT_PREVIEW_ID)) return
|
|
19
|
+
const link = document.createElement('link')
|
|
20
|
+
link.id = ALL_FONT_PREVIEW_ID
|
|
21
|
+
link.rel = 'stylesheet'
|
|
22
|
+
link.href = `https://fonts.googleapis.com/css2?family=${ALL_FONTS_QUERY}&display=swap`
|
|
23
|
+
document.head.appendChild(link)
|
|
24
|
+
}, [])
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const FONT_OPTIONS = Object.entries(FONT_THEMES) as [FontTheme, (typeof FONT_THEMES)[FontTheme]][]
|
|
28
|
+
|
|
29
|
+
const COLOR_OPTIONS = Object.entries(COLOR_THEMES) as [ColorTheme, ColorThemeConfig][]
|
|
30
|
+
|
|
31
|
+
function presetMatches(preset: ColorThemeConfig, bg?: string, fg?: string): boolean {
|
|
32
|
+
return (preset.background ?? undefined) === bg && (preset.foreground ?? undefined) === fg
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type CustomizePanelProps = {
|
|
36
|
+
ref?: Ref<HTMLDivElement>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function CustomizePanel({ ref }: CustomizePanelProps) {
|
|
40
|
+
usePreloadAllFonts()
|
|
41
|
+
const { layout, setLayout } = useWorkspaceLayoutCtx()
|
|
42
|
+
const currentFont = layout.theme?.font ?? 'default'
|
|
43
|
+
const currentBg = layout.theme?.background
|
|
44
|
+
const currentFg = layout.theme?.foreground
|
|
45
|
+
|
|
46
|
+
function setTheme(update: Partial<NonNullable<typeof layout.theme>>) {
|
|
47
|
+
setLayout({ theme: { ...layout.theme, font: currentFont, ...update } })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<BottomPanel ref={ref} title="Customize">
|
|
52
|
+
<div className="flex flex-col gap-6">
|
|
53
|
+
{/* Font picker */}
|
|
54
|
+
<div className="flex flex-col gap-2">
|
|
55
|
+
<p className="text-muted-foreground text-xs font-medium">Font</p>
|
|
56
|
+
<div className="grid grid-cols-3 gap-2">
|
|
57
|
+
{FONT_OPTIONS.map(([key, config]) => (
|
|
58
|
+
<button
|
|
59
|
+
key={key}
|
|
60
|
+
type="button"
|
|
61
|
+
onClick={() => setTheme({ font: key })}
|
|
62
|
+
className={cn(
|
|
63
|
+
'flex flex-col items-start rounded-md px-3 py-2 text-left transition-colors',
|
|
64
|
+
key === currentFont
|
|
65
|
+
? 'ring-primary bg-primary/5 ring-2'
|
|
66
|
+
: 'hover:bg-muted border-transparent'
|
|
67
|
+
)}
|
|
68
|
+
style={{ fontFamily: config.sans }}
|
|
69
|
+
>
|
|
70
|
+
<span className="text-sm font-medium">{config.label}</span>
|
|
71
|
+
<span className="text-muted-foreground text-xs">{config.feel}</span>
|
|
72
|
+
</button>
|
|
73
|
+
))}
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
{/* Color palette */}
|
|
78
|
+
<div className="flex flex-col gap-2">
|
|
79
|
+
<p className="text-muted-foreground text-xs font-medium">Colors</p>
|
|
80
|
+
<div className="grid grid-cols-3 gap-2">
|
|
81
|
+
{COLOR_OPTIONS.map(([key, preset]) => {
|
|
82
|
+
const active = presetMatches(preset, currentBg, currentFg)
|
|
83
|
+
return (
|
|
84
|
+
<button
|
|
85
|
+
key={key}
|
|
86
|
+
type="button"
|
|
87
|
+
onClick={() =>
|
|
88
|
+
setTheme({ background: preset.background, foreground: preset.foreground })
|
|
89
|
+
}
|
|
90
|
+
className={cn(
|
|
91
|
+
'flex items-center gap-2 rounded-md border px-3 py-2 transition-colors',
|
|
92
|
+
active
|
|
93
|
+
? 'ring-primary bg-primary/5 ring-2'
|
|
94
|
+
: 'hover:bg-muted border-transparent'
|
|
95
|
+
)}
|
|
96
|
+
>
|
|
97
|
+
<span
|
|
98
|
+
className="size-5 shrink-0 rounded-full border border-black/10"
|
|
99
|
+
style={{ backgroundColor: preset.background ?? 'oklch(1 0 0)' }}
|
|
100
|
+
>
|
|
101
|
+
<span
|
|
102
|
+
className="flex size-full items-center justify-center text-[9px] font-bold leading-none"
|
|
103
|
+
style={{ color: preset.foreground ?? 'oklch(0.145 0 0)' }}
|
|
104
|
+
>
|
|
105
|
+
A
|
|
106
|
+
</span>
|
|
107
|
+
</span>
|
|
108
|
+
<span className="text-sm">{preset.label}</span>
|
|
109
|
+
</button>
|
|
110
|
+
)
|
|
111
|
+
})}
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
</BottomPanel>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ReactNode, Ref } from 'react'
|
|
2
|
+
import { useMemo } from 'react'
|
|
3
|
+
|
|
4
|
+
import { AnimatePresence, motion } from 'motion/react'
|
|
5
|
+
|
|
6
|
+
import { cn } from '@/client/lib/cn'
|
|
7
|
+
import { packItems } from '@/client/lib/grid-pack'
|
|
8
|
+
|
|
9
|
+
import { BottomPanel } from './BottomPanel'
|
|
10
|
+
import { WidgetFrame } from './WidgetFrame'
|
|
11
|
+
import type { GridItem } from './WidgetGrid'
|
|
12
|
+
|
|
13
|
+
// Static maps so Tailwind includes these classes (dynamic strings get purged)
|
|
14
|
+
const COL_START: Record<number, string> = {
|
|
15
|
+
0: 'col-start-1',
|
|
16
|
+
1: 'col-start-2',
|
|
17
|
+
2: 'col-start-3',
|
|
18
|
+
3: 'col-start-4'
|
|
19
|
+
}
|
|
20
|
+
const ROW_START: Record<number, string> = {
|
|
21
|
+
0: 'row-start-1',
|
|
22
|
+
1: 'row-start-2',
|
|
23
|
+
2: 'row-start-3',
|
|
24
|
+
3: 'row-start-4',
|
|
25
|
+
4: 'row-start-5',
|
|
26
|
+
5: 'row-start-6',
|
|
27
|
+
6: 'row-start-7',
|
|
28
|
+
7: 'row-start-8'
|
|
29
|
+
}
|
|
30
|
+
const COL_SPAN: Record<number, string> = {
|
|
31
|
+
1: 'col-span-1',
|
|
32
|
+
2: 'col-span-2',
|
|
33
|
+
3: 'col-span-3',
|
|
34
|
+
4: 'col-span-4'
|
|
35
|
+
}
|
|
36
|
+
const ROW_SPAN: Record<number, string> = {
|
|
37
|
+
1: 'row-span-1',
|
|
38
|
+
2: 'row-span-2',
|
|
39
|
+
3: 'row-span-3',
|
|
40
|
+
4: 'row-span-4'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type HiddenPanelProps = {
|
|
44
|
+
items: GridItem[]
|
|
45
|
+
renderItem: (id: string) => ReactNode
|
|
46
|
+
onRestore: (id: string) => void
|
|
47
|
+
ref?: Ref<HTMLDivElement>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function HiddenPanel({ items, renderItem, onRestore, ref }: HiddenPanelProps) {
|
|
51
|
+
const layout = useMemo(() => packItems(items), [items])
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<BottomPanel ref={ref} title="Hidden">
|
|
55
|
+
{/* gap-2 + grid-cols-4 + [grid-auto-rows:160px] matches RGL's margin/rowHeight exactly */}
|
|
56
|
+
<div className="grid grid-cols-4 gap-2 [grid-auto-rows:160px]">
|
|
57
|
+
<AnimatePresence>
|
|
58
|
+
{layout.map(item => (
|
|
59
|
+
<motion.div
|
|
60
|
+
key={item.i}
|
|
61
|
+
layoutId={item.i}
|
|
62
|
+
className={cn(
|
|
63
|
+
COL_START[item.x],
|
|
64
|
+
ROW_START[item.y],
|
|
65
|
+
COL_SPAN[item.w],
|
|
66
|
+
ROW_SPAN[item.h]
|
|
67
|
+
)}
|
|
68
|
+
transition={{ type: 'spring', duration: 0.35, bounce: 0 }}
|
|
69
|
+
>
|
|
70
|
+
<WidgetFrame editing onRemove={() => onRestore(item.i)} hidden>
|
|
71
|
+
{renderItem(item.i)}
|
|
72
|
+
</WidgetFrame>
|
|
73
|
+
</motion.div>
|
|
74
|
+
))}
|
|
75
|
+
</AnimatePresence>
|
|
76
|
+
</div>
|
|
77
|
+
</BottomPanel>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WorkspacesPage } from './WorkspacesPage'
|
|
2
|
+
import { PanelHeader, SidebarLayout, SidebarToggle } from './layout/SidebarLayout'
|
|
3
|
+
|
|
4
|
+
// The `/` route: the app shell wrapping the workspaces view.
|
|
5
|
+
export function HomePage() {
|
|
6
|
+
return (
|
|
7
|
+
<SidebarLayout>
|
|
8
|
+
<PanelHeader>
|
|
9
|
+
<SidebarToggle />
|
|
10
|
+
<span className="text-foreground text-sm font-medium">Home</span>
|
|
11
|
+
</PanelHeader>
|
|
12
|
+
<div className="min-h-0 flex-1 overflow-y-auto">
|
|
13
|
+
<WorkspacesPage />
|
|
14
|
+
</div>
|
|
15
|
+
</SidebarLayout>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ComponentProps } from 'react'
|
|
2
|
+
|
|
3
|
+
import ReactMarkdown from 'react-markdown'
|
|
4
|
+
import rehypeHighlight from 'rehype-highlight'
|
|
5
|
+
import remarkGfm from 'remark-gfm'
|
|
6
|
+
|
|
7
|
+
import { cn } from '@/client/lib/cn'
|
|
8
|
+
|
|
9
|
+
const remarkPlugins = [remarkGfm]
|
|
10
|
+
const rehypePlugins = [rehypeHighlight]
|
|
11
|
+
|
|
12
|
+
const components = {
|
|
13
|
+
pre({ children }: ComponentProps<'pre'>) {
|
|
14
|
+
return (
|
|
15
|
+
<div className="not-prose border-border bg-muted my-2 rounded-md border px-3 py-2.5">
|
|
16
|
+
<pre className="text-foreground/80 max-h-[300px] overflow-auto whitespace-pre font-mono text-xs leading-relaxed">
|
|
17
|
+
{children}
|
|
18
|
+
</pre>
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type MarkdownContentProps = {
|
|
25
|
+
size?: 'sm'
|
|
26
|
+
content: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function MarkdownContent({ size = 'sm', content }: MarkdownContentProps) {
|
|
30
|
+
return (
|
|
31
|
+
<div className={cn('prose prose-inherit', size === 'sm' && 'prose-sm')}>
|
|
32
|
+
<ReactMarkdown
|
|
33
|
+
remarkPlugins={remarkPlugins}
|
|
34
|
+
rehypePlugins={rehypePlugins}
|
|
35
|
+
components={components}
|
|
36
|
+
>
|
|
37
|
+
{content}
|
|
38
|
+
</ReactMarkdown>
|
|
39
|
+
</div>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { IconChevronDown, IconPlus } from '@tabler/icons-react'
|
|
2
|
+
|
|
3
|
+
import { useWorkspaceSessions } from '@/client/api/workspaces'
|
|
4
|
+
import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
|
|
5
|
+
import { cn } from '@/client/lib/cn'
|
|
6
|
+
import { useChatStore } from '@/client/store/chat'
|
|
7
|
+
|
|
8
|
+
import { Button } from './ui/button'
|
|
9
|
+
import {
|
|
10
|
+
DropdownMenu,
|
|
11
|
+
DropdownMenuContent,
|
|
12
|
+
DropdownMenuGroup,
|
|
13
|
+
DropdownMenuItem,
|
|
14
|
+
DropdownMenuShortcut,
|
|
15
|
+
DropdownMenuTrigger
|
|
16
|
+
} from './ui/dropdown-menu'
|
|
17
|
+
|
|
18
|
+
type ThreadSelectorProps = {
|
|
19
|
+
onSwitch: (sessionId: string | null) => void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatDate(ms: number) {
|
|
23
|
+
const date = new Date(ms)
|
|
24
|
+
const now = new Date()
|
|
25
|
+
const isToday = date.toDateString() === now.toDateString()
|
|
26
|
+
const yesterday = new Date(now)
|
|
27
|
+
yesterday.setDate(yesterday.getDate() - 1)
|
|
28
|
+
const isYesterday = date.toDateString() === yesterday.toDateString()
|
|
29
|
+
|
|
30
|
+
if (isToday) return date.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })
|
|
31
|
+
if (isYesterday) return 'Yesterday'
|
|
32
|
+
return date.toLocaleDateString([], { month: 'short', day: 'numeric' })
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function ThreadSelector({ onSwitch }: ThreadSelectorProps) {
|
|
36
|
+
const workspaceId = useWorkspaceId()
|
|
37
|
+
const { data: sessions = [], refetch } = useWorkspaceSessions(workspaceId)
|
|
38
|
+
const activeSessionId = useChatStore(s => s.activeSessionId)
|
|
39
|
+
|
|
40
|
+
const active = sessions.find(s => s.sessionId === activeSessionId)
|
|
41
|
+
const label = active?.summary ?? 'New thread'
|
|
42
|
+
|
|
43
|
+
function handleSelect(sessionId: string | null) {
|
|
44
|
+
onSwitch(sessionId)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<DropdownMenu
|
|
49
|
+
onOpenChange={open => {
|
|
50
|
+
if (open) refetch()
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
<DropdownMenuTrigger
|
|
54
|
+
render={
|
|
55
|
+
<Button variant="ghost" className="-mx-3">
|
|
56
|
+
<span className="max-w-64 truncate">{label}</span>
|
|
57
|
+
<IconChevronDown stroke={1.5} className="text-muted-foreground" />
|
|
58
|
+
</Button>
|
|
59
|
+
}
|
|
60
|
+
/>
|
|
61
|
+
<DropdownMenuContent align="start" className="max-h-80 w-80 overflow-y-auto">
|
|
62
|
+
<DropdownMenuItem
|
|
63
|
+
className="text-muted-foreground! **:text-muted-foreground!"
|
|
64
|
+
onClick={() => handleSelect(null)}
|
|
65
|
+
>
|
|
66
|
+
<IconPlus size={16} stroke={1.5} />
|
|
67
|
+
New thread
|
|
68
|
+
</DropdownMenuItem>
|
|
69
|
+
{sessions.length > 0 && (
|
|
70
|
+
<DropdownMenuGroup>
|
|
71
|
+
{sessions.map(s => (
|
|
72
|
+
<DropdownMenuItem
|
|
73
|
+
key={s.sessionId}
|
|
74
|
+
className={cn(activeSessionId === s.sessionId && 'bg-accent')}
|
|
75
|
+
onClick={() => handleSelect(s.sessionId)}
|
|
76
|
+
>
|
|
77
|
+
<span className="truncate">{s.summary}</span>
|
|
78
|
+
<DropdownMenuShortcut className="shrink-0 tracking-normal">
|
|
79
|
+
{formatDate(s.lastModified)}
|
|
80
|
+
</DropdownMenuShortcut>
|
|
81
|
+
</DropdownMenuItem>
|
|
82
|
+
))}
|
|
83
|
+
</DropdownMenuGroup>
|
|
84
|
+
)}
|
|
85
|
+
</DropdownMenuContent>
|
|
86
|
+
</DropdownMenu>
|
|
87
|
+
)
|
|
88
|
+
}
|