react-semaphor 0.1.448 → 0.1.453

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 (134) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +115 -109
  3. package/dist/appearance/index.cjs +1 -1
  4. package/dist/appearance/index.js +1 -1
  5. package/dist/brand-studio/index.cjs +4 -4
  6. package/dist/brand-studio/index.js +15 -13
  7. package/dist/briefings/index.cjs +1 -1
  8. package/dist/briefings/index.js +39 -2131
  9. package/dist/chunks/{analyze-result-contract-BHb7sUUW.cjs → analyze-result-contract-Dxw66nUG.cjs} +1 -1
  10. package/dist/chunks/{analyze-result-contract-T-0Ntzys.js → analyze-result-contract-GHKFwThg.js} +1 -1
  11. package/dist/chunks/canonical-result-keys-Drc2x-lf.cjs +1 -0
  12. package/dist/chunks/canonical-result-keys-KLk__J_O.js +466 -0
  13. package/dist/chunks/color-CJvdlFM_.js +2162 -0
  14. package/dist/chunks/color-CyB5o13F.cjs +4 -0
  15. package/dist/chunks/{common-types-CQ6SHfLk.cjs → common-types-Ci66eflG.cjs} +1 -1
  16. package/dist/chunks/{common-types-B7Jk3Rtj.js → common-types-F6qk6PPS.js} +1 -1
  17. package/dist/chunks/contracts-CoCOpd_i.js +11 -0
  18. package/dist/chunks/contracts-CtB2VONT.cjs +1 -0
  19. package/dist/chunks/{dashboard-briefing-launcher-DHAgK6LQ.js → dashboard-briefing-launcher-CFpX0WX3.js} +86 -84
  20. package/dist/chunks/dashboard-briefing-launcher-mUXWuiOZ.cjs +26 -0
  21. package/dist/chunks/{dashboard-controls-D83FAKol.js → dashboard-controls-BeYAmOJc.js} +15 -13
  22. package/dist/chunks/{dashboard-controls-Cq1L0Iaq.cjs → dashboard-controls-SoNubIu1.cjs} +1 -1
  23. package/dist/chunks/dashboard-json-BublPnQ4.cjs +1 -0
  24. package/dist/chunks/{dashboard-json-BumpAIpV.js → dashboard-json-DeLUagVV.js} +25 -23
  25. package/dist/chunks/edit-dashboard-visual-CrvPcO7A.cjs +172 -0
  26. package/dist/chunks/{edit-dashboard-visual-BApnAJlf.js → edit-dashboard-visual-Go0h82DR.js} +6926 -6948
  27. package/dist/chunks/editor-action-buttons-1Lo0fIh7.cjs +16 -0
  28. package/dist/chunks/{editor-action-buttons-B5I-BUky.js → editor-action-buttons-BFNtjFzO.js} +41 -39
  29. package/dist/chunks/format-types-CFHQoIuk.js +1350 -0
  30. package/dist/chunks/format-types-PSZZ7hG8.cjs +1 -0
  31. package/dist/chunks/index-B3ZugihZ.js +3713 -0
  32. package/dist/chunks/{index-CxnEYRCF.js → index-BsH32bn1.js} +47472 -47845
  33. package/dist/chunks/index-ByFbacH7.cjs +1 -0
  34. package/dist/chunks/index-CACdoqu3.js +318 -0
  35. package/dist/chunks/index-DSKR3nKn.js +421 -0
  36. package/dist/chunks/index-DjiIh_9n.cjs +4 -0
  37. package/dist/chunks/index-F25jnH0p.cjs +1 -0
  38. package/dist/chunks/index-q12_nNUS.cjs +1392 -0
  39. package/dist/chunks/{metric-comparison-97zHGEx5.js → metric-comparison-D0T0MKRK.js} +1 -1
  40. package/dist/chunks/{metric-comparison-CUAJ8n4y.cjs → metric-comparison-DYR3RXam.cjs} +1 -1
  41. package/dist/chunks/pivot-header-presentation-DcfPaCiy.cjs +4 -0
  42. package/dist/chunks/pivot-header-presentation-nk604qc1.js +557 -0
  43. package/dist/chunks/{pivot-result-identity-CwJWpKI7.js → pivot-result-identity-C43Ai5Kr.js} +1 -1
  44. package/dist/chunks/{pivot-result-identity-CDLRT-YG.cjs → pivot-result-identity-CRUokNgm.cjs} +1 -1
  45. package/dist/chunks/pivot-result-lifecycle-4kSe0Hk1.js +1642 -0
  46. package/dist/chunks/pivot-result-lifecycle-BiJepH5S.cjs +1 -0
  47. package/dist/chunks/raw-temporal-contract-BF7PjBY9.js +64 -0
  48. package/dist/chunks/raw-temporal-contract-CxbRFwnd.cjs +1 -0
  49. package/dist/chunks/report-preferences-dialog-BEVZAE3m.cjs +1 -0
  50. package/dist/chunks/report-preferences-dialog-BNV7qXYH.js +723 -0
  51. package/dist/chunks/{report-runtime-context-bCy3CVzK.js → report-runtime-context-BJQDu2fV.js} +1 -1
  52. package/dist/chunks/{report-runtime-context-C8LZFsqV.cjs → report-runtime-context-DjYqLV-c.cjs} +1 -1
  53. package/dist/chunks/saved-temporal-bucket-format-DiZdQXOL.js +924 -0
  54. package/dist/chunks/saved-temporal-bucket-format-Gfbh4IiP.cjs +1 -0
  55. package/dist/chunks/switch-CjJ6FHYJ.cjs +138 -0
  56. package/dist/chunks/{switch-BXet-Sno.js → switch-DgLwr7O-.js} +4352 -5249
  57. package/dist/chunks/temporal-bucket-Dnj8qT9l.cjs +1 -0
  58. package/dist/chunks/temporal-bucket-FBZGrDCe.js +560 -0
  59. package/dist/chunks/temporal-bucket-authoring-7hv2laOG.cjs +1 -0
  60. package/dist/chunks/temporal-bucket-authoring-FIRnJz0e.js +221 -0
  61. package/dist/chunks/{temporal-bucket-contract-_F6vNhhH.js → temporal-bucket-contract-BQOj6Frl.js} +1 -1
  62. package/dist/chunks/{temporal-bucket-contract-ChDBWX8I.cjs → temporal-bucket-contract-anl4h-vg.cjs} +1 -1
  63. package/dist/chunks/{token-types-BHR58aTy.js → token-types-CRpQJ4kv.js} +1 -1
  64. package/dist/chunks/{token-types-BdQ8kHBm.cjs → token-types-D0i0IUX3.cjs} +1 -1
  65. package/dist/chunks/{update-policy-BxvYMYz0.cjs → update-policy-C1i9bgsy.cjs} +1 -1
  66. package/dist/chunks/{update-policy-g0rCQ9BM.js → update-policy-CaJz9aPG.js} +1 -1
  67. package/dist/chunks/{validators-Cs74WVie.js → validators-DeMXwRON.js} +253 -233
  68. package/dist/chunks/validators-Dm7Kpz6p.cjs +1 -0
  69. package/dist/dashboard/index.cjs +1 -1
  70. package/dist/dashboard/index.js +2 -2
  71. package/dist/dashboard-authoring/index.cjs +3 -3
  72. package/dist/dashboard-authoring/index.js +32 -29
  73. package/dist/data-app-builder/index.cjs +1 -1
  74. package/dist/data-app-builder/index.js +2 -2
  75. package/dist/data-app-codegen/index.cjs +1 -1
  76. package/dist/data-app-codegen/index.js +2 -2
  77. package/dist/data-app-codegen-node/index.cjs +1 -1
  78. package/dist/data-app-codegen-node/index.js +3 -3
  79. package/dist/data-app-sdk/index.cjs +1 -1
  80. package/dist/data-app-sdk/index.js +3 -3
  81. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  82. package/dist/data-app-sdk-adapters/index.js +2 -2
  83. package/dist/data-app-sdk-validation/index.cjs +1 -1
  84. package/dist/data-app-sdk-validation/index.js +3 -3
  85. package/dist/format-utils/index.cjs +3 -3
  86. package/dist/format-utils/index.js +162 -145
  87. package/dist/index.cjs +1 -1
  88. package/dist/index.js +157 -155
  89. package/dist/report-runtime-context/index.cjs +1 -1
  90. package/dist/report-runtime-context/index.js +2 -2
  91. package/dist/style.css +1 -1
  92. package/dist/surfboard/index.cjs +1 -1
  93. package/dist/surfboard/index.js +3 -3
  94. package/dist/types/analytics-protocol.d.ts +37 -0
  95. package/dist/types/briefings.d.ts +718 -7
  96. package/dist/types/dashboard-assistant.d.ts +18 -0
  97. package/dist/types/dashboard-authoring.d.ts +52 -2
  98. package/dist/types/dashboard.d.ts +128 -0
  99. package/dist/types/data-app-sdk-validation.d.ts +13 -0
  100. package/dist/types/data-app-sdk.d.ts +13 -0
  101. package/dist/types/format-utils.d.ts +190 -3
  102. package/dist/types/index.cjs +1 -1
  103. package/dist/types/index.js +4 -4
  104. package/dist/types/main.d.ts +103 -12
  105. package/dist/types/shared.d.ts +5 -0
  106. package/dist/types/surfboard.d.ts +129 -1
  107. package/dist/types/types.d.ts +98 -6
  108. package/dist/types/value-format-preferences.d.ts +3 -0
  109. package/package.json +2 -1
  110. package/dist/chunks/card-config-utils-15sRtebL.cjs +0 -1
  111. package/dist/chunks/card-config-utils-BYZ5MJOh.js +0 -16
  112. package/dist/chunks/dashboard-briefing-launcher-BbBD6r23.cjs +0 -26
  113. package/dist/chunks/dashboard-json-MQsd_x4u.cjs +0 -1
  114. package/dist/chunks/edit-dashboard-visual-DDg6-670.cjs +0 -177
  115. package/dist/chunks/editor-action-buttons-BW3qw_Og.cjs +0 -16
  116. package/dist/chunks/format-types-CSv0V7mm.cjs +0 -1
  117. package/dist/chunks/format-types-DZGgYj39.js +0 -1663
  118. package/dist/chunks/index-CJdxSyQq.js +0 -2578
  119. package/dist/chunks/index-DRlMUglg.cjs +0 -4
  120. package/dist/chunks/index-zREDXi6s.cjs +0 -1395
  121. package/dist/chunks/pivot-result-lifecycle-BBabQ_da.js +0 -914
  122. package/dist/chunks/pivot-result-lifecycle-DPc0ANwk.cjs +0 -4
  123. package/dist/chunks/presentation-execution-BLfPTGX_.js +0 -637
  124. package/dist/chunks/presentation-execution-BTV-Q43g.cjs +0 -1
  125. package/dist/chunks/report-preferences-dialog-BRGOibDO.cjs +0 -1
  126. package/dist/chunks/report-preferences-dialog-lyC6PCs9.js +0 -691
  127. package/dist/chunks/switch-Cjk6G06r.cjs +0 -138
  128. package/dist/chunks/temporal-bucket-BnPxGrAi.js +0 -446
  129. package/dist/chunks/temporal-bucket-authoring-CPTwHzvs.cjs +0 -1
  130. package/dist/chunks/temporal-bucket-authoring-CgOuakGW.js +0 -205
  131. package/dist/chunks/temporal-bucket-pMnV-4Nj.cjs +0 -1
  132. package/dist/chunks/temporal-result-owner-6peubmhU.js +0 -443
  133. package/dist/chunks/temporal-result-owner-f6-i65Fb.cjs +0 -1
  134. package/dist/chunks/validators-9D4KBqKD.cjs +0 -1
