

























@@ -8,6 +8,7 @@ import type { ReplyPayload } from "../types.js";
88import { createBlockReplyCoalescer } from "./block-reply-coalescer.js";
99import type { BlockStreamingCoalescing } from "./block-streaming.js";
101011+/** Streaming block reply pipeline that tracks sent content and media. */
1112export type BlockReplyPipeline = {
1213enqueue: (payload: ReplyPayload) => void;
1314flush: (options?: { force?: boolean }) => Promise<void>;
@@ -19,12 +20,14 @@ export type BlockReplyPipeline = {
1920getSentMediaUrls: () => readonly string[];
2021};
212223+/** Optional buffering strategy used before payloads enter block delivery. */
2224export type BlockReplyBuffer = {
2325shouldBuffer: (payload: ReplyPayload) => boolean;
2426onEnqueue?: (payload: ReplyPayload) => void;
2527finalize?: (payload: ReplyPayload) => ReplyPayload;
2628};
272930+/** Buffers audio payloads so final delivery can preserve voice presentation. */
2831export function createAudioAsVoiceBuffer(params: {
2932isAudioPayload: (payload: ReplyPayload) => boolean;
3033}): BlockReplyBuffer {
@@ -40,6 +43,7 @@ export function createAudioAsVoiceBuffer(params: {
4043};
4144}
424546+/** Creates a stable duplicate key for a complete outbound payload. */
4347export function createBlockReplyPayloadKey(payload: ReplyPayload): string {
4448const reply = resolveSendableOutboundReplyParts(payload);
4549return JSON.stringify({
@@ -53,6 +57,7 @@ export function createBlockReplyPayloadKey(payload: ReplyPayload): string {
5357});
5458}
555960+/** Creates a duplicate key that ignores reply target for final suppression. */
5661export function createBlockReplyContentKey(payload: ReplyPayload): string {
5762const reply = resolveSendableOutboundReplyParts(payload);
5863// Content-only key used for final-payload suppression after block streaming.
@@ -88,6 +93,7 @@ const withTimeout = async <T>(
8893}
8994};
909596+/** Creates the ordered block reply delivery pipeline for streamed payloads. */
9197export function createBlockReplyPipeline(params: {
9298onBlockReply: (
9399payload: ReplyPayload,
@@ -138,6 +144,7 @@ export function createBlockReplyPipeline(params: {
138144}
139145pendingKeys.add(payloadKey);
140146147+// Preserve outbound order by chaining sends; abort after timeout to avoid stale blocks.
141148const timeoutError = new Error(`block reply delivery timed out after ${timeoutMs}ms`);
142149const abortController = new AbortController();
143150sendChain = sendChain
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。