import {
  GITHUB_SEARCH_DESCRIPTION,
  WARP_GREP_DESCRIPTION
} from "./chunk-KJZMKDDP.js";
import {
  WarpGrepClient,
  executeToolCall,
  executeToolCallStreaming
} from "./chunk-TXT3W4QK.js";

// tools/warp_grep/vercel.ts
import { tool } from "ai";
import { z } from "zod";
var warpGrepJsonSchema = {
  type: "object",
  properties: {
    query: {
      type: "string",
      description: "Free-form repository question"
    }
  },
  required: ["query"],
  additionalProperties: false
};
async function execute(input, config) {
  return executeToolCall(input, config);
}
function createWarpGrepTool(config) {
  const schema = config.inputSchema ?? z.object({
    query: z.string().describe("Free-form repository question")
  });
  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({
      query: z.string().describe("Natural language search query"),
      github: z.string().describe('GitHub URL or "owner/repo" shorthand'),
      branch: z.string().optional().describe("Branch to search (defaults to repo default branch)")
    }),
    execute: async (params) => {
      const result = await client.searchGitHub(params);
      if (!result.success) {
        throw new Error(`GitHub search failed: ${result.error}`);
      }
      return {
        success: true,
        contexts: result.contexts,
        summary: result.summary
      };
    }
  });
}
var vercel_default = createWarpGrepTool;

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