moi-computer 0.3.0-next.2 → 0.3.0
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/client/AGENTS.md +2 -2
- package/client/api/http.ts +1 -1
- package/client/api/workspace-keys.ts +1 -0
- package/client/app/AppRouter.tsx +14 -5
- package/client/app/routes/HomeRoute.tsx +1 -1
- package/client/app/routes/WorkspaceRoute.tsx +8 -2
- package/client/app/shell/SidebarLayout.tsx +10 -5
- package/client/assets/openai.svg +3 -0
- package/client/components/shared/BottomPanel.tsx +2 -2
- package/client/components/ui/button.tsx +3 -2
- package/client/components/ui/input.tsx +1 -1
- package/client/features/applets/AppletMount.tsx +44 -0
- package/client/features/applets/WidgetShell.tsx +4 -1
- package/client/features/applets/applet-cache.ts +8 -0
- package/client/features/applets/applet-styles.ts +61 -0
- package/client/features/chat/ChatComposer.tsx +2 -2
- package/client/features/chat/ChatPanel.tsx +8 -25
- package/client/features/chat/ChatPopup.tsx +3 -3
- package/client/features/chat/{ThreadSelector.tsx → ChatSelector.tsx} +4 -4
- package/client/features/chat/TurnView.tsx +8 -9
- package/client/features/chat/api.ts +1 -1
- package/client/features/chat/chat-send.ts +57 -0
- package/client/features/chat/tool-group/ToolCallGroup.tsx +2 -1
- package/client/features/chat/tool-group/format.ts +117 -0
- package/client/features/chat/useChat.ts +10 -34
- package/client/features/connectors/McpMenu.tsx +4 -21
- package/client/features/dev/DevRoutes.tsx +18 -0
- package/client/features/dev/HarnessDebugPage.tsx +468 -0
- package/client/{components/playground → features/dev}/PlaygroundPage.tsx +1 -1
- package/client/features/home/CreateWorkspaceDialog.tsx +64 -158
- package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
- package/client/features/home/HomeLogo.tsx +344 -0
- package/client/features/home/HomePage.tsx +15 -21
- package/client/features/home/WorkspacePreview.tsx +12 -5
- package/client/features/home/api.ts +11 -3
- package/client/features/home/workspace-presentation.tsx +4 -4
- package/client/features/settings/GeneralSettings.tsx +3 -3
- package/client/features/settings/IconPicker.tsx +4 -3
- package/client/features/settings/icon-picker-options.ts +0 -131
- 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/features/widgets/WidgetGrid.tsx +36 -20
- package/client/features/widgets/Widgets.tsx +140 -90
- package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -9
- package/client/features/workspace/WorkspaceScreen.tsx +179 -40
- package/client/features/workspace/WorkspaceTabs.tsx +4 -4
- package/client/index.css +0 -35
- package/client/index.html +1 -1
- package/client/lib/app-icon-registry.ts +145 -0
- package/client/runtime/useWorkspaceEvents.ts +3 -1
- package/client/theme.css +1 -1
- package/dist/chunk-4vf1t6v1.js +10 -0
- package/dist/chunk-4z52b2av.css +1 -0
- package/dist/chunk-6c8cwpzc.js +1 -0
- package/dist/chunk-b4b276wx.js +15 -0
- package/dist/{chunk-c4j722at.js → chunk-cs8vbert.js} +2 -2
- package/dist/chunk-fjksw6xf.js +1 -0
- package/dist/chunk-kxmvv1ax.js +48 -0
- package/dist/{chunk-p68fnz3q.js → chunk-vkvb3hjm.js} +1 -1
- package/dist/chunk-y82s1jxm.js +61 -0
- package/dist/chunk-zpxrb1ce.js +2 -0
- package/dist/index.html +2 -2
- package/dist/openai-h13pza4b.svg +3 -0
- package/lib/format.ts +2 -2
- package/lib/types.ts +38 -2
- package/lib/view-builder-meta.ts +35 -0
- package/lib/workspace-layout.ts +14 -0
- package/package.json +2 -1
- package/server/AGENTS.md +3 -3
- package/server/api.ts +165 -51
- 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 +79 -2
- 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} +1 -1
- 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 +326 -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 +6 -12
- package/server/moi-scaffold.ts +1 -1
- package/server/registry.ts +14 -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 +18 -40
- package/server/workspace-init.ts +6 -6
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +1 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
- package/client/assets/hermes-nous.png +0 -0
- package/client/hooks/useScrollFade.ts +0 -38
- package/dist/chunk-23cgr1tz.css +0 -1
- package/dist/chunk-3hy3qy6d.js +0 -10
- package/dist/chunk-dyfaffyz.js +0 -119
- package/dist/chunk-kpe40hm8.js +0 -1
- package/dist/chunk-ty6dvda0.js +0 -1
- package/dist/hermes-nous-pznd63x9.png +0 -0
- /package/client/{components/playground → features/dev}/PixelPainter.tsx +0 -0
- /package/client/{components/playground → features/dev}/ToolCallsPage.tsx +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
|
@@ -1,134 +1,3 @@
|
|
|
1
|
-
import type { Icon } from '@tabler/icons-react'
|
|
2
|
-
import {
|
|
3
|
-
IconActivity,
|
|
4
|
-
IconApi,
|
|
5
|
-
IconAtom,
|
|
6
|
-
IconBell,
|
|
7
|
-
IconBolt,
|
|
8
|
-
IconBook,
|
|
9
|
-
IconBrain,
|
|
10
|
-
IconBriefcase,
|
|
11
|
-
IconBug,
|
|
12
|
-
IconBulb,
|
|
13
|
-
IconCalendar,
|
|
14
|
-
IconCamera,
|
|
15
|
-
IconChartBar,
|
|
16
|
-
IconChefHat,
|
|
17
|
-
IconCloud,
|
|
18
|
-
IconCode,
|
|
19
|
-
IconCompass,
|
|
20
|
-
IconCpu,
|
|
21
|
-
IconCube,
|
|
22
|
-
IconDatabase,
|
|
23
|
-
IconDeviceGamepad2,
|
|
24
|
-
IconDiamond,
|
|
25
|
-
IconFeather,
|
|
26
|
-
IconFile,
|
|
27
|
-
IconFlame,
|
|
28
|
-
IconFlask,
|
|
29
|
-
IconFolder,
|
|
30
|
-
IconGhost,
|
|
31
|
-
IconGift,
|
|
32
|
-
IconGlobe,
|
|
33
|
-
IconHeart,
|
|
34
|
-
IconHexagon,
|
|
35
|
-
IconHome,
|
|
36
|
-
IconKey,
|
|
37
|
-
IconLeaf,
|
|
38
|
-
IconMail,
|
|
39
|
-
IconMap,
|
|
40
|
-
IconMessage,
|
|
41
|
-
IconMoon,
|
|
42
|
-
IconMountain,
|
|
43
|
-
IconMusic,
|
|
44
|
-
IconPalette,
|
|
45
|
-
IconPaperclip,
|
|
46
|
-
IconPhoto,
|
|
47
|
-
IconPlanet,
|
|
48
|
-
IconPlug,
|
|
49
|
-
IconRobot,
|
|
50
|
-
IconRocket,
|
|
51
|
-
IconSettings,
|
|
52
|
-
IconShield,
|
|
53
|
-
IconShoppingCart,
|
|
54
|
-
IconSnowflake,
|
|
55
|
-
IconSparkles,
|
|
56
|
-
IconStar,
|
|
57
|
-
IconSun,
|
|
58
|
-
IconTarget,
|
|
59
|
-
IconTerminal2,
|
|
60
|
-
IconTool,
|
|
61
|
-
IconTrophy,
|
|
62
|
-
IconUser,
|
|
63
|
-
IconWand,
|
|
64
|
-
IconWorld
|
|
65
|
-
} from '@tabler/icons-react'
|
|
66
|
-
|
|
67
|
-
export const ICON_CHOICES: { id: string; Icon: Icon }[] = [
|
|
68
|
-
{ id: 'rocket', Icon: IconRocket },
|
|
69
|
-
{ id: 'sparkles', Icon: IconSparkles },
|
|
70
|
-
{ id: 'bolt', Icon: IconBolt },
|
|
71
|
-
{ id: 'flame', Icon: IconFlame },
|
|
72
|
-
{ id: 'star', Icon: IconStar },
|
|
73
|
-
{ id: 'heart', Icon: IconHeart },
|
|
74
|
-
{ id: 'diamond', Icon: IconDiamond },
|
|
75
|
-
{ id: 'trophy', Icon: IconTrophy },
|
|
76
|
-
{ id: 'target', Icon: IconTarget },
|
|
77
|
-
{ id: 'bulb', Icon: IconBulb },
|
|
78
|
-
{ id: 'brain', Icon: IconBrain },
|
|
79
|
-
{ id: 'robot', Icon: IconRobot },
|
|
80
|
-
{ id: 'wand', Icon: IconWand },
|
|
81
|
-
{ id: 'atom', Icon: IconAtom },
|
|
82
|
-
{ id: 'flask', Icon: IconFlask },
|
|
83
|
-
{ id: 'cpu', Icon: IconCpu },
|
|
84
|
-
{ id: 'code', Icon: IconCode },
|
|
85
|
-
{ id: 'terminal', Icon: IconTerminal2 },
|
|
86
|
-
{ id: 'api', Icon: IconApi },
|
|
87
|
-
{ id: 'database', Icon: IconDatabase },
|
|
88
|
-
{ id: 'cube', Icon: IconCube },
|
|
89
|
-
{ id: 'hexagon', Icon: IconHexagon },
|
|
90
|
-
{ id: 'plug', Icon: IconPlug },
|
|
91
|
-
{ id: 'tool', Icon: IconTool },
|
|
92
|
-
{ id: 'settings', Icon: IconSettings },
|
|
93
|
-
{ id: 'bug', Icon: IconBug },
|
|
94
|
-
{ id: 'activity', Icon: IconActivity },
|
|
95
|
-
{ id: 'chart', Icon: IconChartBar },
|
|
96
|
-
{ id: 'briefcase', Icon: IconBriefcase },
|
|
97
|
-
{ id: 'folder', Icon: IconFolder },
|
|
98
|
-
{ id: 'file', Icon: IconFile },
|
|
99
|
-
{ id: 'book', Icon: IconBook },
|
|
100
|
-
{ id: 'message', Icon: IconMessage },
|
|
101
|
-
{ id: 'mail', Icon: IconMail },
|
|
102
|
-
{ id: 'bell', Icon: IconBell },
|
|
103
|
-
{ id: 'paperclip', Icon: IconPaperclip },
|
|
104
|
-
{ id: 'key', Icon: IconKey },
|
|
105
|
-
{ id: 'shield', Icon: IconShield },
|
|
106
|
-
{ id: 'user', Icon: IconUser },
|
|
107
|
-
{ id: 'home', Icon: IconHome },
|
|
108
|
-
{ id: 'globe', Icon: IconGlobe },
|
|
109
|
-
{ id: 'world', Icon: IconWorld },
|
|
110
|
-
{ id: 'planet', Icon: IconPlanet },
|
|
111
|
-
{ id: 'compass', Icon: IconCompass },
|
|
112
|
-
{ id: 'map', Icon: IconMap },
|
|
113
|
-
{ id: 'calendar', Icon: IconCalendar },
|
|
114
|
-
{ id: 'cloud', Icon: IconCloud },
|
|
115
|
-
{ id: 'sun', Icon: IconSun },
|
|
116
|
-
{ id: 'moon', Icon: IconMoon },
|
|
117
|
-
{ id: 'snowflake', Icon: IconSnowflake },
|
|
118
|
-
{ id: 'leaf', Icon: IconLeaf },
|
|
119
|
-
{ id: 'mountain', Icon: IconMountain },
|
|
120
|
-
{ id: 'feather', Icon: IconFeather },
|
|
121
|
-
{ id: 'ghost', Icon: IconGhost },
|
|
122
|
-
{ id: 'music', Icon: IconMusic },
|
|
123
|
-
{ id: 'camera', Icon: IconCamera },
|
|
124
|
-
{ id: 'photo', Icon: IconPhoto },
|
|
125
|
-
{ id: 'palette', Icon: IconPalette },
|
|
126
|
-
{ id: 'gamepad', Icon: IconDeviceGamepad2 },
|
|
127
|
-
{ id: 'gift', Icon: IconGift },
|
|
128
|
-
{ id: 'cart', Icon: IconShoppingCart },
|
|
129
|
-
{ id: 'chef', Icon: IconChefHat }
|
|
130
|
-
]
|
|
131
|
-
|
|
132
1
|
export const FAVORITE_EMOJI = [
|
|
133
2
|
'🚀',
|
|
134
3
|
'✨',
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type FormEvent, type KeyboardEvent, useEffect, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { IconArrowUp, IconLoader2 } from '@tabler/icons-react'
|
|
4
|
+
|
|
5
|
+
import { Button } from '@/client/components/ui/button'
|
|
6
|
+
import type { ViewBuilder } from '@/lib/types'
|
|
7
|
+
|
|
8
|
+
type ViewBuilderTabProps = {
|
|
9
|
+
builder: ViewBuilder
|
|
10
|
+
onSave: (requirements: string) => Promise<unknown>
|
|
11
|
+
onSubmit: (requirements: string) => Promise<unknown>
|
|
12
|
+
onOpenChat: () => void
|
|
13
|
+
onDiscard: () => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function ViewBuilderTab({
|
|
17
|
+
builder,
|
|
18
|
+
onSave,
|
|
19
|
+
onSubmit,
|
|
20
|
+
onOpenChat,
|
|
21
|
+
onDiscard
|
|
22
|
+
}: ViewBuilderTabProps) {
|
|
23
|
+
const [requirements, setRequirements] = useState(builder.input.requirements)
|
|
24
|
+
const [submitting, setSubmitting] = useState(false)
|
|
25
|
+
const [saveError, setSaveError] = useState<string | null>(null)
|
|
26
|
+
const composerRef = useRef<HTMLTextAreaElement>(null)
|
|
27
|
+
const onSaveRef = useRef(onSave)
|
|
28
|
+
onSaveRef.current = onSave
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (builder.status !== 'draft' || requirements === builder.input.requirements) return
|
|
32
|
+
const timer = setTimeout(() => {
|
|
33
|
+
void onSaveRef
|
|
34
|
+
.current(requirements)
|
|
35
|
+
.then(() => setSaveError(null))
|
|
36
|
+
.catch(error =>
|
|
37
|
+
setSaveError(error instanceof Error ? error.message : 'Could not save requirements')
|
|
38
|
+
)
|
|
39
|
+
}, 500)
|
|
40
|
+
return () => clearTimeout(timer)
|
|
41
|
+
}, [builder.input.requirements, builder.status, requirements])
|
|
42
|
+
|
|
43
|
+
const submit = async (event: FormEvent) => {
|
|
44
|
+
event.preventDefault()
|
|
45
|
+
if (!requirements.trim() || submitting) return
|
|
46
|
+
setSubmitting(true)
|
|
47
|
+
try {
|
|
48
|
+
await onSubmit(requirements)
|
|
49
|
+
} catch (error) {
|
|
50
|
+
setSaveError(error instanceof Error ? error.message : 'Could not start view builder')
|
|
51
|
+
setSubmitting(false)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (builder.status === 'draft') {
|
|
56
|
+
return (
|
|
57
|
+
<div className="flex min-h-0 flex-1 items-center justify-center px-3 py-6">
|
|
58
|
+
<div className="flex w-full max-w-(--chat-max-container) flex-col gap-6">
|
|
59
|
+
<div className="flex flex-col gap-1 text-center">
|
|
60
|
+
<h1 className="font-medium">What should this view do?</h1>
|
|
61
|
+
<p className="mx-auto max-w-sm text-sm text-muted-foreground">
|
|
62
|
+
Describe the content, data, and actions you need.
|
|
63
|
+
</p>
|
|
64
|
+
</div>
|
|
65
|
+
<form
|
|
66
|
+
onSubmit={submit}
|
|
67
|
+
onMouseDown={event => {
|
|
68
|
+
if (event.target instanceof HTMLElement && event.target.closest('button')) return
|
|
69
|
+
event.preventDefault()
|
|
70
|
+
composerRef.current?.focus()
|
|
71
|
+
}}
|
|
72
|
+
className="flex w-full cursor-text flex-col gap-1 rounded-lg bg-card p-2 text-card-foreground shadow-xs transition-[color,box-shadow] outline-none focus-within:shadow-sm"
|
|
73
|
+
>
|
|
74
|
+
<label className="sr-only" htmlFor={`view-builder-${builder.id}`}>
|
|
75
|
+
View requirements
|
|
76
|
+
</label>
|
|
77
|
+
<textarea
|
|
78
|
+
ref={composerRef}
|
|
79
|
+
id={`view-builder-${builder.id}`}
|
|
80
|
+
value={requirements}
|
|
81
|
+
onChange={event => setRequirements(event.target.value)}
|
|
82
|
+
onKeyDown={(event: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
83
|
+
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
|
|
84
|
+
event.preventDefault()
|
|
85
|
+
event.currentTarget.form?.requestSubmit()
|
|
86
|
+
}
|
|
87
|
+
}}
|
|
88
|
+
placeholder="Build a customer dashboard with…"
|
|
89
|
+
rows={1}
|
|
90
|
+
className="field-sizing-content max-h-40 min-h-16 w-full resize-none bg-transparent px-2 py-1 text-sm leading-relaxed outline-none placeholder:text-muted-foreground disabled:opacity-50"
|
|
91
|
+
aria-describedby={saveError ? `view-builder-error-${builder.id}` : undefined}
|
|
92
|
+
aria-invalid={Boolean(saveError)}
|
|
93
|
+
autoFocus
|
|
94
|
+
/>
|
|
95
|
+
<div className="flex items-center justify-end gap-1.5">
|
|
96
|
+
<Button
|
|
97
|
+
type="submit"
|
|
98
|
+
size="icon"
|
|
99
|
+
disabled={!requirements.trim() || submitting}
|
|
100
|
+
aria-label="Build view"
|
|
101
|
+
>
|
|
102
|
+
{submitting ? (
|
|
103
|
+
<IconLoader2 stroke={1.5} className="animate-spin" />
|
|
104
|
+
) : (
|
|
105
|
+
<IconArrowUp stroke={1.5} />
|
|
106
|
+
)}
|
|
107
|
+
</Button>
|
|
108
|
+
</div>
|
|
109
|
+
</form>
|
|
110
|
+
{saveError && (
|
|
111
|
+
<p
|
|
112
|
+
id={`view-builder-error-${builder.id}`}
|
|
113
|
+
role="alert"
|
|
114
|
+
className="text-sm text-destructive"
|
|
115
|
+
>
|
|
116
|
+
{saveError}
|
|
117
|
+
</p>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (builder.status === 'waiting') {
|
|
125
|
+
return (
|
|
126
|
+
<div className="flex min-h-0 flex-1 items-center justify-center p-6">
|
|
127
|
+
<div className="flex max-w-md flex-col items-center gap-4 text-center">
|
|
128
|
+
<div className="flex flex-col gap-1">
|
|
129
|
+
<h1 className="text-lg font-semibold">The view needs your attention</h1>
|
|
130
|
+
<p className="text-sm text-muted-foreground">
|
|
131
|
+
{builder.error ?? 'Open its chat to answer or ask the agent to continue.'}
|
|
132
|
+
</p>
|
|
133
|
+
</div>
|
|
134
|
+
<div className="flex gap-2">
|
|
135
|
+
<Button onClick={onOpenChat}>Open chat</Button>
|
|
136
|
+
<Button variant="secondary" onClick={onDiscard}>
|
|
137
|
+
Discard
|
|
138
|
+
</Button>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<div className="flex min-h-0 flex-1 items-center justify-center p-6">
|
|
147
|
+
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
|
148
|
+
<IconLoader2 stroke={1.75} className="animate-spin" />
|
|
149
|
+
{builder.status === 'ready' ? 'Opening view…' : 'Building your view…'}
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
|
|
3
|
+
import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
|
|
4
|
+
import { WORKSPACE_RESOURCE_OPTIONS } from '@/client/api/query-options'
|
|
5
|
+
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
6
|
+
import { APP_ICON_IDS } from '@/client/lib/app-icon-registry'
|
|
7
|
+
import { useWorkspaceEvent } from '@/client/runtime/useWorkspaceEvents'
|
|
8
|
+
import type { ViewBuilder } from '@/lib/types'
|
|
9
|
+
|
|
10
|
+
function upsertBuilder(builders: ViewBuilder[] | undefined, builder: ViewBuilder): ViewBuilder[] {
|
|
11
|
+
const current = builders ?? []
|
|
12
|
+
const index = current.findIndex(candidate => candidate.id === builder.id)
|
|
13
|
+
if (index === -1) return [...current, builder]
|
|
14
|
+
return current.map(candidate =>
|
|
15
|
+
candidate.id === builder.id && candidate.updatedAt <= builder.updatedAt ? builder : candidate
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useViewBuilders(workspaceId: string) {
|
|
20
|
+
const queryClient = useQueryClient()
|
|
21
|
+
useWorkspaceEvent(event => {
|
|
22
|
+
if (event.type === 'view-builder:updated' && event.workspaceId === workspaceId) {
|
|
23
|
+
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
24
|
+
upsertBuilder(current, event.builder)
|
|
25
|
+
)
|
|
26
|
+
} else if (event.type === 'view-builder:deleted' && event.workspaceId === workspaceId) {
|
|
27
|
+
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
28
|
+
(current ?? []).filter(builder => builder.id !== event.builderId)
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return useQuery<ViewBuilder[]>({
|
|
34
|
+
queryKey: workspaceKeys.viewBuilders(workspaceId),
|
|
35
|
+
queryFn: async () => {
|
|
36
|
+
const data = await requestJson<{ builders: ViewBuilder[] }>(
|
|
37
|
+
`/api/workspaces/${workspaceId}/view-builders`
|
|
38
|
+
)
|
|
39
|
+
return data.builders
|
|
40
|
+
},
|
|
41
|
+
...WORKSPACE_RESOURCE_OPTIONS
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function useCreateViewBuilder(workspaceId: string) {
|
|
46
|
+
const queryClient = useQueryClient()
|
|
47
|
+
return useMutation<ViewBuilder, Error>({
|
|
48
|
+
mutationFn: () =>
|
|
49
|
+
requestJson(
|
|
50
|
+
`/api/workspaces/${workspaceId}/view-builders`,
|
|
51
|
+
jsonRequest('POST'),
|
|
52
|
+
'Failed to create view builder'
|
|
53
|
+
),
|
|
54
|
+
onSuccess: builder => {
|
|
55
|
+
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
56
|
+
upsertBuilder(current, builder)
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function useSaveViewBuilder(workspaceId: string) {
|
|
63
|
+
const queryClient = useQueryClient()
|
|
64
|
+
return useMutation<ViewBuilder, Error, { builderId: string; requirements: string }>({
|
|
65
|
+
mutationFn: ({ builderId, requirements }) =>
|
|
66
|
+
requestJson(
|
|
67
|
+
`/api/workspaces/${workspaceId}/view-builders/${builderId}`,
|
|
68
|
+
jsonRequest('PATCH', { input: { requirements } }),
|
|
69
|
+
'Failed to save view requirements'
|
|
70
|
+
),
|
|
71
|
+
onSuccess: builder => {
|
|
72
|
+
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
73
|
+
upsertBuilder(current, builder)
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type SubmitViewBuilderInput = {
|
|
80
|
+
builderId: string
|
|
81
|
+
requirements: string
|
|
82
|
+
optimisticId: string
|
|
83
|
+
model?: string
|
|
84
|
+
effort?: string
|
|
85
|
+
stream?: boolean
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function useSubmitViewBuilder(workspaceId: string) {
|
|
89
|
+
const queryClient = useQueryClient()
|
|
90
|
+
return useMutation<ViewBuilder, Error, SubmitViewBuilderInput>({
|
|
91
|
+
mutationFn: ({ builderId, requirements, ...options }) =>
|
|
92
|
+
requestJson(
|
|
93
|
+
`/api/workspaces/${workspaceId}/view-builders/${builderId}/submit`,
|
|
94
|
+
jsonRequest('POST', {
|
|
95
|
+
input: { requirements },
|
|
96
|
+
availableIcons: APP_ICON_IDS,
|
|
97
|
+
...options
|
|
98
|
+
}),
|
|
99
|
+
'Failed to start view builder'
|
|
100
|
+
),
|
|
101
|
+
onSuccess: builder => {
|
|
102
|
+
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
103
|
+
upsertBuilder(current, builder)
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function useDiscardViewBuilder(workspaceId: string) {
|
|
110
|
+
const queryClient = useQueryClient()
|
|
111
|
+
return useMutation<void, Error, string>({
|
|
112
|
+
mutationFn: builderId =>
|
|
113
|
+
requestVoid(
|
|
114
|
+
`/api/workspaces/${workspaceId}/view-builders/${builderId}`,
|
|
115
|
+
{ method: 'DELETE' },
|
|
116
|
+
'Failed to discard view builder'
|
|
117
|
+
),
|
|
118
|
+
onSuccess: (_result, builderId) => {
|
|
119
|
+
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
120
|
+
(current ?? []).filter(builder => builder.id !== builderId)
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
|
|
3
|
+
import { useWorkspaceModels } from '@/client/features/chat/api'
|
|
4
|
+
import { resolveChatRunOptions, startOptimisticTurn } from '@/client/features/chat/chat-send'
|
|
5
|
+
import { liveStore } from '@/client/features/chat/chat-store'
|
|
6
|
+
import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
|
|
7
|
+
import {
|
|
8
|
+
useCreateViewBuilder,
|
|
9
|
+
useDiscardViewBuilder,
|
|
10
|
+
useSaveViewBuilder,
|
|
11
|
+
useSubmitViewBuilder
|
|
12
|
+
} from '@/client/features/views/api'
|
|
13
|
+
import type { ViewBuilder } from '@/lib/types'
|
|
14
|
+
|
|
15
|
+
export function useViewBuilderActions() {
|
|
16
|
+
const queryClient = useQueryClient()
|
|
17
|
+
const { workspaceId, layout } = useWorkspaceLayoutCtx()
|
|
18
|
+
const modelData = useWorkspaceModels(workspaceId).data
|
|
19
|
+
const createMutation = useCreateViewBuilder(workspaceId)
|
|
20
|
+
const saveMutation = useSaveViewBuilder(workspaceId)
|
|
21
|
+
const submitMutation = useSubmitViewBuilder(workspaceId)
|
|
22
|
+
const discardMutation = useDiscardViewBuilder(workspaceId)
|
|
23
|
+
|
|
24
|
+
const create = () => createMutation.mutateAsync()
|
|
25
|
+
|
|
26
|
+
const save = (builderId: string, requirements: string) =>
|
|
27
|
+
saveMutation.mutateAsync({ builderId, requirements })
|
|
28
|
+
|
|
29
|
+
const submit = async (builder: ViewBuilder, requirements: string) => {
|
|
30
|
+
const text = requirements.trim()
|
|
31
|
+
if (!text) return
|
|
32
|
+
|
|
33
|
+
const optimisticId = startOptimisticTurn({
|
|
34
|
+
queryClient,
|
|
35
|
+
workspaceId,
|
|
36
|
+
sessionId: builder.sessionId,
|
|
37
|
+
parts: [{ type: 'text', text }]
|
|
38
|
+
})
|
|
39
|
+
liveStore.getState().setActive(workspaceId, builder.sessionId)
|
|
40
|
+
|
|
41
|
+
const { model, effort, stream } = resolveChatRunOptions(
|
|
42
|
+
modelData,
|
|
43
|
+
layout.selectedModel,
|
|
44
|
+
layout.selectedEffort
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
await submitMutation.mutateAsync({
|
|
49
|
+
builderId: builder.id,
|
|
50
|
+
requirements: text,
|
|
51
|
+
optimisticId,
|
|
52
|
+
model,
|
|
53
|
+
effort,
|
|
54
|
+
stream
|
|
55
|
+
})
|
|
56
|
+
} catch (error) {
|
|
57
|
+
liveStore.getState().setProcessing(workspaceId, builder.sessionId, false)
|
|
58
|
+
liveStore
|
|
59
|
+
.getState()
|
|
60
|
+
.setError(
|
|
61
|
+
workspaceId,
|
|
62
|
+
builder.sessionId,
|
|
63
|
+
error instanceof Error ? error.message : 'Could not start view builder'
|
|
64
|
+
)
|
|
65
|
+
throw error
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const discard = (builderId: string) => discardMutation.mutateAsync(builderId)
|
|
70
|
+
|
|
71
|
+
return { create, save, submit, discard }
|
|
72
|
+
}
|
|
@@ -12,27 +12,19 @@ import type { GridItem } from '@/client/features/widgets/grid'
|
|
|
12
12
|
|
|
13
13
|
import { WidgetFrame } from './WidgetFrame'
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
cols?: number
|
|
17
|
-
rowHeight?: number
|
|
18
|
-
gap?: number
|
|
15
|
+
type WidgetGridLayoutProps = {
|
|
19
16
|
items: GridItem[]
|
|
20
17
|
editing?: boolean
|
|
21
18
|
renderItem: (id: string) => ReactNode
|
|
22
19
|
onLayoutChange?: (items: GridItem[]) => void
|
|
23
|
-
onRemove?: (id: string) => void
|
|
24
20
|
}
|
|
25
21
|
|
|
26
|
-
export function
|
|
27
|
-
cols = 4,
|
|
28
|
-
rowHeight = 160,
|
|
29
|
-
gap = 8,
|
|
22
|
+
export function WidgetGridLayout({
|
|
30
23
|
items,
|
|
31
24
|
editing,
|
|
32
25
|
renderItem,
|
|
33
|
-
onLayoutChange
|
|
34
|
-
|
|
35
|
-
}: WidgetGridProps) {
|
|
26
|
+
onLayoutChange
|
|
27
|
+
}: WidgetGridLayoutProps) {
|
|
36
28
|
const [layout, setLayout] = useState<Layout>(() => packItems(items, []))
|
|
37
29
|
const [prevItems, setPrevItems] = useState(items)
|
|
38
30
|
|
|
@@ -71,12 +63,12 @@ export function WidgetGrid({
|
|
|
71
63
|
)
|
|
72
64
|
|
|
73
65
|
return (
|
|
74
|
-
<div ref={containerRef}>
|
|
66
|
+
<div ref={containerRef} className="mx-auto w-full max-w-[var(--column-w)]">
|
|
75
67
|
{mounted && (
|
|
76
68
|
<GridLayout
|
|
77
69
|
width={width}
|
|
78
70
|
layout={layout}
|
|
79
|
-
gridConfig={{ cols, rowHeight, margin: [
|
|
71
|
+
gridConfig={{ cols: 4, rowHeight: 160, margin: [8, 8], containerPadding: [0, 0] }}
|
|
80
72
|
dragConfig={{ enabled: !!editing }}
|
|
81
73
|
resizeConfig={{ enabled: false }}
|
|
82
74
|
compactor={verticalCompactor}
|
|
@@ -90,12 +82,7 @@ export function WidgetGrid({
|
|
|
90
82
|
className="size-full"
|
|
91
83
|
transition={{ type: 'spring', duration: 0.35, bounce: 0 }}
|
|
92
84
|
>
|
|
93
|
-
|
|
94
|
-
editing={editing}
|
|
95
|
-
onRemove={onRemove ? () => onRemove(item.i) : undefined}
|
|
96
|
-
>
|
|
97
|
-
{renderItem(item.i)}
|
|
98
|
-
</WidgetFrame>
|
|
85
|
+
{renderItem(item.i)}
|
|
99
86
|
</motion.div>
|
|
100
87
|
</div>
|
|
101
88
|
))}
|
|
@@ -104,3 +91,32 @@ export function WidgetGrid({
|
|
|
104
91
|
</div>
|
|
105
92
|
)
|
|
106
93
|
}
|
|
94
|
+
|
|
95
|
+
export type WidgetGridProps = {
|
|
96
|
+
items: GridItem[]
|
|
97
|
+
editing?: boolean
|
|
98
|
+
renderItem: (id: string) => ReactNode
|
|
99
|
+
onLayoutChange?: (items: GridItem[]) => void
|
|
100
|
+
onRemove?: (id: string) => void
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function WidgetGrid({
|
|
104
|
+
items,
|
|
105
|
+
editing,
|
|
106
|
+
renderItem,
|
|
107
|
+
onLayoutChange,
|
|
108
|
+
onRemove
|
|
109
|
+
}: WidgetGridProps) {
|
|
110
|
+
return (
|
|
111
|
+
<WidgetGridLayout
|
|
112
|
+
items={items}
|
|
113
|
+
editing={editing}
|
|
114
|
+
onLayoutChange={onLayoutChange}
|
|
115
|
+
renderItem={id => (
|
|
116
|
+
<WidgetFrame editing={editing} onRemove={onRemove ? () => onRemove(id) : undefined}>
|
|
117
|
+
{renderItem(id)}
|
|
118
|
+
</WidgetFrame>
|
|
119
|
+
)}
|
|
120
|
+
/>
|
|
121
|
+
)
|
|
122
|
+
}
|