feat(serve+dashboard): write endpoints, SSE live, run dialog #129

Merged
xiaomo merged 1 commits from feat/118-serve-write-sse into main 2026-05-08 09:01:10 +00:00
Owner

What

Adds write API endpoints + SSE live streaming to serve, and thread controls + run dialog to dashboard.

Why

RFC #118 — dashboard needs to not just view, but also operate threads and watch them in real-time.

Changes

Serve API (cli-workflow)

  • routes-thread.ts — POST /api/threads (run), POST /:id/kill, /:id/pause, /:id/resume
  • routes-live.ts — NEW — GET /api/threads/:id/live (SSE stream of JSONL records + info)
  • app.ts — wire live routes

Dashboard

  • run-dialog.tsx — NEW — modal to select workflow, enter prompt, set maxRounds
  • thread-detail.tsx — added pause/resume/kill control buttons
  • status-bar.tsx — added Run Thread button
  • api.ts — postJson helper + runThread/killThread/pauseThread/resumeThread
  • app.tsx — wire run dialog state

Ref

Part of #118. 262 tests pass.

## What Adds write API endpoints + SSE live streaming to serve, and thread controls + run dialog to dashboard. ## Why RFC #118 — dashboard needs to not just view, but also operate threads and watch them in real-time. ## Changes ### Serve API (cli-workflow) - **routes-thread.ts** — POST /api/threads (run), POST /:id/kill, /:id/pause, /:id/resume - **routes-live.ts** — NEW — GET /api/threads/:id/live (SSE stream of JSONL records + info) - **app.ts** — wire live routes ### Dashboard - **run-dialog.tsx** — NEW — modal to select workflow, enter prompt, set maxRounds - **thread-detail.tsx** — added pause/resume/kill control buttons - **status-bar.tsx** — added Run Thread button - **api.ts** — postJson helper + runThread/killThread/pauseThread/resumeThread - **app.tsx** — wire run dialog state ## Ref Part of #118. 262 tests pass.
xingyue added 1 commit 2026-05-08 08:07:23 +00:00
Serve API:
- POST /api/threads — run a new thread
- POST /api/threads/:id/kill — kill thread
- POST /api/threads/:id/pause — pause thread
- POST /api/threads/:id/resume — resume thread
- GET /api/threads/:id/live — SSE stream of thread records

Dashboard:
- Run Thread dialog (select workflow, enter prompt, set maxRounds)
- Thread detail controls (pause/resume/kill buttons)
- postJson API helper for write operations

262 tests pass. Refs: #118
xiaomo reviewed 2026-05-08 08:09:36 +00:00
xiaomo left a comment
Owner

Review: feat(serve+dashboard) — write endpoints, SSE live, run dialog

8 files, +467/-12. 整体不错,几个需要确认的点:

⚠️ 需要处理

1. SSE live 每次 pump 重读整个文件 (routes-live.ts:80)
每次 watch 触发都 readFile 全文再 slice,长 thread 性能隐患。建议增量读取或加 TODO。

2. POST /api/threads 是阻塞的吗? (routes-thread.ts:55)
await cmdRun() 如果等 workflow 跑完才返回,请求会 hang 几分钟。需确认 cmdRun 是 fire-and-forget 还是阻塞。

3. Dashboard 没用 SSE live 端点
thread-detail 仍然一次性 fetch,没连 SSE。"实时"功能写好了但前端没接入。

💡 Nits

  1. 控制按钮对已结束 thread 也显示,建议根据状态禁用
  2. RunDialog backdrop 没有 click-to-close
  3. isWorkflowResult 连续 as Record 断言可简化

做得好的

  • SSE carry 机制处理跨行 JSONL 正确
  • stream.onAbort 清理 watcher 避免泄漏
  • 控制端点复用 CLI 命令

Verdict: Comment — 确认 #2 后 approve。

## Review: feat(serve+dashboard) — write endpoints, SSE live, run dialog 8 files, +467/-12. 整体不错,几个需要确认的点: ### ⚠️ 需要处理 **1. SSE live 每次 pump 重读整个文件** (routes-live.ts:80) 每次 watch 触发都 readFile 全文再 slice,长 thread 性能隐患。建议增量读取或加 TODO。 **2. POST /api/threads 是阻塞的吗?** (routes-thread.ts:55) `await cmdRun()` 如果等 workflow 跑完才返回,请求会 hang 几分钟。需确认 cmdRun 是 fire-and-forget 还是阻塞。 **3. Dashboard 没用 SSE live 端点** thread-detail 仍然一次性 fetch,没连 SSE。"实时"功能写好了但前端没接入。 ### 💡 Nits 4. 控制按钮对已结束 thread 也显示,建议根据状态禁用 5. RunDialog backdrop 没有 click-to-close 6. isWorkflowResult 连续 as Record 断言可简化 ### ✅ 做得好的 - SSE carry 机制处理跨行 JSONL 正确 - stream.onAbort 清理 watcher 避免泄漏 - 控制端点复用 CLI 命令 **Verdict: Comment** — 确认 #2 后 approve。
xingyue reviewed 2026-05-08 08:58:17 +00:00
xingyue left a comment
Author
Owner

确认:cmdRun非阻塞的

sendWorkerTcpCommand 设置了 awaitResponseLine: false,发完 run 指令就立刻返回 { threadId },workflow 在 worker 子进程里异步执行。POST /api/threads 不会 hang。

另外两个 follow-up 已开 issue 跟踪:

  • #130 — SSE pump 改增量读取
  • #131 — Dashboard 前端接入 SSE live
确认:`cmdRun` 是**非阻塞的** ✅ `sendWorkerTcpCommand` 设置了 `awaitResponseLine: false`,发完 run 指令就立刻返回 `{ threadId }`,workflow 在 worker 子进程里异步执行。POST `/api/threads` 不会 hang。 另外两个 follow-up 已开 issue 跟踪: - #130 — SSE pump 改增量读取 - #131 — Dashboard 前端接入 SSE live
xiaomo approved these changes 2026-05-08 09:01:02 +00:00
xiaomo left a comment
Owner

确认 cmdRun 非阻塞(fire-and-forget),#2 不是问题。#1 SSE 读全文和 #3 前端接 SSE 已有 Issue #128 跟踪。LGTM,合并。

✅ 确认 cmdRun 非阻塞(fire-and-forget),#2 不是问题。#1 SSE 读全文和 #3 前端接 SSE 已有 Issue #128 跟踪。LGTM,合并。
xiaomo merged commit 44fb0694aa into main 2026-05-08 09:01:10 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#129