"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// tools/warp_grep/providers/code_storage_http.ts
var code_storage_http_exports = {};
__export(code_storage_http_exports, {
  createCodeStorageHttpCommands: () => createCodeStorageHttpCommands
});
module.exports = __toCommonJS(code_storage_http_exports);
async function post(url, body, op) {
  const res = await fetch(url, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(body)
  });
  if (!res.ok) {
    const text = await res.text().catch(() => res.statusText);
    try {
      const parsed = JSON.parse(text);
      if (parsed.error) return `Error: ${parsed.error}`;
    } catch {
    }
    return `Error: ${op} failed (${res.status}): ${text}`;
  }
  const data = await res.json();
  if (data.error) throw new Error(data.error);
  return data.stdout;
}
function createCodeStorageHttpCommands(config) {
  const { baseUrl, repoId, branch } = config;
  const encodedRepoId = encodeURIComponent(repoId);
  return {
    grep: (pattern, path, glob) => post(`${baseUrl}/api/code-search/${encodedRepoId}/grep`, { pattern, path, glob, branch }, "grep"),
    read: (path, start, end) => post(`${baseUrl}/api/code-search/${encodedRepoId}/read`, { path, start, end, branch }, "read"),
    listDir: (path, maxDepth) => post(`${baseUrl}/api/code-search/${encodedRepoId}/list`, { path, maxDepth, branch }, "list")
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createCodeStorageHttpCommands
});
//# sourceMappingURL=code_storage_http.cjs.map