"use client";
import Dagre from '@dagrejs/dagre';

// src/astrlabe/utils/logic-node-defaults.ts
function createDefaultLogicNodeConfig(nodeType) {
  switch (nodeType) {
    case "start":
      return { type: "start", inputVariables: [] };
    case "end":
      return { type: "end", outputVariables: [] };
    case "if_else":
      return {
        type: "if_else",
        conditions: [{ variable: "", operator: "equals", value: "" }],
        logicalOperator: "and"
      };
    case "code":
      return { type: "code", language: "javascript", code: "" };
    case "http_request":
      return {
        type: "http_request",
        method: "GET",
        url: "",
        headers: {},
        body: "",
        timeoutMs: 1e4
      };
    case "s3_write":
      return {
        type: "s3_write",
        bucket: "",
        key: "",
        sourceUrl: "",
        body: "",
        contentType: "",
        timeoutMs: 3e5,
        connectionId: ""
      };
    case "template_transform":
      return { type: "template_transform", template: "", outputVariable: "" };
    case "iteration":
      return { type: "iteration", iteratorVariable: "", maxIterations: 100 };
    case "knowledge_base":
      return { type: "knowledge_base", sourceId: "", topK: 5, similarityThreshold: 0.7 };
    case "answer":
      return { type: "answer", outputTemplate: "", outputVariables: [] };
    case "question_classifier":
      return {
        type: "question_classifier",
        modelId: "",
        instructions: "",
        categories: [
          { id: crypto.randomUUID(), name: "", description: "" },
          { id: crypto.randomUUID(), name: "", description: "" }
        ]
      };
    case "parameter_extractor":
      return {
        type: "parameter_extractor",
        modelId: "",
        parameters: [{ name: "", type: "string", description: "", required: true }]
      };
    case "variable_assigner":
      return {
        type: "variable_assigner",
        assignments: [{ target: "", source: "" }]
      };
    case "variable_aggregator":
      return {
        type: "variable_aggregator",
        inputVariables: [],
        outputVariable: "",
        aggregationMode: "array"
      };
    case "document_extractor":
      return {
        type: "document_extractor",
        extractionMode: "text",
        outputVariable: ""
      };
    case "list_operator":
      return {
        type: "list_operator",
        operation: "filter",
        inputVariable: "",
        outputVariable: "",
        condition: ""
      };
    case "iteration_start":
      return {
        type: "iteration_start",
        iteratorVariable: "",
        itemVariable: "item",
        indexVariable: "index"
      };
    case "note":
      return {
        type: "note",
        text: "",
        color: "yellow",
        width: 200,
        height: 150
      };
    case "group":
      return {
        type: "group",
        label: "Group",
        color: "slate",
        isExpanded: true,
        width: 400,
        height: 300,
        collapsedWidth: 260,
        collapsedHeight: 60
      };
    case "datasource":
      return {
        type: "datasource",
        datasourceId: "",
        dialect: "",
        table: "",
        selectedColumns: [],
        filterVariables: {},
        outputVariable: "datasourceResult",
        limit: 100
      };
    case "dashboard_output":
      return {
        type: "dashboard_output",
        dashboardFrom: ""
      };
    case "audio_input":
      return {
        type: "audio_input",
        url: ""
      };
    case "speech_transcriber":
      return {
        type: "speech_transcriber",
        audioUrl: "",
        model: "whisper-1",
        responseFormat: "verbose_json",
        timeoutMs: 12e4
      };
    default:
      return null;
  }
}
var DEFAULT_NODE_WIDTH = 260;
var DEFAULT_NODE_HEIGHT = 70;
function getNodeSize(node) {
  const measured = node.measured;
  return {
    width: measured?.width ?? DEFAULT_NODE_WIDTH,
    height: measured?.height ?? DEFAULT_NODE_HEIGHT
  };
}
function applyDagreLayout(nodes, edges, direction) {
  const nodeSpacingHorizontal = 80;
  const nodeSpacingVertical = 50;
  const layoutNodes = nodes.filter(
    (node) => !node.parentId && node.type !== "note"
  );
  const dagreGraph = new Dagre.graphlib.Graph({ directed: true });
  dagreGraph.setDefaultEdgeLabel(() => ({}));
  const isHorizontal = direction === "LR";
  dagreGraph.setGraph({
    rankdir: direction,
    nodesep: isHorizontal ? nodeSpacingVertical : nodeSpacingHorizontal,
    ranksep: isHorizontal ? nodeSpacingHorizontal : nodeSpacingVertical,
    marginx: 40,
    marginy: 40
  });
  const layoutNodeIds = new Set(layoutNodes.map((node) => node.id));
  for (const node of layoutNodes) {
    const { width, height } = getNodeSize(node);
    dagreGraph.setNode(node.id, { width, height });
  }
  for (const edge of edges) {
    if (layoutNodeIds.has(edge.source) && layoutNodeIds.has(edge.target)) {
      dagreGraph.setEdge(edge.source, edge.target);
    }
  }
  Dagre.layout(dagreGraph);
  const positionMap = /* @__PURE__ */ new Map();
  for (const node of layoutNodes) {
    const dagreNode = dagreGraph.node(node.id);
    if (!dagreNode) continue;
    const { width, height } = getNodeSize(node);
    positionMap.set(node.id, {
      x: dagreNode.x - width / 2,
      y: dagreNode.y - height / 2
    });
  }
  return nodes.map((node) => {
    const newPosition = positionMap.get(node.id);
    if (!newPosition) return node;
    return { ...node, position: newPosition };
  });
}

// src/astrlabe/utils/agent-tier.ts
var TIERS = [
  { maxElo: 1200, tier: { key: "beginner", pillColor: "bg-cyan-100 text-cyan-700 dark:bg-cyan-900/30 dark:text-cyan-400" } },
  { maxElo: 1600, tier: { key: "intermediate", pillColor: "bg-pink-100 text-pink-700 dark:bg-pink-900/30 dark:text-pink-400" } },
  { maxElo: 2e3, tier: { key: "advanced", pillColor: "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400" } },
  { maxElo: Infinity, tier: { key: "expert", pillColor: "bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400" } }
];
function getAgentTier(elo) {
  const eloValue = elo ?? 0;
  for (const { maxElo, tier } of TIERS) {
    if (eloValue < maxElo) return tier;
  }
  return TIERS[TIERS.length - 1].tier;
}

export { applyDagreLayout, createDefaultLogicNodeConfig, getAgentTier };
//# sourceMappingURL=chunk-G7JQ4OCE.mjs.map
//# sourceMappingURL=chunk-G7JQ4OCE.mjs.map