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,22 +1,11 @@
1
- import { useState } from 'react'
1
+ import { memo } from 'react'
2
2
 
3
- import {
4
- IconAlertTriangle,
5
- IconBrain,
6
- IconChevronRight,
7
- IconLoader2,
8
- IconPlug,
9
- IconSparkles,
10
- IconUsersGroup,
11
- IconX
12
- } from '@tabler/icons-react'
13
- import { relative } from 'pathe'
3
+ import { IconFile } from '@tabler/icons-react'
14
4
 
15
5
  import { MarkdownContent } from '@/client/components/MarkdownContent'
16
- import { cn } from '@/client/lib/cn'
17
- import { formatMcpServerName, getMcpIcon } from '@/client/lib/mcp-icons'
18
- import { useChatStore } from '@/client/store/chat'
19
- import type { Part, SubagentRecord, ToolCall, Turn } from '@/lib/types'
6
+ import { ToolCallGroup } from '@/client/components/tool-group/ToolCallGroup'
7
+ import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
8
+ import type { Part, Turn } from '@/lib/types'
20
9
 
21
10
  export function EmptyState() {
22
11
  return <div className="flex flex-1 flex-col items-center justify-center" />
@@ -39,61 +28,119 @@ export function ThinkingIndicator() {
39
28
  )
40
29
  }
41
30
 
