moi-computer 0.8.1-next.0 → 0.9.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.
Files changed (103) hide show
  1. package/client/assets/hermes.png +0 -0
  2. package/client/components/shared/IconGhost.tsx +15 -18
  3. package/client/components/ui/button.tsx +2 -2
  4. package/client/components/ui/hover-card.tsx +1 -1
  5. package/client/components/ui/popover.tsx +3 -1
  6. package/client/features/chat/ChatEmptyState.tsx +25 -7
  7. package/client/features/chat/ChatPanel.tsx +70 -28
  8. package/client/features/chat/ChatPopup.tsx +3 -2
  9. package/client/features/chat/ChatPromptBubbles.tsx +1 -1
  10. package/client/features/chat/MarkdownContent.tsx +1 -1
  11. package/client/features/chat/attachment-staging.ts +153 -0
  12. package/client/features/chat/chat-send.ts +55 -0
  13. package/client/features/chat/chat-store.ts +32 -8
  14. package/client/features/chat/composer/ChatComposer.tsx +190 -77
  15. package/client/features/chat/{ModelPicker.tsx → composer/ModelPicker.tsx} +29 -25
  16. package/client/features/chat/composer/banners/ComposerBanner.tsx +1 -1
  17. package/client/features/chat/composer/banners/WorkspaceAgentAvailabilityBanner.tsx +4 -13
  18. package/client/features/chat/{model-order.ts → composer/model-order.ts} +16 -0
  19. package/client/features/chat/composer/useWorkspaceComposerState.tsx +9 -4
  20. package/client/features/chat/tool-group/format/claude.ts +48 -0
  21. package/client/features/chat/tool-group/format/codex.ts +126 -0
  22. package/client/features/chat/tool-group/format/hermes.ts +68 -0
  23. package/client/features/chat/tool-group/format/index.ts +34 -0
  24. package/client/features/chat/tool-group/format/mcp.ts +64 -0
  25. package/client/features/chat/tool-group/format/openclaw.ts +116 -0
  26. package/client/features/chat/tool-group/format/shared.ts +49 -0
  27. package/client/features/chat/useChat.ts +5 -10
  28. package/client/features/dev/ChatStatesPage.tsx +40 -2
  29. package/client/features/drawings/DrawingLayer.tsx +49 -0
  30. package/client/features/drawings/DrawingToolbar.tsx +95 -0
  31. package/client/features/drawings/annotation-availability.ts +10 -0
  32. package/client/features/drawings/capture-element.ts +45 -0
  33. package/client/features/drawings/useChatAnnotation.ts +222 -0
  34. package/client/features/drawings/useDrawingLayer.ts +758 -0
  35. package/client/features/drawings/useViewBuilderSketch.ts +151 -0
  36. package/client/features/home/workspace-presentation.tsx +6 -2
  37. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +12 -6
  38. package/client/features/scratchpad/ScratchpadControls.tsx +19 -5
  39. package/client/features/views/ViewBuilder.tsx +224 -0
  40. package/client/features/views/api.ts +1 -0
  41. package/client/features/views/useViewBuilderActions.ts +24 -3
  42. package/client/features/views/useViewBuilderDrafts.ts +66 -0
  43. package/client/features/widgets/Widgets.tsx +23 -39
  44. package/client/features/workspace/CustomizePanel.tsx +1 -1
  45. package/client/features/workspace/WorkspaceScreen.tsx +157 -57
  46. package/client/features/workspace/WorkspaceTabs.tsx +3 -3
  47. package/client/features/workspace/useFitsSplitLayout.ts +14 -8
  48. package/client/index.css +8 -0
  49. package/client/store/ui.ts +19 -0
  50. package/client/theme.css +33 -8
  51. package/dist/chunk-3becmq75.js +81 -0
  52. package/dist/{chunk-kkj86722.js → chunk-6w6j9g4b.js} +78 -78
  53. package/dist/{chunk-xeyxk7ep.js → chunk-8ew39cvq.js} +4 -4
  54. package/dist/chunk-c8gtrjwp.js +1 -0
  55. package/dist/{chunk-2vaafjp4.js → chunk-pp62fnxh.js} +1 -1
  56. package/dist/{chunk-35fq49qa.js → chunk-sxc24vfp.js} +1 -1
  57. package/dist/{chunk-xzx7c9hq.js → chunk-v964b5g7.js} +1 -1
  58. package/dist/chunk-zx33ts9d.css +1 -0
  59. package/dist/hermes-pznd63x9.png +0 -0
  60. package/dist/index.html +1 -1
  61. package/lib/format.ts +21 -7
  62. package/lib/themes.ts +8 -8
  63. package/lib/types.ts +8 -1
  64. package/lib/workspace-types.ts +2 -1
  65. package/package.json +6 -4
  66. package/server/api.ts +21 -2
  67. package/server/bundler/build-applet.ts +35 -44
  68. package/server/cli-env.ts +2 -2
  69. package/server/cli.ts +227 -56
  70. package/server/constants.ts +8 -0
  71. package/server/control-client.ts +124 -0
  72. package/server/control.ts +2 -2
  73. package/server/harness/README.md +74 -23
  74. package/server/harness/acp/adapter.ts +220 -0
  75. package/server/harness/acp/archived.ts +88 -0
  76. package/server/harness/acp/client.ts +328 -0
  77. package/server/harness/acp/discovery.ts +130 -0
  78. package/server/harness/acp/run-durations.ts +68 -0
  79. package/server/harness/acp/session.ts +788 -0
  80. package/server/harness/acp/wire.ts +132 -0
  81. package/server/harness/executable.ts +15 -1
  82. package/server/harness/hermes/NOTES.md +815 -0
  83. package/server/harness/hermes/discovery.ts +155 -0
  84. package/server/harness/hermes/index.ts +155 -0
  85. package/server/harness/hermes/models.ts +79 -0
  86. package/server/harness/openclaw/NOTES.md +196 -94
  87. package/server/harness/openclaw/adapter.ts +28 -55
  88. package/server/harness/openclaw/compat.ts +4 -8
  89. package/server/harness/openclaw/session.ts +257 -238
  90. package/server/harness/openclaw/strip.ts +10 -34
  91. package/server/harness/openclaw/thinking.ts +5 -53
  92. package/server/harness/registry.ts +3 -1
  93. package/server/service.ts +2 -2
  94. package/server/view-builders.ts +4 -2
  95. package/server/workspace-import.ts +30 -1
  96. package/workspace/.claude/skills/moi-workspace/SKILL.md +6 -6
  97. package/client/features/chat/tool-group/format.ts +0 -359
  98. package/client/features/views/ViewBuilderTab.tsx +0 -152
  99. package/dist/chunk-gny990qx.css +0 -1
  100. package/dist/chunk-gt7n06ef.js +0 -1
  101. package/dist/chunk-n7pga5x3.js +0 -80
  102. /package/workspace/.claude/skills/moi-workspace/{DESIGN.md → references/DESIGN.md} +0 -0
  103. /package/workspace/.claude/skills/moi-workspace/{SCRATCHPAD.md → references/SCRATCHPAD.md} +0 -0
