moi-computer 0.9.0 → 0.9.1-next.0

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 (87) hide show
  1. package/client/assets/hermes.png +0 -0
  2. package/client/components/shared/IconGhost.tsx +15 -18
  3. package/client/components/ui/button.tsx +2 -2
  4. package/client/components/ui/hover-card.tsx +1 -1
  5. package/client/components/ui/popover.tsx +3 -1
  6. package/client/features/chat/ChatEmptyState.tsx +25 -7
  7. package/client/features/chat/ChatPanel.tsx +70 -28
  8. package/client/features/chat/ChatPopup.tsx +3 -2
  9. package/client/features/chat/ChatPromptBubbles.tsx +1 -1
  10. package/client/features/chat/MarkdownContent.tsx +1 -1
  11. package/client/features/chat/attachment-staging.ts +153 -0
  12. package/client/features/chat/chat-send.ts +55 -0
  13. package/client/features/chat/chat-store.ts +32 -8
  14. package/client/features/chat/composer/ChatComposer.tsx +190 -77
  15. package/client/features/chat/{ModelPicker.tsx → composer/ModelPicker.tsx} +29 -25
  16. package/client/features/chat/composer/banners/ComposerBanner.tsx +1 -1
  17. package/client/features/chat/composer/banners/WorkspaceAgentAvailabilityBanner.tsx +4 -13
  18. package/client/features/chat/{model-order.ts → composer/model-order.ts} +16 -0
  19. package/client/features/chat/composer/useWorkspaceComposerState.tsx +9 -4
  20. package/client/features/chat/tool-group/format/claude.ts +48 -0
  21. package/client/features/chat/tool-group/format/codex.ts +126 -0
  22. package/client/features/chat/tool-group/format/hermes.ts +68 -0
  23. package/client/features/chat/tool-group/format/index.ts +34 -0
  24. package/client/features/chat/tool-group/format/mcp.ts +64 -0
  25. package/client/features/chat/tool-group/format/openclaw.ts +116 -0
  26. package/client/features/chat/tool-group/format/shared.ts +49 -0
  27. package/client/features/chat/useChat.ts +5 -10
  28. package/client/features/drawings/DrawingLayer.tsx +49 -0
  29. package/client/features/drawings/DrawingToolbar.tsx +95 -0
  30. package/client/features/drawings/annotation-availability.ts +10 -0
  31. package/client/features/drawings/capture-element.ts +45 -0
  32. package/client/features/drawings/useChatAnnotation.ts +222 -0
  33. package/client/features/drawings/useDrawingLayer.ts +758 -0
  34. package/client/features/drawings/useViewBuilderSketch.ts +151 -0
  35. package/client/features/home/workspace-presentation.tsx +6 -2
  36. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +12 -6
  37. package/client/features/scratchpad/ScratchpadControls.tsx +19 -5
  38. package/client/features/views/ViewBuilder.tsx +224 -0
  39. package/client/features/views/api.ts +1 -0
  40. package/client/features/views/useViewBuilderActions.ts +24 -3
  41. package/client/features/views/useViewBuilderDrafts.ts +66 -0
  42. package/client/features/widgets/Widgets.tsx +23 -39
  43. package/client/features/workspace/CustomizePanel.tsx +1 -1
  44. package/client/features/workspace/WorkspaceScreen.tsx +157 -57
  45. package/client/features/workspace/WorkspaceTabs.tsx +3 -3
  46. package/client/features/workspace/useFitsSplitLayout.ts +14 -8
  47. package/client/index.css +8 -0
  48. package/client/store/ui.ts +19 -0
  49. package/client/theme.css +33 -8
  50. package/dist/chunk-3becmq75.js +81 -0
  51. package/dist/{chunk-kkj86722.js → chunk-6w6j9g4b.js} +78 -78
  52. package/dist/{chunk-xeyxk7ep.js → chunk-8ew39cvq.js} +4 -4
  53. package/dist/chunk-c8gtrjwp.js +1 -0
  54. package/dist/{chunk-2vaafjp4.js → chunk-pp62fnxh.js} +1 -1
  55. package/dist/{chunk-35fq49qa.js → chunk-sxc24vfp.js} +1 -1
  56. package/dist/{chunk-3b3rkjet.js → chunk-v964b5g7.js} +1 -1
  57. package/dist/chunk-zx33ts9d.css +1 -0
  58. package/dist/hermes-pznd63x9.png +0 -0
  59. package/dist/index.html +1 -1
  60. package/lib/format.ts +1 -1
  61. package/lib/themes.ts +8 -8
  62. package/lib/types.ts +8 -1
  63. package/lib/workspace-types.ts +2 -1
  64. package/package.json +2 -1
  65. package/server/api.ts +21 -2
  66. package/server/cli.ts +188 -3
  67. package/server/harness/README.md +64 -17
  68. package/server/harness/acp/adapter.ts +220 -0
  69. package/server/harness/acp/archived.ts +88 -0
  70. package/server/harness/acp/client.ts +328 -0
  71. package/server/harness/acp/discovery.ts +130 -0
  72. package/server/harness/acp/run-durations.ts +68 -0
  73. package/server/harness/acp/session.ts +788 -0
  74. package/server/harness/acp/wire.ts +132 -0
  75. package/server/harness/executable.ts +15 -1
  76. package/server/harness/hermes/NOTES.md +815 -0
  77. package/server/harness/hermes/discovery.ts +155 -0
  78. package/server/harness/hermes/index.ts +155 -0
  79. package/server/harness/hermes/models.ts +79 -0
  80. package/server/harness/registry.ts +3 -1
  81. package/server/view-builders.ts +4 -2
  82. package/server/workspace-import.ts +30 -1
  83. package/client/features/chat/tool-group/format.ts +0 -384
  84. package/client/features/views/ViewBuilderTab.tsx +0 -152
  85. package/dist/chunk-gt7n06ef.js +0 -1
  86. package/dist/chunk-ty1sqbmn.js +0 -80
  87. package/dist/chunk-yz6wd5vc.css +0 -1
