feat(shared): add parallel Stream Event v1 channel to RunManager - #42
Open
sjr666666 wants to merge 3 commits into
Open
feat(shared): add parallel Stream Event v1 channel to RunManager#42sjr666666 wants to merge 3 commits into
sjr666666 wants to merge 3 commits into
Conversation
sjr666666
force-pushed
the
feat/27-stream-event-runtime
branch
2 times, most recently
from
September 11, 2026 09:12
0ce4fa7 to
2f0ba16
Compare
This was referenced Sep 11, 2026
sjr666666
force-pushed
the
feat/27-stream-event-runtime
branch
2 times, most recently
from
September 13, 2026 13:01
23e2b9d to
3fcb288
Compare
added 3 commits
September 13, 2026 21:03
Introduce the pure-type foundation for the structured streaming event protocol (issue helsome#27): versioned envelope, 12 typed events, and the idempotency/cancel/reconnect contracts as types. Zero runtime change. Adds ADR 0001 documenting context, decision, migration path and open questions for maintainer review.
Emit Stream Event Protocol v1 events alongside the existing AgentEvent stream (issue helsome#27, ADR 0001 migration step 2). Adds toStreamEvents mapping (8 AgentEvent types -> 12 protocol events, cancel normalized to 'cancelled') and RunManager.subscribeStream. Existing AgentEvent consumers are untouched; the parallel channel only activates when a stream subscriber is registered.
StreamEvent was a single indexed-union instantiation (Tagged StreamEventEnvelope<StreamEventType>), so payload could not be narrowed by type in switch/if. Rewrite as a distributive mapped union; on-disk type shape is unchanged. Adjusts adapter unit-test helper accordingly.
sjr666666
force-pushed
the
feat/27-stream-event-runtime
branch
from
September 13, 2026 13:05
3fcb288 to
9275dec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景与动机
issue #27 需要一条版本化、带单调
sequence与显式取消的流式事件协议。#41 落了协议类型;本 PR 是第二步:在RunManager里加一条并行的协议通道,让现有AgentEvent消费方完全不受影响。完成了什么
packages/shared/src/kernel/stream-event-adapter.ts(新增):纯函数toStreamEvents(AgentEvent) -> StreamEvent[]的映射。现有 8 事件映射到 12 种协议事件:message_delta→text_delta(保留增量字段)、tool_completed→tool_result、run_failed(code=RUN_CANCELLED)→ 显式cancelled(不再从失败推断取消);时间戳统一为 ISO 8601。RunManager.subscribeStream(sessionId, event):新的并行订阅入口;现有subscribe/AgentEvent路径与全部消费方未改动,没有 stream 订阅者时不产生额外工作。sequence契约:runtime 与本管理器都会自产事件、各自从 1 计数,因此在emit唯一汇聚点统一重排为 run 内严格 +1(幂等键与 replay 游标都依赖它)。向后兼容
对现有消费方无行为变更;未注册 stream 订阅者时零开销。renderer / transport 接线是下一步(#43)。
关联 Issue
Refs #27(第二步,不关闭)、#34(身份模型)。依赖 #41。
验证
环境:Bun 1.4.2 / Windows 11 (NT 10.0.26200)
CI(本 PR 的 checks,全部 pass):Typecheck / Focused tests / Full unit tests (advisory) / Secret scan。
本地
本机 Windows 依赖安装不完整(
execa等解析失败,origin/main上同样存在),长桥链路相关的 E2E 无法在本机加载,由 CI 覆盖。Open questions
与 ADR 0001 §Open questions 一致(resume 数据源、
status.phase取值充分性)。messageId与runId的身份问题已在 #43 收敛为"message 级事件带messageId、run 级不带"。Rebase 说明
已 rebase 到最新
main(046b5d3)。栈 #41 → #42 → #43;合并时以 #43 栈顶一次性带入,不再分别 squash #41/#42。