"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolDefinitionWithMcpOutputImpl = void 0;
const tslib_1 = require("tslib");
const snakeCase_1 = tslib_1.__importDefault(require("lodash/snakeCase"));
const agentInputSchema_1 = require("./agentInputSchema");
const McpSchemaCompatLayer_1 = require("./McpSchemaCompatLayer");
const toolDefinitionUtils_1 = require("./toolDefinitionUtils");
class ToolDefinitionWithMcpOutputImpl {
    constructor(args) {
        this.name = args.name;
        this.title = args.title;
        this.descriptionConfig = args.description;
        this.availability = args.availability;
        this.inputSchema = args.inputSchema;
        this.inputSchemaTransformed = args.inputSchemaTransformed;
        this.agentConfig = args.agentConfig;
        this.mcpConfig = args.mcpConfig;
    }
    get description() {
        return (0, toolDefinitionUtils_1.resolveDescription)(this.descriptionConfig, {
            runtime: 'agent',
            toolName: this.name,
        });
    }
    buildAgentView() {
        const base = {
            name: this.name,
            title: this.title,
            description: this.description,
            inputSchema: (0, agentInputSchema_1.createAgentInputSchema)(this.inputSchema),
            toModelOutput: this.agentConfig?.toModelOutput ?? toolDefinitionUtils_1.defaultAgentToModelOutput,
        };
        if (this.agentConfig?.outputSchema) {
            return {
                ...base,
                outputSchema: this.agentConfig.outputSchema,
            };
        }
        return base;
    }
    get outputSchema() {
        return this.mcpConfig.structuredContentSchema;
    }
    for(runtime) {
        (0, toolDefinitionUtils_1.assertAvailable)(this.name, this.availability, runtime);
        if (runtime === 'agent') {
            return this.buildAgentView();
        }
        const mcpName = this.mcpConfig.name ?? (0, snakeCase_1.default)(this.name);
        return {
            name: mcpName,
            canonicalName: this.name,
            title: this.title,
            description: (0, toolDefinitionUtils_1.resolveDescription)(this.descriptionConfig, {
                runtime: 'mcp',
                toolName: mcpName,
            }),
            inputSchema: (0, McpSchemaCompatLayer_1.createMcpCompatibleInputSchema)(this.inputSchema),
            annotations: this.mcpConfig.annotations,
            outputSchema: this.outputSchema,
            meta: this.mcpConfig.meta,
            result: (0, toolDefinitionUtils_1.createMcpToolResultBuilders)(),
        };
    }
}
exports.ToolDefinitionWithMcpOutputImpl = ToolDefinitionWithMcpOutputImpl;
//# sourceMappingURL=toolDefinitionWithMcpOutput.js.map