@claritylabs/cl-sdk 3.1.2 → 3.1.4

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
@@ -546,6 +546,13 @@ var PET_SPECIES = PetSpeciesSchema.options;
546
546
 
547
547
  // src/schemas/shared.ts
548
548
  import { z as z3 } from "zod";
549
+ var SourceProvenanceSchema = z3.object({
550
+ sourceSpanIds: z3.array(z3.string().min(1)).min(1),
551
+ documentNodeId: z3.string().optional(),
552
+ sourceTextHash: z3.string().optional(),
553
+ pageStart: z3.number().int().positive().optional(),
554
+ pageEnd: z3.number().int().positive().optional()
555
+ });
549
556
  var AddressSchema = z3.object({
550
557
  street1: z3.string(),
551
558
  street2: z3.string().optional(),
@@ -554,6 +561,7 @@ var AddressSchema = z3.object({
554
561
  zip: z3.string(),
555
562
  country: z3.string().optional()
556
563
  });
564
+ var SourceBackedAddressSchema = AddressSchema.merge(SourceProvenanceSchema);
557
565
  var ContactSchema = z3.object({
558
566
  name: z3.string().optional(),
559
567
  title: z3.string().optional(),
@@ -563,7 +571,7 @@ var ContactSchema = z3.object({
563
571
  email: z3.string().optional(),
564
572
  address: AddressSchema.optional(),
565
573
  hours: z3.string().optional()
566
- });
574
+ }).merge(SourceProvenanceSchema);
567
575
  var FormReferenceSchema = z3.object({
568
576
  formNumber: z3.string(),
569
577
  editionDate: z3.string().optional(),
@@ -610,7 +618,7 @@ var NamedInsuredSchema = z3.object({
610
618
  name: z3.string(),
611
619
  relationship: z3.string().optional(),
612
620
  address: AddressSchema.optional()
613
- });
621
+ }).merge(SourceProvenanceSchema);
614
622
 
615
623
  // src/schemas/coverage.ts
616
624
  import { z as z4 } from "zod";
@@ -682,7 +690,7 @@ var EndorsementPartySchema = z5.object({
682
690
  address: AddressSchema.optional(),
683
691
  relationship: z5.string().optional(),
684
692
  scope: z5.string().optional()
685
- });
693
+ }).merge(SourceProvenanceSchema);
686
694
  var EndorsementSchema = z5.object({
687
695
  formNumber: z5.string(),
688
696
  editionDate: z5.string().optional(),
@@ -749,7 +757,7 @@ var InsurerInfoSchema = z8.object({
749
757
  amBestNumber: z8.string().optional(),
750
758
  admittedStatus: AdmittedStatusSchema.optional(),
751
759
  stateOfDomicile: z8.string().optional()
752
- });
760
+ }).merge(SourceProvenanceSchema);
753
761
  var ProducerInfoSchema = z8.object({
754
762
  agencyName: z8.string(),
755
763
  contactName: z8.string().optional(),
@@ -757,7 +765,7 @@ var ProducerInfoSchema = z8.object({
757
765
  phone: z8.string().optional(),
758
766
  email: z8.string().optional(),
759
767
  address: AddressSchema.optional()
760
- });
768
+ }).merge(SourceProvenanceSchema);
761
769
 
762
770
  // src/schemas/financial.ts
763
771
  import { z as z9 } from "zod";