42
- type TurnViewProps = { turn: Turn }
31
+ // A part either folds into a tool-group "run" (reasoning + tool calls — including
32
+ // subagents and skills, which render as their own timeline rows) or stands alone
33
+ // (text, files, sources, data).
34
+ function isRunPart(part: Part): boolean {
35
+ if (part.type === 'reasoning') return true
36
+ if (part.type === 'tool-call') return true
37
+ return false
38
+ }
39
+
40
+ type Segment = { kind: 'run'; parts: Part[] } | { kind: 'single'; part: Part }
41
+
42
+ // Split a turn's parts into runs (consecutive run-parts) and singles, preserving
43
+ // order. Each run becomes one <ToolCallGroup>; singles render individually.
44
+ function buildSegments(parts: Part[]): Segment[] {
45
+ const segments: Segment[] = []
46
+ for (const part of parts) {
47
+ if (isRunPart(part)) {
48
+ const last = segments[segments.length - 1]
49
+ if (last && last.kind === 'run') last.parts.push(part)
50
+ else segments.push({ kind: 'run', parts: [part] })
51
+ } else {
52
+ segments.push({ kind: 'single', part })
53
+ }
54
+ }
55
+ return segments
56
+ }
57
+
58
+ type TurnPartsProps = { parts: Part[]; cwd: string | null; processing?: boolean }
59
+
60
+ // Shared body renderer for a sequence of parts — used by both a finalized turn
61
+ // and the live streaming preview turn (see client/lib/preview-turn.ts), so a
62
+ // streamed message and its finalized form render identically. Consecutive
63
+ // reasoning + tool-call parts fold into one <ToolCallGroup> run; text/files/etc.
64
+ // stand alone. `processing` flows into the LAST run so a trailing reasoning there
65
+ // reads as a live, expanded "Thinking" row.
66
+ export function TurnParts({ parts, cwd, processing = false }: TurnPartsProps) {
67
+ const segments = buildSegments(parts)
68
+ return (
69
+ <div className="flex flex-col">
70
+ {segments.map((seg, i) => {
71
+ const spacing = i === 0 ? '' : 'mt-3'
72
+ const isLast = i === segments.length - 1
73
+ return (
74
+ <div key={i} className={spacing}>
75
+ {seg.kind === 'run' ? (
76
+ <ToolCallGroup parts={seg.parts} cwd={cwd} processing={processing && isLast} />
77
+ ) : (
78
+ <PartRenderer part={seg.part} />
79
+ )}
80
+ </div>
81
+ )
82
+ })}
83
+ </div>
84
+ )
85
+ }
86
+
87
+ type TurnViewProps = { turn: Turn; processing?: boolean }
88
+
89
+ // Memoized: the message list maps over grouped turns (stable identities — see
90
+ // `groupTurns` in ChatPanel), so a parent re-render (e.g. the scroll-fade state
91
+ // toggling on every scroll) no longer re-renders every row — only rows whose
92
+ // `turn` or `processing` actually changed.
93
+ export const TurnView = memo(function TurnView({ turn, processing = false }: TurnViewProps) {
94
+ const cwd = useWorkspaceLayoutCtx().cwd
43
95
 
44
- export function TurnView({ turn }: TurnViewProps) {
45
96
  if (turn.origin.kind === 'replay') return null
46
97
 
47
98
  // The SKILL.md body is captured as the owning Skill tool call's `skill.body`
48
- // and not surfaced in the scroll (see ClaudeAdapter). Other synthetic turns
49
- // (system reminders, hook output) stay hidden by default.
99
+ // and not surfaced in the scroll. Other synthetic turns (system reminders,
100
+ // hook output) and subagent prompts stay hidden by default.
50
101
  if (turn.origin.kind === 'synthetic') return null
51
102
  if (turn.origin.kind === 'subagent-prompt') return null
52
103
 
53
104
  if (turn.role === 'user' && turn.origin.kind === 'user-input') {
54
- // Plain user input — right-aligned bubble (only text is typical here)
105
+ // Plain user input — right-aligned. Attachments (images/files) stack above
106
+ // the text bubble.
107
+ const fileParts = turn.parts.filter(
108
+ (p): p is Extract<Part, { type: 'file' }> => p.type === 'file'
109
+ )
55
110
  const text = turn.parts
56
111
  .filter(p => p.type === 'text')
57
112
  .map(p => (p.type === 'text' ? p.text : ''))
58
113
  .join('\n')
59
- if (!text) return null
114
+ if (!text && fileParts.length === 0) return null
60
115
  return (
61
- <p className="ml-8 self-end rounded-md bg-black/[0.07] px-4 py-2 text-sm leading-normal whitespace-pre-wrap">
62
- {text}
63
- </p>
116
+ <div className="ml-8 flex flex-col items-end gap-1.5">
117
+ {fileParts.map((p, i) => (
118
+ <FilePart key={i} mediaType={p.mediaType} url={p.url} filename={p.filename} />
119
+ ))}
120
+ {text && (
121
+ <p className="rounded-md bg-black/[0.07] px-4 py-2 text-sm leading-normal whitespace-pre-wrap">
122
+ {text}
123
+ </p>
124
+ )}
125
+ </div>
64
126
  )
65
127
  }
66
128
 
67
- return (
68
- <div className="flex flex-col">
69
- {turn.parts.map((part, i) => {
70
- // Default 12px between siblings, tightened to 4px when both this
71
- // part and the previous one are tool-call cards. Lets a chain of
72
- // tool calls (especially after the groupTurns merge) read as a
73
- // single sequence instead of a sparse list.
74
- const prev = i > 0 ? turn.parts[i - 1] : null
75
- const tightToolPair = prev?.type === 'tool-call' && part.type === 'tool-call'
76
- const spacing = i === 0 ? '' : tightToolPair ? 'mt-1' : 'mt-3'
77
- return (
78
- <div key={i} className={spacing}>
79
- <PartRenderer part={part} />
80
- </div>
81
- )
82
- })}
83
- </div>
84
- )
85
- }
129
+ return <TurnParts parts={turn.parts} cwd={cwd} processing={processing} />
130
+ })
86
131
 
87
132
  type PartRendererProps = { part: Part }
88
133
 