@@ -0,0 +1,151 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react'
2
+
3
+ import { stageDrawing, stageDrawingDraft } from '@/client/features/chat/attachment-staging'
4
+ import { attachmentKey, liveStore } from '@/client/features/chat/chat-store'
5
+ import type { WorkspaceTabId } from '@/lib/types'
6
+
7
+ import { useDrawingLayer } from './useDrawingLayer'
8
+
9
+ type UseViewBuilderSketchOptions = {
10
+ active: boolean
11
+ builderId: string
12
+ sessionId: string
13
+ sourceTab: WorkspaceTabId
14
+ workspaceId: string
15
+ onEditingStart: () => void
16
+ onContinueInChat: () => void
17
+ }
18
+
19
+ export type ViewBuilderSketchController = ReturnType<typeof useViewBuilderSketch>
20
+
21
+ export function useViewBuilderSketch({
22
+ active,
23
+ builderId,
24
+ sessionId,
25
+ sourceTab,
26
+ workspaceId,
27
+ onEditingStart,
28
+ onContinueInChat
29
+ }: UseViewBuilderSketchOptions) {
30
+ const attachmentIdRef = useRef(`sketch:${builderId}`)
31
+ const uploadRevisionRef = useRef(0)
32
+ const uploadedBlobRef = useRef<Blob | null>(null)
33
+ const pendingStageRef = useRef<Promise<void> | null>(null)
34
+ const acceptExportsRef = useRef(true)
35
+ const [continuing, setContinuing] = useState(false)
36
+ const onEditingStartRef = useRef(onEditingStart)
37
+ const onContinueInChatRef = useRef(onContinueInChat)
38
+ onEditingStartRef.current = onEditingStart
39
+ onContinueInChatRef.current = onContinueInChat
40
+
41
+ // While drawing, every commit only refreshes the chip's local preview. The
42
+ // single upload happens when the sketching session ends: prepareForSend
43
+ // (submit) or deactivate (tab switch, continue in chat).
44
+ const change = useCallback(
45
+ (blob: Blob | null) => {
46
+ if (!acceptExportsRef.current) return
47
+ if (!blob) {
48
+ uploadRevisionRef.current += 1
49
+ uploadedBlobRef.current = null
50
+ pendingStageRef.current = null
51
+ liveStore.getState().removeAttachment(workspaceId, sessionId, attachmentIdRef.current)
52
+ return
53
+ }
54
+
55
+ stageDrawingDraft({
56
+ workspaceId,
57
+ sessionId,
58
+ localId: attachmentIdRef.current,
59
+ purpose: 'sketch',
60
+ sourceTab,
61
+ blob
62
+ })
63
+ },
64
+ [sessionId, sourceTab, workspaceId]
65
+ )
66
+
67
+ // Exports are cached per history version, so an unchanged sketch comes back
68
+ // as the same Blob instance — the identity check is what makes repeated
69
+ // deactivations free instead of re-uploading the same image. A failed
70
+ // upload removes the attachment, so "same blob but not staged" retries.
71
+ const uploadIfNeeded = useCallback(
72
+ (blob: Blob | null): Promise<void> => {
73
+ if (!blob) return pendingStageRef.current ?? Promise.resolve()
74
+ if (blob === uploadedBlobRef.current) {
75
+ const staged = liveStore
76
+ .getState()
77
+ .attachments[attachmentKey(workspaceId, sessionId)]?.some(
78
+ attachment =>
79
+ attachment.localId === attachmentIdRef.current &&
80
+ (attachment.status === 'ready' || attachment.status === 'uploading')
81
+ )
82
+ if (staged) return pendingStageRef.current ?? Promise.resolve()
83
+ }
84
+ uploadedBlobRef.current = blob
85
+ const revision = ++uploadRevisionRef.current
86
+ const pending = stageDrawing({
87
+ workspaceId,
88
+ sessionId,
89
+ localId: attachmentIdRef.current,
90
+ purpose: 'sketch',
91
+ sourceTab,
92
+ blob,
93
+ isCurrent: () => uploadRevisionRef.current === revision
94
+ })
95
+ pendingStageRef.current = pending
96
+ return pending
97
+ },
98
+ [sessionId, sourceTab, workspaceId]
99
+ )
100
+
101
+ const drawing = useDrawingLayer({
102
+ mode: 'sketch',
103
+ onChange: change,
104
+ onEditingStart: () => onEditingStartRef.current()
105
+ })
106
+ const { controls } = drawing
107
+
108
+ const prepareForSend = useCallback(async () => {
109
+ await uploadIfNeeded(await controls.flush())
110
+ }, [controls, uploadIfNeeded])
111
+
112
+ const deactivate = useCallback(async () => {
113
+ await uploadIfNeeded(await controls.deactivate())
114
+ }, [controls, uploadIfNeeded])
115
+
116
+ const continueInChat = useCallback(async () => {
117
+ if (continuing) return
118
+ setContinuing(true)
119
+ try {
120
+ await deactivate()
121
+ onContinueInChatRef.current()
122
+ } finally {
123
+ setContinuing(false)
124
+ }
125
+ }, [continuing, deactivate])
126
+
127
+ const resetDocument = useCallback(async () => {
128
+ acceptExportsRef.current = false
129
+ uploadRevisionRef.current += 1
130
+ uploadedBlobRef.current = null
131
+ pendingStageRef.current = null
132
+ liveStore.getState().removeAttachment(workspaceId, sessionId, attachmentIdRef.current)
133
+ try {
134
+ await controls.cancel()
135
+ } finally {
136
+ acceptExportsRef.current = true
137
+ }
138
+ }, [controls, sessionId, workspaceId])
139
+
140
+ useEffect(() => {
141
+ if (!active && controls.active) void deactivate()
142
+ }, [active, controls.active, deactivate])
143
+
144
+ return {
145
+ ...drawing,
146
+ continuing,
147
+ continueInChat,
148
+ prepareForSend,
149
+ resetDocument
150
+ }
151
+ }
@@ -1,4 +1,5 @@
1
1
  import claudeIcon from '@/client/assets/claude.svg'
