import { b as getEnvString } from "./logger-BudIH0qK.js";
import { o as sha256 } from "./extractor-DJ7JYpPo.js";

//#region src/prompts/constants.ts
const PROMPT_DELIMITER = getEnvString("PROMPTFOO_PROMPT_SEPARATOR") || "---";
const VALID_FILE_EXTENSIONS = [
	".cjs",
	".cts",
	".j2",
	".js",
	".json",
	".jsonl",
	".md",
	".mjs",
	".mts",
	".py",
	".ts",
	".txt",
	".yml",
	".yaml"
];

//#endregion
//#region src/prompts/utils.ts
/**
* Determines if a string is a valid file path.
* @param str - The string to check.
* @returns True if the string is a valid file path, false otherwise.
*/
function maybeFilePath(str) {
	if (typeof str !== "string") throw new Error(`Invalid input: ${JSON.stringify(str)}`);
	if ([
		"\n",
		"portkey://",
		"langfuse://",
		"helicone://"
	].some((substring) => str.includes(substring))) return false;
	return str.startsWith("file://") || VALID_FILE_EXTENSIONS.some((ext) => {
		const tokens = str.split(":");
		return tokens.pop()?.endsWith(ext) || tokens.pop()?.endsWith(ext);
	}) || str.charAt(str.length - 3) === "." || str.charAt(str.length - 4) === "." || str.includes("*") || str.includes("/") || str.includes("\\");
}
/**
* Normalizes the input prompt to an array of prompts, rejecting invalid and empty inputs.
* @param promptPathOrGlobs - The input prompt.
* @returns The normalized prompts.
* @throws If the input is invalid or empty.
*/
function normalizeInput(promptPathOrGlobs) {
	if (!promptPathOrGlobs || (typeof promptPathOrGlobs === "string" || Array.isArray(promptPathOrGlobs)) && promptPathOrGlobs.length === 0) throw new Error(`Invalid input prompt: ${JSON.stringify(promptPathOrGlobs)}`);
	if (typeof promptPathOrGlobs === "string") return [{ raw: promptPathOrGlobs }];
	if (Array.isArray(promptPathOrGlobs)) return promptPathOrGlobs.map((promptPathOrGlob, _index) => {
		if (typeof promptPathOrGlob === "string") return { raw: promptPathOrGlob };
		return {
			raw: promptPathOrGlob.raw || promptPathOrGlob.id,
			...promptPathOrGlob
		};
	});
	if (typeof promptPathOrGlobs === "object" && Object.keys(promptPathOrGlobs).length) return Object.entries(promptPathOrGlobs).map(([raw, key]) => ({
		label: key,
		raw
	}));
	throw new Error(`Invalid input prompt: ${JSON.stringify(promptPathOrGlobs)}`);
}
function hashPrompt(prompt) {
	return prompt.id || prompt.label ? sha256(prompt.label) : sha256(typeof prompt.raw === "object" ? JSON.stringify(prompt.raw) : prompt.raw);
}

//#endregion
export { PROMPT_DELIMITER as i, maybeFilePath as n, normalizeInput as r, hashPrompt as t };
//# sourceMappingURL=utils-DYARxGNi.js.map