import { n as extractAssistantTextForPhase } from "./chat-message-content-ir65IHKw.js";
import "./pi-embedded-helpers-XZLyX3NH.js";
import { S as sanitizeUserFacingText } from "./errors-BAYY50Ex.js";
import { r as sanitizeAssistantVisibleTextWithProfile } from "./assistant-visible-text-CZBcZ1bS.js";
//#region src/agents/tools/chat-history-text.ts
function stripToolMessages(messages) {
	return messages.filter((msg) => {
		if (!msg || typeof msg !== "object") return true;
		const role = msg.role;
		return role !== "toolResult" && role !== "tool";
	});
}
/**
* Sanitize text content to strip tool call markers and thinking tags.
* This ensures user-facing text doesn't leak internal tool representations.
*/
function sanitizeTextContent(text) {
	return sanitizeAssistantVisibleTextWithProfile(text, "history");
}
function hasAssistantPhaseMetadata(message) {
	if (!message || typeof message !== "object") return false;
	if (message.role !== "assistant") return false;
	const content = message.content;
	if (!Array.isArray(content)) return false;
	return content.some((block) => block && typeof block === "object" && typeof block.textSignature === "string");
}
function extractAssistantText(message) {
	if (!message || typeof message !== "object") return;
	if (message.role !== "assistant") return;
	const joined = extractAssistantTextForPhase(message, {
		phase: "final_answer",
		sanitizeText: sanitizeTextContent,
		joinWith: ""
	}) ?? extractAssistantTextForPhase(message, {
		sanitizeText: sanitizeTextContent,
		joinWith: ""
	});
	const errorContext = message.stopReason === "error";
	return joined ? sanitizeUserFacingText(joined, { errorContext }) : void 0;
}
//#endregion
export { stripToolMessages as i, hasAssistantPhaseMetadata as n, sanitizeTextContent as r, extractAssistantText as t };
