

















@@ -867,6 +867,7 @@ async function runMatrixToolProgressScenario(
867867params: {
868868expectedPreviewKind: MatrixQaObservedEvent["kind"];
869869finalText: string;
870+allowFinalOnly?: boolean;
870871label: string;
871872allowGenericProgressLine?: boolean;
872873mentionSafety?: boolean;
@@ -896,9 +897,13 @@ async function runMatrixToolProgressScenario(
896897predicate: (event) =>
897898event.roomId === context.roomId &&
898899event.sender === context.sutUserId &&
899-event.kind === params.expectedPreviewKind &&
900-(event.relatesTo === undefined ||
901-(event.relatesTo.relType === "m.replace" && matchesExpectedProgress(event.body))),
900+((event.kind === params.expectedPreviewKind &&
901+(event.relatesTo === undefined ||
902+(event.relatesTo.relType === "m.replace" && matchesExpectedProgress(event.body)))) ||
903+(params.allowFinalOnly === true &&
904+event.relatesTo === undefined &&
905+isMatrixQaMessageLikeKind(event.kind) &&
906+doesMatrixQaReplyBodyMatchToken(event, params.finalText))),
902907roomId: context.roomId,
903908since: startSince,
904909timeoutMs: context.timeoutMs,
@@ -916,6 +921,44 @@ async function runMatrixToolProgressScenario(
916921}),
917922);
918923});
924+if (
925+params.allowFinalOnly === true &&
926+doesMatrixQaReplyBodyMatchToken(preview.event, params.finalText)
927+) {
928+const unexpectedWorkingEvents = findMatrixQaUnexpectedWorkingEvents({
929+events: context.observedEvents,
930+finalEventId: preview.event.eventId,
931+startIndex: startObservedIndex,
932+sutUserId: context.sutUserId,
933+});
934+if (unexpectedWorkingEvents.length > 0) {
935+throw new Error(
936+`Matrix tool progress leaked outside preview event: ${unexpectedWorkingEvents.map((event) => `${event.eventId}:${event.body ?? ""}`).join("; ")}`,
937+);
938+}
939+advanceMatrixQaActorCursor({
940+actorId: "driver",
941+syncState: context.syncState,
942+nextSince: preview.since,
943+ startSince,
944+});
945+const finalReply = buildMatrixReplyArtifact(preview.event, params.finalText);
946+return {
947+artifacts: {
948+ driverEventId,
949+previewEventId: undefined,
950+reply: finalReply,
951+token: params.finalText,
952+ triggerBody,
953+},
954+details: [
955+`driver event: ${driverEventId}`,
956+`scenario: ${params.label}`,
957+"preview event: <none>; final delivered before observable tool-progress preview",
958+ ...buildMatrixReplyDetails("final reply", finalReply),
959+].join("\n"),
960+} satisfies MatrixQaScenarioExecution;
961+}
919962const previewRootEventId = getPreviewRootEventId(preview.event);
920963const progress = matchesExpectedProgress(preview.event.body)
921964 ? preview
@@ -1041,6 +1084,7 @@ export async function runToolProgressPreviewScenario(context: MatrixQaScenarioCo
10411084expectedPreviewKind: "notice",
10421085finalText: buildMatrixQaToken("MATRIX_QA_TOOL_PROGRESS"),
10431086label: "tool progress preview",
1087+allowFinalOnly: true,
10441088allowGenericProgressLine: true,
10451089progressPattern: /\b(?:tool:\s*)?read\s*:\s*from\b|\btool:\s*read\b/i,
10461090triggerBodyBuilder: buildMatrixToolProgressPrompt,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。