@claritylabs/cl-sdk 3.2.7 → 3.2.9

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
@@ -3576,16 +3576,6 @@ var OPERATIONAL_COVERAGE_TERM_KINDS2 = [
3576
3576
  "other"
3577
3577
  ];
3578
3578
  var OperationalCoverageTermKindSchema = z21.enum(OPERATIONAL_COVERAGE_TERM_KINDS2);
3579
- var CleanupTermSchema = z21.object({
3580
- kind: OperationalCoverageTermKindSchema,
3581
- label: z21.string(),
3582
- value: z21.string(),
3583
- amount: z21.number().nullable().optional(),
3584
- appliesTo: z21.string().nullable().optional(),
3585
- sourceNodeIds: z21.array(z21.string()).optional(),
3586
- sourceSpanIds: z21.array(z21.string()).optional(),
3587
- reason: z21.string().optional()
3588
- });
3589
3579
  var OperationalProfileCleanupSchema = z21.object({
3590
3580
  coverageDecisions: z21.array(z21.object({
3591
3581
  coverageIndex: z21.number().int().nonnegative(),
@@ -3609,8 +3599,7 @@ var OperationalProfileCleanupSchema = z21.object({
3609
3599
  appliesTo: z21.string().nullable().optional(),
3610
3600
  sourceNodeIds: z21.array(z21.string()).optional(),
3611
3601
  sourceSpanIds: z21.array(z21.string()).optional()
3612
- })).optional(),
3613
- termAdditions: z21.array(CleanupTermSchema).optional()
3602
+ })).optional()
3614
3603
  })).default([]),
3615
3604
  warnings: z21.array(z21.string()).default([])
3616
3605
  });
@@ -3618,7 +3607,6 @@ var CLEANUP_CANDIDATE_ID_LIMIT = 12;
3618
3607
  var CLEANUP_SOURCE_NODE_LIMIT = 90;
3619
3608
  var CLEANUP_SIBLING_WINDOW = 4;
3620
3609
  var CLEANUP_KEYWORD = /\b(coverage|limit|liability|deductible|retention|retroactive|premium|aggregate|sublimit|sub-limit|claim|occurrence|loss|proceeding|endorsement|declarations?)\b|\$[0-9]/i;
