moi-computer 0.3.0-next.1 → 0.3.0-next.3
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/README.md +1 -1
- package/bunfig.toml +5 -1
- package/client/AGENTS.md +17 -2
- 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 +18 -0
- package/client/app/AppRouter.tsx +44 -0
- package/client/app/routes/HomeRoute.tsx +13 -0
- package/client/app/routes/WorkspaceRoute.tsx +95 -0
- package/client/app/shell/SidebarLayout.tsx +196 -0
- package/client/assets/openai.svg +3 -0
- package/client/assets.d.ts +9 -0
- package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +2 -2
- package/client/components/shared/PanelHeader.tsx +9 -0
- package/client/components/shared/ReorderableList.tsx +199 -0
- package/client/components/ui/button.tsx +11 -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/input.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/features/applets/AppletMount.tsx +44 -0
- package/client/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
- package/client/{components → features/applets}/WidgetShell.tsx +5 -2
- package/client/{lib → features/applets}/applet-cache.ts +8 -0
- package/client/features/applets/applet-styles.ts +61 -0
- package/client/{hooks → features/applets}/useApplet.ts +6 -7
- package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +30 -24
- package/client/features/chat/ChatPanel.tsx +171 -0
- package/client/{components → features/chat}/ChatPopup.tsx +24 -13
- package/client/{components/ThreadSelector.tsx → features/chat/ChatSelector.tsx} +15 -13
- package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
- package/client/{components → features/chat}/ModelPicker.tsx +68 -17
- package/client/{components → features/chat}/TurnView.tsx +17 -11
- 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/features/chat/chat-send.ts +57 -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 +14 -5
- package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
- package/client/{components → features/chat}/tool-group/format.ts +117 -0
- package/client/{hooks → features/chat}/useChat.ts +16 -44
- package/client/features/connectors/ConnectorsPage.tsx +92 -0
- package/client/features/connectors/McpMenu.tsx +145 -0
- package/client/features/connectors/api.ts +28 -0
- package/client/features/dev/DevRoutes.tsx +18 -0
- package/client/features/dev/HarnessDebugPage.tsx +468 -0
- package/client/{components/playground → features/dev}/PixelPainter.tsx +10 -21
- package/client/{components/playground → features/dev}/PlaygroundPage.tsx +10 -12
- package/client/{components/playground → features/dev}/ToolCallsPage.tsx +9 -11
- package/client/features/home/CreateWorkspaceDialog.tsx +130 -0
- package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
- package/client/features/home/HomeLogo.tsx +344 -0
- package/client/features/home/HomePage.tsx +214 -0
- package/client/{components → features/home}/WorkspacePreview.tsx +4 -4
- package/client/features/home/api.ts +156 -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 +76 -224
- 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 +30 -0
- package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
- package/client/features/views/ViewBuilderTab.tsx +153 -0
- package/client/features/views/api.ts +124 -0
- package/client/features/views/useViewBuilderActions.ts +72 -0
- 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 +38 -29
- package/client/features/widgets/Widgets.tsx +265 -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 +16 -15
- package/client/features/workspace/WorkspaceScreen.tsx +675 -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 -45
- package/client/index.html +2 -2
- package/client/index.tsx +14 -31
- package/client/lib/app-icon-registry.ts +145 -0
- package/client/main.tsx +2 -2
- package/client/runtime/hmr-watchdog.ts +39 -0
- package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +12 -7
- package/client/store/ui.ts +5 -1
- package/client/theme.css +1 -3
- package/dist/chunk-11cab5dq.css +1 -0
- package/dist/chunk-4vf1t6v1.js +10 -0
- package/dist/chunk-6c24yndg.js +61 -0
- package/dist/chunk-6c8cwpzc.js +1 -0
- package/dist/chunk-b4b276wx.js +15 -0
- package/dist/chunk-cs8vbert.js +546 -0
- package/dist/chunk-cwqmay73.css +1 -0
- package/dist/chunk-kxmvv1ax.js +48 -0
- package/dist/chunk-pcnahct1.js +5 -0
- package/dist/chunk-rq0ar7vp.js +1 -0
- package/dist/chunk-tqd3pkg8.css +1 -0
- package/dist/chunk-vkvb3hjm.js +2 -0
- package/dist/chunk-zpxrb1ce.js +2 -0
- package/dist/index.html +3 -3
- package/dist/openai-h13pza4b.svg +3 -0
- package/lib/format.ts +2 -2
- package/lib/types.ts +56 -9
- package/lib/view-builder-meta.ts +35 -0
- package/lib/workspace-layout.ts +14 -0
- package/lib/workspace-name.ts +14 -0
- package/package.json +4 -2
- package/server/AGENTS.md +3 -3
- package/server/api.ts +279 -60
- package/server/applets.ts +1 -1
- package/server/bundle-queue.ts +19 -0
- package/server/bundler/applet-css.ts +50 -0
- package/server/{build-applet.ts → bundler/build-applet.ts} +36 -26
- package/server/cli.ts +90 -7
- package/server/control.ts +106 -8
- package/server/env-apply.ts +2 -2
- package/server/harness/README.md +228 -0
- package/server/harness/claude-code/NOTES.md +578 -0
- package/{lib/claude-adapter.ts → server/harness/claude-code/adapter.ts} +67 -5
- package/server/harness/claude-code/index.ts +124 -0
- package/server/{mcp.ts → harness/claude-code/mcp.ts} +73 -16
- package/server/{cc-session.ts → harness/claude-code/session.ts} +42 -14
- package/server/harness/claude-code/sessions.ts +42 -0
- package/server/harness/codex/NOTES.md +239 -0
- package/server/harness/codex/adapter.ts +414 -0
- package/server/harness/codex/client.ts +343 -0
- package/server/harness/codex/index.ts +68 -0
- package/server/harness/codex/probe.ts +186 -0
- package/server/harness/codex/session.ts +617 -0
- package/server/harness/debug.ts +57 -0
- package/server/harness/openclaw/NOTES.md +316 -0
- package/server/{openclaw-adapter.ts → harness/openclaw/adapter.ts} +2 -2
- package/server/harness/openclaw/index.ts +93 -0
- package/server/{openclaw-session.ts → harness/openclaw/session.ts} +44 -9
- package/server/{openclaw-strip.ts → harness/openclaw/strip.ts} +3 -1
- package/server/harness/registry.ts +36 -0
- package/server/harness/types.ts +87 -0
- package/server/layout.ts +36 -11
- package/server/moi-scaffold.ts +56 -11
- package/server/registry.ts +30 -52
- package/server/state.ts +5 -38
- package/server/status.ts +7 -46
- package/server/vendor.ts +1 -1
- package/server/view-builders.ts +428 -0
- package/server/views.ts +0 -0
- package/server/web.ts +19 -40
- package/server/workspace-init.ts +11 -25
- package/tsconfig.json +1 -1
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +2 -1
- package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
- package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
- package/client/api/workspaces.ts +0 -427
- package/client/assets/hermes-nous.png +0 -0
- 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/hooks/useScrollFade.ts +0 -38
- package/client/lib/connection.ts +0 -238
- package/dist/chunk-07qf2tv1.css +0 -1
- package/dist/chunk-w18801vn.js +0 -672
- package/dist/hermes-nous-pznd63x9.png +0 -0
- /package/client/components/{playground → shared}/LedLogo.tsx +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/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
- /package/server/{agent.ts → harness/claude-code/models.ts} +0 -0
- /package/server/{openclaw.ts → harness/openclaw/discovery.ts} +0 -0
- /package/server/{openclaw-gateway.ts → harness/openclaw/gateway.ts} +0 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { IconChevronRight, IconEggCracked, IconLoader2, IconPlus } from '@tabler/icons-react'
|
|
2
|
+
import { Link, useLocation } from 'wouter'
|
|
3
|
+
|
|
4
|
+
import { useAddWorkspace, useDiscoveredWorkspaces, useWorkspaces } from './api'
|
|
5
|
+
import { HomeLogo } from './HomeLogo'
|
|
6
|
+
import { Button } from '@/client/components/ui/button'
|
|
7
|
+
import {
|
|
8
|
+
Collapsible,
|
|
9
|
+
CollapsibleContent,
|
|
10
|
+
CollapsibleTrigger
|
|
11
|
+
} from '@/client/components/ui/collapsible'
|
|
12
|
+
import { cn } from '@/client/lib/cn'
|
|
13
|
+
import { useUiStore } from '@/client/store/ui'
|
|
14
|
+
import {
|
|
15
|
+
WorkspaceTypeIcon,
|
|
16
|
+
workspaceDisplayName,
|
|
17
|
+
workspaceProviderIcon
|
|
18
|
+
} from '@/client/features/home/workspace-presentation'
|
|
19
|
+
import type { DiscoveredWorkspace, WorkspaceEntry } from '@/lib/types'
|
|
20
|
+
|
|
21
|
+
import { CreateWorkspaceDialog } from './CreateWorkspaceDialog'
|
|
22
|
+
import { WorkspacePreview } from './WorkspacePreview'
|
|
23
|
+
|
|
24
|
+
export function HomePage() {
|
|
25
|
+
const [, navigate] = useLocation()
|
|
26
|
+
const workspacesQuery = useWorkspaces()
|
|
27
|
+
const discoveredQuery = useDiscoveredWorkspaces()
|
|
28
|
+
const importMutation = useAddWorkspace()
|
|
29
|
+
const discoveredWorkspacesOpen = useUiStore(state => state.discoveredWorkspacesOpen)
|
|
30
|
+
const setDiscoveredWorkspacesOpen = useUiStore(state => state.setDiscoveredWorkspacesOpen)
|
|
31
|
+
|
|
32
|
+
if (workspacesQuery.isPending || discoveredQuery.isPending) {
|
|
33
|
+
return (
|
|
34
|
+
<div className="flex min-h-[50vh] items-center justify-center">
|
|
35
|
+
<IconLoader2 size={20} stroke={1.5} className="animate-spin text-muted-foreground" />
|
|
36
|
+
</div>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (workspacesQuery.isError || discoveredQuery.isError) {
|
|
41
|
+
return (
|
|
42
|
+
<div className="flex min-h-[50vh] items-center justify-center">
|
|
43
|
+
<p className="text-sm text-muted-foreground">Could not load spaces.</p>
|
|
44
|
+
</div>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const workspaces = workspacesQuery.data
|
|
49
|
+
const discovered = discoveredQuery.data
|
|
50
|
+
const count = workspaces.length
|
|
51
|
+
const importingPath =
|
|
52
|
+
importMutation.isPending && importMutation.variables ? importMutation.variables.path : null
|
|
53
|
+
|
|
54
|
+
function handleAdd(suggestion: DiscoveredWorkspace) {
|
|
55
|
+
importMutation.mutate(suggestion, {
|
|
56
|
+
onSuccess: entry => navigate(`/workspace/${entry.id}`)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className="mx-auto w-full max-w-3xl px-8 pt-14 pb-16">
|
|
62
|
+
<HomeLogo className="mb-8" />
|
|
63
|
+
|
|
64
|
+
{count > 0 ? (
|
|
65
|
+
<section className="mb-10">
|
|
66
|
+
<div className="mb-2 flex items-center justify-between gap-2">
|
|
67
|
+
<h1 className="text-sm font-medium text-foreground">My workspaces</h1>
|
|
68
|
+
<CreateWorkspaceDialog
|
|
69
|
+
trigger={
|
|
70
|
+
<Button variant="outline" size="sm">
|
|
71
|
+
<IconPlus data-icon="inline-start" stroke={1.75} />
|
|
72
|
+
New
|
|
73
|
+
</Button>
|
|
74
|
+
}
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 md:grid-cols-3">
|
|
79
|
+
{workspaces.map(ws => (
|
|
80
|
+
<WorkspaceCard key={ws.id} workspace={ws} />
|
|
81
|
+
))}
|
|
82
|
+
</div>
|
|
83
|
+
</section>
|
|
84
|
+
) : (
|
|
85
|
+
<div className="mb-10 flex flex-col items-center gap-4 px-8 pt-6 pb-12 text-center">
|
|
86
|
+
<IconEggCracked size={32} stroke={1.5} className="text-muted-foreground" />
|
|
87
|
+
<div className="flex flex-col gap-1.5">
|
|
88
|
+
<h2 className="font-medium">Let’s start with creating your first workspace</h2>
|
|
89
|
+
<p className="mx-auto max-w-sm text-sm text-muted-foreground">
|
|
90
|
+
Workspace is a place for all the chats, widgets, and views that share the same
|
|
91
|
+
context. Create a new one or import an existing folder you’ve worked in before.
|
|
92
|
+
</p>
|
|
93
|
+
</div>
|
|
94
|
+
<CreateWorkspaceDialog trigger={<Button>Create workspace</Button>} />
|
|
95
|
+
</div>
|
|
96
|
+
)}
|
|
97
|
+
|
|
98
|
+
{discovered.length > 0 && (
|
|
99
|
+
<section>
|
|
100
|
+
<Collapsible
|
|
101
|
+
open={discoveredWorkspacesOpen}
|
|
102
|
+
onOpenChange={setDiscoveredWorkspacesOpen}
|
|
103
|
+
className="group"
|
|
104
|
+
>
|
|
105
|
+
<CollapsibleTrigger
|
|
106
|
+
className={cn(
|
|
107
|
+
'group/trigger',
|
|
108
|
+
'flex w-full items-center gap-1 pb-4 text-left outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring',
|
|
109
|
+
'text-muted-foreground group-data-open:text-foreground hover:text-foreground'
|
|
110
|
+
)}
|
|
111
|
+
>
|
|
112
|
+
<span className="text-sm font-medium">Import from this computer</span>
|
|
113
|
+
<IconChevronRight
|
|
114
|
+
size={16}
|
|
115
|
+
stroke={2}
|
|
116
|
+
className={cn(
|
|
117
|
+
'opacity-0 transition-[opacity,transform]',
|
|
118
|
+
'group-hover/trigger:opacity-100 group-focus-visible/trigger:opacity-100 group-data-open:rotate-90'
|
|
119
|
+
)}
|
|
120
|
+
/>
|
|
121
|
+
</CollapsibleTrigger>
|
|
122
|
+
<CollapsibleContent>
|
|
123
|
+
<ul className="border-t border-border">
|
|
124
|
+
{discovered.map(item => (
|
|
125
|
+
<SuggestedRow
|
|
126
|
+
key={item.path}
|
|
127
|
+
suggestion={item}
|
|
128
|
+
onAdd={handleAdd}
|
|
129
|
+
loading={importingPath === item.path}
|
|
130
|
+
/>
|
|
131
|
+
))}
|
|
132
|
+
</ul>
|
|
133
|
+
{importMutation.isError && (
|
|
134
|
+
<p className="mt-3 text-xs text-destructive">{importMutation.error.message}</p>
|
|
135
|
+
)}
|
|
136
|
+
</CollapsibleContent>
|
|
137
|
+
</Collapsible>
|
|
138
|
+
</section>
|
|
139
|
+
)}
|
|
140
|
+
</div>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
type WorkspaceCardProps = {
|
|
145
|
+
workspace: WorkspaceEntry
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function WorkspaceCard({ workspace }: WorkspaceCardProps) {
|
|
149
|
+
const name = workspaceDisplayName(workspace)
|
|
150
|
+
const meta = formatAddedAt(workspace.addedAt)
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<Link
|
|
154
|
+
href={`/workspace/${workspace.id}`}
|
|
155
|
+
className="group flex min-w-0 flex-col gap-4 rounded-xl bg-card p-2 shadow-xs transition-shadow hover:shadow-sm"
|
|
156
|
+
>
|
|
157
|
+
<WorkspacePreview workspaceId={workspace.id} />
|
|
158
|
+
<div className="flex min-w-0 flex-col px-2 pb-2">
|
|
159
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
160
|
+
<img
|
|
161
|
+
src={workspace.icon ?? workspaceProviderIcon[workspace.type ?? 'claude-code']}
|
|
162
|
+
alt=""
|
|
163
|
+
className="size-4 shrink-0 rounded-[4px]"
|
|
164
|
+
/>
|
|
165
|
+
<span className="truncate text-sm font-medium text-foreground">{name}</span>
|
|
166
|
+
</div>
|
|
167
|
+
<div title={workspace.path} className="mt-2 truncate text-xs text-muted-foreground">
|
|
168
|
+
{workspace.displayPath ?? workspace.path}
|
|
169
|
+
</div>
|
|
170
|
+
<div className="mt-2 text-xs text-muted-foreground">{meta}</div>
|
|
171
|
+
</div>
|
|
172
|
+
</Link>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
type SuggestedRowProps = {
|
|
177
|
+
suggestion: DiscoveredWorkspace
|
|
178
|
+
onAdd: (suggestion: DiscoveredWorkspace) => void
|
|
179
|
+
loading: boolean
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function SuggestedRow({ suggestion, onAdd, loading }: SuggestedRowProps) {
|
|
183
|
+
const { path, type } = suggestion
|
|
184
|
+
const name = workspaceDisplayName(suggestion)
|
|
185
|
+
return (
|
|
186
|
+
<li className="flex items-center gap-2 border-b border-border px-1 py-3">
|
|
187
|
+
<WorkspaceTypeIcon type={type} />
|
|
188
|
+
<span className="shrink-0 text-sm font-medium text-foreground">{name}</span>
|
|
189
|
+
<span title={path} className="min-w-0 flex-1 truncate text-xs text-muted-foreground">
|
|
190
|
+
{suggestion.displayPath ?? path}
|
|
191
|
+
</span>
|
|
192
|
+
<Button variant="outline" size="sm" onClick={() => onAdd(suggestion)} disabled={loading}>
|
|
193
|
+
{loading ? (
|
|
194
|
+
<IconLoader2 stroke={1.75} className="animate-spin" />
|
|
195
|
+
) : (
|
|
196
|
+
<IconPlus stroke={1.75} />
|
|
197
|
+
)}
|
|
198
|
+
Add
|
|
199
|
+
</Button>
|
|
200
|
+
</li>
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function formatAddedAt(iso: string): string {
|
|
205
|
+
const ms = Date.now() - new Date(iso).getTime()
|
|
206
|
+
const mins = Math.floor(ms / 60000)
|
|
207
|
+
if (mins < 1) return 'Added just now'
|
|
208
|
+
if (mins < 60) return `Added ${mins} min${mins === 1 ? '' : 's'} ago`
|
|
209
|
+
const hours = Math.floor(mins / 60)
|
|
210
|
+
if (hours < 24) return `Added ${hours} hour${hours === 1 ? '' : 's'} ago`
|
|
211
|
+
const days = Math.floor(hours / 24)
|
|
212
|
+
if (days < 30) return `Added ${days} day${days === 1 ? '' : 's'} ago`
|
|
213
|
+
return `Added ${new Date(iso).toLocaleDateString()}`
|
|
214
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IconGhost } from '@tabler/icons-react'
|
|
2
2
|
|
|
3
|
-
import { useWorkspacePreview } from '
|
|
3
|
+
import { useWorkspacePreview } from './api'
|
|
4
4
|
|
|
5
5
|
type WorkspacePreviewProps = {
|
|
6
6
|
workspaceId: string
|
|
@@ -16,7 +16,7 @@ export function WorkspacePreview({ workspaceId }: WorkspacePreviewProps) {
|
|
|
16
16
|
const isEmpty = query.data !== undefined && !hasItems
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
|
-
<div className="flex
|
|
19
|
+
<div className="flex aspect-video w-full items-center justify-center rounded-sm bg-muted p-3">
|
|
20
20
|
{hasItems && (
|
|
21
21
|
<svg
|
|
22
22
|
viewBox={`0 0 ${cols} ${rows}`}
|
|
@@ -37,7 +37,7 @@ export function WorkspacePreview({ workspaceId }: WorkspacePreviewProps) {
|
|
|
37
37
|
</svg>
|
|
38
38
|
)}
|
|
39
39
|
{isEmpty && (
|
|
40
|
-
<
|
|
40
|
+
<IconGhost
|
|
41
41
|
size={20}
|
|
42
42
|
stroke={1.5}
|
|
43
43
|
className="animate-in text-muted-foreground/40 duration-300 fade-in"
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
|
|
3
|
+
import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
|
|
4
|
+
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
5
|
+
import type {
|
|
6
|
+
DiscoveredWorkspace,
|
|
7
|
+
WorkspaceEntry,
|
|
8
|
+
WorkspacePreview,
|
|
9
|
+
WorkspaceType
|
|
10
|
+
} from '@/lib/types'
|
|
11
|
+
|
|
12
|
+
export function upsertWorkspaceEntry(
|
|
13
|
+
entries: WorkspaceEntry[] | undefined,
|
|
14
|
+
entry: WorkspaceEntry
|
|
15
|
+
): WorkspaceEntry[] {
|
|
16
|
+
const current = entries ?? []
|
|
17
|
+
const existing = current.findIndex(item => item.id === entry.id || item.path === entry.path)
|
|
18
|
+
if (existing === -1) return [...current, entry]
|
|
19
|
+
return current.map((item, index) => (index === existing ? { ...item, ...entry } : item))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useWorkspaces() {
|
|
23
|
+
return useQuery<WorkspaceEntry[]>({
|
|
24
|
+
queryKey: workspaceKeys.all,
|
|
25
|
+
queryFn: () => requestJson('/api/workspaces'),
|
|
26
|
+
staleTime: Infinity,
|
|
27
|
+
refetchOnMount: 'always'
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useWorkspacePreview(workspaceId: string) {
|
|
32
|
+
return useQuery<WorkspacePreview>({
|
|
33
|
+
queryKey: workspaceKeys.preview(workspaceId),
|
|
34
|
+
queryFn: () => requestJson(`/api/workspaces/${workspaceId}/preview`),
|
|
35
|
+
staleTime: 60_000
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function useDiscoveredWorkspaces() {
|
|
40
|
+
return useQuery<DiscoveredWorkspace[]>({
|
|
41
|
+
queryKey: workspaceKeys.discover,
|
|
42
|
+
queryFn: () => requestJson('/api/workspaces/discover')
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function useAddWorkspace() {
|
|
47
|
+
const queryClient = useQueryClient()
|
|
48
|
+
return useMutation<WorkspaceEntry, Error, DiscoveredWorkspace>({
|
|
49
|
+
mutationFn: discovered =>
|
|
50
|
+
requestJson('/api/workspaces', jsonRequest('POST', discovered), 'Failed to add workspace'),
|
|
51
|
+
onSuccess: (entry, suggestion) => {
|
|
52
|
+
queryClient.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, previous =>
|
|
53
|
+
upsertWorkspaceEntry(previous, entry)
|
|
54
|
+
)
|
|
55
|
+
queryClient.setQueryData<DiscoveredWorkspace[]>(workspaceKeys.discover, previous =>
|
|
56
|
+
(previous ?? []).filter(item => item.path !== suggestion.path)
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type CreateWorkspaceInfo = {
|
|
63
|
+
root: string
|
|
64
|
+
displayRoot: string
|
|
65
|
+
canChooseFolder: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function useCreateWorkspaceInfo() {
|
|
69
|
+
return useQuery<CreateWorkspaceInfo>({
|
|
70
|
+
queryKey: workspaceKeys.createInfo,
|
|
71
|
+
queryFn: () => requestJson('/api/workspaces/create'),
|
|
72
|
+
staleTime: Infinity
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type ChooseFolderResult = { path: string } | { canceled: true }
|
|
77
|
+
|
|
78
|
+
export function useChooseFolder() {
|
|
79
|
+
return useMutation<ChooseFolderResult, Error, void>({
|
|
80
|
+
mutationFn: () =>
|
|
81
|
+
requestJson('/api/workspaces/choose-folder', { method: 'POST' }, 'Failed to choose folder')
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type CreateWorkspaceInput = {
|
|
86
|
+
name: string
|
|
87
|
+
type: WorkspaceType
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function useCreateWorkspace() {
|
|
91
|
+
const queryClient = useQueryClient()
|
|
92
|
+
return useMutation<WorkspaceEntry, Error, CreateWorkspaceInput>({
|
|
93
|
+
mutationFn: input =>
|
|
94
|
+
requestJson(
|
|
95
|
+
'/api/workspaces/create',
|
|
96
|
+
jsonRequest('POST', input),
|
|
97
|
+
'Failed to create workspace'
|
|
98
|
+
),
|
|
99
|
+
onSuccess: entry => {
|
|
100
|
+
queryClient.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, previous => [
|
|
101
|
+
...(previous ?? []),
|
|
102
|
+
entry
|
|
103
|
+
])
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function useReorderWorkspaces() {
|
|
109
|
+
const queryClient = useQueryClient()
|
|
110
|
+
return useMutation<WorkspaceEntry[], Error, string[], { previous?: WorkspaceEntry[] }>({
|
|
111
|
+
mutationFn: ids =>
|
|
112
|
+
requestJson('/api/workspaces/order', jsonRequest('PUT', { ids }), 'Failed to reorder spaces'),
|
|
113
|
+
onMutate: async ids => {
|
|
114
|
+
// Exact: only pause the workspace list itself — a prefix cancel would
|
|
115
|
+
// abort unrelated in-flight fetches (transcripts, widgets) that never
|
|
116
|
+
// retry on their own.
|
|
117
|
+
await queryClient.cancelQueries({ queryKey: workspaceKeys.all, exact: true })
|
|
118
|
+
const previous = queryClient.getQueryData<WorkspaceEntry[]>(workspaceKeys.all)
|
|
119
|
+
if (previous) {
|
|
120
|
+
const byId = new Map(previous.map(entry => [entry.id, entry]))
|
|
121
|
+
const ordered = ids
|
|
122
|
+
.map(id => byId.get(id))
|
|
123
|
+
.filter((entry): entry is WorkspaceEntry => Boolean(entry))
|
|
124
|
+
if (ordered.length === previous.length) {
|
|
125
|
+
queryClient.setQueryData(workspaceKeys.all, ordered)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { previous }
|
|
129
|
+
},
|
|
130
|
+
onError: (_error, _ids, context) => {
|
|
131
|
+
if (context?.previous) queryClient.setQueryData(workspaceKeys.all, context.previous)
|
|
132
|
+
queryClient.invalidateQueries({ queryKey: workspaceKeys.all, exact: true })
|
|
133
|
+
},
|
|
134
|
+
onSuccess: entries => {
|
|
135
|
+
queryClient.setQueryData(workspaceKeys.all, entries)
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function useRemoveWorkspace() {
|
|
141
|
+
const queryClient = useQueryClient()
|
|
142
|
+
return useMutation<void, Error, string>({
|
|
143
|
+
mutationFn: workspaceId =>
|
|
144
|
+
requestVoid(
|
|
145
|
+
`/api/workspaces/${workspaceId}`,
|
|
146
|
+
{ method: 'DELETE' },
|
|
147
|
+
'Failed to remove workspace'
|
|
148
|
+
),
|
|
149
|
+
onSuccess: (_result, workspaceId) => {
|
|
150
|
+
queryClient.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, previous =>
|
|
151
|
+
(previous ?? []).filter(workspace => workspace.id !== workspaceId)
|
|
152
|
+
)
|
|
153
|
+
queryClient.invalidateQueries({ queryKey: workspaceKeys.discover })
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import claudeIcon from '@/client/assets/claude.svg'
|
|
2
|
+
import openaiIcon from '@/client/assets/openai.svg'
|
|
3
|
+
import openclawIcon from '@/client/assets/openclaw.svg'
|
|
4
|
+
import { cn } from '@/client/lib/cn'
|
|
5
|
+
import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
|
|
6
|
+
|
|
7
|
+
export const workspaceProviderIcon: Record<WorkspaceType, string> = {
|
|
8
|
+
'claude-code': claudeIcon,
|
|
9
|
+
openclaw: openclawIcon,
|
|
10
|
+
codex: openaiIcon
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const workspaceTypeLabel: Record<WorkspaceType, string> = {
|
|
14
|
+
'claude-code': 'Claude',
|
|
15
|
+
openclaw: 'OpenClaw',
|
|
16
|
+
codex: 'Codex'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type WorkspaceTypeIconProps = {
|
|
20
|
+
type: WorkspaceType
|
|
21
|
+
className?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function WorkspaceTypeIcon({ type, className }: WorkspaceTypeIconProps) {
|
|
25
|
+
return (
|
|
26
|
+
<img
|
|
27
|
+
src={workspaceProviderIcon[type]}
|
|
28
|
+
alt=""
|
|
29
|
+
aria-label={workspaceTypeLabel[type]}
|
|
30
|
+
className={cn('size-4 shrink-0', className)}
|
|
31
|
+
/>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type WorkspaceDisplaySource = Pick<
|
|
36
|
+
WorkspaceEntry | DiscoveredWorkspace,
|
|
37
|
+
'name' | 'path' | 'type' | 'agentId'
|
|
38
|
+
>
|
|
39
|
+
|
|
40
|
+
export function workspaceDisplayName(workspace: WorkspaceDisplaySource): string {
|
|
41
|
+
if (workspace.name) return workspace.name
|
|
42
|
+
if (workspace.type === 'openclaw') return workspace.agentId ?? 'OpenClaw agent'
|
|
43
|
+
return workspace.path.split('/').pop() || workspace.path
|
|
44
|
+
}
|