@claritylabs/cl-sdk 1.3.5 → 1.3.6
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.js +13 -177
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -177
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6436,113 +6436,6 @@ Your task:
|
|
|
6436
6436
|
Return JSON only.`;
|
|
6437
6437
|
}
|
|
6438
6438
|
|
|
6439
|
-
// src/extraction/heuristics.ts
|
|
6440
|
-
function looksReferential(value) {
|
|
6441
|
-
if (typeof value !== "string") return false;
|
|
6442
|
-
const normalized = value.toLowerCase();
|
|
6443
|
-
return normalized.includes("shown in the declarations") || normalized.includes("shown in declarations") || normalized.includes("shown in the schedule") || normalized.includes("as stated") || normalized.includes("if applicable");
|
|
6444
|
-
}
|
|
6445
|
-
function looksCoveredReasonSection(section) {
|
|
6446
|
-
const title = String(section.title ?? "").toLowerCase();
|
|
6447
|
-
const type = String(section.type ?? "").toLowerCase();
|
|
6448
|
-
return type === "covered_reason" || title.includes("covered cause") || title.includes("covered reason") || title.includes("covered peril");
|
|
6449
|
-
}
|
|
6450
|
-
|
|
6451
|
-
// src/extraction/referential-workflow.ts
|
|
6452
|
-
function normalizeText2(value) {
|
|
6453
|
-
return typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
6454
|
-
}
|
|
6455
|
-
function containsTarget(value, target) {
|
|
6456
|
-
const normalizedValue = normalizeText2(value);
|
|
6457
|
-
return Boolean(normalizedValue && target && normalizedValue.includes(target));
|
|
6458
|
-
}
|
|
6459
|
-
function pageRangeFrom(startPage, endPage) {
|
|
6460
|
-
if (typeof startPage !== "number" || !Number.isFinite(startPage) || startPage <= 0) {
|
|
6461
|
-
return void 0;
|
|
6462
|
-
}
|
|
6463
|
-
const normalizedEnd = typeof endPage === "number" && Number.isFinite(endPage) && endPage >= startPage ? endPage : startPage;
|
|
6464
|
-
return { startPage, endPage: normalizedEnd };
|
|
6465
|
-
}
|
|
6466
|
-
function parseReferentialTarget(rawTarget) {
|
|
6467
|
-
const raw = rawTarget?.trim() || "unknown";
|
|
6468
|
-
const normalized = raw.toLowerCase();
|
|
6469
|
-
if (normalized === "unknown") return { raw, normalized, kind: "unknown" };
|
|
6470
|
-
if (/declarations?|dec\b|decs\b/.test(normalized)) return { raw, normalized, kind: "declarations" };
|
|
6471
|
-
if (/schedule|scheduled/.test(normalized)) return { raw, normalized, kind: "schedule" };
|
|
6472
|
-
if (/\bitem\b/.test(normalized)) return { raw, normalized, kind: "item" };
|
|
6473
|
-
if (/premises?|location|building/.test(normalized)) return { raw, normalized, kind: "premises" };
|
|
6474
|
-
if (/\bsection\b/.test(normalized)) return { raw, normalized, kind: "section" };
|
|
6475
|
-
if (/policy|coverage\s+part|coverage\s+form/.test(normalized)) return { raw, normalized, kind: "policy" };
|
|
6476
|
-
return { raw, normalized, kind: "unknown" };
|
|
6477
|
-
}
|
|
6478
|
-
function findLocalReferentialPages(params) {
|
|
6479
|
-
const targetLower = params.referenceTarget.toLowerCase();
|
|
6480
|
-
for (const section of params.sections) {
|
|
6481
|
-
if (containsTarget(section.title, targetLower)) {
|
|
6482
|
-
const range = pageRangeFrom(section.pageStart, section.pageEnd);
|
|
6483
|
-
if (range) return range;
|
|
6484
|
-
}
|
|
6485
|
-
}
|
|
6486
|
-
for (const form of params.formInventory) {
|
|
6487
|
-
const titleMatch = containsTarget(form.title, targetLower);
|
|
6488
|
-
const typeMatch = containsTarget(form.formType, targetLower);
|
|
6489
|
-
const numberMatch = containsTarget(form.formNumber, targetLower);
|
|
6490
|
-
if (titleMatch || typeMatch || numberMatch) {
|
|
6491
|
-
const range = pageRangeFrom(form.pageStart, form.pageEnd);
|
|
6492
|
-
if (range) return range;
|
|
6493
|
-
}
|
|
6494
|
-
}
|
|
6495
|
-
return void 0;
|
|
6496
|
-
}
|
|
6497
|
-
function findDeclarationsSchedulePages(parsedTarget, formInventory) {
|
|
6498
|
-
for (const form of formInventory) {
|
|
6499
|
-
const formType = normalizeText2(form.formType);
|
|
6500
|
-
const title = normalizeText2(form.title);
|
|
6501
|
-
const matchesDeclarations = formType === "declarations" || /declarations?|dec\b|decs\b/.test(title);
|
|
6502
|
-
const matchesSchedule = /schedule|scheduled|coverage/.test(title) || formType === "coverage";
|
|
6503
|
-
const shouldUse = parsedTarget.kind === "declarations" ? matchesDeclarations : parsedTarget.kind === "schedule" || parsedTarget.kind === "item" || parsedTarget.kind === "premises" ? matchesSchedule || matchesDeclarations : parsedTarget.kind === "policy" ? matchesDeclarations || matchesSchedule : false;
|
|
6504
|
-
if (shouldUse) {
|
|
6505
|
-
const range = pageRangeFrom(form.pageStart, form.pageEnd);
|
|
6506
|
-
if (range) return range;
|
|
6507
|
-
}
|
|
6508
|
-
}
|
|
6509
|
-
return void 0;
|
|
6510
|
-
}
|
|
6511
|
-
function findSectionPages(parsedTarget, sections) {
|
|
6512
|
-
for (const section of sections) {
|
|
6513
|
-
const title = normalizeText2(section.title);
|
|
6514
|
-
const type = normalizeText2(section.type);
|
|
6515
|
-
const matchesKind = parsedTarget.kind === "declarations" && (type === "declarations" || /declarations?/.test(title)) || parsedTarget.kind === "schedule" && (type === "schedule" || /schedule|scheduled/.test(title)) || parsedTarget.kind === "premises" && /premises?|location|building/.test(title) || parsedTarget.kind === "item" && /\bitem\b|schedule|scheduled/.test(title) || parsedTarget.kind === "section" && containsTarget(title, parsedTarget.normalized);
|
|
6516
|
-
if (matchesKind) {
|
|
6517
|
-
const range = pageRangeFrom(section.pageStart, section.pageEnd);
|
|
6518
|
-
if (range) return range;
|
|
6519
|
-
}
|
|
6520
|
-
}
|
|
6521
|
-
return void 0;
|
|
6522
|
-
}
|
|
6523
|
-
function decideReferentialResolutionAction(params) {
|
|
6524
|
-
if (params.localPageRange) {
|
|
6525
|
-
return { kind: "lookup_pages", source: "local", pageRange: params.localPageRange };
|
|
6526
|
-
}
|
|
6527
|
-
const parsedTarget = parseReferentialTarget(params.referenceTarget);
|
|
6528
|
-
const declarationsScheduleRange = findDeclarationsSchedulePages(parsedTarget, params.formInventory);
|
|
6529
|
-
if (declarationsScheduleRange) {
|
|
6530
|
-
return {
|
|
6531
|
-
kind: "lookup_pages",
|
|
6532
|
-
source: "declarations_schedule",
|
|
6533
|
-
pageRange: declarationsScheduleRange
|
|
6534
|
-
};
|
|
6535
|
-
}
|
|
6536
|
-
const sectionRange = findSectionPages(parsedTarget, params.sections);
|
|
6537
|
-
if (sectionRange) {
|
|
6538
|
-
return { kind: "lookup_pages", source: "sections", pageRange: sectionRange };
|
|
6539
|
-
}
|
|
6540
|
-
if (parsedTarget.kind === "unknown") {
|
|
6541
|
-
return { kind: "skip", reason: "no concrete reference target" };
|
|
6542
|
-
}
|
|
6543
|
-
return { kind: "page_location" };
|
|
6544
|
-
}
|
|
6545
|
-
|
|
6546
6439
|
// src/extraction/resolve-referential.ts
|
|
6547
6440
|
function formatDoclingTextContext(providerOptions) {
|
|
6548
6441
|
const doclingText = providerOptions?.doclingText;
|
|
@@ -6555,24 +6448,7 @@ ${doclingText}`;
|
|
|
6555
6448
|
function parseReferenceTarget(text) {
|
|
6556
6449
|
if (typeof text !== "string") return void 0;
|
|
6557
6450
|
const normalized = text.trim();
|
|
6558
|
-
|
|
6559
|
-
const sectionMatch = normalized.match(/\b(Section\s+\d+[A-Za-z]?)/i);
|
|
6560
|
-
if (sectionMatch) return sectionMatch[1];
|
|
6561
|
-
const itemMatch = normalized.match(/\b(Item\s+\d+[A-Za-z]?)/i);
|
|
6562
|
-
if (itemMatch) return itemMatch[1];
|
|
6563
|
-
const premisesMatch = normalized.match(/\b(Premises?(?:\s+No\.?\s*\d+[A-Za-z]?|\s+\d+[A-Za-z]?)?)/i);
|
|
6564
|
-
if (premisesMatch) return premisesMatch[1].trim();
|
|
6565
|
-
if (/declarations/i.test(normalized)) return "Declarations";
|
|
6566
|
-
const scheduleMatch = normalized.match(/\b(Schedule(?:\s+of\s+[A-Za-z ]+)?)/i);
|
|
6567
|
-
if (scheduleMatch) return scheduleMatch[1].trim();
|
|
6568
|
-
const asStatedMatch = normalized.match(/(?:as\s+stated\s+in|see|shown\s+in(?:\s+the)?)\s+(.+)/i);
|
|
6569
|
-
if (asStatedMatch) {
|
|
6570
|
-
let target = asStatedMatch[1].trim().replace(/\s+of\s+the\s+policy$/i, "").trim();
|
|
6571
|
-
target = target.replace(/\.+$/, "").trim();
|
|
6572
|
-
if (target) return target;
|
|
6573
|
-
}
|
|
6574
|
-
if (/if applicable/i.test(normalized)) return void 0;
|
|
6575
|
-
return void 0;
|
|
6451
|
+
return normalized || void 0;
|
|
6576
6452
|
}
|
|
6577
6453
|
var PageLocationSchema = z40.object({
|
|
6578
6454
|
startPage: z40.number(),
|
|
@@ -6581,8 +6457,6 @@ var PageLocationSchema = z40.object({
|
|
|
6581
6457
|
async function findReferencedPages(params) {
|
|
6582
6458
|
const {
|
|
6583
6459
|
referenceTarget,
|
|
6584
|
-
sections,
|
|
6585
|
-
formInventory,
|
|
6586
6460
|
pdfInput,
|
|
6587
6461
|
pageCount,
|
|
6588
6462
|
generateObject,
|
|
@@ -6592,29 +6466,6 @@ async function findReferencedPages(params) {
|
|
|
6592
6466
|
modelBudgetConstraints,
|
|
6593
6467
|
log
|
|
6594
6468
|
} = params;
|
|
6595
|
-
const localPageRange = findLocalReferentialPages({
|
|
6596
|
-
referenceTarget,
|
|
6597
|
-
sections,
|
|
6598
|
-
formInventory
|
|
6599
|
-
});
|
|
6600
|
-
const action = decideReferentialResolutionAction({
|
|
6601
|
-
referenceTarget,
|
|
6602
|
-
sections,
|
|
6603
|
-
formInventory,
|
|
6604
|
-
localPageRange
|
|
6605
|
-
});
|
|
6606
|
-
if (action.kind === "lookup_pages") {
|
|
6607
|
-
await log?.(
|
|
6608
|
-
`Referential target "${referenceTarget}" resolved to pages ${action.pageRange.startPage}-${action.pageRange.endPage} via ${action.source}.`
|
|
6609
|
-
);
|
|
6610
|
-
return action.pageRange;
|
|
6611
|
-
}
|
|
6612
|
-
if (action.kind === "skip") {
|
|
6613
|
-
await log?.(
|
|
6614
|
-
`Skipping referential target "${referenceTarget}": ${action.reason}.`
|
|
6615
|
-
);
|
|
6616
|
-
return void 0;
|
|
6617
|
-
}
|
|
6618
6469
|
try {
|
|
6619
6470
|
const budget = resolveModelBudget({
|
|
6620
6471
|
taskKind: "extraction_referential_lookup",
|
|
@@ -6693,7 +6544,7 @@ async function resolveReferentialCoverages(params) {
|
|
|
6693
6544
|
const referentialCoverages = coverages.filter((cov) => {
|
|
6694
6545
|
const limitType = cov.limitValueType;
|
|
6695
6546
|
const deductibleType = cov.deductibleValueType;
|
|
6696
|
-
return limitType === "referential" || limitType === "as_stated" || deductibleType === "referential" || deductibleType === "as_stated"
|
|
6547
|
+
return limitType === "referential" || limitType === "as_stated" || deductibleType === "referential" || deductibleType === "as_stated";
|
|
6697
6548
|
});
|
|
6698
6549
|
const attempts = referentialCoverages.length;
|
|
6699
6550
|
if (attempts === 0) {
|
|
@@ -6711,9 +6562,9 @@ async function resolveReferentialCoverages(params) {
|
|
|
6711
6562
|
const targetGroups = /* @__PURE__ */ new Map();
|
|
6712
6563
|
for (let i = 0; i < referentialCoverages.length; i++) {
|
|
6713
6564
|
const cov = referentialCoverages[i];
|
|
6714
|
-
const refString =
|
|
6565
|
+
const refString = cov.limit ?? "";
|
|
6715
6566
|
const sectionRef = typeof cov.sectionRef === "string" ? cov.sectionRef : "";
|
|
6716
|
-
const parsedTarget =
|
|
6567
|
+
const parsedTarget = sectionRef || parseReferenceTarget(refString);
|
|
6717
6568
|
const target = parsedTarget || "unknown";
|
|
6718
6569
|
const group = targetGroups.get(target) ?? [];
|
|
6719
6570
|
group.push({ coverage: cov, index: i });
|
|
@@ -6807,8 +6658,8 @@ async function resolveReferentialCoverages(params) {
|
|
|
6807
6658
|
unresolved++;
|
|
6808
6659
|
continue;
|
|
6809
6660
|
}
|
|
6810
|
-
const limitResolved = rc.resolvedLimit && rc.resolvedLimitValueType !== "referential" && rc.resolvedLimitValueType !== "as_stated"
|
|
6811
|
-
const deductibleResolved = rc.resolvedDeductible && rc.resolvedDeductibleValueType !== "referential" && rc.resolvedDeductibleValueType !== "as_stated"
|
|
6661
|
+
const limitResolved = rc.resolvedLimit && rc.resolvedLimitValueType !== "referential" && rc.resolvedLimitValueType !== "as_stated";
|
|
6662
|
+
const deductibleResolved = rc.resolvedDeductible && rc.resolvedDeductibleValueType !== "referential" && rc.resolvedDeductibleValueType !== "as_stated";
|
|
6812
6663
|
if (limitResolved || deductibleResolved) {
|
|
6813
6664
|
if (limitResolved) {
|
|
6814
6665
|
coverage.limit = rc.resolvedLimit;
|
|
@@ -6987,6 +6838,13 @@ function shouldFailQualityGate(mode, status) {
|
|
|
6987
6838
|
return mode === "strict" && status === "failed";
|
|
6988
6839
|
}
|
|
6989
6840
|
|
|
6841
|
+
// src/extraction/heuristics.ts
|
|
6842
|
+
function looksCoveredReasonSection(section) {
|
|
6843
|
+
const title = String(section.title ?? "").toLowerCase();
|
|
6844
|
+
const type = String(section.type ?? "").toLowerCase();
|
|
6845
|
+
return type === "covered_reason" || title.includes("covered cause") || title.includes("covered reason") || title.includes("covered peril");
|
|
6846
|
+
}
|
|
6847
|
+
|
|
6990
6848
|
// src/extraction/quality.ts
|
|
6991
6849
|
function normalizeFormNumber(value) {
|
|
6992
6850
|
if (typeof value !== "string") return void 0;
|
|
@@ -7162,17 +7020,6 @@ function buildExtractionReviewReport(params) {
|
|
|
7162
7020
|
itemName: typeof coverage.name === "string" ? coverage.name : void 0
|
|
7163
7021
|
});
|
|
7164
7022
|
}
|
|
7165
|
-
if (looksReferential(coverage.limit) || looksReferential(coverage.deductible)) {
|
|
7166
|
-
deterministicIssues.push({
|
|
7167
|
-
code: "coverage_referential_value",
|
|
7168
|
-
severity: "warning",
|
|
7169
|
-
message: `Coverage "${String(coverage.name ?? "unknown")}" contains referential language instead of a concrete scheduled term.`,
|
|
7170
|
-
extractorName: "coverage_limits",
|
|
7171
|
-
formNumber,
|
|
7172
|
-
pageNumber: typeof coverage.pageNumber === "number" ? coverage.pageNumber : void 0,
|
|
7173
|
-
itemName: typeof coverage.name === "string" ? coverage.name : void 0
|
|
7174
|
-
});
|
|
7175
|
-
}
|
|
7176
7023
|
if (formNumber && !inventory.has(formNumber)) {
|
|
7177
7024
|
deterministicIssues.push({
|
|
7178
7025
|
code: "coverage_form_missing_from_inventory",
|
|
@@ -7312,17 +7159,6 @@ function buildExtractionReviewReport(params) {
|
|
|
7312
7159
|
itemName
|
|
7313
7160
|
});
|
|
7314
7161
|
}
|
|
7315
|
-
if (looksReferential(content) || looksReferential(coveredReason.reason)) {
|
|
7316
|
-
deterministicIssues.push({
|
|
7317
|
-
code: "covered_reason_referential_value",
|
|
7318
|
-
severity: "warning",
|
|
7319
|
-
message: `Covered reason "${itemName}" contains referential language instead of the extracted covered cause wording.`,
|
|
7320
|
-
extractorName: "covered_reasons",
|
|
7321
|
-
formNumber: normalizeFormNumber(coveredReason.formNumber),
|
|
7322
|
-
pageNumber: typeof coveredReason.pageNumber === "number" ? coveredReason.pageNumber : typeof coveredReason.pageStart === "number" ? coveredReason.pageStart : void 0,
|
|
7323
|
-
itemName
|
|
7324
|
-
});
|
|
7325
|
-
}
|
|
7326
7162
|
}
|
|
7327
7163
|
for (const section of sections) {
|
|
7328
7164
|
if (typeof section.content === "string" && section.content.trim().length < 120 && typeof section.pageStart === "number" && (!("pageEnd" in section) || section.pageEnd === section.pageStart || section.pageEnd === void 0)) {
|