react-semaphor 0.1.391 → 0.1.392

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +120 -252
  3. package/dist/brand-studio/index.cjs +1 -1
  4. package/dist/brand-studio/index.js +7 -7
  5. package/dist/chunks/analyze-result-contract-C9Gv2_qW.js +1585 -0
  6. package/dist/chunks/analyze-result-contract-Zgg-Bbpj.js +1 -0
  7. package/dist/chunks/{braces--20GzUQh.js → braces-8TRlDwDw.js} +1 -1
  8. package/dist/chunks/{braces-C0Vh_Mft.js → braces-D2tStQjF.js} +1 -1
  9. package/dist/chunks/{calendar-preferences-dialog-B-VsxhsA.js → calendar-preferences-dialog-49fcEPXS.js} +4 -4
  10. package/dist/chunks/{calendar-preferences-dialog-DE67Z3oQ.js → calendar-preferences-dialog-DwLeBLy2.js} +1 -1
  11. package/dist/chunks/dashboard-briefing-launcher-CgkSKkZR.js +80 -0
  12. package/dist/chunks/{dashboard-briefing-launcher-BIj3X7b3.js → dashboard-briefing-launcher-cgPKz1yX.js} +252 -252
  13. package/dist/chunks/dashboard-controls-D12ZSUP_.js +52 -0
  14. package/dist/chunks/{dashboard-controls-BXxucM4f.js → dashboard-controls-VMFm3OP4.js} +87 -87
  15. package/dist/chunks/{dashboard-json-C6oZuipD.js → dashboard-json-C-GG5yC7.js} +4 -4
  16. package/dist/chunks/{dashboard-json-BNwshkK2.js → dashboard-json-CvK0oI24.js} +1 -1
  17. package/dist/chunks/{edit-dashboard-visual-CmfrI_L3.js → edit-dashboard-visual-B5KB7dx4.js} +977 -977
  18. package/dist/chunks/edit-dashboard-visual-ql99faTz.js +178 -0
  19. package/dist/chunks/{index-icb12JV1.js → index-CQmKDEbe.js} +735 -741
  20. package/dist/chunks/{index-4W_ElSBJ.js → index-DXCBPLDu.js} +218 -223
  21. package/dist/chunks/{layout-grid-B7-klXiK.js → layout-grid-C0OI-MRn.js} +1 -1
  22. package/dist/chunks/{layout-grid-DV89AC9_.js → layout-grid-CiubineE.js} +1 -1
  23. package/dist/chunks/{palette-Dj-dgPYh.js → palette-C4KTXOug.js} +1 -1
  24. package/dist/chunks/{palette-5IwhMbSF.js → palette-Cp1hqZtm.js} +1 -1
  25. package/dist/chunks/{save-C5fwVdTF.js → save-C__QggEE.js} +1 -1
  26. package/dist/chunks/{save-16C6YSW2.js → save-DgMfP0j8.js} +1 -1
  27. package/dist/chunks/{search-0LmWwZzW.js → search-BHsQIWBV.js} +17 -7
  28. package/dist/chunks/{search-Dq1Mbb03.js → search-DNCejM7Z.js} +9 -4
  29. package/dist/chunks/source-identity-uMaUe036.js +1 -0
  30. package/dist/chunks/{source-identity-CN4xiyKJ.js → source-identity-y0VSSreA.js} +33 -15
  31. package/dist/chunks/{switch-bdJp0Bkw.js → switch-B79Hn4Qh.js} +27 -32
  32. package/dist/chunks/{switch-DUdaHFZQ.js → switch-BXQAlSuW.js} +637 -647
  33. package/dist/chunks/use-create-flow-overlay-state-7MFN3PWX.js +21 -0
  34. package/dist/chunks/{use-create-flow-overlay-state-YvqCp6Zo.js → use-create-flow-overlay-state-Bw5LRkf9.js} +93 -92
  35. package/dist/chunks/{validators-CHPH6ORs.js → validators-4EGCWWga.js} +1 -1
  36. package/dist/chunks/{validators-lWo8m0Q7.js → validators-CPtkrola.js} +1 -1
  37. package/dist/chunks/{x-B_cx7LwM.js → x-B6ghREd2.js} +10 -5
  38. package/dist/chunks/{x-IdR_js6f.js → x-CXDkqdur.js} +28 -18
  39. package/dist/dashboard/index.cjs +1 -1
  40. package/dist/dashboard/index.js +1 -1
  41. package/dist/dashboard-authoring/index.cjs +1 -1
  42. package/dist/dashboard-authoring/index.js +3 -3
  43. package/dist/data-app-builder/index.cjs +13 -13
  44. package/dist/data-app-builder/index.js +11 -11
  45. package/dist/data-app-sdk/index.cjs +5 -5
  46. package/dist/data-app-sdk/index.js +1589 -1234
  47. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  48. package/dist/data-app-sdk-adapters/index.js +6 -7
  49. package/dist/data-app-sdk-validation/index.cjs +1 -1
  50. package/dist/data-app-sdk-validation/index.js +3 -3
  51. package/dist/index.cjs +1 -1
  52. package/dist/index.js +13 -13
  53. package/dist/surfboard/index.cjs +1 -1
  54. package/dist/surfboard/index.js +2 -2
  55. package/dist/types/analytics-protocol.d.ts +2107 -43
  56. package/dist/types/dashboard-assistant.d.ts +3 -1
  57. package/dist/types/data-app-sdk-adapters.d.ts +1 -1
  58. package/dist/types/data-app-sdk-validation.d.ts +4 -2
  59. package/dist/types/data-app-sdk.d.ts +73 -5
  60. package/package.json +2 -1
  61. package/src/data-app-sdk/README.md +55 -0
  62. package/dist/chunks/analyze-result-contract-CtXfp3nv.js +0 -1
  63. package/dist/chunks/analyze-result-contract-DuhlklhI.js +0 -102
  64. package/dist/chunks/dashboard-briefing-launcher-Czx6BcXW.js +0 -80
  65. package/dist/chunks/dashboard-controls-BP-DcPFs.js +0 -52
  66. package/dist/chunks/edit-dashboard-visual-BAprin3J.js +0 -178
  67. package/dist/chunks/source-identity-C-xaeE_I.js +0 -1
  68. package/dist/chunks/use-create-flow-overlay-state-BIHKf_XK.js +0 -21
