import { isAgentQuery } from "../util/agent-utils.js";
function queryPredicate(agentName) {
    return (query) => isAgentQuery(query.json, agentName);
}
class AgentImpl {
    #schema;
    #agentName;
    #agent;
    constructor(parent, name, agent) {
        this.#schema = parent;
        this.#agentName = name;
        this.#agent = agent;
    }
    get name() {
        return this.#agentName;
    }
    get title() {
        return this.#agent.title;
    }
    get description() {
        return this.#agent.description;
    }
    get disabled() {
        return this.#agent.disabled;
    }
    get systemPrompt() {
        return this.#agent.systemPrompt;
    }
    get sessionMemoryShape() {
        const ref = this.#agent.memory?.sessionMemory.shape;
        if (ref) {
            return this.#schema.getShape(ref);
        }
        return undefined;
    }
    get historyStrategies() {
        return this.#agent.historyStrategies;
    }
    get isProtectionEnabled() {
        return this.#agent.protection?.enabled ?? false;
    }
    get apiInputs() {
        return this.#agent.api.inputs;
    }
    get startState() {
        return this.#agent.start;
    }
    getState(stateId) {
        return this.#agent.states[stateId];
    }
    ensureState(stateId) {
        const state = this.getState(stateId);
        if (!state) {
            throw new Error(`State "${stateId}" not found in agent "${this.#agentName}"`);
        }
        return state;
    }
    getMutations() {
        return this.#schema.getLocalMutations().filter(queryPredicate(this.name));
    }
    getQueries() {
        return this.#schema.getLocalQueries().filter(queryPredicate(this.name));
    }
    getInputConfig(inputName) {
        return this.#agent.api.inputs.find((input) => input.name === inputName);
    }
    get json() {
        return this.#agent;
    }
}
export function createAgent(parent, name, agent) {
    return new AgentImpl(parent, name, agent);
}
