moi-computer 0.11.1-next.2 → 0.11.1-next.3

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 (222) hide show
  1. package/README.md +2 -2
  2. package/client/app/AppRouter.tsx +2 -2
  3. package/client/app/routes/WorkspaceRoute.tsx +7 -9
  4. package/client/app/shell/SidebarLayout.tsx +18 -15
  5. package/client/components/shared/BottomPanel.tsx +26 -14
  6. package/client/components/shared/PanelHeader.tsx +1 -1
  7. package/client/components/shared/ReorderableList.tsx +7 -2
  8. package/client/components/shared/WorkspaceIcon.tsx +92 -0
  9. package/client/components/ui/alert-dialog.tsx +1 -0
  10. package/client/components/ui/checkbox.tsx +1 -0
  11. package/client/components/ui/inline-input.tsx +84 -0
  12. package/client/components/ui/toast.tsx +2 -2
  13. package/client/features/applets/AppletMount.tsx +1 -1
  14. package/client/features/applets/applet-cache.ts +3 -3
  15. package/client/features/applets/applet-runtime.ts +147 -108
  16. package/client/features/applets/applet-styles.ts +2 -2
  17. package/client/features/applets/applet-thumbnail.ts +6 -8
  18. package/client/features/applets/useApplet.ts +10 -9
  19. package/client/features/chat/ChatPanel.tsx +19 -10
  20. package/client/features/chat/ChatPopup.tsx +7 -2
  21. package/client/features/chat/applet-chat-intents.ts +170 -0
  22. package/client/features/chat/chat-send.ts +103 -62
  23. package/client/features/chat/chat-store.ts +50 -59
  24. package/client/features/chat/composer/ChatComposer.tsx +43 -132
  25. package/client/features/chat/composer/ModelPicker.tsx +1 -1
  26. package/client/features/chat/composer/attachments/AttachmentChip.tsx +99 -0
  27. package/client/features/chat/composer/attachments/DrawingAttachmentChip.tsx +37 -0
  28. package/client/features/chat/composer/attachments/FileAttachmentChip.tsx +22 -0
  29. package/client/features/chat/composer/attachments/TextAttachmentChip.tsx +11 -0
  30. package/client/features/chat/composer/attachments/draft-attachments.ts +168 -0
  31. package/client/features/chat/composer/attachments/types.ts +25 -0
  32. package/client/features/chat/composer/attachments/uploads.ts +26 -0
  33. package/client/features/chat/{chat-connection.ts → connection/chat-connection.ts} +1 -1
  34. package/client/features/chat/{chat-frames.ts → connection/chat-frames.ts} +2 -2
  35. package/client/features/chat/{ChatEmptyState.tsx → messages/ChatEmptyState.tsx} +16 -11
  36. package/client/features/chat/{MarkdownContent.tsx → messages/MarkdownContent.tsx} +16 -1
  37. package/client/features/chat/{TurnView.tsx → messages/TurnView.tsx} +22 -15
  38. package/client/features/chat/{tool-group → messages/tool-group}/SubagentCard.tsx +1 -1
  39. package/client/features/chat/{tool-group → messages/tool-group}/TimelineRow.tsx +2 -2
  40. package/client/features/chat/{tool-group → messages/tool-group}/ToolCallGroup.tsx +1 -1
  41. package/client/features/chat/{ChatSelector.tsx → sessions/ChatSelector.tsx} +3 -3
  42. package/client/features/chat/{api.ts → sessions/api.ts} +1 -1
  43. package/client/features/chat/useChat.ts +32 -15
  44. package/client/features/dev/ChatStatesPage.tsx +5 -6
  45. package/client/features/dev/HarnessDebugPage.tsx +10 -7
  46. package/client/features/dev/ToolCallsPage.tsx +1 -1
  47. package/client/features/dev/UiComponentPreviews.tsx +21 -0
  48. package/client/features/dev/chat-states-fixtures.ts +13 -2
  49. package/client/features/drawings/useChatAnnotation.ts +17 -17
  50. package/client/features/drawings/useDrawingLayer.ts +7 -9
  51. package/client/features/drawings/useViewBuilderSketch.ts +18 -15
  52. package/client/features/home/HomePage.tsx +8 -7
  53. package/client/features/home/WorkspacePreview.tsx +1 -1
  54. package/client/features/home/workspace-presentation.tsx +1 -11
  55. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +2 -4
  56. package/client/features/overview/HiddenPanel.tsx +109 -0
  57. package/client/features/overview/Overview.tsx +302 -0
  58. package/client/features/overview/WidgetCanvas.tsx +164 -0
  59. package/client/features/{widgets → overview}/WidgetFrame.tsx +24 -16
  60. package/client/features/overview/WorkspaceName.tsx +60 -0
  61. package/client/features/overview/api.ts +30 -0
  62. package/client/features/overview/default/ViewsWidget.tsx +252 -0
  63. package/client/features/overview/default/registry.tsx +36 -0
  64. package/client/features/{widgets → overview}/grid.ts +36 -0
  65. package/client/features/overview/useGridReconcile.ts +94 -0
  66. package/client/features/scratchpad/Scratchpad.tsx +7 -8
  67. package/client/features/scratchpad/ScratchpadControls.tsx +0 -1
  68. package/client/features/scratchpad/useScratchpadSnapshot.tsx +23 -13
  69. package/client/features/settings/GeneralSettings.tsx +55 -58
  70. package/client/features/settings/SettingsLayout.tsx +2 -2
  71. package/client/features/settings/WorkspaceIconPicker.tsx +318 -0
  72. package/client/features/settings/WorkspaceSettingsDialog.tsx +65 -0
  73. package/client/features/settings/api.ts +48 -24
  74. package/client/features/views/ViewBuilder.tsx +5 -4
  75. package/client/features/views/ViewManager.tsx +11 -13
  76. package/client/features/views/api.ts +36 -2
  77. package/client/features/views/useViewBuilderActions.ts +8 -5
  78. package/client/features/views/useViewBuilderDrafts.ts +23 -21
  79. package/client/features/views/view-presentation.ts +13 -0
  80. package/client/features/workspace/{CustomizePanel.tsx → ThemePanel.tsx} +26 -31
  81. package/client/features/workspace/UnavailablePage.tsx +21 -0
  82. package/client/features/workspace/WorkspaceLayoutContext.tsx +4 -7
  83. package/client/features/workspace/WorkspaceScreen.tsx +205 -161
  84. package/client/features/workspace/WorkspaceSplitLayout.tsx +1 -1
  85. package/client/features/workspace/WorkspaceTabs.tsx +2 -0
  86. package/client/features/workspace/api.ts +0 -26
  87. package/client/features/workspace/moi-context.ts +8 -9
  88. package/client/features/workspace/tab-resolution.ts +10 -33
  89. package/client/features/workspace/useWorkspaceNavigation.ts +164 -101
  90. package/client/index.css +1 -1
  91. package/client/lib/app-icon-registry.ts +2 -0
  92. package/client/lib/use-latest-ref.ts +11 -0
  93. package/client/main.tsx +1 -1
  94. package/client/runtime/useWorkspaceEvents.ts +59 -14
  95. package/client/theme.css +5 -5
  96. package/dist/chunk-1pp135b4.js +1 -0
  97. package/dist/chunk-2gs8jjx4.css +1 -0
  98. package/dist/chunk-94m3q9ce.js +1 -0
  99. package/dist/chunk-azkjzc7a.js +68 -0
  100. package/dist/{chunk-w482ew2c.js → chunk-brr0zbeh.js} +73 -73
  101. package/dist/chunk-m1fvqssh.js +2 -0
  102. package/dist/chunk-p34hvqt3.js +1 -0
  103. package/dist/{chunk-4s15axjs.js → chunk-p83f0jnj.js} +2 -2
  104. package/dist/{chunk-j3wvxjr7.js → chunk-tzz101ea.js} +1 -1
  105. package/dist/chunk-xg01f6pn.js +10 -0
  106. package/dist/{chunk-53a7pxcz.js → chunk-zs4mte79.js} +1 -1
  107. package/dist/index.html +1 -1
  108. package/lib/app-icons.ts +1 -0
  109. package/lib/applet-selector.ts +24 -0
  110. package/lib/chat-title.ts +6 -1
  111. package/lib/default-widgets.ts +32 -0
  112. package/lib/format.ts +12 -1
  113. package/lib/message-attachments.ts +40 -0
  114. package/lib/moi-attachments.ts +204 -0
  115. package/lib/moi-context.ts +20 -35
  116. package/lib/navigation.ts +84 -0
  117. package/lib/types.ts +79 -24
  118. package/lib/workspace-icon.ts +20 -0
  119. package/lib/workspace-layout.ts +22 -2
  120. package/lib/workspace-tabs.ts +9 -33
  121. package/package.json +27 -27
  122. package/registry.json +13 -0
  123. package/server/AGENTS.md +1 -0
  124. package/server/api.ts +114 -37
  125. package/server/applet-typecheck.ts +95 -0
  126. package/server/{bundler → applets}/build-applet.ts +13 -246
  127. package/server/applets/config.ts +226 -0
  128. package/server/applets/dependencies.ts +206 -0
  129. package/server/{applets.ts → applets/index.ts} +15 -161
  130. package/server/applets/runtime/base.ts +4 -0
  131. package/server/applets/runtime/moi.ts +42 -0
  132. package/server/applets/runtime/rpc.ts +17 -0
  133. package/server/applets/view-source.ts +67 -0
  134. package/server/attachment-message.ts +95 -0
  135. package/server/cli.ts +163 -97
  136. package/server/control.ts +63 -42
  137. package/server/harness/README.md +4 -2
  138. package/server/harness/acp/adapter.ts +7 -21
  139. package/server/harness/acp/session.ts +31 -50
  140. package/server/harness/claude-code/NOTES.md +8 -2
  141. package/server/harness/claude-code/adapter.ts +8 -25
  142. package/server/harness/claude-code/index.ts +2 -0
  143. package/server/harness/claude-code/session.ts +42 -47
  144. package/server/harness/claude-code/sessions.ts +9 -4
  145. package/server/harness/codex/adapter.ts +8 -7
  146. package/server/harness/codex/index.ts +1 -0
  147. package/server/harness/codex/permissions.ts +1 -1
  148. package/server/harness/codex/session.ts +20 -47
  149. package/server/harness/hermes/NOTES.md +1 -1
  150. package/server/harness/hermes/index.ts +4 -0
  151. package/server/harness/openclaw/NOTES.md +1 -1
  152. package/server/harness/openclaw/adapter.ts +22 -4
  153. package/server/harness/openclaw/gateway.ts +5 -3
  154. package/server/harness/openclaw/session.ts +27 -27
  155. package/server/harness/types.ts +5 -3
  156. package/server/layout.ts +9 -14
  157. package/server/moi-scaffold.ts +21 -13
  158. package/server/navigation-relay.ts +110 -0
  159. package/server/registry.ts +8 -0
  160. package/server/selected-session.ts +24 -4
  161. package/server/skill-update.ts +5 -3
  162. package/server/skill-version.ts +4 -7
  163. package/server/skills-template.ts +48 -9
  164. package/server/tabs.ts +19 -33
  165. package/server/uploads.ts +0 -0
  166. package/server/view-builders.ts +18 -1
  167. package/server/views.ts +126 -6
  168. package/server/web.ts +35 -9
  169. package/server/widgets.ts +12 -5
  170. package/server/workspace-config.ts +13 -9
  171. package/ui-components/button.tsx +2 -2
  172. package/ui-components/docs/kbd.md +191 -0
  173. package/ui-components/dropdown-menu.tsx +1 -1
  174. package/ui-components/kbd.tsx +32 -0
  175. package/ui-components/slider.tsx +1 -1
  176. package/ui-components/switch.tsx +1 -1
  177. package/ui-components/tabs.tsx +1 -1
  178. package/workspace/.claude/skills/moi-workspace/SKILL.md +284 -228
  179. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +100 -153
  180. package/workspace/.claude/skills/moi-workspace/references/INTENTS.md +156 -0
  181. package/client/features/chat/attachment-staging.ts +0 -153
  182. package/client/features/chat/uploads.ts +0 -18
  183. package/client/features/chat/useAppletChatMessage.ts +0 -68
  184. package/client/features/settings/IconPicker.tsx +0 -442
  185. package/client/features/settings/WorkspaceSettings.tsx +0 -95
  186. package/client/features/settings/render-icon.ts +0 -173
  187. package/client/features/widgets/HiddenPanel.tsx +0 -80
  188. package/client/features/widgets/WidgetGrid.tsx +0 -123
  189. package/client/features/widgets/Widgets.tsx +0 -262
  190. package/client/features/widgets/useGridReconcile.ts +0 -73
  191. package/dist/chunk-245wt82v.css +0 -1
  192. package/dist/chunk-87thzbtw.js +0 -2
  193. package/dist/chunk-a6jad1a6.js +0 -1
  194. package/dist/chunk-dghwstd2.js +0 -9
  195. package/dist/chunk-eg120aca.js +0 -1
  196. package/dist/chunk-j7hh2ab4.js +0 -70
  197. package/dist/chunk-y8eyahwx.js +0 -1
  198. /package/client/features/chat/{ChatPromptBubbles.tsx → messages/ChatPromptBubbles.tsx} +0 -0
  199. /package/client/features/chat/{ShimmerText.tsx → messages/ShimmerText.tsx} +0 -0
  200. /package/client/features/chat/{group-turns.ts → messages/group-turns.ts} +0 -0
  201. /package/client/features/chat/{interleave-notices.ts → messages/interleave-notices.ts} +0 -0
  202. /package/client/features/chat/{preview-turn.ts → messages/preview-turn.ts} +0 -0
  203. /package/client/features/chat/{tool-group → messages/tool-group}/CodeBlock.tsx +0 -0
  204. /package/client/features/chat/{tool-group → messages/tool-group}/Collapse.tsx +0 -0
  205. /package/client/features/chat/{tool-group → messages/tool-group}/ReadImagePreview.tsx +0 -0
  206. /package/client/features/chat/{tool-group → messages/tool-group}/ToolOutput.tsx +0 -0
  207. /package/client/features/chat/{tool-group → messages/tool-group}/detect.ts +0 -0
  208. /package/client/features/chat/{tool-group → messages/tool-group}/fixtures.ts +0 -0
  209. /package/client/features/chat/{tool-group → messages/tool-group}/format/claude.ts +0 -0
  210. /package/client/features/chat/{tool-group → messages/tool-group}/format/codex.ts +0 -0
  211. /package/client/features/chat/{tool-group → messages/tool-group}/format/hermes.ts +0 -0
  212. /package/client/features/chat/{tool-group → messages/tool-group}/format/index.ts +0 -0
  213. /package/client/features/chat/{tool-group → messages/tool-group}/format/mcp.ts +0 -0
  214. /package/client/features/chat/{tool-group → messages/tool-group}/format/openclaw.ts +0 -0
  215. /package/client/features/chat/{tool-group → messages/tool-group}/format/shared.ts +0 -0
  216. /package/client/features/chat/{tool-group → messages/tool-group}/format/shell.ts +0 -0
  217. /package/client/features/chat/{tool-group → messages/tool-group}/index.ts +0 -0
  218. /package/client/features/chat/{useStickToBottom.ts → messages/useStickToBottom.ts} +0 -0
  219. /package/client/features/chat/{session-view.ts → sessions/session-view.ts} +0 -0
  220. /package/client/features/chat/{useSelectedSession.ts → sessions/useSelectedSession.ts} +0 -0
  221. /package/server/{bundler → applets}/applet-css.ts +0 -0
  222. /package/server/{bundler → applets}/build-worker.ts +0 -0
