"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineTool = defineTool;
const toolDefinition_1 = require("./toolDefinition");
const validateToolDefinition = (args) => {
    if (args.availability.length === 0) {
        throw new Error(`Tool "${args.name}" must be available somewhere`);
    }
    if (new Set(args.availability).size !== args.availability.length) {
        throw new Error(`Tool "${args.name}" has duplicate runtimes`);
    }
    if (args.availability.includes('mcp') && !args.mcp?.annotations) {
        throw new Error(`Tool "${args.name}" is MCP-available but has no annotations`);
    }
};
const hasMcpStructuredContentSchema = (mcpConfig) => mcpConfig?.structuredContentSchema !== undefined;
function defineTool(def) {
    validateToolDefinition(def);
    const inputSchemaTransformed = def.inputSchemaTransformed ?? def.inputSchema;
    const mcpConfig = def.mcp;
    if (hasMcpStructuredContentSchema(mcpConfig)) {
        return new toolDefinition_1.ToolDefinitionWithMcpOutputImpl({
            name: def.name,
            title: def.title,
            description: def.description,
            availability: def.availability,
            inputSchema: def.inputSchema,
            inputSchemaTransformed,
            agentConfig: def.agent ?? null,
            mcpConfig,
        });
    }
    return new toolDefinition_1.ToolDefinitionWithoutMcpOutputImpl({
        name: def.name,
        title: def.title,
        description: def.description,
        availability: def.availability,
        inputSchema: def.inputSchema,
        inputSchemaTransformed,
        agentConfig: def.agent ?? null,
        mcpConfig: mcpConfig ?? null,
    });
}
//# sourceMappingURL=defineTool.js.map