























@@ -7,7 +7,13 @@ import { normalizeOptionalString } from "../../shared/string-coerce.js";
77import type { MsgContext } from "../templating.js";
88import { resolveAgentTurnAttachments } from "./agent-turn-attachments.js";
9910-function countCurrentImageAttachmentCandidates(ctx: MsgContext): number {
10+type CurrentImageAttachment = {
11+index: number;
12+path: string;
13+mediaType: string;
14+};
15+16+function collectCurrentImageAttachments(ctx: MsgContext): CurrentImageAttachment[] {
1117const pathsFromArray = Array.isArray(ctx.MediaPaths) ? ctx.MediaPaths : undefined;
1218const paths =
1319pathsFromArray && pathsFromArray.length > 0
@@ -16,21 +22,43 @@ function countCurrentImageAttachmentCandidates(ctx: MsgContext): number {
1622 ? [ctx.MediaPath]
1723 : [];
1824if (paths.length === 0) {
19-return 0;
25+return [];
2026}
2127const types =
2228Array.isArray(ctx.MediaTypes) && ctx.MediaTypes.length === paths.length
2329 ? ctx.MediaTypes
2430 : undefined;
25-let count = 0;
31+const attachments: CurrentImageAttachment[] = [];
2632for (const [index, pathValue] of paths.entries()) {
2733const mediaPath = normalizeOptionalString(pathValue);
2834const mediaType = normalizeOptionalString(types?.[index] ?? ctx.MediaType);
2935if (mediaPath && mediaType?.startsWith("image/")) {
30-count++;
36+attachments.push({ index, path: mediaPath, mediaType });
3137}
3238}
33-return count;
39+return attachments;
40+}
41+42+function collectDescribedImageAttachmentIndexes(ctx: MsgContext): Set<number> {
43+return new Set(
44+ctx.MediaUnderstanding?.filter((output) => output.kind === "image.description").map(
45+(output) => output.attachmentIndex,
46+) ?? [],
47+);
48+}
49+50+function createUndescribedImageContext(
51+ctx: MsgContext,
52+undescribedAttachments: CurrentImageAttachment[],
53+): MsgContext {
54+const first = undescribedAttachments[0];
55+return {
56+ ...ctx,
57+MediaPath: first?.path,
58+MediaType: first?.mediaType,
59+MediaPaths: undescribedAttachments.map((attachment) => attachment.path),
60+MediaTypes: undescribedAttachments.map((attachment) => attachment.mediaType),
61+};
3462}
35633664export async function resolveCurrentTurnImages(params: {
@@ -46,14 +74,21 @@ export async function resolveCurrentTurnImages(params: {
4674return { images: params.images, imageOrder: params.imageOrder };
4775}
487649-const currentImageCandidateCount = countCurrentImageAttachmentCandidates(params.ctx);
50-if (currentImageCandidateCount === 0) {
77+const currentImageAttachments = collectCurrentImageAttachments(params.ctx);
78+if (currentImageAttachments.length === 0) {
79+return { images: params.images, imageOrder: params.imageOrder };
80+}
81+const describedImageIndexes = collectDescribedImageAttachmentIndexes(params.ctx);
82+const undescribedImageAttachments = currentImageAttachments.filter(
83+(attachment) => !describedImageIndexes.has(attachment.index),
84+);
85+if (undescribedImageAttachments.length === 0) {
5186return { images: params.images, imageOrder: params.imageOrder };
5287}
53885489try {
5590const resolved = await resolveAgentTurnAttachments({
56-ctx: params.ctx,
91+ctx: createUndescribedImageContext(params.ctx, undescribedImageAttachments),
5792cfg: params.cfg,
5893includeRecentHistoryImages: false,
5994});
@@ -64,9 +99,9 @@ export async function resolveCurrentTurnImages(params: {
6499mimeType: attachment.mediaType,
65100}),
66101);
67-if (images.length < currentImageCandidateCount) {
102+if (images.length < undescribedImageAttachments.length) {
68103logVerbose(
69-`agent-runner: native PI media resolution produced ${images.length}/${currentImageCandidateCount} current image attachment(s); falling back to prompt image refs`,
104+`agent-runner: native PI media resolution produced ${images.length}/${undescribedImageAttachments.length} current image attachment(s); falling back to prompt image refs`,
70105);
71106return { images: params.images, imageOrder: params.imageOrder };
72107}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。