moi-computer 0.3.0 → 0.3.1-next.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/client/api/workspace-keys.ts +2 -2
- package/client/app/AppRouter.tsx +0 -2
- package/client/app/routes/WorkspaceRoute.tsx +3 -1
- package/client/app/shell/SidebarLayout.tsx +3 -16
- package/client/assets/openai.svg +1 -3
- package/client/components/shared/Composer.tsx +112 -0
- package/client/components/ui/button.tsx +1 -1
- package/client/components/ui/dropdown-menu.tsx +3 -3
- package/client/components/ui/tooltip.tsx +12 -15
- package/client/features/applets/WidgetErrorBoundary.tsx +19 -3
- package/client/features/applets/WidgetShell.tsx +8 -1
- package/client/features/applets/applet-log.ts +100 -0
- package/client/features/applets/useApplet.ts +21 -7
- package/client/features/chat/ChatComposer.tsx +33 -30
- package/client/features/chat/ChatPanel.tsx +5 -2
- package/client/features/chat/MarkdownContent.tsx +20 -2
- package/client/features/chat/ModelPicker.tsx +29 -41
- package/client/features/chat/TurnView.tsx +2 -2
- package/client/features/chat/chat-frames.ts +14 -6
- package/client/features/chat/chat-send.ts +1 -1
- package/client/features/chat/chat-store.ts +22 -17
- package/client/features/chat/model-order.ts +47 -0
- package/client/features/chat/tool-group/ToolOutput.tsx +4 -12
- package/client/features/chat/tool-group/format.ts +0 -6
- package/client/features/chat/useChat.ts +15 -2
- package/client/features/connectors/McpServerCards.tsx +95 -0
- package/client/features/connectors/api.ts +0 -11
- package/client/features/home/HomePage.tsx +45 -42
- package/client/features/home/WorkspacePreview.tsx +179 -38
- package/client/features/home/api.ts +24 -12
- package/client/features/home/workspace-presentation.tsx +17 -15
- package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +243 -0
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +95 -0
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +230 -0
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +35 -0
- package/client/features/home/workspace-setup/useWorkspaceImport.ts +61 -0
- package/client/features/settings/ConnectorsSettings.tsx +89 -0
- package/client/features/settings/GeneralSettings.tsx +12 -0
- package/client/features/settings/SettingsLayout.tsx +2 -2
- package/client/features/settings/WorkspaceSettings.tsx +8 -4
- package/client/features/views/ViewBuilderTab.tsx +28 -29
- package/client/features/views/useViewBuilderActions.ts +1 -1
- package/client/features/widgets/WidgetFrame.tsx +3 -0
- package/client/features/widgets/WidgetGrid.tsx +1 -0
- package/client/features/widgets/Widgets.tsx +12 -3
- package/client/features/widgets/api.ts +47 -0
- package/client/features/widgets/useWidgetThumbnails.ts +107 -0
- package/client/features/widgets/widget-snapshot.ts +71 -0
- package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -4
- package/client/features/workspace/WorkspaceScreen.tsx +19 -4
- package/client/features/workspace/api.ts +25 -3
- package/client/features/workspace/moi-context.ts +85 -0
- package/client/index.css +0 -5
- package/client/main.tsx +13 -4
- package/dist/{chunk-cs8vbert.js → chunk-1dfbr7n2.js} +2 -2
- package/dist/chunk-339jds4x.js +15 -0
- package/dist/chunk-3xsvsnhr.css +1 -0
- package/dist/{chunk-zpxrb1ce.js → chunk-anqmsbjt.js} +2 -2
- package/dist/chunk-hbvfb6sk.js +63 -0
- package/dist/chunk-jen6xcm1.js +14 -0
- package/dist/{chunk-kxmvv1ax.js → chunk-qwm5f6qk.js} +1 -1
- package/dist/{chunk-fjksw6xf.js → chunk-sxbfh73c.js} +1 -1
- package/dist/chunk-yp4srgqt.js +10 -0
- package/dist/index.html +1 -1
- package/dist/openai-ep9ht2pq.svg +1 -0
- package/lib/ids.ts +15 -0
- package/lib/moi-context.ts +170 -0
- package/lib/types.ts +95 -13
- package/lib/view-builder-directives.ts +16 -0
- package/lib/workspace-types.ts +12 -0
- package/package.json +4 -2
- package/server/api.ts +180 -34
- package/server/applet-log.ts +149 -0
- package/server/cli.ts +161 -7
- package/server/control.ts +81 -1
- package/server/functions.ts +44 -14
- package/server/harness/README.md +26 -9
- package/server/harness/claude-code/NOTES.md +20 -6
- package/server/harness/claude-code/adapter.ts +2 -2
- package/server/harness/claude-code/git-worktree.ts +32 -0
- package/server/harness/claude-code/index.ts +35 -13
- package/server/harness/claude-code/mcp.ts +16 -65
- package/server/harness/claude-code/models.ts +3 -0
- package/server/harness/claude-code/session.ts +196 -61
- package/server/harness/claude-code/sessions.ts +51 -0
- package/server/harness/codex/NOTES.md +41 -11
- package/server/harness/codex/adapter.ts +52 -6
- package/server/harness/codex/client.ts +69 -18
- package/server/harness/codex/discovery.ts +114 -0
- package/server/harness/codex/index.ts +12 -5
- package/server/harness/codex/probe.ts +4 -2
- package/server/harness/codex/session.ts +57 -5
- package/server/harness/executable.ts +82 -0
- package/server/harness/openclaw/adapter.ts +8 -1
- package/server/harness/openclaw/discovery.ts +139 -6
- package/server/harness/openclaw/gateway.ts +40 -18
- package/server/harness/openclaw/index.ts +12 -15
- package/server/harness/openclaw/session.ts +50 -10
- package/server/harness/openclaw/strip.ts +2 -2
- package/server/harness/shell-path.ts +79 -0
- package/server/harness/types.ts +37 -5
- package/server/layout.ts +81 -51
- package/server/registry.ts +57 -12
- package/server/scratchpad-assets.ts +41 -6
- package/server/scratchpad.ts +30 -0
- package/server/view-builders.ts +3 -2
- package/server/views.ts +5 -0
- package/server/web.ts +30 -8
- package/server/widgets.ts +23 -2
- package/server/workspace-import.ts +45 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +27 -3
- package/client/features/connectors/ConnectorsPage.tsx +0 -92
- package/client/features/connectors/McpMenu.tsx +0 -145
- package/client/features/home/CreateWorkspaceDialog.tsx +0 -130
- package/client/features/home/CreateWorkspaceDialogSteps.tsx +0 -234
- package/dist/chunk-4vf1t6v1.js +0 -10
- package/dist/chunk-4z52b2av.css +0 -1
- package/dist/chunk-b4b276wx.js +0 -15
- package/dist/chunk-y82s1jxm.js +0 -61
- package/dist/openai-h13pza4b.svg +0 -3
- package/lib/view-builder-meta.ts +0 -35
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import claudeIcon from '@/client/assets/claude.svg'
|
|
2
2
|
import openaiIcon from '@/client/assets/openai.svg'
|
|
3
3
|
import openclawIcon from '@/client/assets/openclaw.svg'
|
|
4
|
-
import { cn } from '@/client/lib/cn'
|
|
5
4
|
import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
|
|
6
5
|
|
|
7
6
|
export const workspaceProviderIcon: Record<WorkspaceType, string> = {
|
|
@@ -16,28 +15,31 @@ export const workspaceTypeLabel: Record<WorkspaceType, string> = {
|
|
|
16
15
|
codex: 'Codex'
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
type
|
|
20
|
-
|
|
21
|
-
className?: string
|
|
18
|
+
type WorkspaceAgentIconsProps = {
|
|
19
|
+
types: WorkspaceType[]
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
export function
|
|
22
|
+
export function WorkspaceAgentIcons({ types }: WorkspaceAgentIconsProps) {
|
|
23
|
+
const label = types.map(type => workspaceTypeLabel[type]).join(', ')
|
|
24
|
+
|
|
25
25
|
return (
|
|
26
|
-
<img
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
<span role="img" aria-label={label} className="inline-flex shrink-0 items-center -space-x-0.5">
|
|
27
|
+
{types.map(type => (
|
|
28
|
+
<img
|
|
29
|
+
key={type}
|
|
30
|
+
src={workspaceProviderIcon[type]}
|
|
31
|
+
alt=""
|
|
32
|
+
className="size-4 shrink-0 rounded-full bg-muted ring-2 ring-muted"
|
|
33
|
+
/>
|
|
34
|
+
))}
|
|
35
|
+
</span>
|
|
32
36
|
)
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
type WorkspaceDisplaySource =
|
|
36
|
-
WorkspaceEntry | DiscoveredWorkspace,
|
|
37
|
-
'name' | 'path' | 'type' | 'agentId'
|
|
38
|
-
>
|
|
39
|
+
type WorkspaceDisplaySource = WorkspaceEntry | DiscoveredWorkspace
|
|
39
40
|
|
|
40
41
|
export function workspaceDisplayName(workspace: WorkspaceDisplaySource): string {
|
|
42
|
+
if ('types' in workspace) return workspace.path.split('/').pop() || workspace.path
|
|
41
43
|
if (workspace.name) return workspace.name
|
|
42
44
|
if (workspace.type === 'openclaw') return workspace.agentId ?? 'OpenClaw agent'
|
|
43
45
|
return workspace.path.split('/').pop() || workspace.path
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { type FormEvent, type ReactElement, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { useLocation } from 'wouter'
|
|
4
|
+
|
|
5
|
+
import { useChooseFolder, useCreateWorkspace, useWorkspaceSetupInfo } from '../api'
|
|
6
|
+
import { Button } from '@/client/components/ui/button'
|
|
7
|
+
import {
|
|
8
|
+
Dialog,
|
|
9
|
+
DialogDescription,
|
|
10
|
+
DialogTitle,
|
|
11
|
+
DialogTrigger
|
|
12
|
+
} from '@/client/components/ui/dialog'
|
|
13
|
+
import { Input } from '@/client/components/ui/input'
|
|
14
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
|
|
15
|
+
import { cn } from '@/client/lib/cn'
|
|
16
|
+
import { validateWorkspaceFolderName } from '@/lib/workspace-name'
|
|
17
|
+
import { WORKSPACE_TYPE_ORDER } from '@/lib/workspace-types'
|
|
18
|
+
import type { WorkspaceType } from '@/lib/types'
|
|
19
|
+
|
|
20
|
+
import { ImportWorkspaceStep } from './ImportWorkspaceDialog'
|
|
21
|
+
import { WorkspaceAgentStep } from './WorkspaceAgentStep'
|
|
22
|
+
import { WorkspaceDialogContent } from './WorkspaceDialogContent'
|
|
23
|
+
import { useWorkspaceImport } from './useWorkspaceImport'
|
|
24
|
+
|
|
25
|
+
type CreateWorkspaceDialogProps = {
|
|
26
|
+
trigger: ReactElement
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type CreateWorkspaceStep = 'agent' | 'name'
|
|
30
|
+
|
|
31
|
+
const DEFAULT_WORKSPACE_TYPE = WORKSPACE_TYPE_ORDER[0]
|
|
32
|
+
|
|
33
|
+
export function CreateWorkspaceDialog({ trigger }: CreateWorkspaceDialogProps) {
|
|
34
|
+
const [, navigate] = useLocation()
|
|
35
|
+
const info = useWorkspaceSetupInfo()
|
|
36
|
+
const createMutation = useCreateWorkspace()
|
|
37
|
+
const chooseFolder = useChooseFolder()
|
|
38
|
+
const importFlow = useWorkspaceImport({ onSuccess: entry => finish(entry.id) })
|
|
39
|
+
|
|
40
|
+
const [open, setOpen] = useState(false)
|
|
41
|
+
const [step, setStep] = useState<CreateWorkspaceStep>('agent')
|
|
42
|
+
const [type, setType] = useState<WorkspaceType>(DEFAULT_WORKSPACE_TYPE)
|
|
43
|
+
const [name, setName] = useState('')
|
|
44
|
+
|
|
45
|
+
const trimmedName = name.trim()
|
|
46
|
+
const nameError = trimmedName ? validateWorkspaceFolderName(trimmedName) : null
|
|
47
|
+
const canChooseFolder = info.data?.canChooseFolder ?? true
|
|
48
|
+
const isImporting = chooseFolder.isPending || importFlow.isPending
|
|
49
|
+
const isCreating = createMutation.isPending
|
|
50
|
+
|
|
51
|
+
function finish(workspaceId: string) {
|
|
52
|
+
setOpen(false)
|
|
53
|
+
navigate(`/workspace/${workspaceId}`)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function resetDialog() {
|
|
57
|
+
setStep('agent')
|
|
58
|
+
setType(DEFAULT_WORKSPACE_TYPE)
|
|
59
|
+
setName('')
|
|
60
|
+
chooseFolder.reset()
|
|
61
|
+
importFlow.reset()
|
|
62
|
+
createMutation.reset()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function chooseExistingFolder() {
|
|
66
|
+
if (isImporting) return
|
|
67
|
+
chooseFolder.reset()
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const result = await chooseFolder.mutateAsync()
|
|
71
|
+
if (!('canceled' in result)) importFlow.startImport(result)
|
|
72
|
+
} catch {
|
|
73
|
+
// The agent step renders the folder-picker error.
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function continueToName() {
|
|
78
|
+
createMutation.reset()
|
|
79
|
+
setStep('name')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function createWorkspace() {
|
|
83
|
+
if (!trimmedName || nameError || isCreating) return
|
|
84
|
+
createMutation.reset()
|
|
85
|
+
createMutation.mutate({ name: trimmedName, type }, { onSuccess: entry => finish(entry.id) })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Dialog
|
|
90
|
+
open={open}
|
|
91
|
+
onOpenChange={setOpen}
|
|
92
|
+
onOpenChangeComplete={nextOpen => {
|
|
93
|
+
if (!nextOpen) resetDialog()
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<DialogTrigger render={trigger} />
|
|
97
|
+
<WorkspaceDialogContent>
|
|
98
|
+
{importFlow.choice ? (
|
|
99
|
+
<ImportWorkspaceStep
|
|
100
|
+
choice={importFlow.choice}
|
|
101
|
+
availability={info.data?.availability}
|
|
102
|
+
isPending={importFlow.isPending}
|
|
103
|
+
errorMessage={importFlow.error?.message}
|
|
104
|
+
onTypeChange={importFlow.selectType}
|
|
105
|
+
onCancel={importFlow.reset}
|
|
106
|
+
onSubmit={importFlow.submit}
|
|
107
|
+
/>
|
|
108
|
+
) : step === 'agent' ? (
|
|
109
|
+
<WorkspaceAgentStep
|
|
110
|
+
title="Create new workspace"
|
|
111
|
+
selectedType={type}
|
|
112
|
+
availability={info.data?.availability}
|
|
113
|
+
isPending={isImporting}
|
|
114
|
+
errorMessage={(chooseFolder.error ?? importFlow.error)?.message}
|
|
115
|
+
secondaryAction={
|
|
116
|
+
<ExistingFolderButton
|
|
117
|
+
available={canChooseFolder}
|
|
118
|
+
disabled={isImporting}
|
|
119
|
+
onClick={chooseExistingFolder}
|
|
120
|
+
/>
|
|
121
|
+
}
|
|
122
|
+
primaryLabel="Next"
|
|
123
|
+
onTypeChange={setType}
|
|
124
|
+
onSubmit={continueToName}
|
|
125
|
+
/>
|
|
126
|
+
) : (
|
|
127
|
+
<WorkspaceNameStep
|
|
128
|
+
name={name}
|
|
129
|
+
validationError={nameError}
|
|
130
|
+
requestError={createMutation.error?.message}
|
|
131
|
+
isPending={isCreating}
|
|
132
|
+
onNameChange={setName}
|
|
133
|
+
onSubmit={createWorkspace}
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
136
|
+
</WorkspaceDialogContent>
|
|
137
|
+
</Dialog>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
type WorkspaceNameStepProps = {
|
|
142
|
+
name: string
|
|
143
|
+
validationError: string | null
|
|
144
|
+
requestError?: string
|
|
145
|
+
isPending: boolean
|
|
146
|
+
onNameChange: (name: string) => void
|
|
147
|
+
onSubmit: () => void
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function WorkspaceNameStep({
|
|
151
|
+
name,
|
|
152
|
+
validationError,
|
|
153
|
+
requestError,
|
|
154
|
+
isPending,
|
|
155
|
+
onNameChange,
|
|
156
|
+
onSubmit
|
|
157
|
+
}: WorkspaceNameStepProps) {
|
|
158
|
+
function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
|
159
|
+
event.preventDefault()
|
|
160
|
+
onSubmit()
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
<form className="flex flex-col gap-5" onSubmit={handleSubmit}>
|
|
165
|
+
<div className="flex flex-col gap-0.5 pr-8">
|
|
166
|
+
<DialogTitle>Create new workspace</DialogTitle>
|
|
167
|
+
<DialogDescription>Give it a short and recognizable name</DialogDescription>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<div className="flex flex-col gap-2">
|
|
171
|
+
<label htmlFor="workspace-name" className="sr-only">
|
|
172
|
+
Workspace name
|
|
173
|
+
</label>
|
|
174
|
+
<Input
|
|
175
|
+
id="workspace-name"
|
|
176
|
+
value={name}
|
|
177
|
+
onChange={event => onNameChange(event.target.value)}
|
|
178
|
+
placeholder="my-workspace"
|
|
179
|
+
autoFocus
|
|
180
|
+
aria-invalid={Boolean(validationError)}
|
|
181
|
+
aria-describedby={validationError ? 'workspace-name-error' : undefined}
|
|
182
|
+
autoComplete="off"
|
|
183
|
+
spellCheck={false}
|
|
184
|
+
/>
|
|
185
|
+
{validationError && (
|
|
186
|
+
<p id="workspace-name-error" role="alert" className="text-xs text-destructive">
|
|
187
|
+
{validationError}
|
|
188
|
+
</p>
|
|
189
|
+
)}
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
{requestError && (
|
|
193
|
+
<p role="alert" className="text-xs text-destructive">
|
|
194
|
+
{requestError}
|
|
195
|
+
</p>
|
|
196
|
+
)}
|
|
197
|
+
|
|
198
|
+
<div className="flex items-center justify-end gap-2">
|
|
199
|
+
<Button type="submit" disabled={!name.trim() || Boolean(validationError) || isPending}>
|
|
200
|
+
{isPending ? 'Creating…' : 'Create workspace'}
|
|
201
|
+
</Button>
|
|
202
|
+
</div>
|
|
203
|
+
</form>
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
type ExistingFolderButtonProps = {
|
|
208
|
+
available: boolean
|
|
209
|
+
disabled: boolean
|
|
210
|
+
onClick: () => void
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function ExistingFolderButton({ available, disabled, onClick }: ExistingFolderButtonProps) {
|
|
214
|
+
const button = (
|
|
215
|
+
<Button
|
|
216
|
+
variant="secondary"
|
|
217
|
+
disabled={available && disabled}
|
|
218
|
+
aria-disabled={!available || undefined}
|
|
219
|
+
onClick={event => {
|
|
220
|
+
if (!available) {
|
|
221
|
+
event.preventDefault()
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
onClick()
|
|
225
|
+
}}
|
|
226
|
+
className={cn(!available && 'cursor-not-allowed opacity-50')}
|
|
227
|
+
>
|
|
228
|
+
Use existing folder
|
|
229
|
+
</Button>
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
if (available) return button
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<Tooltip>
|
|
236
|
+
<TooltipTrigger render={button} />
|
|
237
|
+
<TooltipContent>
|
|
238
|
+
Run <code className="rounded-[4px] bg-accent px-1 py-0.5 font-mono">moi init</code> in the
|
|
239
|
+
folder to add it manually
|
|
240
|
+
</TooltipContent>
|
|
241
|
+
</Tooltip>
|
|
242
|
+
)
|
|
243
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { Button } from '@/client/components/ui/button'
|
|
4
|
+
import { Dialog } from '@/client/components/ui/dialog'
|
|
5
|
+
import { workspaceDisplayName } from '@/client/features/home/workspace-presentation'
|
|
6
|
+
import type { HarnessAvailability, WorkspaceType } from '@/lib/types'
|
|
7
|
+
|
|
8
|
+
import { WorkspaceAgentStep } from './WorkspaceAgentStep'
|
|
9
|
+
import { WorkspaceDialogContent } from './WorkspaceDialogContent'
|
|
10
|
+
import type { WorkspaceImportChoice } from './useWorkspaceImport'
|
|
11
|
+
|
|
12
|
+
type ImportWorkspaceStepProps = {
|
|
13
|
+
choice: WorkspaceImportChoice
|
|
14
|
+
availability?: Partial<Record<WorkspaceType, HarnessAvailability>>
|
|
15
|
+
isPending: boolean
|
|
16
|
+
errorMessage?: string
|
|
17
|
+
onTypeChange: (type: WorkspaceType) => void
|
|
18
|
+
onCancel: () => void
|
|
19
|
+
onSubmit: () => void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function ImportWorkspaceStep({
|
|
23
|
+
choice,
|
|
24
|
+
availability,
|
|
25
|
+
isPending,
|
|
26
|
+
errorMessage,
|
|
27
|
+
onTypeChange,
|
|
28
|
+
onCancel,
|
|
29
|
+
onSubmit
|
|
30
|
+
}: ImportWorkspaceStepProps) {
|
|
31
|
+
return (
|
|
32
|
+
<WorkspaceAgentStep
|
|
33
|
+
title={`Import ${workspaceDisplayName(choice.workspace)}`}
|
|
34
|
+
selectedType={choice.selectedType}
|
|
35
|
+
detectedTypes={choice.workspace.types}
|
|
36
|
+
availability={availability}
|
|
37
|
+
isPending={isPending}
|
|
38
|
+
errorMessage={errorMessage}
|
|
39
|
+
secondaryAction={
|
|
40
|
+
<Button variant="secondary" onClick={onCancel} disabled={isPending}>
|
|
41
|
+
Cancel
|
|
42
|
+
</Button>
|
|
43
|
+
}
|
|
44
|
+
primaryLabel="Add workspace"
|
|
45
|
+
pendingLabel="Adding…"
|
|
46
|
+
onTypeChange={onTypeChange}
|
|
47
|
+
onSubmit={onSubmit}
|
|
48
|
+
/>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type ImportWorkspaceDialogProps = Omit<ImportWorkspaceStepProps, 'onCancel'> & {
|
|
53
|
+
onReset: () => void
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function ImportWorkspaceDialog({
|
|
57
|
+
choice,
|
|
58
|
+
availability,
|
|
59
|
+
isPending,
|
|
60
|
+
errorMessage,
|
|
61
|
+
onTypeChange,
|
|
62
|
+
onSubmit,
|
|
63
|
+
onReset
|
|
64
|
+
}: ImportWorkspaceDialogProps) {
|
|
65
|
+
const [open, setOpen] = useState(true)
|
|
66
|
+
|
|
67
|
+
function handleOpenChange(nextOpen: boolean) {
|
|
68
|
+
if (!nextOpen && isPending) return
|
|
69
|
+
setOpen(nextOpen)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function handleOpenChangeComplete(nextOpen: boolean) {
|
|
73
|
+
if (!nextOpen) onReset()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Dialog
|
|
78
|
+
open={open}
|
|
79
|
+
onOpenChange={handleOpenChange}
|
|
80
|
+
onOpenChangeComplete={handleOpenChangeComplete}
|
|
81
|
+
>
|
|
82
|
+
<WorkspaceDialogContent closeDisabled={isPending}>
|
|
83
|
+
<ImportWorkspaceStep
|
|
84
|
+
choice={choice}
|
|
85
|
+
availability={availability}
|
|
86
|
+
isPending={isPending}
|
|
87
|
+
errorMessage={errorMessage}
|
|
88
|
+
onTypeChange={onTypeChange}
|
|
89
|
+
onCancel={() => setOpen(false)}
|
|
90
|
+
onSubmit={onSubmit}
|
|
91
|
+
/>
|
|
92
|
+
</WorkspaceDialogContent>
|
|
93
|
+
</Dialog>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { type ReactNode, useEffect } from 'react'
|
|
2
|
+
|
|
3
|
+
import { IconCircleCheckFilled } from '@tabler/icons-react'
|
|
4
|
+
|
|
5
|
+
import { Button } from '@/client/components/ui/button'
|
|
6
|
+
import { DialogDescription, DialogTitle } from '@/client/components/ui/dialog'
|
|
7
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
|
|
8
|
+
import {
|
|
9
|
+
workspaceProviderIcon,
|
|
10
|
+
workspaceTypeLabel
|
|
11
|
+
} from '@/client/features/home/workspace-presentation'
|
|
12
|
+
import { cn } from '@/client/lib/cn'
|
|
13
|
+
import { WORKSPACE_TYPE_ORDER } from '@/lib/workspace-types'
|
|
14
|
+
import type { HarnessAvailability, WorkspaceType } from '@/lib/types'
|
|
15
|
+
|
|
16
|
+
const WORKSPACE_AGENT_DESCRIPTION = 'Choose which agent moi will use to build your workspace'
|
|
17
|
+
const OPENCLAW_LOCKED_DESCRIPTION =
|
|
18
|
+
'Initialize OpenClaw in the folder\nmanually, then import it to moi'
|
|
19
|
+
|
|
20
|
+
const workspaceAgentDescription: Record<WorkspaceType, string> = {
|
|
21
|
+
'claude-code': 'By Anthropic',
|
|
22
|
+
codex: 'By OpenAI',
|
|
23
|
+
openclaw: 'Open-source'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type WorkspaceAgentOption = {
|
|
27
|
+
type: WorkspaceType
|
|
28
|
+
description: string
|
|
29
|
+
disabled: boolean
|
|
30
|
+
disabledReason?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type WorkspaceAgentOptionsInput = {
|
|
34
|
+
availability?: Partial<Record<WorkspaceType, HarnessAvailability>>
|
|
35
|
+
detectedTypes?: WorkspaceType[]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getWorkspaceAgentOptions({
|
|
39
|
+
availability,
|
|
40
|
+
detectedTypes = []
|
|
41
|
+
}: WorkspaceAgentOptionsInput): WorkspaceAgentOption[] {
|
|
42
|
+
return WORKSPACE_TYPE_ORDER.map(type => {
|
|
43
|
+
const state = availability?.[type]
|
|
44
|
+
const unavailableReason = state?.available === false ? state.reason : undefined
|
|
45
|
+
const openClawReason =
|
|
46
|
+
type === 'openclaw' && !detectedTypes.includes(type) ? OPENCLAW_LOCKED_DESCRIPTION : undefined
|
|
47
|
+
const disabledReason = unavailableReason ?? openClawReason
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
type,
|
|
51
|
+
description: workspaceAgentDescription[type],
|
|
52
|
+
disabled: Boolean(disabledReason),
|
|
53
|
+
...(disabledReason ? { disabledReason } : {})
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function resolveWorkspaceAgentSelection(
|
|
59
|
+
options: WorkspaceAgentOption[],
|
|
60
|
+
selectedType: WorkspaceType
|
|
61
|
+
): WorkspaceType | undefined {
|
|
62
|
+
const selected = options.find(option => option.type === selectedType)
|
|
63
|
+
if (selected && !selected.disabled) return selected.type
|
|
64
|
+
return options.find(option => !option.disabled)?.type
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type WorkspaceAgentStepProps = {
|
|
68
|
+
title: string
|
|
69
|
+
selectedType: WorkspaceType
|
|
70
|
+
detectedTypes?: WorkspaceType[]
|
|
71
|
+
availability?: Partial<Record<WorkspaceType, HarnessAvailability>>
|
|
72
|
+
isPending: boolean
|
|
73
|
+
errorMessage?: string
|
|
74
|
+
secondaryAction: ReactNode
|
|
75
|
+
primaryLabel: string
|
|
76
|
+
pendingLabel?: string
|
|
77
|
+
onTypeChange: (type: WorkspaceType) => void
|
|
78
|
+
onSubmit: () => void
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function WorkspaceAgentStep({
|
|
82
|
+
title,
|
|
83
|
+
selectedType,
|
|
84
|
+
detectedTypes,
|
|
85
|
+
availability,
|
|
86
|
+
isPending,
|
|
87
|
+
errorMessage,
|
|
88
|
+
secondaryAction,
|
|
89
|
+
primaryLabel,
|
|
90
|
+
pendingLabel,
|
|
91
|
+
onTypeChange,
|
|
92
|
+
onSubmit
|
|
93
|
+
}: WorkspaceAgentStepProps) {
|
|
94
|
+
const options = getWorkspaceAgentOptions({ availability, detectedTypes })
|
|
95
|
+
const selectableType = resolveWorkspaceAgentSelection(options, selectedType)
|
|
96
|
+
const selectedUnavailable = selectableType !== selectedType
|
|
97
|
+
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (selectableType && selectedUnavailable) onTypeChange(selectableType)
|
|
100
|
+
}, [onTypeChange, selectableType, selectedUnavailable])
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<div className="flex flex-col gap-5">
|
|
104
|
+
<div className="flex flex-col gap-0.5 pr-8">
|
|
105
|
+
<DialogTitle>{title}</DialogTitle>
|
|
106
|
+
<DialogDescription>{WORKSPACE_AGENT_DESCRIPTION}</DialogDescription>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<WorkspaceAgentSelector
|
|
110
|
+
options={options}
|
|
111
|
+
selectedType={selectedUnavailable ? undefined : selectedType}
|
|
112
|
+
onTypeChange={onTypeChange}
|
|
113
|
+
/>
|
|
114
|
+
|
|
115
|
+
{errorMessage && (
|
|
116
|
+
<p role="alert" className="text-xs text-destructive">
|
|
117
|
+
{errorMessage}
|
|
118
|
+
</p>
|
|
119
|
+
)}
|
|
120
|
+
|
|
121
|
+
<div className="flex items-center justify-end gap-2">
|
|
122
|
+
{secondaryAction}
|
|
123
|
+
<Button onClick={onSubmit} disabled={isPending || selectedUnavailable}>
|
|
124
|
+
{isPending && pendingLabel ? pendingLabel : primaryLabel}
|
|
125
|
+
</Button>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type WorkspaceAgentSelectorProps = {
|
|
132
|
+
options: WorkspaceAgentOption[]
|
|
133
|
+
selectedType?: WorkspaceType
|
|
134
|
+
onTypeChange: (type: WorkspaceType) => void
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function WorkspaceAgentSelector({
|
|
138
|
+
options,
|
|
139
|
+
selectedType,
|
|
140
|
+
onTypeChange
|
|
141
|
+
}: WorkspaceAgentSelectorProps) {
|
|
142
|
+
return (
|
|
143
|
+
<div
|
|
144
|
+
role="group"
|
|
145
|
+
aria-label="Agent"
|
|
146
|
+
className={cn('grid gap-2', options.length > 2 ? 'grid-cols-3' : 'grid-cols-2')}
|
|
147
|
+
>
|
|
148
|
+
{options.map(option => (
|
|
149
|
+
<WorkspaceAgentOptionButton
|
|
150
|
+
key={option.type}
|
|
151
|
+
option={option}
|
|
152
|
+
selected={selectedType === option.type}
|
|
153
|
+
onSelect={onTypeChange}
|
|
154
|
+
/>
|
|
155
|
+
))}
|
|
156
|
+
</div>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
type WorkspaceAgentOptionButtonProps = {
|
|
161
|
+
option: WorkspaceAgentOption
|
|
162
|
+
selected: boolean
|
|
163
|
+
onSelect: (type: WorkspaceType) => void
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function WorkspaceAgentOptionButton({
|
|
167
|
+
option,
|
|
168
|
+
selected,
|
|
169
|
+
onSelect
|
|
170
|
+
}: WorkspaceAgentOptionButtonProps) {
|
|
171
|
+
const showDisabledTooltip = Boolean(option.disabledReason)
|
|
172
|
+
const button = (
|
|
173
|
+
<button
|
|
174
|
+
type="button"
|
|
175
|
+
disabled={option.disabled && !showDisabledTooltip}
|
|
176
|
+
aria-disabled={option.disabled || undefined}
|
|
177
|
+
aria-pressed={selected}
|
|
178
|
+
onClick={event => {
|
|
179
|
+
if (option.disabled) {
|
|
180
|
+
event.preventDefault()
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
onSelect(option.type)
|
|
184
|
+
}}
|
|
185
|
+
className={cn(
|
|
186
|
+
'relative flex w-full flex-col items-start justify-between gap-6 rounded-lg bg-card p-4 text-left ring-1 ring-border transition-opacity outline-none focus-visible:ring-3 focus-visible:ring-ring/50',
|
|
187
|
+
!selected && 'opacity-70',
|
|
188
|
+
!selected && !option.disabled && 'cursor-pointer hover:opacity-100',
|
|
189
|
+
option.disabled && 'cursor-not-allowed'
|
|
190
|
+
)}
|
|
191
|
+
>
|
|
192
|
+
<span className="relative inline-flex">
|
|
193
|
+
<WorkspaceAgentIcon type={option.type} />
|
|
194
|
+
{selected && (
|
|
195
|
+
<IconCircleCheckFilled
|
|
196
|
+
size={16}
|
|
197
|
+
stroke={1.75}
|
|
198
|
+
aria-hidden="true"
|
|
199
|
+
className="absolute -top-1.5 -right-1.5"
|
|
200
|
+
/>
|
|
201
|
+
)}
|
|
202
|
+
</span>
|
|
203
|
+
<span className="flex min-w-0 flex-col gap-0.5">
|
|
204
|
+
<span className="text-sm font-medium text-foreground">
|
|
205
|
+
{workspaceTypeLabel[option.type]}
|
|
206
|
+
</span>
|
|
207
|
+
<span className="text-xs leading-4 text-muted-foreground">{option.description}</span>
|
|
208
|
+
</span>
|
|
209
|
+
</button>
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
if (!showDisabledTooltip) return button
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<Tooltip>
|
|
216
|
+
<TooltipTrigger render={button} />
|
|
217
|
+
<TooltipContent className="max-w-64 text-center whitespace-pre-line">
|
|
218
|
+
{option.disabledReason}
|
|
219
|
+
</TooltipContent>
|
|
220
|
+
</Tooltip>
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
type WorkspaceAgentIconProps = {
|
|
225
|
+
type: WorkspaceType
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function WorkspaceAgentIcon({ type }: WorkspaceAgentIconProps) {
|
|
229
|
+
return <img src={workspaceProviderIcon[type]} alt="" className="size-8 shrink-0" />
|
|
230
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
import { IconX } from '@tabler/icons-react'
|
|
4
|
+
|
|
5
|
+
import { Button } from '@/client/components/ui/button'
|
|
6
|
+
import { DialogClose, DialogContent } from '@/client/components/ui/dialog'
|
|
7
|
+
|
|
8
|
+
type WorkspaceDialogContentProps = {
|
|
9
|
+
children: ReactNode
|
|
10
|
+
closeDisabled?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function WorkspaceDialogContent({
|
|
14
|
+
children,
|
|
15
|
+
closeDisabled = false
|
|
16
|
+
}: WorkspaceDialogContentProps) {
|
|
17
|
+
return (
|
|
18
|
+
<DialogContent className="w-[calc(100%-2rem)] max-w-md p-6">
|
|
19
|
+
<DialogClose
|
|
20
|
+
render={
|
|
21
|
+
<Button
|
|
22
|
+
variant="ghost"
|
|
23
|
+
size="icon-sm"
|
|
24
|
+
aria-label="Close"
|
|
25
|
+
className="absolute top-4 right-4"
|
|
26
|
+
disabled={closeDisabled}
|
|
27
|
+
>
|
|
28
|
+
<IconX stroke={1.75} />
|
|
29
|
+
</Button>
|
|
30
|
+
}
|
|
31
|
+
/>
|
|
32
|
+
{children}
|
|
33
|
+
</DialogContent>
|
|
34
|
+
)
|
|
35
|
+
}
|