moi-computer 0.0.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 (106) hide show
  1. package/LICENSE +95 -0
  2. package/README.md +71 -0
  3. package/bin/moi.mjs +25 -0
  4. package/bunfig.toml +3 -0
  5. package/client/CLAUDE.md +12 -0
  6. package/client/api/workspaces.ts +158 -0
  7. package/client/assets/claude.svg +3 -0
  8. package/client/assets/favicon.png +0 -0
  9. package/client/assets/hermes-nous.png +0 -0
  10. package/client/assets/mcp/.gitkeep +0 -0
  11. package/client/assets/mcp/atlassian.png +0 -0
  12. package/client/assets/mcp/discord.png +0 -0
  13. package/client/assets/mcp/figma.png +0 -0
  14. package/client/assets/mcp/github.png +0 -0
  15. package/client/assets/mcp/gitlab.png +0 -0
  16. package/client/assets/mcp/granola.png +0 -0
  17. package/client/assets/mcp/hubspot.png +0 -0
  18. package/client/assets/mcp/linear.png +0 -0
  19. package/client/assets/mcp/neon.png +0 -0
  20. package/client/assets/mcp/notion.png +0 -0
  21. package/client/assets/mcp/sentry.png +0 -0
  22. package/client/assets/mcp/slack.png +0 -0
  23. package/client/assets/mcp/stripe.png +0 -0
  24. package/client/assets/mcp/supabase.png +0 -0
  25. package/client/assets/mcp/vercel.png +0 -0
  26. package/client/assets/moi-logo.svg +11 -0
  27. package/client/assets/openclaw.svg +22 -0
  28. package/client/components/App.tsx +35 -0
  29. package/client/components/BottomPanel.tsx +33 -0
  30. package/client/components/ChatInput.tsx +62 -0
  31. package/client/components/ChatPanel.tsx +206 -0
  32. package/client/components/ChatPopup.tsx +60 -0
  33. package/client/components/CustomizePanel.tsx +117 -0
  34. package/client/components/HiddenPanel.tsx +79 -0
  35. package/client/components/HomePage.tsx +17 -0
  36. package/client/components/MarkdownContent.tsx +41 -0
  37. package/client/components/ThreadSelector.tsx +88 -0
  38. package/client/components/TurnView.tsx +618 -0
  39. package/client/components/WidgetErrorBoundary.tsx +46 -0
  40. package/client/components/WidgetFrame.tsx +66 -0
  41. package/client/components/WidgetGrid.tsx +113 -0
  42. package/client/components/WidgetShell.tsx +44 -0
  43. package/client/components/Widgets.tsx +132 -0
  44. package/client/components/WorkspacePreview.tsx +48 -0
  45. package/client/components/WorkspacesPage.tsx +237 -0
  46. package/client/components/layout/SidebarLayout.tsx +260 -0
  47. package/client/components/playground/LedLogo.tsx +181 -0
  48. package/client/components/playground/PixelPainter.tsx +105 -0
  49. package/client/components/playground/PlaygroundPage.tsx +71 -0
  50. package/client/components/routes/workspace/[id].tsx +282 -0
  51. package/client/components/ui/button.tsx +48 -0
  52. package/client/components/ui/dropdown-menu.tsx +257 -0
  53. package/client/components/ui/input.tsx +21 -0
  54. package/client/components/ui/popover.tsx +79 -0
  55. package/client/components/ui/textarea.tsx +18 -0
  56. package/client/externalize-react.ts +29 -0
  57. package/client/hooks/useChat.ts +88 -0
  58. package/client/hooks/useFitsSidebar.ts +34 -0
  59. package/client/hooks/useGridReconcile.ts +73 -0
  60. package/client/hooks/useMeiEvents.ts +66 -0
  61. package/client/hooks/useScrollFade.ts +38 -0
  62. package/client/hooks/useWidget.ts +72 -0
  63. package/client/hooks/useWidgetList.ts +30 -0
  64. package/client/hooks/useWorkspaceTheme.ts +76 -0
  65. package/client/index.css +182 -0
  66. package/client/index.html +43 -0
  67. package/client/index.tsx +19 -0
  68. package/client/lib/WorkspaceContext.tsx +24 -0
  69. package/client/lib/WorkspaceLayoutContext.tsx +92 -0
  70. package/client/lib/cn.ts +6 -0
  71. package/client/lib/grid-pack.ts +35 -0
  72. package/client/lib/group-turns.ts +44 -0
  73. package/client/lib/mcp-icons.ts +53 -0
  74. package/client/lib/ws.ts +129 -0
  75. package/client/main.tsx +23 -0
  76. package/client/store/chat.tsx +162 -0
  77. package/client/store/ui.ts +21 -0
  78. package/client/theme.css +66 -0
  79. package/lib/claude-adapter.ts +602 -0
  80. package/lib/format.ts +212 -0
  81. package/lib/themes.ts +89 -0
  82. package/lib/types.ts +144 -0
  83. package/package.json +117 -0
  84. package/server/CLAUDE.md +6 -0
  85. package/server/agent.ts +132 -0
  86. package/server/build-widget.ts +343 -0
  87. package/server/cli.ts +632 -0
  88. package/server/constants.ts +3 -0
  89. package/server/control.ts +98 -0
  90. package/server/functions-worker.ts +89 -0
  91. package/server/functions.ts +171 -0
  92. package/server/layout.ts +83 -0
  93. package/server/openclaw-adapter.ts +242 -0
  94. package/server/openclaw-gateway.ts +255 -0
  95. package/server/openclaw-session.ts +485 -0
  96. package/server/openclaw-strip.ts +134 -0
  97. package/server/openclaw.ts +206 -0
  98. package/server/registry.ts +150 -0
  99. package/server/skills-template.ts +21 -0
  100. package/server/state.ts +87 -0
  101. package/server/theme.ts +55 -0
  102. package/server/web.ts +321 -0
  103. package/server/widgets.ts +254 -0
  104. package/tsconfig.json +21 -0
  105. package/workspace/.claude/skills/widgets/DESIGN.md +630 -0
  106. package/workspace/.claude/skills/widgets/SKILL.md +176 -0