@@ -1 +1 @@
1
- "use strict";const Z=require("./source-identity-C-xaeE_I.js");function a(e,i,t){return t?{code:e,message:i,path:t}:{code:e,message:i}}function J(e){for(let i=0;i<e.length;i+=1){const t=e[i];if(e.some((n,o)=>o!==i&&U(n,t)))return!1}return!0}function L(e,i){return Z.semaphorFieldRefsMatch(e,i)}function U(e,i){return L(e,i)&&g(e)===g(i)}function W(e){return`Metric intent has duplicate measure "${e.name}" with the same aggregate (${g(e)}). Use different aggregates to request both, or remove one entry.`}function E(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null}function ee(e,i,t){if(e!==void 0){if(!e||typeof e!="object"||Array.isArray(e)){t.push(a("invalid_sql_default_parameters","SQL defaultParameters must be an object keyed by parameter name.",i));return}Object.entries(e).forEach(([n,o])=>{if(!n.trim()){t.push(a("invalid_sql_default_parameter_name","SQL defaultParameters names must be non-empty strings.",`${i}.${n}`));return}(Array.isArray(o)?o.every(E):E(o))||t.push(a("invalid_sql_default_parameter_value","SQL defaultParameters values must be strings, numbers, booleans, nulls, or arrays of those scalar values.",`${i}.${n}`))})}}function ie(e,i){return M(e,i).length===1}function te(e,i){return M(e,i).length===1}function M(e,i){return i.filter(n=>ae(e,n))}function ae(e,i){return ne(e,i)?e.source?L(i,e):!0:!1}function ne(e,i){return!(i.name!==e.name||e.role!==void 0&&i.role!==void 0&&i.role!==e.role||se(e,i)&&g(i)!==g(e))}function se(e,i){return e.role==="measure"||i.role==="measure"||e.aggregate!==void 0||i.aggregate!==void 0}function g(e){return(e.aggregate||"SUM").toUpperCase()}const oe=/^(\d{4})-(\d{2})-(\d{2})$/,re=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})$/;function $(e){if(typeof e!="string")return null;const i=e.trim(),t=oe.exec(i);if(t){const[,y,P,T]=t;return N(y,P,T)?new Date(Date.UTC(Number(y),Number(P)-1,Number(T))):null}const n=re.exec(i);if(!n)return null;const[,o,s,r,c,d,p="00",,m]=n;if(!N(o,s,r)||!v(c,0,23)||!v(d,0,59)||!v(p,0,59)||!de(m))return null;const b=new Date(i);return Number.isFinite(b.getTime())?b:null}function N(e,i,t){const n=Number(e),o=Number(i),s=Number(t);if(!Number.isInteger(n)||!Number.isInteger(o)||!Number.isInteger(s)||o<1||o>12)return!1;const r=new Date(Date.UTC(n,o-1,s));return r.getUTCFullYear()===n&&r.getUTCMonth()===o-1&&r.getUTCDate()===s}function v(e,i,t){const n=Number(e);return Number.isInteger(n)&&n>=i&&n<=t}function de(e){if(e==="Z")return!0;const i=/^([+-])(\d{2}):(\d{2})$/.exec(e);return!!(i&&v(i[2],0,23)&&v(i[3],0,59))}function l(e){return typeof e=="string"&&e.trim().length>0}function le(e){const i=new Set;let t=0;for(;t<e.length;){const n=e[t];if(n==="'"||n==='"'){t=ue(e,t);continue}if(n==="{"){const o=e.indexOf("}",t+1);if(o===-1){t+=1;continue}const s=e.slice(t+1,o);/^[A-Za-z_][A-Za-z0-9_]*$/.test(s)&&i.add(s),t=o+1;continue}t+=1}return Array.from(i)}function ue(e,i){const t=e[i];let n=i+1;for(;n<e.length;){if(e[n]===t){if(e[n+1]===t){n+=2;continue}return n+1}n+=1}return e.length}function u(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function O(e,i,t){if(e!==void 0){if(!u(e)){t.push(a("invalid_pagination","Pagination must be an object with positive integer page and pageSize.",i));return}(!Number.isInteger(e.page)||typeof e.page!="number"||e.page<1)&&t.push(a("invalid_pagination_page","Pagination page must be a positive integer.",`${i}.page`)),(!Number.isInteger(e.pageSize)||typeof e.pageSize!="number"||e.pageSize<1)&&t.push(a("invalid_pagination_page_size","Pagination pageSize must be a positive integer.",`${i}.pageSize`))}}function I(e){const i=new Set;for(const t of e){if(i.has(t))return t;i.add(t)}return null}function w(e,i,t,n){I(e.filter(s=>l(s)))&&n.push(a("duplicate_matrix_public_id",`Matrix ${t} ids must be unique so sort and expansion references are unambiguous.`,i))}const ce=new Set(["SUM","COUNT","AVG","MIN","MAX","MEDIAN","DISTINCT"]);function k(e,i,t){if(!e||typeof e!="object"){t.push(a("missing_source","Analytics intent needs a source.",i));return}if(e.kind==="semantic"){l(e.domainId)||t.push(a("missing_semantic_domain","Semantic source needs a domainId.",`${i}.domainId`)),l(e.datasetName)||t.push(a("missing_dataset_name","Semantic source needs a datasetName.",`${i}.datasetName`));return}if(e.kind==="physical"){l(e.connectionId)||t.push(a("missing_connection_id","Physical source needs a connectionId.",`${i}.connectionId`)),l(e.tableName)||t.push(a("missing_table_name","Physical source needs a tableName.",`${i}.tableName`));return}if(e.kind==="sql"){l(e.connectionId)||t.push(a("missing_connection_id","SQL source needs a connectionId.",`${i}.connectionId`));return}t.push(a("invalid_source_kind","Source kind is not supported.",i))}function f(e,i,t,n={}){if(!e||!u(e)){n.required&&t.push(a("missing_field_ref","Field reference needs a name.",i));return}l(e.name)||t.push(a("missing_field_ref","Field reference needs a name.",`${i}.name`)),e.source!==void 0&&k(e.source,`${i}.source`,t),_(e.aggregate,`${i}.aggregate`,t)}function pe(e,i,t){if(!u(e)){t.push(a("invalid_input_binding","Input bindings must be structured objects.",i));return}l(e.inputId)||t.push(a("invalid_input_binding","Input bindings need a non-empty inputId.",`${i}.inputId`)),e.kind!==void 0&&e.kind!=="filter"&&e.kind!=="control"&&t.push(a("invalid_input_binding","Input binding kind must be filter or control.",`${i}.kind`)),e.field!==void 0&&f(e.field,`${i}.field`,t),e.relationshipHint!==void 0&&R(e.relationshipHint,`${i}.relationshipHint`,t)}function R(e,i,t){if(!u(e)){t.push(a("invalid_relationship_hint","Relationship hints must be structured objects.",i));return}e.relationshipIds!==void 0&&(!Array.isArray(e.relationshipIds)||e.relationshipIds.some(n=>!l(n)))&&t.push(a("invalid_relationship_hint","Relationship hint relationshipIds must be non-empty strings.",`${i}.relationshipIds`))}function fe(e,i){if(l(e.inputId)||i.push(a("missing_input_options_input_id","Input options intent needs the inputId it populates.","inputId")),(!e.labelField||!l(e.labelField.name))&&i.push(a("missing_input_options_label_field","Input options intent needs a labelField.","labelField")),f(e.labelField,"labelField",i,{required:!0}),(!e.valueField||!l(e.valueField.name))&&i.push(a("missing_input_options_value_field","Input options intent needs a valueField.","valueField")),f(e.valueField,"valueField",i,{required:!0}),e.searchField!==void 0&&f(e.searchField,"searchField",i,{required:!0}),e.disambiguationFields!==void 0&&(Array.isArray(e.disambiguationFields)?e.disambiguationFields.forEach((t,n)=>{f(t,`disambiguationFields.${n}`,i,{required:!0})}):i.push(a("invalid_input_options_disambiguation_fields","Input options disambiguationFields must be an array of field refs.","disambiguationFields"))),e.dependencies!==void 0){const t=e.dependencies;if(!u(t))i.push(a("invalid_input_options_dependencies","Input options dependencies must be a structured object.","dependencies"));else{const n=t.mode;n!==void 0&&n!=="auto"&&n!=="independent"&&n!=="explicit"&&i.push(a("invalid_input_options_dependencies","Input options dependencies mode must be auto, independent, or explicit.","dependencies.mode")),j(t.includeInputIds,"dependencies.includeInputIds",i,"Input options includeInputIds must be non-empty strings."),j(t.excludeInputIds,"dependencies.excludeInputIds",i,"Input options excludeInputIds must be non-empty strings."),_e(e,i)}}if(e.population!==void 0){const t=e.population;if(!u(t))i.push(a("invalid_input_options_population","Input options population must be a structured object.","population"));else{const n=t.kind;n!=="option_source"&&n!=="related_population"&&i.push(a("invalid_input_options_population","Input options population kind must be option_source or related_population.","population.kind")),n==="option_source"&&t.baseSource!==void 0&&i.push(a("invalid_input_options_population","Input options population baseSource is only valid for related_population.","population.baseSource")),n==="option_source"&&t.relationshipHint!==void 0&&i.push(a("invalid_input_options_population","Input options population relationshipHint is only valid for related_population.","population.relationshipHint")),n==="related_population"&&(k(t.baseSource,"population.baseSource",i),t.relationshipHint!==void 0&&R(t.relationshipHint,"population.relationshipHint",i))}}}function me(e,i){if(!(!("inputs"in e)||e.inputs===void 0)){if(!Array.isArray(e.inputs)){i.push(a("invalid_input_binding","Analytics intent inputs must be an array of input bindings.","inputs"));return}e.inputs.forEach((t,n)=>pe(t,`inputs.${n}`,i))}}function _e(e,i){var n,o;const t=new Set(Array.isArray(e.inputs)?e.inputs.map(s=>u(s)?s.inputId:void 0).filter(s=>typeof s=="string"):[]);for(const s of((n=e.dependencies)==null?void 0:n.includeInputIds)||[])t.has(s)||i.push(a("invalid_input_options_dependencies",`Input options dependency "${s}" is not declared in inputs.`,"dependencies.includeInputIds"));for(const s of((o=e.dependencies)==null?void 0:o.excludeInputIds)||[])s!==e.inputId&&!t.has(s)&&i.push(a("invalid_input_options_dependencies",`Input options dependency exclusion "${s}" is not the populated inputId and is not declared in inputs.`,"dependencies.excludeInputIds"))}function j(e,i,t,n){e!==void 0&&(!Array.isArray(e)||e.some(o=>!l(o)))&&t.push(a("invalid_input_options_dependencies",n,i))}function _(e,i,t){e!==void 0&&(typeof e!="string"||!ce.has(e))&&t.push(a("invalid_aggregate","Field aggregate must be SUM, COUNT, AVG, MIN, MAX, MEDIAN, or DISTINCT.",i))}const ve=new Set(["measure","dimension","date","id","unknown"]),ge=new Set(["row","aggregate"]),V=new Set(["string","number","boolean","date","datetime","unknown"]),be=new Set(["number","currency","percent","percentage","scientific","date","datetime","duration","string"]),ye=new Set(["millisecond","second","minute","hour","day"]),he=new Set(["compact","digital","long"]);function D(e,i,t){if(e===void 0)return;if(!u(e)){t.push(a("invalid_value_format","Value format must be a structured object.",i));return}const n=e;(typeof n.type!="string"||!be.has(n.type))&&t.push(a("invalid_value_format_type","Value format type must be number, currency, percent, scientific, date, datetime, duration, or string.",`${i}.type`)),h(e.minimumFractionDigits,`${i}.minimumFractionDigits`,t),h(e.maximumFractionDigits,`${i}.maximumFractionDigits`,t),h(e.scale,`${i}.scale`,t),h(e.maxUnits,`${i}.maxUnits`,t),e.useGrouping!==void 0&&typeof e.useGrouping!="boolean"&&t.push(a("invalid_value_format_use_grouping","Value format useGrouping must be boolean.",`${i}.useGrouping`)),e.negativeStyle!==void 0&&e.negativeStyle!=="minus"&&e.negativeStyle!=="parentheses"&&t.push(a("invalid_value_format_negative_style","Value format negativeStyle must be minus or parentheses.",`${i}.negativeStyle`)),e.percentValueMode!==void 0&&e.percentValueMode!=="fraction"&&e.percentValueMode!=="whole"&&t.push(a("invalid_value_format_percent_mode","Value format percentValueMode must be fraction or whole.",`${i}.percentValueMode`));for(const o of["inputUnit","largestUnit","smallestUnit"]){const s=e[o];s!==void 0&&(typeof s!="string"||!ye.has(s))&&t.push(a("invalid_value_format_duration_unit","Duration format units must be millisecond, second, minute, hour, or day.",`${i}.${o}`))}e.outputStyle!==void 0&&(typeof e.outputStyle!="string"||!he.has(e.outputStyle))&&t.push(a("invalid_value_format_duration_style","Duration format outputStyle must be compact, digital, or long.",`${i}.outputStyle`))}function h(e,i,t){e!==void 0&&(typeof e!="number"||!Number.isFinite(e))&&t.push(a("invalid_value_format_number","Value format numeric options must be finite numbers.",i))}const xe=new Set(["additive","non_additive","ratio_of_sums","weighted","pre_aggregated","snapshot"]),we=new Set(["default","symmetric_aggregate","aggregate_then_join","weighted"]);function $e(e,i,t){if(!e||!u(e)){t.push(a("invalid_derived_field_input","Derived field inputs must be structured input references.",i));return}if(e.kind==="field"){f(e.field,`${i}.field`,t,{required:!0}),_(e.aggregate,`${i}.aggregate`,t);return}t.push(a("invalid_derived_field_input","Derived field input kind must be field.",`${i}.kind`))}function B(e,i,t){if(!u(e)){t.push(a("invalid_result_column_ref","Result calculation references must use columnKey or field.",i));return}const n=l(e.columnKey),o=u(e.field);if(n===o){t.push(a("invalid_result_column_ref","Result calculation references must identify exactly one of columnKey or field.",i));return}o&&f(e.field,`${i}.field`,t,{required:!0})}function Ie(e,i,t){if(!u(e)){t.push(a("invalid_result_calculation_output","Result calculation output must be a structured object.",i));return}l(e.key)||t.push(a("invalid_result_calculation_output","Result calculation output needs a stable key.",`${i}.key`)),e.dataType!==void 0&&(typeof e.dataType!="string"||!V.has(e.dataType))&&t.push(a("invalid_result_calculation_output","Result calculation output dataType must be string, number, boolean, date, datetime, or unknown.",`${i}.dataType`)),D(e.format,`${i}.format`,t)}function Se(e,i,t){e!==void 0&&e!=="hour"&&e!=="day"&&e!=="week"&&e!=="month"&&e!=="quarter"&&e!=="year"&&t.push(a("invalid_time_grain","Time grain must be hour, day, week, month, quarter, or year.",i))}function G(e,i,t,n){e!=="asc"&&e!=="desc"&&t.push(a(n,"Sort direction must be asc or desc.",i))}function z(e,i,t,n){e!==void 0&&e!=="warehouseDefault"&&e!=="first"&&e!=="last"&&t.push(a(n,"Null ordering must be warehouseDefault, first, or last.",i))}function Q(e,i,t,n){e!==void 0&&e!=="global"&&e!=="withinParent"&&t.push(a(n,"Sort scope must be global or withinParent.",i))}function Ae(e,i,t){e.enabled!==void 0&&typeof e.enabled!="boolean"&&t.push(a("invalid_matrix_subtotal","Matrix subtotal enabled must be a boolean.",`${i}.enabled`)),e.position!==void 0&&e.position!=="before"&&e.position!=="after"&&t.push(a("invalid_matrix_subtotal","Matrix subtotal position must be before or after.",`${i}.position`)),e.label!==void 0&&typeof e.label!="string"&&t.push(a("invalid_matrix_subtotal","Matrix subtotal label must be a string.",`${i}.label`))}function Me(e,i,t){if(G(e.direction,`${i}.direction`,t,"invalid_matrix_sort_direction"),z(e.nulls,`${i}.nulls`,t,"invalid_matrix_sort_nulls"),Q(e.scope,`${i}.scope`,t,"invalid_matrix_sort_scope"),!u(e.by)){t.push(a("invalid_matrix_sort_by","Matrix sort by must be a structured object.",`${i}.by`));return}if(e.by.kind!=="label"){if(e.by.kind==="field"){f(e.by.field,`${i}.by.field`,t,{required:!0}),_(e.by.aggregate,`${i}.by.aggregate`,t);return}t.push(a("invalid_matrix_sort_by","Matrix axis sort by must be label or field.",`${i}.by.kind`))}}function q(e,i,t,n){if(!Array.isArray(e))return n.required?t.push(a("missing_matrix_rows","Matrix intent needs at least one row axis level.",i)):e!==void 0&&t.push(a("invalid_matrix_columns","Matrix columns must be an array of axis levels.",i)),[];n.required&&e.length===0&&t.push(a("missing_matrix_rows","Matrix intent needs at least one row axis level.",i));const o=[];return e.forEach((s,r)=>{const c=`${i}.${r}`;if(!u(s)){t.push(a("invalid_matrix_axis_level","Matrix axis levels must be structured objects.",c));return}const d=s;o.push(d),d.id!==void 0&&!l(d.id)&&t.push(a("invalid_matrix_axis_level_id","Matrix axis level id must be a non-empty string.",`${c}.id`)),f(d.field,`${c}.field`,t,{required:!0}),Se(d.grain,`${c}.grain`,t),d.label!==void 0&&typeof d.label!="string"&&t.push(a("invalid_matrix_axis_label","Matrix axis level label must be a string.",`${c}.label`)),d.subtotal!==void 0&&typeof d.subtotal!="boolean"&&(u(d.subtotal)?Ae(d.subtotal,`${c}.subtotal`,t):t.push(a("invalid_matrix_subtotal","Matrix subtotal must be a boolean or structured options object.",`${c}.subtotal`))),d.sortBy!==void 0&&(u(d.sortBy)?Me(d.sortBy,`${c}.sortBy`,t):t.push(a("invalid_matrix_sort_by","Matrix axis sortBy must be a structured object.",`${c}.sortBy`)))}),o}function ke(e,i,t){if(!u(e)){t.push(a("invalid_matrix_total_behavior","Matrix total behavior must be a structured object.",i));return}if(e.kind!=="defaultAggregate"&&e.kind!=="blank"&&e.kind!=="labelOnly"&&e.kind!=="customAggregate"&&e.kind!=="percentOfParent"&&e.kind!=="percentOfGrandTotal"&&e.kind!=="customExpression"){t.push(a("invalid_matrix_total_behavior","Matrix total behavior kind is not supported.",`${i}.kind`));return}e.kind==="customAggregate"&&(Object.prototype.hasOwnProperty.call(e,"aggregate")?_(e.aggregate,`${i}.aggregate`,t):t.push(a("invalid_matrix_total_behavior","Custom matrix total behavior needs an aggregate.",`${i}.aggregate`))),e.kind==="customExpression"&&!l(e.expressionId)&&t.push(a("invalid_matrix_total_behavior","Custom matrix total behavior needs an expressionId.",`${i}.expressionId`)),e.kind==="labelOnly"&&e.label!==void 0&&typeof e.label!="string"&&t.push(a("invalid_matrix_total_behavior","Matrix label-only total behavior label must be a string.",`${i}.label`))}function Re(e,i,t){if(!Array.isArray(e)||e.length===0)return t.push(a("missing_matrix_values","Matrix intent needs at least one value field.",i)),[];const n=[];return e.forEach((o,s)=>{const r=`${i}.${s}`;if(!u(o)){t.push(a("invalid_matrix_value","Matrix values must be structured objects.",r));return}const c=o;n.push(c),c.id!==void 0&&!l(c.id)&&t.push(a("invalid_matrix_value_id","Matrix value id must be a non-empty string.",`${r}.id`)),f(c.field,`${r}.field`,t,{required:!0}),_(c.aggregate,`${r}.aggregate`,t),D(c.format,`${r}.format`,t),c.label!==void 0&&typeof c.label!="string"&&t.push(a("invalid_matrix_value_label","Matrix value label must be a string.",`${r}.label`)),c.totalBehavior!==void 0&&ke(c.totalBehavior,`${r}.totalBehavior`,t)}),n}function De(e,i,t){if(!u(e)){t.push(a("invalid_matrix_totals","Matrix totals must be a structured object.",i));return}for(const n of["rows","columns"]){const o=e[n];o!==void 0&&o!==!0&&o!==!1&&o!=="perLevel"&&t.push(a("invalid_matrix_totals","Matrix total axis setting must be a boolean or perLevel.",`${i}.${n}`))}if(e.grandTotal!==void 0&&typeof e.grandTotal!="boolean")if(!u(e.grandTotal))t.push(a("invalid_matrix_totals","Matrix grandTotal must be a boolean or structured object.",`${i}.grandTotal`));else for(const n of["rows","columns"]){const o=e.grandTotal[n];o!==void 0&&typeof o!="boolean"&&t.push(a("invalid_matrix_totals","Matrix grandTotal rows/columns must be booleans.",`${i}.grandTotal.${n}`))}e.rowPosition!==void 0&&e.rowPosition!=="top"&&e.rowPosition!=="bottom"&&t.push(a("invalid_matrix_totals","Matrix row total position must be top or bottom.",`${i}.rowPosition`)),e.columnPosition!==void 0&&e.columnPosition!=="left"&&e.columnPosition!=="right"&&t.push(a("invalid_matrix_totals","Matrix column total position must be left or right.",`${i}.columnPosition`))}function S(e,i,t,n){if(!Array.isArray(e)){n.push(a("invalid_matrix_path","Matrix member path must be an array of path segments.",i));return}e.forEach((o,s)=>{const r=`${i}.${s}`;if(!u(o)){n.push(a("invalid_matrix_path","Matrix path segment must be a structured object.",r));return}const c=o;if(!l(c.levelId)){n.push(a("stable_id_required","Matrix path segments must reference an explicit public axis level id.",`${r}.levelId`));return}Object.prototype.hasOwnProperty.call(o,"value")||n.push(a("invalid_matrix_path","Matrix path segments must include a value property; use explicit null for null members.",`${r}.value`)),t.has(c.levelId)||n.push(a("stable_id_required","Matrix path segment levelId must match an explicit public axis level id.",`${r}.levelId`))})}function H(e,i,t,n){if(!u(e)){n.push(a("invalid_matrix_expansion","Matrix expansion axis options must be structured objects.",i));return}e.defaultDepth!==void 0&&(typeof e.defaultDepth!="number"||!Number.isInteger(e.defaultDepth)||e.defaultDepth<0)&&n.push(a("invalid_matrix_expansion","Matrix expansion defaultDepth must be a non-negative integer.",`${i}.defaultDepth`)),e.lazy!==void 0&&typeof e.lazy!="boolean"&&n.push(a("invalid_matrix_expansion","Matrix expansion lazy must be a boolean.",`${i}.lazy`)),e.expandedPaths!==void 0&&(Array.isArray(e.expandedPaths)?e.expandedPaths.forEach((o,s)=>{S(o,`${i}.expandedPaths.${s}`,t,n)}):n.push(a("invalid_matrix_expansion","Matrix expandedPaths must be an array of member paths.",`${i}.expandedPaths`)))}function Fe(e,i,t,n){if(e!==void 0){if(!u(e)){n.push(a("invalid_matrix_expansion","Matrix expansion must be a structured object.","expansion"));return}e.rows!==void 0&&H(e.rows,"expansion.rows",i,n),e.columns!==void 0&&H(e.columns,"expansion.columns",t,n)}}function Pe(e,i,t,n,o){if(e!==void 0){if(!Array.isArray(e)){o.push(a("invalid_matrix_sort","Matrix sort must be an array of sort rules.","sort"));return}e.forEach((s,r)=>{const c=`sort.${r}`;if(!u(s)){o.push(a("invalid_matrix_sort","Matrix sort rule must be a structured object.",c));return}const d=s;d.axis!=="row"&&d.axis!=="column"&&o.push(a("invalid_matrix_sort","Matrix sort axis must be row or column.",`${c}.axis`));const p=d.axis==="column"?t:i;if(d.targetId!==void 0&&!p.has(d.targetId)&&o.push(a("stable_id_required","Matrix sort targetId must reference an explicit public axis level id.",`${c}.targetId`)),G(d.direction,`${c}.direction`,o,"invalid_matrix_sort_direction"),z(d.nulls,`${c}.nulls`,o,"invalid_matrix_sort_nulls"),Q(d.scope,`${c}.scope`,o,"invalid_matrix_sort_scope"),!u(d.by)){o.push(a("invalid_matrix_sort_by","Matrix sort by must be a structured object.",`${c}.by`));return}if(d.by.kind!=="label"){if(d.by.kind==="field"){f(d.by.field,`${c}.by.field`,o,{required:!0}),_(d.by.aggregate,`${c}.by.aggregate`,o);return}if(d.by.kind==="value"){(!l(d.by.valueId)||!n.has(d.by.valueId))&&o.push(a("stable_id_required","Matrix value sort must reference an explicit public value id.",`${c}.by.valueId`)),d.by.rowPath!==void 0&&S(d.by.rowPath,`${c}.by.rowPath`,i,o),d.by.columnPath!==void 0&&S(d.by.columnPath,`${c}.by.columnPath`,t,o);return}o.push(a("invalid_matrix_sort_by","Matrix sort by must be label, field, or value.",`${c}.by.kind`))}})}}function Te(e,i){if(e!==void 0){if(!u(e)){i.push(a("invalid_matrix_layout","Matrix layout must be a structured object.","layout"));return}e.hierarchy!==void 0&&e.hierarchy!=="compact"&&e.hierarchy!=="tabular"&&e.hierarchy!=="outline"&&i.push(a("invalid_matrix_layout","Matrix hierarchy layout must be compact, tabular, or outline.","layout.hierarchy")),e.valuesPlacement!==void 0&&e.valuesPlacement!=="columns"&&e.valuesPlacement!=="rows"&&i.push(a("invalid_matrix_layout","Matrix valuesPlacement must be columns or rows.","layout.valuesPlacement")),e.stickyRowHeaders!==void 0&&typeof e.stickyRowHeaders!="boolean"&&i.push(a("invalid_matrix_layout","Matrix stickyRowHeaders must be a boolean.","layout.stickyRowHeaders")),e.stickyColumnHeaders!==void 0&&typeof e.stickyColumnHeaders!="boolean"&&i.push(a("invalid_matrix_layout","Matrix stickyColumnHeaders must be a boolean.","layout.stickyColumnHeaders"))}}function C(e,i,t){if(!u(e)){t.push(a("invalid_matrix_display_limits","Matrix display limit must be a structured object.",i));return}(typeof e.limit!="number"||!Number.isInteger(e.limit)||e.limit<1)&&t.push(a("invalid_matrix_display_limits","Matrix display limit must be a positive integer.",`${i}.limit`)),e.by!==void 0&&e.by!=="label"&&e.by!=="value"&&t.push(a("invalid_matrix_display_limits","Matrix display limit by must be label or value.",`${i}.by`)),e.direction!==void 0&&e.direction!=="top"&&e.direction!=="bottom"&&t.push(a("invalid_matrix_display_limits","Matrix display limit direction must be top or bottom.",`${i}.direction`)),e.others!==void 0&&typeof e.others!="boolean"&&(u(e.others)?e.others.label!==void 0&&typeof e.others.label!="string"&&t.push(a("invalid_matrix_display_limits","Matrix display limit others label must be a string.",`${i}.others.label`)):t.push(a("invalid_matrix_display_limits","Matrix display limit others must be a boolean or structured object.",`${i}.others`)))}function Ee(e,i){if(e!==void 0){if(!u(e)){i.push(a("invalid_matrix_display_limits","Matrix displayLimits must be a structured object.","displayLimits"));return}e.rows!==void 0&&C(e.rows,"displayLimits.rows",i),e.columns!==void 0&&C(e.columns,"displayLimits.columns",i)}}function Ne(e,i){var d;((d=e.source)==null?void 0:d.kind)==="sql"&&i.push(a("unsupported_matrix_sql_source","Matrix analytics intent does not support raw SQL sources.","source.kind"));const t=q(e.rows,"rows",i,{required:!0}),n=q(e.columns,"columns",i,{required:!1}),o=Re(e.values,"values",i);x(e.filters,"filters",i),e.totals!==void 0&&De(e.totals,"totals",i),w(t.map(p=>p.id),"rows","row axis level",i),w(n.map(p=>p.id),"columns","column axis level",i),w(o.map(p=>p.id),"values","value",i);const s=new Set(t.map(p=>p.id).filter(p=>l(p))),r=new Set(n.map(p=>p.id).filter(p=>l(p))),c=new Set(o.map(p=>p.id).filter(p=>l(p)));Pe(e.sort,s,r,c,i),Fe(e.expansion,s,r,i),Te(e.layout,i),Ee(e.displayLimits,i)}function Oe(e,i){if(e.analysis===void 0)return;if(!u(e.analysis)){i.push(a("invalid_measure_analysis","Metric analysis must be a structured object.","analysis"));return}if(e.analysis.kind!=="period_change"){i.push(a("invalid_measure_analysis","Metric analysis kind is not supported.","analysis.kind"));return}e.dateField||i.push(a("missing_analysis_date_field","Period-change analysis needs a dateField.","dateField")),e.timeGrain||i.push(a("missing_analysis_time_grain","Period-change analysis needs a timeGrain.","timeGrain")),e.analysis.orderBy!==void 0&&e.analysis.orderBy!=="absolute_change"&&e.analysis.orderBy!=="positive_change"&&e.analysis.orderBy!=="negative_change"&&e.analysis.orderBy!=="period"&&i.push(a("invalid_measure_analysis","Period-change analysis orderBy must be absolute_change, positive_change, negative_change, or period.","analysis.orderBy"));const{timeWindow:t}=e.analysis;t!==void 0&&A(t,"analysis.timeWindow",i)}function A(e,i,t){if(!u(e)){t.push(a("invalid_time_window","Time window must be a structured object.",i));return}if(e.kind!==void 0&&e.kind!=="relative"&&e.kind!=="absolute"&&t.push(a("invalid_time_window","Time window kind must be relative or absolute.",`${i}.kind`)),e.kind==="absolute"){if(l(e.start)||t.push(a("invalid_time_window","Absolute time window start must be a non-empty ISO date or timestamp string.",`${i}.start`)),l(e.end)||t.push(a("invalid_time_window","Absolute time window end must be a non-empty ISO date or timestamp string.",`${i}.end`)),l(e.start)&&l(e.end)){const n=$(e.start),o=$(e.end);n||t.push(a("invalid_time_window","Absolute time window start must be a valid ISO date or timestamp.",`${i}.start`)),o||t.push(a("invalid_time_window","Absolute time window end must be a valid ISO date or timestamp.",`${i}.end`)),n&&o&&n.getTime()>o.getTime()&&t.push(a("invalid_time_window","Absolute time window start must be before or equal to end.",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"&&t.push(a("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)&&t.push(a("invalid_time_window","Time window value must be a positive number.",`${i}.value`)),e.anchor!==void 0&&e.anchor!=="now"&&e.anchor!=="latest_available"&&t.push(a("invalid_time_window","Time window anchor must be now or latest_available.",`${i}.anchor`)),e.completeness!==void 0&&e.completeness!=="include_partial"&&e.completeness!=="complete_periods"&&t.push(a("invalid_time_window","Time window completeness must be include_partial or complete_periods.",`${i}.completeness`))}function x(e,i,t){if(e!==void 0){if(!Array.isArray(e)){t.push(a("invalid_analytics_filters","Analytics filters must be an array.",i));return}e.forEach((n,o)=>{var d;const s=`${i}.${o}`;if(!u(n)){t.push(a("invalid_analytics_filter","Analytics filter must be a structured object.",s));return}const r=n;f(r.field,`${s}.field`,t,{required:!0}),r.scope!==void 0&&r.scope!=="row"&&r.scope!=="aggregate"&&t.push(a("invalid_analytics_filter_scope","Analytics filter scope must be row or aggregate.",`${s}.scope`)),r.scope==="aggregate"&&((d=r.field)==null?void 0:d.role)!==void 0&&r.field.role!=="measure"&&t.push(a("invalid_analytics_filter_scope","Aggregate-scope analytics filters must target a measure field.",`${s}.scope`));const c=r.operator==="is_null"||r.operator==="is_not_null";if(r.operator!==void 0&&r.operator!=="="&&r.operator!=="!="&&r.operator!=="in"&&r.operator!=="not_in"&&r.operator!=="contains"&&r.operator!=="not_contains"&&r.operator!=="between"&&r.operator!=="not_between"&&r.operator!==">"&&r.operator!==">="&&r.operator!=="<"&&r.operator!=="<="&&r.operator!=="is_null"&&r.operator!=="is_not_null"&&t.push(a("invalid_analytics_filter_operator","Analytics filter operator is not supported.",`${s}.operator`)),r.values===void 0&&!c&&t.push(a("missing_analytics_filter_value","Analytics filter needs values unless it is a null check.",s)),c&&r.values!==void 0){t.push(a("invalid_analytics_filter_values","Null-check analytics filters must not include values.",`${s}.values`));return}if(r.values!==void 0&&!Array.isArray(r.values)){t.push(a("invalid_analytics_filter_values","Analytics filter values must be an array when provided.",`${s}.values`));return}if(r.values!==void 0){const p=r.values.length;if(r.operator==="between"||r.operator==="not_between"){p!==2&&t.push(a("invalid_analytics_filter_values","Between analytics filters must include exactly two values.",`${s}.values`));return}(r.operator==="contains"||r.operator==="not_contains"||r.operator==="="||r.operator==="!="||r.operator===">"||r.operator===">="||r.operator==="<"||r.operator==="<="||r.operator===void 0)&&p!==1&&t.push(a("invalid_analytics_filter_values","Scalar analytics filters must include exactly one value. Use in/not_in for multiple values.",`${s}.values`))}})}}function Y(e){const i=[];if(!u(e))return i.push(a("invalid_derived_field","Derived field definition must be a structured object.")),{ok:!1,errors:i,warnings:[]};if(e.kind!=="derived_field"&&i.push(a("invalid_derived_field_kind","Derived field kind must be derived_field.","kind")),l(e.name)||i.push(a("invalid_derived_field_name","Derived field needs a name.","name")),l(e.label)||i.push(a("invalid_derived_field_label","Derived field needs a label.","label")),ve.has(e.resultRole)||i.push(a("invalid_derived_field_role","Derived field resultRole must be measure, dimension, date, id, or unknown.","resultRole")),V.has(e.dataType)||i.push(a("invalid_derived_field_data_type","Derived field dataType must be string, number, boolean, date, datetime, or unknown.","dataType")),ge.has(e.computeStage)||i.push(a("invalid_derived_field_compute_stage","Derived field computeStage must be row or aggregate.","computeStage")),e.computeStage==="aggregate"&&e.resultRole!=="measure"&&i.push(a("invalid_derived_field_compute_stage","Aggregate-stage derived fields must have resultRole measure.","computeStage")),e.resultRole!=="measure"&&e.defaultAggregate!==void 0&&i.push(a("invalid_derived_field_aggregate","Only measure derived fields may declare defaultAggregate.","defaultAggregate")),e.computeStage==="row"&&e.resultRole==="measure"&&e.defaultAggregate===void 0&&i.push(a("missing_derived_field_default_aggregate","Row-stage measure derived fields must declare defaultAggregate so row results have explicit rollup semantics.","defaultAggregate")),_(e.defaultAggregate,"defaultAggregate",i),e.aggregationBehavior!==void 0&&!xe.has(e.aggregationBehavior)&&i.push(a("invalid_derived_field_aggregation_behavior","Derived field aggregationBehavior is not supported.","aggregationBehavior")),e.aggregationStrategy!==void 0&&!we.has(e.aggregationStrategy)&&i.push(a("invalid_derived_field_aggregation_strategy","Derived field aggregationStrategy is not supported.","aggregationStrategy")),l(e.expression)||i.push(a("invalid_derived_field_expression","Derived field needs a named-token expression.","expression")),e.expressionLanguage!==void 0&&e.expressionLanguage!=="semaphor_sql_template"&&i.push(a("invalid_derived_field_expression_language","Derived field expressionLanguage must be semaphor_sql_template.","expressionLanguage")),!u(e.inputs)||Object.keys(e.inputs).length===0?i.push(a("invalid_derived_field_inputs","Derived field needs at least one typed input.","inputs")):Object.entries(e.inputs).forEach(([t,n])=>{if(!l(t)){i.push(a("invalid_derived_field_input_name","Derived field input names must be non-empty strings.","inputs"));return}$e(n,`inputs.${t}`,i)}),l(e.expression)&&u(e.inputs)){const t=le(e.expression),n=new Set(t),o=Object.keys(e.inputs).filter(s=>l(s));t.forEach(s=>{Object.prototype.hasOwnProperty.call(e.inputs,s)||i.push(a("invalid_derived_field_expression_token",`Derived field expression token "{${s}}" needs a matching inputs.${s} entry.`,"expression"))}),o.forEach(s=>{n.has(s)||i.push(a("unused_derived_field_input",`Derived field input "${s}" is not referenced by expression.`,`inputs.${s}`))})}return D(e.format,"format",i),e.tags!==void 0&&(!Array.isArray(e.tags)||e.tags.some(t=>!l(t)))&&i.push(a("invalid_derived_field_tags","Derived field tags must be non-empty strings.","tags")),{ok:i.length===0,errors:i,warnings:[]}}function je(e){const i=[];if(!u(e))return i.push(a("invalid_result_calculation","Result calculation must be a structured object.")),{ok:!1,errors:i,warnings:[]};if(l(e.id)||i.push(a("invalid_result_calculation_id","Result calculation needs an id.","id")),l(e.label)||i.push(a("invalid_result_calculation_label","Result calculation needs a label.","label")),e.kind!=="percent_of_total"&&e.kind!=="rank"&&e.kind!=="running_total"&&e.kind!=="previous_row_delta"&&i.push(a("invalid_result_calculation_kind","Result calculation kind must be percent_of_total, rank, running_total, or previous_row_delta.","kind")),B(e.input,"input",i),Ie(e.output,"output",i),e.kind==="percent_of_total"){const t=e.denominator;t!==void 0&&(u(t)?t.scope==="population"?(f(t.metric,"denominator.metric",i,{required:!0}),x(t.filters,"denominator.filters",i)):t.scope!=="returned_result"&&i.push(a("invalid_result_calculation_denominator","Percent-of-total denominator scope must be returned_result or population.","denominator.scope")):i.push(a("invalid_result_calculation_denominator","Percent-of-total denominator must be a structured object.","denominator")))}return e.kind==="rank"&&e.order!==void 0&&e.order!=="asc"&&e.order!=="desc"&&i.push(a("invalid_result_calculation_order","Rank result calculation order must be asc or desc.","order")),(e.kind==="running_total"||e.kind==="previous_row_delta")&&e.orderBy!==void 0&&B(e.orderBy,"orderBy",i),{ok:i.length===0,errors:i,warnings:[]}}function F(e){var n;const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_analytics_intent","Analytics intent must be a structured object.")],warnings:t,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(a("invalid_version","Analytics intent version must be 1.","version")),k(e.source,"source",i),Be(e,i),me(e,i),"relationshipHint"in e&&e.relationshipHint!==void 0&&R(e.relationshipHint,"relationshipHint",i),e.kind==="metric"){const o=Array.isArray(e.measures)?e.measures.filter(s=>u(s)&&l(s.name)):[];if(!Array.isArray(e.measures)||e.measures.length===0?i.push(a("missing_measure","Metric intent needs at least one measure.","measures")):e.measures.some(s=>!u(s)||!l(s.name))&&i.push(a("invalid_measure_list","Metric intent measures must be an array of field references with names.","measures")),o.forEach((s,r)=>{f(s,`measures.${r}`,i,{required:!0})}),o.length>0&&!J(o)){const s=o.find((r,c)=>o.some((d,p)=>p!==c&&U(d,r)));s&&i.push(a("duplicate_measure",W(s),"measures"))}if(u(e.primaryMeasure)&&l(e.primaryMeasure.name)&&M(e.primaryMeasure,o).length>1&&i.push(a("ambiguous_primary_measure","Metric intent primaryMeasure must identify exactly one selected measure.","primaryMeasure")),e.primaryMeasure!==void 0&&(f(e.primaryMeasure,"primaryMeasure",i,{required:!0}),u(e.primaryMeasure)&&l(e.primaryMeasure.name)&&o.length>0&&!ie(e.primaryMeasure,o)&&i.push(a("invalid_primary_measure","Metric intent primaryMeasure must match one measure field reference.","primaryMeasure"))),e.dimensions!==void 0&&!Array.isArray(e.dimensions)?i.push(a("invalid_measure_dimensions","Metric intent dimensions must be an array of field references.","dimensions")):Array.isArray(e.dimensions)&&e.dimensions.some(s=>!u(s)||!l(s.name))&&i.push(a("invalid_measure_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&&(A(e.timeWindow,"timeWindow",i),e.dateField||i.push(a("missing_time_window_date_field","Metric timeWindow needs a dateField.","dateField"))),x(e.filters,"filters",i),Array.isArray(e.dimensions)&&e.dimensions.forEach((s,r)=>{f(s,`dimensions.${r}`,i)}),e.orderBy!==void 0){if(!u(e.orderBy))i.push(a("invalid_measure_order_by","Metric intent orderBy must be a structured object.","orderBy"));else if(f(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(a("invalid_measure_order_direction","Metric intent orderBy direction must be asc or desc.","orderBy.direction")),u(e.orderBy.field)&&l(e.orderBy.field.name)){const s=[...o,...e.timeGrain&&e.dateField&&u(e.dateField)?[e.dateField]:[],...Array.isArray(e.dimensions)?e.dimensions.filter(r=>u(r)&&l(r.name)):[]];s.length>0&&!te(e.orderBy.field,s)&&i.push(a("invalid_measure_order_by","Metric intent orderBy.field must match one selected measure, grouped dateField, or dimension.","orderBy.field"))}}Oe(e,i)}else e.kind==="records"?(!Array.isArray(e.fields)||e.fields.length===0?i.push(a("missing_record_fields","Records intent needs at least one field.","fields")):e.fields.some(o=>!u(o)||!l(o.name))&&i.push(a("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),O(e.pagination,"pagination",i),e.timeWindow!==void 0&&(A(e.timeWindow,"timeWindow",i),e.dateField||i.push(a("missing_time_window_date_field","Records timeWindow needs a dateField.","dateField"))),x(e.filters,"filters",i),Array.isArray(e.filters)&&e.filters.forEach((o,s)=>{u(o)&&o.scope==="aggregate"&&i.push(a("unsupported_record_filter_scope","Records intents support row-scope filters only. Use a metric intent for aggregate-scope filters.",`filters.${s}.scope`))}),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(a("invalid_record_order_direction","Records intent orderBy direction must be asc or desc.","orderBy.direction"))):i.push(a("invalid_record_order_by","Records intent orderBy must be a structured object.","orderBy")))):e.kind==="inputOptions"?fe(e,i):e.kind==="matrix"?Ne(e,i):e.kind==="sql"?(((n=e.source)==null?void 0:n.kind)!=="sql"&&i.push(a("invalid_sql_source","SQL analytics intent must use a SQL execution source.","source")),l(e.sql)||i.push(a("missing_sql","SQL analytics intent needs SQL text.","sql")),ee(e.defaultParameters,"defaultParameters",i),Array.isArray(e.fields)&&e.fields.forEach((o,s)=>{f(o,`fields.${s}`,i)}),O(e.pagination,"pagination",i)):i.push(a("invalid_analytics_kind","Analytics kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:t,repairHints:He(i)}}function Be(e,i){if(!(!("derivedFields"in e)||e.derivedFields===void 0)){if(!Array.isArray(e.derivedFields)){i.push(a("invalid_derived_fields","Analytics intent derivedFields must be an array of derived field definitions.","derivedFields"));return}e.derivedFields.forEach((t,n)=>{Y(t).errors.forEach(s=>{i.push({...s,path:s.path?`derivedFields.${n}.${s.path}`:`derivedFields.${n}`})})})}}function K(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_operation_intent","Operation intent must be a structured object.")],warnings:t,repairHints:[{code:"invalid_operation_intent",recommendedNextStep:"Send one typed operation intent with version, kind, and required operation fields."}]};if(e.version!==1&&i.push(a("invalid_version","Operation intent version must be 1.","version")),e.kind==="answer_obligations")!Array.isArray(e.obligations)||e.obligations.length===0?i.push(a("missing_obligations","Answer-obligations operation intent needs at least one obligation.","obligations")):e.obligations.forEach((n,o)=>{l(n.id)||i.push(a("missing_obligation_id","Each analytics obligation needs an id.",`obligations.${o}.id`)),l(n.prompt)||i.push(a("missing_obligation_prompt","Each analytics obligation needs a prompt.",`obligations.${o}.prompt`))});else if(e.kind==="dashboard_change"||e.kind==="data_app_change"){if(l(e.instruction)||i.push(a("missing_instruction","Change operation intent needs an instruction.","instruction")),e.analyticsIntent){const n=F(e.analyticsIntent);i.push(...n.errors),t.push(...n.warnings)}}else i.push(a("invalid_operation_kind","Operation intent kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:t,repairHints:X(i)}}function qe(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_recovery_plan","Analytics recovery plan must be a structured object.")],warnings:t,repairHints:[{code:"invalid_recovery_plan",recommendedNextStep:"Return a typed recovery plan with operationIntent and plannedToolCalls."}]};e.version!==1&&i.push(a("invalid_version","Recovery plan version must be 1.","version")),e.kind!=="analytics_recovery_plan"&&i.push(a("invalid_recovery_plan_kind","Recovery plan kind must be analytics_recovery_plan.","kind"));const n=K(e.operationIntent);return i.push(...n.errors),t.push(...n.warnings),Array.isArray(e.plannedToolCalls)||i.push(a("invalid_planned_tool_calls","Recovery plan plannedToolCalls must be an array.","plannedToolCalls")),{ok:i.length===0,errors:i,warnings:t,repairHints:X(i)}}function X(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 He(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_measure":return{code:i.code,fieldRole:"measure",recommendedNextStep:"Choose one exact measure 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_matrix_rows":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Choose at least one row axis level for the matrix table."};case"missing_matrix_values":return{code:i.code,fieldRole:"measure",recommendedNextStep:"Choose at least one value field for the matrix table."};case"unsupported_matrix_sql_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use a semantic or explorer-backed source for matrix tables; raw SQL matrix tables are not supported."};case"missing_input_options_input_id":return{code:i.code,fieldRole:"input",recommendedNextStep:"Provide the inputId that these option values populate."};case"missing_input_options_label_field":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide the human-readable field used as option labels."};case"missing_input_options_value_field":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide the stable field used as option values."};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 Ce(e,i,t,n){if(!e||typeof e!="object"){t.push(a("invalid_view","Dashboard view must be an object.",i));return}if(l(e.title)||t.push(a("missing_view_title","Dashboard view needs a title.",i)),!e.presentation||typeof e.presentation!="object"){t.push(a("missing_presentation","Dashboard view needs a presentation.",`${i}.presentation`));return}if(e.presentation.kind==="text"){l(e.text)||n.push(a("missing_text_content","Text views should include text content.",`${i}.text`));return}if(!e.analytics){t.push(a("missing_view_analytics","Non-text dashboard views need analytics intent.",`${i}.analytics`));return}e.presentation.kind==="matrixTable"&&e.analytics.kind!=="matrix"&&t.push(a("invalid_matrix_view_analytics","Matrix table views need matrix analytics intent.",`${i}.analytics.kind`));const o=F(e.analytics);for(const s of o.errors)t.push(a(s.code,s.message,`${i}.analytics${s.path?`.${s.path}`:""}`));for(const s of o.warnings)n.push(a(s.code,s.message,`${i}.analytics${s.path?`.${s.path}`:""}`))}function Le(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_dashboard_intent","Dashboard intent must be a structured object.")],warnings:t};e.version!==1&&i.push(a("invalid_version","Dashboard intent version must be 1.")),e.kind!=="dashboard"&&i.push(a("invalid_kind","Experience intent kind must be dashboard.")),l(e.title)||i.push(a("missing_title","Dashboard intent needs a title.","title"));const n=Array.isArray(e.inputs)?e.inputs:[],o=I(n.filter(u).map(d=>d.id).filter(d=>typeof d=="string"));o&&i.push(a("duplicate_input_id",`Duplicate input id: ${o}.`,"inputs"));for(const[d,p]of n.entries()){const m=`inputs.${d}`;if(!u(p)){i.push(a("invalid_input","Dashboard input must be an object.",m));continue}l(p.id)||i.push(a("missing_input_id","Input needs an id.",`${m}.id`)),l(p.label)||i.push(a("missing_input_label","Input needs a label.",`${m}.label`)),!p.field||!l(p.field.name)?i.push(a("missing_input_field","Input needs a field.",`${m}.field`)):f(p.field,`${m}.field`,i)}const s=Array.isArray(e.sections)?e.sections:[];s.length===0&&i.push(a("missing_sections","Dashboard intent needs at least one section.","sections"));const r=s.flatMap(d=>d&&typeof d=="object"&&Array.isArray(d.views)?d.views.filter(u).map(p=>p.id).filter(p=>!!p):[]),c=I(r);c&&i.push(a("duplicate_view_id",`Duplicate dashboard view id: ${c}.`,"sections"));for(const[d,p]of s.entries()){const m=`sections.${d}`;if(!p||typeof p!="object"){i.push(a("invalid_section","Dashboard section must be an object.",m));continue}if(l(p.title)||i.push(a("missing_section_title","Dashboard section needs a title.",m)),!Array.isArray(p.views)||p.views.length===0){i.push(a("missing_section_views","Dashboard section needs at least one view.",`${m}.views`));continue}for(const[b,y]of p.views.entries())Ce(y,`${m}.views.${b}`,i,t)}return{ok:i.length===0,errors:i,warnings:t}}exports.parseSemaphorIsoTimeWindowBoundary=$;exports.validateSemaphorAnalyticsIntent=F;exports.validateSemaphorAnalyticsRecoveryPlan=qe;exports.validateSemaphorDashboardIntent=Le;exports.validateSemaphorDerivedFieldDefinition=Y;exports.validateSemaphorOperationIntent=K;exports.validateSemaphorResultCalculation=je;
1
+ "use strict";const Z=require("./source-identity-uMaUe036.js");function a(e,i,t){return t?{code:e,message:i,path:t}:{code:e,message:i}}function J(e){for(let i=0;i<e.length;i+=1){const t=e[i];if(e.some((n,o)=>o!==i&&U(n,t)))return!1}return!0}function L(e,i){return Z.semaphorFieldRefsMatch(e,i)}function U(e,i){return L(e,i)&&g(e)===g(i)}function W(e){return`Metric intent has duplicate measure "${e.name}" with the same aggregate (${g(e)}). Use different aggregates to request both, or remove one entry.`}function E(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null}function ee(e,i,t){if(e!==void 0){if(!e||typeof e!="object"||Array.isArray(e)){t.push(a("invalid_sql_default_parameters","SQL defaultParameters must be an object keyed by parameter name.",i));return}Object.entries(e).forEach(([n,o])=>{if(!n.trim()){t.push(a("invalid_sql_default_parameter_name","SQL defaultParameters names must be non-empty strings.",`${i}.${n}`));return}(Array.isArray(o)?o.every(E):E(o))||t.push(a("invalid_sql_default_parameter_value","SQL defaultParameters values must be strings, numbers, booleans, nulls, or arrays of those scalar values.",`${i}.${n}`))})}}function ie(e,i){return M(e,i).length===1}function te(e,i){return M(e,i).length===1}function M(e,i){return i.filter(n=>ae(e,n))}function ae(e,i){return ne(e,i)?e.source?L(i,e):!0:!1}function ne(e,i){return!(i.name!==e.name||e.role!==void 0&&i.role!==void 0&&i.role!==e.role||se(e,i)&&g(i)!==g(e))}function se(e,i){return e.role==="measure"||i.role==="measure"||e.aggregate!==void 0||i.aggregate!==void 0}function g(e){return(e.aggregate||"SUM").toUpperCase()}const oe=/^(\d{4})-(\d{2})-(\d{2})$/,re=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})$/;function $(e){if(typeof e!="string")return null;const i=e.trim(),t=oe.exec(i);if(t){const[,y,P,T]=t;return N(y,P,T)?new Date(Date.UTC(Number(y),Number(P)-1,Number(T))):null}const n=re.exec(i);if(!n)return null;const[,o,s,r,c,d,p="00",,m]=n;if(!N(o,s,r)||!v(c,0,23)||!v(d,0,59)||!v(p,0,59)||!de(m))return null;const b=new Date(i);return Number.isFinite(b.getTime())?b:null}function N(e,i,t){const n=Number(e),o=Number(i),s=Number(t);if(!Number.isInteger(n)||!Number.isInteger(o)||!Number.isInteger(s)||o<1||o>12)return!1;const r=new Date(Date.UTC(n,o-1,s));return r.getUTCFullYear()===n&&r.getUTCMonth()===o-1&&r.getUTCDate()===s}function v(e,i,t){const n=Number(e);return Number.isInteger(n)&&n>=i&&n<=t}function de(e){if(e==="Z")return!0;const i=/^([+-])(\d{2}):(\d{2})$/.exec(e);return!!(i&&v(i[2],0,23)&&v(i[3],0,59))}function l(e){return typeof e=="string"&&e.trim().length>0}function le(e){const i=new Set;let t=0;for(;t<e.length;){const n=e[t];if(n==="'"||n==='"'){t=ue(e,t);continue}if(n==="{"){const o=e.indexOf("}",t+1);if(o===-1){t+=1;continue}const s=e.slice(t+1,o);/^[A-Za-z_][A-Za-z0-9_]*$/.test(s)&&i.add(s),t=o+1;continue}t+=1}return Array.from(i)}function ue(e,i){const t=e[i];let n=i+1;for(;n<e.length;){if(e[n]===t){if(e[n+1]===t){n+=2;continue}return n+1}n+=1}return e.length}function u(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function O(e,i,t){if(e!==void 0){if(!u(e)){t.push(a("invalid_pagination","Pagination must be an object with positive integer page and pageSize.",i));return}(!Number.isInteger(e.page)||typeof e.page!="number"||e.page<1)&&t.push(a("invalid_pagination_page","Pagination page must be a positive integer.",`${i}.page`)),(!Number.isInteger(e.pageSize)||typeof e.pageSize!="number"||e.pageSize<1)&&t.push(a("invalid_pagination_page_size","Pagination pageSize must be a positive integer.",`${i}.pageSize`))}}function I(e){const i=new Set;for(const t of e){if(i.has(t))return t;i.add(t)}return null}function w(e,i,t,n){I(e.filter(s=>l(s)))&&n.push(a("duplicate_matrix_public_id",`Matrix ${t} ids must be unique so sort and expansion references are unambiguous.`,i))}const ce=new Set(["SUM","COUNT","AVG","MIN","MAX","MEDIAN","DISTINCT"]);function k(e,i,t){if(!e||typeof e!="object"){t.push(a("missing_source","Analytics intent needs a source.",i));return}if(e.kind==="semantic"){l(e.domainId)||t.push(a("missing_semantic_domain","Semantic source needs a domainId.",`${i}.domainId`)),l(e.datasetName)||t.push(a("missing_dataset_name","Semantic source needs a datasetName.",`${i}.datasetName`));return}if(e.kind==="physical"){l(e.connectionId)||t.push(a("missing_connection_id","Physical source needs a connectionId.",`${i}.connectionId`)),l(e.tableName)||t.push(a("missing_table_name","Physical source needs a tableName.",`${i}.tableName`));return}if(e.kind==="sql"){l(e.connectionId)||t.push(a("missing_connection_id","SQL source needs a connectionId.",`${i}.connectionId`));return}t.push(a("invalid_source_kind","Source kind is not supported.",i))}function f(e,i,t,n={}){if(!e||!u(e)){n.required&&t.push(a("missing_field_ref","Field reference needs a name.",i));return}l(e.name)||t.push(a("missing_field_ref","Field reference needs a name.",`${i}.name`)),e.source!==void 0&&k(e.source,`${i}.source`,t),_(e.aggregate,`${i}.aggregate`,t)}function pe(e,i,t){if(!u(e)){t.push(a("invalid_input_binding","Input bindings must be structured objects.",i));return}l(e.inputId)||t.push(a("invalid_input_binding","Input bindings need a non-empty inputId.",`${i}.inputId`)),e.kind!==void 0&&e.kind!=="filter"&&e.kind!=="control"&&t.push(a("invalid_input_binding","Input binding kind must be filter or control.",`${i}.kind`)),e.field!==void 0&&f(e.field,`${i}.field`,t),e.relationshipHint!==void 0&&R(e.relationshipHint,`${i}.relationshipHint`,t)}function R(e,i,t){if(!u(e)){t.push(a("invalid_relationship_hint","Relationship hints must be structured objects.",i));return}e.relationshipIds!==void 0&&(!Array.isArray(e.relationshipIds)||e.relationshipIds.some(n=>!l(n)))&&t.push(a("invalid_relationship_hint","Relationship hint relationshipIds must be non-empty strings.",`${i}.relationshipIds`))}function fe(e,i){if(l(e.inputId)||i.push(a("missing_input_options_input_id","Input options intent needs the inputId it populates.","inputId")),(!e.labelField||!l(e.labelField.name))&&i.push(a("missing_input_options_label_field","Input options intent needs a labelField.","labelField")),f(e.labelField,"labelField",i,{required:!0}),(!e.valueField||!l(e.valueField.name))&&i.push(a("missing_input_options_value_field","Input options intent needs a valueField.","valueField")),f(e.valueField,"valueField",i,{required:!0}),e.searchField!==void 0&&f(e.searchField,"searchField",i,{required:!0}),e.disambiguationFields!==void 0&&(Array.isArray(e.disambiguationFields)?e.disambiguationFields.forEach((t,n)=>{f(t,`disambiguationFields.${n}`,i,{required:!0})}):i.push(a("invalid_input_options_disambiguation_fields","Input options disambiguationFields must be an array of field refs.","disambiguationFields"))),e.dependencies!==void 0){const t=e.dependencies;if(!u(t))i.push(a("invalid_input_options_dependencies","Input options dependencies must be a structured object.","dependencies"));else{const n=t.mode;n!==void 0&&n!=="auto"&&n!=="independent"&&n!=="explicit"&&i.push(a("invalid_input_options_dependencies","Input options dependencies mode must be auto, independent, or explicit.","dependencies.mode")),j(t.includeInputIds,"dependencies.includeInputIds",i,"Input options includeInputIds must be non-empty strings."),j(t.excludeInputIds,"dependencies.excludeInputIds",i,"Input options excludeInputIds must be non-empty strings."),_e(e,i)}}if(e.population!==void 0){const t=e.population;if(!u(t))i.push(a("invalid_input_options_population","Input options population must be a structured object.","population"));else{const n=t.kind;n!=="option_source"&&n!=="related_population"&&i.push(a("invalid_input_options_population","Input options population kind must be option_source or related_population.","population.kind")),n==="option_source"&&t.baseSource!==void 0&&i.push(a("invalid_input_options_population","Input options population baseSource is only valid for related_population.","population.baseSource")),n==="option_source"&&t.relationshipHint!==void 0&&i.push(a("invalid_input_options_population","Input options population relationshipHint is only valid for related_population.","population.relationshipHint")),n==="related_population"&&(k(t.baseSource,"population.baseSource",i),t.relationshipHint!==void 0&&R(t.relationshipHint,"population.relationshipHint",i))}}}function me(e,i){if(!(!("inputs"in e)||e.inputs===void 0)){if(!Array.isArray(e.inputs)){i.push(a("invalid_input_binding","Analytics intent inputs must be an array of input bindings.","inputs"));return}e.inputs.forEach((t,n)=>pe(t,`inputs.${n}`,i))}}function _e(e,i){var n,o;const t=new Set(Array.isArray(e.inputs)?e.inputs.map(s=>u(s)?s.inputId:void 0).filter(s=>typeof s=="string"):[]);for(const s of((n=e.dependencies)==null?void 0:n.includeInputIds)||[])t.has(s)||i.push(a("invalid_input_options_dependencies",`Input options dependency "${s}" is not declared in inputs.`,"dependencies.includeInputIds"));for(const s of((o=e.dependencies)==null?void 0:o.excludeInputIds)||[])s!==e.inputId&&!t.has(s)&&i.push(a("invalid_input_options_dependencies",`Input options dependency exclusion "${s}" is not the populated inputId and is not declared in inputs.`,"dependencies.excludeInputIds"))}function j(e,i,t,n){e!==void 0&&(!Array.isArray(e)||e.some(o=>!l(o)))&&t.push(a("invalid_input_options_dependencies",n,i))}function _(e,i,t){e!==void 0&&(typeof e!="string"||!ce.has(e))&&t.push(a("invalid_aggregate","Field aggregate must be SUM, COUNT, AVG, MIN, MAX, MEDIAN, or DISTINCT.",i))}const ve=new Set(["measure","dimension","date","id","unknown"]),ge=new Set(["row","aggregate"]),V=new Set(["string","number","boolean","date","datetime","unknown"]),be=new Set(["number","currency","percent","percentage","scientific","date","datetime","duration","string"]),ye=new Set(["millisecond","second","minute","hour","day"]),he=new Set(["compact","digital","long"]);function D(e,i,t){if(e===void 0)return;if(!u(e)){t.push(a("invalid_value_format","Value format must be a structured object.",i));return}const n=e;(typeof n.type!="string"||!be.has(n.type))&&t.push(a("invalid_value_format_type","Value format type must be number, currency, percent, scientific, date, datetime, duration, or string.",`${i}.type`)),h(e.minimumFractionDigits,`${i}.minimumFractionDigits`,t),h(e.maximumFractionDigits,`${i}.maximumFractionDigits`,t),h(e.scale,`${i}.scale`,t),h(e.maxUnits,`${i}.maxUnits`,t),e.useGrouping!==void 0&&typeof e.useGrouping!="boolean"&&t.push(a("invalid_value_format_use_grouping","Value format useGrouping must be boolean.",`${i}.useGrouping`)),e.negativeStyle!==void 0&&e.negativeStyle!=="minus"&&e.negativeStyle!=="parentheses"&&t.push(a("invalid_value_format_negative_style","Value format negativeStyle must be minus or parentheses.",`${i}.negativeStyle`)),e.percentValueMode!==void 0&&e.percentValueMode!=="fraction"&&e.percentValueMode!=="whole"&&t.push(a("invalid_value_format_percent_mode","Value format percentValueMode must be fraction or whole.",`${i}.percentValueMode`));for(const o of["inputUnit","largestUnit","smallestUnit"]){const s=e[o];s!==void 0&&(typeof s!="string"||!ye.has(s))&&t.push(a("invalid_value_format_duration_unit","Duration format units must be millisecond, second, minute, hour, or day.",`${i}.${o}`))}e.outputStyle!==void 0&&(typeof e.outputStyle!="string"||!he.has(e.outputStyle))&&t.push(a("invalid_value_format_duration_style","Duration format outputStyle must be compact, digital, or long.",`${i}.outputStyle`))}function h(e,i,t){e!==void 0&&(typeof e!="number"||!Number.isFinite(e))&&t.push(a("invalid_value_format_number","Value format numeric options must be finite numbers.",i))}const xe=new Set(["additive","non_additive","ratio_of_sums","weighted","pre_aggregated","snapshot"]),we=new Set(["default","symmetric_aggregate","aggregate_then_join","weighted"]);function $e(e,i,t){if(!e||!u(e)){t.push(a("invalid_derived_field_input","Derived field inputs must be structured input references.",i));return}if(e.kind==="field"){f(e.field,`${i}.field`,t,{required:!0}),_(e.aggregate,`${i}.aggregate`,t);return}t.push(a("invalid_derived_field_input","Derived field input kind must be field.",`${i}.kind`))}function B(e,i,t){if(!u(e)){t.push(a("invalid_result_column_ref","Result calculation references must use columnKey or field.",i));return}const n=l(e.columnKey),o=u(e.field);if(n===o){t.push(a("invalid_result_column_ref","Result calculation references must identify exactly one of columnKey or field.",i));return}o&&f(e.field,`${i}.field`,t,{required:!0})}function Ie(e,i,t){if(!u(e)){t.push(a("invalid_result_calculation_output","Result calculation output must be a structured object.",i));return}l(e.key)||t.push(a("invalid_result_calculation_output","Result calculation output needs a stable key.",`${i}.key`)),e.dataType!==void 0&&(typeof e.dataType!="string"||!V.has(e.dataType))&&t.push(a("invalid_result_calculation_output","Result calculation output dataType must be string, number, boolean, date, datetime, or unknown.",`${i}.dataType`)),D(e.format,`${i}.format`,t)}function Se(e,i,t){e!==void 0&&e!=="hour"&&e!=="day"&&e!=="week"&&e!=="month"&&e!=="quarter"&&e!=="year"&&t.push(a("invalid_time_grain","Time grain must be hour, day, week, month, quarter, or year.",i))}function G(e,i,t,n){e!=="asc"&&e!=="desc"&&t.push(a(n,"Sort direction must be asc or desc.",i))}function z(e,i,t,n){e!==void 0&&e!=="warehouseDefault"&&e!=="first"&&e!=="last"&&t.push(a(n,"Null ordering must be warehouseDefault, first, or last.",i))}function Q(e,i,t,n){e!==void 0&&e!=="global"&&e!=="withinParent"&&t.push(a(n,"Sort scope must be global or withinParent.",i))}function Ae(e,i,t){e.enabled!==void 0&&typeof e.enabled!="boolean"&&t.push(a("invalid_matrix_subtotal","Matrix subtotal enabled must be a boolean.",`${i}.enabled`)),e.position!==void 0&&e.position!=="before"&&e.position!=="after"&&t.push(a("invalid_matrix_subtotal","Matrix subtotal position must be before or after.",`${i}.position`)),e.label!==void 0&&typeof e.label!="string"&&t.push(a("invalid_matrix_subtotal","Matrix subtotal label must be a string.",`${i}.label`))}function Me(e,i,t){if(G(e.direction,`${i}.direction`,t,"invalid_matrix_sort_direction"),z(e.nulls,`${i}.nulls`,t,"invalid_matrix_sort_nulls"),Q(e.scope,`${i}.scope`,t,"invalid_matrix_sort_scope"),!u(e.by)){t.push(a("invalid_matrix_sort_by","Matrix sort by must be a structured object.",`${i}.by`));return}if(e.by.kind!=="label"){if(e.by.kind==="field"){f(e.by.field,`${i}.by.field`,t,{required:!0}),_(e.by.aggregate,`${i}.by.aggregate`,t);return}t.push(a("invalid_matrix_sort_by","Matrix axis sort by must be label or field.",`${i}.by.kind`))}}function q(e,i,t,n){if(!Array.isArray(e))return n.required?t.push(a("missing_matrix_rows","Matrix intent needs at least one row axis level.",i)):e!==void 0&&t.push(a("invalid_matrix_columns","Matrix columns must be an array of axis levels.",i)),[];n.required&&e.length===0&&t.push(a("missing_matrix_rows","Matrix intent needs at least one row axis level.",i));const o=[];return e.forEach((s,r)=>{const c=`${i}.${r}`;if(!u(s)){t.push(a("invalid_matrix_axis_level","Matrix axis levels must be structured objects.",c));return}const d=s;o.push(d),d.id!==void 0&&!l(d.id)&&t.push(a("invalid_matrix_axis_level_id","Matrix axis level id must be a non-empty string.",`${c}.id`)),f(d.field,`${c}.field`,t,{required:!0}),Se(d.grain,`${c}.grain`,t),d.label!==void 0&&typeof d.label!="string"&&t.push(a("invalid_matrix_axis_label","Matrix axis level label must be a string.",`${c}.label`)),d.subtotal!==void 0&&typeof d.subtotal!="boolean"&&(u(d.subtotal)?Ae(d.subtotal,`${c}.subtotal`,t):t.push(a("invalid_matrix_subtotal","Matrix subtotal must be a boolean or structured options object.",`${c}.subtotal`))),d.sortBy!==void 0&&(u(d.sortBy)?Me(d.sortBy,`${c}.sortBy`,t):t.push(a("invalid_matrix_sort_by","Matrix axis sortBy must be a structured object.",`${c}.sortBy`)))}),o}function ke(e,i,t){if(!u(e)){t.push(a("invalid_matrix_total_behavior","Matrix total behavior must be a structured object.",i));return}if(e.kind!=="defaultAggregate"&&e.kind!=="blank"&&e.kind!=="labelOnly"&&e.kind!=="customAggregate"&&e.kind!=="percentOfParent"&&e.kind!=="percentOfGrandTotal"&&e.kind!=="customExpression"){t.push(a("invalid_matrix_total_behavior","Matrix total behavior kind is not supported.",`${i}.kind`));return}e.kind==="customAggregate"&&(Object.prototype.hasOwnProperty.call(e,"aggregate")?_(e.aggregate,`${i}.aggregate`,t):t.push(a("invalid_matrix_total_behavior","Custom matrix total behavior needs an aggregate.",`${i}.aggregate`))),e.kind==="customExpression"&&!l(e.expressionId)&&t.push(a("invalid_matrix_total_behavior","Custom matrix total behavior needs an expressionId.",`${i}.expressionId`)),e.kind==="labelOnly"&&e.label!==void 0&&typeof e.label!="string"&&t.push(a("invalid_matrix_total_behavior","Matrix label-only total behavior label must be a string.",`${i}.label`))}function Re(e,i,t){if(!Array.isArray(e)||e.length===0)return t.push(a("missing_matrix_values","Matrix intent needs at least one value field.",i)),[];const n=[];return e.forEach((o,s)=>{const r=`${i}.${s}`;if(!u(o)){t.push(a("invalid_matrix_value","Matrix values must be structured objects.",r));return}const c=o;n.push(c),c.id!==void 0&&!l(c.id)&&t.push(a("invalid_matrix_value_id","Matrix value id must be a non-empty string.",`${r}.id`)),f(c.field,`${r}.field`,t,{required:!0}),_(c.aggregate,`${r}.aggregate`,t),D(c.format,`${r}.format`,t),c.label!==void 0&&typeof c.label!="string"&&t.push(a("invalid_matrix_value_label","Matrix value label must be a string.",`${r}.label`)),c.totalBehavior!==void 0&&ke(c.totalBehavior,`${r}.totalBehavior`,t)}),n}function De(e,i,t){if(!u(e)){t.push(a("invalid_matrix_totals","Matrix totals must be a structured object.",i));return}for(const n of["rows","columns"]){const o=e[n];o!==void 0&&o!==!0&&o!==!1&&o!=="perLevel"&&t.push(a("invalid_matrix_totals","Matrix total axis setting must be a boolean or perLevel.",`${i}.${n}`))}if(e.grandTotal!==void 0&&typeof e.grandTotal!="boolean")if(!u(e.grandTotal))t.push(a("invalid_matrix_totals","Matrix grandTotal must be a boolean or structured object.",`${i}.grandTotal`));else for(const n of["rows","columns"]){const o=e.grandTotal[n];o!==void 0&&typeof o!="boolean"&&t.push(a("invalid_matrix_totals","Matrix grandTotal rows/columns must be booleans.",`${i}.grandTotal.${n}`))}e.rowPosition!==void 0&&e.rowPosition!=="top"&&e.rowPosition!=="bottom"&&t.push(a("invalid_matrix_totals","Matrix row total position must be top or bottom.",`${i}.rowPosition`)),e.columnPosition!==void 0&&e.columnPosition!=="left"&&e.columnPosition!=="right"&&t.push(a("invalid_matrix_totals","Matrix column total position must be left or right.",`${i}.columnPosition`))}function S(e,i,t,n){if(!Array.isArray(e)){n.push(a("invalid_matrix_path","Matrix member path must be an array of path segments.",i));return}e.forEach((o,s)=>{const r=`${i}.${s}`;if(!u(o)){n.push(a("invalid_matrix_path","Matrix path segment must be a structured object.",r));return}const c=o;if(!l(c.levelId)){n.push(a("stable_id_required","Matrix path segments must reference an explicit public axis level id.",`${r}.levelId`));return}Object.prototype.hasOwnProperty.call(o,"value")||n.push(a("invalid_matrix_path","Matrix path segments must include a value property; use explicit null for null members.",`${r}.value`)),t.has(c.levelId)||n.push(a("stable_id_required","Matrix path segment levelId must match an explicit public axis level id.",`${r}.levelId`))})}function H(e,i,t,n){if(!u(e)){n.push(a("invalid_matrix_expansion","Matrix expansion axis options must be structured objects.",i));return}e.defaultDepth!==void 0&&(typeof e.defaultDepth!="number"||!Number.isInteger(e.defaultDepth)||e.defaultDepth<0)&&n.push(a("invalid_matrix_expansion","Matrix expansion defaultDepth must be a non-negative integer.",`${i}.defaultDepth`)),e.lazy!==void 0&&typeof e.lazy!="boolean"&&n.push(a("invalid_matrix_expansion","Matrix expansion lazy must be a boolean.",`${i}.lazy`)),e.expandedPaths!==void 0&&(Array.isArray(e.expandedPaths)?e.expandedPaths.forEach((o,s)=>{S(o,`${i}.expandedPaths.${s}`,t,n)}):n.push(a("invalid_matrix_expansion","Matrix expandedPaths must be an array of member paths.",`${i}.expandedPaths`)))}function Fe(e,i,t,n){if(e!==void 0){if(!u(e)){n.push(a("invalid_matrix_expansion","Matrix expansion must be a structured object.","expansion"));return}e.rows!==void 0&&H(e.rows,"expansion.rows",i,n),e.columns!==void 0&&H(e.columns,"expansion.columns",t,n)}}function Pe(e,i,t,n,o){if(e!==void 0){if(!Array.isArray(e)){o.push(a("invalid_matrix_sort","Matrix sort must be an array of sort rules.","sort"));return}e.forEach((s,r)=>{const c=`sort.${r}`;if(!u(s)){o.push(a("invalid_matrix_sort","Matrix sort rule must be a structured object.",c));return}const d=s;d.axis!=="row"&&d.axis!=="column"&&o.push(a("invalid_matrix_sort","Matrix sort axis must be row or column.",`${c}.axis`));const p=d.axis==="column"?t:i;if(d.targetId!==void 0&&!p.has(d.targetId)&&o.push(a("stable_id_required","Matrix sort targetId must reference an explicit public axis level id.",`${c}.targetId`)),G(d.direction,`${c}.direction`,o,"invalid_matrix_sort_direction"),z(d.nulls,`${c}.nulls`,o,"invalid_matrix_sort_nulls"),Q(d.scope,`${c}.scope`,o,"invalid_matrix_sort_scope"),!u(d.by)){o.push(a("invalid_matrix_sort_by","Matrix sort by must be a structured object.",`${c}.by`));return}if(d.by.kind!=="label"){if(d.by.kind==="field"){f(d.by.field,`${c}.by.field`,o,{required:!0}),_(d.by.aggregate,`${c}.by.aggregate`,o);return}if(d.by.kind==="value"){(!l(d.by.valueId)||!n.has(d.by.valueId))&&o.push(a("stable_id_required","Matrix value sort must reference an explicit public value id.",`${c}.by.valueId`)),d.by.rowPath!==void 0&&S(d.by.rowPath,`${c}.by.rowPath`,i,o),d.by.columnPath!==void 0&&S(d.by.columnPath,`${c}.by.columnPath`,t,o);return}o.push(a("invalid_matrix_sort_by","Matrix sort by must be label, field, or value.",`${c}.by.kind`))}})}}function Te(e,i){if(e!==void 0){if(!u(e)){i.push(a("invalid_matrix_layout","Matrix layout must be a structured object.","layout"));return}e.hierarchy!==void 0&&e.hierarchy!=="compact"&&e.hierarchy!=="tabular"&&e.hierarchy!=="outline"&&i.push(a("invalid_matrix_layout","Matrix hierarchy layout must be compact, tabular, or outline.","layout.hierarchy")),e.valuesPlacement!==void 0&&e.valuesPlacement!=="columns"&&e.valuesPlacement!=="rows"&&i.push(a("invalid_matrix_layout","Matrix valuesPlacement must be columns or rows.","layout.valuesPlacement")),e.stickyRowHeaders!==void 0&&typeof e.stickyRowHeaders!="boolean"&&i.push(a("invalid_matrix_layout","Matrix stickyRowHeaders must be a boolean.","layout.stickyRowHeaders")),e.stickyColumnHeaders!==void 0&&typeof e.stickyColumnHeaders!="boolean"&&i.push(a("invalid_matrix_layout","Matrix stickyColumnHeaders must be a boolean.","layout.stickyColumnHeaders"))}}function C(e,i,t){if(!u(e)){t.push(a("invalid_matrix_display_limits","Matrix display limit must be a structured object.",i));return}(typeof e.limit!="number"||!Number.isInteger(e.limit)||e.limit<1)&&t.push(a("invalid_matrix_display_limits","Matrix display limit must be a positive integer.",`${i}.limit`)),e.by!==void 0&&e.by!=="label"&&e.by!=="value"&&t.push(a("invalid_matrix_display_limits","Matrix display limit by must be label or value.",`${i}.by`)),e.direction!==void 0&&e.direction!=="top"&&e.direction!=="bottom"&&t.push(a("invalid_matrix_display_limits","Matrix display limit direction must be top or bottom.",`${i}.direction`)),e.others!==void 0&&typeof e.others!="boolean"&&(u(e.others)?e.others.label!==void 0&&typeof e.others.label!="string"&&t.push(a("invalid_matrix_display_limits","Matrix display limit others label must be a string.",`${i}.others.label`)):t.push(a("invalid_matrix_display_limits","Matrix display limit others must be a boolean or structured object.",`${i}.others`)))}function Ee(e,i){if(e!==void 0){if(!u(e)){i.push(a("invalid_matrix_display_limits","Matrix displayLimits must be a structured object.","displayLimits"));return}e.rows!==void 0&&C(e.rows,"displayLimits.rows",i),e.columns!==void 0&&C(e.columns,"displayLimits.columns",i)}}function Ne(e,i){var d;((d=e.source)==null?void 0:d.kind)==="sql"&&i.push(a("unsupported_matrix_sql_source","Matrix analytics intent does not support raw SQL sources.","source.kind"));const t=q(e.rows,"rows",i,{required:!0}),n=q(e.columns,"columns",i,{required:!1}),o=Re(e.values,"values",i);x(e.filters,"filters",i),e.totals!==void 0&&De(e.totals,"totals",i),w(t.map(p=>p.id),"rows","row axis level",i),w(n.map(p=>p.id),"columns","column axis level",i),w(o.map(p=>p.id),"values","value",i);const s=new Set(t.map(p=>p.id).filter(p=>l(p))),r=new Set(n.map(p=>p.id).filter(p=>l(p))),c=new Set(o.map(p=>p.id).filter(p=>l(p)));Pe(e.sort,s,r,c,i),Fe(e.expansion,s,r,i),Te(e.layout,i),Ee(e.displayLimits,i)}function Oe(e,i){if(e.analysis===void 0)return;if(!u(e.analysis)){i.push(a("invalid_measure_analysis","Metric analysis must be a structured object.","analysis"));return}if(e.analysis.kind!=="period_change"){i.push(a("invalid_measure_analysis","Metric analysis kind is not supported.","analysis.kind"));return}e.dateField||i.push(a("missing_analysis_date_field","Period-change analysis needs a dateField.","dateField")),e.timeGrain||i.push(a("missing_analysis_time_grain","Period-change analysis needs a timeGrain.","timeGrain")),e.analysis.orderBy!==void 0&&e.analysis.orderBy!=="absolute_change"&&e.analysis.orderBy!=="positive_change"&&e.analysis.orderBy!=="negative_change"&&e.analysis.orderBy!=="period"&&i.push(a("invalid_measure_analysis","Period-change analysis orderBy must be absolute_change, positive_change, negative_change, or period.","analysis.orderBy"));const{timeWindow:t}=e.analysis;t!==void 0&&A(t,"analysis.timeWindow",i)}function A(e,i,t){if(!u(e)){t.push(a("invalid_time_window","Time window must be a structured object.",i));return}if(e.kind!==void 0&&e.kind!=="relative"&&e.kind!=="absolute"&&t.push(a("invalid_time_window","Time window kind must be relative or absolute.",`${i}.kind`)),e.kind==="absolute"){if(l(e.start)||t.push(a("invalid_time_window","Absolute time window start must be a non-empty ISO date or timestamp string.",`${i}.start`)),l(e.end)||t.push(a("invalid_time_window","Absolute time window end must be a non-empty ISO date or timestamp string.",`${i}.end`)),l(e.start)&&l(e.end)){const n=$(e.start),o=$(e.end);n||t.push(a("invalid_time_window","Absolute time window start must be a valid ISO date or timestamp.",`${i}.start`)),o||t.push(a("invalid_time_window","Absolute time window end must be a valid ISO date or timestamp.",`${i}.end`)),n&&o&&n.getTime()>o.getTime()&&t.push(a("invalid_time_window","Absolute time window start must be before or equal to end.",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"&&t.push(a("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)&&t.push(a("invalid_time_window","Time window value must be a positive number.",`${i}.value`)),e.anchor!==void 0&&e.anchor!=="now"&&e.anchor!=="latest_available"&&t.push(a("invalid_time_window","Time window anchor must be now or latest_available.",`${i}.anchor`)),e.completeness!==void 0&&e.completeness!=="include_partial"&&e.completeness!=="complete_periods"&&t.push(a("invalid_time_window","Time window completeness must be include_partial or complete_periods.",`${i}.completeness`))}function x(e,i,t){if(e!==void 0){if(!Array.isArray(e)){t.push(a("invalid_analytics_filters","Analytics filters must be an array.",i));return}e.forEach((n,o)=>{var d;const s=`${i}.${o}`;if(!u(n)){t.push(a("invalid_analytics_filter","Analytics filter must be a structured object.",s));return}const r=n;f(r.field,`${s}.field`,t,{required:!0}),r.scope!==void 0&&r.scope!=="row"&&r.scope!=="aggregate"&&t.push(a("invalid_analytics_filter_scope","Analytics filter scope must be row or aggregate.",`${s}.scope`)),r.scope==="aggregate"&&((d=r.field)==null?void 0:d.role)!==void 0&&r.field.role!=="measure"&&t.push(a("invalid_analytics_filter_scope","Aggregate-scope analytics filters must target a measure field.",`${s}.scope`));const c=r.operator==="is_null"||r.operator==="is_not_null";if(r.operator!==void 0&&r.operator!=="="&&r.operator!=="!="&&r.operator!=="in"&&r.operator!=="not_in"&&r.operator!=="contains"&&r.operator!=="not_contains"&&r.operator!=="between"&&r.operator!=="not_between"&&r.operator!==">"&&r.operator!==">="&&r.operator!=="<"&&r.operator!=="<="&&r.operator!=="is_null"&&r.operator!=="is_not_null"&&t.push(a("invalid_analytics_filter_operator","Analytics filter operator is not supported.",`${s}.operator`)),r.values===void 0&&!c&&t.push(a("missing_analytics_filter_value","Analytics filter needs values unless it is a null check.",s)),c&&r.values!==void 0){t.push(a("invalid_analytics_filter_values","Null-check analytics filters must not include values.",`${s}.values`));return}if(r.values!==void 0&&!Array.isArray(r.values)){t.push(a("invalid_analytics_filter_values","Analytics filter values must be an array when provided.",`${s}.values`));return}if(r.values!==void 0){const p=r.values.length;if(r.operator==="between"||r.operator==="not_between"){p!==2&&t.push(a("invalid_analytics_filter_values","Between analytics filters must include exactly two values.",`${s}.values`));return}(r.operator==="contains"||r.operator==="not_contains"||r.operator==="="||r.operator==="!="||r.operator===">"||r.operator===">="||r.operator==="<"||r.operator==="<="||r.operator===void 0)&&p!==1&&t.push(a("invalid_analytics_filter_values","Scalar analytics filters must include exactly one value. Use in/not_in for multiple values.",`${s}.values`))}})}}function Y(e){const i=[];if(!u(e))return i.push(a("invalid_derived_field","Derived field definition must be a structured object.")),{ok:!1,errors:i,warnings:[]};if(e.kind!=="derived_field"&&i.push(a("invalid_derived_field_kind","Derived field kind must be derived_field.","kind")),l(e.name)||i.push(a("invalid_derived_field_name","Derived field needs a name.","name")),l(e.label)||i.push(a("invalid_derived_field_label","Derived field needs a label.","label")),ve.has(e.resultRole)||i.push(a("invalid_derived_field_role","Derived field resultRole must be measure, dimension, date, id, or unknown.","resultRole")),V.has(e.dataType)||i.push(a("invalid_derived_field_data_type","Derived field dataType must be string, number, boolean, date, datetime, or unknown.","dataType")),ge.has(e.computeStage)||i.push(a("invalid_derived_field_compute_stage","Derived field computeStage must be row or aggregate.","computeStage")),e.computeStage==="aggregate"&&e.resultRole!=="measure"&&i.push(a("invalid_derived_field_compute_stage","Aggregate-stage derived fields must have resultRole measure.","computeStage")),e.resultRole!=="measure"&&e.defaultAggregate!==void 0&&i.push(a("invalid_derived_field_aggregate","Only measure derived fields may declare defaultAggregate.","defaultAggregate")),e.computeStage==="row"&&e.resultRole==="measure"&&e.defaultAggregate===void 0&&i.push(a("missing_derived_field_default_aggregate","Row-stage measure derived fields must declare defaultAggregate so row results have explicit rollup semantics.","defaultAggregate")),_(e.defaultAggregate,"defaultAggregate",i),e.aggregationBehavior!==void 0&&!xe.has(e.aggregationBehavior)&&i.push(a("invalid_derived_field_aggregation_behavior","Derived field aggregationBehavior is not supported.","aggregationBehavior")),e.aggregationStrategy!==void 0&&!we.has(e.aggregationStrategy)&&i.push(a("invalid_derived_field_aggregation_strategy","Derived field aggregationStrategy is not supported.","aggregationStrategy")),l(e.expression)||i.push(a("invalid_derived_field_expression","Derived field needs a named-token expression.","expression")),e.expressionLanguage!==void 0&&e.expressionLanguage!=="semaphor_sql_template"&&i.push(a("invalid_derived_field_expression_language","Derived field expressionLanguage must be semaphor_sql_template.","expressionLanguage")),!u(e.inputs)||Object.keys(e.inputs).length===0?i.push(a("invalid_derived_field_inputs","Derived field needs at least one typed input.","inputs")):Object.entries(e.inputs).forEach(([t,n])=>{if(!l(t)){i.push(a("invalid_derived_field_input_name","Derived field input names must be non-empty strings.","inputs"));return}$e(n,`inputs.${t}`,i)}),l(e.expression)&&u(e.inputs)){const t=le(e.expression),n=new Set(t),o=Object.keys(e.inputs).filter(s=>l(s));t.forEach(s=>{Object.prototype.hasOwnProperty.call(e.inputs,s)||i.push(a("invalid_derived_field_expression_token",`Derived field expression token "{${s}}" needs a matching inputs.${s} entry.`,"expression"))}),o.forEach(s=>{n.has(s)||i.push(a("unused_derived_field_input",`Derived field input "${s}" is not referenced by expression.`,`inputs.${s}`))})}return D(e.format,"format",i),e.tags!==void 0&&(!Array.isArray(e.tags)||e.tags.some(t=>!l(t)))&&i.push(a("invalid_derived_field_tags","Derived field tags must be non-empty strings.","tags")),{ok:i.length===0,errors:i,warnings:[]}}function je(e){const i=[];if(!u(e))return i.push(a("invalid_result_calculation","Result calculation must be a structured object.")),{ok:!1,errors:i,warnings:[]};if(l(e.id)||i.push(a("invalid_result_calculation_id","Result calculation needs an id.","id")),l(e.label)||i.push(a("invalid_result_calculation_label","Result calculation needs a label.","label")),e.kind!=="percent_of_total"&&e.kind!=="rank"&&e.kind!=="running_total"&&e.kind!=="previous_row_delta"&&i.push(a("invalid_result_calculation_kind","Result calculation kind must be percent_of_total, rank, running_total, or previous_row_delta.","kind")),B(e.input,"input",i),Ie(e.output,"output",i),e.kind==="percent_of_total"){const t=e.denominator;t!==void 0&&(u(t)?t.scope==="population"?(f(t.metric,"denominator.metric",i,{required:!0}),x(t.filters,"denominator.filters",i)):t.scope!=="returned_result"&&i.push(a("invalid_result_calculation_denominator","Percent-of-total denominator scope must be returned_result or population.","denominator.scope")):i.push(a("invalid_result_calculation_denominator","Percent-of-total denominator must be a structured object.","denominator")))}return e.kind==="rank"&&e.order!==void 0&&e.order!=="asc"&&e.order!=="desc"&&i.push(a("invalid_result_calculation_order","Rank result calculation order must be asc or desc.","order")),(e.kind==="running_total"||e.kind==="previous_row_delta")&&e.orderBy!==void 0&&B(e.orderBy,"orderBy",i),{ok:i.length===0,errors:i,warnings:[]}}function F(e){var n;const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_analytics_intent","Analytics intent must be a structured object.")],warnings:t,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(a("invalid_version","Analytics intent version must be 1.","version")),k(e.source,"source",i),Be(e,i),me(e,i),"relationshipHint"in e&&e.relationshipHint!==void 0&&R(e.relationshipHint,"relationshipHint",i),e.kind==="metric"){const o=Array.isArray(e.measures)?e.measures.filter(s=>u(s)&&l(s.name)):[];if(!Array.isArray(e.measures)||e.measures.length===0?i.push(a("missing_measure","Metric intent needs at least one measure.","measures")):e.measures.some(s=>!u(s)||!l(s.name))&&i.push(a("invalid_measure_list","Metric intent measures must be an array of field references with names.","measures")),o.forEach((s,r)=>{f(s,`measures.${r}`,i,{required:!0})}),o.length>0&&!J(o)){const s=o.find((r,c)=>o.some((d,p)=>p!==c&&U(d,r)));s&&i.push(a("duplicate_measure",W(s),"measures"))}if(u(e.primaryMeasure)&&l(e.primaryMeasure.name)&&M(e.primaryMeasure,o).length>1&&i.push(a("ambiguous_primary_measure","Metric intent primaryMeasure must identify exactly one selected measure.","primaryMeasure")),e.primaryMeasure!==void 0&&(f(e.primaryMeasure,"primaryMeasure",i,{required:!0}),u(e.primaryMeasure)&&l(e.primaryMeasure.name)&&o.length>0&&!ie(e.primaryMeasure,o)&&i.push(a("invalid_primary_measure","Metric intent primaryMeasure must match one measure field reference.","primaryMeasure"))),e.dimensions!==void 0&&!Array.isArray(e.dimensions)?i.push(a("invalid_measure_dimensions","Metric intent dimensions must be an array of field references.","dimensions")):Array.isArray(e.dimensions)&&e.dimensions.some(s=>!u(s)||!l(s.name))&&i.push(a("invalid_measure_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&&(A(e.timeWindow,"timeWindow",i),e.dateField||i.push(a("missing_time_window_date_field","Metric timeWindow needs a dateField.","dateField"))),x(e.filters,"filters",i),Array.isArray(e.dimensions)&&e.dimensions.forEach((s,r)=>{f(s,`dimensions.${r}`,i)}),e.orderBy!==void 0){if(!u(e.orderBy))i.push(a("invalid_measure_order_by","Metric intent orderBy must be a structured object.","orderBy"));else if(f(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(a("invalid_measure_order_direction","Metric intent orderBy direction must be asc or desc.","orderBy.direction")),u(e.orderBy.field)&&l(e.orderBy.field.name)){const s=[...o,...e.timeGrain&&e.dateField&&u(e.dateField)?[e.dateField]:[],...Array.isArray(e.dimensions)?e.dimensions.filter(r=>u(r)&&l(r.name)):[]];s.length>0&&!te(e.orderBy.field,s)&&i.push(a("invalid_measure_order_by","Metric intent orderBy.field must match one selected measure, grouped dateField, or dimension.","orderBy.field"))}}Oe(e,i)}else e.kind==="records"?(!Array.isArray(e.fields)||e.fields.length===0?i.push(a("missing_record_fields","Records intent needs at least one field.","fields")):e.fields.some(o=>!u(o)||!l(o.name))&&i.push(a("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),O(e.pagination,"pagination",i),e.timeWindow!==void 0&&(A(e.timeWindow,"timeWindow",i),e.dateField||i.push(a("missing_time_window_date_field","Records timeWindow needs a dateField.","dateField"))),x(e.filters,"filters",i),Array.isArray(e.filters)&&e.filters.forEach((o,s)=>{u(o)&&o.scope==="aggregate"&&i.push(a("unsupported_record_filter_scope","Records intents support row-scope filters only. Use a metric intent for aggregate-scope filters.",`filters.${s}.scope`))}),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(a("invalid_record_order_direction","Records intent orderBy direction must be asc or desc.","orderBy.direction"))):i.push(a("invalid_record_order_by","Records intent orderBy must be a structured object.","orderBy")))):e.kind==="inputOptions"?fe(e,i):e.kind==="matrix"?Ne(e,i):e.kind==="sql"?(((n=e.source)==null?void 0:n.kind)!=="sql"&&i.push(a("invalid_sql_source","SQL analytics intent must use a SQL execution source.","source")),l(e.sql)||i.push(a("missing_sql","SQL analytics intent needs SQL text.","sql")),ee(e.defaultParameters,"defaultParameters",i),Array.isArray(e.fields)&&e.fields.forEach((o,s)=>{f(o,`fields.${s}`,i)}),O(e.pagination,"pagination",i)):i.push(a("invalid_analytics_kind","Analytics kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:t,repairHints:He(i)}}function Be(e,i){if(!(!("derivedFields"in e)||e.derivedFields===void 0)){if(!Array.isArray(e.derivedFields)){i.push(a("invalid_derived_fields","Analytics intent derivedFields must be an array of derived field definitions.","derivedFields"));return}e.derivedFields.forEach((t,n)=>{Y(t).errors.forEach(s=>{i.push({...s,path:s.path?`derivedFields.${n}.${s.path}`:`derivedFields.${n}`})})})}}function K(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_operation_intent","Operation intent must be a structured object.")],warnings:t,repairHints:[{code:"invalid_operation_intent",recommendedNextStep:"Send one typed operation intent with version, kind, and required operation fields."}]};if(e.version!==1&&i.push(a("invalid_version","Operation intent version must be 1.","version")),e.kind==="answer_obligations")!Array.isArray(e.obligations)||e.obligations.length===0?i.push(a("missing_obligations","Answer-obligations operation intent needs at least one obligation.","obligations")):e.obligations.forEach((n,o)=>{l(n.id)||i.push(a("missing_obligation_id","Each analytics obligation needs an id.",`obligations.${o}.id`)),l(n.prompt)||i.push(a("missing_obligation_prompt","Each analytics obligation needs a prompt.",`obligations.${o}.prompt`))});else if(e.kind==="dashboard_change"||e.kind==="data_app_change"){if(l(e.instruction)||i.push(a("missing_instruction","Change operation intent needs an instruction.","instruction")),e.analyticsIntent){const n=F(e.analyticsIntent);i.push(...n.errors),t.push(...n.warnings)}}else i.push(a("invalid_operation_kind","Operation intent kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:t,repairHints:X(i)}}function qe(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_recovery_plan","Analytics recovery plan must be a structured object.")],warnings:t,repairHints:[{code:"invalid_recovery_plan",recommendedNextStep:"Return a typed recovery plan with operationIntent and plannedToolCalls."}]};e.version!==1&&i.push(a("invalid_version","Recovery plan version must be 1.","version")),e.kind!=="analytics_recovery_plan"&&i.push(a("invalid_recovery_plan_kind","Recovery plan kind must be analytics_recovery_plan.","kind"));const n=K(e.operationIntent);return i.push(...n.errors),t.push(...n.warnings),Array.isArray(e.plannedToolCalls)||i.push(a("invalid_planned_tool_calls","Recovery plan plannedToolCalls must be an array.","plannedToolCalls")),{ok:i.length===0,errors:i,warnings:t,repairHints:X(i)}}function X(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 He(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_measure":return{code:i.code,fieldRole:"measure",recommendedNextStep:"Choose one exact measure 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_matrix_rows":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Choose at least one row axis level for the matrix table."};case"missing_matrix_values":return{code:i.code,fieldRole:"measure",recommendedNextStep:"Choose at least one value field for the matrix table."};case"unsupported_matrix_sql_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use a semantic or explorer-backed source for matrix tables; raw SQL matrix tables are not supported."};case"missing_input_options_input_id":return{code:i.code,fieldRole:"input",recommendedNextStep:"Provide the inputId that these option values populate."};case"missing_input_options_label_field":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide the human-readable field used as option labels."};case"missing_input_options_value_field":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide the stable field used as option values."};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 Ce(e,i,t,n){if(!e||typeof e!="object"){t.push(a("invalid_view","Dashboard view must be an object.",i));return}if(l(e.title)||t.push(a("missing_view_title","Dashboard view needs a title.",i)),!e.presentation||typeof e.presentation!="object"){t.push(a("missing_presentation","Dashboard view needs a presentation.",`${i}.presentation`));return}if(e.presentation.kind==="text"){l(e.text)||n.push(a("missing_text_content","Text views should include text content.",`${i}.text`));return}if(!e.analytics){t.push(a("missing_view_analytics","Non-text dashboard views need analytics intent.",`${i}.analytics`));return}e.presentation.kind==="matrixTable"&&e.analytics.kind!=="matrix"&&t.push(a("invalid_matrix_view_analytics","Matrix table views need matrix analytics intent.",`${i}.analytics.kind`));const o=F(e.analytics);for(const s of o.errors)t.push(a(s.code,s.message,`${i}.analytics${s.path?`.${s.path}`:""}`));for(const s of o.warnings)n.push(a(s.code,s.message,`${i}.analytics${s.path?`.${s.path}`:""}`))}function Le(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_dashboard_intent","Dashboard intent must be a structured object.")],warnings:t};e.version!==1&&i.push(a("invalid_version","Dashboard intent version must be 1.")),e.kind!=="dashboard"&&i.push(a("invalid_kind","Experience intent kind must be dashboard.")),l(e.title)||i.push(a("missing_title","Dashboard intent needs a title.","title"));const n=Array.isArray(e.inputs)?e.inputs:[],o=I(n.filter(u).map(d=>d.id).filter(d=>typeof d=="string"));o&&i.push(a("duplicate_input_id",`Duplicate input id: ${o}.`,"inputs"));for(const[d,p]of n.entries()){const m=`inputs.${d}`;if(!u(p)){i.push(a("invalid_input","Dashboard input must be an object.",m));continue}l(p.id)||i.push(a("missing_input_id","Input needs an id.",`${m}.id`)),l(p.label)||i.push(a("missing_input_label","Input needs a label.",`${m}.label`)),!p.field||!l(p.field.name)?i.push(a("missing_input_field","Input needs a field.",`${m}.field`)):f(p.field,`${m}.field`,i)}const s=Array.isArray(e.sections)?e.sections:[];s.length===0&&i.push(a("missing_sections","Dashboard intent needs at least one section.","sections"));const r=s.flatMap(d=>d&&typeof d=="object"&&Array.isArray(d.views)?d.views.filter(u).map(p=>p.id).filter(p=>!!p):[]),c=I(r);c&&i.push(a("duplicate_view_id",`Duplicate dashboard view id: ${c}.`,"sections"));for(const[d,p]of s.entries()){const m=`sections.${d}`;if(!p||typeof p!="object"){i.push(a("invalid_section","Dashboard section must be an object.",m));continue}if(l(p.title)||i.push(a("missing_section_title","Dashboard section needs a title.",m)),!Array.isArray(p.views)||p.views.length===0){i.push(a("missing_section_views","Dashboard section needs at least one view.",`${m}.views`));continue}for(const[b,y]of p.views.entries())Ce(y,`${m}.views.${b}`,i,t)}return{ok:i.length===0,errors:i,warnings:t}}exports.parseSemaphorIsoTimeWindowBoundary=$;exports.validateSemaphorAnalyticsIntent=F;exports.validateSemaphorAnalyticsRecoveryPlan=qe;exports.validateSemaphorDashboardIntent=Le;exports.validateSemaphorDerivedFieldDefinition=Y;exports.validateSemaphorOperationIntent=K;exports.validateSemaphorResultCalculation=je;
@@ -1,9 +1,9 @@
1
- "use strict";const s=require("react");class c extends Error{}c.prototype.name="InvalidTokenError";function w(t){return decodeURIComponent(atob(t).replace(/(.)/g,(e,r)=>{let o=r.charCodeAt(0).toString(16).toUpperCase();return o.length<2&&(o="0"+o),"%"+o}))}function g(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return w(e)}catch{return atob(e)}}function m(t,e){if(typeof t!="string")throw new c("Invalid token specified: must be a string");e||(e={});const r=e.header===!0?0:1,o=t.split(".")[r];if(typeof o!="string")throw new c(`Invalid token specified: missing part #${r+1}`);let a;try{a=g(o)}catch(n){throw new c(`Invalid token specified: invalid base64 for part #${r+1} (${n.message})`)}try{return JSON.parse(a)}catch(n){throw new c(`Invalid token specified: invalid json for part #${r+1} (${n.message})`)}}/**
1
+ "use strict";const s=require("react");class c extends Error{}c.prototype.name="InvalidTokenError";function f(t){return decodeURIComponent(atob(t).replace(/(.)/g,(e,r)=>{let o=r.charCodeAt(0).toString(16).toUpperCase();return o.length<2&&(o="0"+o),"%"+o}))}function g(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return f(e)}catch{return atob(e)}}function m(t,e){if(typeof t!="string")throw new c("Invalid token specified: must be a string");e||(e={});const r=e.header===!0?0:1,o=t.split(".")[r];if(typeof o!="string")throw new c(`Invalid token specified: missing part #${r+1}`);let a;try{a=g(o)}catch(n){throw new c(`Invalid token specified: invalid base64 for part #${r+1} (${n.message})`)}try{return JSON.parse(a)}catch(n){throw new c(`Invalid token specified: invalid json for part #${r+1} (${n.message})`)}}/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const b=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),i=(...t)=>t.filter((e,r,o)=>!!e&&o.indexOf(e)===r).join(" ");/**
6
+ */const b=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),d=(...t)=>t.filter((e,r,o)=>!!e&&o.indexOf(e)===r).join(" ");/**
7
7
  * @license lucide-react v0.453.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
@@ -13,14 +13,19 @@
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const v=s.forwardRef(({color:t="currentColor",size:e=24,strokeWidth:r=2,absoluteStrokeWidth:o,className:a="",children:n,iconNode:l,...u},p)=>s.createElement("svg",{ref:p,...k,width:e,height:e,stroke:t,strokeWidth:o?Number(r)*24/Number(e):r,className:i("lucide",a),...u},[...l.map(([f,h])=>s.createElement(f,h)),...Array.isArray(n)?n:[n]]));/**
16
+ */const v=s.forwardRef(({color:t="currentColor",size:e=24,strokeWidth:r=2,absoluteStrokeWidth:o,className:a="",children:n,iconNode:l,...u},p)=>s.createElement("svg",{ref:p,...k,width:e,height:e,stroke:t,strokeWidth:o?Number(r)*24/Number(e):r,className:d("lucide",a),...u},[...l.map(([h,w])=>s.createElement(h,w)),...Array.isArray(n)?n:[n]]));/**
17
17
  * @license lucide-react v0.453.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const d=(t,e)=>{const r=s.forwardRef(({className:o,...a},n)=>s.createElement(v,{ref:n,iconNode:e,className:i(`lucide-${b(t)}`,o),...a}));return r.displayName=`${t}`,r};/**
21
+ */const i=(t,e)=>{const r=s.forwardRef(({className:o,...a},n)=>s.createElement(v,{ref:n,iconNode:e,className:d(`lucide-${b(t)}`,o),...a}));return r.displayName=`${t}`,r};/**
22
22
  * @license lucide-react v0.453.0 - ISC
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const y=d("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);exports.X=y;exports.createLucideIcon=d;exports.jwtDecode=m;
26
+ */const y=i("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
27
+ * @license lucide-react v0.453.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const C=i("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);exports.ChevronDown=y;exports.X=C;exports.createLucideIcon=i;exports.jwtDecode=m;
@@ -8,7 +8,7 @@ function g(t) {
8
8
  return o.length < 2 && (o = "0" + o), "%" + o;
9
9
  }));