2
+ import hermesIcon from '@/client/assets/hermes.png'
2
3
  import openaiIcon from '@/client/assets/openai.svg'
3
4
  import openclawIcon from '@/client/assets/openclaw.svg'
4
5
  import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
@@ -6,13 +7,15 @@ import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/t
6
7
  export const workspaceProviderIcon: Record<WorkspaceType, string> = {
7
8
  'claude-code': claudeIcon,
8
9
  openclaw: openclawIcon,
9
- codex: openaiIcon
10
+ codex: openaiIcon,
11
+ hermes: hermesIcon
10
12
  }
11
13
 
12
14
  export const workspaceTypeLabel: Record<WorkspaceType, string> = {
13
15
  'claude-code': 'Claude Code',
14
16
  openclaw: 'OpenClaw',
15
- codex: 'Codex'
17
+ codex: 'Codex',
18
+ hermes: 'Hermes'
16
19
  }
17
20
 
18
21
  type WorkspaceAgentIconsProps = {
@@ -42,5 +45,6 @@ export function workspaceDisplayName(workspace: WorkspaceDisplaySource): string
42
45
  if ('types' in workspace) return workspace.path.split('/').pop() || workspace.path
43
46
  if (workspace.name) return workspace.name
44
47
  if (workspace.type === 'openclaw') return workspace.agentId ?? 'OpenClaw agent'
48
+ if (workspace.type === 'hermes') return workspace.agentId ?? 'Hermes agent'
45
49
  return workspace.path.split('/').pop() || workspace.path
46
50
  }
