feat: WS request proxy — Phase 2 (#210) #214
Reference in New Issue
Block a user
Delete Branch "feat/210-ws-gateway-phase2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Phase 2 of #210: Dashboard API 请求通过 Gateway → WebSocket → 本地 serve 代理,替代 HTTP fetch 经 tunnel。
Why
Phase 1 建立了 WS 连接,但请求仍走 HTTP fetch。CF Workers 不能 fetch localhost(403),所以 WS 代理是让 Dashboard 正常工作的关键。
Changes
Gateway (
packages/workflow-gateway/)src/ws-protocol.ts— 新增 WsRequest/WsResponse 类型 + 严格解析器src/agent-socket.ts— DO 新增 proxy POST 路由:发 WsRequest 到 WS → 等 WsResponse(30s 超时 504,无连接 503)src/index.ts—/api/agents/:agent/*优先走 DO WS 代理,503 时 fallback 到 HTTP fetchpackage.json— exports 增加./ws-protocolAgent (
packages/cli-workflow/)src/commands/serve/ws-client.ts— 收到 WsRequest 后 fetchlocalhost:PORT,回传 WsResponsesrc/commands/serve/serve.ts— 传localPort给 WS clientpackage.json— 依赖@uncaged/workflow-gatewayTesting
#213 验证:
Ref
e84650ccf5toec3c97b200Clean implementation. Good type-safe WS protocol parsers, proper error handling with fallback from WS→direct fetch, no convention violations. LGTM.