@@ -0,0 +1,618 @@
1
+ import { useState } from 'react'
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'
14
+
15
+ 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'
20
+
21
+ export function EmptyState() {
22
+ return <div className="flex flex-1 flex-col items-center justify-center" />
23
+ }
24
+
25
+ export function ThinkingIndicator() {
26
+ return (
27
+ <div className="flex items-center gap-1.5 px-1 py-3">
28
+ {[0, 1, 2].map(i => (
29
+ <span
30
+ key={i}
31
+ className="bg-ring block h-1.5 w-1.5 rounded-full"
32
+ style={{
33
+ animation: 'pulse-dot 1.4s ease-in-out infinite',
34
+ animationDelay: `${i * 0.2}s`
35
+ }}
36
+ />
37
+ ))}
38
+ </div>
39
+ )
40
+ }
41
+
42
+ type TurnViewProps = { turn: Turn }
43
+
44
+ export function TurnView({ turn }: TurnViewProps) {
45
+ if (turn.origin.kind === 'replay') return null
46
+
47
+ // 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.
50
+ if (turn.origin.kind === 'synthetic') return null
51
+ if (turn.origin.kind === 'subagent-prompt') return null
52
+
53
+ if (turn.role === 'user' && turn.origin.kind === 'user-input') {
54
+ // Plain user input — right-aligned bubble (only text is typical here)
55
+ const text = turn.parts
56
+ .filter(p => p.type === 'text')
57
+ .map(p => (p.type === 'text' ? p.text : ''))
58
+ .join('\n')
59
+ if (!text) return null
60
+ return (
61
+ <p className="ml-8 self-end whitespace-pre-wrap rounded-md bg-black/[0.07] px-4 py-2 text-sm leading-normal">
62
+ {text}
63
+ </p>
64
+ )
65
+ }
66
+
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
+ }
86
+
87
+ type PartRendererProps = { part: Part }
88
+
89
+ function PartRenderer({ part }: PartRendererProps) {
90
+ switch (part.type) {
91
+ case 'text':
92
+ return <MarkdownContent content={part.text} />
93
+ case 'reasoning':
94
+ return <ReasoningPart text={part.text} redacted={part.redacted} />
95
+ case 'tool-call':
96
+ return <ToolCallCard call={part.call} />
97
+ case 'file':
98
+ return <FilePart mediaType={part.mediaType} url={part.url} filename={part.filename} />
99
+ case 'source-url':
100
+ return <SourceLink url={part.url} title={part.title} />
101
+ case 'source-document':
102
+ return <SourceLink url="#" title={part.title} />
103
+ case 'data':
104
+ return <DataPart name={part.name} data={part.data} />
105
+ }
106
+ }
107
+
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="text-muted-foreground flex cursor-pointer select-none items-center gap-2 py-1 text-xs">
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="text-muted-foreground ml-4 mt-1 whitespace-pre-wrap text-xs italic leading-relaxed">
128
+ {text}
129
+ </div>
130
+ )}
131
+ </details>
132
+ )
133
+ }
134
+
135
+ type FilePartProps = { mediaType: string; url: string; filename?: string }
136
+ function FilePart({ mediaType, url, filename }: FilePartProps) {
137
+ return (
138
+ <div className="text-muted-foreground text-xs">
139
+ 📎 {filename ?? url} ({mediaType})
140
+ </div>
141
+ )
142
+ }
143
+
144
+ type SourceLinkProps = { url: string; title?: string }
145
+ function SourceLink({ url, title }: SourceLinkProps) {
146
+ return (
147
+ <a href={url} target="_blank" rel="noreferrer" className="text-xs underline">
148
+ {title ?? url}
149
+ </a>
150
+ )
151
+ }
152
+
153
+ type DataPartProps = { name: string; data: unknown }
154
+ function DataPart({ name, data }: DataPartProps) {
155
+ return (
156
+ <details>
157
+ <summary className="text-muted-foreground cursor-pointer text-xs">data:{name}</summary>
158
+ <pre className="bg-muted text-muted-foreground mt-1 overflow-auto rounded p-2 text-xs">
159
+ {JSON.stringify(data, null, 2)}
160
+ </pre>
161
+ </details>
162
+ )
163
+ }
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 select-none items-center gap-2 py-1.5">
200
+ <IconChevronRight
201
+ size={12}
202
+ stroke={1.5}
203
+ className="chevron text-ring shrink-0 transition-transform duration-150 group-open:rotate-90"
204
+ />
205
+ <CallerBadge call={call} />
206
+ <span className="whitespace-nowrap text-xs font-medium">{getToolDisplayName(call)}</span>
207
+ <span className="text-ring truncate text-[11px]">{formatInputBrief(call, cwd)}</span>
208
+ {isRunning && <IconLoader2 size={12} stroke={1.5} className="text-ring animate-spin" />}
209
+ </summary>
210
+ {(output || isError) && (
211
+ <div
212
+ className={cn(
213
+ 'ml-4 mt-1 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 whitespace-pre-wrap break-all font-mono text-xs leading-relaxed',
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 select-none items-center gap-2 py-1.5">
273
+ <IconChevronRight
274
+ size={12}
275
+ stroke={1.5}
276
+ className="chevron text-ring shrink-0 transition-transform duration-150 group-open:rotate-90"
277
+ />
278
+ <span className="bg-muted block size-4 shrink-0 overflow-hidden rounded-[3px]">
279
+ {iconSrc ? (
280
+ <img src={iconSrc} alt="" className="size-full object-cover" />
281
+ ) : (
282
+ <IconPlug size={12} stroke={1.5} className="text-muted-foreground m-0.5" />
283
+ )}
284
+ </span>
285
+ <span className="whitespace-nowrap text-xs font-medium">
286
+ {formatMcpServerName(mcp.server)} MCP
287
+ </span>
288
+ <span className="text-ring truncate text-[11px]">{brief}</span>
289
+ {isRunning && <IconLoader2 size={12} stroke={1.5} className="text-ring animate-spin" />}
290
+ </summary>
291
+ {(output || isError) && (
292
+ <div
293
+ className={cn(
294
+ 'ml-4 mt-1 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 whitespace-pre-wrap break-all font-mono text-xs leading-relaxed',
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="text-ring animate-spin" />}
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-muted-foreground text-[11px] underline"
334
+ >
335
+ {showBody ? 'hide' : 'show'} instructions
336
+ </button>
337
+ )}
338
+ </div>
339
+ {showBody && body && (
340
+ <pre className="bg-muted text-muted-foreground max-h-[300px] overflow-y-auto whitespace-pre-wrap rounded p-3 font-mono text-xs leading-relaxed">
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="text-ring animate-spin" />,
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="border-border bg-muted/40 hover:bg-muted/70 flex items-center gap-2 rounded-md border px-3 py-2 text-left transition-colors"
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="text-muted-foreground mt-0.5 truncate text-[11px]">{latest}</div>
382
+ )}
383
+ {status !== 'running' && subagent.usage?.toolUses != null && (
384
+ <div className="text-muted-foreground mt-0.5 text-[11px]">
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="bg-background flex max-h-[80vh] w-[min(800px,100%)] flex-col overflow-hidden rounded-lg shadow-xl"
409
+ onClick={e => e.stopPropagation()}
410
+ >
411
+ <header className="border-border flex items-start justify-between gap-3 border-b 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="text-muted-foreground mt-0.5 text-[11px]">
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="border-border w-52 shrink-0 border-r pr-4">
436
+ <div className="text-muted-foreground mb-2 text-[11px] font-medium uppercase">
437
+ Progress
438
+ </div>
439
+ <ol className="flex flex-col gap-1">
440
+ {subagent.progress.map((p, i) => (
441
+ <li key={i} className="text-muted-foreground truncate text-[11px]">
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="text-muted-foreground cursor-pointer text-[11px]">
452
+ Prompt
453
+ </summary>
454
+ <pre className="bg-muted text-muted-foreground mt-1 whitespace-pre-wrap rounded p-2 font-mono text-xs">
455
+ {JSON.stringify(call.input, null, 2)}
456
+ </pre>
457
+ </details>
458
+ )}
459
+ {subagent.transcript.length === 0 ? (
460
+ <div className="text-muted-foreground text-xs">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="border-border text-muted-foreground rounded border px-1 text-[9px] 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="border-border text-muted-foreground rounded border px-1 text-[9px] 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
+ }
@@ -0,0 +1,46 @@
1
+ import { Component, type ErrorInfo, type ReactNode } from 'react'
2
+
3
+ import { IconAlertTriangle } from '@tabler/icons-react'
4
+
5
+ type Props = {
6
+ name: string
7
+ resetKey: number
8
+ children: ReactNode
9
+ }
10
+
11
+ type State = { error: Error | null }
12
+
13
+ export class WidgetErrorBoundary extends Component<Props, State> {
14
+ state: State = { error: null }
15
+
16
+ static getDerivedStateFromError(error: Error): State {
17
+ return { error }
18
+ }
19
+
20
+ componentDidCatch(error: Error, info: ErrorInfo) {
21
+ console.error(`[widget:${this.props.name}]`, error, info.componentStack)
22
+ }
23
+
24
+ componentDidUpdate(prev: Props) {
25
+ if (prev.resetKey !== this.props.resetKey && this.state.error) {
26
+ this.setState({ error: null })
27
+ }
28
+ }
29
+
30
+ render() {
31
+ if (this.state.error) {
32
+ return (
33
+ <div className="flex h-full w-full flex-col items-start justify-start gap-1.5 p-4 text-xs">
34
+ <div className="text-destructive flex items-center gap-1.5 font-semibold">
35
+ <IconAlertTriangle size={14} stroke={1.5} />
36
+ Widget crashed
37
+ </div>
38
+ <div className="text-muted-foreground break-words font-mono">
39
+ {this.state.error.message}
40
+ </div>
41
+ </div>
42
+ )
43
+ }
44
+ return this.props.children
45
+ }
46
+ }