@@ -15,13 +15,18 @@ import { WORKSPACE_TYPE_ORDER } from '@/lib/workspace-types'
15
15
  import type { HarnessAvailability, WorkspaceType } from '@/lib/types'
16
16
 
17
17
  const WORKSPACE_AGENT_DESCRIPTION = 'Choose which agent moi will use to build your workspace'
18
- const OPENCLAW_LOCKED_DESCRIPTION =
19
- 'Initialize OpenClaw in the folder\nmanually, then import it to moi'
18
+ // Backends whose workspaces belong to an agent installed on the machine: moi
19
+ // imports them (via discovery or `moi <provider> init`) and never creates one.
20
+ const IMPORT_ONLY_DESCRIPTION: Partial<Record<WorkspaceType, string>> = {
21
+ openclaw: 'Initialize OpenClaw in the folder\nmanually, then import it to moi',
22
+ hermes: 'Create a Hermes profile with\nhermes profile create, then import it'
23
+ }
20
24
 
21
25
  const workspaceAgentDescription: Record<WorkspaceType, string> = {
22
26
  'claude-code': 'Anthropic',
23
27
  codex: 'OpenAI',
24
- openclaw: 'Open-source'
28
+ openclaw: 'Open-source',
29
+ hermes: 'Nous Research'
25
30
  }
26
31
 
