/** Valid personality name pattern: lowercase alphanumeric + hyphens */
const NAME_PATTERN = /^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/;
export class PersonalityManager {
    store;
    constructor(store) {
        this.store = store;
    }
    createPersonality(opts) {
        const { name, label, description, promptFragment } = opts;
        if (!name || typeof name !== "string") {
            throw new Error("Missing personality name");
        }
        if (!NAME_PATTERN.test(name)) {
            throw new Error("Personality name must be lowercase alphanumeric + hyphens (e.g. 'my-personality')");
        }
        if (this.store.getLocal(name)) {
            throw new Error(`Personality "${name}" already exists`);
        }
        if (!label || typeof label !== "string") {
            throw new Error("Missing personality label");
        }
        const now = Date.now();
        const personality = {
            name,
            label,
            description: description || "",
            promptFragment: promptFragment || "",
            createdAt: now,
            updatedAt: now,
        };
        this.store.put(personality);
        return personality;
    }
    getPersonality(name) {
        return this.store.get(name);
    }
    listPersonalities() {
        return this.store.getAll();
    }
    updatePersonality(name, updates) {
        return this.store.update(name, updates);
    }
    deletePersonality(name) {
        const personality = this.store.get(name);
        if (!personality)
            return false;
        this.store.remove(name);
        return true;
    }
    /**
     * Resolve personality names to their definitions.
     * Returns only personalities that exist, silently skipping unknown names.
     */
    resolvePersonalities(names) {
        const result = [];
        for (const name of names) {
            const personality = this.store.get(name);
            if (personality) {
                result.push({ label: personality.label, promptFragment: personality.promptFragment });
            }
        }
        return result;
    }
}
//# sourceMappingURL=personality-manager.js.map