moi-computer 0.3.0 → 0.3.1-next.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 (121) hide show
  1. package/client/api/workspace-keys.ts +2 -2
  2. package/client/app/AppRouter.tsx +0 -2
  3. package/client/app/routes/WorkspaceRoute.tsx +3 -1
  4. package/client/app/shell/SidebarLayout.tsx +3 -16
  5. package/client/assets/openai.svg +1 -3
  6. package/client/components/shared/Composer.tsx +112 -0
  7. package/client/components/ui/button.tsx +1 -1
  8. package/client/components/ui/dropdown-menu.tsx +3 -3
  9. package/client/components/ui/tooltip.tsx +12 -15
  10. package/client/features/applets/WidgetErrorBoundary.tsx +19 -3
  11. package/client/features/applets/WidgetShell.tsx +8 -1
  12. package/client/features/applets/applet-log.ts +100 -0
  13. package/client/features/applets/useApplet.ts +21 -7
  14. package/client/features/chat/ChatComposer.tsx +33 -30
  15. package/client/features/chat/ChatPanel.tsx +5 -2
  16. package/client/features/chat/MarkdownContent.tsx +20 -2
  17. package/client/features/chat/ModelPicker.tsx +29 -41
  18. package/client/features/chat/TurnView.tsx +2 -2
  19. package/client/features/chat/chat-frames.ts +14 -6
  20. package/client/features/chat/chat-send.ts +1 -1
  21. package/client/features/chat/chat-store.ts +22 -17
  22. package/client/features/chat/model-order.ts +47 -0
  23. package/client/features/chat/tool-group/ToolOutput.tsx +4 -12
  24. package/client/features/chat/tool-group/format.ts +0 -6
  25. package/client/features/chat/useChat.ts +15 -2
  26. package/client/features/connectors/McpServerCards.tsx +95 -0
  27. package/client/features/connectors/api.ts +0 -11
  28. package/client/features/home/HomePage.tsx +45 -42
  29. package/client/features/home/WorkspacePreview.tsx +179 -38
  30. package/client/features/home/api.ts +24 -12
  31. package/client/features/home/workspace-presentation.tsx +17 -15
  32. package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +243 -0
  33. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +95 -0
  34. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +230 -0
  35. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +35 -0
  36. package/client/features/home/workspace-setup/useWorkspaceImport.ts +61 -0
  37. package/client/features/settings/ConnectorsSettings.tsx +89 -0
  38. package/client/features/settings/GeneralSettings.tsx +12 -0
  39. package/client/features/settings/SettingsLayout.tsx +2 -2
  40. package/client/features/settings/WorkspaceSettings.tsx +8 -4
  41. package/client/features/views/ViewBuilderTab.tsx +28 -29
  42. package/client/features/views/useViewBuilderActions.ts +1 -1
  43. package/client/features/widgets/WidgetFrame.tsx +3 -0
  44. package/client/features/widgets/WidgetGrid.tsx +1 -0
  45. package/client/features/widgets/Widgets.tsx +12 -3
  46. package/client/features/widgets/api.ts +47 -0
  47. package/client/features/widgets/useWidgetThumbnails.ts +107 -0
  48. package/client/features/widgets/widget-snapshot.ts +71 -0
  49. package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -4
  50. package/client/features/workspace/WorkspaceScreen.tsx +19 -4
  51. package/client/features/workspace/api.ts +25 -3
  52. package/client/features/workspace/moi-context.ts +85 -0
  53. package/client/index.css +0 -5
  54. package/client/main.tsx +13 -4
  55. package/dist/{chunk-cs8vbert.js → chunk-1dfbr7n2.js} +2 -2
  56. package/dist/chunk-339jds4x.js +15 -0
  57. package/dist/chunk-3xsvsnhr.css +1 -0
  58. package/dist/{chunk-zpxrb1ce.js → chunk-anqmsbjt.js} +2 -2
  59. package/dist/chunk-hbvfb6sk.js +63 -0
  60. package/dist/chunk-jen6xcm1.js +14 -0
  61. package/dist/{chunk-kxmvv1ax.js → chunk-qwm5f6qk.js} +1 -1
  62. package/dist/{chunk-fjksw6xf.js → chunk-sxbfh73c.js} +1 -1
  63. package/dist/chunk-yp4srgqt.js +10 -0
  64. package/dist/index.html +1 -1
  65. package/dist/openai-ep9ht2pq.svg +1 -0
  66. package/lib/ids.ts +15 -0
  67. package/lib/moi-context.ts +170 -0
  68. package/lib/types.ts +95 -13
  69. package/lib/view-builder-directives.ts +16 -0
  70. package/lib/workspace-types.ts +12 -0
  71. package/package.json +4 -2
  72. package/server/api.ts +180 -34
  73. package/server/applet-log.ts +149 -0
  74. package/server/cli.ts +161 -7
  75. package/server/control.ts +81 -1
  76. package/server/functions.ts +44 -14
  77. package/server/harness/README.md +26 -9
  78. package/server/harness/claude-code/NOTES.md +20 -6
  79. package/server/harness/claude-code/adapter.ts +2 -2
  80. package/server/harness/claude-code/git-worktree.ts +32 -0
  81. package/server/harness/claude-code/index.ts +35 -13
  82. package/server/harness/claude-code/mcp.ts +16 -65
  83. package/server/harness/claude-code/models.ts +3 -0
  84. package/server/harness/claude-code/session.ts +196 -61
  85. package/server/harness/claude-code/sessions.ts +51 -0
  86. package/server/harness/codex/NOTES.md +41 -11
  87. package/server/harness/codex/adapter.ts +52 -6
  88. package/server/harness/codex/client.ts +69 -18
  89. package/server/harness/codex/discovery.ts +114 -0
  90. package/server/harness/codex/index.ts +12 -5
  91. package/server/harness/codex/probe.ts +4 -2
  92. package/server/harness/codex/session.ts +57 -5
  93. package/server/harness/executable.ts +82 -0
  94. package/server/harness/openclaw/adapter.ts +8 -1
  95. package/server/harness/openclaw/discovery.ts +139 -6
  96. package/server/harness/openclaw/gateway.ts +40 -18
  97. package/server/harness/openclaw/index.ts +12 -15
  98. package/server/harness/openclaw/session.ts +50 -10
  99. package/server/harness/openclaw/strip.ts +2 -2
  100. package/server/harness/shell-path.ts +79 -0
  101. package/server/harness/types.ts +37 -5
  102. package/server/layout.ts +81 -51
  103. package/server/registry.ts +57 -12
  104. package/server/scratchpad-assets.ts +41 -6
  105. package/server/scratchpad.ts +30 -0
  106. package/server/view-builders.ts +3 -2
  107. package/server/views.ts +5 -0
  108. package/server/web.ts +30 -8
  109. package/server/widgets.ts +23 -2
  110. package/server/workspace-import.ts +45 -0
  111. package/workspace/.claude/skills/moi-workspace/SKILL.md +27 -3
  112. package/client/features/connectors/ConnectorsPage.tsx +0 -92
  113. package/client/features/connectors/McpMenu.tsx +0 -145
  114. package/client/features/home/CreateWorkspaceDialog.tsx +0 -130
  115. package/client/features/home/CreateWorkspaceDialogSteps.tsx +0 -234
  116. package/dist/chunk-4vf1t6v1.js +0 -10
  117. package/dist/chunk-4z52b2av.css +0 -1
  118. package/dist/chunk-b4b276wx.js +0 -15
  119. package/dist/chunk-y82s1jxm.js +0 -61
  120. package/dist/openai-h13pza4b.svg +0 -3
  121. package/lib/view-builder-meta.ts +0 -35