@@ -0,0 +1,3713 @@
1
+ var Je = Object.defineProperty;
2
+ var Qe = (e, r, t) => r in e ? Je(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
+ var S = (e, r, t) => Qe(e, typeof r != "symbol" ? r + "" : r, t);
4
+ import { E as Xe, C as et, q as tt, D as rt, A as J, u as q, o as nt, M as ot, w as at, R as it, i as Te, b as ct, m as lt, P as U } from "./pivot-result-lifecycle-4kSe0Hk1.js";
5
+ import { DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES as de } from "../value-format-preferences/index.js";
6
+ import { l as dt, q as ae } from "./validators-DeMXwRON.js";
7
+ import "./analyze-result-contract-GHKFwThg.js";
8
+ import { h as $e, r as ke, a as Ee, v as st, i as mt } from "./saved-temporal-bucket-format-DiZdQXOL.js";
9
+ import { r as z, b as ut, d as ft, P as pt } from "./pivot-result-identity-C43Ai5Kr.js";
10
+ import { v as yt, a as ht } from "./temporal-bucket-contract-BQOj6Frl.js";
11
+ import { f as gt, a as vt, c as xe, D as bt } from "./temporal-bucket-FBZGrDCe.js";
12
+ import { n as It } from "./catalog-field-grounding-S2jKwKGD.js";
13
+ import { r as Se, s as wt, i as Ct, a as Tt, b as $t, c as kt } from "./canonical-result-keys-KLk__J_O.js";
14
+ import "./temporal-bucket-authoring-FIRnJz0e.js";
15
+ import { v as _e } from "./raw-temporal-contract-BF7PjBY9.js";
16
+ const Et = `import pandas as pd
17
+ df = pd.DataFrame(data) # 'data' contains the query result
18
+ result = df.to_dict('records') # must return 'result' as [dict] type
19
+ `;
20
+ function bn(e) {
21
+ return {
22
+ databaseName: (e == null ? void 0 : e.lastSelectedDatabase) || "",
23
+ schemaName: (e == null ? void 0 : e.lastSelectedSchema) || "",
24
+ tableName: (e == null ? void 0 : e.lastSelectedTable) || "",
25
+ datamodelId: (e == null ? void 0 : e.datamodelId) || ""
26
+ };
27
+ }
28
+ function H(e) {
29
+ return e === Et ? "" : e;
30
+ }
31
+ function Q(e, r = e.config) {
32
+ return Se({
33
+ hasExecutableConfig: $e(r),
34
+ sql: e.sql,
35
+ normalizedPython: H(e.python || "")
36
+ });
37
+ }
38
+ class xt extends Error {
39
+ constructor(t) {
40
+ super(
41
+ `ambiguous_temporal_grain: Temporal field "${t}" has saved presentation but no valid grouping grain. Reconfigure and resave the field.`
42
+ );
43
+ S(this, "code", "ambiguous_temporal_grain");
44
+ S(this, "fieldId");
45
+ this.name = "AmbiguousGroupedTemporalGrainError", this.fieldId = t;
46
+ }
47
+ }
48
+ function St(e) {
49
+ return Ee(e) || e.semanticTemporalPresentation != null;
50
+ }
51
+ function _t(e) {
52
+ if (!e.id || !["date", "datetime"].includes(
53
+ It(e.dataType)
54
+ ))
55
+ return;
56
+ if (dt(e.granularity)) return e;
57
+ if (!St(e)) return;
58
+ if (!ke({
59
+ fieldId: e.id,
60
+ dataType: e.dataType,
61
+ granularity: e.granularity,
62
+ format: e.format,
63
+ dateFormat: e.dateFormat,
64
+ customFormat: e.customFormat
65
+ }).ok)
66
+ throw new xt(e.id);
67
+ return { ...e, granularity: "day" };
68
+ }
69
+ function se(e) {
70
+ const r = e.cardConfig ?? e.card.config;
71
+ if (!r || !e.supportsCardType(e.card.type) || Se({
72
+ hasExecutableConfig: $e(r),
73
+ sql: e.card.sql,
74
+ normalizedPython: H(e.card.python || "")
75
+ }) !== "config")
76
+ return;
77
+ const t = [
78
+ ...(r.groupByColumns || []).map((n) => ({
79
+ ...n,
80
+ role: "groupby"
81
+ })),
82
+ ...e.card.type === "pivotTable" ? (r.pivotByColumns || []).map((n) => ({
83
+ ...n,
84
+ role: "pivotby"
85
+ })) : []
86
+ ];
87
+ return {
88
+ cardType: e.card.type,
89
+ cardConfig: r,
90
+ fields: t.flatMap((n) => {
91
+ const o = _t(n);
92
+ return o ? [o] : [];
93
+ })
94
+ };
95
+ }
96
+ function In(e) {
97
+ return se({
98
+ ...e,
99
+ supportsCardType: (r) => r === "table"
100
+ });
101
+ }
102
+ function wn(e) {
103
+ return se({
104
+ ...e,
105
+ supportsCardType: Ct
106
+ });
107
+ }
108
+ function Ft(e) {
109
+ return se({
110
+ ...e,
111
+ // Raw detail-table presentation has its own result/adapter contract.
112
+ // This module remains grouped-only even though the shared producer
113
+ // registry now recognizes detailTable.
114
+ supportsCardType: (r) => r !== "detailTable" && wt(r)
115
+ });
116
+ }
117
+ const ve = /* @__PURE__ */ new WeakMap();
118
+ function Rt(e) {
119
+ const r = ve.get(e);
120
+ if (r) return r;
121
+ const t = Xe(e);
122
+ return ve.set(e, t), t;
123
+ }
124
+ function L(e, r) {
125
+ const t = e ?? [], n = r ?? [];
126
+ return t.length === n.length && t.every((o, a) => o === n[a]);
127
+ }
128
+ function At(e, r) {
129
+ const t = et({
130
+ groupByFields: r.groupByColumns,
131
+ metricFields: r.metricColumns,
132
+ pivotByFields: r.pivotByColumns,
133
+ detailFields: r.detailColumns
134
+ });
135
+ return L(
136
+ e.expectedRoleFieldIds.groupby,
137
+ t.expectedRoleFieldIds.groupby
138
+ ) && L(
139
+ e.expectedRoleFieldIds.metric,
140
+ t.expectedRoleFieldIds.metric
141
+ ) && L(
142
+ e.expectedRoleFieldIds.pivotby,
143
+ t.expectedRoleFieldIds.pivotby
144
+ ) && L(
145
+ e.expectedRoleFieldIds.detail,
146
+ t.expectedRoleFieldIds.detail
147
+ ) && L(
148
+ e.expectedMetricAliases,
149
+ t.expectedMetricAliases
150
+ );
151
+ }
152
+ class Bt extends Error {
153
+ constructor(t) {
154
+ super(
155
+ `missing_resolved_temporal_format: Saved presentation is missing temporal field "${t.fieldId}" for card "${t.cardId}". Resave the report or Briefing to capture the current dashboard presentation.`
156
+ );
157
+ S(this, "code", "missing_resolved_temporal_format");
158
+ S(this, "deliveryBlocking", !0);
159
+ S(this, "dashboardId");
160
+ S(this, "cardId");
161
+ S(this, "fieldId");
162
+ this.name = "MissingResolvedTemporalPresentationError", this.dashboardId = t.dashboardId, this.cardId = t.cardId, this.fieldId = t.fieldId;
163
+ }
164
+ }
165
+ class ee extends Error {
166
+ constructor(t) {
167
+ super(
168
+ `missing_temporal_bucket_metadata: Result column "${t.columnKey}" is missing temporal bucket metadata for field "${t.fieldId}" on card "${t.cardId}". Refresh the report and resave the delivery if the problem persists.`
169
+ );
170
+ S(this, "code", "missing_temporal_bucket_metadata");
171
+ S(this, "deliveryBlocking", !0);
172
+ S(this, "cardId");
173
+ S(this, "fieldId");
174
+ S(this, "columnKey");
175
+ this.name = "MissingTemporalResultMetadataError", this.cardId = t.cardId, this.fieldId = t.fieldId, this.columnKey = t.columnKey;
176
+ }
177
+ }
178
+ class K extends Error {
179
+ constructor(t, n, o) {
180
+ super(`${t}: ${n}`);
181
+ S(this, "deliveryBlocking", !0);
182
+ this.code = t, this.context = o, this.name = "DashboardTemporalBoundaryError";
183
+ }
184
+ }
185
+ function Fe(e, r) {
186
+ return `${r}:${e}`;
187
+ }
188
+ function Pt(e) {
189
+ var r, t;
190
+ return (t = (r = e.presentation) == null ? void 0 : r.byFieldRole) == null ? void 0 : t.get(
191
+ Fe(e.fieldId, e.role)
192
+ );
193
+ }
194
+ function Mt(e) {
195
+ var t;
196
+ if ((((t = e.cardConfig.metricColumns) == null ? void 0 : t.length) || 0) > 0 || e.binding.role !== "metric")
197
+ return !1;
198
+ const r = e.binding.outputKey || e.binding.rawKey;
199
+ return e.columns.some(
200
+ (n) => {
201
+ var o;
202
+ return n.role === "measure" && n.dataType === "number" && (n.key === r || ((o = n.pivotIdentity) == null ? void 0 : o.metricId) === ae);
203
+ }
204
+ );
205
+ }
206
+ function Cn(e, r) {
207
+ return !r || r.byColumnKey.size === 0 ? e.map((t) => ({ ...t })) : e.map((t) => {
208
+ const n = { ...t };
209
+ return r.byColumnKey.forEach((o, a) => {
210
+ Object.prototype.hasOwnProperty.call(t, a) && (n[a] = Re({
211
+ value: t[a],
212
+ presentation: o
213
+ }));
214
+ }), n;
215
+ });
216
+ }
217
+ function Tn(e) {
218
+ var p;
219
+ if (!e.result || typeof e.result != "object") return !1;
220
+ const r = e.result;
221
+ if (e.expectedResultOwner !== void 0 && r.resultOwner !== e.expectedResultOwner)
222
+ return !1;
223
+ const t = e.activation;
224
+ if (!t || t.cardType !== "pivotTable" && t.fields.length === 0)
225
+ return !0;
226
+ const n = Array.isArray(r.records) ? r.records.length : void 0, o = (t.cardConfig.pivotByColumns || []).map((d) => d.id);
227
+ if (t.cardType === "pivotTable")
228
+ try {
229
+ const d = Rt(r);
230
+ if (!At(
231
+ d.pivotResultContract,
232
+ t.cardConfig
233
+ ))
234
+ return !1;
235
+ if (d.pivotResultState === "loaded_empty") return !0;
236
+ const v = d.columns.filter(
237
+ (w) => d.pivotResultContract.columnKinds[w.key] === "pivot_metric"
238
+ ), h = v.filter(
239
+ (w) => {
240
+ var g;
241
+ return (((g = w.pivotIdentity) == null ? void 0 : g.members.length) ?? 0) > 0;
242
+ }
243
+ ), I = v.length > 0 && v.every(
244
+ (w) => {
245
+ var g;
246
+ return ((g = w.pivotIdentity) == null ? void 0 : g.members.length) === 0 && ut({
247
+ expectedPivotFieldIds: o,
248
+ classification: d.pivotResultContract.columnClassifications[w.key]
249
+ });
250
+ }
251
+ );
252
+ return t.fields.every((w) => {
253
+ var E;
254
+ const g = z(
255
+ d.columnKeyMap,
256
+ w.id,
257
+ w.role
258
+ );
259
+ if (!g) return !1;
260
+ if (g.role === "pivotby") {
261
+ const F = h.flatMap(
262
+ (O) => {
263
+ var V;
264
+ return ((V = O.pivotIdentity) == null ? void 0 : V.members.filter(
265
+ (Ze) => Ze.fieldId === w.id
266
+ )) ?? [];
267
+ }
268
+ );
269
+ return F.length === 0 ? I : F.every(
270
+ (O) => {
271
+ var V;
272
+ return ((V = O.temporalBucket) == null ? void 0 : V.granularity) === w.granularity;
273
+ }
274
+ );
275
+ }
276
+ const $ = d.columns.find(
277
+ (F) => F.key === (g.outputKey || g.rawKey)
278
+ );
279
+ return ((E = $ == null ? void 0 : $.temporalBucket) == null ? void 0 : E.granularity) === w.granularity;
280
+ });
281
+ } catch (d) {
282
+ if (d instanceof rt) return !1;
283
+ throw d;
284
+ }
285
+ if (n === 0)
286
+ return !0;
287
+ const a = r.columnKeyMap;
288
+ if (!a || !a.byRole || typeof a.byRole != "object" || Array.isArray(a.byRole))
289
+ return !1;
290
+ const i = [
291
+ ...(t.cardConfig.groupByColumns || []).map((d) => ({
292
+ field: d,
293
+ role: "groupby"
294
+ })),
295
+ ...(t.cardConfig.metricColumns || []).map((d) => ({
296
+ field: d,
297
+ role: "metric"
298
+ })),
299
+ ...(t.cardConfig.pivotByColumns || []).map((d) => ({
300
+ field: d,
301
+ role: "pivotby"
302
+ })),
303
+ ...(t.cardConfig.detailColumns || []).map((d) => ({
304
+ field: d,
305
+ role: "detail"
306
+ }))
307
+ ], l = new Set(
308
+ i.map(({ field: d, role: v }) => `${v}:${d.id}`)
309
+ ), m = new Map(
310
+ (r.columns || []).map((d) => [d.key, d])
311
+ ), c = z(
312
+ a,
313
+ ae,
314
+ "metric"
315
+ );
316
+ if (c) {
317
+ if (!Mt({
318
+ cardConfig: t.cardConfig,
319
+ binding: c,
320
+ columns: r.columns || []
321
+ }))
322
+ return !1;
323
+ l.add(`metric:${ae}`);
324
+ }
325
+ const s = Object.entries(a.byRole).flatMap(
326
+ ([d, v]) => Object.keys(v || {}).map((h) => `${d}:${h}`)
327
+ );
328
+ if (s.length !== l.size || s.some((d) => !l.has(d)) || i.some(
329
+ ({ field: d, role: v }) => !z(a, d.id, v)
330
+ ))
331
+ return !1;
332
+ try {
333
+ ft(
334
+ (r.columns || []).map((d) => ({
335
+ key: d.key,
336
+ pivotIdentity: d.pivotIdentity
337
+ })),
338
+ {
339
+ expectedPivotFieldIds: o,
340
+ columnClassifications: r.columnMetadata
341
+ }
342
+ );
343
+ } catch (d) {
344
+ if (d instanceof pt) return !1;
345
+ throw d;
346
+ }
347
+ const u = (r.columns || []).filter((d) => {
348
+ const v = d.pivotIdentity;
349
+ return !!(v && v.members.length > 0);
350
+ });
351
+ return n !== 0 && ((p = t.cardConfig.pivotByColumns) != null && p.length) && u.length === 0 ? !1 : t.fields.every((d) => {
352
+ var I;
353
+ const v = z(
354
+ a,
355
+ d.id,
356
+ d.role
357
+ );
358
+ if (!v) return !1;
359
+ if (v.role === "pivotby") {
360
+ const g = u.flatMap(
361
+ ($) => {
362
+ var E;
363
+ return ((E = $.pivotIdentity) == null ? void 0 : E.members) ?? [];
364
+ }
365
+ ).filter(($) => $.fieldId === d.id);
366
+ return u.length === 0 ? n === 0 : g.length > 0 && g.every(
367
+ ($) => {
368
+ var E;
369
+ return ((E = $.temporalBucket) == null ? void 0 : E.granularity) === d.granularity;
370
+ }
371
+ );
372
+ }
373
+ const h = m.get(v.outputKey || v.rawKey);
374
+ return ((I = h == null ? void 0 : h.temporalBucket) == null ? void 0 : I.granularity) === d.granularity;
375
+ });
376
+ }
377
+ function Z(e, r) {
378
+ const t = e.semanticTemporalPresentation, n = r === "card" ? {
379
+ format: e.format,
380
+ dateFormat: e.dateFormat
381
+ } : { format: t == null ? void 0 : t.format };
382
+ if (!Ee(n))
383
+ return;
384
+ const o = ke({
385
+ fieldId: e.id,
386
+ dataType: e.dataType,
387
+ granularity: r === "semantic" ? t == null ? void 0 : t.granularity : e.granularity,
388
+ ...r === "card" ? {
389
+ format: e.format,
390
+ dateFormat: e.dateFormat,
391
+ customFormat: e.customFormat
392
+ } : { format: t == null ? void 0 : t.format }
393
+ });
394
+ if (!o.ok) throw new Error(o.error.code);
395
+ return o.format;
396
+ }
397
+ function Dt(e, r, t = de) {
398
+ const n = Z(e, "card"), o = Z(e, "semantic"), a = e.semanticTemporalPresentation;
399
+ return xe({
400
+ metadata: r,
401
+ ...n ? { cardFormat: n } : {},
402
+ ...o && a ? {
403
+ semanticFormat: {
404
+ granularity: a.granularity,
405
+ format: o
406
+ }
407
+ } : {},
408
+ locale: t.locale,
409
+ styles: {
410
+ dateStyle: t.dateStyle,
411
+ dateTime: t.dateTime
412
+ }
413
+ });
414
+ }
415
+ function Ot(e, r = bt, t = "en-US") {
416
+ var i;
417
+ const n = Z(e, "card"), o = ((i = e.semanticTemporalPresentation) == null ? void 0 : i.granularity) === e.granularity ? Z(e, "semantic") : void 0, a = n && n.presentation.mode !== "auto" ? n : o && o.presentation.mode !== "auto" ? o : {
418
+ presentation: { mode: "auto" }
419
+ };
420
+ return a.presentation.mode === "auto" ? {
421
+ type: "temporal_bucket",
422
+ locale: t,
423
+ presentation: { mode: "auto", styles: r }
424
+ } : {
425
+ type: "temporal_bucket",
426
+ locale: t,
427
+ presentation: a.presentation
428
+ };
429
+ }
430
+ function $n(e) {
431
+ const r = e.activation;
432
+ if (!r)
433
+ return {
434
+ byColumnKey: /* @__PURE__ */ new Map(),
435
+ byFieldId: /* @__PURE__ */ new Map(),
436
+ byFieldRole: /* @__PURE__ */ new Map()
437
+ };
438
+ if (e.resultRowCount === 0)
439
+ return {
440
+ byColumnKey: /* @__PURE__ */ new Map(),
441
+ byFieldId: /* @__PURE__ */ new Map(),
442
+ byFieldRole: /* @__PURE__ */ new Map()
443
+ };
444
+ const t = new Map(
445
+ (e.columns || []).map((c) => [c.key, c])
446
+ ), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), i = r.fields.reduce((c, s) => (c.set(s.id, (c.get(s.id) || 0) + 1), c), /* @__PURE__ */ new Map()), l = (c, s) => {
447
+ a.set(
448
+ Fe(c.id, c.role),
449
+ s
450
+ ), i.get(c.id) === 1 && o.set(c.id, s);
451
+ }, m = (c, s, u) => {
452
+ if (s.granularity !== c.granularity)
453
+ throw new K(
454
+ "invalid_temporal_bucket_metadata",
455
+ `Result identity "${u}" declares ${s.granularity} buckets for active ${c.granularity} field "${c.id}".`,
456
+ { cardId: e.card.id, fieldId: c.id, columnKey: u }
457
+ );
458
+ const p = e.executionSnapshot && e.dashboardId ? tt({
459
+ snapshot: e.executionSnapshot,
460
+ scope: {
461
+ dashboardId: e.dashboardId,
462
+ cardId: e.card.id,
463
+ ...e.attachmentIndex !== void 0 ? { attachmentIndex: e.attachmentIndex } : {}
464
+ },
465
+ target: {
466
+ kind: "field",
467
+ fieldId: c.id,
468
+ role: c.role
469
+ }
470
+ }) : void 0;
471
+ if (e.executionSnapshot && !p)
472
+ throw new Bt({
473
+ dashboardId: e.dashboardId,
474
+ cardId: e.card.id,
475
+ fieldId: c.id
476
+ });
477
+ return {
478
+ columnKey: u,
479
+ fieldId: c.id,
480
+ role: c.role,
481
+ metadata: s,
482
+ resolved: p ? xe({
483
+ metadata: s,
484
+ cardFormat: p,
485
+ locale: p.locale,
486
+ ...p.presentation.mode === "auto" ? {
487
+ styles: p.presentation.styles
488
+ } : {}
489
+ }) : Dt(
490
+ c,
491
+ s,
492
+ e.valueFormatPreferences ?? de
493
+ )
494
+ };
495
+ };
496
+ for (const c of r.fields) {
497
+ const s = z(
498
+ e.columnKeyMap,
499
+ c.id,
500
+ c.role
501
+ );
502
+ if (!s) {
503
+ if (e.columns === void 0 && e.columnKeyMap === void 0 && (e.resultRowCount === void 0 || e.resultRowCount === 0))
504
+ continue;
505
+ throw new K(
506
+ "missing_temporal_column_binding",
507
+ `Activated temporal field "${c.id}" has no authoritative result-column binding.`,
508
+ { cardId: e.card.id, fieldId: c.id, columnKey: c.name }
509
+ );
510
+ }
511
+ if (s.role === "pivotby") {
512
+ const h = (e.columns || []).filter(
513
+ (E) => E.pivotIdentity !== void 0
514
+ ), I = h.flatMap(
515
+ (E) => {
516
+ var F;
517
+ return (((F = E.pivotIdentity) == null ? void 0 : F.members) || []).filter((O) => O.fieldId === c.id).map((O) => ({ column: E, member: O }));
518
+ }
519
+ );
520
+ if (I.length === 0) {
521
+ if (h.length === 0 && (e.card.type !== "pivotTable" || e.resultRowCount === 0))
522
+ continue;
523
+ throw new ee({
524
+ cardId: e.card.id,
525
+ fieldId: c.id,
526
+ columnKey: s.outputKey || s.rawKey
527
+ });
528
+ }
529
+ const w = I[0];
530
+ if (!w.member.temporalBucket)
531
+ throw new ee({
532
+ cardId: e.card.id,
533
+ fieldId: c.id,
534
+ columnKey: w.column.key
535
+ });
536
+ const g = yt(
537
+ w.member.temporalBucket
538
+ );
539
+ if (!g.ok || !g.value)
540
+ throw new K(
541
+ "invalid_temporal_bucket_metadata",
542
+ g.ok ? `Pivot result column "${w.column.key}" has no validated temporal bucket metadata.` : g.error.message,
543
+ {
544
+ cardId: e.card.id,
545
+ fieldId: c.id,
546
+ columnKey: w.column.key
547
+ }
548
+ );
549
+ const $ = m(
550
+ c,
551
+ g.value,
552
+ w.column.key
553
+ );
554
+ for (const { column: E, member: F } of I)
555
+ if (!F.temporalBucket || JSON.stringify(F.temporalBucket) !== JSON.stringify(w.member.temporalBucket))
556
+ throw new K(
557
+ "invalid_temporal_bucket_metadata",
558
+ `Pivot result column "${E.key}" has contradictory bucket metadata for field "${c.id}".`,
559
+ { cardId: e.card.id, fieldId: c.id, columnKey: E.key }
560
+ );
561
+ l(c, $);
562
+ continue;
563
+ }
564
+ const u = s.outputKey || s.rawKey, p = t.get(u);
565
+ if (!(p != null && p.temporalBucket))
566
+ throw new ee({
567
+ cardId: e.card.id,
568
+ fieldId: c.id,
569
+ columnKey: u
570
+ });
571
+ const d = ht(p, {
572
+ metadataRequired: !0
573
+ });
574
+ if (!d.ok || !d.value)
575
+ throw new K(
576
+ "invalid_temporal_bucket_metadata",
577
+ d.ok ? `Result column "${u}" has no validated temporal bucket metadata.` : d.error.message,
578
+ { cardId: e.card.id, fieldId: c.id, columnKey: u }
579
+ );
580
+ const v = m(
581
+ c,
582
+ d.value,
583
+ u
584
+ );
585
+ n.set(u, v), l(c, v);
586
+ }
587
+ return { byColumnKey: n, byFieldId: o, byFieldRole: a };
588
+ }
589
+ function kn(e) {
590
+ var t, n;
591
+ const r = e.role ? Pt({
592
+ presentation: e.presentation,
593
+ fieldId: e.fieldId,
594
+ role: e.role
595
+ }) : (n = (t = e.presentation) == null ? void 0 : t.byFieldId) == null ? void 0 : n.get(e.fieldId);
596
+ return r ? Re({
597
+ value: e.value,
598
+ presentation: r
599
+ }) : e.value === null || e.value === void 0 ? "" : String(e.value);
600
+ }
601
+ function Re(e) {
602
+ if (e.value === null || e.value === void 0) return "(Blank)";
603
+ if (typeof e.value != "string")
604
+ throw new K(
605
+ "invalid_temporal_bucket_value",
606
+ `Canonical temporal column "${e.presentation.columnKey}" must contain a string or null.`,
607
+ {
608
+ fieldId: e.presentation.fieldId,
609
+ columnKey: e.presentation.columnKey
610
+ }
611
+ );
612
+ try {
613
+ return gt({
614
+ value: e.value,
615
+ metadata: e.presentation.metadata,
616
+ format: e.presentation.resolved.format
617
+ });
618
+ } catch (r) {
619
+ throw r instanceof vt ? new K(
620
+ r.code,
621
+ r.message,
622
+ {
623
+ fieldId: e.presentation.fieldId,
624
+ columnKey: e.presentation.columnKey
625
+ }
626
+ ) : r;
627
+ }
628
+ }
629
+ class x extends Error {
630
+ constructor(r, t, n) {
631
+ super(`${r}: ${t}`), this.code = r, this.context = n, Object.setPrototypeOf(this, x.prototype), this.name = "RawTemporalPresentationBoundaryError";
632
+ }
633
+ }
634
+ function Ae() {
635
+ return { type: "raw_temporal", presentation: { mode: "auto" } };
636
+ }
637
+ function Kt(e) {
638
+ if (e.locale || e.relative || e.timezone && e.timezone !== "auto" || e.sourceTimezone && e.sourceTimezone !== "auto" || e.prefix || e.suffix)
639
+ throw new x(
640
+ "invalid_raw_temporal_format",
641
+ "Activated raw temporal presentation contains unsupported locale, relative-time, timezone, prefix, or suffix settings."
642
+ );
643
+ }
644
+ function Be(e) {
645
+ const r = e.format;
646
+ if ((r == null ? void 0 : r.type) === "date" && (Kt(r), r.pattern))
647
+ return {
648
+ type: "raw_temporal",
649
+ presentation: {
650
+ mode: "pattern",
651
+ dialect: "semaphor_tokens",
652
+ pattern: r.pattern
653
+ }
654
+ };
655
+ if (r)
656
+ throw new x(
657
+ "invalid_raw_temporal_format",
658
+ `Raw temporal detail field "${e.id}" has an incompatible authored format.`,
659
+ { fieldId: e.id }
660
+ );
661
+ if (e.dateFormat === "custom") {
662
+ if (!e.customFormat)
663
+ throw new x(
664
+ "invalid_raw_temporal_format",
665
+ `Raw temporal detail field "${e.id}" selects a custom pattern but has no customFormat.`,
666
+ { fieldId: e.id }
667
+ );
668
+ return {
669
+ type: "raw_temporal",
670
+ presentation: {
671
+ mode: "pattern",
672
+ dialect: "semaphor_tokens",
673
+ pattern: e.customFormat
674
+ }
675
+ };
676
+ }
677
+ return e.dateFormat ? {
678
+ type: "raw_temporal",
679
+ presentation: {
680
+ mode: "pattern",
681
+ dialect: "semaphor_tokens",
682
+ pattern: e.dateFormat
683
+ }
684
+ } : Ae();
685
+ }
686
+ function me(e) {
687
+ if (e != null && e.useRelativeTime) return;
688
+ if (!e) return Ae();
689
+ if (e.useCustomFormat && !e.customFormat)
690
+ throw new x(
691
+ "invalid_raw_temporal_format",
692
+ "Declared SQL temporal presentation selects a custom pattern but has no customFormat."
693
+ );
694
+ const r = e.useCustomFormat && e.customFormat ? e.customFormat : e.format, t = e.timezone, n = e.sourceTimezone, o = t && t !== "auto" ? { timezone: t } : void 0, a = n && n !== "auto" ? { sourceTimezone: n } : void 0;
695
+ return r ? {
696
+ type: "raw_temporal",
697
+ ...o,
698
+ ...a,
699
+ presentation: {
700
+ mode: "pattern",
701
+ dialect: "date_fns",
702
+ pattern: r
703
+ }
704
+ } : {
705
+ type: "raw_temporal",
706
+ ...o,
707
+ ...a,
708
+ presentation: { mode: "auto" }
709
+ };
710
+ }
711
+ function En(e) {
712
+ const r = me(e.settings);
713
+ if (!r)
714
+ throw new x(
715
+ "invalid_raw_temporal_format",
716
+ "Relative-time SQL presentation does not have an absolute date preview."
717
+ );
718
+ const t = e.valueKind ?? "date", n = {
719
+ kind: "raw_temporal",
720
+ valueKind: t
721
+ }, o = e.value ?? (t === "date" ? "2023-05-15" : t === "wall_datetime" ? "2023-05-15T14:30:45" : "2023-05-15T14:30:45Z"), a = J({
722
+ metadata: n,
723
+ format: q({
724
+ format: r,
725
+ preferences: e.preferences,
726
+ calendar: { tz: e.calendarTimezone }
727
+ })
728
+ })(o);
729
+ if (!a.ok)
730
+ throw new x(
731
+ "invalid_raw_temporal_format",
732
+ a.diagnostic.message
733
+ );
734
+ return a.text;
735
+ }
736
+ function Nt(e) {
737
+ var t;
738
+ const r = e.effectiveCardConfig ?? e.card.config;
739
+ return Q(e.card, r) === "freeform" && !!((t = e.card.sql) != null && t.trim()) && !H(e.card.python || "").trim();
740
+ }
741
+ function zt() {
742
+ return {
743
+ activatedColumnKeys: /* @__PURE__ */ new Set(),
744
+ byColumnKey: /* @__PURE__ */ new Map(),
745
+ byFieldId: /* @__PURE__ */ new Map()
746
+ };
747
+ }
748
+ function ue(e) {
749
+ var r;
750
+ return e.cardType === "detailTable" && e.resultOwner === "config" ? (((r = e.effectiveCardConfig) == null ? void 0 : r.detailColumns) || []).filter(
751
+ (t) => t.dateValueMode === "canonical"
752
+ ) : [];
753
+ }
754
+ function ie(e, r) {
755
+ return e === void 0 ? { kind: "invalid", error: r } : {
756
+ kind: "invalid",
757
+ error: e instanceof x ? e : e instanceof it ? new x(
758
+ e.code,
759
+ e.message,
760
+ r.context
761
+ ) : new x(
762
+ r.code,
763
+ e instanceof Error ? e.message : r.message,
764
+ r.context
765
+ )
766
+ };
767
+ }
768
+ function Vt(e) {
769
+ const r = ue(e);
770
+ if (r.length === 0) return { kind: "inactive" };
771
+ if (!e.result) return { kind: "loading" };
772
+ const { records: t, columns: n, columnKeyMap: o } = e.result;
773
+ if (!Array.isArray(t) || !Array.isArray(n) || !o)
774
+ return ie(
775
+ void 0,
776
+ new x(
777
+ "missing_raw_temporal_result_contract",
778
+ "Activated raw temporal detail results require records, columns, and columnKeyMap atomically."
779
+ )
780
+ );
781
+ try {
782
+ const a = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
783
+ for (const m of r) {
784
+ const c = z(
785
+ o,
786
+ m.id,
787
+ "detail"
788
+ );
789
+ if (!c || c.role !== "detail" || typeof c.rawKey != "string" || c.rawKey.trim().length === 0 || c.outputKey !== void 0 && (typeof c.outputKey != "string" || c.outputKey.trim().length === 0))
790
+ throw new x(
791
+ "missing_raw_temporal_column_binding",
792
+ `Raw temporal detail field "${m.id}" has no valid exact detail result binding.`,
793
+ { fieldId: m.id }
794
+ );
795
+ const s = c.outputKey ?? c.rawKey, u = n.find((h) => h.key === s);
796
+ if (!u)
797
+ throw new x(
798
+ "missing_raw_temporal_result_contract",
799
+ `Raw temporal result column "${s}" is absent.`,
800
+ { fieldId: m.id, columnKey: s }
801
+ );
802
+ const p = _e(u, {
803
+ metadataRequired: !0
804
+ });
805
+ if (!p)
806
+ throw new x(
807
+ "invalid_raw_temporal_metadata",
808
+ `Raw temporal result column "${s}" has no metadata.`,
809
+ { fieldId: m.id, columnKey: s }
810
+ );
811
+ const d = q({
812
+ format: Be(m),
813
+ preferences: e.preferences,
814
+ calendar: e.calendar
815
+ }), v = {
816
+ fieldId: m.id,
817
+ columnKey: s,
818
+ metadata: p,
819
+ format: d,
820
+ formatValue: J({ metadata: p, format: d })
821
+ };
822
+ for (let h = 0; h < t.length; h += 1)
823
+ if (!Object.prototype.hasOwnProperty.call(t[h], s) || t[h][s] === void 0)
824
+ throw new x(
825
+ "missing_raw_temporal_result_contract",
826
+ `Raw temporal result row ${h} is missing column "${s}".`,
827
+ { fieldId: m.id, columnKey: s }
828
+ );
829
+ a.set(s, v), i.set(m.id, v);
830
+ }
831
+ const l = {
832
+ activatedColumnKeys: new Set(a.keys()),
833
+ byColumnKey: a,
834
+ byFieldId: i
835
+ };
836
+ return t.length === 0 ? { kind: "loaded_empty", presentation: l } : { kind: "loaded_valid", presentation: l };
837
+ } catch (a) {
838
+ return ie(
839
+ a,
840
+ new x(
841
+ "invalid_raw_temporal_metadata",
842
+ "Activated raw temporal result metadata is invalid."
843
+ )
844
+ );
845
+ }
846
+ }
847
+ function Lt(e) {
848
+ var n, o;
849
+ const r = e.effectiveCardConfig ?? e.card.config, t = Q(
850
+ e.card,
851
+ r
852
+ );
853
+ return e.card.type === "detailTable" && t === "config" ? ue({
854
+ cardType: e.card.type,
855
+ resultOwner: t,
856
+ effectiveCardConfig: r
857
+ }).length > 0 && e.records !== void 0 && (!e.columns || !e.columnKeyMap) ? {
858
+ kind: "invalid",
859
+ error: new x(
860
+ "missing_raw_temporal_result_contract",
861
+ "Activated raw temporal detail results require records, columns, and columnKeyMap atomically."
862
+ )
863
+ } : be(
864
+ Vt({
865
+ cardType: e.card.type,
866
+ resultOwner: t,
867
+ effectiveCardConfig: r,
868
+ result: e.records === void 0 || !e.columns || !e.columnKeyMap ? void 0 : {
869
+ records: e.records,
870
+ columns: e.columns,
871
+ columnKeyMap: e.columnKeyMap
872
+ },
873
+ preferences: e.preferences,
874
+ calendar: e.calendar
875
+ }),
876
+ e
877
+ ) : be(
878
+ jt({
879
+ resultOwner: t,
880
+ sql: e.card.sql,
881
+ normalizedPython: H(
882
+ e.card.python || ""
883
+ ),
884
+ records: e.records,
885
+ columns: e.columns,
886
+ columnSettings: (o = (n = e.card.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : o.columnSettingsMap,
887
+ preferences: e.preferences,
888
+ calendar: e.calendar
889
+ }),
890
+ e
891
+ );
892
+ }
893
+ function Ut(e) {
894
+ var n, o;
895
+ const r = e.effectiveCardConfig ?? e.card.config, t = Q(
896
+ e.card,
897
+ r
898
+ );
899
+ return ue({
900
+ cardType: e.card.type,
901
+ resultOwner: t,
902
+ effectiveCardConfig: r
903
+ }).length > 0 ? !0 : Nt(e) ? Object.values(
904
+ ((o = (n = e.card.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : o.columnSettingsMap) || {}
905
+ ).some(
906
+ (a) => {
907
+ var i;
908
+ return a.type === "date" && !((i = a.dateFormat) != null && i.useRelativeTime);
909
+ }
910
+ ) : !1;
911
+ }
912
+ function be(e, r) {
913
+ if (!r.executionSnapshot || e.kind === "inactive" || e.kind === "loading" || e.kind === "invalid")
914
+ return e;
915
+ if (!r.dashboardId)
916
+ return {
917
+ kind: "invalid",
918
+ error: new x(
919
+ "missing_raw_temporal_result_contract",
920
+ "A dashboard ID is required to resolve the captured raw temporal presentation."
921
+ )
922
+ };
923
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
924
+ for (const o of e.presentation.activatedColumnKeys) {
925
+ const a = nt({
926
+ snapshot: r.executionSnapshot,
927
+ scope: {
928
+ dashboardId: r.dashboardId,
929
+ cardId: r.card.id,
930
+ ...r.attachmentIndex !== void 0 ? { attachmentIndex: r.attachmentIndex } : {}
931
+ },
932
+ target: { kind: "column", columnKey: o }
933
+ });
934
+ if (!a)
935
+ return {
936
+ kind: "invalid",
937
+ error: new ot(o)
938
+ };
939
+ const i = e.presentation.byColumnKey.get(o);
940
+ if (!i) continue;
941
+ const l = {
942
+ ...i,
943
+ format: a,
944
+ formatValue: J({
945
+ metadata: i.metadata,
946
+ format: a
947
+ })
948
+ };
949
+ t.set(i.columnKey, l), i.fieldId && n.set(i.fieldId, l);
950
+ }
951
+ return {
952
+ ...e,
953
+ presentation: {
954
+ activatedColumnKeys: e.presentation.activatedColumnKeys,
955
+ byColumnKey: t,
956
+ byFieldId: n
957
+ }
958
+ };
959
+ }
960
+ function jt(e) {
961
+ var t, n;
962
+ if (e.resultOwner !== "freeform" || !((t = e.sql) != null && t.trim()) || (n = e.normalizedPython) != null && n.trim())
963
+ return { kind: "inactive" };
964
+ const r = Object.entries(
965
+ e.columnSettings || {}
966
+ ).filter(
967
+ ([, o]) => {
968
+ var a;
969
+ return o.type === "date" && !((a = o.dateFormat) != null && a.useRelativeTime);
970
+ }
971
+ );
972
+ if (r.length === 0) return { kind: "inactive" };
973
+ if (!e.records) return { kind: "loading" };
974
+ try {
975
+ const o = /* @__PURE__ */ new Map(), a = new Set(
976
+ r.map(([c]) => c)
977
+ ), i = /* @__PURE__ */ new Map(), l = [...e.columns || []];
978
+ for (const [c, s] of r) {
979
+ const u = me(
980
+ s.dateFormat
981
+ );
982
+ if (!u) continue;
983
+ const p = at({
984
+ columnKey: c,
985
+ values: e.records.map((I) => {
986
+ if (!Object.prototype.hasOwnProperty.call(I, c))
987
+ throw new x(
988
+ "missing_raw_temporal_result_contract",
989
+ `Declared SQL temporal column "${c}" is absent from a physical result row.`,
990
+ { columnKey: c }
991
+ );
992
+ const w = I[c];
993
+ return w === null || typeof w == "string" ? w : String(w);
994
+ })
995
+ });
996
+ if (i.set(c, p), p.status !== "classified") continue;
997
+ let d = l.findIndex(
998
+ (I) => I.key === c
999
+ );
1000
+ if (e.columns && d < 0)
1001
+ throw new x(
1002
+ "missing_raw_temporal_result_contract",
1003
+ `Classified SQL temporal column "${c}" is absent from result columns.`,
1004
+ { columnKey: c }
1005
+ );
1006
+ d < 0 && (d = l.length, l.push({
1007
+ key: c,
1008
+ name: c,
1009
+ label: c,
1010
+ role: "dimension",
1011
+ dataType: "string"
1012
+ }));
1013
+ const v = {
1014
+ ...l[d],
1015
+ role: "date",
1016
+ dataType: p.metadata.valueKind === "date" ? "date" : "datetime",
1017
+ rawTemporal: p.metadata
1018
+ };
1019
+ _e(v, {
1020
+ metadataRequired: !0
1021
+ }), l[d] = v;
1022
+ const h = q({
1023
+ format: u,
1024
+ preferences: e.preferences,
1025
+ calendar: e.calendar
1026
+ });
1027
+ o.set(c, {
1028
+ columnKey: c,
1029
+ metadata: p.metadata,
1030
+ format: h,
1031
+ formatValue: J({
1032
+ metadata: p.metadata,
1033
+ format: h
1034
+ })
1035
+ });
1036
+ }
1037
+ const m = {
1038
+ ...zt(),
1039
+ activatedColumnKeys: a,
1040
+ byColumnKey: o
1041
+ };
1042
+ return e.records.length === 0 ? {
1043
+ kind: "loaded_empty",
1044
+ presentation: m,
1045
+ adaptedColumns: l,
1046
+ sqlClassifications: i
1047
+ } : {
1048
+ kind: "loaded_valid",
1049
+ presentation: m,
1050
+ adaptedColumns: l,
1051
+ sqlClassifications: i
1052
+ };
1053
+ } catch (o) {
1054
+ return ie(
1055
+ o,
1056
+ new x(
1057
+ "invalid_raw_temporal_format",
1058
+ "Declared SQL raw temporal presentation is invalid."
1059
+ )
1060
+ );
1061
+ }
1062
+ }
1063
+ function xn(e) {
1064
+ if (e.value !== null && typeof e.value != "string")
1065
+ return {
1066
+ value: e.value,
1067
+ label: String(e.value),
1068
+ result: {
1069
+ ok: !1,
1070
+ text: String(e.value),
1071
+ diagnostic: {
1072
+ code: "invalid_raw_temporal_value",
1073
+ message: `Raw temporal column "${e.presentation.columnKey}" must contain a string or null.`
1074
+ }
1075
+ }
1076
+ };
1077
+ const r = e.presentation.formatValue(e.value);
1078
+ return { value: e.value, label: r.text, result: r };
1079
+ }
1080
+ function Sn(e) {
1081
+ if (!e.result || typeof e.result != "object") return !1;
1082
+ const r = e.result;
1083
+ if (e.expectedResultOwner !== void 0 && r.resultOwner !== e.expectedResultOwner)
1084
+ return !1;
1085
+ if (!Ut({
1086
+ card: e.card,
1087
+ effectiveCardConfig: e.effectiveCardConfig
1088
+ }))
1089
+ return !0;
1090
+ if (!Array.isArray(r.records)) return !1;
1091
+ const t = Lt({
1092
+ card: e.card,
1093
+ effectiveCardConfig: e.effectiveCardConfig,
1094
+ records: r.records,
1095
+ columns: r.columns,
1096
+ columnKeyMap: r.columnKeyMap,
1097
+ preferences: de,
1098
+ calendar: { tz: "UTC" }
1099
+ });
1100
+ return t.kind === "inactive" || t.kind === "loaded_empty" || t.kind === "loaded_valid";
1101
+ }
1102
+ function Ie(e) {
1103
+ return !e || typeof e != "object" ? !1 : Array.isArray(e.cards);
1104
+ }
1105
+ function qt(e) {
1106
+ if (!e)
1107
+ return null;
1108
+ if (typeof e == "string")
1109
+ try {
1110
+ const r = JSON.parse(e);
1111
+ return Ie(r) ? r : null;
1112
+ } catch {
1113
+ return null;
1114
+ }
1115
+ return Ie(e) ? e : null;
1116
+ }
1117
+ function Pe(e) {
1118
+ var r;
1119
+ return (r = e == null ? void 0 : e.cards) != null && r.length ? e.activeCardId && e.cards.find((t) => t.id === e.activeCardId) || e.cards[0] : null;
1120
+ }
1121
+ function _n(e) {
1122
+ var t;
1123
+ const r = (e == null ? void 0 : e.frameObject) ?? ((t = e == null ? void 0 : e.visual) == null ? void 0 : t.frameObject);
1124
+ return Pe(qt(r));
1125
+ }
1126
+ function fe(e) {
1127
+ if (!(e != null && e.expectedType)) return "table";
1128
+ const r = Array.isArray(e.expectedType) ? e.expectedType[0] : e.expectedType;
1129
+ return Ht(r) ? r : "table";
1130
+ }
1131
+ const Gt = [
1132
+ "bar",
1133
+ "horizontalBar",
1134
+ "line",
1135
+ "area",
1136
+ "stackedArea",
1137
+ "combo",
1138
+ "pie",
1139
+ "doughnut",
1140
+ "radar",
1141
+ "polarArea",
1142
+ "bubble",
1143
+ "scatter",
1144
+ "stackedBar",
1145
+ "stackedLine",
1146
+ "table",
1147
+ "pivotTable",
1148
+ "aggregateTable",
1149
+ "detailTable",
1150
+ "tableBuilder",
1151
+ "kpi",
1152
+ "pyramid",
1153
+ "tornado",
1154
+ "range",
1155
+ "text",
1156
+ "map",
1157
+ "funnel",
1158
+ "bullet",
1159
+ "heatmap",
1160
+ "treemap",
1161
+ "custom"
1162
+ ];
1163
+ function Ht(e) {
1164
+ return Gt.includes(e);
1165
+ }
1166
+ function G(e) {
1167
+ const r = e.position;
1168
+ if (typeof r == "number") return r;
1169
+ if (typeof r == "string") {
1170
+ const t = r.match(/\d+/);
1171
+ if (t) {
1172
+ const n = Number(t[0]);
1173
+ if (!Number.isNaN(n)) return n;
1174
+ }
1175
+ }
1176
+ return Number.POSITIVE_INFINITY;
1177
+ }
1178
+ function j(e) {
1179
+ if (typeof e == "number")
1180
+ return { kind: "number", start: e, end: e };
1181
+ if (typeof e == "string") {
1182
+ const r = e.match(/^(\d+)$/);
1183
+ if (r) {
1184
+ const o = Number(r[1]);
1185
+ return { kind: "number", start: o, end: o };
1186
+ }
1187
+ const t = e.match(/^(\d+)-(\d+)$/);
1188
+ if (t) {
1189
+ const o = Number(t[1]), a = Number(t[2]);
1190
+ return { kind: "range", start: o, end: a };
1191
+ }
1192
+ const n = e.match(/^(\d+)\+$/);
1193
+ if (n)
1194
+ return { kind: "dynamic", start: Number(n[1]), end: Number.POSITIVE_INFINITY };
1195
+ }
1196
+ return null;
1197
+ }
1198
+ function Me(e) {
1199
+ return !e || e.length === 0 ? void 0 : [...e].sort(
1200
+ (t, n) => G(t) - G(n)
1201
+ )[0];
1202
+ }
1203
+ function De(e, r) {
1204
+ if (!e || e.length === 0) return;
1205
+ const t = [], n = [], o = [];
1206
+ e.forEach((s) => {
1207
+ const u = j(s.position);
1208
+ u && (u.kind === "number" ? t.push(s) : u.kind === "range" ? n.push(s) : u.kind === "dynamic" && o.push(s));
1209
+ });
1210
+ const a = t.find((s) => {
1211
+ const u = j(s.position);
1212
+ return (u == null ? void 0 : u.kind) === "number" && u.start === r;
1213
+ });
1214
+ if (a) return a;
1215
+ const l = n.sort(
1216
+ (s, u) => G(s) - G(u)
1217
+ ).find((s) => {
1218
+ const u = j(s.position);
1219
+ return (u == null ? void 0 : u.kind) === "range" && r >= u.start && r <= u.end;
1220
+ });
1221
+ if (l) return l;
1222
+ const c = o.map((s) => ({
1223
+ slot: s,
1224
+ parsed: j(s.position)
1225
+ })).filter((s) => {
1226
+ var u;
1227
+ return ((u = s.parsed) == null ? void 0 : u.kind) === "dynamic";
1228
+ }).sort(
1229
+ (s, u) => {
1230
+ var p, d;
1231
+ return (((p = s.parsed) == null ? void 0 : p.start) ?? 0) - (((d = u.parsed) == null ? void 0 : d.start) ?? 0);
1232
+ }
1233
+ ).filter((s) => {
1234
+ var u;
1235
+ return r >= (((u = s.parsed) == null ? void 0 : u.start) ?? 0);
1236
+ }).sort(
1237
+ (s, u) => {
1238
+ var p, d;
1239
+ return (((p = u.parsed) == null ? void 0 : p.start) ?? 0) - (((d = s.parsed) == null ? void 0 : d.start) ?? 0);
1240
+ }
1241
+ )[0];
1242
+ return c == null ? void 0 : c.slot;
1243
+ }
1244
+ function Wt(e, r) {
1245
+ const t = De(e, r);
1246
+ if (t)
1247
+ return fe(t);
1248
+ }
1249
+ function Yt(e, r) {
1250
+ var n;
1251
+ const t = (n = e == null ? void 0 : e.customCardPreferences) == null ? void 0 : n.slotIndex;
1252
+ return typeof t == "number" ? t : r;
1253
+ }
1254
+ function we(e, r) {
1255
+ var t;
1256
+ if (!((t = e == null ? void 0 : e.customCardPreferences) != null && t.url))
1257
+ return !1;
1258
+ if (e.type === "custom" || e.customCardPreferences.visualType === "multiple" || e.customCardPreferences.dataInputCardIds || (e.customCardPreferences.minInputs || 0) > 1 || (e.customCardPreferences.maxInputs || 0) > 1)
1259
+ return !0;
1260
+ if (r && r.length > 1) {
1261
+ const n = r.filter(
1262
+ (o) => {
1263
+ var a;
1264
+ return typeof ((a = o.customCardPreferences) == null ? void 0 : a.slotIndex) == "number";
1265
+ }
1266
+ );
1267
+ if (n.length > 1 && n.some((o) => o.id !== e.id))
1268
+ return !0;
1269
+ }
1270
+ return !1;
1271
+ }
1272
+ function Zt(e) {
1273
+ const r = [];
1274
+ let t = -1;
1275
+ e.forEach((n, o) => {
1276
+ const a = Yt(n, o);
1277
+ a > t && (t = a), r[a] = n ?? null;
1278
+ });
1279
+ for (let n = 0; n <= t; n += 1)
1280
+ n in r || (r[n] = null);
1281
+ return r;
1282
+ }
1283
+ function Fn(e) {
1284
+ return e.map((r, t) => !r.customCardPreferences || r.customCardPreferences.slotIndex === t ? r : {
1285
+ ...r,
1286
+ customCardPreferences: {
1287
+ ...r.customCardPreferences,
1288
+ slotIndex: t
1289
+ }
1290
+ });
1291
+ }
1292
+ function Rn(e) {
1293
+ const r = Me(e);
1294
+ if (r)
1295
+ return fe(r);
1296
+ }
1297
+ function An(e, r, t) {
1298
+ if (!e) return;
1299
+ const n = Wt(t, r);
1300
+ return e.type === "custom" && n ? n : e.type;
1301
+ }
1302
+ function Bn(e, r, t) {
1303
+ var v;
1304
+ const n = {
1305
+ dataSource: t.dataSource,
1306
+ connectionId: t.connectionId,
1307
+ lastSelectedDatabase: t.lastSelectedDatabase,
1308
+ lastSelectedSchema: t.lastSelectedSchema,
1309
+ lastSelectedTable: t.lastSelectedTable,
1310
+ lastSelectedDatamodelId: t.lastSelectedDatamodelId,
1311
+ datamodelId: t.datamodelId
1312
+ }, o = {
1313
+ type: "component",
1314
+ visualType: "multiple",
1315
+ url: r.url,
1316
+ componentName: r.name,
1317
+ icon: r.icon,
1318
+ pluginChartType: r.chartType,
1319
+ minInputs: r.minInputs,
1320
+ maxInputs: r.maxInputs
1321
+ }, a = r.minInputs || 1, l = e.map((h) => ({ slot: h, parsed: j(h.position) })).filter((h) => h.parsed !== null).reduce((h, I) => {
1322
+ const w = I.parsed.end;
1323
+ return Number.isFinite(w) ? Math.max(h, w) : h;
1324
+ }, -1), m = Math.max(a, l + 1), c = Me(e), s = c ? G(c) : 0;
1325
+ let u = !1;
1326
+ const p = [];
1327
+ for (let h = 0; h < m; h += 1) {
1328
+ const I = De(e, h), w = fe(I), g = !u && h === s, $ = h, E = {
1329
+ ...n,
1330
+ id: st(),
1331
+ title: (g ? c == null ? void 0 : c.label : I == null ? void 0 : I.label) || `Tab ${h + 1}`,
1332
+ tabTitle: (g ? c == null ? void 0 : c.label : I == null ? void 0 : I.label) || `Tab ${h + 1}`,
1333
+ description: (g ? c == null ? void 0 : c.description : I == null ? void 0 : I.description) || "",
1334
+ type: w,
1335
+ sql: "",
1336
+ preferences: {
1337
+ onClickFilter: [{ columnIndex: 0, expression: "" }]
1338
+ },
1339
+ ...g && {
1340
+ customCardPreferences: {
1341
+ ...o,
1342
+ slotIndex: $
1343
+ }
1344
+ },
1345
+ ...!g && {
1346
+ customCardPreferences: {
1347
+ slotIndex: $
1348
+ }
1349
+ }
1350
+ };
1351
+ g && (u = !0), p.push(E);
1352
+ }
1353
+ if (!u && p.length > 0) {
1354
+ const h = ((v = p[0].customCardPreferences) == null ? void 0 : v.slotIndex) ?? 0;
1355
+ p[0] = {
1356
+ ...p[0],
1357
+ type: p[0].type,
1358
+ customCardPreferences: {
1359
+ ...o,
1360
+ slotIndex: h
1361
+ }
1362
+ };
1363
+ }
1364
+ const d = p.findIndex(
1365
+ (h) => {
1366
+ var I;
1367
+ return !!((I = h.customCardPreferences) != null && I.url);
1368
+ }
1369
+ );
1370
+ if (d > 0) {
1371
+ const [h] = p.splice(d, 1);
1372
+ p.unshift(h);
1373
+ }
1374
+ return p;
1375
+ }
1376
+ function Jt({
1377
+ frame: e,
1378
+ configCard: r,
1379
+ isMultiInputVisual: t
1380
+ }) {
1381
+ var o;
1382
+ if (!t || !r)
1383
+ return e.cards;
1384
+ const n = (o = r.customCardPreferences) == null ? void 0 : o.dataInputCardIds;
1385
+ return n ? Object.keys(n).sort((a, i) => Number(a) - Number(i)).map((a) => {
1386
+ var l;
1387
+ const i = (l = n[a]) == null ? void 0 : l.cardId;
1388
+ return e.cards.find((m) => m.id === i) || null;
1389
+ }) : e.cards;
1390
+ }
1391
+ function Qt(e, r) {
1392
+ return r && we(r, e.cards) ? r : e.cards.find((t) => we(t, e.cards)) || null;
1393
+ }
1394
+ function Xt(e, r) {
1395
+ var o, a;
1396
+ if (!e) return null;
1397
+ const t = r == null ? void 0 : r.visualType;
1398
+ if (t) return t;
1399
+ if (r != null && r.slots && r.slots.length > 0 || ((r == null ? void 0 : r.minInputs) || 0) > 1 || ((r == null ? void 0 : r.maxInputs) || 0) > 1 || ((r == null ? void 0 : r.dataInputs) || []).length > 1)
1400
+ return "multiple";
1401
+ const n = (o = e.customCardPreferences) == null ? void 0 : o.visualType;
1402
+ return n || ((a = e.customCardPreferences) != null && a.dataInputCardIds ? "multiple" : null);
1403
+ }
1404
+ function Pn(e) {
1405
+ return e.visualType === "multiple" || e.slots && e.slots.length > 0 || (e.minInputs || 0) > 1 || (e.maxInputs || 0) > 1 || (e.dataInputs || []).length > 1 ? "multiple" : "single";
1406
+ }
1407
+ function Mn(e) {
1408
+ return Array.isArray(e) ? { records: e } : e;
1409
+ }
1410
+ class W extends Error {
1411
+ constructor(t) {
1412
+ const n = t.cardId ? `card "${t.cardId}"` : t.sheetId ? `sheet "${t.sheetId}"` : `dashboard "${t.dashboardId}"`;
1413
+ super(
1414
+ `Unable to resolve ${n} while capturing report presentation. Refresh the authoring page and select the attachment again.`
1415
+ );
1416
+ S(this, "code", "temporal_snapshot_target_not_found");
1417
+ S(this, "selection");
1418
+ this.name = "TemporalSnapshotSelectionError", this.selection = t;
1419
+ }
1420
+ }
1421
+ function er(e, r) {
1422
+ var o;
1423
+ const t = [], n = /* @__PURE__ */ new Map();
1424
+ for (const a of r) {
1425
+ if (a.dashboardId !== e.id)
1426
+ throw new W(a);
1427
+ const i = (e.sheets || []).filter(
1428
+ (m) => !a.sheetId || a.sheetId === m.id
1429
+ );
1430
+ if (a.sheetId && i.length === 0)
1431
+ throw new W(a);
1432
+ let l = !a.cardId;
1433
+ for (const m of i) {
1434
+ const c = (((o = m.document) == null ? void 0 : o.sections) || []).flatMap(
1435
+ (p) => p.type === "table" || p.type === "chart" ? [p.card] : []
1436
+ ), s = (m.frames || []).flatMap(
1437
+ (p) => tr(p, a.cardId)
1438
+ );
1439
+ s.length > 0 && (l = !0);
1440
+ const u = [
1441
+ ...s,
1442
+ ...(m.cards || []).filter(
1443
+ (p) => !a.cardId || a.cardId === p.id
1444
+ ),
1445
+ ...c.filter(
1446
+ (p) => !a.cardId || a.cardId === p.id
1447
+ )
1448
+ ];
1449
+ for (const p of u) {
1450
+ l = !0;
1451
+ const d = n.get(a.attachmentIndex) ?? /* @__PURE__ */ new Set();
1452
+ d.has(p.id) || (d.add(p.id), n.set(a.attachmentIndex, d), t.push({
1453
+ card: p,
1454
+ ...a.attachmentIndex !== void 0 ? { attachmentIndex: a.attachmentIndex } : {}
1455
+ }));
1456
+ }
1457
+ }
1458
+ if (!l)
1459
+ throw new W(a);
1460
+ }
1461
+ return t;
1462
+ }
1463
+ function tr(e, r) {
1464
+ var i;
1465
+ const t = r ? (i = e.cards) == null ? void 0 : i.find((l) => l.id === r) : Pe(e);
1466
+ if (!t) return [];
1467
+ const n = Qt(e, t), o = (e.cards || []).filter(
1468
+ (l) => {
1469
+ var m;
1470
+ return typeof ((m = l.customCardPreferences) == null ? void 0 : m.slotIndex) == "number";
1471
+ }
1472
+ ).length > 1, a = n != null && (Xt(n) === "multiple" || o);
1473
+ return !n || !a ? [t] : Zt(
1474
+ Jt({
1475
+ frame: e,
1476
+ configCard: n,
1477
+ isMultiInputVisual: !0
1478
+ })
1479
+ ).filter((l) => l !== null);
1480
+ }
1481
+ function Dn(e) {
1482
+ return er(e.dashboard, e.selections).flatMap(
1483
+ ({ card: r, attachmentIndex: t }) => {
1484
+ var s, u, p, d;
1485
+ const n = ((s = e.resolveCardConfig) == null ? void 0 : s.call(e, r)) ?? r.config, o = Ft({
1486
+ card: r,
1487
+ cardConfig: n
1488
+ }), a = {
1489
+ dashboardId: e.dashboard.id,
1490
+ cardId: r.id,
1491
+ ...t !== void 0 ? { attachmentIndex: t } : {}
1492
+ }, i = o ? o.fields.map((v) => ({
1493
+ scope: a,
1494
+ target: {
1495
+ kind: "field",
1496
+ fieldId: v.id,
1497
+ role: v.role
1498
+ },
1499
+ format: Ot(
1500
+ v,
1501
+ {
1502
+ dateStyle: e.valueFormatPreferences.dateStyle,
1503
+ dateTime: { ...e.valueFormatPreferences.dateTime }
1504
+ },
1505
+ e.valueFormatPreferences.locale
1506
+ )
1507
+ })) : [], l = [], m = Q(r, n), c = H(
1508
+ r.python || ""
1509
+ );
1510
+ if (r.type === "detailTable" && m === "config") {
1511
+ const v = (n == null ? void 0 : n.detailColumns) || [], h = [
1512
+ ...((n == null ? void 0 : n.groupByColumns) || []).map((g) => ({
1513
+ field: g,
1514
+ role: "groupby"
1515
+ })),
1516
+ ...((n == null ? void 0 : n.metricColumns) || []).map((g) => ({
1517
+ field: g,
1518
+ role: "metric"
1519
+ })),
1520
+ ...((n == null ? void 0 : n.pivotByColumns) || []).map((g) => ({
1521
+ field: g,
1522
+ role: "pivotby"
1523
+ })),
1524
+ ...v.map((g) => ({
1525
+ field: g,
1526
+ role: "detail"
1527
+ }))
1528
+ ], I = /* @__PURE__ */ new Map(), w = new Set(
1529
+ h.map(
1530
+ ({ field: g, role: $ }) => Tt(g, $)
1531
+ )
1532
+ );
1533
+ for (const { field: g } of h) {
1534
+ const $ = g.label;
1535
+ $ && I.set($, (I.get($) || 0) + 1);
1536
+ }
1537
+ for (const g of v) {
1538
+ if (g.dateValueMode !== "canonical") continue;
1539
+ const $ = $t(g), E = g.label, F = kt({
1540
+ label: E,
1541
+ labelCount: E && I.get(E) || 0,
1542
+ rawKey: $,
1543
+ rawKeys: w
1544
+ });
1545
+ if (!F) throw new W(a);
1546
+ l.push({
1547
+ scope: a,
1548
+ target: { kind: "column", columnKey: F },
1549
+ format: q({
1550
+ format: Be(g),
1551
+ preferences: e.valueFormatPreferences,
1552
+ calendar: e.calendar
1553
+ })
1554
+ });
1555
+ }
1556
+ } else if (m === "freeform" && ((u = r.sql) != null && u.trim()) && !c.trim())
1557
+ for (const [v, h] of Object.entries(
1558
+ ((d = (p = r.preferences) == null ? void 0 : p.tablePrefs) == null ? void 0 : d.columnSettingsMap) || {}
1559
+ )) {
1560
+ if (h.type !== "date") continue;
1561
+ const I = me(
1562
+ h.dateFormat
1563
+ );
1564
+ I && l.push({
1565
+ scope: a,
1566
+ target: { kind: "column", columnKey: v },
1567
+ format: q({
1568
+ format: I,
1569
+ preferences: e.valueFormatPreferences,
1570
+ calendar: e.calendar
1571
+ })
1572
+ });
1573
+ }
1574
+ return [...i, ...l];
1575
+ }
1576
+ );
1577
+ }
1578
+ function rr(e) {
1579
+ return !!e && typeof e == "object" && !Array.isArray(e);
1580
+ }
1581
+ function A(e, r, t) {
1582
+ return rr(e) ? e : (t.push({ field: r, message: "Expected an object." }), {});
1583
+ }
1584
+ function B(e, r, t, n) {
1585
+ const o = new Set(t);
1586
+ Object.keys(e).forEach((a) => {
1587
+ o.has(a) || n.push({
1588
+ field: `${r}.${a}`,
1589
+ message: "Unexpected property."
1590
+ });
1591
+ });
1592
+ }
1593
+ function M(e, r, t, n, o = {}) {
1594
+ if (e == null)
1595
+ return;
1596
+ if (typeof e != "string") {
1597
+ n.push({ field: r, message: "Expected a string." });
1598
+ return;
1599
+ }
1600
+ const a = o.trim === !1 ? e : e.trim();
1601
+ if (!o.allowEmpty && a.length === 0) {
1602
+ n.push({ field: r, message: "Expected a non-empty string." });
1603
+ return;
1604
+ }
1605
+ if (a.length > t) {
1606
+ n.push({
1607
+ field: r,
1608
+ message: `Expected ${t} characters or fewer.`
1609
+ });
1610
+ return;
1611
+ }
1612
+ return a;
1613
+ }
1614
+ function pe(e, r, t) {
1615
+ const n = M(e, r, 2e3, t);
1616
+ if (n)
1617
+ try {
1618
+ return new URL(n), n;
1619
+ } catch {
1620
+ t.push({ field: r, message: "Expected an absolute URL." });
1621
+ return;
1622
+ }
1623
+ }
1624
+ function Ce(e, r, t) {
1625
+ const n = A(e, r, t);
1626
+ B(n, r, ["tokens", "components"], t);
1627
+ const o = {};
1628
+ if (n.tokens !== void 0) {
1629
+ const a = A(n.tokens, `${r}.tokens`, t);
1630
+ B(
1631
+ a,
1632
+ `${r}.tokens`,
1633
+ ["color", "typography"],
1634
+ t
1635
+ );
1636
+ const i = {};
1637
+ if (a.color !== void 0) {
1638
+ const l = A(
1639
+ a.color,
1640
+ `${r}.tokens.color`,
1641
+ t
1642
+ ), m = [
1643
+ "background",
1644
+ "foreground",
1645
+ "muted",
1646
+ "mutedForeground",
1647
+ "border",
1648
+ "primary",
1649
+ "primaryForeground",
1650
+ "positive",
1651
+ "negative",
1652
+ "warning",
1653
+ "info"
1654
+ ];
1655
+ B(l, `${r}.tokens.color`, m, t);
1656
+ const c = {};
1657
+ m.forEach((s) => {
1658
+ const u = M(
1659
+ l[s],
1660
+ `${r}.tokens.color.${s}`,
1661
+ 120,
1662
+ t
1663
+ );
1664
+ u !== void 0 && (c[s] = u);
1665
+ }), i.color = c;
1666
+ }
1667
+ if (a.typography !== void 0) {
1668
+ const l = A(
1669
+ a.typography,
1670
+ `${r}.tokens.typography`,
1671
+ t
1672
+ );
1673
+ B(
1674
+ l,
1675
+ `${r}.tokens.typography`,
1676
+ ["fontFamily", "monoFontFamily"],
1677
+ t
1678
+ );
1679
+ const m = M(
1680
+ l.fontFamily,
1681
+ `${r}.tokens.typography.fontFamily`,
1682
+ 500,
1683
+ t,
1684
+ { allowEmpty: !0 }
1685
+ ), c = M(
1686
+ l.monoFontFamily,
1687
+ `${r}.tokens.typography.monoFontFamily`,
1688
+ 500,
1689
+ t,
1690
+ { allowEmpty: !0 }
1691
+ );
1692
+ i.typography = {
1693
+ ...m !== void 0 ? { fontFamily: m } : {},
1694
+ ...c !== void 0 ? { monoFontFamily: c } : {}
1695
+ };
1696
+ }
1697
+ o.tokens = i;
1698
+ }
1699
+ if (n.components !== void 0) {
1700
+ const a = A(
1701
+ n.components,
1702
+ `${r}.components`,
1703
+ t
1704
+ );
1705
+ if (B(a, `${r}.components`, ["chart"], t), a.chart !== void 0) {
1706
+ const i = A(
1707
+ a.chart,
1708
+ `${r}.components.chart`,
1709
+ t
1710
+ );
1711
+ B(i, `${r}.components.chart`, ["palette"], t);
1712
+ let l;
1713
+ i.palette !== void 0 && (Array.isArray(i.palette) ? i.palette.length > 20 ? t.push({
1714
+ field: `${r}.components.chart.palette`,
1715
+ message: "Expected 20 colors or fewer."
1716
+ }) : l = i.palette.map(
1717
+ (m, c) => M(
1718
+ m,
1719
+ `${r}.components.chart.palette.${c}`,
1720
+ 120,
1721
+ t
1722
+ )
1723
+ ).filter((m) => m !== void 0) : t.push({
1724
+ field: `${r}.components.chart.palette`,
1725
+ message: "Expected an array."
1726
+ })), o.components = {
1727
+ chart: l ? { palette: l } : {}
1728
+ };
1729
+ }
1730
+ }
1731
+ return o;
1732
+ }
1733
+ function nr(e, r) {
1734
+ const t = "presentation.appearance", n = A(e, t, r);
1735
+ B(n, t, ["version", "schemes"], r);
1736
+ const o = {};
1737
+ if (n.version !== void 0 && (typeof n.version != "number" || !Number.isFinite(n.version) ? r.push({ field: `${t}.version`, message: "Expected a number." }) : o.version = n.version), n.schemes !== void 0) {
1738
+ const a = A(n.schemes, `${t}.schemes`, r);
1739
+ B(a, `${t}.schemes`, ["light", "dark"], r), o.schemes = {
1740
+ ...a.light !== void 0 ? {
1741
+ light: Ce(
1742
+ a.light,
1743
+ `${t}.schemes.light`,
1744
+ r
1745
+ )
1746
+ } : {},
1747
+ ...a.dark !== void 0 ? {
1748
+ dark: Ce(
1749
+ a.dark,
1750
+ `${t}.schemes.dark`,
1751
+ r
1752
+ )
1753
+ } : {}
1754
+ };
1755
+ }
1756
+ return o;
1757
+ }
1758
+ function or(e, r) {
1759
+ const t = "presentation.brandOverrides", n = A(e, t, r);
1760
+ B(n, t, ["brandName", "logoUrl", "link"], r);
1761
+ const o = M(
1762
+ n.brandName,
1763
+ `${t}.brandName`,
1764
+ 200,
1765
+ r
1766
+ ), a = pe(n.logoUrl, `${t}.logoUrl`, r), i = M(n.link, `${t}.link`, 120, r);
1767
+ return {
1768
+ ...o !== void 0 ? { brandName: o } : {},
1769
+ ...a !== void 0 ? { logoUrl: a } : {},
1770
+ ...i !== void 0 ? { link: i } : {}
1771
+ };
1772
+ }
1773
+ function ar(e, r) {
1774
+ const t = "presentation.fragments", n = A(e, t, r), o = [
1775
+ "preHeaderText",
1776
+ "headerBannerHtml",
1777
+ "signatureHtml",
1778
+ "footerHtml",
1779
+ "disclaimerHtml",
1780
+ "unsubscribeUrl"
1781
+ ];
1782
+ B(n, t, o, r);
1783
+ const a = {};
1784
+ return o.forEach((i) => {
1785
+ const l = i === "unsubscribeUrl" ? pe(n[i], `${t}.${i}`, r) : M(
1786
+ n[i],
1787
+ `${t}.${i}`,
1788
+ i === "preHeaderText" ? 200 : 5e3,
1789
+ r,
1790
+ { trim: i === "preHeaderText" }
1791
+ );
1792
+ l !== void 0 && (a[i] = l);
1793
+ }), a;
1794
+ }
1795
+ function ir(e) {
1796
+ const r = [], t = {};
1797
+ if (e.appearance !== void 0 && (t.appearance = nr(e.appearance, r)), e.brandOverrides !== void 0 && (t.brandOverrides = or(e.brandOverrides, r)), e.fragments !== void 0 && (t.fragments = ar(e.fragments, r)), e.viewUrl !== void 0) {
1798
+ const n = pe(e.viewUrl, "presentation.viewUrl", r);
1799
+ n !== void 0 && (t.viewUrl = n);
1800
+ }
1801
+ return { value: t, issues: r };
1802
+ }
1803
+ const Oe = [
1804
+ "SUN",
1805
+ "MON",
1806
+ "TUE",
1807
+ "WED",
1808
+ "THU",
1809
+ "FRI",
1810
+ "SAT"
1811
+ ], cr = new Map(
1812
+ Oe.map((e, r) => [e, r])
1813
+ ), On = {
1814
+ cadence: "weekly",
1815
+ hour: 9,
1816
+ minute: 0,
1817
+ weekdays: [1]
1818
+ };
1819
+ function Kn(e) {
1820
+ if (typeof e != "string" || e.length === 0 || e !== e.trim() || /^(?:(?:UTC|GMT)[+-]|[+-]\d{2}:\d{2}$)/.test(e))
1821
+ return !1;
1822
+ try {
1823
+ return new Intl.DateTimeFormat("en-US", { timeZone: e }).format(), !0;
1824
+ } catch {
1825
+ return !1;
1826
+ }
1827
+ }
1828
+ function lr(e) {
1829
+ return Number.isInteger(e.minute) && e.minute >= 0 && e.minute <= 59 && Number.isInteger(e.hour) && e.hour >= 0 && e.hour <= 23;
1830
+ }
1831
+ function Ke(e) {
1832
+ if (e.length === 0) return null;
1833
+ const r = [...e].sort((t, n) => t - n);
1834
+ return r.some(
1835
+ (t, n) => !Number.isInteger(t) || t < 0 || t > 6 || n > 0 && t === r[n - 1]
1836
+ ) ? null : r;
1837
+ }
1838
+ function Nn(e) {
1839
+ if (!lr(e))
1840
+ throw new Error("Choose a valid schedule time.");
1841
+ const r = `${e.minute} ${e.hour}`;
1842
+ switch (e.cadence) {
1843
+ case "daily":
1844
+ return `${r} * * *`;
1845
+ case "weekly": {
1846
+ const t = Ke(e.weekdays);
1847
+ if (!t) throw new Error("Choose at least one weekday.");
1848
+ return `${r} * * ${t.map((n) => Oe[n]).join(",")}`;
1849
+ }
1850
+ case "twice_monthly":
1851
+ return `${r} 1,15 * *`;
1852
+ case "monthly":
1853
+ return `${r} 1 * *`;
1854
+ }
1855
+ }
1856
+ function dr(e) {
1857
+ if (typeof e != "string" || e.length === 0)
1858
+ return { ok: !1, issue: "Choose a supported schedule." };
1859
+ if (e !== e.trim() || e.includes(" "))
1860
+ return { ok: !1, issue: "Choose a supported schedule." };
1861
+ const r = e.split(" ");
1862
+ if (r.length !== 5)
1863
+ return { ok: !1, issue: "Choose a supported schedule." };
1864
+ const [t, n, o, a, i] = r;
1865
+ if (!/^(0|[1-9]\d?)$/.test(t) || !/^(0|[1-9]\d?)$/.test(n))
1866
+ return { ok: !1, issue: "Choose a supported schedule." };
1867
+ const l = Number(t), m = Number(n);
1868
+ if (l > 59 || m > 23 || a !== "*")
1869
+ return { ok: !1, issue: "Choose a supported schedule." };
1870
+ if (o === "*" && i === "*")
1871
+ return {
1872
+ ok: !0,
1873
+ value: { cadence: "daily", hour: m, minute: l, weekdays: [] }
1874
+ };
1875
+ if (o === "*" && i !== "*") {
1876
+ const s = i.split(",").map((d) => cr.get(d));
1877
+ if (s.some((d) => d === void 0))
1878
+ return { ok: !1, issue: "Choose a supported schedule." };
1879
+ const u = s, p = Ke(u);
1880
+ return !p || p.some((d, v) => d !== u[v]) ? { ok: !1, issue: "Choose a supported schedule." } : {
1881
+ ok: !0,
1882
+ value: { cadence: "weekly", hour: m, minute: l, weekdays: p }
1883
+ };
1884
+ }
1885
+ return o === "1,15" && i === "*" ? {
1886
+ ok: !0,
1887
+ value: { cadence: "twice_monthly", hour: m, minute: l, weekdays: [] }
1888
+ } : o === "1" && i === "*" ? {
1889
+ ok: !0,
1890
+ value: { cadence: "monthly", hour: m, minute: l, weekdays: [] }
1891
+ } : { ok: !1, issue: "Choose a supported schedule." };
1892
+ }
1893
+ function sr(e, r, t) {
1894
+ return new Intl.DateTimeFormat(t, {
1895
+ hour: "numeric",
1896
+ minute: "2-digit",
1897
+ timeZone: "UTC"
1898
+ }).format(new Date(Date.UTC(2020, 0, 1, e, r)));
1899
+ }
1900
+ function mr(e, r) {
1901
+ var t;
1902
+ if (e === "UTC") return "UTC";
1903
+ try {
1904
+ return ((t = new Intl.DateTimeFormat(r, {
1905
+ timeZone: e,
1906
+ timeZoneName: "longGeneric"
1907
+ }).formatToParts(new Date(Date.UTC(2020, 0, 1))).find((o) => o.type === "timeZoneName")) == null ? void 0 : t.value) ?? e;
1908
+ } catch {
1909
+ return null;
1910
+ }
1911
+ }
1912
+ function zn(e, r, t = "en-US") {
1913
+ const n = dr(e);
1914
+ if (!n.ok) return null;
1915
+ try {
1916
+ const o = sr(n.value.hour, n.value.minute, t), a = mr(r, t);
1917
+ if (!a) return null;
1918
+ switch (n.value.cadence) {
1919
+ case "daily":
1920
+ return `Daily at ${o} ${a}`;
1921
+ case "weekly": {
1922
+ const i = new Intl.DateTimeFormat(t, {
1923
+ weekday: "long",
1924
+ timeZone: "UTC"
1925
+ });
1926
+ return `${n.value.weekdays.map(
1927
+ (m) => i.format(new Date(Date.UTC(2023, 0, 1 + m)))
1928
+ ).join(" and ")} at ${o} ${a}`;
1929
+ }
1930
+ case "twice_monthly":
1931
+ return `On the 1st and 15th at ${o} ${a}`;
1932
+ case "monthly":
1933
+ return `Monthly on the 1st at ${o} ${a}`;
1934
+ }
1935
+ } catch {
1936
+ return null;
1937
+ }
1938
+ }
1939
+ const ur = /* @__PURE__ */ new Set([
1940
+ "table",
1941
+ "aggregateTable",
1942
+ "pivotTable",
1943
+ "detailTable"
1944
+ ]), fr = /* @__PURE__ */ new Set([
1945
+ "bar",
1946
+ "horizontalBar",
1947
+ "line",
1948
+ "area",
1949
+ "stackedArea",
1950
+ "combo",
1951
+ "pie",
1952
+ "doughnut",
1953
+ "radar",
1954
+ "polarArea",
1955
+ "bubble",
1956
+ "scatter",
1957
+ "stackedBar",
1958
+ "stackedLine",
1959
+ "table",
1960
+ "pivotTable",
1961
+ "aggregateTable",
1962
+ "matrixTable",
1963
+ "detailTable",
1964
+ "kpi",
1965
+ "pyramid",
1966
+ "tornado",
1967
+ "range",
1968
+ "map",
1969
+ "funnel",
1970
+ "bullet",
1971
+ "heatmap",
1972
+ "treemap",
1973
+ "custom"
1974
+ ]);
1975
+ function Vn(e) {
1976
+ var n, o, a;
1977
+ const r = fr.has(e.type) && (e.type !== "custom" || !!((n = e.customCardPreferences) != null && n.url));
1978
+ return e.type === "text" || !r || mt(e) ? { formats: [], defaultFormat: null } : {
1979
+ formats: pr({
1980
+ cardType: e.type,
1981
+ allowDownload: (o = e.preferences) == null ? void 0 : o.allowDownload
1982
+ }),
1983
+ defaultFormat: yr({
1984
+ cardType: e.type,
1985
+ allowDownload: (a = e.preferences) == null ? void 0 : a.allowDownload
1986
+ })
1987
+ };
1988
+ }
1989
+ function pr(e) {
1990
+ return e.allowDownload === !1 ? ["pdf"] : ["pdf", "csv"];
1991
+ }
1992
+ function yr(e) {
1993
+ return ur.has(e.cardType) && e.allowDownload !== !1 ? "csv" : "pdf";
1994
+ }
1995
+ function Ln(e) {
1996
+ return e != null && e.role ? e.type === "tenant" ? e.role === "POWER_USER" : ["AUTHOR", "ADMIN", "SUPER_ADMIN"].includes(e.role) : !1;
1997
+ }
1998
+ function Un(e) {
1999
+ return e.canCreate ? [
2000
+ ...e.scheduledReportAvailable ? ["scheduled_report"] : [],
2001
+ ...e.analyticalBriefingsEnabled ? ["analytical_briefing"] : []
2002
+ ] : [];
2003
+ }
2004
+ function hr(e) {
2005
+ const r = (e == null ? void 0 : e.channels) ?? [];
2006
+ return r.length === 1 && r[0] === "EMAIL";
2007
+ }
2008
+ function gr(e) {
2009
+ return e.body.type === "generated_analysis" ? "Analytical briefing" : e.body.type === "custom_message" && e.attachments.length > 0 && hr(e.deliveryConfig) ? e.scheduleExpr ? "Scheduled report" : "On-demand report" : "Plain briefing";
2010
+ }
2011
+ function jn(e) {
2012
+ const r = gr(e), t = r === "Scheduled report" || r === "On-demand report" ? "report" : "briefing";
2013
+ return {
2014
+ typeLabel: r,
2015
+ noun: t,
2016
+ pluralNoun: t === "report" ? "reports" : "briefings"
2017
+ };
2018
+ }
2019
+ const ce = "BRIEFING", vr = ["markdown", "html"], le = ["markdown"], te = 20, y = {
2020
+ name: 500,
2021
+ description: 2e3,
2022
+ instruction: 5e4,
2023
+ customMessage: 5e4,
2024
+ contentTitle: 500,
2025
+ contentSummary: 2e4,
2026
+ contentText: 5e3,
2027
+ contentSql: 5e4,
2028
+ contentItem: 2e3,
2029
+ contentCell: 500,
2030
+ attachmentTitle: 500,
2031
+ presentationAudience: 1e3,
2032
+ presentationTone: 500,
2033
+ presentationFormat: 2e3,
2034
+ id: 500
2035
+ }, _ = {
2036
+ maxBlocks: 50,
2037
+ maxTableRows: 100,
2038
+ maxTableColumns: 20,
2039
+ maxTableCellCharacters: y.contentCell,
2040
+ maxParagraphCharacters: y.contentText,
2041
+ maxFindingCharacters: y.contentText,
2042
+ maxListItems: 100,
2043
+ // A kpi_grid is rendered as a 2-up tile arrangement in emails. Cap at 8 so
2044
+ // the visual stays at most 4 rows (4 columns wide on desktop would force
2045
+ // tiny tiles in narrow client panels; 2-up was the chosen layout).
2046
+ maxKpiTiles: 8
2047
+ };
2048
+ function br(e) {
2049
+ if (e === null || typeof e != "object" || Array.isArray(e))
2050
+ return !1;
2051
+ const r = e;
2052
+ if (typeof r.value != "number" || !Number.isFinite(r.value))
2053
+ return !1;
2054
+ const t = r.target;
2055
+ if (t === null || typeof t != "object" || Array.isArray(t))
2056
+ return !1;
2057
+ const n = t;
2058
+ return (n.kind === "metric" && typeof n.metricId == "string" && !!n.metricId.trim() || n.kind === "column" && typeof n.columnKey == "string" && !!n.columnKey.trim() || n.kind === "matrix_measure" && typeof n.measureId == "string" && !!n.measureId.trim()) && Te(r.format).ok;
2059
+ }
2060
+ function Ir(e) {
2061
+ return e == null ? "" : br(e) ? ct(e.value, e.format) : String(e);
2062
+ }
2063
+ function qn(e) {
2064
+ return [e.delta, e.percentChange].filter(
2065
+ (r) => r != null
2066
+ ).map(Ir).filter(Boolean).join(" / ");
2067
+ }
2068
+ const Ne = new Set(vr), wr = /* @__PURE__ */ new Set([
2069
+ "EMAIL",
2070
+ "WEBHOOK",
2071
+ "SLACK",
2072
+ "IN_APP",
2073
+ "TELEGRAM"
2074
+ ]), re = {
2075
+ maxToolCalls: { min: 1, max: 100 },
2076
+ maxPlanningIterations: { min: 1, max: 10 },
2077
+ maxRows: { min: 1, max: 1e5 },
2078
+ timeoutMs: { min: 1e3, max: 30 * 6e4 }
2079
+ }, Cr = /* @__PURE__ */ new Set([
2080
+ "letter",
2081
+ "legal",
2082
+ "a4",
2083
+ "a3",
2084
+ "tabloid"
2085
+ ]), Tr = /* @__PURE__ */ new Set([
2086
+ "portrait",
2087
+ "landscape"
2088
+ ]), $r = /* @__PURE__ */ new Set([",", ";", " "]), kr = /* @__PURE__ */ new Set([
2089
+ "current",
2090
+ "all"
2091
+ ]), Er = /* @__PURE__ */ new Set([
2092
+ "concise",
2093
+ "balanced",
2094
+ "detailed"
2095
+ ]), xr = /* @__PURE__ */ new Set([
2096
+ "info",
2097
+ "positive",
2098
+ "warning",
2099
+ "critical"
2100
+ ]), Sr = /* @__PURE__ */ new Set([
2101
+ "text",
2102
+ "number",
2103
+ "currency",
2104
+ "percent",
2105
+ "date",
2106
+ "boolean"
2107
+ ]), _r = /* @__PURE__ */ new Set([
2108
+ "left",
2109
+ "center",
2110
+ "right"
2111
+ ]), Fr = [
2112
+ "pageSize",
2113
+ "orientation",
2114
+ "includeFilters",
2115
+ "includeTimestamp",
2116
+ "delimiter",
2117
+ "includeHeaders",
2118
+ "useFormattedValues",
2119
+ "sheetSelection",
2120
+ "currentSheetId",
2121
+ "currentSheetName",
2122
+ "filterValues",
2123
+ "inlineFilterValues",
2124
+ "sheetFilterValues",
2125
+ "filterLine",
2126
+ "controlValues",
2127
+ "controlDefinitions",
2128
+ "cardControlDefinitions",
2129
+ "controlBindings",
2130
+ "tablePreferences",
2131
+ "dashboardInputExecutionSnapshot",
2132
+ "selectedSheetId",
2133
+ "cardType",
2134
+ "allowDownload",
2135
+ "theme"
2136
+ ];
2137
+ class X extends Error {
2138
+ constructor(t) {
2139
+ super(t.map((n) => `${n.field}: ${n.message}`).join("; "));
2140
+ S(this, "issues");
2141
+ this.name = "BriefingContractError", this.issues = t;
2142
+ }
2143
+ }
2144
+ function ze(e) {
2145
+ return typeof e == "object" && e !== null && !Array.isArray(e);
2146
+ }
2147
+ function f(e, r, t) {
2148
+ e.push({ field: r, message: t });
2149
+ }
2150
+ function k(e, r, t) {
2151
+ return ze(e) ? e : (f(t, r, "Expected an object."), {});
2152
+ }
2153
+ function b(e, r, t, n) {
2154
+ const o = new Set(t);
2155
+ Object.keys(e).forEach((a) => {
2156
+ o.has(a) || f(
2157
+ n,
2158
+ r ? `${r}.${a}` : a,
2159
+ `Unexpected field "${a}".`
2160
+ );
2161
+ });
2162
+ }
2163
+ function C(e, r, t, n) {
2164
+ if (typeof e != "string")
2165
+ return f(n, r, "Expected a string."), "";
2166
+ const o = e.trim();
2167
+ return o ? (o.length > t && f(n, r, `Must be ${t} characters or fewer.`), o) : (f(n, r, "Required value cannot be empty."), "");
2168
+ }
2169
+ function T(e, r, t, n) {
2170
+ if (e == null)
2171
+ return;
2172
+ if (typeof e != "string") {
2173
+ f(n, r, "Expected a string.");
2174
+ return;
2175
+ }
2176
+ const o = e.trim();
2177
+ if (o)
2178
+ return o.length > t && f(n, r, `Must be ${t} characters or fewer.`), o;
2179
+ }
2180
+ function Rr(e, r, t, n) {
2181
+ if (typeof e != "string")
2182
+ return f(n, r, "Expected a string."), "";
2183
+ const o = e.trim();
2184
+ return o.length > t && f(n, r, `Must be ${t} characters or fewer.`), o;
2185
+ }
2186
+ function Ar(e, r, t) {
2187
+ if (e != null) {
2188
+ if (!Number.isInteger(e) || Number(e) < 0) {
2189
+ f(t, r, "Expected a non-negative integer.");
2190
+ return;
2191
+ }
2192
+ return Number(e);
2193
+ }
2194
+ }
2195
+ function R(e, r, t, n = {}) {
2196
+ if (e == null)
2197
+ return n.required ? (f(t, r, "Expected at least one evidence id."), []) : void 0;
2198
+ if (!Array.isArray(e))
2199
+ return f(t, r, "Expected an array."), n.required ? [] : void 0;
2200
+ const o = [];
2201
+ return e.forEach((a, i) => {
2202
+ const l = C(
2203
+ a,
2204
+ `${r}.${i}`,
2205
+ y.id,
2206
+ t
2207
+ );
2208
+ l && !o.includes(l) && o.push(l);
2209
+ }), n.required && o.length === 0 && f(t, r, "Expected at least one evidence id."), o.length > 0 || n.required ? o : void 0;
2210
+ }
2211
+ function N(e, r, t, n) {
2212
+ return e == null ? r : typeof e != "boolean" ? (f(n, t, "Expected a boolean."), r) : e;
2213
+ }
2214
+ function Br(e, r) {
2215
+ return e == null ? "ACTIVE" : e === "ACTIVE" || e === "PAUSED" || e === "DISABLED" ? e : (f(r, "status", "Expected ACTIVE, PAUSED, or DISABLED."), "ACTIVE");
2216
+ }
2217
+ function Pr(e) {
2218
+ return e.includes("@") && e.includes(".") && !e.includes(" ");
2219
+ }
2220
+ function Ve(e, r) {
2221
+ if (e == null)
2222
+ return { type: "project" };
2223
+ const t = k(e, "source", r), n = t.type;
2224
+ return n === "project" ? (b(t, "source", ["type"], r), { type: "project" }) : n === "dashboard" ? (b(t, "source", ["type", "dashboardId"], r), {
2225
+ type: "dashboard",
2226
+ dashboardId: C(
2227
+ t.dashboardId,
2228
+ "source.dashboardId",
2229
+ y.id,
2230
+ r
2231
+ )
2232
+ }) : (f(r, "source.type", "Expected project or dashboard."), { type: "project" });
2233
+ }
2234
+ function Le(e, r) {
2235
+ const t = k(e, "body", r), n = t.type;
2236
+ return n === "generated_analysis" ? (b(t, "body", ["type", "instruction"], r), {
2237
+ type: "generated_analysis",
2238
+ instruction: C(
2239
+ t.instruction,
2240
+ "body.instruction",
2241
+ y.instruction,
2242
+ r
2243
+ )
2244
+ }) : n === "custom_message" ? (b(t, "body", ["type", "message"], r), {
2245
+ type: "custom_message",
2246
+ message: Rr(
2247
+ t.message,
2248
+ "body.message",
2249
+ y.customMessage,
2250
+ r
2251
+ )
2252
+ }) : n === "none" ? (b(t, "body", ["type"], r), { type: "none" }) : (f(
2253
+ r,
2254
+ "body.type",
2255
+ "Expected generated_analysis, custom_message, or none."
2256
+ ), { type: "none" });
2257
+ }
2258
+ function Mr(e, r) {
2259
+ if (e == null)
2260
+ return [...le];
2261
+ if (!Array.isArray(e))
2262
+ return f(r, "presentation.artifactFormats", "Expected an array."), [...le];
2263
+ if (e.length === 0)
2264
+ return f(
2265
+ r,
2266
+ "presentation.artifactFormats",
2267
+ "Choose at least one artifact format."
2268
+ ), [];
2269
+ const t = [];
2270
+ return e.forEach((n, o) => {
2271
+ if (typeof n != "string" || !Ne.has(n)) {
2272
+ f(
2273
+ r,
2274
+ `presentation.artifactFormats.${o}`,
2275
+ "Expected markdown or html."
2276
+ );
2277
+ return;
2278
+ }
2279
+ t.includes(n) || t.push(n);
2280
+ }), t;
2281
+ }
2282
+ function Ue(e, r) {
2283
+ if (e == null)
2284
+ return {
2285
+ artifactFormats: [...le],
2286
+ includeEvidence: !0,
2287
+ includeSql: !0
2288
+ };
2289
+ const t = k(e, "presentation", r);
2290
+ b(
2291
+ t,
2292
+ "presentation",
2293
+ [
2294
+ "artifactFormats",
2295
+ "includeEvidence",
2296
+ "includeSql",
2297
+ "audience",
2298
+ "tone",
2299
+ "format",
2300
+ "appearance",
2301
+ "brandOverrides",
2302
+ "fragments",
2303
+ "viewUrl"
2304
+ ],
2305
+ r
2306
+ );
2307
+ const n = {
2308
+ artifactFormats: Mr(t.artifactFormats, r),
2309
+ includeEvidence: N(
2310
+ t.includeEvidence,
2311
+ !0,
2312
+ "presentation.includeEvidence",
2313
+ r
2314
+ ),
2315
+ includeSql: N(
2316
+ t.includeSql,
2317
+ !0,
2318
+ "presentation.includeSql",
2319
+ r
2320
+ )
2321
+ }, o = T(
2322
+ t.audience,
2323
+ "presentation.audience",
2324
+ y.presentationAudience,
2325
+ r
2326
+ ), a = T(
2327
+ t.tone,
2328
+ "presentation.tone",
2329
+ y.presentationTone,
2330
+ r
2331
+ ), i = T(
2332
+ t.format,
2333
+ "presentation.format",
2334
+ y.presentationFormat,
2335
+ r
2336
+ );
2337
+ o && (n.audience = o), a && (n.tone = a), i && (n.format = i);
2338
+ const l = ir(t);
2339
+ return l.issues.forEach((m) => f(r, m.field, m.message)), Object.assign(n, l.value), n;
2340
+ }
2341
+ function Dr(e, r, t) {
2342
+ return Array.isArray(e) ? (e.length === 0 && f(t, r, "Expected at least one item."), e.length > _.maxListItems && f(
2343
+ t,
2344
+ r,
2345
+ `Must have ${_.maxListItems} items or fewer.`
2346
+ ), e.slice(0, _.maxListItems).map(
2347
+ (n, o) => C(
2348
+ n,
2349
+ `${r}.${o}`,
2350
+ y.contentItem,
2351
+ t
2352
+ )
2353
+ ).filter(Boolean)) : (f(t, r, "Expected an array."), []);
2354
+ }
2355
+ function Or(e, r, t) {
2356
+ const n = k(e, r, t);
2357
+ if (n.kind === "metric")
2358
+ return b(n, r, ["kind", "metricId"], t), {
2359
+ kind: "metric",
2360
+ metricId: C(
2361
+ n.metricId,
2362
+ `${r}.metricId`,
2363
+ y.id,
2364
+ t
2365
+ )
2366
+ };
2367
+ if (n.kind === "column")
2368
+ return b(n, r, ["kind", "columnKey"], t), {
2369
+ kind: "column",
2370
+ columnKey: C(
2371
+ n.columnKey,
2372
+ `${r}.columnKey`,
2373
+ y.id,
2374
+ t
2375
+ )
2376
+ };
2377
+ if (n.kind === "matrix_measure")
2378
+ return b(n, r, ["kind", "measureId"], t), {
2379
+ kind: "matrix_measure",
2380
+ measureId: C(
2381
+ n.measureId,
2382
+ `${r}.measureId`,
2383
+ y.id,
2384
+ t
2385
+ )
2386
+ };
2387
+ f(
2388
+ t,
2389
+ `${r}.kind`,
2390
+ "Expected metric, column, or matrix_measure."
2391
+ );
2392
+ }
2393
+ function je(e, r, t) {
2394
+ if (e === null || typeof e != "object" || Array.isArray(e))
2395
+ return;
2396
+ const n = k(e, r, t);
2397
+ if (!Object.prototype.hasOwnProperty.call(n, "target") && !Object.prototype.hasOwnProperty.call(n, "format"))
2398
+ return;
2399
+ b(n, r, ["value", "target", "format"], t), (typeof n.value != "number" || !Number.isFinite(n.value)) && f(t, `${r}.value`, "Expected a finite number.");
2400
+ const o = Or(
2401
+ n.target,
2402
+ `${r}.target`,
2403
+ t
2404
+ ), a = Te(n.format);
2405
+ if (a.ok || a.issues.forEach(
2406
+ (i) => f(
2407
+ t,
2408
+ i.path === "$" ? `${r}.format` : `${r}.format.${i.path}`,
2409
+ i.message
2410
+ )
2411
+ ), !(typeof n.value != "number" || !Number.isFinite(n.value) || !o || !a.ok))
2412
+ return { value: n.value, target: o, format: a.value };
2413
+ }
2414
+ function P(e, r, t) {
2415
+ if (typeof e == "string")
2416
+ return e;
2417
+ if (typeof e == "number") {
2418
+ if (!Number.isFinite(e)) {
2419
+ f(t, r, "Expected a finite number.");
2420
+ return;
2421
+ }
2422
+ return e;
2423
+ }
2424
+ const n = je(e, r, t);
2425
+ if (n) return n;
2426
+ f(
2427
+ t,
2428
+ r,
2429
+ "Expected a string, number, or structured numeric value."
2430
+ );
2431
+ }
2432
+ function Kr(e, r, t) {
2433
+ if (e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean")
2434
+ return typeof e == "string" && e.length > y.contentCell ? (f(
2435
+ t,
2436
+ r,
2437
+ `Must be ${y.contentCell} characters or fewer.`
2438
+ ), e.slice(0, y.contentCell)) : typeof e == "number" && !Number.isFinite(e) ? (f(t, r, "Expected a finite number."), null) : e;
2439
+ const n = je(e, r, t);
2440
+ return n || (f(
2441
+ t,
2442
+ r,
2443
+ "Expected a string, number, boolean, structured numeric value, or null."
2444
+ ), null);
2445
+ }
2446
+ function Nr(e, r, t) {
2447
+ if (!Array.isArray(e))
2448
+ return f(t, r, "Expected an array."), [];
2449
+ e.length === 0 && f(t, r, "Expected at least one column."), e.length > _.maxTableColumns && f(
2450
+ t,
2451
+ r,
2452
+ `Must have ${_.maxTableColumns} columns or fewer.`
2453
+ );
2454
+ const n = /* @__PURE__ */ new Set();
2455
+ return e.slice(0, _.maxTableColumns).map((o, a) => {
2456
+ const i = `${r}.${a}`, l = k(o, i, t);
2457
+ b(l, i, ["key", "label", "kind", "align"], t);
2458
+ const m = C(
2459
+ l.key,
2460
+ `${i}.key`,
2461
+ y.id,
2462
+ t
2463
+ );
2464
+ m && (n.has(m) && f(t, `${i}.key`, "Column key must be unique."), n.add(m));
2465
+ const c = C(
2466
+ l.label,
2467
+ `${i}.label`,
2468
+ y.contentTitle,
2469
+ t
2470
+ ), s = D(
2471
+ l.kind,
2472
+ `${i}.kind`,
2473
+ Sr,
2474
+ "text, number, currency, percent, date, or boolean",
2475
+ t
2476
+ ), u = D(
2477
+ l.align,
2478
+ `${i}.align`,
2479
+ _r,
2480
+ "left, center, or right",
2481
+ t
2482
+ );
2483
+ return {
2484
+ key: m,
2485
+ label: c,
2486
+ ...s ? { kind: s } : {},
2487
+ ...u ? { align: u } : {}
2488
+ };
2489
+ });
2490
+ }
2491
+ function zr(e, r, t, n) {
2492
+ if (!Array.isArray(e))
2493
+ return f(n, r, "Expected an array."), [];
2494
+ e.length > _.maxTableRows && f(
2495
+ n,
2496
+ r,
2497
+ `Must have ${_.maxTableRows} rows or fewer.`
2498
+ );
2499
+ const o = new Set(t.map((a) => a.key).filter(Boolean));
2500
+ return e.slice(0, _.maxTableRows).map((a, i) => {
2501
+ const l = `${r}.${i}`, m = k(a, l, n);
2502
+ return Object.keys(m).forEach((c) => {
2503
+ o.has(c) || f(n, `${l}.${c}`, `Unexpected table cell "${c}".`);
2504
+ }), Object.fromEntries(
2505
+ t.map((c) => [
2506
+ c.key,
2507
+ Kr(m[c.key] ?? null, `${l}.${c.key}`, n)
2508
+ ])
2509
+ );
2510
+ });
2511
+ }
2512
+ function Vr(e, r, t) {
2513
+ const n = `content.blocks.${r}`, o = k(e, n, t), a = o.type;
2514
+ if (a === "heading") {
2515
+ b(o, n, ["type", "text", "level", "evidenceIds"], t);
2516
+ const i = o.level === void 0 || o.level === null ? void 0 : o.level === 2 || o.level === 3 ? o.level : void 0;
2517
+ o.level !== void 0 && o.level !== null && i === void 0 && f(t, `${n}.level`, "Expected 2 or 3.");
2518
+ const l = R(o.evidenceIds, `${n}.evidenceIds`, t);
2519
+ return {
2520
+ type: "heading",
2521
+ text: C(
2522
+ o.text,
2523
+ `${n}.text`,
2524
+ y.contentTitle,
2525
+ t
2526
+ ),
2527
+ ...i ? { level: i } : {},
2528
+ ...l ? { evidenceIds: l } : {}
2529
+ };
2530
+ }
2531
+ if (a === "paragraph") {
2532
+ b(o, n, ["type", "text", "evidenceIds"], t);
2533
+ const i = R(o.evidenceIds, `${n}.evidenceIds`, t);
2534
+ return {
2535
+ type: "paragraph",
2536
+ text: C(
2537
+ o.text,
2538
+ `${n}.text`,
2539
+ y.contentText,
2540
+ t
2541
+ ),
2542
+ ...i ? { evidenceIds: i } : {}
2543
+ };
2544
+ }
2545
+ if (a === "finding") {
2546
+ b(o, n, ["type", "title", "text", "severity", "evidenceIds"], t);
2547
+ const i = T(
2548
+ o.title,
2549
+ `${n}.title`,
2550
+ y.contentTitle,
2551
+ t
2552
+ ), l = D(
2553
+ o.severity,
2554
+ `${n}.severity`,
2555
+ xr,
2556
+ "info, positive, warning, or critical",
2557
+ t
2558
+ );
2559
+ return {
2560
+ type: "finding",
2561
+ ...i ? { title: i } : {},
2562
+ text: C(
2563
+ o.text,
2564
+ `${n}.text`,
2565
+ y.contentText,
2566
+ t
2567
+ ),
2568
+ ...l ? { severity: l } : {},
2569
+ evidenceIds: R(o.evidenceIds, `${n}.evidenceIds`, t, {
2570
+ required: !0
2571
+ }) ?? []
2572
+ };
2573
+ }
2574
+ if (a === "bullets" || a === "actions" || a === "limitations") {
2575
+ b(o, n, ["type", "title", "items", "evidenceIds"], t);
2576
+ const i = T(
2577
+ o.title,
2578
+ `${n}.title`,
2579
+ y.contentTitle,
2580
+ t
2581
+ ), l = R(o.evidenceIds, `${n}.evidenceIds`, t);
2582
+ return {
2583
+ type: a,
2584
+ ...i ? { title: i } : {},
2585
+ items: Dr(o.items, `${n}.items`, t),
2586
+ ...l ? { evidenceIds: l } : {}
2587
+ };
2588
+ }
2589
+ if (a === "metric") {
2590
+ b(
2591
+ o,
2592
+ n,
2593
+ [
2594
+ "type",
2595
+ "label",
2596
+ "value",
2597
+ "previousValue",
2598
+ "delta",
2599
+ "percentChange",
2600
+ "unit",
2601
+ "evidenceIds"
2602
+ ],
2603
+ t
2604
+ );
2605
+ const i = P(o.value, `${n}.value`, t) ?? "";
2606
+ i === "" && f(
2607
+ t,
2608
+ `${n}.value`,
2609
+ "Expected a non-empty string, number, or structured numeric value."
2610
+ );
2611
+ const l = o.previousValue === void 0 || o.previousValue === null ? o.previousValue : P(
2612
+ o.previousValue,
2613
+ `${n}.previousValue`,
2614
+ t
2615
+ ), m = o.delta === void 0 || o.delta === null ? o.delta : P(
2616
+ o.delta,
2617
+ `${n}.delta`,
2618
+ t
2619
+ ), c = o.percentChange === void 0 || o.percentChange === null ? o.percentChange : P(
2620
+ o.percentChange,
2621
+ `${n}.percentChange`,
2622
+ t
2623
+ ), s = T(
2624
+ o.unit,
2625
+ `${n}.unit`,
2626
+ y.contentTitle,
2627
+ t
2628
+ ), u = R(o.evidenceIds, `${n}.evidenceIds`, t);
2629
+ return {
2630
+ type: "metric",
2631
+ label: C(
2632
+ o.label,
2633
+ `${n}.label`,
2634
+ y.contentTitle,
2635
+ t
2636
+ ),
2637
+ value: i,
2638
+ ...l !== void 0 ? { previousValue: l } : {},
2639
+ ...m !== void 0 ? { delta: m } : {},
2640
+ ...c !== void 0 ? { percentChange: c } : {},
2641
+ ...s ? { unit: s } : {},
2642
+ ...u ? { evidenceIds: u } : {}
2643
+ };
2644
+ }
2645
+ if (a === "kpi_grid") {
2646
+ b(o, n, ["type", "title", "tiles", "evidenceIds"], t);
2647
+ const i = T(
2648
+ o.title,
2649
+ `${n}.title`,
2650
+ y.contentTitle,
2651
+ t
2652
+ ), l = Array.isArray(o.tiles) ? o.tiles : [];
2653
+ Array.isArray(o.tiles) || f(t, `${n}.tiles`, "Expected an array."), l.length === 0 && f(t, `${n}.tiles`, "Expected at least one tile."), l.length > _.maxKpiTiles && f(
2654
+ t,
2655
+ `${n}.tiles`,
2656
+ `Must have ${_.maxKpiTiles} tiles or fewer.`
2657
+ );
2658
+ const m = l.slice(0, _.maxKpiTiles).map((s, u) => {
2659
+ const p = `${n}.tiles.${u}`, d = k(s, p, t);
2660
+ b(
2661
+ d,
2662
+ p,
2663
+ [
2664
+ "label",
2665
+ "value",
2666
+ "previousValue",
2667
+ "delta",
2668
+ "percentChange",
2669
+ "unit",
2670
+ "evidenceIds"
2671
+ ],
2672
+ t
2673
+ );
2674
+ const v = P(
2675
+ d.value,
2676
+ `${p}.value`,
2677
+ t
2678
+ ) ?? "";
2679
+ v === "" && f(
2680
+ t,
2681
+ `${p}.value`,
2682
+ "Expected a non-empty string, number, or structured numeric value."
2683
+ );
2684
+ const h = d.previousValue === void 0 || d.previousValue === null ? d.previousValue : P(
2685
+ d.previousValue,
2686
+ `${p}.previousValue`,
2687
+ t
2688
+ ), I = d.delta === void 0 || d.delta === null ? d.delta : P(
2689
+ d.delta,
2690
+ `${p}.delta`,
2691
+ t
2692
+ ), w = d.percentChange === void 0 || d.percentChange === null ? d.percentChange : P(
2693
+ d.percentChange,
2694
+ `${p}.percentChange`,
2695
+ t
2696
+ ), g = T(
2697
+ d.unit,
2698
+ `${p}.unit`,
2699
+ y.contentTitle,
2700
+ t
2701
+ ), $ = R(
2702
+ d.evidenceIds,
2703
+ `${p}.evidenceIds`,
2704
+ t
2705
+ );
2706
+ return {
2707
+ label: C(
2708
+ d.label,
2709
+ `${p}.label`,
2710
+ y.contentTitle,
2711
+ t
2712
+ ),
2713
+ value: v,
2714
+ ...h !== void 0 ? { previousValue: h } : {},
2715
+ ...I !== void 0 ? { delta: I } : {},
2716
+ ...w !== void 0 ? { percentChange: w } : {},
2717
+ ...g ? { unit: g } : {},
2718
+ ...$ ? { evidenceIds: $ } : {}
2719
+ };
2720
+ }), c = R(
2721
+ o.evidenceIds,
2722
+ `${n}.evidenceIds`,
2723
+ t
2724
+ );
2725
+ return {
2726
+ type: "kpi_grid",
2727
+ ...i ? { title: i } : {},
2728
+ tiles: m,
2729
+ ...c ? { evidenceIds: c } : {}
2730
+ };
2731
+ }
2732
+ if (a === "progress") {
2733
+ b(o, n, ["type", "label", "value", "detail", "evidenceIds"], t);
2734
+ const i = typeof o.value == "number" && Number.isFinite(o.value) ? o.value : 0;
2735
+ (typeof o.value != "number" || !Number.isFinite(o.value)) && f(t, `${n}.value`, "Expected a finite number.");
2736
+ const l = T(
2737
+ o.detail,
2738
+ `${n}.detail`,
2739
+ y.contentText,
2740
+ t
2741
+ ), m = R(o.evidenceIds, `${n}.evidenceIds`, t);
2742
+ return {
2743
+ type: "progress",
2744
+ label: C(
2745
+ o.label,
2746
+ `${n}.label`,
2747
+ y.contentTitle,
2748
+ t
2749
+ ),
2750
+ value: i,
2751
+ ...l ? { detail: l } : {},
2752
+ ...m ? { evidenceIds: m } : {}
2753
+ };
2754
+ }
2755
+ if (a === "table") {
2756
+ b(
2757
+ o,
2758
+ n,
2759
+ ["type", "id", "title", "columns", "rows", "caption", "totalRows", "evidenceIds"],
2760
+ t
2761
+ );
2762
+ const i = Nr(o.columns, `${n}.columns`, t), l = T(
2763
+ o.title,
2764
+ `${n}.title`,
2765
+ y.contentTitle,
2766
+ t
2767
+ ), m = T(
2768
+ o.id,
2769
+ `${n}.id`,
2770
+ y.id,
2771
+ t
2772
+ ), c = T(
2773
+ o.caption,
2774
+ `${n}.caption`,
2775
+ y.contentItem,
2776
+ t
2777
+ ), s = Ar(
2778
+ o.totalRows,
2779
+ `${n}.totalRows`,
2780
+ t
2781
+ ), u = R(o.evidenceIds, `${n}.evidenceIds`, t);
2782
+ return {
2783
+ type: "table",
2784
+ ...m ? { id: m } : {},
2785
+ ...l ? { title: l } : {},
2786
+ columns: i,
2787
+ rows: zr(o.rows, `${n}.rows`, i, t),
2788
+ ...c ? { caption: c } : {},
2789
+ ...s !== void 0 ? { totalRows: s } : {},
2790
+ ...u ? { evidenceIds: u } : {}
2791
+ };
2792
+ }
2793
+ if (a === "evidence_appendix") {
2794
+ b(o, n, ["type", "title", "evidenceIds"], t);
2795
+ const i = T(
2796
+ o.title,
2797
+ `${n}.title`,
2798
+ y.contentTitle,
2799
+ t
2800
+ );
2801
+ return {
2802
+ type: "evidence_appendix",
2803
+ ...i ? { title: i } : {},
2804
+ evidenceIds: R(o.evidenceIds, `${n}.evidenceIds`, t, {
2805
+ required: !0
2806
+ }) ?? []
2807
+ };
2808
+ }
2809
+ if (a === "sql") {
2810
+ b(o, n, ["type", "title", "sql", "evidenceIds"], t);
2811
+ const i = T(
2812
+ o.title,
2813
+ `${n}.title`,
2814
+ y.contentTitle,
2815
+ t
2816
+ ), l = C(
2817
+ o.sql,
2818
+ `${n}.sql`,
2819
+ y.contentSql,
2820
+ t
2821
+ ), m = R(o.evidenceIds, `${n}.evidenceIds`, t);
2822
+ return {
2823
+ type: "sql",
2824
+ ...i ? { title: i } : {},
2825
+ sql: l,
2826
+ ...m ? { evidenceIds: m } : {}
2827
+ };
2828
+ }
2829
+ return f(
2830
+ t,
2831
+ `${n}.type`,
2832
+ "Expected heading, paragraph, finding, bullets, metric, kpi_grid, progress, table, actions, limitations, sql, or evidence_appendix."
2833
+ ), {
2834
+ type: "paragraph",
2835
+ text: ""
2836
+ };
2837
+ }
2838
+ function Lr(e) {
2839
+ const r = [], t = k(e, "content", r);
2840
+ b(t, "content", ["version", "title", "summary", "blocks"], r), t.version !== 1 && f(r, "content.version", "Expected version 1.");
2841
+ const n = T(
2842
+ t.title,
2843
+ "content.title",
2844
+ y.contentTitle,
2845
+ r
2846
+ ), o = T(
2847
+ t.summary,
2848
+ "content.summary",
2849
+ y.contentSummary,
2850
+ r
2851
+ );
2852
+ Array.isArray(t.blocks) || f(r, "content.blocks", "Expected an array.");
2853
+ const a = Array.isArray(t.blocks) ? t.blocks : [];
2854
+ a.length === 0 && f(r, "content.blocks", "Expected at least one block."), a.length > _.maxBlocks && f(
2855
+ r,
2856
+ "content.blocks",
2857
+ `Must have ${_.maxBlocks} blocks or fewer.`
2858
+ );
2859
+ const i = a.slice(0, _.maxBlocks).map((l, m) => Vr(l, m, r));
2860
+ return ye(r), {
2861
+ version: 1,
2862
+ ...n ? { title: n } : {},
2863
+ ...o ? { summary: o } : {},
2864
+ blocks: i
2865
+ };
2866
+ }
2867
+ function Gn(e) {
2868
+ try {
2869
+ return {
2870
+ valid: !0,
2871
+ value: Lr(e),
2872
+ issues: []
2873
+ };
2874
+ } catch (r) {
2875
+ if (r instanceof X)
2876
+ return { valid: !1, issues: r.issues };
2877
+ throw r;
2878
+ }
2879
+ }
2880
+ function Y(e, r, t, n) {
2881
+ return typeof e == "string" && t.includes(e) ? e : (f(n, r, `Expected ${t.join(" or ")}.`), t[0]);
2882
+ }
2883
+ function D(e, r, t, n, o) {
2884
+ if (e != null) {
2885
+ if (typeof e == "string" && t.has(e))
2886
+ return e;
2887
+ f(o, r, `Expected ${n}.`);
2888
+ }
2889
+ }
2890
+ function Ur(e, r, t) {
2891
+ if (e != null) {
2892
+ if (!Array.isArray(e)) {
2893
+ f(t, r, "Expected an array.");
2894
+ return;
2895
+ }
2896
+ return e;
2897
+ }
2898
+ }
2899
+ function jr(e, r, t) {
2900
+ if (e != null) {
2901
+ if (!ze(e)) {
2902
+ f(t, r, "Expected an object.");
2903
+ return;
2904
+ }
2905
+ return e;
2906
+ }
2907
+ }
2908
+ function qr(e, r, t) {
2909
+ if (e == null)
2910
+ return;
2911
+ const n = k(e, r, t);
2912
+ b(n, r, Fr, t);
2913
+ const o = {}, a = D(
2914
+ n.pageSize,
2915
+ `${r}.pageSize`,
2916
+ Cr,
2917
+ "letter, legal, a4, a3, or tabloid",
2918
+ t
2919
+ ), i = D(
2920
+ n.orientation,
2921
+ `${r}.orientation`,
2922
+ Tr,
2923
+ "portrait or landscape",
2924
+ t
2925
+ ), l = D(
2926
+ n.delimiter,
2927
+ `${r}.delimiter`,
2928
+ $r,
2929
+ "comma, semicolon, or tab",
2930
+ t
2931
+ ), m = D(
2932
+ n.sheetSelection,
2933
+ `${r}.sheetSelection`,
2934
+ kr,
2935
+ "current or all",
2936
+ t
2937
+ );
2938
+ a && (o.pageSize = a), i && (o.orientation = i), l && (o.delimiter = l), m && (o.sheetSelection = m);
2939
+ for (const c of [
2940
+ "includeFilters",
2941
+ "includeTimestamp",
2942
+ "includeHeaders",
2943
+ "useFormattedValues",
2944
+ "allowDownload"
2945
+ ])
2946
+ if (!(n[c] === void 0 || n[c] === null)) {
2947
+ if (typeof n[c] != "boolean") {
2948
+ f(t, `${r}.${c}`, "Expected a boolean.");
2949
+ continue;
2950
+ }
2951
+ o[c] = n[c];
2952
+ }
2953
+ for (const c of [
2954
+ "currentSheetId",
2955
+ "currentSheetName",
2956
+ "filterLine",
2957
+ "selectedSheetId",
2958
+ "cardType",
2959
+ "theme"
2960
+ ]) {
2961
+ const s = T(
2962
+ n[c],
2963
+ `${r}.${c}`,
2964
+ y.id,
2965
+ t
2966
+ );
2967
+ s && (o[c] = s);
2968
+ }
2969
+ for (const c of [
2970
+ "filterValues",
2971
+ "inlineFilterValues",
2972
+ "sheetFilterValues",
2973
+ "controlDefinitions",
2974
+ "cardControlDefinitions",
2975
+ "controlBindings"
2976
+ ]) {
2977
+ const s = Ur(n[c], `${r}.${c}`, t);
2978
+ s && (o[c] = s);
2979
+ }
2980
+ for (const c of [
2981
+ "controlValues",
2982
+ "tablePreferences",
2983
+ "dashboardInputExecutionSnapshot"
2984
+ ]) {
2985
+ const s = jr(n[c], `${r}.${c}`, t);
2986
+ s && (o[c] = s);
2987
+ }
2988
+ return Object.keys(o).length > 0 ? o : void 0;
2989
+ }
2990
+ function ne(e, r, t, n) {
2991
+ const o = T(
2992
+ r,
2993
+ t,
2994
+ y.attachmentTitle,
2995
+ n
2996
+ );
2997
+ return o && (e.title = o), e;
2998
+ }
2999
+ function oe(e, r, t, n) {
3000
+ const o = qr(r, t, n);
3001
+ return o && (e.settings = o), e;
3002
+ }
3003
+ function Gr(e, r, t) {
3004
+ const n = `attachments.${r}`, o = k(e, n, t), a = o.type;
3005
+ if (a === "dashboard") {
3006
+ b(
3007
+ o,
3008
+ n,
3009
+ ["type", "dashboardId", "format", "title", "settings"],
3010
+ t
3011
+ );
3012
+ const i = ne(
3013
+ {
3014
+ type: "dashboard",
3015
+ dashboardId: C(
3016
+ o.dashboardId,
3017
+ `${n}.dashboardId`,
3018
+ y.id,
3019
+ t
3020
+ ),
3021
+ format: Y(o.format, `${n}.format`, ["pdf"], t)
3022
+ },
3023
+ o.title,
3024
+ `${n}.title`,
3025
+ t
3026
+ );
3027
+ return oe(i, o.settings, `${n}.settings`, t);
3028
+ }
3029
+ if (a === "dashboard_sheet" || a === "document_sheet") {
3030
+ b(
3031
+ o,
3032
+ n,
3033
+ ["type", "dashboardId", "sheetId", "format", "title", "settings"],
3034
+ t
3035
+ );
3036
+ const i = ne(
3037
+ {
3038
+ type: a,
3039
+ dashboardId: C(
3040
+ o.dashboardId,
3041
+ `${n}.dashboardId`,
3042
+ y.id,
3043
+ t
3044
+ ),
3045
+ sheetId: C(
3046
+ o.sheetId,
3047
+ `${n}.sheetId`,
3048
+ y.id,
3049
+ t
3050
+ ),
3051
+ format: Y(o.format, `${n}.format`, ["pdf"], t)
3052
+ },
3053
+ o.title,
3054
+ `${n}.title`,
3055
+ t
3056
+ );
3057
+ return oe(i, o.settings, `${n}.settings`, t);
3058
+ }
3059
+ if (a === "card") {
3060
+ b(
3061
+ o,
3062
+ n,
3063
+ ["type", "dashboardId", "cardId", "format", "title", "settings"],
3064
+ t
3065
+ );
3066
+ const i = ne(
3067
+ {
3068
+ type: "card",
3069
+ dashboardId: C(
3070
+ o.dashboardId,
3071
+ `${n}.dashboardId`,
3072
+ y.id,
3073
+ t
3074
+ ),
3075
+ cardId: C(
3076
+ o.cardId,
3077
+ `${n}.cardId`,
3078
+ y.id,
3079
+ t
3080
+ ),
3081
+ format: Y(
3082
+ o.format,
3083
+ `${n}.format`,
3084
+ ["csv", "pdf"],
3085
+ t
3086
+ )
3087
+ },
3088
+ o.title,
3089
+ `${n}.title`,
3090
+ t
3091
+ );
3092
+ return oe(i, o.settings, `${n}.settings`, t);
3093
+ }
3094
+ return f(
3095
+ t,
3096
+ `${n}.type`,
3097
+ "Expected dashboard, dashboard_sheet, document_sheet, or card."
3098
+ ), { type: "dashboard", dashboardId: "", format: "pdf" };
3099
+ }
3100
+ function Hr(e) {
3101
+ switch (e.type) {
3102
+ case "dashboard":
3103
+ return `${e.type}:${e.dashboardId}:${e.format}`;
3104
+ case "dashboard_sheet":
3105
+ case "document_sheet":
3106
+ return `${e.type}:${e.dashboardId}:${e.sheetId}:${e.format}`;
3107
+ case "card":
3108
+ return `${e.type}:${e.dashboardId}:${e.cardId}:${e.format}`;
3109
+ }
3110
+ }
3111
+ function qe(e, r) {
3112
+ if (e == null)
3113
+ return [];
3114
+ if (!Array.isArray(e))
3115
+ return f(r, "attachments", "Expected an array."), [];
3116
+ e.length > te && f(
3117
+ r,
3118
+ "attachments",
3119
+ `Choose ${te} attachments or fewer.`
3120
+ );
3121
+ const t = e.slice(0, te).map((o, a) => Gr(o, a, r)), n = /* @__PURE__ */ new Set();
3122
+ return t.forEach((o, a) => {
3123
+ const i = Hr(o);
3124
+ n.has(i) && f(r, `attachments.${a}`, "Duplicate attachment."), n.add(i);
3125
+ }), t;
3126
+ }
3127
+ function Ge(e, r) {
3128
+ if (e == null)
3129
+ return;
3130
+ const t = k(e, "limits", r);
3131
+ b(t, "limits", Object.keys(re), r);
3132
+ const n = {};
3133
+ return Object.keys(re).forEach((o) => {
3134
+ const a = t[o];
3135
+ if (a == null)
3136
+ return;
3137
+ const i = re[o];
3138
+ if (typeof a != "number" || !Number.isInteger(a) || a < i.min || a > i.max) {
3139
+ f(
3140
+ r,
3141
+ `limits.${o}`,
3142
+ `Expected an integer between ${i.min} and ${i.max}.`
3143
+ );
3144
+ return;
3145
+ }
3146
+ n[o] = a;
3147
+ }), Object.keys(n).length > 0 ? n : void 0;
3148
+ }
3149
+ function ye(e) {
3150
+ if (e.length > 0)
3151
+ throw new X(e);
3152
+ }
3153
+ function He(e, r, t) {
3154
+ !(e.type === "generated_analysis" || e.type === "custom_message" && !!e.message.trim()) && r.length === 0 && f(
3155
+ t,
3156
+ "body",
3157
+ "Add briefing instructions, a custom message, or at least one attachment."
3158
+ );
3159
+ }
3160
+ function Wr(e, r, t) {
3161
+ e == null || e.forEach((n, o) => {
3162
+ const a = `${t}.${o}.scope`, i = n.scope.attachmentIndex;
3163
+ if (i === void 0)
3164
+ throw new U(
3165
+ `${a}.attachmentIndex must identify the attachment that owns this presentation entry.`
3166
+ );
3167
+ const l = r[i];
3168
+ if (!l)
3169
+ throw new U(
3170
+ `${a}.attachmentIndex must identify an existing attachment.`
3171
+ );
3172
+ if (n.scope.dashboardId !== l.dashboardId)
3173
+ throw new U(
3174
+ `${a}.dashboardId must match the dashboard selected by the referenced attachment.`
3175
+ );
3176
+ if (l.type === "card" && n.scope.cardId !== l.cardId)
3177
+ throw new U(
3178
+ `${a}.cardId must match the card selected by the referenced attachment.`
3179
+ );
3180
+ });
3181
+ }
3182
+ function We(e) {
3183
+ const r = [], t = k(e, "jobConfig", r);
3184
+ b(
3185
+ t,
3186
+ "jobConfig",
3187
+ [
3188
+ "kind",
3189
+ "presentationExecutionSnapshot",
3190
+ "source",
3191
+ "body",
3192
+ "attachments",
3193
+ "presentation",
3194
+ "limits"
3195
+ ],
3196
+ r
3197
+ ), t.kind !== ce && f(r, "kind", "Expected BRIEFING.");
3198
+ let n;
3199
+ try {
3200
+ n = lt(
3201
+ t.presentationExecutionSnapshot
3202
+ );
3203
+ } catch (c) {
3204
+ if (c instanceof U)
3205
+ throw c;
3206
+ f(
3207
+ r,
3208
+ "jobConfig.presentationExecutionSnapshot",
3209
+ c instanceof Error ? c.message : "Invalid presentation snapshot."
3210
+ );
3211
+ }
3212
+ const o = Ve(t.source, r), a = Le(t.body, r), i = qe(t.attachments, r), l = Ue(t.presentation, r), m = Ge(t.limits, r);
3213
+ return He(a, i, r), Wr(
3214
+ n == null ? void 0 : n.resolvedFormats,
3215
+ i,
3216
+ "jobConfig.presentationExecutionSnapshot.resolvedFormats"
3217
+ ), ye(r), {
3218
+ kind: ce,
3219
+ presentationExecutionSnapshot: n,
3220
+ source: o,
3221
+ body: a,
3222
+ attachments: i,
3223
+ presentation: l,
3224
+ ...m ? { limits: m } : {}
3225
+ };
3226
+ }
3227
+ function Hn(e) {
3228
+ return We({
3229
+ ...e,
3230
+ kind: ce
3231
+ });
3232
+ }
3233
+ function he(e, r, t, n = "deliveryConfig.recipients") {
3234
+ const o = `${n}.${r}`, a = k(e, o, t), i = a.type;
3235
+ if (i === "email") {
3236
+ b(a, o, ["type", "address", "name"], t);
3237
+ const l = C(
3238
+ a.address,
3239
+ `${o}.address`,
3240
+ y.id,
3241
+ t
3242
+ ), m = T(
3243
+ a.name,
3244
+ `${o}.name`,
3245
+ y.attachmentTitle,
3246
+ t
3247
+ );
3248
+ return l && !Pr(l) && f(t, `${o}.address`, "Email address is invalid."), {
3249
+ type: "email",
3250
+ address: l,
3251
+ ...m ? { name: m } : {}
3252
+ };
3253
+ }
3254
+ return i === "user" ? (b(a, o, ["type", "userId"], t), {
3255
+ type: "user",
3256
+ userId: C(
3257
+ a.userId,
3258
+ `${o}.userId`,
3259
+ y.id,
3260
+ t
3261
+ )
3262
+ }) : i === "tenant_user" ? (b(a, o, ["type", "tenantUserId"], t), {
3263
+ type: "tenant_user",
3264
+ tenantUserId: C(
3265
+ a.tenantUserId,
3266
+ `${o}.tenantUserId`,
3267
+ y.id,
3268
+ t
3269
+ )
3270
+ }) : i === "group" ? (b(a, o, ["type", "groupId"], t), {
3271
+ type: "group",
3272
+ groupId: C(
3273
+ a.groupId,
3274
+ `${o}.groupId`,
3275
+ y.id,
3276
+ t
3277
+ )
3278
+ }) : (f(
3279
+ t,
3280
+ `${o}.type`,
3281
+ "Expected email, user, tenant_user, or group."
3282
+ ), { type: "email", address: "" });
3283
+ }
3284
+ function Yr(e, r) {
3285
+ return e == null ? [] : Array.isArray(e) ? e.map(
3286
+ (t, n) => he(t, n, r)
3287
+ ) : (f(r, "deliveryConfig.recipients", "Expected an array."), []);
3288
+ }
3289
+ function Zr(e, r) {
3290
+ if (!Array.isArray(e))
3291
+ return f(r, "deliveryConfig.channels", "Expected an array."), [];
3292
+ const t = [];
3293
+ return e.forEach((n, o) => {
3294
+ if (!Ye(n)) {
3295
+ f(
3296
+ r,
3297
+ `deliveryConfig.channels.${o}`,
3298
+ "Expected EMAIL, WEBHOOK, SLACK, IN_APP, or TELEGRAM."
3299
+ );
3300
+ return;
3301
+ }
3302
+ t.includes(n) || t.push(n);
3303
+ }), t;
3304
+ }
3305
+ function Jr(e, r, t) {
3306
+ if (e == null)
3307
+ return;
3308
+ const n = k(e, r, t), o = {};
3309
+ return Object.entries(n).forEach(([a, i]) => {
3310
+ if (typeof i != "string") {
3311
+ f(t, `${r}.${a}`, "Expected a string.");
3312
+ return;
3313
+ }
3314
+ o[a] = i.trim();
3315
+ }), Object.keys(o).length > 0 ? o : void 0;
3316
+ }
3317
+ function Qr(e, r, t) {
3318
+ if (e == null)
3319
+ return;
3320
+ const n = k(e, r, t);
3321
+ b(
3322
+ n,
3323
+ r,
3324
+ ["url", "method", "headers", "secretEncrypted"],
3325
+ t
3326
+ );
3327
+ const o = n.method === void 0 || n.method === null ? void 0 : Y(n.method, `${r}.method`, ["POST", "PUT"], t), a = Jr(n.headers, `${r}.headers`, t), i = T(
3328
+ n.secretEncrypted,
3329
+ `${r}.secretEncrypted`,
3330
+ 2e3,
3331
+ t
3332
+ );
3333
+ return {
3334
+ url: C(n.url, `${r}.url`, 2e3, t),
3335
+ ...o ? { method: o } : {},
3336
+ ...a ? { headers: a } : {},
3337
+ ...i ? { secretEncrypted: i } : {}
3338
+ };
3339
+ }
3340
+ function Xr(e, r, t) {
3341
+ const n = k(e, r, t), o = n.type;
3342
+ if (o === "channel") {
3343
+ b(
3344
+ n,
3345
+ r,
3346
+ ["type", "channelId", "channelName", "isPrivate"],
3347
+ t
3348
+ );
3349
+ const a = T(
3350
+ n.channelName,
3351
+ `${r}.channelName`,
3352
+ y.attachmentTitle,
3353
+ t
3354
+ ), i = n.isPrivate === void 0 || n.isPrivate === null ? void 0 : N(
3355
+ n.isPrivate,
3356
+ !1,
3357
+ `${r}.isPrivate`,
3358
+ t
3359
+ );
3360
+ return {
3361
+ type: "channel",
3362
+ channelId: C(
3363
+ n.channelId,
3364
+ `${r}.channelId`,
3365
+ y.id,
3366
+ t
3367
+ ),
3368
+ ...a ? { channelName: a } : {},
3369
+ ...i !== void 0 ? { isPrivate: i } : {}
3370
+ };
3371
+ }
3372
+ return o === "dm" ? (b(n, r, ["type", "recipient"], t), f(
3373
+ t,
3374
+ `${r}.type`,
3375
+ "Slack DM delivery is not supported in V1."
3376
+ ), {
3377
+ type: "dm",
3378
+ recipient: he(n.recipient, 0, t, `${r}.recipient`)
3379
+ }) : (f(t, `${r}.type`, "Expected channel."), { type: "channel", channelId: "" });
3380
+ }
3381
+ function en(e, r, t) {
3382
+ if (e == null)
3383
+ return;
3384
+ if (!Array.isArray(e)) {
3385
+ f(t, r, "Expected an array.");
3386
+ return;
3387
+ }
3388
+ const n = e.map(
3389
+ (o, a) => he(o, a, t, r)
3390
+ );
3391
+ return n.length > 0 ? n : void 0;
3392
+ }
3393
+ function tn(e, r, t) {
3394
+ if (e == null)
3395
+ return;
3396
+ const n = k(e, r, t);
3397
+ b(
3398
+ n,
3399
+ r,
3400
+ [
3401
+ "destination",
3402
+ "threadMentions",
3403
+ "postThreadDetail",
3404
+ "includeDashboardLink",
3405
+ "includeBriefingLink"
3406
+ ],
3407
+ t
3408
+ );
3409
+ const o = en(
3410
+ n.threadMentions,
3411
+ `${r}.threadMentions`,
3412
+ t
3413
+ ), a = N(
3414
+ n.postThreadDetail,
3415
+ !0,
3416
+ `${r}.postThreadDetail`,
3417
+ t
3418
+ ), i = N(
3419
+ n.includeDashboardLink,
3420
+ !0,
3421
+ `${r}.includeDashboardLink`,
3422
+ t
3423
+ ), l = N(
3424
+ n.includeBriefingLink,
3425
+ !0,
3426
+ `${r}.includeBriefingLink`,
3427
+ t
3428
+ );
3429
+ return {
3430
+ destination: Xr(
3431
+ n.destination,
3432
+ `${r}.destination`,
3433
+ t
3434
+ ),
3435
+ ...o ? { threadMentions: o } : {},
3436
+ ...n.postThreadDetail !== void 0 ? { postThreadDetail: a } : {},
3437
+ ...n.includeDashboardLink !== void 0 ? { includeDashboardLink: i } : {},
3438
+ ...n.includeBriefingLink !== void 0 ? { includeBriefingLink: l } : {}
3439
+ };
3440
+ }
3441
+ function rn(e, r, t) {
3442
+ const n = k(e, r, t);
3443
+ b(
3444
+ n,
3445
+ r,
3446
+ [
3447
+ "subjectOverride",
3448
+ "titleOverride",
3449
+ "summaryOverride",
3450
+ "actionBlockVisible",
3451
+ "formatProfile",
3452
+ "slackConfig",
3453
+ "webhookConfig"
3454
+ ],
3455
+ t
3456
+ );
3457
+ const o = D(
3458
+ n.formatProfile,
3459
+ `${r}.formatProfile`,
3460
+ Er,
3461
+ "concise, balanced, or detailed",
3462
+ t
3463
+ ), a = T(
3464
+ n.subjectOverride,
3465
+ `${r}.subjectOverride`,
3466
+ 500,
3467
+ t
3468
+ ), i = T(
3469
+ n.titleOverride,
3470
+ `${r}.titleOverride`,
3471
+ 500,
3472
+ t
3473
+ ), l = T(
3474
+ n.summaryOverride,
3475
+ `${r}.summaryOverride`,
3476
+ 2e3,
3477
+ t
3478
+ ), m = N(
3479
+ n.actionBlockVisible,
3480
+ !0,
3481
+ `${r}.actionBlockVisible`,
3482
+ t
3483
+ ), c = Qr(
3484
+ n.webhookConfig,
3485
+ `${r}.webhookConfig`,
3486
+ t
3487
+ ), s = tn(
3488
+ n.slackConfig,
3489
+ `${r}.slackConfig`,
3490
+ t
3491
+ );
3492
+ return {
3493
+ ...o ? { formatProfile: o } : {},
3494
+ ...a ? { subjectOverride: a } : {},
3495
+ ...i ? { titleOverride: i } : {},
3496
+ ...l ? { summaryOverride: l } : {},
3497
+ ...n.actionBlockVisible !== void 0 ? { actionBlockVisible: m } : {},
3498
+ ...s ? { slackConfig: s } : {},
3499
+ ...c ? { webhookConfig: c } : {}
3500
+ };
3501
+ }
3502
+ function nn(e, r) {
3503
+ if (e == null)
3504
+ return;
3505
+ const t = k(e, "deliveryConfig.channelConfigs", r), n = {};
3506
+ return Object.entries(t).forEach(([o, a]) => {
3507
+ if (!Ye(o)) {
3508
+ f(
3509
+ r,
3510
+ `deliveryConfig.channelConfigs.${o}`,
3511
+ "Expected a supported delivery channel."
3512
+ );
3513
+ return;
3514
+ }
3515
+ n[o] = rn(
3516
+ a,
3517
+ `deliveryConfig.channelConfigs.${o}`,
3518
+ r
3519
+ );
3520
+ }), Object.keys(n).length > 0 ? n : void 0;
3521
+ }
3522
+ function on(e, r) {
3523
+ var m, c, s;
3524
+ if (e == null)
3525
+ return null;
3526
+ const t = k(e, "deliveryConfig", r);
3527
+ b(
3528
+ t,
3529
+ "deliveryConfig",
3530
+ ["recipients", "channels", "channelConfigs"],
3531
+ r
3532
+ );
3533
+ const n = nn(t.channelConfigs, r), o = Yr(t.recipients, r), a = Zr(t.channels, r), i = ((c = (m = n == null ? void 0 : n.SLACK) == null ? void 0 : m.slackConfig) == null ? void 0 : c.destination.type) === "channel" && !!n.SLACK.slackConfig.destination.channelId.trim();
3534
+ return a.some(
3535
+ (u) => u !== "SLACK"
3536
+ ) && o.length === 0 && f(
3537
+ r,
3538
+ "deliveryConfig.recipients",
3539
+ "Add at least one recipient or remove delivery config."
3540
+ ), a.length === 0 && f(
3541
+ r,
3542
+ "deliveryConfig.channels",
3543
+ "Choose at least one delivery channel or remove delivery config."
3544
+ ), a.includes("SLACK") && !i && f(
3545
+ r,
3546
+ "deliveryConfig.channelConfigs.SLACK.slackConfig.destination.channelId",
3547
+ "Choose a Slack channel destination."
3548
+ ), !a.includes("SLACK") && ((s = n == null ? void 0 : n.SLACK) != null && s.slackConfig) && f(
3549
+ r,
3550
+ "deliveryConfig.channelConfigs.SLACK",
3551
+ "Slack config requires SLACK in deliveryConfig.channels."
3552
+ ), {
3553
+ recipients: o,
3554
+ channels: a,
3555
+ ...n ? { channelConfigs: n } : {}
3556
+ };
3557
+ }
3558
+ function ge(e) {
3559
+ const r = [], t = k(e, "draft", r);
3560
+ b(
3561
+ t,
3562
+ "draft",
3563
+ [
3564
+ "name",
3565
+ "description",
3566
+ "status",
3567
+ "scheduleExpr",
3568
+ "timezone",
3569
+ "source",
3570
+ "body",
3571
+ "attachments",
3572
+ "presentation",
3573
+ "limits",
3574
+ "deliveryConfig"
3575
+ ],
3576
+ r
3577
+ );
3578
+ const n = C(
3579
+ t.name,
3580
+ "name",
3581
+ y.name,
3582
+ r
3583
+ ), o = T(
3584
+ t.description,
3585
+ "description",
3586
+ y.description,
3587
+ r
3588
+ ) ?? null, a = T(t.scheduleExpr, "scheduleExpr", 500, r) ?? null, i = T(t.timezone, "timezone", 200, r) ?? "UTC", l = Br(t.status, r), m = Ve(t.source, r), c = Le(t.body, r), s = qe(t.attachments, r), u = Ue(t.presentation, r), p = Ge(t.limits, r), d = on(t.deliveryConfig, r);
3589
+ return He(c, s, r), ye(r), {
3590
+ name: n,
3591
+ description: o,
3592
+ status: l,
3593
+ scheduleExpr: a,
3594
+ timezone: i,
3595
+ source: m,
3596
+ body: c,
3597
+ attachments: s,
3598
+ presentation: u,
3599
+ ...p ? { limits: p } : {},
3600
+ deliveryConfig: d
3601
+ };
3602
+ }
3603
+ function Wn(e) {
3604
+ return ge(e);
3605
+ }
3606
+ function Yn(e) {
3607
+ return ge(e);
3608
+ }
3609
+ function Zn(e) {
3610
+ try {
3611
+ return { valid: !0, value: ge(e), issues: [] };
3612
+ } catch (r) {
3613
+ if (r instanceof X)
3614
+ return { valid: !1, issues: r.issues };
3615
+ throw r;
3616
+ }
3617
+ }
3618
+ function Jn(e) {
3619
+ try {
3620
+ return { valid: !0, value: We(e), issues: [] };
3621
+ } catch (r) {
3622
+ if (r instanceof X)
3623
+ return { valid: !1, issues: r.issues };
3624
+ throw r;
3625
+ }
3626
+ }
3627
+ function Qn(e) {
3628
+ return typeof e == "string" && Ne.has(e);
3629
+ }
3630
+ function Ye(e) {
3631
+ return typeof e == "string" && wr.has(e);
3632
+ }
3633
+ export {
3634
+ Pe as $,
3635
+ Dn as A,
3636
+ Q as B,
3637
+ Pt as C,
3638
+ In as D,
3639
+ xn as E,
3640
+ K as F,
3641
+ kn as G,
3642
+ xt as H,
3643
+ Rt as I,
3644
+ At as J,
3645
+ Be as K,
3646
+ me as L,
3647
+ Ot as M,
3648
+ Lt as N,
3649
+ Ut as O,
3650
+ Cn as P,
3651
+ En as Q,
3652
+ Nt as R,
3653
+ Vn as S,
3654
+ pr as T,
3655
+ Kn as U,
3656
+ dr as V,
3657
+ Nn as W,
3658
+ On as X,
3659
+ hr as Y,
3660
+ Ln as Z,
3661
+ qt as _,
3662
+ Un as a,
3663
+ _n as a0,
3664
+ Et as a1,
3665
+ ce as a2,
3666
+ vr as a3,
3667
+ le as a4,
3668
+ te as a5,
3669
+ y as a6,
3670
+ _ as a7,
3671
+ br as a8,
3672
+ Ir as a9,
3673
+ qn as aa,
3674
+ X as ab,
3675
+ Lr as ac,
3676
+ Gn as ad,
3677
+ We as ae,
3678
+ Hn as af,
3679
+ ge as ag,
3680
+ Wn as ah,
3681
+ Yn as ai,
3682
+ Zn as aj,
3683
+ Jn as ak,
3684
+ Qn as al,
3685
+ Ye as am,
3686
+ yr as an,
3687
+ gr as ao,
3688
+ Jt as b,
3689
+ Yt as c,
3690
+ zn as d,
3691
+ An as e,
3692
+ Qt as f,
3693
+ jn as g,
3694
+ Pn as h,
3695
+ we as i,
3696
+ Bn as j,
3697
+ Zt as k,
3698
+ Mn as l,
3699
+ De as m,
3700
+ H as n,
3701
+ Fn as o,
3702
+ fe as p,
3703
+ Rn as q,
3704
+ Xt as r,
3705
+ _t as s,
3706
+ bn as t,
3707
+ $n as u,
3708
+ Ft as v,
3709
+ Tn as w,
3710
+ Sn as x,
3711
+ wn as y,
3712
+ Re as z
3713
+ };