27
32
  export type WorkspaceAgentOption = {
@@ -43,9 +48,10 @@ export function getWorkspaceAgentOptions({
43
48
  return WORKSPACE_TYPE_ORDER.map(type => {
44
49
  const state = availability?.[type]
45
50
  const unavailableReason = state?.available === false ? state.reason : undefined
46
- const openClawReason =
47
- type === 'openclaw' && !detectedTypes.includes(type) ? OPENCLAW_LOCKED_DESCRIPTION : undefined
48
- const disabledReason = unavailableReason ?? openClawReason
51
+ const importOnlyReason = !detectedTypes.includes(type)
52
+ ? IMPORT_ONLY_DESCRIPTION[type]
53
+ : undefined
54
+ const disabledReason = unavailableReason ?? importOnlyReason
49
55
 
50
56
  return {
51
57
  type,
@@ -24,6 +24,7 @@ import {
24
24
  IconHandStop,
25
25
  IconHighlight,
26
26
  IconLine,
27
+ IconPencil,
27
28
  IconPointer2,
28
29
  IconSketching,
29
30
  IconSquare,
@@ -49,7 +50,7 @@ const TOOL_ENTRIES: ToolEntry[] = [
49
50
  { kind: 'tool', id: 'select', label: 'Select', Icon: IconPointer2 },
50
51
  { kind: 'tool', id: 'hand', label: 'Hand', Icon: IconHandStop },
51
52
  { kind: 'sep' },
52
- { kind: 'tool', id: 'draw', label: 'Pencil', Icon: IconSketching },
53
+ { kind: 'tool', id: 'draw', label: 'Pencil', Icon: IconPencil },
53
54
  { kind: 'geo', label: 'Rectangle', Icon: IconSquare },
54
55
  { kind: 'tool', id: 'note', label: 'Sticker', Icon: IconSticker2 },
55
56
  { kind: 'tool', id: 'text', label: 'Text', Icon: IconTypography },
@@ -123,13 +124,26 @@ function applyToolLocks(editor: Editor, toolId: string) {
123
124
  }
124
125
 
125
126
  // Custom vertical tool bar, rendered as an overlay over the canvas (outside
126
- // tldraw's own UI layout). Tracks the current tool reactively via `react`.
127
+ // tldraw's own UI layout). Tracks the current tool and applies the pencil cursor
128
+ // to tldraw's own container so both affordances change together.
129
+ const pencilCursorClass = '[&_.tl-canvas]:cursor-pencil'
130
+
127
131
  export function ScratchToolbar({ editor }: ScratchToolbarProps) {
128
132
  const [toolId, setToolId] = useState(() => editor.getCurrentToolId())
129
133
 
130
134
  useEffect(() => {
131
- setToolId(editor.getCurrentToolId())
132
- return react('scratch current tool', () => setToolId(editor.getCurrentToolId()))
135
+ const container = editor.getContainer()
136
+ const updateTool = () => {
137
+ const currentToolId = editor.getCurrentToolId()
138
+ setToolId(currentToolId)
139
+ container.classList.toggle(pencilCursorClass, currentToolId === 'draw')
140
+ }
141
+ updateTool()
142
+ const stopTracking = react('scratch current tool', updateTool)
143
+ return () => {
144
+ stopTracking()
145
+ container.classList.remove(pencilCursorClass)
146
+ }
133
147
  }, [editor])
134
148
 
135
149
  const activate = (toolId: string) => {
@@ -442,7 +456,7 @@ export function ScratchStyleBar({ editor }: ScratchStyleBarProps) {
442
456
  )}
443
457
  >
444
458
  {state.sizeGlyph === 'pen' ? (
445
- <IconSketching size={20} stroke={1.5} />
459
+ <IconSketching size={20} stroke={s.value === 'm' ? 1.25 : 2} />
446
460
  ) : state.sizeGlyph === 'letter' ? (
447
461
  <IconTypography size={s.glyph} stroke={s.glyph === 16 ? 1.75 : 1.5} />
448
462
  ) : (
@@ -0,0 +1,224 @@
1
+ import type { ReactNode, Ref } from 'react'
2
+ import { useImperativeHandle } from 'react'
3
+
4
+ import { Button } from '@/client/components/ui/button'
5
+ import { DrawingLayer } from '@/client/features/drawings/DrawingLayer'
6
+ import { DrawingToolbar } from '@/client/features/drawings/DrawingToolbar'
7
+ import { useDrawingHistoryState } from '@/client/features/drawings/useDrawingLayer'
8
+ import {
9
+ type ViewBuilderSketchController,
10
+ useViewBuilderSketch
11
+ } from '@/client/features/drawings/useViewBuilderSketch'
12
+ import { cn } from '@/client/lib/cn'
13
+ import type { ViewBuilder as ViewBuilderData } from '@/lib/types'
14
+ import { viewBuilderTabId } from '@/lib/workspace-tabs'
15
+ import { IconScribble } from '@tabler/icons-react'
16
+
17
+ export type ViewBuilderHandle = {
18
+ prepareSketchForSend: () => Promise<void>
19
+ resetSketch: () => Promise<void>
20
+ }
21
+
22
+ type ViewBuilderProps = {
23
+ ref?: Ref<ViewBuilderHandle>
24
+ active: boolean
25
+ builder: ViewBuilderData
26
+ chatDocked: boolean
27
+ workspaceId: string
28
+ onEditingStart: () => void
29
+ onContinueInChat: () => void
30
+ onOpenChat: () => void
31
+ onDiscard: () => void
32
+ }
33
+
34
+ export function ViewBuilder({
35
+ ref,
36
+ active,
37
+ builder,
38
+ chatDocked,
39
+ workspaceId,
40
+ onEditingStart,
41
+ onContinueInChat,
42
+ onOpenChat,
43
+ onDiscard
44
+ }: ViewBuilderProps) {
45
+ const sketch = useViewBuilderSketch({
46
+ active: active && builder.status === 'draft',
47
+ builderId: builder.id,
48
+ sessionId: builder.sessionId,
49
+ sourceTab: viewBuilderTabId(builder.id),
50
+ workspaceId,
51
+ onEditingStart,
52
+ onContinueInChat
53
+ })
54
+
55
+ useImperativeHandle(
56
+ ref,
57
+ () => ({
58
+ prepareSketchForSend: sketch.prepareForSend,
59
+ resetSketch: sketch.resetDocument
60
+ }),
61
+ [sketch.prepareForSend, sketch.resetDocument]
62
+ )
63
+
64
+ switch (builder.status) {
65
+ case 'ready':
66
+ return null
67
+ case 'draft':
68
+ case 'waiting':
69
+ case 'building':
70
+ return (
71
+ <ViewBuilderSketchSurface
72
+ active={active}
73
+ chatDocked={chatDocked}
74
+ error={builder.error}
75
+ sketch={sketch}
76
+ status={builder.status}
77
+ onDiscard={onDiscard}
78
+ onOpenChat={onOpenChat}
79
+ />
80
+ )
81
+ }
82
+ }
83
+
84
+ type ViewBuilderSketchSurfaceProps = {
85
+ active: boolean
86
+ chatDocked: boolean
87
+ error?: string
88
+ sketch: ViewBuilderSketchController
89
+ status: Exclude<ViewBuilderData['status'], 'ready'>
90
+ onDiscard: () => void
91
+ onOpenChat: () => void
92
+ }
93
+
94
+ function ViewBuilderSketchSurface({
95
+ active,
96
+ chatDocked,
97
+ error,
98
+ sketch,
99
+ status,
100
+ onDiscard,
101
+ onOpenChat
102
+ }: ViewBuilderSketchSurfaceProps) {
103
+ const draft = status === 'draft'
104
+
105
+ return (
106
+ <div
107
+ className={cn(
108
+ 'relative min-h-0 flex-1 overflow-hidden bg-background',
109
+ active ? 'flex' : 'hidden'
110
+ )}
111
+ >
112
+ {draft && <ViewBuilderDraftState chatDocked={chatDocked} sketch={sketch} />}
113
+ <div
114
+ inert={draft ? undefined : true}
115
+ className={cn(
116
+ 'absolute inset-0',
117
+ status === 'building' && 'pointer-events-none opacity-50',
118
+ status === 'waiting' && 'invisible'
119
+ )}
120
+ >
121
+ <DrawingLayer {...sketch.layerProps}>
122
+ {draft && (
123
+ <DrawingToolbar
124
+ controls={sketch.controls}
125
+ title="Sketch the view"
126
+ busy={sketch.continuing}
127
+ onComplete={() => void sketch.continueInChat()}
128
+ />
129
+ )}
130
+ </DrawingLayer>
131
+ </div>
132
+ <div
133
+ aria-hidden
134
+ className={cn(
135
+ 'pointer-events-none absolute inset-0 transition-shadow duration-500 ease-in-out',
136
+ status === 'building' &&
137
+ 'animate-glow texture-inset-shadow-50% motion-reduce:animate-none'
138
+ )}
139
+ />
140
+ {status === 'building' && <ViewBuilderBuildingState />}
141
+ {status === 'waiting' && (
142
+ <ViewBuilderWaitingState error={error} onDiscard={onDiscard} onOpenChat={onOpenChat} />
143
+ )}
144
+ </div>
145
+ )
146
+ }
147
+
148
+ type ViewBuilderDraftStateProps = {
149
+ chatDocked: boolean
150
+ sketch: ViewBuilderSketchController
151
+ }
152
+
153
+ function ViewBuilderDraftState({ chatDocked, sketch }: ViewBuilderDraftStateProps) {
154
+ const { hasStrokes } = useDrawingHistoryState(sketch.controls)
155
+
156
+ return (
157
+ <div
158
+ ref={sketch.targetRef}
159
+ className="absolute inset-0 flex items-center justify-center texture-checker-20"
160
+ >
161
+ {!sketch.controls.active && !hasStrokes && (
162
+ <div
163
+ className={cn(
164
+ 'mb-4 flex h-full flex-col items-center justify-center gap-2 p-12 text-center text-sm text-muted-foreground',
165
+ 'bg-radial from-background from-10% to-transparent',
166
+ chatDocked ? 'w-full' : 'mr-auto w-[calc(100%-var(--chat-max))]'
167
+ )}
168
+ >
169
+ <IconScribble size={56} stroke={0.5} />
170
+ <span className="max-w-32">Sketch how the view should look</span>
171
+ </div>
172
+ )}
173
+ </div>
174
+ )
175
+ }
176
+
177
+ type ViewBuilderWaitingStateProps = {
178
+ error?: string
179
+ onDiscard: () => void
180
+ onOpenChat: () => void
181
+ }
182
+
183
+ function ViewBuilderWaitingState({ error, onDiscard, onOpenChat }: ViewBuilderWaitingStateProps) {
184
+ return (
185
+ <ViewBuilderStatusLayout>
186
+ <div className="flex max-w-md flex-col items-center gap-4 bg-radial from-background from-50% to-transparent to-75% p-12 text-center">
187
+ <div className="flex flex-col gap-1">
188
+ <h1 className="font-medium">The view needs your attention</h1>
189
+ <p className="text-sm text-muted-foreground">
190
+ {error ?? 'Open the chat to answer or ask the agent to continue'}
191
+ </p>
192
+ </div>
193
+ <div className="flex gap-2">
194
+ <Button onClick={onOpenChat}>Open chat</Button>
195
+ <Button variant="secondary" onClick={onDiscard}>
196
+ Discard view
197
+ </Button>
198
+ </div>
199
+ </div>
200
+ </ViewBuilderStatusLayout>
201
+ )
202
+ }
203
+
204
+ function ViewBuilderBuildingState() {
205
+ return <ViewBuilderStatusLayout />
206
+ }
207
+
208
+ type ViewBuilderStatusLayoutProps = {
209
+ children?: ReactNode
210
+ className?: string
211
+ }
212
+
213
+ function ViewBuilderStatusLayout({ children, className }: ViewBuilderStatusLayoutProps) {
214
+ return (
215
+ <div
216
+ className={cn(
217
+ 'relative flex min-h-0 flex-1 items-center justify-center texture-checker-20',
218
+ className
219
+ )}
220
+ >
221
+ {children}
222
+ </div>
223
+ )
224
+ }
@@ -80,6 +80,7 @@ export type SubmitViewBuilderInput = {
80
80
  builderId: string
81
81
  requirements: string
82
82
  optimisticId: string
83
+ attachments?: string[]
83
84
  model?: string
84
85
  effort?: string
85
86
  fastMode?: boolean
@@ -1,6 +1,12 @@
1
1
  import { useQueryClient } from '@tanstack/react-query'
2
2
 
3
- import { resolveChatRunOptions, startOptimisticTurn } from '@/client/features/chat/chat-send'
3
+ import {
4
+ attachmentPartsForOptimisticTurn,
5
+ attachmentsForSend,
6
+ resolveChatRunOptions,
7
+ startOptimisticSession,
8
+ startOptimisticTurn
9
+ } from '@/client/features/chat/chat-send'
4
10
  import { liveStore } from '@/client/features/chat/chat-store'
5
11
  import { useSelectedSession } from '@/client/features/chat/useSelectedSession'
6
12
  import { useWorkspaceAgent } from '@/client/features/workspace/api'
@@ -30,13 +36,24 @@ export function useViewBuilderActions() {
30
36
 
31
37
  const submit = async (builder: ViewBuilder, requirements: string) => {
32
38
  const text = requirements.trim()
33
- if (!text) return
39
+ const attachments = attachmentsForSend(workspaceId, builder.sessionId)
40
+ if (!text && attachments.length === 0) return
41
+
42
+ startOptimisticSession({
43
+ queryClient,
44
+ workspaceId,
45
+ sessionId: builder.sessionId,
46
+ text,
47
+ filenames: attachments.map(attachment => attachment.name)
48
+ })
49
+ const parts = attachmentPartsForOptimisticTurn(attachments)
50
+ if (text) parts.push({ type: 'text', text })
34
51
 
35
52
  const optimisticId = startOptimisticTurn({
36
53
  queryClient,
37
54
  workspaceId,
38
55
  sessionId: builder.sessionId,
39
- parts: [{ type: 'text', text }]
56
+ parts
40
57
  })
41
58
  selectSession(builder.sessionId)
42
59
 
@@ -52,11 +69,15 @@ export function useViewBuilderActions() {
52
69
  builderId: builder.id,
53
70
  requirements: text,
54
71
  optimisticId,
72
+ ...(attachments.length > 0
73
+ ? { attachments: attachments.map(attachment => attachment.upload!.id) }
74
+ : {}),
55
75
  model,
56
76
  effort,
57
77
  fastMode,
58
78
  stream
59
79
  })
80
+ liveStore.getState().clearAttachments(workspaceId, builder.sessionId)
60
81
  } catch (error) {
61
82
  liveStore.getState().setActivity(workspaceId, builder.sessionId, 'idle')
62
83
  liveStore
@@ -0,0 +1,66 @@
1
+ import { useCallback, useEffect, useRef } from 'react'
2
+
3
+ import { toast } from '@/client/components/ui/toast'
4
+ import { useUiStore } from '@/client/store/ui'
5
+ import type { ViewBuilder } from '@/lib/types'
6
+
7
+ type UseViewBuilderDraftsOptions = {
8
+ builders: ViewBuilder[]
9
+ onSave: (builderId: string, requirements: string) => Promise<unknown>
10
+ }
11
+
12
+ // Builder draft text lives in the UI store and is subscribed from the
13
+ // composer, so a keystroke re-renders only the composer — never the workspace
14
+ // screen with its tab bar, widgets, mounted views, and builder canvases. This
15
+ // hook owns the writes: the store update, the debounced server save, and the
16
+ // cleanup when a builder leaves its draft state.
17
+ export function useViewBuilderDrafts({ builders, onSave }: UseViewBuilderDraftsOptions) {
18
+ const timersRef = useRef(new Map<string, ReturnType<typeof setTimeout>>())
19
+ const buildersRef = useRef(builders)
20
+ const onSaveRef = useRef(onSave)
21
+ buildersRef.current = builders
22
+ onSaveRef.current = onSave
23
+
24
+ const clear = useCallback((builderId: string) => {
25
+ const timer = timersRef.current.get(builderId)
26
+ if (timer) clearTimeout(timer)
27
+ timersRef.current.delete(builderId)
28
+ useUiStore.getState().setViewBuilderDraft(builderId, null)
29
+ }, [])
30
+
31
+ const change = useCallback((builderId: string, value: string) => {
32
+ useUiStore.getState().setViewBuilderDraft(builderId, value)
33
+ const existing = timersRef.current.get(builderId)
34
+ if (existing) clearTimeout(existing)
35
+ timersRef.current.set(
36
+ builderId,
37
+ setTimeout(() => {
38
+ timersRef.current.delete(builderId)
39
+ const builder = buildersRef.current.find(candidate => candidate.id === builderId)
40
+ if (!builder || builder.status !== 'draft') return
41
+ void onSaveRef.current(builderId, value).catch(() => {
42
+ toast.add({ title: 'Couldn’t save view description', type: 'error' })
43
+ })
44
+ }, 500)
45
+ )
46
+ }, [])
47
+
48
+ // Drop drafts for builders that left draft status through any path (submit
49
+ // from another surface, server-side transition). Builders absent from the
50
+ // list are cleared by the explicit discard/close paths, not here — the
51
+ // store outlives this screen and may hold other workspaces' drafts.
52
+ useEffect(() => {
53
+ for (const builder of builders) {
54
+ if (builder.status !== 'draft') clear(builder.id)
55
+ }
56
+ }, [builders, clear])
57
+
58
+ useEffect(
59
+ () => () => {
60
+ for (const timer of timersRef.current.values()) clearTimeout(timer)
61
+ },
62
+ []
63
+ )
64
+
65
+ return { change, clear }
66
+ }