var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { tool } from "langchain";
import { z } from "zod";
import { serializeApiBasedTool, } from "../../apiBasedTools.js";
const fetchToolSchemaSchema = z.object({
    toolName: z
        .string()
        .describe("Name of the API-based tool to load, for example get_resource."),
});
export function createFetchToolSchemaTool(apiBasedTools) {
    return __awaiter(this, void 0, void 0, function* () {
        return tool((_a) => __awaiter(this, [_a], void 0, function* ({ toolName }) {
            const toolDefinition = apiBasedTools[toolName];
            if (!toolDefinition) {
                return JSON.stringify({
                    status: 404,
                    error: "TOOL_NOT_FOUND",
                    message: `Tool "${toolName}" not found.`,
                }, null, 2);
            }
            return JSON.stringify(Object.assign({ status: 200, name: toolName }, serializeApiBasedTool(toolDefinition)), null, 2);
        }), {
            name: "fetch_tool_schema",
            description: "Fetch the schema for an API-based AdminForth tool by name and load it for later use. Use this right after fetch_skill when the skill mentions non-base tools.",
            schema: fetchToolSchemaSchema,
        });
    });
}
