@claritylabs/cl-sdk 3.1.0 → 3.1.3

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.
package/dist/index.js CHANGED
@@ -3611,6 +3611,12 @@ function moneyAmount(value) {
3611
3611
  function normalizeLabel(value) {
3612
3612
  return normalizeWhitespace3(value ?? "").toLowerCase();
3613
3613
  }
3614
+ function isGenericColumnLabel(value) {
3615
+ return /^column\s+\d+$/i.test(cleanValue(value) ?? "");
3616
+ }
3617
+ function isHeaderRow(row) {
3618
+ return row.metadata?.isHeader === true || row.metadata?.isHeader === "true";
3619
+ }
3614
3620
  var OPERATIONAL_COVERAGE_TERM_KINDS = /* @__PURE__ */ new Set([
3615
3621
  "each_claim_limit",
3616
3622
  "each_occurrence_limit",
@@ -3631,6 +3637,7 @@ function termKind(label, value) {
3631
3637
  if (/\bpremium\b/.test(text)) return "premium";
3632
3638
  if (/\bsub[-\s]?limit\b/.test(text)) return "sublimit";
3633
3639
  if (/\baggregate\b/.test(text)) return "aggregate_limit";
3640
+ if (/\beach\s+proceeding|per\s+proceeding\b/.test(text)) return "sublimit";
3634
3641
  if (/\beach\s+claim|per\s+claim\b/.test(text)) return "each_claim_limit";
3635
3642
  if (/\beach\s+occurrence|per\s+occurrence\b/.test(text)) return "each_occurrence_limit";
3636
3643
  if (/\beach\s+loss|per\s+loss\b/.test(text)) return "each_loss_limit";
@@ -3657,9 +3664,13 @@ function isNameCell(label, value) {
3657
3664
  const normalizedLabel = normalizeLabel(label);
3658
3665
  const normalizedValue = normalizeLabel(value);
3659
3666
  if (!value || moneyAmount(value) !== void 0) return false;
3667
+ if (/^item\s+\d+[.)]?\s*limits?\s+of\s+liability\b/.test(normalizedValue)) return false;
3660
3668
  if (/\b(coverage|coverage part|insuring agreement|description|item|name)\b/.test(normalizedLabel)) {
3661
3669
  return true;
3662
3670
  }
3671
+ if (/\b(sub[-\s]?limit|aggregate(?:\s+policy)?\s+limit|limit\s+of\s+liability)\b/.test(normalizedLabel) && /\b[a-z][a-z0-9&/ -]{2,}\b/.test(normalizedValue) && !/\bcoverage\s+part\s+[a-z]\)?$/.test(normalizedValue)) {
3672
+ return true;
3673
+ }
3663
3674
  if (/^column\s+1$/.test(normalizedLabel) && !/^(item\s+\d+|nwc-|iso-|cg |il |form\b|page\b)/i.test(normalizedValue)) {
3664
3675
  return true;
3665
3676
  }
@@ -3678,13 +3689,32 @@ function childMap(nodes) {
3678
3689
  for (const group of children.values()) group.sort((left, right) => left.order - right.order);
3679
3690
  return children;
3680
3691
  }
3681
- function cellRows(row, children) {
3692
+ function rawCellRows(row, children) {
3682
3693
  return (children.get(row.id) ?? []).filter((child) => child.kind === "table_cell").map((cell) => ({
3683
3694
  label: cleanValue(cell.title) ?? "Value",
3684
3695
  value: cleanValue(cell.textExcerpt ?? cell.description ?? cell.title) ?? "",
3685
3696
  node: cell
3686
3697
  })).filter((cell) => cell.value);
3687
3698
  }
3699
+ function headerLabelsForRow(row, children) {
3700
+ if (!row.parentId) return [];
3701
+ const labels = [];
3702
+ const siblingRows = (children.get(row.parentId) ?? []).filter((candidate) => candidate.kind === "table_row" && candidate.order < row.order).sort((left, right) => left.order - right.order);
3703
+ for (const sibling of siblingRows) {
3704
+ if (!isHeaderRow(sibling)) continue;
3705
+ for (const [index, cell] of rawCellRows(sibling, children).entries()) {
3706
+ const label = cleanValue(cell.value) ?? cleanValue(cell.label);
3707
+ if (label && !isGenericColumnLabel(label)) labels[index] = label;
3708
+ }
3709
+ }
3710
+ return labels;
3711
+ }
3712
+ function cellRows(row, children, headerLabels = []) {
3713
+ return rawCellRows(row, children).map((cell, index) => ({
3714
+ ...cell,
3715
+ label: isGenericColumnLabel(cell.label) && headerLabels[index] ? headerLabels[index] : cell.label
3716
+ }));
3717
+ }
3688
3718
  function directChildren(parent, children) {
3689
3719
  return children.get(parent.id) ?? [];
3690
3720
  }
@@ -3727,18 +3757,10 @@ function sourceIds(nodes) {
3727
3757
  sourceSpanIds: [...new Set(nodes.flatMap((node) => node.sourceSpanIds))]
3728
3758
  };
3729
3759
  }
3730
- function relabelGenericTerm(term, label) {
3731
- const cleanLabel = cleanValue(label);
3732
- if (!cleanLabel || !/^column\s+\d+$/i.test(term.label)) return term;
3733
- return {
3734
- ...term,
3735
- kind: termKind(cleanLabel, term.value),
3736
- label: cleanLabel
3737
- };
3738
- }
3739
3760
  function termFromCell(params) {
3740
- const value = cleanValue(params.value);
3761
+ const value = cleanCoverageTermValue(params.value);
3741
3762
  if (!value) return void 0;
3763
+ if (isRejectedCoverageTermValue(params.label, value)) return void 0;
3742
3764
  const nodes = [params.row, params.cell].filter((node) => Boolean(node));
3743
3765
  const kind = termKind(params.label, value);
3744
3766
  const amount = moneyAmount(value);
@@ -3751,20 +3773,38 @@ function termFromCell(params) {
3751
3773
  ...sourceIds(nodes)
3752
3774
  };
3753
3775
  }
3776
+ function cleanCoverageTermValue(value) {
3777
+ return cleanValue(value)?.replace(/\s+\/\s*$/, "").trim();
3778
+ }
3779
+ function isRejectedCoverageTermValue(label, value) {
3780
+ if (/\bshown\s+in\s+item\s*\d+\b/i.test(value) && moneyAmount(value) === void 0) return true;
3781
+ if (/\b(does not afford coverage|doesn't afford coverage|no coverage|remains excluded|is excluded|are excluded|shall not cover|will not cover)\b/i.test(value) && moneyAmount(value) === void 0) {
3782
+ return true;
3783
+ }
3784
+ if (/^for:\s*\(\d+\)/i.test(label) && moneyAmount(value) === void 0) return true;
3785
+ if (value.length > 80 && /\b(exclusion|excluded|shall not|will not|does not|failure to)\b/i.test(value) && moneyAmount(value) === void 0) return true;
3786
+ return false;
3787
+ }
3754
3788
  function termsFromRow(row, children) {
3755
- const cells = cellRows(row, children);
3789
+ const cells = cellRows(row, children, headerLabelsForRow(row, children));
3756
3790
  if (cells.length > 0) {
3757
3791
  const pairedTerms = [];
3792
+ const pairedIndexes = /* @__PURE__ */ new Set();
3758
3793
  for (const [index, cell] of cells.entries()) {
3759
3794
  const next = cells[index + 1];
3760
3795
  if (!next) continue;
3796
+ if (!isGenericColumnLabel(cell.label) && isNameCell(cell.label, cell.value)) continue;
3761
3797
  if (!isCoverageTermLabel(cell.value)) continue;
3762
3798
  if (isCoverageTermLabel(next.value) && moneyAmount(next.value) === void 0) continue;
3763
3799
  const term = termFromCell({ row, cell: next.node, label: cell.value, value: next.value });
3764
- if (term) pairedTerms.push(term);
3800
+ if (term) {
3801
+ pairedTerms.push(term);
3802
+ pairedIndexes.add(index);
3803
+ pairedIndexes.add(index + 1);
3804
+ }
3765
3805
  }
3766
- if (pairedTerms.length > 0) return pairedTerms;
3767
- return cells.filter((cell) => isValueCell(cell.label, cell.value)).map((cell) => termFromCell({ row, cell: cell.node, label: cell.label, value: cell.value })).filter((term) => Boolean(term));
3806
+ const valueTerms = cells.filter((_, index) => !pairedIndexes.has(index)).filter((cell) => isValueCell(cell.label, cell.value)).map((cell) => termFromCell({ row, cell: cell.node, label: cell.label, value: cell.value })).filter((term) => Boolean(term));
3807
+ return [...pairedTerms, ...valueTerms];
3768
3808
  }
3769
3809
  const text = normalizeWhitespace3(row.textExcerpt ?? row.description ?? nodeText(row));
3770
3810
  const terms = [];
@@ -3790,11 +3830,11 @@ function termsFromRow(row, children) {
3790
3830
  return terms;
3791
3831
  }
3792
3832
  function nameFromRow(row, children) {
3793
- const declarationName = declarationCoverageNameFromRow(row, children);
3794
- if (declarationName) return declarationName;
3795
- const cells = cellRows(row, children);
3833
+ const cells = cellRows(row, children, headerLabelsForRow(row, children));
3796
3834
  const named = cells.find((cell) => isNameCell(cell.label, cell.value));
3797
3835
  if (named) return cleanValue(named.value);
3836
+ const declarationName = declarationCoverageNameFromRow(row, children);
3837
+ if (declarationName) return declarationName;
3798
3838
  return coverageNameFromRow(row.textExcerpt ?? row.description ?? nodeText(row));
3799
3839
  }
3800
3840
  function legacyLimit(terms) {
@@ -3827,7 +3867,7 @@ function isOperationalCoverageRow(coverage) {
3827
3867
  if (coverage.name.split(/\s+/).length > 16 && !/\b(coverage|liability|sub[-\s]?limit|aggregate|each\s+(claim|loss|occurrence)|limit)\b/i.test(coverage.name)) {
3828
3868
  return false;
3829
3869
  }
3830
- return /\b(coverage|coverage part|liability|sub[-\s]?limit|aggregate|each\s+(claim|loss|occurrence)|bricking|cyber|privacy|media|regulatory|defense|ai\/ml|errors?\s*&?\s*omissions|technology)\b/i.test(coverage.name);
3870
+ return /\b(coverage|coverage part|liability|sub[-\s]?limit|aggregate|each\s+(claim|loss|occurrence|proceeding)|bricking|cyber|privacy|media|regulatory|defense|fraud|social engineering|ai\/ml|errors?\s*&?\s*omissions|technology)\b/i.test(coverage.name);
3831
3871
  }
3832
3872
  function uniqueTerms(terms) {
3833
3873
  const seen = /* @__PURE__ */ new Set();
@@ -3841,7 +3881,7 @@ function uniqueTerms(terms) {
3841
3881
  return result;
3842
3882
  }
3843
3883
  function coverageFromTableRow(row, children, byId) {
3844
- if (row.metadata?.isHeader === true || row.metadata?.isHeader === "true") return void 0;
3884
+ if (isHeaderRow(row)) return void 0;
3845
3885
  const name = nameFromRow(row, children);
3846
3886
  const terms = uniqueTerms(termsFromRow(row, children));
3847
3887
  if (!name || terms.length === 0) return void 0;
@@ -3866,8 +3906,7 @@ function coverageFromEndorsement(endorsement, children) {
3866
3906
  const terms = uniqueTerms(rows.flatMap(
3867
3907
  (row) => termsFromRow(row, children).map((term) => {
3868
3908
  const appliesTo = nameFromRow(row, children);
3869
- const labelled = relabelGenericTerm(term, appliesTo);
3870
- return appliesTo && labelled.label !== appliesTo ? { ...labelled, appliesTo } : labelled;
3909
+ return appliesTo && term.label !== appliesTo ? { ...term, appliesTo } : term;
3871
3910
  })
3872
3911
  ));
3873
3912
  if (terms.length === 0) return void 0;
@@ -10062,7 +10101,343 @@ function groundExtractionMemoryWithSourceSpans(memory, sourceSpans) {
10062
10101
  }
10063
10102
 
10064
10103
  // src/extraction/source-tree-extractor.ts
10104
+ var import_zod42 = require("zod");
10105
+
10106
+ // src/extraction/operational-profile-cleanup.ts
10065
10107
  var import_zod41 = require("zod");
10108
+ var OPERATIONAL_COVERAGE_TERM_KINDS2 = [
10109
+ "each_claim_limit",
10110
+ "each_occurrence_limit",
10111
+ "each_loss_limit",
10112
+ "aggregate_limit",
10113
+ "sublimit",
10114
+ "retention",
10115
+ "deductible",
10116
+ "retroactive_date",
10117
+ "premium",
10118
+ "other"
10119
+ ];
10120
+ var OperationalCoverageTermKindSchema = import_zod41.z.enum(OPERATIONAL_COVERAGE_TERM_KINDS2);
10121
+ var OperationalProfileCleanupSchema = import_zod41.z.object({
10122
+ coverageDecisions: import_zod41.z.array(import_zod41.z.object({
10123
+ coverageIndex: import_zod41.z.number().int().nonnegative(),
10124
+ action: import_zod41.z.enum(["keep", "drop", "update"]),
10125
+ reason: import_zod41.z.string().optional(),
10126
+ name: import_zod41.z.string().optional(),
10127
+ limit: import_zod41.z.string().nullable().optional(),
10128
+ deductible: import_zod41.z.string().nullable().optional(),
10129
+ premium: import_zod41.z.string().nullable().optional(),
10130
+ retroactiveDate: import_zod41.z.string().nullable().optional(),
10131
+ coverageOrigin: import_zod41.z.enum(["core", "endorsement"]).optional(),
10132
+ sourceNodeIds: import_zod41.z.array(import_zod41.z.string()).optional(),
10133
+ sourceSpanIds: import_zod41.z.array(import_zod41.z.string()).optional(),
10134
+ termDecisions: import_zod41.z.array(import_zod41.z.object({
10135
+ termIndex: import_zod41.z.number().int().nonnegative(),
10136
+ action: import_zod41.z.enum(["keep", "drop", "update"]),
10137
+ reason: import_zod41.z.string().optional(),
10138
+ kind: OperationalCoverageTermKindSchema.optional(),
10139
+ label: import_zod41.z.string().optional(),
10140
+ value: import_zod41.z.string().optional(),
10141
+ amount: import_zod41.z.number().nullable().optional(),
10142
+ appliesTo: import_zod41.z.string().nullable().optional(),
10143
+ sourceNodeIds: import_zod41.z.array(import_zod41.z.string()).optional(),
10144
+ sourceSpanIds: import_zod41.z.array(import_zod41.z.string()).optional()
10145
+ })).optional()
10146
+ })).default([]),
10147
+ warnings: import_zod41.z.array(import_zod41.z.string()).default([])
10148
+ });
10149
+ function compactNode(node, maxText = 700) {
10150
+ return {
10151
+ id: node.id,
10152
+ kind: node.kind,
10153
+ title: node.title,
10154
+ path: node.path,
10155
+ pageStart: node.pageStart,
10156
+ pageEnd: node.pageEnd,
10157
+ sourceSpanIds: node.sourceSpanIds.slice(0, 8),
10158
+ text: (node.textExcerpt ?? node.description).slice(0, maxText)
10159
+ };
10160
+ }
10161
+ function compactCoverageForCleanup(coverage, coverageIndex) {
10162
+ return {
10163
+ coverageIndex,
10164
+ name: coverage.name,
10165
+ limit: coverage.limit,
10166
+ deductible: coverage.deductible,
10167
+ premium: coverage.premium,
10168
+ retroactiveDate: coverage.retroactiveDate,
10169
+ coverageOrigin: coverage.coverageOrigin,
10170
+ sourceNodeIds: coverage.sourceNodeIds,
10171
+ sourceSpanIds: coverage.sourceSpanIds,
10172
+ terms: coverage.limits.map((term, termIndex) => ({
10173
+ termIndex,
10174
+ kind: term.kind,
10175
+ label: term.label,
10176
+ value: term.value,
10177
+ amount: term.amount,
10178
+ appliesTo: term.appliesTo,
10179
+ sourceNodeIds: term.sourceNodeIds,
10180
+ sourceSpanIds: term.sourceSpanIds
10181
+ }))
10182
+ };
10183
+ }
10184
+ function buildOperationalProfileCleanupPrompt(sourceTree, profile) {
10185
+ const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 320).map((node) => compactNode(node, node.kind === "page" ? 900 : 700));
10186
+ const candidate = {
10187
+ documentType: profile.documentType,
10188
+ policyTypes: profile.policyTypes,
10189
+ coverageTypes: profile.coverageTypes,
10190
+ coverages: profile.coverages.map(compactCoverageForCleanup)
10191
+ };
10192
+ return `Review and clean a source-backed operational profile projection for an insurance policy.
10193
+
10194
+ Task:
10195
+ - Inspect the candidate coverage projection against the source nodes.
10196
+ - Return cleanup decisions only for coverage rows or terms that are malformed, unsupported, mismatched, or misleading.
10197
+ - If the projection is already acceptable, return an empty coverageDecisions array.
10198
+
10199
+ Projection defects to look for:
10200
+ - Generic labels such as "Column 3" that should be renamed from nearby row/header evidence.
10201
+ - Declaration or section headers projected as coverage names when the row evidence is actually a specific coverage, sub-limit, deductible, retention, retroactive date, or premium.
10202
+ - Dangling continuation punctuation such as a trailing "/" copied into values.
10203
+ - Item references such as "shown in Item 7" or bare item numbers treated as money amounts.
10204
+ - Policy wording, exclusions, or unsupported prose copied into operational limit/deductible fields.
10205
+ - Header/value splits where "Limit of Liability", "Deductible", "Retroactive Date", "Aggregate", "Each Claim", or similar terms are attached to the wrong coverage row.
10206
+ - Repeated schedule headings projected as separate coverages when they only introduce the next coverage group.
10207
+
10208
+ Rules:
10209
+ - Use internal reasoning, but return JSON decisions only.
10210
+ - Do not invent policy facts. Keep, drop, or update only existing coverageIndex and termIndex entries.
10211
+ - Use sourceNodeIds and sourceSpanIds only from the provided source nodes or from the existing candidate entry.
10212
+ - Prefer dropping a malformed fact over speculative rewriting.
10213
+ - Keep a coverage when it is a real operational coverage/benefit even if only one term needs cleanup.
10214
+ - When changing a term's semantic meaning, set kind to the corrected normalized term kind.
10215
+ - Do not add new coverage rows or new terms; this pass cleans the existing projection.
10216
+ - Keep reasons concise and factual.
10217
+
10218
+ Candidate projection:
10219
+ ${JSON.stringify(candidate, null, 2)}
10220
+
10221
+ Source nodes:
10222
+ ${JSON.stringify(nodes, null, 2)}
10223
+
10224
+ Return JSON with coverageDecisions and warnings only.`;
10225
+ }
10226
+ function hasOwn(object, key) {
10227
+ return Object.prototype.hasOwnProperty.call(object, key);
10228
+ }
10229
+ function uniqueStrings(values) {
10230
+ return [...new Set(values.filter((value) => value.length > 0))];
10231
+ }
10232
+ function cleanProfileValue(value) {
10233
+ if (typeof value !== "string") return void 0;
10234
+ const cleaned = value.replace(/\s+\/\s*$/, "").replace(/\s+/g, " ").replace(/^[\s:;#-]+|[\s;,.]+$/g, "").trim();
10235
+ return cleaned || void 0;
10236
+ }
10237
+ function validIds(ids, valid) {
10238
+ return uniqueStrings((ids ?? []).filter((id) => valid.has(id)));
10239
+ }
10240
+ function cleanupIds(ids, valid, fallback) {
10241
+ if (ids === void 0) return validIds(fallback, valid);
10242
+ const next = validIds(ids, valid);
10243
+ return next.length > 0 ? next : validIds(fallback, valid);
10244
+ }
10245
+ function amountFromOperationalValue(value) {
10246
+ const match = value.match(/\$\s*([0-9][0-9,]*(?:\.\d+)?)/) ?? value.match(/\b([0-9][0-9,]*(?:\.\d+)?)\s*%/);
10247
+ if (!match) return void 0;
10248
+ const amount = Number(match[1].replace(/,/g, ""));
10249
+ return Number.isFinite(amount) ? amount : void 0;
10250
+ }
10251
+ function normalizedTermText(term) {
10252
+ return `${term.kind} ${term.label} ${term.value}`.toLowerCase();
10253
+ }
10254
+ function isLimitTerm(term) {
10255
+ return ["each_claim_limit", "each_occurrence_limit", "each_loss_limit", "aggregate_limit", "sublimit"].includes(term.kind) || term.kind === "other" && /\b(limit|aggregate|claim|occurrence|loss|proceeding)\b/i.test(normalizedTermText(term));
10256
+ }
10257
+ function isDeductibleTerm(term) {
10258
+ return term.kind === "deductible" || term.kind === "retention" || /\b(deductible|retention|sir)\b/i.test(normalizedTermText(term));
10259
+ }
10260
+ function isPremiumTerm(term) {
10261
+ return term.kind === "premium" || /\bpremium\b/i.test(normalizedTermText(term));
10262
+ }
10263
+ function isRetroactiveDateTerm(term) {
10264
+ return term.kind === "retroactive_date" || /\bretroactive\b/i.test(normalizedTermText(term));
10265
+ }
10266
+ function primaryLimitFromTerms(terms) {
10267
+ return terms.find(isLimitTerm)?.value;
10268
+ }
10269
+ function deductibleFromTerms(terms) {
10270
+ return terms.find(isDeductibleTerm)?.value;
10271
+ }
10272
+ function premiumFromTerms(terms) {
10273
+ return terms.find(isPremiumTerm)?.value;
10274
+ }
10275
+ function retroactiveDateFromTerms(terms) {
10276
+ return terms.find(isRetroactiveDateTerm)?.value;
10277
+ }
10278
+ function termDecisionTouches(coverage, decision, predicate) {
10279
+ const existing = coverage.limits[decision.termIndex];
10280
+ if (existing && predicate(existing)) return true;
10281
+ if (!decision.kind && !decision.label && !decision.value) return false;
10282
+ return predicate({
10283
+ kind: decision.kind ?? existing?.kind ?? "other",
10284
+ label: cleanProfileValue(decision.label) ?? existing?.label ?? "",
10285
+ value: cleanProfileValue(decision.value) ?? existing?.value ?? ""
10286
+ });
10287
+ }
10288
+ function applyTermCleanupDecision(term, decision, validNodeIds, validSpanIds) {
10289
+ if (!decision || decision.action === "keep") return term;
10290
+ if (decision.action === "drop") return void 0;
10291
+ const label = cleanProfileValue(decision.label) ?? term.label;
10292
+ const value = cleanProfileValue(decision.value) ?? term.value;
10293
+ if (!label || !value) return term;
10294
+ const next = {
10295
+ ...term,
10296
+ kind: decision.kind ?? term.kind,
10297
+ label,
10298
+ value,
10299
+ sourceNodeIds: cleanupIds(decision.sourceNodeIds, validNodeIds, term.sourceNodeIds),
10300
+ sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, term.sourceSpanIds)
10301
+ };
10302
+ if (next.sourceNodeIds.length === 0 && next.sourceSpanIds.length === 0) return term;
10303
+ if (hasOwn(decision, "amount")) {
10304
+ if (typeof decision.amount === "number" && Number.isFinite(decision.amount)) next.amount = decision.amount;
10305
+ else delete next.amount;
10306
+ } else if (decision.value || decision.kind) {
10307
+ const amount = next.kind === "retroactive_date" ? void 0 : amountFromOperationalValue(next.value);
10308
+ if (amount === void 0) delete next.amount;
10309
+ else next.amount = amount;
10310
+ }
10311
+ if (hasOwn(decision, "appliesTo")) {
10312
+ const appliesTo = cleanProfileValue(decision.appliesTo);
10313
+ if (appliesTo) next.appliesTo = appliesTo;
10314
+ else delete next.appliesTo;
10315
+ }
10316
+ return next;
10317
+ }
10318
+ function termDecisionsTouch(coverage, decisions, predicate) {
10319
+ return decisions.filter((decision) => decision.action !== "keep").some((decision) => termDecisionTouches(coverage, decision, predicate));
10320
+ }
10321
+ function applyCoverageCleanupDecision(coverage, decision, validNodeIds, validSpanIds) {
10322
+ if (!decision || decision.action === "keep") return coverage;
10323
+ if (decision.action === "drop") return void 0;
10324
+ const next = {
10325
+ ...coverage,
10326
+ limits: [...coverage.limits],
10327
+ sourceNodeIds: cleanupIds(decision.sourceNodeIds, validNodeIds, coverage.sourceNodeIds),
10328
+ sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, coverage.sourceSpanIds)
10329
+ };
10330
+ const name = cleanProfileValue(decision.name);
10331
+ if (name) next.name = name;
10332
+ if (decision.coverageOrigin) next.coverageOrigin = decision.coverageOrigin;
10333
+ if (hasOwn(decision, "limit")) {
10334
+ const value = cleanProfileValue(decision.limit);
10335
+ if (value) next.limit = value;
10336
+ else delete next.limit;
10337
+ }
10338
+ if (hasOwn(decision, "deductible")) {
10339
+ const value = cleanProfileValue(decision.deductible);
10340
+ if (value) next.deductible = value;
10341
+ else delete next.deductible;
10342
+ }
10343
+ if (hasOwn(decision, "premium")) {
10344
+ const value = cleanProfileValue(decision.premium);
10345
+ if (value) next.premium = value;
10346
+ else delete next.premium;
10347
+ }
10348
+ if (hasOwn(decision, "retroactiveDate")) {
10349
+ const value = cleanProfileValue(decision.retroactiveDate);
10350
+ if (value) next.retroactiveDate = value;
10351
+ else delete next.retroactiveDate;
10352
+ }
10353
+ const termDecisions = (decision.termDecisions ?? []).filter((termDecision) => termDecision.termIndex < coverage.limits.length);
10354
+ const termDecisionByIndex = new Map(termDecisions.map((termDecision) => [termDecision.termIndex, termDecision]));
10355
+ next.limits = coverage.limits.map((term, index) => applyTermCleanupDecision(term, termDecisionByIndex.get(index), validNodeIds, validSpanIds)).filter((term) => Boolean(term));
10356
+ if (termDecisions.length > 0) {
10357
+ if (!hasOwn(decision, "limit") && termDecisionsTouch(coverage, termDecisions, isLimitTerm)) {
10358
+ const value = primaryLimitFromTerms(next.limits);
10359
+ if (value) next.limit = value;
10360
+ else delete next.limit;
10361
+ }
10362
+ if (!hasOwn(decision, "deductible") && termDecisionsTouch(coverage, termDecisions, isDeductibleTerm)) {
10363
+ const value = deductibleFromTerms(next.limits);
10364
+ if (value) next.deductible = value;
10365
+ else delete next.deductible;
10366
+ }
10367
+ if (!hasOwn(decision, "premium") && termDecisionsTouch(coverage, termDecisions, isPremiumTerm)) {
10368
+ const value = premiumFromTerms(next.limits);
10369
+ if (value) next.premium = value;
10370
+ else delete next.premium;
10371
+ }
10372
+ if (!hasOwn(decision, "retroactiveDate") && termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm)) {
10373
+ const value = retroactiveDateFromTerms(next.limits);
10374
+ if (value) next.retroactiveDate = value;
10375
+ else delete next.retroactiveDate;
10376
+ }
10377
+ }
10378
+ next.sourceNodeIds = uniqueStrings([
10379
+ ...next.sourceNodeIds,
10380
+ ...next.limits.flatMap((term) => term.sourceNodeIds)
10381
+ ]);
10382
+ next.sourceSpanIds = uniqueStrings([
10383
+ ...next.sourceSpanIds,
10384
+ ...next.limits.flatMap((term) => term.sourceSpanIds)
10385
+ ]);
10386
+ return next.name ? next : coverage;
10387
+ }
10388
+ function sourceIdsFromOperationalProfile(profile) {
10389
+ const backedValues = [
10390
+ profile.policyNumber,
10391
+ profile.namedInsured,
10392
+ profile.insurer,
10393
+ profile.broker,
10394
+ profile.effectiveDate,
10395
+ profile.expirationDate,
10396
+ profile.retroactiveDate,
10397
+ profile.premium
10398
+ ].filter(Boolean);
10399
+ return {
10400
+ sourceNodeIds: uniqueStrings([
10401
+ ...backedValues.flatMap((value) => value?.sourceNodeIds ?? []),
10402
+ ...profile.coverages.flatMap((coverage) => coverage.sourceNodeIds),
10403
+ ...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceNodeIds)),
10404
+ ...profile.parties.flatMap((party) => party.sourceNodeIds),
10405
+ ...profile.endorsementSupport.flatMap((support) => support.sourceNodeIds)
10406
+ ]),
10407
+ sourceSpanIds: uniqueStrings([
10408
+ ...backedValues.flatMap((value) => value?.sourceSpanIds ?? []),
10409
+ ...profile.coverages.flatMap((coverage) => coverage.sourceSpanIds),
10410
+ ...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceSpanIds)),
10411
+ ...profile.parties.flatMap((party) => party.sourceSpanIds),
10412
+ ...profile.endorsementSupport.flatMap((support) => support.sourceSpanIds)
10413
+ ])
10414
+ };
10415
+ }
10416
+ function applyOperationalProfileCleanup(profile, cleanup, validNodeIds, validSpanIds) {
10417
+ const coverageDecisionByIndex = /* @__PURE__ */ new Map();
10418
+ for (const decision of cleanup.coverageDecisions) {
10419
+ if (decision.coverageIndex < profile.coverages.length) coverageDecisionByIndex.set(decision.coverageIndex, decision);
10420
+ }
10421
+ const coverages = profile.coverages.map(
10422
+ (coverage, index) => applyCoverageCleanupDecision(coverage, coverageDecisionByIndex.get(index), validNodeIds, validSpanIds)
10423
+ ).filter((coverage) => Boolean(coverage));
10424
+ const cleanupWarnings = cleanup.warnings.map((warning) => cleanProfileValue(warning)).filter((warning) => Boolean(warning));
10425
+ const nextProfile = {
10426
+ ...profile,
10427
+ coverages,
10428
+ coverageTypes: uniqueStrings(coverages.map((coverage) => coverage.name)),
10429
+ warnings: uniqueStrings([
10430
+ ...profile.warnings,
10431
+ ...cleanupWarnings.map((warning) => `Operational profile cleanup warning: ${warning}`)
10432
+ ])
10433
+ };
10434
+ return PolicyOperationalProfileSchema.parse({
10435
+ ...nextProfile,
10436
+ ...sourceIdsFromOperationalProfile(nextProfile)
10437
+ });
10438
+ }
10439
+
10440
+ // src/extraction/source-tree-extractor.ts
10066
10441
  var ORGANIZABLE_KINDS = [
10067
10442
  "page_group",
10068
10443
  "form",
@@ -10075,10 +10450,10 @@ var ORGANIZATION_TOP_LEVEL_BATCH_SIZE = 80;
10075
10450
  var ORGANIZER_MAX_SOURCE_SPANS = 400;
10076
10451
  var ORGANIZER_MAX_TOP_LEVEL_NODES = 18;
10077
10452
  var OUTLINE_CLEANUP_MAX_TOP_LEVEL_NODES = 80;
10078
- var SourceTreeOrganizationSchema = import_zod41.z.object({
10079
- labels: import_zod41.z.array(import_zod41.z.object({
10080
- nodeId: import_zod41.z.string(),
10081
- kind: import_zod41.z.enum([
10453
+ var SourceTreeOrganizationSchema = import_zod42.z.object({
10454
+ labels: import_zod42.z.array(import_zod42.z.object({
10455
+ nodeId: import_zod42.z.string(),
10456
+ kind: import_zod42.z.enum([
10082
10457
  "document",
10083
10458
  "page_group",
10084
10459
  "page",
@@ -10092,26 +10467,26 @@ var SourceTreeOrganizationSchema = import_zod41.z.object({
10092
10467
  "table_cell",
10093
10468
  "text"
10094
10469
  ]).optional(),
10095
- title: import_zod41.z.string().optional(),
10096
- description: import_zod41.z.string().optional()
10470
+ title: import_zod42.z.string().optional(),
10471
+ description: import_zod42.z.string().optional()
10097
10472
  })),
10098
- groups: import_zod41.z.array(import_zod41.z.object({
10099
- kind: import_zod41.z.enum(ORGANIZABLE_KINDS),
10100
- title: import_zod41.z.string(),
10101
- description: import_zod41.z.string().optional(),
10102
- childNodeIds: import_zod41.z.array(import_zod41.z.string()).min(1)
10473
+ groups: import_zod42.z.array(import_zod42.z.object({
10474
+ kind: import_zod42.z.enum(ORGANIZABLE_KINDS),
10475
+ title: import_zod42.z.string(),
10476
+ description: import_zod42.z.string().optional(),
10477
+ childNodeIds: import_zod42.z.array(import_zod42.z.string()).min(1)
10103
10478
  }))
10104
10479
  });
10105
- var SourceBackedValueForPromptSchema = import_zod41.z.object({
10106
- value: import_zod41.z.string(),
10107
- normalizedValue: import_zod41.z.string().optional(),
10108
- confidence: import_zod41.z.enum(["low", "medium", "high"]).optional(),
10109
- sourceNodeIds: import_zod41.z.array(import_zod41.z.string()),
10110
- sourceSpanIds: import_zod41.z.array(import_zod41.z.string())
10480
+ var SourceBackedValueForPromptSchema = import_zod42.z.object({
10481
+ value: import_zod42.z.string(),
10482
+ normalizedValue: import_zod42.z.string().optional(),
10483
+ confidence: import_zod42.z.enum(["low", "medium", "high"]).optional(),
10484
+ sourceNodeIds: import_zod42.z.array(import_zod42.z.string()),
10485
+ sourceSpanIds: import_zod42.z.array(import_zod42.z.string())
10111
10486
  });
10112
- var OperationalProfilePromptSchema = import_zod41.z.object({
10113
- documentType: import_zod41.z.enum(["policy", "quote"]).optional(),
10114
- policyTypes: import_zod41.z.array(import_zod41.z.string()).optional(),
10487
+ var OperationalProfilePromptSchema = import_zod42.z.object({
10488
+ documentType: import_zod42.z.enum(["policy", "quote"]).optional(),
10489
+ policyTypes: import_zod42.z.array(import_zod42.z.string()).optional(),
10115
10490
  policyNumber: SourceBackedValueForPromptSchema.optional(),
10116
10491
  namedInsured: SourceBackedValueForPromptSchema.optional(),
10117
10492
  insurer: SourceBackedValueForPromptSchema.optional(),
@@ -10120,43 +10495,32 @@ var OperationalProfilePromptSchema = import_zod41.z.object({
10120
10495
  expirationDate: SourceBackedValueForPromptSchema.optional(),
10121
10496
  retroactiveDate: SourceBackedValueForPromptSchema.optional(),
10122
10497
  premium: SourceBackedValueForPromptSchema.optional(),
10123
- coverageTypes: import_zod41.z.array(import_zod41.z.string()).optional(),
10124
- coverages: import_zod41.z.array(import_zod41.z.object({
10125
- name: import_zod41.z.string(),
10126
- coverageCode: import_zod41.z.string().optional(),
10127
- limit: import_zod41.z.string().optional(),
10128
- deductible: import_zod41.z.string().optional(),
10129
- premium: import_zod41.z.string().optional(),
10130
- retroactiveDate: import_zod41.z.string().optional(),
10131
- formNumber: import_zod41.z.string().optional(),
10132
- sectionRef: import_zod41.z.string().optional(),
10133
- coverageOrigin: import_zod41.z.enum(["core", "endorsement"]).optional(),
10134
- endorsementNumber: import_zod41.z.string().optional(),
10135
- limits: import_zod41.z.array(import_zod41.z.object({
10136
- kind: import_zod41.z.enum([
10137
- "each_claim_limit",
10138
- "each_occurrence_limit",
10139
- "each_loss_limit",
10140
- "aggregate_limit",
10141
- "sublimit",
10142
- "retention",
10143
- "deductible",
10144
- "retroactive_date",
10145
- "premium",
10146
- "other"
10147
- ]).optional(),
10148
- label: import_zod41.z.string(),
10149
- value: import_zod41.z.string(),
10150
- amount: import_zod41.z.number().optional(),
10151
- appliesTo: import_zod41.z.string().optional(),
10152
- sourceNodeIds: import_zod41.z.array(import_zod41.z.string()),
10153
- sourceSpanIds: import_zod41.z.array(import_zod41.z.string())
10498
+ coverageTypes: import_zod42.z.array(import_zod42.z.string()).optional(),
10499
+ coverages: import_zod42.z.array(import_zod42.z.object({
10500
+ name: import_zod42.z.string(),
10501
+ coverageCode: import_zod42.z.string().optional(),
10502
+ limit: import_zod42.z.string().optional(),
10503
+ deductible: import_zod42.z.string().optional(),
10504
+ premium: import_zod42.z.string().optional(),
10505
+ retroactiveDate: import_zod42.z.string().optional(),
10506
+ formNumber: import_zod42.z.string().optional(),
10507
+ sectionRef: import_zod42.z.string().optional(),
10508
+ coverageOrigin: import_zod42.z.enum(["core", "endorsement"]).optional(),
10509
+ endorsementNumber: import_zod42.z.string().optional(),
10510
+ limits: import_zod42.z.array(import_zod42.z.object({
10511
+ kind: OperationalCoverageTermKindSchema.optional(),
10512
+ label: import_zod42.z.string(),
10513
+ value: import_zod42.z.string(),
10514
+ amount: import_zod42.z.number().optional(),
10515
+ appliesTo: import_zod42.z.string().optional(),
10516
+ sourceNodeIds: import_zod42.z.array(import_zod42.z.string()),
10517
+ sourceSpanIds: import_zod42.z.array(import_zod42.z.string())
10154
10518
  })).optional(),
10155
- sourceNodeIds: import_zod41.z.array(import_zod41.z.string()),
10156
- sourceSpanIds: import_zod41.z.array(import_zod41.z.string())
10519
+ sourceNodeIds: import_zod42.z.array(import_zod42.z.string()),
10520
+ sourceSpanIds: import_zod42.z.array(import_zod42.z.string())
10157
10521
  })).optional(),
10158
- sourceNodeIds: import_zod41.z.array(import_zod41.z.string()).optional(),
10159
- sourceSpanIds: import_zod41.z.array(import_zod41.z.string()).optional()
10522
+ sourceNodeIds: import_zod42.z.array(import_zod42.z.string()).optional(),
10523
+ sourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional()
10160
10524
  });
10161
10525
  function formatFormHintsForPrompt(forms) {
10162
10526
  const usable = forms.filter((form) => typeof form.pageStart === "number" && typeof form.pageEnd === "number").slice(0, 120).map((form) => ({
@@ -11148,7 +11512,7 @@ function applyEndorsementGrouping(sourceTree) {
11148
11512
  }
11149
11513
  return normalizeSemanticHierarchy(nextTree);
11150
11514
  }
11151
- function compactNode(node, maxText = 700) {
11515
+ function compactNode2(node, maxText = 700) {
11152
11516
  return {
11153
11517
  id: node.id,
11154
11518
  kind: node.kind,
@@ -11238,7 +11602,7 @@ function mergeOrganizationResults(results) {
11238
11602
  };
11239
11603
  }
11240
11604
  function buildOrganizationPrompt(batch, formHints) {
11241
- const nodes = batch.nodes.map((node) => compactNode(node, node.kind === "page" ? 900 : 320));
11605
+ const nodes = batch.nodes.map((node) => compactNode2(node, node.kind === "page" ? 900 : 320));
11242
11606
  return `You organize an insurance document source tree.
11243
11607
 
11244
11608
  Scope:
@@ -11280,7 +11644,7 @@ function shouldRunOutlineCleanup(sourceTree) {
11280
11644
  }
11281
11645
  function buildOutlineCleanupPrompt(sourceTree, formHints) {
11282
11646
  const topLevel = rootChildren(sourceTree).slice(0, OUTLINE_CLEANUP_MAX_TOP_LEVEL_NODES);
11283
- const nodes = topLevel.map((node) => compactNode(node, 900));
11647
+ const nodes = topLevel.map((node) => compactNode2(node, 900));
11284
11648
  return `You clean a top-level source outline for an insurance policy.
11285
11649
 
11286
11650
  Expected product-facing order:
@@ -11309,7 +11673,7 @@ ${JSON.stringify(nodes, null, 2)}
11309
11673
  Return JSON with labels and groups only.`;
11310
11674
  }
11311
11675
  function buildOperationalProfilePrompt(sourceTree, fallback) {
11312
- const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 240).map(compactNode);
11676
+ const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 240).map(compactNode2);
11313
11677
  return `Extract a source-backed operational profile for an insurance policy or quote.
11314
11678
 
11315
11679
  Return only high-value operational facts needed for policy lists, Q&A, compliance, and certificate generation:
@@ -11673,6 +12037,45 @@ async function runSourceTreeExtraction(params) {
11673
12037
  } catch (error) {
11674
12038
  warnings.push(`Operational profile model pass failed; deterministic profile used (${error instanceof Error ? error.message : String(error)})`);
11675
12039
  }
12040
+ if (operationalProfile.coverages.length > 0) {
12041
+ try {
12042
+ const validNodeIds = new Set(sourceTree.map((node) => node.id));
12043
+ const validSpanIds = new Set(sourceSpans.map((span) => span.id));
12044
+ const budget = params.resolveBudget("extraction_operational_profile", 4096);
12045
+ const startedAt = Date.now();
12046
+ const response = await safeGenerateObject(
12047
+ params.generateObject,
12048
+ {
12049
+ prompt: buildOperationalProfileCleanupPrompt(sourceTree, operationalProfile),
12050
+ schema: OperationalProfileCleanupSchema,
12051
+ maxTokens: budget.maxTokens,
12052
+ taskKind: "extraction_operational_profile",
12053
+ budgetDiagnostics: budget,
12054
+ providerOptions: params.providerOptions
12055
+ },
12056
+ {
12057
+ fallback: { coverageDecisions: [], warnings: [] },
12058
+ log: params.log
12059
+ }
12060
+ );
12061
+ localTrack(response.usage, {
12062
+ taskKind: "extraction_operational_profile",
12063
+ label: "operational_profile_cleanup",
12064
+ maxTokens: budget.maxTokens,
12065
+ durationMs: Date.now() - startedAt
12066
+ });
12067
+ operationalProfile = applyOperationalProfileCleanup(
12068
+ operationalProfile,
12069
+ response.object,
12070
+ validNodeIds,
12071
+ validSpanIds
12072
+ );
12073
+ } catch (error) {
12074
+ warnings.push(`Operational profile cleanup pass failed; uncleaned profile used (${error instanceof Error ? error.message : String(error)})`);
12075
+ }
12076
+ } else {
12077
+ await params.log?.("Operational profile has no coverage rows; skipped model cleanup");
12078
+ }
11676
12079
  const document = materializeDocument({
11677
12080
  id: params.id,
11678
12081
  sourceTree,
@@ -12999,8 +13402,8 @@ Respond with JSON only:
12999
13402
  }`;
13000
13403
 
13001
13404
  // src/schemas/application.ts
13002
- var import_zod42 = require("zod");
13003
- var FieldTypeSchema = import_zod42.z.enum([
13405
+ var import_zod43 = require("zod");
13406
+ var FieldTypeSchema = import_zod43.z.enum([
13004
13407
  "text",
13005
13408
  "numeric",
13006
13409
  "currency",
@@ -13009,223 +13412,223 @@ var FieldTypeSchema = import_zod42.z.enum([
13009
13412
  "table",
13010
13413
  "declaration"
13011
13414
  ]);
13012
- var ApplicationFieldSchema = import_zod42.z.object({
13013
- id: import_zod42.z.string(),
13014
- label: import_zod42.z.string(),
13015
- section: import_zod42.z.string(),
13415
+ var ApplicationFieldSchema = import_zod43.z.object({
13416
+ id: import_zod43.z.string(),
13417
+ label: import_zod43.z.string(),
13418
+ section: import_zod43.z.string(),
13016
13419
  fieldType: FieldTypeSchema,
13017
- required: import_zod42.z.boolean(),
13018
- options: import_zod42.z.array(import_zod42.z.string()).optional(),
13019
- columns: import_zod42.z.array(import_zod42.z.string()).optional(),
13020
- requiresExplanationIfYes: import_zod42.z.boolean().optional(),
13021
- condition: import_zod42.z.object({
13022
- dependsOn: import_zod42.z.string(),
13023
- whenValue: import_zod42.z.string()
13420
+ required: import_zod43.z.boolean(),
13421
+ options: import_zod43.z.array(import_zod43.z.string()).optional(),
13422
+ columns: import_zod43.z.array(import_zod43.z.string()).optional(),
13423
+ requiresExplanationIfYes: import_zod43.z.boolean().optional(),
13424
+ condition: import_zod43.z.object({
13425
+ dependsOn: import_zod43.z.string(),
13426
+ whenValue: import_zod43.z.string()
13024
13427
  }).optional(),
13025
- value: import_zod42.z.string().optional(),
13026
- source: import_zod42.z.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
13027
- confidence: import_zod42.z.enum(["confirmed", "high", "medium", "low"]).optional(),
13028
- sourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional().describe("Stable source spans that support the field value or field anchor"),
13029
- userSourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional().describe("Message or attachment spans that support user-provided values"),
13030
- pageNumber: import_zod42.z.number().int().positive().optional().describe("Application page where the field label or anchor appears"),
13031
- fieldAnchorId: import_zod42.z.string().optional().describe("Stable field anchor ID derived from page, section, label, and form metadata"),
13032
- acroFormName: import_zod42.z.string().optional().describe("Native PDF AcroForm field name when available"),
13033
- validationStatus: import_zod42.z.enum(["valid", "needs_review", "unsupported", "missing"]).optional()
13428
+ value: import_zod43.z.string().optional(),
13429
+ source: import_zod43.z.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
13430
+ confidence: import_zod43.z.enum(["confirmed", "high", "medium", "low"]).optional(),
13431
+ sourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional().describe("Stable source spans that support the field value or field anchor"),
13432
+ userSourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional().describe("Message or attachment spans that support user-provided values"),
13433
+ pageNumber: import_zod43.z.number().int().positive().optional().describe("Application page where the field label or anchor appears"),
13434
+ fieldAnchorId: import_zod43.z.string().optional().describe("Stable field anchor ID derived from page, section, label, and form metadata"),
13435
+ acroFormName: import_zod43.z.string().optional().describe("Native PDF AcroForm field name when available"),
13436
+ validationStatus: import_zod43.z.enum(["valid", "needs_review", "unsupported", "missing"]).optional()
13034
13437
  });
13035
- var ApplicationQuestionConditionSchema = import_zod42.z.object({
13036
- dependsOn: import_zod42.z.string(),
13037
- operator: import_zod42.z.enum(["equals", "not_equals", "in", "not_in", "exists"]).optional(),
13038
- value: import_zod42.z.string().optional(),
13039
- whenValue: import_zod42.z.string().optional(),
13040
- values: import_zod42.z.array(import_zod42.z.string()).optional()
13438
+ var ApplicationQuestionConditionSchema = import_zod43.z.object({
13439
+ dependsOn: import_zod43.z.string(),
13440
+ operator: import_zod43.z.enum(["equals", "not_equals", "in", "not_in", "exists"]).optional(),
13441
+ value: import_zod43.z.string().optional(),
13442
+ whenValue: import_zod43.z.string().optional(),
13443
+ values: import_zod43.z.array(import_zod43.z.string()).optional()
13041
13444
  });
13042
- var ApplicationRepeatSchema = import_zod42.z.object({
13043
- min: import_zod42.z.number().int().nonnegative().optional(),
13044
- max: import_zod42.z.number().int().positive().optional(),
13045
- label: import_zod42.z.string().optional()
13445
+ var ApplicationRepeatSchema = import_zod43.z.object({
13446
+ min: import_zod43.z.number().int().nonnegative().optional(),
13447
+ max: import_zod43.z.number().int().positive().optional(),
13448
+ label: import_zod43.z.string().optional()
13046
13449
  });
13047
- var ApplicationQuestionNodeSchema = import_zod42.z.lazy(
13048
- () => import_zod42.z.object({
13049
- id: import_zod42.z.string(),
13050
- nodeType: import_zod42.z.enum(["group", "question", "repeat_group", "table"]),
13051
- fieldId: import_zod42.z.string().optional(),
13052
- fieldPath: import_zod42.z.string().optional(),
13053
- parentId: import_zod42.z.string().optional(),
13054
- order: import_zod42.z.number().int().nonnegative().optional(),
13055
- label: import_zod42.z.string(),
13056
- section: import_zod42.z.string().optional(),
13450
+ var ApplicationQuestionNodeSchema = import_zod43.z.lazy(
13451
+ () => import_zod43.z.object({
13452
+ id: import_zod43.z.string(),
13453
+ nodeType: import_zod43.z.enum(["group", "question", "repeat_group", "table"]),
13454
+ fieldId: import_zod43.z.string().optional(),
13455
+ fieldPath: import_zod43.z.string().optional(),
13456
+ parentId: import_zod43.z.string().optional(),
13457
+ order: import_zod43.z.number().int().nonnegative().optional(),
13458
+ label: import_zod43.z.string(),
13459
+ section: import_zod43.z.string().optional(),
13057
13460
  fieldType: FieldTypeSchema.optional(),
13058
- required: import_zod42.z.boolean().optional(),
13059
- prompt: import_zod42.z.string().optional(),
13060
- options: import_zod42.z.array(import_zod42.z.string()).optional(),
13061
- columns: import_zod42.z.array(import_zod42.z.string()).optional(),
13461
+ required: import_zod43.z.boolean().optional(),
13462
+ prompt: import_zod43.z.string().optional(),
13463
+ options: import_zod43.z.array(import_zod43.z.string()).optional(),
13464
+ columns: import_zod43.z.array(import_zod43.z.string()).optional(),
13062
13465
  condition: ApplicationQuestionConditionSchema.optional(),
13063
13466
  repeat: ApplicationRepeatSchema.optional(),
13064
- children: import_zod42.z.array(ApplicationQuestionNodeSchema).optional()
13467
+ children: import_zod43.z.array(ApplicationQuestionNodeSchema).optional()
13065
13468
  })
13066
13469
  );
13067
- var ApplicationQuestionGraphSchema = import_zod42.z.object({
13068
- id: import_zod42.z.string(),
13069
- version: import_zod42.z.string(),
13070
- title: import_zod42.z.string().optional(),
13071
- applicationType: import_zod42.z.string().nullable().optional(),
13072
- source: import_zod42.z.enum(["pdf", "manual", "imported", "generated"]).default("generated"),
13073
- rootNodeIds: import_zod42.z.array(import_zod42.z.string()).optional(),
13074
- nodes: import_zod42.z.array(ApplicationQuestionNodeSchema)
13470
+ var ApplicationQuestionGraphSchema = import_zod43.z.object({
13471
+ id: import_zod43.z.string(),
13472
+ version: import_zod43.z.string(),
13473
+ title: import_zod43.z.string().optional(),
13474
+ applicationType: import_zod43.z.string().nullable().optional(),
13475
+ source: import_zod43.z.enum(["pdf", "manual", "imported", "generated"]).default("generated"),
13476
+ rootNodeIds: import_zod43.z.array(import_zod43.z.string()).optional(),
13477
+ nodes: import_zod43.z.array(ApplicationQuestionNodeSchema)
13075
13478
  });
13076
- var ApplicationTemplateSchema = import_zod42.z.object({
13077
- id: import_zod42.z.string(),
13078
- version: import_zod42.z.string(),
13079
- title: import_zod42.z.string(),
13080
- applicationType: import_zod42.z.string().nullable().optional(),
13479
+ var ApplicationTemplateSchema = import_zod43.z.object({
13480
+ id: import_zod43.z.string(),
13481
+ version: import_zod43.z.string(),
13482
+ title: import_zod43.z.string(),
13483
+ applicationType: import_zod43.z.string().nullable().optional(),
13081
13484
  questionGraph: ApplicationQuestionGraphSchema,
13082
- fields: import_zod42.z.array(ApplicationFieldSchema).optional()
13485
+ fields: import_zod43.z.array(ApplicationFieldSchema).optional()
13083
13486
  });
13084
- var ApplicationClassifyResultSchema = import_zod42.z.object({
13085
- isApplication: import_zod42.z.boolean(),
13086
- confidence: import_zod42.z.number().min(0).max(1),
13087
- applicationType: import_zod42.z.string().nullable()
13487
+ var ApplicationClassifyResultSchema = import_zod43.z.object({
13488
+ isApplication: import_zod43.z.boolean(),
13489
+ confidence: import_zod43.z.number().min(0).max(1),
13490
+ applicationType: import_zod43.z.string().nullable()
13088
13491
  });
13089
- var FieldExtractionResultSchema = import_zod42.z.object({
13090
- fields: import_zod42.z.array(ApplicationFieldSchema)
13492
+ var FieldExtractionResultSchema = import_zod43.z.object({
13493
+ fields: import_zod43.z.array(ApplicationFieldSchema)
13091
13494
  });
13092
- var AutoFillMatchSchema = import_zod42.z.object({
13093
- fieldId: import_zod42.z.string(),
13094
- value: import_zod42.z.string(),
13095
- confidence: import_zod42.z.enum(["confirmed"]),
13096
- contextKey: import_zod42.z.string()
13495
+ var AutoFillMatchSchema = import_zod43.z.object({
13496
+ fieldId: import_zod43.z.string(),
13497
+ value: import_zod43.z.string(),
13498
+ confidence: import_zod43.z.enum(["confirmed"]),
13499
+ contextKey: import_zod43.z.string()
13097
13500
  });
13098
- var AutoFillResultSchema = import_zod42.z.object({
13099
- matches: import_zod42.z.array(AutoFillMatchSchema)
13501
+ var AutoFillResultSchema = import_zod43.z.object({
13502
+ matches: import_zod43.z.array(AutoFillMatchSchema)
13100
13503
  });
13101
- var QuestionBatchResultSchema = import_zod42.z.object({
13102
- batches: import_zod42.z.array(import_zod42.z.array(import_zod42.z.string()).describe("Array of field IDs in this batch"))
13504
+ var QuestionBatchResultSchema = import_zod43.z.object({
13505
+ batches: import_zod43.z.array(import_zod43.z.array(import_zod43.z.string()).describe("Array of field IDs in this batch"))
13103
13506
  });
13104
- var LookupRequestSchema = import_zod42.z.object({
13105
- type: import_zod42.z.string().describe("Type of lookup: 'records', 'website', 'policy'"),
13106
- description: import_zod42.z.string(),
13107
- url: import_zod42.z.string().optional(),
13108
- targetFieldIds: import_zod42.z.array(import_zod42.z.string())
13507
+ var LookupRequestSchema = import_zod43.z.object({
13508
+ type: import_zod43.z.string().describe("Type of lookup: 'records', 'website', 'policy'"),
13509
+ description: import_zod43.z.string(),
13510
+ url: import_zod43.z.string().optional(),
13511
+ targetFieldIds: import_zod43.z.array(import_zod43.z.string())
13109
13512
  });
13110
- var ReplyIntentSchema = import_zod42.z.object({
13111
- primaryIntent: import_zod42.z.enum(["answers_only", "question", "lookup_request", "mixed"]),
13112
- hasAnswers: import_zod42.z.boolean(),
13113
- questionText: import_zod42.z.string().optional(),
13114
- questionFieldIds: import_zod42.z.array(import_zod42.z.string()).optional(),
13115
- lookupRequests: import_zod42.z.array(LookupRequestSchema).optional()
13513
+ var ReplyIntentSchema = import_zod43.z.object({
13514
+ primaryIntent: import_zod43.z.enum(["answers_only", "question", "lookup_request", "mixed"]),
13515
+ hasAnswers: import_zod43.z.boolean(),
13516
+ questionText: import_zod43.z.string().optional(),
13517
+ questionFieldIds: import_zod43.z.array(import_zod43.z.string()).optional(),
13518
+ lookupRequests: import_zod43.z.array(LookupRequestSchema).optional()
13116
13519
  });
13117
- var ParsedAnswerSchema = import_zod42.z.object({
13118
- fieldId: import_zod42.z.string(),
13119
- value: import_zod42.z.string(),
13120
- explanation: import_zod42.z.string().optional()
13520
+ var ParsedAnswerSchema = import_zod43.z.object({
13521
+ fieldId: import_zod43.z.string(),
13522
+ value: import_zod43.z.string(),
13523
+ explanation: import_zod43.z.string().optional()
13121
13524
  });
13122
- var AnswerParsingResultSchema = import_zod42.z.object({
13123
- answers: import_zod42.z.array(ParsedAnswerSchema),
13124
- unanswered: import_zod42.z.array(import_zod42.z.string()).describe("Field IDs that were not answered")
13525
+ var AnswerParsingResultSchema = import_zod43.z.object({
13526
+ answers: import_zod43.z.array(ParsedAnswerSchema),
13527
+ unanswered: import_zod43.z.array(import_zod43.z.string()).describe("Field IDs that were not answered")
13125
13528
  });
13126
- var LookupFillSchema = import_zod42.z.object({
13127
- fieldId: import_zod42.z.string(),
13128
- value: import_zod42.z.string(),
13129
- source: import_zod42.z.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'"),
13130
- sourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional()
13529
+ var LookupFillSchema = import_zod43.z.object({
13530
+ fieldId: import_zod43.z.string(),
13531
+ value: import_zod43.z.string(),
13532
+ source: import_zod43.z.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'"),
13533
+ sourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional()
13131
13534
  });
13132
- var LookupFillResultSchema = import_zod42.z.object({
13133
- fills: import_zod42.z.array(LookupFillSchema),
13134
- unfillable: import_zod42.z.array(import_zod42.z.string()),
13135
- explanation: import_zod42.z.string().optional()
13535
+ var LookupFillResultSchema = import_zod43.z.object({
13536
+ fills: import_zod43.z.array(LookupFillSchema),
13537
+ unfillable: import_zod43.z.array(import_zod43.z.string()),
13538
+ explanation: import_zod43.z.string().optional()
13136
13539
  });
13137
- var FlatPdfPlacementSchema = import_zod42.z.object({
13138
- fieldId: import_zod42.z.string(),
13139
- page: import_zod42.z.number(),
13140
- x: import_zod42.z.number().describe("Percentage from left edge (0-100)"),
13141
- y: import_zod42.z.number().describe("Percentage from top edge (0-100)"),
13142
- text: import_zod42.z.string(),
13143
- fontSize: import_zod42.z.number().optional(),
13144
- isCheckmark: import_zod42.z.boolean().optional()
13540
+ var FlatPdfPlacementSchema = import_zod43.z.object({
13541
+ fieldId: import_zod43.z.string(),
13542
+ page: import_zod43.z.number(),
13543
+ x: import_zod43.z.number().describe("Percentage from left edge (0-100)"),
13544
+ y: import_zod43.z.number().describe("Percentage from top edge (0-100)"),
13545
+ text: import_zod43.z.string(),
13546
+ fontSize: import_zod43.z.number().optional(),
13547
+ isCheckmark: import_zod43.z.boolean().optional()
13145
13548
  });
13146
- var AcroFormMappingSchema = import_zod42.z.object({
13147
- fieldId: import_zod42.z.string(),
13148
- acroFormName: import_zod42.z.string(),
13149
- value: import_zod42.z.string()
13549
+ var AcroFormMappingSchema = import_zod43.z.object({
13550
+ fieldId: import_zod43.z.string(),
13551
+ acroFormName: import_zod43.z.string(),
13552
+ value: import_zod43.z.string()
13150
13553
  });
13151
- var QualityGateStatusSchema = import_zod42.z.enum(["passed", "warning", "failed"]);
13152
- var QualitySeveritySchema = import_zod42.z.enum(["info", "warning", "blocking"]);
13153
- var ApplicationQualityIssueSchema = import_zod42.z.object({
13154
- code: import_zod42.z.string(),
13554
+ var QualityGateStatusSchema = import_zod43.z.enum(["passed", "warning", "failed"]);
13555
+ var QualitySeveritySchema = import_zod43.z.enum(["info", "warning", "blocking"]);
13556
+ var ApplicationQualityIssueSchema = import_zod43.z.object({
13557
+ code: import_zod43.z.string(),
13155
13558
  severity: QualitySeveritySchema,
13156
- message: import_zod42.z.string(),
13157
- fieldId: import_zod42.z.string().optional()
13559
+ message: import_zod43.z.string(),
13560
+ fieldId: import_zod43.z.string().optional()
13158
13561
  });
13159
- var ApplicationQualityRoundSchema = import_zod42.z.object({
13160
- round: import_zod42.z.number(),
13161
- kind: import_zod42.z.string(),
13562
+ var ApplicationQualityRoundSchema = import_zod43.z.object({
13563
+ round: import_zod43.z.number(),
13564
+ kind: import_zod43.z.string(),
13162
13565
  status: QualityGateStatusSchema,
13163
- summary: import_zod42.z.string().optional()
13566
+ summary: import_zod43.z.string().optional()
13164
13567
  });
13165
- var ApplicationQualityArtifactSchema = import_zod42.z.object({
13166
- kind: import_zod42.z.string(),
13167
- label: import_zod42.z.string().optional(),
13168
- itemCount: import_zod42.z.number().optional()
13568
+ var ApplicationQualityArtifactSchema = import_zod43.z.object({
13569
+ kind: import_zod43.z.string(),
13570
+ label: import_zod43.z.string().optional(),
13571
+ itemCount: import_zod43.z.number().optional()
13169
13572
  });
13170
- var ApplicationEmailReviewSchema = import_zod42.z.object({
13171
- issues: import_zod42.z.array(ApplicationQualityIssueSchema),
13573
+ var ApplicationEmailReviewSchema = import_zod43.z.object({
13574
+ issues: import_zod43.z.array(ApplicationQualityIssueSchema),
13172
13575
  qualityGateStatus: QualityGateStatusSchema
13173
13576
  });
13174
- var ApplicationQualityReportSchema = import_zod42.z.object({
13175
- issues: import_zod42.z.array(ApplicationQualityIssueSchema),
13176
- rounds: import_zod42.z.array(ApplicationQualityRoundSchema).optional(),
13177
- artifacts: import_zod42.z.array(ApplicationQualityArtifactSchema).optional(),
13577
+ var ApplicationQualityReportSchema = import_zod43.z.object({
13578
+ issues: import_zod43.z.array(ApplicationQualityIssueSchema),
13579
+ rounds: import_zod43.z.array(ApplicationQualityRoundSchema).optional(),
13580
+ artifacts: import_zod43.z.array(ApplicationQualityArtifactSchema).optional(),
13178
13581
  emailReview: ApplicationEmailReviewSchema.optional(),
13179
13582
  qualityGateStatus: QualityGateStatusSchema
13180
13583
  });
13181
- var ApplicationContextProposalSchema = import_zod42.z.object({
13182
- id: import_zod42.z.string(),
13183
- fieldId: import_zod42.z.string().optional(),
13184
- key: import_zod42.z.string(),
13185
- value: import_zod42.z.string(),
13186
- category: import_zod42.z.string(),
13187
- source: import_zod42.z.enum(["application", "user", "lookup", "policy", "email", "chat", "imessage", "mcp"]),
13188
- confidence: import_zod42.z.enum(["confirmed", "high", "medium", "low"]),
13189
- sourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional(),
13190
- userSourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional()
13584
+ var ApplicationContextProposalSchema = import_zod43.z.object({
13585
+ id: import_zod43.z.string(),
13586
+ fieldId: import_zod43.z.string().optional(),
13587
+ key: import_zod43.z.string(),
13588
+ value: import_zod43.z.string(),
13589
+ category: import_zod43.z.string(),
13590
+ source: import_zod43.z.enum(["application", "user", "lookup", "policy", "email", "chat", "imessage", "mcp"]),
13591
+ confidence: import_zod43.z.enum(["confirmed", "high", "medium", "low"]),
13592
+ sourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional(),
13593
+ userSourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional()
13191
13594
  });
13192
- var ApplicationPacketAnswerSchema = import_zod42.z.object({
13193
- fieldId: import_zod42.z.string(),
13194
- label: import_zod42.z.string(),
13195
- section: import_zod42.z.string(),
13196
- value: import_zod42.z.string(),
13197
- source: import_zod42.z.string(),
13198
- confidence: import_zod42.z.enum(["confirmed", "high", "medium", "low"]).optional(),
13199
- sourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional(),
13200
- userSourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional()
13595
+ var ApplicationPacketAnswerSchema = import_zod43.z.object({
13596
+ fieldId: import_zod43.z.string(),
13597
+ label: import_zod43.z.string(),
13598
+ section: import_zod43.z.string(),
13599
+ value: import_zod43.z.string(),
13600
+ source: import_zod43.z.string(),
13601
+ confidence: import_zod43.z.enum(["confirmed", "high", "medium", "low"]).optional(),
13602
+ sourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional(),
13603
+ userSourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional()
13201
13604
  });
13202
- var ApplicationPacketSchema = import_zod42.z.object({
13203
- id: import_zod42.z.string(),
13204
- applicationId: import_zod42.z.string(),
13205
- title: import_zod42.z.string(),
13206
- status: import_zod42.z.enum(["draft", "broker_ready", "submitted"]),
13207
- answers: import_zod42.z.array(ApplicationPacketAnswerSchema),
13208
- missingFieldIds: import_zod42.z.array(import_zod42.z.string()),
13605
+ var ApplicationPacketSchema = import_zod43.z.object({
13606
+ id: import_zod43.z.string(),
13607
+ applicationId: import_zod43.z.string(),
13608
+ title: import_zod43.z.string(),
13609
+ status: import_zod43.z.enum(["draft", "broker_ready", "submitted"]),
13610
+ answers: import_zod43.z.array(ApplicationPacketAnswerSchema),
13611
+ missingFieldIds: import_zod43.z.array(import_zod43.z.string()),
13209
13612
  qualityReport: ApplicationQualityReportSchema,
13210
- submissionNotes: import_zod42.z.string().optional(),
13211
- createdAt: import_zod42.z.number()
13613
+ submissionNotes: import_zod43.z.string().optional(),
13614
+ createdAt: import_zod43.z.number()
13212
13615
  });
13213
- var ApplicationStateSchema = import_zod42.z.object({
13214
- id: import_zod42.z.string(),
13215
- pdfBase64: import_zod42.z.string().optional().describe("Original PDF, omitted after extraction"),
13216
- templateId: import_zod42.z.string().optional(),
13217
- templateVersion: import_zod42.z.string().optional(),
13616
+ var ApplicationStateSchema = import_zod43.z.object({
13617
+ id: import_zod43.z.string(),
13618
+ pdfBase64: import_zod43.z.string().optional().describe("Original PDF, omitted after extraction"),
13619
+ templateId: import_zod43.z.string().optional(),
13620
+ templateVersion: import_zod43.z.string().optional(),
13218
13621
  templateSnapshot: ApplicationTemplateSchema.optional(),
13219
- title: import_zod42.z.string().optional(),
13220
- applicationType: import_zod42.z.string().nullable().optional(),
13622
+ title: import_zod43.z.string().optional(),
13623
+ applicationType: import_zod43.z.string().nullable().optional(),
13221
13624
  questionGraph: ApplicationQuestionGraphSchema.optional(),
13222
- fields: import_zod42.z.array(ApplicationFieldSchema),
13223
- batches: import_zod42.z.array(import_zod42.z.array(import_zod42.z.string())).optional(),
13224
- currentBatchIndex: import_zod42.z.number().default(0),
13225
- contextProposals: import_zod42.z.array(ApplicationContextProposalSchema).optional(),
13625
+ fields: import_zod43.z.array(ApplicationFieldSchema),
13626
+ batches: import_zod43.z.array(import_zod43.z.array(import_zod43.z.string())).optional(),
13627
+ currentBatchIndex: import_zod43.z.number().default(0),
13628
+ contextProposals: import_zod43.z.array(ApplicationContextProposalSchema).optional(),
13226
13629
  packet: ApplicationPacketSchema.optional(),
13227
13630
  qualityReport: ApplicationQualityReportSchema.optional(),
13228
- status: import_zod42.z.enum([
13631
+ status: import_zod43.z.enum([
13229
13632
  "classifying",
13230
13633
  "extracting",
13231
13634
  "auto_filling",
@@ -13239,8 +13642,8 @@ var ApplicationStateSchema = import_zod42.z.object({
13239
13642
  "cancelled",
13240
13643
  "complete"
13241
13644
  ]),
13242
- createdAt: import_zod42.z.number(),
13243
- updatedAt: import_zod42.z.number()
13645
+ createdAt: import_zod43.z.number(),
13646
+ updatedAt: import_zod43.z.number()
13244
13647
  });
13245
13648
 
13246
13649
  // src/application/agents/classifier.ts
@@ -14974,106 +15377,106 @@ Respond with the final answer, deduplicated citations array, overall confidence
14974
15377
  }
14975
15378
 
14976
15379
  // src/schemas/query.ts
14977
- var import_zod43 = require("zod");
14978
- var QueryIntentSchema = import_zod43.z.enum([
15380
+ var import_zod44 = require("zod");
15381
+ var QueryIntentSchema = import_zod44.z.enum([
14979
15382
  "policy_question",
14980
15383
  "coverage_comparison",
14981
15384
  "document_search",
14982
15385
  "claims_inquiry",
14983
15386
  "general_knowledge"
14984
15387
  ]);
14985
- var QueryAttachmentKindSchema = import_zod43.z.enum(["image", "pdf", "text"]);
14986
- var QueryAttachmentSchema = import_zod43.z.object({
14987
- id: import_zod43.z.string().optional().describe("Optional stable attachment ID from the caller"),
15388
+ var QueryAttachmentKindSchema = import_zod44.z.enum(["image", "pdf", "text"]);
15389
+ var QueryAttachmentSchema = import_zod44.z.object({
15390
+ id: import_zod44.z.string().optional().describe("Optional stable attachment ID from the caller"),
14988
15391
  kind: QueryAttachmentKindSchema,
14989
- name: import_zod43.z.string().optional().describe("Original filename or user-facing label"),
14990
- mimeType: import_zod43.z.string().optional().describe("MIME type such as image/jpeg or application/pdf"),
14991
- base64: import_zod43.z.string().optional().describe("Base64-encoded file content for image/pdf attachments"),
14992
- text: import_zod43.z.string().optional().describe("Plain-text attachment content when available"),
14993
- description: import_zod43.z.string().optional().describe("Caller-provided description of the attachment")
15392
+ name: import_zod44.z.string().optional().describe("Original filename or user-facing label"),
15393
+ mimeType: import_zod44.z.string().optional().describe("MIME type such as image/jpeg or application/pdf"),
15394
+ base64: import_zod44.z.string().optional().describe("Base64-encoded file content for image/pdf attachments"),
15395
+ text: import_zod44.z.string().optional().describe("Plain-text attachment content when available"),
15396
+ description: import_zod44.z.string().optional().describe("Caller-provided description of the attachment")
14994
15397
  });
14995
- var QueryRetrievalModeSchema = import_zod43.z.enum([
15398
+ var QueryRetrievalModeSchema = import_zod44.z.enum([
14996
15399
  "graph_only",
14997
15400
  "source_rag",
14998
15401
  "long_context",
14999
15402
  "hybrid"
15000
15403
  ]);
15001
- var SubQuestionSchema = import_zod43.z.object({
15002
- question: import_zod43.z.string().describe("Atomic sub-question to retrieve and answer independently"),
15404
+ var SubQuestionSchema = import_zod44.z.object({
15405
+ question: import_zod44.z.string().describe("Atomic sub-question to retrieve and answer independently"),
15003
15406
  intent: QueryIntentSchema,
15004
- chunkTypes: import_zod43.z.array(import_zod43.z.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
15005
- documentFilters: import_zod43.z.object({
15006
- type: import_zod43.z.enum(["policy", "quote"]).optional(),
15007
- carrier: import_zod43.z.string().optional(),
15008
- insuredName: import_zod43.z.string().optional(),
15009
- policyNumber: import_zod43.z.string().optional(),
15010
- quoteNumber: import_zod43.z.string().optional(),
15011
- policyTypes: import_zod43.z.array(PolicyTypeSchema).optional().describe("Filter by policy type (e.g. homeowners_ho3, renters_ho4, pet) to avoid mixing up similar policies")
15407
+ chunkTypes: import_zod44.z.array(import_zod44.z.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
15408
+ documentFilters: import_zod44.z.object({
15409
+ type: import_zod44.z.enum(["policy", "quote"]).optional(),
15410
+ carrier: import_zod44.z.string().optional(),
15411
+ insuredName: import_zod44.z.string().optional(),
15412
+ policyNumber: import_zod44.z.string().optional(),
15413
+ quoteNumber: import_zod44.z.string().optional(),
15414
+ policyTypes: import_zod44.z.array(PolicyTypeSchema).optional().describe("Filter by policy type (e.g. homeowners_ho3, renters_ho4, pet) to avoid mixing up similar policies")
15012
15415
  }).optional().describe("Structured filters to narrow document lookup")
15013
15416
  });
15014
- var QueryClassifyResultSchema = import_zod43.z.object({
15417
+ var QueryClassifyResultSchema = import_zod44.z.object({
15015
15418
  intent: QueryIntentSchema,
15016
- subQuestions: import_zod43.z.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
15017
- requiresDocumentLookup: import_zod43.z.boolean().describe("Whether structured document lookup is needed"),
15018
- requiresChunkSearch: import_zod43.z.boolean().describe("Whether semantic chunk search is needed"),
15019
- requiresConversationHistory: import_zod43.z.boolean().describe("Whether conversation history is relevant"),
15419
+ subQuestions: import_zod44.z.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
15420
+ requiresDocumentLookup: import_zod44.z.boolean().describe("Whether structured document lookup is needed"),
15421
+ requiresChunkSearch: import_zod44.z.boolean().describe("Whether semantic chunk search is needed"),
15422
+ requiresConversationHistory: import_zod44.z.boolean().describe("Whether conversation history is relevant"),
15020
15423
  retrievalMode: QueryRetrievalModeSchema.optional().describe("Preferred retrieval strategy for the query when source-span retrieval is available")
15021
15424
  });
15022
- var EvidenceItemSchema = import_zod43.z.object({
15023
- source: import_zod43.z.enum(["chunk", "document", "conversation", "attachment", "source_span", "source_node"]),
15024
- chunkId: import_zod43.z.string().optional(),
15025
- sourceNodeId: import_zod43.z.string().optional(),
15026
- sourceSpanId: import_zod43.z.string().optional(),
15027
- documentId: import_zod43.z.string().optional(),
15028
- turnId: import_zod43.z.string().optional(),
15029
- attachmentId: import_zod43.z.string().optional(),
15030
- text: import_zod43.z.string().describe("Text excerpt from the source"),
15031
- relevance: import_zod43.z.number().min(0).max(1),
15425
+ var EvidenceItemSchema = import_zod44.z.object({
15426
+ source: import_zod44.z.enum(["chunk", "document", "conversation", "attachment", "source_span", "source_node"]),
15427
+ chunkId: import_zod44.z.string().optional(),
15428
+ sourceNodeId: import_zod44.z.string().optional(),
15429
+ sourceSpanId: import_zod44.z.string().optional(),
15430
+ documentId: import_zod44.z.string().optional(),
15431
+ turnId: import_zod44.z.string().optional(),
15432
+ attachmentId: import_zod44.z.string().optional(),
15433
+ text: import_zod44.z.string().describe("Text excerpt from the source"),
15434
+ relevance: import_zod44.z.number().min(0).max(1),
15032
15435
  retrievalMode: QueryRetrievalModeSchema.optional(),
15033
15436
  sourceLocation: SourceSpanLocationSchema.optional(),
15034
- metadata: import_zod43.z.array(import_zod43.z.object({ key: import_zod43.z.string(), value: import_zod43.z.string() })).optional()
15437
+ metadata: import_zod44.z.array(import_zod44.z.object({ key: import_zod44.z.string(), value: import_zod44.z.string() })).optional()
15035
15438
  });
15036
- var AttachmentInterpretationSchema = import_zod43.z.object({
15037
- summary: import_zod43.z.string().describe("Concise summary of what the attachment shows or contains"),
15038
- extractedFacts: import_zod43.z.array(import_zod43.z.string()).describe("Specific observable or document facts grounded in the attachment"),
15039
- recommendedFocus: import_zod43.z.array(import_zod43.z.string()).describe("Important details to incorporate when answering follow-up questions"),
15040
- confidence: import_zod43.z.number().min(0).max(1)
15439
+ var AttachmentInterpretationSchema = import_zod44.z.object({
15440
+ summary: import_zod44.z.string().describe("Concise summary of what the attachment shows or contains"),
15441
+ extractedFacts: import_zod44.z.array(import_zod44.z.string()).describe("Specific observable or document facts grounded in the attachment"),
15442
+ recommendedFocus: import_zod44.z.array(import_zod44.z.string()).describe("Important details to incorporate when answering follow-up questions"),
15443
+ confidence: import_zod44.z.number().min(0).max(1)
15041
15444
  });
15042
- var RetrievalResultSchema = import_zod43.z.object({
15043
- subQuestion: import_zod43.z.string(),
15044
- evidence: import_zod43.z.array(EvidenceItemSchema)
15445
+ var RetrievalResultSchema = import_zod44.z.object({
15446
+ subQuestion: import_zod44.z.string(),
15447
+ evidence: import_zod44.z.array(EvidenceItemSchema)
15045
15448
  });
15046
- var CitationSchema = import_zod43.z.object({
15047
- index: import_zod43.z.number().describe("Citation number [1], [2], etc."),
15048
- chunkId: import_zod43.z.string().optional().describe("Source chunk ID, e.g. doc-123:coverage:2"),
15049
- sourceNodeId: import_zod43.z.string().optional().describe("Source tree node ID when available"),
15050
- sourceSpanId: import_zod43.z.string().optional().describe("Precise source span ID when available"),
15051
- documentId: import_zod43.z.string(),
15052
- documentType: import_zod43.z.enum(["policy", "quote"]).optional(),
15053
- field: import_zod43.z.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
15054
- quote: import_zod43.z.string().describe("Exact text from source that supports the claim"),
15055
- relevance: import_zod43.z.number().min(0).max(1),
15449
+ var CitationSchema = import_zod44.z.object({
15450
+ index: import_zod44.z.number().describe("Citation number [1], [2], etc."),
15451
+ chunkId: import_zod44.z.string().optional().describe("Source chunk ID, e.g. doc-123:coverage:2"),
15452
+ sourceNodeId: import_zod44.z.string().optional().describe("Source tree node ID when available"),
15453
+ sourceSpanId: import_zod44.z.string().optional().describe("Precise source span ID when available"),
15454
+ documentId: import_zod44.z.string(),
15455
+ documentType: import_zod44.z.enum(["policy", "quote"]).optional(),
15456
+ field: import_zod44.z.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
15457
+ quote: import_zod44.z.string().describe("Exact text from source that supports the claim"),
15458
+ relevance: import_zod44.z.number().min(0).max(1),
15056
15459
  retrievalMode: QueryRetrievalModeSchema.optional(),
15057
15460
  sourceLocation: SourceSpanLocationSchema.optional()
15058
15461
  });
15059
- var SubAnswerSchema = import_zod43.z.object({
15060
- subQuestion: import_zod43.z.string(),
15061
- answer: import_zod43.z.string(),
15062
- citations: import_zod43.z.array(CitationSchema),
15063
- confidence: import_zod43.z.number().min(0).max(1),
15064
- needsMoreContext: import_zod43.z.boolean().describe("True if evidence was insufficient to answer fully")
15462
+ var SubAnswerSchema = import_zod44.z.object({
15463
+ subQuestion: import_zod44.z.string(),
15464
+ answer: import_zod44.z.string(),
15465
+ citations: import_zod44.z.array(CitationSchema),
15466
+ confidence: import_zod44.z.number().min(0).max(1),
15467
+ needsMoreContext: import_zod44.z.boolean().describe("True if evidence was insufficient to answer fully")
15065
15468
  });
15066
- var VerifyResultSchema = import_zod43.z.object({
15067
- approved: import_zod43.z.boolean().describe("Whether all sub-answers are adequately grounded"),
15068
- issues: import_zod43.z.array(import_zod43.z.string()).describe("Specific grounding or consistency issues found"),
15069
- retrySubQuestions: import_zod43.z.array(import_zod43.z.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
15469
+ var VerifyResultSchema = import_zod44.z.object({
15470
+ approved: import_zod44.z.boolean().describe("Whether all sub-answers are adequately grounded"),
15471
+ issues: import_zod44.z.array(import_zod44.z.string()).describe("Specific grounding or consistency issues found"),
15472
+ retrySubQuestions: import_zod44.z.array(import_zod44.z.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
15070
15473
  });
15071
- var QueryResultSchema = import_zod43.z.object({
15072
- answer: import_zod43.z.string(),
15073
- citations: import_zod43.z.array(CitationSchema),
15474
+ var QueryResultSchema = import_zod44.z.object({
15475
+ answer: import_zod44.z.string(),
15476
+ citations: import_zod44.z.array(CitationSchema),
15074
15477
  intent: QueryIntentSchema,
15075
- confidence: import_zod43.z.number().min(0).max(1),
15076
- followUp: import_zod43.z.string().optional().describe("Suggested follow-up question if applicable")
15478
+ confidence: import_zod44.z.number().min(0).max(1),
15479
+ followUp: import_zod44.z.string().optional().describe("Suggested follow-up question if applicable")
15077
15480
  });
15078
15481
 
15079
15482
  // src/query/retriever.ts
@@ -16140,7 +16543,7 @@ ${sa.answer}`).join("\n\n"),
16140
16543
  }
16141
16544
 
16142
16545
  // src/pce/index.ts
16143
- var import_zod44 = require("zod");
16546
+ var import_zod45 = require("zod");
16144
16547
 
16145
16548
  // src/prompts/pce/index.ts
16146
16549
  function buildPceNormalizePrompt(input) {
@@ -16174,11 +16577,11 @@ ${input.openQuestions.map((question) => `- ${question.id}${question.fieldPath ?
16174
16577
  }
16175
16578
 
16176
16579
  // src/pce/index.ts
16177
- var ReplyAnswersSchema = import_zod44.z.object({
16178
- answers: import_zod44.z.array(import_zod44.z.object({
16179
- questionId: import_zod44.z.string().optional(),
16180
- fieldPath: import_zod44.z.string().optional(),
16181
- answer: import_zod44.z.string()
16580
+ var ReplyAnswersSchema = import_zod45.z.object({
16581
+ answers: import_zod45.z.array(import_zod45.z.object({
16582
+ questionId: import_zod45.z.string().optional(),
16583
+ fieldPath: import_zod45.z.string().optional(),
16584
+ answer: import_zod45.z.string()
16182
16585
  }))
16183
16586
  });
16184
16587
  function createPceAgent(config = {}) {