import { readAgentMessageContent } from "./agent-message-access.js";
import { buildMemoryContextBlock } from "./context-fence.js";
//#region src/agent/memory/inject-prefetch.ts
/**
* Prefix user message with fenced prefetched memory context (if any).
*/
async function injectPrefetchIntoUserMessage(memoryManager, sessionKey, userMessage, queryText) {
	const q = queryText.trim();
	if (!q) return userMessage;
	const block = buildMemoryContextBlock(await memoryManager.prefetchAll(q, { sessionId: sessionKey }));
	if (!block.trim()) return userMessage;
	const prefix = `${block}\n\n`;
	const c = readAgentMessageContent(userMessage);
	if (typeof c === "string") return {
		...userMessage,
		content: prefix + c
	};
	if (Array.isArray(c) && c.length > 0) {
		const first = c[0];
		if (first?.type === "text" && typeof first.text === "string") {
			const copy = [...c];
			copy[0] = {
				type: "text",
				text: prefix + first.text
			};
			return {
				...userMessage,
				content: copy
			};
		}
		return {
			...userMessage,
			content: [{
				type: "text",
				text: prefix
			}, ...c]
		};
	}
	return userMessage;
}
//#endregion
export { injectPrefetchIntoUserMessage };

//# sourceMappingURL=inject-prefetch.js.map