react-semaphor 0.1.391 → 0.1.393

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +120 -252
  3. package/dist/brand-studio/index.cjs +1 -1
  4. package/dist/brand-studio/index.js +7 -7
  5. package/dist/chunks/analyze-result-contract-C9Gv2_qW.js +1585 -0
  6. package/dist/chunks/analyze-result-contract-Zgg-Bbpj.js +1 -0
  7. package/dist/chunks/{braces--20GzUQh.js → braces-8TRlDwDw.js} +1 -1
  8. package/dist/chunks/{braces-C0Vh_Mft.js → braces-D2tStQjF.js} +1 -1
  9. package/dist/chunks/{calendar-preferences-dialog-B-VsxhsA.js → calendar-preferences-dialog-49fcEPXS.js} +4 -4
  10. package/dist/chunks/{calendar-preferences-dialog-DE67Z3oQ.js → calendar-preferences-dialog-DwLeBLy2.js} +1 -1
  11. package/dist/chunks/dashboard-briefing-launcher-CgkSKkZR.js +80 -0
  12. package/dist/chunks/{dashboard-briefing-launcher-BIj3X7b3.js → dashboard-briefing-launcher-cgPKz1yX.js} +252 -252
  13. package/dist/chunks/dashboard-controls-D12ZSUP_.js +52 -0
  14. package/dist/chunks/{dashboard-controls-BXxucM4f.js → dashboard-controls-VMFm3OP4.js} +87 -87
  15. package/dist/chunks/{dashboard-json-C6oZuipD.js → dashboard-json-C-GG5yC7.js} +4 -4
  16. package/dist/chunks/{dashboard-json-BNwshkK2.js → dashboard-json-CvK0oI24.js} +1 -1
  17. package/dist/chunks/{edit-dashboard-visual-CmfrI_L3.js → edit-dashboard-visual-B5KB7dx4.js} +977 -977
  18. package/dist/chunks/edit-dashboard-visual-ql99faTz.js +178 -0
  19. package/dist/chunks/{index-icb12JV1.js → index-CQmKDEbe.js} +735 -741
  20. package/dist/chunks/{index-4W_ElSBJ.js → index-DXCBPLDu.js} +218 -223
  21. package/dist/chunks/{layout-grid-B7-klXiK.js → layout-grid-C0OI-MRn.js} +1 -1
  22. package/dist/chunks/{layout-grid-DV89AC9_.js → layout-grid-CiubineE.js} +1 -1
  23. package/dist/chunks/{palette-Dj-dgPYh.js → palette-C4KTXOug.js} +1 -1
  24. package/dist/chunks/{palette-5IwhMbSF.js → palette-Cp1hqZtm.js} +1 -1
  25. package/dist/chunks/{save-C5fwVdTF.js → save-C__QggEE.js} +1 -1
  26. package/dist/chunks/{save-16C6YSW2.js → save-DgMfP0j8.js} +1 -1
  27. package/dist/chunks/{search-0LmWwZzW.js → search-BHsQIWBV.js} +17 -7
  28. package/dist/chunks/{search-Dq1Mbb03.js → search-DNCejM7Z.js} +9 -4
  29. package/dist/chunks/source-identity-uMaUe036.js +1 -0
  30. package/dist/chunks/{source-identity-CN4xiyKJ.js → source-identity-y0VSSreA.js} +33 -15
  31. package/dist/chunks/{switch-bdJp0Bkw.js → switch-B79Hn4Qh.js} +27 -32
  32. package/dist/chunks/{switch-DUdaHFZQ.js → switch-BXQAlSuW.js} +637 -647
  33. package/dist/chunks/use-create-flow-overlay-state-7MFN3PWX.js +21 -0
  34. package/dist/chunks/{use-create-flow-overlay-state-YvqCp6Zo.js → use-create-flow-overlay-state-Bw5LRkf9.js} +93 -92
  35. package/dist/chunks/{validators-CHPH6ORs.js → validators-4EGCWWga.js} +1 -1
  36. package/dist/chunks/{validators-lWo8m0Q7.js → validators-CPtkrola.js} +1 -1
  37. package/dist/chunks/{x-B_cx7LwM.js → x-B6ghREd2.js} +10 -5
  38. package/dist/chunks/{x-IdR_js6f.js → x-CXDkqdur.js} +28 -18
  39. package/dist/dashboard/index.cjs +1 -1
  40. package/dist/dashboard/index.js +1 -1
  41. package/dist/dashboard-authoring/index.cjs +1 -1
  42. package/dist/dashboard-authoring/index.js +3 -3
  43. package/dist/data-app-builder/index.cjs +13 -13
  44. package/dist/data-app-builder/index.js +11 -11
  45. package/dist/data-app-sdk/index.cjs +5 -5
  46. package/dist/data-app-sdk/index.js +1589 -1234
  47. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  48. package/dist/data-app-sdk-adapters/index.js +6 -7
  49. package/dist/data-app-sdk-validation/index.cjs +1 -1
  50. package/dist/data-app-sdk-validation/index.js +3 -3
  51. package/dist/index.cjs +1 -1
  52. package/dist/index.js +13 -13
  53. package/dist/surfboard/index.cjs +1 -1
  54. package/dist/surfboard/index.js +2 -2
  55. package/dist/types/analytics-protocol.d.ts +2107 -43
  56. package/dist/types/dashboard-assistant.d.ts +3 -1
  57. package/dist/types/data-app-sdk-adapters.d.ts +1 -1
  58. package/dist/types/data-app-sdk-validation.d.ts +4 -2
  59. package/dist/types/data-app-sdk.d.ts +73 -5
  60. package/package.json +2 -1
  61. package/src/data-app-sdk/README.md +55 -0
  62. package/dist/chunks/analyze-result-contract-CtXfp3nv.js +0 -1
  63. package/dist/chunks/analyze-result-contract-DuhlklhI.js +0 -102
  64. package/dist/chunks/dashboard-briefing-launcher-Czx6BcXW.js +0 -80
  65. package/dist/chunks/dashboard-controls-BP-DcPFs.js +0 -52
  66. package/dist/chunks/edit-dashboard-visual-BAprin3J.js +0 -178
  67. package/dist/chunks/source-identity-C-xaeE_I.js +0 -1
  68. package/dist/chunks/use-create-flow-overlay-state-BIHKf_XK.js +0 -21
@@ -2,12 +2,12 @@ import { jsx as r, jsxs as c, Fragment as re } from "react/jsx-runtime";
2
2
  import * as Yn from "react";
3
3
  import { useContext as Zn, useState as x, useRef as oe, useMemo as ze, useEffect as W, useCallback as Ot } from "react";
4
4
  import * as Xn from "react-dom/client";
5
- import { ae as ea, af as ta, ag as Ir, ah as jr, ai as zr, aj as ra, ak as Wr, al as Hr, am as Jr, an as Vr, ao as _r, ap as Ur, aq as Gr, ar as na, as as aa, at as oa, au as Ht, av as on, x as Kr, aw as sa, ax as Vt, ay as _t, az as sn, aA as ia, aB as la } from "../chunks/index-icb12JV1.js";
6
- import { B as H, P as it, a as lt, b as dt, $ as da, a0 as ca, a1 as ua, a2 as pa, a3 as ha, e as me, R as ma, d as Ut } from "../chunks/switch-DUdaHFZQ.js";
5
+ import { ae as ea, af as ta, ag as Ir, ah as jr, ai as zr, aj as ra, ak as Wr, al as Hr, am as Jr, an as Vr, ao as _r, ap as Ur, aq as Gr, ar as na, as as aa, at as oa, au as Ht, av as on, x as Kr, aw as sa, ax as Vt, ay as sn, az as ia, aA as la } from "../chunks/index-CQmKDEbe.js";
6
+ import { B as H, P as it, a as lt, b as dt, _ as da, $ as ca, a0 as ua, a1 as pa, a2 as ha, e as me, R as ma, d as _t } from "../chunks/switch-BXQAlSuW.js";
7
7
  import { loadSemaphorBrowserRuntime as ot } from "../data-app-builder-browser-runtime/index.js";
