react-semaphor 0.1.340 → 0.1.341

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +1 -1
  3. package/dist/chunks/{calendar-preferences-dialog-8-KE5sVX.js → calendar-preferences-dialog-_u4Xm011.js} +1 -1
  4. package/dist/chunks/{calendar-preferences-dialog-2IbYrrP1.js → calendar-preferences-dialog-hS6POgEs.js} +1 -1
  5. package/dist/chunks/{dashboard-briefing-launcher-CcqDPVke.js → dashboard-briefing-launcher-D18qNhwa.js} +1 -1
  6. package/dist/chunks/{dashboard-briefing-launcher-DtxDRAiu.js → dashboard-briefing-launcher-DHzIiaKF.js} +3 -3
  7. package/dist/chunks/{dashboard-controls-By7aKmDj.js → dashboard-controls-CilLVS_Q.js} +1 -1
  8. package/dist/chunks/{dashboard-controls-Bi98DhYD.js → dashboard-controls-g1OcteYf.js} +3 -3
  9. package/dist/chunks/{dashboard-json-CGxIsTEP.js → dashboard-json-BjnGSaxC.js} +1 -1
  10. package/dist/chunks/{dashboard-json-BOyLuhS6.js → dashboard-json-ClH0kTga.js} +1 -1
  11. package/dist/chunks/{edit-dashboard-visual-BuXlHmJH.js → edit-dashboard-visual-C_3NYnPz.js} +1 -1
  12. package/dist/chunks/{edit-dashboard-visual-Ba8LenNc.js → edit-dashboard-visual-DbVMVMKM.js} +3 -3
  13. package/dist/chunks/{index-DT9osgRT.js → index-BNZjkxPH.js} +3 -3
  14. package/dist/chunks/{index-DVPvpd8u.js → index-CuSvSh86.js} +7 -6
  15. package/dist/chunks/{resource-management-panel-98Hy6SYB.js → resource-management-panel-DxjN2uw4.js} +2 -2
  16. package/dist/chunks/{resource-management-panel-ByR-FD3h.js → resource-management-panel-N5iUOE89.js} +1 -1
  17. package/dist/chunks/{use-create-flow-overlay-state-uNxArZdj.js → use-create-flow-overlay-state-CSjc7cXZ.js} +1 -1
  18. package/dist/chunks/{use-create-flow-overlay-state-D5uvjbwY.js → use-create-flow-overlay-state-CXPnnXh1.js} +2 -2
  19. package/dist/chunks/{use-visual-utils-CpaqIHoc.js → use-visual-utils-C3MRLrHu.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-BLh9mKic.js → use-visual-utils-DsoGoqPF.js} +1 -1
  21. package/dist/chunks/validators-Caj7EMd1.js +1 -0
  22. package/dist/chunks/{validators-CPEQojnV.js → validators-YtnkRA1G.js} +66 -43
  23. package/dist/dashboard/index.cjs +1 -1
  24. package/dist/dashboard/index.js +1 -1
  25. package/dist/dashboard-authoring/index.cjs +1 -1
  26. package/dist/dashboard-authoring/index.js +1 -1
  27. package/dist/data-app-builder/index.cjs +1 -1
  28. package/dist/data-app-builder/index.js +1 -1
  29. package/dist/data-app-sdk/index.cjs +1 -1
  30. package/dist/data-app-sdk/index.js +120 -113
  31. package/dist/index.cjs +1 -1
  32. package/dist/index.js +5 -5
  33. package/dist/surfboard/index.cjs +1 -1
  34. package/dist/surfboard/index.js +2 -2
  35. package/dist/types/analytics-protocol.d.ts +12 -1
  36. package/dist/types/dashboard-authoring.d.ts +4 -0
  37. package/dist/types/dashboard.d.ts +2 -0
  38. package/dist/types/data-app-builder.d.ts +3 -0
  39. package/dist/types/data-app-sdk.d.ts +3 -0
  40. package/dist/types/main.d.ts +5 -0
  41. package/dist/types/shared.d.ts +1 -0
  42. package/dist/types/surfboard.d.ts +2 -0
  43. package/dist/types/types.d.ts +2 -0
  44. package/package.json +1 -1
  45. package/dist/chunks/validators-CfP-49k9.js +0 -1
@@ -48175,7 +48175,7 @@ function Y$e(e, t, n = []) {
48175
48175
  role: "metric"
48176
48176
  };
48177
48177
  }
48178
- const c = o === "number" ? "SUM" : "COUNT", u = qne(
48178
+ const c = e.aggregate || (o === "number" ? "SUM" : "COUNT"), u = qne(
48179
48179
  e.label,
48180
48180
  c
48181
48181
  ), f = L$e(
@@ -101806,7 +101806,8 @@ function Iue(e) {
101806
101806
  role: F.role,
101807
101807
  expression: F.expression,
101808
101808
  calculatedFormula: F.calculatedFormula,
101809
- format: Xu(F.format)
101809
+ format: Xu(F.format),
101810
+ aggregate: F.aggregate
101810
101811
  };
101811
101812
  })
101812
101813
  };
@@ -143015,10 +143016,10 @@ function JSt() {
143015
143016
  }
143016
143017
  );
143017
143018
  }
