moi-computer 0.3.0-next.1 → 0.3.0-next.2
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/bunfig.toml +5 -1
- package/client/AGENTS.md +15 -0
- 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 +17 -0
- package/client/app/AppRouter.tsx +35 -0
- package/client/app/routes/HomeRoute.tsx +13 -0
- package/client/app/routes/WorkspaceRoute.tsx +89 -0
- package/client/app/shell/SidebarLayout.tsx +191 -0
- package/client/assets.d.ts +9 -0
- package/client/components/playground/PixelPainter.tsx +10 -21
- package/client/components/playground/PlaygroundPage.tsx +9 -11
- package/client/components/playground/ToolCallsPage.tsx +9 -11
- package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +1 -1
- package/client/components/shared/PanelHeader.tsx +9 -0
- package/client/components/shared/ReorderableList.tsx +199 -0
- package/client/components/ui/button.tsx +10 -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/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/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
- package/client/{components → features/applets}/WidgetShell.tsx +1 -1
- package/client/{hooks → features/applets}/useApplet.ts +6 -7
- package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +29 -23
- package/client/features/chat/ChatPanel.tsx +188 -0
- package/client/{components → features/chat}/ChatPopup.tsx +23 -12
- package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
- package/client/{components → features/chat}/ModelPicker.tsx +68 -17
- package/client/{components → features/chat}/ThreadSelector.tsx +11 -9
- package/client/{components → features/chat}/TurnView.tsx +16 -9
- 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/{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 +12 -4
- package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
- package/client/{hooks → features/chat}/useChat.ts +7 -11
- package/client/features/connectors/ConnectorsPage.tsx +92 -0
- package/client/features/connectors/McpMenu.tsx +162 -0
- package/client/features/connectors/api.ts +28 -0
- package/client/features/home/CreateWorkspaceDialog.tsx +224 -0
- package/client/features/home/HomePage.tsx +220 -0
- package/client/{components → features/home}/WorkspacePreview.tsx +2 -2
- package/client/features/home/api.ts +148 -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 +73 -222
- 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 +161 -0
- package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
- 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 +2 -9
- package/client/features/widgets/Widgets.tsx +215 -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 +15 -8
- package/client/features/workspace/WorkspaceScreen.tsx +536 -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 -10
- package/client/index.html +1 -1
- package/client/index.tsx +14 -31
- package/client/main.tsx +2 -2
- package/client/runtime/hmr-watchdog.ts +39 -0
- package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +9 -6
- package/client/store/ui.ts +5 -1
- package/client/theme.css +0 -2
- package/dist/chunk-11cab5dq.css +1 -0
- package/dist/chunk-23cgr1tz.css +1 -0
- package/dist/chunk-3hy3qy6d.js +10 -0
- package/dist/chunk-c4j722at.js +546 -0
- package/dist/chunk-dyfaffyz.js +119 -0
- package/dist/chunk-kpe40hm8.js +1 -0
- package/dist/chunk-p68fnz3q.js +2 -0
- package/dist/chunk-pcnahct1.js +5 -0
- package/dist/chunk-tqd3pkg8.css +1 -0
- package/dist/chunk-ty6dvda0.js +1 -0
- package/dist/index.html +2 -2
- package/lib/types.ts +18 -7
- package/lib/workspace-name.ts +14 -0
- package/package.json +3 -2
- package/server/api.ts +119 -14
- package/server/cli.ts +11 -5
- package/server/layout.ts +38 -7
- package/server/mcp.ts +72 -15
- package/server/moi-scaffold.ts +55 -10
- package/server/registry.ts +16 -0
- package/server/web.ts +1 -0
- package/server/workspace-init.ts +5 -19
- package/tsconfig.json +1 -1
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +1 -1
- package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
- package/client/api/workspaces.ts +0 -427
- 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/lib/connection.ts +0 -238
- package/dist/chunk-07qf2tv1.css +0 -1
- package/dist/chunk-w18801vn.js +0 -672
- /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
- /package/client/{lib → features/applets}/applet-cache.ts +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/format.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
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { type FormEvent, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { IconLoader2, IconPlus } from '@tabler/icons-react'
|
|
4
|
-
import { useLocation } from 'wouter'
|
|
5
|
-
|
|
6
|
-
import { useCreateWorkspace, useCreateWorkspaceInfo } from '@/client/api/workspaces'
|
|
7
|
-
import { TypeIcon, typeLabel } from '@/client/components/WorkspacesPage'
|
|
8
|
-
import { PanelHeader, SidebarLayout, SidebarToggle } from '@/client/components/layout/SidebarLayout'
|
|
9
|
-
import { Button } from '@/client/components/ui/button'
|
|
10
|
-
import { Input } from '@/client/components/ui/input'
|
|
11
|
-
import { cn } from '@/client/lib/cn'
|
|
12
|
-
import type { WorkspaceType } from '@/lib/types'
|
|
13
|
-
|
|
14
|
-
// Mirrors the server's validateWorkspaceFolderName (workspace-init.ts) for
|
|
15
|
-
// instant feedback; the server remains the authority and re-validates.
|
|
16
|
-
function folderNameError(name: string): string | null {
|
|
17
|
-
if (!name) return null // an empty field just disables the submit, no nagging
|
|
18
|
-
if (name.length > 64) return 'Folder name is too long (max 64 characters)'
|
|
19
|
-
if (!/^[A-Za-z0-9][A-Za-z0-9._ -]*$/.test(name)) {
|
|
20
|
-
return 'Use letters, numbers, dots, dashes, underscores and spaces, starting with a letter or number'
|
|
21
|
-
}
|
|
22
|
-
if (name.endsWith('.') || name.endsWith(' ')) return 'Folder name cannot end with a dot or space'
|
|
23
|
-
return null
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type AgentOption = {
|
|
27
|
-
type: WorkspaceType
|
|
28
|
-
hint: string
|
|
29
|
-
disabled?: boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Only Claude Code workspaces can be created from scratch for now. OpenClaw
|
|
33
|
-
// workspaces belong to their agents — they arrive via discovery on the home
|
|
34
|
-
// page — and Hermes has no init path yet.
|
|
35
|
-
const AGENT_OPTIONS: AgentOption[] = [
|
|
36
|
-
{ type: 'claude-code', hint: 'Powered by the Claude Agent SDK' },
|
|
37
|
-
{ type: 'openclaw', hint: 'Import a discovered agent from Home', disabled: true },
|
|
38
|
-
{ type: 'hermes', hint: 'Coming soon', disabled: true }
|
|
39
|
-
]
|
|
40
|
-
|
|
41
|
-
// The `/workspace/create` route: name a folder, get a provisioned (skills +
|
|
42
|
-
// `.moi/` scaffold) and registered workspace under the server's workspaces
|
|
43
|
-
// root, then land in it.
|
|
44
|
-
export function CreateWorkspacePage() {
|
|
45
|
-
const [, navigate] = useLocation()
|
|
46
|
-
const info = useCreateWorkspaceInfo()
|
|
47
|
-
const createMutation = useCreateWorkspace()
|
|
48
|
-
|
|
49
|
-
const [name, setName] = useState('')
|
|
50
|
-
const [type, setType] = useState<WorkspaceType>('claude-code')
|
|
51
|
-
|
|
52
|
-
const trimmed = name.trim()
|
|
53
|
-
const nameError = folderNameError(trimmed)
|
|
54
|
-
const canSubmit = trimmed.length > 0 && !nameError && !createMutation.isPending
|
|
55
|
-
const root = info.data?.displayRoot ?? '…'
|
|
56
|
-
|
|
57
|
-
function handleSubmit(e: FormEvent) {
|
|
58
|
-
e.preventDefault()
|
|
59
|
-
if (!canSubmit) return
|
|
60
|
-
createMutation.mutate(
|
|
61
|
-
{ name: trimmed, type },
|
|
62
|
-
{ onSuccess: entry => navigate(`/workspace/${entry.id}`) }
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<SidebarLayout>
|
|
68
|
-
<PanelHeader>
|
|
69
|
-
<SidebarToggle />
|
|
70
|
-
<span className="text-sm font-medium text-foreground">New workspace</span>
|
|
71
|
-
</PanelHeader>
|
|
72
|
-
<div className="min-h-0 flex-1 overflow-y-auto">
|
|
73
|
-
<form onSubmit={handleSubmit} className="mx-auto w-full max-w-xl px-8 pt-14 pb-16">
|
|
74
|
-
<h1 className="mb-1.5 text-base font-semibold text-foreground">Create a workspace</h1>
|
|
75
|
-
<p className="mb-8 text-sm text-muted-foreground">
|
|
76
|
-
A new folder in <code className="rounded bg-muted px-1 py-0.5 font-mono text-xs">{root}</code>,
|
|
77
|
-
set up with moi skills and widgets, ready to chat.
|
|
78
|
-
</p>
|
|
79
|
-
|
|
80
|
-
<fieldset className="mb-6">
|
|
81
|
-
<legend className="mb-2 text-sm font-medium text-foreground">Agent</legend>
|
|
82
|
-
<div className="grid grid-cols-3 gap-2">
|
|
83
|
-
{AGENT_OPTIONS.map(option => (
|
|
84
|
-
<button
|
|
85
|
-
key={option.type}
|
|
86
|
-
type="button"
|
|
87
|
-
disabled={option.disabled}
|
|
88
|
-
onClick={() => setType(option.type)}
|
|
89
|
-
aria-pressed={type === option.type}
|
|
90
|
-
className={cn(
|
|
91
|
-
'flex flex-col items-start gap-1.5 rounded-lg border p-3 text-left transition-colors',
|
|
92
|
-
type === option.type
|
|
93
|
-
? 'border-ring bg-muted/50 shadow-[inset_0_0_0_1px_var(--ring)]'
|
|
94
|
-
: 'border-border hover:bg-muted/40',
|
|
95
|
-
option.disabled && 'cursor-not-allowed opacity-50 hover:bg-transparent'
|
|
96
|
-
)}
|
|
97
|
-
>
|
|
98
|
-
<span className="flex items-center gap-2">
|
|
99
|
-
<TypeIcon type={option.type} />
|
|
100
|
-
<span className="text-sm font-medium text-foreground">
|
|
101
|
-
{typeLabel[option.type]}
|
|
102
|
-
</span>
|
|
103
|
-
</span>
|
|
104
|
-
<span className="text-xs text-muted-foreground">{option.hint}</span>
|
|
105
|
-
</button>
|
|
106
|
-
))}
|
|
107
|
-
</div>
|
|
108
|
-
</fieldset>
|
|
109
|
-
|
|
110
|
-
<div className="mb-2">
|
|
111
|
-
<label htmlFor="workspace-name" className="mb-2 block text-sm font-medium text-foreground">
|
|
112
|
-
Folder name
|
|
113
|
-
</label>
|
|
114
|
-
<Input
|
|
115
|
-
id="workspace-name"
|
|
116
|
-
value={name}
|
|
117
|
-
onChange={e => setName(e.target.value)}
|
|
118
|
-
placeholder="my-workspace"
|
|
119
|
-
autoFocus
|
|
120
|
-
aria-invalid={!!nameError}
|
|
121
|
-
autoComplete="off"
|
|
122
|
-
spellCheck={false}
|
|
123
|
-
/>
|
|
124
|
-
</div>
|
|
125
|
-
{nameError ? (
|
|
126
|
-
<p className="mb-6 text-xs text-destructive">{nameError}</p>
|
|
127
|
-
) : (
|
|
128
|
-
<p className="mb-6 font-mono text-xs text-muted-foreground">
|
|
129
|
-
{root}/{trimmed || 'my-workspace'}
|
|
130
|
-
</p>
|
|
131
|
-
)}
|
|
132
|
-
|
|
133
|
-
<div className="flex items-center gap-3">
|
|
134
|
-
<Button type="submit" disabled={!canSubmit}>
|
|
135
|
-
{createMutation.isPending ? (
|
|
136
|
-
<IconLoader2 stroke={1.5} className="animate-spin" />
|
|
137
|
-
) : (
|
|
138
|
-
<IconPlus stroke={1.5} />
|
|
139
|
-
)}
|
|
140
|
-
Create workspace
|
|
141
|
-
</Button>
|
|
142
|
-
{createMutation.isPending && (
|
|
143
|
-
<span className="text-xs text-muted-foreground">
|
|
144
|
-
Setting up skills and widgets…
|
|
145
|
-
</span>
|
|
146
|
-
)}
|
|
147
|
-
</div>
|
|
148
|
-
{createMutation.isError && (
|
|
149
|
-
<p className="mt-3 text-xs text-destructive">{createMutation.error.message}</p>
|
|
150
|
-
)}
|
|
151
|
-
</form>
|
|
152
|
-
</div>
|
|
153
|
-
</SidebarLayout>
|
|
154
|
-
)
|
|
155
|
-
}
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { type ReactNode, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { IconLoader2, IconPlus, IconTrash } from '@tabler/icons-react'
|
|
4
|
-
|
|
5
|
-
import { useSaveWorkspaceName } from '@/client/api/workspaces'
|
|
6
|
-
import { useEnvVars } from '@/client/hooks/useEnvVars'
|
|
7
|
-
import { Button } from '@/client/components/ui/button'
|
|
8
|
-
import { Input } from '@/client/components/ui/input'
|
|
9
|
-
import { Switch } from '@/client/components/ui/switch'
|
|
10
|
-
import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
|
|
11
|
-
import { cn } from '@/client/lib/cn'
|
|
12
|
-
import type { WorkspaceEnvVar } from '@/lib/types'
|
|
13
|
-
|
|
14
|
-
import { IconPicker } from './IconPicker'
|
|
15
|
-
|
|
16
|
-
// ── Shared page primitives ──────────────────────────────────────────────────
|
|
17
|
-
|
|
18
|
-
type SettingsPageProps = {
|
|
19
|
-
title: string
|
|
20
|
-
description?: string
|
|
21
|
-
children: ReactNode
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function SettingsPage({ title, description, children }: SettingsPageProps) {
|
|
25
|
-
return (
|
|
26
|
-
<div className="flex flex-col gap-6">
|
|
27
|
-
<header className="flex flex-col gap-1">
|
|
28
|
-
<h2 className="text-xl font-semibold tracking-tight">{title}</h2>
|
|
29
|
-
{description && <p className="text-sm text-muted-foreground">{description}</p>}
|
|
30
|
-
</header>
|
|
31
|
-
{children}
|
|
32
|
-
</div>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
type SettingsSectionProps = {
|
|
37
|
-
label?: string
|
|
38
|
-
children: ReactNode
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function SettingsSection({ label, children }: SettingsSectionProps) {
|
|
42
|
-
return (
|
|
43
|
-
<section className="flex flex-col gap-2">
|
|
44
|
-
{label && <p className="px-0.5 text-xs font-medium text-muted-foreground">{label}</p>}
|
|
45
|
-
<div className="flex flex-col divide-y divide-dashed divide-border overflow-hidden rounded-lg border border-border bg-card">
|
|
46
|
-
{children}
|
|
47
|
-
</div>
|
|
48
|
-
</section>
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type SettingsRowProps = {
|
|
53
|
-
title: string
|
|
54
|
-
description?: string
|
|
55
|
-
control?: ReactNode
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function SettingsRow({ title, description, control }: SettingsRowProps) {
|
|
59
|
-
return (
|
|
60
|
-
<div className="flex items-center gap-3 px-3.5 py-3">
|
|
61
|
-
<div className="flex min-w-0 flex-col">
|
|
62
|
-
<span className="text-sm font-medium">{title}</span>
|
|
63
|
-
{description && <span className="text-xs text-muted-foreground">{description}</span>}
|
|
64
|
-
</div>
|
|
65
|
-
{control && <div className="ml-auto flex shrink-0 items-center pl-3">{control}</div>}
|
|
66
|
-
</div>
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// ── General ─────────────────────────────────────────────────────────────────
|
|
71
|
-
|
|
72
|
-
export function GeneralSettings() {
|
|
73
|
-
const { name, icon, workspaceId } = useWorkspaceLayoutCtx()
|
|
74
|
-
const saveName = useSaveWorkspaceName(workspaceId)
|
|
75
|
-
const [draft, setDraft] = useState(name ?? '')
|
|
76
|
-
|
|
77
|
-
// Persist on blur (or Enter): an empty value clears the override so the name
|
|
78
|
-
// falls back to the folder name.
|
|
79
|
-
const commit = () => {
|
|
80
|
-
const next = draft.trim()
|
|
81
|
-
if (next === (name ?? '')) return
|
|
82
|
-
saveName.mutate(next === '' ? null : next)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<SettingsPage title="General" description="Basic details for this workspace.">
|
|
87
|
-
<SettingsSection>
|
|
88
|
-
<SettingsRow
|
|
89
|
-
title="Name"
|
|
90
|
-
description="Shown in the sidebar and the workspace header."
|
|
91
|
-
control={
|
|
92
|
-
<Input
|
|
93
|
-
value={draft}
|
|
94
|
-
onChange={e => setDraft(e.target.value)}
|
|
95
|
-
onBlur={commit}
|
|
96
|
-
onKeyDown={e => {
|
|
97
|
-
if (e.key === 'Enter') e.currentTarget.blur()
|
|
98
|
-
}}
|
|
99
|
-
placeholder="Workspace name"
|
|
100
|
-
className="w-56"
|
|
101
|
-
/>
|
|
102
|
-
}
|
|
103
|
-
/>
|
|
104
|
-
<div className="flex flex-col gap-4 px-3.5 py-3.5">
|
|
105
|
-
<div className="flex flex-col">
|
|
106
|
-
<span className="text-sm font-medium">Icon</span>
|
|
107
|
-
<span className="text-xs text-muted-foreground">
|
|
108
|
-
Pick an emoji or a glyph on a generated background, or upload an image.
|
|
109
|
-
</span>
|
|
110
|
-
</div>
|
|
111
|
-
<IconPicker icon={icon} />
|
|
112
|
-
</div>
|
|
113
|
-
</SettingsSection>
|
|
114
|
-
</SettingsPage>
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// ── Environment ─────────────────────────────────────────────────────────────
|
|
119
|
-
|
|
120
|
-
// Source badge copy: where the key actually comes from.
|
|
121
|
-
const SOURCE_LABEL: Record<WorkspaceEnvVar['source'], string> = {
|
|
122
|
-
dotenv: '.env',
|
|
123
|
-
custom: 'secret',
|
|
124
|
-
both: 'override'
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/
|
|
128
|
-
|
|
129
|
-
export function EnvironmentSettings() {
|
|
130
|
-
const { workspaceId } = useWorkspaceLayoutCtx()
|
|
131
|
-
const { env, update } = useEnvVars(workspaceId)
|
|
132
|
-
|
|
133
|
-
const [draftKey, setDraftKey] = useState('')
|
|
134
|
-
const [draftValue, setDraftValue] = useState('')
|
|
135
|
-
|
|
136
|
-
const keyValid = ENV_KEY_RE.test(draftKey)
|
|
137
|
-
const canAdd = keyValid && draftValue.length > 0 && !update.isPending
|
|
138
|
-
|
|
139
|
-
const addVar = () => {
|
|
140
|
-
if (!canAdd) return
|
|
141
|
-
update.mutate(
|
|
142
|
-
{ set: { [draftKey]: draftValue } },
|
|
143
|
-
{
|
|
144
|
-
onSuccess: () => {
|
|
145
|
-
setDraftKey('')
|
|
146
|
-
setDraftValue('')
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const vars = env.data?.vars ?? []
|
|
153
|
-
const fileCount = env.data?.files.reduce((n, f) => n + f.count, 0) ?? 0
|
|
154
|
-
const dotenvFiles = env.data?.files.length ?? 0
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
<SettingsPage
|
|
158
|
-
title="Environment"
|
|
159
|
-
description="Secrets injected into widgets and the agent at run time. Values are write-only — they're never shown again once saved."
|
|
160
|
-
>
|
|
161
|
-
<SettingsSection label="Variables">
|
|
162
|
-
{env.isLoading ? (
|
|
163
|
-
<div className="flex items-center justify-center px-3.5 py-6 text-muted-foreground">
|
|
164
|
-
<IconLoader2 className="size-4 animate-spin" stroke={1.75} />
|
|
165
|
-
</div>
|
|
166
|
-
) : vars.length === 0 ? (
|
|
167
|
-
<p className="px-3.5 py-4 text-sm text-muted-foreground">No variables yet.</p>
|
|
168
|
-
) : (
|
|
169
|
-
vars.map(v => {
|
|
170
|
-
const editable = v.source !== 'dotenv'
|
|
171
|
-
return (
|
|
172
|
-
<div key={v.key} className="flex items-center gap-3 px-3.5 py-2.5">
|
|
173
|
-
<code className="min-w-0 flex-1 truncate font-mono text-xs text-foreground">
|
|
174
|
-
{v.key}
|
|
175
|
-
</code>
|
|
176
|
-
<span className="text-xs tracking-widest text-muted-foreground/60 select-none">
|
|
177
|
-
••••••
|
|
178
|
-
</span>
|
|
179
|
-
<span
|
|
180
|
-
className={cn(
|
|
181
|
-
'rounded-sm px-1.5 py-0.5 text-[11px] font-medium',
|
|
182
|
-
v.source === 'dotenv'
|
|
183
|
-
? 'bg-muted text-muted-foreground'
|
|
184
|
-
: 'bg-primary/10 text-primary'
|
|
185
|
-
)}
|
|
186
|
-
>
|
|
187
|
-
{SOURCE_LABEL[v.source]}
|
|
188
|
-
</span>
|
|
189
|
-
{!editable && (
|
|
190
|
-
<span className="text-right text-[11px] text-muted-foreground/60">from file</span>
|
|
191
|
-
)}
|
|
192
|
-
<button
|
|
193
|
-
type="button"
|
|
194
|
-
onClick={() => update.mutate({ remove: [v.key] })}
|
|
195
|
-
disabled={!editable}
|
|
196
|
-
aria-label={`Delete ${v.key}`}
|
|
197
|
-
className="text-muted-foreground/50 transition-colors not-disabled:hover:text-foreground disabled:invisible [&_svg]:size-4"
|
|
198
|
-
>
|
|
199
|
-
<IconTrash stroke={1.5} />
|
|
200
|
-
</button>
|
|
201
|
-
</div>
|
|
202
|
-
)
|
|
203
|
-
})
|
|
204
|
-
)}
|
|
205
|
-
|
|
206
|
-
{/* Add row */}
|
|
207
|
-
<div className="flex items-center gap-2 px-3.5 py-2.5">
|
|
208
|
-
<Input
|
|
209
|
-
value={draftKey}
|
|
210
|
-
onChange={e => setDraftKey(e.target.value)}
|
|
211
|
-
placeholder="NEW_KEY"
|
|
212
|
-
aria-invalid={draftKey.length > 0 && !keyValid}
|
|
213
|
-
className="h-7 w-40 font-mono text-xs"
|
|
214
|
-
/>
|
|
215
|
-
<Input
|
|
216
|
-
value={draftValue}
|
|
217
|
-
onChange={e => setDraftValue(e.target.value)}
|
|
218
|
-
onKeyDown={e => {
|
|
219
|
-
if (e.key === 'Enter') addVar()
|
|
220
|
-
}}
|
|
221
|
-
type="password"
|
|
222
|
-
placeholder="value"
|
|
223
|
-
className="h-7 flex-1 text-xs"
|
|
224
|
-
/>
|
|
225
|
-
<Button variant="outline" size="sm" className="h-7" onClick={addVar} disabled={!canAdd}>
|
|
226
|
-
{update.isPending ? (
|
|
227
|
-
<IconLoader2 className="animate-spin" />
|
|
228
|
-
) : (
|
|
229
|
-
<IconPlus stroke={1.75} />
|
|
230
|
-
)}
|
|
231
|
-
Add
|
|
232
|
-
</Button>
|
|
233
|
-
</div>
|
|
234
|
-
</SettingsSection>
|
|
235
|
-
|
|
236
|
-
<SettingsSection label="From .env files">
|
|
237
|
-
<SettingsRow
|
|
238
|
-
title="Inherit .env files"
|
|
239
|
-
description={
|
|
240
|
-
dotenvFiles > 0
|
|
241
|
-
? `Discovered ${fileCount} ${fileCount === 1 ? 'key' : 'keys'} across ${dotenvFiles} ${dotenvFiles === 1 ? 'file' : 'files'} in this workspace.`
|
|
242
|
-
: 'No .env files found in this workspace.'
|
|
243
|
-
}
|
|
244
|
-
control={
|
|
245
|
-
<Switch
|
|
246
|
-
checked={env.data?.inheritDotenv ?? true}
|
|
247
|
-
disabled={env.isLoading}
|
|
248
|
-
onCheckedChange={checked => update.mutate({ inheritDotenv: checked })}
|
|
249
|
-
/>
|
|
250
|
-
}
|
|
251
|
-
/>
|
|
252
|
-
</SettingsSection>
|
|
253
|
-
</SettingsPage>
|
|
254
|
-
)
|
|
255
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
// Resolve a CSS length token (px or rem) defined on :root to pixels, so the fit
|
|
4
|
-
// math shares the layout tokens in index.css rather than duplicating values.
|
|
5
|
-
function tokenPx(name: string): number {
|
|
6
|
-
const root = document.documentElement
|
|
7
|
-
const raw = getComputedStyle(root).getPropertyValue(name).trim()
|
|
8
|
-
const value = parseFloat(raw)
|
|
9
|
-
return raw.endsWith('rem') ? value * parseFloat(getComputedStyle(root).fontSize) : value
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Observe the content row (full panel width — stable regardless of whether the
|
|
13
|
-
// chat is docked) and dock the chat only while the widget area would stay at
|
|
14
|
-
// its content width (--column-w) once the chat takes its minimum (--chat-min).
|
|
15
|
-
// Measuring the widget area element directly would oscillate: docking shrinks
|
|
16
|
-
// it back under the threshold, which would undock it, which would grow it, etc.
|
|
17
|
-
export function useFitsSidebar<T extends HTMLElement>() {
|
|
18
|
-
const ref = useRef<T>(null)
|
|
19
|
-
const [fits, setFits] = useState(false)
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const el = ref.current
|
|
23
|
-
if (!el) return
|
|
24
|
-
const minWidget = tokenPx('--column-w')
|
|
25
|
-
const chatMin = tokenPx('--chat-min')
|
|
26
|
-
const ro = new ResizeObserver(([entry]) => {
|
|
27
|
-
if (entry) setFits(entry.contentRect.width - chatMin >= minWidget)
|
|
28
|
-
})
|
|
29
|
-
ro.observe(el)
|
|
30
|
-
return () => ro.disconnect()
|
|
31
|
-
}, [])
|
|
32
|
-
|
|
33
|
-
return { ref, fits }
|
|
34
|
-
}
|
package/client/lib/connection.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import type { QueryClient } from '@tanstack/react-query'
|
|
2
|
-
|
|
3
|
-
import { workspaceKeys } from '@/client/api/workspaces'
|
|
4
|
-
import { getScratchExecutor } from '@/client/lib/scratch-executor'
|
|
5
|
-
import { wsUrl } from '@/client/lib/ws-url'
|
|
6
|
-
import { liveStore } from '@/client/store/live'
|
|
7
|
-
import { applyEvent } from '@/lib/format'
|
|
8
|
-
import type {
|
|
9
|
-
ClientMessage,
|
|
10
|
-
PreviewFrame,
|
|
11
|
-
ScratchOp,
|
|
12
|
-
StreamEvent,
|
|
13
|
-
ThreadConfig,
|
|
14
|
-
ViewState
|
|
15
|
-
} from '@/lib/types'
|
|
16
|
-
|
|
17
|
-
// App-wide chat connection: ONE WebSocket for the whole client, opened once at
|
|
18
|
-
// startup and never torn down on navigation. Every server frame is tagged with
|
|
19
|
-
// `workspaceId`, so a single socket serves every workspace and the client routes
|
|
20
|
-
// each frame to the right `(workspaceId, sessionId)` slice — live transcript
|
|
21
|
-
// deltas into the React Query cache, status/error/rename into the live store.
|
|
22
|
-
//
|
|
23
|
-
// Socket identity is tracked by a monotonic `generation`: each socket captures
|
|
24
|
-
// the generation at creation and every callback bails if it's no longer current,
|
|
25
|
-
// so a delayed close/open from a superseded socket can't corrupt live state.
|
|
26
|
-
|
|
27
|
-
let qc: QueryClient | null = null
|
|
28
|
-
let socket: WebSocket | null = null
|
|
29
|
-
let generation = 0
|
|
30
|
-
let reconnectTimer: ReturnType<typeof setTimeout> | null = null
|
|
31
|
-
const queue: ClientMessage[] = []
|
|
32
|
-
let onWorkspaceSwitch: ((workspaceId: string) => void) | null = null
|
|
33
|
-
let sweepTimer: ReturnType<typeof setInterval> | null = null
|
|
34
|
-
|
|
35
|
-
// TTL backstop for live previews. Every clear path (turn arrival, run end,
|
|
36
|
-
// reconnect) is exact and should fire first; this only reaps a preview whose
|
|
37
|
-
// clear was somehow missed, so it can be generous.
|
|
38
|
-
const PREVIEW_TTL_MS = 15_000
|
|
39
|
-
|
|
40
|
-
export function initConnection(queryClient: QueryClient) {
|
|
41
|
-
qc = queryClient
|
|
42
|
-
if (!sweepTimer) {
|
|
43
|
-
sweepTimer = setInterval(
|
|
44
|
-
() => liveStore.getState().sweepPreviews(PREVIEW_TTL_MS, Date.now()),
|
|
45
|
-
5_000
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
if (socket) return // already connected (mount/StrictMode re-invoke safety)
|
|
49
|
-
connect()
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function connect() {
|
|
53
|
-
const myGen = ++generation
|
|
54
|
-
if (reconnectTimer) {
|
|
55
|
-
clearTimeout(reconnectTimer)
|
|
56
|
-
reconnectTimer = null
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const s = new WebSocket(wsUrl('/ws'))
|
|
60
|
-
socket = s
|
|
61
|
-
|
|
62
|
-
s.onopen = () => {
|
|
63
|
-
if (generation !== myGen) {
|
|
64
|
-
s.close()
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
for (const m of queue) s.send(JSON.stringify(m))
|
|
68
|
-
queue.length = 0
|
|
69
|
-
// Heal any deltas missed while disconnected: refetch every live transcript.
|
|
70
|
-
// No-op on the first connect (nothing cached yet).
|
|
71
|
-
qc?.invalidateQueries({ queryKey: ['workspaces', 'events'] })
|
|
72
|
-
// Any in-flight preview from before the drop is superseded by that refetch
|
|
73
|
-
// (which returns the authoritative disk state) — drop them all so a frozen
|
|
74
|
-
// half-streamed preview can't linger over the healed transcript.
|
|
75
|
-
liveStore.getState().clearAllPreviews()
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
s.onmessage = e => {
|
|
79
|
-
if (generation !== myGen) return
|
|
80
|
-
let data: unknown
|
|
81
|
-
try {
|
|
82
|
-
data = JSON.parse(e.data)
|
|
83
|
-
} catch {
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
handleFrame(data as Record<string, unknown>)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
s.onclose = () => {
|
|
90
|
-
if (generation !== myGen) return
|
|
91
|
-
socket = null
|
|
92
|
-
reconnectTimer = setTimeout(connect, 1000)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
s.onerror = () => s.close()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function handleFrame(data: Record<string, unknown>) {
|
|
99
|
-
const store = liveStore.getState()
|
|
100
|
-
|
|
101
|
-
// Control frames first.
|
|
102
|
-
if (data.type === 'status_snapshot') {
|
|
103
|
-
store.reconcileProcessing(
|
|
104
|
-
(data.running as { workspaceId: string; sessionId: string }[] | undefined) ?? []
|
|
105
|
-
)
|
|
106
|
-
return
|
|
107
|
-
}
|
|
108
|
-
if (data.type === 'status') {
|
|
109
|
-
const workspaceId = data.workspaceId as string
|
|
110
|
-
const sessionId = data.sessionId as string
|
|
111
|
-
const processing = data.processing as boolean
|
|
112
|
-
store.setProcessing(workspaceId, sessionId, processing)
|
|
113
|
-
// Run fully ended → any leftover preview for this session is stale (its
|
|
114
|
-
// finalized turns already arrived). Belt for a per-message clear that was
|
|
115
|
-
// missed (e.g. a turn that carried no apiMessageId).
|
|
116
|
-
if (!processing) store.clearPreviewsForSession(workspaceId, sessionId)
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
if (data.type === 'preview') {
|
|
120
|
-
const frame = data as unknown as PreviewFrame
|
|
121
|
-
// Only hold previews for a thread whose transcript is loaded (mirrors
|
|
122
|
-
// patchView): keeps the store bounded and never renders a preview over a
|
|
123
|
-
// history-less background session that would then never refetch.
|
|
124
|
-
const key = workspaceKeys.events(frame.workspaceId, frame.sessionId)
|
|
125
|
-
if (qc?.getQueryData(key) === undefined) return
|
|
126
|
-
store.setPreview({
|
|
127
|
-
workspaceId: frame.workspaceId,
|
|
128
|
-
sessionId: frame.sessionId,
|
|
129
|
-
messageId: frame.messageId,
|
|
130
|
-
parentToolUseId: frame.parentToolUseId,
|
|
131
|
-
blocks: frame.blocks
|
|
132
|
-
})
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
if (data.type === 'session_renamed') {
|
|
136
|
-
const workspaceId = data.workspaceId as string
|
|
137
|
-
const from = data.from as string
|
|
138
|
-
const to = data.to as string
|
|
139
|
-
store.renameSession(workspaceId, from, to)
|
|
140
|
-
// Move the cached transcript from the client's temp id to the real one.
|
|
141
|
-
const prev = qc?.getQueryData<ViewState>(workspaceKeys.events(workspaceId, from))
|
|
142
|
-
if (prev !== undefined) {
|
|
143
|
-
qc?.setQueryData(workspaceKeys.events(workspaceId, to), prev)
|
|
144
|
-
qc?.removeQueries({ queryKey: workspaceKeys.events(workspaceId, from) })
|
|
145
|
-
}
|
|
146
|
-
// Likewise move any per-thread config the picker wrote under the temp id, so
|
|
147
|
-
// a model/effort change made before the rename lands isn't stranded. The
|
|
148
|
-
// server migrates the stored config in renameSession to match.
|
|
149
|
-
const cfg = qc?.getQueryData<ThreadConfig>(workspaceKeys.threadConfig(workspaceId, from))
|
|
150
|
-
if (cfg !== undefined) {
|
|
151
|
-
qc?.setQueryData(workspaceKeys.threadConfig(workspaceId, to), cfg)
|
|
152
|
-
qc?.removeQueries({ queryKey: workspaceKeys.threadConfig(workspaceId, from) })
|
|
153
|
-
}
|
|
154
|
-
// The real id now exists on disk — refresh the thread list so it appears.
|
|
155
|
-
qc?.invalidateQueries({ queryKey: workspaceKeys.sessions(workspaceId) })
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
if (data.type === 'workspace:switch') {
|
|
159
|
-
onWorkspaceSwitch?.(data.workspaceId as string)
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// A relayed Scratchpad op from `moi scratch`. Only run it if THIS tab has a
|
|
164
|
-
// live editor for that workspace; otherwise ignore (another tab — or none —
|
|
165
|
-
// handles it, and the server times out if no tab answers). Ids are
|
|
166
|
-
// deterministic, so if several tabs run it they converge; first reply wins.
|
|
167
|
-
if (data.type === 'scratchpad:op') {
|
|
168
|
-
const run = getScratchExecutor(data.workspaceId as string)
|
|
169
|
-
if (!run) return
|
|
170
|
-
const opId = data.opId as string
|
|
171
|
-
run(data.op as ScratchOp).then(
|
|
172
|
-
result => sendMessage({ type: 'scratchpad:op-result', opId, result }),
|
|
173
|
-
err =>
|
|
174
|
-
sendMessage({
|
|
175
|
-
type: 'scratchpad:op-result',
|
|
176
|
-
opId,
|
|
177
|
-
error: err instanceof Error ? err.message : String(err)
|
|
178
|
-
})
|
|
179
|
-
)
|
|
180
|
-
return
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// StreamEvent frames — tagged with workspaceId + sessionId.
|
|
184
|
-
const workspaceId = data.workspaceId as string | undefined
|
|
185
|
-
const sessionId = data.sessionId as string | undefined
|
|
186
|
-
if (!workspaceId || !sessionId) return
|
|
187
|
-
const kind = data.kind
|
|
188
|
-
|
|
189
|
-
if (kind === 'snapshot' || kind === 'turn' || kind === 'notice' || kind === 'result') {
|
|
190
|
-
patchView(workspaceId, sessionId, data as unknown as StreamEvent)
|
|
191
|
-
// The real turn superseding a live preview is the clean handoff: drop the
|
|
192
|
-
// preview for that exact message id the instant its finalized turn lands, so
|
|
193
|
-
// there's no double-render and no flicker (both updates commit together).
|
|
194
|
-
if (kind === 'turn') {
|
|
195
|
-
const mid = (data as unknown as { turn?: { meta?: { apiMessageId?: string } } }).turn?.meta
|
|
196
|
-
?.apiMessageId
|
|
197
|
-
if (mid) store.clearPreview(mid)
|
|
198
|
-
}
|
|
199
|
-
// A `result` ends the turn — sweep any preview that never got an exact clear.
|
|
200
|
-
if (kind === 'result') store.clearPreviewsForSession(workspaceId, sessionId)
|
|
201
|
-
}
|
|
202
|
-
if (kind === 'error' && typeof data.content === 'string') {
|
|
203
|
-
store.setError(workspaceId, sessionId, data.content)
|
|
204
|
-
store.clearPreviewsForSession(workspaceId, sessionId)
|
|
205
|
-
}
|
|
206
|
-
if (kind === 'stopped') {
|
|
207
|
-
store.setProcessing(workspaceId, sessionId, false)
|
|
208
|
-
store.clearPreviewsForSession(workspaceId, sessionId)
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Fold a delta into a thread's cached transcript — but only if that transcript
|
|
213
|
-
// is already loaded/primed. A never-viewed background session has no cache
|
|
214
|
-
// entry; we deliberately skip it so a stray mid-run delta can't seed a partial,
|
|
215
|
-
// history-less view that would then never refetch. It loads in full from disk
|
|
216
|
-
// when the user actually opens it.
|
|
217
|
-
function patchView(workspaceId: string, sessionId: string, ev: StreamEvent) {
|
|
218
|
-
const queryKey = workspaceKeys.events(workspaceId, sessionId)
|
|
219
|
-
const existing = qc?.getQueryData<ViewState>(queryKey)
|
|
220
|
-
if (existing === undefined) return
|
|
221
|
-
qc?.setQueryData<ViewState>(queryKey, applyEvent(existing, ev))
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export function sendMessage(msg: ClientMessage) {
|
|
225
|
-
if (socket && socket.readyState === WebSocket.OPEN) socket.send(JSON.stringify(msg))
|
|
226
|
-
else queue.push(msg)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export function setWorkspaceSwitchHandler(fn: ((workspaceId: string) => void) | null) {
|
|
230
|
-
onWorkspaceSwitch = fn
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Test seam: inject the QueryClient the frame handler reads, without opening a
|
|
234
|
-
// socket (the browser-only `connect()` path). Production always goes through
|
|
235
|
-
// `initConnection`.
|
|
236
|
-
export function __setQueryClientForTests(client: QueryClient | null) {
|
|
237
|
-
qc = client
|
|
238
|
-
}
|