@claritylabs/cl-sdk 3.2.9 → 3.2.10
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/README.md +6 -8
- package/dist/index.js +41 -230
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -230
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,6 @@ const extractor = createExtractor({
|
|
|
37
37
|
return { object: result.object, usage: result.usage };
|
|
38
38
|
},
|
|
39
39
|
concurrency: 3,
|
|
40
|
-
pageMapConcurrency: 3,
|
|
41
40
|
extractorConcurrency: 4,
|
|
42
41
|
formatConcurrency: 2,
|
|
43
42
|
reviewMode: "auto",
|
|
@@ -81,7 +80,7 @@ const extractor = createExtractor({ generateText, generateObject, sourceStore })
|
|
|
81
80
|
const result = await extractor.extract(pdfBase64, "policy-123", { sourceSpans });
|
|
82
81
|
```
|
|
83
82
|
|
|
84
|
-
When source spans are available, extraction returns `sourceTree`, `sourceSpans`, `operationalProfile`, `warnings`, `tokenUsage`, and `performanceReport`. The source tree is canonical for policy wording and hierarchy. The extractor
|
|
83
|
+
When source spans are available, extraction returns `sourceTree`, `sourceSpans`, `operationalProfile`, `warnings`, `tokenUsage`, and `performanceReport`. The source tree is canonical for policy wording and hierarchy. The extractor groups parser-provided page, title, table, row, and text spans into declarations, policy forms, endorsements, sections, and schedules without running a separate form-inventory, page-map, or source-tree-organizer model call. The operational profile model receives a bounded packet of high-value declaration, schedule, premium, producer, endorsement, and coverage evidence rather than the full document wording. The operational profile contains model-extracted policy metadata, parties, coverage units, nested coverage limit terms, deductibles/retentions, premiums, key dates, and endorsement-support facts, each with `sourceNodeIds` and `sourceSpanIds`. Source-backed identity records such as insurer, producer, contacts, named insured rows, endorsement parties, and standalone insured addresses must include non-empty `sourceSpanIds`. After extraction, a bounded model cleanup pass may keep, drop, or update existing coverage rows and terms by index; the SDK enforces the schema and rejects source IDs that are not present in the current source tree/spans. Endorsement schedules are modeled as whole endorsement coverage units with their own `limits[]` terms instead of unrelated flat rows like `Aggregate Limit`.
|
|
85
84
|
|
|
86
85
|
Store `result.sourceTree` in a retrievable node index and embed node `description` values for search. Keep `result.sourceSpans` as the exact PDF highlighting layer. `result.document` and its `documentOutline` remain compatibility projections for existing host screens; do not treat broad structured policy JSON as canonical extraction truth.
|
|
87
86
|
|
|
@@ -140,17 +139,16 @@ If your callback ignores those fields, the model will only see the text prompt.
|
|
|
140
139
|
|
|
141
140
|
## Model routing metadata
|
|
142
141
|
|
|
143
|
-
Every SDK model callback may receive `taskKind`, `budgetDiagnostics`, and `trace`. Hosts can use these provider-agnostic fields for cheap-first routing, fallback, and telemetry without the SDK hardcoding model names. Example task kinds include `
|
|
142
|
+
Every SDK model callback may receive `taskKind`, `budgetDiagnostics`, and `trace`. Hosts can use these provider-agnostic fields for cheap-first routing, fallback, and telemetry without the SDK hardcoding model names. Example task kinds include `extraction_operational_profile`, `extraction_coverage_cleanup`, `query_reason`, `application_extract_fields`, and `pce_impact_analysis`. `budgetDiagnostics` includes the resolved output-token budget, preferred task budget, truncation-risk warnings, and any model/provider caps that constrained the current subtask. `maxOutputTokens` is treated as a ceiling, not a default request size, so small classifier and lookup calls stay small even on models with large output windows. `trace` identifies the current source-backed or workflow call so host logs can show what was being generated instead of a generic model-call label.
|
|
144
143
|
|
|
145
144
|
## Bounded Agentic Workflows
|
|
146
145
|
|
|
147
146
|
CL-SDK uses deterministic scaffolding with agentic decision points rather than fixed all-tools-all-the-time chains:
|
|
148
147
|
|
|
149
|
-
-
|
|
150
|
-
-
|
|
151
|
-
- Referential coverage resolution
|
|
152
|
-
-
|
|
153
|
-
- Formatting skips the LLM cleanup pass for plain prose and formats long or noisy markdown/table/list content in parallel batches.
|
|
148
|
+
- Policy extraction requires caller-provided source spans and does not run the older form-inventory, page-map, focused-extractor, or source-tree-organizer model calls.
|
|
149
|
+
- Source-tree construction stays deterministic from parser spans; the model is used for the operational profile and optional coverage cleanup because those are end-user facts.
|
|
150
|
+
- Referential coverage resolution and application/query workflows still use bounded target-specific actions when those workflows need lookup or explanation steps.
|
|
151
|
+
- Formatting skips the LLM cleanup pass for plain prose and formats long or noisy markdown/table/list content in parallel batches outside the v3 source-span extraction path.
|
|
154
152
|
- `reviewMode: "auto"` skips the expensive LLM review pass when deterministic checks are clean and source spans are available. Use `"always"` for maximum review coverage or `"skip"` when the host owns quality review separately.
|
|
155
153
|
- Application processing plans optional backfill, context auto-fill, document search, batching, reply parsing, lookup, explanations, and next-batch email generation based on current active question state. Conditional fields that are not active are skipped until their parent answers trigger them.
|
|
156
154
|
|
package/dist/index.js
CHANGED
|
@@ -4583,36 +4583,6 @@ function spanPageEnd(span) {
|
|
|
4583
4583
|
function spanSourceUnit(span) {
|
|
4584
4584
|
return span.sourceUnit ?? span.metadata?.sourceUnit ?? span.metadata?.elementType;
|
|
4585
4585
|
}
|
|
4586
|
-
function formNumberFromText(value) {
|
|
4587
|
-
return cleanText(value, "").match(/\b[A-Z]{2,}(?:-[A-Z0-9]+)+\s+\d{2}\s+\d{2}\b/)?.[0]?.replace(/\s+/g, " ");
|
|
4588
|
-
}
|
|
4589
|
-
function editionDateFromFormNumber(formNumber) {
|
|
4590
|
-
const match = formNumber?.match(/\b(\d{2})\s+(\d{2})$/);
|
|
4591
|
-
return match ? `${match[1]}/${match[2]}` : void 0;
|
|
4592
|
-
}
|
|
4593
|
-
function pageTitleFromText(text, fallback) {
|
|
4594
|
-
const normalized = cleanText(text, fallback);
|
|
4595
|
-
const patterns = [
|
|
4596
|
-
/\bIMPORTANT NOTICE\s+[—-]\s+HOW TO REPORT A CLAIM\b/i,
|
|
4597
|
-
/\bPRIVACY NOTICE TO POLICYHOLDERS\b/i,
|
|
4598
|
-
/\bOFAC ADVISORY NOTICE\b/i,
|
|
4599
|
-
/\bTERRORISM RISK INSURANCE ACT\s*\(TRIA\)\s*DISCLOSURE AND REJECTION\b/i,
|
|
4600
|
-
/\bDECLARATIONS PAGE\b/i,
|
|
4601
|
-
/\bTECHNOLOGY ERRORS?\s*&\s*OMISSIONS AND CYBER LIABILITY INSURANCE POLICY\b/i,
|
|
4602
|
-
/\bTRADE OR ECONOMIC SANCTIONS LIMITATION\b/i,
|
|
4603
|
-
/\bFORMS? AND ENDORSEMENTS\b/i
|
|
4604
|
-
];
|
|
4605
|
-
for (const pattern of patterns) {
|
|
4606
|
-
const match = normalized.match(pattern)?.[0];
|
|
4607
|
-
if (match) return cleanText(match, fallback);
|
|
4608
|
-
}
|
|
4609
|
-
const endorsement = normalized.match(/\bENDORSEMENT\s+(?:NO\.?|NUMBER|#)\s*[A-Z0-9][A-Z0-9.-]*\b/i)?.[0];
|
|
4610
|
-
if (endorsement) return cleanText(endorsement, fallback);
|
|
4611
|
-
const firstSentence = normalized.split(/(?<=\.)\s+/)[0];
|
|
4612
|
-
if (/^page\s+\d+\b/i.test(firstSentence)) return fallback;
|
|
4613
|
-
if (firstSentence && firstSentence.length <= 120) return firstSentence.replace(/[.]$/, "");
|
|
4614
|
-
return fallback;
|
|
4615
|
-
}
|
|
4616
4586
|
function pageHeadingTitleFromText(text, fallback) {
|
|
4617
4587
|
const normalized = cleanText(text, "");
|
|
4618
4588
|
const headingText = normalized.replace(/^page\s+\d+\s*(?:\|\s*page\s*\|\s*page\s+\d+\s*\|?)?/i, "").slice(0, 700);
|
|
@@ -4632,194 +4602,9 @@ function pageHeadingTitleFromText(text, fallback) {
|
|
|
4632
4602
|
}
|
|
4633
4603
|
return fallback;
|
|
4634
4604
|
}
|
|
4635
|
-
function pageFormTypeFromText(text) {
|
|
4636
|
-
if (hasSubstantiveDeclarationsScheduleText(text)) return "declarations";
|
|
4637
|
-
if (/\b(declarations?\s+page|declarations?\s+schedule)\b/i.test(text)) return "declarations";
|
|
4638
|
-
if (/\b(endorsement\s+(?:no\.?|number|#)|this endorsement changes the policy|[A-Z]{2,}-END\s+\d{2,})\b/i.test(text)) return "endorsement";
|
|
4639
|
-
if (/\b(technology errors?\s*&?\s*omissions.*liability insurance policy|policy form|coverage form|insuring agreement|definitions?|exclusions?|conditions?)\b/i.test(text)) return "coverage";
|
|
4640
|
-
if (/\b(important notice|privacy notice|ofac advisory|terrorism risk insurance act|tria|trade or economic sanctions)\b/i.test(text)) return "notice";
|
|
4641
|
-
return "other";
|
|
4642
|
-
}
|
|
4643
4605
|
function hasSubstantiveDeclarationsScheduleText(text) {
|
|
4644
4606
|
return /\bitem\s+\d+\.?\s*(?:named insured|policy number|policy period|renewal|form of business|coverage parts?|limits?|premium|extended reporting|producer|forms? and endorsements?)\b/i.test(text) || /\bforms? and endorsements attached at inception\b/i.test(text) || /\bcoverage parts?,?\s+limits? of liability,?\s+deductibles?,?\s+and retroactive dates\b/i.test(text) || /\bannual premium\s*\(all coverage parts?\)\b/i.test(text) || /\berp option\b/i.test(text) || /\bproducer\b[\s\S]{0,240}\blicense\b/i.test(text);
|
|
4645
4607
|
}
|
|
4646
|
-
function administrativeFormTypeFromText(text) {
|
|
4647
|
-
if (hasSubstantiveDeclarationsScheduleText(text)) return void 0;
|
|
4648
|
-
if (/\b(important notice|privacy notice|ofac advisory|terrorism risk insurance act|tria|trade or economic sanctions|economic sanctions limitation|how to report a claim)\b/i.test(text)) {
|
|
4649
|
-
return "notice";
|
|
4650
|
-
}
|
|
4651
|
-
if (/\b(specimen policy|policy jacket|countersigned|countersignature|licensed resident agent|corporate secretary|president and ceo|application of insurance executed)\b/i.test(text)) {
|
|
4652
|
-
return "other";
|
|
4653
|
-
}
|
|
4654
|
-
return void 0;
|
|
4655
|
-
}
|
|
4656
|
-
function pageTextByNumber(sourceSpans) {
|
|
4657
|
-
const pageTexts = /* @__PURE__ */ new Map();
|
|
4658
|
-
const pageSpanTexts = /* @__PURE__ */ new Map();
|
|
4659
|
-
for (const span of sourceSpans) {
|
|
4660
|
-
const start = spanPageStart(span);
|
|
4661
|
-
if (typeof start !== "number") continue;
|
|
4662
|
-
const end = spanPageEnd(span) ?? start;
|
|
4663
|
-
for (let page = start; page <= end; page += 1) {
|
|
4664
|
-
if (spanSourceUnit(span) === "page") {
|
|
4665
|
-
pageSpanTexts.set(page, cleanText(span.text, ""));
|
|
4666
|
-
continue;
|
|
4667
|
-
}
|
|
4668
|
-
const existing = pageTexts.get(page) ?? "";
|
|
4669
|
-
if (existing.length < 4e3) pageTexts.set(page, cleanText([existing, span.text].filter(Boolean).join(" "), ""));
|
|
4670
|
-
}
|
|
4671
|
-
}
|
|
4672
|
-
return new Map([.../* @__PURE__ */ new Set([...pageTexts.keys(), ...pageSpanTexts.keys()])].map((page) => [
|
|
4673
|
-
page,
|
|
4674
|
-
pageSpanTexts.get(page) ?? pageTexts.get(page) ?? ""
|
|
4675
|
-
]));
|
|
4676
|
-
}
|
|
4677
|
-
function reconcileFormTypeWithSourceText(form, pageTexts) {
|
|
4678
|
-
const pages = [];
|
|
4679
|
-
const start = form.pageStart;
|
|
4680
|
-
const end = form.pageEnd ?? start;
|
|
4681
|
-
if (typeof start === "number" && typeof end === "number") {
|
|
4682
|
-
for (let page = start; page <= end; page += 1) pages.push(pageTexts.get(page) ?? "");
|
|
4683
|
-
}
|
|
4684
|
-
const text = cleanText([form.title, form.formNumber, ...pages].filter(Boolean).join(" "), "");
|
|
4685
|
-
const administrativeType = administrativeFormTypeFromText(text);
|
|
4686
|
-
if (administrativeType && form.formType !== administrativeType) return administrativeType;
|
|
4687
|
-
return form.formType;
|
|
4688
|
-
}
|
|
4689
|
-
function inferFormHintsFromSourceSpans(sourceSpans) {
|
|
4690
|
-
const pageTexts = pageTextByNumber(sourceSpans);
|
|
4691
|
-
if (pageTexts.size === 0) return [];
|
|
4692
|
-
const pageHints = [...pageTexts.keys()].sort((left, right) => left - right).map((page) => {
|
|
4693
|
-
const text = pageTexts.get(page) ?? "";
|
|
4694
|
-
const formNumber = formNumberFromText(text);
|
|
4695
|
-
return {
|
|
4696
|
-
formNumber,
|
|
4697
|
-
editionDate: editionDateFromFormNumber(formNumber),
|
|
4698
|
-
title: pageTitleFromText(text, `Page ${page}`),
|
|
4699
|
-
formType: pageFormTypeFromText(text),
|
|
4700
|
-
pageStart: page,
|
|
4701
|
-
pageEnd: page
|
|
4702
|
-
};
|
|
4703
|
-
});
|
|
4704
|
-
const merged = [];
|
|
4705
|
-
for (const hint of pageHints) {
|
|
4706
|
-
const previous = merged[merged.length - 1];
|
|
4707
|
-
const startsNewEndorsement = hint.formType === "endorsement" && /\bendorsement\s+(?:no\.?|number|#)\s*[A-Z0-9]|this endorsement changes the policy/i.test(hint.title ?? "");
|
|
4708
|
-
const canMerge = previous && previous.formType === hint.formType && previous.pageEnd !== void 0 && hint.pageStart === previous.pageEnd + 1 && (hint.formType === "declarations" || hint.formType === "coverage" || hint.formType === "endorsement" && !startsNewEndorsement);
|
|
4709
|
-
if (!canMerge) {
|
|
4710
|
-
merged.push(hint);
|
|
4711
|
-
continue;
|
|
4712
|
-
}
|
|
4713
|
-
previous.pageEnd = hint.pageEnd;
|
|
4714
|
-
previous.title = previous.title ?? hint.title;
|
|
4715
|
-
previous.formNumber = previous.formNumber ?? hint.formNumber;
|
|
4716
|
-
previous.editionDate = previous.editionDate ?? hint.editionDate;
|
|
4717
|
-
}
|
|
4718
|
-
return merged;
|
|
4719
|
-
}
|
|
4720
|
-
function normalizeFormHints(forms, sourceSpans) {
|
|
4721
|
-
const pageTexts = pageTextByNumber(sourceSpans);
|
|
4722
|
-
const provided = (forms ?? []).filter(
|
|
4723
|
-
(form) => typeof form.pageStart === "number" && typeof form.pageEnd === "number" && form.pageStart > 0 && form.pageEnd >= form.pageStart
|
|
4724
|
-
).map((form) => ({
|
|
4725
|
-
...form,
|
|
4726
|
-
formType: reconcileFormTypeWithSourceText(form, pageTexts),
|
|
4727
|
-
title: form.title ? cleanText(form.title, "") : void 0
|
|
4728
|
-
})).sort(
|
|
4729
|
-
(left, right) => (left.pageStart ?? Number.MAX_SAFE_INTEGER) - (right.pageStart ?? Number.MAX_SAFE_INTEGER) || (left.pageEnd ?? Number.MAX_SAFE_INTEGER) - (right.pageEnd ?? Number.MAX_SAFE_INTEGER)
|
|
4730
|
-
);
|
|
4731
|
-
return provided.length ? provided : inferFormHintsFromSourceSpans(sourceSpans);
|
|
4732
|
-
}
|
|
4733
|
-
function formHintForPage(forms, page) {
|
|
4734
|
-
return forms.find(
|
|
4735
|
-
(form) => typeof form.pageStart === "number" && typeof form.pageEnd === "number" && page >= form.pageStart && page <= form.pageEnd
|
|
4736
|
-
);
|
|
4737
|
-
}
|
|
4738
|
-
function titleFromFormHint(form, fallback) {
|
|
4739
|
-
if (form.formType === "declarations") return "Declarations";
|
|
4740
|
-
if (form.formType === "coverage") return "Policy Form";
|
|
4741
|
-
if (form.formType === "endorsement") return endorsementTitle([form.title, form.formNumber].filter(Boolean).join(" ")) ?? cleanText(form.title, fallback);
|
|
4742
|
-
return cleanText(form.title, fallback);
|
|
4743
|
-
}
|
|
4744
|
-
function formGroupConfig(form) {
|
|
4745
|
-
if (form.formType === "declarations") {
|
|
4746
|
-
return {
|
|
4747
|
-
kind: "page_group",
|
|
4748
|
-
title: "Declarations",
|
|
4749
|
-
description: "Declarations pages and schedules grouped from form inventory",
|
|
4750
|
-
organizer: "form_inventory_declarations_grouping"
|
|
4751
|
-
};
|
|
4752
|
-
}
|
|
4753
|
-
if (form.formType === "coverage") {
|
|
4754
|
-
return {
|
|
4755
|
-
kind: "form",
|
|
4756
|
-
title: "Policy Form",
|
|
4757
|
-
description: "Policy form pages grouped from form inventory",
|
|
4758
|
-
organizer: "form_inventory_policy_form_grouping"
|
|
4759
|
-
};
|
|
4760
|
-
}
|
|
4761
|
-
if (form.formType === "endorsement") {
|
|
4762
|
-
const title = titleFromFormHint(form, "Endorsement");
|
|
4763
|
-
return {
|
|
4764
|
-
kind: "endorsement",
|
|
4765
|
-
title,
|
|
4766
|
-
description: `${title} grouped from form inventory`,
|
|
4767
|
-
organizer: "form_inventory_endorsement_grouping"
|
|
4768
|
-
};
|
|
4769
|
-
}
|
|
4770
|
-
return void 0;
|
|
4771
|
-
}
|
|
4772
|
-
function applyFormInventoryHints(sourceTree, forms) {
|
|
4773
|
-
if (forms.length === 0) return sourceTree;
|
|
4774
|
-
const rootId = sourceTreeRootId(sourceTree);
|
|
4775
|
-
if (!rootId) return sourceTree;
|
|
4776
|
-
const byParent = nodesByParent(sourceTree);
|
|
4777
|
-
const children = (byParent.get(rootId) ?? []).filter((node) => node.kind !== "document").sort((left, right) => left.order - right.order);
|
|
4778
|
-
const rootPages = children.filter((node) => node.kind === "page" && typeof node.pageStart === "number");
|
|
4779
|
-
let nextTree = sourceTree.map((node) => {
|
|
4780
|
-
if (node.kind !== "page" || typeof node.pageStart !== "number") return node;
|
|
4781
|
-
const form = formHintForPage(forms, node.pageStart);
|
|
4782
|
-
if (!form) return node;
|
|
4783
|
-
const isStartPage = form.pageStart === node.pageStart;
|
|
4784
|
-
const shouldRetitle = isStartPage && form.formType !== "other";
|
|
4785
|
-
return {
|
|
4786
|
-
...node,
|
|
4787
|
-
title: shouldRetitle ? titleFromFormHint(form, node.title) : node.title,
|
|
4788
|
-
metadata: {
|
|
4789
|
-
...node.metadata,
|
|
4790
|
-
formInventoryHint: {
|
|
4791
|
-
formType: form.formType,
|
|
4792
|
-
formNumber: form.formNumber,
|
|
4793
|
-
title: form.title,
|
|
4794
|
-
pageStart: form.pageStart,
|
|
4795
|
-
pageEnd: form.pageEnd
|
|
4796
|
-
}
|
|
4797
|
-
}
|
|
4798
|
-
};
|
|
4799
|
-
});
|
|
4800
|
-
const claimed = /* @__PURE__ */ new Set();
|
|
4801
|
-
for (const form of forms) {
|
|
4802
|
-
const config = formGroupConfig(form);
|
|
4803
|
-
const pageStart2 = form.pageStart;
|
|
4804
|
-
const pageEnd2 = form.pageEnd;
|
|
4805
|
-
if (!config || typeof pageStart2 !== "number" || typeof pageEnd2 !== "number") continue;
|
|
4806
|
-
const childIds = rootPages.filter(
|
|
4807
|
-
(page) => !claimed.has(page.id) && typeof page.pageStart === "number" && page.pageStart >= pageStart2 && page.pageStart <= pageEnd2
|
|
4808
|
-
).map((page) => page.id);
|
|
4809
|
-
if (childIds.length === 0) continue;
|
|
4810
|
-
nextTree = groupAdjacentChildren({
|
|
4811
|
-
sourceTree: nextTree,
|
|
4812
|
-
children,
|
|
4813
|
-
childIds,
|
|
4814
|
-
kind: config.kind,
|
|
4815
|
-
title: config.title,
|
|
4816
|
-
description: config.description,
|
|
4817
|
-
organizer: config.organizer
|
|
4818
|
-
});
|
|
4819
|
-
childIds.forEach((id) => claimed.add(id));
|
|
4820
|
-
}
|
|
4821
|
-
return normalizeDocumentSourceTreePaths(nextTree);
|
|
4822
|
-
}
|
|
4823
4608
|
function looksLikeDeclarationsStart(node) {
|
|
4824
4609
|
const title = cleanText(node.title, "");
|
|
4825
4610
|
const text = sourceNodeText(node);
|
|
@@ -4830,13 +4615,13 @@ function looksLikeDeclarationsStart(node) {
|
|
|
4830
4615
|
}
|
|
4831
4616
|
function looksLikeDeclarationsContinuation(node) {
|
|
4832
4617
|
const text = sourceNodeText(node);
|
|
4833
|
-
return looksLikeDeclarationsStart(node) || /\b(item\s+\d+\.|coverage part|each claim limit|aggregate limit|retroactive date|self-insured retention|premium|payment plan|producer|broker|forms? and endorsements?|extended reporting period|discovery period)\b/i.test(text);
|
|
4618
|
+
return looksLikeDeclarationsStart(node) || /\b(item\s+\d+\.|coverage part|limits?,?\s+sub-limits?|each claim limit|aggregate limit|retroactive date|self-insured retention|premium|payment plan|producer|broker|forms? and endorsements?|attached at inception|extended reporting period|discovery period)\b/i.test(text) || /\b(these declarations|policy form|[A-Z]{2,}-END\s+\d{3}|endorsement\s+(?:no\.?|number|#)?\s*\d+)\b/i.test(text);
|
|
4834
4619
|
}
|
|
4835
4620
|
function looksLikePolicyFormStart(node) {
|
|
4836
4621
|
const text = sourceNodeText(node);
|
|
4837
4622
|
const excerpt = cleanText(node.textExcerpt, "");
|
|
4838
4623
|
if (isAdministrativeNoticeNode(node) || looksLikeDeclarationsStart(node)) return false;
|
|
4839
|
-
return /\bpolicy form\b/i.test(node.title) || /^policy\s+form\b/i.test(excerpt) || /\btechnology errors?\s*&?\s*omissions\b/i.test(text) && /\bplease read this entire policy carefully\b/i.test(text) || /\bform\s+[A-Z]{2,}-[A-Z0-9-]+\s+\d{2}\s+\d{2}\b/i.test(text);
|
|
4624
|
+
return /\bpolicy form\b/i.test(node.title) || /^policy\s+form\b/i.test(excerpt) || /\btechnology errors?\s*&?\s*omissions\b/i.test(text) && /\bplease read this entire policy carefully\b/i.test(text) || /\bsection\s+[IVX0-9]+\s*[—-]\s*(insuring agreements?|definitions?|exclusions?|conditions?)\b/i.test(text) || /\bform\s+[A-Z]{2,}-[A-Z0-9-]+\s+\d{2}\s+\d{2}\b/i.test(text);
|
|
4840
4625
|
}
|
|
4841
4626
|
function looksLikePolicyFormContinuation(node) {
|
|
4842
4627
|
const text = sourceNodeText(node);
|
|
@@ -5598,25 +5383,51 @@ function isOperationalEvidenceAnchor(span) {
|
|
|
5598
5383
|
if (/\$[\d,.]+|[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}|[0-9]{1,2}\s+[A-Za-z]{3,9}\s+[0-9]{4}/.test(text)) return true;
|
|
5599
5384
|
return false;
|
|
5600
5385
|
}
|
|
5386
|
+
function operationalEvidencePages(sourceSpans) {
|
|
5387
|
+
const scores = /* @__PURE__ */ new Map();
|
|
5388
|
+
for (const span of sourceSpans) {
|
|
5389
|
+
const page = spanPageStart(span);
|
|
5390
|
+
if (typeof page !== "number") continue;
|
|
5391
|
+
const text = cleanText([span.text, span.formNumber, spanSourceUnit(span)].filter(Boolean).join(" "), "");
|
|
5392
|
+
if (!text) continue;
|
|
5393
|
+
let score = Math.max(0, operationalEvidenceScore(span));
|
|
5394
|
+
if (/\bdeclarations?\s+(page|schedule)?\b/i.test(text)) score += 24;
|
|
5395
|
+
if (/\bitem\s+\d+\.?\s*(?:named insured|policy number|policy period|coverage parts?|limits?|premium|producer|forms? and endorsements?)\b/i.test(text)) score += 20;
|
|
5396
|
+
if (/\bcoverage parts?,?\s+limits? of liability,?\s+deductibles?,?\s+and retroactive dates\b/i.test(text)) score += 24;
|
|
5397
|
+
if (/\b(policy\s*(number|period|term)|effective date|expiration date|expiry date|named insured|insurer|carrier|security)\b/i.test(text)) score += 12;
|
|
5398
|
+
if (/\b(premium|total due|tax|fee|producer|broker)\b/i.test(text)) score += 10;
|
|
5399
|
+
if (/\b(endorsement\s+(?:no\.?|number|#)?\s*[A-Z0-9]|attached at inception|forms? and endorsements?)\b/i.test(text)) score += 8;
|
|
5400
|
+
if (/\b(definitions?|exclusions?|conditions?|duties in the event|action against|cancellation by)\b/i.test(text)) score -= 12;
|
|
5401
|
+
if (score > 0) scores.set(page, (scores.get(page) ?? 0) + score);
|
|
5402
|
+
}
|
|
5403
|
+
return new Set(
|
|
5404
|
+
[...scores.entries()].filter(([, score]) => score >= 18).sort((left, right) => right[1] - left[1] || left[0] - right[0]).slice(0, 12).map(([page]) => page)
|
|
5405
|
+
);
|
|
5406
|
+
}
|
|
5601
5407
|
function operationalProfileEvidence(sourceTree, sourceSpans) {
|
|
5602
5408
|
const sorted = [...sourceSpans].sort(
|
|
5603
5409
|
(left, right) => (spanPageStart(left) ?? Number.MAX_SAFE_INTEGER) - (spanPageStart(right) ?? Number.MAX_SAFE_INTEGER) || (left.location?.charStart ?? Number.MAX_SAFE_INTEGER) - (right.location?.charStart ?? Number.MAX_SAFE_INTEGER) || left.id.localeCompare(right.id)
|
|
5604
5410
|
);
|
|
5411
|
+
const selectedPages = operationalEvidencePages(sorted);
|
|
5605
5412
|
const selected = /* @__PURE__ */ new Set();
|
|
5606
5413
|
const selectedTableIds = /* @__PURE__ */ new Set();
|
|
5607
5414
|
for (let index = 0; index < sorted.length; index += 1) {
|
|
5608
|
-
const
|
|
5415
|
+
const span = sorted[index];
|
|
5416
|
+
const score = operationalEvidenceScore(span);
|
|
5609
5417
|
if (score < 8) continue;
|
|
5610
|
-
if (!isOperationalEvidenceAnchor(
|
|
5611
|
-
const
|
|
5612
|
-
if (
|
|
5613
|
-
const
|
|
5614
|
-
|
|
5418
|
+
if (!isOperationalEvidenceAnchor(span)) continue;
|
|
5419
|
+
const page = spanPageStart(span);
|
|
5420
|
+
if (selectedPages.size > 0 && typeof page === "number" && !selectedPages.has(page) && score < 30) continue;
|
|
5421
|
+
const tableId2 = spanTableId(span);
|
|
5422
|
+
if (tableId2 && !isTableCellSpan(span)) selectedTableIds.add(tableId2);
|
|
5423
|
+
const neighborWindow = score >= 24 ? 2 : 1;
|
|
5424
|
+
for (let offset = -neighborWindow; offset <= neighborWindow; offset += 1) {
|
|
5615
5425
|
const neighborIndex = index + offset;
|
|
5616
5426
|
const neighbor = sorted[neighborIndex];
|
|
5617
5427
|
if (!neighbor || spanPageStart(neighbor) !== page) continue;
|
|
5428
|
+
if (selectedPages.size > 0 && typeof page === "number" && !selectedPages.has(page) && operationalEvidenceScore(neighbor) < 30) continue;
|
|
5618
5429
|
const neighborText = cleanText(neighbor.text, "");
|
|
5619
|
-
if (!neighborText || neighborText.length >
|
|
5430
|
+
if (!neighborText || neighborText.length > 3e3) continue;
|
|
5620
5431
|
selected.add(neighborIndex);
|
|
5621
5432
|
}
|
|
5622
5433
|
}
|
|
@@ -5625,7 +5436,7 @@ function operationalProfileEvidence(sourceTree, sourceSpans) {
|
|
|
5625
5436
|
const tableId2 = spanTableId(span);
|
|
5626
5437
|
if (!tableId2 || !selectedTableIds.has(tableId2) || isTableCellSpan(span)) return;
|
|
5627
5438
|
const text = cleanText(span.text, "");
|
|
5628
|
-
if (text && text.length <=
|
|
5439
|
+
if (text && text.length <= 3e3) selected.add(index);
|
|
5629
5440
|
});
|
|
5630
5441
|
}
|
|
5631
5442
|
const nodeIdsBySpanId = sourceNodeIdsBySpanId(sourceTree);
|
|
@@ -5643,12 +5454,12 @@ function operationalProfileEvidence(sourceTree, sourceSpans) {
|
|
|
5643
5454
|
pageEnd: spanPageEnd(span),
|
|
5644
5455
|
sourceUnit: spanSourceUnit(span),
|
|
5645
5456
|
formNumber: span.formNumber,
|
|
5646
|
-
text: text.slice(0, span.sourceUnit === "page" ?
|
|
5457
|
+
text: text.slice(0, span.sourceUnit === "page" ? 900 : 700)
|
|
5647
5458
|
}];
|
|
5648
5459
|
});
|
|
5649
5460
|
const detailEntries = entries.filter((entry) => entry.sourceUnit !== "page");
|
|
5650
5461
|
const pageEntries = entries.filter((entry) => entry.sourceUnit === "page");
|
|
5651
|
-
return [...detailEntries, ...pageEntries
|
|
5462
|
+
return [...detailEntries.slice(0, 80), ...pageEntries.slice(0, 8)];
|
|
5652
5463
|
}
|
|
5653
5464
|
function sourceTreeRootId(sourceTree) {
|
|
5654
5465
|
return sourceTree.find((node) => node.kind === "document")?.id;
|
|
@@ -5697,7 +5508,7 @@ Rules:
|
|
|
5697
5508
|
- 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.
|
|
5698
5509
|
- 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.
|
|
5699
5510
|
- 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.
|
|
5700
|
-
- Forms-and-endorsements schedules are
|
|
5511
|
+
- Forms-and-endorsements schedules are form schedule evidence, not coverage limits. Do not turn form schedule rows into coverage units unless the row also states a coverage-specific limit or deductible.
|
|
5701
5512
|
- 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.
|
|
5702
5513
|
- 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.
|
|
5703
5514
|
- Use the declaration coverage name for declaration/core schedule rows. Use the endorsement title or endorsement schedule coverage name for endorsement rows, and include formNumber and endorsementNumber when source-backed.
|
|
@@ -5936,8 +5747,8 @@ async function cleanupOperationalCoverageSchedules(params) {
|
|
|
5936
5747
|
}
|
|
5937
5748
|
async function runSourceTreeExtraction(params) {
|
|
5938
5749
|
const sourceSpans = normalizeSourceSpans(params.sourceSpans);
|
|
5939
|
-
const formHints =
|
|
5940
|
-
let sourceTree = applySemanticPageGrouping(
|
|
5750
|
+
const formHints = [];
|
|
5751
|
+
let sourceTree = applySemanticPageGrouping(buildDocumentSourceTree(sourceSpans, params.id));
|
|
5941
5752
|
const warnings = [];
|
|
5942
5753
|
let modelCalls = 0;
|
|
5943
5754
|
let callsWithUsage = 0;
|