@standardagents/cli 0.41.21 → 0.41.23

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.
@@ -3,16 +3,15 @@
3
3
  import { AgentBuilderProvider } from '@standardagents/react'
4
4
  import { ThemeProvider } from '../../src/hooks/useTheme'
5
5
  import { AuthProvider } from '../../src/hooks/useAuth'
6
+ import { getSdkEndpoint } from '../../src/lib/api'
6
7
  import App from '../../src/App'
7
8
 
8
- // SDK endpoint - uses rewrites so just /api
9
- const SDK_ENDPOINT = '/api'
10
-
11
9
  export default function Page() {
12
10
  return (
13
11
  <ThemeProvider>
14
12
  <AuthProvider>
15
- <AgentBuilderProvider config={{ endpoint: SDK_ENDPOINT }}>
13
+ {/* next.config.ts rewrites /api to the runtime, so the SDK stays same-origin. */}
14
+ <AgentBuilderProvider config={{ endpoint: getSdkEndpoint() }}>
16
15
  <App />
17
16
  </AgentBuilderProvider>
18
17
  </AuthProvider>
package/chat/package.json CHANGED
@@ -7,7 +7,9 @@
7
7
  "dev:vite": "vite --config vite/vite.config.ts",
8
8
  "build:vite": "vite build --config vite/vite.config.ts",
9
9
  "dev:next": "cd next && next dev --port 5175",
10
- "build:next": "cd next && next build"
10
+ "build:next": "cd next && next build",
11
+ "typecheck": "tsc --noEmit && tsc --noEmit -p next",
12
+ "test": "vitest run"
11
13
  },
12
14
  "dependencies": {
13
15
  "@standardagents/react": "workspace:*",
@@ -15,11 +17,14 @@
15
17
  "react": "^19.0.0",
16
18
  "react-dom": "^19.0.0",
17
19
  "react-markdown": "^10.1.0",
18
- "react-shiki": "^0.9.1"
20
+ "react-shiki": "^0.9.1",
21
+ "remark-gfm": "^4.0.1",
22
+ "remend": "^1.4.0"
19
23
  },
20
24
  "devDependencies": {
21
25
  "@tailwindcss/postcss": "^4.0.0",
22
26
  "@tailwindcss/vite": "^4.0.0",
27
+ "@types/hast": "^3.0.4",
23
28
  "@types/node": "^22.0.0",
24
29
  "@types/react": "^19.0.0",
25
30
  "@types/react-dom": "^19.0.0",
@@ -27,6 +32,7 @@
27
32
  "postcss": "^8.5.0",
28
33
  "tailwindcss": "^4.0.0",
29
34
  "typescript": "^5.9.0",
30
- "vite": "^6.0.0"
35
+ "vite": "^6.0.0",
36
+ "vitest": "^2.1.9"
31
37
  }
32
38
  }
