import { r as reactExports, j as jsxRuntimeExports } from "../_libs/react.mjs";
import { g as getLogFormatAdapter, r as resolveLogFormat, a as getConversationId, c as cn, B as Badge, f as formatTokens } from "./ProxyViewerContainer--3K3o3Sm.mjs";
import { JsonViewerFromString } from "./json-viewer-B4c_WjXD.mjs";
import "./router-DVixpJO-.mjs";
import "../_libs/modelcontextprotocol__server.mjs";
import "../_libs/jszip.mjs";
import { X, H as Rows3, I as Columns2, m as Minus, P as Plus, l as Pencil, f as ChevronRight, J as Equal, C as Check, a as Copy } from "../_libs/lucide-react.mjs";
import "../_libs/swr.mjs";
import "../_libs/use-sync-external-store.mjs";
import "../_libs/dequal.mjs";
import "../_libs/clsx.mjs";
import "../_libs/tailwind-merge.mjs";
import "../_libs/class-variance-authority.mjs";
import "../_libs/radix-ui__react-dialog.mjs";
import "../_libs/radix-ui__primitive.mjs";
import "../_libs/radix-ui__react-compose-refs.mjs";
import "../_libs/radix-ui__react-context.mjs";
import "../_libs/radix-ui__react-id.mjs";
import "../_libs/@radix-ui/react-use-layout-effect+[...].mjs";
import "../_libs/@radix-ui/react-use-controllable-state+[...].mjs";
import "../_libs/@radix-ui/react-dismissable-layer+[...].mjs";
import "../_libs/radix-ui__react-primitive.mjs";
import "../_libs/react-dom.mjs";
import "util";
import "async_hooks";
import "stream";
import "crypto";
import "../_libs/radix-ui__react-slot.mjs";
import "../_libs/@radix-ui/react-use-callback-ref+[...].mjs";
import "../_libs/@radix-ui/react-use-escape-keydown+[...].mjs";
import "../_libs/radix-ui__react-focus-scope.mjs";
import "../_libs/radix-ui__react-portal.mjs";
import "../_libs/radix-ui__react-presence.mjs";
import "../_libs/radix-ui__react-focus-guards.mjs";
import "../_libs/react-remove-scroll.mjs";
import "tslib";
import "../_libs/react-remove-scroll-bar.mjs";
import "../_libs/react-style-singleton.mjs";
import "../_libs/get-nonce.mjs";
import "../_libs/use-sidecar.mjs";
import "../_libs/use-callback-ref.mjs";
import "../_libs/aria-hidden.mjs";
import "../_libs/diff.mjs";
import "../_libs/tanstack__react-virtual.mjs";
import "../_libs/tanstack__virtual-core.mjs";
import "../_libs/radix-ui__react-select.mjs";
import "../_libs/radix-ui__number.mjs";
import "../_libs/radix-ui__react-collection.mjs";
import "../_libs/radix-ui__react-direction.mjs";
import "../_libs/radix-ui__react-popper.mjs";
import "../_libs/floating-ui__react-dom.mjs";
import "../_libs/floating-ui__dom.mjs";
import "../_libs/floating-ui__core.mjs";
import "../_libs/floating-ui__utils.mjs";
import "../_libs/radix-ui__react-arrow.mjs";
import "../_libs/radix-ui__react-use-size.mjs";
import "../_libs/radix-ui__react-use-previous.mjs";
import "../_libs/@radix-ui/react-visually-hidden+[...].mjs";
import "../_libs/zod.mjs";
import "../_libs/radix-ui__react-tooltip.mjs";
import "../_libs/radix-ui__react-tabs.mjs";
import "../_libs/radix-ui__react-roving-focus.mjs";
import "../_libs/react-markdown.mjs";
import "../_libs/devlop.mjs";
import "../_libs/unified.mjs";
import "../_libs/bail.mjs";
import "../_libs/extend.mjs";
import "../_libs/is-plain-obj.mjs";
import "../_libs/trough.mjs";
import "../_libs/vfile.mjs";
import "../_libs/vfile-message.mjs";
import "../_libs/unist-util-stringify-position.mjs";
import "node:process";
import "node:path";
import "node:url";
import "../_libs/remark-parse.mjs";
import "../_libs/mdast-util-from-markdown.mjs";
import "../_libs/micromark-util-decode-numeric-character-reference+[...].mjs";
import "../_libs/micromark-util-decode-string.mjs";
import "../_libs/decode-named-character-reference+[...].mjs";
import "../_libs/character-entities.mjs";
import "../_libs/micromark-util-normalize-identifier+[...].mjs";
import "../_libs/micromark.mjs";
import "../_libs/micromark-util-combine-extensions+[...].mjs";
import "../_libs/micromark-util-chunked.mjs";
import "../_libs/micromark-factory-space.mjs";
import "../_libs/micromark-util-character.mjs";
import "../_libs/micromark-core-commonmark.mjs";
import "../_libs/micromark-util-classify-character+[...].mjs";
import "../_libs/micromark-util-resolve-all.mjs";
import "../_libs/micromark-util-subtokenize.mjs";
import "../_libs/micromark-factory-destination.mjs";
import "../_libs/micromark-factory-label.mjs";
import "../_libs/micromark-factory-title.mjs";
import "../_libs/micromark-factory-whitespace.mjs";
import "../_libs/micromark-util-html-tag-name.mjs";
import "../_libs/mdast-util-to-string.mjs";
import "../_libs/remark-rehype.mjs";
import "../_libs/mdast-util-to-hast.mjs";
import "../_libs/ungap__structured-clone.mjs";
import "../_libs/micromark-util-sanitize-uri.mjs";
import "../_libs/unist-util-position.mjs";
import "../_libs/trim-lines.mjs";
import "../_libs/unist-util-visit.mjs";
import "../_libs/unist-util-visit-parents.mjs";
import "../_libs/unist-util-is.mjs";
import "../_libs/hast-util-to-jsx-runtime.mjs";
import "../_libs/comma-separated-tokens.mjs";
import "../_libs/property-information.mjs";
import "../_libs/space-separated-tokens.mjs";
import "../_libs/style-to-js.mjs";
import "../_libs/style-to-object.mjs";
import "../_libs/inline-style-parser.mjs";
import "../_libs/hast-util-whitespace.mjs";
import "../_libs/estree-util-is-identifier-name.mjs";
import "../_libs/html-url-attributes.mjs";
import "../_libs/tanstack__react-router.mjs";
import "../_libs/tiny-warning.mjs";
import "../_libs/tanstack__router-core.mjs";
import "../_libs/cookie-es.mjs";
import "../_libs/tanstack__history.mjs";
import "../_libs/tiny-invariant.mjs";
import "../_libs/seroval.mjs";
import "../_libs/seroval-plugins.mjs";
import "node:stream/web";
import "node:stream";
import "../_libs/isbot.mjs";
import "node:fs";
import "node:fs/promises";
import "node:buffer";
import "../_libs/conf.mjs";
import "node:util";
import "node:crypto";
import "node:assert";
import "../_libs/dot-prop.mjs";
import "../_libs/env-paths.mjs";
import "node:os";
import "../_libs/atomically.mjs";
import "../_libs/stubborn-fs.mjs";
import "../_libs/stubborn-utils.mjs";
import "../_libs/when-exit.mjs";
import "../_libs/ajv.mjs";
import "../_libs/fast-deep-equal.mjs";
import "../_libs/json-schema-traverse.mjs";
import "../_libs/fast-uri.mjs";
import "../_libs/ajv-formats.mjs";
import "../_libs/debounce-fn.mjs";
import "../_libs/mimic-function.mjs";
import "../_libs/semver.mjs";
import "../_libs/uint8array-extras.mjs";
import "node:child_process";
import "node:worker_threads";
import "../_libs/readable-stream.mjs";
import "events";
import "node:string_decoder";
import "../_libs/process-nextick-args.mjs";
import "../_libs/isarray.mjs";
import "../_libs/safe-buffer.mjs";
import "buffer";
import "../_libs/core-util-is.mjs";
import "../_libs/inherits.mjs";
import "../_libs/util-deprecate.mjs";
import "../_libs/lie.mjs";
import "../_libs/immediate.mjs";
import "../_libs/setimmediate.mjs";
import "../_libs/pako.mjs";
const ROOT_PATH = "";
function formatPath(segments) {
  if (segments.length === 0) return ROOT_PATH;
  let out = "";
  for (let i = 0; i < segments.length; i++) {
    const seg = segments[i];
    if (seg === void 0) continue;
    if (typeof seg === "number") {
      out += `[${seg}]`;
    } else if (i === 0) {
      out += seg;
    } else {
      out += `.${seg}`;
    }
  }
  return out;
}
function isPlainObject(value) {
  return typeof value === "object" && value !== null && !Array.isArray(value);
}
function normalizeRequest(raw) {
  if (typeof raw === "string") {
    try {
      return toNode(JSON.parse(raw));
    } catch {
      return { kind: "primitive", value: raw };
    }
  }
  return toNode(raw);
}
function toNode(value) {
  if (value === null) return { kind: "primitive", value: null };
  if (typeof value === "string") return { kind: "primitive", value };
  if (typeof value === "number") return { kind: "primitive", value };
  if (typeof value === "boolean") return { kind: "primitive", value };
  if (Array.isArray(value)) {
    return { kind: "array", value: value.map((v) => toNode(v)) };
  }
  if (isPlainObject(value)) {
    const out = {};
    for (const k of Object.keys(value).sort()) {
      out[k] = toNode(value[k]);
    }
    return { kind: "object", value: out };
  }
  return { kind: "primitive", value: null };
}
function diffTrees(left, right) {
  const ops = [];
  walk([], left, right, ops);
  return ops;
}
function walk(segments, left, right, out) {
  const path = formatPath(segments);
  if (nodeEqual(left, right)) {
    out.push({ kind: "equal", path, value: left });
    return;
  }
  if (left.kind !== right.kind) {
    out.push({ kind: "changed", path, left, right });
    return;
  }
  if (left.kind === "primitive" && right.kind === "primitive") {
    out.push({ kind: "changed", path, left, right });
    return;
  }
  if (left.kind === "object" && right.kind === "object") {
    const leftKeys = Object.keys(left.value);
    const rightKeys = Object.keys(right.value);
    const rightKeySet = new Set(rightKeys);
    for (const k of leftKeys) {
      const lChild = left.value[k];
      if (lChild === void 0) continue;
      if (!rightKeySet.has(k)) {
        out.push({
          kind: "removed",
          path: formatPath([...segments, k]),
          value: lChild
        });
      } else {
        const rChild = right.value[k];
        if (rChild === void 0) continue;
        walk([...segments, k], lChild, rChild, out);
      }
    }
    for (const k of rightKeys) {
      if (leftKeys.includes(k)) continue;
      const rChild = right.value[k];
      if (rChild === void 0) continue;
      out.push({
        kind: "added",
        path: formatPath([...segments, k]),
        value: rChild
      });
    }
    return;
  }
  if (left.kind === "array" && right.kind === "array") {
    const minLen = Math.min(left.value.length, right.value.length);
    for (let i = 0; i < minLen; i++) {
      const lChild = left.value[i];
      const rChild = right.value[i];
      if (lChild === void 0 || rChild === void 0) continue;
      walk([...segments, i], lChild, rChild, out);
    }
    for (let i = minLen; i < right.value.length; i++) {
      const rChild = right.value[i];
      if (rChild === void 0) continue;
      out.push({
        kind: "added",
        path: formatPath([...segments, i]),
        value: rChild
      });
    }
    for (let i = minLen; i < left.value.length; i++) {
      const lChild = left.value[i];
      if (lChild === void 0) continue;
      out.push({
        kind: "removed",
        path: formatPath([...segments, i]),
        value: lChild
      });
    }
  }
}
function nodeEqual(a, b) {
  if (a.kind !== b.kind) return false;
  if (a.kind === "primitive" && b.kind === "primitive") {
    return a.value === b.value;
  }
  if (a.kind === "array" && b.kind === "array") {
    if (a.value.length !== b.value.length) return false;
    for (let i = 0; i < a.value.length; i++) {
      const ai = a.value[i];
      const bi = b.value[i];
      if (ai === void 0 || bi === void 0) return false;
      if (!nodeEqual(ai, bi)) return false;
    }
    return true;
  }
  if (a.kind === "object" && b.kind === "object") {
    const aKeys = Object.keys(a.value);
    const bKeys = Object.keys(b.value);
    if (aKeys.length !== bKeys.length) return false;
    for (const k of aKeys) {
      const av = a.value[k];
      const bv = b.value[k];
      if (av === void 0 || bv === void 0) return false;
      if (!nodeEqual(av, bv)) return false;
    }
    return true;
  }
  return false;
}
function previewNode(node, maxLen = 80) {
  let s;
  switch (node.kind) {
    case "primitive":
      s = node.value === null ? "null" : JSON.stringify(node.value);
      break;
    case "array":
      s = `[… ${node.value.length} items]`;
      break;
    case "object":
      s = `{… ${Object.keys(node.value).length} keys}`;
      break;
  }
  if (s.length > maxLen) s = `${s.slice(0, maxLen - 1)}…`;
  return s;
}
function nodeToJsonString(node, indent = 2) {
  return JSON.stringify(nodeToJsonValue(node), null, indent);
}
function nodeToJsonValue(node) {
  switch (node.kind) {
    case "primitive":
      return node.value;
    case "array":
      return node.value.map(nodeToJsonValue);
    case "object": {
      const out = {};
      for (const [k, v] of Object.entries(node.value)) {
        out[k] = nodeToJsonValue(v);
      }
      return out;
    }
  }
}
function parentPath(path) {
  if (path === "") return "";
  for (let i = path.length - 1; i >= 0; i--) {
    const ch = path[i];
    if (ch === "." || ch === "[") {
      return path.substring(0, i);
    }
  }
  return "";
}
function isDeepEqual(op) {
  return op.kind === "equal" && (op.value.kind === "object" || op.value.kind === "array");
}
function groupContiguousEquals(ops) {
  const out = [];
  let i = 0;
  while (i < ops.length) {
    const op = ops[i];
    if (op !== void 0 && isDeepEqual(op)) {
      const startParent = parentPath(op.path);
      let j = i + 1;
      while (j < ops.length) {
        const next = ops[j];
        if (next === void 0) break;
        if (!isDeepEqual(next)) break;
        if (parentPath(next.path) !== startParent) break;
        j++;
      }
      if (j - i > 1) {
        const equalOps = [];
        for (let k = i; k < j; k++) {
          const eop = ops[k];
          if (eop !== void 0 && eop.kind === "equal") {
            equalOps.push(eop);
          }
        }
        out.push({ kind: "equal-run", ops: equalOps });
        i = j;
        continue;
      }
    }
    if (op !== void 0) {
      out.push({ kind: "single", op });
    }
    i++;
  }
  return out;
}
const KIND_VISUAL = {
  added: {
    icon: Plus,
    accent: "text-emerald-600 dark:text-emerald-400",
    bg: "bg-emerald-500/5 hover:bg-emerald-500/10",
    border: "border-l-emerald-500",
    label: "ADDED"
  },
  removed: {
    icon: Minus,
    accent: "text-rose-600 dark:text-rose-400",
    bg: "bg-rose-500/5 hover:bg-rose-500/10",
    border: "border-l-rose-500",
    label: "REMOVED"
  },
  changed: {
    icon: Pencil,
    accent: "text-amber-600 dark:text-amber-400",
    bg: "bg-amber-500/5 hover:bg-amber-500/10",
    border: "border-l-amber-500",
    label: "CHANGED"
  },
  equal: {
    icon: Equal,
    accent: "text-muted-foreground/70",
    bg: "bg-muted/20 hover:bg-muted/30",
    border: "border-l-muted-foreground/20",
    label: "EQUAL"
  }
};
function EqualRunRow({
  ops,
  expanded,
  onToggle
}) {
  const first = ops[0];
  const last = ops[ops.length - 1];
  if (first === void 0 || last === void 0) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-muted-foreground/40 text-xs", children: "—" });
  }
  const firstPath = first.path;
  const lastPath = last.path;
  const label = ops.length === 1 ? firstPath : `${firstPath} … ${lastPath}`;
  const summary = first.value.kind === "array" ? `${ops.length} equal arrays` : first.value.kind === "object" ? `${ops.length} equal objects` : "equal";
  const v = KIND_VISUAL.equal;
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: cn("border-l-4 rounded-sm", v.border, v.bg), children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      "button",
      {
        type: "button",
        onClick: onToggle,
        className: "w-full text-left flex items-center gap-2 px-3 py-1.5 text-xs text-muted-foreground cursor-pointer",
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            ChevronRight,
            {
              className: cn("size-3 transition-transform shrink-0", expanded && "rotate-90")
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(v.icon, { className: cn("size-3 shrink-0", v.accent) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono truncate flex-1", title: `${firstPath} … ${lastPath}`, children: label }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: cn("text-[10px] uppercase tracking-wider shrink-0", v.accent), children: v.label }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-muted-foreground/60 shrink-0", children: [
            "(",
            summary,
            ")"
          ] })
        ]
      }
    ),
    expanded && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "ml-5 mt-1 mb-2 space-y-2 pr-2", children: ops.map((op) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "border border-border/50 rounded p-2 bg-muted/20", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-xs text-muted-foreground mb-1", children: op.path }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(JsonViewerFromString, { text: nodeToJsonString(op.value), defaultExpandDepth: 0 })
    ] }, op.path)) })
  ] });
}
function UnifiedOpRow({
  op,
  idx,
  copiedPath,
  onCopyPath,
  expanded,
  onToggle
}) {
  const v = KIND_VISUAL[op.kind];
  const Icon = v.icon;
  const isExpandable = op.kind === "added" || op.kind === "removed" ? op.value.kind === "object" || op.value.kind === "array" : op.kind === "changed" ? op.left.kind === "object" || op.left.kind === "array" || op.right.kind === "object" || op.right.kind === "array" : false;
  const preview = op.kind === "changed" ? [
    {
      text: previewNode(op.left, 400),
      tone: "text-rose-700 dark:text-rose-300 line-through"
    },
    { text: previewNode(op.right, 400), tone: "text-emerald-700 dark:text-emerald-300" }
  ] : op.kind === "removed" ? [
    {
      text: previewNode(op.value, 400),
      tone: "text-rose-700 dark:text-rose-300 line-through"
    }
  ] : op.kind === "added" ? [{ text: previewNode(op.value, 400), tone: "text-emerald-700 dark:text-emerald-300" }] : [{ text: previewNode(op.value, 400), tone: "text-muted-foreground" }];
  const justCopied = copiedPath === op.path && op.path !== "";
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
    "div",
    {
      "data-diff-idx": idx,
      "data-diff-kind": op.kind,
      className: cn("border-l-4 rounded-sm px-3 py-2 my-0.5 transition-colors", v.border, v.bg),
      children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(
          "button",
          {
            type: "button",
            onClick: onToggle,
            disabled: !isExpandable,
            className: cn(
              "w-full flex items-center gap-2 text-xs text-left rounded-sm",
              isExpandable ? "cursor-pointer" : "cursor-default"
            ),
            "aria-expanded": isExpandable ? expanded : void 0,
            "aria-label": isExpandable ? expanded ? `Collapse ${op.path || "root"}` : `Expand ${op.path || "root"}` : void 0,
            children: [
              isExpandable ? /* @__PURE__ */ jsxRuntimeExports.jsx(
                ChevronRight,
                {
                  className: cn(
                    "size-3 shrink-0 transition-transform",
                    v.accent,
                    expanded && "rotate-90"
                  )
                }
              ) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "size-3 shrink-0", "aria-hidden": "true" }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(Icon, { className: cn("size-3.5 shrink-0", v.accent), strokeWidth: 2.5 }),
              /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono truncate flex-1 min-w-0", title: op.path || "(root)", children: op.path === "" ? "(root)" : op.path }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(
                "span",
                {
                  className: cn(
                    "text-[9px] font-bold uppercase tracking-wider shrink-0 px-1.5 py-0.5 rounded",
                    v.accent,
                    op.kind === "equal" ? "bg-muted/40" : "bg-background/60"
                  ),
                  children: v.label
                }
              ),
              op.path !== "" && /* @__PURE__ */ jsxRuntimeExports.jsx(
                "span",
                {
                  role: "button",
                  tabIndex: 0,
                  onClick: (e) => {
                    e.stopPropagation();
                    onCopyPath(op.path);
                  },
                  onKeyDown: (e) => {
                    if (e.key === "Enter" || e.key === " ") {
                      e.stopPropagation();
                      e.preventDefault();
                      onCopyPath(op.path);
                    }
                  },
                  className: cn(
                    "shrink-0 p-1 rounded transition-colors cursor-pointer inline-flex items-center justify-center",
                    justCopied ? "text-emerald-500" : "text-muted-foreground/50 hover:text-foreground hover:bg-muted"
                  ),
                  "aria-label": justCopied ? "Copied" : "Copy",
                  title: justCopied ? "Copied!" : "Copy",
                  children: justCopied ? /* @__PURE__ */ jsxRuntimeExports.jsx(Check, { className: "size-3" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Copy, { className: "size-3" })
                }
              )
            ]
          }
        ),
        preview.map((p, i) => (
          // biome-ignore lint/suspicious/noArrayIndexKey: preview list is rebuilt on every render and is positional
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: cn("font-mono text-xs mt-1 break-all pl-5", p.tone), children: p.text }, i)
        )),
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          "div",
          {
            className: "overflow-hidden transition-all duration-200",
            style: { maxHeight: expanded && isExpandable ? "2000px" : "0" },
            "aria-hidden": !expanded,
            children: expanded && isExpandable && op.kind !== "equal" ? /* @__PURE__ */ jsxRuntimeExports.jsx(ExpandedSubtree, { op }) : null
          }
        )
      ]
    }
  );
}
function ExpandedSubtree({ op }) {
  if (op.kind === "added" || op.kind === "removed") {
    return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "pl-5 mt-2 border border-border/50 rounded p-2 bg-muted/20", children: /* @__PURE__ */ jsxRuntimeExports.jsx(JsonViewerFromString, { text: nodeToJsonString(op.value), defaultExpandDepth: 0 }) });
  }
  const leftIsStructured = op.left.kind === "object" || op.left.kind === "array";
  const rightIsStructured = op.right.kind === "object" || op.right.kind === "array";
  if (!leftIsStructured && !rightIsStructured) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "pl-5 mt-2 text-xs text-muted-foreground/70 italic", children: "Primitive values are shown inline above." });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "pl-5 mt-2 grid grid-cols-1 md:grid-cols-2 gap-2", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "border border-rose-500/30 rounded p-2 bg-rose-500/5", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] uppercase tracking-wider text-rose-500 mb-1", children: "Old" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(JsonViewerFromString, { text: nodeToJsonString(op.left), defaultExpandDepth: 0 })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "border border-emerald-500/30 rounded p-2 bg-emerald-500/5", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] uppercase tracking-wider text-emerald-500 mb-1", children: "New" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(JsonViewerFromString, { text: nodeToJsonString(op.right), defaultExpandDepth: 0 })
    ] })
  ] });
}
function SummaryChips({
  counts,
  onJumpTo
}) {
  const total = counts.added + counts.removed + counts.changed;
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-4 py-2 border-b border-border bg-muted/20 flex items-center gap-2 text-xs flex-wrap", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-muted-foreground font-medium", children: [
      total,
      " ",
      total === 1 ? "change" : "changes"
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      "button",
      {
        type: "button",
        onClick: () => onJumpTo("removed"),
        disabled: counts.removed === 0,
        className: cn(
          "inline-flex items-center gap-1 px-2 py-0.5 rounded-full border cursor-pointer transition-colors",
          counts.removed > 0 ? "border-rose-500/40 text-rose-600 dark:text-rose-400 bg-rose-500/10 hover:bg-rose-500/20" : "border-border text-muted-foreground/40 cursor-not-allowed"
        ),
        title: counts.removed > 0 ? "Jump to first removed" : "No removals",
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Minus, { className: "size-3" }),
          counts.removed,
          " removed"
        ]
      }
    ),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      "button",
      {
        type: "button",
        onClick: () => onJumpTo("added"),
        disabled: counts.added === 0,
        className: cn(
          "inline-flex items-center gap-1 px-2 py-0.5 rounded-full border cursor-pointer transition-colors",
          counts.added > 0 ? "border-emerald-500/40 text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 hover:bg-emerald-500/20" : "border-border text-muted-foreground/40 cursor-not-allowed"
        ),
        title: counts.added > 0 ? "Jump to first added" : "No additions",
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Plus, { className: "size-3" }),
          counts.added,
          " added"
        ]
      }
    ),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      "button",
      {
        type: "button",
        onClick: () => onJumpTo("changed"),
        disabled: counts.changed === 0,
        className: cn(
          "inline-flex items-center gap-1 px-2 py-0.5 rounded-full border cursor-pointer transition-colors",
          counts.changed > 0 ? "border-amber-500/40 text-amber-600 dark:text-amber-400 bg-amber-500/10 hover:bg-amber-500/20" : "border-border text-muted-foreground/40 cursor-not-allowed"
        ),
        title: counts.changed > 0 ? "Jump to first changed" : "No changes",
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Pencil, { className: "size-3" }),
          counts.changed,
          " changed"
        ]
      }
    )
  ] });
}
function ModeToggle({
  mode,
  onChange
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "inline-flex rounded-md border border-border overflow-hidden", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      "button",
      {
        type: "button",
        onClick: () => onChange("unified"),
        "aria-pressed": mode === "unified",
        className: cn(
          "flex items-center gap-1 px-2 py-1 text-xs transition-colors cursor-pointer",
          mode === "unified" ? "bg-muted text-foreground" : "hover:bg-muted/50 text-muted-foreground"
        ),
        title: "Unified view (single column, emphasized diffs)",
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Rows3, { className: "size-3" }),
          "Unified"
        ]
      }
    ),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      "button",
      {
        type: "button",
        onClick: () => onChange("split"),
        "aria-pressed": mode === "split",
        className: cn(
          "flex items-center gap-1 px-2 py-1 text-xs transition-colors border-l border-border cursor-pointer",
          mode === "split" ? "bg-muted text-foreground" : "hover:bg-muted/50 text-muted-foreground"
        ),
        title: "Split view (path | left | right)",
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Columns2, { className: "size-3" }),
          "Split"
        ]
      }
    )
  ] });
}
function SideSummary({ log, side }) {
  const conversationId = getConversationId(log);
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0 space-y-1 text-xs", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        Badge,
        {
          variant: "outline",
          className: cn(
            "text-[10px] px-1.5 py-0 h-5 font-mono shrink-0",
            side === "left" ? "border-rose-500/40 text-rose-400" : "border-emerald-500/40 text-emerald-400"
          ),
          children: side === "left" ? "← Left" : "Right →"
        }
      ),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-mono text-blue-400/80", children: [
        "#",
        log.id
      ] }),
      log.model !== null && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono text-muted-foreground truncate", children: log.model })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3 text-muted-foreground font-mono", children: [
      log.cacheCreationInputTokens !== null && log.cacheCreationInputTokens > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-emerald-400", children: [
        "Cache +",
        formatTokens(log.cacheCreationInputTokens)
      ] }),
      log.cacheReadInputTokens !== null && log.cacheReadInputTokens > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-purple-400", children: [
        "Cache ~",
        formatTokens(log.cacheReadInputTokens)
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate", title: log.timestamp, children: log.timestamp })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-muted-foreground/70 font-mono truncate", title: conversationId, children: [
      "session: ",
      conversationId
    ] })
  ] });
}
function CompareDrawer({ left, right, onClose }) {
  const ops = reactExports.useMemo(() => {
    const leftRequest = getLogFormatAdapter(resolveLogFormat(left)).analyzeRequest(
      left.rawRequestBody
    );
    const rightRequest = getLogFormatAdapter(resolveLogFormat(right)).analyzeRequest(
      right.rawRequestBody
    );
    const l = normalizeRequest(leftRequest.comparisonValue);
    const r = normalizeRequest(rightRequest.comparisonValue);
    return diffTrees(l, r);
  }, [
    left.apiFormat,
    left.path,
    left.rawRequestBody,
    right.apiFormat,
    right.path,
    right.rawRequestBody
  ]);
  const grouped = reactExports.useMemo(() => groupContiguousEquals(ops), [ops]);
  const counts = reactExports.useMemo(() => {
    let added = 0;
    let removed = 0;
    let changed = 0;
    for (const g of grouped) {
      if (g.kind !== "single") continue;
      switch (g.op.kind) {
        case "added":
          added++;
          break;
        case "removed":
          removed++;
          break;
        case "changed":
          changed++;
          break;
      }
    }
    return { added, removed, changed };
  }, [grouped]);
  const [expandedRuns, setExpandedRuns] = reactExports.useState(/* @__PURE__ */ new Set());
  const toggleRun = (idx) => {
    setExpandedRuns((prev) => {
      const next = new Set(prev);
      if (next.has(idx)) next.delete(idx);
      else next.add(idx);
      return next;
    });
  };
  const [expandedRows, setExpandedRows] = reactExports.useState(/* @__PURE__ */ new Set());
  const toggleRow = (idx) => {
    setExpandedRows((prev) => {
      const next = new Set(prev);
      if (next.has(idx)) next.delete(idx);
      else next.add(idx);
      return next;
    });
  };
  reactExports.useEffect(() => {
    setExpandedRows(/* @__PURE__ */ new Set());
  }, [left.id, right.id]);
  const [mode, setMode] = reactExports.useState("unified");
  const bodyRef = reactExports.useRef(null);
  const [copiedPath, setCopiedPath] = reactExports.useState(null);
  const copyResetTimer = reactExports.useRef(null);
  const onCopyPath = (path) => {
    void window.navigator.clipboard.writeText(path).then(() => {
      setCopiedPath(path);
      if (copyResetTimer.current !== null) clearTimeout(copyResetTimer.current);
      copyResetTimer.current = setTimeout(() => setCopiedPath(null), 1500);
    });
  };
  reactExports.useEffect(() => {
    return () => {
      if (copyResetTimer.current !== null) clearTimeout(copyResetTimer.current);
    };
  }, []);
  const jumpToKind = (kind) => {
    const idx = grouped.findIndex((g) => g.kind === "single" && g.op.kind === kind);
    if (idx === -1) return;
    const root = bodyRef.current;
    if (root === null) return;
    const el = root.querySelector(`[data-diff-idx="${idx}"]`);
    if (el !== null) {
      el.scrollIntoView({ behavior: "smooth", block: "center" });
    }
  };
  reactExports.useEffect(() => {
    const onKey = (e) => {
      if (e.key === "Escape") onClose();
    };
    document.addEventListener("keydown", onKey);
    const prevOverflow = document.body.style.overflow;
    document.body.style.overflow = "hidden";
    return () => {
      document.removeEventListener("keydown", onKey);
      document.body.style.overflow = prevOverflow;
    };
  }, [onClose]);
  const sameSession = getConversationId(left) === getConversationId(right);
  const allEqual = ops.length === 1 && ops[0]?.kind === "equal";
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
    "div",
    {
      className: "fixed inset-0 z-50 flex justify-end",
      role: "dialog",
      "aria-modal": "true",
      "aria-label": "Compare two log requests",
      children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          "button",
          {
            type: "button",
            onClick: onClose,
            "aria-label": "Close compare drawer",
            className: "absolute inset-0 bg-black/40 cursor-default",
            tabIndex: -1
          }
        ),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(
          "div",
          {
            className: cn(
              "relative bg-background border-l border-border shadow-xl",
              "w-full md:w-[70vw] max-w-[1100px] flex flex-col h-full"
            ),
            onClick: (e) => e.stopPropagation(),
            onKeyDown: (e) => e.stopPropagation(),
            children: [
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start gap-4 px-4 py-3 border-b border-border", children: [
                /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 flex gap-4 min-w-0", children: [
                  /* @__PURE__ */ jsxRuntimeExports.jsx(SideSummary, { log: left, side: "left" }),
                  /* @__PURE__ */ jsxRuntimeExports.jsx(SideSummary, { log: right, side: "right" })
                ] }),
                /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 shrink-0", children: [
                  /* @__PURE__ */ jsxRuntimeExports.jsx(ModeToggle, { mode, onChange: setMode }),
                  /* @__PURE__ */ jsxRuntimeExports.jsx(
                    "button",
                    {
                      type: "button",
                      onClick: onClose,
                      "aria-label": "Close",
                      className: "p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted cursor-pointer",
                      children: /* @__PURE__ */ jsxRuntimeExports.jsx(X, { className: "size-4" })
                    }
                  )
                ] })
              ] }),
              !sameSession && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "px-4 py-1.5 text-xs text-amber-400 bg-amber-500/10 border-b border-border", children: "Heads up: the two selected logs are from different sessions." }),
              allEqual ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 min-h-0 overflow-y-auto flex items-center justify-center text-muted-foreground text-sm", children: "The two Request payloads are identical." }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
                /* @__PURE__ */ jsxRuntimeExports.jsx(SummaryChips, { counts, onJumpTo: jumpToKind }),
                /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: bodyRef, className: "flex-1 min-h-0 overflow-y-auto", children: mode === "unified" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "px-3 py-2 space-y-0.5", children: grouped.map((g, i) => {
                  if (g.kind === "equal-run") {
                    return /* @__PURE__ */ jsxRuntimeExports.jsx(
                      EqualRunRow,
                      {
                        ops: g.ops,
                        expanded: expandedRuns.has(i),
                        onToggle: () => toggleRun(i)
                      },
                      `r${i}`
                    );
                  }
                  const op = g.op;
                  return /* @__PURE__ */ jsxRuntimeExports.jsx(
                    UnifiedOpRow,
                    {
                      op,
                      idx: i,
                      copiedPath,
                      onCopyPath,
                      expanded: expandedRows.has(i),
                      onToggle: () => toggleRow(i)
                    },
                    `o${i}`
                  );
                }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(SplitBody, { grouped, left, right }) })
              ] })
            ]
          }
        )
      ]
    }
  );
}
function SplitBody({
  grouped,
  left,
  right
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-[200px_1fr_1fr] gap-x-2 gap-y-0.5 px-3 py-2 text-xs", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-[200px_1fr_1fr] gap-x-2 col-span-3 pb-2 mb-2 border-b border-border text-[10px] uppercase tracking-wider text-muted-foreground", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Path" }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
        "Left (Log #",
        left.id,
        ")"
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
        "Right (Log #",
        right.id,
        ")"
      ] })
    ] }),
    grouped.map((g, i) => {
      if (g.kind === "equal-run") {
        return /* @__PURE__ */ jsxRuntimeExports.jsxs(
          "div",
          {
            className: "col-span-3 px-2 py-1 text-xs text-muted-foreground/60",
            children: [
              g.ops.length,
              " equal siblings collapsed — switch to Unified to expand"
            ]
          },
          i
        );
      }
      const op = g.op;
      if (op.kind === "equal") {
        return /* @__PURE__ */ jsxRuntimeExports.jsxs(
          "div",
          {
            className: "col-span-3 grid grid-cols-[200px_1fr_1fr] gap-x-2 px-2 py-0.5 text-muted-foreground",
            children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono text-xs truncate", title: op.path, children: op.path }),
              /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono text-xs break-all opacity-60", children: previewNode(op.value, 200) }),
              /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono text-xs break-all opacity-60", children: previewNode(op.value, 200) })
            ]
          },
          i
        );
      }
      if (op.kind === "added") {
        return /* @__PURE__ */ jsxRuntimeExports.jsxs(
          "div",
          {
            className: "col-span-3 px-2 py-1 rounded text-xs border-l-2 border-l-emerald-400/70 bg-emerald-500/5",
            children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-xs text-muted-foreground mb-0.5", children: op.path }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "font-mono break-all text-emerald-300/90", children: [
                "+ ",
                previewNode(op.value, 400)
              ] })
            ]
          },
          i
        );
      }
      if (op.kind === "removed") {
        return /* @__PURE__ */ jsxRuntimeExports.jsxs(
          "div",
          {
            className: "col-span-3 px-2 py-1 rounded text-xs border-l-2 border-l-rose-400/70 bg-rose-500/5",
            children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-xs text-muted-foreground mb-0.5", children: op.path }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "font-mono break-all text-rose-300/90 line-through", children: [
                "− ",
                previewNode(op.value, 400)
              ] })
            ]
          },
          i
        );
      }
      return /* @__PURE__ */ jsxRuntimeExports.jsxs(
        "div",
        {
          className: "col-span-3 px-2 py-1 rounded text-xs border-l-2 border-l-amber-400/70 bg-amber-500/5",
          children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-xs text-muted-foreground mb-1", children: op.path }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-2 gap-2", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-rose-300/90 break-all line-through", children: previewNode(op.left, 400) }),
              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-emerald-300/90 break-all", children: previewNode(op.right, 400) })
            ] })
          ]
        },
        i
      );
    })
  ] });
}
export {
  CompareDrawer
};
