react-semaphor 0.1.389 → 0.1.391

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.
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("../data-app-sdk-adapters/index.cjs"),i=require("react/jsx-runtime"),l=require("react"),se=require("../chunks/search-Dq1Mbb03.js"),Ye=require("../chunks/x-B_cx7LwM.js"),Sr=require("../chunks/validators-lWo8m0Q7.js");require("../chunks/analyze-result-contract-CtXfp3nv.js");function te(e,r,t={}){return{...t,name:e,role:r}}function Ir(e){return e}function wr(e){return e}const qr={source:{semantic(e){return{...e,kind:"semantic"}},sql(e){return{...e,kind:"sql"}}},field:{measure(e,r){return te(e,"measure",r)},dimension(e,r){return te(e,"dimension",r)},date(e,r){return te(e,"date",r)},id(e,r){return te(e,"id",r)}},filter(e){return{...e,kind:"filter"}},bindInput(e,r){return{toAnalyticsInput(){const[t]=x.toSemaphorInputSnapshots([e]),n=x.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"}}},fe=10,pe=100,jr=25,Rr=500,Xe={enabled:!1,queries:[],getQuery:()=>{},getQueries:()=>[]},je=l.createContext(null),Re=l.createContext(null),Ae=l.createContext(void 0),_=[];function Ar({debug:e,children:r}){const t=l.useMemo(()=>Lt(e),[e]),[n,o]=l.useReducer(wt,t,dr),d=l.useRef(n),u=l.useId(),[f,c]=l.useState({open:!1});d.current=n,l.useEffect(()=>{o({type:"config",config:t})},[t]),l.useEffect(()=>{if(!n.enabled||!n.exposeWindowBridge||typeof window>"u")return;const b=Ct(()=>d.current);return Er({ownerId:u,bridge:b}),()=>{Cr(u)}},[u,n.enabled,n.exposeWindowBridge]);const p=l.useMemo(()=>({state:n,dispatch:o}),[n]),g=l.useCallback(b=>{c({open:!0,focus:b})},[]),h=l.useCallback(()=>{c(b=>({...b,open:!1}))},[]),y=l.useCallback(b=>{c({open:!0,focus:b})},[]),m=l.useMemo(()=>({open:f.open,focus:f.focus,openDevtools:g,closeDevtools:h,focusTrace:y}),[h,y,g,f.focus,f.open]);return i.jsx(je.Provider,{value:p,children:i.jsx(Re.Provider,{value:m,children:r})})}function Er(e){const r=_.findIndex(t=>t.ownerId===e.ownerId);r>=0&&_.splice(r,1),_.push(e),Ze()}function Cr(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 Tr({id:e,title:r,children:t}){const n=l.useMemo(()=>({id:e,title:r}),[e,r]);return i.jsx(Ae.Provider,{value:n,children:t})}function er({buttonPosition:e="bottom-right",initialIsOpen:r=!1,panelPosition:t="right",className:n,style:o}={}){const d=Ee(),u=l.useContext(Re),[f,c]=l.useState(""),[p,g]=l.useState(!1),h=l.useRef(null),y=l.useRef(null),m=u==null?void 0:u.openDevtools,b=u==null?void 0:u.closeDevtools,C=(u==null?void 0:u.open)===!0;l.useEffect(()=>{ar()},[]),l.useEffect(()=>{r&&d.enabled&&(m==null||m())},[r,d.enabled,m]),l.useEffect(()=>{if(!C||!b)return;const v=S=>{var w,A;const R=S.target;R instanceof Node&&((w=h.current)!=null&&w.contains(R)||(A=y.current)!=null&&A.contains(R)||b())};return document.addEventListener("pointerdown",v,!0),document.addEventListener("mousedown",v,!0),document.addEventListener("click",v,!0),()=>{document.removeEventListener("pointerdown",v,!0),document.removeEventListener("mousedown",v,!0),document.removeEventListener("click",v,!0)}},[b,C]);const a=l.useMemo(()=>Ur(d.queries),[d.queries]),I=Gr(a),T=l.useMemo(()=>Jr(d.queries,f),[d.queries,f]),k=l.useMemo(()=>Yr(T),[T]),D=l.useMemo(()=>rr(T,u==null?void 0:u.focus)||T[0],[T,u==null?void 0:u.focus]);return!d.enabled||!u?null:i.jsxs(i.Fragment,{children:[i.jsxs("button",{ref:h,type:"button","aria-label":"Open Semaphor Inspector",title:I,className:n?`${O} ${n}`:O,style:{...s.launcher,...ht(e),...yt(a.severity),...o},onClick:()=>u.openDevtools(),children:[i.jsx(Lr,{}),i.jsx("span",{style:s.launcherText,children:a.total}),a.issueCount>0?i.jsxs("span",{style:s.launcherIssueCount,children:[a.issueCount," issue",a.issueCount===1?"":"s"]}):null]}),u.open?i.jsxs("div",{ref:y,role:"dialog","aria-label":"Semaphor Inspector","aria-modal":"false",className:O,style:{...s.panel,...vt(t),...p?s.panelFullscreen:null},children:[i.jsxs("div",{style:s.panelHeader,children:[i.jsxs("div",{style:s.panelTitleBlock,children:[i.jsx("div",{style:s.panelTitle,children:"Semaphor Inspector"}),i.jsxs("div",{style:s.panelSubtitle,children:[a.total," queries · ",a.loading," loading ·"," ",a.failed," failed"]})]}),i.jsxs("div",{style:s.panelActions,children:[i.jsx("button",{type:"button","aria-label":p?"Exit fullscreen Semaphor Inspector":"Enter fullscreen Semaphor Inspector",title:p?"Exit fullscreen Semaphor Inspector":"Enter fullscreen Semaphor Inspector",style:s.iconButton,onClick:()=>g(v=>!v),children:p?i.jsx(se.Minimize2,{size:15}):i.jsx(se.Maximize2,{size:15})}),i.jsx("button",{type:"button","aria-label":"Close Semaphor Inspector",style:s.iconButton,onClick:u.closeDevtools,children:i.jsx(Ye.X,{size:15})})]})]}),i.jsxs("label",{style:s.searchBox,children:[i.jsx(se.Search,{size:14}),i.jsx("input",{"aria-label":"Search Semaphor traces",value:f,onChange:v=>c(v.currentTarget.value),placeholder:"Search traces",style:s.searchInput})]}),i.jsxs("div",{style:{...s.panelBody,...bt(t)},children:[i.jsx("div",{style:{...s.queryList,...xt()},"aria-label":"Registered queries",children:T.length?k.map(v=>i.jsxs("div",{style:s.queryGroup,children:[i.jsxs("div",{style:s.queryGroupHeader,children:[i.jsx("span",{children:v.title}),i.jsx("span",{style:s.queryGroupCount,children:v.traces.length})]}),v.traces.length?v.traces.map(S=>{var j;const R=Zr(S,D),w=Ce(S),A=ir(S),N=or(S),Q=rt(S,w,N),U=Q.join(" · "),ee=tr(A);return i.jsxs("button",{type:"button",title:`${w} · ${A} · ${U}`,style:{...s.queryListItem,...R?s.queryListItemSelected:null},onClick:()=>u.focusTrace({traceId:S.traceId,queryId:S.queryId,viewId:S.viewId}),children:[i.jsxs("span",{style:s.queryListItemHeader,children:[i.jsx(Br,{status:(j=S.latestAttempt)==null?void 0:j.status}),i.jsx("span",{style:s.queryListTitle,title:w,children:w}),i.jsx("span",{style:{...s.queryListKindChip,...nr(ee)},children:A})]}),i.jsx("span",{className:`${O}-source`,style:s.queryListSource,title:U,children:Q.map(($,G)=>i.jsxs(l.Fragment,{children:[G>0?i.jsx("span",{style:s.queryListSubtitleSep,children:" · "}):null,i.jsx("span",{children:$})]},`${$}:${G}`))})]},we(S))}):i.jsx("div",{style:s.queryGroupEmpty,children:"No input traces"})]},v.title)):i.jsx("div",{style:s.emptyState,children:"No matching traces"})}),i.jsx(Or,{trace:D})]})]}):null]})}function kr({queryId:e,viewId:r,label:t,className:n,style:o}={}){var h,y;const d=Ee(),u=l.useContext(Re),f=l.useContext(Ae);l.useEffect(()=>{ar()},[]);const c=r||(f==null?void 0:f.id),p=l.useMemo(()=>Xr(d.queries,{queryId:e,viewId:c}),[d.queries,e,c]);if(!d.enabled||!u||!p)return null;const g=t||`Inspect ${tt(p,!!e)}`;return i.jsxs("button",{type:"button","aria-label":g,title:g,className:n?`${O} ${n}`:O,style:{...s.inspectButton,...St((h=p.latestAttempt)==null?void 0:h.status),...o},onClick:()=>u.openDevtools({traceId:p.traceId,queryId:p.queryId,viewId:p.viewId}),children:[i.jsx(se.Eye,{size:13}),i.jsx("span",{style:s.inspectButtonText,children:((y=p.latestAttempt)==null?void 0:y.status)||"idle"})]})}function Ee(){const e=l.useContext(je);return!e||!e.state.enabled?Xe:de(e.state)}function Dr({spec:e,queryKind:r,queryKey:t,intent:n,activeInputs:o,debug:d}){const u=l.useContext(je),f=l.useContext(Ae),c=!!(u!=null&&u.state.enabled),p=u==null?void 0:u.dispatch,g=Bt(e),h=e.label,y=l.useMemo(()=>JSON.stringify(e),[e]),m=l.useMemo(()=>JSON.stringify(o||[]),[o]),b=l.useMemo(()=>JSON.stringify(n||null),[n]),C=l.useRef(e),a=l.useRef(y),I=l.useRef(n),T=l.useRef(b),k=l.useRef(o),D=l.useRef(m),v=Ot(d),S=JSON.stringify(v||[]),R=l.useRef(v),w=l.useRef(S);a.current!==y&&(a.current=y,C.current=e),T.current!==b&&(T.current=b,I.current=n),D.current!==m&&(D.current=m,k.current=o),w.current!==S&&(w.current=S,R.current=v);const A=C.current,N=I.current,Q=k.current,U=R.current,ee=l.useId(),j=l.useMemo(()=>g||`query_${pr(t)}`,[t,g]),$=(d==null?void 0:d.viewId)||(f==null?void 0:f.id),G=(d==null?void 0:d.viewTitle)||(d==null?void 0:d.title)||(f==null?void 0:f.title),Le=d==null?void 0:d.visualType,Oe=d==null?void 0:d.sectionTitle,W=l.useMemo(()=>[$||"unscoped-view",j,ee].join("::"),[j,ee,$]),Be=l.useMemo(()=>({traceKey:W,spec:A,queryId:j,queryLabel:h,queryKind:r,builder:Kt(r),viewId:$,viewTitle:G,visualType:Le,sectionTitle:Oe,sourceHints:U,intent:N,activeInputs:Q,clientWarnings:g?[]:["Query spec is missing an explicit id; using an opaque internal id."]}),[j,r,g,h,A,Q,N,U,Oe,W,$,G,Le]);l.useEffect(()=>{if(!(!c||!p))return p({type:"register",descriptor:Be}),()=>{p({type:"unregister",traceKey:W})}},[Be,p,c,W]);const B=l.useCallback((E,z)=>{!c||!p||p({type:"event",traceKey:W,event:E,latestAttempt:z})},[p,c,W]),Ke=l.useCallback(()=>{B({type:"query_started",queryId:j,at:oe()},{status:"loading"})},[B,j]),Me=l.useCallback((E,z)=>{const J=Ue(E),Y=Ht(E),xr=Pt(E);B({type:"query_succeeded",queryId:j,requestId:J,at:oe(),rowCount:Y,durationMs:z},{requestId:J,status:"success",durationMs:z,rowCount:Y,columnCount:xr,executionResult:Qe(E)})},[B,j]),re=l.useCallback((E,z)=>{const J=Ue(E),Y=E instanceof Error?E.message:String(E);B({type:"query_failed",queryId:j,requestId:J,at:oe(),errorMessage:Y},{requestId:J,status:"error",durationMs:z,errorMessage:Y,executionResult:Qe(E)})},[B,j]),Ne=l.useCallback(E=>{B({type:"query_ignored_stale",queryId:j,at:oe(),reason:E})},[B,j]),$e=l.useCallback(E=>{re(E,0)},[re]),ce=c?u==null?void 0:u.state.entries[W]:void 0;return l.useMemo(()=>({enabled:c,queryId:j,trace:ce?ae(ce):void 0,start:Ke,success:Me,failure:re,ignored:Ne,validationFailure:$e}),[c,re,Ne,j,Ke,Me,ce,$e])}function Lr(){return i.jsx("span",{style:s.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 Or({trace:e}){var k,D,v,S,R;if(!e)return i.jsx("div",{style:s.detailsPane,children:i.jsx("div",{style:s.emptyState,children:"No traces registered yet"})});const r=e.latestAttempt,t=r==null?void 0:r.executionResult,n=ge((k=t==null?void 0:t.validation)==null?void 0:k.warnings),o=ge((D=t==null?void 0:t.validation)==null?void 0:D.errors),d=ge((v=t==null?void 0:t.coverage)==null?void 0:v.missingObligations),u=t==null?void 0:t.compiledQuery,f=gt(t),c=((S=e.server)==null?void 0:S.compiledSql)||f.compiledSql,p=r!=null&&r.errorMessage?[r.errorMessage]:[],g=[...e.clientWarnings,...n,...o,...d],h=e.inputsApplied.length>0,y=!!(u||c),m=ot(e),b=lt(r==null?void 0:r.rowCount),C=ut(r==null?void 0:r.durationMs),a=e.sourceRefs.length,I=ir(e),T=tr(I);return i.jsxs("div",{style:s.detailsPane,children:[i.jsxs("div",{style:s.detailsHeader,children:[i.jsxs("div",{style:s.detailsHeaderTopRow,children:[i.jsx("span",{"aria-hidden":!0,style:{...s.detailsHeaderStatusDot,...sr(r==null?void 0:r.status)}}),i.jsx("span",{style:s.detailsTitle,children:Ce(e)}),i.jsx("span",{style:{...s.detailsKindChip,...nr(T)},children:I})]}),i.jsxs("div",{style:s.metaStrip,children:[i.jsx("span",{style:s.metaStripItem,children:m}),i.jsx("span",{style:s.metaStripDot,children:"·"}),i.jsxs("span",{style:s.metaStripItem,children:[b," rows"]}),i.jsx("span",{style:s.metaStripDot,children:"·"}),i.jsx("span",{style:s.metaStripItem,children:C}),a>0?i.jsxs(i.Fragment,{children:[i.jsx("span",{style:s.metaStripDot,children:"·"}),i.jsx("span",{style:s.metaStripItem,children:a===1?"1 source":`${a} sources`})]}):null]})]}),p.length?i.jsx(We,{tone:"error",title:"Error",items:p}):null,g.length?i.jsx(We,{tone:"warning",title:"Warnings",items:g}):null,i.jsx(Kr,{trace:e}),i.jsx($r,{trace:e}),(R=e.sourceHints)!=null&&R.length?i.jsx(Wr,{hints:e.sourceHints}):null,h?i.jsx(Hr,{inputs:e.inputsApplied}):null,y?i.jsx(X,{title:"Compiled Query",defaultOpen:!0,children:i.jsx(Pr,{compiledQuery:u,compiledSql:c})}):null,i.jsx(X,{title:"Lifecycle Events",children:e.recentEvents.length?i.jsx("div",{style:s.eventList,children:e.recentEvents.slice(-5).map((w,A)=>i.jsxs("div",{style:s.eventRow,children:[i.jsx("span",{style:s.eventType,children:ft(w)}),i.jsx("span",{style:s.eventMeta,children:pt(w)})]},`${w.type}:${w.at}:${A}`))}):i.jsx("div",{style:s.mutedText,children:"No attempts recorded"})}),i.jsx(X,{title:"Raw Trace",children:i.jsx("pre",{style:s.codeBlock,children:ct(e)})})]})}function We({tone:e,title:r,items:t}){const n=e==="error"?s.alertCardError:s.alertCardWarning;return i.jsxs("div",{style:{...s.alertCard,...n},children:[i.jsx("div",{style:s.alertCardTitle,children:r}),t.length>1?i.jsx("ul",{style:s.alertCardList,children:t.map((o,d)=>i.jsx("li",{children:o},`${e}-${d}`))}):i.jsx("div",{children:t[0]})]})}function Br({status:e}){return i.jsx("span",{"aria-hidden":!0,style:{...s.statusDot,...sr(e)}})}function X({title:e,children:r,defaultOpen:t=!1}){const[n,o]=l.useState(t);return i.jsxs("details",{style:s.disclosure,open:n,onToggle:d=>o(d.currentTarget.open),children:[i.jsx("summary",{style:s.disclosureSummary,children:e}),i.jsx("div",{style:s.disclosureBody,children:r})]})}function Kr({trace:e}){var o;const r=(o=e.projectionFieldRefs)!=null&&o.length?e.projectionFieldRefs:e.fieldRefs,t=e.inputFieldRefs||[],n=it(r);return i.jsxs("div",{style:s.recipe,children:[i.jsx(Mr,{sources:e.sourceRefs}),i.jsx(F,{title:"Measures",fields:n.measures}),i.jsx(F,{title:"Time fields",fields:n.timeFields}),i.jsx(F,{title:"Dimensions",fields:n.dimensions,emptyText:"No dimensions selected"}),i.jsx(F,{title:"Identifiers",fields:n.identifiers}),i.jsx(F,{title:"Other fields",fields:n.other}),i.jsx(F,{title:"Input bindings",fields:t})]})}function Mr({sources:e}){return e.length?i.jsxs("div",{style:s.recipeGroup,children:[i.jsxs("div",{style:s.recipeGroupHeader,children:[i.jsx("span",{style:s.recipeGroupTitle,children:"From"}),i.jsx("span",{style:s.recipeGroupCount,children:e.length})]}),i.jsx("div",{style:s.sourcePillRow,children:e.map((r,t)=>i.jsx(Nr,{source:r},`${K(r)}:${t}`))})]}):null}function Nr({source:e}){const r=K(e);return i.jsxs("span",{style:s.sourcePill,title:r,children:[i.jsx("span",{style:s.sourcePillLabel,children:r}),i.jsx("span",{style:s.sourcePillRole,children:e.kind})]})}function $r({trace:e}){return!e.sourceRefs.length&&!e.fieldRefs.length?null:i.jsx(X,{title:"Sources and field refs",children:i.jsxs("div",{style:s.traceLineage,children:[i.jsx(Fr,{sources:e.sourceRefs}),i.jsx(F,{title:"All field refs",fields:e.fieldRefs,emptyText:"No field refs captured"})]})})}function Wr({hints:e}){return i.jsx(X,{title:"Source hints",children:i.jsx("div",{style:s.recipeFieldList,children:e.map((r,t)=>{const n=dt(r),o=r.component||r.exportName||n||"Source hint",d=[r.exportName&&r.exportName!==o?r.exportName:void 0,n,r.note].filter(Boolean).join(" · ");return i.jsxs("div",{style:s.recipeFieldRow,title:d||o,children:[i.jsx("span",{style:s.recipeFieldName,children:o}),d?i.jsx("span",{style:s.recipeFieldMeta,children:d}):null]},`${o}:${n}:${t}`)})})})}function Fr({sources:e}){return i.jsxs("div",{style:s.recipeGroup,children:[i.jsxs("div",{style:s.recipeGroupHeader,children:[i.jsx("span",{style:s.recipeGroupTitle,children:"Sources"}),i.jsx("span",{style:s.recipeGroupCount,children:e.length})]}),e.length?i.jsx("div",{style:s.recipeFieldList,children:e.map((r,t)=>i.jsxs("div",{style:s.recipeFieldRow,title:K(r),children:[i.jsx("span",{style:s.recipeFieldName,children:K(r)}),i.jsx("span",{style:s.recipeFieldMeta,children:r.kind})]},`${K(r)}:${t}`))}):i.jsx("div",{style:s.recipeEmptyText,children:"No sources captured"})]})}function F({title:e,fields:r,emptyText:t}){return!r.length&&!t?null:i.jsxs("div",{style:s.recipeGroup,children:[i.jsxs("div",{style:s.recipeGroupHeader,children:[i.jsx("span",{style:s.recipeGroupTitle,children:e}),i.jsx("span",{style:s.recipeGroupCount,children:r.length})]}),r.length?i.jsx("div",{style:s.fieldChipList,children:r.map((n,o)=>i.jsx(_r,{field:n,groupTitle:e},`${Te(n)}:${o}`))}):i.jsx("div",{style:s.recipeEmptyText,children:t})]})}function _r({field:e,groupTitle:r}){const t=st(e),n=e.label||e.name,o=e.dataType&&e.dataType!=="unknown"?e.dataType:void 0,d=e.source?K(e.source):void 0,u=[t,o,d].filter(Boolean).join(" · "),f=zr(e,r);return i.jsxs("div",{style:s.fieldChip,title:u,children:[i.jsx("span",{style:{...s.fieldGlyph,...f.style},children:f.text}),e.aggregate?i.jsx("span",{style:s.fieldAggBadge,children:e.aggregate}):null,i.jsx("span",{style:s.fieldChipName,children:n}),o?i.jsx("span",{style:s.fieldChipMeta,children:o}):null,o&&d?i.jsx("span",{style:s.fieldChipMetaDot,children:"·"}):null,d?i.jsx("span",{style:s.fieldChipMeta,children:d}):null]})}function zr(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 Hr({inputs:e}){return i.jsxs("div",{style:s.inputsAppliedBlock,children:[i.jsxs("div",{style:s.inputsAppliedHeader,children:[i.jsx("span",{style:s.inputsAppliedTitle,children:"Active Inputs"}),i.jsx("span",{style:s.inputsAppliedCount,children:e.length})]}),i.jsx("div",{style:s.inputRecipeList,children:e.map(r=>{const t=at(r);return i.jsxs("div",{style:s.inputRecipeRow,title:t.title,children:[i.jsxs("div",{style:s.inputRecipeHeader,children:[i.jsx("span",{style:s.inputRecipeId,title:r.inputId,children:r.inputId}),t.operator?i.jsx("span",{style:s.inputOperatorBadge,children:t.operator}):null,i.jsx("span",{style:s.inputValuePreview,title:t.value,children:t.value})]}),t.binding?i.jsx("div",{style:s.inputRecipeBinding,title:t.binding,children:t.binding}):null]},r.inputId)})})]})}function Pr({compiledQuery:e,compiledSql:r}){return(e==null?void 0:e.kind)==="sql"?i.jsxs("div",{style:s.compiledQuery,children:[i.jsx(Fe,{label:"SQL",value:e.sql}),e.pythonCode?i.jsx(me,{label:"Python",value:e.pythonCode}):null,e.parameters?i.jsx(me,{label:"Parameters",value:qe(e.parameters)}):null]}):r?i.jsx(Fe,{label:"SQL",value:r}):i.jsx(me,{label:"Compiled Query",value:qe(e)})}function me({label:e,value:r}){return i.jsxs("div",{style:s.codeBlockGroup,children:[i.jsx("div",{style:s.codeBlockLabel,children:e}),i.jsx("pre",{style:s.codeBlock,children:r})]})}function Fe({label:e,value:r}){return i.jsxs("div",{style:s.codeBlockGroup,children:[i.jsx("div",{style:s.codeBlockLabel,children:e}),i.jsx("pre",{style:s.codeBlock,children:Qr(r)})]})}const Vr=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 Qr(e){return e.split(/(\s+|,|\(|\))/).map((t,n)=>{if(!t)return null;const o=t.toUpperCase();return Vr.has(o)?i.jsx("span",{style:s.sqlKeyword,children:t},n):t.startsWith("$")||t.startsWith(":")||t.startsWith("?")?i.jsx("span",{style:s.sqlBindParam,children:t},n):i.jsx("span",{children:t},n)})}function Ur(e){const r=e.filter(o=>{var d;return((d=o.latestAttempt)==null?void 0:d.status)==="error"}).length,t=e.filter(o=>{var d;return((d=o.latestAttempt)==null?void 0:d.status)==="loading"}).length,n=e.filter(o=>{var d,u,f,c;return o.clientWarnings.length>0||!!((c=(f=(u=(d=o.latestAttempt)==null?void 0:d.executionResult)==null?void 0:u.validation)==null?void 0:f.warnings)!=null&&c.length)}).length;return{total:e.length,failed:r,loading:t,warningCount:n,issueCount:r+n,severity:r?"error":n?"warning":t?"loading":"ok"}}function Gr(e){return[`${e.total} ${e.total===1?"trace":"traces"}`,`${e.loading} loading`,`${e.failed} failed`,`${e.warningCount} warning${e.warningCount===1?"":"s"}`].join(" · ")}function Jr(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,or(n)].filter(Boolean).join(" ").toLowerCase().includes(t)):e}function Yr(e){const r=e.filter(o=>o.queryKind==="inputOptions"),t=new Set(r.map(we));return[{title:"Views",traces:e.filter(o=>!t.has(we(o)))},{title:"Inputs",traces:r}]}function rr(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 Xr(e,r){if(r.queryId)return rr(e,r);if(!r.viewId)return;const t=e.filter(n=>n.viewId===r.viewId);return t.length===1?t[0]:void 0}function Zr(e,r){return!!(e&&r&&e.traceId===r.traceId)}function we(e){return e.traceId}function et(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 ue(e)}}function tr(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 nr(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 Ce(e){return e.viewTitle||e.queryLabel||e.viewId||e.queryId}function rt(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 ir(e){return nt(e.visualType)||et(e.queryKind)}function tt(e,r){return r?e.queryLabel||e.queryId:Ce(e)}function nt(e){if(e)return e.replace(/[_-]+/g," ").replace(/\b\w/g,r=>r.toUpperCase())}function or(e){const r=e.sourceRefs.map(K);return r.length?r.length===1?r[0]:`${r[0]} + ${r.length-1} more`:"No source"}function it(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 ot(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 ue(e.queryKind)}}function st(e){return[e.aggregate,e.label||e.name].filter(Boolean).join(" ")}function at(e){var u,f,c;const r=e.valuePreview||"redacted",t=((u=e.fieldRef)==null?void 0:u.label)||((f=e.fieldRef)==null?void 0:f.name),n=(c=e.fieldRef)!=null&&c.source?K(e.fieldRef.source):void 0,o=[t?`on ${t}`:void 0,n].filter(Boolean).join(" · "),d=[e.inputId,e.operator,r,o].filter(Boolean).join(" - ");return{operator:e.operator,value:r,binding:o,title:d}}function K(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 dt(e){if(e.file)return e.line&&e.column?`${e.file}:${e.line}:${e.column}`:e.line?`${e.file}:${e.line}`:e.file}function lt(e){return typeof e=="number"?e.toLocaleString():"-"}function ut(e){return typeof e=="number"?`${Math.round(e)}ms`:"-"}function ct(e){return qe(e)}function qe(e){return JSON.stringify(e,null,2)??"undefined"}function ft(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 mt(e)}}function pt(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 mt(e){throw new Error(`Unsupported Semaphor trace event: ${JSON.stringify(e)}`)}function ge(e){return Array.isArray(e)?e.filter(r=>typeof r=="string"):[]}function gt(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 ht(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 yt(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 vt(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 bt(e){return e==="right"?{gridTemplateColumns:"minmax(210px, 280px) minmax(0, 1fr)"}:{gridTemplateColumns:"minmax(260px, 340px) minmax(0, 1fr)"}}function xt(e){return{borderRight:"1px solid var(--sd-border)",borderBottom:0}}function sr(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 St(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",O="semaphor-devtools",It=`
2
- .${O} {
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} {
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
- .${O} {
51
+ .${B} {
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
- .${O}-source {
95
+ .${B}-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 ar(){if(typeof document>"u"||document.getElementById(_e))return;const e=document.createElement("style");e.id=_e,e.textContent=It,document.head.appendChild(e)}const ne='ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',L="ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",he={color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},s={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 ${ne}`,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 ${ne}`},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 ${ne}`},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",...he},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:L,fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em"},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:L,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:L,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:L,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:L,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:L,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:L,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",...he},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:L,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:L,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:{...he},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:L,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 ${ne}`,cursor:"pointer"},inspectButtonText:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}};function dr(e){return{...e,order:[],entries:{},sequence:0}}function wt(e,r){if(r.type==="config")return r.config.enabled?{...e,...r.config}:dr(r.config);if(!e.enabled)return e;switch(r.type){case"register":return At(qt(e,r.descriptor));case"unregister":return jt(e,r.traceKey);case"event":return Rt(e,r);default:return e}}function qt(e,r){const t=e.entries[r.traceKey],n=t?e.sequence:e.sequence+1,o=ke(),d={...t||Et(r),...lr(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)||o};return{...e,sequence:n,order:t?e.order:[...e.order,r.traceKey],entries:{...e.entries,[r.traceKey]:d}}}function jt(e,r){const t=e.entries[r];return t?{...e,entries:{...e.entries,[r]:{...t,mounted:!1}}}:e}function Rt(e,r){const t=e.entries[r.traceKey];if(!t)return e;const n=ke(),o=[...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:o,lastEventAt:n}}}}function At(e){if(e.order.length<=e.maxQueries)return e;const r=e.order.map(o=>e.entries[o]).filter(o=>!!o).sort((o,d)=>o.mounted!==d.mounted?o.mounted?1:-1:o.lastEventAt-d.lastEventAt),t=e.order.length-e.maxQueries,n=new Set(r.slice(0,t).map(o=>o.traceKey));return n.size?{...e,order:e.order.filter(o=>!n.has(o)),entries:Object.fromEntries(Object.entries(e.entries).filter(([o])=>!n.has(o)))}:e}function Et(e){const r=ke();return{...lr(e),traceKey:e.traceKey,latestAttempt:{status:"idle"},recentEvents:[],mounted:!0,registeredAt:0,lastEventAt:r}}function lr(e){var n;const r=Wt(e.spec),t=Ft(e.spec,e.activeInputs);return{traceId:pr(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:$t(e.intent),sourceHints:(n=e.sourceHints)!=null&&n.length?e.sourceHints:void 0,projectionFieldRefs:r,inputFieldRefs:t,fieldRefs:_t(e.intent),inputsApplied:(e.activeInputs||[]).map(o=>({inputId:o.inputId,fieldRef:o.field,operator:o.operator,valuePreview:Mt(o)})),recentEvents:[],clientWarnings:e.clientWarnings}}function ae(e){const{traceKey:r,mounted:t,registeredAt:n,lastEventAt:o,...d}=e;return d}function de(e){return e.enabled?{enabled:!0,queries:e.order.map(t=>e.entries[t]).filter(t=>!!t).map(ae),getQuery:t=>{const n=Object.values(e.entries).find(o=>o.queryId===t);return n?ae(n):void 0},getQueries:t=>Object.values(e.entries).filter(n=>n.queryId===t).map(ae)}:Xe}function Ct(e){return{snapshot:()=>Tt(de(e())),getQuery:r=>ze(de(e()).getQuery(r)),getQueries:r=>de(e()).getQueries(r).map(t=>ze(t)).filter(t=>!!t)}}function Tt(e){if(!e.enabled)return e;const r=e.queries.map(ur);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?ur(e):void 0}function ur(e){var r;return(r=e==null?void 0:e.latestAttempt)!=null&&r.executionResult?{...e,latestAttempt:{...e.latestAttempt,executionResult:kt(e.latestAttempt.executionResult)}}:e}function kt(e){const{compiledQuery:r,intent:t,result:n,...o}=e,d=Dt(o.metadata);return{...o,...d?{metadata:d}:{}}}function Dt(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 Lt(e){return e===void 0||e===!1?{enabled:!1,exposeWindowBridge:!1,maxEventsPerQuery:fe,maxQueries:pe}:e===!0?{enabled:!0,exposeWindowBridge:!1,maxEventsPerQuery:fe,maxQueries:pe}:{enabled:e.enabled!==!1,exposeWindowBridge:e.exposeWindowBridge===!0,maxEventsPerQuery:Pe(e.maxEventsPerQuery,fe,jr),maxQueries:Pe(e.maxQueries,pe,Rr)}}function Ot(e){const t=[e==null?void 0:e.sourceHint,...(e==null?void 0:e.sourceHints)||[]].filter(n=>!!n).map(n=>({file:ie(n.file),line:He(n.line),column:He(n.column),exportName:ie(n.exportName),component:ie(n.component),note:ie(n.note)})).filter(n=>!!(n.file||n.line||n.column||n.exportName||n.component||n.note));return t.length?t:void 0}function ie(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 Bt(e){return typeof e.id=="string"&&e.id.trim()?e.id:void 0}function Kt(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 ue(e)}}function ue(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function Mt(e){if(Nt(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(", "),o=t.length>3?`, +${t.length-3} more`:"";return Ve(`${n}${o}`)}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 Nt(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 $t(e){const r=new Map;return le(e,t=>{zt(t)&&r.set(fr(t),t)}),[...r.values()]}function Wt(e){switch(e.queryKind){case"metric":case"analysis":return P([...e.measures||[],e.primaryMeasure,e.dateField,...e.dimensions||[]]);case"records":return P(e.fields||[]);case"inputOptions":return P([e.labelField,e.valueField,e.searchField,...e.disambiguationFields||[]]);case"sql":return P(e.fields||[]);case"matrix":return P([...(e.rows||[]).map(ye),...(e.columns||[]).map(ye),...(e.values||[]).map(ye)]);default:return ue(e)}}function Ft(e,r){const t=[...(e.inputs||[]).map(cr),...(r||[]).map(n=>n.field)];return P(t)}function P(e){const r=new Map;return e.forEach(t=>{t&&Z(t)&&r.set(Te(t),t)}),[...r.values()]}function cr(e){if(!e||typeof e!="object")return;const r=e.toAnalyticsInput;if(typeof r=="function"){const n=r.call(e);return cr(n)}const t=e.field;return Z(t)?t:void 0}function ye(e){if(Z(e))return e;if(!e||typeof e!="object")return;const r=e.field;return Z(r)?r:void 0}function _t(e){const r=new Map;return le(e,t=>{Z(t)&&r.set(Te(t),t)}),[...r.values()]}function le(e,r){if(!(!e||typeof e!="object")){if(r(e),Array.isArray(e)){e.forEach(t=>le(t,r));return}Object.values(e).forEach(t=>le(t,r))}}function zt(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 Z(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 fr(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 Te(e){return[e.name,e.role,e.aggregate,e.source?fr(e.source):""].join(":")}function Ht(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 Pt(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 pr(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 oe(){return new Date().toISOString()}function ke(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const Vt=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"],Qt=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"];function mr(e){if(!e)return{};const r=Xt(e.executionResult),t=Ut(e,r),n=Jt(t);return{...e,...Object.keys(t).length?{resultSets:t}:{},...n?{columns:n.columns,records:n.records,rowCount:n.rowCount}:{}}}function Ut(e,r){const t=Gt(e.resultSets);for(const o of Vt){if(t[o]){t[o]=gr(t[o]);continue}const d=Zt(e[o]);if(!d.length)continue;const u=r.length?r:en(d);t[o]={records:De(d,u),columns:u,rowCount:d.length}}const n=Yt(e.executionResult);return n&&n.records.length>0&&!t.records&&(t.records=n),t}function Gt(e){return Object.fromEntries(Object.entries(e||{}).map(([r,t])=>[r,gr(t)]))}function gr(e){var r;return{...e,records:De(e.records||[],e.columns||[]),rowCount:e.rowCount??((r=e.records)==null?void 0:r.length)??0}}function Jt(e){var r;for(const t of Qt)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 Yt(e){const r=e==null?void 0:e.result;if(!(!r||r.kind!=="records"&&r.kind!=="sql"))return{records:De(r.records,r.columns),columns:r.columns,rowCount:r.rowCount??r.records.length}}function Xt(e){const r=e==null?void 0:e.result;return!r||r.kind!=="records"&&r.kind!=="sql"?[]:r.columns}function Zt(e){return Array.isArray(e)?e.filter(r=>!!(r&&typeof r=="object"&&!Array.isArray(r))):[]}function De(e,r){return r.length?e.map(t=>{const n={};return r.forEach((o,d)=>{const u=rn(t,{name:o.key,label:o.label,fallbackNames:[o.name,Object.keys(t)[d]]});u!==void 0&&(n[o.key]=u)}),Object.keys(n).length?n:t}):e}function en(e){return Array.from(new Set(e.flatMap(t=>Object.keys(t)))).map(t=>({key:t,name:t,label:t}))}function rn(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 hr(){return{executeAnalysis:(e,r,t)=>H(e,r,t??{}).then(mr),executeMetric:(e,r)=>H(e,r),executeRecords:(e,r)=>H(e,r),executeInputOptions:(e,r)=>H(e,r),executeSql:(e,r)=>H(e,r),executeMatrix:(e,r)=>H(e,r)}}async function H(e,r,t){if(!r.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const n=un(r),o=on(e,n);let d;try{d=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,...nn(r)?{debug:{responseDetail:"debug"}}:{}})})}catch(f){throw new Error(`${o}: ${f instanceof Error?f.message:String(f)}`)}const u=await dn(d);if(!d.ok||u.error)throw tn(`${o}: ${u.error||`Semaphor Data App execution failed with status ${d.status}.`}`,u);return u}function tn(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 nn(e){const r=e.debug;return r?r===!0?!0:r.enabled!==!1&&r.requestServerDebug!==!1:!1}function on(e,r){return[`Semaphor ${e.kind} query`,e.id?`id=${e.id}`:void 0,e.label?`label=${e.label}`:void 0,sn(e),`endpoint=${an(r)}`].filter(t=>!!t).join(" ")}function sn(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 an(e){if(!e)return"/api/v1/data-app/execute";try{return new URL(e,"http://localhost").pathname}catch{return e}}async function dn(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:ln(e,r),details:r}}}function ln(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 un(e){const r=cn(e).replace(/\/+$/,"");return r?r.endsWith("/api")?`${r}/v1/data-app/execute`:`${r}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function cn(e){if(e.apiBaseUrl)return e.apiBaseUrl;if(!e.token)return"";try{return Ye.jwtDecode(e.token).apiServiceUrl||""}catch{return""}}const yr=l.createContext({});function fn(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function pn(){return l.useContext(yr)}const ve={value:null},be={},mn={records:[]},xe={options:[]},gn={records:[]},Se={};function hn(e){const r=x.toSemaphorActiveInputSnapshots(e.inputs),t=x.toSemaphorAnalysisQueryOptions(e);try{const n=x.toSemaphorAnalysisIntent(e),o=V(n);return o?{error:o,activeInputs:r,analysisOptions:t,queryKey:q(void 0,r,o,t),idleData:be}:{intent:n,error:null,activeInputs:r,analysisOptions:t,queryKey:q(n,r,void 0,t),idleData:be}}catch(n){const o=M(n);return{error:o,activeInputs:r,analysisOptions:t,queryKey:q(void 0,r,o,t),idleData:be}}}function yn(e){const r=x.toSemaphorActiveInputSnapshots(e.inputs);try{const t=x.toSemaphorMetricIntent(e),n=V(t);return n?{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:ve}:{intent:t,error:null,activeInputs:r,queryKey:q(t,r),idleData:ve}}catch(t){const n=M(t);return{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:ve}}}function vn(e){const r=x.toSemaphorActiveInputSnapshots(e.inputs),t=mn;try{const n=x.toSemaphorRecordsIntent(e),o=V(n);return o?{error:o,activeInputs:r,queryKey:q(void 0,r,o),idleData:t}:{intent:n,error:null,activeInputs:r,queryKey:q(n,r),idleData:t}}catch(n){const o=M(n);return{error:o,activeInputs:r,queryKey:q(void 0,r,o),idleData:t}}}function bn(e){const r=x.toSemaphorActiveInputSnapshots(e.inputs);try{const t=x.toSemaphorInputOptionsIntent(e),n=V(t);return n?{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:xe}:{intent:t,error:null,activeInputs:r,queryKey:q(t,r),idleData:xe}}catch(t){const n=M(t);return{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:xe}}}function xn(e){const r=x.toSemaphorActiveInputSnapshots(e.inputs),t=gn;try{const n=x.toSemaphorSqlIntent(e),o=V(n);return o?{error:o,activeInputs:r,queryKey:q(void 0,r,o),idleData:t}:{intent:n,error:null,activeInputs:r,queryKey:q(n,r),idleData:t}}catch(n){const o=M(n);return{error:o,activeInputs:r,queryKey:q(void 0,r,o),idleData:t}}}function Sn(e){const r=x.toSemaphorActiveInputSnapshots(e.inputs);try{const t=x.toSemaphorMatrixIntent(e),n=V(t);return n?{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:Se}:{intent:t,error:null,activeInputs:r,queryKey:q(t,r),idleData:Se}}catch(t){const n=M(t);return{error:n,activeInputs:r,queryKey:q(void 0,r,n),idleData:Se}}}function M(e){return e instanceof Error?e:new Error(String(e))}function V(e){const r=Sr.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 q(e,r,t,n){return JSON.stringify({intent:e,activeInputs:r,analysisOptions:n,error:t==null?void 0:t.message})}function In(e){const[r,t]=l.useState(e.defaultValue),n=Object.prototype.hasOwnProperty.call(e,"value"),o=n?e.value:r,d=l.useMemo(()=>x.normalizeSemaphorInputOptions(e.options),[e.options]),u=l.useCallback(c=>{var g;const p=c;(g=e.onValueChange)==null||g.call(e,p),n||t(p)},[n,e]),f=l.useCallback(()=>u(void 0),[u]);return l.useMemo(()=>{const c=x.toSemaphorInputSpec(e);return{id:e.id,kind:e.kind,label:e.label,field:c.field,operator:c.operator,relationshipHint:c.relationshipHint,controlRole:e.kind==="control"?e.role:void 0,value:o,options:d,isActive:x.hasSemaphorInputValue(o),setValue:u,clear:f,toAnalyticsInput:()=>({inputId:c.inputId,field:c.field,kind:e.kind,label:e.label,value:o,isActive:x.hasSemaphorInputValue(o),operator:c.operator,relationshipHint:c.relationshipHint,controlRole:e.kind==="control"?e.role:void 0})}},[f,d,u,e,o])}function wn(e){const[r,t]=l.useState(()=>En(e));return l.useEffect(()=>{t(n=>{let o=n;for(const d of e)!Object.prototype.hasOwnProperty.call(o,d.id)&&d.defaultValue!==void 0&&(o={...o,[d.id]:d.defaultValue});return o})},[e]),l.useMemo(()=>e.map(n=>{const o=Object.prototype.hasOwnProperty.call(n,"value"),d=o?n.value:r[n.id],u=x.normalizeSemaphorInputOptions(n.options),f=g=>{var h;(h=n.onValueChange)==null||h.call(n,g),o||t(y=>({...y,[n.id]:g}))},c=()=>f(void 0),p=x.toSemaphorInputSpec(n);return{id:n.id,kind:n.kind,label:n.label,field:p.field,operator:p.operator,relationshipHint:p.relationshipHint,controlRole:n.kind==="control"?n.role:void 0,value:d,options:u,isActive:x.hasSemaphorInputValue(d),setValue:f,clear:c,toAnalyticsInput:()=>({inputId:p.inputId,field:p.field,kind:n.kind,label:n.label,value:d,isActive:x.hasSemaphorInputValue(d),operator:p.operator,relationshipHint:p.relationshipHint,controlRole:n.kind==="control"?n.role:void 0})}}),[e,r])}function qn(e,r){const t=(r==null?void 0:r.status)==="success"?r.options:void 0,n=l.useMemo(()=>jn(t),[t]);l.useEffect(()=>{vr(e.value,t)||e.clear()},[e,n,r==null?void 0:r.status,t])}function vr(e,r){if(!x.hasSemaphorInputValue(e)||r===void 0)return!0;const t=new Set(r.map(o=>Ge(o.value)));return(Array.isArray(e)?e:[e]).every(o=>t.has(Ge(o)))}function jn(e){return JSON.stringify((e||[]).map(r=>r.value))}function Ge(e){return`${typeof e}:${String(e)}`}function Rn(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:yn(t)};case"analysis":return{queryKind:t.queryKind,request:hn(t)};case"records":return{queryKind:t.queryKind,request:vn(t)};case"inputOptions":return{queryKind:t.queryKind,request:bn(t)};case"sql":return{queryKind:t.queryKind,request:xn(t)};case"matrix":return{queryKind:t.queryKind,request:Sn(t)};default:return Ie(t)}},[t]),o=Dr({spec:t,queryKind:n.queryKind,queryKey:n.request.queryKey,intent:n.request.intent,activeInputs:n.request.activeInputs,debug:r.debug}),d=l.useRef(null),u=l.useMemo(()=>({start:o.start,success:o.success,failure:o.failure,ignored:o.ignored}),[o.failure,o.ignored,o.start,o.success]),f=l.useCallback(a=>{var T,k,D,v,S,R,w,A,N;const I=n.request;if(I.intent)switch(n.queryKind){case"metric":return(T=a.executor)==null?void 0:T.executeMetric(I.intent,a);case"analysis":return(D=(k=a.executor)==null?void 0:k.executeAnalysis)==null?void 0:D.call(k,I.intent,a,I.analysisOptions);case"records":return(v=a.executor)==null?void 0:v.executeRecords(I.intent,a);case"inputOptions":return(S=a.executor)==null?void 0:S.executeInputOptions(I.intent,a);case"sql":return(w=(R=a.executor)==null?void 0:R.executeSql)==null?void 0:w.call(R,I.intent,a);case"matrix":return(N=(A=a.executor)==null?void 0:A.executeMatrix)==null?void 0:N.call(A,I.intent,a);default:return Ie(n)}},[n]),c=An(n.request.queryKey,f,n.request.idleData,n.request.activeInputs,u),p=o.queryId,g=o.validationFailure;l.useEffect(()=>{const a=n.request.error;if(!a){d.current=null;return}const I=`${p}:${a.message}`;d.current!==I&&(d.current=I,g(a))},[n.request.error,n.request.queryKey,p,g]);const h=n.request.error?n.request.idleData:c.data,y=n.request.error?"error":c.status,m=!n.request.error&&c.status==="loading",b=n.request.error||c.error,C=o.trace;switch(n.queryKind){case"metric":{const a=h;return{id:t.id,intent:n.request.intent,value:(a==null?void 0:a.value)??null,measures:a==null?void 0:a.measures,comparisonValue:a==null?void 0:a.comparisonValue,delta:a==null?void 0:a.delta,deltaPercent:a==null?void 0:a.deltaPercent,records:a==null?void 0:a.records,executionResult:a==null?void 0:a.executionResult,status:y,isLoading:m,error:b,trace:C}}case"analysis":{const a=mr(h);return{id:t.id,intent:n.request.intent,...a||{},status:y,isLoading:m,error:b,trace:C}}case"records":{const a=h;return{id:t.id,intent:n.request.intent,records:(a==null?void 0:a.records)||[],columns:a==null?void 0:a.columns,rowCount:a==null?void 0:a.rowCount,pagination:a==null?void 0:a.pagination,executionResult:a==null?void 0:a.executionResult,status:y,isLoading:m,error:b,trace:C}}case"inputOptions":{const a=h;return{id:t.id,intent:n.request.intent,options:(a==null?void 0:a.options)||[],executionResult:a==null?void 0:a.executionResult,status:y,isLoading:m,error:b,trace:C}}case"sql":{const a=h;return{id:t.id,intent:n.request.intent,records:(a==null?void 0:a.records)||[],columns:a==null?void 0:a.columns,rowCount:a==null?void 0:a.rowCount,pagination:a==null?void 0:a.pagination,output:a==null?void 0:a.output,rowLimitExceeded:a==null?void 0:a.rowLimitExceeded,executionResult:a==null?void 0:a.executionResult,status:y,isLoading:m,error:b,trace:C}}case"matrix":{const a=h;return{id:t.id,intent:n.request.intent,matrixResult:a==null?void 0:a.matrixResult,grid:a==null?void 0:a.grid,expansion:a==null?void 0:a.expansion,executionResult:a==null?void 0:a.executionResult,status:y,isLoading:m,error:b,trace:C}}default:return Ie(n)}}function An(e,r,t,n,o){const d=pn(),u=l.useRef(r),f=l.useRef(n),[c,p]=l.useState({status:"idle",data:t,error:null});return u.current=r,f.current=n,l.useEffect(()=>{let g;try{g=u.current({...d,activeInputs:f.current})}catch(m){o==null||o.failure(m,0),p({status:"error",data:t,error:M(m)});return}if(!g){p({status:"idle",data:t,error:null});return}let h=!1;const y=br();return o==null||o.start(),p(m=>({status:"loading",data:m.data,error:null})),g.then(m=>{h?o==null||o.ignored("superseded"):(o==null||o.success(m,Je(y)),p({status:"success",data:m,error:null}))}).catch(m=>{h?o==null||o.ignored("superseded"):(o==null||o.failure(m,Je(y)),p({status:"error",data:t,error:M(m)}))}),()=>{h=!0}},[t,e,d,o]),c}function br(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}function Je(e){return Math.max(0,Math.round(br()-e))}function En(e){return Object.fromEntries(e.filter(r=>r.defaultValue!==void 0).map(r=>[r.id,r.defaultValue]))}function Ie(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function Cn(e){return!e||typeof e=="boolean"||e.enabled===!1?null:e.autoRenderDevtools===!0?{}:e.autoRenderDevtools?e.autoRenderDevtools:null}function Tn({token:e,apiBaseUrl:r,executor:t,debug:n,children:o}){var m;const d=fn(),u=((m=d==null?void 0:d.authToken)==null?void 0:m.accessToken)||e,f=(d==null?void 0:d.dataApiBaseUrl)||(d==null?void 0:d.apiBaseUrl)||r,c=(d==null?void 0:d.debug)??n,p=Cn(c),g=l.useMemo(()=>hr(),[]),h=t||g,y=l.useMemo(()=>({token:u,apiBaseUrl:f,executor:h,debug:c}),[f,c,h,u]);return i.jsx(Ar,{debug:c,children:i.jsxs(yr.Provider,{value:y,children:[o,p?i.jsx(er,{...p}):null]})})}exports.SemaphorDataAppProvider=Tn;exports.SemaphorDevtools=er;exports.SemaphorDevtoolsInspectButton=kr;exports.SemaphorViewBoundary=Tr;exports.createSemaphorQueryExecutor=hr;exports.defineSemaphorDataApp=Ir;exports.defineSemaphorInput=wr;exports.isSemaphorInputValueValidForOptions=vr;exports.semaphor=qr;exports.useClearInvalidSemaphorInputValue=qn;exports.useSemaphorDevtools=Ee;exports.useSemaphorInput=In;exports.useSemaphorInputs=wn;exports.useSemaphorQuery=Rn;
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;