package/chat/src/App.tsx CHANGED
@@ -110,10 +110,11 @@ function AuthenticatedApp() {
110
110
  </button>
111
111
 
112
112
  {currentThreadId ? (
113
- <ThreadProvider key={currentThreadId} threadId={currentThreadId} live useWorkblocks>
113
+ <ThreadProvider key={currentThreadId} threadId={currentThreadId} live includeSilent useWorkblocks useSubagentBlocks>
114
114
  <Chat
115
115
  thread={threads.find(t => t.id === currentThreadId)}
116
116
  onUpdateTitle={(title) => updateThreadTitle(currentThreadId, title)}
117
+ onRunStateChange={refreshThreads}
117
118
  sidebarOpen={sidebarOpen}
118
119
  />
119
120
  </ThreadProvider>
@@ -9,11 +9,23 @@ import { type Thread, getThreadTitle } from '../hooks/useThreads'
9
9
  interface ChatProps {
10
10
  thread?: Thread
11
11
  onUpdateTitle?: (title: string) => void
12
+ /** Called when the pushed run state changes, so the thread list can refresh. */
13
+ onRunStateChange?: () => void
12
14
  sidebarOpen?: boolean
13
15
  }
14
16
 
15
- export function Chat({ thread, onUpdateTitle, sidebarOpen = true }: ChatProps) {
16
- const { status } = useThread()
17
+ export function Chat({ thread, onUpdateTitle, onRunStateChange, sidebarOpen = true }: ChatProps) {
18
+ const { status, runStatus } = useThread()
19
+ const runState = runStatus?.state
20
+ const lastRunState = useRef(runState)
21
+
22
+ // Event-driven sidebar refresh: one read per run-state transition.
23
+ useEffect(() => {
24
+ if (lastRunState.current !== undefined && runState !== lastRunState.current) {
25
+ onRunStateChange?.()
26
+ }
27
+ lastRunState.current = runState
28
+ }, [runState, onRunStateChange])
17
29
  const [isEditingTitle, setIsEditingTitle] = useState(false)
18
30
  const [titleValue, setTitleValue] = useState('')
19
31
  const inputRef = useRef<HTMLInputElement>(null)
@@ -101,6 +113,9 @@ export function Chat({ thread, onUpdateTitle, sidebarOpen = true }: ChatProps) {
101
113
 
102
114
  {/* Agent name and connection status on the right */}
103
115
  <div className="flex items-center gap-3 ml-4">
116
+ {runState === 'running' && (
117
+ <span className="text-xs text-violet-500 hidden sm:inline">Running</span>
118
+ )}
104
119
  <span className="text-sm text-[var(--text-tertiary)] hidden sm:inline">{agentName}</span>
105
120
  <div
106
121
  className={`w-2 h-2 rounded-full ${ledColor}`}
@@ -1,24 +1,25 @@
1
1
  'use client'
2
2
 
3
- import { useState, useCallback, useEffect, useRef, useMemo } from 'react'
4
- import type { Thread } from '../hooks/useThreads'
3
+ import { useState, useCallback, useEffect, useRef } from 'react'
4
+ import type { AttachmentPayload } from '@standardagents/react'
5
+ import { apiFetch } from '../lib/api'
6
+ import { withThreadName, type CreatedThread, type SideBacking, type Thread } from '../hooks/useThreads'
5
7
  import { Logo } from './Logo'
6
8
 
9
+ /** One entry of `GET /api/agents`. */
7
10
  interface Agent {
8
11
  id: string
9
12
  name: string
10
- title?: string
11
- description?: string
13
+ title?: string | null
14
+ description?: string | null
15
+ primary?: boolean
16
+ side_a_backing?: SideBacking
17
+ side_b_backing?: SideBacking
12
18
  }
13
19
 
14
- interface PendingAttachment {
20
+ interface PendingAttachment extends AttachmentPayload {
15
21
  id: string
16
- name: string
17
- mimeType: string
18
- data: string // base64
19
- width?: number
20
- height?: number
21
- preview?: string // data URL for preview
22
+ preview?: string // object URL for preview
22
23
  }
23
24
 
24
25
  interface EmptyStateProps {
@@ -27,19 +28,14 @@ interface EmptyStateProps {
27
28
  onThreadCreated: (thread: Thread) => void
28
29
  }
29
30
 
30
- // Helper to get API config
31
- function getApiConfig() {
32
- const isVite = typeof import.meta !== 'undefined' && import.meta.env
33
- const baseUrl = isVite
34
- ? (import.meta.env.VITE_AGENTBUILDER_URL || '')
35
- : (process.env.NEXT_PUBLIC_AGENTBUILDER_URL || '')
36
-
37
- // Token is stored in localStorage by auth flow
38
- const token = typeof localStorage !== 'undefined'
39
- ? localStorage.getItem('agentbuilder_auth_token') || ''
40
- : ''
41
-
42
- return { baseUrl, token }
31
+ /**
32
+ * Agents a person can chat with: primary (not subagent-only) agents with a
33
+ * human side. Spec 0.2.0 replaced the agent `type` with per-side backings.
34
+ */
35
+ function isChatAgent(agent: Agent): boolean {
36
+ if (agent.primary === false) return false
37
+ if (!agent.side_a_backing && !agent.side_b_backing) return true
38
+ return agent.side_a_backing === 'human' || agent.side_b_backing === 'human'
43
39
  }
44
40
 
45
41
  // Read file as base64
@@ -88,21 +84,13 @@ export function EmptyState({
88
84
  const textareaRef = useRef<HTMLTextAreaElement>(null)
89
85
  const fileInputRef = useRef<HTMLInputElement>(null)
90
86
 
91
- const { baseUrl, token } = useMemo(() => getApiConfig(), [])
92
- const headers = useMemo(() => {
93
- const h: Record<string, string> = { 'Content-Type': 'application/json' }
94
- if (token) h['Authorization'] = `Bearer ${token}`
95
- return h
96
- }, [token])
97
-
98
87
  useEffect(() => {
99
88
  const fetchAgents = async () => {
100
89
  try {
101
- const response = await fetch(`${baseUrl}/api/agents`, { headers })
90
+ const response = await apiFetch('/api/agents')
102
91
  if (!response.ok) throw new Error('Failed to fetch agents')
103
- const data = await response.json()
104
- const agentList = data.agents || []
105
- console.log('Agents from API:', agentList)
92
+ const data = await response.json() as { agents?: Agent[] }
93
+ const agentList = (data.agents || []).filter(isChatAgent)
106
94
  setAgents(agentList)
107
95
  if (!selectedAgentId && agentList.length > 0) {
108
96
  onAgentChange(agentList[0].id)
@@ -114,7 +102,7 @@ export function EmptyState({
114
102
  }
115
103
  }
116
104
  fetchAgents()
117
- }, [selectedAgentId, onAgentChange, baseUrl, headers])
105
+ }, [selectedAgentId, onAgentChange])
118
106
 
119
107
  useEffect(() => {
120
108
  const handleClickOutside = (e: MouseEvent) => {
@@ -191,68 +179,46 @@ export function EmptyState({
191
179
  const currentAttachments = [...attachments]
192
180
 
193
181
  try {
194
- // Create thread
195
- const threadRes = await fetch(`${baseUrl}/api/threads`, {
182
+ // Create the thread already named, then send the first message.
183
+ const tags = withThreadName([], title)
184
+ const threadRes = await apiFetch('/api/threads', {
196
185
  method: 'POST',
197
- headers,
198
- body: JSON.stringify({ agent_id: selectedAgentId }),
186
+ body: JSON.stringify({ agent_id: selectedAgentId, tags }),
199
187
  })
200
-
201
188
  if (!threadRes.ok) throw new Error('Failed to create thread')
202
- const threadData = await threadRes.json()
203
- const threadId = threadData.threadId
204
-
205
- // Set title on the thread via tags
206
- await fetch(`${baseUrl}/api/threads/${threadId}`, {
207
- method: 'PATCH',
208
- headers,
209
- body: JSON.stringify({ tags: [`title:${title}`] }),
210
- })
211
-
212
- // Build message payload with attachments
213
- const messagePayload: {
214
- role: string
215
- content: string
216
- attachments?: Array<{
217
- name: string
218
- mimeType: string
219
- data: string
220
- width?: number
221
- height?: number
222
- }>
223
- } = {
224
- role: 'user',
225
- content: message,
226
- }
227
-
228
- if (currentAttachments.length > 0) {
229
- messagePayload.attachments = currentAttachments.map(a => ({
230
- name: a.name,
231
- mimeType: a.mimeType,
232
- data: a.data,
233
- ...(a.width && a.height ? { width: a.width, height: a.height } : {}),
234
- }))
235
- }
236
-
237
- // Send the first message
238
- await fetch(`${baseUrl}/api/threads/${threadId}/messages`, {
189
+ const { threadId } = await threadRes.json() as CreatedThread
190
+
191
+ const attachmentPayloads: AttachmentPayload[] = currentAttachments.map(a => ({
192
+ name: a.name,
193
+ mimeType: a.mimeType,
194
+ data: a.data,
195
+ ...(a.width && a.height ? { width: a.width, height: a.height } : {}),
196
+ }))
197
+ const messageRes = await apiFetch(`/api/threads/${threadId}/messages`, {
239
198
  method: 'POST',
240
- headers,
241
- body: JSON.stringify(messagePayload),
199
+ body: JSON.stringify({
200
+ role: 'user',
201
+ content: message,
202
+ ...(attachmentPayloads.length > 0 ? { attachments: attachmentPayloads } : {}),
203
+ }),
242
204
  })
205
+ if (!messageRes.ok) throw new Error('Failed to send message')
243
206
 
244
- // Navigate to the thread - use agent info from selected agent
245
207
  const selectedAgent = agents.find(a => a.id === selectedAgentId)
208
+ const now = Math.floor(Date.now() / 1000) // API uses seconds
246
209
  onThreadCreated({
247
210
  id: threadId,
248
211
  agent_id: selectedAgentId,
249
212
  user_id: null,
250
- tags: [`title:${title}`],
251
- created_at: Math.floor(Date.now() / 1000), // API uses seconds
213
+ tags,
214
+ created_at: now,
215
+ last_activity_at: now,
216
+ executing: true,
252
217
  agent: {
253
218
  name: selectedAgent?.name,
254
- title: selectedAgent?.title,
255
- type: 'ai_human',
219
+ title: selectedAgent?.title ?? undefined,
220
+ side_a_backing: selectedAgent?.side_a_backing,
221
+ side_b_backing: selectedAgent?.side_b_backing,
256
222
  },
257
223
  })
258
224
  setMessage('')
@@ -262,7 +228,7 @@ export function EmptyState({
262
228
  } finally {
263
229
  setIsCreating(false)
264
230
  }
265
- }, [message, attachments, selectedAgentId, isCreating, onThreadCreated, baseUrl, headers, agents])
231
+ }, [message, attachments, selectedAgentId, isCreating, onThreadCreated, agents])
266
232
 
267
233
  return (
268
234
  <div className="flex-1 flex flex-col items-center px-4 py-8">
@@ -1,6 +1,6 @@
1
1
  'use client'
2
2
 
3
- import { useState, useCallback, type FormEvent } from 'react'
3
+ import { useState, useCallback, useEffect, type FormEvent } from 'react'
4
4
  import { useAuth } from '../hooks/useAuth'
5
5
  import { Logo } from './Logo'
6
6
 
@@ -9,7 +9,35 @@ export function Login() {
9
9
  const [password, setPassword] = useState('')
10
10
  const [error, setError] = useState('')
11
11
  const [isSubmitting, setIsSubmitting] = useState(false)
12
- const { login } = useAuth()
12
+ const { login, config, bootstrapStandardAgents, redirectToStandardAgents } = useAuth()
13
+
14
+ // Mirror the builder login: platform-connected instances sign in only with
15
+ // Standard Agents; the password form is for local-password instances.
16
+ const standardAgentsSignIn = !!config && (config.standardAgentsLogin || config.platformConnected)
17
+ const showPasswordForm = !!config && !config.hosted && !standardAgentsSignIn && config.localPassword
18
+
19
+ const handleStandardAgents = useCallback(async () => {
20
+ setError('')
21
+ if (config?.standardAgentsLogin) {
22
+ redirectToStandardAgents()
23
+ return
24
+ }
25
+ setIsSubmitting(true)
26
+ const result = await bootstrapStandardAgents()
27
+ if (!result.success) {
28
+ setError(result.error || 'Standard Agents sign-in failed.')
29
+ setIsSubmitting(false)
30
+ }
31
+ }, [config, bootstrapStandardAgents, redirectToStandardAgents])
32
+
33
+ useEffect(() => {
34
+ const saError = new URLSearchParams(window.location.search).get('sa_error')
35
+ if (saError) {
36
+ setError(saError === 'forbidden'
37
+ ? "Your Standard Agents account doesn't have access to this instance."
38
+ : "Standard Agents sign-in didn't complete. Please try again.")
39
+ }
40
+ }, [])
13
41
 
14
42
  const handleSubmit = useCallback(async (e: FormEvent) => {
15
43
  e.preventDefault()
@@ -51,6 +79,30 @@ export function Login() {
51
79
 
52
80
  {/* Login card */}
53
81
  <div className="bg-[var(--bg-secondary)]/80 backdrop-blur-xl rounded-3xl border border-[var(--border-primary)] shadow-2xl shadow-black/10 p-8">
82
+ {error && !showPasswordForm && (
83
+ <div className="mb-5 p-4 rounded-2xl bg-red-500/10 border border-red-500/20 text-red-400 text-sm">
84
+ {error}
85
+ </div>
86
+ )}
87
+
88
+ {standardAgentsSignIn && (
89
+ <button
90
+ type="button"
91
+ onClick={handleStandardAgents}
92
+ disabled={isSubmitting}
93
+ className="w-full py-3.5 px-4 rounded-xl bg-[var(--text-primary)] text-[var(--bg-primary)] font-semibold hover:opacity-90 disabled:opacity-40 transition-all duration-150 shadow-lg shadow-black/10"
94
+ >
95
+ {isSubmitting ? 'Signing in...' : 'Continue with Standard Agents'}
96
+ </button>
97
+ )}
98
+
99
+ {config && !standardAgentsSignIn && !showPasswordForm && (
100
+ <p className="text-sm text-[var(--text-secondary)] text-center">
101
+ This instance has no sign-in method available to the chat.
102
+ </p>
103
+ )}
104
+
105
+ {showPasswordForm && (
54
106
  <form onSubmit={handleSubmit} className="space-y-5">
55
107
  {error && (
56
108
  <div className="p-4 rounded-2xl bg-red-500/10 border border-red-500/20 text-red-400 text-sm flex items-center gap-3">
@@ -119,6 +171,7 @@ export function Login() {
119
171
  )}
120
172
  </button>
121
173
  </form>
174
+ )}
122
175
  </div>
123
176
 
124
177
  {/* Subtle footer */}
@@ -130,7 +183,7 @@ export function Login() {
130
183
  rel="noopener noreferrer"
131
184
  className="text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors"
132
185
  >
133
- AgentBuilder
186
+ Standard Agents
134
187
  </a>
135
188
  </p>
136
189
  </div>
@@ -1,10 +1,12 @@
1
1
  'use client'
2
2
 
3
- import { useState, useCallback } from 'react'
3
+ import { memo, useMemo, useState, useCallback } from 'react'
4
4
  import ReactMarkdown from 'react-markdown'
5
+ import remarkGfm from 'remark-gfm'
5
6
  import ShikiHighlighter, { isInlineCode } from 'react-shiki'
6
7
  import type { Components } from 'react-markdown'
7
8
  import type { Element } from 'hast'
9
+ import { repairStreamingMarkdown } from '../lib/streamingMarkdown'
8
10
 
9
11
  // Copy icon component
10
12
  function CopyIcon({ className }: { className?: string }) {
@@ -142,14 +144,28 @@ const components: Components = {
142
144
  p: ({ children }) => (
143
145
  <p className="mb-4 last:mb-0">{children}</p>
144
146
  ),
145
- ul: ({ children }) => (
146
- <ul className="list-disc list-inside mb-4 space-y-1">{children}</ul>
147
+ // Outside markers with padding keep wrapped list text aligned; task lists
148
+ // (GFM `- [ ]`) drop the bullet in favor of their checkbox.
149
+ ul: ({ children, className }) => (
150
+ <ul className={`${className === 'contains-task-list' ? 'list-none pl-1' : 'list-disc pl-6'} mb-4 space-y-1.5 [&_ul]:mt-1.5 [&_ul]:mb-0 [&_ol]:mt-1.5 [&_ol]:mb-0`}>{children}</ul>
147
151
  ),
148
- ol: ({ children }) => (
149
- <ol className="list-decimal list-inside mb-4 space-y-1">{children}</ol>
152
+ ol: ({ children, start }) => (
153
+ <ol start={start} className="list-decimal pl-6 mb-4 space-y-1.5 [&_ul]:mt-1.5 [&_ul]:mb-0 [&_ol]:mt-1.5 [&_ol]:mb-0">{children}</ol>
150
154
  ),
151
155
  li: ({ children }) => (
152
- <li className="text-[var(--text-primary)]">{children}</li>
156
+ <li className="text-[var(--text-primary)] pl-1 marker:text-[var(--text-tertiary)] [&>p]:mb-2 [&>p:last-child]:mb-0">{children}</li>
157
+ ),
158
+ input: ({ checked, type }) => type === 'checkbox' ? (
159
+ <input type="checkbox" checked={!!checked} readOnly className="mr-2 align-middle accent-[var(--text-primary)]" />
160
+ ) : null,
161
+ del: ({ children }) => (
162
+ <del className="text-[var(--text-tertiary)]">{children}</del>
163
+ ),
164
+ sup: ({ children }) => (
165
+ <sup className="text-[0.75em] [&_a]:no-underline">{children}</sup>
166
+ ),
167
+ section: ({ children, className }) => (
168
+ <section className={className === 'footnotes' ? 'mt-6 pt-4 border-t border-[var(--border-primary)] text-sm text-[var(--text-secondary)] [&_h2]:sr-only' : undefined}>{children}</section>
153
169
  ),
154
170
  h1: ({ children }) => (
155
171
  <h1 className="text-2xl font-bold mb-4 mt-6 first:mt-0 text-[var(--text-primary)]">{children}</h1>
@@ -168,16 +184,19 @@ const components: Components = {
168
184
  {children}
169
185
  </blockquote>
170
186
  ),
171
- a: ({ href, children }) => (
172
- <a
173
- href={href}
174
- target="_blank"
175
- rel="noopener noreferrer"
176
- className="text-blue-500 hover:text-blue-400 underline"
177
- >
178
- {children}
179
- </a>
180
- ),
187
+ // External links open in a new tab; in-page anchors (GFM footnotes) don't.
188
+ a: ({ href, children }) => {
189
+ const external = !!href && !href.startsWith('#')
190
+ return (
191
+ <a
192
+ href={href}
193
+ {...(external ? { target: '_blank', rel: 'noopener noreferrer' } : {})}
194
+ className="text-blue-500 hover:text-blue-400 underline underline-offset-2 break-words"
195
+ >
196
+ {children}
197
+ </a>
198
+ )
199
+ },
181
200
  strong: ({ children }) => (
182
201
  <strong className="font-semibold text-[var(--text-primary)]">{children}</strong>
183
202
  ),
@@ -188,35 +207,43 @@ const components: Components = {
188
207
  <hr className="my-6 border-[var(--border-primary)]" />
189
208
  ),
190
209
  table: ({ children }) => (
191
- <div className="overflow-x-auto my-4">
192
- <table className="min-w-full border-collapse border border-[var(--border-primary)]">
210
+ <div className="overflow-x-auto my-4 rounded-lg border border-[var(--border-primary)]">
211
+ <table className="min-w-full border-collapse text-sm">
193
212
  {children}
194
213
  </table>
195
214
  </div>
196
215
  ),
197
- th: ({ children }) => (
198
- <th className="border border-[var(--border-primary)] px-3 py-2 bg-[var(--bg-tertiary)] text-left font-semibold">
216
+ th: ({ children, style }) => (
217
+ <th style={style} className="border-b border-[var(--border-primary)] px-3 py-2 bg-[var(--bg-tertiary)] text-left font-semibold align-bottom">
199
218
  {children}
200
219
  </th>
201
220
  ),
202
- td: ({ children }) => (
203
- <td className="border border-[var(--border-primary)] px-3 py-2">
221
+ td: ({ children, style }) => (
222
+ <td style={style} className="border-t border-[var(--border-primary)] px-3 py-2 align-top">
204
223
  {children}
205
224
  </td>
206
225
  ),
207
226
  }
208
227
 
228
+ const remarkPlugins = [remarkGfm]
229
+
209
230
  interface MarkdownProps {
210
231
  children: string
211
232
  className?: string
233
+ /** True while the message is still streaming; repairs partial syntax. */
234
+ streaming?: boolean
212
235
  }
213
236
 
214
- export function Markdown({ children, className }: MarkdownProps) {
237
+ export const Markdown = memo(function Markdown({ children, className, streaming = false }: MarkdownProps) {
238
+ const source = useMemo(
239
+ () => (streaming ? repairStreamingMarkdown(children) : children),
240
+ [children, streaming],
241
+ )
215
242
  return (
216
243
  <div className={className}>
217
- <ReactMarkdown components={components}>
218
- {children}
244
+ <ReactMarkdown remarkPlugins={remarkPlugins} components={components}>
245
+ {source}
219
246
  </ReactMarkdown>
220
247
  </div>
221
248
  )
222
- }
249
+ })
@@ -7,20 +7,21 @@ export function MessageInput() {
7
7
  const [input, setInput] = useState('')
8
8
  const [sending, setSending] = useState(false)
9
9
  const {
10
- loading,
10
+ runStatus,
11
11
  sendMessage,
12
12
  stopExecution,
13
13
  addAttachment,
14
14
  attachments,
15
15
  removeAttachment,
16
- getPreviewUrl,
17
16
  } = useThread()
18
17
  const textareaRef = useRef<HTMLTextAreaElement>(null)
18
+ // Pushed by the runtime; drives the stop button instead of history loading.
19
+ const running = runStatus?.state === 'running'
19
20
  const fileInputRef = useRef<HTMLInputElement>(null)
20
21
 
21
22
  const handleSubmit = useCallback(async (e: React.FormEvent) => {
22
23
  e.preventDefault()
23
- if ((!input.trim() && attachments.length === 0) || loading || sending) return
24
+ if ((!input.trim() && attachments.length === 0) || running || sending) return
24
25
 
25
26
  const message = input
26
27
  setInput('')
@@ -35,7 +36,7 @@ export function MessageInput() {
35
36
  } finally {
36
37
  setSending(false)
37
38
  }
38
- }, [input, attachments.length, loading, sending, sendMessage])
39
+ }, [input, attachments.length, running, sending, sendMessage])
39
40
 
40
41
  const handleFileSelect = useCallback(async (e: React.ChangeEvent<HTMLInputElement>) => {
41
42
  const files = e.target.files
@@ -65,12 +66,12 @@ export function MessageInput() {
65
66
 
66
67
  // Focus textarea when not loading
67
68
  useEffect(() => {
68
- if (!loading && !sending) {
69
+ if (!running && !sending) {
69
70
  textareaRef.current?.focus()
70
71
  }
71
- }, [loading, sending])
72
+ }, [running, sending])
72
73
 
73
- const isDisabled = loading || sending
74
+ const isDisabled = running || sending
74
75
  const canSend = (input.trim() || attachments.length > 0) && !isDisabled
75
76
 
76
77
  return (
@@ -80,9 +81,8 @@ export function MessageInput() {
80
81
  <div className="px-3 pt-3 pb-2 border-b border-[var(--border-secondary)]">
81
82
  <div className="flex flex-wrap gap-2">
82
83
  {attachments.map((attachment) => {
83
- // Try multiple ways to get preview URL
84
- const previewUrl = getPreviewUrl(attachment) || (attachment as any).localPreviewUrl || (attachment as any).previewUrl
85
- const isImage = attachment.mimeType?.startsWith('image/') || (attachment as any).type?.startsWith('image/')
84
+ const previewUrl = attachment.previewUrl
85
+ const isImage = attachment.isImage
86
86
  return (
87
87
  <div
88
88
  key={attachment.id}
@@ -161,7 +161,7 @@ export function MessageInput() {
161
161
  />
162
162
 
163
163
  {/* Stop / Send button */}
164
- {loading ? (
164
+ {running ? (
165
165
  <button
166
166
  type="button"
167
167
  onClick={stopExecution}