import { ToolDefinitionWithMcpOutputImpl, ToolDefinitionWithoutMcpOutputImpl, } from './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;
export function defineTool(def) {
    validateToolDefinition(def);
    const inputSchemaTransformed = def.inputSchemaTransformed ?? def.inputSchema;
    const mcpConfig = def.mcp;
    if (hasMcpStructuredContentSchema(mcpConfig)) {
        return new ToolDefinitionWithMcpOutputImpl({
            name: def.name,
            title: def.title,
            description: def.description,
            availability: def.availability,
            inputSchema: def.inputSchema,
            inputSchemaTransformed,
            agentConfig: def.agent ?? null,
            mcpConfig,
        });
    }
    return new 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