moi-computer 0.9.0 → 0.9.1-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/client/api/app-config.ts +51 -0
  2. package/client/api/workspace-keys.ts +1 -0
  3. package/client/app/routes/WorkspaceRoute.tsx +4 -2
  4. package/client/assets/hermes.png +0 -0
  5. package/client/components/shared/IconGhost.tsx +15 -18
  6. package/client/components/ui/button.tsx +2 -2
  7. package/client/components/ui/hover-card.tsx +1 -1
  8. package/client/components/ui/popover.tsx +3 -1
  9. package/client/features/applets/api.ts +38 -0
  10. package/client/features/applets/applet-thumbnail.ts +208 -0
  11. package/client/features/chat/ChatEmptyState.tsx +30 -10
  12. package/client/features/chat/ChatPanel.tsx +67 -31
  13. package/client/features/chat/ChatPopup.tsx +3 -2
  14. package/client/features/chat/ChatPromptBubbles.tsx +1 -1
  15. package/client/features/chat/ChatSelector.tsx +29 -10
  16. package/client/features/chat/MarkdownContent.tsx +3 -3
  17. package/client/features/chat/attachment-staging.ts +153 -0
  18. package/client/features/chat/chat-send.ts +55 -0
  19. package/client/features/chat/chat-store.ts +32 -8
  20. package/client/features/chat/composer/ChatComposer.tsx +190 -77
  21. package/client/features/chat/{ModelPicker.tsx → composer/ModelPicker.tsx} +29 -25
  22. package/client/features/chat/composer/banners/ComposerBanner.tsx +1 -1
  23. package/client/features/chat/composer/banners/WorkspaceAgentAvailabilityBanner.tsx +4 -13
  24. package/client/features/chat/{model-order.ts → composer/model-order.ts} +16 -0
  25. package/client/features/chat/composer/useWorkspaceComposerState.tsx +9 -4
  26. package/client/features/chat/tool-group/format/claude.ts +48 -0
  27. package/client/features/chat/tool-group/format/codex.ts +126 -0
  28. package/client/features/chat/tool-group/format/hermes.ts +68 -0
  29. package/client/features/chat/tool-group/format/index.ts +34 -0
  30. package/client/features/chat/tool-group/format/mcp.ts +64 -0
  31. package/client/features/chat/tool-group/format/openclaw.ts +116 -0
  32. package/client/features/chat/tool-group/format/shared.ts +49 -0
  33. package/client/features/chat/useChat.ts +5 -10
  34. package/client/features/drawings/DrawingLayer.tsx +49 -0
  35. package/client/features/drawings/DrawingToolbar.tsx +95 -0
  36. package/client/features/drawings/capture-element.ts +45 -0
  37. package/client/features/drawings/useChatAnnotation.ts +222 -0
  38. package/client/features/drawings/useDrawingLayer.ts +758 -0
  39. package/client/features/drawings/useViewBuilderSketch.ts +151 -0
  40. package/client/features/home/HomePage.tsx +13 -0
  41. package/client/features/home/WorkspacePreview.tsx +10 -5
  42. package/client/features/home/workspace-presentation.tsx +6 -2
  43. package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +9 -0
  44. package/client/features/home/workspace-setup/InstallMoiDialog.tsx +245 -0
  45. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +13 -7
  46. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +1 -1
  47. package/client/features/scratchpad/ScratchpadControls.tsx +19 -5
  48. package/client/features/views/ViewBuilder.tsx +238 -0
  49. package/client/features/views/ViewManager.tsx +18 -2
  50. package/client/features/views/api.ts +1 -0
  51. package/client/features/views/useViewBuilderActions.ts +24 -3
  52. package/client/features/views/useViewBuilderDrafts.ts +66 -0
  53. package/client/features/widgets/WidgetFrame.tsx +1 -1
  54. package/client/features/widgets/WidgetGrid.tsx +1 -1
  55. package/client/features/widgets/Widgets.tsx +39 -54
  56. package/client/features/workspace/CustomizePanel.tsx +30 -9
  57. package/client/features/workspace/WorkspaceScreen.tsx +158 -64
  58. package/client/features/workspace/WorkspaceTabs.tsx +3 -3
  59. package/client/features/workspace/useFitsSplitLayout.ts +14 -8
  60. package/client/index.css +8 -0
  61. package/client/index.tsx +6 -1
  62. package/client/runtime/useWorkspaceEvents.ts +17 -0
  63. package/client/runtime/workspace-theme.ts +29 -6
  64. package/client/store/ui.ts +19 -0
  65. package/client/theme.css +33 -8
  66. package/dist/chunk-5c19v3zr.js +10 -0
  67. package/dist/chunk-6wx91x8j.js +1 -0
  68. package/dist/chunk-8s41nd3g.js +1 -0
  69. package/dist/{chunk-kkj86722.js → chunk-a7fzp0z0.js} +78 -78
  70. package/dist/{chunk-2vaafjp4.js → chunk-b959mdkj.js} +1 -1
  71. package/dist/chunk-cagtq45k.js +1 -0
  72. package/dist/chunk-cva7jpt4.js +82 -0
  73. package/dist/chunk-sapvd7he.css +1 -0
  74. package/dist/{chunk-35fq49qa.js → chunk-zbeq02yc.js} +1 -1
  75. package/dist/chunk-zbt8emsw.js +2 -0
  76. package/dist/chunk-zfz3b4xg.js +2 -0
  77. package/dist/hermes-pznd63x9.png +0 -0
  78. package/dist/index.html +1 -1
  79. package/lib/format.ts +1 -1
  80. package/lib/themes.ts +8 -8
  81. package/lib/types.ts +68 -42
  82. package/lib/workspace-types.ts +2 -1
  83. package/package.json +2 -1
  84. package/server/api.ts +90 -33
  85. package/server/app-config.ts +144 -0
  86. package/server/applets.ts +17 -0
  87. package/server/cli.ts +235 -14
  88. package/server/harness/README.md +64 -17
  89. package/server/harness/acp/adapter.ts +220 -0
  90. package/server/harness/acp/archived.ts +88 -0
  91. package/server/harness/acp/client.ts +328 -0
  92. package/server/harness/acp/discovery.ts +130 -0
  93. package/server/harness/acp/run-durations.ts +68 -0
  94. package/server/harness/acp/session.ts +788 -0
  95. package/server/harness/acp/wire.ts +132 -0
  96. package/server/harness/executable.ts +15 -1
  97. package/server/harness/hermes/NOTES.md +815 -0
  98. package/server/harness/hermes/discovery.ts +155 -0
  99. package/server/harness/hermes/index.ts +155 -0
  100. package/server/harness/hermes/models.ts +79 -0
  101. package/server/harness/registry.ts +3 -1
  102. package/server/layout.ts +40 -45
  103. package/server/moi-scaffold.ts +37 -1
  104. package/server/thumbnails.ts +197 -0
  105. package/server/view-builders.ts +4 -2
  106. package/server/views.ts +10 -1
  107. package/server/widgets.ts +4 -18
  108. package/server/workspace-import.ts +30 -1
  109. package/workspace/.claude/skills/moi-workspace/SKILL.md +13 -1
  110. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +153 -253
  111. package/client/features/chat/tool-group/format.ts +0 -384
  112. package/client/features/views/ViewBuilderTab.tsx +0 -152
  113. package/client/features/widgets/api.ts +0 -47
  114. package/client/features/widgets/useWidgetThumbnails.ts +0 -107
  115. package/client/features/widgets/widget-snapshot.ts +0 -71
  116. package/dist/chunk-3b3rkjet.js +0 -1
  117. package/dist/chunk-gt7n06ef.js +0 -1
  118. package/dist/chunk-ty1sqbmn.js +0 -80
  119. package/dist/chunk-xeyxk7ep.js +0 -10
  120. package/dist/chunk-yz6wd5vc.css +0 -1
