'use strict';

var chunkYUWWXTL2_cjs = require('./chunk-YUWWXTL2.cjs');
var chunkY2BKW5ND_cjs = require('./chunk-Y2BKW5ND.cjs');
var chunk6P7P7Y5U_cjs = require('./chunk-6P7P7Y5U.cjs');
var chunk64ITUOXI_cjs = require('./chunk-64ITUOXI.cjs');

// src/server/handlers/tool-providers.ts
var LIST_TOOL_PROVIDERS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/tool-providers",
  responseType: "json",
  responseSchema: chunkYUWWXTL2_cjs.listToolProvidersResponseSchema,
  summary: "List tool providers",
  description: "Returns a list of all registered tool providers with their info",
  tags: ["Tool Providers"],
  requiresAuth: true,
  handler: async ({ mastra }) => {
    try {
      const editor = mastra.getEditor();
      if (!editor) {
        throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Editor is not configured" });
      }
      const providers = editor.getToolProviders();
      return { providers: Object.values(providers).map((provider) => provider.info) };
    } catch (error) {
      return chunkY2BKW5ND_cjs.handleError(error, "Error listing tool providers");
    }
  }
});
var LIST_TOOL_PROVIDER_TOOLKITS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/tool-providers/:providerId/toolkits",
  responseType: "json",
  pathParamSchema: chunkYUWWXTL2_cjs.toolProviderIdPathParams,
  responseSchema: chunkYUWWXTL2_cjs.listToolProviderToolkitsResponseSchema,
  summary: "List tool provider toolkits",
  description: "Returns the toolkits available from a specific tool provider",
  tags: ["Tool Providers"],
  requiresAuth: true,
  handler: async ({ mastra, providerId }) => {
    try {
      const editor = mastra.getEditor();
      if (!editor) {
        throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Editor is not configured" });
      }
      const provider = editor.getToolProvider(providerId);
      if (!provider) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Tool provider with id ${providerId} not found` });
      }
      if (!provider.listToolkits) {
        return { data: [] };
      }
      return await provider.listToolkits();
    } catch (error) {
      return chunkY2BKW5ND_cjs.handleError(error, "Error listing tool provider toolkits");
    }
  }
});
var LIST_TOOL_PROVIDER_TOOLS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/tool-providers/:providerId/tools",
  responseType: "json",
  pathParamSchema: chunkYUWWXTL2_cjs.toolProviderIdPathParams,
  queryParamSchema: chunkYUWWXTL2_cjs.listToolProviderToolsQuerySchema,
  responseSchema: chunkYUWWXTL2_cjs.listToolProviderToolsResponseSchema,
  summary: "List tool provider tools",
  description: "Returns the tools available from a specific tool provider, with optional filtering",
  tags: ["Tool Providers"],
  requiresAuth: true,
  handler: async ({ mastra, providerId, toolkit, search, page, perPage }) => {
    try {
      const editor = mastra.getEditor();
      if (!editor) {
        throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Editor is not configured" });
      }
      const provider = editor.getToolProvider(providerId);
      if (!provider) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Tool provider with id ${providerId} not found` });
      }
      const options = {};
      if (toolkit !== void 0) options.toolkit = toolkit;
      if (search !== void 0) options.search = search;
      if (page !== void 0) options.page = page;
      if (perPage !== void 0) options.perPage = perPage;
      return await provider.listTools(Object.keys(options).length > 0 ? options : void 0);
    } catch (error) {
      return chunkY2BKW5ND_cjs.handleError(error, "Error listing tool provider tools");
    }
  }
});
var GET_TOOL_PROVIDER_TOOL_SCHEMA_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/tool-providers/:providerId/tools/:toolSlug/schema",
  responseType: "json",
  pathParamSchema: chunkYUWWXTL2_cjs.toolSlugPathParams,
  responseSchema: chunkYUWWXTL2_cjs.getToolProviderToolSchemaResponseSchema,
  summary: "Get tool provider tool schema",
  description: "Returns the schema for a specific tool from a tool provider",
  tags: ["Tool Providers"],
  requiresAuth: true,
  handler: async ({ mastra, providerId, toolSlug }) => {
    try {
      const editor = mastra.getEditor();
      if (!editor) {
        throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Editor is not configured" });
      }
      const provider = editor.getToolProvider(providerId);
      if (!provider) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Tool provider with id ${providerId} not found` });
      }
      if (!provider.getToolSchema) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Tool provider ${providerId} does not support getToolSchema` });
      }
      const schema = await provider.getToolSchema(toolSlug);
      if (!schema) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Schema for tool ${toolSlug} not found in provider ${providerId}` });
      }
      return schema;
    } catch (error) {
      return chunkY2BKW5ND_cjs.handleError(error, "Error getting tool provider tool schema");
    }
  }
});

exports.GET_TOOL_PROVIDER_TOOL_SCHEMA_ROUTE = GET_TOOL_PROVIDER_TOOL_SCHEMA_ROUTE;
exports.LIST_TOOL_PROVIDERS_ROUTE = LIST_TOOL_PROVIDERS_ROUTE;
exports.LIST_TOOL_PROVIDER_TOOLKITS_ROUTE = LIST_TOOL_PROVIDER_TOOLKITS_ROUTE;
exports.LIST_TOOL_PROVIDER_TOOLS_ROUTE = LIST_TOOL_PROVIDER_TOOLS_ROUTE;
//# sourceMappingURL=chunk-6T2DK2GP.cjs.map
//# sourceMappingURL=chunk-6T2DK2GP.cjs.map