moi-computer 0.0.3 → 0.1.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 (216) hide show
  1. package/README.md +2 -2
  2. package/bunfig.toml +4 -0
  3. package/client/api/workspaces.ts +277 -6
  4. package/client/assets/mcp/agentation.png +0 -0
  5. package/client/assets/mcp/airtable.png +0 -0
  6. package/client/assets/mcp/apollo.png +0 -0
  7. package/client/assets/mcp/asana.png +0 -0
  8. package/client/assets/mcp/box.png +0 -0
  9. package/client/assets/mcp/chrome.svg +33 -0
  10. package/client/assets/mcp/clickup.png +0 -0
  11. package/client/assets/mcp/cloudflare.png +0 -0
  12. package/client/assets/mcp/context7.png +0 -0
  13. package/client/assets/mcp/datadog.png +0 -0
  14. package/client/assets/mcp/dropbox.png +0 -0
  15. package/client/assets/mcp/elevenlabs.png +0 -0
  16. package/client/assets/mcp/exa.png +0 -0
  17. package/client/assets/mcp/firecrawl.png +0 -0
  18. package/client/assets/mcp/gmail.png +0 -0
  19. package/client/assets/mcp/googlecalendar.png +0 -0
  20. package/client/assets/mcp/googledrive.png +0 -0
  21. package/client/assets/mcp/grafana.png +0 -0
  22. package/client/assets/mcp/huggingface.png +0 -0
  23. package/client/assets/mcp/intercom.png +0 -0
  24. package/client/assets/mcp/monday.png +0 -0
  25. package/client/assets/mcp/mongodb.png +0 -0
  26. package/client/assets/mcp/paper.png +0 -0
  27. package/client/assets/mcp/paypal.png +0 -0
  28. package/client/assets/mcp/perplexity.png +0 -0
  29. package/client/assets/mcp/postgresql.png +0 -0
  30. package/client/assets/mcp/posthog.png +0 -0
  31. package/client/assets/mcp/puppeteer.png +0 -0
  32. package/client/assets/mcp/railway.png +0 -0
  33. package/client/assets/mcp/redis.png +0 -0
  34. package/client/assets/mcp/salesforce.png +0 -0
  35. package/client/assets/mcp/shopify.png +0 -0
  36. package/client/assets/mcp/snowflake.png +0 -0
  37. package/client/assets/mcp/telegram.png +0 -0
  38. package/client/assets/mcp/twilio.png +0 -0
  39. package/client/assets/mcp/zapier.png +0 -0
  40. package/client/components/App.tsx +7 -1
  41. package/client/components/ChatInput.tsx +194 -13
  42. package/client/components/ChatPanel.tsx +116 -47
  43. package/client/components/ChatPopup.tsx +1 -1
  44. package/client/components/IconMcp.tsx +21 -0
  45. package/client/components/McpMenu.tsx +125 -0
  46. package/client/components/ModelPicker.tsx +147 -0
  47. package/client/components/Scratchpad.tsx +775 -0
  48. package/client/components/ShimmerText.tsx +20 -0
  49. package/client/components/ThreadSelector.tsx +2 -2
  50. package/client/components/TurnView.tsx +111 -531
  51. package/client/components/WidgetShell.tsx +1 -1
  52. package/client/components/WorkspacesPage.tsx +12 -4
  53. package/client/components/layout/SidebarLayout.tsx +18 -9
  54. package/client/components/playground/ToolCallsPage.tsx +81 -0
  55. package/client/components/routes/workspace/[id].tsx +534 -141
  56. package/client/components/routes/workspace/create.tsx +155 -0
  57. package/client/components/settings/IconPicker.tsx +590 -0
  58. package/client/components/settings/SettingsPages.tsx +307 -0
  59. package/client/components/settings/WorkspaceSettings.tsx +92 -0
  60. package/client/components/tool-group/CodeBlock.tsx +41 -0
  61. package/client/components/tool-group/Collapse.tsx +28 -0
  62. package/client/components/tool-group/ReadImagePreview.tsx +46 -0
  63. package/client/components/tool-group/SubagentCard.tsx +135 -0
  64. package/client/components/tool-group/TimelineRow.tsx +147 -0
  65. package/client/components/tool-group/ToolCallGroup.tsx +231 -0
  66. package/client/components/tool-group/ToolOutput.tsx +139 -0
  67. package/client/components/tool-group/detect.ts +93 -0
  68. package/client/components/tool-group/fixtures.ts +315 -0
  69. package/client/components/tool-group/format.ts +211 -0
  70. package/client/components/tool-group/index.ts +9 -0
  71. package/client/components/ui/dialog.tsx +58 -0
  72. package/client/components/ui/hover-card.tsx +44 -0
  73. package/client/components/ui/switch.tsx +23 -0
  74. package/client/components/ui/tooltip.tsx +54 -0
  75. package/client/externalize-react.ts +6 -0
  76. package/client/hooks/useApplet.ts +117 -0
  77. package/client/hooks/useChat.ts +162 -62
  78. package/client/hooks/useMeiEvents.ts +9 -2
  79. package/client/hooks/useStickToBottom.ts +86 -0
  80. package/client/hooks/useWorkspaceTheme.ts +8 -2
  81. package/client/index.css +48 -2
  82. package/client/index.html +9 -5
  83. package/client/index.tsx +29 -2
  84. package/client/lib/WorkspaceContext.tsx +5 -8
  85. package/client/lib/WorkspaceLayoutContext.tsx +30 -10
  86. package/client/lib/applet-cache.ts +54 -0
  87. package/client/lib/connection.ts +237 -0
  88. package/client/lib/flags.ts +10 -0
  89. package/client/lib/mcp-icons.ts +142 -10
  90. package/client/lib/preview-turn.ts +37 -0
  91. package/client/lib/render-icon.ts +173 -0
  92. package/client/lib/scratch-executor.ts +20 -0
  93. package/client/lib/uploads.ts +18 -0
  94. package/client/main.tsx +5 -0
  95. package/client/store/live.ts +282 -0
  96. package/client/structured-clone-shim.ts +14 -0
  97. package/client/theme.css +2 -2
  98. package/client/vendor/emojibase/en/data.json +1 -0
  99. package/client/vendor/emojibase/en/messages.json +1 -0
  100. package/client/vendor/react/development/_impl/react-dom-client.js +15871 -0
  101. package/client/vendor/react/development/_impl/react-dom.js +223 -0
  102. package/client/vendor/react/development/_impl/react-jsx-dev-runtime.js +256 -0
  103. package/client/vendor/react/development/_impl/react-jsx-runtime.js +260 -0
  104. package/client/vendor/react/development/_impl/react.js +863 -0
  105. package/client/vendor/react/development/react-dom-client.js +6 -0
  106. package/client/vendor/react/development/react-dom.js +17 -0
  107. package/client/vendor/react/development/react-jsx-dev-runtime.js +5 -0
  108. package/client/vendor/react/development/react-jsx-runtime.js +6 -0
  109. package/client/vendor/react/development/react.js +47 -0
  110. package/client/vendor/react/production/_impl/react-dom-client.js +10361 -0
  111. package/client/vendor/react/production/_impl/react-dom.js +184 -0
  112. package/client/vendor/react/production/_impl/react-jsx-dev-runtime.js +37 -0
  113. package/client/vendor/react/production/_impl/react-jsx-runtime.js +60 -0
  114. package/client/vendor/react/production/_impl/react.js +428 -0
  115. package/client/vendor/react/production/react-dom-client.js +6 -0
  116. package/client/vendor/react/production/react-dom.js +17 -0
  117. package/client/vendor/react/production/react-jsx-dev-runtime.js +5 -0
  118. package/client/vendor/react/production/react-jsx-runtime.js +6 -0
  119. package/client/vendor/react/production/react.js +47 -0
  120. package/dist/agentation-4s0nn45p.png +0 -0
  121. package/dist/airtable-hsa66v6q.png +0 -0
  122. package/dist/apollo-2ed5dy2d.png +0 -0
  123. package/dist/asana-tvgtwbx2.png +0 -0
  124. package/dist/box-w3n36t5g.png +0 -0
  125. package/dist/chrome-tspm94rw.svg +33 -0
  126. package/dist/chunk-kc6e9nd4.css +1 -0
  127. package/dist/chunk-yf3p7qg7.js +673 -0
  128. package/dist/clickup-qqrqqvqb.png +0 -0
  129. package/dist/cloudflare-j9p931v6.png +0 -0
  130. package/dist/context7-8ht0xjfy.png +0 -0
  131. package/dist/datadog-70ne3yzt.png +0 -0
  132. package/dist/dropbox-4m5s9mgr.png +0 -0
  133. package/dist/elevenlabs-2nzzej1t.png +0 -0
  134. package/dist/exa-qqj3vr0x.png +0 -0
  135. package/dist/firecrawl-w2t8nehx.png +0 -0
  136. package/dist/gmail-sg6a5v3x.png +0 -0
  137. package/dist/googlecalendar-nqhh2v7r.png +0 -0
  138. package/dist/googledrive-6s8xyab7.png +0 -0
  139. package/dist/grafana-1yfsnwr6.png +0 -0
  140. package/dist/huggingface-kxzaxj83.png +0 -0
  141. package/dist/index.html +10 -6
  142. package/dist/intercom-td763jt8.png +0 -0
  143. package/dist/monday-jdbs4wwf.png +0 -0
  144. package/dist/mongodb-emzxvhd5.png +0 -0
  145. package/dist/paper-zbt34fab.png +0 -0
  146. package/dist/paypal-kwwf7xsc.png +0 -0
  147. package/dist/perplexity-4y63rxvj.png +0 -0
  148. package/dist/postgresql-qsspbsr1.png +0 -0
  149. package/dist/posthog-sphppc4w.png +0 -0
  150. package/dist/puppeteer-2xjt1a9b.png +0 -0
  151. package/dist/railway-834de8d2.png +0 -0
  152. package/dist/redis-spm6w2m1.png +0 -0
  153. package/dist/salesforce-1mk56v4z.png +0 -0
  154. package/dist/shopify-90dadaav.png +0 -0
  155. package/dist/snowflake-hfpykpgy.png +0 -0
  156. package/dist/telegram-v6tjyrs7.png +0 -0
  157. package/dist/twilio-dpyjdwpj.png +0 -0
  158. package/dist/zapier-p67qfch0.png +0 -0
  159. package/lib/attachment-note.ts +48 -0
  160. package/lib/claude-adapter.ts +219 -29
  161. package/lib/format.ts +32 -0
  162. package/lib/types.ts +314 -6
  163. package/package.json +11 -5
  164. package/server/CLAUDE.md +4 -1
  165. package/server/agent.ts +25 -118
  166. package/server/api.ts +593 -0
  167. package/server/applets.ts +396 -0
  168. package/server/build-applet.ts +580 -0
  169. package/server/cc-session.ts +611 -0
  170. package/server/cli-colors.ts +17 -0
  171. package/server/cli-ui.ts +52 -0
  172. package/server/cli.ts +965 -73
  173. package/server/constants.ts +1 -1
  174. package/server/control.ts +166 -19
  175. package/server/debug.ts +10 -0
  176. package/server/events.ts +24 -0
  177. package/server/functions-worker.ts +18 -2
  178. package/server/functions.ts +59 -12
  179. package/server/icon.ts +13 -0
  180. package/server/layout.ts +25 -3
  181. package/server/mcp.ts +125 -0
  182. package/server/moi-scaffold.ts +85 -0
  183. package/server/openclaw-session.ts +41 -10
  184. package/server/openclaw.ts +22 -0
  185. package/server/preview.ts +70 -0
  186. package/server/registry.ts +32 -2
  187. package/server/scratchpad-executor.ts +380 -0
  188. package/server/scratchpad-relay.ts +45 -0
  189. package/server/scratchpad.ts +171 -0
  190. package/server/skill-version.ts +146 -0
  191. package/server/skills-template.ts +6 -1
  192. package/server/state.ts +22 -36
  193. package/server/static.ts +23 -0
  194. package/server/status.ts +94 -0
  195. package/server/thread-config.ts +125 -0
  196. package/server/uploads.ts +0 -0
  197. package/server/vendor.ts +63 -0
  198. package/server/views.ts +0 -0
  199. package/server/web.ts +108 -253
  200. package/server/widgets.ts +52 -142
  201. package/server/workspace-config.ts +37 -0
  202. package/server/workspace-env.ts +407 -0
  203. package/server/workspace-init.ts +66 -0
  204. package/workspace/.claude/skills/moi-workspace/DESIGN.md +109 -0
  205. package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +57 -0
  206. package/workspace/.claude/skills/moi-workspace/SKILL.md +252 -0
  207. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +22 -0
  208. package/client/hooks/useWidget.ts +0 -72
  209. package/client/hooks/useWidgetList.ts +0 -30
  210. package/client/lib/ws.ts +0 -129
  211. package/client/store/chat.tsx +0 -162
  212. package/dist/chunk-4615fa69.js +0 -67
  213. package/dist/chunk-582xmy05.css +0 -1
  214. package/server/build-widget.ts +0 -343
  215. package/workspace/.claude/skills/widgets/DESIGN.md +0 -630
  216. package/workspace/.claude/skills/widgets/SKILL.md +0 -176