8
- import { c as $e, X as Je } from "../chunks/x-IdR_js6f.js";
9
- import { S as fa } from "../chunks/save-16C6YSW2.js";
10
- import { S as ga } from "../chunks/search-0LmWwZzW.js";
8
+ import { c as $e, X as Je } from "../chunks/x-CXDkqdur.js";
9
+ import { S as fa } from "../chunks/save-DgMfP0j8.js";
10
+ import { C as Ut, S as ga } from "../chunks/search-BHsQIWBV.js";
11
11
  /**
12
12
  * @license lucide-react v0.453.0 - ISC
13
13
  *
@@ -860,7 +860,7 @@ function cn({
860
860
  style: { paddingLeft: `${8 + a * 14}px` },
861
861
  children: [
862
862
  l ? /* @__PURE__ */ c(re, { children: [
863
- /* @__PURE__ */ r(_t, { className: "h-3 w-3 rotate-90 text-muted-foreground" }),
863
+ /* @__PURE__ */ r(Ut, { className: "h-3 w-3 rotate-90 text-muted-foreground" }),
864
864
  /* @__PURE__ */ r(xa, { className: "h-3.5 w-3.5 text-muted-foreground" })
865
865
  ] }) : /* @__PURE__ */ c(re, { children: [
866
866
  /* @__PURE__ */ r("span", { className: "h-3 w-3" }),
@@ -3044,7 +3044,7 @@ function Ya({
3044
3044
  {
3045
3045
  className: `flex items-start gap-2 rounded-[6px] border px-2.5 py-2 text-[11.5px] leading-relaxed ${de.state === "failed" ? "border-destructive/30 bg-destructive/10 text-destructive" : de.state === "done" ? "border-emerald-200 bg-emerald-50 text-emerald-800 dark:border-emerald-900/60 dark:bg-emerald-950/30 dark:text-emerald-300" : "border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-900/60 dark:bg-blue-950/30 dark:text-blue-300"}`,
3046
3046
  children: [
3047
- de.state === "running" ? /* @__PURE__ */ r(me, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin" }) : de.state === "done" ? /* @__PURE__ */ r(Ut, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }) : /* @__PURE__ */ r(Je, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }),
3047
+ de.state === "running" ? /* @__PURE__ */ r(me, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin" }) : de.state === "done" ? /* @__PURE__ */ r(_t, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }) : /* @__PURE__ */ r(Je, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }),
3048
3048
  /* @__PURE__ */ c("div", { className: "min-w-0", children: [
3049
3049
  /* @__PURE__ */ r("div", { className: "font-medium", children: de.label }),
3050
3050
  de.detail ? /* @__PURE__ */ r("div", { className: "mt-0.5 truncate opacity-80", children: de.detail }) : null
@@ -3144,7 +3144,7 @@ function Za({ code: e, lang: a }) {
3144
3144
  },
3145
3145
  className: "inline-flex items-center gap-1 rounded-[4px] px-1.5 py-0.5 text-[10.5px] font-medium text-muted-foreground hover:bg-accent hover:text-foreground",
3146
3146
  children: s ? /* @__PURE__ */ c(re, { children: [
3147
- /* @__PURE__ */ r(Ut, { className: "h-3 w-3" }),
3147
+ /* @__PURE__ */ r(_t, { className: "h-3 w-3" }),
3148
3148
  "Copied"
3149
3149
  ] }) : /* @__PURE__ */ c(re, { children: [
3150
3150
  /* @__PURE__ */ r(on, { className: "h-3 w-3" }),
@@ -3226,7 +3226,7 @@ function no({
3226
3226
  className: "flex w-full items-center gap-2 px-2.5 py-1.5 text-left",
3227
3227
  children: [
3228
3228
  /* @__PURE__ */ r(
3229
- _t,
3229
+ Ut,
3230
3230
  {
3231
3231
  className: `h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform ${l ? "rotate-90" : ""}`
3232
3232
  }
@@ -3549,7 +3549,7 @@ function uo({
3549
3549
  className: "group rounded-[6px] border border-border/60 bg-muted/20",
3550
3550
  children: [
3551
3551
  /* @__PURE__ */ c("summary", { className: "flex cursor-pointer list-none items-center gap-2 px-2.5 py-1.5 text-[12px] marker:hidden", children: [
3552
- /* @__PURE__ */ r(_t, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform group-open:rotate-90" }),
3552
+ /* @__PURE__ */ r(Ut, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform group-open:rotate-90" }),
3553
3553
  /* @__PURE__ */ r(
3554
3554
  "span",
3555
3555
  {
@@ -3673,7 +3673,7 @@ function po({
3673
3673
  ] });
3674
3674
  }
3675
3675
  function ho({ state: e }) {
3676
- return e === "done" ? /* @__PURE__ */ r(Ut, { className: "h-3.5 w-3.5 text-emerald-600" }) : e === "running" ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin text-blue-600" }) : e === "blocked" ? /* @__PURE__ */ r(Je, { className: "h-3.5 w-3.5 text-destructive" }) : /* @__PURE__ */ r(la, { className: "h-2.5 w-2.5 fill-zinc-300 stroke-none" });
3676
+ return e === "done" ? /* @__PURE__ */ r(_t, { className: "h-3.5 w-3.5 text-emerald-600" }) : e === "running" ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin text-blue-600" }) : e === "blocked" ? /* @__PURE__ */ r(Je, { className: "h-3.5 w-3.5 text-destructive" }) : /* @__PURE__ */ r(la, { className: "h-2.5 w-2.5 fill-zinc-300 stroke-none" });
3677
3677
  }
3678
3678
  export {
3679
3679
  ko as DataAppBuilder
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../data-app-sdk-adapters/index.cjs"),s=require("react/jsx-runtime"),l=require("react"),ue=require("../chunks/search-Dq1Mbb03.js"),Ye=require("../chunks/x-B_cx7LwM.js"),jr=require("../chunks/validators-lWo8m0Q7.js");require("../chunks/analyze-result-contract-CtXfp3nv.js");function ie(e,r,t={}){return{...t,name:e,role:r}}function qr(e){return e}function Rr(e){return e}const Ar={source:{semantic(e){return{...e,kind:"semantic"}},sql(e){return{...e,kind:"sql"}}},field:{measure(e,r){return ie(e,"measure",r)},dimension(e,r){return ie(e,"dimension",r)},date(e,r){return ie(e,"date",r)},id(e,r){return ie(e,"id",r)}},filter(e){return{...e,kind:"filter"}},bindInput(e,r){return{toAnalyticsInput(){const[t]=S.toSemaphorInputSnapshots([e]),n=S.toSemaphorInputBinding({...r,inputId:r.inputId||t.inputId});return{...t,inputId:n.inputId,...n.kind?{kind:n.kind}:{},...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{},...n.relationshipHint?{relationshipHint:n.relationshipHint}:{}}}}},control(e){return{...e,kind:"control"}},sqlParam(e){return{...e,kind:"control",role:"sqlParam"}},derivedField(e){return{...e,kind:"derived_field",expressionLanguage:e.expressionLanguage||"semaphor_sql_template"}},metric(e){return{...e,queryKind:"metric"}},analysis(e){return{...e,queryKind:"analysis"}},records(e){return{...e,queryKind:"records"}},inputOptions(e){return{...e,queryKind:"inputOptions"}},sql(e){return{...e,queryKind:"sql"}},matrix(e){return{...e,queryKind:"matrix"}}},he=10,be=100,Cr=25,Er=500,Xe={enabled:!1,queries:[],getQuery:()=>{},getQueries:()=>[]},Ce=l.createContext(null),Ee=l.createContext(null),Te=l.createContext(void 0),_=[];function Tr({debug:e,children:r}){const t=l.useMemo(()=>Wt(e),[e]),[n,i]=l.useReducer(Ct,t,cr),a=l.useRef(n),u=l.useId(),[p,f]=l.useState({open:!1});a.current=n,l.useEffect(()=>{i({type:"config",config:t})},[t]),l.useEffect(()=>{if(!n.enabled||!n.exposeWindowBridge||typeof window>"u")return;const h=Ot(()=>a.current);return kr({ownerId:u,bridge:h}),()=>{Dr(u)}},[u,n.enabled,n.exposeWindowBridge]);const c=l.useMemo(()=>({state:n,dispatch:i}),[n]),b=l.useCallback(h=>{f({open:!0,focus:h})},[]),y=l.useCallback(()=>{f(h=>({...h,open:!1}))},[]),v=l.useCallback(h=>{f({open:!0,focus:h})},[]),g=l.useMemo(()=>({open:p.open,focus:p.focus,openDevtools:b,closeDevtools:y,focusTrace:v}),[y,v,b,p.focus,p.open]);return s.jsx(Ce.Provider,{value:c,children:s.jsx(Ee.Provider,{value:g,children:r})})}function kr(e){const r=_.findIndex(t=>t.ownerId===e.ownerId);r>=0&&_.splice(r,1),_.push(e),Ze()}function Dr(e){const r=_.findIndex(t=>t.ownerId===e);r>=0&&_.splice(r,1),Ze()}function Ze(){if(typeof window>"u")return;const e=_[_.length-1];e?window.__SEMAPHOR_DEVTOOLS__=e.bridge:delete window.__SEMAPHOR_DEVTOOLS__}function Lr({id:e,title:r,children:t}){const n=l.useMemo(()=>({id:e,title:r}),[e,r]);return s.jsx(Te.Provider,{value:n,children:t})}function er({buttonPosition:e="bottom-right",initialIsOpen:r=!1,panelPosition:t="right",className:n,style:i}={}){const a=ke(),u=l.useContext(Ee),[p,f]=l.useState(""),[c,b]=l.useState(!1),y=l.useRef(null),v=l.useRef(null),g=u==null?void 0:u.openDevtools,h=u==null?void 0:u.closeDevtools,E=(u==null?void 0:u.open)===!0;l.useEffect(()=>{ur()},[]),l.useEffect(()=>{r&&a.enabled&&(g==null||g())},[r,a.enabled,g]),l.useEffect(()=>{if(!E||!h)return;const m=x=>{var w,q;const T=x.target;T instanceof Node&&((w=y.current)!=null&&w.contains(T)||(q=v.current)!=null&&q.contains(T)||h())};return document.addEventListener("pointerdown",m,!0),document.addEventListener("mousedown",m,!0),document.addEventListener("click",m,!0),()=>{document.removeEventListener("pointerdown",m,!0),document.removeEventListener("mousedown",m,!0),document.removeEventListener("click",m,!0)}},[h,E]);const d=l.useMemo(()=>Zr(a.queries),[a.queries]),I=l.useMemo(()=>rr(a.queries),[a.queries]),D=et(d),R=l.useMemo(()=>rt(a.queries,p),[a.queries,p]),L=l.useMemo(()=>tt(R),[R]),k=l.useMemo(()=>tr(R,u==null?void 0:u.focus)||R[0],[R,u==null?void 0:u.focus]);return!a.enabled||!u?null:s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:y,type:"button","aria-label":"Open Semaphor Inspector",title:D,className:n?`${B} ${n}`:B,style:{...o.launcher,...St(e),...It(d.severity),...i},onClick:()=>{var x;const m=(x=I[0])==null?void 0:x.trace;u.openDevtools(m?{traceId:m.traceId,queryId:m.queryId,viewId:m.viewId}:void 0)},children:[s.jsx($r,{}),s.jsx("span",{style:o.launcherText,children:d.total}),d.issueCount>0?s.jsxs("span",{style:o.launcherIssueCount,children:[d.issueCount," issue",d.issueCount===1?"":"s"]}):null]}),u.open?s.jsxs("div",{ref:v,role:"dialog","aria-label":"Semaphor Inspector","aria-modal":"false",className:B,style:{...o.panel,...wt(t),...c?o.panelFullscreen:null},children:[s.jsxs("div",{style:o.panelHeader,children:[s.jsxs("div",{style:o.panelTitleBlock,children:[s.jsx("div",{style:o.panelTitle,children:"Semaphor Inspector"}),s.jsxs("div",{style:o.panelSubtitle,children:[d.total," queries · ",d.loading," loading ·"," ",d.failed," failed · ",d.warningCount," warnings"]})]}),s.jsxs("div",{style:o.panelActions,children:[s.jsx("button",{type:"button","aria-label":c?"Exit fullscreen Semaphor Inspector":"Enter fullscreen Semaphor Inspector",title:c?"Exit fullscreen Semaphor Inspector":"Enter fullscreen Semaphor Inspector",style:o.iconButton,onClick:()=>b(m=>!m),children:c?s.jsx(ue.Minimize2,{size:15}):s.jsx(ue.Maximize2,{size:15})}),s.jsx("button",{type:"button","aria-label":"Close Semaphor Inspector",style:o.iconButton,onClick:u.closeDevtools,children:s.jsx(Ye.X,{size:15})})]})]}),s.jsxs("label",{style:o.searchBox,children:[s.jsx(ue.Search,{size:14}),s.jsx("input",{"aria-label":"Search Semaphor traces",value:p,onChange:m=>f(m.currentTarget.value),placeholder:"Search traces",style:o.searchInput})]}),I.length?s.jsx(Wr,{issues:I,onSelect:m=>u.focusTrace({traceId:m.traceId,queryId:m.queryId,viewId:m.viewId})}):null,s.jsxs("div",{style:{...o.panelBody,...jt(t)},children:[s.jsx("div",{style:{...o.queryList,...qt()},"aria-label":"Registered queries",children:R.length?L.map(m=>s.jsxs("div",{style:o.queryGroup,children:[s.jsxs("div",{style:o.queryGroupHeader,children:[s.jsx("span",{children:m.title}),s.jsx("span",{style:o.queryGroupCount,children:m.traces.length})]}),m.traces.length?m.traces.map(x=>{var Y;const T=nr(x,k),w=ge(x),q=or(x),z=ar(x),G=it(x,w,z),J=G.join(" · "),A=sr(q),N=Xr(I,x);return s.jsxs("button",{type:"button",title:`${w} · ${q} · ${J}`,style:{...o.queryListItem,...T?o.queryListItemSelected:null},onClick:()=>u.focusTrace({traceId:x.traceId,queryId:x.queryId,viewId:x.viewId}),children:[s.jsxs("span",{style:o.queryListItemHeader,children:[s.jsx(Nr,{status:(Y=x.latestAttempt)==null?void 0:Y.status}),s.jsx("span",{style:o.queryListTitle,title:w,children:w}),s.jsx("span",{style:{...o.queryListKindChip,...ir(A)},children:q}),N>0?s.jsx("span",{style:o.queryListIssueBadge,children:N}):null]}),s.jsx("span",{className:`${B}-source`,style:o.queryListSource,title:J,children:G.map((X,Z)=>s.jsxs(l.Fragment,{children:[Z>0?s.jsx("span",{style:o.queryListSubtitleSep,children:" · "}):null,s.jsx("span",{children:X})]},`${X}:${Z}`))})]},Re(x))}):s.jsx("div",{style:o.queryGroupEmpty,children:"No input traces"})]},m.title)):s.jsx("div",{style:o.emptyState,children:"No matching traces"})}),s.jsx(Mr,{trace:k})]})]}):null]})}function Or({queryId:e,viewId:r,label:t,className:n,style:i}={}){var y,v;const a=ke(),u=l.useContext(Ee),p=l.useContext(Te);l.useEffect(()=>{ur()},[]);const f=r||(p==null?void 0:p.id),c=l.useMemo(()=>nt(a.queries,{queryId:e,viewId:f}),[a.queries,e,f]);if(!a.enabled||!u||!c)return null;const b=t||`Inspect ${ot(c,!!e)}`;return s.jsxs("button",{type:"button","aria-label":b,title:b,className:n?`${B} ${n}`:B,style:{...o.inspectButton,...Rt((y=c.latestAttempt)==null?void 0:y.status),...i},onClick:()=>u.openDevtools({traceId:c.traceId,queryId:c.queryId,viewId:c.viewId}),children:[s.jsx(ue.Eye,{size:13}),s.jsx("span",{style:o.inspectButtonText,children:((v=c.latestAttempt)==null?void 0:v.status)||"idle"})]})}function ke(){const e=l.useContext(Ce);return!e||!e.state.enabled?Xe:fe(e.state)}function Br({spec:e,queryKind:r,queryKey:t,intent:n,activeInputs:i,debug:a}){const u=l.useContext(Ce),p=l.useContext(Te),f=!!(u!=null&&u.state.enabled),c=u==null?void 0:u.dispatch,b=Kt(e),y=e.label,v=l.useMemo(()=>JSON.stringify(e),[e]),g=l.useMemo(()=>JSON.stringify(i||[]),[i]),h=l.useMemo(()=>JSON.stringify(n||null),[n]),E=l.useRef(e),d=l.useRef(v),I=l.useRef(n),D=l.useRef(h),R=l.useRef(i),L=l.useRef(g),k=Nt(a),m=JSON.stringify(k||[]),x=l.useRef(k),T=l.useRef(m);d.current!==v&&(d.current=v,E.current=e),D.current!==h&&(D.current=h,I.current=n),L.current!==g&&(L.current=g,R.current=i),T.current!==m&&(T.current=m,x.current=k);const w=E.current,q=I.current,z=R.current,G=x.current,J=l.useId(),A=l.useMemo(()=>b||`query_${yr(t)}`,[t,b]),N=(a==null?void 0:a.viewId)||(p==null?void 0:p.id),Y=(a==null?void 0:a.viewTitle)||(a==null?void 0:a.title)||(p==null?void 0:p.title),X=a==null?void 0:a.visualType,Z=a==null?void 0:a.sectionTitle,K=l.useMemo(()=>[N||"unscoped-view",A,J].join("::"),[A,J,N]),Be=l.useMemo(()=>({traceKey:K,spec:w,queryId:A,queryLabel:y,queryKind:r,builder:Ft(r),viewId:N,viewTitle:Y,visualType:X,sectionTitle:Z,sourceHints:G,intent:q,activeInputs:z,clientWarnings:b?[]:["Query spec is missing an explicit id; using an opaque internal id."]}),[A,r,b,y,w,z,q,G,Z,K,N,Y,X]);l.useEffect(()=>{if(!(!f||!c))return c({type:"register",descriptor:Be}),()=>{c({type:"unregister",traceKey:K})}},[Be,c,f,K]);const $=l.useCallback((C,H)=>{!f||!c||c({type:"event",traceKey:K,event:C,latestAttempt:H})},[c,f,K]),$e=l.useCallback(()=>{$({type:"query_started",queryId:A,at:le()},{status:"loading"})},[$,A]),Me=l.useCallback((C,H)=>{const ee=Ue(C),re=Gt(C),wr=Jt(C);$({type:"query_succeeded",queryId:A,requestId:ee,at:le(),rowCount:re,durationMs:H},{requestId:ee,status:"success",durationMs:H,rowCount:re,columnCount:wr,executionResult:Qe(C)})},[$,A]),se=l.useCallback((C,H)=>{const ee=Ue(C),re=C instanceof Error?C.message:String(C);$({type:"query_failed",queryId:A,requestId:ee,at:le(),errorMessage:re},{requestId:ee,status:"error",durationMs:H,errorMessage:re,executionResult:Qe(C)})},[$,A]),We=l.useCallback(C=>{$({type:"query_ignored_stale",queryId:A,at:le(),reason:C})},[$,A]),Ne=l.useCallback(C=>{se(C,0)},[se]),ye=f?u==null?void 0:u.state.entries[K]:void 0;return l.useMemo(()=>({enabled:f,queryId:A,trace:ye?ce(ye):void 0,start:$e,success:Me,failure:se,ignored:We,validationFailure:Ne}),[f,se,We,A,$e,Me,ye,Ne])}function $r(){return s.jsx("span",{style:o.logoMark,"aria-hidden":!0,children:s.jsxs("svg",{viewBox:"0 0 100 100",fill:"none",width:"16",height:"16",focusable:"false",children:[s.jsx("rect",{x:"20",y:"15",width:"60",height:"12",rx:"6",fill:"currentColor"}),s.jsx("rect",{x:"20",y:"35",width:"40",height:"12",rx:"6",fill:"currentColor"}),s.jsx("rect",{x:"40",y:"55",width:"40",height:"12",rx:"6",fill:"currentColor"}),s.jsx("rect",{x:"20",y:"75",width:"60",height:"12",rx:"6",fill:"currentColor"})]})})}function Mr({trace:e}){var L,k,m,x,T,w;if(!e)return s.jsx("div",{style:o.detailsPane,children:s.jsx("div",{style:o.emptyState,children:"No traces registered yet"})});const r=e.latestAttempt,t=r==null?void 0:r.executionResult,n=Q((L=t==null?void 0:t.validation)==null?void 0:L.warnings),i=Q((k=t==null?void 0:t.validation)==null?void 0:k.errors),a=dr((m=t==null?void 0:t.coverage)==null?void 0:m.missingObligations),u=Q((x=t==null?void 0:t.coverage)==null?void 0:x.warnings),p=t==null?void 0:t.compiledQuery,f=xt(t),c=((T=e.server)==null?void 0:T.compiledSql)||f.compiledSql,b=r!=null&&r.errorMessage?[r.errorMessage]:[],y=[...e.clientWarnings,...n,...i,...a,...u],v=e.inputsApplied.length>0,g=!!(p||c),h=lt(e),E=pt(r==null?void 0:r.rowCount),d=gt(r==null?void 0:r.durationMs),I=e.sourceRefs.length,D=or(e),R=sr(D);return s.jsxs("div",{style:o.detailsPane,children:[s.jsxs("div",{style:o.detailsHeader,children:[s.jsxs("div",{style:o.detailsHeaderTopRow,children:[s.jsx("span",{"aria-hidden":!0,style:{...o.detailsHeaderStatusDot,...lr(r==null?void 0:r.status)}}),s.jsx("span",{style:o.detailsTitle,children:ge(e)}),s.jsx("span",{style:{...o.detailsKindChip,...ir(R)},children:D})]}),s.jsxs("div",{style:o.metaStrip,children:[s.jsx("span",{style:o.metaStripItem,children:h}),s.jsx("span",{style:o.metaStripDot,children:"·"}),s.jsxs("span",{style:o.metaStripItem,children:[E," rows"]}),s.jsx("span",{style:o.metaStripDot,children:"·"}),s.jsx("span",{style:o.metaStripItem,children:d}),I>0?s.jsxs(s.Fragment,{children:[s.jsx("span",{style:o.metaStripDot,children:"·"}),s.jsx("span",{style:o.metaStripItem,children:I===1?"1 source":`${I} sources`})]}):null]})]}),b.length?s.jsx(Ke,{tone:"error",title:"Error",items:b}):null,y.length?s.jsx(Ke,{tone:"warning",title:"Warnings",items:y}):null,s.jsx(Kr,{trace:e}),s.jsx(zr,{trace:e}),(w=e.sourceHints)!=null&&w.length?s.jsx(Hr,{hints:e.sourceHints}):null,v?s.jsx(Ur,{inputs:e.inputsApplied}):null,g?s.jsx(te,{title:"Compiled Query",defaultOpen:!0,children:s.jsx(Gr,{compiledQuery:p,compiledSql:c})}):null,s.jsx(te,{title:"Lifecycle Events",children:e.recentEvents.length?s.jsx("div",{style:o.eventList,children:e.recentEvents.slice(-5).map((q,z)=>s.jsxs("div",{style:o.eventRow,children:[s.jsx("span",{style:o.eventType,children:yt(q)}),s.jsx("span",{style:o.eventMeta,children:ht(q)})]},`${q.type}:${q.at}:${z}`))}):s.jsx("div",{style:o.mutedText,children:"No attempts recorded"})}),s.jsx(te,{title:"Raw Trace",children:s.jsx("pre",{style:o.codeBlock,children:mt(e)})})]})}function Ke({tone:e,title:r,items:t}){const n=e==="error"?o.alertCardError:o.alertCardWarning;return s.jsxs("div",{style:{...o.alertCard,...n},children:[s.jsx("div",{style:o.alertCardTitle,children:r}),t.length>1?s.jsx("ul",{style:o.alertCardList,children:t.map((i,a)=>s.jsx("li",{children:i},`${e}-${a}`))}):s.jsx("div",{children:t[0]})]})}function Wr({issues:e,onSelect:r}){const t=e.slice(0,6),n=e.length-t.length;return s.jsxs("section",{style:o.issueSummary,"aria-label":"Semaphor trace issues",children:[s.jsxs("div",{style:o.issueSummaryHeader,children:[s.jsx("span",{children:"Issues"}),s.jsx("span",{style:o.issueSummaryCount,children:e.length})]}),s.jsxs("div",{style:o.issueSummaryList,children:[t.map((i,a)=>s.jsxs("button",{type:"button",title:`${i.title}: ${i.message}`,style:o.issueSummaryItem,onClick:()=>r(i.trace),children:[s.jsx("span",{style:{...o.issueSummaryBadge,...i.tone==="error"?o.issueSummaryBadgeError:o.issueSummaryBadgeWarning},children:i.tone==="error"?"Error":"Warning"}),s.jsxs("span",{style:o.issueSummaryText,children:[s.jsx("span",{style:o.issueSummaryTitle,children:i.title}),s.jsx("span",{style:o.issueSummaryMessage,children:i.message})]})]},`${i.trace.traceId}:${i.title}:${a}`)),n>0?s.jsxs("div",{style:o.issueSummaryMore,children:[n," more issue",n===1?"":"s"," in traces"]}):null]})]})}function Nr({status:e}){return s.jsx("span",{"aria-hidden":!0,style:{...o.statusDot,...lr(e)}})}function te({title:e,children:r,defaultOpen:t=!1}){const[n,i]=l.useState(t);return s.jsxs("details",{style:o.disclosure,open:n,onToggle:a=>i(a.currentTarget.open),children:[s.jsx("summary",{style:o.disclosureSummary,children:e}),s.jsx("div",{style:o.disclosureBody,children:r})]})}function Kr({trace:e}){var i;const r=(i=e.projectionFieldRefs)!=null&&i.length?e.projectionFieldRefs:e.fieldRefs,t=e.inputFieldRefs||[],n=dt(r);return s.jsxs("div",{style:o.recipe,children:[s.jsx(Fr,{sources:e.sourceRefs}),s.jsx(F,{title:"Measures",fields:n.measures}),s.jsx(F,{title:"Time fields",fields:n.timeFields}),s.jsx(F,{title:"Dimensions",fields:n.dimensions,emptyText:"No dimensions selected"}),s.jsx(F,{title:"Identifiers",fields:n.identifiers}),s.jsx(F,{title:"Other fields",fields:n.other}),s.jsx(F,{title:"Input bindings",fields:t})]})}function Fr({sources:e}){return e.length?s.jsxs("div",{style:o.recipeGroup,children:[s.jsxs("div",{style:o.recipeGroupHeader,children:[s.jsx("span",{style:o.recipeGroupTitle,children:"From"}),s.jsx("span",{style:o.recipeGroupCount,children:e.length})]}),s.jsx("div",{style:o.sourcePillRow,children:e.map((r,t)=>s.jsx(_r,{source:r},`${M(r)}:${t}`))})]}):null}function _r({source:e}){const r=M(e);return s.jsxs("span",{style:o.sourcePill,title:r,children:[s.jsx("span",{style:o.sourcePillLabel,children:r}),s.jsx("span",{style:o.sourcePillRole,children:e.kind})]})}function zr({trace:e}){return!e.sourceRefs.length&&!e.fieldRefs.length?null:s.jsx(te,{title:"Sources and field refs",children:s.jsxs("div",{style:o.traceLineage,children:[s.jsx(Pr,{sources:e.sourceRefs}),s.jsx(F,{title:"All field refs",fields:e.fieldRefs,emptyText:"No field refs captured"})]})})}function Hr({hints:e}){return s.jsx(te,{title:"Source hints",children:s.jsx("div",{style:o.recipeFieldList,children:e.map((r,t)=>{const n=ft(r),i=r.component||r.exportName||n||"Source hint",a=[r.exportName&&r.exportName!==i?r.exportName:void 0,n,r.note].filter(Boolean).join(" · ");return s.jsxs("div",{style:o.recipeFieldRow,title:a||i,children:[s.jsx("span",{style:o.recipeFieldName,children:i}),a?s.jsx("span",{style:o.recipeFieldMeta,children:a}):null]},`${i}:${n}:${t}`)})})})}function Pr({sources:e}){return s.jsxs("div",{style:o.recipeGroup,children:[s.jsxs("div",{style:o.recipeGroupHeader,children:[s.jsx("span",{style:o.recipeGroupTitle,children:"Sources"}),s.jsx("span",{style:o.recipeGroupCount,children:e.length})]}),e.length?s.jsx("div",{style:o.recipeFieldList,children:e.map((r,t)=>s.jsxs("div",{style:o.recipeFieldRow,title:M(r),children:[s.jsx("span",{style:o.recipeFieldName,children:M(r)}),s.jsx("span",{style:o.recipeFieldMeta,children:r.kind})]},`${M(r)}:${t}`))}):s.jsx("div",{style:o.recipeEmptyText,children:"No sources captured"})]})}function F({title:e,fields:r,emptyText:t}){return!r.length&&!t?null:s.jsxs("div",{style:o.recipeGroup,children:[s.jsxs("div",{style:o.recipeGroupHeader,children:[s.jsx("span",{style:o.recipeGroupTitle,children:e}),s.jsx("span",{style:o.recipeGroupCount,children:r.length})]}),r.length?s.jsx("div",{style:o.fieldChipList,children:r.map((n,i)=>s.jsx(Vr,{field:n,groupTitle:e},`${De(n)}:${i}`))}):s.jsx("div",{style:o.recipeEmptyText,children:t})]})}function Vr({field:e,groupTitle:r}){const t=ut(e),n=e.label||e.name,i=e.dataType&&e.dataType!=="unknown"?e.dataType:void 0,a=e.source?M(e.source):void 0,u=[t,i,a].filter(Boolean).join(" · "),p=Qr(e,r);return s.jsxs("div",{style:o.fieldChip,title:u,children:[s.jsx("span",{style:{...o.fieldGlyph,...p.style},children:p.text}),e.aggregate?s.jsx("span",{style:o.fieldAggBadge,children:e.aggregate}):null,s.jsx("span",{style:o.fieldChipName,children:n}),i?s.jsx("span",{style:o.fieldChipMeta,children:i}):null,i&&a?s.jsx("span",{style:o.fieldChipMetaDot,children:"·"}):null,a?s.jsx("span",{style:o.fieldChipMeta,children:a}):null]})}function Qr(e,r){const t=e.dataType,n=e.role;return!!e.aggregate||n==="measure"||r==="Measures"?{text:"Σ",style:{borderColor:"var(--sd-tone-metric-border)",background:"var(--sd-tone-metric-bg)",color:"var(--sd-tone-metric-fg)"}}:t==="date"||t==="datetime"||n==="date"||r==="Time fields"?{text:"◷",style:{borderColor:"var(--sd-tone-date-border)",background:"var(--sd-tone-date-bg)",color:"var(--sd-tone-date-fg)"}}:t==="number"?{text:"#",style:{borderColor:"var(--sd-tone-records-border)",background:"var(--sd-tone-records-bg)",color:"var(--sd-tone-records-fg)"}}:t==="boolean"?{text:"◐",style:{borderColor:"var(--sd-border)",background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)"}}:{text:"A",style:{borderColor:"var(--sd-tone-string-border)",background:"var(--sd-tone-string-bg)",color:"var(--sd-tone-string-fg)"}}}function Ur({inputs:e}){return s.jsxs("div",{style:o.inputsAppliedBlock,children:[s.jsxs("div",{style:o.inputsAppliedHeader,children:[s.jsx("span",{style:o.inputsAppliedTitle,children:"Active Inputs"}),s.jsx("span",{style:o.inputsAppliedCount,children:e.length})]}),s.jsx("div",{style:o.inputRecipeList,children:e.map(r=>{const t=ct(r);return s.jsxs("div",{style:o.inputRecipeRow,title:t.title,children:[s.jsxs("div",{style:o.inputRecipeHeader,children:[s.jsx("span",{style:o.inputRecipeId,title:r.inputId,children:r.inputId}),t.operator?s.jsx("span",{style:o.inputOperatorBadge,children:t.operator}):null,s.jsx("span",{style:o.inputValuePreview,title:t.value,children:t.value})]}),t.binding?s.jsx("div",{style:o.inputRecipeBinding,title:t.binding,children:t.binding}):null]},r.inputId)})})]})}function Gr({compiledQuery:e,compiledSql:r}){return(e==null?void 0:e.kind)==="sql"?s.jsxs("div",{style:o.compiledQuery,children:[s.jsx(Fe,{label:"SQL",value:e.sql}),e.pythonCode?s.jsx(ve,{label:"Python",value:e.pythonCode}):null,e.parameters?s.jsx(ve,{label:"Parameters",value:Ae(e.parameters)}):null]}):r?s.jsx(Fe,{label:"SQL",value:r}):s.jsx(ve,{label:"Compiled Query",value:Ae(e)})}function ve({label:e,value:r}){return s.jsxs("div",{style:o.codeBlockGroup,children:[s.jsx("div",{style:o.codeBlockLabel,children:e}),s.jsx("pre",{style:o.codeBlock,children:r})]})}function Fe({label:e,value:r}){return s.jsxs("div",{style:o.codeBlockGroup,children:[s.jsx("div",{style:o.codeBlockLabel,children:e}),s.jsx("pre",{style:o.codeBlock,children:Yr(r)})]})}const Jr=new Set(["SELECT","FROM","JOIN","LEFT","RIGHT","INNER","OUTER","CROSS","ON","USING","WHERE","AND","OR","GROUP","BY","HAVING","ORDER","ASC","DESC","LIMIT","OFFSET","AS","BETWEEN","IN","NOT","NULL","IS","CASE","WHEN","THEN","ELSE","END","DISTINCT","UNION","ALL","WITH"]);function Yr(e){return e.split(/(\s+|,|\(|\))/).map((t,n)=>{if(!t)return null;const i=t.toUpperCase();return Jr.has(i)?s.jsx("span",{style:o.sqlKeyword,children:t},n):t.startsWith("$")||t.startsWith(":")||t.startsWith("?")?s.jsx("span",{style:o.sqlBindParam,children:t},n):s.jsx("span",{children:t},n)})}function rr(e){return e.flatMap(r=>{var b,y,v,g;const t=r.latestAttempt,n=t==null?void 0:t.executionResult,i=Q((b=n==null?void 0:n.validation)==null?void 0:b.warnings),a=Q((y=n==null?void 0:n.validation)==null?void 0:y.errors),u=dr((v=n==null?void 0:n.coverage)==null?void 0:v.missingObligations),p=Q((g=n==null?void 0:n.coverage)==null?void 0:g.warnings),f=[],c=ge(r);(t==null?void 0:t.status)==="error"&&f.push({trace:r,tone:"error",title:c,message:t.errorMessage||"Query attempt failed."});for(const h of r.clientWarnings)f.push({trace:r,tone:"warning",title:c,message:h});for(const h of i)f.push({trace:r,tone:"warning",title:c,message:h});for(const h of a)f.push({trace:r,tone:"warning",title:c,message:h});for(const h of u)f.push({trace:r,tone:"warning",title:c,message:h});for(const h of p)f.push({trace:r,tone:"warning",title:c,message:h});return f})}function Xr(e,r){return e.filter(t=>nr(t.trace,r)).length}function Zr(e){const r=rr(e),t=e.filter(a=>{var u;return((u=a.latestAttempt)==null?void 0:u.status)==="error"}).length,n=e.filter(a=>{var u;return((u=a.latestAttempt)==null?void 0:u.status)==="loading"}).length,i=r.filter(a=>a.tone==="warning").length;return{total:e.length,failed:t,loading:n,warningCount:i,issueCount:r.length,severity:t?"error":i?"warning":n?"loading":"ok"}}function et(e){return[`${e.total} ${e.total===1?"trace":"traces"}`,`${e.loading} loading`,`${e.failed} failed`,`${e.warningCount} warning${e.warningCount===1?"":"s"}`].join(" · ")}function rt(e,r){const t=r.trim().toLowerCase();return t?e.filter(n=>[n.queryId,n.queryLabel,n.viewId,n.viewTitle,n.visualType,n.sectionTitle,n.builder,n.queryKind,ar(n)].filter(Boolean).join(" ").toLowerCase().includes(t)):e}function tt(e){const r=e.filter(i=>i.queryKind==="inputOptions"),t=new Set(r.map(Re));return[{title:"Views",traces:e.filter(i=>!t.has(Re(i)))},{title:"Inputs",traces:r}]}function tr(e,r){if(!(!(r!=null&&r.traceId)&&!(r!=null&&r.queryId)&&!(r!=null&&r.viewId)))return r.traceId?e.find(t=>t.traceId===r.traceId):e.find(t=>!(r.queryId&&t.queryId!==r.queryId||r.viewId&&t.viewId!==r.viewId))}function nt(e,r){if(r.queryId)return tr(e,r);if(!r.viewId)return;const t=e.filter(n=>n.viewId===r.viewId);return t.length===1?t[0]:void 0}function nr(e,r){return!!(e&&r&&e.traceId===r.traceId)}function Re(e){return e.traceId}function st(e){switch(e){case"metric":return"metric";case"records":return"records";case"matrix":return"matrix";case"analysis":return"analysis";case"inputOptions":return"inputs";case"sql":return"sql";default:return me(e)}}function sr(e){const r=e.trim().toLowerCase();return r==="metric"||r==="kpi"?"metric":r==="records"||r==="table"?"records":r==="matrix"||r==="pivot"?"matrix":r==="analysis"?"analysis":r==="inputs"||r==="input options"?"inputs":r==="sql"?"sql":"default"}function ir(e){switch(e){case"metric":return{borderColor:"var(--sd-tone-metric-border)",background:"var(--sd-tone-metric-bg)",color:"var(--sd-tone-metric-fg)"};case"records":return{borderColor:"var(--sd-tone-records-border)",background:"var(--sd-tone-records-bg)",color:"var(--sd-tone-records-fg)"};case"analysis":case"matrix":return{borderColor:"var(--sd-tone-analysis-border)",background:"var(--sd-tone-analysis-bg)",color:"var(--sd-tone-analysis-fg)"};case"inputs":case"sql":case"default":default:return{borderColor:"var(--sd-border)",background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)"}}}function ge(e){return e.viewTitle||e.queryLabel||e.viewId||e.queryId}function it(e,r,t){const n=[];return e.queryLabel&&e.queryLabel!==r&&n.push(e.queryLabel),e.queryId&&e.queryId!==r&&e.queryId!==e.queryLabel?n.push(e.queryId):e.viewId&&e.viewId!==r&&e.viewId!==e.queryLabel&&n.push(e.viewId),n.push(t),n}function or(e){return at(e.visualType)||st(e.queryKind)}function ot(e,r){return r?e.queryLabel||e.queryId:ge(e)}function at(e){if(e)return e.replace(/[_-]+/g," ").replace(/\b\w/g,r=>r.toUpperCase())}function ar(e){const r=e.sourceRefs.map(M);return r.length?r.length===1?r[0]:`${r[0]} + ${r.length-1} more`:"No source"}function dt(e){return e.reduce((r,t)=>(t.role==="measure"?r.measures.push(t):t.role==="date"?r.timeFields.push(t):t.role==="dimension"?r.dimensions.push(t):t.role==="id"?r.identifiers.push(t):r.other.push(t),r),{measures:[],timeFields:[],dimensions:[],identifiers:[],other:[]})}function lt(e){var r,t;if(e.queryKind==="records"&&((r=e.projectionFieldRefs)!=null&&r.length)&&e.projectionFieldRefs.every(n=>n.role==="measure")&&((t=e.latestAttempt)==null?void 0:t.rowCount)===1)return"KPI query";switch(e.queryKind){case"metric":return"KPI query";case"records":return"Records query";case"matrix":return"Matrix query";case"analysis":return"Analysis query";case"inputOptions":return"Input options query";case"sql":return"SQL query";default:return me(e.queryKind)}}function ut(e){return[e.aggregate,e.label||e.name].filter(Boolean).join(" ")}function ct(e){var u,p,f;const r=e.valuePreview||"redacted",t=((u=e.fieldRef)==null?void 0:u.label)||((p=e.fieldRef)==null?void 0:p.name),n=(f=e.fieldRef)!=null&&f.source?M(e.fieldRef.source):void 0,i=[t?`on ${t}`:void 0,n].filter(Boolean).join(" · "),a=[e.inputId,e.operator,r,i].filter(Boolean).join(" - ");return{operator:e.operator,value:r,binding:i,title:a}}function M(e){return e.kind==="semantic"?e.datasetName||e.datasetId||e.domainId:e.kind==="physical"?[e.schemaName,e.tableName].filter(Boolean).join(".")||e.tableName:e.connectionId?`SQL ${e.connectionId}`:"SQL source"}function ft(e){if(e.file)return e.line&&e.column?`${e.file}:${e.line}:${e.column}`:e.line?`${e.file}:${e.line}`:e.file}function pt(e){return typeof e=="number"?e.toLocaleString():"-"}function gt(e){return typeof e=="number"?`${Math.round(e)}ms`:"-"}function mt(e){return Ae(e)}function Ae(e){return JSON.stringify(e,null,2)??"undefined"}function yt(e){switch(e.type){case"query_started":return"Started";case"query_succeeded":return"Succeeded";case"query_failed":return"Failed";case"query_ignored_stale":return"Ignored stale";case"input_changed":return"Input changed";default:return bt(e)}}function ht(e){return[e.at,"durationMs"in e&&typeof e.durationMs=="number"?`${Math.round(e.durationMs)}ms`:void 0,"rowCount"in e&&typeof e.rowCount=="number"?`${e.rowCount} rows`:void 0,"reason"in e?e.reason:void 0,"errorMessage"in e?e.errorMessage:void 0].filter(Boolean).join(" - ")}function bt(e){throw new Error(`Unsupported Semaphor trace event: ${JSON.stringify(e)}`)}function dr(e){return Array.isArray(e)?e.filter(r=>typeof r=="string"):[]}function Q(e){return Array.isArray(e)?e.map(r=>vt(r)).filter(r=>!!r):[]}function vt(e){if(typeof e=="string")return e;if(!e||typeof e!="object"||Array.isArray(e))return;const r=e,t=typeof r.message=="string"?r.message:"",n=typeof r.code=="string"?r.code:"",i=typeof r.path=="string"?r.path:"";return t&&n?i?`${t} (${n}, ${i})`:`${t} (${n})`:t||n||void 0}function xt(e){const r=e==null?void 0:e.metadata,t=r&&typeof r=="object"&&!Array.isArray(r)&&"dataAppDebug"in r&&r.dataAppDebug&&typeof r.dataAppDebug=="object"&&!Array.isArray(r.dataAppDebug)?r.dataAppDebug:void 0;return{compiledSql:typeof(t==null?void 0:t.compiledSql)=="string"?t.compiledSql:void 0,queryHash:typeof(t==null?void 0:t.queryHash)=="string"?t.queryHash:void 0}}function St(e){return e==="relative"?{position:"relative",top:"auto",right:"auto",bottom:"auto",left:"auto"}:{top:e.startsWith("top")?20:"auto",right:e.endsWith("right")?20:"auto",bottom:e.startsWith("bottom")?20:"auto",left:e.endsWith("left")?20:"auto"}}function It(e){return e==="error"?{borderColor:"var(--sd-error-border)",background:"var(--sd-error-bg)",color:"var(--sd-error-fg)"}:e==="warning"?{borderColor:"var(--sd-warning-border)",background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)"}:e==="loading"?{borderColor:"var(--sd-loading-border)",background:"var(--sd-loading-bg)",color:"var(--sd-loading-fg)"}:{borderColor:"var(--sd-success-border)",background:"var(--sd-success-bg)",color:"var(--sd-success-fg)"}}function wt(e){return e==="right"?{top:16,right:16,bottom:16,left:"auto",width:"min(720px, calc(100vw - 32px))",height:"auto",borderRadius:6}:{top:"auto",right:16,bottom:16,left:16,width:"auto",height:"min(420px, 45vh)",borderRadius:6}}function jt(e){return e==="right"?{gridTemplateColumns:"minmax(210px, 280px) minmax(0, 1fr)"}:{gridTemplateColumns:"minmax(260px, 340px) minmax(0, 1fr)"}}function qt(e){return{borderRight:"1px solid var(--sd-border)",borderBottom:0}}function lr(e){return e==="error"?{background:"var(--sd-error-dot)"}:e==="success"?{background:"var(--sd-success-dot)"}:e==="loading"?{background:"var(--sd-loading-dot)"}:{background:"var(--sd-idle-dot)"}}function Rt(e){return e==="error"?{borderColor:"var(--sd-error-border)",color:"var(--sd-error-fg)"}:e==="success"?{borderColor:"var(--sd-success-border)",color:"var(--sd-success-fg)"}:e==="loading"?{borderColor:"var(--sd-loading-border)",color:"var(--sd-loading-fg)"}:{borderColor:"var(--sd-border)",color:"var(--sd-fg-muted)"}}const _e="semaphor-devtools-stylesheet",B="semaphor-devtools",At=`
2
- .${B} {
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("../data-app-sdk-adapters/index.cjs"),i=require("react/jsx-runtime"),c=require("react"),or=require("../chunks/source-identity-uMaUe036.js");require("../chunks/analyze-result-contract-Zgg-Bbpj.js");const se=require("../chunks/search-DNCejM7Z.js"),Oe=require("../chunks/x-B6ghREd2.js"),Lr=require("../chunks/validators-CPtkrola.js");function de(e,r,t={}){return{...t,name:e,role:r}}function Or(e){return e}function Br(e){return e}const $r={source:{semantic(e){return{...e,kind:"semantic"}},sql(e){return{...e,kind:"sql"}}},field:{measure(e,r){return de(e,"measure",r)},dimension(e,r){return de(e,"dimension",r)},date(e,r){return de(e,"date",r)},id(e,r){return de(e,"id",r)}},filter(e){return{...e,kind:"filter"}},bindInput(e,r){return{toAnalyticsInput(){const[t]=I.toSemaphorInputSnapshots([e]),n=I.toSemaphorInputBinding({...r,inputId:r.inputId||t.inputId});return{...t,inputId:n.inputId,...n.kind?{kind:n.kind}:{},...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{},...n.relationshipHint?{relationshipHint:n.relationshipHint}:{}}}}},control(e){return{...e,kind:"control"}},sqlParam(e){return{...e,kind:"control",role:"sqlParam"}},derivedField(e){return{...e,kind:"derived_field",expressionLanguage:e.expressionLanguage||"semaphor_sql_template"}},metric(e){return{...e,queryKind:"metric"}},analysis(e){return{...e,queryKind:"analysis"}},records(e){return{...e,queryKind:"records"}},inputOptions(e){return{...e,queryKind:"inputOptions"}},sql(e){return{...e,queryKind:"sql"}},matrix(e){return{...e,queryKind:"matrix"}}},xe=10,Se=100,Kr=25,Wr=500,ar={enabled:!1,queries:[],issues:[],getQuery:()=>{},getQueries:()=>[]},Be=c.createContext(null),$e=c.createContext(null),Ke=c.createContext(void 0),F=[];function _r({debug:e,children:r}){const t=c.useMemo(()=>Ut(e),[e]),[n,s]=c.useReducer(Wt,t,xr),o=c.useRef(n),u=c.useId(),[p,d]=c.useState({open:!1});o.current=n,c.useEffect(()=>{s({type:"config",config:t})},[t]),c.useEffect(()=>{if(!n.enabled||!n.exposeWindowBridge||typeof window>"u")return;const b=Ht(()=>o.current);return Mr({ownerId:u,bridge:b}),()=>{Nr(u)}},[u,n.enabled,n.exposeWindowBridge]);const f=c.useMemo(()=>({state:n,dispatch:s}),[n]),m=c.useCallback(b=>{d({open:!0,focus:b})},[]),v=c.useCallback(()=>{d(b=>({...b,open:!1}))},[]),x=c.useCallback(b=>{d({open:!0,focus:b})},[]),g=c.useMemo(()=>({open:p.open,focus:p.focus,openDevtools:m,closeDevtools:v,focusTrace:x}),[v,x,m,p.focus,p.open]);return i.jsx(Be.Provider,{value:f,children:i.jsx($e.Provider,{value:g,children:r})})}function Mr(e){const r=F.findIndex(t=>t.ownerId===e.ownerId);r>=0&&F.splice(r,1),F.push(e),dr()}function Nr(e){const r=F.findIndex(t=>t.ownerId===e);r>=0&&F.splice(r,1),dr()}function dr(){if(typeof window>"u")return;const e=F[F.length-1];e?window.__SEMAPHOR_DEVTOOLS__=e.bridge:delete window.__SEMAPHOR_DEVTOOLS__}function Fr({id:e,title:r,children:t}){const n=c.useMemo(()=>({id:e,title:r}),[e,r]);return i.jsx(Ke.Provider,{value:n,children:t})}function lr({buttonPosition:e="bottom-right",initialIsOpen:r=!1,panelPosition:t="right",className:n,style:s}={}){const o=We(),u=c.useContext($e),[p,d]=c.useState(""),[f,m]=c.useState(!1),v=c.useRef(null),x=c.useRef(null),g=u==null?void 0:u.openDevtools,b=u==null?void 0:u.closeDevtools,k=(u==null?void 0:u.open)===!0;c.useEffect(()=>{br()},[]),c.useEffect(()=>{r&&o.enabled&&(g==null||g())},[r,o.enabled,g]),c.useEffect(()=>{if(!k||!b)return;const h=S=>{var w,j;const T=S.target;T instanceof Node&&((w=v.current)!=null&&w.contains(T)||(j=x.current)!=null&&j.contains(T)||b())};return document.addEventListener("pointerdown",h,!0),document.addEventListener("mousedown",h,!0),document.addEventListener("click",h,!0),()=>{document.removeEventListener("pointerdown",h,!0),document.removeEventListener("mousedown",h,!0),document.removeEventListener("click",h,!0)}},[b,k]);const l=c.useMemo(()=>lt(o.queries),[o.queries]),y=c.useMemo(()=>_e(o.queries),[o.queries]),L=ut(l),A=c.useMemo(()=>ct(o.queries,p),[o.queries,p]),O=c.useMemo(()=>ft(A),[A]),R=c.useMemo(()=>ur(A,u==null?void 0:u.focus)||A[0],[A,u==null?void 0:u.focus]);return!o.enabled||!u?null:i.jsxs(i.Fragment,{children:[i.jsxs("button",{ref:v,type:"button","aria-label":"Open Semaphor Inspector",title:L,className:n?`${$} ${n}`:$,style:{...a.launcher,...Rt(e),...Dt(l.severity),...s},onClick:()=>{var S;const h=(S=y[0])==null?void 0:S.trace;u.openDevtools(h?{traceId:h.traceId,queryId:h.queryId,viewId:h.viewId}:void 0)},children:[i.jsx(Pr,{}),i.jsx("span",{style:a.launcherText,children:l.total}),l.issueCount>0?i.jsxs("span",{style:a.launcherIssueCount,children:[l.issueCount," issue",l.issueCount===1?"":"s"]}):null]}),u.open?i.jsxs("div",{ref:x,role:"dialog","aria-label":"Semaphor Inspector","aria-modal":"false",className:$,style:{...a.panel,...Lt(t),...f?a.panelFullscreen:null},children:[i.jsxs("div",{style:a.panelHeader,children:[i.jsxs("div",{style:a.panelTitleBlock,children:[i.jsx("div",{style:a.panelTitle,children:"Semaphor Inspector"}),i.jsxs("div",{style:a.panelSubtitle,children:[l.total," queries · ",l.loading," loading ·"," ",l.failed," failed · ",l.errorCount," errors ·"," ",l.warningCount," warnings"]})]}),i.jsxs("div",{style:a.panelActions,children:[i.jsx("button",{type:"button","aria-label":f?"Exit fullscreen Semaphor Inspector":"Enter fullscreen Semaphor Inspector",title:f?"Exit fullscreen Semaphor Inspector":"Enter fullscreen Semaphor Inspector",style:a.iconButton,onClick:()=>m(h=>!h),children:f?i.jsx(se.Minimize2,{size:15}):i.jsx(se.Maximize2,{size:15})}),i.jsx("button",{type:"button","aria-label":"Close Semaphor Inspector",style:a.iconButton,onClick:u.closeDevtools,children:i.jsx(Oe.X,{size:15})})]})]}),i.jsxs("label",{style:a.searchBox,children:[i.jsx(se.Search,{size:14}),i.jsx("input",{"aria-label":"Search Semaphor traces",value:p,onChange:h=>d(h.currentTarget.value),placeholder:"Search traces",style:a.searchInput})]}),y.length?i.jsx(Qr,{issues:y,onSelect:h=>u.focusTrace({traceId:h.traceId,queryId:h.queryId,viewId:h.viewId})}):null,i.jsxs("div",{style:{...a.panelBody,...Ot(t)},children:[i.jsx("div",{style:{...a.queryList,...Bt()},"aria-label":"Registered queries",children:A.length?O.map(h=>i.jsxs("div",{style:a.queryGroup,children:[i.jsxs("div",{style:a.queryGroupHeader,children:[i.jsx("span",{children:h.title}),i.jsx("span",{style:a.queryGroupCount,children:h.traces.length})]}),h.traces.length?h.traces.map(S=>{var X;const T=cr(S,R),w=ye(S),j=gr(S),z=mr(S),J=mt(S,w,z),Y=J.join(" · "),C=fr(j),_=dt(y,S);return i.jsxs("button",{type:"button",title:`${w} · ${j} · ${Y}`,style:{...a.queryListItem,...T?a.queryListItemSelected:null},onClick:()=>u.focusTrace({traceId:S.traceId,queryId:S.queryId,viewId:S.viewId}),children:[i.jsxs("span",{style:a.queryListItemHeader,children:[i.jsx(Ur,{status:(X=S.latestAttempt)==null?void 0:X.status}),i.jsx("span",{style:a.queryListTitle,title:w,children:w}),i.jsx("span",{style:{...a.queryListKindChip,...pr(C)},children:j}),_>0?i.jsx("span",{style:a.queryListIssueBadge,children:_}):null]}),i.jsx("span",{className:`${$}-source`,style:a.queryListSource,title:Y,children:J.map((Z,ee)=>i.jsxs(c.Fragment,{children:[ee>0?i.jsx("span",{style:a.queryListSubtitleSep,children:" · "}):null,i.jsx("span",{children:Z})]},`${Z}:${ee}`))})]},Te(S))}):i.jsx("div",{style:a.queryGroupEmpty,children:"No input traces"})]},h.title)):i.jsx("div",{style:a.emptyState,children:"No matching traces"})}),i.jsx(Vr,{trace:R})]})]}):null]})}function zr({queryId:e,viewId:r,label:t,className:n,style:s}={}){var v,x;const o=We(),u=c.useContext($e),p=c.useContext(Ke);c.useEffect(()=>{br()},[]);const d=r||(p==null?void 0:p.id),f=c.useMemo(()=>pt(o.queries,{queryId:e,viewId:d}),[o.queries,e,d]);if(!o.enabled||!u||!f)return null;const m=t||`Inspect ${yt(f,!!e)}`;return i.jsxs("button",{type:"button","aria-label":m,title:m,className:n?`${$} ${n}`:$,style:{...a.inspectButton,...$t((v=f.latestAttempt)==null?void 0:v.status),...s},onClick:()=>u.openDevtools({traceId:f.traceId,queryId:f.queryId,viewId:f.viewId}),children:[i.jsx(se.Eye,{size:13}),i.jsx("span",{style:a.inspectButtonText,children:((x=f.latestAttempt)==null?void 0:x.status)||"idle"})]})}function We(){const e=c.useContext(Be);return!e||!e.state.enabled?ar:ne(e.state)}function Hr({spec:e,queryKind:r,queryKey:t,intent:n,activeInputs:s,debug:o}){const u=c.useContext(Be),p=c.useContext(Ke),d=!!(u!=null&&u.state.enabled),f=u==null?void 0:u.dispatch,m=Jt(e),v=e.label,x=c.useMemo(()=>JSON.stringify(e),[e]),g=c.useMemo(()=>JSON.stringify(s||[]),[s]),b=c.useMemo(()=>JSON.stringify(n||null),[n]),k=c.useRef(e),l=c.useRef(x),y=c.useRef(n),L=c.useRef(b),A=c.useRef(s),O=c.useRef(g),R=Gt(o),h=JSON.stringify(R||[]),S=c.useRef(R),T=c.useRef(h);l.current!==x&&(l.current=x,k.current=e),L.current!==b&&(L.current=b,y.current=n),O.current!==g&&(O.current=g,A.current=s),T.current!==h&&(T.current=h,S.current=R);const w=k.current,j=y.current,z=A.current,J=S.current,Y=c.useId(),C=c.useMemo(()=>m||`query_${qr(t)}`,[t,m]),_=(o==null?void 0:o.viewId)||(p==null?void 0:p.id),X=(o==null?void 0:o.viewTitle)||(o==null?void 0:o.title)||(p==null?void 0:p.title),Z=o==null?void 0:o.visualType,ee=o==null?void 0:o.sectionTitle,M=c.useMemo(()=>[_||"unscoped-view",C,Y].join("::"),[C,Y,_]),He=c.useMemo(()=>({traceKey:M,spec:w,queryId:C,queryLabel:v,queryKind:r,builder:Yt(r),viewId:_,viewTitle:X,visualType:Z,sectionTitle:ee,sourceHints:J,intent:j,activeInputs:z,clientWarnings:m?[]:["Query spec is missing an explicit id; using an opaque internal id."]}),[C,r,m,v,w,z,j,J,ee,M,_,X,Z]);c.useEffect(()=>{if(!(!d||!f))return f({type:"register",descriptor:He}),()=>{f({type:"unregister",traceKey:M})}},[He,f,d,M]);const K=c.useCallback((E,H)=>{!d||!f||f({type:"event",traceKey:M,event:E,latestAttempt:H})},[f,d,M]),Pe=c.useCallback(()=>{K({type:"query_started",queryId:C,at:fe()},{status:"loading"})},[K,C]),Ve=c.useCallback((E,H)=>{const re=nr(E),te=on(E),Dr=an(E);K({type:"query_succeeded",queryId:C,requestId:re,at:fe(),rowCount:te,durationMs:H},{requestId:re,status:"success",durationMs:H,rowCount:te,columnCount:Dr,executionResult:tr(E)})},[K,C]),ae=c.useCallback((E,H)=>{const re=nr(E),te=E instanceof Error?E.message:String(E);K({type:"query_failed",queryId:C,requestId:re,at:fe(),errorMessage:te},{requestId:re,status:"error",durationMs:H,errorMessage:te,executionResult:tr(E)})},[K,C]),Qe=c.useCallback(E=>{K({type:"query_ignored_stale",queryId:C,at:fe(),reason:E})},[K,C]),Ue=c.useCallback(E=>{ae(E,0)},[ae]),be=d?u==null?void 0:u.state.entries[M]:void 0;return c.useMemo(()=>({enabled:d,queryId:C,trace:be?pe(be):void 0,start:Pe,success:Ve,failure:ae,ignored:Qe,validationFailure:Ue}),[d,ae,Qe,C,Pe,Ve,be,Ue])}function Pr(){return i.jsx("span",{style:a.logoMark,"aria-hidden":!0,children:i.jsxs("svg",{viewBox:"0 0 100 100",fill:"none",width:"16",height:"16",focusable:"false",children:[i.jsx("rect",{x:"20",y:"15",width:"60",height:"12",rx:"6",fill:"currentColor"}),i.jsx("rect",{x:"20",y:"35",width:"40",height:"12",rx:"6",fill:"currentColor"}),i.jsx("rect",{x:"40",y:"55",width:"40",height:"12",rx:"6",fill:"currentColor"}),i.jsx("rect",{x:"20",y:"75",width:"60",height:"12",rx:"6",fill:"currentColor"})]})})}function Vr({trace:e}){var O,R,h,S,T,w;if(!e)return i.jsx("div",{style:a.detailsPane,children:i.jsx("div",{style:a.emptyState,children:"No traces registered yet"})});const r=e.latestAttempt,t=r==null?void 0:r.executionResult,n=we((O=t==null?void 0:t.validation)==null?void 0:O.warnings),s=we((R=t==null?void 0:t.validation)==null?void 0:R.errors),o=yr((h=t==null?void 0:t.coverage)==null?void 0:h.missingObligations),u=we((S=t==null?void 0:t.coverage)==null?void 0:S.warnings),p=t==null?void 0:t.compiledQuery,d=Tt(t),f=((T=e.server)==null?void 0:T.compiledSql)||d.compiledSql,m=[...r!=null&&r.errorMessage?[r.errorMessage]:[],...s],v=[...e.clientWarnings,...n,...o,...u],x=e.inputsApplied.length>0,g=!!(p||f),b=bt(e),k=wt(r==null?void 0:r.rowCount),l=qt(r==null?void 0:r.durationMs),y=e.sourceRefs.length,L=gr(e),A=fr(L);return i.jsxs("div",{style:a.detailsPane,children:[i.jsxs("div",{style:a.detailsHeader,children:[i.jsxs("div",{style:a.detailsHeaderTopRow,children:[i.jsx("span",{"aria-hidden":!0,style:{...a.detailsHeaderStatusDot,...vr(r==null?void 0:r.status)}}),i.jsx("span",{style:a.detailsTitle,children:ye(e)}),i.jsx("span",{style:{...a.detailsKindChip,...pr(A)},children:L})]}),i.jsxs("div",{style:a.metaStrip,children:[i.jsx("span",{style:a.metaStripItem,children:b}),i.jsx("span",{style:a.metaStripDot,children:"·"}),i.jsxs("span",{style:a.metaStripItem,children:[k," rows"]}),i.jsx("span",{style:a.metaStripDot,children:"·"}),i.jsx("span",{style:a.metaStripItem,children:l}),y>0?i.jsxs(i.Fragment,{children:[i.jsx("span",{style:a.metaStripDot,children:"·"}),i.jsx("span",{style:a.metaStripItem,children:y===1?"1 source":`${y} sources`})]}):null]})]}),m.length?i.jsx(Ge,{tone:"error",title:"Error",items:m}):null,v.length?i.jsx(Ge,{tone:"warning",title:"Warnings",items:v}):null,i.jsx(Gr,{trace:e}),i.jsx(Xr,{trace:e}),(w=e.sourceHints)!=null&&w.length?i.jsx(Zr,{hints:e.sourceHints}):null,x?i.jsx(nt,{inputs:e.inputsApplied}):null,g?i.jsx(ie,{title:"Compiled Query",defaultOpen:!0,children:i.jsx(st,{compiledQuery:p,compiledSql:f})}):null,i.jsx(ie,{title:"Lifecycle Events",children:e.recentEvents.length?i.jsx("div",{style:a.eventList,children:e.recentEvents.slice(-5).map((j,z)=>i.jsxs("div",{style:a.eventRow,children:[i.jsx("span",{style:a.eventType,children:At(j)}),i.jsx("span",{style:a.eventMeta,children:Ct(j)})]},`${j.type}:${j.at}:${z}`))}):i.jsx("div",{style:a.mutedText,children:"No attempts recorded"})}),i.jsx(ie,{title:"Raw Trace",children:i.jsx("pre",{style:a.codeBlock,children:jt(e)})})]})}function Ge({tone:e,title:r,items:t}){const n=e==="error"?a.alertCardError:a.alertCardWarning;return i.jsxs("div",{style:{...a.alertCard,...n},children:[i.jsx("div",{style:a.alertCardTitle,children:r}),t.length>1?i.jsx("ul",{style:a.alertCardList,children:t.map((s,o)=>i.jsx("li",{children:s},`${e}-${o}`))}):i.jsx("div",{children:t[0]})]})}function Qr({issues:e,onSelect:r}){const[t,n]=c.useState(!1),s=e.slice(0,6),o=e.length-s.length,u=e.filter(f=>f.tone==="error").length,p=e.length-u,d=[u?`${u} error${u===1?"":"s"}`:"",p?`${p} warning${p===1?"":"s"}`:""].filter(Boolean);return i.jsxs("section",{style:a.issueSummary,"aria-label":"Semaphor trace issues",children:[i.jsxs("button",{type:"button","aria-expanded":t,style:a.issueSummaryToggle,onClick:()=>n(f=>!f),children:[i.jsxs("span",{style:a.issueSummaryHeaderLabel,children:[t?i.jsx(Oe.ChevronDown,{size:13}):i.jsx(se.ChevronRight,{size:13}),i.jsx("span",{children:"Issues"})]}),i.jsx("span",{style:a.issueSummaryCount,children:e.length})]}),t?i.jsxs("div",{style:a.issueSummaryList,children:[s.map((f,m)=>i.jsxs("button",{type:"button",title:`${f.title}: ${f.message}`,style:a.issueSummaryItem,onClick:()=>r(f.trace),children:[i.jsx("span",{style:{...a.issueSummaryBadge,...f.tone==="error"?a.issueSummaryBadgeError:a.issueSummaryBadgeWarning},children:f.tone==="error"?"Error":"Warning"}),i.jsxs("span",{style:a.issueSummaryText,children:[i.jsx("span",{style:a.issueSummaryTitle,children:f.title}),i.jsx("span",{style:a.issueSummaryMessage,children:f.message})]})]},`${f.trace.traceId}:${f.title}:${m}`)),o>0?i.jsxs("div",{style:a.issueSummaryMore,children:[o," more issue",o===1?"":"s"," in traces"]}):null]}):i.jsxs("div",{style:a.issueSummaryCollapsed,children:[d.join(" · ")," across traces"]})]})}function Ur({status:e}){return i.jsx("span",{"aria-hidden":!0,style:{...a.statusDot,...vr(e)}})}function ie({title:e,children:r,defaultOpen:t=!1}){const[n,s]=c.useState(t);return i.jsxs("details",{style:a.disclosure,open:n,onToggle:o=>s(o.currentTarget.open),children:[i.jsx("summary",{style:a.disclosureSummary,children:e}),i.jsx("div",{style:a.disclosureBody,children:r})]})}function Gr({trace:e}){var s;const r=(s=e.projectionFieldRefs)!=null&&s.length?e.projectionFieldRefs:e.fieldRefs,t=e.inputFieldRefs||[],n=vt(r);return i.jsxs("div",{style:a.recipe,children:[i.jsx(Jr,{sources:e.sourceRefs}),i.jsx(N,{title:"Measures",fields:n.measures}),i.jsx(N,{title:"Time fields",fields:n.timeFields}),i.jsx(N,{title:"Dimensions",fields:n.dimensions,emptyText:"No dimensions selected"}),i.jsx(N,{title:"Identifiers",fields:n.identifiers}),i.jsx(N,{title:"Other fields",fields:n.other}),i.jsx(N,{title:"Input bindings",fields:t})]})}function Jr({sources:e}){return e.length?i.jsxs("div",{style:a.recipeGroup,children:[i.jsxs("div",{style:a.recipeGroupHeader,children:[i.jsx("span",{style:a.recipeGroupTitle,children:"From"}),i.jsx("span",{style:a.recipeGroupCount,children:e.length})]}),i.jsx("div",{style:a.sourcePillRow,children:e.map((r,t)=>i.jsx(Yr,{source:r},`${W(r)}:${t}`))})]}):null}function Yr({source:e}){const r=W(e);return i.jsxs("span",{style:a.sourcePill,title:r,children:[i.jsx("span",{style:a.sourcePillLabel,children:r}),i.jsx("span",{style:a.sourcePillRole,children:e.kind})]})}function Xr({trace:e}){return!e.sourceRefs.length&&!e.fieldRefs.length?null:i.jsx(ie,{title:"Sources and field refs",children:i.jsxs("div",{style:a.traceLineage,children:[i.jsx(et,{sources:e.sourceRefs}),i.jsx(N,{title:"All field refs",fields:e.fieldRefs,emptyText:"No field refs captured"})]})})}function Zr({hints:e}){return i.jsx(ie,{title:"Source hints",children:i.jsx("div",{style:a.recipeFieldList,children:e.map((r,t)=>{const n=It(r),s=r.component||r.exportName||n||"Source hint",o=[r.exportName&&r.exportName!==s?r.exportName:void 0,n,r.note].filter(Boolean).join(" · ");return i.jsxs("div",{style:a.recipeFieldRow,title:o||s,children:[i.jsx("span",{style:a.recipeFieldName,children:s}),o?i.jsx("span",{style:a.recipeFieldMeta,children:o}):null]},`${s}:${n}:${t}`)})})})}function et({sources:e}){return i.jsxs("div",{style:a.recipeGroup,children:[i.jsxs("div",{style:a.recipeGroupHeader,children:[i.jsx("span",{style:a.recipeGroupTitle,children:"Sources"}),i.jsx("span",{style:a.recipeGroupCount,children:e.length})]}),e.length?i.jsx("div",{style:a.recipeFieldList,children:e.map((r,t)=>i.jsxs("div",{style:a.recipeFieldRow,title:W(r),children:[i.jsx("span",{style:a.recipeFieldName,children:W(r)}),i.jsx("span",{style:a.recipeFieldMeta,children:r.kind})]},`${W(r)}:${t}`))}):i.jsx("div",{style:a.recipeEmptyText,children:"No sources captured"})]})}function N({title:e,fields:r,emptyText:t}){return!r.length&&!t?null:i.jsxs("div",{style:a.recipeGroup,children:[i.jsxs("div",{style:a.recipeGroupHeader,children:[i.jsx("span",{style:a.recipeGroupTitle,children:e}),i.jsx("span",{style:a.recipeGroupCount,children:r.length})]}),r.length?i.jsx("div",{style:a.fieldChipList,children:r.map((n,s)=>i.jsx(rt,{field:n,groupTitle:e},`${Me(n)}:${s}`))}):i.jsx("div",{style:a.recipeEmptyText,children:t})]})}function rt({field:e,groupTitle:r}){const t=xt(e),n=e.label||e.name,s=e.dataType&&e.dataType!=="unknown"?e.dataType:void 0,o=e.source?W(e.source):void 0,u=[t,s,o].filter(Boolean).join(" · "),p=tt(e,r);return i.jsxs("div",{style:a.fieldChip,title:u,children:[i.jsx("span",{style:{...a.fieldGlyph,...p.style},children:p.text}),e.aggregate?i.jsx("span",{style:a.fieldAggBadge,children:e.aggregate}):null,i.jsx("span",{style:a.fieldChipName,children:n}),s?i.jsx("span",{style:a.fieldChipMeta,children:s}):null,s&&o?i.jsx("span",{style:a.fieldChipMetaDot,children:"·"}):null,o?i.jsx("span",{style:a.fieldChipMeta,children:o}):null]})}function tt(e,r){const t=e.dataType,n=e.role;return!!e.aggregate||n==="measure"||r==="Measures"?{text:"Σ",style:{borderColor:"var(--sd-tone-metric-border)",background:"var(--sd-tone-metric-bg)",color:"var(--sd-tone-metric-fg)"}}:t==="date"||t==="datetime"||n==="date"||r==="Time fields"?{text:"◷",style:{borderColor:"var(--sd-tone-date-border)",background:"var(--sd-tone-date-bg)",color:"var(--sd-tone-date-fg)"}}:t==="number"?{text:"#",style:{borderColor:"var(--sd-tone-records-border)",background:"var(--sd-tone-records-bg)",color:"var(--sd-tone-records-fg)"}}:t==="boolean"?{text:"◐",style:{borderColor:"var(--sd-border)",background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)"}}:{text:"A",style:{borderColor:"var(--sd-tone-string-border)",background:"var(--sd-tone-string-bg)",color:"var(--sd-tone-string-fg)"}}}function nt({inputs:e}){return i.jsxs("div",{style:a.inputsAppliedBlock,children:[i.jsxs("div",{style:a.inputsAppliedHeader,children:[i.jsx("span",{style:a.inputsAppliedTitle,children:"Active Inputs"}),i.jsx("span",{style:a.inputsAppliedCount,children:e.length})]}),i.jsx("div",{style:a.inputRecipeList,children:e.map(r=>{const t=St(r);return i.jsxs("div",{style:a.inputRecipeRow,title:t.title,children:[i.jsxs("div",{style:a.inputRecipeHeader,children:[i.jsx("span",{style:a.inputRecipeId,title:r.inputId,children:r.inputId}),t.operator?i.jsx("span",{style:a.inputOperatorBadge,children:t.operator}):null,i.jsx("span",{style:a.inputValuePreview,title:t.value,children:t.value})]}),t.binding?i.jsx("div",{style:a.inputRecipeBinding,title:t.binding,children:t.binding}):null]},r.inputId)})})]})}function st({compiledQuery:e,compiledSql:r}){return(e==null?void 0:e.kind)==="sql"?i.jsxs("div",{style:a.compiledQuery,children:[i.jsx(Je,{label:"SQL",value:e.sql}),e.pythonCode?i.jsx(Ie,{label:"Python",value:e.pythonCode}):null,e.parameters?i.jsx(Ie,{label:"Parameters",value:Re(e.parameters)}):null]}):r?i.jsx(Je,{label:"SQL",value:r}):i.jsx(Ie,{label:"Compiled Query",value:Re(e)})}function Ie({label:e,value:r}){return i.jsxs("div",{style:a.codeBlockGroup,children:[i.jsx("div",{style:a.codeBlockLabel,children:e}),i.jsx("pre",{style:a.codeBlock,children:r})]})}function Je({label:e,value:r}){return i.jsxs("div",{style:a.codeBlockGroup,children:[i.jsx("div",{style:a.codeBlockLabel,children:e}),i.jsx("pre",{style:a.codeBlock,children:ot(r)})]})}const it=new Set(["SELECT","FROM","JOIN","LEFT","RIGHT","INNER","OUTER","CROSS","ON","USING","WHERE","AND","OR","GROUP","BY","HAVING","ORDER","ASC","DESC","LIMIT","OFFSET","AS","BETWEEN","IN","NOT","NULL","IS","CASE","WHEN","THEN","ELSE","END","DISTINCT","UNION","ALL","WITH"]);function ot(e){return e.split(/(\s+|,|\(|\))/).map((t,n)=>{if(!t)return null;const s=t.toUpperCase();return it.has(s)?i.jsx("span",{style:a.sqlKeyword,children:t},n):t.startsWith("$")||t.startsWith(":")||t.startsWith("?")?i.jsx("span",{style:a.sqlBindParam,children:t},n):i.jsx("span",{children:t},n)})}function _e(e){return e.flatMap(r=>{var m,v,x,g;const t=r.latestAttempt,n=t==null?void 0:t.executionResult,s=qe((m=n==null?void 0:n.validation)==null?void 0:m.warnings),o=qe((v=n==null?void 0:n.validation)==null?void 0:v.errors),u=yr((x=n==null?void 0:n.coverage)==null?void 0:x.missingObligations),p=qe((g=n==null?void 0:n.coverage)==null?void 0:g.warnings),d=[],f=ye(r);(t==null?void 0:t.status)==="error"&&d.push({trace:r,tone:"error",title:f,message:t.errorMessage||"Query attempt failed."});for(const b of r.clientWarnings)d.push({trace:r,tone:"warning",title:f,message:b});for(const b of s)d.push({trace:r,tone:"warning",title:f,...b});for(const b of o)d.push({trace:r,tone:"error",title:f,...b});for(const b of u)d.push({trace:r,tone:"warning",title:f,message:b});for(const b of p)d.push({trace:r,tone:"warning",title:f,...b});return d})}function at(e){return{traceId:e.trace.traceId,queryId:e.trace.queryId,viewId:e.trace.viewId,viewTitle:e.trace.viewTitle,queryLabel:e.trace.queryLabel,severity:e.tone,title:e.title,message:e.message,code:e.code,path:e.path}}function dt(e,r){return e.filter(t=>cr(t.trace,r)).length}function lt(e){const r=_e(e),t=e.filter(u=>{var p;return((p=u.latestAttempt)==null?void 0:p.status)==="error"}).length,n=e.filter(u=>{var p;return((p=u.latestAttempt)==null?void 0:p.status)==="loading"}).length,s=r.filter(u=>u.tone==="error").length,o=r.filter(u=>u.tone==="warning").length;return{total:e.length,failed:t,loading:n,errorCount:s,warningCount:o,issueCount:r.length,severity:t||s?"error":o?"warning":n?"loading":"ok"}}function ut(e){return[`${e.total} ${e.total===1?"trace":"traces"}`,`${e.loading} loading`,`${e.failed} failed`,`${e.errorCount} error${e.errorCount===1?"":"s"}`,`${e.warningCount} warning${e.warningCount===1?"":"s"}`].join(" · ")}function ct(e,r){const t=r.trim().toLowerCase();return t?e.filter(n=>[n.queryId,n.queryLabel,n.viewId,n.viewTitle,n.visualType,n.sectionTitle,n.builder,n.queryKind,mr(n)].filter(Boolean).join(" ").toLowerCase().includes(t)):e}function ft(e){const r=e.filter(s=>s.queryKind==="inputOptions"),t=new Set(r.map(Te));return[{title:"Views",traces:e.filter(s=>!t.has(Te(s)))},{title:"Inputs",traces:r}]}function ur(e,r){if(!(!(r!=null&&r.traceId)&&!(r!=null&&r.queryId)&&!(r!=null&&r.viewId)))return r.traceId?e.find(t=>t.traceId===r.traceId):e.find(t=>!(r.queryId&&t.queryId!==r.queryId||r.viewId&&t.viewId!==r.viewId))}function pt(e,r){if(r.queryId)return ur(e,r);if(!r.viewId)return;const t=e.filter(n=>n.viewId===r.viewId);return t.length===1?t[0]:void 0}function cr(e,r){return!!(e&&r&&e.traceId===r.traceId)}function Te(e){return e.traceId}function gt(e){switch(e){case"metric":return"metric";case"records":return"records";case"matrix":return"matrix";case"analysis":return"analysis";case"inputOptions":return"inputs";case"sql":return"sql";default:return he(e)}}function fr(e){const r=e.trim().toLowerCase();return r==="metric"||r==="kpi"?"metric":r==="records"||r==="table"?"records":r==="matrix"||r==="pivot"?"matrix":r==="analysis"?"analysis":r==="inputs"||r==="input options"?"inputs":r==="sql"?"sql":"default"}function pr(e){switch(e){case"metric":return{borderColor:"var(--sd-tone-metric-border)",background:"var(--sd-tone-metric-bg)",color:"var(--sd-tone-metric-fg)"};case"records":return{borderColor:"var(--sd-tone-records-border)",background:"var(--sd-tone-records-bg)",color:"var(--sd-tone-records-fg)"};case"analysis":case"matrix":return{borderColor:"var(--sd-tone-analysis-border)",background:"var(--sd-tone-analysis-bg)",color:"var(--sd-tone-analysis-fg)"};case"inputs":case"sql":case"default":default:return{borderColor:"var(--sd-border)",background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)"}}}function ye(e){return e.viewTitle||e.queryLabel||e.viewId||e.queryId}function mt(e,r,t){const n=[];return e.queryLabel&&e.queryLabel!==r&&n.push(e.queryLabel),e.queryId&&e.queryId!==r&&e.queryId!==e.queryLabel?n.push(e.queryId):e.viewId&&e.viewId!==r&&e.viewId!==e.queryLabel&&n.push(e.viewId),n.push(t),n}function gr(e){return ht(e.visualType)||gt(e.queryKind)}function yt(e,r){return r?e.queryLabel||e.queryId:ye(e)}function ht(e){if(e)return e.replace(/[_-]+/g," ").replace(/\b\w/g,r=>r.toUpperCase())}function mr(e){const r=e.sourceRefs.map(W);return r.length?r.length===1?r[0]:`${r[0]} + ${r.length-1} more`:"No source"}function vt(e){return e.reduce((r,t)=>(t.role==="measure"?r.measures.push(t):t.role==="date"?r.timeFields.push(t):t.role==="dimension"?r.dimensions.push(t):t.role==="id"?r.identifiers.push(t):r.other.push(t),r),{measures:[],timeFields:[],dimensions:[],identifiers:[],other:[]})}function bt(e){var r,t;if(e.queryKind==="records"&&((r=e.projectionFieldRefs)!=null&&r.length)&&e.projectionFieldRefs.every(n=>n.role==="measure")&&((t=e.latestAttempt)==null?void 0:t.rowCount)===1)return"KPI query";switch(e.queryKind){case"metric":return"KPI query";case"records":return"Records query";case"matrix":return"Matrix query";case"analysis":return"Analysis query";case"inputOptions":return"Input options query";case"sql":return"SQL query";default:return he(e.queryKind)}}function xt(e){return[e.aggregate,e.label||e.name].filter(Boolean).join(" ")}function St(e){var u,p,d;const r=e.valuePreview||"redacted",t=((u=e.fieldRef)==null?void 0:u.label)||((p=e.fieldRef)==null?void 0:p.name),n=(d=e.fieldRef)!=null&&d.source?W(e.fieldRef.source):void 0,s=[t?`on ${t}`:void 0,n].filter(Boolean).join(" · "),o=[e.inputId,e.operator,r,s].filter(Boolean).join(" - ");return{operator:e.operator,value:r,binding:s,title:o}}function W(e){return e.kind==="semantic"?e.datasetName||e.datasetId||e.domainId:e.kind==="physical"?[e.schemaName,e.tableName].filter(Boolean).join(".")||e.tableName:e.connectionId?`SQL ${e.connectionId}`:"SQL source"}function It(e){if(e.file)return e.line&&e.column?`${e.file}:${e.line}:${e.column}`:e.line?`${e.file}:${e.line}`:e.file}function wt(e){return typeof e=="number"?e.toLocaleString():"-"}function qt(e){return typeof e=="number"?`${Math.round(e)}ms`:"-"}function jt(e){return Re(e)}function Re(e){return JSON.stringify(e,null,2)??"undefined"}function At(e){switch(e.type){case"query_started":return"Started";case"query_succeeded":return"Succeeded";case"query_failed":return"Failed";case"query_ignored_stale":return"Ignored stale";case"input_changed":return"Input changed";default:return Et(e)}}function Ct(e){return[e.at,"durationMs"in e&&typeof e.durationMs=="number"?`${Math.round(e.durationMs)}ms`:void 0,"rowCount"in e&&typeof e.rowCount=="number"?`${e.rowCount} rows`:void 0,"reason"in e?e.reason:void 0,"errorMessage"in e?e.errorMessage:void 0].filter(Boolean).join(" - ")}function Et(e){throw new Error(`Unsupported Semaphor trace event: ${JSON.stringify(e)}`)}function yr(e){return Array.isArray(e)?e.filter(r=>typeof r=="string"):[]}function we(e){return Array.isArray(e)?e.map(r=>kt(r)).filter(r=>!!r):[]}function qe(e){return Array.isArray(e)?e.map(r=>hr(r)).filter(r=>!!r):[]}function kt(e){var r;return(r=hr(e))==null?void 0:r.message}function hr(e){if(typeof e=="string")return{message:e};if(!e||typeof e!="object"||Array.isArray(e))return;const r=e,t=typeof r.message=="string"?r.message:"",n=typeof r.code=="string"?r.code:"",s=typeof r.path=="string"?r.path:"";return t&&n?{message:s?`${t} (${n}, ${s})`:`${t} (${n})`,code:n,...s?{path:s}:{}}:t?{message:t}:n?{message:n,code:n}:void 0}function Tt(e){const r=e==null?void 0:e.metadata,t=r&&typeof r=="object"&&!Array.isArray(r)&&"dataAppDebug"in r&&r.dataAppDebug&&typeof r.dataAppDebug=="object"&&!Array.isArray(r.dataAppDebug)?r.dataAppDebug:void 0;return{compiledSql:typeof(t==null?void 0:t.compiledSql)=="string"?t.compiledSql:void 0,queryHash:typeof(t==null?void 0:t.queryHash)=="string"?t.queryHash:void 0}}function Rt(e){return e==="relative"?{position:"relative",top:"auto",right:"auto",bottom:"auto",left:"auto"}:{top:e.startsWith("top")?20:"auto",right:e.endsWith("right")?20:"auto",bottom:e.startsWith("bottom")?20:"auto",left:e.endsWith("left")?20:"auto"}}function Dt(e){return e==="error"?{borderColor:"var(--sd-error-border)",background:"var(--sd-error-bg)",color:"var(--sd-error-fg)"}:e==="warning"?{borderColor:"var(--sd-warning-border)",background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)"}:e==="loading"?{borderColor:"var(--sd-loading-border)",background:"var(--sd-loading-bg)",color:"var(--sd-loading-fg)"}:{borderColor:"var(--sd-success-border)",background:"var(--sd-success-bg)",color:"var(--sd-success-fg)"}}function Lt(e){return e==="right"?{top:16,right:16,bottom:16,left:"auto",width:"min(720px, calc(100vw - 32px))",height:"auto",borderRadius:6}:{top:"auto",right:16,bottom:16,left:16,width:"auto",height:"min(420px, 45vh)",borderRadius:6}}function Ot(e){return e==="right"?{gridTemplateColumns:"minmax(210px, 280px) minmax(0, 1fr)"}:{gridTemplateColumns:"minmax(260px, 340px) minmax(0, 1fr)"}}function Bt(e){return{borderRight:"1px solid var(--sd-border)",borderBottom:0}}function vr(e){return e==="error"?{background:"var(--sd-error-dot)"}:e==="success"?{background:"var(--sd-success-dot)"}:e==="loading"?{background:"var(--sd-loading-dot)"}:{background:"var(--sd-idle-dot)"}}function $t(e){return e==="error"?{borderColor:"var(--sd-error-border)",color:"var(--sd-error-fg)"}:e==="success"?{borderColor:"var(--sd-success-border)",color:"var(--sd-success-fg)"}:e==="loading"?{borderColor:"var(--sd-loading-border)",color:"var(--sd-loading-fg)"}:{borderColor:"var(--sd-border)",color:"var(--sd-fg-muted)"}}const Ye="semaphor-devtools-stylesheet",$="semaphor-devtools",Kt=`
2
+ .${$} {
3
3
  --sd-bg: #ffffff;
4
4
  --sd-bg-muted: #fafafa;
5
5
  --sd-bg-raised: #ffffff;
@@ -48,7 +48,7 @@
48
48
  }
49
49
 
50
50
  @media (prefers-color-scheme: dark) {
51
- .${B} {
51
+ .${$} {
52
52
  --sd-bg: #09090b;
53
53
  --sd-bg-muted: #18181b;
54
54
  --sd-bg-raised: #18181b;
@@ -92,11 +92,11 @@
92
92
  }
93
93
  }
94
94
 
95
- .${B}-source {
95
+ .${$}-source {
96
96
  display: -webkit-box;
97
97
  -webkit-line-clamp: 2;
98
98
  -webkit-box-orient: vertical;
99
99
  overflow: hidden;
100
100
  word-break: break-all;
101
101
  }
102
- `;function ur(){if(typeof document>"u"||document.getElementById(_e))return;const e=document.createElement("style");e.id=_e,e.textContent=At,document.head.appendChild(e)}const oe='ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',O="ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",ae={color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},o={launcher:{position:"fixed",bottom:20,zIndex:2147483e3,display:"inline-flex",alignItems:"center",gap:7,height:36,minWidth:36,padding:"0 10px",borderWidth:1,borderStyle:"solid",borderRadius:6,boxShadow:"var(--sd-shadow)",font:`600 12px/1.2 ${oe}`,cursor:"pointer"},launcherText:{fontVariantNumeric:"tabular-nums"},launcherIssueCount:{display:"grid",minWidth:18,height:18,padding:"0 6px",placeItems:"center",borderRadius:999,border:"1px solid currentColor",background:"var(--sd-bg)",color:"currentColor",fontSize:10,lineHeight:"18px",whiteSpace:"nowrap"},logoMark:{display:"grid",width:18,height:18,placeItems:"center",flex:"0 0 auto",borderRadius:4,background:"var(--sd-fg)",color:"var(--sd-bg)"},panel:{position:"fixed",top:16,right:16,bottom:16,zIndex:2147483001,width:"min(720px, calc(100vw - 32px))",display:"flex",flexDirection:"column",overflow:"hidden",border:"1px solid var(--sd-border)",borderRadius:6,background:"var(--sd-bg)",color:"var(--sd-fg)",boxShadow:"var(--sd-shadow)",font:`13px/1.4 ${oe}`},panelFullscreen:{top:0,right:0,bottom:0,left:0,width:"100vw",height:"100vh",borderRadius:0},panelHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--sd-border)"},panelTitleBlock:{minWidth:0},panelTitle:{fontSize:13,fontWeight:600},panelSubtitle:{marginTop:2,color:"var(--sd-fg-muted)",fontSize:11},panelActions:{display:"flex",alignItems:"center",gap:6},iconButton:{display:"grid",width:28,height:28,placeItems:"center",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,background:"var(--sd-bg)",color:"var(--sd-fg-muted)",cursor:"pointer"},searchBox:{display:"flex",alignItems:"center",gap:8,margin:10,height:28,padding:"0 8px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,color:"var(--sd-fg-muted)"},searchInput:{minWidth:0,flex:1,border:0,outline:0,background:"transparent",color:"var(--sd-fg)",font:`12px/1.4 ${oe}`},issueSummary:{margin:"0 10px 10px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-warning-border)",borderRadius:6,background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)",overflow:"hidden"},issueSummaryHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"7px 9px 5px",...ae},issueSummaryCount:{fontVariantNumeric:"tabular-nums"},issueSummaryList:{display:"grid",gap:1,padding:"0 6px 6px"},issueSummaryItem:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr)",alignItems:"start",gap:8,width:"100%",padding:"7px 8px",border:0,borderRadius:5,background:"transparent",color:"inherit",textAlign:"left",cursor:"pointer"},issueSummaryBadge:{display:"inline-flex",alignItems:"center",height:17,padding:"0 5px",borderWidth:1,borderStyle:"solid",borderRadius:3,fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.06em"},issueSummaryBadgeError:{borderColor:"var(--sd-error-border)",background:"var(--sd-error-bg)",color:"var(--sd-error-fg)"},issueSummaryBadgeWarning:{borderColor:"var(--sd-warning-border)",background:"var(--sd-bg)",color:"var(--sd-warning-fg)"},issueSummaryText:{display:"grid",gap:2,minWidth:0},issueSummaryTitle:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,fontWeight:650},issueSummaryMessage:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-warning-fg)",fontSize:11},issueSummaryMore:{padding:"3px 8px 5px",color:"var(--sd-fg-muted)",fontSize:11},panelBody:{display:"grid",gridTemplateColumns:"minmax(210px, 280px) minmax(0, 1fr)",minHeight:0,flex:1,borderTop:"1px solid var(--sd-border-soft)"},queryList:{minHeight:0,overflowY:"auto",padding:8,borderRight:"1px solid var(--sd-border)",background:"var(--sd-bg-muted)"},queryGroup:{display:"grid",gap:3,marginBottom:8},queryGroupHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 6px 3px",...ae},queryGroupCount:{color:"var(--sd-fg-subtle)",fontVariantNumeric:"tabular-nums"},queryGroupEmpty:{padding:"7px 8px",color:"var(--sd-fg-subtle)",fontSize:11},queryListItem:{display:"grid",gap:3,width:"100%",padding:"7px 8px",borderWidth:1,borderStyle:"solid",borderColor:"transparent",borderRadius:5,background:"transparent",color:"var(--sd-fg)",textAlign:"left",cursor:"pointer"},queryListItemSelected:{borderColor:"var(--sd-border-strong)",background:"var(--sd-bg-raised)"},queryListItemHeader:{display:"flex",alignItems:"center",gap:7,minWidth:0},statusDot:{width:7,height:7,flex:"0 0 auto",borderRadius:999},queryListTitle:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:650,color:"var(--sd-fg)"},queryListKindChip:{flex:"0 0 auto",display:"inline-flex",alignItems:"center",height:15,padding:"0 5px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)",fontFamily:O,fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em"},queryListIssueBadge:{flex:"0 0 auto",display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:16,height:16,padding:"0 4px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-warning-border)",borderRadius:999,background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)",fontSize:10,fontWeight:700,fontVariantNumeric:"tabular-nums"},queryListSource:{minWidth:0,paddingLeft:14,color:"var(--sd-fg-muted)",fontSize:11,lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},queryListSubtitleSep:{color:"var(--sd-fg-subtle)"},detailsPane:{minHeight:0,overflowY:"auto",padding:16},detailsHeader:{display:"grid",gap:6,marginBottom:14},detailsHeaderTopRow:{display:"flex",alignItems:"center",gap:8,minWidth:0},detailsHeaderStatusDot:{width:8,height:8,flex:"0 0 auto",borderRadius:999},detailsTitle:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:14,fontWeight:700,color:"var(--sd-fg)"},detailsKindChip:{flex:"0 0 auto",padding:"2px 6px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)",fontFamily:O,fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em"},metaStrip:{display:"flex",flexWrap:"wrap",alignItems:"center",columnGap:6,rowGap:2,paddingLeft:16,color:"var(--sd-fg-muted)",fontSize:11},metaStripItem:{color:"var(--sd-fg-muted)",fontVariantNumeric:"tabular-nums"},metaStripDot:{color:"var(--sd-fg-subtle)"},sourcePillRow:{display:"flex",flexWrap:"wrap",gap:6},sourcePill:{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 7px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,background:"var(--sd-bg)",color:"var(--sd-fg)"},sourcePillLabel:{fontFamily:O,fontSize:11,color:"var(--sd-fg)"},sourcePillRole:{display:"inline-flex",alignItems:"center",height:14,padding:"0 4px",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-subtle)",fontFamily:O,fontSize:9,textTransform:"uppercase",letterSpacing:"0.06em"},fieldChipList:{display:"grid",gap:5,paddingTop:6},fieldChip:{display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"6px 9px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,background:"var(--sd-bg)"},fieldGlyph:{display:"inline-flex",flex:"0 0 auto",alignItems:"center",justifyContent:"center",width:18,height:18,borderWidth:1,borderStyle:"solid",borderRadius:4,fontFamily:O,fontSize:11,fontWeight:700,lineHeight:1},fieldAggBadge:{display:"inline-flex",alignItems:"center",height:16,padding:"0 5px",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg)",fontFamily:O,fontSize:10,fontWeight:600,letterSpacing:"0.04em"},fieldChipName:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,fontWeight:500},fieldChipMeta:{flex:"0 0 auto",fontFamily:O,fontSize:10,color:"var(--sd-fg-subtle)"},fieldChipMetaDot:{color:"var(--sd-fg-subtle)",fontSize:10},sqlKeyword:{color:"var(--sd-sql-keyword)",fontWeight:600},sqlBindParam:{color:"var(--sd-sql-bind)"},disclosure:{marginTop:16},disclosureSummary:{cursor:"pointer",...ae},disclosureBody:{marginTop:8},alertCard:{marginTop:12,padding:"8px 10px",borderWidth:1,borderStyle:"solid",borderRadius:5,fontSize:12,lineHeight:1.45},alertCardError:{borderColor:"var(--sd-error-border)",background:"var(--sd-error-bg)",color:"var(--sd-error-fg)"},alertCardWarning:{borderColor:"var(--sd-warning-border)",background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)"},alertCardTitle:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em",fontSize:10,marginBottom:4},alertCardList:{margin:0,paddingLeft:16,display:"grid",gap:3},recipe:{display:"grid",gap:12},traceLineage:{display:"grid",gap:12},recipeGroup:{display:"grid",gap:4},recipeGroupHeader:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:4,borderBottom:"1px solid var(--sd-border-soft)"},recipeGroupTitle:{color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},recipeGroupCount:{color:"var(--sd-fg-subtle)",fontSize:10,fontVariantNumeric:"tabular-nums"},recipeFieldList:{display:"grid"},recipeEmptyText:{padding:"5px 0",color:"var(--sd-fg-subtle)",fontSize:11},recipeFieldRow:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, auto)",alignItems:"center",gap:10,minHeight:26,padding:"4px 0",borderBottom:"1px solid var(--sd-border-soft)"},recipeFieldName:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,fontWeight:500},recipeFieldMeta:{minWidth:0,display:"inline-flex",alignItems:"baseline",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-subtle)",fontSize:11,textAlign:"right"},inputsAppliedBlock:{marginTop:16,padding:"10px 12px",border:"1px solid var(--sd-border)",borderLeft:"2px solid var(--sd-fg-muted)",borderRadius:5,background:"var(--sd-bg-muted)"},inputsAppliedHeader:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,marginBottom:6},inputsAppliedTitle:{color:"var(--sd-fg)",fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.08em"},inputsAppliedCount:{color:"var(--sd-fg-subtle)",fontSize:10,fontVariantNumeric:"tabular-nums"},inputRecipeList:{display:"grid"},inputRecipeRow:{display:"grid",gap:2,minWidth:0,padding:"6px 0",borderBottom:"1px solid var(--sd-border-soft)"},inputRecipeHeader:{display:"flex",alignItems:"center",gap:8,minWidth:0},inputRecipeId:{flex:"0 0 auto",maxWidth:"40%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontFamily:O,fontSize:11,fontWeight:600},inputOperatorBadge:{display:"inline-flex",flex:"0 0 auto",alignItems:"center",height:16,padding:"0 5px",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)",fontFamily:O,fontSize:10,textTransform:"uppercase",letterSpacing:"0.06em"},inputValuePreview:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,textAlign:"right"},inputRecipeBinding:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-muted)",fontSize:11},eventList:{display:"grid"},eventRow:{display:"grid",gridTemplateColumns:"96px minmax(0, 1fr)",gap:10,padding:"6px 0",borderBottom:"1px solid var(--sd-border-soft)"},eventType:{color:"var(--sd-fg)",fontWeight:600,fontSize:12},eventMeta:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-muted)",fontSize:11},mutedText:{color:"var(--sd-fg-muted)",fontSize:12},compiledQuery:{display:"grid",gap:10},codeBlockGroup:{display:"grid",gap:5},codeBlockLabel:{...ae},codeBlock:{maxHeight:260,margin:0,overflow:"auto",padding:"8px 10px",border:"1px solid var(--sd-border)",borderRadius:5,background:"var(--sd-bg-muted)",color:"var(--sd-fg)",fontFamily:O,fontSize:11,lineHeight:1.5,whiteSpace:"pre-wrap"},emptyState:{padding:10,color:"var(--sd-fg-muted)",textAlign:"center",fontSize:12},inspectButton:{display:"inline-flex",alignItems:"center",gap:5,height:24,maxWidth:"100%",padding:"0 7px",borderWidth:1,borderStyle:"solid",borderRadius:5,background:"var(--sd-bg)",font:`600 11px/1 ${oe}`,cursor:"pointer"},inspectButtonText:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}};function cr(e){return{...e,order:[],entries:{},sequence:0}}function Ct(e,r){if(r.type==="config")return r.config.enabled?{...e,...r.config}:cr(r.config);if(!e.enabled)return e;switch(r.type){case"register":return Dt(Et(e,r.descriptor));case"unregister":return Tt(e,r.traceKey);case"event":return kt(e,r);default:return e}}function Et(e,r){const t=e.entries[r.traceKey],n=t?e.sequence:e.sequence+1,i=Le(),a={...t||Lt(r),...fr(r),traceKey:r.traceKey,latestAttempt:(t==null?void 0:t.latestAttempt)||{status:"idle"},recentEvents:(t==null?void 0:t.recentEvents)||[],mounted:!0,registeredAt:(t==null?void 0:t.registeredAt)||n,lastEventAt:(t==null?void 0:t.lastEventAt)||i};return{...e,sequence:n,order:t?e.order:[...e.order,r.traceKey],entries:{...e.entries,[r.traceKey]:a}}}function Tt(e,r){const t=e.entries[r];return t?{...e,entries:{...e.entries,[r]:{...t,mounted:!1}}}:e}function kt(e,r){const t=e.entries[r.traceKey];if(!t)return e;const n=Le(),i=[...t.recentEvents,r.event].slice(-e.maxEventsPerQuery);return{...e,entries:{...e.entries,[r.traceKey]:{...t,latestAttempt:r.latestAttempt?{...t.latestAttempt,...r.latestAttempt}:t.latestAttempt,recentEvents:i,lastEventAt:n}}}}function Dt(e){if(e.order.length<=e.maxQueries)return e;const r=e.order.map(i=>e.entries[i]).filter(i=>!!i).sort((i,a)=>i.mounted!==a.mounted?i.mounted?1:-1:i.lastEventAt-a.lastEventAt),t=e.order.length-e.maxQueries,n=new Set(r.slice(0,t).map(i=>i.traceKey));return n.size?{...e,order:e.order.filter(i=>!n.has(i)),entries:Object.fromEntries(Object.entries(e.entries).filter(([i])=>!n.has(i)))}:e}function Lt(e){const r=Le();return{...fr(e),traceKey:e.traceKey,latestAttempt:{status:"idle"},recentEvents:[],mounted:!0,registeredAt:0,lastEventAt:r}}function fr(e){var n;const r=Pt(e.spec),t=Vt(e.spec,e.activeInputs);return{traceId:yr(e.traceKey),viewId:e.viewId,viewTitle:e.viewTitle,visualType:e.visualType,sectionTitle:e.sectionTitle,queryId:e.queryId,queryLabel:e.queryLabel,queryKind:e.queryKind,builder:e.builder,sourceRefs:Ht(e.intent),sourceHints:(n=e.sourceHints)!=null&&n.length?e.sourceHints:void 0,projectionFieldRefs:r,inputFieldRefs:t,fieldRefs:Qt(e.intent),inputsApplied:(e.activeInputs||[]).map(i=>({inputId:i.inputId,fieldRef:i.field,operator:i.operator,valuePreview:_t(i)})),recentEvents:[],clientWarnings:e.clientWarnings}}function ce(e){const{traceKey:r,mounted:t,registeredAt:n,lastEventAt:i,...a}=e;return a}function fe(e){return e.enabled?{enabled:!0,queries:e.order.map(t=>e.entries[t]).filter(t=>!!t).map(ce),getQuery:t=>{const n=Object.values(e.entries).find(i=>i.queryId===t);return n?ce(n):void 0},getQueries:t=>Object.values(e.entries).filter(n=>n.queryId===t).map(ce)}:Xe}function Ot(e){return{snapshot:()=>Bt(fe(e())),getQuery:r=>ze(fe(e()).getQuery(r)),getQueries:r=>fe(e()).getQueries(r).map(t=>ze(t)).filter(t=>!!t)}}function Bt(e){if(!e.enabled)return e;const r=e.queries.map(pr);return{enabled:e.enabled,queries:r,getQuery:t=>r.find(n=>n.queryId===t),getQueries:t=>r.filter(n=>n.queryId===t)}}function ze(e){return e?pr(e):void 0}function pr(e){var r;return(r=e==null?void 0:e.latestAttempt)!=null&&r.executionResult?{...e,latestAttempt:{...e.latestAttempt,executionResult:$t(e.latestAttempt.executionResult)}}:e}function $t(e){const{compiledQuery:r,intent:t,result:n,...i}=e,a=Mt(i.metadata);return{...i,...a?{metadata:a}:{}}}function Mt(e){if(!e||typeof e!="object"||Array.isArray(e))return e;const r=e.dataAppDebug;if(!r||typeof r!="object"||Array.isArray(r))return e;const{compiledSql:t,...n}=r;return{...e,dataAppDebug:n}}function Wt(e){return e===void 0||e===!1?{enabled:!1,exposeWindowBridge:!1,maxEventsPerQuery:he,maxQueries:be}:e===!0?{enabled:!0,exposeWindowBridge:!1,maxEventsPerQuery:he,maxQueries:be}:{enabled:e.enabled!==!1,exposeWindowBridge:e.exposeWindowBridge===!0,maxEventsPerQuery:Pe(e.maxEventsPerQuery,he,Cr),maxQueries:Pe(e.maxQueries,be,Er)}}function Nt(e){const t=[e==null?void 0:e.sourceHint,...(e==null?void 0:e.sourceHints)||[]].filter(n=>!!n).map(n=>({file:de(n.file),line:He(n.line),column:He(n.column),exportName:de(n.exportName),component:de(n.component),note:de(n.note)})).filter(n=>!!(n.file||n.line||n.column||n.exportName||n.component||n.note));return t.length?t:void 0}function de(e){if(typeof e!="string")return;const r=e.trim();return r||void 0}function He(e){return typeof e=="number"&&Number.isInteger(e)&&e>0?e:void 0}function Pe(e,r,t){return e===void 0||!Number.isFinite(e)||!Number.isInteger(e)||e<=0?r:Math.min(e,t)}function Kt(e){return typeof e.id=="string"&&e.id.trim()?e.id:void 0}function Ft(e){switch(e){case"metric":return"semaphor.metric";case"records":return"semaphor.records";case"matrix":return"semaphor.matrix";case"analysis":return"semaphor.analysis";case"inputOptions":return"semaphor.inputOptions";case"sql":return"semaphor.sql";default:return me(e)}}function me(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function _t(e){if(zt(e))return;const r=e.value;if(r!==void 0){if(Array.isArray(r)){const t=r.filter(n=>typeof n=="string"||typeof n=="number"||typeof n=="boolean").map(n=>String(n));if(t.length===r.length&&t.length>0){const n=t.slice(0,3).join(", "),i=t.length>3?`, +${t.length-3} more`:"";return Ve(`${n}${i}`)}return`${r.length} selected`}return typeof r=="number"||typeof r=="boolean"?String(r):typeof r=="string"?Ve(r):r&&typeof r=="object"?`object(${Object.keys(r).slice(0,5).join(",")})`:String(r)}}function Ve(e){return e.length>80?`${e.slice(0,77)}...`:e}function zt(e){var t;const r=[e.inputId,e.label,(t=e.field)==null?void 0:t.name].filter(Boolean).join(" ").toLowerCase();return["token","secret","password","email","phone","ssn"].some(n=>r.includes(n))}function Ht(e){const r=new Map;return pe(e,t=>{Ut(t)&&r.set(mr(t),t)}),[...r.values()]}function Pt(e){switch(e.queryKind){case"metric":case"analysis":return V([...e.measures||[],e.primaryMeasure,e.dateField,...e.dimensions||[]]);case"records":return V(e.fields||[]);case"inputOptions":return V([e.labelField,e.valueField,e.searchField,...e.disambiguationFields||[]]);case"sql":return V(e.fields||[]);case"matrix":return V([...(e.rows||[]).map(xe),...(e.columns||[]).map(xe),...(e.values||[]).map(xe)]);default:return me(e)}}function Vt(e,r){const t=[...(e.inputs||[]).map(gr),...(r||[]).map(n=>n.field)];return V(t)}function V(e){const r=new Map;return e.forEach(t=>{t&&ne(t)&&r.set(De(t),t)}),[...r.values()]}function gr(e){if(!e||typeof e!="object")return;const r=e.toAnalyticsInput;if(typeof r=="function"){const n=r.call(e);return gr(n)}const t=e.field;return ne(t)?t:void 0}function xe(e){if(ne(e))return e;if(!e||typeof e!="object")return;const r=e.field;return ne(r)?r:void 0}function Qt(e){const r=new Map;return pe(e,t=>{ne(t)&&r.set(De(t),t)}),[...r.values()]}function pe(e,r){if(!(!e||typeof e!="object")){if(r(e),Array.isArray(e)){e.forEach(t=>pe(t,r));return}Object.values(e).forEach(t=>pe(t,r))}}function Ut(e){if(!e||typeof e!="object")return!1;const r=e;return r.kind==="semantic"?typeof r.domainId=="string"&&typeof r.datasetName=="string":r.kind==="physical"?typeof r.connectionId=="string"&&typeof r.tableName=="string":r.kind==="sql"?typeof r.connectionId=="string":!1}function ne(e){if(!e||typeof e!="object")return!1;const r=e;return typeof r.name=="string"&&(r.source!==void 0||r.role!==void 0||r.dataType!==void 0||r.aggregate!==void 0)}function mr(e){return e.kind==="semantic"?[e.kind,e.domainId,e.datasetId||e.datasetName].join(":"):e.kind==="physical"?[e.kind,e.connectionId,e.databaseName,e.schemaName,e.tableName].join(":"):[e.kind,e.connectionId].join(":")}function De(e){return[e.name,e.role,e.aggregate,e.source?mr(e.source):""].join(":")}function Gt(e){const r=e;return typeof(r==null?void 0:r.rowCount)=="number"?r.rowCount:Array.isArray(r==null?void 0:r.records)?r.records.length:void 0}function Jt(e){const r=e;return Array.isArray(r==null?void 0:r.columns)?r.columns.length:void 0}function Qe(e){const r=e;return r==null?void 0:r.executionResult}function Ue(e){const r=e;return typeof(r==null?void 0:r.requestId)=="string"?r.requestId:void 0}function yr(e){let r=2166136261;for(let t=0;t<e.length;t+=1)r^=e.charCodeAt(t),r=Math.imul(r,16777619);return(r>>>0).toString(36)}function le(){return new Date().toISOString()}function Le(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const Yt=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"],Xt=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"];function hr(e){if(!e)return{};const r=nn(e.executionResult),t=Zt(e,r),n=rn(t);return{...e,...Object.keys(t).length?{resultSets:t}:{},...n?{columns:n.columns,records:n.records,rowCount:n.rowCount}:{}}}function Zt(e,r){const t=en(e.resultSets);for(const i of Yt){if(t[i]){t[i]=br(t[i]);continue}const a=sn(e[i]);if(!a.length)continue;const u=r.length?r:on(a);t[i]={records:Oe(a,u),columns:u,rowCount:a.length}}const n=tn(e.executionResult);return n&&n.records.length>0&&!t.records&&(t.records=n),t}function en(e){return Object.fromEntries(Object.entries(e||{}).map(([r,t])=>[r,br(t)]))}function br(e){var r;return{...e,records:Oe(e.records||[],e.columns||[]),rowCount:e.rowCount??((r=e.records)==null?void 0:r.length)??0}}function rn(e){var r;for(const t of Xt)if((r=e[t])!=null&&r.records.length)return e[t];return Object.values(e).find(t=>t.records.length)||Object.values(e)[0]}function tn(e){const r=e==null?void 0:e.result;if(!(!r||r.kind!=="records"&&r.kind!=="sql"))return{records:Oe(r.records,r.columns),columns:r.columns,rowCount:r.rowCount??r.records.length}}function nn(e){const r=e==null?void 0:e.result;return!r||r.kind!=="records"&&r.kind!=="sql"?[]:r.columns}function sn(e){return Array.isArray(e)?e.filter(r=>!!(r&&typeof r=="object"&&!Array.isArray(r))):[]}function Oe(e,r){return r.length?e.map(t=>{const n={};return r.forEach((i,a)=>{const u=an(t,{name:i.key,label:i.label,fallbackNames:[i.name,Object.keys(t)[a]]});u!==void 0&&(n[i.key]=u)}),Object.keys(n).length?n:t}):e}function on(e){return Array.from(new Set(e.flatMap(t=>Object.keys(t)))).map(t=>({key:t,name:t,label:t}))}function an(e,r){const t=[r.name,r.label,...r.fallbackNames||[]].filter(n=>!!n);for(const n of t)if(Object.prototype.hasOwnProperty.call(e,n))return e[n]}function vr(){return{executeAnalysis:(e,r,t)=>P(e,r,t??{}).then(hr),executeMetric:(e,r)=>P(e,r),executeRecords:(e,r)=>P(e,r),executeInputOptions:(e,r)=>P(e,r),executeSql:(e,r)=>P(e,r),executeMatrix:(e,r)=>P(e,r)}}async function P(e,r,t){if(!r.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const n=mn(r),i=un(e,n);let a;try{a=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.token}`},body:JSON.stringify({intent:e,activeInputs:r.activeInputs,...t?{analysisOptions:t}:{},resultShape:e.kind,...ln(r)?{debug:{responseDetail:"debug"}}:{}})})}catch(p){throw new Error(`${i}: ${p instanceof Error?p.message:String(p)}`)}const u=await pn(a);if(!a.ok||u.error)throw dn(`${i}: ${u.error||`Semaphor Data App execution failed with status ${a.status}.`}`,u);return u}function dn(e,r){const t=new Error(e);return r.requestId&&(t.requestId=r.requestId),r.details!==void 0&&(t.details=r.details),r.executionResult!==void 0&&(t.executionResult=r.executionResult),t}function ln(e){const r=e.debug;return r?r===!0?!0:r.enabled!==!1&&r.requestServerDebug!==!1:!1}function un(e,r){return[`Semaphor ${e.kind} query`,e.id?`id=${e.id}`:void 0,e.label?`label=${e.label}`:void 0,cn(e),`endpoint=${fn(r)}`].filter(t=>!!t).join(" ")}function cn(e){const r="source"in e?e.source:void 0;if(!(!r||typeof r!="object")){if(r.kind==="semantic")return`source=${[r.domainId,r.datasetId||r.datasetName].filter(Boolean).join("/")}`;if(r.kind==="physical")return`source=${[r.connectionId,r.databaseName,r.schemaName,r.tableName].filter(Boolean).join("/")}`;if(r.kind==="sql")return r.connectionId?`source=${r.connectionId}`:void 0}}function fn(e){if(!e)return"/api/v1/data-app/execute";try{return new URL(e,"http://localhost").pathname}catch{return e}}async function pn(e){const r=await e.text().catch(()=>"");if(!r.trim())return e.ok?{error:"Semaphor Data App execution returned an empty response."}:{};try{return JSON.parse(r)}catch{return e.ok?{error:"Semaphor Data App execution returned invalid JSON.",details:r}:{error:gn(e,r),details:r}}}function gn(e,r){const t=e.statusText?` ${e.statusText}`:"",n=r.replace(/\s+/g," ").trim();return n?`Semaphor Data App execution failed with status ${e.status}${t}: ${n.slice(0,240)}`:`Semaphor Data App execution failed with status ${e.status}${t}.`}function mn(e){const r=yn(e).replace(/\/+$/,"");return r?r.endsWith("/api")?`${r}/v1/data-app/execute`:`${r}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function yn(e){if(e.apiBaseUrl)return e.apiBaseUrl;if(!e.token)return"";try{return Ye.jwtDecode(e.token).apiServiceUrl||""}catch{return""}}const xr=l.createContext({});function hn(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function bn(){return l.useContext(xr)}const Se={value:null},Ie={},vn={records:[]},we={options:[]},xn={records:[]},je={};function Sn(e){const r=S.toSemaphorActiveInputSnapshots(e.inputs),t=S.toSemaphorAnalysisQueryOptions(e);try{const n=S.toSemaphorAnalysisIntent(e),i=U(n);return i?{error:i,activeInputs:r,analysisOptions:t,queryKey:j(void 0,r,i,t),idleData:Ie}:{intent:n,error:null,activeInputs:r,analysisOptions:t,queryKey:j(n,r,void 0,t),idleData:Ie}}catch(n){const i=W(n);return{error:i,activeInputs:r,analysisOptions:t,queryKey:j(void 0,r,i,t),idleData:Ie}}}function In(e){const r=S.toSemaphorActiveInputSnapshots(e.inputs);try{const t=S.toSemaphorMetricIntent(e),n=U(t);return n?{error:n,activeInputs:r,queryKey:j(void 0,r,n),idleData:Se}:{intent:t,error:null,activeInputs:r,queryKey:j(t,r),idleData:Se}}catch(t){const n=W(t);return{error:n,activeInputs:r,queryKey:j(void 0,r,n),idleData:Se}}}function wn(e){const r=S.toSemaphorActiveInputSnapshots(e.inputs),t=vn;try{const n=S.toSemaphorRecordsIntent(e),i=U(n);return i?{error:i,activeInputs:r,queryKey:j(void 0,r,i),idleData:t}:{intent:n,error:null,activeInputs:r,queryKey:j(n,r),idleData:t}}catch(n){const i=W(n);return{error:i,activeInputs:r,queryKey:j(void 0,r,i),idleData:t}}}function jn(e){const r=S.toSemaphorActiveInputSnapshots(e.inputs);try{const t=S.toSemaphorInputOptionsIntent(e),n=U(t);return n?{error:n,activeInputs:r,queryKey:j(void 0,r,n),idleData:we}:{intent:t,error:null,activeInputs:r,queryKey:j(t,r),idleData:we}}catch(t){const n=W(t);return{error:n,activeInputs:r,queryKey:j(void 0,r,n),idleData:we}}}function qn(e){const r=S.toSemaphorActiveInputSnapshots(e.inputs),t=xn;try{const n=S.toSemaphorSqlIntent(e),i=U(n);return i?{error:i,activeInputs:r,queryKey:j(void 0,r,i),idleData:t}:{intent:n,error:null,activeInputs:r,queryKey:j(n,r),idleData:t}}catch(n){const i=W(n);return{error:i,activeInputs:r,queryKey:j(void 0,r,i),idleData:t}}}function Rn(e){const r=S.toSemaphorActiveInputSnapshots(e.inputs);try{const t=S.toSemaphorMatrixIntent(e),n=U(t);return n?{error:n,activeInputs:r,queryKey:j(void 0,r,n),idleData:je}:{intent:t,error:null,activeInputs:r,queryKey:j(t,r),idleData:je}}catch(t){const n=W(t);return{error:n,activeInputs:r,queryKey:j(void 0,r,n),idleData:je}}}function W(e){return e instanceof Error?e:new Error(String(e))}function U(e){const r=jr.validateSemaphorAnalyticsIntent(e);if(r.ok)return null;const t=r.errors.map(n=>n.path?`${n.code} at ${n.path}: ${n.message}`:`${n.code}: ${n.message}`).join("; ");return new Error(`Invalid Semaphor analytics intent. ${t}`)}function j(e,r,t,n){return JSON.stringify({intent:e,activeInputs:r,analysisOptions:n,error:t==null?void 0:t.message})}function An(e){const[r,t]=l.useState(e.defaultValue),n=Object.prototype.hasOwnProperty.call(e,"value"),i=n?e.value:r,a=l.useMemo(()=>S.normalizeSemaphorInputOptions(e.options),[e.options]),u=l.useCallback(f=>{var b;const c=f;(b=e.onValueChange)==null||b.call(e,c),n||t(c)},[n,e]),p=l.useCallback(()=>u(void 0),[u]);return l.useMemo(()=>{const f=S.toSemaphorInputSpec(e);return{id:e.id,kind:e.kind,label:e.label,field:f.field,operator:f.operator,relationshipHint:f.relationshipHint,controlRole:e.kind==="control"?e.role:void 0,value:i,options:a,isActive:S.hasSemaphorInputValue(i),setValue:u,clear:p,toAnalyticsInput:()=>({inputId:f.inputId,field:f.field,kind:e.kind,label:e.label,value:i,isActive:S.hasSemaphorInputValue(i),operator:f.operator,relationshipHint:f.relationshipHint,controlRole:e.kind==="control"?e.role:void 0})}},[p,a,u,e,i])}function Cn(e){const[r,t]=l.useState(()=>Ln(e));return l.useEffect(()=>{t(n=>{let i=n;for(const a of e)!Object.prototype.hasOwnProperty.call(i,a.id)&&a.defaultValue!==void 0&&(i={...i,[a.id]:a.defaultValue});return i})},[e]),l.useMemo(()=>e.map(n=>{const i=Object.prototype.hasOwnProperty.call(n,"value"),a=i?n.value:r[n.id],u=S.normalizeSemaphorInputOptions(n.options),p=b=>{var y;(y=n.onValueChange)==null||y.call(n,b),i||t(v=>({...v,[n.id]:b}))},f=()=>p(void 0),c=S.toSemaphorInputSpec(n);return{id:n.id,kind:n.kind,label:n.label,field:c.field,operator:c.operator,relationshipHint:c.relationshipHint,controlRole:n.kind==="control"?n.role:void 0,value:a,options:u,isActive:S.hasSemaphorInputValue(a),setValue:p,clear:f,toAnalyticsInput:()=>({inputId:c.inputId,field:c.field,kind:n.kind,label:n.label,value:a,isActive:S.hasSemaphorInputValue(a),operator:c.operator,relationshipHint:c.relationshipHint,controlRole:n.kind==="control"?n.role:void 0})}}),[e,r])}function En(e,r){const t=(r==null?void 0:r.status)==="success"?r.options:void 0,n=l.useMemo(()=>Tn(t),[t]);l.useEffect(()=>{Sr(e.value,t)||e.clear()},[e,n,r==null?void 0:r.status,t])}function Sr(e,r){if(!S.hasSemaphorInputValue(e)||r===void 0)return!0;const t=new Set(r.map(i=>Ge(i.value)));return(Array.isArray(e)?e:[e]).every(i=>t.has(Ge(i)))}function Tn(e){return JSON.stringify((e||[]).map(r=>r.value))}function Ge(e){return`${typeof e}:${String(e)}`}function kn(e,r={}){const t=l.useMemo(()=>r.inputs?{...e,inputs:r.inputs}:e,[r.inputs,e]),n=l.useMemo(()=>{switch(t.queryKind){case"metric":return{queryKind:t.queryKind,request:In(t)};case"analysis":return{queryKind:t.queryKind,request:Sn(t)};case"records":return{queryKind:t.queryKind,request:wn(t)};case"inputOptions":return{queryKind:t.queryKind,request:jn(t)};case"sql":return{queryKind:t.queryKind,request:qn(t)};case"matrix":return{queryKind:t.queryKind,request:Rn(t)};default:return qe(t)}},[t]),i=Br({spec:t,queryKind:n.queryKind,queryKey:n.request.queryKey,intent:n.request.intent,activeInputs:n.request.activeInputs,debug:r.debug}),a=l.useRef(null),u=l.useMemo(()=>({start:i.start,success:i.success,failure:i.failure,ignored:i.ignored}),[i.failure,i.ignored,i.start,i.success]),p=l.useCallback(d=>{var D,R,L,k,m,x,T,w,q;const I=n.request;if(I.intent)switch(n.queryKind){case"metric":return(D=d.executor)==null?void 0:D.executeMetric(I.intent,d);case"analysis":return(L=(R=d.executor)==null?void 0:R.executeAnalysis)==null?void 0:L.call(R,I.intent,d,I.analysisOptions);case"records":return(k=d.executor)==null?void 0:k.executeRecords(I.intent,d);case"inputOptions":return(m=d.executor)==null?void 0:m.executeInputOptions(I.intent,d);case"sql":return(T=(x=d.executor)==null?void 0:x.executeSql)==null?void 0:T.call(x,I.intent,d);case"matrix":return(q=(w=d.executor)==null?void 0:w.executeMatrix)==null?void 0:q.call(w,I.intent,d);default:return qe(n)}},[n]),f=Dn(n.request.queryKey,p,n.request.idleData,n.request.activeInputs,u),c=i.queryId,b=i.validationFailure;l.useEffect(()=>{const d=n.request.error;if(!d){a.current=null;return}const I=`${c}:${d.message}`;a.current!==I&&(a.current=I,b(d))},[n.request.error,n.request.queryKey,c,b]);const y=n.request.error?n.request.idleData:f.data,v=n.request.error?"error":f.status,g=!n.request.error&&f.status==="loading",h=n.request.error||f.error,E=i.trace;switch(n.queryKind){case"metric":{const d=y;return{id:t.id,intent:n.request.intent,value:(d==null?void 0:d.value)??null,measures:d==null?void 0:d.measures,comparisonValue:d==null?void 0:d.comparisonValue,delta:d==null?void 0:d.delta,deltaPercent:d==null?void 0:d.deltaPercent,records:d==null?void 0:d.records,executionResult:d==null?void 0:d.executionResult,status:v,isLoading:g,error:h,trace:E}}case"analysis":{const d=hr(y);return{id:t.id,intent:n.request.intent,...d||{},status:v,isLoading:g,error:h,trace:E}}case"records":{const d=y;return{id:t.id,intent:n.request.intent,records:(d==null?void 0:d.records)||[],columns:d==null?void 0:d.columns,rowCount:d==null?void 0:d.rowCount,pagination:d==null?void 0:d.pagination,executionResult:d==null?void 0:d.executionResult,status:v,isLoading:g,error:h,trace:E}}case"inputOptions":{const d=y;return{id:t.id,intent:n.request.intent,options:(d==null?void 0:d.options)||[],executionResult:d==null?void 0:d.executionResult,status:v,isLoading:g,error:h,trace:E}}case"sql":{const d=y;return{id:t.id,intent:n.request.intent,records:(d==null?void 0:d.records)||[],columns:d==null?void 0:d.columns,rowCount:d==null?void 0:d.rowCount,pagination:d==null?void 0:d.pagination,output:d==null?void 0:d.output,rowLimitExceeded:d==null?void 0:d.rowLimitExceeded,executionResult:d==null?void 0:d.executionResult,status:v,isLoading:g,error:h,trace:E}}case"matrix":{const d=y;return{id:t.id,intent:n.request.intent,matrixResult:d==null?void 0:d.matrixResult,grid:d==null?void 0:d.grid,expansion:d==null?void 0:d.expansion,executionResult:d==null?void 0:d.executionResult,status:v,isLoading:g,error:h,trace:E}}default:return qe(n)}}function Dn(e,r,t,n,i){const a=bn(),u=l.useRef(r),p=l.useRef(n),[f,c]=l.useState({status:"idle",data:t,error:null});return u.current=r,p.current=n,l.useEffect(()=>{let b;try{b=u.current({...a,activeInputs:p.current})}catch(g){i==null||i.failure(g,0),c({status:"error",data:t,error:W(g)});return}if(!b){c({status:"idle",data:t,error:null});return}let y=!1;const v=Ir();return i==null||i.start(),c(g=>({status:"loading",data:g.data,error:null})),b.then(g=>{y?i==null||i.ignored("superseded"):(i==null||i.success(g,Je(v)),c({status:"success",data:g,error:null}))}).catch(g=>{y?i==null||i.ignored("superseded"):(i==null||i.failure(g,Je(v)),c({status:"error",data:t,error:W(g)}))}),()=>{y=!0}},[t,e,a,i]),f}function Ir(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}function Je(e){return Math.max(0,Math.round(Ir()-e))}function Ln(e){return Object.fromEntries(e.filter(r=>r.defaultValue!==void 0).map(r=>[r.id,r.defaultValue]))}function qe(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function On(e){return!e||typeof e=="boolean"||e.enabled===!1?null:e.autoRenderDevtools===!0?{}:e.autoRenderDevtools?e.autoRenderDevtools:null}function Bn({token:e,apiBaseUrl:r,executor:t,debug:n,children:i}){var g;const a=hn(),u=((g=a==null?void 0:a.authToken)==null?void 0:g.accessToken)||e,p=(a==null?void 0:a.dataApiBaseUrl)||(a==null?void 0:a.apiBaseUrl)||r,f=(a==null?void 0:a.debug)??n,c=On(f),b=l.useMemo(()=>vr(),[]),y=t||b,v=l.useMemo(()=>({token:u,apiBaseUrl:p,executor:y,debug:f}),[p,f,y,u]);return s.jsx(Tr,{debug:f,children:s.jsxs(xr.Provider,{value:v,children:[i,c?s.jsx(er,{...c}):null]})})}exports.SemaphorDataAppProvider=Bn;exports.SemaphorDevtools=er;exports.SemaphorDevtoolsInspectButton=Or;exports.SemaphorViewBoundary=Lr;exports.createSemaphorQueryExecutor=vr;exports.defineSemaphorDataApp=qr;exports.defineSemaphorInput=Rr;exports.isSemaphorInputValueValidForOptions=Sr;exports.semaphor=Ar;exports.useClearInvalidSemaphorInputValue=En;exports.useSemaphorDevtools=ke;exports.useSemaphorInput=An;exports.useSemaphorInputs=Cn;exports.useSemaphorQuery=kn;
102
+ `;function br(){if(typeof document>"u"||document.getElementById(Ye))return;const e=document.createElement("style");e.id=Ye,e.textContent=Kt,document.head.appendChild(e)}const le='ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',B="ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",ue={color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},a={launcher:{position:"fixed",bottom:20,zIndex:2147483e3,display:"inline-flex",alignItems:"center",gap:7,height:36,minWidth:36,padding:"0 10px",borderWidth:1,borderStyle:"solid",borderRadius:6,boxShadow:"var(--sd-shadow)",font:`600 12px/1.2 ${le}`,cursor:"pointer"},launcherText:{fontVariantNumeric:"tabular-nums"},launcherIssueCount:{display:"grid",minWidth:18,height:18,padding:"0 6px",placeItems:"center",borderRadius:999,border:"1px solid currentColor",background:"var(--sd-bg)",color:"currentColor",fontSize:10,lineHeight:"18px",whiteSpace:"nowrap"},logoMark:{display:"grid",width:18,height:18,placeItems:"center",flex:"0 0 auto",borderRadius:4,background:"var(--sd-fg)",color:"var(--sd-bg)"},panel:{position:"fixed",top:16,right:16,bottom:16,zIndex:2147483001,width:"min(720px, calc(100vw - 32px))",display:"flex",flexDirection:"column",overflow:"hidden",border:"1px solid var(--sd-border)",borderRadius:6,background:"var(--sd-bg)",color:"var(--sd-fg)",boxShadow:"var(--sd-shadow)",font:`13px/1.4 ${le}`},panelFullscreen:{top:0,right:0,bottom:0,left:0,width:"100vw",height:"100vh",borderRadius:0},panelHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--sd-border)"},panelTitleBlock:{minWidth:0},panelTitle:{fontSize:13,fontWeight:600},panelSubtitle:{marginTop:2,color:"var(--sd-fg-muted)",fontSize:11},panelActions:{display:"flex",alignItems:"center",gap:6},iconButton:{display:"grid",width:28,height:28,placeItems:"center",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,background:"var(--sd-bg)",color:"var(--sd-fg-muted)",cursor:"pointer"},searchBox:{display:"flex",alignItems:"center",gap:8,margin:10,height:28,padding:"0 8px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,color:"var(--sd-fg-muted)"},searchInput:{minWidth:0,flex:1,border:0,outline:0,background:"transparent",color:"var(--sd-fg)",font:`12px/1.4 ${le}`},issueSummary:{margin:"0 10px 10px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-warning-border)",borderRadius:6,background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)",overflow:"hidden"},issueSummaryToggle:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,width:"100%",padding:"7px 9px 5px",border:0,background:"transparent",color:"inherit",cursor:"pointer",...ue},issueSummaryHeaderLabel:{display:"inline-flex",alignItems:"center",gap:4,minWidth:0},issueSummaryCount:{fontVariantNumeric:"tabular-nums"},issueSummaryCollapsed:{padding:"0 9px 8px 26px",color:"var(--sd-fg-muted)",fontSize:11},issueSummaryList:{display:"grid",gap:1,padding:"0 6px 6px"},issueSummaryItem:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr)",alignItems:"start",gap:8,width:"100%",padding:"7px 8px",border:0,borderRadius:5,background:"transparent",color:"inherit",textAlign:"left",cursor:"pointer"},issueSummaryBadge:{display:"inline-flex",alignItems:"center",height:17,padding:"0 5px",borderWidth:1,borderStyle:"solid",borderRadius:3,fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.06em"},issueSummaryBadgeError:{borderColor:"var(--sd-error-border)",background:"var(--sd-error-bg)",color:"var(--sd-error-fg)"},issueSummaryBadgeWarning:{borderColor:"var(--sd-warning-border)",background:"var(--sd-bg)",color:"var(--sd-warning-fg)"},issueSummaryText:{display:"grid",gap:2,minWidth:0},issueSummaryTitle:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,fontWeight:650},issueSummaryMessage:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-warning-fg)",fontSize:11},issueSummaryMore:{padding:"3px 8px 5px",color:"var(--sd-fg-muted)",fontSize:11},panelBody:{display:"grid",gridTemplateColumns:"minmax(210px, 280px) minmax(0, 1fr)",minHeight:0,flex:1,borderTop:"1px solid var(--sd-border-soft)"},queryList:{minHeight:0,overflowY:"auto",padding:8,borderRight:"1px solid var(--sd-border)",background:"var(--sd-bg-muted)"},queryGroup:{display:"grid",gap:3,marginBottom:8},queryGroupHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 6px 3px",...ue},queryGroupCount:{color:"var(--sd-fg-subtle)",fontVariantNumeric:"tabular-nums"},queryGroupEmpty:{padding:"7px 8px",color:"var(--sd-fg-subtle)",fontSize:11},queryListItem:{display:"grid",gap:3,width:"100%",padding:"7px 8px",borderWidth:1,borderStyle:"solid",borderColor:"transparent",borderRadius:5,background:"transparent",color:"var(--sd-fg)",textAlign:"left",cursor:"pointer"},queryListItemSelected:{borderColor:"var(--sd-border-strong)",background:"var(--sd-bg-raised)"},queryListItemHeader:{display:"flex",alignItems:"center",gap:7,minWidth:0},statusDot:{width:7,height:7,flex:"0 0 auto",borderRadius:999},queryListTitle:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:650,color:"var(--sd-fg)"},queryListKindChip:{flex:"0 0 auto",display:"inline-flex",alignItems:"center",height:15,padding:"0 5px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)",fontFamily:B,fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em"},queryListIssueBadge:{flex:"0 0 auto",display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:16,height:16,padding:"0 4px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-warning-border)",borderRadius:999,background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)",fontSize:10,fontWeight:700,fontVariantNumeric:"tabular-nums"},queryListSource:{minWidth:0,paddingLeft:14,color:"var(--sd-fg-muted)",fontSize:11,lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},queryListSubtitleSep:{color:"var(--sd-fg-subtle)"},detailsPane:{minHeight:0,overflowY:"auto",padding:16},detailsHeader:{display:"grid",gap:6,marginBottom:14},detailsHeaderTopRow:{display:"flex",alignItems:"center",gap:8,minWidth:0},detailsHeaderStatusDot:{width:8,height:8,flex:"0 0 auto",borderRadius:999},detailsTitle:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:14,fontWeight:700,color:"var(--sd-fg)"},detailsKindChip:{flex:"0 0 auto",padding:"2px 6px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)",fontFamily:B,fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em"},metaStrip:{display:"flex",flexWrap:"wrap",alignItems:"center",columnGap:6,rowGap:2,paddingLeft:16,color:"var(--sd-fg-muted)",fontSize:11},metaStripItem:{color:"var(--sd-fg-muted)",fontVariantNumeric:"tabular-nums"},metaStripDot:{color:"var(--sd-fg-subtle)"},sourcePillRow:{display:"flex",flexWrap:"wrap",gap:6},sourcePill:{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 7px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,background:"var(--sd-bg)",color:"var(--sd-fg)"},sourcePillLabel:{fontFamily:B,fontSize:11,color:"var(--sd-fg)"},sourcePillRole:{display:"inline-flex",alignItems:"center",height:14,padding:"0 4px",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-subtle)",fontFamily:B,fontSize:9,textTransform:"uppercase",letterSpacing:"0.06em"},fieldChipList:{display:"grid",gap:5,paddingTop:6},fieldChip:{display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"6px 9px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,background:"var(--sd-bg)"},fieldGlyph:{display:"inline-flex",flex:"0 0 auto",alignItems:"center",justifyContent:"center",width:18,height:18,borderWidth:1,borderStyle:"solid",borderRadius:4,fontFamily:B,fontSize:11,fontWeight:700,lineHeight:1},fieldAggBadge:{display:"inline-flex",alignItems:"center",height:16,padding:"0 5px",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg)",fontFamily:B,fontSize:10,fontWeight:600,letterSpacing:"0.04em"},fieldChipName:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,fontWeight:500},fieldChipMeta:{flex:"0 0 auto",fontFamily:B,fontSize:10,color:"var(--sd-fg-subtle)"},fieldChipMetaDot:{color:"var(--sd-fg-subtle)",fontSize:10},sqlKeyword:{color:"var(--sd-sql-keyword)",fontWeight:600},sqlBindParam:{color:"var(--sd-sql-bind)"},disclosure:{marginTop:16},disclosureSummary:{cursor:"pointer",...ue},disclosureBody:{marginTop:8},alertCard:{marginTop:12,padding:"8px 10px",borderWidth:1,borderStyle:"solid",borderRadius:5,fontSize:12,lineHeight:1.45},alertCardError:{borderColor:"var(--sd-error-border)",background:"var(--sd-error-bg)",color:"var(--sd-error-fg)"},alertCardWarning:{borderColor:"var(--sd-warning-border)",background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)"},alertCardTitle:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em",fontSize:10,marginBottom:4},alertCardList:{margin:0,paddingLeft:16,display:"grid",gap:3},recipe:{display:"grid",gap:12},traceLineage:{display:"grid",gap:12},recipeGroup:{display:"grid",gap:4},recipeGroupHeader:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:4,borderBottom:"1px solid var(--sd-border-soft)"},recipeGroupTitle:{color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},recipeGroupCount:{color:"var(--sd-fg-subtle)",fontSize:10,fontVariantNumeric:"tabular-nums"},recipeFieldList:{display:"grid"},recipeEmptyText:{padding:"5px 0",color:"var(--sd-fg-subtle)",fontSize:11},recipeFieldRow:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, auto)",alignItems:"center",gap:10,minHeight:26,padding:"4px 0",borderBottom:"1px solid var(--sd-border-soft)"},recipeFieldName:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,fontWeight:500},recipeFieldMeta:{minWidth:0,display:"inline-flex",alignItems:"baseline",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-subtle)",fontSize:11,textAlign:"right"},inputsAppliedBlock:{marginTop:16,padding:"10px 12px",border:"1px solid var(--sd-border)",borderLeft:"2px solid var(--sd-fg-muted)",borderRadius:5,background:"var(--sd-bg-muted)"},inputsAppliedHeader:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,marginBottom:6},inputsAppliedTitle:{color:"var(--sd-fg)",fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.08em"},inputsAppliedCount:{color:"var(--sd-fg-subtle)",fontSize:10,fontVariantNumeric:"tabular-nums"},inputRecipeList:{display:"grid"},inputRecipeRow:{display:"grid",gap:2,minWidth:0,padding:"6px 0",borderBottom:"1px solid var(--sd-border-soft)"},inputRecipeHeader:{display:"flex",alignItems:"center",gap:8,minWidth:0},inputRecipeId:{flex:"0 0 auto",maxWidth:"40%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontFamily:B,fontSize:11,fontWeight:600},inputOperatorBadge:{display:"inline-flex",flex:"0 0 auto",alignItems:"center",height:16,padding:"0 5px",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)",fontFamily:B,fontSize:10,textTransform:"uppercase",letterSpacing:"0.06em"},inputValuePreview:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,textAlign:"right"},inputRecipeBinding:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-muted)",fontSize:11},eventList:{display:"grid"},eventRow:{display:"grid",gridTemplateColumns:"96px minmax(0, 1fr)",gap:10,padding:"6px 0",borderBottom:"1px solid var(--sd-border-soft)"},eventType:{color:"var(--sd-fg)",fontWeight:600,fontSize:12},eventMeta:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-muted)",fontSize:11},mutedText:{color:"var(--sd-fg-muted)",fontSize:12},compiledQuery:{display:"grid",gap:10},codeBlockGroup:{display:"grid",gap:5},codeBlockLabel:{...ue},codeBlock:{maxHeight:260,margin:0,overflow:"auto",padding:"8px 10px",border:"1px solid var(--sd-border)",borderRadius:5,background:"var(--sd-bg-muted)",color:"var(--sd-fg)",fontFamily:B,fontSize:11,lineHeight:1.5,whiteSpace:"pre-wrap"},emptyState:{padding:10,color:"var(--sd-fg-muted)",textAlign:"center",fontSize:12},inspectButton:{display:"inline-flex",alignItems:"center",gap:5,height:24,maxWidth:"100%",padding:"0 7px",borderWidth:1,borderStyle:"solid",borderRadius:5,background:"var(--sd-bg)",font:`600 11px/1 ${le}`,cursor:"pointer"},inspectButtonText:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}};function xr(e){return{...e,order:[],entries:{},sequence:0}}function Wt(e,r){if(r.type==="config")return r.config.enabled?{...e,...r.config}:xr(r.config);if(!e.enabled)return e;switch(r.type){case"register":return Ft(_t(e,r.descriptor));case"unregister":return Mt(e,r.traceKey);case"event":return Nt(e,r);default:return e}}function _t(e,r){const t=e.entries[r.traceKey],n=t?e.sequence:e.sequence+1,s=Ne(),o={...t||zt(r),...Sr(r),traceKey:r.traceKey,latestAttempt:(t==null?void 0:t.latestAttempt)||{status:"idle"},recentEvents:(t==null?void 0:t.recentEvents)||[],mounted:!0,registeredAt:(t==null?void 0:t.registeredAt)||n,lastEventAt:(t==null?void 0:t.lastEventAt)||s};return{...e,sequence:n,order:t?e.order:[...e.order,r.traceKey],entries:{...e.entries,[r.traceKey]:o}}}function Mt(e,r){const t=e.entries[r];return t?{...e,entries:{...e.entries,[r]:{...t,mounted:!1}}}:e}function Nt(e,r){const t=e.entries[r.traceKey];if(!t)return e;const n=Ne(),s=[...t.recentEvents,r.event].slice(-e.maxEventsPerQuery);return{...e,entries:{...e.entries,[r.traceKey]:{...t,latestAttempt:r.latestAttempt?{...t.latestAttempt,...r.latestAttempt}:t.latestAttempt,recentEvents:s,lastEventAt:n}}}}function Ft(e){if(e.order.length<=e.maxQueries)return e;const r=e.order.map(s=>e.entries[s]).filter(s=>!!s).sort((s,o)=>s.mounted!==o.mounted?s.mounted?1:-1:s.lastEventAt-o.lastEventAt),t=e.order.length-e.maxQueries,n=new Set(r.slice(0,t).map(s=>s.traceKey));return n.size?{...e,order:e.order.filter(s=>!n.has(s)),entries:Object.fromEntries(Object.entries(e.entries).filter(([s])=>!n.has(s)))}:e}function zt(e){const r=Ne();return{...Sr(e),traceKey:e.traceKey,latestAttempt:{status:"idle"},recentEvents:[],mounted:!0,registeredAt:0,lastEventAt:r}}function Sr(e){var n;const r=rn(e.spec),t=tn(e.spec,e.activeInputs);return{traceId:qr(e.traceKey),viewId:e.viewId,viewTitle:e.viewTitle,visualType:e.visualType,sectionTitle:e.sectionTitle,queryId:e.queryId,queryLabel:e.queryLabel,queryKind:e.queryKind,builder:e.builder,sourceRefs:en(e.intent),sourceHints:(n=e.sourceHints)!=null&&n.length?e.sourceHints:void 0,projectionFieldRefs:r,inputFieldRefs:t,fieldRefs:nn(e.intent),inputsApplied:(e.activeInputs||[]).map(s=>({inputId:s.inputId,fieldRef:s.field,operator:s.operator,valuePreview:Xt(s)})),recentEvents:[],clientWarnings:e.clientWarnings}}function pe(e){const{traceKey:r,mounted:t,registeredAt:n,lastEventAt:s,...o}=e;return o}function ne(e){if(!e.enabled)return ar;const r=e.order.map(n=>e.entries[n]).filter(n=>!!n).map(pe),t=_e(r).map(at);return{enabled:!0,queries:r,issues:t,getQuery:n=>{const s=Object.values(e.entries).find(o=>o.queryId===n);return s?pe(s):void 0},getQueries:n=>Object.values(e.entries).filter(s=>s.queryId===n).map(pe)}}function Ht(e){return{snapshot:()=>Pt(ne(e())),getQuery:r=>Xe(ne(e()).getQuery(r)),getQueries:r=>ne(e()).getQueries(r).map(t=>Xe(t)).filter(t=>!!t),getIssues:()=>ne(e()).issues}}function Pt(e){if(!e.enabled)return e;const r=e.queries.map(Ir);return{enabled:e.enabled,queries:r,issues:e.issues,getQuery:t=>r.find(n=>n.queryId===t),getQueries:t=>r.filter(n=>n.queryId===t)}}function Xe(e){return e?Ir(e):void 0}function Ir(e){var r;return(r=e==null?void 0:e.latestAttempt)!=null&&r.executionResult?{...e,latestAttempt:{...e.latestAttempt,executionResult:Vt(e.latestAttempt.executionResult)}}:e}function Vt(e){const{compiledQuery:r,intent:t,result:n,...s}=e,o=Qt(s.metadata);return{...s,...o?{metadata:o}:{}}}function Qt(e){if(!e||typeof e!="object"||Array.isArray(e))return e;const r=e.dataAppDebug;if(!r||typeof r!="object"||Array.isArray(r))return e;const{compiledSql:t,...n}=r;return{...e,dataAppDebug:n}}function Ut(e){return e===void 0||e===!1?{enabled:!1,exposeWindowBridge:!1,maxEventsPerQuery:xe,maxQueries:Se}:e===!0?{enabled:!0,exposeWindowBridge:!1,maxEventsPerQuery:xe,maxQueries:Se}:{enabled:e.enabled!==!1,exposeWindowBridge:e.exposeWindowBridge===!0,maxEventsPerQuery:er(e.maxEventsPerQuery,xe,Kr),maxQueries:er(e.maxQueries,Se,Wr)}}function Gt(e){const t=[e==null?void 0:e.sourceHint,...(e==null?void 0:e.sourceHints)||[]].filter(n=>!!n).map(n=>({file:ce(n.file),line:Ze(n.line),column:Ze(n.column),exportName:ce(n.exportName),component:ce(n.component),note:ce(n.note)})).filter(n=>!!(n.file||n.line||n.column||n.exportName||n.component||n.note));return t.length?t:void 0}function ce(e){if(typeof e!="string")return;const r=e.trim();return r||void 0}function Ze(e){return typeof e=="number"&&Number.isInteger(e)&&e>0?e:void 0}function er(e,r,t){return e===void 0||!Number.isFinite(e)||!Number.isInteger(e)||e<=0?r:Math.min(e,t)}function Jt(e){return typeof e.id=="string"&&e.id.trim()?e.id:void 0}function Yt(e){switch(e){case"metric":return"semaphor.metric";case"records":return"semaphor.records";case"matrix":return"semaphor.matrix";case"analysis":return"semaphor.analysis";case"inputOptions":return"semaphor.inputOptions";case"sql":return"semaphor.sql";default:return he(e)}}function he(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function Xt(e){if(Zt(e))return;const r=e.value;if(r!==void 0){if(Array.isArray(r)){const t=r.filter(n=>typeof n=="string"||typeof n=="number"||typeof n=="boolean").map(n=>String(n));if(t.length===r.length&&t.length>0){const n=t.slice(0,3).join(", "),s=t.length>3?`, +${t.length-3} more`:"";return rr(`${n}${s}`)}return`${r.length} selected`}return typeof r=="number"||typeof r=="boolean"?String(r):typeof r=="string"?rr(r):r&&typeof r=="object"?`object(${Object.keys(r).slice(0,5).join(",")})`:String(r)}}function rr(e){return e.length>80?`${e.slice(0,77)}...`:e}function Zt(e){var t;const r=[e.inputId,e.label,(t=e.field)==null?void 0:t.name].filter(Boolean).join(" ").toLowerCase();return["token","secret","password","email","phone","ssn"].some(n=>r.includes(n))}function en(e){const r=[];return me(e,t=>{sn(t)&&r.push(t)}),or.mergeSemaphorSourcesByIdentity(r)}function rn(e){switch(e.queryKind){case"metric":case"analysis":return Q([...e.measures||[],e.primaryMeasure,e.dateField,...e.dimensions||[]]);case"records":return Q(e.fields||[]);case"inputOptions":return Q([e.labelField,e.valueField,e.searchField,...e.disambiguationFields||[]]);case"sql":return Q(e.fields||[]);case"matrix":return Q([...(e.rows||[]).map(je),...(e.columns||[]).map(je),...(e.values||[]).map(je)]);default:return he(e)}}function tn(e,r){const t=[...(e.inputs||[]).map(wr),...(r||[]).map(n=>n.field)];return Q(t)}function Q(e){const r=new Map;return e.forEach(t=>{t&&oe(t)&&r.set(Me(t),t)}),[...r.values()]}function wr(e){if(!e||typeof e!="object")return;const r=e.toAnalyticsInput;if(typeof r=="function"){const n=r.call(e);return wr(n)}const t=e.field;return oe(t)?t:void 0}function je(e){if(oe(e))return e;if(!e||typeof e!="object")return;const r=e.field;return oe(r)?r:void 0}function nn(e){const r=new Map;return me(e,t=>{oe(t)&&r.set(Me(t),t)}),[...r.values()]}function me(e,r){if(!(!e||typeof e!="object")){if(r(e),Array.isArray(e)){e.forEach(t=>me(t,r));return}Object.values(e).forEach(t=>me(t,r))}}function sn(e){if(!e||typeof e!="object")return!1;const r=e;return r.kind==="semantic"?typeof r.domainId=="string"&&typeof r.datasetName=="string":r.kind==="physical"?typeof r.connectionId=="string"&&typeof r.tableName=="string":r.kind==="sql"?typeof r.connectionId=="string":!1}function oe(e){if(!e||typeof e!="object")return!1;const r=e;return typeof r.name=="string"&&(r.source!==void 0||r.role!==void 0||r.dataType!==void 0||r.aggregate!==void 0)}function Me(e){return[e.name,e.role,e.aggregate,e.source?or.semaphorSourceIdentityKey(e.source):""].join(":")}function on(e){const r=e;return typeof(r==null?void 0:r.rowCount)=="number"?r.rowCount:Array.isArray(r==null?void 0:r.records)?r.records.length:void 0}function an(e){const r=e;return Array.isArray(r==null?void 0:r.columns)?r.columns.length:void 0}function tr(e){const r=e;return r==null?void 0:r.executionResult}function nr(e){const r=e;return typeof(r==null?void 0:r.requestId)=="string"?r.requestId:void 0}function qr(e){let r=2166136261;for(let t=0;t<e.length;t+=1)r^=e.charCodeAt(t),r=Math.imul(r,16777619);return(r>>>0).toString(36)}function fe(){return new Date().toISOString()}function Ne(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const dn=["primary","comparisons","contributors","segments","periodChanges","records","changes","drivers","absoluteDeltaDrivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"],ln=["primary","records","periodChanges","changes","comparisons","contributors","segments","drivers","absoluteDeltaDrivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"];function jr(e){if(!e)return{};const r=mn(e.executionResult),t=un(e,r),n=pn(t),s=Ar(ze(e.analysisWarnings),vn(t));return{...e,...Object.keys(t).length?{resultSets:t}:{},...s.length?{analysisWarnings:s}:{},...n?{columns:n.columns,records:n.records,rowCount:n.rowCount}:{}}}function un(e,r){const t=cn(e.resultSets);for(const s of dn){if(t[s])continue;const o=yn(e[s]);if(!o.length)continue;const u=r.length?r:hn(o);t[s]={id:s,role:s,...Fe({records:o,columns:u,resultSetKey:s}),columns:u,rowCount:o.length}}const n=gn(e.executionResult);return n&&n.records.length>0&&!t.records&&(t.records=n),t}function cn(e){return Object.fromEntries(Object.entries(e||{}).map(([r,t])=>[r,fn(t,r)]))}function fn(e,r=e.id||e.role||"resultSet"){var n;const t=Fe({records:e.records||[],columns:e.columns||[],resultSetKey:r});return{...e,...t,...e.warnings||t.warnings?{warnings:Ar(ze(e.warnings),t.warnings)}:{},rowCount:e.rowCount??((n=e.records)==null?void 0:n.length)??0}}function pn(e){var r;for(const t of ln)if((r=e[t])!=null&&r.records.length)return e[t];return Object.values(e).find(t=>t.records.length)||Object.values(e)[0]}function gn(e){const r=e==null?void 0:e.result;if(!(!r||r.kind!=="records"&&r.kind!=="sql"))return{id:"records",role:"records",...Fe({records:r.records,columns:r.columns,resultSetKey:"records"}),columns:r.columns,rowCount:r.rowCount??r.records.length}}function mn(e){const r=e==null?void 0:e.result;return!r||r.kind!=="records"&&r.kind!=="sql"?[]:r.columns}function yn(e){return Array.isArray(e)?e.filter(r=>!!(r&&typeof r=="object"&&!Array.isArray(r))):[]}function Fe({records:e,columns:r,resultSetKey:t}){if(!r.length)return{records:e};const n=[];return{records:e.map((o,u)=>{const p={};return r.forEach(d=>{if(Object.prototype.hasOwnProperty.call(o,d.key)){p[d.key]=o[d.key];return}n.push({code:"missing_analysis_result_key",severity:"warning",resultSetKey:t,rowIndex:u,columnKey:d.key,...d.name?{columnName:d.name}:{},...d.label?{columnLabel:d.label}:{},availableKeys:Object.keys(o),message:`Analysis result set "${t}" row ${u} is missing column key "${d.key}". Rows must expose values by column.key; labels and column names are display metadata only.`})}),p}),...n.length?{warnings:n}:{}}}function hn(e){return Array.from(new Set(e.flatMap(t=>Object.keys(t)))).map(t=>({key:t,name:t,label:t}))}function vn(e){return Object.values(e).flatMap(r=>ze(r.warnings))}function ze(e){return Array.isArray(e)?e.filter(bn):[]}function bn(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Ar(...e){const r=new Set,t=[];for(const n of e.flatMap(s=>s||[])){const s=xn(n);r.has(s)||(r.add(s),t.push(n))}return t}function xn(e){return e.code==="missing_analysis_result_key"?[e.code,e.resultSetKey,e.rowIndex,e.columnKey].join(":"):De(e)}function De(e){if(!e||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t=>De(t)).join(",")}]`;const r=e;return`{${Object.keys(r).sort().map(t=>`${JSON.stringify(t)}:${De(r[t])}`).join(",")}}`}const Ae={value:null},Ce={},Sn={records:[]},Ee={options:[]},In={records:[]},ke={};function wn(e){const r=I.toSemaphorActiveInputSnapshots(e.inputs),t=I.toSemaphorAnalysisQueryOptions(e);try{const n=I.toSemaphorAnalysisIntent(e),s=G(n,"analysis");return s?{error:s,activeInputs:r,analysisOptions:t,queryKey:q(void 0,r,s,t),idleData:Ce}:{intent:n,error:null,activeInputs:r,analysisOptions:t,queryKey:q(n,r,void 0,t),idleData:Ce}}catch(n){const s=U(n,"analysis");return{error:s,activeInputs:r,analysisOptions:t,queryKey:q(void 0,r,s,t),idleData:Ce}}}function qn(e){const r=I.toSemaphorActiveInputSnapshots(e.inputs);try{const t=I.toSemaphorMetricIntent(e),n=G(t);return n?{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:Ae}:{intent:t,error:null,activeInputs:r,queryKey:q(t,r),idleData:Ae}}catch(t){const n=U(t,"metric");return{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:Ae}}}function jn(e){const r=I.toSemaphorActiveInputSnapshots(e.inputs),t=Sn;try{const n=I.toSemaphorRecordsIntent(e),s=G(n);return s?{error:s,activeInputs:r,queryKey:q(void 0,r,s),idleData:t}:{intent:n,error:null,activeInputs:r,queryKey:q(n,r),idleData:t}}catch(n){const s=U(n,"records");return{error:s,activeInputs:r,queryKey:q(void 0,r,s),idleData:t}}}function An(e){const r=I.toSemaphorActiveInputSnapshots(e.inputs);try{const t=I.toSemaphorInputOptionsIntent(e),n=G(t);return n?{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:Ee}:{intent:t,error:null,activeInputs:r,queryKey:q(t,r),idleData:Ee}}catch(t){const n=U(t,"inputOptions");return{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:Ee}}}function Cn(e){const r=I.toSemaphorActiveInputSnapshots(e.inputs),t=In;try{const n=I.toSemaphorSqlIntent(e),s=G(n);return s?{error:s,activeInputs:r,queryKey:q(void 0,r,s),idleData:t}:{intent:n,error:null,activeInputs:r,queryKey:q(n,r),idleData:t}}catch(n){const s=U(n,"sql");return{error:s,activeInputs:r,queryKey:q(void 0,r,s),idleData:t}}}function En(e){const r=I.toSemaphorActiveInputSnapshots(e.inputs);try{const t=I.toSemaphorMatrixIntent(e),n=G(t);return n?{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:ke}:{intent:t,error:null,activeInputs:r,queryKey:q(t,r),idleData:ke}}catch(t){const n=U(t,"matrix");return{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:ke}}}function Le(e){var o;if(kn(e))return e;const r=e instanceof Error?e:void 0,t=e,n=t==null?void 0:t.executionResult,s=ve((r==null?void 0:r.message)??String(e),{requestId:typeof(t==null?void 0:t.requestId)=="string"?t.requestId:void 0,details:t==null?void 0:t.details,executionResult:n,validation:(t==null?void 0:t.validation)??(n==null?void 0:n.validation),validationIssues:(t==null?void 0:t.validationIssues)??((o=n==null?void 0:n.validation)==null?void 0:o.errors)});return s.name=(r==null?void 0:r.name)||s.name,s.stack=r==null?void 0:r.stack,s}function U(e,r){const t=Le(e);if(t.executionResult||t.validation)return t;const n={ok:!1,errors:[{code:"invalid_query_spec",message:t.message,path:"spec"}],warnings:[],repairHints:[{code:"invalid_query_spec",message:t.message,recommendedNextStep:"Update the Data App query spec to satisfy the SDK builder contract."}]},s=Cr(void 0,r,n),o=ve(t.message,{executionResult:s,validation:n,validationIssues:n.errors});return o.stack=t.stack,o}function ve(e,r={}){var s,o,u;const t=new Error(e);t.name="SemaphorDataAppQueryError",t.kind="data_app_query_error",r.requestId&&(t.requestId=r.requestId),r.details!==void 0&&(t.details=r.details),r.executionResult!==void 0&&(t.executionResult=r.executionResult),r.validation!==void 0&&(t.validation=r.validation);const n=r.validationIssues??((s=r.validation)==null?void 0:s.errors)??((u=(o=r.executionResult)==null?void 0:o.validation)==null?void 0:u.errors);return n!==void 0&&(t.validationIssues=n),t}function kn(e){return e instanceof Error&&e.kind==="data_app_query_error"}function G(e,r=e.kind){const t=Lr.validateSemaphorAnalyticsIntent(e);if(t.ok)return null;const n=t.errors.map(o=>o.path?`${o.code} at ${o.path}: ${o.message}`:`${o.code}: ${o.message}`).join("; "),s=Cr(e,r,t);return ve(`Invalid Semaphor analytics intent. ${n}`,{executionResult:s,validation:t,validationIssues:t.errors})}function Cr(e,r,t){return{...e!=null&&e.id?{intentId:e.id}:{},...e?{intent:e}:{},status:"failed",resultShape:r,validation:t,coverage:{answeredObligations:[],missingObligations:["query_spec_validation"],warnings:t.warnings},missingFields:t.errors.filter(n=>n.code==="missing_field").flatMap(n=>{var o;const s=n.path||((o=n.repairHint)==null?void 0:o.invalidField);return s?[s]:[]}),warnings:t.warnings.map(n=>n.message),diagnosticFeedback:{version:1,status:"blocked",summary:"Data App query spec validation failed.",answered:[],blocked:t.errors.map(n=>{var o,u;const s={reasonCode:"query_validation_failed",message:n.message};return n.code==="missing_field"&&(s.missingFields=[n.path||((o=n.repairHint)==null?void 0:o.invalidField)||n.message]),(u=n.repairHint)!=null&&u.recommendedNextStep&&(s.recommendedNextStep=n.repairHint.recommendedNextStep),s})},metadata:{validationKind:"data_app_sdk_query_spec"}}}function q(e,r,t,n){return JSON.stringify({intent:e,activeInputs:r,analysisOptions:n,error:t==null?void 0:t.message})}function Er(){return{executeAnalysis:(e,r,t)=>P(e,r,t??{}).then(jr),executeMetric:(e,r)=>P(e,r),executeRecords:(e,r)=>P(e,r),executeInputOptions:(e,r)=>P(e,r),executeSql:(e,r)=>P(e,r),executeMatrix:(e,r)=>P(e,r)}}async function P(e,r,t){if(!r.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const n=Kn(r),s=Dn(e,n);let o;try{o=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.token}`},body:JSON.stringify({intent:e,activeInputs:r.activeInputs,...t?{analysisOptions:t}:{},resultShape:e.kind,...Rn(r)?{debug:{responseDetail:"debug"}}:{}})})}catch(p){throw new Error(`${s}: ${p instanceof Error?p.message:String(p)}`)}const u=await Bn(o);if(!o.ok||u.error)throw Tn(`${s}: ${u.error||`Semaphor Data App execution failed with status ${o.status}.`}`,u);return u}function Tn(e,r){var t;return ve(e,{requestId:r.requestId,details:r.details,executionResult:r.executionResult,validation:(t=r.executionResult)==null?void 0:t.validation})}function Rn(e){const r=e.debug;return r?r===!0?!0:r.enabled!==!1&&r.requestServerDebug!==!1:!1}function Dn(e,r){return[`Semaphor ${e.kind} query`,e.id?`id=${e.id}`:void 0,e.label?`label=${e.label}`:void 0,Ln(e),`endpoint=${On(r)}`].filter(t=>!!t).join(" ")}function Ln(e){const r="source"in e?e.source:void 0;if(!(!r||typeof r!="object")){if(r.kind==="semantic")return`source=${[r.domainId,r.datasetId||r.datasetName].filter(Boolean).join("/")}`;if(r.kind==="physical")return`source=${[r.connectionId,r.databaseName,r.schemaName,r.tableName].filter(Boolean).join("/")}`;if(r.kind==="sql")return r.connectionId?`source=${r.connectionId}`:void 0}}function On(e){if(!e)return"/api/v1/data-app/execute";try{return new URL(e,"http://localhost").pathname}catch{return e}}async function Bn(e){const r=await e.text().catch(()=>"");if(!r.trim())return e.ok?{error:"Semaphor Data App execution returned an empty response."}:{};try{return JSON.parse(r)}catch{return e.ok?{error:"Semaphor Data App execution returned invalid JSON.",details:r}:{error:$n(e,r),details:r}}}function $n(e,r){const t=e.statusText?` ${e.statusText}`:"",n=r.replace(/\s+/g," ").trim();return n?`Semaphor Data App execution failed with status ${e.status}${t}: ${n.slice(0,240)}`:`Semaphor Data App execution failed with status ${e.status}${t}.`}function Kn(e){const r=Wn(e).replace(/\/+$/,"");return r?r.endsWith("/api")?`${r}/v1/data-app/execute`:`${r}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function Wn(e){if(e.apiBaseUrl)return e.apiBaseUrl;if(!e.token)return"";try{return Oe.jwtDecode(e.token).apiServiceUrl||""}catch{return""}}const kr=c.createContext({});function _n(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function Mn(){return c.useContext(kr)}function Nn(e){const[r,t]=c.useState(e.defaultValue),n=Object.prototype.hasOwnProperty.call(e,"value"),s=n?e.value:r,o=c.useMemo(()=>I.normalizeSemaphorInputOptions(e.options),[e.options]),u=c.useCallback(d=>{var m;const f=d;(m=e.onValueChange)==null||m.call(e,f),n||t(f)},[n,e]),p=c.useCallback(()=>u(void 0),[u]);return c.useMemo(()=>{const d=I.toSemaphorInputSpec(e);return{id:e.id,kind:e.kind,label:e.label,field:d.field,operator:d.operator,relationshipHint:d.relationshipHint,controlRole:e.kind==="control"?e.role:void 0,value:s,options:o,isActive:I.hasSemaphorInputValue(s),setValue:u,clear:p,toAnalyticsInput:()=>({inputId:d.inputId,field:d.field,kind:e.kind,label:e.label,value:s,isActive:I.hasSemaphorInputValue(s),operator:d.operator,relationshipHint:d.relationshipHint,controlRole:e.kind==="control"?e.role:void 0})}},[p,o,u,e,s])}function Fn(e){const[r,t]=c.useState(()=>Jn(e));return c.useEffect(()=>{t(n=>{let s=n;for(const o of e)!Object.prototype.hasOwnProperty.call(s,o.id)&&o.defaultValue!==void 0&&(s={...s,[o.id]:o.defaultValue});return s})},[e]),c.useMemo(()=>e.map(n=>{const s=Object.prototype.hasOwnProperty.call(n,"value"),o=s?n.value:r[n.id],u=I.normalizeSemaphorInputOptions(n.options),p=m=>{var v;(v=n.onValueChange)==null||v.call(n,m),s||t(x=>({...x,[n.id]:m}))},d=()=>p(void 0),f=I.toSemaphorInputSpec(n);return{id:n.id,kind:n.kind,label:n.label,field:f.field,operator:f.operator,relationshipHint:f.relationshipHint,controlRole:n.kind==="control"?n.role:void 0,value:o,options:u,isActive:I.hasSemaphorInputValue(o),setValue:p,clear:d,toAnalyticsInput:()=>({inputId:f.inputId,field:f.field,kind:n.kind,label:n.label,value:o,isActive:I.hasSemaphorInputValue(o),operator:f.operator,relationshipHint:f.relationshipHint,controlRole:n.kind==="control"?n.role:void 0})}}),[e,r])}function zn(e,r){const t=(r==null?void 0:r.status)==="success"?r.options:void 0,n=c.useMemo(()=>Hn(t),[t]);c.useEffect(()=>{Tr(e.value,t)||e.clear()},[e,n,r==null?void 0:r.status,t])}function Tr(e,r){if(!I.hasSemaphorInputValue(e)||r===void 0)return!0;const t=new Set(r.map(s=>sr(s.value)));return(Array.isArray(e)?e:[e]).every(s=>t.has(sr(s)))}function Hn(e){return JSON.stringify((e||[]).map(r=>r.value))}function sr(e){return`${typeof e}:${String(e)}`}function Pn(e,r={}){const t=c.useMemo(()=>r.inputs?{...e,inputs:r.inputs}:e,[r.inputs,e]),n=c.useMemo(()=>{switch(t.queryKind){case"metric":return{queryKind:t.queryKind,request:qn(t)};case"analysis":return{queryKind:t.queryKind,request:wn(t)};case"records":return{queryKind:t.queryKind,request:jn(t)};case"inputOptions":return{queryKind:t.queryKind,request:An(t)};case"sql":return{queryKind:t.queryKind,request:Cn(t)};case"matrix":return{queryKind:t.queryKind,request:En(t)};default:return ge(t)}},[t]),s=Hr({spec:t,queryKind:n.queryKind,queryKey:n.request.queryKey,intent:n.request.intent,activeInputs:n.request.activeInputs,debug:r.debug}),o=c.useRef(null),u=c.useMemo(()=>({start:s.start,success:s.success,failure:s.failure,ignored:s.ignored}),[s.failure,s.ignored,s.start,s.success]),p=c.useCallback(l=>{var L,A,O,R,h,S,T,w,j;const y=n.request;if(y.intent)switch(n.queryKind){case"metric":return(L=l.executor)==null?void 0:L.executeMetric(y.intent,l);case"analysis":return(O=(A=l.executor)==null?void 0:A.executeAnalysis)==null?void 0:O.call(A,y.intent,l,y.analysisOptions);case"records":return(R=l.executor)==null?void 0:R.executeRecords(y.intent,l);case"inputOptions":return(h=l.executor)==null?void 0:h.executeInputOptions(y.intent,l);case"sql":return(T=(S=l.executor)==null?void 0:S.executeSql)==null?void 0:T.call(S,y.intent,l);case"matrix":return(j=(w=l.executor)==null?void 0:w.executeMatrix)==null?void 0:j.call(w,y.intent,l);default:return ge(n)}},[n]),d=Gn(n.request.queryKey,p,n.request.idleData,n.request.activeInputs,u),f=s.queryId,m=s.validationFailure;c.useEffect(()=>{const l=n.request.error;if(!l){o.current=null;return}const y=`${f}:${l.message}`;o.current!==y&&(o.current=y,m(l))},[n.request.error,n.request.queryKey,f,m]);const v=n.request.error?n.request.idleData:d.data,x=n.request.error?"error":d.status,g=!n.request.error&&d.status==="loading",b=n.request.error||d.error,k=s.trace;switch(n.queryKind){case"metric":{const l=v,y=V({queryKind:n.queryKind,status:x,isLoading:g,error:b,trace:k,payload:l,activeInputs:n.request.activeInputs,isStale:d.isStale});return{id:t.id,intent:n.request.intent,value:(l==null?void 0:l.value)??null,measures:l==null?void 0:l.measures,comparisonValue:l==null?void 0:l.comparisonValue,delta:l==null?void 0:l.delta,deltaPercent:l==null?void 0:l.deltaPercent,records:l==null?void 0:l.records,...y}}case"analysis":{const l=jr(v),y=V({queryKind:n.queryKind,status:x,isLoading:g,error:b,trace:k,payload:l,activeInputs:n.request.activeInputs,isStale:d.isStale});return{id:t.id,intent:n.request.intent,...l||{},...y}}case"records":{const l=v,y=V({queryKind:n.queryKind,status:x,isLoading:g,error:b,trace:k,payload:l,activeInputs:n.request.activeInputs,isStale:d.isStale});return{id:t.id,intent:n.request.intent,records:(l==null?void 0:l.records)||[],columns:l==null?void 0:l.columns,rowCount:l==null?void 0:l.rowCount,pagination:l==null?void 0:l.pagination,...y}}case"inputOptions":{const l=v,y=V({queryKind:n.queryKind,status:x,isLoading:g,error:b,trace:k,payload:l,activeInputs:n.request.activeInputs,isStale:d.isStale});return{id:t.id,intent:n.request.intent,options:(l==null?void 0:l.options)||[],...y}}case"sql":{const l=v,y=V({queryKind:n.queryKind,status:x,isLoading:g,error:b,trace:k,payload:l,activeInputs:n.request.activeInputs,isStale:d.isStale});return{id:t.id,intent:n.request.intent,records:(l==null?void 0:l.records)||[],columns:l==null?void 0:l.columns,rowCount:l==null?void 0:l.rowCount,pagination:l==null?void 0:l.pagination,output:l==null?void 0:l.output,rowLimitExceeded:l==null?void 0:l.rowLimitExceeded,...y}}case"matrix":{const l=v,y=V({queryKind:n.queryKind,status:x,isLoading:g,error:b,trace:k,payload:l,activeInputs:n.request.activeInputs,isStale:d.isStale});return{id:t.id,intent:n.request.intent,matrixResult:l==null?void 0:l.matrixResult,grid:l==null?void 0:l.grid,expansion:l==null?void 0:l.expansion,...y}}default:return ge(n)}}function V(e){var o,u,p;const r=Vn(e.payload)??((o=e.error)==null?void 0:o.executionResult),t=((u=e.error)==null?void 0:u.validation)??(r==null?void 0:r.validation),n=r==null?void 0:r.coverage,s=r==null?void 0:r.diagnosticFeedback;return{status:e.status,executionStatus:r==null?void 0:r.status,executionResult:r,validation:t,coverage:n,diagnosticFeedback:s,isLoading:e.isLoading,isEmpty:Un(e.queryKind,e.payload,e.status),isPartial:Qn(e.payload,r),isFiltered:!!((p=e.activeInputs)!=null&&p.some(d=>d.kind==="filter"&&d.isActive)),isStale:e.isStale,isValidated:!!t,error:e.error,trace:e.trace}}function Vn(e){const r=e;return r==null?void 0:r.executionResult}function Qn(e,r){var n,s;const t=!!(e!=null&&e.rowLimitExceeded);return!!((r==null?void 0:r.status)==="partial"||((n=r==null?void 0:r.diagnosticFeedback)==null?void 0:n.status)==="partial"||(r==null?void 0:r.status)!=="failed"&&((s=r==null?void 0:r.coverage)!=null&&s.missingObligations.length)||t)}function Un(e,r,t){var n,s,o,u,p;if(t!=="success")return!1;switch(e){case"metric":{const d=r;return(d==null?void 0:d.value)==null&&!D(d==null?void 0:d.records)}case"analysis":{const d=r;return d?!d.answerSummary&&!D(d.records)&&!D(d.changes)&&!D(d.drivers)&&!D(d.largestNegativeChanges)&&!D(d.largestPositiveChanges)&&!D(d.largestNegativeDrivers)&&!D(d.largestPositiveDrivers)&&!Object.values(d.resultSets||{}).some(f=>D(f.records)):!0}case"records":{const d=r;return!D(d==null?void 0:d.records)}case"sql":{const d=r;return!D(d==null?void 0:d.records)&&(d==null?void 0:d.output)===void 0}case"inputOptions":{const d=r;return!((n=d==null?void 0:d.options)!=null&&n.length)}case"matrix":{const d=r;return!((o=(s=d==null?void 0:d.matrixResult)==null?void 0:s.cells)!=null&&o.length)&&!((p=(u=d==null?void 0:d.grid)==null?void 0:u.cells)!=null&&p.length)}default:return ge(e)}}function D(e){return Array.isArray(e)&&e.length>0}function Gn(e,r,t,n,s){const o=Mn(),u=c.useRef(r),p=c.useRef(n),[d,f]=c.useState({status:"idle",data:t,error:null,isStale:!1});return u.current=r,p.current=n,c.useEffect(()=>{let m;try{m=u.current({...o,activeInputs:p.current})}catch(g){s==null||s.failure(g,0),f({status:"error",data:t,error:Le(g),isStale:!1});return}if(!m){f({status:"idle",data:t,error:null,isStale:!1});return}let v=!1;const x=Rr();return s==null||s.start(),f(g=>({status:"loading",data:g.data,error:null,isStale:g.isStale||g.status==="success"})),m.then(g=>{v?s==null||s.ignored("superseded"):(s==null||s.success(g,ir(x)),f({status:"success",data:g,error:null,isStale:!1}))}).catch(g=>{v?s==null||s.ignored("superseded"):(s==null||s.failure(g,ir(x)),f({status:"error",data:t,error:Le(g),isStale:!1}))}),()=>{v=!0}},[t,e,o,s]),d}function Rr(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}function ir(e){return Math.max(0,Math.round(Rr()-e))}function Jn(e){return Object.fromEntries(e.filter(r=>r.defaultValue!==void 0).map(r=>[r.id,r.defaultValue]))}function ge(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function Yn(e){return!e||typeof e=="boolean"||e.enabled===!1?null:e.autoRenderDevtools===!0?{}:e.autoRenderDevtools?e.autoRenderDevtools:null}function Xn({token:e,apiBaseUrl:r,executor:t,debug:n,children:s}){var g;const o=_n(),u=((g=o==null?void 0:o.authToken)==null?void 0:g.accessToken)||e,p=(o==null?void 0:o.dataApiBaseUrl)||(o==null?void 0:o.apiBaseUrl)||r,d=(o==null?void 0:o.debug)??n,f=Yn(d),m=c.useMemo(()=>Er(),[]),v=t||m,x=c.useMemo(()=>({token:u,apiBaseUrl:p,executor:v,debug:d}),[p,d,v,u]);return i.jsx(_r,{debug:d,children:i.jsxs(kr.Provider,{value:x,children:[s,f?i.jsx(lr,{...f}):null]})})}exports.SemaphorDataAppProvider=Xn;exports.SemaphorDevtools=lr;exports.SemaphorDevtoolsInspectButton=zr;exports.SemaphorViewBoundary=Fr;exports.createSemaphorQueryExecutor=Er;exports.defineSemaphorDataApp=Or;exports.defineSemaphorInput=Br;exports.isSemaphorInputValueValidForOptions=Tr;exports.semaphor=$r;exports.useClearInvalidSemaphorInputValue=zn;exports.useSemaphorDevtools=We;exports.useSemaphorInput=Nn;exports.useSemaphorInputs=Fn;exports.useSemaphorQuery=Pn;