import { resolveImageModelConfigForTool } from "./tool-model-config.js";
import { describeImagesWithFallback } from "./understanding/runtime.js";
import { resolveImageHandlingStrategy } from "./vision-detection.js";
//#region src/agent/image/inbound-image-handling.ts
async function resolveInboundImageContentParts(params) {
	if (resolveImageHandlingStrategy(params.modelRef) === "native") return params.images.map((att) => ({
		type: "image",
		data: att.data,
		mimeType: att.mimeType
	}));
	const toolCfg = resolveImageModelConfigForTool({ cfg: params.cfg });
	const primary = toolCfg?.primary;
	const fallbacks = toolCfg?.fallbacks ?? [];
	if (!primary) return [{
		type: "text",
		text: `[${params.images.length} image(s) attached; configure agents.defaults.imageModel to describe them.]`
	}];
	try {
		return [{
			type: "text",
			text: `[Image description: ${(await describeImagesWithFallback({
				modelRef: primary,
				fallbacks,
				images: params.images.map((att) => ({
					buffer: Buffer.from(att.data, "base64"),
					mimeType: att.mimeType
				})),
				prompt: params.userTextForContext.trim() ? `Describe these images in the context of the user's message: "${params.userTextForContext}"` : "Describe these images in detail.",
				maxTokens: 1024,
				timeoutMs: 3e4
			})).text}]`
		}];
	} catch (err) {
		return [{
			type: "text",
			text: `[${params.images.length} image(s) attached but could not be described: ${err instanceof Error ? err.message : String(err)}]`
		}];
	}
}
//#endregion
export { resolveInboundImageContentParts };

//# sourceMappingURL=inbound-image-handling.js.map