






















@@ -820,6 +820,12 @@ function extractLastCapture(text: string, pattern: RegExp) {
820820return lastMatch?.[1]?.trim() || null;
821821}
822822823+function extractCaptures(text: string, pattern: RegExp) {
824+const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
825+const globalPattern = new RegExp(pattern.source, flags);
826+return Array.from(text.matchAll(globalPattern), (match) => match[1]?.trim()).filter(Boolean);
827+}
828+823829function extractLastMatchingUserText(texts: string[], pattern: RegExp) {
824830for (let index = texts.length - 1; index >= 0; index -= 1) {
825831const text = texts[index] ?? "";
@@ -872,6 +878,29 @@ function extractLabeledMarkerDirective(text: string, label: string) {
872878);
873879}
874880881+function extractBlockStreamingMarkerDirectives(text: string) {
882+const firstLabeledMarker = extractLabeledMarkerDirective(text, "first exact marker");
883+const secondLabeledMarker = extractLabeledMarkerDirective(text, "second exact marker");
884+if (firstLabeledMarker && secondLabeledMarker) {
885+return {
886+first: firstLabeledMarker,
887+second: secondLabeledMarker,
888+};
889+}
890+891+const markers = extractCaptures(text, /exact marker\b[^:\n]{0,120}:\s*`([^`]+)`/i);
892+if (markers.length < 2) {
893+return null;
894+}
895+const [first, second] = markers.slice(-2);
896+return first && second
897+ ? {
898+ first,
899+ second,
900+}
901+ : null;
902+}
903+875904function extractQuotedToolArg(text: string, name: string) {
876905const escapedName = escapeRegExp(name);
877906return extractLastCapture(text, new RegExp(`\\b${escapedName}\\s*=\\s*"([^"]+)"`, "i"));
@@ -1604,15 +1633,14 @@ async function buildResponsesPayload(
16041633extractExactReplyDirective(prompt) ?? extractExactReplyDirective(allInputText);
16051634const exactMarkerDirective =
16061635extractExactMarkerDirective(prompt) ?? extractExactMarkerDirective(allInputText);
1636+const blockStreamingPrompt =
1637+extractLastMatchingUserText(extractAllUserTexts(input), QA_BLOCK_STREAMING_PROMPT_RE) ||
1638+prompt ||
1639+allInputText;
1640+const blockStreamingMarkers =
1641+extractBlockStreamingMarkerDirectives(blockStreamingPrompt) ??
1642+extractBlockStreamingMarkerDirectives(allInputText);
16071643const latestImageUserTurn = extractLatestImageUserTurn(input);
1608-const firstExactMarkerDirective = extractLabeledMarkerDirective(
1609-allInputText,
1610-"first exact marker",
1611-);
1612-const secondExactMarkerDirective = extractLabeledMarkerDirective(
1613-allInputText,
1614-"second exact marker",
1615-);
16161644const isGroupChat = allInputText.includes('"is_group_chat": true');
16171645const isBaselineUnmentionedChannelChatter = /\bno bot ping here\b/i.test(prompt);
16181646const hasReasoningOnlyRetryInstruction = allInputText.includes(QA_REASONING_ONLY_RETRY_NEEDLE);
@@ -1832,23 +1860,19 @@ async function buildResponsesPayload(
18321860}
18331861return buildAssistantEvents(toolProgressReplyDirective);
18341862}
1835-if (
1836-QA_BLOCK_STREAMING_PROMPT_RE.test(allInputText) &&
1837-firstExactMarkerDirective &&
1838-secondExactMarkerDirective
1839-) {
1863+if (QA_BLOCK_STREAMING_PROMPT_RE.test(allInputText) && blockStreamingMarkers) {
18401864return buildAssistantEvents([
18411865{
18421866id: "msg_mock_block_1",
18431867phase: "final_answer",
1844-streamDeltas: splitMockStreamingText(firstExactMarkerDirective),
1845-text: firstExactMarkerDirective,
1868+streamDeltas: splitMockStreamingText(blockStreamingMarkers.first),
1869+text: blockStreamingMarkers.first,
18461870},
18471871{
18481872id: "msg_mock_block_2",
18491873phase: "final_answer",
1850-streamDeltas: splitMockStreamingText(secondExactMarkerDirective),
1851-text: secondExactMarkerDirective,
1874+streamDeltas: splitMockStreamingText(blockStreamingMarkers.second),
1875+text: blockStreamingMarkers.second,
18521876},
18531877]);
18541878}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。