@@ -1,384 +0,0 @@
1
- // Formatting utils for tool rows: turn a raw ToolCall into the display name and
2
- // one-line brief, and parse the two MCP call shapes. Pure functions, no React.
3
- import { relative } from 'pathe'
4
-
5
- import type { ToolCall } from '@/lib/types'
6
-
7
- export type McpRef = { server: string; tool: string; rest: string }
8
-
9
- // Detect a `mcporter call <server>.<tool> [args...]` invocation inside a shell
10
- // command. Accepts any prefix (env VAR=…, `$(which mcporter)`, `npx mcporter`),
11
- // stops at the first command separator so a chained command doesn't bleed into
12
- // `rest`. Returns null for non-`call` invocations.
13
- export function parseMcporterCall(call: ToolCall): McpRef | null {
14
- const isShell = call.name === 'Bash' || call.name === 'exec'
15
- if (!isShell) return null
16
- const input = (call.input as Record<string, unknown>) ?? {}
17
- const command = typeof input.command === 'string' ? input.command : ''
18
- if (!command) return null
19
- const m = command.match(
20
- /(?:^|\s|\$\()mcporter(?:\)?)\s+call\s+([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]+)((?:\s+(?!&&|\|\||;|\|)\S+)*)/
21
- )
22
- if (!m) return null
23
- return { server: m[1], tool: m[2], rest: (m[3] ?? '').trim() }
24
- }
25
-
26
- // Native MCP tool calls arrive as `mcp__<server>__<tool>` (the server is encoded
27
- // in the name; `caller` is `model` and `mcpServer` is unset). Server tokens use
28
- // single underscores, so split on the FIRST `__` after the prefix.
29
- // e.g. `mcp__notion__notion-search` → notion / notion-search.
30
- export function parseNativeMcp(call: ToolCall): McpRef | null {
31
- const name = call.name
32
- if (!name.startsWith('mcp__')) return null
33
- const rest = name.slice(5)
34
- const i = rest.indexOf('__')
35
- if (i <= 0) return null
36
- return { server: rest.slice(0, i), tool: rest.slice(i + 2), rest: '' }
37
- }
38
-
39
- // Codex MCP calls arrive with a real `mcpServer` field and a plain tool name.
40
- // Two shapes get the server-branded card:
41
- // - a call against a configured server (`server: "codex_apps"`), where app
42
- // tools are dotted `<app>.<tool>` (`resume_io.build_resume_with_templates`)
43
- // — brand by the app, not the host;
44
- // - anything else brands by the server itself.
45
- // Codex's own MCP-management pseudo-tools (`server: "codex"`, or the
46
- // list/read management names on any server) stay plain rows — they're
47
- // runtime introspection, not a call INTO a server (see CODEX_TOOL_LABELS).
48
- export function parseCodexMcp(call: ToolCall): McpRef | null {
49
- if (call.provider !== 'codex' || !call.mcpServer) return null
50
- if (call.name in CODEX_TOOL_LABELS) return null
51
- if (call.mcpServer === 'codex') return null
52
- const dot = call.name.indexOf('.')
53
- if (dot > 0) return { server: call.name.slice(0, dot), tool: call.name.slice(dot + 1), rest: '' }
54
- return { server: call.mcpServer, tool: call.name, rest: '' }
55
- }
56
-
57
- // Drop the redundant server prefix many MCP tools repeat — the icon + server name
58
- // already identify it: `notion-search` → `search`, `notion-get-teams` →
59
- // `get-teams`. Tools that don't repeat the server pass through unchanged.
60
- export function formatMcpTool(server: string, tool: string): string {
61
- const lower = tool.toLowerCase()
62
- const sep = ['-', '_', '.'].find(s => lower.startsWith(server.toLowerCase() + s))
63
- return sep ? tool.slice(server.length + 1) : tool
64
- }
65
-
66
- function getInputValue(input: Record<string, unknown>, key: string): string {
67
- const value = input[key]
68
- return typeof value === 'string' ? value : ''
69
- }
70
-
71
- // Compact wall-clock duration in whole seconds: under a minute → "3s", longer
72
- // → "1m 5s". Used on agent-run and subagent duration labels.
73
- //
74
- // Never milliseconds. A column of "Thought for 514ms" / "Thought for 784ms"
75
- // rows reads as jitter — the exact figure is noise at this size, and the
76
- // varying width makes the list look ragged next to a plain "Thought for 1s".
77
- // Sub-second durations round UP so a real pause never renders as "0s".
78
- export function formatDuration(ms: number): string {
79
- const s = Math.max(1, Math.round(ms / 1000))
80
- if (s < 60) return `${s}s`
81
- const m = Math.floor(s / 60)
82
- const rem = s % 60
83
- return rem ? `${m}m ${rem}s` : `${m}m`
84
- }
85
-
86
- function makeShortenPaths(cwd: string | null) {
87
- return (s: string) =>
88
- s.replace(/\/[^\s"']+/g, p => {
89
- if (!cwd) return p
90
- const rel = relative(cwd, p)
91
- return rel.startsWith('..') ? p : rel
92
- })
93
- }
94
-
95
- // Tool name → user-facing label, picked per provider. Adapters send the raw
96
- // upstream tool name; the UI humanizes it. Unknown names fall through to the raw
97
- // name so plugin tools still render something.
98
- const OPENCLAW_TOOL_LABELS: Record<string, string> = {
99
- read: 'Read file',
100
- write: 'Write file',
101
- edit: 'Edit file',
102
- apply_patch: 'Edit',
103
- exec: 'Bash',
104
- // 2026.7.2+ renamed the shell tool `bash` and split filesystem tools out.
105
- bash: 'Bash',
106
- ls: 'List files',
107
- find: 'Find files',
108
- grep: 'Search',
109
- process: 'Manage process',
110
- web_search: 'Web search',
111
- web_fetch: 'Fetch',
112
- sessions_list: 'List sessions',
113
- sessions_history: 'Recall session',
114
- sessions_yield: 'Yield to session',
115
- sessions_send: 'Send to session',
116
- sessions_spawn: 'Spawn session',
117
- subagents: 'Run sub-agent',
118
- agents_list: 'List agents',
119
- session_status: 'Session status',
120
- image: 'Analyze image',
121
- image_generate: 'Generate image',
122
- memory_get: 'Read memory',
123
- memory_search: 'Search memory',
124
- update_plan: 'Update plan',
125
- message: 'Send message',
126
- browser: 'Browser',
127
- canvas: 'Canvas',
128
- cron: 'Cron',
129
- gateway: 'Gateway',
130
- code_execution: 'Run Python',
131
- tts: 'Text-to-speech',
132
- music_generate: 'Generate music',
133
- video_generate: 'Generate video',
134
- x_search: 'Search X'
135
- }
136
-
137
- // Claude tool names are mostly already presentable (Read, Bash, …); only a few
138
- // need spacing/relabelling.
139
- const CLAUDE_TOOL_LABELS: Record<string, string> = {
140
- ToolSearch: 'Tool search',
141
- WebSearch: 'Web search',
142
- WebFetch: 'Web fetch'
143
- }
144
-
145
- // Codex emits semantic items, which the adapter maps to a small fixed set of
146
- // tool names (plus raw MCP tool names, which fall through unchanged).
147
- const CODEX_TOOL_LABELS: Record<string, string> = {
148
- exec: 'Bash',
149
- apply_patch: 'Edit',
150
- web_search: 'Web search',
151
- update_plan: 'Update plan',
152
- subagent: 'Run sub-agent',
153
- subagent_activity: 'Sub-agent',
154
- review: 'Review',
155
- view_image: 'View image',
156
- generate_image: 'Generate image',
157
- // MCP-management introspection (can arrive under any server, incl. the
158
- // "codex" pseudo-server) — plain rows, never the server-branded card.
159
- list_mcp_resources: 'List MCP resources',
160
- list_mcp_resource_templates: 'List MCP templates',
161
- read_mcp_resource: 'Read MCP resource'
162
- }
163
-
164
- // Codex classifies each shell command itself (`commandActions`, one entry per
165
- // piped command). When every action agrees on a type, use a CC-style semantic
166
- // label instead of "Bash".
167
- type CodexCommandAction = { type?: string; name?: string; path?: string; query?: string | null }
168
-
169
- const CODEX_ACTION_LABELS: Record<string, string> = {
170
- read: 'Read',
171
- listFiles: 'List files',
172
- search: 'Search'
173
- }
174
-
175
- function codexExecAction(input: unknown): CodexCommandAction | null {
176
- const actions = (input as { commandActions?: unknown } | null)?.commandActions
177
- if (!Array.isArray(actions) || actions.length === 0) return null
178
- const first = actions[0] as CodexCommandAction
179
- const type = first?.type
180
- if (!type || !(type in CODEX_ACTION_LABELS)) return null
181
- if (actions.some(a => (a as CodexCommandAction)?.type !== type)) return null
182
- return first
183
- }
184
-
185
- // Codex collab tool actions (`input.action` on the `subagent` card). `wait`
186
- // never reaches the UI — the adapter drops it.
187
- const CODEX_SUBAGENT_ACTION_LABELS: Record<string, string> = {
188
- spawn_agent: 'Run sub-agent',
189
- send_input: 'Message the agent',
190
- resume_agent: 'Resume the agent',
191
- close_agent: 'Stopping the agent'
192
- }
193
-
194
- export function getToolDisplayName(call: ToolCall): string {
195
- // An OpenClaw agent pinned to the `claude-cli` runtime reports Claude Code's
196
- // own tool names (`Read`, `Bash`, `Edit`, …) rather than OpenClaw's, so the
197
- // Claude vocabulary is the fallback before giving up and showing the raw name.
198
- if (call.provider === 'openclaw') {
199
- return OPENCLAW_TOOL_LABELS[call.name] ?? CLAUDE_TOOL_LABELS[call.name] ?? call.name
200
- }
201
- if (call.provider === 'codex') {
202
- if (call.name === 'exec') {
203
- const action = codexExecAction(call.input)
204
- if (action?.type) return CODEX_ACTION_LABELS[action.type]
205
- }
206
- if (call.name === 'subagent') {
207
- const action = (call.input as { action?: unknown } | null)?.action
208
- if (typeof action === 'string' && action in CODEX_SUBAGENT_ACTION_LABELS) {
209
- return CODEX_SUBAGENT_ACTION_LABELS[action]
210
- }
211
- }
212
- return CODEX_TOOL_LABELS[call.name] ?? call.name
213
- }
214
- return CLAUDE_TOOL_LABELS[call.name] ?? call.name
215
- }
216
-
217
- // Short tool label from a fully-qualified MCP tool name: `mcp__notion__notion-
218
- // search` → `notion-search` (drop the `mcp__<server>__` prefix). Plain names
219
- // pass through.
220
- function shortToolName(name: string): string {
221
- if (!name.startsWith('mcp__')) return name
222
- const parts = name.slice(5).split('__')
223
- return parts.length >= 2 ? parts.slice(1).join('__') : parts[0]
224
- }
225
-
226
- export function formatInputBrief(call: ToolCall, cwd: string | null): string {
227
- const input = (call.input as Record<string, unknown>) ?? {}
228
- const shorten = makeShortenPaths(cwd)
229
- if (call.provider === 'openclaw') {
230
- // Same fallback as the label: a claude-cli-backed run carries Claude Code's
231
- // tool names and argument keys (`file_path`, not `path`).
232
- return (
233
- formatOpenClawBrief(call.name, input, shorten) || formatClaudeBrief(call.name, input, shorten)
234
- )
235
- }
236
- if (call.provider === 'codex') return formatCodexBrief(call.name, input, shorten)
237
- return formatClaudeBrief(call.name, input, shorten)
238
- }
239
-
240
- function formatCodexBrief(
241
- tool: string,
242
- input: Record<string, unknown>,
243
- shorten: (s: string) => string
244
- ): string {
245
- if (tool === 'exec') {
246
- // Semantic brief when Codex classified the command (label says Read/
247
- // Search/List files); raw command otherwise.
248
- const action = codexExecAction(input)
249
- if (action?.type === 'read') return shorten(action.path || action.name || '')
250
- if (action?.type === 'search')
251
- return [action.query && `/${action.query}/`, action.path && shorten(action.path)]
252
- .filter(Boolean)
253
- .join(' ')
254
- if (action?.type === 'listFiles') return action.path ? shorten(action.path) : ''
255
- return shorten(`$ ${getInputValue(input, 'command')}`)
256
- }
257
- if (tool === 'apply_patch') {
258
- // The adapter sends structured per-file changes: [{ path, kind, diff }].
259
- const changes = input.changes
260
- if (Array.isArray(changes)) {
261
- const paths = changes
262
- .map(c => (c && typeof c === 'object' ? (c as { path?: unknown }).path : undefined))
263
- .filter((p): p is string => typeof p === 'string')
264
- .map(shorten)
265
- return paths.join(', ')
266
- }
267
- return ''
268
- }
269
- if (tool === 'web_search') {
270
- // Multi-query fan-outs carry every query in `queries`; single searches
271
- // just have `query`.
272
- const queries = input.queries
273
- if (Array.isArray(queries) && queries.length > 0) {
274
- return queries.filter((q): q is string => typeof q === 'string').join(' · ')
275
- }
276
- return getInputValue(input, 'query')
277
- }
278
- if (tool === 'update_plan') {
279
- const plan = input.plan
280
- return typeof plan === 'string' ? plan.split('\n')[0] : ''
281
- }
282
- if (tool === 'subagent') {
283
- // The label already names the action; the brief carries the text being
284
- // sent (spawn prompt, send_input/resume_agent message). close_agent has
285
- // none — the label alone reads fine.
286
- if (getInputValue(input, 'action') === 'close_agent') return ''
287
- return getInputValue(input, 'prompt')
288
- }
289
- if (tool === 'subagent_activity') return getInputValue(input, 'kind')
290
- if (tool === 'generate_image') return getInputValue(input, 'prompt').split('\n')[0]
291
- if (tool === 'read_mcp_resource') return getInputValue(input, 'uri')
292
- if (tool === 'list_mcp_resources' || tool === 'list_mcp_resource_templates')
293
- return getInputValue(input, 'server')
294
- return ''
295
- }
296
-
297
- function formatClaudeBrief(
298
- tool: string,
299
- input: Record<string, unknown>,
300
- shorten: (s: string) => string
301
- ): string {
302
- if (tool === 'Bash') return shorten(`$ ${getInputValue(input, 'command')}`)
303
- if (tool === 'Read' || tool === 'Write' || tool === 'Edit')
304
- return shorten(getInputValue(input, 'file_path'))
305
- if (tool === 'Glob') return shorten(getInputValue(input, 'pattern'))
306
- if (tool === 'Grep')
307
- return `/${getInputValue(input, 'pattern')}/ ${shorten(getInputValue(input, 'path'))}`
308
- if (tool === 'WebSearch') return getInputValue(input, 'query')
309
- if (tool === 'WebFetch') return getInputValue(input, 'url')
310
- if (tool === 'ToolSearch') {
311
- const query = getInputValue(input, 'query')
312
- // `select:a,b,c` loads those tools → list their short names; otherwise it's a
313
- // free-text discovery query → show it as-is.
314
- if (query.startsWith('select:')) return query.slice(7).split(',').map(shortToolName).join(', ')
315
- return query
316
- }
317
- return ''
318
- }
319
-
320
- function formatOpenClawBrief(
321
- tool: string,
322
- input: Record<string, unknown>,
323
- shorten: (s: string) => string
324
- ): string {
325
- if (tool === 'read' || tool === 'write' || tool === 'edit')
326
- return shorten(getInputValue(input, 'path'))
327
- if (tool === 'apply_patch') {
328
- // The codex runtime describes an edit structurally: `{ changes: [{ path,
329
- // kind }] }` (captured live on 2026.7.1). Name the file, or count them when
330
- // one patch touches several.
331
- const changes = input.changes
332
- if (Array.isArray(changes) && changes.length > 0) {
333
- const paths = changes
334
- .map(c =>
335
- c && typeof c === 'object' ? getInputValue(c as Record<string, unknown>, 'path') : ''
336
- )
337
- .filter(Boolean)
338
- if (paths.length === 1) return shorten(paths[0])
339
- if (paths.length > 1) return `${paths.length} files`
340
- }
341
- // Older shape: the raw patch text, whose `*** ` header names the file.
342
- const patch = getInputValue(input, 'patch') || getInputValue(input, 'input')
343
- const firstLine = patch.split('\n').find(l => l.startsWith('*** ')) ?? patch.split('\n')[0]
344
- return shorten(firstLine ?? '')
345
- }
346
- if (tool === 'exec' || tool === 'bash') {
347
- // `command` on 2026.7.1 + the newer `bash` tool; the 2026.7.2 exec sandbox
348
- // instead carries a `code` script (JS that shells out) — show whichever.
349
- const command = getInputValue(input, 'command') || getInputValue(input, 'code')
350
- return command ? shorten(`$ ${command}`) : ''
351
- }
352
- if (tool === 'ls' || tool === 'find' || tool === 'grep')
353
- return shorten(getInputValue(input, 'path') || getInputValue(input, 'pattern'))
354
- if (tool === 'process') {
355
- const action = getInputValue(input, 'action')
356
- const name = getInputValue(input, 'name')
357
- return [action, name].filter(Boolean).join(' ') || shorten(getInputValue(input, 'command'))
358
- }
359
- if (tool === 'web_search' || tool === 'x_search') return getInputValue(input, 'query')
360
- if (tool === 'web_fetch') return getInputValue(input, 'url')
361
- if (tool === 'memory_search') return getInputValue(input, 'query')
362
- if (tool === 'memory_get') return getInputValue(input, 'key') || getInputValue(input, 'name')
363
- if (tool === 'sessions_history' || tool === 'sessions_send' || tool === 'sessions_yield')
364
- return getInputValue(input, 'sessionKey') || getInputValue(input, 'agentId')
365
- if (tool === 'sessions_list' || tool === 'agents_list') return getInputValue(input, 'agentId')
366
- if (tool === 'subagents' || tool === 'sessions_spawn')
367
- return getInputValue(input, 'task') || getInputValue(input, 'agentId')
368
- if (tool === 'image' || tool === 'image_generate')
369
- return getInputValue(input, 'prompt') || shorten(getInputValue(input, 'path'))
370
- if (tool === 'message') return getInputValue(input, 'recipient') || getInputValue(input, 'to')
371
- if (tool === 'update_plan') {
372
- const plan = input.plan
373
- if (Array.isArray(plan)) {
374
- const inProgress = plan.find(
375
- (p): p is { step: string } =>
376
- !!p && typeof p === 'object' && (p as { status?: unknown }).status === 'in_progress'
377
- )
378
- const step = inProgress?.step ?? (plan[0] as { step?: unknown })?.step
379
- if (typeof step === 'string') return step
380
- }
381
- return ''
382
- }
383
- return ''
384
- }
@@ -1,152 +0,0 @@
1
- import { type FormEvent, type KeyboardEvent, useEffect, useRef, useState } from 'react'
2
-
3
- import { Button } from '@/client/components/ui/button'
4
- import {
5
- canSubmitComposerAction,
6
- type ComposerAvailability,
7
- Composer,
8
- ComposerFooter,
9
- ComposerSubmitButton,
10
- ComposerTextarea
11
- } from '@/client/components/shared/Composer'
12
- import { ModelPicker } from '@/client/features/chat/ModelPicker'
13
- import type { ViewBuilder } from '@/lib/types'
14
- import { Spinner } from '@/client/components/ui/spinner'
15
-
16
- type ViewBuilderTabProps = {
17
- builder: ViewBuilder
18
- composerAvailability: ComposerAvailability
19
- onSave: (requirements: string) => Promise<unknown>
20
- onSubmit: (requirements: string) => Promise<unknown>
21
- onOpenChat: () => void
22
- onDiscard: () => void
23
- }
24
-
25
- export function ViewBuilderTab({
26
- builder,
27
- composerAvailability,
28
- onSave,
29
- onSubmit,
30
- onOpenChat,
31
- onDiscard
32
- }: ViewBuilderTabProps) {
33
- const [requirements, setRequirements] = useState(builder.input.requirements)
34
- const [submitting, setSubmitting] = useState(false)
35
- const [saveError, setSaveError] = useState<string | null>(null)
36
- const composerRef = useRef<HTMLTextAreaElement>(null)
37
- const onSaveRef = useRef(onSave)
38
- onSaveRef.current = onSave
39
- const hasRequirements = requirements.trim().length > 0
40
- const canSubmit = canSubmitComposerAction(hasRequirements, submitting, composerAvailability)
41
-
42
- useEffect(() => {
43
- if (builder.status !== 'draft' || requirements === builder.input.requirements) return
44
- const timer = setTimeout(() => {
45
- void onSaveRef
46
- .current(requirements)
47
- .then(() => setSaveError(null))
48
- .catch(error =>
49
- setSaveError(error instanceof Error ? error.message : 'Could not save requirements')
50
- )
51
- }, 500)
52
- return () => clearTimeout(timer)
53
- }, [builder.input.requirements, builder.status, requirements])
54
-
55
- const submit = async (event: FormEvent) => {
56
- event.preventDefault()
57
- if (!canSubmit) return
58
- setSubmitting(true)
59
- try {
60
- await onSubmit(requirements)
61
- } catch (error) {
62
- setSaveError(error instanceof Error ? error.message : 'Could not start view builder')
63
- setSubmitting(false)
64
- }
65
- }
66
-
67
- if (builder.status === 'draft') {
68
- return (
69
- <div className="flex min-h-0 flex-1 items-center justify-center px-3 py-6">
70
- <div className="flex w-full max-w-(--chat-max-container) flex-col gap-6">
71
- <div className="flex flex-col gap-1 text-center">
72
- <h1 className="font-medium">What should this view do?</h1>
73
- <p className="mx-auto max-w-sm text-sm text-muted-foreground">
74
- Describe the content, data, and actions you need.
75
- </p>
76
- </div>
77
- <Composer composerRef={composerRef} onSubmit={submit}>
78
- <label className="sr-only" htmlFor={`view-builder-${builder.id}`}>
79
- View requirements
80
- </label>
81
- <ComposerTextarea
82
- textareaRef={composerRef}
83
- id={`view-builder-${builder.id}`}
84
- value={requirements}
85
- onChange={event => setRequirements(event.target.value)}
86
- onKeyDown={(event: KeyboardEvent<HTMLTextAreaElement>) => {
87
- if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
88
- event.preventDefault()
89
- event.currentTarget.form?.requestSubmit()
90
- }
91
- }}
92
- placeholder="Build a customer dashboard with…"
93
- rows={1}
94
- className="min-h-16"
95
- aria-describedby={saveError ? `view-builder-error-${builder.id}` : undefined}
96
- aria-invalid={Boolean(saveError)}
97
- autoFocus
98
- />
99
- <ComposerFooter>
100
- <ModelPicker scope="workspace" />
101
- <ComposerSubmitButton
102
- label="Build view"
103
- hasContent={hasRequirements}
104
- loading={submitting}
105
- availability={composerAvailability}
106
- />
107
- </ComposerFooter>
108
- </Composer>
109
- {saveError && (
110
- <p
111
- id={`view-builder-error-${builder.id}`}
112
- role="alert"
113
- className="text-sm text-destructive"
114
- >
115
- {saveError}
116
- </p>
117
- )}
118
- </div>
119
- </div>
120
- )
121
- }
122
-
123
- if (builder.status === 'waiting') {
124
- return (
125
- <div className="flex min-h-0 flex-1 items-center justify-center p-6">
126
- <div className="flex max-w-md flex-col items-center gap-4 text-center">
127
- <div className="flex flex-col gap-1">
128
- <h1 className="text-lg font-semibold">The view needs your attention</h1>
129
- <p className="text-sm text-muted-foreground">
130
- {builder.error ?? 'Open its chat to answer or ask the agent to continue.'}
131
- </p>
132
- </div>
133
- <div className="flex gap-2">
134
- <Button onClick={onOpenChat}>Open chat</Button>
135
- <Button variant="secondary" onClick={onDiscard}>
136
- Discard
137
- </Button>
138
- </div>
139
- </div>
140
- </div>
141
- )
142
- }
143
-
144
- return (
145
- <div className="flex min-h-0 flex-1 items-center justify-center p-6">
146
- <div className="flex items-center gap-2 text-sm text-muted-foreground">
147
- <Spinner />
148
- {builder.status === 'ready' ? 'Opening view…' : 'Building view…'}
149
- </div>
150
- </div>
151
- )
152
- }
@@ -1 +0,0 @@
1
- import{a}from"/chunk-pcnahct1.js";import"/chunk-35fq49qa.js";export{a as sanitizeSvg};