| 332 | * claude/codex, which carry their own CLI login. |
| 333 | */ |
| 334 | export async function quickChat( |
| 335 | prompt: string, |
| 336 | agent?: string, |
| 337 | credentialSlug?: string, |
| 338 | targetWsId?: string, |
| 339 | terminalTheme?: TerminalThemeVariant, |
| 340 | ): Promise<QuickChatResult> { |
| 341 | const body: Record<string, unknown> = { prompt }; |
| 342 | if (agent !== undefined) body['agent'] = agent; |
| 343 | if (credentialSlug !== undefined) body['credentialSlug'] = credentialSlug; |
| 344 | if (targetWsId !== undefined) body['targetWsId'] = targetWsId; |
| 345 | if (terminalTheme !== undefined) body['terminalTheme'] = terminalTheme; |
| 346 | const res = await fetch('/api/workspaces/quick-chat', { |
| 347 | method: 'POST', |
| 348 | headers: { 'content-type': 'application/json' }, |
| 349 | body: JSON.stringify(body), |
| 350 | }); |
| 351 | if (!res.ok) { |
| 352 | const parsed = (await res.json().catch(() => null)) as { error?: string } | null; |
| 353 | throw new QuickChatError(`quick chat failed: ${res.status} ${parsed?.error ?? ''}`, parsed?.error); |
| 354 | } |
| 355 | return (await res.json()) as QuickChatResult; |
| 356 | } |
| 357 | |
| 358 | /** Pause a session — kills its PTY but keeps the record so it can be resumed later. */ |
| 359 | export async function pauseSession(wsId: string, sessionId: string): Promise<boolean> { |