import {
  makeRequest
} from "./chunk-CAY57CKF.js";

// src/langwatch-api-agents.ts
async function listAgents(params) {
  const query = new URLSearchParams();
  if (params?.page) query.set("page", String(params.page));
  if (params?.limit) query.set("limit", String(params.limit));
  const qs = query.toString() ? `?${query}` : "";
  return makeRequest("GET", `/api/agents${qs}`);
}
async function getAgent(id) {
  return makeRequest(
    "GET",
    `/api/agents/${encodeURIComponent(id)}`
  );
}
async function createAgent(data) {
  return makeRequest("POST", "/api/agents", data);
}
async function updateAgent(params) {
  const { id, ...data } = params;
  return makeRequest(
    "PATCH",
    `/api/agents/${encodeURIComponent(id)}`,
    data
  );
}
async function runAgent(id, input) {
  const agent = await getAgent(id);
  const config = agent.config ?? {};
  if (agent.type === "http") {
    const url = config.url;
    if (!url) {
      throw new Error("HTTP agent has no URL configured");
    }
    const response = await fetch(url, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(input ?? {})
    });
    const result2 = await response.json();
    return { agentType: "http", result: result2 };
  }
  const workflowId = config.workflowId;
  if (!workflowId) {
    throw new Error(
      `Agent "${agent.name}" (type: ${agent.type}) cannot be executed directly. Only HTTP agents and workflow-linked agents can be run.`
    );
  }
  const { runWorkflow } = await import("./langwatch-api-workflows-CXCTTCXT.js");
  const result = await runWorkflow(workflowId, input);
  return { agentType: agent.type, result };
}
async function deleteAgent(id) {
  return makeRequest(
    "DELETE",
    `/api/agents/${encodeURIComponent(id)}`
  );
}

export {
  listAgents,
  getAgent,
  createAgent,
  updateAgent,
  runAgent,
  deleteAgent
};
//# sourceMappingURL=chunk-IUP5IHBD.js.map