const require_logger = require('./logger-CMp-NS-e.cjs');
const require_extractor = require('./extractor-6TFoLBb3.cjs');

//#region src/prompts/constants.ts
const PROMPT_DELIMITER = require_logger.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/models/prompt.ts
/**
* Generates a unique identifier for a prompt based on its properties.
*
* Priority order:
* 1. If label is truthy, hash the label
* 2. If id is truthy, hash the id
* 3. Otherwise, hash the raw content (stringified if object)
*
* @param prompt - The prompt object to generate an ID for
* @returns A SHA-256 hash string
*/
function generateIdFromPrompt(prompt) {
	if (prompt.label) return require_extractor.sha256(prompt.label);
	if (prompt.id) return require_extractor.sha256(prompt.id);
	return require_extractor.sha256(typeof prompt.raw === "object" ? JSON.stringify(prompt.raw) : prompt.raw);
}

//#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)}`);
}
/**
* Generates a hash identifier for a prompt.
* This is an alias for generateIdFromPrompt for backward compatibility.
*
* @param prompt - The prompt to hash
* @returns A SHA-256 hash string
*/
function hashPrompt(prompt) {
	return generateIdFromPrompt(prompt);
}

//#endregion
Object.defineProperty(exports, 'PROMPT_DELIMITER', {
  enumerable: true,
  get: function () {
    return PROMPT_DELIMITER;
  }
});
Object.defineProperty(exports, 'generateIdFromPrompt', {
  enumerable: true,
  get: function () {
    return generateIdFromPrompt;
  }
});
Object.defineProperty(exports, 'hashPrompt', {
  enumerable: true,
  get: function () {
    return hashPrompt;
  }
});
Object.defineProperty(exports, 'maybeFilePath', {
  enumerable: true,
  get: function () {
    return maybeFilePath;
  }
});
Object.defineProperty(exports, 'normalizeInput', {
  enumerable: true,
  get: function () {
    return normalizeInput;
  }
});
//# sourceMappingURL=utils-u1jU5_Iq.cjs.map