import {
  GITHUB_READ_FILE_DESCRIPTION,
  GITHUB_SEARCH_DESCRIPTION,
  WARP_GREP_DESCRIPTION
} from "./chunk-Q6QCHAMD.js";
import {
  WarpGrepClient,
  executeGitHubReadFile,
  executeToolCall,
  executeToolCallStreaming
} from "./chunk-75F5XTPD.js";

// tools/warp_grep/vercel.ts
import { tool } from "ai";
import { z } from "zod";
var warpGrepJsonSchema = {
  type: "object",
  properties: {
    search_term: {
      type: "string",
      description: "Search problem statement that this subagent is supposed to research for"
    }
  },
  required: ["search_term"],
  additionalProperties: false
};
async function execute(input, config) {
  return executeToolCall(input, config);
}
function createWarpGrepTool(config) {
  const schema = config.inputSchema ?? z.object({
    search_term: z.string().describe("Search problem statement that this subagent is supposed to research for")
  });
  return tool({
    description: config.description ?? WARP_GREP_DESCRIPTION,
    inputSchema: schema,
    execute: async (params) => {
      const steps = [];
      const generator = executeToolCallStreaming(params, config);
      let result;
      for (; ; ) {
        const { value, done } = await generator.next();
        if (done) {
          result = value;
          break;
        }
        steps.push(value);
      }
      if (!result.success) {
        throw new Error(`Failed to search codebase: ${result.error}`);
      }
      const allToolCalls = steps.flatMap((s) => s.toolCalls);
      return {
        success: true,
        contexts: result.contexts,
        summary: result.summary,
        progress: allToolCalls.length > 0 ? { turn: steps.length, toolCalls: allToolCalls } : void 0
      };
    }
  });
}
function createGitHubSearchTool(config) {
  const client = new WarpGrepClient(config);
  return tool({
    description: GITHUB_SEARCH_DESCRIPTION,
    inputSchema: z.object({
      search_term: z.string().describe("Search problem statement that this subagent is supposed to research for"),
      github_url: z.string().optional().describe('GitHub repository URL to search (e.g. "https://github.com/vercel/next.js"). You must provide either github_url or owner_repo.'),
      owner_repo: z.string().optional().describe('Repository owner/repo shorthand (e.g. "vercel/next.js"). You must provide either github_url or owner_repo.'),
      branch: z.string().optional().describe("Branch to search (defaults to repo default branch)")
    }),
    execute: async (params) => {
      const github = params.github_url || params.owner_repo;
      if (!github) {
        throw new Error("Please provide github search url or owner/repo id");
      }
      const result = await client.searchGitHub({ searchTerm: params.search_term, github, branch: params.branch });
      if (!result.success) {
        throw new Error(`GitHub search failed: ${result.error}`);
      }
      return {
        success: true,
        contexts: result.contexts,
        summary: result.summary
      };
    }
  });
}
function createGitHubReadFileTool(config) {
  return tool({
    description: GITHUB_READ_FILE_DESCRIPTION,
    inputSchema: z.object({
      github: z.string().describe('owner/repo shorthand (e.g., "vercel/next.js")'),
      path: z.string().describe("File path within the repository"),
      startLine: z.number().optional().describe("Start line number (1-based)"),
      endLine: z.number().optional().describe("End line number (1-based, inclusive)"),
      branch: z.string().optional().describe("Branch to read from (defaults to repo default branch)")
    }),
    execute: async (params) => {
      const result = await executeGitHubReadFile(params, config);
      if (!result.success) {
        throw new Error(`GitHub read file failed: ${result.error}`);
      }
      return result;
    }
  });
}
var vercel_default = createWarpGrepTool;

export {
  warpGrepJsonSchema,
  execute,
  createWarpGrepTool,
  createGitHubSearchTool,
  createGitHubReadFileTool,
  vercel_default
};
//# sourceMappingURL=chunk-22QLJ2YB.js.map