@@ -1,14 +1,15 @@
1
1
  import { type RefObject, useRef, useState } from 'react'
2
2
 
3
- import {
4
- IconArrowUp,
5
- IconFile,
6
- IconLoader2,
7
- IconPaperclip,
8
- IconPlayerStop,
9
- IconX
10
- } from '@tabler/icons-react'
3
+ import { IconFile, IconLoader2, IconPaperclip, IconPlayerStop, IconX } from '@tabler/icons-react'
11
4
 
5
+ import {
6
+ canSubmitComposerAction,
7
+ Composer,
8
+ ComposerFooter,
9
+ ComposerSubmitButton,
10
+ ComposerTextarea
11
+ } from '@/client/components/shared/Composer'
12
+ import { Button } from '@/client/components/ui/button'
12
13
  import { cn } from '@/client/lib/cn'
13
14
  import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
14
15
  import { uploadFiles } from '@/client/features/chat/uploads'
@@ -20,13 +21,13 @@ import {
20
21
  } from '@/client/features/chat/chat-store'
21
22
 
22
23
  import { ModelPicker } from './ModelPicker'
23
- import { Button } from '@/client/components/ui/button'
24
24
 
25
25
  type ChatComposerProps = {
26
26
  composerRef: RefObject<HTMLTextAreaElement | null>
27
27
  onSend: (text: string) => void
28
28
  onStop: () => void
29
29
  processing: boolean
30
+ unavailableReason: string | null | undefined
30
31
  }
31
32
 
32
33
  // The composer owns the draft: it reads/writes the per-thread draft in the live