@@ -1468,7 +1476,7 @@ var BaseDocumentFields = {
1468
1476
  isRenewal: z16.boolean().optional(),
1469
1477
  isPackage: z16.boolean().optional(),
1470
1478
  insuredDba: z16.string().optional(),
1471
- insuredAddress: AddressSchema.optional(),
1479
+ insuredAddress: SourceBackedAddressSchema.optional(),
1472
1480
  insuredEntityType: EntityTypeSchema.optional(),
1473
1481
  additionalNamedInsureds: z16.array(NamedInsuredSchema).optional(),
1474
1482
  insuredSicCode: z16.string().optional(),
@@ -3381,15 +3389,6 @@ function sourceIds(nodes) {
3381
3389
  sourceSpanIds: [...new Set(nodes.flatMap((node) => node.sourceSpanIds))]
3382
3390
  };
3383
3391
  }
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
3392
  function termFromCell(params) {
3394
3393
  const value = cleanCoverageTermValue(params.value);
3395
3394
  if (!value) return void 0;
@@ -3539,8 +3538,7 @@ function coverageFromEndorsement(endorsement, children) {
3539
3538
  const terms = uniqueTerms(rows.flatMap(
3540
3539
  (row) => termsFromRow(row, children).map((term) => {
3541
3540
  const appliesTo = nameFromRow(row, children);
3542
- const labelled = relabelGenericTerm(term, appliesTo);
3543
- return appliesTo && labelled.label !== appliesTo ? { ...labelled, appliesTo } : labelled;
3541
+ return appliesTo && term.label !== appliesTo ? { ...term, appliesTo } : term;
3544
3542
  })
3545
3543
  ));
3546
3544
  if (terms.length === 0) return void 0;
@@ -4659,6 +4657,17 @@ function getCoveredReasons(memory) {
4659
4657
  }
4660
4658
 
4661
4659
  // src/extraction/promote.ts
4660
+ function sourceProvenance(raw) {
4661
+ const sourceSpanIds = Array.isArray(raw.sourceSpanIds) ? raw.sourceSpanIds.filter((id) => typeof id === "string" && id.trim().length > 0) : [];
4662
+ if (sourceSpanIds.length === 0) return void 0;
4663
+ return {
4664
+ sourceSpanIds,
4665
+ ...typeof raw.documentNodeId === "string" ? { documentNodeId: raw.documentNodeId } : {},
4666
+ ...typeof raw.sourceTextHash === "string" ? { sourceTextHash: raw.sourceTextHash } : {},
4667
+ ...typeof raw.pageStart === "number" ? { pageStart: raw.pageStart } : {},
4668
+ ...typeof raw.pageEnd === "number" ? { pageEnd: raw.pageEnd } : {}
4669
+ };
4670
+ }
4662
4671
  function stringValue(value) {
4663
4672
  return typeof value === "string" && value.trim() ? value : void 0;
4664
4673
  }
@@ -4679,36 +4688,38 @@ function promoteRawFields(raw, mappings) {
4679
4688
  }
4680
4689
  function promoteCarrierFields(doc) {
4681
4690
  const raw = doc;
4691
+ const provenance = sourceProvenance(raw);
4682
4692
  promoteRawFields(raw, [
4683
4693
  { from: "naicNumber", to: "carrierNaicNumber" },
4684
4694
  { from: "amBestRating", to: "carrierAmBestRating" },
4685
4695
  { from: "admittedStatus", to: "carrierAdmittedStatus" }
4686
4696
  ]);
4687
- if (!raw.insurer && raw.carrierLegalName) {
4697
+ if (!raw.insurer && raw.carrierLegalName && provenance) {
4688
4698
  raw.insurer = {
4689
4699
  legalName: raw.carrierLegalName,
4690
4700
  ...raw.carrierNaicNumber ? { naicNumber: raw.carrierNaicNumber } : {},
4691
4701
  ...raw.carrierAmBestRating ? { amBestRating: raw.carrierAmBestRating } : {},
4692
- ...raw.carrierAdmittedStatus ? { admittedStatus: raw.carrierAdmittedStatus } : {}
4702
+ ...raw.carrierAdmittedStatus ? { admittedStatus: raw.carrierAdmittedStatus } : {},
4703
+ ...provenance
4693
4704
  };
4694
4705
  }
4695
4706
  }
4696
4707
  function promoteBroker(doc) {
4697
4708
  const raw = doc;
4709
+ const provenance = sourceProvenance(raw);
4698
4710
  const brokerAgency = findRawString(raw, ["brokerAgency"]);
4699
4711
  const brokerContact = findRawString(raw, ["brokerContactName"]);
4700
4712
  const brokerLicense = findRawString(raw, ["brokerLicenseNumber"]);
4701
4713
  const brokerPhone = findRawString(raw, ["brokerPhone"]);
4702
4714
  const brokerEmail = findRawString(raw, ["brokerEmail"]);
4703
- const brokerAddress = findRawString(raw, ["brokerAddress"]);
4704
- if (!raw.producer && brokerAgency) {
4715
+ if (!raw.producer && brokerAgency && provenance) {
4705
4716
  raw.producer = {
4706
4717
  agencyName: brokerAgency,
4707
4718
  ...brokerContact ? { contactName: brokerContact } : {},
4708
4719
  ...brokerLicense ? { licenseNumber: brokerLicense } : {},
4709
4720
  ...brokerPhone ? { phone: brokerPhone } : {},
4710
4721
  ...brokerEmail ? { email: brokerEmail } : {},
4711
- ...brokerAddress ? { address: { street1: brokerAddress } } : {}
4722
+ ...provenance
4712
4723
  };
4713
4724
  }
4714
4725
  }
@@ -7662,16 +7673,19 @@ Return JSON only.`;
7662
7673
 
7663
7674
  // src/prompts/extractors/named-insured.ts
7664
7675
  import { z as z27 } from "zod";
7665
- var AddressSchema2 = z27.object({
7666
- street1: z27.string(),
7667
- city: z27.string(),
7668
- state: z27.string(),
7669
- zip: z27.string()
7670
- });
7676
+ var AdditionalNamedInsuredSchema = z27.object({
7677
+ name: z27.string(),
7678
+ relationship: z27.string().optional().describe("e.g. subsidiary, affiliate"),
7679
+ address: SourceBackedAddressSchema.optional()
7680
+ }).merge(SourceProvenanceSchema);
7681
+ var ScheduledPartySchema = z27.object({
7682
+ name: z27.string(),
7683
+ address: SourceBackedAddressSchema.optional()
7684
+ }).merge(SourceProvenanceSchema);
7671
7685
  var NamedInsuredSchema2 = z27.object({
7672
7686
  insuredName: z27.string().describe("Name of primary named insured"),
7673
7687
  insuredDba: z27.string().optional().describe("Doing-business-as name"),
7674
- insuredAddress: AddressSchema2.optional().describe("Primary insured mailing address"),
7688
+ insuredAddress: SourceBackedAddressSchema.optional().describe("Primary insured mailing address"),
7675
7689
  insuredEntityType: z27.enum([
7676
7690
  "corporation",
7677
7691
  "llc",
@@ -7688,25 +7702,9 @@ var NamedInsuredSchema2 = z27.object({
7688
7702
  insuredFein: z27.string().optional().describe("Federal Employer Identification Number"),
7689
7703
  insuredSicCode: z27.string().optional().describe("SIC code"),
7690
7704
  insuredNaicsCode: z27.string().optional().describe("NAICS code"),
7691
- additionalNamedInsureds: z27.array(
7692
- z27.object({
7693
- name: z27.string(),
7694
- relationship: z27.string().optional().describe("e.g. subsidiary, affiliate"),
7695
- address: AddressSchema2.optional()
7696
- })
7697
- ).optional().describe("Additional named insureds listed on the policy"),
7698
- lossPayees: z27.array(
7699
- z27.object({
7700
- name: z27.string(),
7701
- address: AddressSchema2.optional()
7702
- })
7703
- ).optional().describe("Loss payees listed on the policy"),
7704
- mortgageHolders: z27.array(
7705
- z27.object({
7706
- name: z27.string(),
7707
- address: AddressSchema2.optional()
7708
- })
7709
- ).optional().describe("Mortgage holders / lienholders listed on the policy")
7705
+ additionalNamedInsureds: z27.array(AdditionalNamedInsuredSchema).optional().describe("Additional named insureds listed on the policy"),
7706
+ lossPayees: z27.array(ScheduledPartySchema).optional().describe("Loss payees listed on the policy"),
7707
+ mortgageHolders: z27.array(ScheduledPartySchema).optional().describe("Mortgage holders / lienholders listed on the policy")
7710
7708
  });
7711
7709
  function buildNamedInsuredPrompt() {
7712
7710
  return `You are an expert insurance document analyst. Extract all named insured information from this document.
@@ -7723,6 +7721,7 @@ Focus on:
7723
7721
  Look on the declarations page, named insured schedule, loss payee schedule, mortgagee schedule, and any endorsements that add or modify named insureds, loss payees, or mortgage holders.
7724
7722
 
7725
7723
  Critical rules:
7724
+ - Every insuredAddress, additionalNamedInsureds row, lossPayees row, and mortgageHolders row must include sourceSpanIds from the source evidence. Omit the row if source spans are unavailable.
7726
7725
  - Prefer declaration-table labels such as "Named Insured", "Named Insured and Address", "Applicant", or "Insured" over contact blocks, notice contacts, authorized officers, licensing statements, signatures, and corporate-authority wording.
7727
7726
  - Do not use an authorized officer, broker, producer, contact person, officer title, email address owner, or licensing/entity-status statement as the primary insured unless that exact person/entity is explicitly labeled as the named insured.
7728
7727
  - If a row combines the insured name with a mailing address, put the legal name in insuredName and the mailing address in insuredAddress.
@@ -8186,13 +8185,6 @@ Return JSON only.`;
8186
8185
 
8187
8186
  // src/prompts/extractors/supplementary.ts
8188
8187
  import { z as z36 } from "zod";
8189
- var ContactSchema2 = z36.object({
8190
- name: z36.string().optional().describe("Organization or person name"),
8191
- phone: z36.string().optional().describe("Phone number"),
8192
- email: z36.string().optional().describe("Email address"),
8193
- address: z36.string().optional().describe("Mailing address"),
8194
- type: z36.string().optional().describe("Contact type, e.g. 'State Department of Insurance'")
8195
- });
8196
8188
  var AuxiliaryFactSchema2 = z36.object({
8197
8189
  key: z36.string().describe("Normalized machine-readable fact key, e.g. 'policyholder_age' or 'insured_name'"),
8198
8190
  value: z36.string().describe("Concrete extracted fact value"),
@@ -8200,9 +8192,9 @@ var AuxiliaryFactSchema2 = z36.object({
8200
8192
  context: z36.string().optional().describe("Short disambiguating context, such as 'Driver Schedule' or 'Named Insured'")
8201
8193
  });
8202
8194
  var SupplementarySchema = z36.object({
8203
- regulatoryContacts: z36.array(ContactSchema2).optional().describe("Regulatory body contacts (state department of insurance, ombudsman)"),
8204
- claimsContacts: z36.array(ContactSchema2).optional().describe("Claims reporting contacts and instructions"),
8205
- thirdPartyAdministrators: z36.array(ContactSchema2).optional().describe("Third-party administrators for claims handling"),
8195
+ regulatoryContacts: z36.array(ContactSchema).optional().describe("Regulatory body contacts (state department of insurance, ombudsman)"),
8196
+ claimsContacts: z36.array(ContactSchema).optional().describe("Claims reporting contacts and instructions"),
8197
+ thirdPartyAdministrators: z36.array(ContactSchema).optional().describe("Third-party administrators for claims handling"),
8206
8198
  cancellationNoticeDays: z36.number().optional().describe("Required notice period for cancellation in days"),
8207
8199
  nonrenewalNoticeDays: z36.number().optional().describe("Required notice period for nonrenewal in days"),
8208
8200
  auxiliaryFacts: z36.array(AuxiliaryFactSchema2).optional().describe("Additional retrieval-only facts that do not fit the strict primary schema")
@@ -8217,7 +8209,7 @@ ${alreadyExtractedSummary}
8217
8209
  return `You are an expert insurance document analyst. Extract supplementary, retrieval-only information from this document that is NOT already captured in the structured extraction results.
8218
8210
  ${exclusionBlock}
8219
8211
  Focus on:
8220
- - Regulatory contacts: state department of insurance, regulatory bodies, ombudsman offices \u2014 with phone, email, address
8212
+ - Regulatory contacts: state department of insurance, regulatory bodies, ombudsman offices \u2014 with phone, email, structured address
8221
8213
  - Claims contacts: how to report claims, claims department contact info, hours of operation
8222
8214
  - Third-party administrators (TPAs) for claims handling
8223
8215
  - Cancellation notice period in days
@@ -8228,6 +8220,8 @@ Focus on:
8228
8220
 
8229
8221
  Look for regulatory notices, complaint contact sections, claims reporting instructions, and cancellation/nonrenewal provisions throughout the document.
8230
8222
 
8223
+ Every regulatoryContacts, claimsContacts, and thirdPartyAdministrators row must include sourceSpanIds from the source evidence. Omit contacts when source spans are unavailable.
8224
+
8231
8225
  For auxiliaryFacts:
8232
8226
  - ONLY capture facts that are NOT already present in the structured extraction results above.
8233
8227
  - Do not duplicate information that has already been extracted \u2014 no policy numbers, insured names, addresses, coverage limits, deductibles, or any other field that appears in the already-extracted data.
@@ -9743,7 +9737,343 @@ function groundExtractionMemoryWithSourceSpans(memory, sourceSpans) {
9743
9737
  }
9744
9738
 
9745
9739
  // src/extraction/source-tree-extractor.ts
9740
+ import { z as z42 } from "zod";
9741
+
9742
+ // src/extraction/operational-profile-cleanup.ts
9746
9743
  import { z as z41 } from "zod";
9744
+ var OPERATIONAL_COVERAGE_TERM_KINDS2 = [
9745
+ "each_claim_limit",
9746
+ "each_occurrence_limit",
9747
+ "each_loss_limit",
9748
+ "aggregate_limit",
9749
+ "sublimit",
9750
+ "retention",
9751
+ "deductible",
9752
+ "retroactive_date",
9753
+ "premium",
9754
+ "other"
9755
+ ];
9756
+ var OperationalCoverageTermKindSchema = z41.enum(OPERATIONAL_COVERAGE_TERM_KINDS2);
9757
+ var OperationalProfileCleanupSchema = z41.object({
9758
+ coverageDecisions: z41.array(z41.object({
9759
+ coverageIndex: z41.number().int().nonnegative(),
9760
+ action: z41.enum(["keep", "drop", "update"]),
9761
+ reason: z41.string().optional(),
9762
+ name: z41.string().optional(),
9763
+ limit: z41.string().nullable().optional(),
9764
+ deductible: z41.string().nullable().optional(),
9765
+ premium: z41.string().nullable().optional(),
9766
+ retroactiveDate: z41.string().nullable().optional(),
9767
+ coverageOrigin: z41.enum(["core", "endorsement"]).optional(),
9768
+ sourceNodeIds: z41.array(z41.string()).optional(),
9769
+ sourceSpanIds: z41.array(z41.string()).optional(),
9770
+ termDecisions: z41.array(z41.object({
9771
+ termIndex: z41.number().int().nonnegative(),
9772
+ action: z41.enum(["keep", "drop", "update"]),
9773
+ reason: z41.string().optional(),
9774
+ kind: OperationalCoverageTermKindSchema.optional(),
9775
+ label: z41.string().optional(),
9776
+ value: z41.string().optional(),
9777
+ amount: z41.number().nullable().optional(),
9778
+ appliesTo: z41.string().nullable().optional(),
9779
+ sourceNodeIds: z41.array(z41.string()).optional(),
9780
+ sourceSpanIds: z41.array(z41.string()).optional()
9781
+ })).optional()
9782
+ })).default([]),
9783
+ warnings: z41.array(z41.string()).default([])
9784
+ });
9785
+ function compactNode(node, maxText = 700) {
9786
+ return {
9787
+ id: node.id,
9788
+ kind: node.kind,
9789
+ title: node.title,
9790
+ path: node.path,
9791
+ pageStart: node.pageStart,
9792
+ pageEnd: node.pageEnd,
9793
+ sourceSpanIds: node.sourceSpanIds.slice(0, 8),
9794
+ text: (node.textExcerpt ?? node.description).slice(0, maxText)
9795
+ };
9796
+ }
9797
+ function compactCoverageForCleanup(coverage, coverageIndex) {
9798
+ return {
9799
+ coverageIndex,
9800
+ name: coverage.name,
9801
+ limit: coverage.limit,
9802
+ deductible: coverage.deductible,
9803
+ premium: coverage.premium,
9804
+ retroactiveDate: coverage.retroactiveDate,
9805
+ coverageOrigin: coverage.coverageOrigin,
9806
+ sourceNodeIds: coverage.sourceNodeIds,
9807
+ sourceSpanIds: coverage.sourceSpanIds,
9808
+ terms: coverage.limits.map((term, termIndex) => ({
9809
+ termIndex,
9810
+ kind: term.kind,
9811
+ label: term.label,
9812
+ value: term.value,
9813
+ amount: term.amount,
9814
+ appliesTo: term.appliesTo,
9815
+ sourceNodeIds: term.sourceNodeIds,
9816
+ sourceSpanIds: term.sourceSpanIds
9817
+ }))
9818
+ };
9819
+ }
9820
+ function buildOperationalProfileCleanupPrompt(sourceTree, profile) {
9821
+ const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 320).map((node) => compactNode(node, node.kind === "page" ? 900 : 700));
9822
+ const candidate = {
9823
+ documentType: profile.documentType,
9824
+ policyTypes: profile.policyTypes,
9825
+ coverageTypes: profile.coverageTypes,
9826
+ coverages: profile.coverages.map(compactCoverageForCleanup)
9827
+ };
9828
+ return `Review and clean a source-backed operational profile projection for an insurance policy.
9829
+
9830
+ Task:
9831
+ - Inspect the candidate coverage projection against the source nodes.
9832
+ - Return cleanup decisions only for coverage rows or terms that are malformed, unsupported, mismatched, or misleading.
9833
+ - If the projection is already acceptable, return an empty coverageDecisions array.
9834
+
9835
+ Projection defects to look for:
9836
+ - Generic labels such as "Column 3" that should be renamed from nearby row/header evidence.
9837
+ - 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.
9838
+ - Dangling continuation punctuation such as a trailing "/" copied into values.
9839
+ - Item references such as "shown in Item 7" or bare item numbers treated as money amounts.
9840
+ - Policy wording, exclusions, or unsupported prose copied into operational limit/deductible fields.
9841
+ - Header/value splits where "Limit of Liability", "Deductible", "Retroactive Date", "Aggregate", "Each Claim", or similar terms are attached to the wrong coverage row.
9842
+ - Repeated schedule headings projected as separate coverages when they only introduce the next coverage group.
9843
+
9844
+ Rules:
9845
+ - Use internal reasoning, but return JSON decisions only.
9846
+ - Do not invent policy facts. Keep, drop, or update only existing coverageIndex and termIndex entries.
9847
+ - Use sourceNodeIds and sourceSpanIds only from the provided source nodes or from the existing candidate entry.
9848
+ - Prefer dropping a malformed fact over speculative rewriting.
9849
+ - Keep a coverage when it is a real operational coverage/benefit even if only one term needs cleanup.
9850
+ - When changing a term's semantic meaning, set kind to the corrected normalized term kind.
9851
+ - Do not add new coverage rows or new terms; this pass cleans the existing projection.
9852
+ - Keep reasons concise and factual.
9853
+
9854
+ Candidate projection:
9855
+ ${JSON.stringify(candidate, null, 2)}
9856
+
9857
+ Source nodes:
9858
+ ${JSON.stringify(nodes, null, 2)}
9859
+
9860
+ Return JSON with coverageDecisions and warnings only.`;
9861
+ }
9862
+ function hasOwn(object, key) {
9863
+ return Object.prototype.hasOwnProperty.call(object, key);
9864
+ }
9865
+ function uniqueStrings(values) {
9866
+ return [...new Set(values.filter((value) => value.length > 0))];
9867
+ }
9868
+ function cleanProfileValue(value) {
9869
+ if (typeof value !== "string") return void 0;
9870
+ const cleaned = value.replace(/\s+\/\s*$/, "").replace(/\s+/g, " ").replace(/^[\s:;#-]+|[\s;,.]+$/g, "").trim();
9871
+ return cleaned || void 0;
9872
+ }
9873
+ function validIds(ids, valid) {
9874
+ return uniqueStrings((ids ?? []).filter((id) => valid.has(id)));
9875
+ }
9876
+ function cleanupIds(ids, valid, fallback) {
9877
+ if (ids === void 0) return validIds(fallback, valid);
9878
+ const next = validIds(ids, valid);
9879
+ return next.length > 0 ? next : validIds(fallback, valid);
9880
+ }
9881
+ function amountFromOperationalValue(value) {
9882
+ const match = value.match(/\$\s*([0-9][0-9,]*(?:\.\d+)?)/) ?? value.match(/\b([0-9][0-9,]*(?:\.\d+)?)\s*%/);
9883
+ if (!match) return void 0;
9884
+ const amount = Number(match[1].replace(/,/g, ""));
9885
+ return Number.isFinite(amount) ? amount : void 0;
9886
+ }
9887
+ function normalizedTermText(term) {
9888
+ return `${term.kind} ${term.label} ${term.value}`.toLowerCase();
9889
+ }
9890
+ function isLimitTerm(term) {
9891
+ 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));
9892
+ }
9893
+ function isDeductibleTerm(term) {
9894
+ return term.kind === "deductible" || term.kind === "retention" || /\b(deductible|retention|sir)\b/i.test(normalizedTermText(term));
9895
+ }
9896
+ function isPremiumTerm(term) {
9897
+ return term.kind === "premium" || /\bpremium\b/i.test(normalizedTermText(term));
9898
+ }
9899
+ function isRetroactiveDateTerm(term) {
9900
+ return term.kind === "retroactive_date" || /\bretroactive\b/i.test(normalizedTermText(term));
9901
+ }
9902
+ function primaryLimitFromTerms(terms) {
9903
+ return terms.find(isLimitTerm)?.value;
9904
+ }
9905
+ function deductibleFromTerms(terms) {
9906
+ return terms.find(isDeductibleTerm)?.value;
9907
+ }
9908
+ function premiumFromTerms(terms) {
9909
+ return terms.find(isPremiumTerm)?.value;
9910
+ }
9911
+ function retroactiveDateFromTerms(terms) {
9912
+ return terms.find(isRetroactiveDateTerm)?.value;
9913
+ }
9914
+ function termDecisionTouches(coverage, decision, predicate) {
9915
+ const existing = coverage.limits[decision.termIndex];
9916
+ if (existing && predicate(existing)) return true;
9917
+ if (!decision.kind && !decision.label && !decision.value) return false;
9918
+ return predicate({
9919
+ kind: decision.kind ?? existing?.kind ?? "other",
9920
+ label: cleanProfileValue(decision.label) ?? existing?.label ?? "",
9921
+ value: cleanProfileValue(decision.value) ?? existing?.value ?? ""
9922
+ });
9923
+ }
9924
+ function applyTermCleanupDecision(term, decision, validNodeIds, validSpanIds) {
9925
+ if (!decision || decision.action === "keep") return term;
9926
+ if (decision.action === "drop") return void 0;
9927
+ const label = cleanProfileValue(decision.label) ?? term.label;
9928
+ const value = cleanProfileValue(decision.value) ?? term.value;
9929
+ if (!label || !value) return term;
9930
+ const next = {
9931
+ ...term,
9932
+ kind: decision.kind ?? term.kind,
9933
+ label,
9934
+ value,
9935
+ sourceNodeIds: cleanupIds(decision.sourceNodeIds, validNodeIds, term.sourceNodeIds),
9936
+ sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, term.sourceSpanIds)
9937
+ };
9938
+ if (next.sourceNodeIds.length === 0 && next.sourceSpanIds.length === 0) return term;
9939
+ if (hasOwn(decision, "amount")) {
9940
+ if (typeof decision.amount === "number" && Number.isFinite(decision.amount)) next.amount = decision.amount;
9941
+ else delete next.amount;
9942
+ } else if (decision.value || decision.kind) {
9943
+ const amount = next.kind === "retroactive_date" ? void 0 : amountFromOperationalValue(next.value);
9944
+ if (amount === void 0) delete next.amount;
9945
+ else next.amount = amount;
9946
+ }
9947
+ if (hasOwn(decision, "appliesTo")) {
9948
+ const appliesTo = cleanProfileValue(decision.appliesTo);
9949
+ if (appliesTo) next.appliesTo = appliesTo;
9950
+ else delete next.appliesTo;
9951
+ }
9952
+ return next;
9953
+ }
9954
+ function termDecisionsTouch(coverage, decisions, predicate) {
9955
+ return decisions.filter((decision) => decision.action !== "keep").some((decision) => termDecisionTouches(coverage, decision, predicate));
9956
+ }
9957
+ function applyCoverageCleanupDecision(coverage, decision, validNodeIds, validSpanIds) {
9958
+ if (!decision || decision.action === "keep") return coverage;
9959
+ if (decision.action === "drop") return void 0;
9960
+ const next = {
9961
+ ...coverage,
9962
+ limits: [...coverage.limits],
9963
+ sourceNodeIds: cleanupIds(decision.sourceNodeIds, validNodeIds, coverage.sourceNodeIds),
9964
+ sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, coverage.sourceSpanIds)
9965
+ };
9966
+ const name = cleanProfileValue(decision.name);
9967
+ if (name) next.name = name;
9968
+ if (decision.coverageOrigin) next.coverageOrigin = decision.coverageOrigin;
9969
+ if (hasOwn(decision, "limit")) {
9970
+ const value = cleanProfileValue(decision.limit);
9971
+ if (value) next.limit = value;
9972
+ else delete next.limit;
9973
+ }
9974
+ if (hasOwn(decision, "deductible")) {
9975
+ const value = cleanProfileValue(decision.deductible);
9976
+ if (value) next.deductible = value;
9977
+ else delete next.deductible;
9978
+ }
9979
+ if (hasOwn(decision, "premium")) {
9980
+ const value = cleanProfileValue(decision.premium);
9981
+ if (value) next.premium = value;
9982
+ else delete next.premium;
9983
+ }
9984
+ if (hasOwn(decision, "retroactiveDate")) {
9985
+ const value = cleanProfileValue(decision.retroactiveDate);
9986
+ if (value) next.retroactiveDate = value;
9987
+ else delete next.retroactiveDate;
9988
+ }
9989
+ const termDecisions = (decision.termDecisions ?? []).filter((termDecision) => termDecision.termIndex < coverage.limits.length);
9990
+ const termDecisionByIndex = new Map(termDecisions.map((termDecision) => [termDecision.termIndex, termDecision]));
9991
+ next.limits = coverage.limits.map((term, index) => applyTermCleanupDecision(term, termDecisionByIndex.get(index), validNodeIds, validSpanIds)).filter((term) => Boolean(term));
9992
+ if (termDecisions.length > 0) {
9993
+ if (!hasOwn(decision, "limit") && termDecisionsTouch(coverage, termDecisions, isLimitTerm)) {
9994
+ const value = primaryLimitFromTerms(next.limits);
9995
+ if (value) next.limit = value;
9996
+ else delete next.limit;
9997
+ }
9998
+ if (!hasOwn(decision, "deductible") && termDecisionsTouch(coverage, termDecisions, isDeductibleTerm)) {
9999
+ const value = deductibleFromTerms(next.limits);
10000
+ if (value) next.deductible = value;
10001
+ else delete next.deductible;
10002
+ }
10003
+ if (!hasOwn(decision, "premium") && termDecisionsTouch(coverage, termDecisions, isPremiumTerm)) {
10004
+ const value = premiumFromTerms(next.limits);
10005
+ if (value) next.premium = value;
10006
+ else delete next.premium;
10007
+ }
10008
+ if (!hasOwn(decision, "retroactiveDate") && termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm)) {
10009
+ const value = retroactiveDateFromTerms(next.limits);
10010
+ if (value) next.retroactiveDate = value;
10011
+ else delete next.retroactiveDate;
10012
+ }
10013
+ }
10014
+ next.sourceNodeIds = uniqueStrings([
10015
+ ...next.sourceNodeIds,
10016
+ ...next.limits.flatMap((term) => term.sourceNodeIds)
10017
+ ]);
10018
+ next.sourceSpanIds = uniqueStrings([
10019
+ ...next.sourceSpanIds,
10020
+ ...next.limits.flatMap((term) => term.sourceSpanIds)
10021
+ ]);
10022
+ return next.name ? next : coverage;
10023
+ }
10024
+ function sourceIdsFromOperationalProfile(profile) {
10025
+ const backedValues = [
10026
+ profile.policyNumber,
10027
+ profile.namedInsured,
10028
+ profile.insurer,
10029
+ profile.broker,
10030
+ profile.effectiveDate,
10031
+ profile.expirationDate,
10032
+ profile.retroactiveDate,
10033
+ profile.premium
10034
+ ].filter(Boolean);
10035
+ return {
10036
+ sourceNodeIds: uniqueStrings([
10037
+ ...backedValues.flatMap((value) => value?.sourceNodeIds ?? []),
10038
+ ...profile.coverages.flatMap((coverage) => coverage.sourceNodeIds),
10039
+ ...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceNodeIds)),
10040
+ ...profile.parties.flatMap((party) => party.sourceNodeIds),
10041
+ ...profile.endorsementSupport.flatMap((support) => support.sourceNodeIds)
10042
+ ]),
10043
+ sourceSpanIds: uniqueStrings([
10044
+ ...backedValues.flatMap((value) => value?.sourceSpanIds ?? []),
10045
+ ...profile.coverages.flatMap((coverage) => coverage.sourceSpanIds),
10046
+ ...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceSpanIds)),
10047
+ ...profile.parties.flatMap((party) => party.sourceSpanIds),
10048
+ ...profile.endorsementSupport.flatMap((support) => support.sourceSpanIds)
10049
+ ])
10050
+ };
10051
+ }
10052
+ function applyOperationalProfileCleanup(profile, cleanup, validNodeIds, validSpanIds) {
10053
+ const coverageDecisionByIndex = /* @__PURE__ */ new Map();
10054
+ for (const decision of cleanup.coverageDecisions) {
10055
+ if (decision.coverageIndex < profile.coverages.length) coverageDecisionByIndex.set(decision.coverageIndex, decision);
10056
+ }
10057
+ const coverages = profile.coverages.map(
10058
+ (coverage, index) => applyCoverageCleanupDecision(coverage, coverageDecisionByIndex.get(index), validNodeIds, validSpanIds)
10059
+ ).filter((coverage) => Boolean(coverage));
10060
+ const cleanupWarnings = cleanup.warnings.map((warning) => cleanProfileValue(warning)).filter((warning) => Boolean(warning));
10061
+ const nextProfile = {
10062
+ ...profile,
10063
+ coverages,
10064
+ coverageTypes: uniqueStrings(coverages.map((coverage) => coverage.name)),
10065
+ warnings: uniqueStrings([
10066
+ ...profile.warnings,
10067
+ ...cleanupWarnings.map((warning) => `Operational profile cleanup warning: ${warning}`)
10068
+ ])
10069
+ };
10070
+ return PolicyOperationalProfileSchema.parse({
10071
+ ...nextProfile,
10072
+ ...sourceIdsFromOperationalProfile(nextProfile)
10073
+ });
10074
+ }
10075
+
10076
+ // src/extraction/source-tree-extractor.ts
9747
10077
  var ORGANIZABLE_KINDS = [
9748
10078
  "page_group",
9749
10079
  "form",
@@ -9756,10 +10086,10 @@ var ORGANIZATION_TOP_LEVEL_BATCH_SIZE = 80;
9756
10086
  var ORGANIZER_MAX_SOURCE_SPANS = 400;
9757
10087
  var ORGANIZER_MAX_TOP_LEVEL_NODES = 18;
9758
10088
  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([
10089
+ var SourceTreeOrganizationSchema = z42.object({
10090
+ labels: z42.array(z42.object({
10091
+ nodeId: z42.string(),
10092
+ kind: z42.enum([
9763
10093
  "document",
9764
10094
  "page_group",
9765
10095
  "page",
@@ -9773,26 +10103,26 @@ var SourceTreeOrganizationSchema = z41.object({
9773
10103
  "table_cell",
9774
10104
  "text"
9775
10105
  ]).optional(),
9776
- title: z41.string().optional(),
9777
- description: z41.string().optional()
10106
+ title: z42.string().optional(),
10107
+ description: z42.string().optional()
9778
10108
  })),
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)
10109
+ groups: z42.array(z42.object({
10110
+ kind: z42.enum(ORGANIZABLE_KINDS),
10111
+ title: z42.string(),
10112
+ description: z42.string().optional(),
10113
+ childNodeIds: z42.array(z42.string()).min(1)
9784
10114
  }))
9785
10115
  });
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())
10116
+ var SourceBackedValueForPromptSchema = z42.object({
10117
+ value: z42.string(),
10118
+ normalizedValue: z42.string().optional(),
10119
+ confidence: z42.enum(["low", "medium", "high"]).optional(),
10120
+ sourceNodeIds: z42.array(z42.string()),
10121
+ sourceSpanIds: z42.array(z42.string())
9792
10122
  });
9793
- var OperationalProfilePromptSchema = z41.object({
9794
- documentType: z41.enum(["policy", "quote"]).optional(),
9795
- policyTypes: z41.array(z41.string()).optional(),
10123
+ var OperationalProfilePromptSchema = z42.object({
10124
+ documentType: z42.enum(["policy", "quote"]).optional(),
10125
+ policyTypes: z42.array(z42.string()).optional(),
9796
10126
  policyNumber: SourceBackedValueForPromptSchema.optional(),
9797
10127
  namedInsured: SourceBackedValueForPromptSchema.optional(),
9798
10128
  insurer: SourceBackedValueForPromptSchema.optional(),
@@ -9801,43 +10131,32 @@ var OperationalProfilePromptSchema = z41.object({
9801
10131
  expirationDate: SourceBackedValueForPromptSchema.optional(),
9802
10132
  retroactiveDate: SourceBackedValueForPromptSchema.optional(),
9803
10133
  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())
10134
+ coverageTypes: z42.array(z42.string()).optional(),
10135
+ coverages: z42.array(z42.object({
10136
+ name: z42.string(),
10137
+ coverageCode: z42.string().optional(),
10138
+ limit: z42.string().optional(),
10139
+ deductible: z42.string().optional(),
10140
+ premium: z42.string().optional(),
10141
+ retroactiveDate: z42.string().optional(),
10142
+ formNumber: z42.string().optional(),
10143
+ sectionRef: z42.string().optional(),
10144
+ coverageOrigin: z42.enum(["core", "endorsement"]).optional(),
10145
+ endorsementNumber: z42.string().optional(),
10146
+ limits: z42.array(z42.object({
10147
+ kind: OperationalCoverageTermKindSchema.optional(),
10148
+ label: z42.string(),
10149
+ value: z42.string(),
10150
+ amount: z42.number().optional(),
10151
+ appliesTo: z42.string().optional(),
10152
+ sourceNodeIds: z42.array(z42.string()),
10153
+ sourceSpanIds: z42.array(z42.string())
9835
10154
  })).optional(),
9836
- sourceNodeIds: z41.array(z41.string()),
9837
- sourceSpanIds: z41.array(z41.string())
10155
+ sourceNodeIds: z42.array(z42.string()),
10156
+ sourceSpanIds: z42.array(z42.string())
9838
10157
  })).optional(),
9839
- sourceNodeIds: z41.array(z41.string()).optional(),
9840
- sourceSpanIds: z41.array(z41.string()).optional()
10158
+ sourceNodeIds: z42.array(z42.string()).optional(),
10159
+ sourceSpanIds: z42.array(z42.string()).optional()
9841
10160
  });
9842
10161
  function formatFormHintsForPrompt(forms) {
9843
10162
  const usable = forms.filter((form) => typeof form.pageStart === "number" && typeof form.pageEnd === "number").slice(0, 120).map((form) => ({
@@ -10829,7 +11148,7 @@ function applyEndorsementGrouping(sourceTree) {
10829
11148
  }
10830
11149
  return normalizeSemanticHierarchy(nextTree);
10831
11150
  }
10832
- function compactNode(node, maxText = 700) {
11151
+ function compactNode2(node, maxText = 700) {
10833
11152
  return {
10834
11153
  id: node.id,
10835
11154
  kind: node.kind,
@@ -10919,7 +11238,7 @@ function mergeOrganizationResults(results) {
10919
11238
  };
10920
11239
  }
10921
11240
  function buildOrganizationPrompt(batch, formHints) {
10922
- const nodes = batch.nodes.map((node) => compactNode(node, node.kind === "page" ? 900 : 320));
11241
+ const nodes = batch.nodes.map((node) => compactNode2(node, node.kind === "page" ? 900 : 320));
10923
11242
  return `You organize an insurance document source tree.
10924
11243
 
10925
11244
  Scope:
@@ -10961,7 +11280,7 @@ function shouldRunOutlineCleanup(sourceTree) {
10961
11280
  }
10962
11281
  function buildOutlineCleanupPrompt(sourceTree, formHints) {
10963
11282
  const topLevel = rootChildren(sourceTree).slice(0, OUTLINE_CLEANUP_MAX_TOP_LEVEL_NODES);
10964
- const nodes = topLevel.map((node) => compactNode(node, 900));
11283
+ const nodes = topLevel.map((node) => compactNode2(node, 900));
10965
11284
  return `You clean a top-level source outline for an insurance policy.
10966
11285
 
10967
11286
  Expected product-facing order:
@@ -10990,7 +11309,7 @@ ${JSON.stringify(nodes, null, 2)}
10990
11309
  Return JSON with labels and groups only.`;
10991
11310
  }
10992
11311
  function buildOperationalProfilePrompt(sourceTree, fallback) {
10993
- const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 240).map(compactNode);
11312
+ const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 240).map(compactNode2);
10994
11313
  return `Extract a source-backed operational profile for an insurance policy or quote.
10995
11314
 
10996
11315
  Return only high-value operational facts needed for policy lists, Q&A, compliance, and certificate generation:
@@ -11117,6 +11436,13 @@ function valueOf(profile, key) {
11117
11436
  }
11118
11437
  return String(value.value);
11119
11438
  }
11439
+ function provenanceOf(value) {
11440
+ if (!value?.sourceSpanIds.length) return void 0;
11441
+ return {
11442
+ sourceSpanIds: value.sourceSpanIds,
11443
+ ...value.sourceNodeIds[0] ? { documentNodeId: value.sourceNodeIds[0] } : {}
11444
+ };
11445
+ }
11120
11446
  function materializeDocument(params) {
11121
11447
  const profile = params.operationalProfile;
11122
11448
  const policyNumber = valueOf(profile, "policyNumber") ?? "Unknown";
@@ -11125,6 +11451,9 @@ function materializeDocument(params) {
11125
11451
  const effectiveDate = valueOf(profile, "effectiveDate") ?? "Unknown";
11126
11452
  const expirationDate = valueOf(profile, "expirationDate") ?? "Unknown";
11127
11453
  const premium = valueOf(profile, "premium");
11454
+ const insurerProvenance = provenanceOf(profile.insurer);
11455
+ const broker = valueOf(profile, "broker");
11456
+ const brokerProvenance = provenanceOf(profile.broker);
11128
11457
  const coverages = profile.coverages.map((coverage) => ({
11129
11458
  name: coverage.name,
11130
11459
  coverageCode: coverage.coverageCode,
@@ -11176,6 +11505,11 @@ function materializeDocument(params) {
11176
11505
  security: carrier,
11177
11506
  insuredName,
11178
11507
  premium,
11508
+ ...insurerProvenance ? { insurer: { legalName: carrier, ...insurerProvenance } } : {},
11509
+ ...broker && brokerProvenance ? {
11510
+ brokerAgency: broker,
11511
+ producer: { agencyName: broker, ...brokerProvenance }
11512
+ } : {},
11179
11513
  policyTypes: profile.policyTypes,
11180
11514
  formInventory: params.formInventory.filter((form) => typeof form.formNumber === "string" && form.formNumber.trim().length > 0).map((form) => ({
11181
11515
  formNumber: form.formNumber,
@@ -11354,6 +11688,45 @@ async function runSourceTreeExtraction(params) {
11354
11688
  } catch (error) {
11355
11689
  warnings.push(`Operational profile model pass failed; deterministic profile used (${error instanceof Error ? error.message : String(error)})`);
11356
11690
  }
11691
+ if (operationalProfile.coverages.length > 0) {
11692
+ try {
11693
+ const validNodeIds = new Set(sourceTree.map((node) => node.id));
11694
+ const validSpanIds = new Set(sourceSpans.map((span) => span.id));
11695
+ const budget = params.resolveBudget("extraction_operational_profile", 4096);
11696
+ const startedAt = Date.now();
11697
+ const response = await safeGenerateObject(
11698
+ params.generateObject,
11699
+ {
11700
+ prompt: buildOperationalProfileCleanupPrompt(sourceTree, operationalProfile),
11701
+ schema: OperationalProfileCleanupSchema,
11702
+ maxTokens: budget.maxTokens,
11703
+ taskKind: "extraction_operational_profile",
11704
+ budgetDiagnostics: budget,
11705
+ providerOptions: params.providerOptions
11706
+ },
11707
+ {
11708
+ fallback: { coverageDecisions: [], warnings: [] },
11709
+ log: params.log
11710
+ }
11711
+ );
11712
+ localTrack(response.usage, {
11713
+ taskKind: "extraction_operational_profile",
11714
+ label: "operational_profile_cleanup",
11715
+ maxTokens: budget.maxTokens,
11716
+ durationMs: Date.now() - startedAt
11717
+ });
11718
+ operationalProfile = applyOperationalProfileCleanup(
11719
+ operationalProfile,
11720
+ response.object,
11721
+ validNodeIds,
11722
+ validSpanIds
11723
+ );
11724
+ } catch (error) {
11725
+ warnings.push(`Operational profile cleanup pass failed; uncleaned profile used (${error instanceof Error ? error.message : String(error)})`);
11726
+ }
11727
+ } else {
11728
+ await params.log?.("Operational profile has no coverage rows; skipped model cleanup");
11729
+ }
11357
11730
  const document = materializeDocument({
11358
11731
  id: params.id,
11359
11732
  sourceTree,
@@ -12680,8 +13053,8 @@ Respond with JSON only:
12680
13053
  }`;
12681
13054
 
12682
13055
  // src/schemas/application.ts
12683
- import { z as z42 } from "zod";
12684
- var FieldTypeSchema = z42.enum([
13056
+ import { z as z43 } from "zod";
13057
+ var FieldTypeSchema = z43.enum([
12685
13058
  "text",
12686
13059
  "numeric",
12687
13060
  "currency",
@@ -12690,223 +13063,223 @@ var FieldTypeSchema = z42.enum([
12690
13063
  "table",
12691
13064
  "declaration"
12692
13065
  ]);
12693
- var ApplicationFieldSchema = z42.object({
12694
- id: z42.string(),
12695
- label: z42.string(),
12696
- section: z42.string(),
13066
+ var ApplicationFieldSchema = z43.object({
13067
+ id: z43.string(),
13068
+ label: z43.string(),
13069
+ section: z43.string(),
12697
13070
  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()
13071
+ required: z43.boolean(),
13072
+ options: z43.array(z43.string()).optional(),
13073
+ columns: z43.array(z43.string()).optional(),
13074
+ requiresExplanationIfYes: z43.boolean().optional(),
13075
+ condition: z43.object({
13076
+ dependsOn: z43.string(),
13077
+ whenValue: z43.string()
12705
13078
  }).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()
13079
+ value: z43.string().optional(),
13080
+ source: z43.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
13081
+ confidence: z43.enum(["confirmed", "high", "medium", "low"]).optional(),
13082
+ sourceSpanIds: z43.array(z43.string()).optional().describe("Stable source spans that support the field value or field anchor"),
13083
+ userSourceSpanIds: z43.array(z43.string()).optional().describe("Message or attachment spans that support user-provided values"),
13084
+ pageNumber: z43.number().int().positive().optional().describe("Application page where the field label or anchor appears"),
13085
+ fieldAnchorId: z43.string().optional().describe("Stable field anchor ID derived from page, section, label, and form metadata"),
13086
+ acroFormName: z43.string().optional().describe("Native PDF AcroForm field name when available"),
13087
+ validationStatus: z43.enum(["valid", "needs_review", "unsupported", "missing"]).optional()
12715
13088
  });
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()
13089
+ var ApplicationQuestionConditionSchema = z43.object({
13090
+ dependsOn: z43.string(),
13091
+ operator: z43.enum(["equals", "not_equals", "in", "not_in", "exists"]).optional(),
13092
+ value: z43.string().optional(),
13093
+ whenValue: z43.string().optional(),
13094
+ values: z43.array(z43.string()).optional()
12722
13095
  });
12723
- var ApplicationRepeatSchema = z42.object({
12724
- min: z42.number().int().nonnegative().optional(),
12725
- max: z42.number().int().positive().optional(),
12726
- label: z42.string().optional()
13096
+ var ApplicationRepeatSchema = z43.object({
13097
+ min: z43.number().int().nonnegative().optional(),
13098
+ max: z43.number().int().positive().optional(),
13099
+ label: z43.string().optional()
12727
13100
  });
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(),
13101
+ var ApplicationQuestionNodeSchema = z43.lazy(
13102
+ () => z43.object({
13103
+ id: z43.string(),
13104
+ nodeType: z43.enum(["group", "question", "repeat_group", "table"]),
13105
+ fieldId: z43.string().optional(),
13106
+ fieldPath: z43.string().optional(),
13107
+ parentId: z43.string().optional(),
13108
+ order: z43.number().int().nonnegative().optional(),
13109
+ label: z43.string(),
13110
+ section: z43.string().optional(),
12738
13111
  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(),
13112
+ required: z43.boolean().optional(),
13113
+ prompt: z43.string().optional(),
13114
+ options: z43.array(z43.string()).optional(),
13115
+ columns: z43.array(z43.string()).optional(),
12743
13116
  condition: ApplicationQuestionConditionSchema.optional(),
12744
13117
  repeat: ApplicationRepeatSchema.optional(),
12745
- children: z42.array(ApplicationQuestionNodeSchema).optional()
13118
+ children: z43.array(ApplicationQuestionNodeSchema).optional()
12746
13119
  })
12747
13120
  );
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)
13121
+ var ApplicationQuestionGraphSchema = z43.object({
13122
+ id: z43.string(),
13123
+ version: z43.string(),
13124
+ title: z43.string().optional(),
13125
+ applicationType: z43.string().nullable().optional(),
13126
+ source: z43.enum(["pdf", "manual", "imported", "generated"]).default("generated"),
13127
+ rootNodeIds: z43.array(z43.string()).optional(),
13128
+ nodes: z43.array(ApplicationQuestionNodeSchema)
12756
13129
  });
12757
- var ApplicationTemplateSchema = z42.object({
12758
- id: z42.string(),
12759
- version: z42.string(),
12760
- title: z42.string(),
12761
- applicationType: z42.string().nullable().optional(),
13130
+ var ApplicationTemplateSchema = z43.object({
13131
+ id: z43.string(),
13132
+ version: z43.string(),
13133
+ title: z43.string(),
13134
+ applicationType: z43.string().nullable().optional(),
12762
13135
  questionGraph: ApplicationQuestionGraphSchema,
12763
- fields: z42.array(ApplicationFieldSchema).optional()
13136
+ fields: z43.array(ApplicationFieldSchema).optional()
12764
13137
  });
12765
- var ApplicationClassifyResultSchema = z42.object({
12766
- isApplication: z42.boolean(),
12767
- confidence: z42.number().min(0).max(1),
12768
- applicationType: z42.string().nullable()
13138
+ var ApplicationClassifyResultSchema = z43.object({
13139
+ isApplication: z43.boolean(),
13140
+ confidence: z43.number().min(0).max(1),
13141
+ applicationType: z43.string().nullable()
12769
13142
  });
12770
- var FieldExtractionResultSchema = z42.object({
12771
- fields: z42.array(ApplicationFieldSchema)
13143
+ var FieldExtractionResultSchema = z43.object({
13144
+ fields: z43.array(ApplicationFieldSchema)
12772
13145
  });
12773
- var AutoFillMatchSchema = z42.object({
12774
- fieldId: z42.string(),
12775
- value: z42.string(),
12776
- confidence: z42.enum(["confirmed"]),
12777
- contextKey: z42.string()
13146
+ var AutoFillMatchSchema = z43.object({
13147
+ fieldId: z43.string(),
13148
+ value: z43.string(),
13149
+ confidence: z43.enum(["confirmed"]),
13150
+ contextKey: z43.string()
12778
13151
  });
12779
- var AutoFillResultSchema = z42.object({
12780
- matches: z42.array(AutoFillMatchSchema)
13152
+ var AutoFillResultSchema = z43.object({
13153
+ matches: z43.array(AutoFillMatchSchema)
12781
13154
  });
12782
- var QuestionBatchResultSchema = z42.object({
12783
- batches: z42.array(z42.array(z42.string()).describe("Array of field IDs in this batch"))
13155
+ var QuestionBatchResultSchema = z43.object({
13156
+ batches: z43.array(z43.array(z43.string()).describe("Array of field IDs in this batch"))
12784
13157
  });
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())
13158
+ var LookupRequestSchema = z43.object({
13159
+ type: z43.string().describe("Type of lookup: 'records', 'website', 'policy'"),
13160
+ description: z43.string(),
13161
+ url: z43.string().optional(),
13162
+ targetFieldIds: z43.array(z43.string())
12790
13163
  });
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()
13164
+ var ReplyIntentSchema = z43.object({
13165
+ primaryIntent: z43.enum(["answers_only", "question", "lookup_request", "mixed"]),
13166
+ hasAnswers: z43.boolean(),
13167
+ questionText: z43.string().optional(),
13168
+ questionFieldIds: z43.array(z43.string()).optional(),
13169
+ lookupRequests: z43.array(LookupRequestSchema).optional()
12797
13170
  });
12798
- var ParsedAnswerSchema = z42.object({
12799
- fieldId: z42.string(),
12800
- value: z42.string(),
12801
- explanation: z42.string().optional()
13171
+ var ParsedAnswerSchema = z43.object({
13172
+ fieldId: z43.string(),
13173
+ value: z43.string(),
13174
+ explanation: z43.string().optional()
12802
13175
  });
12803
- var AnswerParsingResultSchema = z42.object({
12804
- answers: z42.array(ParsedAnswerSchema),
12805
- unanswered: z42.array(z42.string()).describe("Field IDs that were not answered")
13176
+ var AnswerParsingResultSchema = z43.object({
13177
+ answers: z43.array(ParsedAnswerSchema),
13178
+ unanswered: z43.array(z43.string()).describe("Field IDs that were not answered")
12806
13179
  });
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()
13180
+ var LookupFillSchema = z43.object({
13181
+ fieldId: z43.string(),
13182
+ value: z43.string(),
13183
+ source: z43.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'"),
13184
+ sourceSpanIds: z43.array(z43.string()).optional()
12812
13185
  });
12813
- var LookupFillResultSchema = z42.object({
12814
- fills: z42.array(LookupFillSchema),
12815
- unfillable: z42.array(z42.string()),
12816
- explanation: z42.string().optional()
13186
+ var LookupFillResultSchema = z43.object({
13187
+ fills: z43.array(LookupFillSchema),
13188
+ unfillable: z43.array(z43.string()),
13189
+ explanation: z43.string().optional()
12817
13190
  });
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()
13191
+ var FlatPdfPlacementSchema = z43.object({
13192
+ fieldId: z43.string(),
13193
+ page: z43.number(),
13194
+ x: z43.number().describe("Percentage from left edge (0-100)"),
13195
+ y: z43.number().describe("Percentage from top edge (0-100)"),
13196
+ text: z43.string(),
13197
+ fontSize: z43.number().optional(),
13198
+ isCheckmark: z43.boolean().optional()
12826
13199
  });
12827
- var AcroFormMappingSchema = z42.object({
12828
- fieldId: z42.string(),
12829
- acroFormName: z42.string(),
12830
- value: z42.string()
13200
+ var AcroFormMappingSchema = z43.object({
13201
+ fieldId: z43.string(),
13202
+ acroFormName: z43.string(),
13203
+ value: z43.string()
12831
13204
  });
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(),
13205
+ var QualityGateStatusSchema = z43.enum(["passed", "warning", "failed"]);
13206
+ var QualitySeveritySchema = z43.enum(["info", "warning", "blocking"]);
13207
+ var ApplicationQualityIssueSchema = z43.object({
13208
+ code: z43.string(),
12836
13209
  severity: QualitySeveritySchema,
12837
- message: z42.string(),
12838
- fieldId: z42.string().optional()
13210
+ message: z43.string(),
13211
+ fieldId: z43.string().optional()
12839
13212
  });
12840
- var ApplicationQualityRoundSchema = z42.object({
12841
- round: z42.number(),
12842
- kind: z42.string(),
13213
+ var ApplicationQualityRoundSchema = z43.object({
13214
+ round: z43.number(),
13215
+ kind: z43.string(),
12843
13216
  status: QualityGateStatusSchema,
12844
- summary: z42.string().optional()
13217
+ summary: z43.string().optional()
12845
13218
  });
12846
- var ApplicationQualityArtifactSchema = z42.object({
12847
- kind: z42.string(),
12848
- label: z42.string().optional(),
12849
- itemCount: z42.number().optional()
13219
+ var ApplicationQualityArtifactSchema = z43.object({
13220
+ kind: z43.string(),
13221
+ label: z43.string().optional(),
13222
+ itemCount: z43.number().optional()
12850
13223
  });
12851
- var ApplicationEmailReviewSchema = z42.object({
12852
- issues: z42.array(ApplicationQualityIssueSchema),
13224
+ var ApplicationEmailReviewSchema = z43.object({
13225
+ issues: z43.array(ApplicationQualityIssueSchema),
12853
13226
  qualityGateStatus: QualityGateStatusSchema
12854
13227
  });
12855
- var ApplicationQualityReportSchema = z42.object({
12856
- issues: z42.array(ApplicationQualityIssueSchema),
12857
- rounds: z42.array(ApplicationQualityRoundSchema).optional(),
12858
- artifacts: z42.array(ApplicationQualityArtifactSchema).optional(),
13228
+ var ApplicationQualityReportSchema = z43.object({
13229
+ issues: z43.array(ApplicationQualityIssueSchema),
13230
+ rounds: z43.array(ApplicationQualityRoundSchema).optional(),
13231
+ artifacts: z43.array(ApplicationQualityArtifactSchema).optional(),
12859
13232
  emailReview: ApplicationEmailReviewSchema.optional(),
12860
13233
  qualityGateStatus: QualityGateStatusSchema
12861
13234
  });
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()
13235
+ var ApplicationContextProposalSchema = z43.object({
13236
+ id: z43.string(),
13237
+ fieldId: z43.string().optional(),
13238
+ key: z43.string(),
13239
+ value: z43.string(),
13240
+ category: z43.string(),
13241
+ source: z43.enum(["application", "user", "lookup", "policy", "email", "chat", "imessage", "mcp"]),
13242
+ confidence: z43.enum(["confirmed", "high", "medium", "low"]),
13243
+ sourceSpanIds: z43.array(z43.string()).optional(),
13244
+ userSourceSpanIds: z43.array(z43.string()).optional()
12872
13245
  });
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()
13246
+ var ApplicationPacketAnswerSchema = z43.object({
13247
+ fieldId: z43.string(),
13248
+ label: z43.string(),
13249
+ section: z43.string(),
13250
+ value: z43.string(),
13251
+ source: z43.string(),
13252
+ confidence: z43.enum(["confirmed", "high", "medium", "low"]).optional(),
13253
+ sourceSpanIds: z43.array(z43.string()).optional(),
13254
+ userSourceSpanIds: z43.array(z43.string()).optional()
12882
13255
  });
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()),
13256
+ var ApplicationPacketSchema = z43.object({
13257
+ id: z43.string(),
13258
+ applicationId: z43.string(),
13259
+ title: z43.string(),
13260
+ status: z43.enum(["draft", "broker_ready", "submitted"]),
13261
+ answers: z43.array(ApplicationPacketAnswerSchema),
13262
+ missingFieldIds: z43.array(z43.string()),
12890
13263
  qualityReport: ApplicationQualityReportSchema,
12891
- submissionNotes: z42.string().optional(),
12892
- createdAt: z42.number()
13264
+ submissionNotes: z43.string().optional(),
13265
+ createdAt: z43.number()
12893
13266
  });
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(),
13267
+ var ApplicationStateSchema = z43.object({
13268
+ id: z43.string(),
13269
+ pdfBase64: z43.string().optional().describe("Original PDF, omitted after extraction"),
13270
+ templateId: z43.string().optional(),
13271
+ templateVersion: z43.string().optional(),
12899
13272
  templateSnapshot: ApplicationTemplateSchema.optional(),
12900
- title: z42.string().optional(),
12901
- applicationType: z42.string().nullable().optional(),
13273
+ title: z43.string().optional(),
13274
+ applicationType: z43.string().nullable().optional(),
12902
13275
  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(),
13276
+ fields: z43.array(ApplicationFieldSchema),
13277
+ batches: z43.array(z43.array(z43.string())).optional(),
13278
+ currentBatchIndex: z43.number().default(0),
13279
+ contextProposals: z43.array(ApplicationContextProposalSchema).optional(),
12907
13280
  packet: ApplicationPacketSchema.optional(),
12908
13281
  qualityReport: ApplicationQualityReportSchema.optional(),
12909
- status: z42.enum([
13282
+ status: z43.enum([
12910
13283
  "classifying",
12911
13284
  "extracting",
12912
13285
  "auto_filling",
@@ -12920,8 +13293,8 @@ var ApplicationStateSchema = z42.object({
12920
13293
  "cancelled",
12921
13294
  "complete"
12922
13295
  ]),
12923
- createdAt: z42.number(),
12924
- updatedAt: z42.number()
13296
+ createdAt: z43.number(),
13297
+ updatedAt: z43.number()
12925
13298
  });
12926
13299
 
12927
13300
  // src/application/agents/classifier.ts
@@ -14655,106 +15028,106 @@ Respond with the final answer, deduplicated citations array, overall confidence
14655
15028
  }
14656
15029
 
14657
15030
  // src/schemas/query.ts
14658
- import { z as z43 } from "zod";
14659
- var QueryIntentSchema = z43.enum([
15031
+ import { z as z44 } from "zod";
15032
+ var QueryIntentSchema = z44.enum([
14660
15033
  "policy_question",
14661
15034
  "coverage_comparison",
14662
15035
  "document_search",
14663
15036
  "claims_inquiry",
14664
15037
  "general_knowledge"
14665
15038
  ]);
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"),
15039
+ var QueryAttachmentKindSchema = z44.enum(["image", "pdf", "text"]);
15040
+ var QueryAttachmentSchema = z44.object({
15041
+ id: z44.string().optional().describe("Optional stable attachment ID from the caller"),
14669
15042
  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")
15043
+ name: z44.string().optional().describe("Original filename or user-facing label"),
15044
+ mimeType: z44.string().optional().describe("MIME type such as image/jpeg or application/pdf"),
15045
+ base64: z44.string().optional().describe("Base64-encoded file content for image/pdf attachments"),
15046
+ text: z44.string().optional().describe("Plain-text attachment content when available"),
15047
+ description: z44.string().optional().describe("Caller-provided description of the attachment")
14675
15048
  });
14676
- var QueryRetrievalModeSchema = z43.enum([
15049
+ var QueryRetrievalModeSchema = z44.enum([
14677
15050
  "graph_only",
14678
15051
  "source_rag",
14679
15052
  "long_context",
14680
15053
  "hybrid"
14681
15054
  ]);
14682
- var SubQuestionSchema = z43.object({
14683
- question: z43.string().describe("Atomic sub-question to retrieve and answer independently"),
15055
+ var SubQuestionSchema = z44.object({
15056
+ question: z44.string().describe("Atomic sub-question to retrieve and answer independently"),
14684
15057
  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")
15058
+ chunkTypes: z44.array(z44.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
15059
+ documentFilters: z44.object({
15060
+ type: z44.enum(["policy", "quote"]).optional(),
15061
+ carrier: z44.string().optional(),
15062
+ insuredName: z44.string().optional(),
15063
+ policyNumber: z44.string().optional(),
15064
+ quoteNumber: z44.string().optional(),
15065
+ policyTypes: z44.array(PolicyTypeSchema).optional().describe("Filter by policy type (e.g. homeowners_ho3, renters_ho4, pet) to avoid mixing up similar policies")
14693
15066
  }).optional().describe("Structured filters to narrow document lookup")
14694
15067
  });
14695
- var QueryClassifyResultSchema = z43.object({
15068
+ var QueryClassifyResultSchema = z44.object({
14696
15069
  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"),
15070
+ subQuestions: z44.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
15071
+ requiresDocumentLookup: z44.boolean().describe("Whether structured document lookup is needed"),
15072
+ requiresChunkSearch: z44.boolean().describe("Whether semantic chunk search is needed"),
15073
+ requiresConversationHistory: z44.boolean().describe("Whether conversation history is relevant"),
14701
15074
  retrievalMode: QueryRetrievalModeSchema.optional().describe("Preferred retrieval strategy for the query when source-span retrieval is available")
14702
15075
  });
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),
15076
+ var EvidenceItemSchema = z44.object({
15077
+ source: z44.enum(["chunk", "document", "conversation", "attachment", "source_span", "source_node"]),
15078
+ chunkId: z44.string().optional(),
15079
+ sourceNodeId: z44.string().optional(),
15080
+ sourceSpanId: z44.string().optional(),
15081
+ documentId: z44.string().optional(),
15082
+ turnId: z44.string().optional(),
15083
+ attachmentId: z44.string().optional(),
15084
+ text: z44.string().describe("Text excerpt from the source"),
15085
+ relevance: z44.number().min(0).max(1),
14713
15086
  retrievalMode: QueryRetrievalModeSchema.optional(),
14714
15087
  sourceLocation: SourceSpanLocationSchema.optional(),
14715
- metadata: z43.array(z43.object({ key: z43.string(), value: z43.string() })).optional()
15088
+ metadata: z44.array(z44.object({ key: z44.string(), value: z44.string() })).optional()
14716
15089
  });
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)
15090
+ var AttachmentInterpretationSchema = z44.object({
15091
+ summary: z44.string().describe("Concise summary of what the attachment shows or contains"),
15092
+ extractedFacts: z44.array(z44.string()).describe("Specific observable or document facts grounded in the attachment"),
15093
+ recommendedFocus: z44.array(z44.string()).describe("Important details to incorporate when answering follow-up questions"),
15094
+ confidence: z44.number().min(0).max(1)
14722
15095
  });
14723
- var RetrievalResultSchema = z43.object({
14724
- subQuestion: z43.string(),
14725
- evidence: z43.array(EvidenceItemSchema)
15096
+ var RetrievalResultSchema = z44.object({
15097
+ subQuestion: z44.string(),
15098
+ evidence: z44.array(EvidenceItemSchema)
14726
15099
  });
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),
15100
+ var CitationSchema = z44.object({
15101
+ index: z44.number().describe("Citation number [1], [2], etc."),
15102
+ chunkId: z44.string().optional().describe("Source chunk ID, e.g. doc-123:coverage:2"),
15103
+ sourceNodeId: z44.string().optional().describe("Source tree node ID when available"),
15104
+ sourceSpanId: z44.string().optional().describe("Precise source span ID when available"),
15105
+ documentId: z44.string(),
15106
+ documentType: z44.enum(["policy", "quote"]).optional(),
15107
+ field: z44.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
15108
+ quote: z44.string().describe("Exact text from source that supports the claim"),
15109
+ relevance: z44.number().min(0).max(1),
14737
15110
  retrievalMode: QueryRetrievalModeSchema.optional(),
14738
15111
  sourceLocation: SourceSpanLocationSchema.optional()
14739
15112
  });
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")
15113
+ var SubAnswerSchema = z44.object({
15114
+ subQuestion: z44.string(),
15115
+ answer: z44.string(),
15116
+ citations: z44.array(CitationSchema),
15117
+ confidence: z44.number().min(0).max(1),
15118
+ needsMoreContext: z44.boolean().describe("True if evidence was insufficient to answer fully")
14746
15119
  });
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")
15120
+ var VerifyResultSchema = z44.object({
15121
+ approved: z44.boolean().describe("Whether all sub-answers are adequately grounded"),
15122
+ issues: z44.array(z44.string()).describe("Specific grounding or consistency issues found"),
15123
+ retrySubQuestions: z44.array(z44.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
14751
15124
  });
14752
- var QueryResultSchema = z43.object({
14753
- answer: z43.string(),
14754
- citations: z43.array(CitationSchema),
15125
+ var QueryResultSchema = z44.object({
15126
+ answer: z44.string(),
15127
+ citations: z44.array(CitationSchema),
14755
15128
  intent: QueryIntentSchema,
14756
- confidence: z43.number().min(0).max(1),
14757
- followUp: z43.string().optional().describe("Suggested follow-up question if applicable")
15129
+ confidence: z44.number().min(0).max(1),
15130
+ followUp: z44.string().optional().describe("Suggested follow-up question if applicable")
14758
15131
  });
14759
15132
 
14760
15133
  // src/query/retriever.ts
@@ -15821,7 +16194,7 @@ ${sa.answer}`).join("\n\n"),
15821
16194
  }
15822
16195
 
15823
16196
  // src/pce/index.ts
15824
- import { z as z44 } from "zod";
16197
+ import { z as z45 } from "zod";
15825
16198
 
15826
16199
  // src/prompts/pce/index.ts
15827
16200
  function buildPceNormalizePrompt(input) {
@@ -15855,11 +16228,11 @@ ${input.openQuestions.map((question) => `- ${question.id}${question.fieldPath ?
15855
16228
  }
15856
16229
 
15857
16230
  // 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()
16231
+ var ReplyAnswersSchema = z45.object({
16232
+ answers: z45.array(z45.object({
16233
+ questionId: z45.string().optional(),
16234
+ fieldPath: z45.string().optional(),
16235
+ answer: z45.string()
15863
16236
  }))
15864
16237
  });
15865
16238
  function createPceAgent(config = {}) {
@@ -16819,9 +17192,11 @@ export {
16819
17192
  ScheduledItemCategorySchema,
16820
17193
  SectionSchema,
16821
17194
  SharedLimitSchema,
17195
+ SourceBackedAddressSchema,
16822
17196
  SourceBackedValueSchema,
16823
17197
  SourceChunkSchema,
16824
17198
  SourceKindSchema,
17199
+ SourceProvenanceSchema,
16825
17200
  SourceSpanBBoxSchema,
16826
17201
  SourceSpanKindSchema,
16827
17202
  SourceSpanLocationSchema,