diff --git a/lib/net-scope.js b/lib/net-scope.js index 053ec72..bb6a9cb 100644 --- a/lib/net-scope.js +++ b/lib/net-scope.js @@ -450,7 +450,14 @@ async function denialMessage() { }; } -function denialStream() { +const COMPACT_STREAM_TYPES = new Set([ + "chunk", + "text-chunks", + "reasoning-chunks", + "tool-call-chunks", +]); + +function denialChunks() { return [ { type: "block-start", index: 0, blockType: "text" }, { type: "text-delta", index: 0, text: DENIAL }, @@ -459,6 +466,22 @@ function denialStream() { ]; } +/** 宿主持久化只要 Accumulator 紧致记录;裸 chunk 会让 firstRunMemberTime 读 undefined.length(#84)。 */ +function denialStream(now = Date.now()) { + const time0 = Number.isSafeInteger(now) ? now : Date.now(); + const stream = denialChunks().map((chunk, i) => ({ + type: "chunk", + time: time0 + i, + chunk, + })); + for (const record of stream) { + if (!record || !COMPACT_STREAM_TYPES.has(record.type)) { + throw new TypeError("denial stream must use compact Assistant records"); + } + } + return stream; +} + async function appendDenial(session, turn, step) { session.append("assistant/message", { turn,