feat(session)!: embed assistant streams in format v2

This commit is contained in:
Tianyi Cui
2026-09-02 04:00:01 +08:00
parent 0bb7bba015
commit f99b06eaed
387 changed files with 9491 additions and 4625 deletions
+10 -9
View File
@@ -90,8 +90,8 @@ function summarize(session: Session, firstSeq: SessionLogOffset): RunOutcome {
/**
* Project provider-reported reasoning from one owned run to stderr as it is
* appended, while keeping final outcome derivation on the durable log.
* @param ctx - plugin context carrying the Session event feed.
* streamed, while keeping final outcome derivation on the durable log.
* @param ctx - plugin context carrying the live Assistant frame feed.
* @param agent - the exact Agent whose reasoning belongs to this invocation.
* @param stderr - progress output sink.
* @returns a disposer that also terminates an unterminated reasoning line.
@@ -101,7 +101,6 @@ function streamReasoning(
agent: Agent,
stderr: HeadlessIo['stderr'],
): () => void {
let started = false
let open = false
let endsWithNewline = true
const close = (): void => {
@@ -110,15 +109,17 @@ function streamReasoning(
open = false
endsWithNewline = true
}
const dispose = ctx.on('session/event', (session, event) => {
if (session !== agent.session) return
if (event.type === 'turn/start') {
const dispose = ctx.on('agent/assistant-stream', ({ agent: subject, frame }) => {
if (subject !== agent) return
if (frame.type === 'start') {
close()
started = true
return
}
if (!started || event.type !== 'assistant/chunk') return
const chunk = event.data.chunk
if (frame.type === 'end') {
close()
return
}
const chunk = frame.chunk
switch (chunk.type) {
case 'reasoning-delta':
if (chunk.text === '') return