3621
- var CLEANUP_CONTINUATION_KEYWORD = /\b(coverage part|limit of liability|deductible|retention|retroactive date|aggregate|sublimit|sub-limit|each claim|each occurrence|each loss|each proceeding|coinsurance)\b|\$[0-9]/i;
3622
3610
  function compactNode(node, maxText = 700) {
3623
3611
  return {
3624
3612
  id: node.id,
@@ -3747,15 +3735,11 @@ function selectCoverageCleanupNodes(sourceTree, coverages) {
3747
3735
  const children = childrenByParent.get(selectedNode.id) ?? [];
3748
3736
  for (const child of children.slice(0, 24)) addNode(child, 760);
3749
3737
  }
3750
- const continuationPages = new Set([...coveragePages].map((page) => page + 1));
3751
3738
  for (const node of sourceTree) {
3752
3739
  if (node.kind === "document") continue;
3753
- if (typeof node.pageStart !== "number") continue;
3754
- const samePage = coveragePages.has(node.pageStart);
3755
- const nearbyContinuationPage = continuationPages.has(node.pageStart);
3756
- if (!samePage && !nearbyContinuationPage) continue;
3740
+ if (!node.pageStart || !coveragePages.has(node.pageStart)) continue;
3757
3741
  const text = nodeTextForSelection(node);
3758
- if (CLEANUP_KEYWORD.test(text) || nodeTextMatchesCoverage(node, coverageTerms) || nearbyContinuationPage && CLEANUP_CONTINUATION_KEYWORD.test(text)) {
3742
+ if (CLEANUP_KEYWORD.test(text) || nodeTextMatchesCoverage(node, coverageTerms)) {
3759
3743
  addNode(node, 600);
3760
3744
  }
3761
3745
  }
@@ -3769,7 +3753,7 @@ function buildOperationalProfileCleanupPrompt(sourceTree, profile, options = {})
3769
3753
  const coverageEntries = coverageCleanupEntries(profile, options.coverageIndexes);
3770
3754
  const nodes = selectCoverageCleanupNodes(sourceTree, coverageEntries.map((entry) => entry.coverage)).map((node) => compactNode(
3771
3755
  node,
3772
- node.kind === "page" || node.kind === "page_group" ? 520 : node.kind === "table_row" || node.kind === "table_cell" ? 520 : 360
3756
+ node.kind === "page" || node.kind === "page_group" ? 260 : node.kind === "table_row" || node.kind === "table_cell" ? 520 : 360
3773
3757
  ));
3774
3758
  const candidate = {
3775
3759
  documentType: profile.documentType,
@@ -3793,24 +3777,20 @@ Projection defects to look for:
3793
3777
  - Item references such as "shown in Item 7" or bare item numbers treated as money amounts.
3794
3778
  - Policy wording, exclusions, or unsupported prose copied into operational limit/deductible fields.
3795
3779
  - Header/value splits where "Limit of Liability", "Deductible", "Retroactive Date", "Aggregate", "Each Claim", or similar terms are attached to the wrong coverage row.
3796
- - Collapsed combined bases where one candidate term says "Each Claim / Aggregate", "Each Loss / Aggregate", "Each Proceeding / Aggregate", or a continuation line supplies a separate policy aggregate, sub-limit, deductible, retention, retroactive date, or coinsurance term.
3797
3780
  - Repeated schedule headings projected as separate coverages when they only introduce the next coverage group.
3798
- - Generic policy form rows projected as scheduled coverages when their values only say "as stated in Item...", "shown in the Declarations", or similar cross-references instead of actual scheduled amounts.
3799
3781
 
3800
3782
  Rules:
3801
3783
  - Use internal reasoning, but return JSON decisions only.
3802
- - Do not invent policy facts. Keep, drop, or update only existing coverageIndex and termIndex entries, except for source-backed termAdditions on an existing coverage.
3784
+ - Do not invent policy facts. Keep, drop, or update only existing coverageIndex and termIndex entries.
3803
3785
  - Use sourceNodeIds and sourceSpanIds only from the provided source nodes or from the existing candidate entry.
3804
3786
  - Prefer dropping a malformed fact over speculative rewriting.
3805
3787
  - Keep a coverage when it is a real operational coverage/benefit even if only one term needs cleanup.
3788
+ - Never drop a declaration or schedule coverage row that names a coverage and states policy-specific amounts, dates, deductibles, retentions, premiums, or coverage terms. Repair its terms instead.
3806
3789
  - When changing a term's semantic meaning, set kind to the corrected normalized term kind.
3807
- - Do not add new coverage rows.
3808
- - Add termAdditions only when a provided source node directly supports the missing term and the candidate already has the correct coverage row.
3809
- - When replacing one combined term with split terms, drop the combined term and add one term per basis. For example, "$1,000,000 Each Claim / Aggregate" should become one each_claim_limit term and one aggregate_limit term, both with value "$1,000,000".
3810
- - When a schedule continues onto the next page before the next item marker, attach continuation terms such as "Aggregate", "Policy Aggregate", coinsurance, deductible, or retroactive date to the previous coverage row.
3811
- - Drop a coverage row when it is only generic policy wording that points back to a declarations item or schedule and does not itself state policy-specific limits, deductibles, retentions, premiums, dates, or coverage names.
3790
+ - Do not add new coverage rows or new terms; this pass cleans the existing projection.
3791
+ - If one existing term combines multiple real limit bases, such as "Each Claim / Aggregate", keep the combined term unless another existing term already represents the other basis. Do not relabel it to only one basis and lose information.
3812
3792
  - Include every JSON key in each decision. Use null for scalar fields you are not changing and [] for source ID lists you are not changing.
3813
- - For each coverage decision, always include termDecisions and termAdditions. Use [] when no existing terms need cleanup or no new terms are needed.
3793
+ - For each coverage decision, always include termDecisions. Use [] when no terms need cleanup.
3814
3794
  - Keep reasons concise and factual.
3815
3795
 
3816
3796
  Candidate projection:
@@ -3951,50 +3931,9 @@ function applyTermCleanupDecision(term, decision, validNodeIds, validSpanIds) {
3951
3931
  }
3952
3932
  return next;
3953
3933
  }
3954
- function termAdditionTouches(addition, predicate) {
3955
- return predicate({
3956
- kind: addition.kind,
3957
- label: cleanProfileValue(addition.label) ?? "",
3958
- value: cleanProfileValue(addition.value) ?? ""
3959
- });
3960
- }
3961
3934
  function termDecisionsTouch(coverage, decisions, predicate) {
3962
3935
  return decisions.filter((decision) => decision.action !== "keep").some((decision) => termDecisionTouches(coverage, decision, predicate));
3963
3936
  }
3964
- function termAdditionsTouch(additions, predicate) {
3965
- return additions.some((addition) => termAdditionTouches(addition, predicate));
3966
- }
3967
- function termKey(term) {
3968
- return [
3969
- term.kind,
3970
- cleanProfileValue(term.label)?.toLowerCase(),
3971
- cleanProfileValue(term.value)?.toLowerCase()
3972
- ].join("|");
3973
- }
3974
- function applyTermAddition(addition, validNodeIds, validSpanIds) {
3975
- const label = cleanProfileValue(addition.label);
3976
- const value = cleanProfileValue(addition.value);
3977
- if (!label || !value) return void 0;
3978
- const sourceNodeIds = validIds(addition.sourceNodeIds, validNodeIds);
3979
- const sourceSpanIds = validIds(addition.sourceSpanIds, validSpanIds);
3980
- if (sourceNodeIds.length === 0 && sourceSpanIds.length === 0) return void 0;
3981
- const term = {
3982
- kind: addition.kind,
3983
- label,
3984
- value,
3985
- sourceNodeIds,
3986
- sourceSpanIds
3987
- };
3988
- if (typeof addition.amount === "number" && Number.isFinite(addition.amount)) {
3989
- term.amount = addition.amount;
3990
- } else if (term.kind !== "retroactive_date") {
3991
- const amount = amountFromOperationalValue(value);
3992
- if (amount !== void 0) term.amount = amount;
3993
- }
3994
- const appliesTo = cleanProfileValue(addition.appliesTo);
3995
- if (appliesTo) term.appliesTo = appliesTo;
3996
- return term;
3997
- }
3998
3937
  function applyCoverageCleanupDecision(coverage, decision, validNodeIds, validSpanIds) {
3999
3938
  if (!decision || decision.action === "keep") return coverage;
4000
3939
  if (decision.action === "drop") return void 0;
@@ -4025,31 +3964,23 @@ function applyCoverageCleanupDecision(coverage, decision, validNodeIds, validSpa
4025
3964
  const termDecisions = (decision.termDecisions ?? []).filter((termDecision) => termDecision.termIndex < coverage.limits.length);
4026
3965
  const termDecisionByIndex = new Map(termDecisions.map((termDecision) => [termDecision.termIndex, termDecision]));
4027
3966
  next.limits = coverage.limits.map((term, index) => applyTermCleanupDecision(term, termDecisionByIndex.get(index), validNodeIds, validSpanIds)).filter((term) => Boolean(term));
4028
- const termAdditions = (decision.termAdditions ?? []).map((addition) => applyTermAddition(addition, validNodeIds, validSpanIds)).filter((term) => Boolean(term));
4029
- const existingTermKeys = new Set(next.limits.map(termKey));
4030
- for (const term of termAdditions) {
4031
- const key = termKey(term);
4032
- if (existingTermKeys.has(key)) continue;
4033
- next.limits.push(term);
4034
- existingTermKeys.add(key);
4035
- }
4036
- if (termDecisions.length > 0 || termAdditions.length > 0) {
4037
- if (decision.limit == null && (termDecisionsTouch(coverage, termDecisions, isLimitTerm) || termAdditionsTouch(termAdditions, isLimitTerm))) {
3967
+ if (termDecisions.length > 0) {
3968
+ if (decision.limit == null && termDecisionsTouch(coverage, termDecisions, isLimitTerm)) {
4038
3969
  const value = primaryLimitFromTerms(next.limits);
4039
3970
  if (value) next.limit = value;
4040
3971
  else delete next.limit;
4041
3972
  }
4042
- if (decision.deductible == null && (termDecisionsTouch(coverage, termDecisions, isDeductibleTerm) || termAdditionsTouch(termAdditions, isDeductibleTerm))) {
3973
+ if (decision.deductible == null && termDecisionsTouch(coverage, termDecisions, isDeductibleTerm)) {
4043
3974
  const value = deductibleFromTerms(next.limits);
4044
3975
  if (value) next.deductible = value;
4045
3976
  else delete next.deductible;
4046
3977
  }
4047
- if (decision.premium == null && (termDecisionsTouch(coverage, termDecisions, isPremiumTerm) || termAdditionsTouch(termAdditions, isPremiumTerm))) {
3978
+ if (decision.premium == null && termDecisionsTouch(coverage, termDecisions, isPremiumTerm)) {
4048
3979
  const value = premiumFromTerms(next.limits);
4049
3980
  if (value) next.premium = value;
4050
3981
  else delete next.premium;
4051
3982
  }
4052
- if (decision.retroactiveDate == null && (termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm) || termAdditionsTouch(termAdditions, isRetroactiveDateTerm))) {
3983
+ if (decision.retroactiveDate == null && termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm)) {
4053
3984
  const value = retroactiveDateFromTerms(next.limits);
4054
3985
  if (value) next.retroactiveDate = value;
4055
3986
  else delete next.retroactiveDate;
@@ -5389,6 +5320,7 @@ Rules:
5389
5320
  - A coverage schedule row's coverage name should come from the "Coverage Part" or equivalent row label. Limit, deductible, aggregate, sublimit, retention, and retroactive-date values belong as nested terms under that coverage, not in the coverage title.
5390
5321
  - If a coverage schedule continues onto the next page before the next item marker, include the continuation rows in the same coverage or declaration item.
5391
5322
  - If one schedule row or continuation row states the same amount with multiple bases, such as "$1,000,000 Each Claim / Aggregate", return separate limit terms for each basis using the same value instead of one combined "Each Claim / Aggregate" term.
5323
+ - LiteParse text can fragment visual table cells into adjacent lines. Before extracting coverage terms, mentally join adjacent lines in the same declaration item or schedule row. For example, "$2,000,000 Policy Each Claim" followed immediately by "Aggregate" means "$2,000,000 Policy Aggregate"; a line ending with "/" followed by "Aggregate ..." means the limit cell continues, not a new coverage.
5392
5324
  - Forms-and-endorsements schedules are operational form inventory evidence, not coverage limits. Do not turn form schedule rows into coverage units unless the row also states a coverage-specific limit or deductible.
5393
5325
  - Keep each coverage unit tied to one evidence scope: a declaration/core schedule row, a core policy form section, or one specific endorsement schedule. Do not merge declaration facts and endorsement schedule facts into the same coverage unit, even when they use the same coverage name.
5394
5326
  - If the declarations schedule and an endorsement schedule both list Network Security, Social Engineering Fraud, Regulatory Proceedings, or another same-named coverage, return separate coverage units for each supported source scope.