143018
- const eNt = xw(() => import("./dashboard-controls-Bi98DhYD.js")), tNt = xw(
143019
- () => import("./edit-dashboard-visual-Ba8LenNc.js")
143020
- ), nNt = xw(() => import("./dashboard-json-CGxIsTEP.js")), rNt = xw(
143021
- () => import("./resource-management-panel-98Hy6SYB.js").then(
143019
+ const eNt = xw(() => import("./dashboard-controls-g1OcteYf.js")), tNt = xw(
143020
+ () => import("./edit-dashboard-visual-DbVMVMKM.js")
143021
+ ), nNt = xw(() => import("./dashboard-json-BjnGSaxC.js")), rNt = xw(
143022
+ () => import("./resource-management-panel-DxjN2uw4.js").then(
143022
143023
  (e) => ({ default: e.ResourceManagementPanel })
143023
143024
  )
143024
143025
  );
@@ -1,9 +1,9 @@
1
1
  import { jsx as e, jsxs as n, Fragment as oe } from "react/jsx-runtime";
2
2
  import { c as He, u as se, G as Ge, a as Z, B as O, f as te, N as be, V as $e, L as ie, a2 as de, X as ke, Z as We, _ as Xe, $ as Ye, a1 as Ze, az as Je } from "./switch-CP7SmEIZ.js";
3
3
  import Qe, { useState as b, useEffect as ee, useRef as qe } from "react";
4
- import { ah as ue, aL as et, aM as tt, aI as ce, aN as nt, aO as at, aP as st, aQ as it, aR as Y, aS as ot, aT as rt, aU as lt, aV as xe, az as he, aW as dt, aX as ct, aY as Ne, aZ as we, a_ as ut, J as ye, A as Ce, a$ as ve, b0 as Se, b1 as Ee, b2 as Ve, b3 as Le, b4 as Ae, b5 as Oe, b6 as Te, b7 as Re, b8 as ht, b9 as pe, ba as pt, y as ae, u as mt, bb as Ue, c as Ie, d as ze, e as Me, f as Pe, g as Fe, bc as ft, o as je, bd as gt, be as De, bf as xt } from "./index-DVPvpd8u.js";
4
+ import { ah as ue, aL as et, aM as tt, aI as ce, aN as nt, aO as at, aP as st, aQ as it, aR as Y, aS as ot, aT as rt, aU as lt, aV as xe, az as he, aW as dt, aX as ct, aY as Ne, aZ as we, a_ as ut, J as ye, A as Ce, a$ as ve, b0 as Se, b1 as Ee, b2 as Ve, b3 as Le, b4 as Ae, b5 as Oe, b6 as Te, b7 as Re, b8 as ht, b9 as pe, ba as pt, y as ae, u as mt, bb as Ue, c as Ie, d as ze, e as Me, f as Pe, g as Fe, bc as ft, o as je, bd as gt, be as De, bf as xt } from "./index-CuSvSh86.js";
5
5
  import "./index-CuHybtft.js";
6
- import { u as Be } from "./use-visual-utils-BLh9mKic.js";
6
+ import { u as Be } from "./use-visual-utils-DsoGoqPF.js";
7
7
  /**
8
8
  * @license lucide-react v0.453.0 - ISC
9
9
  *
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./switch-DYRgERrC.js"),x=require("react"),t=require("./index-DT9osgRT.js");require("./index-BxM99sFL.js");const oe=require("./use-visual-utils-CpaqIHoc.js");/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./switch-DYRgERrC.js"),x=require("react"),t=require("./index-BNZjkxPH.js");require("./index-BxM99sFL.js");const oe=require("./use-visual-utils-C3MRLrHu.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- "use strict";const s=require("./switch-DYRgERrC.js"),v=require("react"),p=require("./index-DT9osgRT.js"),e=require("react/jsx-runtime");require("./index-BxM99sFL.js");const re=require("./use-visual-utils-CpaqIHoc.js");/**
1
+ "use strict";const s=require("./switch-DYRgERrC.js"),v=require("react"),p=require("./index-BNZjkxPH.js"),e=require("react/jsx-runtime");require("./index-BxM99sFL.js");const re=require("./use-visual-utils-C3MRLrHu.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,9 +1,9 @@
1
1
  import { c as te, G as L, H as ne, u as oe, Z as ft, _ as ht, $ as gt, a as ie, a1 as bt, a9 as yt, B as V, e as xt, X as Ke, E as Pe, f as Ye, S as Ge, aa as vt, ab as Ct, ac as se, ad as Ae, ae as ze, af as be, ag as ye, ah as kt, ai as Me, aj as Nt, ak as St, al as le, am as Dt, an as Oe, g as Be, ao as Xe, ap as Je, aq as Ze, L as P, a2 as We, a3 as xe, a4 as ve, a5 as Ce, a6 as ke, a7 as Ne, ar as et, as as wt, at as It, au as Re, av as Et, aw as Qe, ax as Tt, ay as Se } from "./switch-CP7SmEIZ.js";
2
2
  import { useEffect as de, useMemo as z, useState as Q, useRef as De, useCallback as O, Fragment as Vt } from "react";
3
- import { al as _t, am as tt, an as qt, ao as Ft, ap as Lt, aq as At, ar as zt, y as Mt, as as Ot, ae as ue, at, ag as rt, au as st, av as Bt, p as R, aw as Rt, ax as Qt, ay as je, az as jt, aA as Ut, aB as lt, aC as nt, aD as Ht, aE as $t, aF as Kt, aG as Pt, aH as Yt, aI as Gt, aJ as Xt, aK as Jt } from "./index-DVPvpd8u.js";
3
+ import { al as _t, am as tt, an as qt, ao as Ft, ap as Lt, aq as At, ar as zt, y as Mt, as as Ot, ae as ue, at, ag as rt, au as st, av as Bt, p as R, aw as Rt, ax as Qt, ay as je, az as jt, aA as Ut, aB as lt, aC as nt, aD as Ht, aE as $t, aF as Kt, aG as Pt, aH as Yt, aI as Gt, aJ as Xt, aK as Jt } from "./index-CuSvSh86.js";
4
4
  import { jsx as t, jsxs as d, Fragment as $ } from "react/jsx-runtime";
5
5
  import "./index-CuHybtft.js";
6
- import { u as we } from "./use-visual-utils-BLh9mKic.js";
6
+ import { u as we } from "./use-visual-utils-DsoGoqPF.js";
7
7
  /**
8
8
  * @license lucide-react v0.453.0 - ISC
9
9
  *
@@ -1 +1 @@
1
- "use strict";const u=require("./index-DT9osgRT.js"),f=require("./switch-DYRgERrC.js"),S=require("react");function K(e){const[a,s]=S.useState(null),[r,t]=S.useState(null),o=u.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const i=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const m=await import(i);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>m.useChartStore),t(null)}catch(n){const i=n instanceof Error?n.message:"Unknown error";console.error("Failed to load remote chart store:",i),t(i),s(null)}})()},[e,o]),a}function X(e,a){if(e.length===0)return"";const s=e.find(r=>{var t,o;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=r.customCardPreferences)!=null&&o.dataInputCardIds)});if(s)return s.id;if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const l=t.split("__")[0],n=e.find(i=>i.tabTitle===l);return n?n.id:e[0].id}return a}}return e[0].id}const A=new Set;function Y(e){return A.add(e),()=>{A.delete(e)}}function z(){A.forEach(e=>{e()})}const Z=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:a,...s}=e;return s};async function B(e,a,s,r){if(!a||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],o=r.getQueryData(t);if(o)return console.log("Using cached visual data for:",s),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",s);const l=u.ue.loading("Loading visual...",{position:"top-center"});try{const n=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${a}`}});if(!n.ok)throw new Error("Failed to load visual");const i=await n.json();return r.setQueryData(t,i),u.ue.dismiss(l),{data:i,fromCache:!1}}catch(n){throw u.ue.dismiss(l),n}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function ee(e,a){var o,l;const s=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!s)return!1;const r=H(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(l=r.cards)==null?void 0:l.find(n=>n.id===r.activeCardId);return t?(u.setupEditorWithCard({...a,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function te(){const e=f.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),a=K(e);return{getUpdatedFrame:S.useCallback(()=>{var b;z();const{frame:r,card:t,isDevMode:o,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y}=f.useEditorStore.getState(),I=t.sql,U=(b=a==null?void 0:a.getState())==null?void 0:b.settings,V=f.buildSavedEditorCard(t,{isDevMode:o,cardSql:I,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y,remoteChartSettings:U,stripConfig:Z}),g=r.cards.map(E=>E.id===t.id?V:E);return{...r,cards:g,activeCardId:X(g,r.activeCardId)}},[a])}}function re(){const{authToken:e,tokenProps:a}=u.useSemaphorContext(),s=u.useQueryClient(),r=u.useAddFrameWithFreshSemanticExecutionPayload(),t=u.useSelectedVisual(),{selectVisual:o}=u.useManagementActions(),{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,clearEditorContext:L}=f.useEditorActions(),{setIsDashboardEditing:v,setIsVisualEditing:T,setSelectedFrameId:j,clearSelectedFrameId:N,setIsDashboardPanelOpen:R}=f.useDashboardActions(),w=f.useDashboardStore(c=>c.selectedSheetId),W=f.useDashboardStore(c=>c.selectedFrameId),$=f.useDashboardStore(c=>c.dashboard),_=f.useDashboardStore(c=>c.filterValues),x=f.useDashboardStore(c=>c.inlineFilterValuesMap),F=u.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),Q=S.useCallback(async c=>{try{o(c),N(),L();const{data:h,fromCache:D}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s);if(!ee(h,{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,setIsDashboardEditing:v,setIsVisualEditing:T,dashboard:$,selectedSheetId:w,selectedFrameId:W,filterValues:_,inlineFilterValuesMap:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:D}}catch(h){return console.error("Error editing visual:",h),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,l,n,v,T,i,m,p,y,I,U,V,g,b,E,P,M,k,L,N,$,w,W,_,x]),G=S.useCallback(async c=>{var D;const h=d=>(u.ue.error(d),{success:!1,error:d});try{if(o(c),!w)return h("No sheet selected. Please select a sheet first.");const{data:d,fromCache:J}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s),O=(d==null?void 0:d.frameObject)??((D=d==null?void 0:d.visual)==null?void 0:D.frameObject);if(!O)return h("Visual has no frame data");const C=H(O);if(!(C!=null&&C.cards)||C.cards.length===0)return h("Visual frame is malformed");const q={...u.cloneLinkedFrameWithSourceMapping(C),visualId:c.id};return await r(w,q,"end"),v(!0),j(q.id),R(!1),{success:!0,fromCache:J}}catch(d){return console.error("Error adding visual:",d),h(d instanceof Error?d.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,w,v,j,R,r]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:G,getUpdatedFrame:te().getUpdatedFrame,refetch:F.refetch}}exports.flushPendingEditorDrafts=z;exports.registerPendingEditorDraftFlusher=Y;exports.useVisualUtils=re;
1
+ "use strict";const u=require("./index-BNZjkxPH.js"),f=require("./switch-DYRgERrC.js"),S=require("react");function K(e){const[a,s]=S.useState(null),[r,t]=S.useState(null),o=u.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const i=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const m=await import(i);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>m.useChartStore),t(null)}catch(n){const i=n instanceof Error?n.message:"Unknown error";console.error("Failed to load remote chart store:",i),t(i),s(null)}})()},[e,o]),a}function X(e,a){if(e.length===0)return"";const s=e.find(r=>{var t,o;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=r.customCardPreferences)!=null&&o.dataInputCardIds)});if(s)return s.id;if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const l=t.split("__")[0],n=e.find(i=>i.tabTitle===l);return n?n.id:e[0].id}return a}}return e[0].id}const A=new Set;function Y(e){return A.add(e),()=>{A.delete(e)}}function z(){A.forEach(e=>{e()})}const Z=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:a,...s}=e;return s};async function B(e,a,s,r){if(!a||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],o=r.getQueryData(t);if(o)return console.log("Using cached visual data for:",s),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",s);const l=u.ue.loading("Loading visual...",{position:"top-center"});try{const n=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${a}`}});if(!n.ok)throw new Error("Failed to load visual");const i=await n.json();return r.setQueryData(t,i),u.ue.dismiss(l),{data:i,fromCache:!1}}catch(n){throw u.ue.dismiss(l),n}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function ee(e,a){var o,l;const s=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!s)return!1;const r=H(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(l=r.cards)==null?void 0:l.find(n=>n.id===r.activeCardId);return t?(u.setupEditorWithCard({...a,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function te(){const e=f.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),a=K(e);return{getUpdatedFrame:S.useCallback(()=>{var b;z();const{frame:r,card:t,isDevMode:o,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y}=f.useEditorStore.getState(),I=t.sql,U=(b=a==null?void 0:a.getState())==null?void 0:b.settings,V=f.buildSavedEditorCard(t,{isDevMode:o,cardSql:I,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y,remoteChartSettings:U,stripConfig:Z}),g=r.cards.map(E=>E.id===t.id?V:E);return{...r,cards:g,activeCardId:X(g,r.activeCardId)}},[a])}}function re(){const{authToken:e,tokenProps:a}=u.useSemaphorContext(),s=u.useQueryClient(),r=u.useAddFrameWithFreshSemanticExecutionPayload(),t=u.useSelectedVisual(),{selectVisual:o}=u.useManagementActions(),{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,clearEditorContext:L}=f.useEditorActions(),{setIsDashboardEditing:v,setIsVisualEditing:T,setSelectedFrameId:j,clearSelectedFrameId:N,setIsDashboardPanelOpen:R}=f.useDashboardActions(),w=f.useDashboardStore(c=>c.selectedSheetId),W=f.useDashboardStore(c=>c.selectedFrameId),$=f.useDashboardStore(c=>c.dashboard),_=f.useDashboardStore(c=>c.filterValues),x=f.useDashboardStore(c=>c.inlineFilterValuesMap),F=u.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),Q=S.useCallback(async c=>{try{o(c),N(),L();const{data:h,fromCache:D}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s);if(!ee(h,{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,setIsDashboardEditing:v,setIsVisualEditing:T,dashboard:$,selectedSheetId:w,selectedFrameId:W,filterValues:_,inlineFilterValuesMap:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:D}}catch(h){return console.error("Error editing visual:",h),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,l,n,v,T,i,m,p,y,I,U,V,g,b,E,P,M,k,L,N,$,w,W,_,x]),G=S.useCallback(async c=>{var D;const h=d=>(u.ue.error(d),{success:!1,error:d});try{if(o(c),!w)return h("No sheet selected. Please select a sheet first.");const{data:d,fromCache:J}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s),O=(d==null?void 0:d.frameObject)??((D=d==null?void 0:d.visual)==null?void 0:D.frameObject);if(!O)return h("Visual has no frame data");const C=H(O);if(!(C!=null&&C.cards)||C.cards.length===0)return h("Visual frame is malformed");const q={...u.cloneLinkedFrameWithSourceMapping(C),visualId:c.id};return await r(w,q,"end"),v(!0),j(q.id),R(!1),{success:!0,fromCache:J}}catch(d){return console.error("Error adding visual:",d),h(d instanceof Error?d.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,w,v,j,R,r]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:G,getUpdatedFrame:te().getUpdatedFrame,refetch:F.refetch}}exports.flushPendingEditorDrafts=z;exports.registerPendingEditorDraftFlusher=Y;exports.useVisualUtils=re;
@@ -1,4 +1,4 @@
1
- import { ad as X, u as Y, ae as Z, af as ee, ag as te, ah as re, ai as se, aj as ae, p as V, ak as oe } from "./index-DVPvpd8u.js";
1
+ import { ad as X, u as Y, ae as Z, af as ee, ag as te, ah as re, ai as se, aj as ae, p as V, ak as oe } from "./index-CuSvSh86.js";
2
2
  import { H as ne, E as ie, u as b, G as H, I as ce } from "./switch-CP7SmEIZ.js";
3
3
  import { useState as z, useEffect as de, useCallback as A } from "react";
4
4
  function le(e) {
@@ -0,0 +1 @@
1
+ "use strict";function _(e){return e?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,e.dialect||"",e.label||""].join(":"):""}function g(e,i){return!e||!i?e===i:e.kind!==i.kind?!1:e.kind==="semantic"&&i.kind==="semantic"?e.domainId!==i.domainId?!1:e.datasetId&&i.datasetId?e.datasetId===i.datasetId:e.datasetName===i.datasetName:_(e)===_(i)}function A(e,i){return e.kind!=="semantic"||i.kind!=="semantic"?e:{...e,datasetId:e.datasetId||i.datasetId,label:e.label||i.label,connectionId:e.connectionId||i.connectionId}}function I(e,i){return e.name===i.name&&g(e.source,i.source)}function R(e,i){return{...e,label:e.label||i.label,role:e.role||i.role,dataType:e.dataType||i.dataType,source:e.source&&i.source?A(e.source,i.source):e.source||i.source}}function n(e,i,a){return a?{code:e,message:i,path:a}:{code:e,message:i}}function j(e){for(let i=0;i<e.length;i+=1){const a=e[i];if(e.some((r,o)=>o!==i&&y(r,a)))return!1}return!0}function y(e,i){return I(e,i)}function F(e,i){const a=i.filter(r=>r.name===e.name);return e.source?a.some(r=>y(r,e)&&v(e,r)):a.length===1&&v(e,a[0])}function v(e,i){return i?e.aggregate?i.aggregate===e.aggregate:!0:!1}function d(e){return typeof e=="string"&&e.trim().length>0}function u(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function b(e){const i=new Set;for(const a of e){if(i.has(a))return a;i.add(a)}return null}const D=new Set(["SUM","COUNT","AVG","MIN","MAX","MEDIAN","DISTINCT"]);function k(e,i,a){if(!e||typeof e!="object"){a.push(n("missing_source","Analytics intent needs a source.",i));return}if(e.kind==="semantic"){d(e.domainId)||a.push(n("missing_semantic_domain","Semantic source needs a domainId.",`${i}.domainId`)),d(e.datasetName)||a.push(n("missing_dataset_name","Semantic source needs a datasetName.",`${i}.datasetName`));return}if(e.kind==="physical"){d(e.connectionId)||a.push(n("missing_connection_id","Physical source needs a connectionId.",`${i}.connectionId`)),d(e.tableName)||a.push(n("missing_table_name","Physical source needs a tableName.",`${i}.tableName`));return}if(e.kind==="sql"){d(e.connectionId)||a.push(n("missing_connection_id","SQL source needs a connectionId.",`${i}.connectionId`));return}a.push(n("invalid_source_kind","Source kind is not supported.",i))}function f(e,i,a,r={}){if(!e||!u(e)){r.required&&a.push(n("missing_field_ref","Field reference needs a name.",i));return}d(e.name)||a.push(n("missing_field_ref","Field reference needs a name.",`${i}.name`)),e.source!==void 0&&k(e.source,`${i}.source`,a),T(e.aggregate,`${i}.aggregate`,a)}function T(e,i,a){e!==void 0&&(typeof e!="string"||!D.has(e))&&a.push(n("invalid_aggregate","Field aggregate must be SUM, COUNT, AVG, MIN, MAX, MEDIAN, or DISTINCT.",i))}function q(e,i){if(e.analysis===void 0)return;if(!u(e.analysis)){i.push(n("invalid_metric_analysis","Metric analysis must be a structured object.","analysis"));return}if(e.analysis.kind!=="period_change"){i.push(n("invalid_metric_analysis","Metric analysis kind is not supported.","analysis.kind"));return}e.dateField||i.push(n("missing_analysis_date_field","Period-change analysis needs a dateField.","dateField")),e.timeGrain||i.push(n("missing_analysis_time_grain","Period-change analysis needs a timeGrain.","timeGrain"));const{timeWindow:a}=e.analysis;a!==void 0&&w(a,"analysis.timeWindow",i)}function w(e,i,a){if(!u(e)){a.push(n("invalid_time_window","Time window must be a structured object.",i));return}e.unit!=="second"&&e.unit!=="minute"&&e.unit!=="hour"&&e.unit!=="day"&&e.unit!=="week"&&e.unit!=="month"&&e.unit!=="quarter"&&e.unit!=="year"&&a.push(n("invalid_time_window","Time window unit must be second, minute, hour, day, week, month, quarter, or year.",`${i}.unit`)),(typeof e.value!="number"||!Number.isFinite(e.value)||e.value<=0)&&a.push(n("invalid_time_window","Time window value must be a positive number.",`${i}.value`)),e.anchor!==void 0&&e.anchor!=="now"&&e.anchor!=="latest_available"&&a.push(n("invalid_time_window","Time window anchor must be now or latest_available.",`${i}.anchor`))}function x(e,i,a){if(e!==void 0){if(!Array.isArray(e)){a.push(n("invalid_analytics_filters","Analytics filters must be an array.",i));return}e.forEach((r,o)=>{const s=`${i}.${o}`;if(!u(r)){a.push(n("invalid_analytics_filter","Analytics filter must be a structured object.",s));return}const t=r;f(t.field,`${s}.field`,a,{required:!0});const p=t.operator==="is_null"||t.operator==="is_not_null";if(t.operator!==void 0&&t.operator!=="="&&t.operator!=="!="&&t.operator!=="in"&&t.operator!=="not_in"&&t.operator!=="contains"&&t.operator!=="not_contains"&&t.operator!=="between"&&t.operator!=="not_between"&&t.operator!==">"&&t.operator!==">="&&t.operator!=="<"&&t.operator!=="<="&&t.operator!=="is_null"&&t.operator!=="is_not_null"&&a.push(n("invalid_analytics_filter_operator","Analytics filter operator is not supported.",`${s}.operator`)),t.values===void 0&&!p&&a.push(n("missing_analytics_filter_value","Analytics filter needs values unless it is a null check.",s)),p&&t.values!==void 0){a.push(n("invalid_analytics_filter_values","Null-check analytics filters must not include values.",`${s}.values`));return}t.values!==void 0&&!Array.isArray(t.values)&&a.push(n("invalid_analytics_filter_values","Analytics filter values must be an array when provided.",`${s}.values`))})}}function h(e){var r;const i=[],a=[];if(!e||typeof e!="object")return{ok:!1,errors:[n("invalid_analytics_intent","Analytics intent must be a structured object.")],warnings:a,repairHints:[{code:"invalid_analytics_intent",recommendedNextStep:"Send one structured analytics intent object with kind, source, and required fields."}]};if(e.version!==void 0&&e.version!==1&&i.push(n("invalid_version","Analytics intent version must be 1.","version")),k(e.source,"source",i),e.kind==="metric"){const o=Array.isArray(e.metrics)?e.metrics.filter(s=>u(s)&&d(s.name)):[];if(!Array.isArray(e.metrics)||e.metrics.length===0?i.push(n("missing_metric","Metric intent needs at least one metric.","metrics")):e.metrics.some(s=>!u(s)||!d(s.name))&&i.push(n("invalid_metric_list","Metric intent metrics must be an array of field references with names.","metrics")),o.forEach((s,t)=>{f(s,`metrics.${t}`,i,{required:!0})}),o.length>0&&!j(o)){const s=o.find((t,p)=>o.some((c,l)=>l!==p&&y(c,t)));s&&i.push(n("duplicate_metric",`Metric intent has duplicate metric "${s.name}".`,"metrics"))}u(e.primaryMetric)&&d(e.primaryMetric.name)&&e.primaryMetric.source===void 0&&o.filter(s=>{var t;return s.name===((t=e.primaryMetric)==null?void 0:t.name)}).length>1&&i.push(n("ambiguous_primary_metric","Metric intent primaryMetric needs a source when it names a duplicated metric.","primaryMetric")),e.primaryMetric!==void 0&&(f(e.primaryMetric,"primaryMetric",i,{required:!0}),u(e.primaryMetric)&&d(e.primaryMetric.name)&&o.length>0&&!F(e.primaryMetric,o)&&i.push(n("invalid_primary_metric","Metric intent primaryMetric must match one metric field reference.","primaryMetric"))),e.dimensions!==void 0&&!Array.isArray(e.dimensions)?i.push(n("invalid_metric_dimensions","Metric intent dimensions must be an array of field references.","dimensions")):Array.isArray(e.dimensions)&&e.dimensions.some(s=>!u(s)||!d(s.name))&&i.push(n("invalid_metric_dimensions","Metric intent dimensions must be an array of field references with names.","dimensions")),e.dateField!==void 0&&f(e.dateField,"dateField",i),e.timeWindow!==void 0&&(w(e.timeWindow,"timeWindow",i),e.dateField||i.push(n("missing_time_window_date_field","Metric timeWindow needs a dateField.","dateField"))),x(e.filters,"filters",i),Array.isArray(e.dimensions)&&e.dimensions.forEach((s,t)=>{f(s,`dimensions.${t}`,i)}),q(e,i)}else e.kind==="records"?(!Array.isArray(e.fields)||e.fields.length===0?i.push(n("missing_record_fields","Records intent needs at least one field.","fields")):e.fields.some(o=>!u(o)||!d(o.name))&&i.push(n("invalid_record_fields","Records intent fields must be field references with names.","fields")),Array.isArray(e.fields)&&e.fields.forEach((o,s)=>{f(o,`fields.${s}`,i)}),e.dateField!==void 0&&f(e.dateField,"dateField",i),e.orderBy!==void 0&&(u(e.orderBy)?(f(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(n("invalid_record_order_direction","Records intent orderBy direction must be asc or desc.","orderBy.direction"))):i.push(n("invalid_record_order_by","Records intent orderBy must be a structured object.","orderBy")))):e.kind==="inputOptions"?((!e.field||!d(e.field.name))&&i.push(n("missing_input_options_field","Input options intent needs a field.","field")),f(e.field,"field",i,{required:!0})):e.kind==="sql"?(((r=e.source)==null?void 0:r.kind)!=="sql"&&i.push(n("invalid_sql_source","SQL analytics intent must use a SQL execution source.","source")),d(e.sql)||i.push(n("missing_sql","SQL analytics intent needs SQL text.","sql")),Array.isArray(e.fields)&&e.fields.forEach((o,s)=>{f(o,`fields.${s}`,i)})):i.push(n("invalid_analytics_kind","Analytics kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:a,repairHints:B(i)}}function S(e){const i=[],a=[];if(!e||typeof e!="object")return{ok:!1,errors:[n("invalid_operation_intent","Operation intent must be a structured object.")],warnings:a,repairHints:[{code:"invalid_operation_intent",recommendedNextStep:"Send one typed operation intent with version, kind, and required operation fields."}]};if(e.version!==1&&i.push(n("invalid_version","Operation intent version must be 1.","version")),e.kind==="answer_obligations")!Array.isArray(e.obligations)||e.obligations.length===0?i.push(n("missing_obligations","Answer-obligations operation intent needs at least one obligation.","obligations")):e.obligations.forEach((r,o)=>{d(r.id)||i.push(n("missing_obligation_id","Each analytics obligation needs an id.",`obligations.${o}.id`)),d(r.prompt)||i.push(n("missing_obligation_prompt","Each analytics obligation needs a prompt.",`obligations.${o}.prompt`))});else if(e.kind==="dashboard_change"||e.kind==="data_app_change"){if(d(e.instruction)||i.push(n("missing_instruction","Change operation intent needs an instruction.","instruction")),e.analyticsIntent){const r=h(e.analyticsIntent);i.push(...r.errors),a.push(...r.warnings)}}else i.push(n("invalid_operation_kind","Operation intent kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:a,repairHints:M(i)}}function E(e){const i=[],a=[];if(!e||typeof e!="object")return{ok:!1,errors:[n("invalid_recovery_plan","Analytics recovery plan must be a structured object.")],warnings:a,repairHints:[{code:"invalid_recovery_plan",recommendedNextStep:"Return a typed recovery plan with operationIntent and plannedToolCalls."}]};e.version!==1&&i.push(n("invalid_version","Recovery plan version must be 1.","version")),e.kind!=="analytics_recovery_plan"&&i.push(n("invalid_recovery_plan_kind","Recovery plan kind must be analytics_recovery_plan.","kind"));const r=S(e.operationIntent);return i.push(...r.errors),a.push(...r.warnings),Array.isArray(e.plannedToolCalls)||i.push(n("invalid_planned_tool_calls","Recovery plan plannedToolCalls must be an array.","plannedToolCalls")),{ok:i.length===0,errors:i,warnings:a,repairHints:M(i)}}function M(e){return e.map(i=>({code:i.code,recommendedNextStep:i.code==="missing_obligations"?"Normalize the user request into one or more typed analytics obligations before recovery planning.":"Correct the operation/recovery contract shape before planning execution."}))}function B(e){return e.map(i=>{switch(i.code){case"missing_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Provide a semantic, physical, or SQL source before executing analytics."};case"missing_metric":return{code:i.code,fieldRole:"metric",recommendedNextStep:"Choose one exact metric from the grounded schema candidates."};case"missing_record_fields":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide at least one field for the records intent."};case"missing_input_options_field":return{code:i.code,fieldRole:"input",recommendedNextStep:"Provide the exact field whose option values should be listed."};case"missing_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Provide bounded read-only SQL with an explicit outer LIMIT."};case"conflicting_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Use one canonical SQL text location for the intent; prefer top-level sql."};case"missing_semantic_domain":case"missing_dataset_name":case"missing_connection_id":case"missing_table_name":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use grounded catalog metadata to fill the missing source reference."};default:return}}).filter(i=>!!i)}function C(e,i,a,r){if(!e||typeof e!="object"){a.push(n("invalid_view","Dashboard view must be an object.",i));return}if(d(e.title)||a.push(n("missing_view_title","Dashboard view needs a title.",i)),!e.presentation||typeof e.presentation!="object"){a.push(n("missing_presentation","Dashboard view needs a presentation.",`${i}.presentation`));return}if(e.presentation.kind==="text"){d(e.text)||r.push(n("missing_text_content","Text views should include text content.",`${i}.text`));return}if(!e.analytics){a.push(n("missing_view_analytics","Non-text dashboard views need analytics intent.",`${i}.analytics`));return}const o=h(e.analytics);for(const s of o.errors)a.push(n(s.code,s.message,`${i}.analytics${s.path?`.${s.path}`:""}`));for(const s of o.warnings)r.push(n(s.code,s.message,`${i}.analytics${s.path?`.${s.path}`:""}`))}function P(e){const i=[],a=[];if(!e||typeof e!="object")return{ok:!1,errors:[n("invalid_dashboard_intent","Dashboard intent must be a structured object.")],warnings:a};e.version!==1&&i.push(n("invalid_version","Dashboard intent version must be 1.")),e.kind!=="dashboard"&&i.push(n("invalid_kind","Experience intent kind must be dashboard.")),d(e.title)||i.push(n("missing_title","Dashboard intent needs a title.","title"));const r=Array.isArray(e.inputs)?e.inputs:[],o=b(r.filter(u).map(c=>c.id).filter(c=>typeof c=="string"));o&&i.push(n("duplicate_input_id",`Duplicate input id: ${o}.`,"inputs"));for(const[c,l]of r.entries()){const m=`inputs.${c}`;if(!u(l)){i.push(n("invalid_input","Dashboard input must be an object.",m));continue}d(l.id)||i.push(n("missing_input_id","Input needs an id.",`${m}.id`)),d(l.label)||i.push(n("missing_input_label","Input needs a label.",`${m}.label`)),!l.field||!d(l.field.name)?i.push(n("missing_input_field","Input needs a field.",`${m}.field`)):f(l.field,`${m}.field`,i)}const s=Array.isArray(e.sections)?e.sections:[];s.length===0&&i.push(n("missing_sections","Dashboard intent needs at least one section.","sections"));const t=s.flatMap(c=>c&&typeof c=="object"&&Array.isArray(c.views)?c.views.filter(u).map(l=>l.id).filter(l=>!!l):[]),p=b(t);p&&i.push(n("duplicate_view_id",`Duplicate dashboard view id: ${p}.`,"sections"));for(const[c,l]of s.entries()){const m=`sections.${c}`;if(!l||typeof l!="object"){i.push(n("invalid_section","Dashboard section must be an object.",m));continue}if(d(l.title)||i.push(n("missing_section_title","Dashboard section needs a title.",m)),!Array.isArray(l.views)||l.views.length===0){i.push(n("missing_section_views","Dashboard section needs at least one view.",`${m}.views`));continue}for(const[$,N]of l.views.entries())C(N,`${m}.views.${$}`,i,a)}return{ok:i.length===0,errors:i,warnings:a}}exports.preferSemaphorFieldRefMetadata=R;exports.preferSemaphorSourceMetadata=A;exports.semaphorFieldRefsMatch=I;exports.semaphorSourceIdentityKey=_;exports.semaphorSourcesReferToSameDataset=g;exports.validateSemaphorAnalyticsIntent=h;exports.validateSemaphorAnalyticsRecoveryPlan=E;exports.validateSemaphorDashboardIntent=P;exports.validateSemaphorOperationIntent=S;
@@ -17,7 +17,7 @@ function y(e) {
17
17
  e.label || ""
18
18
  ].join(":") : "";
19
19
  }
20
- function I(e, i) {
20
+ function S(e, i) {
21
21
  return !e || !i ? e === i : e.kind !== i.kind ? !1 : e.kind === "semantic" && i.kind === "semantic" ? e.domainId !== i.domainId ? !1 : e.datasetId && i.datasetId ? e.datasetId === i.datasetId : e.datasetName === i.datasetName : y(e) === y(i);
22
22
  }
23
23
  function $(e, i) {
@@ -28,10 +28,10 @@ function $(e, i) {
28
28
  connectionId: e.connectionId || i.connectionId
29
29
  };
30
30
  }
31
- function S(e, i) {
32
- return e.name === i.name && I(e.source, i.source);
31
+ function M(e, i) {
32
+ return e.name === i.name && S(e.source, i.source);
33
33
  }
34
- function D(e, i) {
34
+ function B(e, i) {
35
35
  return {
36
36
  ...e,
37
37
  label: e.label || i.label,
@@ -43,7 +43,7 @@ function D(e, i) {
43
43
  function n(e, i, s) {
44
44
  return s ? { code: e, message: i, path: s } : { code: e, message: i };
45
45
  }
46
- function M(e) {
46
+ function N(e) {
47
47
  for (let i = 0; i < e.length; i += 1) {
48
48
  const s = e[i];
49
49
  if (e.some(
@@ -54,11 +54,16 @@ function M(e) {
54
54
  return !0;
55
55
  }
56
56
  function _(e, i) {
57
- return S(e, i);
57
+ return M(e, i);
58
58
  }
59
- function N(e, i) {
59
+ function R(e, i) {
60
60
  const s = i.filter((r) => r.name === e.name);
61
- return e.source ? s.some((r) => _(r, e)) : s.length === 1;
61
+ return e.source ? s.some(
62
+ (r) => _(r, e) && h(e, r)
63
+ ) : s.length === 1 && h(e, s[0]);
64
+ }
65
+ function h(e, i) {
66
+ return i ? e.aggregate ? i.aggregate === e.aggregate : !0 : !1;
62
67
  }
63
68
  function d(e) {
64
69
  return typeof e == "string" && e.trim().length > 0;
@@ -66,7 +71,7 @@ function d(e) {
66
71
  function u(e) {
67
72
  return !!(e && typeof e == "object" && !Array.isArray(e));
68
73
  }
69
- function h(e) {
74
+ function v(e) {
70
75
  const i = /* @__PURE__ */ new Set();
71
76
  for (const s of e) {
72
77
  if (i.has(s))
@@ -75,7 +80,16 @@ function h(e) {
75
80
  }
76
81
  return null;
77
82
  }
78
- function v(e, i, s) {
83
+ const j = /* @__PURE__ */ new Set([
84
+ "SUM",
85
+ "COUNT",
86
+ "AVG",
87
+ "MIN",
88
+ "MAX",
89
+ "MEDIAN",
90
+ "DISTINCT"
91
+ ]);
92
+ function b(e, i, s) {
79
93
  if (!e || typeof e != "object") {
80
94
  s.push(n("missing_source", "Analytics intent needs a source.", i));
81
95
  return;
@@ -133,9 +147,18 @@ function f(e, i, s, r = {}) {
133
147
  }
134
148
  d(e.name) || s.push(
135
149
  n("missing_field_ref", "Field reference needs a name.", `${i}.name`)
136
- ), e.source !== void 0 && v(e.source, `${i}.source`, s);
150
+ ), e.source !== void 0 && b(e.source, `${i}.source`, s), q(e.aggregate, `${i}.aggregate`, s);
137
151
  }
138
- function R(e, i) {
152
+ function q(e, i, s) {
153
+ e !== void 0 && (typeof e != "string" || !j.has(e)) && s.push(
154
+ n(
155
+ "invalid_aggregate",
156
+ "Field aggregate must be SUM, COUNT, AVG, MIN, MAX, MEDIAN, or DISTINCT.",
157
+ i
158
+ )
159
+ );
160
+ }
161
+ function x(e, i) {
139
162
  if (e.analysis === void 0)
140
163
  return;
141
164
  if (!u(e.analysis)) {
@@ -172,9 +195,9 @@ function R(e, i) {
172
195
  )
173
196
  );
174
197
  const { timeWindow: s } = e.analysis;
175
- s !== void 0 && b(s, "analysis.timeWindow", i);
198
+ s !== void 0 && g(s, "analysis.timeWindow", i);
176
199
  }
177
- function b(e, i, s) {
200
+ function g(e, i, s) {
178
201
  if (!u(e)) {
179
202
  s.push(
180
203
  n(
@@ -205,7 +228,7 @@ function b(e, i, s) {
205
228
  )
206
229
  );
207
230
  }
208
- function j(e, i, s) {
231
+ function F(e, i, s) {
209
232
  if (e !== void 0) {
210
233
  if (!Array.isArray(e)) {
211
234
  s.push(
@@ -266,7 +289,7 @@ function j(e, i, s) {
266
289
  });
267
290
  }
268
291
  }
269
- function g(e) {
292
+ function A(e) {
270
293
  var r;
271
294
  const i = [], s = [];
272
295
  if (!e || typeof e != "object")
@@ -288,7 +311,7 @@ function g(e) {
288
311
  };
289
312
  if (e.version !== void 0 && e.version !== 1 && i.push(
290
313
  n("invalid_version", "Analytics intent version must be 1.", "version")
291
- ), v(e.source, "source", i), e.kind === "metric") {
314
+ ), b(e.source, "source", i), e.kind === "metric") {
292
315
  const o = Array.isArray(e.metrics) ? e.metrics.filter(
293
316
  (a) => u(a) && d(a.name)
294
317
  ) : [];
@@ -306,7 +329,7 @@ function g(e) {
306
329
  f(a, `metrics.${t}`, i, {
307
330
  required: !0
308
331
  });
309
- }), o.length > 0 && !M(o)) {
332
+ }), o.length > 0 && !N(o)) {
310
333
  const a = o.find(
311
334
  (t, p) => o.some(
312
335
  (c, l) => l !== p && _(c, t)
@@ -331,7 +354,7 @@ function g(e) {
331
354
  )
332
355
  ), e.primaryMetric !== void 0 && (f(e.primaryMetric, "primaryMetric", i, {
333
356
  required: !0
334
- }), u(e.primaryMetric) && d(e.primaryMetric.name) && o.length > 0 && !N(
357
+ }), u(e.primaryMetric) && d(e.primaryMetric.name) && o.length > 0 && !R(
335
358
  e.primaryMetric,
336
359
  o
337
360
  ) && i.push(
@@ -354,15 +377,15 @@ function g(e) {
354
377
  "Metric intent dimensions must be an array of field references with names.",
355
378
  "dimensions"
356
379
  )
357
- ), e.dateField !== void 0 && f(e.dateField, "dateField", i), e.timeWindow !== void 0 && (b(e.timeWindow, "timeWindow", i), e.dateField || i.push(
380
+ ), e.dateField !== void 0 && f(e.dateField, "dateField", i), e.timeWindow !== void 0 && (g(e.timeWindow, "timeWindow", i), e.dateField || i.push(
358
381
  n(
359
382
  "missing_time_window_date_field",
360
383
  "Metric timeWindow needs a dateField.",
361
384
  "dateField"
362
385
  )
363
- )), j(e.filters, "filters", i), Array.isArray(e.dimensions) && e.dimensions.forEach((a, t) => {
386
+ )), F(e.filters, "filters", i), Array.isArray(e.dimensions) && e.dimensions.forEach((a, t) => {
364
387
  f(a, `dimensions.${t}`, i);
365
- }), R(e, i);
388
+ }), x(e, i);
366
389
  } else e.kind === "records" ? (!Array.isArray(e.fields) || e.fields.length === 0 ? i.push(
367
390
  n(
368
391
  "missing_record_fields",
@@ -414,10 +437,10 @@ function g(e) {
414
437
  ok: i.length === 0,
415
438
  errors: i,
416
439
  warnings: s,
417
- repairHints: x(i)
440
+ repairHints: D(i)
418
441
  };
419
442
  }
420
- function q(e) {
443
+ function T(e) {
421
444
  const i = [], s = [];
422
445
  if (!e || typeof e != "object")
423
446
  return {
@@ -468,7 +491,7 @@ function q(e) {
468
491
  "instruction"
469
492
  )
470
493
  ), e.analyticsIntent) {
471
- const r = g(
494
+ const r = A(
472
495
  e.analyticsIntent
473
496
  );
474
497
  i.push(...r.errors), s.push(...r.warnings);
@@ -488,7 +511,7 @@ function q(e) {
488
511
  repairHints: k(i)
489
512
  };
490
513
  }
491
- function T(e) {
514
+ function C(e) {
492
515
  const i = [], s = [];
493
516
  if (!e || typeof e != "object")
494
517
  return {
@@ -516,7 +539,7 @@ function T(e) {
516
539
  "kind"
517
540
  )
518
541
  );
519
- const r = q(e.operationIntent);
542
+ const r = T(e.operationIntent);
520
543
  return i.push(...r.errors), s.push(...r.warnings), Array.isArray(e.plannedToolCalls) || i.push(
521
544
  n(
522
545
  "invalid_planned_tool_calls",
@@ -536,7 +559,7 @@ function k(e) {
536
559
  recommendedNextStep: i.code === "missing_obligations" ? "Normalize the user request into one or more typed analytics obligations before recovery planning." : "Correct the operation/recovery contract shape before planning execution."
537
560
  }));
538
561
  }
539
- function x(e) {
562
+ function D(e) {
540
563
  return e.map((i) => {
541
564
  switch (i.code) {
542
565
  case "missing_source":
@@ -589,7 +612,7 @@ function x(e) {
589
612
  }
590
613
  }).filter((i) => !!i);
591
614
  }
592
- function F(e, i, s, r) {
615
+ function E(e, i, s, r) {
593
616
  if (!e || typeof e != "object") {
594
617
  s.push(n("invalid_view", "Dashboard view must be an object.", i));
595
618
  return;
@@ -624,7 +647,7 @@ function F(e, i, s, r) {
624
647
  );
625
648
  return;
626
649
  }
627
- const o = g(e.analytics);
650
+ const o = A(e.analytics);
628
651
  for (const a of o.errors)
629
652
  s.push(
630
653
  n(a.code, a.message, `${i}.analytics${a.path ? `.${a.path}` : ""}`)
@@ -638,7 +661,7 @@ function F(e, i, s, r) {
638
661
  )
639
662
  );
640
663
  }
641
- function B(e) {
664
+ function P(e) {
642
665
  const i = [], s = [];
643
666
  if (!e || typeof e != "object")
644
667
  return {
@@ -652,7 +675,7 @@ function B(e) {
652
675
  warnings: s
653
676
  };
654
677
  e.version !== 1 && i.push(n("invalid_version", "Dashboard intent version must be 1.")), e.kind !== "dashboard" && i.push(n("invalid_kind", "Experience intent kind must be dashboard.")), d(e.title) || i.push(n("missing_title", "Dashboard intent needs a title.", "title"));
655
- const r = Array.isArray(e.inputs) ? e.inputs : [], o = h(
678
+ const r = Array.isArray(e.inputs) ? e.inputs : [], o = v(
656
679
  r.filter(u).map((c) => c.id).filter((c) => typeof c == "string")
657
680
  );
658
681
  o && i.push(
@@ -684,7 +707,7 @@ function B(e) {
684
707
  );
685
708
  const t = a.flatMap(
686
709
  (c) => c && typeof c == "object" && Array.isArray(c.views) ? c.views.filter(u).map((l) => l.id).filter((l) => !!l) : []
687
- ), p = h(t);
710
+ ), p = v(t);
688
711
  p && i.push(
689
712
  n(
690
713
  "duplicate_view_id",
@@ -712,9 +735,9 @@ function B(e) {
712
735
  );
713
736
  continue;
714
737
  }
715
- for (const [w, A] of l.views.entries())
716
- F(
717
- A,
738
+ for (const [w, I] of l.views.entries())
739
+ E(
740
+ I,
718
741
  `${m}.views.${w}`,
719
742
  i,
720
743
  s
@@ -723,13 +746,13 @@ function B(e) {
723
746
  return { ok: i.length === 0, errors: i, warnings: s };
724
747
  }
725
748
  export {
726
- q as a,
727
- T as b,
728
- B as c,
729
- I as d,
730
- S as e,
731
- D as f,
749
+ T as a,
750
+ C as b,
751
+ P as c,
752
+ S as d,
753
+ M as e,
754
+ B as f,
732
755
  $ as p,
733
756
  y as s,
734
- g as v
757
+ A as v
735
758
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-DT9osgRT.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-BNZjkxPH.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { D as o } from "../chunks/index-DVPvpd8u.js";
1
+ import { D as o } from "../chunks/index-CuSvSh86.js";
2
2
  import { C as s, E as C } from "../chunks/common-types-4bjoIgvm.js";
3
3
  export {
4
4
  s as CONTROL_CARD_DEFAULT_VALUE,
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../chunks/validators-CfP-49k9.js"),Se=require("../chunks/catalog-field-grounding-Du6mKDcF.js"),re=["lg","md","sm","xs","xxs"],$=10;function _(e){return e&&typeof e=="object"?e:null}function D(e){return typeof e=="string"?e:null}function ae(e){var t,n,r;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((n=_(e))==null?void 0:n.kind)==="physical"||((r=_(e))==null?void 0:r.kind)==="sql")}function N(e){return ae(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function we(e){return v.semaphorSourceIdentityKey(e)}function G(e,t){return v.semaphorSourcesReferToSameDataset(e,t)}function ie(e,t){return v.preferSemaphorSourceMetadata(e,t)}function M(e){const t=[];for(const n of e){const r=t.findIndex(a=>G(a,n));r===-1?t.push(n):t[r]=ie(t[r],n)}return t}function ve(e){return M(e)[0]}function H(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!v.semaphorSourcesReferToSameDataset(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function W(e){return N(e)?e:void 0}function ne(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(n=>(n==null?void 0:n.kind)==="semantic"&&v.semaphorSourcesReferToSameDataset(e,n)&&!!n.connectionId)}function w(e,t){const n=W(e==null?void 0:e.source);return n?H(n,t):void 0}function oe({explicitSource:e,field:t,defaultSource:n,fallbackSources:r}){const a=[n,...r||[]],i=W(e),o=i?H(i,ne(i,a)):void 0;if(o)return o;if(e!==void 0)return;const d=w(t,n),s=d?H(d,ne(d,a)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return W(n)}function De(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const n=w(e),r=w(t);return!n||!r?!0:G(n,r)}function C(e){var t;return D((t=_(e))==null?void 0:t.kind)}function se(e){var t,n;return C(e)!=="semantic"?null:((n=D((t=_(e))==null?void 0:t.domainId))==null?void 0:n.trim())||null}function Ae(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetName)}function Ce(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetId)}function ke(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.connectionId)}function xe(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.tableName)}function Fe(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.databaseName)||""}function Te(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.schemaName)||""}function de(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function ce({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const n=e.map(se),r=new Set(n.filter(Boolean));return n.some(a=>!a)||r.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function z(e,t){if(!t)return!1;if(t.kind==="semantic"){const n=Ce(e);return se(e)===t.domainId?n&&t.datasetId?n===t.datasetId:Ae(e)===t.datasetName:!1}return t.kind==="physical"?ke(e)===t.connectionId&&xe(e)===t.tableName&&Fe(e)===(t.databaseName||"")&&Te(e)===(t.schemaName||""):!1}function $e(e,t){return e.find(n=>z(n,t))}function f(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function B(e){const t=new Set;for(const n of e){if(t.has(n))return n;t.add(n)}return null}function le({card:e,datasets:t,errors:n}){if(e.type==="text")return;const r=de(e);if(!r){if(t.length<=1)return;n.push(f("missing_card_analytics_source","Multi-dataset dashboard cards must include analytics intent with a source so the materializer can choose the correct dataset.",e.id));return}t.some(a=>z(a,r))||n.push(f("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function V(e){return e.map(t=>t==null?void 0:t.source).filter(t=>!!t)}function L(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Me(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Ne(e){var n;if(!e)return[];const t=[e.source];return e.kind==="metric"?t.push(...V([...L(e.metrics),e.primaryMetric,e.dateField,...L(e.dimensions),...Me(e.filters).map(r=>r.field)])):e.kind==="records"?t.push(...V([...L(e.fields),e.dateField,(n=e.orderBy)==null?void 0:n.field])):e.kind==="inputOptions"?t.push(...V([e.field])):e.kind==="sql"&&t.push(...V(e.fields||[])),t}function ue({card:e,datasets:t,errors:n}){if(e.type!=="text"){for(const r of Ne(e.analyticsIntent))if(r&&!t.some(a=>z(a,r))){n.push(f("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function fe({card:e,errors:t}){if(e.type==="text"||!e.analyticsIntent)return;const n=v.validateSemaphorAnalyticsIntent(e.analyticsIntent);if(!n.ok)for(const r of n.errors)t.push(f(r.code,r.path?`${r.path}: ${r.message}`:r.message,e.id))}function pe({datasets:e,errors:t,requireAtLeastOne:n}){const r=ce({datasets:e,requireAtLeastOne:n});if(!r.ok){if(r.issue==="invalid_dataset_count"){t.push(f("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(f("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function he(e){var p,S;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[f("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const n=e,r=[...n.warnings||[]];n.version!==1&&t.push(f("invalid_version","Dashboard plan version must be 1.")),(p=n.title)!=null&&p.trim()||t.push(f("missing_title","Dashboard plan needs a title."));const a=Array.isArray(n.datasets)?n.datasets:[],i=Array.isArray(n.sheets)?n.sheets:[];pe({datasets:a,errors:t,requireAtLeastOne:!0}),i.length!==1&&t.push(f("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const o=i[0];o&&o.kind!=="dashboard"&&t.push(f("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(o==null?void 0:o.cards)||[];d.length>$&&t.push(f("too_many_cards",`Generated dashboards can contain at most ${$} cards.`));const s=B(d.map(l=>l.id));s&&t.push(f("duplicate_card_id",`Duplicate generated card id: ${s}.`));const u=B(d.map(l=>l.frameId));u&&t.push(f("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const l of d)(S=l.title)!=null&&S.trim()||t.push(f("missing_card_title","Card title is required.",l.id)),l.type==="custom"&&t.push(f("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.id)),l.type!=="text"&&!l.analyticsIntent&&r.push(f("missing_analytics_intent","Non-text card has no analytics intent and may be skipped by the app layer.",l.id)),le({card:l,datasets:a,errors:t}),fe({card:l,errors:t}),ue({card:l,datasets:a,errors:t});const h=Array.isArray(n.filterInputs)?n.filterInputs:[],b=h.map(l=>l.id),y=B(b);y&&t.push(f("duplicate_input_id",`Duplicate dashboard input id: ${y}.`));const c=h.map(l=>l.variableName).filter(Boolean)||[],g=B(c);g&&t.push(f("duplicate_input_variable",`Duplicate dashboard input variable name: ${g}.`));const A=Array.isArray(n.calculatedFields)?n.calculatedFields:[];for(const l of A)l.scope==="domain"&&l.reuseOnly!==!0&&t.push(f("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:r}}function me(e){var o;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[f("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const n=e,r=[...n.warnings||[]];n.version!==1&&t.push(f("invalid_version","Dashboard change plan version must be 1.")),(o=n.dashboardId)!=null&&o.trim()||t.push(f("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const a=Array.isArray(n.datasets)?n.datasets:[],i=Array.isArray(n.operations)?n.operations:[];pe({datasets:a,errors:t,requireAtLeastOne:!1});for(const d of i){if(d.kind==="unsupported"){r.push(f("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(f("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(le({card:d.card,datasets:a,errors:t}),fe({card:d.card,errors:t}),ue({card:d.card,datasets:a,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(f("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${d.field.name}" is outside MVP.`))}return{ok:t.length===0,errors:t,warnings:r}}const Pe={lg:48,md:36,sm:24,xs:12,xxs:6};function Re(e,t){let n=0,r=0,a=0;return e.map(i=>{const o=Math.min(i.w,t);n>0&&n+o>t&&(n=0,r+=a,a=0);const d={i:i.frameId,x:n,y:r,w:o,h:i.h,minW:Math.min(i.minW,t),minH:i.minH,static:!1};return n+=o,a=Math.max(a,i.h),d})}function Be(e){const t=[...e].sort((s,u)=>s.priority-u.priority),n=t.filter(s=>s.role==="kpi"),r=t.filter(s=>s.role==="chart"),a=t.filter(s=>s.role==="table"),i=t.filter(s=>s.role==="text"),o=i.slice(0,1),d=i.slice(o.length);return{kpis:n,introText:o,charts:r,tables:a,supportingText:d}}function Ve(e,t,n){return t==="xxs"||t==="xs"?n:t==="sm"?Math.min(12,n):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function ze(e,t,n,r){return n==="xxs"||n==="xs"||n==="sm"||n==="md"||t===1||t%2===1&&e===0?r:r/2}function Oe(e){const{item:t,band:n,index:r,bandCount:a,breakpoint:i,columns:o}=e;return n==="kpi"?{...t,band:n,w:Ve(a,i,o),h:15,minW:Math.min(6,o),minH:12}:n==="table"?{...t,band:n,w:o,h:i==="xxs"||i==="xs"?34:38,minW:Math.min(12,o),minH:18}:n==="introText"?{...t,band:n,w:o,h:i==="xxs"||i==="xs"?12:10,minW:Math.min(12,o),minH:8}:n==="supportingText"?{...t,band:n,w:i==="lg"?o/2:o,h:i==="xxs"||i==="xs"?12:10,minW:Math.min(12,o),minH:8}:{...t,band:n,w:ze(r,a,i,o),h:i==="xxs"||i==="xs"?28:30,minW:Math.min(12,o),minH:16}}function x(e,t,n,r){return e.map((a,i)=>Oe({item:a,band:t,index:i,bandCount:e.length,breakpoint:n,columns:r}))}function O(e){const t=Be(e);return Object.fromEntries(re.map(n=>{const r=Pe[n],a=[...x(t.introText,"introText",n,r),...x(t.kpis,"kpi",n,r),...x(t.charts,"chart",n,r),...x(t.tables,"table",n,r),...x(t.supportingText,"supportingText",n,r)];return[n,Re(a,r)]}))}function qe(e){const t=Se.normalizeAnalyticsCatalogDataType(e);return t==="datetime"?"date":t==="unknown"?"string":t}function Le(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function je(e){return Le(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function Ee(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function He(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function K(e,t){if(t===void 0)return;const n=qe(e.dataType),r=e.operation||"in";if(je(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:n,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(r==="is null"||r==="is not null")return{filterId:e.id,name:e.column,operation:r,valueType:n,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const a=Array.isArray(t)?t:[t],i=n==="date"?He(a):Ee(a);if(i.length!==0&&!((r==="between"||r==="not between")&&i.length<2))return{filterId:e.id,name:e.column,operation:r,valueType:n,values:i,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function We(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function Ge(e,t,n){const r=(t||[]).filter(a=>a.scope==="card"&&a.targetCardId===n).map(a=>a.field).filter(Boolean);return r.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...r]}}function Ke(e){const t={};return{inputs:(e.filterInputs||[]).map((r,a)=>{const i=K(r.filter,r.defaultValue);return i&&(t.shared??(t.shared={}),t.shared[r.id]={status:"set",value:{kind:"filter",filterValue:i}}),{id:r.id,kind:"filter",label:r.label,variableName:r.variableName,scope:r.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:a},exports:["label","value","start","end","range"],filter:r.filter}}),defaultInputValues:t.shared&&Object.keys(t.shared).length>0?t:void 0}}function Ue(e){var b,y;const t=he(e.plan);if(!t.ok)throw new Error(t.errors.map(c=>c.message).join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../chunks/validators-Caj7EMd1.js"),Se=require("../chunks/catalog-field-grounding-Du6mKDcF.js"),re=["lg","md","sm","xs","xxs"],$=10;function _(e){return e&&typeof e=="object"?e:null}function D(e){return typeof e=="string"?e:null}function ae(e){var t,n,r;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((n=_(e))==null?void 0:n.kind)==="physical"||((r=_(e))==null?void 0:r.kind)==="sql")}function N(e){return ae(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function we(e){return v.semaphorSourceIdentityKey(e)}function G(e,t){return v.semaphorSourcesReferToSameDataset(e,t)}function ie(e,t){return v.preferSemaphorSourceMetadata(e,t)}function M(e){const t=[];for(const n of e){const r=t.findIndex(a=>G(a,n));r===-1?t.push(n):t[r]=ie(t[r],n)}return t}function ve(e){return M(e)[0]}function H(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!v.semaphorSourcesReferToSameDataset(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function W(e){return N(e)?e:void 0}function ne(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(n=>(n==null?void 0:n.kind)==="semantic"&&v.semaphorSourcesReferToSameDataset(e,n)&&!!n.connectionId)}function w(e,t){const n=W(e==null?void 0:e.source);return n?H(n,t):void 0}function oe({explicitSource:e,field:t,defaultSource:n,fallbackSources:r}){const a=[n,...r||[]],i=W(e),o=i?H(i,ne(i,a)):void 0;if(o)return o;if(e!==void 0)return;const d=w(t,n),s=d?H(d,ne(d,a)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return W(n)}function De(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const n=w(e),r=w(t);return!n||!r?!0:G(n,r)}function C(e){var t;return D((t=_(e))==null?void 0:t.kind)}function se(e){var t,n;return C(e)!=="semantic"?null:((n=D((t=_(e))==null?void 0:t.domainId))==null?void 0:n.trim())||null}function Ae(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetName)}function Ce(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetId)}function ke(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.connectionId)}function xe(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.tableName)}function Fe(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.databaseName)||""}function Te(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.schemaName)||""}function de(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function ce({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const n=e.map(se),r=new Set(n.filter(Boolean));return n.some(a=>!a)||r.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function z(e,t){if(!t)return!1;if(t.kind==="semantic"){const n=Ce(e);return se(e)===t.domainId?n&&t.datasetId?n===t.datasetId:Ae(e)===t.datasetName:!1}return t.kind==="physical"?ke(e)===t.connectionId&&xe(e)===t.tableName&&Fe(e)===(t.databaseName||"")&&Te(e)===(t.schemaName||""):!1}function $e(e,t){return e.find(n=>z(n,t))}function f(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function B(e){const t=new Set;for(const n of e){if(t.has(n))return n;t.add(n)}return null}function le({card:e,datasets:t,errors:n}){if(e.type==="text")return;const r=de(e);if(!r){if(t.length<=1)return;n.push(f("missing_card_analytics_source","Multi-dataset dashboard cards must include analytics intent with a source so the materializer can choose the correct dataset.",e.id));return}t.some(a=>z(a,r))||n.push(f("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function V(e){return e.map(t=>t==null?void 0:t.source).filter(t=>!!t)}function L(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Me(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Ne(e){var n;if(!e)return[];const t=[e.source];return e.kind==="metric"?t.push(...V([...L(e.metrics),e.primaryMetric,e.dateField,...L(e.dimensions),...Me(e.filters).map(r=>r.field)])):e.kind==="records"?t.push(...V([...L(e.fields),e.dateField,(n=e.orderBy)==null?void 0:n.field])):e.kind==="inputOptions"?t.push(...V([e.field])):e.kind==="sql"&&t.push(...V(e.fields||[])),t}function ue({card:e,datasets:t,errors:n}){if(e.type!=="text"){for(const r of Ne(e.analyticsIntent))if(r&&!t.some(a=>z(a,r))){n.push(f("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function fe({card:e,errors:t}){if(e.type==="text"||!e.analyticsIntent)return;const n=v.validateSemaphorAnalyticsIntent(e.analyticsIntent);if(!n.ok)for(const r of n.errors)t.push(f(r.code,r.path?`${r.path}: ${r.message}`:r.message,e.id))}function pe({datasets:e,errors:t,requireAtLeastOne:n}){const r=ce({datasets:e,requireAtLeastOne:n});if(!r.ok){if(r.issue==="invalid_dataset_count"){t.push(f("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(f("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function he(e){var p,S;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[f("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const n=e,r=[...n.warnings||[]];n.version!==1&&t.push(f("invalid_version","Dashboard plan version must be 1.")),(p=n.title)!=null&&p.trim()||t.push(f("missing_title","Dashboard plan needs a title."));const a=Array.isArray(n.datasets)?n.datasets:[],i=Array.isArray(n.sheets)?n.sheets:[];pe({datasets:a,errors:t,requireAtLeastOne:!0}),i.length!==1&&t.push(f("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const o=i[0];o&&o.kind!=="dashboard"&&t.push(f("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(o==null?void 0:o.cards)||[];d.length>$&&t.push(f("too_many_cards",`Generated dashboards can contain at most ${$} cards.`));const s=B(d.map(l=>l.id));s&&t.push(f("duplicate_card_id",`Duplicate generated card id: ${s}.`));const u=B(d.map(l=>l.frameId));u&&t.push(f("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const l of d)(S=l.title)!=null&&S.trim()||t.push(f("missing_card_title","Card title is required.",l.id)),l.type==="custom"&&t.push(f("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.id)),l.type!=="text"&&!l.analyticsIntent&&r.push(f("missing_analytics_intent","Non-text card has no analytics intent and may be skipped by the app layer.",l.id)),le({card:l,datasets:a,errors:t}),fe({card:l,errors:t}),ue({card:l,datasets:a,errors:t});const h=Array.isArray(n.filterInputs)?n.filterInputs:[],b=h.map(l=>l.id),y=B(b);y&&t.push(f("duplicate_input_id",`Duplicate dashboard input id: ${y}.`));const c=h.map(l=>l.variableName).filter(Boolean)||[],g=B(c);g&&t.push(f("duplicate_input_variable",`Duplicate dashboard input variable name: ${g}.`));const A=Array.isArray(n.calculatedFields)?n.calculatedFields:[];for(const l of A)l.scope==="domain"&&l.reuseOnly!==!0&&t.push(f("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:r}}function me(e){var o;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[f("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const n=e,r=[...n.warnings||[]];n.version!==1&&t.push(f("invalid_version","Dashboard change plan version must be 1.")),(o=n.dashboardId)!=null&&o.trim()||t.push(f("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const a=Array.isArray(n.datasets)?n.datasets:[],i=Array.isArray(n.operations)?n.operations:[];pe({datasets:a,errors:t,requireAtLeastOne:!1});for(const d of i){if(d.kind==="unsupported"){r.push(f("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(f("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(le({card:d.card,datasets:a,errors:t}),fe({card:d.card,errors:t}),ue({card:d.card,datasets:a,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(f("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${d.field.name}" is outside MVP.`))}return{ok:t.length===0,errors:t,warnings:r}}const Pe={lg:48,md:36,sm:24,xs:12,xxs:6};function Re(e,t){let n=0,r=0,a=0;return e.map(i=>{const o=Math.min(i.w,t);n>0&&n+o>t&&(n=0,r+=a,a=0);const d={i:i.frameId,x:n,y:r,w:o,h:i.h,minW:Math.min(i.minW,t),minH:i.minH,static:!1};return n+=o,a=Math.max(a,i.h),d})}function Be(e){const t=[...e].sort((s,u)=>s.priority-u.priority),n=t.filter(s=>s.role==="kpi"),r=t.filter(s=>s.role==="chart"),a=t.filter(s=>s.role==="table"),i=t.filter(s=>s.role==="text"),o=i.slice(0,1),d=i.slice(o.length);return{kpis:n,introText:o,charts:r,tables:a,supportingText:d}}function Ve(e,t,n){return t==="xxs"||t==="xs"?n:t==="sm"?Math.min(12,n):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function ze(e,t,n,r){return n==="xxs"||n==="xs"||n==="sm"||n==="md"||t===1||t%2===1&&e===0?r:r/2}function Oe(e){const{item:t,band:n,index:r,bandCount:a,breakpoint:i,columns:o}=e;return n==="kpi"?{...t,band:n,w:Ve(a,i,o),h:15,minW:Math.min(6,o),minH:12}:n==="table"?{...t,band:n,w:o,h:i==="xxs"||i==="xs"?34:38,minW:Math.min(12,o),minH:18}:n==="introText"?{...t,band:n,w:o,h:i==="xxs"||i==="xs"?12:10,minW:Math.min(12,o),minH:8}:n==="supportingText"?{...t,band:n,w:i==="lg"?o/2:o,h:i==="xxs"||i==="xs"?12:10,minW:Math.min(12,o),minH:8}:{...t,band:n,w:ze(r,a,i,o),h:i==="xxs"||i==="xs"?28:30,minW:Math.min(12,o),minH:16}}function x(e,t,n,r){return e.map((a,i)=>Oe({item:a,band:t,index:i,bandCount:e.length,breakpoint:n,columns:r}))}function O(e){const t=Be(e);return Object.fromEntries(re.map(n=>{const r=Pe[n],a=[...x(t.introText,"introText",n,r),...x(t.kpis,"kpi",n,r),...x(t.charts,"chart",n,r),...x(t.tables,"table",n,r),...x(t.supportingText,"supportingText",n,r)];return[n,Re(a,r)]}))}function qe(e){const t=Se.normalizeAnalyticsCatalogDataType(e);return t==="datetime"?"date":t==="unknown"?"string":t}function Le(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function je(e){return Le(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function Ee(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function He(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function K(e,t){if(t===void 0)return;const n=qe(e.dataType),r=e.operation||"in";if(je(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:n,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(r==="is null"||r==="is not null")return{filterId:e.id,name:e.column,operation:r,valueType:n,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const a=Array.isArray(t)?t:[t],i=n==="date"?He(a):Ee(a);if(i.length!==0&&!((r==="between"||r==="not between")&&i.length<2))return{filterId:e.id,name:e.column,operation:r,valueType:n,values:i,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function We(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function Ge(e,t,n){const r=(t||[]).filter(a=>a.scope==="card"&&a.targetCardId===n).map(a=>a.field).filter(Boolean);return r.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...r]}}function Ke(e){const t={};return{inputs:(e.filterInputs||[]).map((r,a)=>{const i=K(r.filter,r.defaultValue);return i&&(t.shared??(t.shared={}),t.shared[r.id]={status:"set",value:{kind:"filter",filterValue:i}}),{id:r.id,kind:"filter",label:r.label,variableName:r.variableName,scope:r.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:a},exports:["label","value","start","end","range"],filter:r.filter}}),defaultInputValues:t.shared&&Object.keys(t.shared).length>0?t:void 0}}function Ue(e){var b,y;const t=he(e.plan);if(!t.ok)throw new Error(t.errors.map(c=>c.message).join(`
2
2
  `)||"Dashboard plan is invalid.");const n=e.plan.sheets[0],r=[...t.warnings],a=[],i=new Map(e.cardArtifacts.map(c=>[c.planCardId,c])),o=[];for(const c of n.cards){const g=i.get(c.id);if(!g){const p=We("missing_card_artifact",`Card "${c.title}" was skipped because no generated artifact was supplied.`,c.id);a.push(p);continue}r.push(...g.warnings||[]);const A=Ge(g.card,e.plan.calculatedFields,c.id);o.push({id:c.frameId,cards:[A],activeCardId:A.id})}if(o.length===0)throw new Error("Dashboard plan did not produce any persistable cards.");const{inputs:d,defaultInputValues:s}=Ke(e.plan),u=O(n.cards.filter(c=>o.some(g=>g.id===c.frameId)).map(c=>({frameId:c.frameId,priority:c.priority,role:c.role})));return{dashboard:{id:e.dashboardId,title:e.plan.title,description:e.plan.description||"",sheets:[{id:n.id,kind:"dashboard",title:n.title,description:n.description,frames:o,layouts:u,calculatedFields:(b=e.plan.calculatedFields)==null?void 0:b.filter(c=>c.scope==="sheet"&&c.field).map(c=>c.field)}],calculatedFields:(y=e.plan.calculatedFields)==null?void 0:y.filter(c=>c.scope==="dashboard"&&c.field).map(c=>c.field),inputs:d,...s?{defaultInputValues:s}:{}},warnings:r,skippedOperations:a}}function k(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function Xe(e){return JSON.parse(JSON.stringify(e))}function Je(e){var t;return(t=e.sheets)==null?void 0:t.find(n=>(n.kind||"dashboard")==="dashboard")}function j(e,t){var n;for(const r of e.sheets||[])for(const a of r.frames||[]){const i=(n=a.cards)==null?void 0:n.find(o=>o.id===t);if(i)return{sheet:r,frame:a,card:i}}return null}function ge(e){var n,r;const t=(r=(n=e.cards)==null?void 0:n[0])==null?void 0:r.type;return t==="kpi"?"kpi":t==="table"||t==="detailTable"||t==="pivotTable"?"table":t==="text"?"text":"chart"}function Qe(e){var t;return new Map((((t=e.layouts)==null?void 0:t.lg)||[]).map((n,r)=>[n.i,r]))}function be(e,t=new Map){const n=Qe(e),r=Math.max(n.size,t.size),a=(e.frames||[]).map((i,o)=>({frameId:i.id,role:ge(i),priority:t.get(i.id)??n.get(i.id)??r+o}));e.layouts=O(a)}function Ye(e){return Object.values(e.layouts||{}).some(t=>t.length>0)}function Ze(e,t){if(!Ye(e)){be(e);return}const n=O([{frameId:t.id,role:ge(t),priority:0}]);e.layouts??(e.layouts={});for(const[r,a]of Object.entries(n)){const i=e.layouts[r]||[];if(i.some(s=>s.i===t.id))continue;const o=a[0];if(!o)continue;const d=i.reduce((s,u)=>Math.max(s,u.y+u.h),0);e.layouts[r]=[...i,{...o,y:d}]}}function et(e,t){var r;const n=K(t.filter,t.defaultValue);n&&(e.defaultInputValues??(e.defaultInputValues={}),(r=e.defaultInputValues).shared??(r.shared={}),e.defaultInputValues.shared[t.id]={status:"set",value:{kind:"filter",filterValue:n}})}function tt(e){var d;const t=me(e.changePlan);if(!t.ok)throw new Error(t.errors.map(s=>s.message).join(`
3
3
  `)||"Dashboard change plan is invalid.");const n=Xe(e.dashboard),r=[...t.warnings],a=[],i=new Map(e.cardArtifacts.map(s=>[s.planCardId,s])),o=Je(n);if(!o)throw new Error("Dashboard has no editable dashboard sheet.");o.frames??(o.frames=[]);for(const s of e.changePlan.operations)switch(s.kind){case"addCard":{if((o.frames||[]).reduce((y,c)=>{var g;return y+(((g=c.cards)==null?void 0:g.length)||0)},0)>=$){a.push(k("generated_card_limit_reached",`MVP AI refinement is capped at ${$} cards.`,s.card.id));break}const h=i.get(s.card.id);if(!h){a.push(k("missing_card_artifact",`Card "${s.card.title}" was skipped because no generated artifact was supplied.`,s.card.id));break}const b={id:s.card.frameId,cards:[h.card],activeCardId:h.card.id};o.frames.push(b),Ze(o,b);break}case"addFilterInput":{n.inputs??(n.inputs=[]);const u={id:s.input.id,kind:"filter",label:s.input.label,variableName:s.input.variableName,scope:s.input.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:n.inputs.length},exports:["label","value","start","end","range"],filter:s.input.filter};n.inputs.push(u),et(n,s.input);break}case"addCalculatedField":{if(s.field.scope==="dashboard"&&s.field.field)n.calculatedFields??(n.calculatedFields=[]),n.calculatedFields.push(s.field.field);else if(s.field.scope==="sheet"&&s.field.field)o.calculatedFields??(o.calculatedFields=[]),o.calculatedFields.push(s.field.field);else if(s.field.scope==="card"&&s.field.field){const u=s.field.targetCardId?j(n,s.field.targetCardId):null;u?((d=u.card).calculatedFields??(d.calculatedFields=[]),u.card.calculatedFields.push(s.field.field)):a.push(k("missing_calculated_field_target",`Calculated field "${s.field.name}" needs a valid target card.`))}break}case"renameCard":{const u=j(n,s.cardId);if(!u){a.push(k("card_not_found",`Card "${s.cardId}" could not be renamed because it was not found.`,s.cardId));break}u.card.title=s.title,s.description!==void 0&&(u.card.description=s.description);break}case"reorderCards":{const u=new Map;for(let h=0;h<s.cardIds.length;h+=1){const b=s.cardIds[h],y=j(n,b);y&&u.set(y.frame.id,h)}be(o,u);break}case"reuseCalculatedField":r.push(k("reused_calculated_field",`Calculated field "${s.fieldId}" is reused by reference.`));break;case"unsupported":a.push(k("unsupported_operation",s.reason||s.requestedAction));break}return{dashboard:n,warnings:r,skippedOperations:a}}function I(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function T(e,t){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||t}function Ie(e,t){if(!t.has(e))return t.add(e),e;let n=2,r=`${e}-${n}`;for(;t.has(r);)n+=1,r=`${e}-${n}`;return t.add(r),r}function P(e){return!!(e&&typeof e=="object")}function ye(e){return Array.isArray(e.inputs)?e.inputs.filter(t=>P(t)&&typeof t.id=="string"):[]}function U(e){return Array.isArray(e.sections)?e.sections.filter(t=>P(t)):[]}function X(e){return Array.isArray(e.views)?e.views.filter(t=>P(t)):[]}function F(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const r=w(n);r&&t.push(r)}return t}function nt(e){var r;if(!e)return[];const t=[];if(N(e.source)&&t.push(e.source),e.kind==="metric"){t.push(...F(e.metrics));const a=w(e.dateField);a&&t.push(a),t.push(...F(e.dimensions)),t.push(...F((r=e.filters)==null?void 0:r.map(i=>i.field)))}else if(e.kind==="records"){const a=w(e.dateField);a&&t.push(a),t.push(...F(e.fields))}else if(e.kind==="inputOptions"){const a=w(e.field);a&&t.push(a)}else e.kind==="sql"&&t.push(...F(e.fields));const n="inputs"in e&&Array.isArray(e.inputs)?e.inputs:[];for(const a of n){const i=w(a.field);i&&t.push(i)}return t}function rt(e){const t=[];for(const n of ye(e)){const r=w(n.field);r&&t.push(r)}for(const n of U(e))for(const r of X(n))t.push(...nt(r.analytics));return t}function at(e){var n;const t=[];for(const r of U(e))for(const a of X(r))N((n=a.analytics)==null?void 0:n.source)&&t.push(a.analytics.source);return t}function it(e,t){const n=M(e).filter(N);if(n.length===0)return t.push(I("missing_materializable_dataset","No semantic or physical source could be converted into the current dashboard authoring dataset reference.")),[];const r=n.every(i=>i.kind==="semantic"),a=Array.from(new Set(n.filter(i=>i.kind==="semantic").map(i=>i.domainId)));return n.length>1&&(!r||a.length!==1)?(t.push(I("multiple_datasets_out_of_scope","The dashboard authoring compiler supports multiple datasets only within one semantic domain; using the first source and deferring the rest.")),[n[0]]):n}function ot(e,t){const n=U(e),r=ye(e),a=M(rt(e)),i=M(at(e));return{sections:n,inputs:r,sources:a,primarySources:i,defaultSource:i.length===1?i[0]:void 0,datasets:it(a,t)}}function st(e){return e&&v.validateSemaphorAnalyticsIntent(e).ok?e:void 0}function dt(e){var t;switch((t=e.presentation)==null?void 0:t.kind){case"kpi":return"kpi";case"lineChart":return"line";case"barChart":return"bar";case"areaChart":return"area";case"table":return"table";case"text":return"text";default:return null}}function ct(e){var t,n,r;return((t=e.presentation)==null?void 0:t.kind)==="kpi"?"kpi":((n=e.presentation)==null?void 0:n.kind)==="table"?"table":((r=e.presentation)==null?void 0:r.kind)==="text"?"text":"chart"}function lt(e){switch(e){case"not_in":return"not in";case"not_between":return"not between";case"contains":return"like";default:return e||"in"}}function ut(e){return P(e.field)?e.field.dataType==="datetime"?"date":e.field.dataType||"string":"string"}function ft(e){if(!(!e||e.kind!=="physical"))return[e.databaseName,e.schemaName,e.tableName].filter(Boolean).join(".")}function pt(e,t,n,r,a,i){if(e.kind!=="filter")return i.push(I("control_inputs_deferred",`Control input "${e.label}" is represented in the protocol but not yet materialized by the dashboard authoring adapter.`)),null;if(!P(e.field)||typeof e.field.name!="string")return i.push(I("filter_requires_field",`Filter "${e.label||e.id}" needs a field before the dashboard compiler can materialize it.`)),null;const o=oe({explicitSource:void 0,field:e.field,defaultSource:t,fallbackSources:n}),d=(o==null?void 0:o.kind)==="semantic"||(o==null?void 0:o.kind)==="physical"?o.connectionId:void 0;if(!d)return i.push(I("filter_requires_connection_id",`Filter "${e.label}" needs a source connectionId before the dashboard compiler can materialize it.`)),null;const h={id:`filter-${Ie(T(e.id,e.field.name),a)}`,variableName:e.id,connectionId:d,title:e.label,column:e.field.name,dataType:ut(e),qualifiedTableName:ft(o),sql:"",operation:lt(e.operator),type:e.multi===!1?"single":"multiple",location:"dashboard",displayMode:"toolbar",fieldMeta:(o==null?void 0:o.kind)==="semantic"?{name:e.field.name,qualifiedFieldName:e.field.name,dataType:e.field.dataType,role:e.field.role==="measure"?"metric":"groupby"}:void 0,semanticContext:(o==null?void 0:o.kind)==="semantic"?{semanticDomainId:o.domainId,connectionId:o.connectionId}:void 0};return{id:e.id,label:e.label,variableName:e.id,scope:r,filter:h,defaultValue:K(h,e.defaultValue)}}function E(e){const t=[],n=[];for(const r of e.viewIds){const a=e.viewIdToCardId.get(r);a?t.push(a):n.push(r)}return n.length>0&&e.warnings.push(I("input_scope_view_not_found",`Filter "${e.inputLabel}" referenced unknown view ids: ${n.join(", ")}.`)),Array.from(new Set(t))}function ht(e){var r,a;if(!e.protocolScope){const i=Array.from(new Set(e.boundCardIds));return i.length>0&&i.length<e.allCardIds.length?{kind:"cards",cardIds:i}:void 0}if(e.protocolScope.level==="dashboard"){if(!((r=e.protocolScope.excludeViewIds)!=null&&r.length))return;const i=new Set(E({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:e.allCardIds.filter(o=>!i.has(o))}}if(e.protocolScope.level==="view"){const i=E({inputLabel:e.inputLabel,viewIds:e.protocolScope.viewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings});return i.length===0?(e.warnings.push(I("input_scope_has_no_materialized_cards",`Filter "${e.inputLabel}" was deferred because its view scope does not match any materialized cards.`)),null):{kind:"cards",cardIds:i}}const t=e.sectionIdToCardIds.get(e.protocolScope.sectionId)||[];if(t.length===0)return e.warnings.push(I("input_scope_section_not_found",`Filter "${e.inputLabel}" was deferred because section "${e.protocolScope.sectionId}" does not match any materialized cards.`)),null;if(!((a=e.protocolScope.excludeViewIds)!=null&&a.length))return{kind:"cards",cardIds:t};const n=new Set(E({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:t.filter(i=>!n.has(i))}}function mt(e){var c,g,A;const t=[],n=v.validateSemaphorDashboardIntent(e);for(const p of n.warnings)t.push(I(p.code,p.message));for(const p of n.errors)t.push(I(p.code,p.message));const r=ot(e,t),a=[],i=new Map,o=new Map,d=new Map,s=new Set,u=new Set;let h=0;for(const[p,S]of r.sections.entries()){const l=typeof S.title=="string"?S.title:`Section ${p+1}`,J=S.id||T(l,`section-${p+1}`);o.set(J,[]);for(const[Q,m]of X(S).entries()){const Y=dt(m),q=T(m.id||`${l}-${m.title||`View ${Q+1}`}`,`card-${p+1}-${Q+1}`);if(!Y){t.push(I("unsupported_presentation",`Dashboard presentation "${((c=m.presentation)==null?void 0:c.kind)||"unknown"}" is not supported by the dashboard authoring adapter.`,`card-${q}`));continue}if(((g=m.analytics)==null?void 0:g.kind)==="sql"){t.push(I("sql_intent_deferred","SQL analytics intent is valid protocol, but the current dashboard authoring adapter only materializes semantic and physical config-card intents.",`card-${q}`));continue}const Z=Ie(q,s),R=`card-${Z}`;m.id&&i.set(m.id,R),(A=o.get(J))==null||A.push(R);const _e=m.analytics&&"inputs"in m.analytics?m.analytics.inputs:void 0;for(const ee of _e||[]){const te=d.get(ee.inputId)||[];te.push(R),d.set(ee.inputId,te)}a.push({id:R,frameId:`frame-${Z}`,title:m.title,description:m.description,type:Y,role:ct(m),priority:h,section:l,analyticsIntent:st(m.analytics),text:m.text}),h+=1}}const b=r.inputs.map(p=>{const S=ht({protocolScope:p.scope,inputLabel:p.label,allCardIds:a.map(l=>l.id),boundCardIds:d.get(p.id)||[],viewIdToCardId:i,sectionIdToCardIds:o,warnings:t});return S===null?null:pt(p,r.defaultSource,r.sources,S,u,t)}).filter(p=>!!p);return{plan:{version:1,id:`plan-${T(e.title,"dashboard")}`,title:e.title,description:e.description,datasets:r.datasets,sheets:[{id:`sheet-${T(e.title,"dashboard")}`,title:e.title,description:e.description,kind:"dashboard",cards:a}],filterInputs:b.length?b:void 0,warnings:t.length?t:void 0,unresolvedRequests:n.ok?void 0:n.errors.map(p=>p.message)},warnings:t}}exports.DASHBOARD_AUTHORING_BREAKPOINTS=re;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=$;exports.applyDashboardChangePlan=tt;exports.compileDashboardFromPlan=Ue;exports.compileResponsiveDashboardLayouts=O;exports.dashboardAuthoringDatasetMatchesSource=z;exports.dashboardAuthoringFieldsReferToSameTarget=De;exports.dashboardAuthoringSourceFromField=w;exports.dashboardAuthoringSourceKey=we;exports.dashboardAuthoringSourcesReferToSameDataset=G;exports.dashboardPlanFromSemaphorDashboardIntent=mt;exports.findDashboardAuthoringDatasetForSource=$e;exports.getDashboardAuthoringCardSource=de;exports.isMaterializableDashboardAuthoringSource=N;exports.isSemaphorSourceRef=ae;exports.mergeDashboardAuthoringSources=M;exports.preferDashboardAuthoringSourceMetadata=ie;exports.preferredDashboardAuthoringSource=ve;exports.resolveDashboardAuthoringSource=oe;exports.validateDashboardAuthoringDatasetScope=ce;exports.validateDashboardChangePlan=me;exports.validateDashboardPlan=he;
@@ -1,4 +1,4 @@
1
- import { s as he, d as W, p as me, v as ne, c as ge } from "../chunks/validators-CPEQojnV.js";
1
+ import { s as he, d as W, p as me, v as ne, c as ge } from "../chunks/validators-YtnkRA1G.js";
2
2
  import { b as be } from "../chunks/catalog-field-grounding-DoEBOXQd.js";
3
3
  const Ie = [
4
4
  "lg",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-DT9osgRT.js");exports.DataAppBuilder=e.DataAppBuilder;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-BNZjkxPH.js");exports.DataAppBuilder=e.DataAppBuilder;
@@ -1,4 +1,4 @@
1
- import { b as r } from "../chunks/index-DVPvpd8u.js";
1
+ import { b as r } from "../chunks/index-CuSvSh86.js";
2
2
  export {
3
3
  r as DataAppBuilder
4
4
  };