@@ -34,7 +35,13 @@ type ChatComposerProps = {
34
35
  // panel, message list, or surrounding workspace. The draft is keyed by the
35
36
  // active thread, so switching threads swaps the unsent text with you. Attachments
36
37
  // (drag/drop, paste, attach button) are tracked the same way and cleared on send.
37
- export function ChatComposer({ composerRef, onSend, onStop, processing }: ChatComposerProps) {
38
+ export function ChatComposer({
39
+ composerRef,
40
+ onSend,
41
+ onStop,
42
+ processing,
43
+ unavailableReason
44
+ }: ChatComposerProps) {
38
45
  const fileRef = useRef<HTMLInputElement>(null)
39
46
  const workspaceId = useWorkspaceId()
40
47
  const sessionId = useLive(s => s.activeByWorkspace[workspaceId] ?? null)
@@ -44,7 +51,8 @@ export function ChatComposer({ composerRef, onSend, onStop, processing }: ChatCo
44
51
 
45
52
  const uploading = attachments.some(a => a.status === 'uploading')
46
53
  const hasReady = attachments.some(a => a.status === 'ready')
47
- const canSend = (value.trim().length > 0 || hasReady) && !uploading
54
+ const hasContent = value.trim().length > 0 || hasReady
55
+ const canSend = canSubmitComposerAction(hasContent, uploading, unavailableReason)
48
56
 
49
57
  const onChange = (next: string) => liveStore.getState().setDraft(workspaceId, sessionId, next)
50
58
 
@@ -89,16 +97,12 @@ export function ChatComposer({ composerRef, onSend, onStop, processing }: ChatCo
89
97
  }
90
98
 
91
99
  return (
92
- <form
100
+ <Composer
101
+ composerRef={composerRef}
93
102
  onSubmit={e => {
94
103
  e.preventDefault()
95
104
  send()
96
105
  }}
97
- onMouseDown={e => {
98
- if (e.target instanceof HTMLElement && e.target.closest('button')) return
99
- e.preventDefault()
100
- composerRef.current?.focus()
101
- }}
102
106
  onDragOver={e => {
103
107
  if (!e.dataTransfer.types.includes('Files')) return
104
108
  e.preventDefault()
@@ -115,10 +119,7 @@ export function ChatComposer({ composerRef, onSend, onStop, processing }: ChatCo
115
119
  setDragOver(false)
116
120
  addFiles(Array.from(e.dataTransfer.files))
117
121
  }}
118
- className={cn(
119
- 'flex w-full max-w-(--chat-max-container) cursor-text flex-col gap-1 rounded-lg bg-card p-2 text-card-foreground shadow-xs transition-[color,box-shadow] outline-none focus-within:shadow-sm',
120
- dragOver && 'ring-2 ring-ring/60'
121
- )}
122
+ className={cn(dragOver && 'ring-2 ring-ring/60')}
122
123
  >
123
124
  {attachments.length > 0 && (
124
125
  <div className="flex flex-wrap gap-2 px-1 pt-1 pb-0.5">
@@ -134,8 +135,8 @@ export function ChatComposer({ composerRef, onSend, onStop, processing }: ChatCo
134
135
  </div>
135
136
  )}
136
137
 
137
- <textarea
138
- ref={composerRef}
138
+ <ComposerTextarea
139
+ textareaRef={composerRef}
139
140
  id="chat-input"
140
141
  name="message"
141
142
  value={value}
@@ -154,9 +155,8 @@ export function ChatComposer({ composerRef, onSend, onStop, processing }: ChatCo
154
155
  }}
155
156
  placeholder={processing ? 'Queue a follow-up' : 'Do anything'}
156
157
  rows={1}
157
- className="field-sizing-content max-h-40 w-full resize-none bg-transparent px-2 py-1 text-sm leading-relaxed outline-none placeholder:text-muted-foreground disabled:opacity-50"
158
158
  />
159
- <div className="flex items-center justify-end gap-1.5">
159
+ <ComposerFooter>
160
160
  <input
161
161
  ref={fileRef}
162
162
  type="file"
@@ -183,12 +183,15 @@ export function ChatComposer({ composerRef, onSend, onStop, processing }: ChatCo
183
183
  <IconPlayerStop stroke={1.5} />
184
184
  </Button>
185
185
  ) : (
186
- <Button type="submit" size="icon" disabled={!canSend} aria-label="Send message">
187
- <IconArrowUp stroke={1.5} />
188
- </Button>
186
+ <ComposerSubmitButton
187
+ label="Send message"
188
+ hasContent={hasContent}
189
+ busy={uploading}
190
+ unavailableReason={unavailableReason}
191
+ />
189
192
  )}
190
- </div>
191
- </form>
193
+ </ComposerFooter>
194
+ </Composer>
192
195
  )
193
196
  }
194
197
 
@@ -25,6 +25,7 @@ type ChatPanelProps = {
25
25
  processing: boolean
26
26
  error?: string | null
27
27
  onDismissError?: () => void
28
+ unavailableReason: string | null | undefined
28
29
  send: (text: string) => void
29
30
  stop: () => void
30
31
  onSwitchThread: (sessionId: string | null) => void
@@ -48,6 +49,7 @@ export function ChatPanel({
48
49
  processing,
49
50
  error,
50
51
  onDismissError,
52
+ unavailableReason,
51
53
  send,
52
54
  stop,
53
55
  onSwitchThread,
@@ -141,9 +143,9 @@ export function ChatPanel({
141
143
  )}
142
144
  </div>
143
145
 
144
- <div className="mx-auto flex w-full justify-center px-3">
146
+ <div className="mx-auto flex w-full flex-col items-center px-3">
145
147
  {error && (
146
- <div className="mb-2 flex items-start gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
148
+ <div className="mb-2 flex w-full max-w-(--chat-max-container) items-start gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
147
149
  <span className="flex-1 wrap-break-word">{error}</span>
148
150
  {onDismissError && (
149
151
  <Button
@@ -164,6 +166,7 @@ export function ChatPanel({
164
166
  onSend={handleSend}
165
167
  onStop={stop}
166
168
  processing={processing}
169
+ unavailableReason={unavailableReason}
167
170
  />
168
171
  </div>
169
172
  </div>
@@ -10,10 +10,23 @@ const remarkPlugins = [remarkGfm]
10
10
  const rehypePlugins = [rehypeHighlight]
11
11
 
12
12
  const components = {
13
+ code({ className, children, ...props }: ComponentProps<'code'>) {
14
+ return (
15
+ <code
16
+ className={cn(
17
+ 'rounded-[4px] bg-accent px-1 py-0.5 font-mono font-normal before:content-none after:content-none',
18
+ className
19
+ )}
20
+ {...props}
21
+ >
22
+ {children}
23
+ </code>
24
+ )
25
+ },
13
26
  pre({ children }: ComponentProps<'pre'>) {
14
27
  return (
15
28
  <div className="not-prose my-2 rounded-md border border-border bg-muted px-3 py-2.5">
16
- <pre className="max-h-[300px] overflow-auto font-mono text-xs leading-relaxed whitespace-pre text-foreground">
29
+ <pre className="max-h-[300px] overflow-auto font-mono text-xs leading-relaxed whitespace-pre text-foreground [&>code]:rounded-none [&>code]:bg-transparent [&>code]:p-0">
17
30
  {children}
18
31
  </pre>
19
32
  </div>
@@ -28,7 +41,12 @@ type MarkdownContentProps = {
28
41
 
29
42
  export function MarkdownContent({ size = 'sm', content }: MarkdownContentProps) {
30
43
  return (
31
- <div className={cn('prose prose-inherit', size === 'sm' && 'prose-sm')}>
44
+ <div
45
+ className={cn(
46
+ 'prose max-w-full min-w-0 wrap-anywhere prose-inherit',
47
+ size === 'sm' && 'prose-sm'
48
+ )}
49
+ >
32
50
  <ReactMarkdown
33
51
  remarkPlugins={remarkPlugins}
34
52
  rehypePlugins={rehypePlugins}
@@ -3,9 +3,13 @@ import { memo, useState } from 'react'
3
3
  import { IconChevronDown } from '@tabler/icons-react'
4
4
 
5
5
  import { useSaveThreadConfig, useThreadConfig, useWorkspaceModels } from './api'
6
+ import {
7
+ resolveDisplayedEffort,
8
+ reverseEffortLevels,
9
+ sortModelsByProviderOrder
10
+ } from './model-order'
6
11
  import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
7
12
  import { useLive } from '@/client/features/chat/chat-store'
8
- import type { Model } from '@/lib/types'
9
13
 
10
14
  import { Button } from '@/client/components/ui/button'
11
15
  import {
@@ -39,31 +43,8 @@ function effortLabel(level: string): string {
39
43
  return level === 'xhigh' ? 'Extra' : capitalize(level)
40
44
  }
41
45
 
42
- // Output price ($/Mtok) parsed from a model's "$in/$out per Mtok" blurb.
43
- function outputPrice(description?: string): number {
44
- const m = description?.match(/\$\d+(?:\.\d+)?\s*\/\s*\$(\d+(?:\.\d+)?)\s*per Mtok/)
45
- return m ? Number(m[1]) : -1
46
- }
47
-
48
- // Canonical wire id without a context-variant suffix, e.g.
49
- // 'claude-opus-4-8[1m]' → 'claude-opus-4-8'. Groups a model with its variants.
50
- function familyOf(m: Model): string | undefined {
51
- return m.resolvedModel?.replace(/\[[^\]]*\]$/, '')
52
- }
53
-
54
- // Sort key ordering models most-capable-first (Fable → Opus → Sonnet → Haiku)
55
- // from price alone, no hardcoded names. A bare alias that omits its price (e.g.
56
- // plain 'opus') borrows a same-family variant's price ('opus[1m]'s $/Mtok) so
57
- // the two group together. Unpriced models (OpenClaw) return -1 → sort last,
58
- // keeping their original order since they're all equal.
59
- function sortPrice(m: Model, all: Model[]): number {
60
- const own = outputPrice(m.description)
61
- if (own >= 0) return own
62
- const family = familyOf(m)
63
- const sibling = all.find(
64
- x => x !== m && familyOf(x) === family && outputPrice(x.description) >= 0
65
- )
66
- return sibling ? outputPrice(sibling.description) : -1
46
+ type ModelPickerProps = {
47
+ scope?: 'active-chat' | 'workspace'
67
48
  }
68
49
 
69
50
  // Model selector for the chat composer. Renders the workspace's available
@@ -73,10 +54,11 @@ function sortPrice(m: Model, all: Model[]): number {
73
54
  // edits the workspace defaults, which seed the new thread. Both are sent with
74
55
  // each chat frame (see useChat); leaving them untouched runs on the SDK default.
75
56
  // Fast mode remains local-only for now.
76
- // Memoized (no props): it lives inside ChatInput, which re-renders on every
77
- // keystroke, so memo keeps the picker from re-rendering with it — it updates
78
- // only on its own store/query changes (active thread, models, layout).
79
- export const ModelPicker = memo(function ModelPicker() {
57
+ // The workspace scope gives new-chat surfaces such as the view builder the same
58
+ // defaults that their submit path reads. The active-chat scope persists per
59
+ // thread once one exists.
60
+ // Memoized because composer text changes should not re-render the picker.
61
+ export const ModelPicker = memo(function ModelPicker({ scope = 'active-chat' }: ModelPickerProps) {
80
62
  const { workspaceId, layout, setLayout } = useWorkspaceLayoutCtx()
81
63
  const { data } = useWorkspaceModels(workspaceId)
82
64
  // The SDK prepends a synthetic "default" entry ("Use the default model
@@ -85,15 +67,18 @@ export const ModelPicker = memo(function ModelPicker() {
85
67
  // "use default" row.
86
68
  const allModels = data?.models ?? []
87
69
  const defaultEntry = allModels.find(m => m.value === 'default')
88
- // Drop the "default" entry, then order by price descending. Array.sort is
89
- // stable, so same-price variants (Opus 1M vs standard) keep the SDK's order.
90
- const models = allModels
91
- .filter(m => m.value !== 'default')
92
- .sort((a, b) => sortPrice(b, allModels) - sortPrice(a, allModels))
70
+ const models = data
71
+ ? sortModelsByProviderOrder(
72
+ allModels.filter(model => model.value !== 'default'),
73
+ data.provider
74
+ )
75
+ : []
93
76
 
94
77
  // The active thread, if any. Its stored config is the source of truth; a new
95
78
  // chat (no active thread) falls back to — and edits — the workspace defaults.
96
- const activeSessionId = useLive(s => s.activeByWorkspace[workspaceId] ?? null)
79
+ const activeSessionId = useLive(s =>
80
+ scope === 'active-chat' ? (s.activeByWorkspace[workspaceId] ?? null) : null
81
+ )
97
82
  const threadCfg = useThreadConfig(workspaceId, activeSessionId).data
98
83
  const saveThreadCfg = useSaveThreadConfig(workspaceId)
99
84
  const [fastMode, setFastMode] = useState(false)
@@ -124,9 +109,10 @@ export const ModelPicker = memo(function ModelPicker() {
124
109
  ) ?? models[0]
125
110
  const current = persisted ?? defaultModel.value
126
111
  const model = models.find(m => m.value === current) ?? models[0]
127
- const effortLevels = model.supportsEffort ? (model.supportedEffortLevels ?? []) : []
128
- const currentEffort =
129
- selectedEffort && effortLevels.includes(selectedEffort) ? selectedEffort : effortLevels[0]
112
+ const effortLevels = reverseEffortLevels(
113
+ model.supportsEffort ? (model.supportedEffortLevels ?? []) : []
114
+ )
115
+ const currentEffort = resolveDisplayedEffort(effortLevels, selectedEffort)
130
116
  const showReasoning = effortLevels.length > 0
131
117
  // Fast mode is Claude-only (Opus); OpenClaw models never report supportsFastMode.
132
118
  const showFastMode = !!model.supportsFastMode
@@ -140,9 +126,11 @@ export const ModelPicker = memo(function ModelPicker() {
140
126
  {headline(model.description) || model.displayName}
141
127
  </span>
142
128
  {currentEffort && (
143
- <span className="text-muted-foreground">{effortLabel(currentEffort)}</span>
129
+ <span className="font-normal text-muted-foreground">
130
+ {effortLabel(currentEffort)}
131
+ </span>
144
132
  )}
145
- <IconChevronDown stroke={1.5} />
133
+ <IconChevronDown stroke={1.5} className="text-muted-foreground" />
146
134
  </Button>
147
135
  }
148
136
  />
@@ -119,12 +119,12 @@ export const TurnView = memo(function TurnView({ turn, processing = false }: Tur
119
119
  .join('\n')
120
120
  if (!text && fileParts.length === 0) return null
121
121
  return (
122
- <div className="ml-8 flex flex-col items-end gap-1.5">
122
+ <div className="ml-8 flex min-w-0 flex-col items-end gap-1.5">
123
123
  {fileParts.map((p, i) => (
124
124
  <FilePart key={i} mediaType={p.mediaType} url={p.url} filename={p.filename} />
125
125
  ))}
126
126
  {text && (
127
- <p className="rounded-md bg-accent px-4 py-2 text-sm leading-normal whitespace-pre-wrap text-accent-foreground">
127
+ <p className="max-w-full min-w-0 rounded-md bg-accent px-4 py-2 text-sm leading-normal wrap-anywhere whitespace-pre-wrap text-accent-foreground">
128
128
  {text}
129
129
  </p>
130
130
  )}
@@ -8,6 +8,7 @@ import type {
8
8
  ClientMessage,
9
9
  PreviewFrame,
10
10
  ScratchOp,
11
+ SessionActivity,
11
12
  StreamEvent,
12
13
  ThreadConfig,
13
14
  ViewState
@@ -24,17 +25,19 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
24
25
  const store = liveStore.getState()
25
26
 
26
27
  if (data.type === 'status_snapshot') {
27
- store.reconcileProcessing(
28
- (data.running as { workspaceId: string; sessionId: string }[] | undefined) ?? []
28
+ store.reconcileActivity(
29
+ (data.sessions as
30
+ | { workspaceId: string; sessionId: string; activity: SessionActivity }[]
31
+ | undefined) ?? []
29
32
  )
30
33
  return
31
34
  }
32
35
  if (data.type === 'status') {
33
36
  const workspaceId = data.workspaceId as string
34
37
  const sessionId = data.sessionId as string
35
- const processing = data.processing as boolean
36
- store.setProcessing(workspaceId, sessionId, processing)
37
- if (!processing) store.clearPreviewsForSession(workspaceId, sessionId)
38
+ const activity = data.activity as SessionActivity
39
+ store.setActivity(workspaceId, sessionId, activity)
40
+ if (activity !== 'running') store.clearPreviewsForSession(workspaceId, sessionId)
38
41
  return
39
42
  }
40
43
  if (data.type === 'preview') {
@@ -72,6 +75,7 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
72
75
  queryClient?.removeQueries({ queryKey: workspaceKeys.threadConfig(workspaceId, from) })
73
76
  }
74
77
  queryClient?.invalidateQueries({ queryKey: workspaceKeys.sessions(workspaceId) })
78
+ queryClient?.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
75
79
  return
76
80
  }
77
81
  if (data.type === 'workspace:switch') {
@@ -110,10 +114,14 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
110
114
  }
111
115
  if (kind === 'error' && typeof data.content === 'string') {
112
116
  store.setError(workspaceId, sessionId, data.content)
117
+ // Servers only emit `error` terminally, so it also ends the busy state —
118
+ // relying solely on a separate status frame left the spinner stuck when
119
+ // that frame was lost.
120
+ store.setActivity(workspaceId, sessionId, 'idle')
113
121
  store.clearPreviewsForSession(workspaceId, sessionId)
114
122
  }
115
123
  if (kind === 'stopped') {
116
- store.setProcessing(workspaceId, sessionId, false)
124
+ store.setActivity(workspaceId, sessionId, 'idle')
117
125
  store.clearPreviewsForSession(workspaceId, sessionId)
118
126
  }
119
127
  }
@@ -32,7 +32,7 @@ export function startOptimisticTurn({
32
32
  }
33
33
  })
34
34
  )
35
- liveStore.getState().setProcessing(workspaceId, sessionId, true)
35
+ liveStore.getState().setActivity(workspaceId, sessionId, 'running')
36
36
  liveStore.getState().setError(workspaceId, sessionId, null)
37
37
  return optimisticId
38
38
  }
@@ -1,7 +1,7 @@
1
1
  import { useStore } from 'zustand'
2
2
  import { createStore } from 'zustand/vanilla'
3
3
 
4
- import type { PreviewBlock, PreviewFrame, UploadInfo } from '@/lib/types'
4
+ import type { PreviewBlock, PreviewFrame, SessionActivity, UploadInfo } from '@/lib/types'
5
5
 
6
6
  // One composer attachment, tracked per thread until the message is sent. It is
7
7
  // uploaded as soon as it's added (drop/paste/pick); `status` reflects that
@@ -20,7 +20,7 @@ export type ChatAttachment = {
20
20
  // App-level ephemeral chat state — the bits that are *pushed* from the server
21
21
  // over the WebSocket and can't be re-fetched as request/response data:
22
22
  // - which thread is active per workspace (a UI selection),
23
- // - per-session `processing` (spinner) flags,
23
+ // - per-session `activity` (spinner) state,
24
24
  // - per-session error banners.
25
25
  //
26
26
  // The durable message transcripts live in the React Query cache (see
@@ -56,7 +56,10 @@ export type LivePreview = {
56
56
 
57
57
  export type LiveStore = {
58
58
  activeByWorkspace: Record<string, string | null>
59
- processing: Record<string, boolean>
59
+ // Per-session activity mirrored from server `status` frames. Only `running`
60
+ // shows the loader/Stop; `requires-action` is tracked but not rendered yet.
61
+ // Missing key = idle.
62
+ activity: Record<string, SessionActivity>
60
63
  errors: Record<string, string | null>
61
64
  // Live token-streaming previews, keyed by `messageId` (the API `msg_...` id)
62
65
  // so concurrent streams never collide. Reconciled against the durable
@@ -73,11 +76,13 @@ export type LiveStore = {
73
76
  attachments: Record<string, ChatAttachment[]>
74
77
 
75
78
  setActive: (workspaceId: string, sessionId: string | null) => void
76
- setProcessing: (workspaceId: string, sessionId: string, value: boolean) => void
79
+ setActivity: (workspaceId: string, sessionId: string, value: SessionActivity) => void
77
80
  // Authoritative reconcile from a server `status_snapshot`: exactly the listed
78
- // sessions are processing; everything else is cleared (fixes a spinner whose
79
- // terminal status was emitted while we were disconnected).
80
- reconcileProcessing: (running: { workspaceId: string; sessionId: string }[]) => void
81
+ // sessions are active; everything else is cleared to idle (fixes a spinner
82
+ // whose terminal status frame was lost while we were disconnected).
83
+ reconcileActivity: (
84
+ sessions: { workspaceId: string; sessionId: string; activity: SessionActivity }[]
85
+ ) => void
81
86
  setError: (workspaceId: string, sessionId: string, message: string | null) => void
82
87
  setDraft: (workspaceId: string, sessionId: string | null, value: string) => void
83
88
  addAttachments: (workspaceId: string, sessionId: string | null, items: ChatAttachment[]) => void
@@ -107,7 +112,7 @@ export type LiveStore = {
107
112
 
108
113
  export const liveStore = createStore<LiveStore>()(set => ({
109
114
  activeByWorkspace: {},
110
- processing: {},
115
+ activity: {},
111
116
  errors: {},
112
117
  drafts: {},
113
118
  previews: {},
@@ -116,12 +121,12 @@ export const liveStore = createStore<LiveStore>()(set => ({
116
121
  setActive: (workspaceId, sessionId) =>
117
122
  set(s => ({ activeByWorkspace: { ...s.activeByWorkspace, [workspaceId]: sessionId } })),
118
123
 
119
- setProcessing: (workspaceId, sessionId, value) =>
120
- set(s => ({ processing: { ...s.processing, [key(workspaceId, sessionId)]: value } })),
124
+ setActivity: (workspaceId, sessionId, value) =>
125
+ set(s => ({ activity: { ...s.activity, [key(workspaceId, sessionId)]: value } })),
121
126
 
122
- reconcileProcessing: running =>
127
+ reconcileActivity: sessions =>
123
128
  set(() => ({
124
- processing: Object.fromEntries(running.map(r => [key(r.workspaceId, r.sessionId), true]))
129
+ activity: Object.fromEntries(sessions.map(r => [key(r.workspaceId, r.sessionId), r.activity]))
125
130
  })),
126
131
 
127
132
  setError: (workspaceId, sessionId, message) =>
@@ -219,11 +224,11 @@ export const liveStore = createStore<LiveStore>()(set => ({
219
224
  set(s => {
220
225
  const fromKey = key(workspaceId, from)
221
226
  const toKey = key(workspaceId, to)
222
- const processing = { ...s.processing }
227
+ const activity = { ...s.activity }
223
228
  const errors = { ...s.errors }
224
- if (fromKey in processing) {
225
- processing[toKey] = processing[fromKey]
226
- delete processing[fromKey]
229
+ if (fromKey in activity) {
230
+ activity[toKey] = activity[fromKey]
231
+ delete activity[fromKey]
227
232
  }
228
233
  if (fromKey in errors) {
229
234
  errors[toKey] = errors[fromKey]
@@ -246,7 +251,7 @@ export const liveStore = createStore<LiveStore>()(set => ({
246
251
  previews[id] = { ...p, sessionId: to }
247
252
  }
248
253
  }
249
- return { processing, errors, activeByWorkspace, previews }
254
+ return { activity, errors, activeByWorkspace, previews }
250
255
  })
251
256
  }))
252
257
 
@@ -0,0 +1,47 @@
1
+ import type { Model, WorkspaceType } from '@/lib/types'
2
+
3
+ export const DEFAULT_EFFORT = 'high'
4
+
5
+ export const MODEL_ORDER = {
6
+ 'claude-code': [
7
+ 'claude-fable-5',
8
+ 'claude-opus-4-8',
9
+ 'claude-opus-4-8[1m]',
10
+ 'claude-sonnet-5',
11
+ 'claude-haiku-4-5-20251001'
12
+ ],
13
+ codex: [],
14
+ openclaw: []
15
+ } as const satisfies Record<WorkspaceType, readonly string[]>
16
+
17
+ function modelOrderKey(model: Model): string {
18
+ return model.resolvedModel ?? model.value
19
+ }
20
+
21
+ export function reverseEffortLevels(levels: readonly string[]): string[] {
22
+ return [...levels].reverse()
23
+ }
24
+
25
+ export function resolveDisplayedEffort(
26
+ levels: readonly string[],
27
+ selectedEffort: string | undefined
28
+ ): string | undefined {
29
+ if (selectedEffort && levels.includes(selectedEffort)) return selectedEffort
30
+ if (levels.includes(DEFAULT_EFFORT)) return DEFAULT_EFFORT
31
+ return levels[0]
32
+ }
33
+
34
+ export function sortModelsByProviderOrder(models: Model[], provider: WorkspaceType): Model[] {
35
+ const configuredOrder: readonly string[] = MODEL_ORDER[provider]
36
+ const rank = new Map<string, number>(configuredOrder.map((model, index) => [model, index]))
37
+
38
+ return models
39
+ .map((model, index) => ({ model, index, rank: rank.get(modelOrderKey(model)) }))
40
+ .sort((a, b) => {
41
+ if (a.rank === undefined && b.rank === undefined) return a.index - b.index
42
+ if (a.rank === undefined) return -1
43
+ if (b.rank === undefined) return 1
44
+ return a.rank - b.rank || a.index - b.index
45
+ })
46
+ .map(({ model }) => model)
47
+ }
@@ -8,7 +8,6 @@ import type { ToolCall } from '@/lib/types'
8
8
  import { Button } from '@/client/components/ui/button'
9
9
  import { CodeBlock } from './CodeBlock'
10
10
  import { detectOutput } from './detect'
11
- import { formatBytes } from './format'
12
11
 
13
12
  type ToolOutputProps = { call: ToolCall; output: string; isError: boolean }
14
13
 
@@ -49,13 +48,7 @@ export function ToolOutput({ call, output, isError }: ToolOutputProps) {
49
48
  return (
50
49
  <div className="overflow-hidden rounded-md border border-border bg-muted">
51
50
  {/* Size is always the raw output; copy grabs whatever's currently shown. */}
52
- <Header
53
- raw={raw}
54
- onRaw={setRaw}
55
- label={view.label}
56
- size={formatBytes(output)}
57
- copyText={raw ? output : view.code}
58
- />
51
+ <Header raw={raw} onRaw={setRaw} label={view.label} copyText={raw ? output : view.code} />
59
52
  {raw ? (
60
53
  <pre className={cn(PRE, 'break-all whitespace-pre-wrap text-muted-foreground')}>
61
54
  {output || '(empty)'}
@@ -71,19 +64,18 @@ type HeaderProps = {
71
64
  raw: boolean
72
65
  onRaw: (raw: boolean) => void
73
66
  label: string
74
- size: string
75
67
  copyText: string
76
68
  }
77
69
 
78
70
  // Output toolbar: a left outline switch (<label> | raw), and on the right the
79
71
  // raw byte size + a copy button.
80
- function Header({ raw, onRaw, label, size, copyText }: HeaderProps) {
72
+ function Header({ raw, onRaw, label, copyText }: HeaderProps) {
81
73
  const options: [boolean, string][] = [
82
74
  [false, label],
83
75
  [true, 'raw']
84
76
  ]
85
77
  return (
86
- <div className="flex items-center gap-1 border-b border-border px-2 py-1">
78
+ <div className="flex items-center gap-1 border-b border-border p-2">
87
79
  {options.map(([value, text]) => (
88
80
  <Button
89
81
  key={text}
@@ -91,12 +83,12 @@ function Header({ raw, onRaw, label, size, copyText }: HeaderProps) {
91
83
  variant={raw === value ? 'outline' : 'ghost'}
92
84
  size="sm"
93
85
  onClick={() => onRaw(value)}
86
+ className="rounded-full text-xs uppercase"
94
87
  >
95
88
  {text}
96
89
  </Button>
97
90
  ))}
98
91
  <div className="flex-1" />
99
- <span className="text-[10px] font-medium text-muted-foreground tabular-nums">{size}</span>
100
92
  <CopyButton text={copyText} />
101
93
  </div>
102
94
  )
@@ -68,12 +68,6 @@ function getInputValue(input: Record<string, unknown>, key: string): string {
68
68
  return typeof value === 'string' ? value : ''
69
69
  }
70
70
 
71
- // Human byte size of a string (UTF-8): `124B`, `2.5KB`.
72
- export function formatBytes(text: string): string {
73
- const n = new TextEncoder().encode(text).length
74
- return n < 1024 ? `${n}B` : `${(n / 1024).toFixed(1)}KB`
75
- }
76
-
77
71
  // Compact wall-clock duration: sub-second → "850ms", under a minute → "3.2s" /
78
72
  // "11s", longer → "1m 5s". Used on the subagent card's duration badge.
79
73
  export function formatDuration(ms: number): string {