import { listToolProvidersResponseSchema, listToolProviderToolkitsResponseSchema, toolProviderIdPathParams, listToolProviderToolsResponseSchema, listToolProviderToolsQuerySchema, getToolProviderToolSchemaResponseSchema, toolSlugPathParams } from './chunk-QB3ZGAO4.js';
import { handleError } from './chunk-NA7LKQPZ.js';
import { createRoute } from './chunk-OLKVMPNB.js';
import { HTTPException } from './chunk-6QWQZI4Q.js';

// src/server/handlers/tool-providers.ts
var LIST_TOOL_PROVIDERS_ROUTE = createRoute({
  method: "GET",
  path: "/tool-providers",
  responseType: "json",
  responseSchema: 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 HTTPException(500, { message: "Editor is not configured" });
      }
      const providers = editor.getToolProviders();
      return { providers: Object.values(providers).map((provider) => provider.info) };
    } catch (error) {
      return handleError(error, "Error listing tool providers");
    }
  }
});
var LIST_TOOL_PROVIDER_TOOLKITS_ROUTE = createRoute({
  method: "GET",
  path: "/tool-providers/:providerId/toolkits",
  responseType: "json",
  pathParamSchema: toolProviderIdPathParams,
  responseSchema: 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 HTTPException(500, { message: "Editor is not configured" });
      }
      const provider = editor.getToolProvider(providerId);
      if (!provider) {
        throw new HTTPException(404, { message: `Tool provider with id ${providerId} not found` });
      }
      if (!provider.listToolkits) {
        return { data: [] };
      }
      return await provider.listToolkits();
    } catch (error) {
      return handleError(error, "Error listing tool provider toolkits");
    }
  }
});
var LIST_TOOL_PROVIDER_TOOLS_ROUTE = createRoute({
  method: "GET",
  path: "/tool-providers/:providerId/tools",
  responseType: "json",
  pathParamSchema: toolProviderIdPathParams,
  queryParamSchema: listToolProviderToolsQuerySchema,
  responseSchema: 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 HTTPException(500, { message: "Editor is not configured" });
      }
      const provider = editor.getToolProvider(providerId);
      if (!provider) {
        throw new 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 handleError(error, "Error listing tool provider tools");
    }
  }
});
var GET_TOOL_PROVIDER_TOOL_SCHEMA_ROUTE = createRoute({
  method: "GET",
  path: "/tool-providers/:providerId/tools/:toolSlug/schema",
  responseType: "json",
  pathParamSchema: toolSlugPathParams,
  responseSchema: 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 HTTPException(500, { message: "Editor is not configured" });
      }
      const provider = editor.getToolProvider(providerId);
      if (!provider) {
        throw new HTTPException(404, { message: `Tool provider with id ${providerId} not found` });
      }
      if (!provider.getToolSchema) {
        throw new HTTPException(404, { message: `Tool provider ${providerId} does not support getToolSchema` });
      }
      const schema = await provider.getToolSchema(toolSlug);
      if (!schema) {
        throw new HTTPException(404, { message: `Schema for tool ${toolSlug} not found in provider ${providerId}` });
      }
      return schema;
    } catch (error) {
      return handleError(error, "Error getting tool provider tool schema");
    }
  }
});

export { GET_TOOL_PROVIDER_TOOL_SCHEMA_ROUTE, LIST_TOOL_PROVIDERS_ROUTE, LIST_TOOL_PROVIDER_TOOLKITS_ROUTE, LIST_TOOL_PROVIDER_TOOLS_ROUTE };
//# sourceMappingURL=chunk-YVN3HW3L.js.map
//# sourceMappingURL=chunk-YVN3HW3L.js.map