react-semaphor 0.1.335 → 0.1.337

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  function s(e, i, n) {
2
2
  return n ? { code: e, message: i, path: n } : { code: e, message: i };
3
3
  }
4
- function h(e) {
4
+ function y(e) {
5
5
  const i = /* @__PURE__ */ new Set();
6
6
  for (const n of e) {
7
7
  if (i.has(n))
@@ -13,10 +13,10 @@ function h(e) {
13
13
  function a(e) {
14
14
  return typeof e == "string" && e.trim().length > 0;
15
15
  }
16
- function f(e) {
16
+ function p(e) {
17
17
  return !!(e && typeof e == "object" && !Array.isArray(e));
18
18
  }
19
- function _(e, i, n, t = {}) {
19
+ function h(e, i, n, o = {}) {
20
20
  if (!e || typeof e != "object") {
21
21
  n.push(s("missing_source", "Analytics intent needs a source.", i));
22
22
  return;
@@ -60,28 +60,28 @@ function _(e, i, n, t = {}) {
60
60
  "SQL source needs a connectionId.",
61
61
  `${i}.connectionId`
62
62
  )
63
- ), t.requireSqlText !== !1 && !a(e.sql) && n.push(s("missing_sql", "SQL source needs SQL text.", `${i}.sql`));
63
+ ), o.requireSqlText !== !1 && !a(e.sql) && n.push(s("missing_sql", "SQL source needs SQL text.", `${i}.sql`));
64
64
  return;
65
65
  }
66
66
  n.push(s("invalid_source_kind", "Source kind is not supported.", i));
67
67
  }
68
- function m(e, i, n, t = {}) {
69
- if (!e || !f(e)) {
70
- t.required && n.push(
68
+ function m(e, i, n, o = {}) {
69
+ if (!e || !p(e)) {
70
+ o.required && n.push(
71
71
  s("missing_field_ref", "Field reference needs a name.", i)
72
72
  );
73
73
  return;
74
74
  }
75
75
  a(e.name) || n.push(
76
76
  s("missing_field_ref", "Field reference needs a name.", `${i}.name`)
77
- ), e.source !== void 0 && _(e.source, `${i}.source`, n, {
77
+ ), e.source !== void 0 && h(e.source, `${i}.source`, n, {
78
78
  requireSqlText: !1
79
79
  });
80
80
  }
81
81
  function k(e, i) {
82
82
  if (e.analysis === void 0)
83
83
  return;
84
- if (!f(e.analysis)) {
84
+ if (!p(e.analysis)) {
85
85
  i.push(
86
86
  s(
87
87
  "invalid_metric_analysis",
@@ -115,140 +115,239 @@ function k(e, i) {
115
115
  )
116
116
  );
117
117
  const { timeWindow: n } = e.analysis;
118
- if (n !== void 0) {
119
- if (!f(n)) {
120
- i.push(
118
+ n !== void 0 && b(n, "analysis.timeWindow", i);
119
+ }
120
+ function b(e, i, n) {
121
+ if (!p(e)) {
122
+ n.push(
123
+ s(
124
+ "invalid_time_window",
125
+ "Time window must be a structured object.",
126
+ i
127
+ )
128
+ );
129
+ return;
130
+ }
131
+ e.unit !== "second" && e.unit !== "minute" && e.unit !== "hour" && e.unit !== "day" && e.unit !== "week" && e.unit !== "month" && e.unit !== "quarter" && e.unit !== "year" && n.push(
132
+ s(
133
+ "invalid_time_window",
134
+ "Time window unit must be second, minute, hour, day, week, month, quarter, or year.",
135
+ `${i}.unit`
136
+ )
137
+ ), (typeof e.value != "number" || !Number.isFinite(e.value) || e.value <= 0) && n.push(
138
+ s(
139
+ "invalid_time_window",
140
+ "Time window value must be a positive number.",
141
+ `${i}.value`
142
+ )
143
+ ), e.anchor !== void 0 && e.anchor !== "now" && e.anchor !== "latest_available" && n.push(
144
+ s(
145
+ "invalid_time_window",
146
+ "Time window anchor must be now or latest_available.",
147
+ `${i}.anchor`
148
+ )
149
+ );
150
+ }
151
+ function q(e, i, n) {
152
+ if (e !== void 0) {
153
+ if (!Array.isArray(e)) {
154
+ n.push(
121
155
  s(
122
- "invalid_time_window",
123
- "Analysis timeWindow must be a structured object.",
124
- "analysis.timeWindow"
156
+ "invalid_analytics_filters",
157
+ "Analytics filters must be an array.",
158
+ i
125
159
  )
126
160
  );
127
161
  return;
128
162
  }
129
- n.unit !== "day" && n.unit !== "month" && i.push(
163
+ e.forEach((o, f) => {
164
+ const d = `${i}.${f}`;
165
+ if (!p(o)) {
166
+ n.push(
167
+ s(
168
+ "invalid_analytics_filter",
169
+ "Analytics filter must be a structured object.",
170
+ d
171
+ )
172
+ );
173
+ return;
174
+ }
175
+ const r = o;
176
+ m(r.field, `${d}.field`, n, {
177
+ required: !0
178
+ }), r.operator !== void 0 && r.operator !== "=" && r.operator !== "!=" && r.operator !== "in" && r.operator !== "not_in" && r.operator !== "contains" && r.operator !== "not_contains" && r.operator !== "between" && r.operator !== "not_between" && r.operator !== ">" && r.operator !== ">=" && r.operator !== "<" && r.operator !== "<=" && r.operator !== "is_null" && r.operator !== "is_not_null" && n.push(
179
+ s(
180
+ "invalid_analytics_filter_operator",
181
+ "Analytics filter operator is not supported.",
182
+ `${d}.operator`
183
+ )
184
+ ), r.value === void 0 && r.values === void 0 && r.operator !== "is_null" && r.operator !== "is_not_null" && n.push(
185
+ s(
186
+ "missing_analytics_filter_value",
187
+ "Analytics filter needs value or values unless it is a null check.",
188
+ d
189
+ )
190
+ ), r.values !== void 0 && !Array.isArray(r.values) && n.push(
191
+ s(
192
+ "invalid_analytics_filter_values",
193
+ "Analytics filter values must be an array when provided.",
194
+ `${d}.values`
195
+ )
196
+ );
197
+ });
198
+ }
199
+ }
200
+ function g(e) {
201
+ var o, f, d, r;
202
+ const i = [], n = [];
203
+ if (!e || typeof e != "object")
204
+ return {
205
+ ok: !1,
206
+ errors: [
207
+ s(
208
+ "invalid_analytics_intent",
209
+ "Analytics intent must be a structured object."
210
+ )
211
+ ],
212
+ warnings: n,
213
+ repairHints: [
214
+ {
215
+ code: "invalid_analytics_intent",
216
+ recommendedNextStep: "Send one structured analytics intent object with kind, source, and required fields."
217
+ }
218
+ ]
219
+ };
220
+ if (e.version !== void 0 && e.version !== 1 && i.push(
221
+ s("invalid_version", "Analytics intent version must be 1.", "version")
222
+ ), h(e.source, "source", i, {
223
+ requireSqlText: e.kind !== "sql" || !a(e.sql)
224
+ }), e.kind === "metric") {
225
+ const u = Array.isArray(e.metrics) ? e.metrics.filter(a) : [];
226
+ if (!Array.isArray(e.metrics) || e.metrics.length === 0 ? i.push(
227
+ s("missing_metric", "Metric intent needs at least one metric.", "metrics")
228
+ ) : e.metrics.some((t) => !a(t)) && i.push(
229
+ s(
230
+ "invalid_metric_list",
231
+ "Metric intent metrics must be an array of non-empty metric names.",
232
+ "metrics"
233
+ )
234
+ ), u.length > 0) {
235
+ const t = y(u);
236
+ t && i.push(
237
+ s(
238
+ "duplicate_metric",
239
+ `Metric intent has duplicate metric "${t}".`,
240
+ "metrics"
241
+ )
242
+ );
243
+ }
244
+ if (e.primaryMetric !== void 0 && (!a(e.primaryMetric) || u.length > 0 && !u.includes(e.primaryMetric)) && i.push(
130
245
  s(
131
- "invalid_time_window",
132
- "Analysis timeWindow unit must be day or month.",
133
- "analysis.timeWindow.unit"
246
+ "invalid_primary_metric",
247
+ "Metric intent primaryMetric must be one of metrics.",
248
+ "primaryMetric"
134
249
  )
135
- ), (typeof n.value != "number" || !Number.isFinite(n.value) || n.value <= 0) && i.push(
250
+ ), e.metricRefs !== void 0 && !Array.isArray(e.metricRefs))
251
+ i.push(
252
+ s(
253
+ "invalid_metric_refs",
254
+ "Metric intent metricRefs must be an array of field references.",
255
+ "metricRefs"
256
+ )
257
+ );
258
+ else if (Array.isArray(e.metricRefs)) {
259
+ e.metricRefs.forEach((c, _) => {
260
+ m(c, `metricRefs.${_}`, i, {
261
+ required: !0
262
+ });
263
+ });
264
+ const t = e.metricRefs.filter(
265
+ (c) => p(c) && a(c.name)
266
+ ).map((c) => c.name);
267
+ (u.length > 0 ? t.filter(
268
+ (c) => !u.includes(c)
269
+ ) : []).length > 0 && i.push(
270
+ s(
271
+ "invalid_metric_refs",
272
+ "Metric intent metricRefs must reference names included in metrics.",
273
+ "metricRefs"
274
+ )
275
+ );
276
+ }
277
+ e.dimensions !== void 0 && !Array.isArray(e.dimensions) ? i.push(
136
278
  s(
137
- "invalid_time_window",
138
- "Analysis timeWindow value must be a positive number.",
139
- "analysis.timeWindow.value"
279
+ "invalid_metric_dimensions",
280
+ "Metric intent dimensions must be an array of field references.",
281
+ "dimensions"
140
282
  )
141
- ), n.anchor !== void 0 && n.anchor !== "now" && n.anchor !== "latest_available" && i.push(
283
+ ) : Array.isArray(e.dimensions) && e.dimensions.some(
284
+ (t) => !p(t) || !a(t.name)
285
+ ) && i.push(
142
286
  s(
143
- "invalid_time_window",
144
- "Analysis timeWindow anchor must be now or latest_available.",
145
- "analysis.timeWindow.anchor"
287
+ "invalid_metric_dimensions",
288
+ "Metric intent dimensions must be an array of field references with names.",
289
+ "dimensions"
146
290
  )
147
- );
148
- }
149
- }
150
- function v(e) {
151
- var t, c, d, p;
152
- const i = [], n = [];
153
- return !e || typeof e != "object" ? {
154
- ok: !1,
155
- errors: [
291
+ ), e.dateField !== void 0 && m(e.dateField, "dateField", i), e.timeWindow !== void 0 && (b(e.timeWindow, "timeWindow", i), e.dateField || i.push(
156
292
  s(
157
- "invalid_analytics_intent",
158
- "Analytics intent must be a structured object."
293
+ "missing_time_window_date_field",
294
+ "Metric timeWindow needs a dateField.",
295
+ "dateField"
159
296
  )
160
- ],
161
- warnings: n,
162
- repairHints: [
163
- {
164
- code: "invalid_analytics_intent",
165
- recommendedNextStep: "Send one structured analytics intent object with kind, source, and required fields."
166
- }
167
- ]
168
- } : (e.version !== void 0 && e.version !== 1 && i.push(
169
- s("invalid_version", "Analytics intent version must be 1.", "version")
170
- ), _(e.source, "source", i, {
171
- requireSqlText: e.kind !== "sql" || !a(e.sql)
172
- }), e.kind === "metric" ? (a(e.metric) || i.push(
173
- s("missing_metric", "Metric intent needs a metric.", "metric")
174
- ), e.metrics !== void 0 && !Array.isArray(e.metrics) ? i.push(
175
- s(
176
- "invalid_metric_list",
177
- "Metric intent metrics must be an array of metric names.",
178
- "metrics"
179
- )
180
- ) : Array.isArray(e.metrics) && e.metrics.some((l) => !a(l)) && i.push(
181
- s(
182
- "invalid_metric_list",
183
- "Metric intent metrics must be an array of non-empty metric names.",
184
- "metrics"
185
- )
186
- ), e.dimensions !== void 0 && !Array.isArray(e.dimensions) ? i.push(
187
- s(
188
- "invalid_metric_dimensions",
189
- "Metric intent dimensions must be an array of field references.",
190
- "dimensions"
191
- )
192
- ) : Array.isArray(e.dimensions) && e.dimensions.some(
193
- (l) => !f(l) || !a(l.name)
194
- ) && i.push(
195
- s(
196
- "invalid_metric_dimensions",
197
- "Metric intent dimensions must be an array of field references with names.",
198
- "dimensions"
199
- )
200
- ), e.dateField !== void 0 && m(e.dateField, "dateField", i), Array.isArray(e.dimensions) && e.dimensions.forEach((l, r) => {
201
- m(l, `dimensions.${r}`, i);
202
- }), k(e, i)) : e.kind === "records" ? (!Array.isArray(e.fields) || e.fields.length === 0 ? i.push(
297
+ )), q(e.filters, "filters", i), Array.isArray(e.dimensions) && e.dimensions.forEach((t, l) => {
298
+ m(t, `dimensions.${l}`, i);
299
+ }), k(e, i);
300
+ } else e.kind === "records" ? (!Array.isArray(e.fields) || e.fields.length === 0 ? i.push(
203
301
  s(
204
302
  "missing_record_fields",
205
303
  "Records intent needs at least one field.",
206
304
  "fields"
207
305
  )
208
306
  ) : e.fields.some(
209
- (l) => !f(l) || !a(l.name)
307
+ (u) => !p(u) || !a(u.name)
210
308
  ) && i.push(
211
309
  s(
212
310
  "invalid_record_fields",
213
311
  "Records intent fields must be field references with names.",
214
312
  "fields"
215
313
  )
216
- ), Array.isArray(e.fields) && e.fields.forEach((l, r) => {
217
- m(l, `fields.${r}`, i);
314
+ ), Array.isArray(e.fields) && e.fields.forEach((u, t) => {
315
+ m(u, `fields.${t}`, i);
218
316
  }), e.dateField !== void 0 && m(e.dateField, "dateField", i)) : e.kind === "inputOptions" ? ((!e.field || !a(e.field.name)) && i.push(
219
317
  s(
220
318
  "missing_input_options_field",
221
319
  "Input options intent needs a field.",
222
320
  "field"
223
321
  )
224
- ), m(e.field, "field", i, { required: !0 })) : e.kind === "sql" ? (((t = e.source) == null ? void 0 : t.kind) !== "sql" && ((c = e.source) == null ? void 0 : c.kind) !== "physical" && i.push(
322
+ ), m(e.field, "field", i, { required: !0 })) : e.kind === "sql" ? (((o = e.source) == null ? void 0 : o.kind) !== "sql" && ((f = e.source) == null ? void 0 : f.kind) !== "physical" && i.push(
225
323
  s(
226
324
  "invalid_sql_source",
227
325
  "SQL analytics intent must use a SQL or physical source.",
228
326
  "source"
229
327
  )
230
- ), a(e.sql) && ((d = e.source) == null ? void 0 : d.kind) === "sql" && a(e.source.sql) && y(e.sql) !== y(e.source.sql) && i.push(
328
+ ), a(e.sql) && ((d = e.source) == null ? void 0 : d.kind) === "sql" && a(e.source.sql) && v(e.sql) !== v(e.source.sql) && i.push(
231
329
  s(
232
330
  "conflicting_sql",
233
331
  "SQL analytics intent cannot define different SQL text in source.sql and sql.",
234
332
  "sql"
235
333
  )
236
- ), !a(e.sql) && !(((p = e.source) == null ? void 0 : p.kind) === "sql" && a(e.source.sql)) && i.push(s("missing_sql", "SQL analytics intent needs SQL text.", "sql")), Array.isArray(e.fields) && e.fields.forEach((l, r) => {
237
- m(l, `fields.${r}`, i);
334
+ ), !a(e.sql) && !(((r = e.source) == null ? void 0 : r.kind) === "sql" && a(e.source.sql)) && i.push(s("missing_sql", "SQL analytics intent needs SQL text.", "sql")), Array.isArray(e.fields) && e.fields.forEach((u, t) => {
335
+ m(u, `fields.${t}`, i);
238
336
  })) : i.push(
239
337
  s("invalid_analytics_kind", "Analytics kind is not supported.", "kind")
240
- ), {
338
+ );
339
+ return {
241
340
  ok: i.length === 0,
242
341
  errors: i,
243
342
  warnings: n,
244
- repairHints: q(i)
245
- });
343
+ repairHints: S(i)
344
+ };
246
345
  }
247
- function y(e) {
346
+ function v(e) {
248
347
  return e.replace(/\r\n/g, `
249
348
  `).trim();
250
349
  }
251
- function A(e) {
350
+ function $(e) {
252
351
  const i = [], n = [];
253
352
  if (!e || typeof e != "object")
254
353
  return {
@@ -276,18 +375,18 @@ function A(e) {
276
375
  "Answer-obligations operation intent needs at least one obligation.",
277
376
  "obligations"
278
377
  )
279
- ) : e.obligations.forEach((t, c) => {
280
- a(t.id) || i.push(
378
+ ) : e.obligations.forEach((o, f) => {
379
+ a(o.id) || i.push(
281
380
  s(
282
381
  "missing_obligation_id",
283
382
  "Each analytics obligation needs an id.",
284
- `obligations.${c}.id`
383
+ `obligations.${f}.id`
285
384
  )
286
- ), a(t.prompt) || i.push(
385
+ ), a(o.prompt) || i.push(
287
386
  s(
288
387
  "missing_obligation_prompt",
289
388
  "Each analytics obligation needs a prompt.",
290
- `obligations.${c}.prompt`
389
+ `obligations.${f}.prompt`
291
390
  )
292
391
  );
293
392
  });
@@ -299,10 +398,10 @@ function A(e) {
299
398
  "instruction"
300
399
  )
301
400
  ), e.analyticsIntent) {
302
- const t = v(
401
+ const o = g(
303
402
  e.analyticsIntent
304
403
  );
305
- i.push(...t.errors), n.push(...t.warnings);
404
+ i.push(...o.errors), n.push(...o.warnings);
306
405
  }
307
406
  } else
308
407
  i.push(
@@ -316,10 +415,10 @@ function A(e) {
316
415
  ok: i.length === 0,
317
416
  errors: i,
318
417
  warnings: n,
319
- repairHints: b(i)
418
+ repairHints: w(i)
320
419
  };
321
420
  }
322
- function x(e) {
421
+ function R(e) {
323
422
  const i = [], n = [];
324
423
  if (!e || typeof e != "object")
325
424
  return {
@@ -347,8 +446,8 @@ function x(e) {
347
446
  "kind"
348
447
  )
349
448
  );
350
- const t = A(e.operationIntent);
351
- return i.push(...t.errors), n.push(...t.warnings), Array.isArray(e.plannedToolCalls) || i.push(
449
+ const o = $(e.operationIntent);
450
+ return i.push(...o.errors), n.push(...o.warnings), Array.isArray(e.plannedToolCalls) || i.push(
352
451
  s(
353
452
  "invalid_planned_tool_calls",
354
453
  "Recovery plan plannedToolCalls must be an array.",
@@ -358,16 +457,16 @@ function x(e) {
358
457
  ok: i.length === 0,
359
458
  errors: i,
360
459
  warnings: n,
361
- repairHints: b(i)
460
+ repairHints: w(i)
362
461
  };
363
462
  }
364
- function b(e) {
463
+ function w(e) {
365
464
  return e.map((i) => ({
366
465
  code: i.code,
367
466
  recommendedNextStep: i.code === "missing_obligations" ? "Normalize the user request into one or more typed analytics obligations before recovery planning." : "Correct the operation/recovery contract shape before planning execution."
368
467
  }));
369
468
  }
370
- function q(e) {
469
+ function S(e) {
371
470
  return e.map((i) => {
372
471
  switch (i.code) {
373
472
  case "missing_source":
@@ -420,7 +519,7 @@ function q(e) {
420
519
  }
421
520
  }).filter((i) => !!i);
422
521
  }
423
- function S(e, i, n, t) {
522
+ function x(e, i, n, o) {
424
523
  if (!e || typeof e != "object") {
425
524
  n.push(s("invalid_view", "Dashboard view must be an object.", i));
426
525
  return;
@@ -436,7 +535,7 @@ function S(e, i, n, t) {
436
535
  return;
437
536
  }
438
537
  if (e.presentation.kind === "text") {
439
- a(e.text) || t.push(
538
+ a(e.text) || o.push(
440
539
  s(
441
540
  "missing_text_content",
442
541
  "Text views should include text content.",
@@ -455,13 +554,13 @@ function S(e, i, n, t) {
455
554
  );
456
555
  return;
457
556
  }
458
- const c = v(e.analytics);
459
- for (const d of c.errors)
557
+ const f = g(e.analytics);
558
+ for (const d of f.errors)
460
559
  n.push(
461
560
  s(d.code, d.message, `${i}.analytics${d.path ? `.${d.path}` : ""}`)
462
561
  );
463
- for (const d of c.warnings)
464
- t.push(
562
+ for (const d of f.warnings)
563
+ o.push(
465
564
  s(
466
565
  d.code,
467
566
  d.message,
@@ -469,7 +568,7 @@ function S(e, i, n, t) {
469
568
  )
470
569
  );
471
570
  }
472
- function $(e) {
571
+ function I(e) {
473
572
  const i = [], n = [];
474
573
  if (!e || typeof e != "object")
475
574
  return {
@@ -483,27 +582,27 @@ function $(e) {
483
582
  warnings: n
484
583
  };
485
584
  e.version !== 1 && i.push(s("invalid_version", "Dashboard intent version must be 1.")), e.kind !== "dashboard" && i.push(s("invalid_kind", "Experience intent kind must be dashboard.")), a(e.title) || i.push(s("missing_title", "Dashboard intent needs a title.", "title"));
486
- const t = Array.isArray(e.inputs) ? e.inputs : [], c = h(
487
- t.filter(f).map((r) => r.id).filter((r) => typeof r == "string")
585
+ const o = Array.isArray(e.inputs) ? e.inputs : [], f = y(
586
+ o.filter(p).map((t) => t.id).filter((t) => typeof t == "string")
488
587
  );
489
- c && i.push(
588
+ f && i.push(
490
589
  s(
491
590
  "duplicate_input_id",
492
- `Duplicate input id: ${c}.`,
591
+ `Duplicate input id: ${f}.`,
493
592
  "inputs"
494
593
  )
495
594
  );
496
- for (const [r, o] of t.entries()) {
497
- const u = `inputs.${r}`;
498
- if (!f(o)) {
499
- i.push(s("invalid_input", "Dashboard input must be an object.", u));
595
+ for (const [t, l] of o.entries()) {
596
+ const c = `inputs.${t}`;
597
+ if (!p(l)) {
598
+ i.push(s("invalid_input", "Dashboard input must be an object.", c));
500
599
  continue;
501
600
  }
502
- a(o.id) || i.push(s("missing_input_id", "Input needs an id.", `${u}.id`)), a(o.label) || i.push(
503
- s("missing_input_label", "Input needs a label.", `${u}.label`)
504
- ), !o.field || !a(o.field.name) ? i.push(
505
- s("missing_input_field", "Input needs a field.", `${u}.field`)
506
- ) : m(o.field, `${u}.field`, i), o.source && _(o.source, `${u}.source`, i);
601
+ a(l.id) || i.push(s("missing_input_id", "Input needs an id.", `${c}.id`)), a(l.label) || i.push(
602
+ s("missing_input_label", "Input needs a label.", `${c}.label`)
603
+ ), !l.field || !a(l.field.name) ? i.push(
604
+ s("missing_input_field", "Input needs a field.", `${c}.field`)
605
+ ) : m(l.field, `${c}.field`, i), l.source && h(l.source, `${c}.source`, i);
507
606
  }
508
607
  const d = Array.isArray(e.sections) ? e.sections : [];
509
608
  d.length === 0 && i.push(
@@ -513,40 +612,40 @@ function $(e) {
513
612
  "sections"
514
613
  )
515
614
  );
516
- const p = d.flatMap(
517
- (r) => r && typeof r == "object" && Array.isArray(r.views) ? r.views.filter(f).map((o) => o.id).filter((o) => !!o) : []
518
- ), l = h(p);
519
- l && i.push(
615
+ const r = d.flatMap(
616
+ (t) => t && typeof t == "object" && Array.isArray(t.views) ? t.views.filter(p).map((l) => l.id).filter((l) => !!l) : []
617
+ ), u = y(r);
618
+ u && i.push(
520
619
  s(
521
620
  "duplicate_view_id",
522
- `Duplicate dashboard view id: ${l}.`,
621
+ `Duplicate dashboard view id: ${u}.`,
523
622
  "sections"
524
623
  )
525
624
  );
526
- for (const [r, o] of d.entries()) {
527
- const u = `sections.${r}`;
528
- if (!o || typeof o != "object") {
625
+ for (const [t, l] of d.entries()) {
626
+ const c = `sections.${t}`;
627
+ if (!l || typeof l != "object") {
529
628
  i.push(
530
- s("invalid_section", "Dashboard section must be an object.", u)
629
+ s("invalid_section", "Dashboard section must be an object.", c)
531
630
  );
532
631
  continue;
533
632
  }
534
- if (a(o.title) || i.push(
535
- s("missing_section_title", "Dashboard section needs a title.", u)
536
- ), !Array.isArray(o.views) || o.views.length === 0) {
633
+ if (a(l.title) || i.push(
634
+ s("missing_section_title", "Dashboard section needs a title.", c)
635
+ ), !Array.isArray(l.views) || l.views.length === 0) {
537
636
  i.push(
538
637
  s(
539
638
  "missing_section_views",
540
639
  "Dashboard section needs at least one view.",
541
- `${u}.views`
640
+ `${c}.views`
542
641
  )
543
642
  );
544
643
  continue;
545
644
  }
546
- for (const [g, w] of o.views.entries())
547
- S(
548
- w,
549
- `${u}.views.${g}`,
645
+ for (const [_, A] of l.views.entries())
646
+ x(
647
+ A,
648
+ `${c}.views.${_}`,
550
649
  i,
551
650
  n
552
651
  );
@@ -554,8 +653,8 @@ function $(e) {
554
653
  return { ok: i.length === 0, errors: i, warnings: n };
555
654
  }
556
655
  export {
557
- A as a,
558
- x as b,
559
- $ as c,
560
- v
656
+ $ as a,
657
+ R as b,
658
+ I as c,
659
+ g as v
561
660
  };
@@ -0,0 +1,2 @@
1
+ "use strict";function s(e,i,n){return n?{code:e,message:i,path:n}:{code:e,message:i}}function h(e){const i=new Set;for(const n of e){if(i.has(n))return n;i.add(n)}return null}function a(e){return typeof e=="string"&&e.trim().length>0}function p(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function y(e,i,n,o={}){if(!e||typeof e!="object"){n.push(s("missing_source","Analytics intent needs a source.",i));return}if(e.kind==="semantic"){a(e.domainId)||n.push(s("missing_semantic_domain","Semantic source needs a domainId.",`${i}.domainId`)),a(e.datasetName)||n.push(s("missing_dataset_name","Semantic source needs a datasetName.",`${i}.datasetName`));return}if(e.kind==="physical"){a(e.connectionId)||n.push(s("missing_connection_id","Physical source needs a connectionId.",`${i}.connectionId`)),a(e.tableName)||n.push(s("missing_table_name","Physical source needs a tableName.",`${i}.tableName`));return}if(e.kind==="sql"){a(e.connectionId)||n.push(s("missing_connection_id","SQL source needs a connectionId.",`${i}.connectionId`)),o.requireSqlText!==!1&&!a(e.sql)&&n.push(s("missing_sql","SQL source needs SQL text.",`${i}.sql`));return}n.push(s("invalid_source_kind","Source kind is not supported.",i))}function m(e,i,n,o={}){if(!e||!p(e)){o.required&&n.push(s("missing_field_ref","Field reference needs a name.",i));return}a(e.name)||n.push(s("missing_field_ref","Field reference needs a name.",`${i}.name`)),e.source!==void 0&&y(e.source,`${i}.source`,n,{requireSqlText:!1})}function q(e,i){if(e.analysis===void 0)return;if(!p(e.analysis)){i.push(s("invalid_metric_analysis","Metric analysis must be a structured object.","analysis"));return}if(e.analysis.kind!=="period_change"){i.push(s("invalid_metric_analysis","Metric analysis kind is not supported.","analysis.kind"));return}e.dateField||i.push(s("missing_analysis_date_field","Period-change analysis needs a dateField.","dateField")),e.timeGrain||i.push(s("missing_analysis_time_grain","Period-change analysis needs a timeGrain.","timeGrain"));const{timeWindow:n}=e.analysis;n!==void 0&&g(n,"analysis.timeWindow",i)}function g(e,i,n){if(!p(e)){n.push(s("invalid_time_window","Time window must be a structured object.",i));return}e.unit!=="second"&&e.unit!=="minute"&&e.unit!=="hour"&&e.unit!=="day"&&e.unit!=="week"&&e.unit!=="month"&&e.unit!=="quarter"&&e.unit!=="year"&&n.push(s("invalid_time_window","Time window unit must be second, minute, hour, day, week, month, quarter, or year.",`${i}.unit`)),(typeof e.value!="number"||!Number.isFinite(e.value)||e.value<=0)&&n.push(s("invalid_time_window","Time window value must be a positive number.",`${i}.value`)),e.anchor!==void 0&&e.anchor!=="now"&&e.anchor!=="latest_available"&&n.push(s("invalid_time_window","Time window anchor must be now or latest_available.",`${i}.anchor`))}function $(e,i,n){if(e!==void 0){if(!Array.isArray(e)){n.push(s("invalid_analytics_filters","Analytics filters must be an array.",i));return}e.forEach((o,f)=>{const d=`${i}.${f}`;if(!p(o)){n.push(s("invalid_analytics_filter","Analytics filter must be a structured object.",d));return}const r=o;m(r.field,`${d}.field`,n,{required:!0}),r.operator!==void 0&&r.operator!=="="&&r.operator!=="!="&&r.operator!=="in"&&r.operator!=="not_in"&&r.operator!=="contains"&&r.operator!=="not_contains"&&r.operator!=="between"&&r.operator!=="not_between"&&r.operator!==">"&&r.operator!==">="&&r.operator!=="<"&&r.operator!=="<="&&r.operator!=="is_null"&&r.operator!=="is_not_null"&&n.push(s("invalid_analytics_filter_operator","Analytics filter operator is not supported.",`${d}.operator`)),r.value===void 0&&r.values===void 0&&r.operator!=="is_null"&&r.operator!=="is_not_null"&&n.push(s("missing_analytics_filter_value","Analytics filter needs value or values unless it is a null check.",d)),r.values!==void 0&&!Array.isArray(r.values)&&n.push(s("invalid_analytics_filter_values","Analytics filter values must be an array when provided.",`${d}.values`))})}}function v(e){var o,f,d,r;const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[s("invalid_analytics_intent","Analytics intent must be a structured object.")],warnings:n,repairHints:[{code:"invalid_analytics_intent",recommendedNextStep:"Send one structured analytics intent object with kind, source, and required fields."}]};if(e.version!==void 0&&e.version!==1&&i.push(s("invalid_version","Analytics intent version must be 1.","version")),y(e.source,"source",i,{requireSqlText:e.kind!=="sql"||!a(e.sql)}),e.kind==="metric"){const u=Array.isArray(e.metrics)?e.metrics.filter(a):[];if(!Array.isArray(e.metrics)||e.metrics.length===0?i.push(s("missing_metric","Metric intent needs at least one metric.","metrics")):e.metrics.some(t=>!a(t))&&i.push(s("invalid_metric_list","Metric intent metrics must be an array of non-empty metric names.","metrics")),u.length>0){const t=h(u);t&&i.push(s("duplicate_metric",`Metric intent has duplicate metric "${t}".`,"metrics"))}if(e.primaryMetric!==void 0&&(!a(e.primaryMetric)||u.length>0&&!u.includes(e.primaryMetric))&&i.push(s("invalid_primary_metric","Metric intent primaryMetric must be one of metrics.","primaryMetric")),e.metricRefs!==void 0&&!Array.isArray(e.metricRefs))i.push(s("invalid_metric_refs","Metric intent metricRefs must be an array of field references.","metricRefs"));else if(Array.isArray(e.metricRefs)){e.metricRefs.forEach((c,_)=>{m(c,`metricRefs.${_}`,i,{required:!0})});const t=e.metricRefs.filter(c=>p(c)&&a(c.name)).map(c=>c.name);(u.length>0?t.filter(c=>!u.includes(c)):[]).length>0&&i.push(s("invalid_metric_refs","Metric intent metricRefs must reference names included in metrics.","metricRefs"))}e.dimensions!==void 0&&!Array.isArray(e.dimensions)?i.push(s("invalid_metric_dimensions","Metric intent dimensions must be an array of field references.","dimensions")):Array.isArray(e.dimensions)&&e.dimensions.some(t=>!p(t)||!a(t.name))&&i.push(s("invalid_metric_dimensions","Metric intent dimensions must be an array of field references with names.","dimensions")),e.dateField!==void 0&&m(e.dateField,"dateField",i),e.timeWindow!==void 0&&(g(e.timeWindow,"timeWindow",i),e.dateField||i.push(s("missing_time_window_date_field","Metric timeWindow needs a dateField.","dateField"))),$(e.filters,"filters",i),Array.isArray(e.dimensions)&&e.dimensions.forEach((t,l)=>{m(t,`dimensions.${l}`,i)}),q(e,i)}else e.kind==="records"?(!Array.isArray(e.fields)||e.fields.length===0?i.push(s("missing_record_fields","Records intent needs at least one field.","fields")):e.fields.some(u=>!p(u)||!a(u.name))&&i.push(s("invalid_record_fields","Records intent fields must be field references with names.","fields")),Array.isArray(e.fields)&&e.fields.forEach((u,t)=>{m(u,`fields.${t}`,i)}),e.dateField!==void 0&&m(e.dateField,"dateField",i)):e.kind==="inputOptions"?((!e.field||!a(e.field.name))&&i.push(s("missing_input_options_field","Input options intent needs a field.","field")),m(e.field,"field",i,{required:!0})):e.kind==="sql"?(((o=e.source)==null?void 0:o.kind)!=="sql"&&((f=e.source)==null?void 0:f.kind)!=="physical"&&i.push(s("invalid_sql_source","SQL analytics intent must use a SQL or physical source.","source")),a(e.sql)&&((d=e.source)==null?void 0:d.kind)==="sql"&&a(e.source.sql)&&b(e.sql)!==b(e.source.sql)&&i.push(s("conflicting_sql","SQL analytics intent cannot define different SQL text in source.sql and sql.","sql")),!a(e.sql)&&!(((r=e.source)==null?void 0:r.kind)==="sql"&&a(e.source.sql))&&i.push(s("missing_sql","SQL analytics intent needs SQL text.","sql")),Array.isArray(e.fields)&&e.fields.forEach((u,t)=>{m(u,`fields.${t}`,i)})):i.push(s("invalid_analytics_kind","Analytics kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:n,repairHints:x(i)}}function b(e){return e.replace(/\r\n/g,`
2
+ `).trim()}function A(e){const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[s("invalid_operation_intent","Operation intent must be a structured object.")],warnings:n,repairHints:[{code:"invalid_operation_intent",recommendedNextStep:"Send one typed operation intent with version, kind, and required operation fields."}]};if(e.version!==1&&i.push(s("invalid_version","Operation intent version must be 1.","version")),e.kind==="answer_obligations")!Array.isArray(e.obligations)||e.obligations.length===0?i.push(s("missing_obligations","Answer-obligations operation intent needs at least one obligation.","obligations")):e.obligations.forEach((o,f)=>{a(o.id)||i.push(s("missing_obligation_id","Each analytics obligation needs an id.",`obligations.${f}.id`)),a(o.prompt)||i.push(s("missing_obligation_prompt","Each analytics obligation needs a prompt.",`obligations.${f}.prompt`))});else if(e.kind==="dashboard_change"||e.kind==="data_app_change"){if(a(e.instruction)||i.push(s("missing_instruction","Change operation intent needs an instruction.","instruction")),e.analyticsIntent){const o=v(e.analyticsIntent);i.push(...o.errors),n.push(...o.warnings)}}else i.push(s("invalid_operation_kind","Operation intent kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:n,repairHints:w(i)}}function S(e){const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[s("invalid_recovery_plan","Analytics recovery plan must be a structured object.")],warnings:n,repairHints:[{code:"invalid_recovery_plan",recommendedNextStep:"Return a typed recovery plan with operationIntent and plannedToolCalls."}]};e.version!==1&&i.push(s("invalid_version","Recovery plan version must be 1.","version")),e.kind!=="analytics_recovery_plan"&&i.push(s("invalid_recovery_plan_kind","Recovery plan kind must be analytics_recovery_plan.","kind"));const o=A(e.operationIntent);return i.push(...o.errors),n.push(...o.warnings),Array.isArray(e.plannedToolCalls)||i.push(s("invalid_planned_tool_calls","Recovery plan plannedToolCalls must be an array.","plannedToolCalls")),{ok:i.length===0,errors:i,warnings:n,repairHints:w(i)}}function w(e){return e.map(i=>({code:i.code,recommendedNextStep:i.code==="missing_obligations"?"Normalize the user request into one or more typed analytics obligations before recovery planning.":"Correct the operation/recovery contract shape before planning execution."}))}function x(e){return e.map(i=>{switch(i.code){case"missing_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Provide a semantic, physical, or SQL source before executing analytics."};case"missing_metric":return{code:i.code,fieldRole:"metric",recommendedNextStep:"Choose one exact metric from the grounded schema candidates."};case"missing_record_fields":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide at least one field for the records intent."};case"missing_input_options_field":return{code:i.code,fieldRole:"input",recommendedNextStep:"Provide the exact field whose option values should be listed."};case"missing_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Provide bounded read-only SQL with an explicit outer LIMIT."};case"conflicting_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Use one canonical SQL text location for the intent; prefer top-level sql."};case"missing_semantic_domain":case"missing_dataset_name":case"missing_connection_id":case"missing_table_name":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use grounded catalog metadata to fill the missing source reference."};default:return}}).filter(i=>!!i)}function R(e,i,n,o){if(!e||typeof e!="object"){n.push(s("invalid_view","Dashboard view must be an object.",i));return}if(a(e.title)||n.push(s("missing_view_title","Dashboard view needs a title.",i)),!e.presentation||typeof e.presentation!="object"){n.push(s("missing_presentation","Dashboard view needs a presentation.",`${i}.presentation`));return}if(e.presentation.kind==="text"){a(e.text)||o.push(s("missing_text_content","Text views should include text content.",`${i}.text`));return}if(!e.analytics){n.push(s("missing_view_analytics","Non-text dashboard views need analytics intent.",`${i}.analytics`));return}const f=v(e.analytics);for(const d of f.errors)n.push(s(d.code,d.message,`${i}.analytics${d.path?`.${d.path}`:""}`));for(const d of f.warnings)o.push(s(d.code,d.message,`${i}.analytics${d.path?`.${d.path}`:""}`))}function I(e){const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[s("invalid_dashboard_intent","Dashboard intent must be a structured object.")],warnings:n};e.version!==1&&i.push(s("invalid_version","Dashboard intent version must be 1.")),e.kind!=="dashboard"&&i.push(s("invalid_kind","Experience intent kind must be dashboard.")),a(e.title)||i.push(s("missing_title","Dashboard intent needs a title.","title"));const o=Array.isArray(e.inputs)?e.inputs:[],f=h(o.filter(p).map(t=>t.id).filter(t=>typeof t=="string"));f&&i.push(s("duplicate_input_id",`Duplicate input id: ${f}.`,"inputs"));for(const[t,l]of o.entries()){const c=`inputs.${t}`;if(!p(l)){i.push(s("invalid_input","Dashboard input must be an object.",c));continue}a(l.id)||i.push(s("missing_input_id","Input needs an id.",`${c}.id`)),a(l.label)||i.push(s("missing_input_label","Input needs a label.",`${c}.label`)),!l.field||!a(l.field.name)?i.push(s("missing_input_field","Input needs a field.",`${c}.field`)):m(l.field,`${c}.field`,i),l.source&&y(l.source,`${c}.source`,i)}const d=Array.isArray(e.sections)?e.sections:[];d.length===0&&i.push(s("missing_sections","Dashboard intent needs at least one section.","sections"));const r=d.flatMap(t=>t&&typeof t=="object"&&Array.isArray(t.views)?t.views.filter(p).map(l=>l.id).filter(l=>!!l):[]),u=h(r);u&&i.push(s("duplicate_view_id",`Duplicate dashboard view id: ${u}.`,"sections"));for(const[t,l]of d.entries()){const c=`sections.${t}`;if(!l||typeof l!="object"){i.push(s("invalid_section","Dashboard section must be an object.",c));continue}if(a(l.title)||i.push(s("missing_section_title","Dashboard section needs a title.",c)),!Array.isArray(l.views)||l.views.length===0){i.push(s("missing_section_views","Dashboard section needs at least one view.",`${c}.views`));continue}for(const[_,k]of l.views.entries())R(k,`${c}.views.${_}`,i,n)}return{ok:i.length===0,errors:i,warnings:n}}exports.validateSemaphorAnalyticsIntent=v;exports.validateSemaphorAnalyticsRecoveryPlan=S;exports.validateSemaphorDashboardIntent=I;exports.validateSemaphorOperationIntent=A;