// tools/warp_grep/providers/code_storage_http.ts
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")
  };
}

export {
  createCodeStorageHttpCommands
};
//# sourceMappingURL=chunk-GVGJIXV2.js.map