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
|
@@ -9,7 +9,7 @@ A view is a **real app screen**, not a giant widget. Where a widget earns one gl
|
|
|
9
9
|
- **Own the whole frame.** The root is `w-full h-full` and handles **its own scrolling** (`overflow-auto`) — there is no outer scroll container. Provide your own padding, header, and chrome.
|
|
10
10
|
- **One view = one screen.** No client-side routing inside a view; cross-screen navigation is the workspace nav. Internal sub-navigation (tabs, a master/detail split) is yours to build.
|
|
11
11
|
- **Three states, always.** Loading → a skeleton that mirrors the real layout (never a spinner). Error → one human sentence + a retry. Empty → a short prompt, never blank.
|
|
12
|
-
- **Tailwind for static styling.** No custom CSS, no `@apply`, no static `style={{}}`. Icons only from `@tabler/icons-react`. Views import only from their own folder.
|
|
12
|
+
- **Tailwind for static styling.** No custom CSS, no `@apply`, no static `style={{}}`. Icons only from `@tabler/icons-react`; use the host project icon rule when present (`.agents/rules/icons.md`) instead of duplicating size/stroke guidance. Views import only from their own folder.
|
|
13
13
|
|
|
14
14
|
## Layout
|
|
15
15
|
|
package/client/api/workspaces.ts
DELETED
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
-
|
|
3
|
-
import { applyEvents } from '@/lib/format'
|
|
4
|
-
import type {
|
|
5
|
-
DiscoveredWorkspace,
|
|
6
|
-
McpServer,
|
|
7
|
-
SessionInfo,
|
|
8
|
-
StreamEvent,
|
|
9
|
-
ThreadConfig,
|
|
10
|
-
ViewInfo,
|
|
11
|
-
ViewState,
|
|
12
|
-
WidgetInfo,
|
|
13
|
-
WorkspaceEntry,
|
|
14
|
-
WorkspaceEnvView,
|
|
15
|
-
WorkspaceLayout,
|
|
16
|
-
WorkspaceModels,
|
|
17
|
-
WorkspacePreview,
|
|
18
|
-
WorkspaceType
|
|
19
|
-
} from '@/lib/types'
|
|
20
|
-
|
|
21
|
-
// `/api/workspaces/:id` payload: the persisted layout plus server-resolved
|
|
22
|
-
// metadata merged in by the route — `name` (settings override or folder name),
|
|
23
|
-
// `cwd` (workspace folder), `provider` (agent backend), and `agentId`.
|
|
24
|
-
export type WorkspaceLayoutResponse = WorkspaceLayout & {
|
|
25
|
-
cwd: string
|
|
26
|
-
name: string
|
|
27
|
-
provider?: WorkspaceType
|
|
28
|
-
agentId?: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Central query-key registry for the workspaces domain. Both the `/` view and
|
|
32
|
-
// the sidebar read from these keys, so the cache is shared.
|
|
33
|
-
export const workspaceKeys = {
|
|
34
|
-
all: ['workspaces'] as const,
|
|
35
|
-
discover: ['workspaces', 'discover'] as const,
|
|
36
|
-
createInfo: ['workspaces', 'create-info'] as const,
|
|
37
|
-
preview: (id: string) => ['workspaces', 'preview', id] as const,
|
|
38
|
-
layout: (id: string) => ['workspaces', 'layout', id] as const,
|
|
39
|
-
widgets: (id: string) => ['workspaces', 'widgets', id] as const,
|
|
40
|
-
views: (id: string) => ['workspaces', 'views', id] as const,
|
|
41
|
-
sessions: (id: string) => ['workspaces', 'sessions', id] as const,
|
|
42
|
-
// Materialized transcript (ViewState) for one thread. The connection manager
|
|
43
|
-
// patches this cache with live WS deltas; the `['workspaces','events']`
|
|
44
|
-
// prefix lets it invalidate every thread on reconnect.
|
|
45
|
-
events: (id: string, sessionId: string) => ['workspaces', 'events', id, sessionId] as const,
|
|
46
|
-
threadConfig: (id: string, sessionId: string) =>
|
|
47
|
-
['workspaces', 'threadConfig', id, sessionId] as const,
|
|
48
|
-
mcp: (id: string) => ['workspaces', 'mcp', id] as const,
|
|
49
|
-
models: (id: string) => ['workspaces', 'models', id] as const,
|
|
50
|
-
env: (id: string) => ['workspaces', 'env', id] as const
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Registered workspaces (the contents of workspaces.json).
|
|
54
|
-
//
|
|
55
|
-
// Cache-first: the list rarely changes, so `staleTime: Infinity` keeps it cached
|
|
56
|
-
// indefinitely (no focus/interval refetch churn) and mutations below keep it
|
|
57
|
-
// current. `refetchOnMount: 'always'` still fires a background refetch on every
|
|
58
|
-
// (re)mount — e.g. when the Sidebar remounts on collapse — while showing the
|
|
59
|
-
// cached data immediately, so the rows never flicker empty.
|
|
60
|
-
export function useWorkspaces() {
|
|
61
|
-
return useQuery<WorkspaceEntry[]>({
|
|
62
|
-
queryKey: workspaceKeys.all,
|
|
63
|
-
queryFn: () => fetch('/api/workspaces').then(r => r.json()),
|
|
64
|
-
staleTime: Infinity,
|
|
65
|
-
refetchOnMount: 'always'
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Per-workspace dashboard preview (widget grid thumbnail).
|
|
70
|
-
export function useWorkspacePreview(workspaceId: string) {
|
|
71
|
-
return useQuery<WorkspacePreview>({
|
|
72
|
-
queryKey: workspaceKeys.preview(workspaceId),
|
|
73
|
-
queryFn: () => fetch(`/api/workspaces/${workspaceId}/preview`).then(r => r.json()),
|
|
74
|
-
staleTime: 60_000
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Shared freshness policy for a workspace's resources: always considered stale
|
|
79
|
-
// (`staleTime: 0`) so every (re)mount and window-focus refetches in the
|
|
80
|
-
// background, while `gcTime` keeps the data cached when you switch to another
|
|
81
|
-
// workspace and back — so the panel shows instantly, then revalidates.
|
|
82
|
-
const WORKSPACE_RESOURCE_OPTS = {
|
|
83
|
-
staleTime: 0,
|
|
84
|
-
gcTime: 5 * 60_000,
|
|
85
|
-
refetchOnMount: true,
|
|
86
|
-
refetchOnWindowFocus: true
|
|
87
|
-
} as const
|
|
88
|
-
|
|
89
|
-
// Persisted layout + workspace metadata for a single workspace.
|
|
90
|
-
export function useWorkspaceLayout(workspaceId: string) {
|
|
91
|
-
return useQuery<WorkspaceLayoutResponse>({
|
|
92
|
-
queryKey: workspaceKeys.layout(workspaceId),
|
|
93
|
-
queryFn: () => fetch(`/api/workspaces/${workspaceId}`).then(r => r.json()),
|
|
94
|
-
...WORKSPACE_RESOURCE_OPTS
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Widgets declared in a workspace (the endpoint wraps them in `{ widgets }`).
|
|
99
|
-
export function useWorkspaceWidgets(workspaceId: string) {
|
|
100
|
-
return useQuery<WidgetInfo[]>({
|
|
101
|
-
queryKey: workspaceKeys.widgets(workspaceId),
|
|
102
|
-
queryFn: () =>
|
|
103
|
-
fetch(`/api/workspaces/${workspaceId}/widgets`)
|
|
104
|
-
.then(r => r.json())
|
|
105
|
-
.then((d: { widgets: WidgetInfo[] }) => d.widgets),
|
|
106
|
-
...WORKSPACE_RESOURCE_OPTS
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Views declared in a workspace (the endpoint wraps them in `{ views }`), in
|
|
111
|
-
// nav/manifest order.
|
|
112
|
-
export function useWorkspaceViews(workspaceId: string) {
|
|
113
|
-
return useQuery<ViewInfo[]>({
|
|
114
|
-
queryKey: workspaceKeys.views(workspaceId),
|
|
115
|
-
queryFn: () =>
|
|
116
|
-
fetch(`/api/workspaces/${workspaceId}/views`)
|
|
117
|
-
.then(r => r.json())
|
|
118
|
-
.then((d: { views: ViewInfo[] }) => d.views),
|
|
119
|
-
...WORKSPACE_RESOURCE_OPTS
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Sessions (chat threads) available in a workspace, latest first.
|
|
124
|
-
export function useWorkspaceSessions(workspaceId: string) {
|
|
125
|
-
return useQuery<SessionInfo[]>({
|
|
126
|
-
queryKey: workspaceKeys.sessions(workspaceId),
|
|
127
|
-
queryFn: () => fetch(`/api/workspaces/${workspaceId}/sessions`).then(r => r.json()),
|
|
128
|
-
...WORKSPACE_RESOURCE_OPTS
|
|
129
|
-
})
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// A thread's materialized transcript (ViewState), fetched once from `/events`
|
|
133
|
-
// and then kept live by WS deltas the connection manager folds in via
|
|
134
|
-
// setQueryData. `staleTime: Infinity` + no focus/mount refetch is deliberate:
|
|
135
|
-
// the app-wide socket never drops on navigation, so we never miss deltas while
|
|
136
|
-
// navigating and must NOT refetch (which would clobber live state). A real
|
|
137
|
-
// socket reconnect invalidates these queries to heal any offline gap. New
|
|
138
|
-
// (unsent) sessions are primed via setQueryData, so this never fetches an empty
|
|
139
|
-
// transcript over their optimistic turn.
|
|
140
|
-
export function useSessionView(workspaceId: string, sessionId: string | null) {
|
|
141
|
-
return useQuery<ViewState>({
|
|
142
|
-
queryKey: workspaceKeys.events(workspaceId, sessionId ?? ''),
|
|
143
|
-
queryFn: async () => {
|
|
144
|
-
const res = await fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/events`)
|
|
145
|
-
const evs: StreamEvent[] = res.ok ? await res.json() : []
|
|
146
|
-
return applyEvents(evs)
|
|
147
|
-
},
|
|
148
|
-
enabled: !!sessionId,
|
|
149
|
-
staleTime: Infinity,
|
|
150
|
-
gcTime: 5 * 60_000,
|
|
151
|
-
refetchOnMount: false,
|
|
152
|
-
refetchOnWindowFocus: false
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// MCP servers configured for a workspace (Claude Code only). Fetching is
|
|
157
|
-
// expensive — the server spawns an agent query to probe connection status — so
|
|
158
|
-
// this is cache-first: `staleTime`/`gcTime` Infinity means it's fetched once and
|
|
159
|
-
// then served from cache, surviving navigation between workspaces (no refetch on
|
|
160
|
-
// remount/focus). `enabled` gates it to Claude workspaces.
|
|
161
|
-
export function useWorkspaceMcp(workspaceId: string, enabled: boolean) {
|
|
162
|
-
return useQuery<McpServer[]>({
|
|
163
|
-
queryKey: workspaceKeys.mcp(workspaceId),
|
|
164
|
-
queryFn: () => fetch(`/api/workspaces/${workspaceId}/mcp`).then(r => r.json()),
|
|
165
|
-
enabled,
|
|
166
|
-
staleTime: Infinity,
|
|
167
|
-
gcTime: Infinity,
|
|
168
|
-
refetchOnMount: false,
|
|
169
|
-
refetchOnWindowFocus: false
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Models the workspace's agent backend can run (normalized across providers by
|
|
174
|
-
// the server). Like MCP status, the list is stable per workspace, so it's
|
|
175
|
-
// cache-first — fetched once and served from cache across navigation.
|
|
176
|
-
export function useWorkspaceModels(workspaceId: string) {
|
|
177
|
-
return useQuery<WorkspaceModels>({
|
|
178
|
-
queryKey: workspaceKeys.models(workspaceId),
|
|
179
|
-
queryFn: () => fetch(`/api/workspaces/${workspaceId}/models`).then(r => r.json()),
|
|
180
|
-
staleTime: Infinity,
|
|
181
|
-
gcTime: Infinity,
|
|
182
|
-
refetchOnMount: false,
|
|
183
|
-
refetchOnWindowFocus: false
|
|
184
|
-
})
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Per-thread agent settings (model + reasoning effort). Returns {} for threads
|
|
188
|
-
// that never overrode the workspace defaults; the picker falls back to the
|
|
189
|
-
// workspace layout defaults for display in that case. Gated on a sessionId so a
|
|
190
|
-
// brand-new (unsent) chat — which has no thread id yet — never fetches.
|
|
191
|
-
export function useThreadConfig(workspaceId: string, sessionId: string | null) {
|
|
192
|
-
return useQuery<ThreadConfig>({
|
|
193
|
-
queryKey: workspaceKeys.threadConfig(workspaceId, sessionId ?? ''),
|
|
194
|
-
queryFn: () =>
|
|
195
|
-
fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/config`).then(r => r.json()),
|
|
196
|
-
enabled: !!sessionId,
|
|
197
|
-
// Cache-first: thread config only changes via this app's own PUTs (which
|
|
198
|
-
// write through the cache), so refetching on every picker (re)mount would
|
|
199
|
-
// just flash the workspace default before the GET resolves. Fetch once per
|
|
200
|
-
// thread, then serve from cache.
|
|
201
|
-
staleTime: Infinity,
|
|
202
|
-
gcTime: 5 * 60_000,
|
|
203
|
-
refetchOnMount: false,
|
|
204
|
-
refetchOnWindowFocus: false
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Patch a thread's config (PUT returns the merged result). Writes the merged
|
|
209
|
-
// config straight into the query cache so the picker reflects it immediately.
|
|
210
|
-
export function useSaveThreadConfig(workspaceId: string) {
|
|
211
|
-
const qc = useQueryClient()
|
|
212
|
-
return useMutation<ThreadConfig, Error, { sessionId: string; patch: ThreadConfig }>({
|
|
213
|
-
mutationFn: async ({ patch, sessionId }) => {
|
|
214
|
-
const res = await fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/config`, {
|
|
215
|
-
method: 'PUT',
|
|
216
|
-
headers: { 'Content-Type': 'application/json' },
|
|
217
|
-
body: JSON.stringify(patch)
|
|
218
|
-
})
|
|
219
|
-
if (!res.ok) throw new Error('Failed to save thread config')
|
|
220
|
-
return res.json()
|
|
221
|
-
},
|
|
222
|
-
onSuccess: (next, { sessionId }) => {
|
|
223
|
-
qc.setQueryData<ThreadConfig>(workspaceKeys.threadConfig(workspaceId, sessionId), next)
|
|
224
|
-
}
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Persist a workspace's layout (widget grid, chat mode, theme). Callers update
|
|
229
|
-
// the layout query cache optimistically and use this to write through to the
|
|
230
|
-
// server, so it's a plain fire-and-forget PUT with no extra cache work.
|
|
231
|
-
export function useSaveLayout(workspaceId: string) {
|
|
232
|
-
return useMutation<void, Error, WorkspaceLayout>({
|
|
233
|
-
mutationFn: async layout => {
|
|
234
|
-
const res = await fetch(`/api/workspaces/${workspaceId}`, {
|
|
235
|
-
method: 'PUT',
|
|
236
|
-
headers: { 'Content-Type': 'application/json' },
|
|
237
|
-
body: JSON.stringify(layout)
|
|
238
|
-
})
|
|
239
|
-
if (!res.ok) throw new Error('Failed to save layout')
|
|
240
|
-
}
|
|
241
|
-
})
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// A workspace's effective env view (masked values + discovered `.env`).
|
|
245
|
-
export function useWorkspaceEnv(workspaceId: string) {
|
|
246
|
-
return useQuery<WorkspaceEnvView>({
|
|
247
|
-
queryKey: workspaceKeys.env(workspaceId),
|
|
248
|
-
queryFn: () => fetch(`/api/workspaces/${workspaceId}/env`).then(r => r.json()),
|
|
249
|
-
...WORKSPACE_RESOURCE_OPTS
|
|
250
|
-
})
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Patch of a workspace's env: set/remove custom secrets, or toggle `.env`
|
|
254
|
-
// inheritance. The PUT returns the fresh view (see useUpdateEnv).
|
|
255
|
-
export type EnvPatch = {
|
|
256
|
-
set?: Record<string, string>
|
|
257
|
-
remove?: string[]
|
|
258
|
-
inheritDotenv?: boolean
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// Apply an env patch. The endpoint returns the recomputed view, which we write
|
|
262
|
-
// straight into the cache so the list reflects the change immediately.
|
|
263
|
-
export function useUpdateEnv(workspaceId: string) {
|
|
264
|
-
const qc = useQueryClient()
|
|
265
|
-
return useMutation<WorkspaceEnvView, Error, EnvPatch>({
|
|
266
|
-
mutationFn: async patch => {
|
|
267
|
-
const res = await fetch(`/api/workspaces/${workspaceId}/env`, {
|
|
268
|
-
method: 'PUT',
|
|
269
|
-
headers: { 'Content-Type': 'application/json' },
|
|
270
|
-
body: JSON.stringify(patch)
|
|
271
|
-
})
|
|
272
|
-
if (!res.ok) throw new Error(await res.text())
|
|
273
|
-
return res.json()
|
|
274
|
-
},
|
|
275
|
-
onSuccess: next => {
|
|
276
|
-
qc.setQueryData<WorkspaceEnvView>(workspaceKeys.env(workspaceId), next)
|
|
277
|
-
}
|
|
278
|
-
})
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Set (or clear, with `null`) the workspace display-name override. The server
|
|
282
|
-
// broadcasts `workspace:updated`, but we also invalidate locally so the modal,
|
|
283
|
-
// header, and sidebar reflect the change without waiting on the socket.
|
|
284
|
-
export function useSaveWorkspaceName(workspaceId: string) {
|
|
285
|
-
const qc = useQueryClient()
|
|
286
|
-
return useMutation<void, Error, string | null>({
|
|
287
|
-
mutationFn: async name => {
|
|
288
|
-
const res = await fetch(`/api/workspaces/${workspaceId}/config`, {
|
|
289
|
-
method: 'PUT',
|
|
290
|
-
headers: { 'Content-Type': 'application/json' },
|
|
291
|
-
body: JSON.stringify({ name })
|
|
292
|
-
})
|
|
293
|
-
if (!res.ok) throw new Error('Failed to save name')
|
|
294
|
-
},
|
|
295
|
-
onSuccess: () => {
|
|
296
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.layout(workspaceId) })
|
|
297
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.all })
|
|
298
|
-
}
|
|
299
|
-
})
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Upload a raw image as the workspace icon (the server resizes to a 128×128
|
|
303
|
-
// WebP and returns the data URL). Used for direct uploads and for the canvas
|
|
304
|
-
// rasterized from an emoji/glyph + background.
|
|
305
|
-
export function useSaveWorkspaceIcon(workspaceId: string) {
|
|
306
|
-
const qc = useQueryClient()
|
|
307
|
-
return useMutation<{ icon: string }, Error, Blob>({
|
|
308
|
-
mutationFn: async blob => {
|
|
309
|
-
const res = await fetch(`/api/workspaces/${workspaceId}/icon`, {
|
|
310
|
-
method: 'PUT',
|
|
311
|
-
headers: { 'Content-Type': blob.type || 'application/octet-stream' },
|
|
312
|
-
body: blob
|
|
313
|
-
})
|
|
314
|
-
if (!res.ok) throw new Error(await res.text())
|
|
315
|
-
return res.json()
|
|
316
|
-
},
|
|
317
|
-
onSuccess: () => {
|
|
318
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.layout(workspaceId) })
|
|
319
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.all })
|
|
320
|
-
}
|
|
321
|
-
})
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// Reset the icon back to the provider default.
|
|
325
|
-
export function useResetWorkspaceIcon(workspaceId: string) {
|
|
326
|
-
const qc = useQueryClient()
|
|
327
|
-
return useMutation<void, Error, void>({
|
|
328
|
-
mutationFn: async () => {
|
|
329
|
-
const res = await fetch(`/api/workspaces/${workspaceId}/icon`, { method: 'DELETE' })
|
|
330
|
-
if (!res.ok) throw new Error('Failed to reset icon')
|
|
331
|
-
},
|
|
332
|
-
onSuccess: () => {
|
|
333
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.layout(workspaceId) })
|
|
334
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.all })
|
|
335
|
-
}
|
|
336
|
-
})
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// CC / OpenClaw directories found on the machine but not yet registered.
|
|
340
|
-
export function useDiscoveredWorkspaces() {
|
|
341
|
-
return useQuery<DiscoveredWorkspace[]>({
|
|
342
|
-
queryKey: workspaceKeys.discover,
|
|
343
|
-
queryFn: () => fetch('/api/workspaces/discover').then(r => r.json())
|
|
344
|
-
})
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// Import a discovered workspace into the registry (optimistically move it from
|
|
348
|
-
// the discover list into the registered list).
|
|
349
|
-
export function useAddWorkspace() {
|
|
350
|
-
const qc = useQueryClient()
|
|
351
|
-
return useMutation<WorkspaceEntry, Error, DiscoveredWorkspace>({
|
|
352
|
-
mutationFn: async discovered => {
|
|
353
|
-
const res = await fetch('/api/workspaces', {
|
|
354
|
-
method: 'POST',
|
|
355
|
-
headers: { 'Content-Type': 'application/json' },
|
|
356
|
-
body: JSON.stringify(discovered)
|
|
357
|
-
})
|
|
358
|
-
// The server provisions (skills + `.moi/`) before registering, so a
|
|
359
|
-
// failure comes back as a plain-text error, not an entry.
|
|
360
|
-
if (!res.ok) throw new Error(await res.text())
|
|
361
|
-
return res.json()
|
|
362
|
-
},
|
|
363
|
-
onSuccess: (entry, suggestion) => {
|
|
364
|
-
qc.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, prev => [...(prev ?? []), entry])
|
|
365
|
-
qc.setQueryData<DiscoveredWorkspace[]>(workspaceKeys.discover, prev =>
|
|
366
|
-
(prev ?? []).filter(s => s.path !== suggestion.path)
|
|
367
|
-
)
|
|
368
|
-
}
|
|
369
|
-
})
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// Where `/workspace/create` places new folders on disk. `displayRoot` is the
|
|
373
|
-
// home-relative form (e.g. "~/moi") shown in the create form.
|
|
374
|
-
export type CreateWorkspaceInfo = {
|
|
375
|
-
root: string
|
|
376
|
-
displayRoot: string
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
export function useCreateWorkspaceInfo() {
|
|
380
|
-
return useQuery<CreateWorkspaceInfo>({
|
|
381
|
-
queryKey: workspaceKeys.createInfo,
|
|
382
|
-
queryFn: () => fetch('/api/workspaces/create').then(r => r.json()),
|
|
383
|
-
staleTime: Infinity
|
|
384
|
-
})
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
export type CreateWorkspaceInput = {
|
|
388
|
-
name: string
|
|
389
|
-
type: WorkspaceType
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// Create a brand-new workspace folder (server provisions skills + `.moi/` and
|
|
393
|
-
// registers it). Non-2xx responses carry a user-facing message in the body.
|
|
394
|
-
export function useCreateWorkspace() {
|
|
395
|
-
const qc = useQueryClient()
|
|
396
|
-
return useMutation<WorkspaceEntry, Error, CreateWorkspaceInput>({
|
|
397
|
-
mutationFn: async input => {
|
|
398
|
-
const res = await fetch('/api/workspaces/create', {
|
|
399
|
-
method: 'POST',
|
|
400
|
-
headers: { 'Content-Type': 'application/json' },
|
|
401
|
-
body: JSON.stringify(input)
|
|
402
|
-
})
|
|
403
|
-
if (!res.ok) throw new Error(await res.text())
|
|
404
|
-
return res.json()
|
|
405
|
-
},
|
|
406
|
-
onSuccess: entry => {
|
|
407
|
-
qc.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, prev => [...(prev ?? []), entry])
|
|
408
|
-
}
|
|
409
|
-
})
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// Remove a workspace from the registry (re-discovery may surface it again).
|
|
413
|
-
export function useRemoveWorkspace() {
|
|
414
|
-
const qc = useQueryClient()
|
|
415
|
-
return useMutation<void, Error, WorkspaceEntry>({
|
|
416
|
-
mutationFn: async entry => {
|
|
417
|
-
const res = await fetch(`/api/workspaces/${entry.id}`, { method: 'DELETE' })
|
|
418
|
-
if (!res.ok) throw new Error('Failed to remove workspace')
|
|
419
|
-
},
|
|
420
|
-
onSuccess: (_void, entry) => {
|
|
421
|
-
qc.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, prev =>
|
|
422
|
-
(prev ?? []).filter(w => w.id !== entry.id)
|
|
423
|
-
)
|
|
424
|
-
qc.invalidateQueries({ queryKey: workspaceKeys.discover })
|
|
425
|
-
}
|
|
426
|
-
})
|
|
427
|
-
}
|
|
Binary file
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react'
|
|
2
|
-
|
|
3
|
-
import { Route, Switch, useLocation } from 'wouter'
|
|
4
|
-
|
|
5
|
-
import { setWorkspaceSwitchHandler } from '@/client/lib/connection'
|
|
6
|
-
|
|
7
|
-
import { HomePage } from './HomePage'
|
|
8
|
-
import { PlaygroundPage } from './playground/PlaygroundPage'
|
|
9
|
-
import { ToolCallsPage } from './playground/ToolCallsPage'
|
|
10
|
-
import { WorkspaceRoute } from './routes/workspace/[id]'
|
|
11
|
-
import { CreateWorkspacePage } from './routes/workspace/create'
|
|
12
|
-
|
|
13
|
-
// Top-level router — sets up all client-side routes
|
|
14
|
-
export function AppRouter() {
|
|
15
|
-
const [, navigate] = useLocation()
|
|
16
|
-
|
|
17
|
-
// When the server broadcasts a workspace:switch (e.g. from `moi start`),
|
|
18
|
-
// navigate to that workspace
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
setWorkspaceSwitchHandler(id => navigate(`/workspace/${id}`))
|
|
21
|
-
return () => setWorkspaceSwitchHandler(null)
|
|
22
|
-
}, [navigate])
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<Switch>
|
|
26
|
-
<Route path="/" component={HomePage} />
|
|
27
|
-
<Route path="/playground/tool-calls" component={ToolCallsPage} />
|
|
28
|
-
<Route path="/playground" component={PlaygroundPage} />
|
|
29
|
-
{/* Must precede `/workspace/:id` — the Switch matches in order, so the
|
|
30
|
-
literal route wins over the id pattern. */}
|
|
31
|
-
<Route path="/workspace/create" component={CreateWorkspacePage} />
|
|
32
|
-
<Route path="/workspace/:id">
|
|
33
|
-
{/* Key by id so switching workspaces mounts a fresh subtree — the
|
|
34
|
-
per-workspace chat store (and its websocket) tears down and resets
|
|
35
|
-
cleanly rather than leaking state across workspaces. Cached React
|
|
36
|
-
Query data keeps the remount instant. */}
|
|
37
|
-
{(params: { id: string }) => <WorkspaceRoute key={params.id} id={params.id} />}
|
|
38
|
-
</Route>
|
|
39
|
-
</Switch>
|
|
40
|
-
)
|
|
41
|
-
}
|