@@ -1,13 +1,9 @@
1
+ import { TextAttachmentChip } from './attachments/TextAttachmentChip'
2
+ import { DrawingAttachmentChip } from './attachments/DrawingAttachmentChip'
3
+ import { FileAttachmentChip } from './attachments/FileAttachmentChip'
1
4
  import { type RefObject, useRef, useState } from 'react'
2
5
 
3
- import {
4
- IconFile,
5
- IconLoader2,
6
- IconPaperclip,
7
- IconPlayerStopFilled,
8
- IconScribble,
9
- IconX
10
- } from '@tabler/icons-react'
6
+ import { IconPaperclip, IconPlayerStopFilled, IconScribble } from '@tabler/icons-react'
11
7
 
12
8
  import {
13
9
  canSubmitComposerAction,
@@ -17,18 +13,14 @@ import {
17
13
  ComposerTextarea
18
14
  } from '@/client/components/shared/Composer'
19
15
  import { Button } from '@/client/components/ui/button'
20
- import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/client/components/ui/hover-card'
21
16
  import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
22
- import { stageComposerFiles } from '@/client/features/chat/attachment-staging'
17
+ import { stageComposerFiles } from '@/client/features/chat/composer/attachments/draft-attachments'
23
18
  import { cn } from '@/client/lib/cn'
24
19
  import type { AgentAvailability } from '@/client/lib/agent-availability'
25
20
  import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
26
- import {
27
- type ChatAttachment,
28
- attachmentKey,
29
- liveStore,
30
- useLive
31
- } from '@/client/features/chat/chat-store'
21
+ import { useLatestRef } from '@/client/lib/use-latest-ref'
22
+ import { attachmentKey, liveStore, useLive } from '@/client/features/chat/chat-store'
23
+ import type { StagedAttachment } from '@/client/features/chat/composer/attachments/types'
32
24
  import { useUiStore } from '@/client/store/ui'
33
25
 
34
26
  import { ModelPicker } from './ModelPicker'
@@ -87,15 +79,16 @@ export function ChatComposer({
87
79
  const workspaceDraft = useUiStore(s => s.composerDrafts[workspaceId] ?? '')
88
80
  const builderDraft = useUiStore(s => (draft ? (s.viewBuilderDrafts ?? {})[draft.id] : undefined))
89
81
  const value = draft ? (builderDraft ?? draft.initialValue) : workspaceDraft
90
- const valueRef = useRef(value)
91
- valueRef.current = value
82
+ const valueRef = useLatestRef(value)
92
83
  const attachments = useLive(s => s.attachments[attachmentKey(workspaceId, sessionId)] ?? EMPTY)
93
84
  const [dragOver, setDragOver] = useState(false)
94
85
 
95
- const uploading = attachments.some(a => a.status === 'uploading')
86
+ const uploading = attachments.some(a => a.kind !== 'text' && a.status === 'uploading')
96
87
  // A draft annotation counts as sendable content: send() finishes the drawing
97
88
  // first, which uploads it before the message goes out.
98
- const hasSendable = attachments.some(a => a.status === 'ready' || a.status === 'draft')
89
+ const hasSendable = attachments.some(
90
+ a => a.kind === 'text' || a.status === 'ready' || a.status === 'draft'
91
+ )
99
92
  const hasContent = value.trim().length > 0 || hasSendable
100
93
  const canSend = canSubmitComposerAction(hasContent, uploading, availability)
101
94
 
@@ -114,12 +107,12 @@ export function ChatComposer({
114
107
  // upload isn't lost.
115
108
  const sendingRef = useRef(false)
116
109
 
117
- const removeAttachment = (attachment: ChatAttachment) => {
110
+ const removeAttachment = (attachment: StagedAttachment) => {
118
111
  if (attachment.kind === 'drawing' && onRemoveDrawing) {
119
112
  onRemoveDrawing(attachment.localId)
120
113
  return
121
114
  }
122
- liveStore.getState().removeAttachment(workspaceId, sessionId, attachment.localId)
115
+ liveStore.getState().removeAttachment(workspaceId, attachment.localId)
123
116
  }
124
117
 
125
118
  const send = async () => {
@@ -165,9 +158,29 @@ export function ChatComposer({
165
158
  >
166
159
  {attachments.length > 0 && (
167
160
  <div className="flex flex-wrap gap-2 px-1 pt-1 pb-1">
168
- {attachments.map(a => (
169
- <AttachmentChip key={a.localId} attachment={a} onRemove={() => removeAttachment(a)} />
170
- ))}
161
+ {attachments
162
+ .toSorted((a, b) => ATTACHMENT_ORDER[a.kind] - ATTACHMENT_ORDER[b.kind])
163
+ .map(a =>
164
+ a.kind === 'text' ? (
165
+ <TextAttachmentChip
166
+ key={a.localId}
167
+ label={a.label}
168
+ onRemove={() => removeAttachment(a)}
169
+ />
170
+ ) : a.kind === 'drawing' ? (
171
+ <DrawingAttachmentChip
172
+ key={a.localId}
173
+ attachment={a}
174
+ onRemove={() => removeAttachment(a)}
175
+ />
176
+ ) : (
177
+ <FileAttachmentChip
178
+ key={a.localId}
179
+ attachment={a}
180
+ onRemove={() => removeAttachment(a)}
181
+ />
182
+ )
183
+ )}
171
184
  </div>
172
185
  )}
173
186
 
@@ -271,111 +284,9 @@ export function ChatComposer({
271
284
  )
272
285
  }
273
286
 
274
- const EMPTY: ChatAttachment[] = []
275
-
276
- type AttachmentChipProps = {
277
- attachment: ChatAttachment
278
- onRemove: () => void
279
- }
280
-
281
- // A composer attachment preview: an image thumbnail or a labelled file chip,
282
- // with an upload spinner / error overlay and a remove button.
283
- function AttachmentChip({ attachment, onRemove }: AttachmentChipProps) {
284
- if (attachment.kind === 'drawing') {
285
- return <DrawingAttachmentChip attachment={attachment} onRemove={onRemove} />
286
- }
287
-
288
- const { name, previewUrl, status, error } = attachment
289
- const isImage = !!previewUrl
290
-
291
- return (
292
- <div
293
- className={cn(
294
- 'group relative flex items-center gap-2 overflow-hidden rounded-lg bg-accent text-accent-foreground ring-1 ring-border',
295
- isImage ? 'size-14' : 'h-10 max-w-52 pr-2 pl-2',
296
- status === 'error' && 'border-destructive/50'
297
- )}
298
- title={error ?? name}
299
- >
300
- {isImage ? (
301
- <img src={previewUrl} alt={name} className="size-full object-cover" />
302
- ) : (
303
- <>
304
- <IconFile size={16} stroke={1.75} className="shrink-0 text-muted-foreground" />
305
- <span className="truncate text-xs">{name}</span>
306
- </>
307
- )}
308
-
309
- {status === 'uploading' && (
310
- <div className="absolute inset-0 flex items-center justify-center bg-background/70">
311
- <IconLoader2 size={16} stroke={1.75} className="animate-spin text-muted-foreground" />
312
- </div>
313
- )}
314
- {status === 'error' && (
315
- <div className="absolute inset-0 flex items-center justify-center bg-destructive/10 text-[10px] text-destructive">
316
- Failed
317
- </div>
318
- )}
319
-
320
- <Button
321
- type="button"
322
- variant="ghost"
323
- size="icon-sm"
324
- onClick={onRemove}
325
- aria-label={`Remove ${name}`}
326
- className="absolute top-0.5 right-0.5 size-4 rounded-full bg-primary/70 text-primary-foreground opacity-0 transition-opacity group-hover:opacity-100 hover:bg-primary/80 [&_svg]:size-3"
327
- >
328
- <IconX stroke={1.75} />
329
- </Button>
330
- </div>
331
- )
332
- }
333
-
334
- type DrawingAttachmentChipProps = {
335
- attachment: Extract<ChatAttachment, { kind: 'drawing' }>
336
- onRemove: () => void
337
- }
338
-
339
- function DrawingAttachmentChip({ attachment, onRemove }: DrawingAttachmentChipProps) {
340
- const { previewUrl, purpose } = attachment
341
- const label = purpose === 'sketch' ? 'Sketch' : 'Annotation'
342
-
343
- return (
344
- <HoverCard>
345
- <HoverCardTrigger
346
- render={
347
- <div
348
- tabIndex={0}
349
- className="group flex h-7 cursor-default items-center rounded-md bg-background pr-2 pl-0.5 text-sm whitespace-nowrap text-foreground ring-1 ring-border outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
350
- />
351
- }
352
- >
353
- <Button
354
- type="button"
355
- variant="ghost"
356
- size="icon-sm"
357
- onClick={onRemove}
358
- aria-label={`Remove ${label.toLowerCase()}`}
359
- className="size-6 shrink-0 hover:bg-transparent hover:text-current"
360
- >
361
- <IconScribble stroke={1.75} className="group-focus-within:hidden group-hover:hidden" />
362
- <IconX stroke={1.75} className="hidden group-focus-within:block group-hover:block" />
363
- </Button>
364
- <span>{label}</span>
365
- </HoverCardTrigger>
366
- {previewUrl && (
367
- <HoverCardContent
368
- side="top"
369
- align="start"
370
- className="w-60 max-w-[calc(100vw-2rem)] rounded-xl"
371
- >
372
- <img
373
- src={previewUrl}
374
- alt={`${label} preview`}
375
- className="max-h-72 w-full rounded-md object-contain"
376
- />
377
- </HoverCardContent>
378
- )}
379
- </HoverCard>
380
- )
287
+ const EMPTY: StagedAttachment[] = []
288
+ const ATTACHMENT_ORDER: Record<StagedAttachment['kind'], number> = {
289
+ file: 0,
290
+ drawing: 1,
291
+ text: 2
381
292
  }
@@ -4,7 +4,7 @@ import { AnimatePresence, motion } from 'motion/react'
4
4
 
5
5
  import { IconBolt, IconBoltFilled } from '@tabler/icons-react'
6
6
 
7
- import { useSaveSessionConfig, useSessionConfig } from '../api'
7
+ import { useSaveSessionConfig, useSessionConfig } from '../sessions/api'
8
8
  import { useWorkspaceAgent } from '@/client/features/workspace/api'
9
9
  import {
10
10
  groupModels,
@@ -0,0 +1,99 @@
1
+ import type { ComponentPropsWithRef } from 'react'
2
+ import { IconLoader2, IconX, type Icon } from '@tabler/icons-react'
3
+ import { Button } from '@/client/components/ui/button'
4
+ import { cn } from '@/client/lib/cn'
5
+
6
+ type AttachmentChipProps = ComponentPropsWithRef<'div'> & {
7
+ label: string
8
+ icon: Icon
9
+ onRemove?: () => void
10
+ previewUrl?: string
11
+ loading?: boolean
12
+ }
13
+
14
+ // Two layouts share one frame: a labelled chip or an image thumbnail.
15
+ // Upload status is an overlay; it doesn't introduce another layout.
16
+ export function AttachmentChip({
17
+ label,
18
+ icon,
19
+ onRemove,
20
+ previewUrl,
21
+ loading,
22
+ className,
23
+ children,
24
+ ...props
25
+ }: AttachmentChipProps) {
26
+ return (
27
+ <div
28
+ {...props}
29
+ className={cn(
30
+ 'group relative flex max-w-full min-w-0 cursor-default items-center rounded-md bg-background text-sm whitespace-nowrap text-foreground ring-1 ring-border outline-none focus-visible:ring-3 focus-visible:ring-ring/50',
31
+ previewUrl ? 'size-14 overflow-hidden' : 'h-7 pr-2 pl-0.5',
32
+ className
33
+ )}
34
+ >
35
+ {loading && (
36
+ <div className="pointer-events-none absolute inset-0 flex items-center justify-center bg-background/70">
37
+ <IconLoader2 size={16} stroke={1.75} className="animate-spin text-muted-foreground" />
38
+ </div>
39
+ )}
40
+ {previewUrl ? (
41
+ <ImageChipContent label={label} previewUrl={previewUrl} onRemove={onRemove} />
42
+ ) : (
43
+ <LabelChipContent label={label} icon={icon} onRemove={onRemove} />
44
+ )}
45
+ {children}
46
+ </div>
47
+ )
48
+ }
49
+
50
+ type LabelChipContentProps = Pick<AttachmentChipProps, 'label' | 'icon' | 'onRemove'>
51
+
52
+ function LabelChipContent({ label, icon: IconComponent, onRemove }: LabelChipContentProps) {
53
+ return (
54
+ <>
55
+ {onRemove ? (
56
+ <Button
57
+ type="button"
58
+ variant="ghost"
59
+ size="icon-sm"
60
+ onClick={onRemove}
61
+ aria-label={`Remove ${label}`}
62
+ className="size-6 shrink-0 hover:bg-transparent hover:text-current"
63
+ >
64
+ <IconComponent stroke={1.75} className="group-focus-within:hidden group-hover:hidden" />
65
+ <IconX stroke={1.75} className="hidden group-focus-within:block group-hover:block" />
66
+ </Button>
67
+ ) : (
68
+ <span className="flex size-6 shrink-0 items-center justify-center">
69
+ <IconComponent size={16} stroke={1.75} />
70
+ </span>
71
+ )}
72
+ <span className="truncate">{label}</span>
73
+ </>
74
+ )
75
+ }
76
+
77
+ type ImageChipContentProps = Pick<AttachmentChipProps, 'label' | 'onRemove'> & {
78
+ previewUrl: string
79
+ }
80
+
81
+ function ImageChipContent({ label, previewUrl, onRemove }: ImageChipContentProps) {
82
+ return (
83
+ <>
84
+ <img src={previewUrl} alt={label} className="size-full object-cover" />
85
+ {onRemove && (
86
+ <Button
87
+ type="button"
88
+ variant="outline"
89
+ size="icon-sm"
90
+ onClick={onRemove}
91
+ aria-label={`Remove ${label}`}
92
+ className="absolute top-1 right-1 size-4 rounded-xs border-0 opacity-0 shadow-xs transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 [&_svg]:size-3"
93
+ >
94
+ <IconX stroke={1.75} />
95
+ </Button>
96
+ )}
97
+ </>
98
+ )
99
+ }
@@ -0,0 +1,37 @@
1
+ import { IconScribble } from '@tabler/icons-react'
2
+ import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/client/components/ui/hover-card'
3
+ import type { StagedAttachment } from './types'
4
+ import { AttachmentChip } from './AttachmentChip'
5
+
6
+ type DrawingAttachmentChipProps = {
7
+ attachment: Extract<StagedAttachment, { kind: 'drawing' }>
8
+ onRemove: () => void
9
+ }
10
+
11
+ export function DrawingAttachmentChip({ attachment, onRemove }: DrawingAttachmentChipProps) {
12
+ const { previewUrl, purpose } = attachment
13
+ const label = purpose === 'sketch' ? 'Sketch' : 'Annotation'
14
+
15
+ return (
16
+ <HoverCard>
17
+ <HoverCardTrigger
18
+ render={
19
+ <AttachmentChip tabIndex={0} label={label} icon={IconScribble} onRemove={onRemove} />
20
+ }
21
+ />
22
+ {previewUrl && (
23
+ <HoverCardContent
24
+ side="top"
25
+ align="start"
26
+ className="w-60 max-w-[calc(100vw-2rem)] rounded-xl"
27
+ >
28
+ <img
29
+ src={previewUrl}
30
+ alt={`${label} preview`}
31
+ className="max-h-72 w-full rounded-md object-contain"
32
+ />
33
+ </HoverCardContent>
34
+ )}
35
+ </HoverCard>
36
+ )
37
+ }
@@ -0,0 +1,22 @@
1
+ import { IconFile } from '@tabler/icons-react'
2
+ import type { StagedAttachment } from './types'
3
+ import { AttachmentChip } from './AttachmentChip'
4
+
5
+ type FileAttachmentChipProps = {
6
+ attachment: Extract<StagedAttachment, { kind: 'file' }>
7
+ onRemove: () => void
8
+ }
9
+
10
+ export function FileAttachmentChip({ attachment, onRemove }: FileAttachmentChipProps) {
11
+ return (
12
+ <AttachmentChip
13
+ label={attachment.label}
14
+ icon={IconFile}
15
+ onRemove={onRemove}
16
+ previewUrl={attachment.previewUrl}
17
+ loading={attachment.status === 'uploading'}
18
+ title={attachment.label}
19
+ className="max-w-52"
20
+ />
21
+ )
22
+ }
@@ -0,0 +1,11 @@
1
+ import { IconLibrary } from '@tabler/icons-react'
2
+ import { AttachmentChip } from './AttachmentChip'
3
+
4
+ type TextAttachmentChipProps = {
5
+ label: string
6
+ onRemove?: () => void
7
+ }
8
+
9
+ export function TextAttachmentChip({ label, onRemove }: TextAttachmentChipProps) {
10
+ return <AttachmentChip label={label} icon={IconLibrary} onRemove={onRemove} />
11
+ }
@@ -0,0 +1,168 @@
1
+ import type {
2
+ AttachmentInput,
3
+ AttachmentOrigin,
4
+ DrawingPurpose,
5
+ TextAttachment,
6
+ WorkspaceTabId
7
+ } from '@/lib/types'
8
+
9
+ import { findAttachment, liveStore } from '../../chat-store'
10
+ import { uploadChatFile } from './uploads'
11
+ import { reportAppletError } from '@/client/features/applets/applet-log'
12
+ import { toast } from '@/client/components/ui/toast'
13
+
14
+ type ComposerTarget = {
15
+ workspaceId: string
16
+ sessionId: string | null
17
+ }
18
+
19
+ export function stageComposerFiles(target: ComposerTarget, files: File[]): void {
20
+ for (const file of files) void stageFile(target, file)
21
+ }
22
+
23
+ // Both file sources enter the same draft lifecycle and become ordinary uploads.
24
+ async function stageFile(
25
+ { workspaceId, sessionId }: ComposerTarget,
26
+ input: File | string,
27
+ onError?: (message: string) => void,
28
+ source?: string
29
+ ): Promise<void> {
30
+ const file = typeof input === 'string' ? null : input
31
+ const label = typeof input === 'string' ? input.split('/').at(-1)! : input.name || 'file'
32
+ const localId = crypto.randomUUID()
33
+ liveStore.getState().addAttachments(workspaceId, sessionId, [
34
+ {
35
+ kind: 'file',
36
+ source,
37
+ localId,
38
+ label,
39
+ mediaType: file?.type || 'application/octet-stream',
40
+ previewUrl: file?.type.startsWith('image/') ? URL.createObjectURL(file) : undefined,
41
+ status: 'uploading'
42
+ }
43
+ ])
44
+ try {
45
+ const upload = await uploadChatFile(workspaceId, input)
46
+ liveStore.getState().updateAttachment(workspaceId, localId, {
47
+ status: 'ready',
48
+ upload,
49
+ label: upload.filename,
50
+ mediaType: upload.mediaType,
51
+ ...(upload.kind === 'image' && !file?.type.startsWith('image/')
52
+ ? { previewUrl: `/api/workspaces/${workspaceId}/uploads/${upload.id}` }
53
+ : {})
54
+ })
55
+ } catch (error: unknown) {
56
+ const message = error instanceof Error ? error.message : 'The file couldn’t be uploaded'
57
+ liveStore.getState().removeAttachment(workspaceId, localId)
58
+ toast.add({ title: `Couldn’t add ${label}`, description: message, type: 'error' })
59
+ onError?.(message)
60
+ }
61
+ }
62
+
63
+ export function stageChatAttachment(
64
+ target: ComposerTarget,
65
+ input: AttachmentInput & AttachmentOrigin
66
+ ): Promise<void> {
67
+ if (input.type === 'text') {
68
+ const { source, label, text } = input
69
+ stageTextAttachment(target, { source, label, text })
70
+ return Promise.resolve()
71
+ }
72
+ return stageFile(
73
+ target,
74
+ input.file ?? input.path,
75
+ message => {
76
+ reportAppletError(target.workspaceId, {
77
+ source: 'runtime',
78
+ message: `addChatAttachment() from ${input.source}: ${message}`
79
+ })
80
+ },
81
+ input.source
82
+ )
83
+ }
84
+
85
+ type StageDrawingDraftInput = ComposerTarget & {
86
+ localId: string
87
+ purpose: DrawingPurpose
88
+ source: WorkspaceTabId
89
+ blob: Blob
90
+ }
91
+
92
+ // Local-only staging while the user is still drawing: the chip shows the
93
+ // latest composite as its preview, but nothing is uploaded until the drawing
94
+ // session ends (stageDrawing).
95
+ export function stageDrawingDraft({
96
+ workspaceId,
97
+ sessionId,
98
+ localId,
99
+ purpose,
100
+ source,
101
+ blob
102
+ }: StageDrawingDraftInput): void {
103
+ const label = purpose === 'sketch' ? 'Sketch' : 'Annotation'
104
+ const previewUrl = URL.createObjectURL(blob)
105
+ const store = liveStore.getState()
106
+ const existing = findAttachment(store.attachments, workspaceId, localId)
107
+
108
+ if (existing) {
109
+ store.updateAttachment(workspaceId, localId, {
110
+ previewUrl,
111
+ status: 'draft',
112
+ upload: undefined
113
+ })
114
+ } else {
115
+ store.addAttachments(workspaceId, sessionId, [
116
+ {
117
+ kind: 'drawing',
118
+ purpose,
119
+ localId,
120
+ source,
121
+ label: `${label}.png`,
122
+ mediaType: 'image/png',
123
+ previewUrl,
124
+ status: 'draft'
125
+ }
126
+ ])
127
+ }
128
+ }
129
+
130
+ type StageDrawingInput = StageDrawingDraftInput & {
131
+ isCurrent: () => boolean
132
+ }
133
+
134
+ // Upload a drawing once its editing session ends (finish, send, or an
135
+ // implicit cancel that keeps the attachment). `isCurrent` guards the result:
136
+ // a stale upload must not resurrect an attachment the user has removed.
137
+ export async function stageDrawing(input: StageDrawingInput): Promise<void> {
138
+ const { workspaceId, localId, purpose, blob, isCurrent } = input
139
+ const label = purpose === 'sketch' ? 'Sketch' : 'Annotation'
140
+ stageDrawingDraft(input)
141
+ liveStore.getState().updateAttachment(workspaceId, localId, { status: 'uploading' })
142
+
143
+ try {
144
+ const upload = await uploadChatFile(
145
+ workspaceId,
146
+ new File([blob], `${label}.png`, { type: 'image/png' })
147
+ )
148
+ if (!isCurrent()) return
149
+ liveStore.getState().updateAttachment(workspaceId, localId, {
150
+ status: 'ready',
151
+ upload,
152
+ mediaType: upload.mediaType
153
+ })
154
+ } catch {
155
+ if (!isCurrent()) return
156
+ liveStore.getState().removeAttachment(workspaceId, localId)
157
+ }
158
+ }
159
+
160
+ export function stageTextAttachment(
161
+ { workspaceId, sessionId }: ComposerTarget,
162
+ attachment: TextAttachment
163
+ ): void {
164
+ const store = liveStore.getState()
165
+ store.addAttachments(workspaceId, sessionId, [
166
+ { kind: 'text', localId: crypto.randomUUID(), ...attachment }
167
+ ])
168
+ }
@@ -0,0 +1,25 @@
1
+ import type { AttachmentOrigin, DrawingPurpose, TextAttachment, UploadInfo } from '@/lib/types'
2
+
3
+ // One composer attachment, tracked per session until the message is sent. A
4
+ // file uploads as soon as it's added (drop/paste/pick); an annotation stays a
5
+ // local `draft` while it's being drawn and uploads once when the drawing
6
+ // session ends. `status` reflects that lifecycle, and `upload` holds the server
7
+ // handle once ready. `previewUrl` is a local object URL for image thumbnails
8
+ // (revoked on remove/clear).
9
+ type StagedUploadFields = {
10
+ label: string
11
+ mediaType: string
12
+ previewUrl?: string
13
+ status: 'draft' | 'uploading' | 'ready'
14
+ upload?: UploadInfo
15
+ }
16
+
17
+ export type StagedAttachment = { localId: string } & (
18
+ | ({ kind: 'file' } & StagedUploadFields & Partial<AttachmentOrigin>)
19
+ | ({ kind: 'drawing'; purpose: DrawingPurpose } & StagedUploadFields & AttachmentOrigin)
20
+ | ({ kind: 'text' } & TextAttachment)
21
+ )
22
+
23
+ export type StagedAttachmentPatch = Partial<
24
+ Pick<StagedUploadFields, 'label' | 'mediaType' | 'previewUrl' | 'status' | 'upload'>
25
+ >
@@ -0,0 +1,26 @@
1
+ import { jsonRequest, requestJson } from '@/client/api/http'
2
+ import type { UploadInfo } from '@/lib/types'
3
+
4
+ // Shared single-file preparation for drafts, drawings, and immediate sends.
5
+ export async function uploadChatFile(
6
+ workspaceId: string,
7
+ input: File | string
8
+ ): Promise<UploadInfo> {
9
+ const url = `/api/workspaces/${workspaceId}/uploads`
10
+ if (typeof input === 'string') {
11
+ return requestJson<UploadInfo>(
12
+ `${url}/from-path`,
13
+ jsonRequest('POST', { path: input }),
14
+ 'The file couldn’t be uploaded'
15
+ )
16
+ }
17
+ const form = new FormData()
18
+ form.append('files', input)
19
+ const [upload] = await requestJson<UploadInfo[]>(
20
+ url,
21
+ { method: 'POST', body: form },
22
+ 'The file couldn’t be uploaded'
23
+ )
24
+ if (!upload) throw new Error('The upload didn’t finish')
25
+ return upload
26
+ }
@@ -2,7 +2,7 @@ import type { QueryClient } from '@tanstack/react-query'
2
2
 
3
3
  import { wsUrl } from '@/client/lib/ws-url'
4
4
  import { liveStore } from '@/client/features/chat/chat-store'
5
- import { reduceChatFrame } from '@/client/features/chat/chat-frames'
5
+ import { reduceChatFrame } from '@/client/features/chat/connection/chat-frames'
6
6
  import type { ClientMessage } from '@/lib/types'
7
7
 
8
8
  // App-wide chat connection: ONE WebSocket for the whole client, opened once at
@@ -3,8 +3,8 @@ import type { QueryClient } from '@tanstack/react-query'
3
3
  import { workspaceKeys } from '@/client/api/workspace-keys'
4
4
  import { getScratchExecutor } from '@/client/features/scratchpad/scratch-executor'
5
5
  import { liveStore } from '@/client/features/chat/chat-store'
6
- import { bufferSessionEvent } from '@/client/features/chat/session-view'
7
- import { renameSelectedSessionInCache } from '@/client/features/chat/useSelectedSession'
6
+ import { bufferSessionEvent } from '@/client/features/chat/sessions/session-view'
7
+ import { renameSelectedSessionInCache } from '@/client/features/chat/sessions/useSelectedSession'
8
8
  import { applyEvent } from '@/lib/format'
9
9
  import type {
10
10
  ClientMessage,