@@ -17,7 +17,7 @@ import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
17
17
  import type { SystemNotice, Turn, ViewState } from '@/lib/types'
18
18
 
19
19
  import type { ComposerBanner } from './composer/banners/ComposerBanner'
20
- import { ChatComposer } from './composer/ChatComposer'
20
+ import { ChatComposer, type ComposerAnnotationControls } from './composer/ChatComposer'
21
21
  import { ChatEmptyState, resolveChatEmptyState } from './ChatEmptyState'
22
22
  import { ChatSelector } from './ChatSelector'
23
23
  import { ThinkingIndicator, TurnView } from './TurnView'
@@ -26,6 +26,18 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/
26
26
  import { cn } from '@/client/lib/cn'
27
27
  import { useUiStore } from '@/client/store/ui'
28
28
 
29
+ export type ViewBuilderChatDraft = {
30
+ sessionId: string
31
+ builderId: string
32
+ // Server-saved requirements the composer falls back to; the live draft text
33
+ // is subscribed from the UI store by builder id inside ChatComposer, so
34
+ // typing never re-renders this panel or the screen hosting it.
35
+ initialValue: string
36
+ onChange: (value: string) => void
37
+ onRemoveDrawing: (localId: string) => void
38
+ onSubmit: (value: string) => Promise<void>
39
+ }
40
+
29
41
  type ChatPanelProps = {
30
42
  active?: boolean
31
43
  focusRequest?: number
@@ -42,13 +54,17 @@ type ChatPanelProps = {
42
54
  processing: boolean
43
55
  composerBanner?: ComposerBanner
44
56
  composerAvailability: ComposerAvailability
57
+ annotation?: ComposerAnnotationControls
45
58
  send: (text: string, options?: ChatSendOptions) => void
46
59
  stop: () => void
47
- onSelectSession: (sessionId: string | null) => void
48
60
  // Chat on a separate tab doesn't have a close button
49
61
  onClose?: () => void
62
+ builderDraft?: ViewBuilderChatDraft
50
63
  }
51
64
 
65
+ const EMPTY_TURNS: Turn[] = []
66
+ const EMPTY_NOTICES: SystemNotice[] = []
67
+
52
68
  export function ChatPanel({
53
69
  active = true,
54
70
  focusRequest = 0,
@@ -60,21 +76,24 @@ export function ChatPanel({
60
76
  processing,
61
77
  composerBanner,
62
78
  composerAvailability,
79
+ annotation,
63
80
  send,
64
81
  stop,
65
- onSelectSession,
66
- onClose
82
+ onClose,
83
+ builderDraft
67
84
  }: ChatPanelProps) {
68
85
  const workspaceId = useWorkspaceId()
69
86
  const composerRef = useRef<HTMLTextAreaElement>(null)
70
87
  const scrollRef = useRef<HTMLDivElement>(null)
71
- const turns = view.turns
88
+ const effectiveSessionId = builderDraft?.sessionId ?? sessionId ?? null
89
+ const modelSessionId = builderDraft ? null : (sessionId ?? null)
90
+ const turns = builderDraft ? EMPTY_TURNS : view.turns
72
91
  const hasSentMessageFromMoi = useUiStore(state => state.hasSentMessageFromMoi)
73
92
  const isWorkspacePendingAnalysis = useUiStore(state =>
74
93
  (state.workspaceIdsPendingAnalysis ?? []).includes(workspaceId)
75
94
  )
76
95
  const attachmentsUploading = useLive(state =>
77
- (state.attachments[attachmentKey(workspaceId, sessionId ?? null)] ?? []).some(
96
+ (state.attachments[attachmentKey(workspaceId, effectiveSessionId)] ?? []).some(
78
97
  attachment => attachment.status === 'uploading'
79
98
  )
80
99
  )
@@ -85,30 +104,32 @@ export function ChatPanel({
85
104
  // inter-turn gap between every tool call. See `dev/turn-spacing.md`.
86
105
  // The live preview turn is appended before grouping, so a thinking-only
87
106
  // preview merges into the trailing tool group exactly like its finalized form.
107
+ const effectivePreviewTurn = builderDraft ? null : previewTurn
108
+ const notices = builderDraft ? EMPTY_NOTICES : view.notices
88
109
  const groupedTurns = useMemo(
89
- () => groupTurns(previewTurn ? [...turns, previewTurn] : turns),
90
- [turns, previewTurn]
110
+ () => groupTurns(effectivePreviewTurn ? [...turns, effectivePreviewTurn] : turns),
111
+ [turns, effectivePreviewTurn]
91
112
  )
92
113
  // Grouped turns plus the renderable notices (compaction, model changes)
93
114
  // woven in at the moment they happened. Interleaving runs AFTER grouping so
94
115
  // a notice never splits a tool-only run apart.
95
- const timeline = useMemo(
96
- () => interleaveNotices(groupedTurns, view.notices),
97
- [groupedTurns, view.notices]
98
- )
116
+ const timeline = useMemo(() => interleaveNotices(groupedTurns, notices), [groupedTurns, notices])
99
117
  const lastTurnId = groupedTurns.length > 0 ? groupedTurns[groupedTurns.length - 1].id : null
100
- const showEmptyChat = chatLoaded && timeline.length === 0 && !processing
118
+ const effectiveProcessing = builderDraft ? false : processing
119
+ const showEmptyState =
120
+ !!builderDraft || (chatLoaded && timeline.length === 0 && !effectiveProcessing)
101
121
  const emptyStateKind = resolveChatEmptyState({
122
+ isViewBuilderDraft: !!builderDraft,
102
123
  hasSentMessageFromMoi,
103
124
  isWorkspacePendingAnalysis
104
125
  })
105
126
 
106
127
  // Stick to the bottom while pinned; respect scroll-up; jump on session switch.
107
- const { atBottom, scrollToBottom, scrollToTop } = useStickToBottom(scrollRef, sessionId)
128
+ const { atBottom, scrollToBottom, scrollToTop } = useStickToBottom(scrollRef, effectiveSessionId)
108
129
 
109
130
  useLayoutEffect(() => {
110
- if (showEmptyChat && emptyStateKind !== 'empty') scrollToTop()
111
- }, [showEmptyChat, emptyStateKind, scrollToTop])
131
+ if (showEmptyState && emptyStateKind !== 'empty') scrollToTop()
132
+ }, [showEmptyState, emptyStateKind, scrollToTop])
112
133
 
113
134
  // The active chat surface owns initial focus. A monotonically increasing
114
135
  // request also refocuses an already-visible composer after intent actions.
@@ -119,11 +140,12 @@ export function ChatPanel({
119
140
  // Sending always returns the user to the bottom, even if they'd scrolled up —
120
141
  // they expect to see their message and the reply.
121
142
  const handleSend = useCallback(
122
- (text: string, options?: ChatSendOptions) => {
123
- send(text, options)
143
+ async (text: string, options?: ChatSendOptions) => {
144
+ if (builderDraft) await builderDraft.onSubmit(text)
145
+ else send(text, options)
124
146
  scrollToBottom()
125
147
  },
126
- [send, scrollToBottom]
148
+ [builderDraft, send, scrollToBottom]
127
149
  )
128
150
 
129
151
  const handlePromptSelect = useCallback(
@@ -137,7 +159,7 @@ export function ChatPanel({
137
159
  return (
138
160
  <div className="flex min-h-0 flex-1 flex-col pt-2 pb-3">
139
161
  <header className="mx-auto flex w-full max-w-[calc(var(--chat-max-container)+40px)] items-center justify-between pr-2 pb-2 pl-2">
140
- <ChatSelector selectedSessionId={sessionId ?? null} onSelectSession={onSelectSession} />
162
+ <ChatSelector isViewBuilder={!!builderDraft} />
141
163
  {onClose && docked && (
142
164
  <Tooltip>
143
165
  <TooltipTrigger
@@ -150,7 +172,7 @@ export function ChatPanel({
150
172
  <TooltipContent>Undock agent</TooltipContent>
151
173
  </Tooltip>
152
174
  )}
153
- {onClose && !docked && (
175
+ {!builderDraft && onClose && !docked && (
154
176
  <Button variant="ghost" size="icon-sm" onClick={onClose} aria-label="Close chat">
155
177
  <IconX stroke={2} />
156
178
  </Button>
@@ -160,10 +182,10 @@ export function ChatPanel({
160
182
  <div className="relative flex min-h-0 flex-1 flex-col">
161
183
  <div
162
184
  ref={scrollRef}
163
- className="flex scrollbar-thin flex-1 scroll-fade flex-col overflow-y-auto overscroll-contain px-5 pt-4 pb-12 [--scroll-fade-reveal:8px]"
185
+ className="flex scrollbar-thin flex-1 scroll-fade flex-col overflow-y-auto overscroll-contain px-5 pt-4 pb-8 [--scroll-fade-reveal:8px]"
164
186
  >
165
- <div className="mx-auto flex w-full max-w-(--chat-max-container) flex-1 flex-col items-center gap-6">
166
- {showEmptyChat && (
187
+ <div className="mx-auto flex w-full max-w-(--chat-max-container) flex-1 flex-col gap-6">
188
+ {showEmptyState && (
167
189
  <ChatEmptyState
168
190
  kind={emptyStateKind}
169
191
  disabled={promptDisabled}
@@ -177,13 +199,13 @@ export function ChatPanel({
177
199
  <TurnView
178
200
  key={item.turn.id}
179
201
  turn={item.turn}
180
- processing={processing && item.turn.id === lastTurnId}
202
+ processing={effectiveProcessing && item.turn.id === lastTurnId}
181
203
  />
182
204
  )
183
205
  )}
184
206
  {/* Pulsing dots only before the first token — once the preview has
185
207
  visible content it renders as a (possibly merged) grouped turn. */}
186
- {processing && !previewTurn && <ThinkingIndicator />}
208
+ {effectiveProcessing && !effectivePreviewTurn && <ThinkingIndicator />}
187
209
  </div>
188
210
  </div>
189
211
 
@@ -207,9 +229,9 @@ export function ChatPanel({
207
229
  <div
208
230
  className={cn(
209
231
  '@container flex w-full flex-col transition-[padding]',
210
- composerBanner && 'gap-2 rounded-t-xl rounded-b-2xl p-2',
211
- composerBanner?.tone === 'muted' && 'bg-muted',
212
- composerBanner?.tone === 'destructive' && 'bg-destructive/10'
232
+ composerBanner && 'gap-2 rounded-t-lg rounded-b-2xl p-2',
233
+ composerBanner?.tone === 'default' && 'bg-accent',
234
+ composerBanner?.tone === 'error' && 'bg-destructive/10'
213
235
  )}
214
236
  >
215
237
  {composerBanner?.content}
@@ -217,9 +239,23 @@ export function ChatPanel({
217
239
  composerRef={composerRef}
218
240
  onSend={handleSend}
219
241
  onStop={stop}
220
- processing={processing}
221
- sessionId={sessionId ?? null}
242
+ processing={effectiveProcessing}
243
+ sessionId={effectiveSessionId}
244
+ modelSessionId={modelSessionId}
222
245
  availability={composerAvailability}
246
+ annotation={builderDraft ? undefined : annotation}
247
+ onRemoveDrawing={builderDraft?.onRemoveDrawing ?? annotation?.onRemove}
248
+ allowFiles={!builderDraft}
249
+ placeholder={builderDraft ? 'Drop in the details' : undefined}
250
+ draft={
251
+ builderDraft
252
+ ? {
253
+ id: builderDraft.builderId,
254
+ initialValue: builderDraft.initialValue,
255
+ onChange: builderDraft.onChange
256
+ }
257
+ : undefined
258
+ }
223
259
  />
224
260
  </div>
225
261
  </div>
@@ -39,6 +39,8 @@ export function ChatPopup({
39
39
  onOpenChange={handleOpenChange}
40
40
  onOpenChangeComplete={onOpenChangeComplete}
41
41
  >
42
+ {/* Floating over a themed workspace — use the card pair so it stays
43
+ legible regardless of the active theme background. */}
42
44
  <PopoverTrigger
43
45
  render={
44
46
  <div className="fixed right-4 bottom-4 sm:right-6 sm:bottom-6">
@@ -52,8 +54,6 @@ export function ChatPopup({
52
54
  animate={open ? 'invisible' : 'to'}
53
55
  transition={{ type: 'spring', duration: 0.3, delay: 0.2, bounce: 0 }}
54
56
  >
55
- {/* Floating over a themed workspace — use the card pair so it
56
- stays legible regardless of the active theme background. */}
57
57
  <Button
58
58
  variant="outline"
59
59
  size="icon-lg"
@@ -67,6 +67,7 @@ export function ChatPopup({
67
67
  }
68
68
  />
69
69
  <PopoverContent
70
+ positionMethod="fixed"
70
71
  side="top"
71
72
  sideOffset={-48}
72
73
  align="end"
@@ -36,7 +36,7 @@ export function ChatPromptBubble({
36
36
  className
37
37
  )}
38
38
  >
39
- <Icon stroke={2} aria-hidden className="mt-0.5 text-muted-foreground" />
39
+ <Icon stroke={2} aria-hidden className="mt-0.5" />
40
40
  <span>{prompt.label}</span>
41
41
  </Button>
42
42
  )
@@ -4,6 +4,7 @@ import { IconArchive, IconChevronDown, IconEdit } from '@tabler/icons-react'
4
4
  import { useArchiveWorkspaceSession, useWorkspaceSessions } from './api'
5
5
  import { useWorkspaceAgent } from '@/client/features/workspace/api'
6
6
  import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
7
+ import { useSelectedSession } from '@/client/features/chat/useSelectedSession'
7
8
  import { cn } from '@/client/lib/cn'
8
9
  import {
9
10
  hasRunningBackgroundSession,
@@ -28,8 +29,11 @@ import {
28
29
  import { Spinner } from '@/client/components/ui/spinner'
29
30
 
30
31
  type ChatSelectorProps = {
31
- onSelectSession: (sessionId: string | null) => void
32
- selectedSessionId: string | null
32
+ isViewBuilder?: boolean
33
+ }
34
+
35
+ type ChatHeaderLabelProps = {
36
+ label: string
33
37
  }
34
38
 
35
39
  type ChatSessionGroup = {
@@ -38,6 +42,10 @@ type ChatSessionGroup = {
38
42
  sessions: SessionInfo[]
39
43
  }
40
44
 
45
+ function ChatHeaderLabel({ label }: ChatHeaderLabelProps) {
46
+ return <div className="flex h-7 items-center px-2.5 text-sm font-medium">{label}</div>
47
+ }
48
+
41
49
  // One tiny text badge per row at most: a cron/subagent flavor wins; otherwise
42
50
  // an external origin shows its provider lowercase (e.g. "irc", "telegram").
43
51
  // Plain app chats get none.
@@ -231,8 +239,18 @@ export function groupSessionsByDate(sessions: SessionInfo[], now = new Date()):
231
239
  return [...groups.values()]
232
240
  }
233
241
 
234
- export function ChatSelector({ onSelectSession, selectedSessionId }: ChatSelectorProps) {
242
+ export function ChatSelector({ isViewBuilder = false }: ChatSelectorProps) {
243
+ if (isViewBuilder) {
244
+ return <ChatHeaderLabel label="Build a new view" />
245
+ }
246
+
247
+ return <SessionSelector />
248
+ }
249
+
250
+ function SessionSelector() {
235
251
  const workspaceId = useWorkspaceId()
252
+ const [selectedSession, selectSession] = useSelectedSession()
253
+ const selectedSessionId = selectedSession ?? null
236
254
  const [confirmingSessionId, setConfirmingSessionId] = useState<string | null>(null)
237
255
  const { data: sessions = [] } = useWorkspaceSessions(workspaceId)
238
256
  const canArchive = useWorkspaceAgent(workspaceId).data?.supportsArchiving === true
@@ -240,14 +258,15 @@ export function ChatSelector({ onSelectSession, selectedSessionId }: ChatSelecto
240
258
  const hasRunningBackgroundChat = useLive(state =>
241
259
  hasRunningBackgroundSession(state.activity, workspaceId, selectedSessionId)
242
260
  )
261
+
262
+ if (sessions.length === 0) {
263
+ return <ChatHeaderLabel label="New chat" />
264
+ }
265
+
243
266
  const active = sessions.find(s => s.sessionId === selectedSessionId)
244
267
  const label = active?.summary ?? 'New chat'
245
268
  const sessionGroups = groupSessionsByDate(sessions)
246
269
 
247
- function handleSelect(sessionId: string | null) {
248
- onSelectSession(sessionId)
249
- }
250
-
251
270
  function handleMenuOpenChange(open: boolean) {
252
271
  if (!open) setConfirmingSessionId(null)
253
272
  }
@@ -259,7 +278,7 @@ export function ChatSelector({ onSelectSession, selectedSessionId }: ChatSelecto
259
278
  store.clearAttachments(workspaceId, sessionId)
260
279
  store.clearPreviewsForSession(workspaceId, sessionId)
261
280
  if (selectedSessionId === sessionId) {
262
- onSelectSession(null)
281
+ selectSession(null)
263
282
  }
264
283
  }
265
284
 
@@ -286,7 +305,7 @@ export function ChatSelector({ onSelectSession, selectedSessionId }: ChatSelecto
286
305
  >
287
306
  <DropdownMenuItem
288
307
  className="shrink-0 gap-1 font-medium text-muted-foreground! **:text-muted-foreground!"
289
- onClick={() => handleSelect(null)}
308
+ onClick={() => selectSession(null)}
290
309
  >
291
310
  <IconEdit size={16} stroke={1.75} />
292
311
  New chat
@@ -305,7 +324,7 @@ export function ChatSelector({ onSelectSession, selectedSessionId }: ChatSelecto
305
324
  active={selectedSessionId === session.sessionId}
306
325
  canArchive={canArchive}
307
326
  confirmingArchive={confirmingSessionId === session.sessionId}
308
- onSelect={handleSelect}
327
+ onSelect={selectSession}
309
328
  onArchive={handleArchive}
310
329
  onRequestArchive={setConfirmingSessionId}
311
330
  workspaceId={workspaceId}
@@ -1,6 +1,6 @@
1
1
  import type { ComponentProps } from 'react'
2
2
 
3
- import ReactMarkdown from 'react-markdown'
3
+ import ReactMarkdown, { type ExtraProps } from 'react-markdown'
4
4
  import rehypeHighlight from 'rehype-highlight'
5
5
  import remarkGfm from 'remark-gfm'
6
6
 
@@ -10,7 +10,7 @@ const remarkPlugins = [remarkGfm]
10
10
  const rehypePlugins = [rehypeHighlight]
11
11
 
12
12
  const components = {
13
- code({ className, children, ...props }: ComponentProps<'code'>) {
13
+ code({ node: _node, className, children, ...props }: ComponentProps<'code'> & ExtraProps) {
14
14
  return (
15
15
  <code
16
16
  className={cn(
@@ -25,7 +25,7 @@ const components = {
25
25
  },
26
26
  pre({ children }: ComponentProps<'pre'>) {
27
27
  return (
28
- <div className="not-prose my-2 rounded-lg border border-border bg-[color-mix(var(--foreground)_5%,transparent)] px-3 py-2.5">
28
+ <div className="not-prose my-2 rounded-lg border border-border bg-accent px-3 py-2.5">
29
29
  <pre className="overflow-auto font-mono text-xs leading-relaxed whitespace-pre text-foreground [&>code]:rounded-none [&>code]:bg-transparent [&>code]:p-0">
30
30
  {children}
31
31
  </pre>
@@ -0,0 +1,153 @@
1
+ import type { WorkspaceTabId } from '@/lib/types'
2
+
3
+ import { attachmentKey, type ChatAttachment, type DrawingPurpose, liveStore } from './chat-store'
4
+ import { uploadFiles } from './uploads'
5
+
6
+ type ComposerTarget = {
7
+ workspaceId: string
8
+ sessionId: string | null
9
+ }
10
+
11
+ export function stageComposerFiles(
12
+ { workspaceId, sessionId }: ComposerTarget,
13
+ files: File[]
14
+ ): void {
15
+ if (files.length === 0) return
16
+
17
+ const items: ChatAttachment[] = files.map(file => ({
18
+ kind: 'file',
19
+ localId: crypto.randomUUID(),
20
+ name: file.name || 'file',
21
+ mediaType: file.type || 'application/octet-stream',
22
+ previewUrl: file.type.startsWith('image/') ? URL.createObjectURL(file) : undefined,
23
+ status: 'uploading'
24
+ }))
25
+ liveStore.getState().addAttachments(workspaceId, sessionId, items)
26
+
27
+ items.forEach((item, index) => {
28
+ uploadFiles(workspaceId, [files[index]])
29
+ .then(([upload]) => {
30
+ liveStore.getState().updateAttachment(workspaceId, sessionId, item.localId, {
31
+ status: 'ready',
32
+ upload,
33
+ mediaType: upload.mediaType
34
+ })
35
+ })
36
+ .catch((error: unknown) => {
37
+ liveStore.getState().updateAttachment(workspaceId, sessionId, item.localId, {
38
+ status: 'error',
39
+ error: error instanceof Error ? error.message : 'Upload failed'
40
+ })
41
+ })
42
+ })
43
+ }
44
+
45
+ type StageDrawingDraftInput = ComposerTarget & {
46
+ localId: string
47
+ purpose: DrawingPurpose
48
+ sourceTab: WorkspaceTabId
49
+ blob: Blob
50
+ }
51
+
52
+ // Local-only staging while the user is still drawing: the chip shows the
53
+ // latest composite as its preview, but nothing is uploaded until the drawing
54
+ // session ends (stageDrawing).
55
+ export function stageDrawingDraft({
56
+ workspaceId,
57
+ sessionId,
58
+ localId,
59
+ purpose,
60
+ sourceTab,
61
+ blob
62
+ }: StageDrawingDraftInput): void {
63
+ const label = purpose === 'sketch' ? 'Sketch' : 'Annotation'
64
+ const previewUrl = URL.createObjectURL(blob)
65
+ const store = liveStore.getState()
66
+ const existing = store.attachments[attachmentKey(workspaceId, sessionId)]?.some(
67
+ attachment => attachment.localId === localId
68
+ )
69
+
70
+ if (existing) {
71
+ store.updateAttachment(workspaceId, sessionId, localId, {
72
+ previewUrl,
73
+ status: 'draft',
74
+ upload: undefined,
75
+ error: undefined
76
+ })
77
+ } else {
78
+ store.addAttachments(workspaceId, sessionId, [
79
+ {
80
+ kind: 'drawing',
81
+ purpose,
82
+ localId,
83
+ sourceTab,
84
+ name: `${label}.png`,
85
+ mediaType: 'image/png',
86
+ previewUrl,
87
+ status: 'draft'
88
+ }
89
+ ])
90
+ }
91
+ }
92
+
93
+ type StageDrawingInput = StageDrawingDraftInput & {
94
+ isCurrent: () => boolean
95
+ }
96
+
97
+ // Upload a drawing once its editing session ends (finish, send, or an
98
+ // implicit cancel that keeps the attachment). `isCurrent` guards the result:
99
+ // a stale upload must not resurrect an attachment the user has removed.
100
+ export async function stageDrawing({
101
+ workspaceId,
102
+ sessionId,
103
+ localId,
104
+ purpose,
105
+ sourceTab,
106
+ blob,
107
+ isCurrent
108
+ }: StageDrawingInput): Promise<void> {
109
+ const label = purpose === 'sketch' ? 'Sketch' : 'Annotation'
110
+ const previewUrl = URL.createObjectURL(blob)
111
+ const store = liveStore.getState()
112
+ const existing = store.attachments[attachmentKey(workspaceId, sessionId)]?.some(
113
+ attachment => attachment.localId === localId
114
+ )
115
+
116
+ if (existing) {
117
+ store.updateAttachment(workspaceId, sessionId, localId, {
118
+ previewUrl,
119
+ status: 'uploading',
120
+ upload: undefined,
121
+ error: undefined
122
+ })
123
+ } else {
124
+ store.addAttachments(workspaceId, sessionId, [
125
+ {
126
+ kind: 'drawing',
127
+ purpose,
128
+ localId,
129
+ sourceTab,
130
+ name: `${label}.png`,
131
+ mediaType: 'image/png',
132
+ previewUrl,
133
+ status: 'uploading'
134
+ }
135
+ ])
136
+ }
137
+
138
+ try {
139
+ const [upload] = await uploadFiles(workspaceId, [
140
+ new File([blob], `${label}.png`, { type: 'image/png' })
141
+ ])
142
+ if (!isCurrent()) return
143
+ liveStore.getState().updateAttachment(workspaceId, sessionId, localId, {
144
+ status: 'ready',
145
+ upload,
146
+ mediaType: upload.mediaType,
147
+ error: undefined
148
+ })
149
+ } catch {
150
+ if (!isCurrent()) return
151
+ liveStore.getState().removeAttachment(workspaceId, sessionId, localId)
152
+ }
153
+ }
@@ -32,6 +32,61 @@ export function attachmentsForSend(
32
32
  return pending.filter(a => a.status === 'ready' && a.upload)
33
33
  }
34
34
 
35
+ export function attachmentPartsForOptimisticTurn(attachments: readonly ChatAttachment[]): Part[] {
36
+ return attachments.map(attachment => {
37
+ if (attachment.upload?.kind === 'image' && attachment.previewUrl) {
38
+ return {
39
+ type: 'file',
40
+ mediaType: attachment.mediaType,
41
+ url: attachment.previewUrl,
42
+ filename: attachment.name
43
+ }
44
+ }
45
+ return {
46
+ type: 'file',
47
+ mediaType: attachment.mediaType,
48
+ url: '',
49
+ filename: attachment.name
50
+ }
51
+ })
52
+ }
53
+
54
+ export function withAttachmentDirectives(
55
+ options: ChatSendOptions | undefined,
56
+ attachments: readonly ChatAttachment[]
57
+ ): ChatSendOptions | undefined {
58
+ if (!ownsComposerAttachments(options)) return options
59
+ const annotations: string[] = []
60
+ const sketches: string[] = []
61
+ let imagePosition = 0
62
+ for (const attachment of attachments) {
63
+ if (attachment.upload?.kind !== 'image') continue
64
+ imagePosition += 1
65
+ if (attachment.kind === 'drawing' && attachment.purpose === 'annotation') {
66
+ annotations.push(`${imagePosition}. ${JSON.stringify(attachment.sourceTab)}`)
67
+ }
68
+ if (attachment.kind === 'drawing' && attachment.purpose === 'sketch') {
69
+ sketches.push(`${imagePosition}. ${JSON.stringify(attachment.sourceTab)}`)
70
+ }
71
+ }
72
+ if (annotations.length === 0 && sketches.length === 0) return options
73
+
74
+ const directives = [...(options?.directives ?? [])]
75
+ if (annotations.length > 0) {
76
+ directives.push(`Annotation attachment sources in attachment order: ${annotations.join('; ')}.`)
77
+ }
78
+ if (sketches.length > 0) {
79
+ directives.push(
80
+ `Sketch attachment sources in attachment order: ${sketches.join('; ')}. Each sketch shows the intended layout of a new view.`
81
+ )
82
+ }
83
+
84
+ return {
85
+ ...options,
86
+ directives
87
+ }
88
+ }
89
+
35
90
  type StartOptimisticTurnInput = {
36
91
  queryClient: QueryClient
37
92
  workspaceId: string
@@ -1,22 +1,42 @@
1
1
  import { useStore } from 'zustand'
2
2
  import { createStore } from 'zustand/vanilla'
3
3
 
4
- import type { PreviewBlock, PreviewFrame, SessionActivity, UploadInfo } from '@/lib/types'
4
+ import type {
5
+ PreviewBlock,
6
+ PreviewFrame,
7
+ SessionActivity,
8
+ UploadInfo,
9
+ WorkspaceTabId
10
+ } from '@/lib/types'
5
11
 
6
- // One composer attachment, tracked per session until the message is sent. It is
7
- // uploaded as soon as it's added (drop/paste/pick); `status` reflects that
8
- // in-flight upload, and `upload` holds the server handle once ready. `previewUrl`
9
- // is a local object URL for image thumbnails (revoked on remove/clear).
10
- export type ChatAttachment = {
12
+ // One composer attachment, tracked per session until the message is sent. A
13
+ // file uploads as soon as it's added (drop/paste/pick); an annotation stays a
14
+ // local `draft` while it's being drawn and uploads once when the drawing
15
+ // session ends. `status` reflects that lifecycle, and `upload` holds the server
16
+ // handle once ready. `previewUrl` is a local object URL for image thumbnails
17
+ // (revoked on remove/clear).
18
+ type ChatAttachmentBase = {
11
19
  localId: string
12
20
  name: string
13
21
  mediaType: string
14
22
  previewUrl?: string
15
- status: 'uploading' | 'ready' | 'error'
23
+ status: 'draft' | 'uploading' | 'ready' | 'error'
16
24
  upload?: UploadInfo
17
25
  error?: string
18
26
  }
19
27
 
28
+ export type DrawingPurpose = 'annotation' | 'sketch'
29
+
30
+ export type ChatAttachment = ChatAttachmentBase &
31
+ (
32
+ | { kind: 'file'; purpose?: never; sourceTab?: never }
33
+ | { kind: 'drawing'; purpose: DrawingPurpose; sourceTab: WorkspaceTabId }
34
+ )
35
+
36
+ type ChatAttachmentPatch = Partial<
37
+ Pick<ChatAttachmentBase, 'name' | 'mediaType' | 'previewUrl' | 'status' | 'upload' | 'error'>
38
+ >
39
+
20
40
  // App-level ephemeral chat state — the bits that are *pushed* from the server
21
41
  // over the WebSocket and can't be re-fetched as request/response data:
22
42
  // - per-session `activity` (spinner) state,
@@ -114,7 +134,7 @@ export type LiveStore = {
114
134
  workspaceId: string,
115
135
  sessionId: string | null,
116
136
  localId: string,
117
- patch: Partial<ChatAttachment>
137
+ patch: ChatAttachmentPatch
118
138
  ) => void
119
139
  removeAttachment: (workspaceId: string, sessionId: string | null, localId: string) => void
120
140
  clearAttachments: (workspaceId: string, sessionId: string | null) => void
@@ -207,6 +227,10 @@ export const liveStore = createStore<LiveStore>()(set => ({
207
227
  const k = attachmentKey(workspaceId, sessionId)
208
228
  const list = s.attachments[k]
209
229
  if (!list) return {}
230
+ const target = list.find(attachment => attachment.localId === localId)
231
+ if (target?.previewUrl && 'previewUrl' in patch && patch.previewUrl !== target.previewUrl) {
232
+ URL.revokeObjectURL(target.previewUrl)
233
+ }
210
234
  return {
211
235
  attachments: {
212
236
  ...s.attachments,