/**
 * brain_query — wrapper of BrainPort.queryKnowledge with hash propagation.
 *
 * @public
 */
import { z } from "zod";
import { SkillExecutionError } from "./errors.js";
import { withSkillSpan } from "./_otel.js";
const inputSchema = z
    .object({
    query: z.string().min(1).max(512),
    category: z.string().optional(),
    tags: z.array(z.string()).max(16).optional(),
    limit: z.number().int().min(1).max(100).default(10),
    mcp_call_hash: z.string().optional(),
})
    .strict();
export const brainQuery = {
    name: "brain_query",
    inputSchema,
    async execute(input, ctx) {
        if (ctx.isReplay) {
            const mock = ctx.dryRunMocks["brain_query"];
            if (mock)
                return mock(input);
            return { entries: [] };
        }
        return withSkillSpan("brain_query", async () => {
            const brain = ctx.brain;
            if (!brain || !brain.queryKnowledge) {
                throw new SkillExecutionError("brain_query", "no BrainPort.queryKnowledge attached to context");
            }
            const filters = {
                category: input.category,
                tags: input.tags,
                limit: input.limit,
            };
            if (input.mcp_call_hash) {
                filters.mcp_call_hash = input.mcp_call_hash;
            }
            const entries = await brain.queryKnowledge(input.query, filters);
            return { entries };
        });
    },
};
//# sourceMappingURL=brain-query.js.map