134
+ // Renders the standalone parts. Reasoning + tool calls never reach here — they're
135
+ // folded into a <ToolCallGroup> run by buildSegments.
89
136
  function PartRenderer({ part }: PartRendererProps) {
90
137
  switch (part.type) {
91
138
  case 'text':
92
139
  return <MarkdownContent content={part.text} />
93
- case 'reasoning':
94
- return <ReasoningPart text={part.text} redacted={part.redacted} />
95
140
  case 'tool-call':
96
- return <ToolCallCard call={part.call} />
141
+ // Tool calls normally fold into a run; this is a defensive fallback for a
142
+ // lone tool-call segment, rendered as a one-row group.
143
+ return <ToolCallGroup parts={[part]} cwd={null} />
97
144
  case 'file':
98
145
  return <FilePart mediaType={part.mediaType} url={part.url} filename={part.filename} />
99
146
  case 'source-url':
@@ -102,41 +149,29 @@ function PartRenderer({ part }: PartRendererProps) {
102
149
  return <SourceLink url="#" title={part.title} />
103
150
  case 'data':
104
151
  return <DataPart name={part.name} data={part.data} />
152
+ case 'reasoning':
153
+ return null
105
154
  }
106
155
  }
107
156
 
108
- type ReasoningPartProps = { text: string; redacted?: boolean }
109
- function ReasoningPart({ text, redacted }: ReasoningPartProps) {
110
- const [open, setOpen] = useState(false)
111
- return (
112
- <details
113
- className="group"
114
- open={open}
115
- onToggle={e => setOpen((e.target as HTMLDetailsElement).open)}
116
- >
117
- <summary className="flex cursor-pointer items-center gap-2 py-1 text-xs text-muted-foreground select-none">
118
- <IconChevronRight
119
- size={12}
120
- stroke={1.5}
121
- className="chevron transition-transform duration-150 group-open:rotate-90"
122
- />
123
- <IconBrain size={12} stroke={1.5} />
124
- <span>{redacted ? 'Redacted thinking' : 'Thinking'}</span>
125
- </summary>
126
- {!redacted && (
127
- <div className="mt-1 ml-4 text-xs leading-relaxed whitespace-pre-wrap text-muted-foreground italic">
128
- {text}
129
- </div>
130
- )}
131
- </details>
132
- )
133
- }
134
-
135
157
  type FilePartProps = { mediaType: string; url: string; filename?: string }
136
158
  function FilePart({ mediaType, url, filename }: FilePartProps) {
159
+ // Images (data/object/remote URLs) render as a thumbnail; everything else is a
160
+ // labelled chip. A file with no usable url (e.g. a non-image attachment whose
161
+ // bytes live only server-side) still shows its name.
162
+ if (mediaType.startsWith('image/') && url) {
163
+ return (
164
+ <img
165
+ src={url}
166
+ alt={filename ?? 'attachment'}
167
+ className="max-h-64 max-w-full rounded-md border border-black/10 object-contain"
168
+ />
169
+ )
170
+ }
137
171
  return (
138
- <div className="text-xs text-muted-foreground">
139
- 📎 {filename ?? url} ({mediaType})
172
+ <div className="flex items-center gap-1.5 rounded-md border border-black/10 bg-black/[0.03] px-2.5 py-1.5 text-xs text-muted-foreground">
173
+ <IconFile size={14} stroke={1.5} />
174
+ <span className="truncate">{filename ?? mediaType}</span>
140
175
  </div>
141
176
  )
142
177
  }
@@ -161,458 +196,3 @@ function DataPart({ name, data }: DataPartProps) {
161
196
  </details>
162
197
  )
163
198
  }
