import { getLogger } from "../../../logger.js";

//#region src/domains/run/agents/SystemPromptBuilder.ts
const logger = getLogger("SystemPromptBuilder");
var SystemPromptBuilder = class {
	templates = /* @__PURE__ */ new Map();
	loaded = false;
	constructor(version, versionConfig) {
		this.version = version;
		this.versionConfig = versionConfig;
	}
	loadTemplates() {
		if (this.loaded) return;
		try {
			const loadedTemplates = this.versionConfig.loadTemplates();
			for (const [name, content] of loadedTemplates) this.templates.set(name, content);
			this.loaded = true;
			logger.debug({
				templateCount: this.templates.size,
				version: this.version
			}, `Loaded ${this.templates.size} templates for version ${this.version}`);
		} catch (error) {
			logger.error({ error }, `Failed to load templates for version ${this.version}`);
			throw new Error(`Template loading failed: ${error}`);
		}
	}
	/**
	* Build the system prompt and return both the prompt string and token breakdown
	*/
	buildSystemPrompt(config) {
		this.loadTemplates();
		this.validateTemplateVariables(config);
		return this.versionConfig.assemble(this.templates, config);
	}
	validateTemplateVariables(config) {
		if (!config) throw new Error("Configuration object is required");
		if (typeof config !== "object") throw new Error("Configuration must be an object");
	}
	getLoadedTemplates() {
		return Array.from(this.templates.keys());
	}
	isLoaded() {
		return this.loaded;
	}
};

//#endregion
export { SystemPromptBuilder };