moi-computer 0.12.0 → 0.12.1-next.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/app-ui-keys.ts +1 -1
- package/client/api/workspace-keys.ts +1 -3
- package/client/app/routes/WorkspaceRoute.tsx +2 -8
- package/client/features/applets/applet-runtime.ts +11 -13
- package/client/features/chat/ChatPanel.tsx +70 -49
- package/client/features/chat/ChatPopup.tsx +81 -8
- package/client/features/chat/applet-chat-intents.ts +31 -12
- package/client/features/chat/chat-send.ts +33 -1
- package/client/features/chat/chat-store.ts +10 -0
- package/client/features/chat/composer/ChatComposer.tsx +24 -27
- package/client/features/chat/composer/ModelPicker.tsx +3 -3
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +3 -3
- package/client/features/chat/connection/chat-frames.ts +14 -7
- package/client/features/chat/messages/ChatEmptyState.tsx +33 -19
- package/client/features/chat/messages/MarkdownContent.tsx +3 -3
- package/client/features/chat/messages/fork-history.ts +14 -0
- package/client/features/chat/sessions/ChatSelector.tsx +138 -79
- package/client/features/chat/sessions/api.ts +109 -19
- package/client/features/chat/sessions/browser-tab-state.ts +30 -7
- package/client/features/chat/sessions/useSelectedSession.ts +217 -51
- package/client/features/chat/useChat.ts +43 -45
- package/client/features/collab/client.ts +10 -11
- package/client/features/collab/hooks.tsx +6 -11
- package/client/features/collab/host-state.ts +57 -128
- package/client/features/collab/provider.tsx +3 -3
- package/client/features/collab/testing/fake-engine.ts +6 -27
- package/client/features/collab/workspace-users-menu.tsx +3 -7
- package/client/features/drawings/{useViewBuilderSketch.ts → useViewSketch.ts} +7 -7
- package/client/features/home/HomePage.tsx +2 -2
- package/client/features/overview/Overview.tsx +3 -6
- package/client/features/overview/default/ViewsWidget.tsx +5 -12
- package/client/features/overview/default/registry.tsx +2 -4
- package/client/features/views/PendingViewScreen.tsx +279 -0
- package/client/features/views/ViewManager.tsx +10 -10
- package/client/features/views/api.ts +63 -130
- package/client/features/views/useViewActions.ts +151 -0
- package/client/features/views/useViewDrafts.ts +79 -0
- package/client/features/views/view-presentation.ts +4 -5
- package/client/features/views/view-submission.ts +88 -0
- package/client/features/workspace/WorkspaceMenu.tsx +63 -0
- package/client/features/workspace/WorkspaceScreen.tsx +180 -375
- package/client/features/workspace/browser-tab-state.ts +16 -9
- package/client/features/workspace/moi-context.ts +13 -15
- package/client/features/workspace/tab-resolution.ts +16 -29
- package/client/features/workspace/useWorkspaceNavigation.ts +146 -104
- package/client/index.tsx +5 -1
- package/client/runtime/useWorkspaceEvents.ts +7 -6
- package/client/store/ui.ts +25 -29
- package/dist/chunk-1zhnhy00.js +1 -0
- package/dist/chunk-27501vke.js +1 -0
- package/dist/{chunk-jf6czgrz.js → chunk-9xtv6djt.js} +2 -2
- package/dist/chunk-am1x230f.js +2 -0
- package/dist/{chunk-nez8sdta.js → chunk-darpsw65.js} +1 -1
- package/dist/{chunk-97eg9mjn.js → chunk-gps4qc38.js} +1 -1
- package/dist/{chunk-3a48fyf7.js → chunk-hzwr8dp8.js} +4 -4
- package/dist/{chunk-efdyz6xp.js → chunk-j905va8r.js} +1 -1
- package/dist/chunk-n33w9y38.js +10 -0
- package/dist/chunk-r63ks44z.js +68 -0
- package/dist/{chunk-vfpsc75k.js → chunk-vqpkqtdr.js} +1 -1
- package/dist/chunk-wd46nk26.css +1 -0
- package/dist/chunk-xgt7vxt9.js +1 -0
- package/dist/{chunk-z3byfve5.js → chunk-yvzhwtfa.js} +2 -2
- package/dist/index.html +1 -1
- package/lib/ids.ts +2 -5
- package/lib/moi-context.ts +100 -73
- package/lib/navigation.ts +48 -87
- package/lib/session-drafts.ts +10 -0
- package/lib/types.ts +64 -31
- package/lib/view-build-directives.ts +12 -0
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-tabs.ts +12 -7
- package/package.json +3 -1
- package/server/agent-launcher.ts +27 -0
- package/server/api.ts +119 -209
- package/server/app-config.ts +21 -2
- package/server/applets/build-worker.ts +2 -1
- package/server/applets/view-source.ts +7 -1
- package/server/cli-env.ts +72 -50
- package/server/cli.ts +101 -64
- package/server/control.ts +82 -63
- package/server/data-dir.ts +13 -0
- package/server/functions.ts +2 -1
- package/server/harness/README.md +8 -0
- package/server/harness/acp/adapter.ts +2 -2
- package/server/harness/acp/client.ts +2 -1
- package/server/harness/acp/discovery.ts +3 -3
- package/server/harness/acp/session.ts +6 -9
- package/server/harness/claude-code/adapter.ts +13 -8
- package/server/harness/claude-code/auth.ts +3 -2
- package/server/harness/claude-code/cli.ts +3 -1
- package/server/harness/claude-code/git-worktree.ts +5 -2
- package/server/harness/claude-code/index.ts +5 -0
- package/server/harness/claude-code/mcp.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -0
- package/server/harness/claude-code/session.ts +5 -34
- package/server/harness/claude-code/sessions.ts +8 -12
- package/server/harness/codex/NOTES.md +23 -4
- package/server/harness/codex/adapter.ts +5 -3
- package/server/harness/codex/client.ts +13 -21
- package/server/harness/codex/index.ts +18 -0
- package/server/harness/codex/session.ts +6 -14
- package/server/harness/codex/thread-list.ts +74 -0
- package/server/harness/fork.ts +12 -0
- package/server/harness/openclaw/adapter.ts +3 -3
- package/server/harness/openclaw/session.ts +2 -30
- package/server/harness/session-title.ts +12 -3
- package/server/harness/types.ts +8 -3
- package/server/moi-scaffold.ts +2 -1
- package/server/pending-views.ts +164 -0
- package/server/registry.ts +14 -4
- package/server/selected-session.ts +91 -44
- package/server/service.ts +16 -2
- package/server/session-archive.ts +32 -0
- package/server/session-config.ts +16 -111
- package/server/session-lifecycle.ts +17 -0
- package/server/session-store.ts +127 -0
- package/server/status.ts +3 -1
- package/server/tabs.ts +7 -10
- package/server/view-sessions.ts +267 -0
- package/server/views.ts +30 -41
- package/server/web.ts +47 -45
- package/server/workspace-env.ts +27 -0
- package/server/workspace-init.ts +6 -2
- package/workspace/.claude/skills/moi-workspace/SKILL.md +49 -20
- package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +2 -5
- package/client/features/views/ViewBuilder.tsx +0 -239
- package/client/features/views/useViewBuilderActions.ts +0 -103
- package/client/features/views/useViewBuilderDrafts.ts +0 -68
- package/dist/chunk-2jncyq65.js +0 -1
- package/dist/chunk-e2q5ken7.js +0 -68
- package/dist/chunk-h2kj1ysj.js +0 -1
- package/dist/chunk-nzwgm8vc.css +0 -1
- package/dist/chunk-ph0h6h86.js +0 -1
- package/dist/chunk-ryg9z3kn.js +0 -10
- package/dist/chunk-tpn177bt.js +0 -2
- package/lib/view-builder-directives.ts +0 -16
- package/server/chat-selection.ts +0 -22
- package/server/view-builders.ts +0 -453
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import type { ReactNode, Ref } from 'react'
|
|
2
|
+
import { useImperativeHandle } from 'react'
|
|
3
|
+
|
|
4
|
+
import { Button } from '@/client/components/ui/button'
|
|
5
|
+
import { Spinner } from '@/client/components/ui/spinner'
|
|
6
|
+
import { DrawingLayer } from '@/client/features/drawings/DrawingLayer'
|
|
7
|
+
import { DrawingToolbar } from '@/client/features/drawings/DrawingToolbar'
|
|
8
|
+
import {
|
|
9
|
+
type DrawingControls,
|
|
10
|
+
useDrawingHistoryState
|
|
11
|
+
} from '@/client/features/drawings/useDrawingLayer'
|
|
12
|
+
import { type ViewSketchController, useViewSketch } from '@/client/features/drawings/useViewSketch'
|
|
13
|
+
import { cn } from '@/client/lib/cn'
|
|
14
|
+
import type { PendingView } from '@/lib/types'
|
|
15
|
+
import { draftSessionId } from '@/lib/session-drafts'
|
|
16
|
+
import { viewTabId } from '@/lib/workspace-tabs'
|
|
17
|
+
import { IconScribble } from '@tabler/icons-react'
|
|
18
|
+
|
|
19
|
+
export type PendingViewHandle = {
|
|
20
|
+
prepareSketchForSend: () => Promise<void>
|
|
21
|
+
resetSketch: () => Promise<void>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type PendingViewScreenProps = {
|
|
25
|
+
ref?: Ref<PendingViewHandle>
|
|
26
|
+
active: boolean
|
|
27
|
+
pendingView: PendingView
|
|
28
|
+
running: boolean
|
|
29
|
+
sketchSessionId?: string
|
|
30
|
+
chatDocked: boolean
|
|
31
|
+
workspaceId: string
|
|
32
|
+
onEditingStart: () => void
|
|
33
|
+
onContinueInChat: () => void
|
|
34
|
+
onOpenChat: () => void
|
|
35
|
+
onDiscard: () => void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function PendingViewScreen({
|
|
39
|
+
ref,
|
|
40
|
+
active,
|
|
41
|
+
pendingView,
|
|
42
|
+
running,
|
|
43
|
+
sketchSessionId,
|
|
44
|
+
chatDocked,
|
|
45
|
+
workspaceId,
|
|
46
|
+
onEditingStart,
|
|
47
|
+
onContinueInChat,
|
|
48
|
+
onOpenChat,
|
|
49
|
+
onDiscard
|
|
50
|
+
}: PendingViewScreenProps) {
|
|
51
|
+
const displayStatus =
|
|
52
|
+
pendingView.status === 'submitted' ? (running ? 'building' : 'waiting') : pendingView.status
|
|
53
|
+
const sketch = useViewSketch({
|
|
54
|
+
active: active && pendingView.status === 'draft',
|
|
55
|
+
viewId: pendingView.id,
|
|
56
|
+
sessionId:
|
|
57
|
+
sketchSessionId ??
|
|
58
|
+
pendingView.executionSessionId ??
|
|
59
|
+
draftSessionId(viewTabId(pendingView.id)),
|
|
60
|
+
source: viewTabId(pendingView.id),
|
|
61
|
+
workspaceId,
|
|
62
|
+
onEditingStart,
|
|
63
|
+
onContinueInChat
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
useImperativeHandle(
|
|
67
|
+
ref,
|
|
68
|
+
() => ({
|
|
69
|
+
prepareSketchForSend: sketch.prepareForSend,
|
|
70
|
+
resetSketch: sketch.resetDocument
|
|
71
|
+
}),
|
|
72
|
+
[sketch.prepareForSend, sketch.resetDocument]
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<PendingViewScreenSketchSurface
|
|
77
|
+
active={active}
|
|
78
|
+
chatDocked={chatDocked}
|
|
79
|
+
error={pendingView.error}
|
|
80
|
+
sketch={sketch}
|
|
81
|
+
displayStatus={displayStatus}
|
|
82
|
+
onDiscard={onDiscard}
|
|
83
|
+
onOpenChat={onOpenChat}
|
|
84
|
+
/>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function PendingViewScreenStarting() {
|
|
89
|
+
return (
|
|
90
|
+
<PendingViewScreenStatusLayout>
|
|
91
|
+
<div className="flex max-w-md flex-col items-center gap-4 p-8 text-center">
|
|
92
|
+
<Spinner className="size-6 text-muted-foreground" />
|
|
93
|
+
<p className="text-sm text-muted-foreground">Starting view chat…</p>
|
|
94
|
+
</div>
|
|
95
|
+
</PendingViewScreenStatusLayout>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
type PendingViewScreenFailedProps = {
|
|
100
|
+
error?: string
|
|
101
|
+
onOpenChat: () => void
|
|
102
|
+
onDiscard: () => void
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function PendingViewScreenFailed({ error, onOpenChat, onDiscard }: PendingViewScreenFailedProps) {
|
|
106
|
+
return (
|
|
107
|
+
<PendingViewScreenStatusLayout>
|
|
108
|
+
<div className="pointer-events-auto flex max-w-md flex-col items-center gap-4 bg-radial from-background from-50% to-transparent to-75% p-8 text-center">
|
|
109
|
+
<p className="text-sm text-muted-foreground">{error}</p>
|
|
110
|
+
<Button onClick={onOpenChat}>Open chat</Button>
|
|
111
|
+
<Button variant="secondary" onClick={onDiscard}>
|
|
112
|
+
Discard view
|
|
113
|
+
</Button>
|
|
114
|
+
</div>
|
|
115
|
+
</PendingViewScreenStatusLayout>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
type PendingViewScreenSketchSurfaceProps = {
|
|
120
|
+
active: boolean
|
|
121
|
+
chatDocked: boolean
|
|
122
|
+
error?: string
|
|
123
|
+
sketch: ViewSketchController
|
|
124
|
+
displayStatus: 'draft' | 'starting' | 'building' | 'waiting' | 'failed'
|
|
125
|
+
onDiscard: () => void
|
|
126
|
+
onOpenChat: () => void
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function PendingViewScreenSketchSurface({
|
|
130
|
+
active,
|
|
131
|
+
chatDocked,
|
|
132
|
+
error,
|
|
133
|
+
sketch,
|
|
134
|
+
displayStatus,
|
|
135
|
+
onDiscard,
|
|
136
|
+
onOpenChat
|
|
137
|
+
}: PendingViewScreenSketchSurfaceProps) {
|
|
138
|
+
const draft = displayStatus === 'draft'
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<div
|
|
142
|
+
className={cn(
|
|
143
|
+
'relative min-h-0 flex-1 overflow-hidden bg-background',
|
|
144
|
+
active ? 'flex' : 'hidden'
|
|
145
|
+
)}
|
|
146
|
+
>
|
|
147
|
+
<PendingViewScreenSketchBackground chatDocked={chatDocked} sketch={sketch} draft={draft} />
|
|
148
|
+
<div
|
|
149
|
+
inert={draft ? undefined : true}
|
|
150
|
+
className={cn('absolute inset-0', !draft && 'pointer-events-none opacity-50')}
|
|
151
|
+
>
|
|
152
|
+
<DrawingLayer {...sketch.layerProps}>
|
|
153
|
+
{draft && (
|
|
154
|
+
<DrawingToolbar
|
|
155
|
+
controls={sketch.controls}
|
|
156
|
+
title="Sketch the view"
|
|
157
|
+
busy={sketch.continuing}
|
|
158
|
+
onComplete={() => void sketch.continueInChat()}
|
|
159
|
+
/>
|
|
160
|
+
)}
|
|
161
|
+
</DrawingLayer>
|
|
162
|
+
</div>
|
|
163
|
+
<div
|
|
164
|
+
aria-hidden
|
|
165
|
+
className={cn(
|
|
166
|
+
'pointer-events-none absolute inset-0 transition-shadow duration-500 ease-in-out',
|
|
167
|
+
displayStatus === 'building' &&
|
|
168
|
+
'animate-glow texture-inset-shadow-50% motion-reduce:animate-none'
|
|
169
|
+
)}
|
|
170
|
+
/>
|
|
171
|
+
{displayStatus === 'building' && (
|
|
172
|
+
<PendingViewScreenBuildingState controls={sketch.controls} />
|
|
173
|
+
)}
|
|
174
|
+
{displayStatus === 'starting' && <PendingViewScreenStarting />}
|
|
175
|
+
{displayStatus === 'waiting' && (
|
|
176
|
+
<PendingViewScreenWaitingState
|
|
177
|
+
error={error}
|
|
178
|
+
onDiscard={onDiscard}
|
|
179
|
+
onOpenChat={onOpenChat}
|
|
180
|
+
/>
|
|
181
|
+
)}
|
|
182
|
+
{displayStatus === 'failed' && (
|
|
183
|
+
<PendingViewScreenFailed error={error} onOpenChat={onOpenChat} onDiscard={onDiscard} />
|
|
184
|
+
)}
|
|
185
|
+
</div>
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
type PendingViewScreenSketchBackgroundProps = {
|
|
190
|
+
chatDocked: boolean
|
|
191
|
+
sketch: ViewSketchController
|
|
192
|
+
draft: boolean
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function PendingViewScreenSketchBackground({
|
|
196
|
+
chatDocked,
|
|
197
|
+
sketch,
|
|
198
|
+
draft
|
|
199
|
+
}: PendingViewScreenSketchBackgroundProps) {
|
|
200
|
+
const { controls, targetRef } = sketch
|
|
201
|
+
const { hasStrokes } = useDrawingHistoryState(controls)
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<div
|
|
205
|
+
ref={targetRef}
|
|
206
|
+
className="absolute inset-0 flex items-center justify-center texture-checker-20"
|
|
207
|
+
>
|
|
208
|
+
{draft && !controls.active && !hasStrokes && (
|
|
209
|
+
<div
|
|
210
|
+
className={cn(
|
|
211
|
+
'mb-4 flex h-full flex-col items-center justify-center gap-2 p-12 text-center text-sm text-muted-foreground',
|
|
212
|
+
'bg-radial from-background from-10% to-transparent',
|
|
213
|
+
chatDocked ? 'w-full' : 'mr-auto w-[calc(100%-var(--chat-max))]'
|
|
214
|
+
)}
|
|
215
|
+
>
|
|
216
|
+
<IconScribble size={56} stroke={0.5} />
|
|
217
|
+
<span className="max-w-32">Sketch how the view should look</span>
|
|
218
|
+
</div>
|
|
219
|
+
)}
|
|
220
|
+
</div>
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
type PendingViewScreenWaitingStateProps = {
|
|
225
|
+
error?: string
|
|
226
|
+
onDiscard: () => void
|
|
227
|
+
onOpenChat: () => void
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function PendingViewScreenWaitingState({
|
|
231
|
+
error,
|
|
232
|
+
onDiscard,
|
|
233
|
+
onOpenChat
|
|
234
|
+
}: PendingViewScreenWaitingStateProps) {
|
|
235
|
+
return (
|
|
236
|
+
<PendingViewScreenStatusLayout>
|
|
237
|
+
<div className="pointer-events-auto flex max-w-md flex-col items-center gap-4 bg-radial from-background from-50% to-transparent to-75% p-12 text-center">
|
|
238
|
+
<div className="flex flex-col gap-1">
|
|
239
|
+
<h1 className="font-medium">The view needs your attention</h1>
|
|
240
|
+
<p className="text-sm text-muted-foreground">
|
|
241
|
+
{error ?? 'Open the chat to answer or ask the agent to continue'}
|
|
242
|
+
</p>
|
|
243
|
+
</div>
|
|
244
|
+
<div className="flex gap-2">
|
|
245
|
+
<Button onClick={onOpenChat}>Open chat</Button>
|
|
246
|
+
<Button variant="secondary" onClick={onDiscard}>
|
|
247
|
+
Discard view
|
|
248
|
+
</Button>
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
</PendingViewScreenStatusLayout>
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
type PendingViewScreenBuildingStateProps = {
|
|
256
|
+
controls: DrawingControls
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function PendingViewScreenBuildingState({ controls }: PendingViewScreenBuildingStateProps) {
|
|
260
|
+
const { hasStrokes } = useDrawingHistoryState(controls)
|
|
261
|
+
|
|
262
|
+
return (
|
|
263
|
+
<PendingViewScreenStatusLayout>
|
|
264
|
+
{!hasStrokes && <Spinner className="size-6 text-muted-foreground" />}
|
|
265
|
+
</PendingViewScreenStatusLayout>
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
type PendingViewScreenStatusLayoutProps = {
|
|
270
|
+
children: ReactNode
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function PendingViewScreenStatusLayout({ children }: PendingViewScreenStatusLayoutProps) {
|
|
274
|
+
return (
|
|
275
|
+
<div className="pointer-events-none absolute inset-0 flex items-center justify-center">
|
|
276
|
+
{children}
|
|
277
|
+
</div>
|
|
278
|
+
)
|
|
279
|
+
}
|
|
@@ -29,7 +29,7 @@ import { AppletPresenceProvider } from '@/client/features/collab'
|
|
|
29
29
|
import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
|
|
30
30
|
import { cn } from '@/client/lib/cn'
|
|
31
31
|
import { useLatestRef } from '@/client/lib/use-latest-ref'
|
|
32
|
-
import type {
|
|
32
|
+
import type { CompiledView } from '@/lib/types'
|
|
33
33
|
|
|
34
34
|
import {
|
|
35
35
|
nextEvictionDelay,
|
|
@@ -39,10 +39,10 @@ import {
|
|
|
39
39
|
} from './view-residency'
|
|
40
40
|
|
|
41
41
|
type ViewManagerProps = {
|
|
42
|
-
views:
|
|
42
|
+
views: CompiledView[]
|
|
43
43
|
// The view the active tab names, or null when another tab is on screen. The
|
|
44
44
|
// manager stays mounted either way — that is what makes coming back from the
|
|
45
|
-
//
|
|
45
|
+
// Overview or Scratchpad tab instant too.
|
|
46
46
|
activeViewId: string | null
|
|
47
47
|
// The active view's URL query params. Parked views retain their last values.
|
|
48
48
|
params: Record<string, string>
|
|
@@ -83,7 +83,7 @@ export const ViewManager = memo(function ViewManager({
|
|
|
83
83
|
|
|
84
84
|
// The views mounted right now: the active one, plus the recently-visited ones
|
|
85
85
|
// parked offscreen. The policy (and its timing) lives in view-residency.ts.
|
|
86
|
-
function useResidentViews(activeId: string | null, views:
|
|
86
|
+
function useResidentViews(activeId: string | null, views: CompiledView[]): ResidentView[] {
|
|
87
87
|
const [residents, setResidents] = useState<ResidentView[]>([])
|
|
88
88
|
// A workspace refetch hands us a new array on every event; residency only
|
|
89
89
|
// cares whether a view appeared or disappeared. So the effect keys off the id
|
|
@@ -119,7 +119,7 @@ function useResidentViews(activeId: string | null, views: ViewInfo[]): ResidentV
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
type ViewSlotProps = {
|
|
122
|
-
view:
|
|
122
|
+
view: CompiledView
|
|
123
123
|
active: boolean
|
|
124
124
|
params: Record<string, string>
|
|
125
125
|
}
|
|
@@ -191,8 +191,8 @@ function ViewSlot({ view, active, params }: ViewSlotProps) {
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
type ViewFrameProps = {
|
|
194
|
-
view:
|
|
195
|
-
build:
|
|
194
|
+
view: CompiledView
|
|
195
|
+
build: LoadedViewVersion
|
|
196
196
|
params: Record<string, string>
|
|
197
197
|
// Play the rebuild dissolve. Set on the incoming build only, and only while
|
|
198
198
|
// the build it replaced is still rendered underneath it.
|
|
@@ -237,7 +237,7 @@ function ViewFrame({ view, build, params, entering, current = false }: ViewFrame
|
|
|
237
237
|
)
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
type
|
|
240
|
+
type LoadedViewVersion = {
|
|
241
241
|
Component: ComponentType<AppletComponentProps>
|
|
242
242
|
version: number
|
|
243
243
|
}
|
|
@@ -248,11 +248,11 @@ type LoadedBundle = {
|
|
|
248
248
|
// spinner every time the agent edits it is worse than showing the previous
|
|
249
249
|
// build for that moment. The splash is for a view with nothing to show yet —
|
|
250
250
|
// the first time it is opened.
|
|
251
|
-
current:
|
|
251
|
+
current: LoadedViewVersion | null
|
|
252
252
|
// The build `current` just replaced, kept underneath for the length of the
|
|
253
253
|
// dissolve so the new one fades in over the view instead of over an empty
|
|
254
254
|
// panel. Null except during a rebuild swap on screen.
|
|
255
|
-
outgoing:
|
|
255
|
+
outgoing: LoadedViewVersion | null
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
// How long the outgoing build stays underneath. Matches the `duration-200` the
|
|
@@ -1,117 +1,78 @@
|
|
|
1
|
+
import type { MessageAttachment, PendingView, SelectedSessionScope, ViewInfo } from '@/lib/types'
|
|
1
2
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
-
|
|
3
3
|
import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
|
|
4
4
|
import { WORKSPACE_RESOURCE_OPTIONS } from '@/client/api/query-options'
|
|
5
5
|
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
6
|
-
import { APP_ICON_IDS } from '@/client/lib/app-icon-registry'
|
|
7
6
|
import { useWorkspaceEvent } from '@/client/runtime/useWorkspaceEvents'
|
|
8
|
-
import type { MessageAttachment, SelectedSessionScope, ViewBuilder, ViewInfo } from '@/lib/types'
|
|
9
7
|
|
|
10
8
|
export function useViews(workspaceId: string) {
|
|
9
|
+
const queryClient = useQueryClient()
|
|
10
|
+
useWorkspaceEvent(event => {
|
|
11
|
+
if (
|
|
12
|
+
(event.type === 'views:changed' || event.type === 'view:deleted') &&
|
|
13
|
+
event.workspaceId === workspaceId
|
|
14
|
+
) {
|
|
15
|
+
void queryClient.invalidateQueries({ queryKey: workspaceKeys.views(workspaceId) })
|
|
16
|
+
if (event.type === 'view:deleted')
|
|
17
|
+
void queryClient.invalidateQueries({ queryKey: workspaceKeys.sessions(workspaceId) })
|
|
18
|
+
}
|
|
19
|
+
})
|
|
11
20
|
return useQuery<ViewInfo[]>({
|
|
12
21
|
queryKey: workspaceKeys.views(workspaceId),
|
|
13
|
-
queryFn: async () =>
|
|
14
|
-
|
|
15
|
-
return data.views
|
|
16
|
-
},
|
|
22
|
+
queryFn: async () =>
|
|
23
|
+
(await requestJson<{ views: ViewInfo[] }>(`/api/workspaces/${workspaceId}/views`)).views,
|
|
17
24
|
...WORKSPACE_RESOURCE_OPTIONS
|
|
18
25
|
})
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return useMutation
|
|
23
|
-
mutationFn
|
|
24
|
-
|
|
25
|
-
`/api/workspaces/${workspaceId}/views/${encodeURIComponent(viewId)}`,
|
|
26
|
-
jsonRequest('PATCH', { title }),
|
|
27
|
-
'Failed to rename view'
|
|
28
|
-
)
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function useDeleteView(workspaceId: string) {
|
|
33
|
-
return useMutation<void, Error, string>({
|
|
34
|
-
mutationFn: viewId =>
|
|
35
|
-
requestVoid(
|
|
36
|
-
`/api/workspaces/${workspaceId}/views/${encodeURIComponent(viewId)}`,
|
|
37
|
-
{ method: 'DELETE' },
|
|
38
|
-
'Failed to delete view'
|
|
39
|
-
)
|
|
27
|
+
function useViewMutation<T, Input>(workspaceId: string, mutationFn: (input: Input) => Promise<T>) {
|
|
28
|
+
const queryClient = useQueryClient()
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationFn,
|
|
31
|
+
onSuccess: () => queryClient.invalidateQueries({ queryKey: workspaceKeys.views(workspaceId) })
|
|
40
32
|
})
|
|
41
33
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
export function useRenameView(workspaceId: string) {
|
|
35
|
+
return useViewMutation(workspaceId, ({ viewId, title }: { viewId: string; title: string }) =>
|
|
36
|
+
requestJson<ViewInfo>(
|
|
37
|
+
`/api/workspaces/${workspaceId}/views/${encodeURIComponent(viewId)}`,
|
|
38
|
+
jsonRequest('PATCH', { title }),
|
|
39
|
+
'Couldn’t rename view'
|
|
40
|
+
)
|
|
49
41
|
)
|
|
50
42
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
} else if (event.type === 'view-builder:deleted' && event.workspaceId === workspaceId) {
|
|
60
|
-
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
61
|
-
(current ?? []).filter(builder => builder.id !== event.builderId)
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
return useQuery<ViewBuilder[]>({
|
|
67
|
-
queryKey: workspaceKeys.viewBuilders(workspaceId),
|
|
68
|
-
queryFn: async () => {
|
|
69
|
-
const data = await requestJson<{ builders: ViewBuilder[] }>(
|
|
70
|
-
`/api/workspaces/${workspaceId}/view-builders`
|
|
71
|
-
)
|
|
72
|
-
return data.builders
|
|
73
|
-
},
|
|
74
|
-
...WORKSPACE_RESOURCE_OPTIONS
|
|
75
|
-
})
|
|
43
|
+
export function useDeleteView(workspaceId: string) {
|
|
44
|
+
return useViewMutation(workspaceId, (viewId: string) =>
|
|
45
|
+
requestVoid(
|
|
46
|
+
`/api/workspaces/${workspaceId}/views/${encodeURIComponent(viewId)}`,
|
|
47
|
+
{ method: 'DELETE' },
|
|
48
|
+
'Couldn’t delete view'
|
|
49
|
+
)
|
|
50
|
+
)
|
|
76
51
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
'Failed to create view builder'
|
|
86
|
-
),
|
|
87
|
-
onSuccess: builder => {
|
|
88
|
-
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
89
|
-
upsertBuilder(current, builder)
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
})
|
|
52
|
+
export function useCreateView(workspaceId: string) {
|
|
53
|
+
return useViewMutation(workspaceId, () =>
|
|
54
|
+
requestJson<PendingView>(
|
|
55
|
+
`/api/workspaces/${workspaceId}/views`,
|
|
56
|
+
jsonRequest('POST'),
|
|
57
|
+
'Couldn’t create view'
|
|
58
|
+
)
|
|
59
|
+
)
|
|
93
60
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
'Failed to save view requirements'
|
|
103
|
-
),
|
|
104
|
-
onSuccess: builder => {
|
|
105
|
-
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
106
|
-
upsertBuilder(current, builder)
|
|
61
|
+
export function useSaveViewDraft(workspaceId: string) {
|
|
62
|
+
return useViewMutation(
|
|
63
|
+
workspaceId,
|
|
64
|
+
({ viewId, requirements }: { viewId: string; requirements: string }) =>
|
|
65
|
+
requestJson<PendingView>(
|
|
66
|
+
`/api/workspaces/${workspaceId}/views/${viewId}`,
|
|
67
|
+
jsonRequest('PATCH', { requirements }),
|
|
68
|
+
'Couldn’t save view requirements'
|
|
107
69
|
)
|
|
108
|
-
|
|
109
|
-
})
|
|
70
|
+
)
|
|
110
71
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
builderId: string
|
|
72
|
+
export type SubmitViewInput = {
|
|
73
|
+
viewId: string
|
|
114
74
|
requirements: string
|
|
75
|
+
sessionId: string
|
|
115
76
|
optimisticId: string
|
|
116
77
|
selectedSessionScope?: SelectedSessionScope
|
|
117
78
|
attachments?: MessageAttachment[]
|
|
@@ -120,41 +81,13 @@ export type SubmitViewBuilderInput = {
|
|
|
120
81
|
fastMode?: boolean
|
|
121
82
|
stream?: boolean
|
|
122
83
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
input: { requirements },
|
|
132
|
-
availableIcons: APP_ICON_IDS,
|
|
133
|
-
...options
|
|
134
|
-
}),
|
|
135
|
-
'Failed to start view builder'
|
|
136
|
-
),
|
|
137
|
-
onSuccess: builder => {
|
|
138
|
-
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
139
|
-
upsertBuilder(current, builder)
|
|
140
|
-
)
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function useDiscardViewBuilder(workspaceId: string) {
|
|
146
|
-
const queryClient = useQueryClient()
|
|
147
|
-
return useMutation<void, Error, string>({
|
|
148
|
-
mutationFn: builderId =>
|
|
149
|
-
requestVoid(
|
|
150
|
-
`/api/workspaces/${workspaceId}/view-builders/${builderId}`,
|
|
151
|
-
{ method: 'DELETE' },
|
|
152
|
-
'Failed to discard view builder'
|
|
153
|
-
),
|
|
154
|
-
onSuccess: (_result, builderId) => {
|
|
155
|
-
queryClient.setQueryData<ViewBuilder[]>(workspaceKeys.viewBuilders(workspaceId), current =>
|
|
156
|
-
(current ?? []).filter(builder => builder.id !== builderId)
|
|
157
|
-
)
|
|
158
|
-
}
|
|
159
|
-
})
|
|
84
|
+
export function useSubmitView(workspaceId: string) {
|
|
85
|
+
return useViewMutation(workspaceId, ({ viewId, ...input }: SubmitViewInput) =>
|
|
86
|
+
requestJson<{ viewId: string; sessionId: string }>(
|
|
87
|
+
`/api/workspaces/${workspaceId}/views/${viewId}/submit`,
|
|
88
|
+
jsonRequest('POST', input),
|
|
89
|
+
'Couldn’t start view chat'
|
|
90
|
+
)
|
|
91
|
+
)
|
|
160
92
|
}
|
|
93
|
+
export const useDiscardView = useDeleteView
|