@@ -1,33 +1,134 @@
1
- import { useRef } from 'react'
1
+ import { useRef, useState } from 'react'
2
2
 
3
- import { IconArrowUp, IconPlayerStop } from '@tabler/icons-react'
3
+ import {
4
+ IconArrowUp,
5
+ IconFile,
6
+ IconLoader2,
7
+ IconPaperclip,
8
+ IconPlayerStop,
9
+ IconX
10
+ } from '@tabler/icons-react'
4
11
 
12
+ import { cn } from '@/client/lib/cn'
13
+ import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
14
+ import { uploadFiles } from '@/client/lib/uploads'
15
+ import { type ChatAttachment, draftKey, liveStore, useLive } from '@/client/store/live'
16
+
17
+ import { ModelPicker } from './ModelPicker'
5
18
  import { Button } from './ui/button'
6
19
 
7
20
  type ChatInputProps = {
8
- value: string
9
- onChange: (value: string) => void
10
- onSend: () => void
21
+ onSend: (text: string) => void
11
22
  onStop: () => void
12
23
  processing: boolean
13
24
  }
14
25
 
15
- export function ChatInput({ value, onChange, onSend, onStop, processing }: ChatInputProps) {
26
+ // The composer owns the draft: it reads/writes the per-thread draft in the live
27
+ // store directly, so a keystroke re-renders only this component — not the chat
28
+ // panel, message list, or surrounding workspace. The draft is keyed by the
29
+ // active thread, so switching threads swaps the unsent text with you. Attachments
30
+ // (drag/drop, paste, attach button) are tracked the same way and cleared on send.
31
+ export function ChatInput({ onSend, onStop, processing }: ChatInputProps) {
16
32
  const ref = useRef<HTMLTextAreaElement>(null)
33
+ const fileRef = useRef<HTMLInputElement>(null)
34
+ const workspaceId = useWorkspaceId()
35
+ const sessionId = useLive(s => s.activeByWorkspace[workspaceId] ?? null)
36
+ const value = useLive(s => s.drafts[draftKey(workspaceId, sessionId)] ?? '')
37
+ const attachments = useLive(s => s.attachments[draftKey(workspaceId, sessionId)] ?? EMPTY)
38
+ const [dragOver, setDragOver] = useState(false)
39
+
40
+ const uploading = attachments.some(a => a.status === 'uploading')
41
+ const hasReady = attachments.some(a => a.status === 'ready')
42
+ const canSend = (value.trim().length > 0 || hasReady) && !uploading
43
+
44
+ const onChange = (next: string) => liveStore.getState().setDraft(workspaceId, sessionId, next)
45
+
46
+ // Upload each picked file immediately, tracking its in-flight status so the
47
+ // thumbnail row can show a spinner / error per file.
48
+ const addFiles = (files: File[]) => {
49
+ if (files.length === 0) return
50
+ const store = liveStore.getState()
51
+ const items: ChatAttachment[] = files.map(f => ({
52
+ localId: crypto.randomUUID(),
53
+ name: f.name || 'file',
54
+ mediaType: f.type || 'application/octet-stream',
55
+ previewUrl: f.type.startsWith('image/') ? URL.createObjectURL(f) : undefined,
56
+ status: 'uploading'
57
+ }))
58
+ store.addAttachments(workspaceId, sessionId, items)
59
+ items.forEach((item, i) => {
60
+ uploadFiles(workspaceId, [files[i]])
61
+ .then(([info]) =>
62
+ liveStore.getState().updateAttachment(workspaceId, sessionId, item.localId, {
63
+ status: 'ready',
64
+ upload: info,
65
+ mediaType: info.mediaType
66
+ })
67
+ )
68
+ .catch((err: unknown) =>
69
+ liveStore.getState().updateAttachment(workspaceId, sessionId, item.localId, {
70
+ status: 'error',
71
+ error: err instanceof Error ? err.message : 'Upload failed'
72
+ })
73
+ )
74
+ })
75
+ }
76
+
77
+ const send = () => {
78
+ if (!canSend) return
79
+ onSend(value)
80
+ // Clear under the current key. On a new chat `sessionId` is still null, so
81
+ // this clears the `'new'` draft; `send` then mints the real id and the input
82
+ // re-renders empty under the new key. (Attachments are cleared by `send`.)
83
+ liveStore.getState().setDraft(workspaceId, sessionId, '')
84
+ }
17
85
 
18
86
  return (
19
87
  <form
20
88
  onSubmit={e => {
21
89
  e.preventDefault()
22
- onSend()
90
+ send()
23
91
  }}
24
92
  onMouseDown={e => {
25
93
  if (e.target instanceof HTMLElement && e.target.closest('button')) return
26
94
  e.preventDefault()
27
95
  ref.current?.focus()
28
96
  }}
29
- className="flex w-full cursor-text flex-col gap-1 rounded-lg bg-white p-2 shadow-xs transition-[color,box-shadow] outline-none focus-within:shadow-sm"
97
+ onDragOver={e => {
98
+ if (!e.dataTransfer.types.includes('Files')) return
99
+ e.preventDefault()
100
+ setDragOver(true)
101
+ }}
102
+ onDragLeave={e => {
103
+ // Ignore leaves into child elements — only reset when leaving the form.
104
+ if (e.currentTarget.contains(e.relatedTarget as Node | null)) return
105
+ setDragOver(false)
106
+ }}
107
+ onDrop={e => {
108
+ if (!e.dataTransfer.types.includes('Files')) return
109
+ e.preventDefault()
110
+ setDragOver(false)
111
+ addFiles(Array.from(e.dataTransfer.files))
112
+ }}
113
+ className={cn(
114
+ 'flex w-full cursor-text flex-col gap-1 rounded-lg bg-white p-2 shadow-xs transition-[color,box-shadow] outline-none focus-within:shadow-sm',
115
+ dragOver && 'ring-2 ring-ring/60'
116
+ )}
30
117
  >
118
+ {attachments.length > 0 && (
119
+ <div className="flex flex-wrap gap-2 px-1 pt-1 pb-0.5">
120
+ {attachments.map(a => (
121
+ <AttachmentChip
122
+ key={a.localId}
123
+ attachment={a}
124
+ onRemove={() =>
125
+ liveStore.getState().removeAttachment(workspaceId, sessionId, a.localId)
126
+ }
127
+ />
128
+ ))}
129
+ </div>
130
+ )}
131
+
31
132
  <textarea
32
133
  ref={ref}
33
134
  id="chat-input"
@@ -37,22 +138,48 @@ export function ChatInput({ value, onChange, onSend, onStop, processing }: ChatI
37
138
  onKeyDown={e => {
38
139
  if (e.key === 'Enter' && !e.shiftKey) {
39
140
  e.preventDefault()
40
- onSend()
141
+ send()
41
142
  }
42
143
  }}
43
- placeholder="Ask anything..."
44
- disabled={processing}
144
+ onPaste={e => {
145
+ const files = Array.from(e.clipboardData?.files ?? [])
146
+ if (files.length === 0) return
147
+ e.preventDefault()
148
+ addFiles(files)
149
+ }}
150
+ placeholder={processing ? 'Queue a follow-up...' : 'Ask anything...'}
45
151
  autoFocus
46
152
  rows={1}
47
153
  className="field-sizing-content max-h-40 w-full resize-none bg-transparent px-2 py-1 text-sm leading-relaxed outline-none placeholder:text-muted-foreground disabled:opacity-50"
48
154
  />
49
- <div className="flex justify-end">
155
+ <div className="flex items-center justify-end gap-1.5">
156
+ <input
157
+ ref={fileRef}
158
+ type="file"
159
+ multiple
160
+ hidden
161
+ onChange={e => {
162
+ addFiles(Array.from(e.target.files ?? []))
163
+ e.target.value = ''
164
+ }}
165
+ />
166
+ <Button
167
+ type="button"
168
+ variant="ghost"
169
+ size="icon"
170
+ className="mr-auto"
171
+ onClick={() => fileRef.current?.click()}
172
+ aria-label="Attach files"
173
+ >
174
+ <IconPaperclip stroke={1.5} />
175
+ </Button>
176
+ <ModelPicker />
50
177
  {processing ? (
51
178
  <Button type="button" size="icon" onClick={onStop} aria-label="Stop agent">
52
179
  <IconPlayerStop stroke={1.5} />
53
180
  </Button>
54
181
  ) : (
55
- <Button type="submit" size="icon" disabled={!value.trim()} aria-label="Send message">
182
+ <Button type="submit" size="icon" disabled={!canSend} aria-label="Send message">
56
183
  <IconArrowUp stroke={1.5} />
57
184
  </Button>
58
185
  )}
@@ -60,3 +187,57 @@ export function ChatInput({ value, onChange, onSend, onStop, processing }: ChatI
60
187
  </form>
61
188
  )
62
189
  }
190
+
191
+ const EMPTY: ChatAttachment[] = []
192
+
193
+ type AttachmentChipProps = {
194
+ attachment: ChatAttachment
195
+ onRemove: () => void
196
+ }
197
+
198
+ // A composer attachment preview: an image thumbnail or a labelled file chip,
199
+ // with an upload spinner / error overlay and a remove button.
200
+ function AttachmentChip({ attachment, onRemove }: AttachmentChipProps) {
201
+ const { name, previewUrl, status, error } = attachment
202
+ const isImage = !!previewUrl
203
+
204
+ return (
205
+ <div
206
+ className={cn(
207
+ 'group relative flex items-center gap-2 overflow-hidden rounded-md border border-black/10 bg-black/[0.03]',
208
+ isImage ? 'size-14' : 'h-10 max-w-52 pr-2 pl-2',
209
+ status === 'error' && 'border-red-300'
210
+ )}
211
+ title={error ?? name}
212
+ >
213
+ {isImage ? (
214
+ <img src={previewUrl} alt={name} className="size-full object-cover" />
215
+ ) : (
216
+ <>
217
+ <IconFile size={16} stroke={1.5} className="shrink-0 text-muted-foreground" />
218
+ <span className="truncate text-xs text-foreground/80">{name}</span>
219
+ </>
220
+ )}
221
+
222
+ {status === 'uploading' && (
223
+ <div className="absolute inset-0 flex items-center justify-center bg-white/60">
224
+ <IconLoader2 size={16} stroke={1.5} className="animate-spin text-muted-foreground" />
225
+ </div>
226
+ )}
227
+ {status === 'error' && (
228
+ <div className="absolute inset-0 flex items-center justify-center bg-red-50/80 text-[10px] text-red-700">
229
+ Failed
230
+ </div>
231
+ )}
232
+
233
+ <button
234
+ type="button"
235
+ onClick={onRemove}
236
+ aria-label={`Remove ${name}`}
237
+ className="absolute top-0.5 right-0.5 flex size-4 items-center justify-center rounded-full bg-black/60 text-white opacity-0 transition-opacity group-hover:opacity-100"
238
+ >
239
+ <IconX size={10} stroke={2} />
240
+ </button>
241
+ </div>
242
+ )
243
+ }
@@ -1,11 +1,12 @@
1
- import { type ReactNode, useEffect, useMemo } from 'react'
1
+ import { useCallback, useMemo } from 'react'
2
2
 
3
- import { IconChevronsRight, IconSelector, IconX } from '@tabler/icons-react'
3
+ import { IconChevronDown, IconChevronsRight, IconSelector, IconX } from '@tabler/icons-react'
4
4
 
5
5
  import { useScrollFade } from '@/client/hooks/useScrollFade'
6
+ import { useStickToBottom } from '@/client/hooks/useStickToBottom'
6
7
  import { cn } from '@/client/lib/cn'
7
8
  import { groupTurns } from '@/client/lib/group-turns'
8
- import type { ViewState } from '@/lib/types'
9
+ import type { ChatDisplay, Turn, ViewState } from '@/lib/types'
9
10
 
10
11
  import { ChatInput } from './ChatInput'
11
12
  import { ThreadSelector } from './ThreadSelector'
@@ -19,8 +20,6 @@ import {
19
20
  DropdownMenuTrigger
20
21
  } from './ui/dropdown-menu'
21
22
 
22
- export type ChatMode = 'sidebar' | 'floating'
23
-
24
23
  type ChatModeIconProps = {
25
24
  className?: string
26
25
  }
@@ -59,40 +58,67 @@ function ChatModeIconFloating({ className }: ChatModeIconProps) {
59
58
  )
60
59
  }
61
60
 
61
+ function ChatModeIconFullscreen({ className }: ChatModeIconProps) {
62
+ return (
63
+ <svg
64
+ xmlns="http://www.w3.org/2000/svg"
65
+ width="24"
66
+ height="24"
67
+ viewBox="0 0 24 24"
68
+ fill="none"
69
+ strokeWidth="1.5"
70
+ className={className}
71
+ >
72
+ <rect x="1.75" y="3.75" width="20.5" height="16.5" rx="2.25" stroke="currentColor" />
73
+ <rect x="4.5" y="6.5" width="15" height="11" rx="1" fill="currentColor" />
74
+ </svg>
75
+ )
76
+ }
77
+
62
78
  type ChatPanelProps = {
63
79
  view: ViewState
64
- input: string
65
- setInput: (v: string) => void
80
+ // The live streaming preview as a synthetic assistant turn (or null). Merged
81
+ // into the transcript through the same groupTurns pipeline so a thinking-only
82
+ // preview folds into the current tool group. See client/lib/preview-turn.ts.
83
+ previewTurn?: Turn | null
84
+ // Active thread id — used only as the scroll reset key (jump to bottom on
85
+ // thread switch).
86
+ sessionId?: string | null
66
87
  processing: boolean
67
88
  error?: string | null
68
89
  onDismissError?: () => void
69
- send: () => void
90
+ send: (text: string) => void
70
91
  stop: () => void
71
- chatMode: ChatMode
92
+ // How the chat is shown right now (position, or fullscreen). The mode switch
93
+ // and collapse/close affordances key off this; fullscreen shows neither.
94
+ chatMode: ChatDisplay
95
+ // Constrain the scrollable history and the composer to a centered max-width
96
+ // column (var --chat-max-container) while the header still spans full width.
97
+ // Always on for now; will be toggled per layout mode later.
98
+ contained?: boolean
72
99
  onSwitchThread: (sessionId: string | null) => void
73
- onModeChange?: (mode: 'sidebar' | 'floating') => void
100
+ // The chat display picker — sidebar / floating (position) and fullscreen (the
101
+ // transient view). The parent routes each to the right state.
102
+ onModeChange?: (mode: ChatDisplay) => void
74
103
  onCollapse?: () => void
75
104
  onClose?: () => void
76
- // Rendered at the start of the chat header. Solo mode passes the sidebar
77
- // toggle here since there's no separate workspace header beside the chat.
78
- leading?: ReactNode
79
105
  }
80
106
 
81
107
  export function ChatPanel({
82
108
  view,
83
- input,
84
- setInput,
109
+ previewTurn,
110
+ sessionId,
85
111
  processing,
86
112
  error,
87
113
  onDismissError,
88
114
  send,
89
115
  stop,
90
116
  chatMode,
117
+ contained = true,
91
118
  onSwitchThread,
92
119
  onModeChange,
93
120
  onCollapse,
94
- onClose,
95
- leading
121
+ onClose
96
122
  }: ChatPanelProps) {
97
123
  const { ref: scrollRef, showTopFade, showBottomFade } = useScrollFade()
98
124
  const turns = view.turns
@@ -100,20 +126,37 @@ export function ChatPanel({
100
126
  // synthetic turn so OpenAI Codex–style traces (which serialize one
101
127
  // assistant message per agent step) don't render with the wider
102
128
  // inter-turn gap between every tool call. See `dev/turn-spacing.md`.
103
- const groupedTurns = useMemo(() => groupTurns(turns), [turns])
129
+ // The live preview turn is appended before grouping, so a thinking-only
130
+ // preview merges into the trailing tool group exactly like its finalized form.
131
+ const groupedTurns = useMemo(
132
+ () => groupTurns(previewTurn ? [...turns, previewTurn] : turns),
133
+ [turns, previewTurn]
134
+ )
104
135
 
105
- useEffect(() => {
106
- const el = scrollRef.current
107
- el?.scrollTo({ top: el.scrollHeight, behavior: 'instant' })
108
- }, [scrollRef, turns])
136
+ // Stick to the bottom while pinned; respect scroll-up; jump on thread switch.
137
+ const { atBottom, scrollToBottom } = useStickToBottom(scrollRef, sessionId)
109
138
 
110
- const TriggerIcon = chatMode === 'sidebar' ? ChatModeIconSidebar : ChatModeIconFloating
139
+ // Sending always returns the user to the bottom, even if they'd scrolled up —
140
+ // they expect to see their message and the reply.
141
+ const handleSend = useCallback(
142
+ (text: string) => {
143
+ send(text)
144
+ scrollToBottom()
145
+ },
146
+ [send, scrollToBottom]
147
+ )
148
+
149
+ const TriggerIcon =
150
+ chatMode === 'sidebar'
151
+ ? ChatModeIconSidebar
152
+ : chatMode === 'floating'
153
+ ? ChatModeIconFloating
154
+ : ChatModeIconFullscreen
111
155
 
112
156
  return (
113
- <div className="flex h-full flex-col">
114
- <header className="flex items-center justify-between pb-2 pl-2">
157
+ <div className="flex h-full flex-col pt-2 pb-4">
158
+ <header className="flex items-center justify-between pr-2 pb-2 pl-5">
115
159
  <div className="flex min-w-0 items-center gap-2.5">
116
- {leading}
117
160
  <ThreadSelector onSwitch={onSwitchThread} />
118
161
  </div>
119
162
  <div className="flex items-center gap-0.5">
@@ -143,6 +186,10 @@ export function ChatPanel({
143
186
  <ChatModeIconFloating />
144
187
  Floating
145
188
  </DropdownMenuRadioItem>
189
+ <DropdownMenuRadioItem value="fullscreen" closeOnClick>
190
+ <ChatModeIconFullscreen />
191
+ Fullscreen
192
+ </DropdownMenuRadioItem>
146
193
  </DropdownMenuRadioGroup>
147
194
  </DropdownMenuContent>
148
195
  </DropdownMenu>
@@ -161,23 +208,51 @@ export function ChatPanel({
161
208
  </div>
162
209
  </header>
163
210
 
164
- <div
165
- ref={scrollRef}
166
- className={cn(
167
- 'flex flex-1 flex-col gap-6 overflow-y-auto overscroll-contain px-2 pt-4 pb-12',
168
- showTopFade && showBottomFade && 'mask-fade-y',
169
- showTopFade && !showBottomFade && 'mask-fade-top',
170
- !showTopFade && showBottomFade && 'mask-fade-bottom'
211
+ <div className="relative flex min-h-0 flex-1 flex-col">
212
+ <div
213
+ ref={scrollRef}
214
+ className={cn(
215
+ 'flex scrollbar-thin flex-1 flex-col overflow-y-auto overscroll-contain px-5 pt-4 pb-12',
216
+ showTopFade && showBottomFade && 'mask-fade-y',
217
+ showTopFade && !showBottomFade && 'mask-fade-top',
218
+ !showTopFade && showBottomFade && 'mask-fade-bottom'
219
+ )}
220
+ >
221
+ <div
222
+ className={cn(
223
+ 'flex flex-1 flex-col gap-6',
224
+ contained && 'mx-auto w-full max-w-[var(--chat-max-container)]'
225
+ )}
226
+ >
227
+ {turns.length === 0 && !processing && <EmptyState />}
228
+ {groupedTurns.map((turn, i) => (
229
+ <TurnView
230
+ key={turn.id}
231
+ turn={turn}
232
+ processing={processing && i === groupedTurns.length - 1}
233
+ />
234
+ ))}
235
+ {/* Pulsing dots only before the first token — once the preview has
236
+ visible content it renders as a (possibly merged) grouped turn. */}
237
+ {processing && !previewTurn && <ThinkingIndicator />}
238
+ </div>
239
+ </div>
240
+
241
+ {/* Jump to latest — shown only when scrolled up, so following the tail
242
+ never yanks the user while they read history. */}
243
+ {!atBottom && turns.length > 0 && (
244
+ <button
245
+ type="button"
246
+ onClick={() => scrollToBottom('smooth')}
247
+ aria-label="Jump to latest"
248
+ className="absolute bottom-3 left-1/2 flex size-8 -translate-x-1/2 animate-in items-center justify-center rounded-full border border-border bg-background text-muted-foreground shadow-md transition-colors duration-150 fade-in slide-in-from-bottom-1 hover:text-foreground"
249
+ >
250
+ <IconChevronDown size={18} stroke={1.5} />
251
+ </button>
171
252
  )}
172
- >
173
- {turns.length === 0 && !processing && <EmptyState />}
174
- {groupedTurns.map(turn => (
175
- <TurnView key={turn.id} turn={turn} />
176
- ))}
177
- {processing && <ThinkingIndicator />}
178
253
  </div>
179
254
 
180
- <div>
255
+ <div className={cn(contained && 'mx-auto w-full max-w-[var(--chat-max-container)] px-3')}>
181
256
  {error && (
182
257
  <div className="mb-2 flex items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-800">
183
258
  <span className="flex-1 break-words">{error}</span>
@@ -193,13 +268,7 @@ export function ChatPanel({
193
268
  )}
194
269
  </div>
195
270
  )}
196
- <ChatInput
197
- value={input}
198
- onChange={setInput}
199
- onSend={send}
200
- onStop={stop}
201
- processing={processing}
202
- />
271
+ <ChatInput onSend={handleSend} onStop={stop} processing={processing} />
203
272
  </div>
204
273
  </div>
205
274
  )
@@ -49,7 +49,7 @@ export function ChatPopup({ defaultOpen = false, container, children }: ChatPopu
49
49
  sideOffset={-48}
50
50
  align="end"
51
51
  alignOffset={-8}
52
- className="flex h-[calc(100vh-2rem)] w-[min(440px,calc(100vw-1rem))] flex-col gap-0 rounded-3xl p-3 sm:h-[calc(100vh-8rem)] sm:w-[min(440px,calc(100vw-2rem))] sm:p-4"
52
+ className="flex h-[calc(100vh-2rem)] w-[min(440px,calc(100vw-1rem))] flex-col gap-0 rounded-3xl p-0 sm:h-[calc(100vh-8rem)] sm:w-[min(440px,calc(100vw-2rem))] sm:p-1"
53
53
  keepMounted
54
54
  container={container}
55
55
  >
@@ -0,0 +1,21 @@
1
+ // MCP icon — supplied by design (not a Tabler glyph). Stroke inherits the
2
+ // current text color; size via `className`. Shared by the workspace-header MCP
3
+ // menu and the tool-call timeline's fallback node for unknown servers.
4
+ export function IconMcp({ className }: { className?: string }) {
5
+ return (
6
+ <svg
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ viewBox="0 0 24 24"
9
+ fill="none"
10
+ stroke="currentColor"
11
+ strokeWidth={1.5}
12
+ strokeLinecap="round"
13
+ strokeLinejoin="round"
14
+ className={className}
15
+ aria-hidden="true"
16
+ >
17
+ <path d="M3.49994 11.7501L11.6717 3.57855C12.7762 2.47398 14.5672 2.47398 15.6717 3.57855C16.7762 4.68312 16.7762 6.47398 15.6717 7.57855M15.6717 7.57855L9.49994 13.7501M15.6717 7.57855C16.7762 6.47398 18.5672 6.47398 19.6717 7.57855C20.7762 8.68312 20.7762 10.474 19.6717 11.5785L12.7072 18.543C12.3167 18.9335 12.3167 19.5667 12.7072 19.9572L13.9999 21.2499" />
18
+ <path d="M17.4999 9.74921L11.3282 15.921C10.2238 17.0255 8.43275 17.0255 7.32825 15.921C6.22376 14.8164 6.22376 13.0255 7.32825 11.921L13.4999 5.74939" />
19
+ </svg>
20
+ )
21
+ }
@@ -0,0 +1,125 @@
1
+ import { useWorkspaceMcp } from '@/client/api/workspaces'
2
+ import { IconMcp } from '@/client/components/IconMcp'
3
+ import { Button } from '@/client/components/ui/button'
4
+ import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/client/components/ui/hover-card'
5
+ import { useScrollFade } from '@/client/hooks/useScrollFade'
6
+ import { formatMcpServerName, getMcpIcon } from '@/client/lib/mcp-icons'
7
+ import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
8
+ import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
9
+ import { cn } from '@/client/lib/cn'
10
+ import type { McpServer } from '@/lib/types'
11
+
12
+ function McpServerRow({ server }: { server: McpServer }) {
13
+ const icon = getMcpIcon(server.name)
14
+ const connected = server.status === 'connected'
15
+ return (
16
+ <div className="flex items-center gap-2.5 rounded-xs px-2 py-1 hover:bg-muted">
17
+ {icon ? (
18
+ <img src={icon} alt="" className="size-5 shrink-0 rounded ring-2 ring-background" />
19
+ ) : (
20
+ <span className="flex size-5 shrink-0 items-center justify-center rounded bg-muted text-muted-foreground ring-2 ring-background">
21
+ <IconMcp className="size-4" />
22
+ </span>
23
+ )}
24
+ <span className="flex-1 truncate text-sm text-foreground">
25
+ {formatMcpServerName(server.name)}
26
+ </span>
27
+ <span
28
+ className={cn(
29
+ 'size-[5px] shrink-0 rounded-full',
30
+ connected ? 'bg-emerald-500' : 'bg-yellow-500/75'
31
+ )}
32
+ />
33
+ </div>
34
+ )
35
+ }
36
+
37
+ // The scrollable server list. Its own component so `useScrollFade`'s effect runs
38
+ // when the (portaled, mount-on-open) hover card opens — attaching the scroll ref.
39
+ // Overflow is signalled with top/bottom mask fades; the scrollbar is hidden.
40
+ function McpList({ servers }: { servers: McpServer[] }) {
41
+ const { ref, showTopFade, showBottomFade } = useScrollFade()
42
+ const fade =
43
+ showTopFade && showBottomFade
44
+ ? 'mask-fade-y'
45
+ : showTopFade
46
+ ? 'mask-fade-top'
47
+ : showBottomFade
48
+ ? 'mask-fade-bottom'
49
+ : undefined
50
+ return (
51
+ <div
52
+ ref={ref}
53
+ className={cn(
54
+ 'scrollbar-none flex max-h-72 flex-col overflow-y-auto overscroll-contain',
55
+ fade
56
+ )}
57
+ >
58
+ {servers.map(server => (
59
+ <McpServerRow key={server.name} server={server} />
60
+ ))}
61
+ </div>
62
+ )
63
+ }
64
+
65
+ // MCP status hover card — Claude workspaces only (OpenClaw/Hermes use other
66
+ // backends). Lists each MCP server with a green/red dot. The (expensive, cached)
67
+ // status query: while it hasn't resolved the trigger is just a gray icon with no
68
+ // dot and no hover card; once loaded the card opens on hover and the icon goes
69
+ // dark + shows a dot badge when any server is connected.
70
+ export function McpMenu() {
71
+ const workspaceId = useWorkspaceId()
72
+ // Read provider from the shared layout context, not a second `useWorkspaceLayout`
73
+ // observer — a duplicate observer that remounts (e.g. when this menu moves
74
+ // between the fullscreen and two-pane headers) fires `refetchOnMount`, which
75
+ // overwrites an in-flight optimistic chat-mode change before it's persisted.
76
+ const { provider, isLoading } = useWorkspaceLayoutCtx()
77
+ const isClaude = !isLoading && provider !== 'openclaw' && provider !== 'hermes'
78
+ const { data: servers } = useWorkspaceMcp(workspaceId, isClaude)
79
+
80
+ if (!isClaude) return null
81
+
82
+ const anyConnected = servers?.some(s => s.status === 'connected') ?? false
83
+
84
+ const trigger = (
85
+ <Button
86
+ variant="ghost"
87
+ size="icon"
88
+ aria-label="MCP"
89
+ className={cn(
90
+ 'relative size-7 [&_svg]:size-[20px]',
91
+ anyConnected ? 'text-foreground' : 'text-muted-foreground'
92
+ )}
93
+ >
94
+ <IconMcp />
95
+ {anyConnected && (
96
+ <span className="absolute right-[5px] bottom-1.5 size-[5px] rounded-full bg-foreground ring-1 ring-background" />
97
+ )}
98
+ </Button>
99
+ )
100
+
101
+ // Not loaded yet → plain gray icon, no hover card.
102
+ if (!servers) return trigger
103
+
104
+ // Active (connected) servers first, then disabled/errored/auth-pending. The
105
+ // sort is stable, so each group keeps the server list's original order.
106
+ const sorted = [...servers].sort(
107
+ (a, b) => Number(b.status === 'connected') - Number(a.status === 'connected')
108
+ )
109
+
110
+ return (
111
+ <HoverCard delay={0} closeDelay={100}>
112
+ <HoverCardTrigger render={trigger} />
113
+ <HoverCardContent align="end" sideOffset={6} className="w-56 p-1">
114
+ <div className="px-2 pt-1 pb-1.5 text-xs font-medium text-muted-foreground">
115
+ Connected MCPs
116
+ </div>
117
+ {servers.length === 0 ? (
118
+ <div className="px-2 py-1 text-sm text-muted-foreground">No MCP servers</div>
119
+ ) : (
120
+ <McpList servers={sorted} />
121
+ )}
122
+ </HoverCardContent>
123
+ </HoverCard>
124
+ )
125
+ }