@claritylabs/cl-sdk 4.0.1 → 4.1.0

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
@@ -2360,6 +2360,40 @@ var SourceBackedValueSchema = z21.object({
2360
2360
  sourceNodeIds: z21.array(z21.string().min(1)).default([]),
2361
2361
  sourceSpanIds: z21.array(z21.string().min(1)).default([])
2362
2362
  });
2363
+ var OperationalAddressSchema = z21.object({
2364
+ street1: z21.string().optional(),
2365
+ street2: z21.string().optional(),
2366
+ city: z21.string().optional(),
2367
+ state: z21.string().optional(),
2368
+ zip: z21.string().optional(),
2369
+ country: z21.string().optional(),
2370
+ formatted: z21.string().optional()
2371
+ });
2372
+ var OperationalDeclarationFactSchema = z21.object({
2373
+ field: z21.enum([
2374
+ "namedInsured",
2375
+ "mailingAddress",
2376
+ "dba",
2377
+ "entityType",
2378
+ "taxId",
2379
+ "additionalNamedInsured",
2380
+ "policyNumber",
2381
+ "insurer",
2382
+ "broker",
2383
+ "effectiveDate",
2384
+ "expirationDate",
2385
+ "premium",
2386
+ "other"
2387
+ ]),
2388
+ label: z21.string().optional(),
2389
+ value: z21.string(),
2390
+ normalizedValue: z21.string().optional(),
2391
+ valueKind: z21.enum(["string", "number", "date", "money", "address", "list", "unknown"]).default("string"),
2392
+ address: OperationalAddressSchema.optional(),
2393
+ confidence: z21.enum(["low", "medium", "high"]).default("medium"),
2394
+ sourceNodeIds: z21.array(z21.string().min(1)).default([]),
2395
+ sourceSpanIds: z21.array(z21.string().min(1)).default([])
2396
+ });
2363
2397
  var OperationalCoverageTermSchema = z21.object({
2364
2398
  kind: z21.enum([
2365
2399
  "each_claim_limit",
@@ -2434,6 +2468,7 @@ var PolicyOperationalProfileSchema = z21.preprocess(
2434
2468
  expirationDate: SourceBackedValueSchema.optional(),
2435
2469
  retroactiveDate: SourceBackedValueSchema.optional(),
2436
2470
  premium: SourceBackedValueSchema.optional(),
2471
+ declarationFacts: z21.array(OperationalDeclarationFactSchema).default([]),
2437
2472
  coverages: z21.array(OperationalCoverageLineSchema).default([]),
2438
2473
  parties: z21.array(OperationalPartySchema).default([]),
2439
2474
  endorsementSupport: z21.array(OperationalEndorsementSupportSchema).default([]),
@@ -3767,6 +3802,9 @@ function cleanValue(value) {
3767
3802
  if (!value) return void 0;
3768
3803
  return normalizeWhitespace4(value.replace(/^[\s:;#-]+|[\s;,.]+$/g, ""));
3769
3804
  }
3805
+ function normalizedFactValue(value) {
3806
+ return value.toLowerCase().replace(/&/g, " and ").replace(/[.,#]/g, " ").replace(/\s+/g, " ").trim();
3807
+ }
3770
3808
  var OPERATIONAL_COVERAGE_TERM_KINDS = /* @__PURE__ */ new Set([
3771
3809
  "each_claim_limit",
3772
3810
  "each_occurrence_limit",
@@ -3800,6 +3838,63 @@ function mergeOperationalProfile(base, candidate, validNodeIds, validSpanIds) {
3800
3838
  sourceSpanIds: sourceSpanIds2
3801
3839
  };
3802
3840
  };
3841
+ const mergeDeclarationFact = (fact) => {
3842
+ if (!fact || typeof fact !== "object" || Array.isArray(fact)) return void 0;
3843
+ const record = fact;
3844
+ const field = typeof record.field === "string" ? cleanValue(record.field) : void 0;
3845
+ const value = typeof record.value === "string" ? cleanValue(record.value) : void 0;
3846
+ const sourceNodeIds2 = keepIds(record.sourceNodeIds, validNodeIds);
3847
+ const sourceSpanIds2 = keepIds(record.sourceSpanIds, validSpanIds);
3848
+ if (!field || !value || sourceNodeIds2.length === 0 && sourceSpanIds2.length === 0) return void 0;
3849
+ const address = record.address && typeof record.address === "object" && !Array.isArray(record.address) ? Object.fromEntries(
3850
+ Object.entries(record.address).flatMap(([key, item]) => {
3851
+ const text = typeof item === "string" ? cleanValue(item) : void 0;
3852
+ return text ? [[key, text]] : [];
3853
+ })
3854
+ ) : void 0;
3855
+ return {
3856
+ field: [
3857
+ "namedInsured",
3858
+ "mailingAddress",
3859
+ "dba",
3860
+ "entityType",
3861
+ "taxId",
3862
+ "additionalNamedInsured",
3863
+ "policyNumber",
3864
+ "insurer",
3865
+ "broker",
3866
+ "effectiveDate",
3867
+ "expirationDate",
3868
+ "premium",
3869
+ "other"
3870
+ ].includes(field) ? field : "other",
3871
+ label: typeof record.label === "string" ? cleanValue(record.label) : void 0,
3872
+ value,
3873
+ normalizedValue: typeof record.normalizedValue === "string" ? cleanValue(record.normalizedValue) : normalizedFactValue(value),
3874
+ valueKind: [
3875
+ "string",
3876
+ "number",
3877
+ "date",
3878
+ "money",
3879
+ "address",
3880
+ "list",
3881
+ "unknown"
3882
+ ].includes(String(record.valueKind)) ? record.valueKind : "string",
3883
+ address,
3884
+ confidence: record.confidence === "high" || record.confidence === "low" || record.confidence === "medium" ? record.confidence : "medium",
3885
+ sourceNodeIds: sourceNodeIds2,
3886
+ sourceSpanIds: sourceSpanIds2
3887
+ };
3888
+ };
3889
+ const sourceBackedDeclarationFact = (field, value, valueKind = "string") => value ? {
3890
+ field,
3891
+ value: value.value,
3892
+ normalizedValue: value.normalizedValue ?? normalizedFactValue(value.value),
3893
+ valueKind,
3894
+ confidence: value.confidence,
3895
+ sourceNodeIds: value.sourceNodeIds,
3896
+ sourceSpanIds: value.sourceSpanIds
3897
+ } : void 0;
3803
3898
  const policyNumber = mergeValue(base.policyNumber, candidate.policyNumber);
3804
3899
  const namedInsured = mergeValue(base.namedInsured, candidate.namedInsured);
3805
3900
  const insurer = mergeValue(base.insurer, candidate.insurer);
@@ -3808,6 +3903,22 @@ function mergeOperationalProfile(base, candidate, validNodeIds, validSpanIds) {
3808
3903
  const expirationDate = mergeValue(base.expirationDate, candidate.expirationDate);
3809
3904
  const retroactiveDate = mergeValue(base.retroactiveDate, candidate.retroactiveDate);
3810
3905
  const premium = mergeValue(base.premium, candidate.premium);
3906
+ const candidateDeclarationFacts = Array.isArray(candidate.declarationFacts) ? candidate.declarationFacts.map(mergeDeclarationFact).filter((fact) => Boolean(fact)) : [];
3907
+ const declarationFacts = [
3908
+ ...base.declarationFacts,
3909
+ sourceBackedDeclarationFact("policyNumber", policyNumber),
3910
+ sourceBackedDeclarationFact("namedInsured", namedInsured),
3911
+ sourceBackedDeclarationFact("insurer", insurer),
3912
+ sourceBackedDeclarationFact("broker", broker),
3913
+ sourceBackedDeclarationFact("effectiveDate", effectiveDate, "date"),
3914
+ sourceBackedDeclarationFact("expirationDate", expirationDate, "date"),
3915
+ sourceBackedDeclarationFact("premium", premium, "money"),
3916
+ ...candidateDeclarationFacts
3917
+ ].filter((fact) => Boolean(fact)).filter(
3918
+ (fact, index, rows) => rows.findIndex(
3919
+ (other) => other.field === fact.field && other.normalizedValue === fact.normalizedValue && other.sourceNodeIds.join(",") === fact.sourceNodeIds.join(",") && other.sourceSpanIds.join(",") === fact.sourceSpanIds.join(",")
3920
+ ) === index
3921
+ );
3811
3922
  const sourceValues = [
3812
3923
  policyNumber,
3813
3924
  namedInsured,
@@ -3912,6 +4023,7 @@ function mergeOperationalProfile(base, candidate, validNodeIds, validSpanIds) {
3912
4023
  ...base.sourceNodeIds,
3913
4024
  ...keepIds(candidate.sourceNodeIds, validNodeIds),
3914
4025
  ...sourceValues.flatMap((value) => value.sourceNodeIds),
4026
+ ...declarationFacts.flatMap((fact) => fact.sourceNodeIds),
3915
4027
  ...coverages.flatMap((coverage) => coverage.sourceNodeIds),
3916
4028
  ...coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceNodeIds)),
3917
4029
  ...parties.flatMap((party) => party.sourceNodeIds),
@@ -3921,6 +4033,7 @@ function mergeOperationalProfile(base, candidate, validNodeIds, validSpanIds) {
3921
4033
  ...base.sourceSpanIds,
3922
4034
  ...keepIds(candidate.sourceSpanIds, validSpanIds),
3923
4035
  ...sourceValues.flatMap((value) => value.sourceSpanIds),
4036
+ ...declarationFacts.flatMap((fact) => fact.sourceSpanIds),
3924
4037
  ...coverages.flatMap((coverage) => coverage.sourceSpanIds),
3925
4038
  ...coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceSpanIds)),
3926
4039
  ...parties.flatMap((party) => party.sourceSpanIds),
@@ -3949,6 +4062,7 @@ function mergeOperationalProfile(base, candidate, validNodeIds, validSpanIds) {
3949
4062
  expirationDate,
3950
4063
  retroactiveDate,
3951
4064
  premium,
4065
+ declarationFacts,
3952
4066
  coverages,
3953
4067
  parties,
3954
4068
  endorsementSupport,
@@ -4459,6 +4573,40 @@ var SourceBackedValueForPromptSchema = z23.object({
4459
4573
  sourceNodeIds: z23.array(z23.string()),
4460
4574
  sourceSpanIds: z23.array(z23.string())
4461
4575
  });
4576
+ var OperationalAddressForPromptSchema = z23.object({
4577
+ street1: z23.string().optional(),
4578
+ street2: z23.string().optional(),
4579
+ city: z23.string().optional(),
4580
+ state: z23.string().optional(),
4581
+ zip: z23.string().optional(),
4582
+ country: z23.string().optional(),
4583
+ formatted: z23.string().optional()
4584
+ });
4585
+ var OperationalDeclarationFactForPromptSchema = z23.object({
4586
+ field: z23.enum([
4587
+ "namedInsured",
4588
+ "mailingAddress",
4589
+ "dba",
4590
+ "entityType",
4591
+ "taxId",
4592
+ "additionalNamedInsured",
4593
+ "policyNumber",
4594
+ "insurer",
4595
+ "broker",
4596
+ "effectiveDate",
4597
+ "expirationDate",
4598
+ "premium",
4599
+ "other"
4600
+ ]),
4601
+ label: z23.string().optional(),
4602
+ value: z23.string(),
4603
+ normalizedValue: z23.string().optional(),
4604
+ valueKind: z23.enum(["string", "number", "date", "money", "address", "list", "unknown"]).optional(),
4605
+ address: OperationalAddressForPromptSchema.optional(),
4606
+ confidence: z23.enum(["low", "medium", "high"]).optional(),
4607
+ sourceNodeIds: z23.array(z23.string()),
4608
+ sourceSpanIds: z23.array(z23.string())
4609
+ });
4462
4610
  var OperationalProfilePromptSchema = z23.object({
4463
4611
  documentType: z23.enum(["policy", "quote"]).optional(),
4464
4612
  linesOfBusiness: z23.array(z23.string()).optional(),
@@ -4470,6 +4618,7 @@ var OperationalProfilePromptSchema = z23.object({
4470
4618
  expirationDate: SourceBackedValueForPromptSchema.optional(),
4471
4619
  retroactiveDate: SourceBackedValueForPromptSchema.optional(),
4472
4620
  premium: SourceBackedValueForPromptSchema.optional(),
4621
+ declarationFacts: z23.array(OperationalDeclarationFactForPromptSchema).optional(),
4473
4622
  coverages: z23.array(z23.object({
4474
4623
  name: z23.string(),
4475
4624
  coverageCode: z23.string().optional(),
@@ -5501,6 +5650,7 @@ function emptyOperationalProfile() {
5501
5650
  return {
5502
5651
  documentType: "policy",
5503
5652
  linesOfBusiness: ["UN"],
5653
+ declarationFacts: [],
5504
5654
  coverages: [],
5505
5655
  parties: [],
5506
5656
  endorsementSupport: [],
@@ -5518,6 +5668,7 @@ function buildOperationalProfilePrompt(sourceTree, sourceSpans) {
5518
5668
 
5519
5669
  Return only high-value operational facts needed for policy lists, Q&A, compliance, and certificate generation:
5520
5670
  - policy number, named insured, insurer/carrier/security, broker/producer, policy period, retroactive date, premium
5671
+ - source-backed declarationFacts for named-insured identity details: named insured, mailing address, DBA, entity type, tax ID/FEIN, additional named insureds, and other durable declaration-page identity facts
5521
5672
  - coverage units with their own nested limit terms, deductibles/retentions, retroactive dates, premiums, and form references
5522
5673
  - coverage type labels
5523
5674
 
@@ -5526,6 +5677,8 @@ Rules:
5526
5677
  - When citing an evidence entry, copy its sourceSpanId into the returned sourceSpanIds array.
5527
5678
  - If a value is not directly supported, omit it.
5528
5679
  - Prefer declarations, schedules, premium tables, and endorsement schedules over generic policy wording.
5680
+ - Put named-insured mailing address in declarationFacts[] with field "mailingAddress", valueKind "address", a user-facing value string, and structured address fields when present. Do not put producer, broker, insurer, mortgagee, loss-payee, or certificate-holder addresses in mailingAddress.
5681
+ - Put DBA or trade name in declarationFacts[] with field "dba"; entity/legal form in field "entityType"; FEIN/tax ID in field "taxId"; each additional named insured in field "additionalNamedInsured".
5529
5682
  - For effective, expiration, retroactive, and other date fields, return a normalized YYYY-MM-DD value when the source date is unambiguous, including month-name dates such as "20 Feb 2026". Do not emit fragmented date text such as "20 2 2026".
5530
5683
  - For broker/producer, extract the agency or company legal name, not the license role, credential, or type. In a block like "Bayshore Insurance Brokers, LLC" followed by "Surplus Lines Broker - CA License No. ...", broker.value must be "Bayshore Insurance Brokers, LLC"; the surplus-lines role and license number are not the broker name.
5531
5684
  - On declarations pages, treat "Item N" labels as section boundaries. Use Item 6 or equivalent coverage-schedule rows for coverage limits, deductibles, aggregate terms, and retroactive dates; do not merge Item 7 premium, Item 8 ERP, Item 9 producer, or Item 10 forms into Item 6 coverage facts.
@@ -5599,6 +5752,60 @@ function provenanceOf(value) {
5599
5752
  ...value.sourceNodeIds[0] ? { documentNodeId: value.sourceNodeIds[0] } : {}
5600
5753
  };
5601
5754
  }
5755
+ function provenanceFromIds(sourceSpanIds, sourceNodeIds) {
5756
+ if (sourceSpanIds.length === 0) return void 0;
5757
+ return {
5758
+ sourceSpanIds,
5759
+ ...sourceNodeIds[0] ? { documentNodeId: sourceNodeIds[0] } : {}
5760
+ };
5761
+ }
5762
+ function declarationFactsByField(profile, field) {
5763
+ return profile.declarationFacts.filter((fact) => fact.field === field && fact.value.trim());
5764
+ }
5765
+ function firstDeclarationFact(profile, field) {
5766
+ return declarationFactsByField(profile, field)[0];
5767
+ }
5768
+ function sourceBackedAddressFromFact(fact) {
5769
+ if (!fact?.address || fact.sourceSpanIds.length === 0) return void 0;
5770
+ const address = fact.address;
5771
+ if (!address.street1 || !address.city || !address.state || !address.zip) return void 0;
5772
+ return {
5773
+ street1: address.street1,
5774
+ street2: address.street2,
5775
+ city: address.city,
5776
+ state: address.state,
5777
+ zip: address.zip,
5778
+ country: address.country,
5779
+ ...provenanceFromIds(fact.sourceSpanIds, fact.sourceNodeIds)
5780
+ };
5781
+ }
5782
+ function normalizedEntityType(value) {
5783
+ const normalized = cleanText(value, "").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
5784
+ if (normalized === "inc" || normalized === "incorporated" || normalized === "c_corporation" || normalized === "s_corporation") {
5785
+ return "corporation";
5786
+ }
5787
+ if (normalized === "limited_liability_company") return "llc";
5788
+ if (normalized === "non_profit") return "nonprofit";
5789
+ return [
5790
+ "corporation",
5791
+ "llc",
5792
+ "partnership",
5793
+ "sole_proprietor",
5794
+ "joint_venture",
5795
+ "trust",
5796
+ "nonprofit",
5797
+ "municipality",
5798
+ "individual",
5799
+ "married_couple",
5800
+ "other"
5801
+ ].includes(normalized) ? normalized : void 0;
5802
+ }
5803
+ function declarationFieldName(fact) {
5804
+ if (fact.field === "mailingAddress") return "mailingAddress";
5805
+ if (fact.field === "taxId") return "fein";
5806
+ if (fact.field === "additionalNamedInsured") return "additionalNamedInsured";
5807
+ return fact.field;
5808
+ }
5602
5809
  function materializeDocument(params) {
5603
5810
  const profile = params.operationalProfile;
5604
5811
  const policyNumber = valueOf(profile, "policyNumber") ?? "Unknown";
@@ -5610,6 +5817,15 @@ function materializeDocument(params) {
5610
5817
  const insurerProvenance = provenanceOf(profile.insurer);
5611
5818
  const broker = valueOf(profile, "broker");
5612
5819
  const brokerProvenance = provenanceOf(profile.broker);
5820
+ const mailingAddressFact = firstDeclarationFact(profile, "mailingAddress");
5821
+ const insuredAddress = sourceBackedAddressFromFact(mailingAddressFact);
5822
+ const insuredDba = firstDeclarationFact(profile, "dba")?.value;
5823
+ const insuredEntityType = normalizedEntityType(firstDeclarationFact(profile, "entityType")?.value);
5824
+ const insuredFein = firstDeclarationFact(profile, "taxId")?.value;
5825
+ const additionalNamedInsureds = declarationFactsByField(profile, "additionalNamedInsured").flatMap((fact) => {
5826
+ const provenance = provenanceFromIds(fact.sourceSpanIds, fact.sourceNodeIds);
5827
+ return provenance ? [{ name: fact.value, ...provenance }] : [];
5828
+ });
5613
5829
  const coverages = profile.coverages.map((coverage) => ({
5614
5830
  name: coverage.name,
5615
5831
  coverageCode: coverage.coverageCode,
@@ -5660,6 +5876,11 @@ function materializeDocument(params) {
5660
5876
  security: carrier,
5661
5877
  insuredName,
5662
5878
  premium,
5879
+ insuredDba,
5880
+ insuredAddress,
5881
+ insuredEntityType,
5882
+ insuredFein,
5883
+ ...additionalNamedInsureds.length > 0 ? { additionalNamedInsureds } : {},
5663
5884
  ...insurerProvenance ? { insurer: { legalName: carrier, ...insurerProvenance } } : {},
5664
5885
  ...broker && brokerProvenance ? {
5665
5886
  brokerAgency: broker,
@@ -5683,7 +5904,12 @@ function materializeDocument(params) {
5683
5904
  profile.namedInsured ? { field: "namedInsured", value: profile.namedInsured.value, sourceSpanIds: profile.namedInsured.sourceSpanIds } : void 0,
5684
5905
  profile.insurer ? { field: "insurer", value: profile.insurer.value, sourceSpanIds: profile.insurer.sourceSpanIds } : void 0,
5685
5906
  profile.effectiveDate ? { field: "policyPeriodStart", value: profile.effectiveDate.value, sourceSpanIds: profile.effectiveDate.sourceSpanIds } : void 0,
5686
- profile.expirationDate ? { field: "policyPeriodEnd", value: profile.expirationDate.value, sourceSpanIds: profile.expirationDate.sourceSpanIds } : void 0
5907
+ profile.expirationDate ? { field: "policyPeriodEnd", value: profile.expirationDate.value, sourceSpanIds: profile.expirationDate.sourceSpanIds } : void 0,
5908
+ ...profile.declarationFacts.map((fact) => ({
5909
+ field: declarationFieldName(fact),
5910
+ value: fact.value,
5911
+ sourceSpanIds: fact.sourceSpanIds
5912
+ }))
5687
5913
  ].filter(Boolean)
5688
5914
  },
5689
5915
  supplementaryFacts: profile.endorsementSupport.map((item) => ({
@@ -13012,8 +13238,10 @@ export {
13012
13238
  MemorySourceStore,
13013
13239
  MissingInfoQuestionSchema,
13014
13240
  NamedInsuredSchema,
13241
+ OperationalAddressSchema,
13015
13242
  OperationalCoverageLineSchema,
13016
13243
  OperationalCoverageTermSchema,
13244
+ OperationalDeclarationFactSchema,
13017
13245
  OperationalEndorsementSupportSchema,
13018
13246
  OperationalPartySchema,
13019
13247
  PERSONAL_AUTO_USAGES,