


























@@ -555,6 +555,35 @@ function countImageInputs(value: unknown): number {
555555return count;
556556}
557557558+function extractLatestImageUserTurn(input: ResponsesInputItem[]) {
559+const latestUserIndex = findLastUserIndex(input);
560+if (latestUserIndex < 0) {
561+return { text: "", imageInputCount: 0 };
562+}
563+564+let startIndex = latestUserIndex;
565+while (
566+startIndex > 0 &&
567+input[startIndex - 1]?.role === "user" &&
568+Array.isArray(input[startIndex - 1]?.content)
569+) {
570+startIndex -= 1;
571+}
572+573+const imageTurnItems = input.slice(startIndex, latestUserIndex + 1);
574+const imageInputCount = countImageInputs(imageTurnItems.map((item) => item.content));
575+if (imageInputCount === 0) {
576+return { text: "", imageInputCount: 0 };
577+}
578+return {
579+text: imageTurnItems
580+.map((item) => extractInputText(item.content as unknown[]))
581+.filter(Boolean)
582+.join("\n"),
583+ imageInputCount,
584+};
585+}
586+558587function parseToolOutputJson(toolOutput: string): Record<string, unknown> | null {
559588if (!toolOutput.trim()) {
560589return null;
@@ -1009,7 +1038,7 @@ function buildAssistantText(
10091038extractExactMarkerDirective(prompt) ?? extractExactMarkerDirective(allInputText);
10101039const finishExactlyDirective =
10111040extractFinishExactlyDirective(prompt) ?? extractFinishExactlyDirective(allInputText);
1012-const imageInputCount = countImageInputs(input);
1041+const latestImageUserTurn = extractLatestImageUserTurn(input);
10131042const activeMemorySummary = extractActiveMemorySummary(allInputText);
10141043const snackPreference = extractSnackPreference(activeMemorySummary ?? memorySnippet);
10151044const sessionsSpawnError = extractToolErrorForNamedCall({
@@ -1036,10 +1065,16 @@ function buildAssistantText(
10361065if (isHeartbeatPrompt(prompt)) {
10371066return "HEARTBEAT_OK";
10381067}
1039-if (/roundtrip image inspection check/i.test(allInputText) && imageInputCount > 0) {
1068+if (
1069+/roundtrip image inspection check/i.test(latestImageUserTurn.text) &&
1070+latestImageUserTurn.imageInputCount > 0
1071+) {
10401072return "Protocol note: the generated attachment shows the same QA lighthouse scene from the previous step.";
10411073}
1042-if (/image understanding check/i.test(allInputText) && imageInputCount > 0) {
1074+if (
1075+/image understanding check/i.test(latestImageUserTurn.text) &&
1076+latestImageUserTurn.imageInputCount > 0
1077+) {
10431078return "Protocol note: the attached image is split horizontally, with red on top and blue on the bottom.";
10441079}
10451080if (/\bmarker\b/i.test(allInputText) && exactReplyDirective) {
@@ -1565,7 +1600,7 @@ async function buildResponsesPayload(
15651600extractExactReplyDirective(prompt) ?? extractExactReplyDirective(allInputText);
15661601const exactMarkerDirective =
15671602extractExactMarkerDirective(prompt) ?? extractExactMarkerDirective(allInputText);
1568-const imageInputCount = countImageInputs(input);
1603+const latestImageUserTurn = extractLatestImageUserTurn(input);
15691604const firstExactMarkerDirective = extractLabeledMarkerDirective(
15701605allInputText,
15711606"first exact marker",
@@ -1652,12 +1687,18 @@ async function buildResponsesPayload(
16521687if (/fanout worker beta/i.test(prompt)) {
16531688return buildAssistantEvents("BETA-OK");
16541689}
1655-if (/roundtrip image inspection check/i.test(allInputText) && imageInputCount > 0) {
1690+if (
1691+/roundtrip image inspection check/i.test(latestImageUserTurn.text) &&
1692+latestImageUserTurn.imageInputCount > 0
1693+) {
16561694return buildAssistantEvents(
16571695"Protocol note: the generated attachment shows the same QA lighthouse scene from the previous step.",
16581696);
16591697}
1660-if (/image understanding check/i.test(allInputText) && imageInputCount > 0) {
1698+if (
1699+/image understanding check/i.test(latestImageUserTurn.text) &&
1700+latestImageUserTurn.imageInputCount > 0
1701+) {
16611702return buildAssistantEvents(
16621703"Protocol note: the attached image is split horizontally, with red on top and blue on the bottom.",
16631704);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。