164
-
165
- // -----------------------------------------------------------------------
166
- // Tool call cards
167
- // -----------------------------------------------------------------------
168
-
169
- type ToolCallCardProps = { call: ToolCall }
170
-
171
- function ToolCallCard({ call }: ToolCallCardProps) {
172
- if (call.caller === 'subagent' && call.subagent) {
173
- return <SubagentCard call={call} subagent={call.subagent} />
174
- }
175
- if (call.name === 'Skill' && call.skill) {
176
- return <SkillCard call={call} />
177
- }
178
- // Mcporter calls are shell commands like
179
- // `mcporter call notion.notion-search --args '...'`
180
- // We render them as a server-branded card instead of a raw Bash line.
181
- const mcp = parseMcporterCall(call)
182
- if (mcp) return <MCPCallCard call={call} mcp={mcp} />
183
- return <GenericToolCard call={call} />
184
- }
185
-
186
- type GenericToolCardProps = { call: ToolCall }
187
- function GenericToolCard({ call }: GenericToolCardProps) {
188
- const cwd = useChatStore(s => s.cwd)
189
- const isError = call.state === 'error'
190
- const isRunning = call.state === 'running' || call.state === 'pending'
191
- const output = isError
192
- ? (call.errorText ?? '')
193
- : typeof call.output === 'string'
194
- ? call.output
195
- : ''
196
-
197
- return (
198
- <details className="group">
199
- <summary className="flex cursor-pointer items-center gap-2 py-1.5 select-none">
200
- <IconChevronRight
201
- size={12}
202
- stroke={1.5}
203
- className="chevron shrink-0 text-ring transition-transform duration-150 group-open:rotate-90"
204
- />
205
- <CallerBadge call={call} />
206
- <span className="text-xs font-medium whitespace-nowrap">{getToolDisplayName(call)}</span>
207
- <span className="truncate text-[11px] text-ring">{formatInputBrief(call, cwd)}</span>
208
- {isRunning && <IconLoader2 size={12} stroke={1.5} className="animate-spin text-ring" />}
209
- </summary>
210
- {(output || isError) && (
211
- <div
212
- className={cn(
213
- 'mt-1 ml-4 rounded-md border px-3 py-2.5',
214
- isError ? 'border-red-200 bg-red-50' : 'border-border bg-muted'
215
- )}
216
- >
217
- <pre
218
- className={cn(
219
- 'max-h-[200px] overflow-y-auto font-mono text-xs leading-relaxed break-all whitespace-pre-wrap',
220
- isError ? 'text-red-800' : 'text-muted-foreground'
221
- )}
222
- >
223
- {output || '(empty)'}
224
- </pre>
225
- </div>
226
- )}
227
- </details>
228
- )
229
- }
230
-
231
- // -----------------------------------------------------------------------
232
- // MCP call card (mcporter)
233
- // -----------------------------------------------------------------------
234
-
235
- type McporterCall = { server: string; tool: string; rest: string }
236
-
237
- // Detect a `mcporter call <server>.<tool> [args...]` invocation inside a
238
- // shell command. We accept any prefix (env VAR=…, absolute paths to a Node
239
- // binary, `$(which mcporter)`, `npx mcporter`, etc.) and look for the
240
- // `mcporter call <server>.<tool>` token sequence anywhere in the line. We
241
- // stop at the first command separator (`&&`, `||`, `;`, `|`) so a
242
- // follow-up command in a chain doesn't bleed into `rest`. Returns null for
243
- // anything that's not a `call` invocation (`mcporter config`, `--version`,
244
- // etc. — those keep the Generic Bash card).
245
- function parseMcporterCall(call: ToolCall): McporterCall | null {
246
- const isShell = call.name === 'Bash' || call.name === 'exec'
247
- if (!isShell) return null
248
- const input = (call.input as Record<string, unknown>) ?? {}
249
- const command = typeof input.command === 'string' ? input.command : ''
250
- if (!command) return null
251
- const m = command.match(
252
- /(?:^|\s|\$\()mcporter(?:\)?)\s+call\s+([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]+)((?:\s+(?!&&|\|\||;|\|)\S+)*)/
253
- )
254
- if (!m) return null
255
- return { server: m[1], tool: m[2], rest: (m[3] ?? '').trim() }
256
- }
257
-
258
- type MCPCallCardProps = { call: ToolCall; mcp: McporterCall }
259
- function MCPCallCard({ call, mcp }: MCPCallCardProps) {
260
- const isError = call.state === 'error'
261
- const isRunning = call.state === 'running' || call.state === 'pending'
262
- const output = isError
263
- ? (call.errorText ?? '')
264
- : typeof call.output === 'string'
265
- ? call.output
266
- : ''
267
- const iconSrc = getMcpIcon(mcp.server)
268
- const brief = mcp.rest ? `${mcp.tool} ${mcp.rest}` : mcp.tool
269
-
270
- return (
271
- <details className="group">
272
- <summary className="flex cursor-pointer items-center gap-2 py-1.5 select-none">
273
- <IconChevronRight
274
- size={12}
275
- stroke={1.5}
276
- className="chevron shrink-0 text-ring transition-transform duration-150 group-open:rotate-90"
277
- />
278
- <span className="block size-4 shrink-0 overflow-hidden rounded-[3px] bg-muted">
279
- {iconSrc ? (
280
- <img src={iconSrc} alt="" className="size-full object-cover" />
281
- ) : (
282
- <IconPlug size={12} stroke={1.5} className="m-0.5 text-muted-foreground" />
283
- )}
284
- </span>
285
- <span className="text-xs font-medium whitespace-nowrap">
286
- {formatMcpServerName(mcp.server)} MCP
287
- </span>
288
- <span className="truncate text-[11px] text-ring">{brief}</span>
289
- {isRunning && <IconLoader2 size={12} stroke={1.5} className="animate-spin text-ring" />}
290
- </summary>
291
- {(output || isError) && (
292
- <div
293
- className={cn(
294
- 'mt-1 ml-4 rounded-md border px-3 py-2.5',
295
- isError ? 'border-red-200 bg-red-50' : 'border-border bg-muted'
296
- )}
297
- >
298
- <pre
299
- className={cn(
300
- 'max-h-[200px] overflow-y-auto font-mono text-xs leading-relaxed break-all whitespace-pre-wrap',
301
- isError ? 'text-red-800' : 'text-muted-foreground'
302
- )}
303
- >
304
- {output || '(empty)'}
305
- </pre>
306
- </div>
307
- )}
308
- </details>
309
- )
310
- }
311
-
312
- type SkillCardProps = { call: ToolCall }
313
- function SkillCard({ call }: SkillCardProps) {
314
- const [showBody, setShowBody] = useState(false)
315
- const skillName = call.skill?.skillName ?? 'unknown'
316
- const body = call.skill?.body ?? ''
317
- const isRunning = call.state === 'running'
318
- const isError = call.state === 'error'
319
-
320
- return (
321
- <div className="flex flex-col gap-1">
322
- <div className="flex items-center gap-2 py-1">
323
- <IconSparkles size={14} stroke={1.5} className="text-amber-600" />
324
- <span className="text-xs font-medium">
325
- Loading skill <span className="font-mono">{skillName}</span>
326
- </span>
327
- {isRunning && <IconLoader2 size={12} stroke={1.5} className="animate-spin text-ring" />}
328
- {isError && <IconAlertTriangle size={12} stroke={1.5} className="text-red-600" />}
329
- {body && (
330
- <button
331
- type="button"
332
- onClick={() => setShowBody(v => !v)}
333
- className="text-[11px] text-muted-foreground underline"
334
- >
335
- {showBody ? 'hide' : 'show'} instructions
336
- </button>
337
- )}
338
- </div>
339
- {showBody && body && (
340
- <pre className="max-h-[300px] overflow-y-auto rounded bg-muted p-3 font-mono text-xs leading-relaxed whitespace-pre-wrap text-muted-foreground">
341
- {body}
342
- </pre>
343
- )}
344
- </div>
345
- )
346
- }
347
-
348
- type SubagentCardProps = { call: ToolCall; subagent: SubagentRecord }
349
-
350
- function SubagentCard({ call, subagent }: SubagentCardProps) {
351
- const [open, setOpen] = useState(false)
352
- const status = subagent.status
353
- const latest =
354
- status === 'running' && subagent.progress.length > 0
355
- ? subagent.progress[subagent.progress.length - 1]
356
- : null
357
-
358
- const statusBadge = {
359
- running: <IconLoader2 size={12} stroke={1.5} className="animate-spin text-ring" />,
360
- completed: <span className="text-xs text-emerald-700">✓</span>,
361
- failed: <IconAlertTriangle size={12} stroke={1.5} className="text-red-600" />,
362
- stopped: <IconX size={12} stroke={1.5} className="text-muted-foreground" />
363
- }[status]
364
-
365
- return (
366
- <>
367
- <button
368
- type="button"
369
- onClick={() => setOpen(true)}
370
- className="flex items-center gap-2 rounded-md border border-border bg-muted/40 px-3 py-2 text-left transition-colors hover:bg-muted/70"
371
- >
372
- <IconUsersGroup size={14} stroke={1.5} className="shrink-0 text-blue-600" />
373
- <div className="min-w-0 flex-1">
374
- <div className="flex items-center gap-2">
375
- <span className="truncate text-xs font-medium">
376
- {subagent.description || 'Subtask'}
377
- </span>
378
- {statusBadge}
379
- </div>
380
- {latest && (
381
- <div className="mt-0.5 truncate text-[11px] text-muted-foreground">{latest}</div>
382
- )}
383
- {status !== 'running' && subagent.usage?.toolUses != null && (
384
- <div className="mt-0.5 text-[11px] text-muted-foreground">
385
- {subagent.usage.toolUses} tool call{subagent.usage.toolUses === 1 ? '' : 's'}
386
- </div>
387
- )}
388
- </div>
389
- </button>
390
- {open && <SubagentModal call={call} subagent={subagent} onClose={() => setOpen(false)} />}
391
- </>
392
- )
393
- }
394
-
395
- type SubagentModalProps = {
396
- call: ToolCall
397
- subagent: SubagentRecord
398
- onClose: () => void
399
- }
400
-
401
- function SubagentModal({ call, subagent, onClose }: SubagentModalProps) {
402
- return (
403
- <div
404
- className="fixed inset-0 z-50 flex items-center justify-center bg-black/30 p-4"
405
- onClick={onClose}
406
- >
407
- <div
408
- className="flex max-h-[80vh] w-[min(800px,100%)] flex-col overflow-hidden rounded-lg bg-background shadow-xl"
409
- onClick={e => e.stopPropagation()}
410
- >
411
- <header className="flex items-start justify-between gap-3 border-b border-border px-5 py-4">
412
- <div className="min-w-0 flex-1">
413
- <div className="flex items-center gap-2">
414
- <IconUsersGroup size={16} stroke={1.5} className="text-blue-600" />
415
- <h3 className="text-sm font-semibold">{subagent.description || 'Subagent task'}</h3>
416
- </div>
417
- <div className="mt-0.5 text-[11px] text-muted-foreground">
418
- status: {subagent.status}
419
- {subagent.usage?.durationMs != null &&
420
- ` · ${Math.round(subagent.usage.durationMs / 1000)}s`}
421
- {subagent.usage?.totalTokens != null && ` · ${subagent.usage.totalTokens} tokens`}
422
- </div>
423
- </div>
424
- <button
425
- type="button"
426
- onClick={onClose}
427
- className="text-muted-foreground hover:text-foreground"
428
- aria-label="Close"
429
- >
430
- <IconX size={18} stroke={1.5} />
431
- </button>
432
- </header>
433
-
434
- <div className="flex flex-1 gap-4 overflow-hidden px-5 py-4">
435
- <aside className="w-52 shrink-0 border-r border-border pr-4">
436
- <div className="mb-2 text-[11px] font-medium text-muted-foreground uppercase">
437
- Progress
438
- </div>
439
- <ol className="flex flex-col gap-1">
440
- {subagent.progress.map((p, i) => (
441
- <li key={i} className="truncate text-[11px] text-muted-foreground">
442
- {i + 1}. {p}
443
- </li>
444
- ))}
445
- </ol>
446
- </aside>
447
-
448
- <div className="flex flex-1 flex-col gap-4 overflow-y-auto pr-2">
449
- {call.input != null && Object.keys(call.input as object).length > 0 && (
450
- <details>
451
- <summary className="cursor-pointer text-[11px] text-muted-foreground">
452
- Prompt
453
- </summary>
454
- <pre className="mt-1 rounded bg-muted p-2 font-mono text-xs whitespace-pre-wrap text-muted-foreground">
455
- {JSON.stringify(call.input, null, 2)}
456
- </pre>
457
- </details>
458
- )}
459
- {subagent.transcript.length === 0 ? (
460
- <div className="text-xs text-muted-foreground">No nested transcript captured.</div>
461
- ) : (
462
- subagent.transcript.map(nested => <TurnView key={nested.id} turn={nested} />)
463
- )}
464
- </div>
465
- </div>
466
- </div>
467
- </div>
468
- )
469
- }
470
-
471
- type CallerBadgeProps = { call: ToolCall }
472
- function CallerBadge({ call }: CallerBadgeProps) {
473
- if (call.caller === 'mcp') {
474
- return (
475
- <span className="rounded border border-border px-1 text-[9px] text-muted-foreground uppercase">
476
- mcp{call.mcpServer ? `:${call.mcpServer.slice(0, 8)}` : ''}
477
- </span>
478
- )
479
- }
480
- if (call.caller === 'server-tool') {
481
- return (
482
- <span className="rounded border border-border px-1 text-[9px] text-muted-foreground uppercase">
483
- server
484
- </span>
485
- )
486
- }
487
- return null
488
- }
489
-
490
- // -----------------------------------------------------------------------
491
- // Tool-input formatting
492
- // -----------------------------------------------------------------------
493
-
494
- function getInputValue(input: Record<string, unknown>, key: string): string {
495
- const value = input[key]
496
- return typeof value === 'string' ? value : ''
497
- }
498
-
499
- function makeShortenPaths(cwd: string | null) {
500
- return (s: string) =>
501
- s.replace(/\/[^\s"']+/g, p => {
502
- if (!cwd) return p
503
- const rel = relative(cwd, p)
504
- return rel.startsWith('..') ? p : rel
505
- })
506
- }
507
-
508
- // Tool name → user-facing label, picked per provider. Adapters send the
509
- // raw upstream tool name; the UI is the only place that humanizes it. Names
510
- // not in either map fall through to the raw name (so unknown / plugin tools
511
- // still render something).
512
- const OPENCLAW_TOOL_LABELS: Record<string, string> = {
513
- read: 'Read file',
514
- write: 'Write file',
515
- edit: 'Edit file',
516
- apply_patch: 'Edit',
517
- exec: 'Bash',
518
- process: 'Manage process',
519
- web_search: 'Web search',
520
- web_fetch: 'Fetch',
521
- sessions_list: 'List sessions',
522
- sessions_history: 'Recall session',
523
- sessions_yield: 'Yield to session',
524
- sessions_send: 'Send to session',
525
- sessions_spawn: 'Spawn session',
526
- subagents: 'Run sub-agent',
527
- agents_list: 'List agents',
528
- session_status: 'Session status',
529
- image: 'Analyze image',
530
- image_generate: 'Generate image',
531
- memory_get: 'Read memory',
532
- memory_search: 'Search memory',
533
- update_plan: 'Update plan',
534
- message: 'Send message',
535
- browser: 'Browser',
536
- canvas: 'Canvas',
537
- cron: 'Cron',
538
- gateway: 'Gateway',
539
- code_execution: 'Run Python',
540
- tts: 'Text-to-speech',
541
- music_generate: 'Generate music',
542
- video_generate: 'Generate video',
543
- x_search: 'Search X'
544
- }
545
-
546
- function getToolDisplayName(call: ToolCall): string {
547
- if (call.provider === 'openclaw') return OPENCLAW_TOOL_LABELS[call.name] ?? call.name
548
- return call.name
549
- }
550
-
551
- function formatInputBrief(call: ToolCall, cwd: string | null): string {
552
- const input = (call.input as Record<string, unknown>) ?? {}
553
- const shorten = makeShortenPaths(cwd)
554
- if (call.provider === 'openclaw') {
555
- return formatOpenClawBrief(call.name, input, shorten)
556
- }
557
- return formatClaudeBrief(call.name, input, shorten)
558
- }
559
-
560
- function formatClaudeBrief(
561
- tool: string,
562
- input: Record<string, unknown>,
563
- shorten: (s: string) => string
564
- ): string {
565
- if (tool === 'Bash') return shorten(`$ ${getInputValue(input, 'command')}`)
566
- if (tool === 'Read' || tool === 'Write' || tool === 'Edit')
567
- return shorten(getInputValue(input, 'file_path'))
568
- if (tool === 'Glob') return shorten(getInputValue(input, 'pattern'))
569
- if (tool === 'Grep')
570
- return `/${getInputValue(input, 'pattern')}/ ${shorten(getInputValue(input, 'path'))}`
571
- return ''
572
- }
573
-
574
- function formatOpenClawBrief(
575
- tool: string,
576
- input: Record<string, unknown>,
577
- shorten: (s: string) => string
578
- ): string {
579
- // File I/O — `path` is the canonical key.
580
- if (tool === 'read' || tool === 'write' || tool === 'edit')
581
- return shorten(getInputValue(input, 'path'))
582
- if (tool === 'apply_patch') {
583
- const patch = getInputValue(input, 'patch')
584
- const firstLine = patch.split('\n').find(l => l.startsWith('*** ')) ?? patch.split('\n')[0]
585
- return shorten(firstLine ?? '')
586
- }
587
- if (tool === 'exec') return shorten(`$ ${getInputValue(input, 'command')}`)
588
- if (tool === 'process') {
589
- const action = getInputValue(input, 'action')
590
- const name = getInputValue(input, 'name')
591
- return [action, name].filter(Boolean).join(' ') || shorten(getInputValue(input, 'command'))
592
- }
593
- if (tool === 'web_search' || tool === 'x_search') return getInputValue(input, 'query')
594
- if (tool === 'web_fetch') return getInputValue(input, 'url')
595
- if (tool === 'memory_search') return getInputValue(input, 'query')
596
- if (tool === 'memory_get') return getInputValue(input, 'key') || getInputValue(input, 'name')
597
- if (tool === 'sessions_history' || tool === 'sessions_send' || tool === 'sessions_yield')
598
- return getInputValue(input, 'sessionKey') || getInputValue(input, 'agentId')
599
- if (tool === 'sessions_list' || tool === 'agents_list') return getInputValue(input, 'agentId')
600
- if (tool === 'subagents' || tool === 'sessions_spawn')
601
- return getInputValue(input, 'task') || getInputValue(input, 'agentId')
602
- if (tool === 'image' || tool === 'image_generate')
603
- return getInputValue(input, 'prompt') || shorten(getInputValue(input, 'path'))
604
- if (tool === 'message') return getInputValue(input, 'recipient') || getInputValue(input, 'to')
605
- if (tool === 'update_plan') {
606
- const plan = input.plan
607
- if (Array.isArray(plan)) {
608
- const inProgress = plan.find(
609
- (p): p is { step: string } =>
610
- !!p && typeof p === 'object' && (p as { status?: unknown }).status === 'in_progress'
611
- )
612
- const step = inProgress?.step ?? (plan[0] as { step?: unknown })?.step
613
- if (typeof step === 'string') return step
614
- }
615
- return ''
616
- }
617
- return ''
618
- }