@claritylabs/cl-sdk 3.1.2 → 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.mjs CHANGED
@@ -3381,15 +3381,6 @@ function sourceIds(nodes) {
3381
3381
  sourceSpanIds: [...new Set(nodes.flatMap((node) => node.sourceSpanIds))]
3382
3382
  };
3383
3383
  }
3384
- function relabelGenericTerm(term, label) {
3385
- const cleanLabel = cleanValue(label);
3386
- if (!cleanLabel || !/^column\s+\d+$/i.test(term.label)) return term;
3387
- return {
3388
- ...term,
3389
- kind: termKind(cleanLabel, term.value),
3390
- label: cleanLabel
3391
- };
3392
- }
3393
3384
  function termFromCell(params) {
3394
3385
  const value = cleanCoverageTermValue(params.value);
3395
3386
  if (!value) return void 0;
@@ -3539,8 +3530,7 @@ function coverageFromEndorsement(endorsement, children) {
3539
3530
  const terms = uniqueTerms(rows.flatMap(
3540
3531
  (row) => termsFromRow(row, children).map((term) => {
3541
3532
  const appliesTo = nameFromRow(row, children);
3542
- const labelled = relabelGenericTerm(term, appliesTo);
3543
- return appliesTo && labelled.label !== appliesTo ? { ...labelled, appliesTo } : labelled;
3533
+ return appliesTo && term.label !== appliesTo ? { ...term, appliesTo } : term;
3544
3534
  })
3545
3535
  ));
3546
3536
  if (terms.length === 0) return void 0;
@@ -9743,7 +9733,343 @@ function groundExtractionMemoryWithSourceSpans(memory, sourceSpans) {
9743
9733
  }
9744
9734
 
9745
9735
  // src/extraction/source-tree-extractor.ts
9736
+ import { z as z42 } from "zod";
9737
+
9738
+ // src/extraction/operational-profile-cleanup.ts
9746
9739
  import { z as z41 } from "zod";
9740
+ var OPERATIONAL_COVERAGE_TERM_KINDS2 = [
9741
+ "each_claim_limit",
9742
+ "each_occurrence_limit",
9743
+ "each_loss_limit",
9744
+ "aggregate_limit",
9745
+ "sublimit",
9746
+ "retention",
9747
+ "deductible",
9748
+ "retroactive_date",
9749
+ "premium",
9750
+ "other"
9751
+ ];
9752
+ var OperationalCoverageTermKindSchema = z41.enum(OPERATIONAL_COVERAGE_TERM_KINDS2);
9753
+ var OperationalProfileCleanupSchema = z41.object({
9754
+ coverageDecisions: z41.array(z41.object({
9755
+ coverageIndex: z41.number().int().nonnegative(),
9756
+ action: z41.enum(["keep", "drop", "update"]),
9757
+ reason: z41.string().optional(),
9758
+ name: z41.string().optional(),
9759
+ limit: z41.string().nullable().optional(),
9760
+ deductible: z41.string().nullable().optional(),
9761
+ premium: z41.string().nullable().optional(),
9762
+ retroactiveDate: z41.string().nullable().optional(),
9763
+ coverageOrigin: z41.enum(["core", "endorsement"]).optional(),
9764
+ sourceNodeIds: z41.array(z41.string()).optional(),
9765
+ sourceSpanIds: z41.array(z41.string()).optional(),
9766
+ termDecisions: z41.array(z41.object({
9767
+ termIndex: z41.number().int().nonnegative(),
9768
+ action: z41.enum(["keep", "drop", "update"]),
9769
+ reason: z41.string().optional(),
9770
+ kind: OperationalCoverageTermKindSchema.optional(),
9771
+ label: z41.string().optional(),
9772
+ value: z41.string().optional(),
9773
+ amount: z41.number().nullable().optional(),
9774
+ appliesTo: z41.string().nullable().optional(),
9775
+ sourceNodeIds: z41.array(z41.string()).optional(),
9776
+ sourceSpanIds: z41.array(z41.string()).optional()
9777
+ })).optional()
9778
+ })).default([]),
9779
+ warnings: z41.array(z41.string()).default([])
9780
+ });
9781
+ function compactNode(node, maxText = 700) {
9782
+ return {
9783
+ id: node.id,
9784
+ kind: node.kind,
9785
+ title: node.title,
9786
+ path: node.path,
9787
+ pageStart: node.pageStart,
9788
+ pageEnd: node.pageEnd,
9789
+ sourceSpanIds: node.sourceSpanIds.slice(0, 8),
9790
+ text: (node.textExcerpt ?? node.description).slice(0, maxText)
9791
+ };
9792
+ }
9793
+ function compactCoverageForCleanup(coverage, coverageIndex) {
9794
+ return {
9795
+ coverageIndex,
9796
+ name: coverage.name,
9797
+ limit: coverage.limit,
9798
+ deductible: coverage.deductible,
9799
+ premium: coverage.premium,
9800
+ retroactiveDate: coverage.retroactiveDate,
9801
+ coverageOrigin: coverage.coverageOrigin,
9802
+ sourceNodeIds: coverage.sourceNodeIds,
9803
+ sourceSpanIds: coverage.sourceSpanIds,
9804
+ terms: coverage.limits.map((term, termIndex) => ({
9805
+ termIndex,
9806
+ kind: term.kind,
9807
+ label: term.label,
9808
+ value: term.value,
9809
+ amount: term.amount,
9810
+ appliesTo: term.appliesTo,
9811
+ sourceNodeIds: term.sourceNodeIds,
9812
+ sourceSpanIds: term.sourceSpanIds
9813
+ }))
9814
+ };
9815
+ }
9816
+ function buildOperationalProfileCleanupPrompt(sourceTree, profile) {
9817
+ const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 320).map((node) => compactNode(node, node.kind === "page" ? 900 : 700));
9818
+ const candidate = {
9819
+ documentType: profile.documentType,
9820
+ policyTypes: profile.policyTypes,
9821
+ coverageTypes: profile.coverageTypes,
9822
+ coverages: profile.coverages.map(compactCoverageForCleanup)
9823
+ };
9824
+ return `Review and clean a source-backed operational profile projection for an insurance policy.
9825
+
9826
+ Task:
9827
+ - Inspect the candidate coverage projection against the source nodes.
9828
+ - Return cleanup decisions only for coverage rows or terms that are malformed, unsupported, mismatched, or misleading.
9829
+ - If the projection is already acceptable, return an empty coverageDecisions array.
9830
+
9831
+ Projection defects to look for:
9832
+ - Generic labels such as "Column 3" that should be renamed from nearby row/header evidence.
9833
+ - 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.
9834
+ - Dangling continuation punctuation such as a trailing "/" copied into values.
9835
+ - Item references such as "shown in Item 7" or bare item numbers treated as money amounts.
9836
+ - Policy wording, exclusions, or unsupported prose copied into operational limit/deductible fields.
9837
+ - Header/value splits where "Limit of Liability", "Deductible", "Retroactive Date", "Aggregate", "Each Claim", or similar terms are attached to the wrong coverage row.
9838
+ - Repeated schedule headings projected as separate coverages when they only introduce the next coverage group.
9839
+
9840
+ Rules:
9841
+ - Use internal reasoning, but return JSON decisions only.
9842
+ - Do not invent policy facts. Keep, drop, or update only existing coverageIndex and termIndex entries.
9843
+ - Use sourceNodeIds and sourceSpanIds only from the provided source nodes or from the existing candidate entry.
9844
+ - Prefer dropping a malformed fact over speculative rewriting.
9845
+ - Keep a coverage when it is a real operational coverage/benefit even if only one term needs cleanup.
9846
+ - When changing a term's semantic meaning, set kind to the corrected normalized term kind.
9847
+ - Do not add new coverage rows or new terms; this pass cleans the existing projection.
9848
+ - Keep reasons concise and factual.
9849
+
9850
+ Candidate projection:
9851
+ ${JSON.stringify(candidate, null, 2)}
9852
+
9853
+ Source nodes:
9854
+ ${JSON.stringify(nodes, null, 2)}
9855
+
9856
+ Return JSON with coverageDecisions and warnings only.`;
9857
+ }
9858
+ function hasOwn(object, key) {
9859
+ return Object.prototype.hasOwnProperty.call(object, key);
9860
+ }
9861
+ function uniqueStrings(values) {
9862
+ return [...new Set(values.filter((value) => value.length > 0))];
9863
+ }
9864
+ function cleanProfileValue(value) {
9865
+ if (typeof value !== "string") return void 0;
9866
+ const cleaned = value.replace(/\s+\/\s*$/, "").replace(/\s+/g, " ").replace(/^[\s:;#-]+|[\s;,.]+$/g, "").trim();
9867
+ return cleaned || void 0;
9868
+ }
9869
+ function validIds(ids, valid) {
9870
+ return uniqueStrings((ids ?? []).filter((id) => valid.has(id)));
9871
+ }
9872
+ function cleanupIds(ids, valid, fallback) {
9873
+ if (ids === void 0) return validIds(fallback, valid);
9874
+ const next = validIds(ids, valid);
9875
+ return next.length > 0 ? next : validIds(fallback, valid);
9876
+ }
9877
+ function amountFromOperationalValue(value) {
9878
+ const match = value.match(/\$\s*([0-9][0-9,]*(?:\.\d+)?)/) ?? value.match(/\b([0-9][0-9,]*(?:\.\d+)?)\s*%/);
9879
+ if (!match) return void 0;
9880
+ const amount = Number(match[1].replace(/,/g, ""));
9881
+ return Number.isFinite(amount) ? amount : void 0;
9882
+ }
9883
+ function normalizedTermText(term) {
9884
+ return `${term.kind} ${term.label} ${term.value}`.toLowerCase();
9885
+ }
9886
+ function isLimitTerm(term) {
9887
+ 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));
9888
+ }
9889
+ function isDeductibleTerm(term) {
9890
+ return term.kind === "deductible" || term.kind === "retention" || /\b(deductible|retention|sir)\b/i.test(normalizedTermText(term));
9891
+ }
9892
+ function isPremiumTerm(term) {
9893
+ return term.kind === "premium" || /\bpremium\b/i.test(normalizedTermText(term));
9894
+ }
9895
+ function isRetroactiveDateTerm(term) {
9896
+ return term.kind === "retroactive_date" || /\bretroactive\b/i.test(normalizedTermText(term));
9897
+ }
9898
+ function primaryLimitFromTerms(terms) {
9899
+ return terms.find(isLimitTerm)?.value;
9900
+ }
9901
+ function deductibleFromTerms(terms) {
9902
+ return terms.find(isDeductibleTerm)?.value;
9903
+ }
9904
+ function premiumFromTerms(terms) {
9905
+ return terms.find(isPremiumTerm)?.value;
9906
+ }
9907
+ function retroactiveDateFromTerms(terms) {
9908
+ return terms.find(isRetroactiveDateTerm)?.value;
9909
+ }
9910
+ function termDecisionTouches(coverage, decision, predicate) {
9911
+ const existing = coverage.limits[decision.termIndex];
9912
+ if (existing && predicate(existing)) return true;
9913
+ if (!decision.kind && !decision.label && !decision.value) return false;
9914
+ return predicate({
9915
+ kind: decision.kind ?? existing?.kind ?? "other",
9916
+ label: cleanProfileValue(decision.label) ?? existing?.label ?? "",
9917
+ value: cleanProfileValue(decision.value) ?? existing?.value ?? ""
9918
+ });
9919
+ }
9920
+ function applyTermCleanupDecision(term, decision, validNodeIds, validSpanIds) {
9921
+ if (!decision || decision.action === "keep") return term;
9922
+ if (decision.action === "drop") return void 0;
9923
+ const label = cleanProfileValue(decision.label) ?? term.label;
9924
+ const value = cleanProfileValue(decision.value) ?? term.value;
9925
+ if (!label || !value) return term;
9926
+ const next = {
9927
+ ...term,
9928
+ kind: decision.kind ?? term.kind,
9929
+ label,
9930
+ value,
9931
+ sourceNodeIds: cleanupIds(decision.sourceNodeIds, validNodeIds, term.sourceNodeIds),
9932
+ sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, term.sourceSpanIds)
9933
+ };
9934
+ if (next.sourceNodeIds.length === 0 && next.sourceSpanIds.length === 0) return term;
9935
+ if (hasOwn(decision, "amount")) {
9936
+ if (typeof decision.amount === "number" && Number.isFinite(decision.amount)) next.amount = decision.amount;
9937
+ else delete next.amount;
9938
+ } else if (decision.value || decision.kind) {
9939
+ const amount = next.kind === "retroactive_date" ? void 0 : amountFromOperationalValue(next.value);
9940
+ if (amount === void 0) delete next.amount;
9941
+ else next.amount = amount;
9942
+ }
9943
+ if (hasOwn(decision, "appliesTo")) {
9944
+ const appliesTo = cleanProfileValue(decision.appliesTo);
9945
+ if (appliesTo) next.appliesTo = appliesTo;
9946
+ else delete next.appliesTo;
9947
+ }
9948
+ return next;
9949
+ }
9950
+ function termDecisionsTouch(coverage, decisions, predicate) {
9951
+ return decisions.filter((decision) => decision.action !== "keep").some((decision) => termDecisionTouches(coverage, decision, predicate));
9952
+ }
9953
+ function applyCoverageCleanupDecision(coverage, decision, validNodeIds, validSpanIds) {
9954
+ if (!decision || decision.action === "keep") return coverage;
9955
+ if (decision.action === "drop") return void 0;
9956
+ const next = {
9957
+ ...coverage,
9958
+ limits: [...coverage.limits],
9959
+ sourceNodeIds: cleanupIds(decision.sourceNodeIds, validNodeIds, coverage.sourceNodeIds),
9960
+ sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, coverage.sourceSpanIds)
9961
+ };
9962
+ const name = cleanProfileValue(decision.name);
9963
+ if (name) next.name = name;
9964
+ if (decision.coverageOrigin) next.coverageOrigin = decision.coverageOrigin;
9965
+ if (hasOwn(decision, "limit")) {
9966
+ const value = cleanProfileValue(decision.limit);
9967
+ if (value) next.limit = value;
9968
+ else delete next.limit;
9969
+ }
9970
+ if (hasOwn(decision, "deductible")) {
9971
+ const value = cleanProfileValue(decision.deductible);
9972
+ if (value) next.deductible = value;
9973
+ else delete next.deductible;
9974
+ }
9975
+ if (hasOwn(decision, "premium")) {
9976
+ const value = cleanProfileValue(decision.premium);
9977
+ if (value) next.premium = value;
9978
+ else delete next.premium;
9979
+ }
9980
+ if (hasOwn(decision, "retroactiveDate")) {
9981
+ const value = cleanProfileValue(decision.retroactiveDate);
9982
+ if (value) next.retroactiveDate = value;
9983
+ else delete next.retroactiveDate;
9984
+ }
9985
+ const termDecisions = (decision.termDecisions ?? []).filter((termDecision) => termDecision.termIndex < coverage.limits.length);
9986
+ const termDecisionByIndex = new Map(termDecisions.map((termDecision) => [termDecision.termIndex, termDecision]));
9987
+ next.limits = coverage.limits.map((term, index) => applyTermCleanupDecision(term, termDecisionByIndex.get(index), validNodeIds, validSpanIds)).filter((term) => Boolean(term));
9988
+ if (termDecisions.length > 0) {
9989
+ if (!hasOwn(decision, "limit") && termDecisionsTouch(coverage, termDecisions, isLimitTerm)) {
9990
+ const value = primaryLimitFromTerms(next.limits);
9991
+ if (value) next.limit = value;
9992
+ else delete next.limit;
9993
+ }
9994
+ if (!hasOwn(decision, "deductible") && termDecisionsTouch(coverage, termDecisions, isDeductibleTerm)) {
9995
+ const value = deductibleFromTerms(next.limits);
9996
+ if (value) next.deductible = value;
9997
+ else delete next.deductible;
9998
+ }
9999
+ if (!hasOwn(decision, "premium") && termDecisionsTouch(coverage, termDecisions, isPremiumTerm)) {
10000
+ const value = premiumFromTerms(next.limits);
10001
+ if (value) next.premium = value;
10002
+ else delete next.premium;
10003
+ }
10004
+ if (!hasOwn(decision, "retroactiveDate") && termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm)) {
10005
+ const value = retroactiveDateFromTerms(next.limits);
10006
+ if (value) next.retroactiveDate = value;
10007
+ else delete next.retroactiveDate;
10008
+ }
10009
+ }
10010
+ next.sourceNodeIds = uniqueStrings([
10011
+ ...next.sourceNodeIds,
10012
+ ...next.limits.flatMap((term) => term.sourceNodeIds)
10013
+ ]);
10014
+ next.sourceSpanIds = uniqueStrings([
10015
+ ...next.sourceSpanIds,
10016
+ ...next.limits.flatMap((term) => term.sourceSpanIds)
10017
+ ]);
10018
+ return next.name ? next : coverage;
10019
+ }
10020
+ function sourceIdsFromOperationalProfile(profile) {
10021
+ const backedValues = [
10022
+ profile.policyNumber,
10023
+ profile.namedInsured,
10024
+ profile.insurer,
10025
+ profile.broker,
10026
+ profile.effectiveDate,
10027
+ profile.expirationDate,
10028
+ profile.retroactiveDate,
10029
+ profile.premium
10030
+ ].filter(Boolean);
10031
+ return {
10032
+ sourceNodeIds: uniqueStrings([
10033
+ ...backedValues.flatMap((value) => value?.sourceNodeIds ?? []),
10034
+ ...profile.coverages.flatMap((coverage) => coverage.sourceNodeIds),
10035
+ ...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceNodeIds)),
10036
+ ...profile.parties.flatMap((party) => party.sourceNodeIds),
10037
+ ...profile.endorsementSupport.flatMap((support) => support.sourceNodeIds)
10038
+ ]),
10039
+ sourceSpanIds: uniqueStrings([
10040
+ ...backedValues.flatMap((value) => value?.sourceSpanIds ?? []),
10041
+ ...profile.coverages.flatMap((coverage) => coverage.sourceSpanIds),
10042
+ ...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceSpanIds)),
10043
+ ...profile.parties.flatMap((party) => party.sourceSpanIds),
10044
+ ...profile.endorsementSupport.flatMap((support) => support.sourceSpanIds)
10045
+ ])
10046
+ };
10047
+ }
10048
+ function applyOperationalProfileCleanup(profile, cleanup, validNodeIds, validSpanIds) {
10049
+ const coverageDecisionByIndex = /* @__PURE__ */ new Map();
10050
+ for (const decision of cleanup.coverageDecisions) {
10051
+ if (decision.coverageIndex < profile.coverages.length) coverageDecisionByIndex.set(decision.coverageIndex, decision);
10052
+ }
10053
+ const coverages = profile.coverages.map(
10054
+ (coverage, index) => applyCoverageCleanupDecision(coverage, coverageDecisionByIndex.get(index), validNodeIds, validSpanIds)
10055
+ ).filter((coverage) => Boolean(coverage));
10056
+ const cleanupWarnings = cleanup.warnings.map((warning) => cleanProfileValue(warning)).filter((warning) => Boolean(warning));
10057
+ const nextProfile = {
10058
+ ...profile,
10059
+ coverages,
10060
+ coverageTypes: uniqueStrings(coverages.map((coverage) => coverage.name)),
10061
+ warnings: uniqueStrings([
10062
+ ...profile.warnings,
10063
+ ...cleanupWarnings.map((warning) => `Operational profile cleanup warning: ${warning}`)
10064
+ ])
10065
+ };
10066
+ return PolicyOperationalProfileSchema.parse({
10067
+ ...nextProfile,
10068
+ ...sourceIdsFromOperationalProfile(nextProfile)
10069
+ });
10070
+ }
10071
+
10072
+ // src/extraction/source-tree-extractor.ts
9747
10073
  var ORGANIZABLE_KINDS = [
9748
10074
  "page_group",
9749
10075
  "form",
@@ -9756,10 +10082,10 @@ var ORGANIZATION_TOP_LEVEL_BATCH_SIZE = 80;
9756
10082
  var ORGANIZER_MAX_SOURCE_SPANS = 400;
9757
10083
  var ORGANIZER_MAX_TOP_LEVEL_NODES = 18;
9758
10084
  var OUTLINE_CLEANUP_MAX_TOP_LEVEL_NODES = 80;
9759
- var SourceTreeOrganizationSchema = z41.object({
9760
- labels: z41.array(z41.object({
9761
- nodeId: z41.string(),
9762
- kind: z41.enum([
10085
+ var SourceTreeOrganizationSchema = z42.object({
10086
+ labels: z42.array(z42.object({
10087
+ nodeId: z42.string(),
10088
+ kind: z42.enum([
9763
10089
  "document",
9764
10090
  "page_group",
9765
10091
  "page",
@@ -9773,26 +10099,26 @@ var SourceTreeOrganizationSchema = z41.object({
9773
10099
  "table_cell",
9774
10100
  "text"
9775
10101
  ]).optional(),
9776
- title: z41.string().optional(),
9777
- description: z41.string().optional()
10102
+ title: z42.string().optional(),
10103
+ description: z42.string().optional()
9778
10104
  })),
9779
- groups: z41.array(z41.object({
9780
- kind: z41.enum(ORGANIZABLE_KINDS),
9781
- title: z41.string(),
9782
- description: z41.string().optional(),
9783
- childNodeIds: z41.array(z41.string()).min(1)
10105
+ groups: z42.array(z42.object({
10106
+ kind: z42.enum(ORGANIZABLE_KINDS),
10107
+ title: z42.string(),
10108
+ description: z42.string().optional(),
10109
+ childNodeIds: z42.array(z42.string()).min(1)
9784
10110
  }))
9785
10111
  });
9786
- var SourceBackedValueForPromptSchema = z41.object({
9787
- value: z41.string(),
9788
- normalizedValue: z41.string().optional(),
9789
- confidence: z41.enum(["low", "medium", "high"]).optional(),
9790
- sourceNodeIds: z41.array(z41.string()),
9791
- sourceSpanIds: z41.array(z41.string())
10112
+ var SourceBackedValueForPromptSchema = z42.object({
10113
+ value: z42.string(),
10114
+ normalizedValue: z42.string().optional(),
10115
+ confidence: z42.enum(["low", "medium", "high"]).optional(),
10116
+ sourceNodeIds: z42.array(z42.string()),
10117
+ sourceSpanIds: z42.array(z42.string())
9792
10118
  });
9793
- var OperationalProfilePromptSchema = z41.object({
9794
- documentType: z41.enum(["policy", "quote"]).optional(),
9795
- policyTypes: z41.array(z41.string()).optional(),
10119
+ var OperationalProfilePromptSchema = z42.object({
10120
+ documentType: z42.enum(["policy", "quote"]).optional(),
10121
+ policyTypes: z42.array(z42.string()).optional(),
9796
10122
  policyNumber: SourceBackedValueForPromptSchema.optional(),
9797
10123
  namedInsured: SourceBackedValueForPromptSchema.optional(),
9798
10124
  insurer: SourceBackedValueForPromptSchema.optional(),
@@ -9801,43 +10127,32 @@ var OperationalProfilePromptSchema = z41.object({
9801
10127
  expirationDate: SourceBackedValueForPromptSchema.optional(),
9802
10128
  retroactiveDate: SourceBackedValueForPromptSchema.optional(),
9803
10129
  premium: SourceBackedValueForPromptSchema.optional(),
9804
- coverageTypes: z41.array(z41.string()).optional(),
9805
- coverages: z41.array(z41.object({
9806
- name: z41.string(),
9807
- coverageCode: z41.string().optional(),
9808
- limit: z41.string().optional(),
9809
- deductible: z41.string().optional(),
9810
- premium: z41.string().optional(),
9811
- retroactiveDate: z41.string().optional(),
9812
- formNumber: z41.string().optional(),
9813
- sectionRef: z41.string().optional(),
9814
- coverageOrigin: z41.enum(["core", "endorsement"]).optional(),
9815
- endorsementNumber: z41.string().optional(),
9816
- limits: z41.array(z41.object({
9817
- kind: z41.enum([
9818
- "each_claim_limit",
9819
- "each_occurrence_limit",
9820
- "each_loss_limit",
9821
- "aggregate_limit",
9822
- "sublimit",
9823
- "retention",
9824
- "deductible",
9825
- "retroactive_date",
9826
- "premium",
9827
- "other"
9828
- ]).optional(),
9829
- label: z41.string(),
9830
- value: z41.string(),
9831
- amount: z41.number().optional(),
9832
- appliesTo: z41.string().optional(),
9833
- sourceNodeIds: z41.array(z41.string()),
9834
- sourceSpanIds: z41.array(z41.string())
10130
+ coverageTypes: z42.array(z42.string()).optional(),
10131
+ coverages: z42.array(z42.object({
10132
+ name: z42.string(),
10133
+ coverageCode: z42.string().optional(),
10134
+ limit: z42.string().optional(),
10135
+ deductible: z42.string().optional(),
10136
+ premium: z42.string().optional(),
10137
+ retroactiveDate: z42.string().optional(),
10138
+ formNumber: z42.string().optional(),
10139
+ sectionRef: z42.string().optional(),
10140
+ coverageOrigin: z42.enum(["core", "endorsement"]).optional(),
10141
+ endorsementNumber: z42.string().optional(),
10142
+ limits: z42.array(z42.object({
10143
+ kind: OperationalCoverageTermKindSchema.optional(),
10144
+ label: z42.string(),
10145
+ value: z42.string(),
10146
+ amount: z42.number().optional(),
10147
+ appliesTo: z42.string().optional(),
10148
+ sourceNodeIds: z42.array(z42.string()),
10149
+ sourceSpanIds: z42.array(z42.string())
9835
10150
  })).optional(),
9836
- sourceNodeIds: z41.array(z41.string()),
9837
- sourceSpanIds: z41.array(z41.string())
10151
+ sourceNodeIds: z42.array(z42.string()),
10152
+ sourceSpanIds: z42.array(z42.string())
9838
10153
  })).optional(),
9839
- sourceNodeIds: z41.array(z41.string()).optional(),
9840
- sourceSpanIds: z41.array(z41.string()).optional()
10154
+ sourceNodeIds: z42.array(z42.string()).optional(),
10155
+ sourceSpanIds: z42.array(z42.string()).optional()
9841
10156
  });
9842
10157
  function formatFormHintsForPrompt(forms) {
9843
10158
  const usable = forms.filter((form) => typeof form.pageStart === "number" && typeof form.pageEnd === "number").slice(0, 120).map((form) => ({
@@ -10829,7 +11144,7 @@ function applyEndorsementGrouping(sourceTree) {
10829
11144
  }
10830
11145
  return normalizeSemanticHierarchy(nextTree);
10831
11146
  }
10832
- function compactNode(node, maxText = 700) {
11147
+ function compactNode2(node, maxText = 700) {
10833
11148
  return {
10834
11149
  id: node.id,
10835
11150
  kind: node.kind,
@@ -10919,7 +11234,7 @@ function mergeOrganizationResults(results) {
10919
11234
  };
10920
11235
  }
10921
11236
  function buildOrganizationPrompt(batch, formHints) {
10922
- const nodes = batch.nodes.map((node) => compactNode(node, node.kind === "page" ? 900 : 320));
11237
+ const nodes = batch.nodes.map((node) => compactNode2(node, node.kind === "page" ? 900 : 320));
10923
11238
  return `You organize an insurance document source tree.
10924
11239
 
10925
11240
  Scope:
@@ -10961,7 +11276,7 @@ function shouldRunOutlineCleanup(sourceTree) {
10961
11276
  }
10962
11277
  function buildOutlineCleanupPrompt(sourceTree, formHints) {
10963
11278
  const topLevel = rootChildren(sourceTree).slice(0, OUTLINE_CLEANUP_MAX_TOP_LEVEL_NODES);
10964
- const nodes = topLevel.map((node) => compactNode(node, 900));
11279
+ const nodes = topLevel.map((node) => compactNode2(node, 900));
10965
11280
  return `You clean a top-level source outline for an insurance policy.
10966
11281
 
10967
11282
  Expected product-facing order:
@@ -10990,7 +11305,7 @@ ${JSON.stringify(nodes, null, 2)}
10990
11305
  Return JSON with labels and groups only.`;
10991
11306
  }
10992
11307
  function buildOperationalProfilePrompt(sourceTree, fallback) {
10993
- const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 240).map(compactNode);
11308
+ const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 240).map(compactNode2);
10994
11309
  return `Extract a source-backed operational profile for an insurance policy or quote.
10995
11310
 
10996
11311
  Return only high-value operational facts needed for policy lists, Q&A, compliance, and certificate generation:
@@ -11354,6 +11669,45 @@ async function runSourceTreeExtraction(params) {
11354
11669
  } catch (error) {
11355
11670
  warnings.push(`Operational profile model pass failed; deterministic profile used (${error instanceof Error ? error.message : String(error)})`);
11356
11671
  }
11672
+ if (operationalProfile.coverages.length > 0) {
11673
+ try {
11674
+ const validNodeIds = new Set(sourceTree.map((node) => node.id));
11675
+ const validSpanIds = new Set(sourceSpans.map((span) => span.id));
11676
+ const budget = params.resolveBudget("extraction_operational_profile", 4096);
11677
+ const startedAt = Date.now();
11678
+ const response = await safeGenerateObject(
11679
+ params.generateObject,
11680
+ {
11681
+ prompt: buildOperationalProfileCleanupPrompt(sourceTree, operationalProfile),
11682
+ schema: OperationalProfileCleanupSchema,
11683
+ maxTokens: budget.maxTokens,
11684
+ taskKind: "extraction_operational_profile",
11685
+ budgetDiagnostics: budget,
11686
+ providerOptions: params.providerOptions
11687
+ },
11688
+ {
11689
+ fallback: { coverageDecisions: [], warnings: [] },
11690
+ log: params.log
11691
+ }
11692
+ );
11693
+ localTrack(response.usage, {
11694
+ taskKind: "extraction_operational_profile",
11695
+ label: "operational_profile_cleanup",
11696
+ maxTokens: budget.maxTokens,
11697
+ durationMs: Date.now() - startedAt
11698
+ });
11699
+ operationalProfile = applyOperationalProfileCleanup(
11700
+ operationalProfile,
11701
+ response.object,
11702
+ validNodeIds,
11703
+ validSpanIds
11704
+ );
11705
+ } catch (error) {
11706
+ warnings.push(`Operational profile cleanup pass failed; uncleaned profile used (${error instanceof Error ? error.message : String(error)})`);
11707
+ }
11708
+ } else {
11709
+ await params.log?.("Operational profile has no coverage rows; skipped model cleanup");
11710
+ }
11357
11711
  const document = materializeDocument({
11358
11712
  id: params.id,
11359
11713
  sourceTree,
@@ -12680,8 +13034,8 @@ Respond with JSON only:
12680
13034
  }`;
12681
13035
 
12682
13036
  // src/schemas/application.ts
12683
- import { z as z42 } from "zod";
12684
- var FieldTypeSchema = z42.enum([
13037
+ import { z as z43 } from "zod";
13038
+ var FieldTypeSchema = z43.enum([
12685
13039
  "text",
12686
13040
  "numeric",
12687
13041
  "currency",
@@ -12690,223 +13044,223 @@ var FieldTypeSchema = z42.enum([
12690
13044
  "table",
12691
13045
  "declaration"
12692
13046
  ]);
12693
- var ApplicationFieldSchema = z42.object({
12694
- id: z42.string(),
12695
- label: z42.string(),
12696
- section: z42.string(),
13047
+ var ApplicationFieldSchema = z43.object({
13048
+ id: z43.string(),
13049
+ label: z43.string(),
13050
+ section: z43.string(),
12697
13051
  fieldType: FieldTypeSchema,
12698
- required: z42.boolean(),
12699
- options: z42.array(z42.string()).optional(),
12700
- columns: z42.array(z42.string()).optional(),
12701
- requiresExplanationIfYes: z42.boolean().optional(),
12702
- condition: z42.object({
12703
- dependsOn: z42.string(),
12704
- whenValue: z42.string()
13052
+ required: z43.boolean(),
13053
+ options: z43.array(z43.string()).optional(),
13054
+ columns: z43.array(z43.string()).optional(),
13055
+ requiresExplanationIfYes: z43.boolean().optional(),
13056
+ condition: z43.object({
13057
+ dependsOn: z43.string(),
13058
+ whenValue: z43.string()
12705
13059
  }).optional(),
12706
- value: z42.string().optional(),
12707
- source: z42.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
12708
- confidence: z42.enum(["confirmed", "high", "medium", "low"]).optional(),
12709
- sourceSpanIds: z42.array(z42.string()).optional().describe("Stable source spans that support the field value or field anchor"),
12710
- userSourceSpanIds: z42.array(z42.string()).optional().describe("Message or attachment spans that support user-provided values"),
12711
- pageNumber: z42.number().int().positive().optional().describe("Application page where the field label or anchor appears"),
12712
- fieldAnchorId: z42.string().optional().describe("Stable field anchor ID derived from page, section, label, and form metadata"),
12713
- acroFormName: z42.string().optional().describe("Native PDF AcroForm field name when available"),
12714
- validationStatus: z42.enum(["valid", "needs_review", "unsupported", "missing"]).optional()
13060
+ value: z43.string().optional(),
13061
+ source: z43.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
13062
+ confidence: z43.enum(["confirmed", "high", "medium", "low"]).optional(),
13063
+ sourceSpanIds: z43.array(z43.string()).optional().describe("Stable source spans that support the field value or field anchor"),
13064
+ userSourceSpanIds: z43.array(z43.string()).optional().describe("Message or attachment spans that support user-provided values"),
13065
+ pageNumber: z43.number().int().positive().optional().describe("Application page where the field label or anchor appears"),
13066
+ fieldAnchorId: z43.string().optional().describe("Stable field anchor ID derived from page, section, label, and form metadata"),
13067
+ acroFormName: z43.string().optional().describe("Native PDF AcroForm field name when available"),
13068
+ validationStatus: z43.enum(["valid", "needs_review", "unsupported", "missing"]).optional()
12715
13069
  });
12716
- var ApplicationQuestionConditionSchema = z42.object({
12717
- dependsOn: z42.string(),
12718
- operator: z42.enum(["equals", "not_equals", "in", "not_in", "exists"]).optional(),
12719
- value: z42.string().optional(),
12720
- whenValue: z42.string().optional(),
12721
- values: z42.array(z42.string()).optional()
13070
+ var ApplicationQuestionConditionSchema = z43.object({
13071
+ dependsOn: z43.string(),
13072
+ operator: z43.enum(["equals", "not_equals", "in", "not_in", "exists"]).optional(),
13073
+ value: z43.string().optional(),
13074
+ whenValue: z43.string().optional(),
13075
+ values: z43.array(z43.string()).optional()
12722
13076
  });
12723
- var ApplicationRepeatSchema = z42.object({
12724
- min: z42.number().int().nonnegative().optional(),
12725
- max: z42.number().int().positive().optional(),
12726
- label: z42.string().optional()
13077
+ var ApplicationRepeatSchema = z43.object({
13078
+ min: z43.number().int().nonnegative().optional(),
13079
+ max: z43.number().int().positive().optional(),
13080
+ label: z43.string().optional()
12727
13081
  });
12728
- var ApplicationQuestionNodeSchema = z42.lazy(
12729
- () => z42.object({
12730
- id: z42.string(),
12731
- nodeType: z42.enum(["group", "question", "repeat_group", "table"]),
12732
- fieldId: z42.string().optional(),
12733
- fieldPath: z42.string().optional(),
12734
- parentId: z42.string().optional(),
12735
- order: z42.number().int().nonnegative().optional(),
12736
- label: z42.string(),
12737
- section: z42.string().optional(),
13082
+ var ApplicationQuestionNodeSchema = z43.lazy(
13083
+ () => z43.object({
13084
+ id: z43.string(),
13085
+ nodeType: z43.enum(["group", "question", "repeat_group", "table"]),
13086
+ fieldId: z43.string().optional(),
13087
+ fieldPath: z43.string().optional(),
13088
+ parentId: z43.string().optional(),
13089
+ order: z43.number().int().nonnegative().optional(),
13090
+ label: z43.string(),
13091
+ section: z43.string().optional(),
12738
13092
  fieldType: FieldTypeSchema.optional(),
12739
- required: z42.boolean().optional(),
12740
- prompt: z42.string().optional(),
12741
- options: z42.array(z42.string()).optional(),
12742
- columns: z42.array(z42.string()).optional(),
13093
+ required: z43.boolean().optional(),
13094
+ prompt: z43.string().optional(),
13095
+ options: z43.array(z43.string()).optional(),
13096
+ columns: z43.array(z43.string()).optional(),
12743
13097
  condition: ApplicationQuestionConditionSchema.optional(),
12744
13098
  repeat: ApplicationRepeatSchema.optional(),
12745
- children: z42.array(ApplicationQuestionNodeSchema).optional()
13099
+ children: z43.array(ApplicationQuestionNodeSchema).optional()
12746
13100
  })
12747
13101
  );
12748
- var ApplicationQuestionGraphSchema = z42.object({
12749
- id: z42.string(),
12750
- version: z42.string(),
12751
- title: z42.string().optional(),
12752
- applicationType: z42.string().nullable().optional(),
12753
- source: z42.enum(["pdf", "manual", "imported", "generated"]).default("generated"),
12754
- rootNodeIds: z42.array(z42.string()).optional(),
12755
- nodes: z42.array(ApplicationQuestionNodeSchema)
13102
+ var ApplicationQuestionGraphSchema = z43.object({
13103
+ id: z43.string(),
13104
+ version: z43.string(),
13105
+ title: z43.string().optional(),
13106
+ applicationType: z43.string().nullable().optional(),
13107
+ source: z43.enum(["pdf", "manual", "imported", "generated"]).default("generated"),
13108
+ rootNodeIds: z43.array(z43.string()).optional(),
13109
+ nodes: z43.array(ApplicationQuestionNodeSchema)
12756
13110
  });
12757
- var ApplicationTemplateSchema = z42.object({
12758
- id: z42.string(),
12759
- version: z42.string(),
12760
- title: z42.string(),
12761
- applicationType: z42.string().nullable().optional(),
13111
+ var ApplicationTemplateSchema = z43.object({
13112
+ id: z43.string(),
13113
+ version: z43.string(),
13114
+ title: z43.string(),
13115
+ applicationType: z43.string().nullable().optional(),
12762
13116
  questionGraph: ApplicationQuestionGraphSchema,
12763
- fields: z42.array(ApplicationFieldSchema).optional()
13117
+ fields: z43.array(ApplicationFieldSchema).optional()
12764
13118
  });
12765
- var ApplicationClassifyResultSchema = z42.object({
12766
- isApplication: z42.boolean(),
12767
- confidence: z42.number().min(0).max(1),
12768
- applicationType: z42.string().nullable()
13119
+ var ApplicationClassifyResultSchema = z43.object({
13120
+ isApplication: z43.boolean(),
13121
+ confidence: z43.number().min(0).max(1),
13122
+ applicationType: z43.string().nullable()
12769
13123
  });
12770
- var FieldExtractionResultSchema = z42.object({
12771
- fields: z42.array(ApplicationFieldSchema)
13124
+ var FieldExtractionResultSchema = z43.object({
13125
+ fields: z43.array(ApplicationFieldSchema)
12772
13126
  });
12773
- var AutoFillMatchSchema = z42.object({
12774
- fieldId: z42.string(),
12775
- value: z42.string(),
12776
- confidence: z42.enum(["confirmed"]),
12777
- contextKey: z42.string()
13127
+ var AutoFillMatchSchema = z43.object({
13128
+ fieldId: z43.string(),
13129
+ value: z43.string(),
13130
+ confidence: z43.enum(["confirmed"]),
13131
+ contextKey: z43.string()
12778
13132
  });
12779
- var AutoFillResultSchema = z42.object({
12780
- matches: z42.array(AutoFillMatchSchema)
13133
+ var AutoFillResultSchema = z43.object({
13134
+ matches: z43.array(AutoFillMatchSchema)
12781
13135
  });
12782
- var QuestionBatchResultSchema = z42.object({
12783
- batches: z42.array(z42.array(z42.string()).describe("Array of field IDs in this batch"))
13136
+ var QuestionBatchResultSchema = z43.object({
13137
+ batches: z43.array(z43.array(z43.string()).describe("Array of field IDs in this batch"))
12784
13138
  });
12785
- var LookupRequestSchema = z42.object({
12786
- type: z42.string().describe("Type of lookup: 'records', 'website', 'policy'"),
12787
- description: z42.string(),
12788
- url: z42.string().optional(),
12789
- targetFieldIds: z42.array(z42.string())
13139
+ var LookupRequestSchema = z43.object({
13140
+ type: z43.string().describe("Type of lookup: 'records', 'website', 'policy'"),
13141
+ description: z43.string(),
13142
+ url: z43.string().optional(),
13143
+ targetFieldIds: z43.array(z43.string())
12790
13144
  });
12791
- var ReplyIntentSchema = z42.object({
12792
- primaryIntent: z42.enum(["answers_only", "question", "lookup_request", "mixed"]),
12793
- hasAnswers: z42.boolean(),
12794
- questionText: z42.string().optional(),
12795
- questionFieldIds: z42.array(z42.string()).optional(),
12796
- lookupRequests: z42.array(LookupRequestSchema).optional()
13145
+ var ReplyIntentSchema = z43.object({
13146
+ primaryIntent: z43.enum(["answers_only", "question", "lookup_request", "mixed"]),
13147
+ hasAnswers: z43.boolean(),
13148
+ questionText: z43.string().optional(),
13149
+ questionFieldIds: z43.array(z43.string()).optional(),
13150
+ lookupRequests: z43.array(LookupRequestSchema).optional()
12797
13151
  });
12798
- var ParsedAnswerSchema = z42.object({
12799
- fieldId: z42.string(),
12800
- value: z42.string(),
12801
- explanation: z42.string().optional()
13152
+ var ParsedAnswerSchema = z43.object({
13153
+ fieldId: z43.string(),
13154
+ value: z43.string(),
13155
+ explanation: z43.string().optional()
12802
13156
  });
12803
- var AnswerParsingResultSchema = z42.object({
12804
- answers: z42.array(ParsedAnswerSchema),
12805
- unanswered: z42.array(z42.string()).describe("Field IDs that were not answered")
13157
+ var AnswerParsingResultSchema = z43.object({
13158
+ answers: z43.array(ParsedAnswerSchema),
13159
+ unanswered: z43.array(z43.string()).describe("Field IDs that were not answered")
12806
13160
  });
12807
- var LookupFillSchema = z42.object({
12808
- fieldId: z42.string(),
12809
- value: z42.string(),
12810
- source: z42.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'"),
12811
- sourceSpanIds: z42.array(z42.string()).optional()
13161
+ var LookupFillSchema = z43.object({
13162
+ fieldId: z43.string(),
13163
+ value: z43.string(),
13164
+ source: z43.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'"),
13165
+ sourceSpanIds: z43.array(z43.string()).optional()
12812
13166
  });
12813
- var LookupFillResultSchema = z42.object({
12814
- fills: z42.array(LookupFillSchema),
12815
- unfillable: z42.array(z42.string()),
12816
- explanation: z42.string().optional()
13167
+ var LookupFillResultSchema = z43.object({
13168
+ fills: z43.array(LookupFillSchema),
13169
+ unfillable: z43.array(z43.string()),
13170
+ explanation: z43.string().optional()
12817
13171
  });
12818
- var FlatPdfPlacementSchema = z42.object({
12819
- fieldId: z42.string(),
12820
- page: z42.number(),
12821
- x: z42.number().describe("Percentage from left edge (0-100)"),
12822
- y: z42.number().describe("Percentage from top edge (0-100)"),
12823
- text: z42.string(),
12824
- fontSize: z42.number().optional(),
12825
- isCheckmark: z42.boolean().optional()
13172
+ var FlatPdfPlacementSchema = z43.object({
13173
+ fieldId: z43.string(),
13174
+ page: z43.number(),
13175
+ x: z43.number().describe("Percentage from left edge (0-100)"),
13176
+ y: z43.number().describe("Percentage from top edge (0-100)"),
13177
+ text: z43.string(),
13178
+ fontSize: z43.number().optional(),
13179
+ isCheckmark: z43.boolean().optional()
12826
13180
  });
12827
- var AcroFormMappingSchema = z42.object({
12828
- fieldId: z42.string(),
12829
- acroFormName: z42.string(),
12830
- value: z42.string()
13181
+ var AcroFormMappingSchema = z43.object({
13182
+ fieldId: z43.string(),
13183
+ acroFormName: z43.string(),
13184
+ value: z43.string()
12831
13185
  });
12832
- var QualityGateStatusSchema = z42.enum(["passed", "warning", "failed"]);
12833
- var QualitySeveritySchema = z42.enum(["info", "warning", "blocking"]);
12834
- var ApplicationQualityIssueSchema = z42.object({
12835
- code: z42.string(),
13186
+ var QualityGateStatusSchema = z43.enum(["passed", "warning", "failed"]);
13187
+ var QualitySeveritySchema = z43.enum(["info", "warning", "blocking"]);
13188
+ var ApplicationQualityIssueSchema = z43.object({
13189
+ code: z43.string(),
12836
13190
  severity: QualitySeveritySchema,
12837
- message: z42.string(),
12838
- fieldId: z42.string().optional()
13191
+ message: z43.string(),
13192
+ fieldId: z43.string().optional()
12839
13193
  });
12840
- var ApplicationQualityRoundSchema = z42.object({
12841
- round: z42.number(),
12842
- kind: z42.string(),
13194
+ var ApplicationQualityRoundSchema = z43.object({
13195
+ round: z43.number(),
13196
+ kind: z43.string(),
12843
13197
  status: QualityGateStatusSchema,
12844
- summary: z42.string().optional()
13198
+ summary: z43.string().optional()
12845
13199
  });
12846
- var ApplicationQualityArtifactSchema = z42.object({
12847
- kind: z42.string(),
12848
- label: z42.string().optional(),
12849
- itemCount: z42.number().optional()
13200
+ var ApplicationQualityArtifactSchema = z43.object({
13201
+ kind: z43.string(),
13202
+ label: z43.string().optional(),
13203
+ itemCount: z43.number().optional()
12850
13204
  });
12851
- var ApplicationEmailReviewSchema = z42.object({
12852
- issues: z42.array(ApplicationQualityIssueSchema),
13205
+ var ApplicationEmailReviewSchema = z43.object({
13206
+ issues: z43.array(ApplicationQualityIssueSchema),
12853
13207
  qualityGateStatus: QualityGateStatusSchema
12854
13208
  });
12855
- var ApplicationQualityReportSchema = z42.object({
12856
- issues: z42.array(ApplicationQualityIssueSchema),
12857
- rounds: z42.array(ApplicationQualityRoundSchema).optional(),
12858
- artifacts: z42.array(ApplicationQualityArtifactSchema).optional(),
13209
+ var ApplicationQualityReportSchema = z43.object({
13210
+ issues: z43.array(ApplicationQualityIssueSchema),
13211
+ rounds: z43.array(ApplicationQualityRoundSchema).optional(),
13212
+ artifacts: z43.array(ApplicationQualityArtifactSchema).optional(),
12859
13213
  emailReview: ApplicationEmailReviewSchema.optional(),
12860
13214
  qualityGateStatus: QualityGateStatusSchema
12861
13215
  });
12862
- var ApplicationContextProposalSchema = z42.object({
12863
- id: z42.string(),
12864
- fieldId: z42.string().optional(),
12865
- key: z42.string(),
12866
- value: z42.string(),
12867
- category: z42.string(),
12868
- source: z42.enum(["application", "user", "lookup", "policy", "email", "chat", "imessage", "mcp"]),
12869
- confidence: z42.enum(["confirmed", "high", "medium", "low"]),
12870
- sourceSpanIds: z42.array(z42.string()).optional(),
12871
- userSourceSpanIds: z42.array(z42.string()).optional()
13216
+ var ApplicationContextProposalSchema = z43.object({
13217
+ id: z43.string(),
13218
+ fieldId: z43.string().optional(),
13219
+ key: z43.string(),
13220
+ value: z43.string(),
13221
+ category: z43.string(),
13222
+ source: z43.enum(["application", "user", "lookup", "policy", "email", "chat", "imessage", "mcp"]),
13223
+ confidence: z43.enum(["confirmed", "high", "medium", "low"]),
13224
+ sourceSpanIds: z43.array(z43.string()).optional(),
13225
+ userSourceSpanIds: z43.array(z43.string()).optional()
12872
13226
  });
12873
- var ApplicationPacketAnswerSchema = z42.object({
12874
- fieldId: z42.string(),
12875
- label: z42.string(),
12876
- section: z42.string(),
12877
- value: z42.string(),
12878
- source: z42.string(),
12879
- confidence: z42.enum(["confirmed", "high", "medium", "low"]).optional(),
12880
- sourceSpanIds: z42.array(z42.string()).optional(),
12881
- userSourceSpanIds: z42.array(z42.string()).optional()
13227
+ var ApplicationPacketAnswerSchema = z43.object({
13228
+ fieldId: z43.string(),
13229
+ label: z43.string(),
13230
+ section: z43.string(),
13231
+ value: z43.string(),
13232
+ source: z43.string(),
13233
+ confidence: z43.enum(["confirmed", "high", "medium", "low"]).optional(),
13234
+ sourceSpanIds: z43.array(z43.string()).optional(),
13235
+ userSourceSpanIds: z43.array(z43.string()).optional()
12882
13236
  });
12883
- var ApplicationPacketSchema = z42.object({
12884
- id: z42.string(),
12885
- applicationId: z42.string(),
12886
- title: z42.string(),
12887
- status: z42.enum(["draft", "broker_ready", "submitted"]),
12888
- answers: z42.array(ApplicationPacketAnswerSchema),
12889
- missingFieldIds: z42.array(z42.string()),
13237
+ var ApplicationPacketSchema = z43.object({
13238
+ id: z43.string(),
13239
+ applicationId: z43.string(),
13240
+ title: z43.string(),
13241
+ status: z43.enum(["draft", "broker_ready", "submitted"]),
13242
+ answers: z43.array(ApplicationPacketAnswerSchema),
13243
+ missingFieldIds: z43.array(z43.string()),
12890
13244
  qualityReport: ApplicationQualityReportSchema,
12891
- submissionNotes: z42.string().optional(),
12892
- createdAt: z42.number()
13245
+ submissionNotes: z43.string().optional(),
13246
+ createdAt: z43.number()
12893
13247
  });
12894
- var ApplicationStateSchema = z42.object({
12895
- id: z42.string(),
12896
- pdfBase64: z42.string().optional().describe("Original PDF, omitted after extraction"),
12897
- templateId: z42.string().optional(),
12898
- templateVersion: z42.string().optional(),
13248
+ var ApplicationStateSchema = z43.object({
13249
+ id: z43.string(),
13250
+ pdfBase64: z43.string().optional().describe("Original PDF, omitted after extraction"),
13251
+ templateId: z43.string().optional(),
13252
+ templateVersion: z43.string().optional(),
12899
13253
  templateSnapshot: ApplicationTemplateSchema.optional(),
12900
- title: z42.string().optional(),
12901
- applicationType: z42.string().nullable().optional(),
13254
+ title: z43.string().optional(),
13255
+ applicationType: z43.string().nullable().optional(),
12902
13256
  questionGraph: ApplicationQuestionGraphSchema.optional(),
12903
- fields: z42.array(ApplicationFieldSchema),
12904
- batches: z42.array(z42.array(z42.string())).optional(),
12905
- currentBatchIndex: z42.number().default(0),
12906
- contextProposals: z42.array(ApplicationContextProposalSchema).optional(),
13257
+ fields: z43.array(ApplicationFieldSchema),
13258
+ batches: z43.array(z43.array(z43.string())).optional(),
13259
+ currentBatchIndex: z43.number().default(0),
13260
+ contextProposals: z43.array(ApplicationContextProposalSchema).optional(),
12907
13261
  packet: ApplicationPacketSchema.optional(),
12908
13262
  qualityReport: ApplicationQualityReportSchema.optional(),
12909
- status: z42.enum([
13263
+ status: z43.enum([
12910
13264
  "classifying",
12911
13265
  "extracting",
12912
13266
  "auto_filling",
@@ -12920,8 +13274,8 @@ var ApplicationStateSchema = z42.object({
12920
13274
  "cancelled",
12921
13275
  "complete"
12922
13276
  ]),
12923
- createdAt: z42.number(),
12924
- updatedAt: z42.number()
13277
+ createdAt: z43.number(),
13278
+ updatedAt: z43.number()
12925
13279
  });
12926
13280
 
12927
13281
  // src/application/agents/classifier.ts
@@ -14655,106 +15009,106 @@ Respond with the final answer, deduplicated citations array, overall confidence
14655
15009
  }
14656
15010
 
14657
15011
  // src/schemas/query.ts
14658
- import { z as z43 } from "zod";
14659
- var QueryIntentSchema = z43.enum([
15012
+ import { z as z44 } from "zod";
15013
+ var QueryIntentSchema = z44.enum([
14660
15014
  "policy_question",
14661
15015
  "coverage_comparison",
14662
15016
  "document_search",
14663
15017
  "claims_inquiry",
14664
15018
  "general_knowledge"
14665
15019
  ]);
14666
- var QueryAttachmentKindSchema = z43.enum(["image", "pdf", "text"]);
14667
- var QueryAttachmentSchema = z43.object({
14668
- id: z43.string().optional().describe("Optional stable attachment ID from the caller"),
15020
+ var QueryAttachmentKindSchema = z44.enum(["image", "pdf", "text"]);
15021
+ var QueryAttachmentSchema = z44.object({
15022
+ id: z44.string().optional().describe("Optional stable attachment ID from the caller"),
14669
15023
  kind: QueryAttachmentKindSchema,
14670
- name: z43.string().optional().describe("Original filename or user-facing label"),
14671
- mimeType: z43.string().optional().describe("MIME type such as image/jpeg or application/pdf"),
14672
- base64: z43.string().optional().describe("Base64-encoded file content for image/pdf attachments"),
14673
- text: z43.string().optional().describe("Plain-text attachment content when available"),
14674
- description: z43.string().optional().describe("Caller-provided description of the attachment")
15024
+ name: z44.string().optional().describe("Original filename or user-facing label"),
15025
+ mimeType: z44.string().optional().describe("MIME type such as image/jpeg or application/pdf"),
15026
+ base64: z44.string().optional().describe("Base64-encoded file content for image/pdf attachments"),
15027
+ text: z44.string().optional().describe("Plain-text attachment content when available"),
15028
+ description: z44.string().optional().describe("Caller-provided description of the attachment")
14675
15029
  });
14676
- var QueryRetrievalModeSchema = z43.enum([
15030
+ var QueryRetrievalModeSchema = z44.enum([
14677
15031
  "graph_only",
14678
15032
  "source_rag",
14679
15033
  "long_context",
14680
15034
  "hybrid"
14681
15035
  ]);
14682
- var SubQuestionSchema = z43.object({
14683
- question: z43.string().describe("Atomic sub-question to retrieve and answer independently"),
15036
+ var SubQuestionSchema = z44.object({
15037
+ question: z44.string().describe("Atomic sub-question to retrieve and answer independently"),
14684
15038
  intent: QueryIntentSchema,
14685
- chunkTypes: z43.array(z43.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
14686
- documentFilters: z43.object({
14687
- type: z43.enum(["policy", "quote"]).optional(),
14688
- carrier: z43.string().optional(),
14689
- insuredName: z43.string().optional(),
14690
- policyNumber: z43.string().optional(),
14691
- quoteNumber: z43.string().optional(),
14692
- policyTypes: z43.array(PolicyTypeSchema).optional().describe("Filter by policy type (e.g. homeowners_ho3, renters_ho4, pet) to avoid mixing up similar policies")
15039
+ chunkTypes: z44.array(z44.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
15040
+ documentFilters: z44.object({
15041
+ type: z44.enum(["policy", "quote"]).optional(),
15042
+ carrier: z44.string().optional(),
15043
+ insuredName: z44.string().optional(),
15044
+ policyNumber: z44.string().optional(),
15045
+ quoteNumber: z44.string().optional(),
15046
+ policyTypes: z44.array(PolicyTypeSchema).optional().describe("Filter by policy type (e.g. homeowners_ho3, renters_ho4, pet) to avoid mixing up similar policies")
14693
15047
  }).optional().describe("Structured filters to narrow document lookup")
14694
15048
  });
14695
- var QueryClassifyResultSchema = z43.object({
15049
+ var QueryClassifyResultSchema = z44.object({
14696
15050
  intent: QueryIntentSchema,
14697
- subQuestions: z43.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
14698
- requiresDocumentLookup: z43.boolean().describe("Whether structured document lookup is needed"),
14699
- requiresChunkSearch: z43.boolean().describe("Whether semantic chunk search is needed"),
14700
- requiresConversationHistory: z43.boolean().describe("Whether conversation history is relevant"),
15051
+ subQuestions: z44.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
15052
+ requiresDocumentLookup: z44.boolean().describe("Whether structured document lookup is needed"),
15053
+ requiresChunkSearch: z44.boolean().describe("Whether semantic chunk search is needed"),
15054
+ requiresConversationHistory: z44.boolean().describe("Whether conversation history is relevant"),
14701
15055
  retrievalMode: QueryRetrievalModeSchema.optional().describe("Preferred retrieval strategy for the query when source-span retrieval is available")
14702
15056
  });
14703
- var EvidenceItemSchema = z43.object({
14704
- source: z43.enum(["chunk", "document", "conversation", "attachment", "source_span", "source_node"]),
14705
- chunkId: z43.string().optional(),
14706
- sourceNodeId: z43.string().optional(),
14707
- sourceSpanId: z43.string().optional(),
14708
- documentId: z43.string().optional(),
14709
- turnId: z43.string().optional(),
14710
- attachmentId: z43.string().optional(),
14711
- text: z43.string().describe("Text excerpt from the source"),
14712
- relevance: z43.number().min(0).max(1),
15057
+ var EvidenceItemSchema = z44.object({
15058
+ source: z44.enum(["chunk", "document", "conversation", "attachment", "source_span", "source_node"]),
15059
+ chunkId: z44.string().optional(),
15060
+ sourceNodeId: z44.string().optional(),
15061
+ sourceSpanId: z44.string().optional(),
15062
+ documentId: z44.string().optional(),
15063
+ turnId: z44.string().optional(),
15064
+ attachmentId: z44.string().optional(),
15065
+ text: z44.string().describe("Text excerpt from the source"),
15066
+ relevance: z44.number().min(0).max(1),
14713
15067
  retrievalMode: QueryRetrievalModeSchema.optional(),
14714
15068
  sourceLocation: SourceSpanLocationSchema.optional(),
14715
- metadata: z43.array(z43.object({ key: z43.string(), value: z43.string() })).optional()
15069
+ metadata: z44.array(z44.object({ key: z44.string(), value: z44.string() })).optional()
14716
15070
  });
14717
- var AttachmentInterpretationSchema = z43.object({
14718
- summary: z43.string().describe("Concise summary of what the attachment shows or contains"),
14719
- extractedFacts: z43.array(z43.string()).describe("Specific observable or document facts grounded in the attachment"),
14720
- recommendedFocus: z43.array(z43.string()).describe("Important details to incorporate when answering follow-up questions"),
14721
- confidence: z43.number().min(0).max(1)
15071
+ var AttachmentInterpretationSchema = z44.object({
15072
+ summary: z44.string().describe("Concise summary of what the attachment shows or contains"),
15073
+ extractedFacts: z44.array(z44.string()).describe("Specific observable or document facts grounded in the attachment"),
15074
+ recommendedFocus: z44.array(z44.string()).describe("Important details to incorporate when answering follow-up questions"),
15075
+ confidence: z44.number().min(0).max(1)
14722
15076
  });
14723
- var RetrievalResultSchema = z43.object({
14724
- subQuestion: z43.string(),
14725
- evidence: z43.array(EvidenceItemSchema)
15077
+ var RetrievalResultSchema = z44.object({
15078
+ subQuestion: z44.string(),
15079
+ evidence: z44.array(EvidenceItemSchema)
14726
15080
  });
14727
- var CitationSchema = z43.object({
14728
- index: z43.number().describe("Citation number [1], [2], etc."),
14729
- chunkId: z43.string().optional().describe("Source chunk ID, e.g. doc-123:coverage:2"),
14730
- sourceNodeId: z43.string().optional().describe("Source tree node ID when available"),
14731
- sourceSpanId: z43.string().optional().describe("Precise source span ID when available"),
14732
- documentId: z43.string(),
14733
- documentType: z43.enum(["policy", "quote"]).optional(),
14734
- field: z43.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
14735
- quote: z43.string().describe("Exact text from source that supports the claim"),
14736
- relevance: z43.number().min(0).max(1),
15081
+ var CitationSchema = z44.object({
15082
+ index: z44.number().describe("Citation number [1], [2], etc."),
15083
+ chunkId: z44.string().optional().describe("Source chunk ID, e.g. doc-123:coverage:2"),
15084
+ sourceNodeId: z44.string().optional().describe("Source tree node ID when available"),
15085
+ sourceSpanId: z44.string().optional().describe("Precise source span ID when available"),
15086
+ documentId: z44.string(),
15087
+ documentType: z44.enum(["policy", "quote"]).optional(),
15088
+ field: z44.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
15089
+ quote: z44.string().describe("Exact text from source that supports the claim"),
15090
+ relevance: z44.number().min(0).max(1),
14737
15091
  retrievalMode: QueryRetrievalModeSchema.optional(),
14738
15092
  sourceLocation: SourceSpanLocationSchema.optional()
14739
15093
  });
14740
- var SubAnswerSchema = z43.object({
14741
- subQuestion: z43.string(),
14742
- answer: z43.string(),
14743
- citations: z43.array(CitationSchema),
14744
- confidence: z43.number().min(0).max(1),
14745
- needsMoreContext: z43.boolean().describe("True if evidence was insufficient to answer fully")
15094
+ var SubAnswerSchema = z44.object({
15095
+ subQuestion: z44.string(),
15096
+ answer: z44.string(),
15097
+ citations: z44.array(CitationSchema),
15098
+ confidence: z44.number().min(0).max(1),
15099
+ needsMoreContext: z44.boolean().describe("True if evidence was insufficient to answer fully")
14746
15100
  });
14747
- var VerifyResultSchema = z43.object({
14748
- approved: z43.boolean().describe("Whether all sub-answers are adequately grounded"),
14749
- issues: z43.array(z43.string()).describe("Specific grounding or consistency issues found"),
14750
- retrySubQuestions: z43.array(z43.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
15101
+ var VerifyResultSchema = z44.object({
15102
+ approved: z44.boolean().describe("Whether all sub-answers are adequately grounded"),
15103
+ issues: z44.array(z44.string()).describe("Specific grounding or consistency issues found"),
15104
+ retrySubQuestions: z44.array(z44.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
14751
15105
  });
14752
- var QueryResultSchema = z43.object({
14753
- answer: z43.string(),
14754
- citations: z43.array(CitationSchema),
15106
+ var QueryResultSchema = z44.object({
15107
+ answer: z44.string(),
15108
+ citations: z44.array(CitationSchema),
14755
15109
  intent: QueryIntentSchema,
14756
- confidence: z43.number().min(0).max(1),
14757
- followUp: z43.string().optional().describe("Suggested follow-up question if applicable")
15110
+ confidence: z44.number().min(0).max(1),
15111
+ followUp: z44.string().optional().describe("Suggested follow-up question if applicable")
14758
15112
  });
14759
15113
 
14760
15114
  // src/query/retriever.ts
@@ -15821,7 +16175,7 @@ ${sa.answer}`).join("\n\n"),
15821
16175
  }
15822
16176
 
15823
16177
  // src/pce/index.ts
15824
- import { z as z44 } from "zod";
16178
+ import { z as z45 } from "zod";
15825
16179
 
15826
16180
  // src/prompts/pce/index.ts
15827
16181
  function buildPceNormalizePrompt(input) {
@@ -15855,11 +16209,11 @@ ${input.openQuestions.map((question) => `- ${question.id}${question.fieldPath ?
15855
16209
  }
15856
16210
 
15857
16211
  // src/pce/index.ts
15858
- var ReplyAnswersSchema = z44.object({
15859
- answers: z44.array(z44.object({
15860
- questionId: z44.string().optional(),
15861
- fieldPath: z44.string().optional(),
15862
- answer: z44.string()
16212
+ var ReplyAnswersSchema = z45.object({
16213
+ answers: z45.array(z45.object({
16214
+ questionId: z45.string().optional(),
16215
+ fieldPath: z45.string().optional(),
16216
+ answer: z45.string()
15863
16217
  }))
15864
16218
  });
15865
16219
  function createPceAgent(config = {}) {