10
10
  }
11
- function w(t) {
11
+ function m(t) {
12
12
  let e = t.replace(/-/g, "+").replace(/_/g, "/");
13
13
  switch (e.length % 4) {
14
14
  case 0:
@@ -37,7 +37,7 @@ function C(t, e) {
37
37
  throw new s(`Invalid token specified: missing part #${r + 1}`);
38
38
  let a;
39
39
  try {
40
- a = w(o);
40
+ a = m(o);
41
41
  } catch (n) {
42
42
  throw new s(`Invalid token specified: invalid base64 for part #${r + 1} (${n.message})`);
43
43
  }
@@ -53,14 +53,14 @@ function C(t, e) {
53
53
  * This source code is licensed under the ISC license.
54
54
  * See the LICENSE file in the root directory of this source tree.
55
55
  */
56
- const m = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), d = (...t) => t.filter((e, r, o) => !!e && o.indexOf(e) === r).join(" ");
56
+ const b = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), d = (...t) => t.filter((e, r, o) => !!e && o.indexOf(e) === r).join(" ");
57
57
  /**
58
58
  * @license lucide-react v0.453.0 - ISC
59
59
  *
60
60
  * This source code is licensed under the ISC license.
61
61
  * See the LICENSE file in the root directory of this source tree.
62
62
  */
63
- var b = {
63
+ var k = {
64
64
  xmlns: "http://www.w3.org/2000/svg",
65
65
  width: 24,
66
66
  height: 24,
@@ -77,7 +77,7 @@ var b = {
77
77
  * This source code is licensed under the ISC license.
78
78
  * See the LICENSE file in the root directory of this source tree.
79
79
  */
80
- const k = i(
80
+ const v = i(
81
81
  ({
82
82
  color: t = "currentColor",
83
83
  size: e = 24,
@@ -85,22 +85,22 @@ const k = i(
85
85
  absoluteStrokeWidth: o,
86
86
  className: a = "",
87
87
  children: n,
88
- iconNode: l,
89
- ...p
90
- }, u) => c(
88
+ iconNode: p,
89
+ ...u
90
+ }, h) => c(
91
91
  "svg",
92
92
  {
93
- ref: u,
94
- ...b,
93
+ ref: h,
94
+ ...k,
95
95
  width: e,
96
96
  height: e,
97
97
  stroke: t,
98
98
  strokeWidth: o ? Number(r) * 24 / Number(e) : r,
99
99
  className: d("lucide", a),
100
- ...p
100
+ ...u
101
101
  },
102
102
  [
103
- ...l.map(([f, h]) => c(f, h)),
103
+ ...p.map(([f, w]) => c(f, w)),
104
104
  ...Array.isArray(n) ? n : [n]
105
105
  ]
106
106
  )
@@ -111,12 +111,12 @@ const k = i(
111
111
  * This source code is licensed under the ISC license.
112
112
  * See the LICENSE file in the root directory of this source tree.
113
113
  */
114
- const v = (t, e) => {
114
+ const l = (t, e) => {
115
115
  const r = i(
116
- ({ className: o, ...a }, n) => c(k, {
116
+ ({ className: o, ...a }, n) => c(v, {
117
117
  ref: n,
118
118
  iconNode: e,
119
- className: d(`lucide-${m(t)}`, o),
119
+ className: d(`lucide-${b(t)}`, o),
120
120
  ...a
121
121
  })
122
122
  );
@@ -128,12 +128,22 @@ const v = (t, e) => {
128
128
  * This source code is licensed under the ISC license.
129
129
  * See the LICENSE file in the root directory of this source tree.
130
130
  */
131
- const I = v("X", [
131
+ const I = l("ChevronDown", [
132
+ ["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]
133
+ ]);
134
+ /**
135
+ * @license lucide-react v0.453.0 - ISC
136
+ *
137
+ * This source code is licensed under the ISC license.
138
+ * See the LICENSE file in the root directory of this source tree.
139
+ */
140
+ const $ = l("X", [
132
141
  ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
133
142
  ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
134
143
  ]);
135
144
  export {
136
- I as X,
137
- v as c,
145
+ I as C,
146
+ $ as X,
147
+ l as c,
138
148
  C as j
139
149
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-4W_ElSBJ.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-DXCBPLDu.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-icb12JV1.js";
1
+ import { D as o } from "../chunks/index-CQmKDEbe.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 C=require("../chunks/contracts-CtB2VONT.js"),M=require("../chunks/source-identity-C-xaeE_I.js"),U=require("../chunks/validators-lWo8m0Q7.js");require("../chunks/analyze-result-contract-CtXfp3nv.js");const De=require("../chunks/catalog-field-grounding-Bnx-3tE0.js"),ve=require("../chunks/operators-DrTQsJXv.js");function _(e){return e&&typeof e=="object"?e:null}function D(e){return typeof e=="string"?e:null}function oe(e){var t,r,n;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((r=_(e))==null?void 0:r.kind)==="physical"||((n=_(e))==null?void 0:n.kind)==="sql")}function F(e){return oe(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function Ce(e){return M.semaphorSourceIdentityKey(e)}function K(e,t){return M.semaphorSourcesReferToSameDataset(e,t)}function se(e,t){return M.preferSemaphorSourceMetadata(e,t)}function N(e){const t=[];for(const r of e){const n=t.findIndex(o=>K(o,r));n===-1?t.push(r):t[n]=se(t[n],r)}return t}function ke(e){return N(e)[0]}function j(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!M.semaphorSourcesReferToSameDataset(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function G(e){return F(e)?e:void 0}function ae(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(r=>(r==null?void 0:r.kind)==="semantic"&&M.semaphorSourcesReferToSameDataset(e,r)&&!!r.connectionId)}function w(e,t){const r=G(e==null?void 0:e.source);return r?j(r,t):void 0}function de({explicitSource:e,field:t,defaultSource:r,fallbackSources:n}){const o=[r,...n||[]],a=G(e),i=a?j(a,ae(a,o)):void 0;if(i)return i;if(e!==void 0)return;const d=w(t,r),s=d?j(d,ae(d,o)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return G(r)}function xe(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const r=w(e),n=w(t);return!r||!n?!0:K(r,n)}function k(e){var t;return D((t=_(e))==null?void 0:t.kind)}function ce(e){var t,r;return k(e)!=="semantic"?null:((r=D((t=_(e))==null?void 0:t.domainId))==null?void 0:r.trim())||null}function Fe(e){var t;return k(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetName)}function Te(e){var t;return k(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetId)}function Re(e){var t;return k(e)!=="physical"?null:D((t=_(e))==null?void 0:t.connectionId)}function Ne(e){var t;return k(e)!=="physical"?null:D((t=_(e))==null?void 0:t.tableName)}function Me(e){var t;return k(e)!=="physical"?"":D((t=_(e))==null?void 0:t.databaseName)||""}function $e(e){var t;return k(e)!=="physical"?"":D((t=_(e))==null?void 0:t.schemaName)||""}function le(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function ue({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const r=e.map(ce),n=new Set(r.filter(Boolean));return r.some(o=>!o)||n.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function q(e,t){if(!t)return!1;if(t.kind==="semantic"){const r=Te(e);return ce(e)===t.domainId?r&&t.datasetId?r===t.datasetId:Fe(e)===t.datasetName:!1}return t.kind==="physical"?Re(e)===t.connectionId&&Ne(e)===t.tableName&&Me(e)===(t.databaseName||"")&&$e(e)===(t.schemaName||""):!1}function Be(e,t){return e.find(r=>q(r,t))}function p(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function O(e){const t=new Set;for(const r of e){if(t.has(r))return r;t.add(r)}return null}function fe({card:e,datasets:t,errors:r}){if(e.type==="text")return;const n=le(e);if(!n){if(t.length<=1)return;r.push(p("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(o=>q(o,n))||r.push(p("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function P(e){return e.map(t=>t==null?void 0:t.source).filter(t=>!!t)}function V(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function ie(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Oe(e){var r,n;if(!e)return[];const t=[e.source];return e.kind==="metric"?t.push(...P([...V(e.measures),e.primaryMeasure,e.dateField,...V(e.dimensions),...ie(e.filters).map(o=>o.field)])):e.kind==="records"?t.push(...P([...V(e.fields),e.dateField,(r=e.orderBy)==null?void 0:r.field,...ie(e.filters).map(o=>o.field)])):e.kind==="inputOptions"?(((n=e.population)==null?void 0:n.kind)==="related_population"&&t.push(e.population.baseSource),t.push(...P([e.labelField,e.valueField,e.searchField,...e.disambiguationFields||[]]))):e.kind==="sql"&&t.push(...P(e.fields||[])),t}function pe({card:e,datasets:t,errors:r}){if(e.type!=="text"){for(const n of Oe(e.analyticsIntent))if(n&&!t.some(o=>q(o,n))){r.push(p("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function he({card:e,errors:t}){if(e.type==="text"||!e.analyticsIntent)return;const r=U.validateSemaphorAnalyticsIntent(e.analyticsIntent);if(!r.ok)for(const n of r.errors)t.push(p(n.code,n.path?`${n.path}: ${n.message}`:n.message,e.id))}function me({datasets:e,errors:t,requireAtLeastOne:r}){const n=ue({datasets:e,requireAtLeastOne:r});if(!n.ok){if(n.issue==="invalid_dataset_count"){t.push(p("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(p("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function ge(e){var f,g;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard plan version must be 1.")),(f=r.title)!=null&&f.trim()||t.push(p("missing_title","Dashboard plan needs a title."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.sheets)?r.sheets:[];me({datasets:o,errors:t,requireAtLeastOne:!0}),a.length!==1&&t.push(p("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const i=a[0];i&&i.kind!=="dashboard"&&t.push(p("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(i==null?void 0:i.cards)||[];d.length>C.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS&&t.push(p("too_many_cards",`Generated dashboards can contain at most ${C.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`));const s=O(d.map(l=>l.id));s&&t.push(p("duplicate_card_id",`Duplicate generated card id: ${s}.`));const u=O(d.map(l=>l.frameId));u&&t.push(p("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const l of d)(g=l.title)!=null&&g.trim()||t.push(p("missing_card_title","Card title is required.",l.id)),l.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.id)),l.type!=="text"&&!l.analyticsIntent&&n.push(p("missing_analytics_intent","Non-text card has no analytics intent and may be skipped by the app layer.",l.id)),fe({card:l,datasets:o,errors:t}),he({card:l,errors:t}),pe({card:l,datasets:o,errors:t});const h=Array.isArray(r.filterInputs)?r.filterInputs:[],I=h.map(l=>l.id),S=O(I);S&&t.push(p("duplicate_input_id",`Duplicate dashboard input id: ${S}.`));const A=h.map(l=>l.variableName).filter(Boolean)||[],y=O(A);y&&t.push(p("duplicate_input_variable",`Duplicate dashboard input variable name: ${y}.`));const c=Array.isArray(r.calculatedFields)?r.calculatedFields:[];for(const l of c)l.scope==="domain"&&l.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:n}}function be(e){var i;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard change plan version must be 1.")),(i=r.dashboardId)!=null&&i.trim()||t.push(p("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.operations)?r.operations:[];me({datasets:o,errors:t,requireAtLeastOne:!1});for(const d of a){if(d.kind==="unsupported"){n.push(p("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(fe({card:d.card,datasets:o,errors:t}),he({card:d.card,errors:t}),pe({card:d.card,datasets:o,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(p("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:n}}const Pe={lg:48,md:36,sm:24,xs:12,xxs:6};function qe(e,t){let r=0,n=0,o=0;return e.map(a=>{const i=Math.min(a.w,t);r>0&&r+i>t&&(r=0,n+=o,o=0);const d={i:a.frameId,x:r,y:n,w:i,h:a.h,minW:Math.min(a.minW,t),minH:a.minH,static:!1};return r+=i,o=Math.max(o,a.h),d})}function ze(e){const t=[...e].sort((s,u)=>s.priority-u.priority),r=t.filter(s=>s.role==="kpi"),n=t.filter(s=>s.role==="chart"),o=t.filter(s=>s.role==="table"),a=t.filter(s=>s.role==="text"),i=a.slice(0,1),d=a.slice(i.length);return{kpis:r,introText:i,charts:n,tables:o,supportingText:d}}function Ee(e,t,r){return t==="xxs"||t==="xs"?r:t==="sm"?Math.min(12,r):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function Ve(e,t,r,n){return r==="xxs"||r==="xs"||r==="sm"||r==="md"||t===1||t%2===1&&e===0?n:n/2}function He(e){const{item:t,band:r,index:n,bandCount:o,breakpoint:a,columns:i}=e;return r==="kpi"?{...t,band:r,w:Ee(o,a,i),h:15,minW:Math.min(6,i),minH:12}:r==="table"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?34:38,minW:Math.min(12,i),minH:18}:r==="introText"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:r==="supportingText"?{...t,band:r,w:a==="lg"?i/2:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:{...t,band:r,w:Ve(n,o,a,i),h:a==="xxs"||a==="xs"?28:30,minW:Math.min(12,i),minH:16}}function T(e,t,r,n){return e.map((o,a)=>He({item:o,band:t,index:a,bandCount:e.length,breakpoint:r,columns:n}))}function z(e){const t=ze(e);return Object.fromEntries(C.DASHBOARD_AUTHORING_BREAKPOINTS.map(r=>{const n=Pe[r],o=[...T(t.introText,"introText",r,n),...T(t.kpis,"kpi",r,n),...T(t.charts,"chart",r,n),...T(t.tables,"table",r,n),...T(t.supportingText,"supportingText",r,n)];return[r,qe(o,n)]}))}function Le(e){const t=De.normalizeAnalyticsCatalogDataType(e);return t==="datetime"?"date":t==="unknown"?"string":t}function je(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Ge(e){return je(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function We(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function Ue(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function X(e,t){if(t===void 0)return;const r=Le(e.dataType),n=e.operation||"in";if(Ge(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:r,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(n==="is null"||n==="is not null")return{filterId:e.id,name:e.column,operation:n,valueType:r,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const o=Array.isArray(t)?t:[t],a=r==="date"?Ue(o):We(o);if(a.length!==0&&!((n==="between"||n==="not between")&&a.length<2))return{filterId:e.id,name:e.column,operation:n,valueType:r,values:a,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function Ie(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ke(e,t,r){const n=(t||[]).filter(o=>o.scope==="card"&&o.targetCardId===r).map(o=>o.field).filter(Boolean);return n.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...n]}}function W(e,t){return Array.from(new Set((e||[]).map(r=>t.get(r)).filter(r=>!!r)))}function Xe(e,t){if((e==null?void 0:e.kind)!=="cards")return e;const r=W(e.cardIds,t);return r.length>0?{...e,cardIds:r}:null}function Je(e,t){return!e.applyToCardIds&&!e.excludeCardIds?e:{...e,...e.applyToCardIds?{applyToCardIds:W(e.applyToCardIds,t)}:{},...e.excludeCardIds?{excludeCardIds:W(e.excludeCardIds,t)}:{}}}function Qe(e,t){const r={},n=[];return{inputs:(e.filterInputs||[]).flatMap((a,i)=>{const d=Xe(a.scope,t);if(d===null)return n.push(Ie("filter_input_scope_empty",`Filter input "${a.label}" was skipped because all scoped cards were skipped during query validation.`)),[];const s=X(a.filter,a.defaultValue);return s&&(r.shared??(r.shared={}),r.shared[a.id]={status:"set",value:{kind:"filter",filterValue:s}}),[{id:a.id,kind:"filter",label:a.label,variableName:a.variableName,scope:d||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:i},exports:["label","value","start","end","range"],filter:Je(a.filter,t)}]}),warnings:n,defaultInputValues:r.shared&&Object.keys(r.shared).length>0?r:void 0}}function Ye(e){var A,y;const t=ge(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 C=require("../chunks/contracts-CtB2VONT.js"),M=require("../chunks/source-identity-uMaUe036.js"),U=require("../chunks/validators-CPtkrola.js");require("../chunks/analyze-result-contract-Zgg-Bbpj.js");const De=require("../chunks/catalog-field-grounding-Bnx-3tE0.js"),ve=require("../chunks/operators-DrTQsJXv.js");function _(e){return e&&typeof e=="object"?e:null}function D(e){return typeof e=="string"?e:null}function oe(e){var t,r,n;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((r=_(e))==null?void 0:r.kind)==="physical"||((n=_(e))==null?void 0:n.kind)==="sql")}function F(e){return oe(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function Ce(e){return M.semaphorSourceIdentityKey(e)}function K(e,t){return M.semaphorSourcesReferToSameDataset(e,t)}function se(e,t){return M.preferSemaphorSourceMetadata(e,t)}function N(e){const t=[];for(const r of e){const n=t.findIndex(o=>K(o,r));n===-1?t.push(r):t[n]=se(t[n],r)}return t}function ke(e){return N(e)[0]}function j(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!M.semaphorSourcesReferToSameDataset(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function G(e){return F(e)?e:void 0}function ae(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(r=>(r==null?void 0:r.kind)==="semantic"&&M.semaphorSourcesReferToSameDataset(e,r)&&!!r.connectionId)}function w(e,t){const r=G(e==null?void 0:e.source);return r?j(r,t):void 0}function de({explicitSource:e,field:t,defaultSource:r,fallbackSources:n}){const o=[r,...n||[]],a=G(e),i=a?j(a,ae(a,o)):void 0;if(i)return i;if(e!==void 0)return;const d=w(t,r),s=d?j(d,ae(d,o)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return G(r)}function xe(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const r=w(e),n=w(t);return!r||!n?!0:K(r,n)}function k(e){var t;return D((t=_(e))==null?void 0:t.kind)}function ce(e){var t,r;return k(e)!=="semantic"?null:((r=D((t=_(e))==null?void 0:t.domainId))==null?void 0:r.trim())||null}function Fe(e){var t;return k(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetName)}function Te(e){var t;return k(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetId)}function Re(e){var t;return k(e)!=="physical"?null:D((t=_(e))==null?void 0:t.connectionId)}function Ne(e){var t;return k(e)!=="physical"?null:D((t=_(e))==null?void 0:t.tableName)}function Me(e){var t;return k(e)!=="physical"?"":D((t=_(e))==null?void 0:t.databaseName)||""}function $e(e){var t;return k(e)!=="physical"?"":D((t=_(e))==null?void 0:t.schemaName)||""}function le(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function ue({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const r=e.map(ce),n=new Set(r.filter(Boolean));return r.some(o=>!o)||n.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function q(e,t){if(!t)return!1;if(t.kind==="semantic"){const r=Te(e);return ce(e)===t.domainId?r&&t.datasetId?r===t.datasetId:Fe(e)===t.datasetName:!1}return t.kind==="physical"?Re(e)===t.connectionId&&Ne(e)===t.tableName&&Me(e)===(t.databaseName||"")&&$e(e)===(t.schemaName||""):!1}function Be(e,t){return e.find(r=>q(r,t))}function p(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function O(e){const t=new Set;for(const r of e){if(t.has(r))return r;t.add(r)}return null}function fe({card:e,datasets:t,errors:r}){if(e.type==="text")return;const n=le(e);if(!n){if(t.length<=1)return;r.push(p("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(o=>q(o,n))||r.push(p("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function P(e){return e.map(t=>t==null?void 0:t.source).filter(t=>!!t)}function V(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function ie(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Oe(e){var r,n;if(!e)return[];const t=[e.source];return e.kind==="metric"?t.push(...P([...V(e.measures),e.primaryMeasure,e.dateField,...V(e.dimensions),...ie(e.filters).map(o=>o.field)])):e.kind==="records"?t.push(...P([...V(e.fields),e.dateField,(r=e.orderBy)==null?void 0:r.field,...ie(e.filters).map(o=>o.field)])):e.kind==="inputOptions"?(((n=e.population)==null?void 0:n.kind)==="related_population"&&t.push(e.population.baseSource),t.push(...P([e.labelField,e.valueField,e.searchField,...e.disambiguationFields||[]]))):e.kind==="sql"&&t.push(...P(e.fields||[])),t}function pe({card:e,datasets:t,errors:r}){if(e.type!=="text"){for(const n of Oe(e.analyticsIntent))if(n&&!t.some(o=>q(o,n))){r.push(p("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function he({card:e,errors:t}){if(e.type==="text"||!e.analyticsIntent)return;const r=U.validateSemaphorAnalyticsIntent(e.analyticsIntent);if(!r.ok)for(const n of r.errors)t.push(p(n.code,n.path?`${n.path}: ${n.message}`:n.message,e.id))}function me({datasets:e,errors:t,requireAtLeastOne:r}){const n=ue({datasets:e,requireAtLeastOne:r});if(!n.ok){if(n.issue==="invalid_dataset_count"){t.push(p("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(p("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function ge(e){var f,g;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard plan version must be 1.")),(f=r.title)!=null&&f.trim()||t.push(p("missing_title","Dashboard plan needs a title."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.sheets)?r.sheets:[];me({datasets:o,errors:t,requireAtLeastOne:!0}),a.length!==1&&t.push(p("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const i=a[0];i&&i.kind!=="dashboard"&&t.push(p("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(i==null?void 0:i.cards)||[];d.length>C.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS&&t.push(p("too_many_cards",`Generated dashboards can contain at most ${C.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`));const s=O(d.map(l=>l.id));s&&t.push(p("duplicate_card_id",`Duplicate generated card id: ${s}.`));const u=O(d.map(l=>l.frameId));u&&t.push(p("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const l of d)(g=l.title)!=null&&g.trim()||t.push(p("missing_card_title","Card title is required.",l.id)),l.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.id)),l.type!=="text"&&!l.analyticsIntent&&n.push(p("missing_analytics_intent","Non-text card has no analytics intent and may be skipped by the app layer.",l.id)),fe({card:l,datasets:o,errors:t}),he({card:l,errors:t}),pe({card:l,datasets:o,errors:t});const h=Array.isArray(r.filterInputs)?r.filterInputs:[],I=h.map(l=>l.id),S=O(I);S&&t.push(p("duplicate_input_id",`Duplicate dashboard input id: ${S}.`));const A=h.map(l=>l.variableName).filter(Boolean)||[],y=O(A);y&&t.push(p("duplicate_input_variable",`Duplicate dashboard input variable name: ${y}.`));const c=Array.isArray(r.calculatedFields)?r.calculatedFields:[];for(const l of c)l.scope==="domain"&&l.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:n}}function be(e){var i;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard change plan version must be 1.")),(i=r.dashboardId)!=null&&i.trim()||t.push(p("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.operations)?r.operations:[];me({datasets:o,errors:t,requireAtLeastOne:!1});for(const d of a){if(d.kind==="unsupported"){n.push(p("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(fe({card:d.card,datasets:o,errors:t}),he({card:d.card,errors:t}),pe({card:d.card,datasets:o,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(p("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:n}}const Pe={lg:48,md:36,sm:24,xs:12,xxs:6};function qe(e,t){let r=0,n=0,o=0;return e.map(a=>{const i=Math.min(a.w,t);r>0&&r+i>t&&(r=0,n+=o,o=0);const d={i:a.frameId,x:r,y:n,w:i,h:a.h,minW:Math.min(a.minW,t),minH:a.minH,static:!1};return r+=i,o=Math.max(o,a.h),d})}function ze(e){const t=[...e].sort((s,u)=>s.priority-u.priority),r=t.filter(s=>s.role==="kpi"),n=t.filter(s=>s.role==="chart"),o=t.filter(s=>s.role==="table"),a=t.filter(s=>s.role==="text"),i=a.slice(0,1),d=a.slice(i.length);return{kpis:r,introText:i,charts:n,tables:o,supportingText:d}}function Ee(e,t,r){return t==="xxs"||t==="xs"?r:t==="sm"?Math.min(12,r):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function Ve(e,t,r,n){return r==="xxs"||r==="xs"||r==="sm"||r==="md"||t===1||t%2===1&&e===0?n:n/2}function He(e){const{item:t,band:r,index:n,bandCount:o,breakpoint:a,columns:i}=e;return r==="kpi"?{...t,band:r,w:Ee(o,a,i),h:15,minW:Math.min(6,i),minH:12}:r==="table"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?34:38,minW:Math.min(12,i),minH:18}:r==="introText"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:r==="supportingText"?{...t,band:r,w:a==="lg"?i/2:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:{...t,band:r,w:Ve(n,o,a,i),h:a==="xxs"||a==="xs"?28:30,minW:Math.min(12,i),minH:16}}function T(e,t,r,n){return e.map((o,a)=>He({item:o,band:t,index:a,bandCount:e.length,breakpoint:r,columns:n}))}function z(e){const t=ze(e);return Object.fromEntries(C.DASHBOARD_AUTHORING_BREAKPOINTS.map(r=>{const n=Pe[r],o=[...T(t.introText,"introText",r,n),...T(t.kpis,"kpi",r,n),...T(t.charts,"chart",r,n),...T(t.tables,"table",r,n),...T(t.supportingText,"supportingText",r,n)];return[r,qe(o,n)]}))}function Le(e){const t=De.normalizeAnalyticsCatalogDataType(e);return t==="datetime"?"date":t==="unknown"?"string":t}function je(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Ge(e){return je(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function We(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function Ue(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function X(e,t){if(t===void 0)return;const r=Le(e.dataType),n=e.operation||"in";if(Ge(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:r,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(n==="is null"||n==="is not null")return{filterId:e.id,name:e.column,operation:n,valueType:r,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const o=Array.isArray(t)?t:[t],a=r==="date"?Ue(o):We(o);if(a.length!==0&&!((n==="between"||n==="not between")&&a.length<2))return{filterId:e.id,name:e.column,operation:n,valueType:r,values:a,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function Ie(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ke(e,t,r){const n=(t||[]).filter(o=>o.scope==="card"&&o.targetCardId===r).map(o=>o.field).filter(Boolean);return n.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...n]}}function W(e,t){return Array.from(new Set((e||[]).map(r=>t.get(r)).filter(r=>!!r)))}function Xe(e,t){if((e==null?void 0:e.kind)!=="cards")return e;const r=W(e.cardIds,t);return r.length>0?{...e,cardIds:r}:null}function Je(e,t){return!e.applyToCardIds&&!e.excludeCardIds?e:{...e,...e.applyToCardIds?{applyToCardIds:W(e.applyToCardIds,t)}:{},...e.excludeCardIds?{excludeCardIds:W(e.excludeCardIds,t)}:{}}}function Qe(e,t){const r={},n=[];return{inputs:(e.filterInputs||[]).flatMap((a,i)=>{const d=Xe(a.scope,t);if(d===null)return n.push(Ie("filter_input_scope_empty",`Filter input "${a.label}" was skipped because all scoped cards were skipped during query validation.`)),[];const s=X(a.filter,a.defaultValue);return s&&(r.shared??(r.shared={}),r.shared[a.id]={status:"set",value:{kind:"filter",filterValue:s}}),[{id:a.id,kind:"filter",label:a.label,variableName:a.variableName,scope:d||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:i},exports:["label","value","start","end","range"],filter:Je(a.filter,t)}]}),warnings:n,defaultInputValues:r.shared&&Object.keys(r.shared).length>0?r:void 0}}function Ye(e){var A,y;const t=ge(e.plan);if(!t.ok)throw new Error(t.errors.map(c=>c.message).join(`
2
2
  `)||"Dashboard plan is invalid.");const r=e.plan.sheets[0],n=[...t.warnings],o=[],a=new Map(e.cardArtifacts.map(c=>[c.planCardId,c])),i=new Map(e.cardArtifacts.map(c=>[c.planCardId,c.card.id])),d=[];for(const c of r.cards){const f=a.get(c.id);if(!f){const l=Ie("missing_card_artifact",`Card "${c.title}" was skipped because no generated artifact was supplied.`,c.id);o.push(l);continue}n.push(...f.warnings||[]);const g=Ke(f.card,e.plan.calculatedFields,c.id);d.push({id:c.frameId,cards:[g],activeCardId:g.id})}if(d.length===0)throw new Error("Dashboard plan did not produce any persistable cards.");const{inputs:s,defaultInputValues:u,warnings:h}=Qe(e.plan,i);n.push(...h);const I=z(r.cards.filter(c=>d.some(f=>f.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:r.id,kind:"dashboard",title:r.title,description:r.description,frames:d,layouts:I,calculatedFields:(A=e.plan.calculatedFields)==null?void 0:A.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:s,...u?{defaultInputValues:u}:{}},warnings:n,skippedOperations:o}}function x(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ze(e){return JSON.parse(JSON.stringify(e))}function et(e){var t;return(t=e.sheets)==null?void 0:t.find(r=>(r.kind||"dashboard")==="dashboard")}function H(e,t){var r;for(const n of e.sheets||[])for(const o of n.frames||[]){const a=(r=o.cards)==null?void 0:r.find(i=>i.id===t);if(a)return{sheet:n,frame:o,card:a}}return null}function ye(e){var r,n;const t=(n=(r=e.cards)==null?void 0:r[0])==null?void 0:n.type;return t==="kpi"?"kpi":t==="table"||t==="detailTable"||t==="pivotTable"?"table":t==="text"?"text":"chart"}function tt(e){var t;return new Map((((t=e.layouts)==null?void 0:t.lg)||[]).map((r,n)=>[r.i,n]))}function _e(e,t=new Map){const r=tt(e),n=Math.max(r.size,t.size),o=(e.frames||[]).map((a,i)=>({frameId:a.id,role:ye(a),priority:t.get(a.id)??r.get(a.id)??n+i}));e.layouts=z(o)}function rt(e){return Object.values(e.layouts||{}).some(t=>t.length>0)}function nt(e,t){if(!rt(e)){_e(e);return}const r=z([{frameId:t.id,role:ye(t),priority:0}]);e.layouts??(e.layouts={});for(const[n,o]of Object.entries(r)){const a=e.layouts[n]||[];if(a.some(s=>s.i===t.id))continue;const i=o[0];if(!i)continue;const d=a.reduce((s,u)=>Math.max(s,u.y+u.h),0);e.layouts[n]=[...a,{...i,y:d}]}}function at(e,t){var n;const r=X(t.filter,t.defaultValue);r&&(e.defaultInputValues??(e.defaultInputValues={}),(n=e.defaultInputValues).shared??(n.shared={}),e.defaultInputValues.shared[t.id]={status:"set",value:{kind:"filter",filterValue:r}})}function it(e){var d;const t=be(e.changePlan);if(!t.ok)throw new Error(t.errors.map(s=>s.message).join(`
3
3
  `)||"Dashboard change plan is invalid.");const r=Ze(e.dashboard),n=[...t.warnings],o=[],a=new Map(e.cardArtifacts.map(s=>[s.planCardId,s])),i=et(r);if(!i)throw new Error("Dashboard has no editable dashboard sheet.");i.frames??(i.frames=[]);for(const s of e.changePlan.operations)switch(s.kind){case"addCard":{if((i.frames||[]).reduce((S,A)=>{var y;return S+(((y=A.cards)==null?void 0:y.length)||0)},0)>=C.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS){o.push(x("generated_card_limit_reached",`AI refinement is capped at ${C.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`,s.card.id));break}const h=a.get(s.card.id);if(!h){o.push(x("missing_card_artifact",`Card "${s.card.title}" was skipped because no generated artifact was supplied.`,s.card.id));break}const I={id:s.card.frameId,cards:[h.card],activeCardId:h.card.id};i.frames.push(I),nt(i,I);break}case"addFilterInput":{r.inputs??(r.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:r.inputs.length},exports:["label","value","start","end","range"],filter:s.input.filter};r.inputs.push(u),at(r,s.input);break}case"addCalculatedField":{if(s.field.scope==="dashboard"&&s.field.field)r.calculatedFields??(r.calculatedFields=[]),r.calculatedFields.push(s.field.field);else if(s.field.scope==="sheet"&&s.field.field)i.calculatedFields??(i.calculatedFields=[]),i.calculatedFields.push(s.field.field);else if(s.field.scope==="card"&&s.field.field){const u=s.field.targetCardId?H(r,s.field.targetCardId):null;u?((d=u.card).calculatedFields??(d.calculatedFields=[]),u.card.calculatedFields.push(s.field.field)):o.push(x("missing_calculated_field_target",`Calculated field "${s.field.name}" needs a valid target card.`))}break}case"renameCard":{const u=H(r,s.cardId);if(!u){o.push(x("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 I=s.cardIds[h],S=H(r,I);S&&u.set(S.frame.id,h)}_e(i,u);break}case"reuseCalculatedField":n.push(x("reused_calculated_field",`Calculated field "${s.fieldId}" is reused by reference.`));break;case"unsupported":o.push(x("unsupported_operation",s.reason||s.requestedAction));break}return{dashboard:r,warnings:n,skippedOperations:o}}function b(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function R(e,t){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||t}function Se(e,t){if(!t.has(e))return t.add(e),e;let r=2,n=`${e}-${r}`;for(;t.has(n);)r+=1,n=`${e}-${r}`;return t.add(n),n}function $(e){return!!(e&&typeof e=="object")}function Ae(e){return Array.isArray(e.inputs)?e.inputs.filter(t=>$(t)&&typeof t.id=="string"):[]}function J(e){return Array.isArray(e.sections)?e.sections.filter(t=>$(t)):[]}function Q(e){return Array.isArray(e.views)?e.views.filter(t=>$(t)):[]}function v(e){if(!Array.isArray(e))return[];const t=[];for(const r of e){const n=w(r);n&&t.push(n)}return t}function ot(e){var n,o,a;if(!e)return[];const t=[];if(F(e.source)&&t.push(e.source),e.kind==="metric"){t.push(...v(e.measures));const i=w(e.dateField);i&&t.push(i),t.push(...v(e.dimensions)),t.push(...v((n=e.filters)==null?void 0:n.map(d=>d.field)))}else if(e.kind==="records"){const i=w(e.dateField);i&&t.push(i),t.push(...v(e.fields)),t.push(...v((o=e.filters)==null?void 0:o.map(d=>d.field)))}else e.kind==="inputOptions"?(((a=e.population)==null?void 0:a.kind)==="related_population"&&F(e.population.baseSource)&&t.push(e.population.baseSource),t.push(...v([e.labelField,e.valueField,e.searchField,...e.disambiguationFields||[]].filter(i=>!!i)))):e.kind==="sql"&&t.push(...v(e.fields));const r="inputs"in e&&Array.isArray(e.inputs)?e.inputs:[];for(const i of r){const d=w(i.field);d&&t.push(d)}return t}function st(e){const t=[];for(const r of Ae(e)){const n=w(r.field);n&&t.push(n)}for(const r of J(e))for(const n of Q(r))t.push(...ot(n.analytics));return t}function dt(e){var r;const t=[];for(const n of J(e))for(const o of Q(n))F((r=o.analytics)==null?void 0:r.source)&&t.push(o.analytics.source);return t}function ct(e,t){const r=N(e).filter(F);if(r.length===0)return t.push(b("missing_materializable_dataset","No semantic or physical source could be converted into the current dashboard authoring dataset reference.")),[];const n=r.every(a=>a.kind==="semantic"),o=Array.from(new Set(r.filter(a=>a.kind==="semantic").map(a=>a.domainId)));return r.length>1&&(!n||o.length!==1)?(t.push(b("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.")),[r[0]]):r}function lt(e,t){const r=J(e),n=Ae(e),o=N(st(e)),a=N(dt(e));return{sections:r,inputs:n,sources:o,primarySources:a,defaultSource:a.length===1?a[0]:void 0,datasets:ct(o,t)}}function ut(e){return e&&U.validateSemaphorAnalyticsIntent(e).ok?e:void 0}function ft(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 pt(e){var t,r,n;return((t=e.presentation)==null?void 0:t.kind)==="kpi"?"kpi":((r=e.presentation)==null?void 0:r.kind)==="table"?"table":((n=e.presentation)==null?void 0:n.kind)==="text"?"text":"chart"}function ht(e){const t=ve.normalizeSemaphorInputOperator(e);switch(t){case"not_in":return"not in";case"not_between":return"not between";case"contains":return"like";case"not_contains":return"not like";default:return t||"in"}}function mt(e){return $(e.field)?e.field.dataType==="datetime"?"date":e.field.dataType||"string":"string"}function gt(e){if(!(!e||e.kind!=="physical"))return[e.databaseName,e.schemaName,e.tableName].filter(Boolean).join(".")}function bt(e,t,r,n,o,a){if(e.kind!=="filter")return a.push(b("control_inputs_deferred",`Control input "${e.label}" is represented in the protocol but not yet materialized by the dashboard authoring adapter.`)),null;if(!$(e.field)||typeof e.field.name!="string")return a.push(b("filter_requires_field",`Filter "${e.label||e.id}" needs a field before the dashboard compiler can materialize it.`)),null;const i=de({explicitSource:void 0,field:e.field,defaultSource:t,fallbackSources:r}),d=(i==null?void 0:i.kind)==="semantic"||(i==null?void 0:i.kind)==="physical"?i.connectionId:void 0;if(!d)return a.push(b("filter_requires_connection_id",`Filter "${e.label}" needs a source connectionId before the dashboard compiler can materialize it.`)),null;const h={id:`filter-${Se(R(e.id,e.field.name),o)}`,variableName:e.id,connectionId:d,title:e.label,column:e.field.name,dataType:mt(e),qualifiedTableName:gt(i),sql:"",operation:ht(e.operator),type:e.multi===!1?"single":"multiple",location:"dashboard",displayMode:"toolbar",fieldMeta:(i==null?void 0:i.kind)==="semantic"?{name:e.field.name,qualifiedFieldName:e.field.name,dataType:e.field.dataType,role:e.field.role==="measure"?"metric":"groupby"}:void 0,semanticContext:(i==null?void 0:i.kind)==="semantic"?{semanticDomainId:i.domainId,connectionId:i.connectionId}:void 0};return{id:e.id,label:e.label,variableName:e.id,scope:n,filter:h,defaultValue:X(h,e.defaultValue)}}function L(e){const t=[],r=[];for(const n of e.viewIds){const o=e.viewIdToCardId.get(n);o?t.push(o):r.push(n)}return r.length>0&&e.warnings.push(b("input_scope_view_not_found",`Filter "${e.inputLabel}" referenced unknown view ids: ${r.join(", ")}.`)),Array.from(new Set(t))}function It(e){var n,o;if(!e.protocolScope){const a=Array.from(new Set(e.boundCardIds));return a.length>0&&a.length<e.allCardIds.length?{kind:"cards",cardIds:a}:void 0}if(e.protocolScope.level==="dashboard"){if(!((n=e.protocolScope.excludeViewIds)!=null&&n.length))return;const a=new Set(L({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:e.allCardIds.filter(i=>!a.has(i))}}if(e.protocolScope.level==="view"){const a=L({inputLabel:e.inputLabel,viewIds:e.protocolScope.viewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings});return a.length===0?(e.warnings.push(b("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:a}}const t=e.sectionIdToCardIds.get(e.protocolScope.sectionId)||[];if(t.length===0)return e.warnings.push(b("input_scope_section_not_found",`Filter "${e.inputLabel}" was deferred because section "${e.protocolScope.sectionId}" does not match any materialized cards.`)),null;if(!((o=e.protocolScope.excludeViewIds)!=null&&o.length))return{kind:"cards",cardIds:t};const r=new Set(L({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:t.filter(a=>!r.has(a))}}function yt(e){var A,y,c;const t=[],r=U.validateSemaphorDashboardIntent(e);for(const f of r.warnings)t.push(b(f.code,f.message));for(const f of r.errors)t.push(b(f.code,f.message));const n=lt(e,t),o=[],a=new Map,i=new Map,d=new Map,s=new Set,u=new Set;let h=0;for(const[f,g]of n.sections.entries()){const l=typeof g.title=="string"?g.title:`Section ${f+1}`,Y=g.id||R(l,`section-${f+1}`);i.set(Y,[]);for(const[Z,m]of Q(g).entries()){const ee=ft(m),E=R(m.id||`${l}-${m.title||`View ${Z+1}`}`,`card-${f+1}-${Z+1}`);if(!ee){t.push(b("unsupported_presentation",`Dashboard presentation "${((A=m.presentation)==null?void 0:A.kind)||"unknown"}" is not supported by the dashboard authoring adapter.`,`card-${E}`));continue}if(((y=m.analytics)==null?void 0:y.kind)==="sql"){t.push(b("sql_intent_deferred","SQL analytics intent is valid protocol, but the current dashboard authoring adapter only materializes semantic and physical config-card intents.",`card-${E}`));continue}const te=Se(E,s),B=`card-${te}`;m.id&&a.set(m.id,B),(c=i.get(Y))==null||c.push(B);const we=m.analytics&&"inputs"in m.analytics?m.analytics.inputs:void 0;for(const re of we||[]){const ne=d.get(re.inputId)||[];ne.push(B),d.set(re.inputId,ne)}o.push({id:B,frameId:`frame-${te}`,title:m.title,description:m.description,type:ee,role:pt(m),priority:h,section:l,analyticsIntent:ut(m.analytics),text:m.text}),h+=1}}const I=n.inputs.map(f=>{const g=It({protocolScope:f.scope,inputLabel:f.label,allCardIds:o.map(l=>l.id),boundCardIds:d.get(f.id)||[],viewIdToCardId:a,sectionIdToCardIds:i,warnings:t});return g===null?null:bt(f,n.defaultSource,n.sources,g,u,t)}).filter(f=>!!f);return{plan:{version:1,id:`plan-${R(e.title,"dashboard")}`,title:e.title,description:e.description,datasets:n.datasets,sheets:[{id:`sheet-${R(e.title,"dashboard")}`,title:e.title,description:e.description,kind:"dashboard",cards:o}],filterInputs:I.length?I:void 0,warnings:t.length?t:void 0,unresolvedRequests:r.ok?void 0:r.errors.map(f=>f.message)},warnings:t}}exports.DASHBOARD_AUTHORING_BREAKPOINTS=C.DASHBOARD_AUTHORING_BREAKPOINTS;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=C.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS;exports.applyDashboardChangePlan=it;exports.compileDashboardFromPlan=Ye;exports.compileResponsiveDashboardLayouts=z;exports.dashboardAuthoringDatasetMatchesSource=q;exports.dashboardAuthoringFieldsReferToSameTarget=xe;exports.dashboardAuthoringSourceFromField=w;exports.dashboardAuthoringSourceKey=Ce;exports.dashboardAuthoringSourcesReferToSameDataset=K;exports.dashboardPlanFromSemaphorDashboardIntent=yt;exports.findDashboardAuthoringDatasetForSource=Be;exports.getDashboardAuthoringCardSource=le;exports.isMaterializableDashboardAuthoringSource=F;exports.isSemaphorSourceRef=oe;exports.mergeDashboardAuthoringSources=N;exports.preferDashboardAuthoringSourceMetadata=se;exports.preferredDashboardAuthoringSource=ke;exports.resolveDashboardAuthoringSource=de;exports.validateDashboardAuthoringDatasetScope=ue;exports.validateDashboardChangePlan=be;exports.validateDashboardPlan=ge;
@@ -1,7 +1,7 @@
1
1
  import { D as P, a as be } from "../chunks/contracts-CoCOpd_i.js";
2
- import { a as Ie, b as E, c as ye } from "../chunks/source-identity-CN4xiyKJ.js";
3
- import { b as ae, e as _e } from "../chunks/validators-CHPH6ORs.js";
4
- import "../chunks/analyze-result-contract-DuhlklhI.js";
2
+ import { a as Ie, b as E, c as ye } from "../chunks/source-identity-y0VSSreA.js";
3
+ import { b as ae, e as _e } from "../chunks/validators-4EGCWWga.js";
4
+ import "../chunks/analyze-result-contract-C9Gv2_qW.js";
5
5
  import { b as we } from "../chunks/catalog-field-grounding-CJKAqtiC.js";
6
6
  import { n as ve } from "../chunks/operators-C8TxpM4C.js";
7
7
  function _(e) {