@claritylabs/cl-sdk 1.3.5 → 1.3.7
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 +38 -177
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -177
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6764,113 +6764,6 @@ Your task:
|
|
|
6764
6764
|
Return JSON only.`;
|
|
6765
6765
|
}
|
|
6766
6766
|
|
|
6767
|
-
// src/extraction/heuristics.ts
|
|
6768
|
-
function looksReferential(value) {
|
|
6769
|
-
if (typeof value !== "string") return false;
|
|
6770
|
-
const normalized = value.toLowerCase();
|
|
6771
|
-
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");
|
|
6772
|
-
}
|
|
6773
|
-
function looksCoveredReasonSection(section) {
|
|
6774
|
-
const title = String(section.title ?? "").toLowerCase();
|
|
6775
|
-
const type = String(section.type ?? "").toLowerCase();
|
|
6776
|
-
return type === "covered_reason" || title.includes("covered cause") || title.includes("covered reason") || title.includes("covered peril");
|
|
6777
|
-
}
|
|
6778
|
-
|
|
6779
|
-
// src/extraction/referential-workflow.ts
|
|
6780
|
-
function normalizeText2(value) {
|
|
6781
|
-
return typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
6782
|
-
}
|
|
6783
|
-
function containsTarget(value, target) {
|
|
6784
|
-
const normalizedValue = normalizeText2(value);
|
|
6785
|
-
return Boolean(normalizedValue && target && normalizedValue.includes(target));
|
|
6786
|
-
}
|
|
6787
|
-
function pageRangeFrom(startPage, endPage) {
|
|
6788
|
-
if (typeof startPage !== "number" || !Number.isFinite(startPage) || startPage <= 0) {
|
|
6789
|
-
return void 0;
|
|
6790
|
-
}
|
|
6791
|
-
const normalizedEnd = typeof endPage === "number" && Number.isFinite(endPage) && endPage >= startPage ? endPage : startPage;
|
|
6792
|
-
return { startPage, endPage: normalizedEnd };
|
|
6793
|
-
}
|
|
6794
|
-
function parseReferentialTarget(rawTarget) {
|
|
6795
|
-
const raw = rawTarget?.trim() || "unknown";
|
|
6796
|
-
const normalized = raw.toLowerCase();
|
|
6797
|
-
if (normalized === "unknown") return { raw, normalized, kind: "unknown" };
|
|
6798
|
-
if (/declarations?|dec\b|decs\b/.test(normalized)) return { raw, normalized, kind: "declarations" };
|
|
6799
|
-
if (/schedule|scheduled/.test(normalized)) return { raw, normalized, kind: "schedule" };
|
|
6800
|
-
if (/\bitem\b/.test(normalized)) return { raw, normalized, kind: "item" };
|
|
6801
|
-
if (/premises?|location|building/.test(normalized)) return { raw, normalized, kind: "premises" };
|
|
6802
|
-
if (/\bsection\b/.test(normalized)) return { raw, normalized, kind: "section" };
|
|
6803
|
-
if (/policy|coverage\s+part|coverage\s+form/.test(normalized)) return { raw, normalized, kind: "policy" };
|
|
6804
|
-
return { raw, normalized, kind: "unknown" };
|
|
6805
|
-
}
|
|
6806
|
-
function findLocalReferentialPages(params) {
|
|
6807
|
-
const targetLower = params.referenceTarget.toLowerCase();
|
|
6808
|
-
for (const section of params.sections) {
|
|
6809
|
-
if (containsTarget(section.title, targetLower)) {
|
|
6810
|
-
const range = pageRangeFrom(section.pageStart, section.pageEnd);
|
|
6811
|
-
if (range) return range;
|
|
6812
|
-
}
|
|
6813
|
-
}
|
|
6814
|
-
for (const form of params.formInventory) {
|
|
6815
|
-
const titleMatch = containsTarget(form.title, targetLower);
|
|
6816
|
-
const typeMatch = containsTarget(form.formType, targetLower);
|
|
6817
|
-
const numberMatch = containsTarget(form.formNumber, targetLower);
|
|
6818
|
-
if (titleMatch || typeMatch || numberMatch) {
|
|
6819
|
-
const range = pageRangeFrom(form.pageStart, form.pageEnd);
|
|
6820
|
-
if (range) return range;
|
|
6821
|
-
}
|
|
6822
|
-
}
|
|
6823
|
-
return void 0;
|
|
6824
|
-
}
|
|
6825
|
-
function findDeclarationsSchedulePages(parsedTarget, formInventory) {
|
|
6826
|
-
for (const form of formInventory) {
|
|
6827
|
-
const formType = normalizeText2(form.formType);
|
|
6828
|
-
const title = normalizeText2(form.title);
|
|
6829
|
-
const matchesDeclarations = formType === "declarations" || /declarations?|dec\b|decs\b/.test(title);
|
|
6830
|
-
const matchesSchedule = /schedule|scheduled|coverage/.test(title) || formType === "coverage";
|
|
6831
|
-
const shouldUse = parsedTarget.kind === "declarations" ? matchesDeclarations : parsedTarget.kind === "schedule" || parsedTarget.kind === "item" || parsedTarget.kind === "premises" ? matchesSchedule || matchesDeclarations : parsedTarget.kind === "policy" ? matchesDeclarations || matchesSchedule : false;
|
|
6832
|
-
if (shouldUse) {
|
|
6833
|
-
const range = pageRangeFrom(form.pageStart, form.pageEnd);
|
|
6834
|
-
if (range) return range;
|
|
6835
|
-
}
|
|
6836
|
-
}
|
|
6837
|
-
return void 0;
|
|
6838
|
-
}
|
|
6839
|
-
function findSectionPages(parsedTarget, sections) {
|
|
6840
|
-
for (const section of sections) {
|
|
6841
|
-
const title = normalizeText2(section.title);
|
|
6842
|
-
const type = normalizeText2(section.type);
|
|
6843
|
-
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);
|
|
6844
|
-
if (matchesKind) {
|
|
6845
|
-
const range = pageRangeFrom(section.pageStart, section.pageEnd);
|
|
6846
|
-
if (range) return range;
|
|
6847
|
-
}
|
|
6848
|
-
}
|
|
6849
|
-
return void 0;
|
|
6850
|
-
}
|
|
6851
|
-
function decideReferentialResolutionAction(params) {
|
|
6852
|
-
if (params.localPageRange) {
|
|
6853
|
-
return { kind: "lookup_pages", source: "local", pageRange: params.localPageRange };
|
|
6854
|
-
}
|
|
6855
|
-
const parsedTarget = parseReferentialTarget(params.referenceTarget);
|
|
6856
|
-
const declarationsScheduleRange = findDeclarationsSchedulePages(parsedTarget, params.formInventory);
|
|
6857
|
-
if (declarationsScheduleRange) {
|
|
6858
|
-
return {
|
|
6859
|
-
kind: "lookup_pages",
|
|
6860
|
-
source: "declarations_schedule",
|
|
6861
|
-
pageRange: declarationsScheduleRange
|
|
6862
|
-
};
|
|
6863
|
-
}
|
|
6864
|
-
const sectionRange = findSectionPages(parsedTarget, params.sections);
|
|
6865
|
-
if (sectionRange) {
|
|
6866
|
-
return { kind: "lookup_pages", source: "sections", pageRange: sectionRange };
|
|
6867
|
-
}
|
|
6868
|
-
if (parsedTarget.kind === "unknown") {
|
|
6869
|
-
return { kind: "skip", reason: "no concrete reference target" };
|
|
6870
|
-
}
|
|
6871
|
-
return { kind: "page_location" };
|
|
6872
|
-
}
|
|
6873
|
-
|
|
6874
6767
|
// src/extraction/resolve-referential.ts
|
|
6875
6768
|
function formatDoclingTextContext(providerOptions) {
|
|
6876
6769
|
const doclingText = providerOptions?.doclingText;
|
|
@@ -6883,24 +6776,7 @@ ${doclingText}`;
|
|
|
6883
6776
|
function parseReferenceTarget(text) {
|
|
6884
6777
|
if (typeof text !== "string") return void 0;
|
|
6885
6778
|
const normalized = text.trim();
|
|
6886
|
-
|
|
6887
|
-
const sectionMatch = normalized.match(/\b(Section\s+\d+[A-Za-z]?)/i);
|
|
6888
|
-
if (sectionMatch) return sectionMatch[1];
|
|
6889
|
-
const itemMatch = normalized.match(/\b(Item\s+\d+[A-Za-z]?)/i);
|
|
6890
|
-
if (itemMatch) return itemMatch[1];
|
|
6891
|
-
const premisesMatch = normalized.match(/\b(Premises?(?:\s+No\.?\s*\d+[A-Za-z]?|\s+\d+[A-Za-z]?)?)/i);
|
|
6892
|
-
if (premisesMatch) return premisesMatch[1].trim();
|
|
6893
|
-
if (/declarations/i.test(normalized)) return "Declarations";
|
|
6894
|
-
const scheduleMatch = normalized.match(/\b(Schedule(?:\s+of\s+[A-Za-z ]+)?)/i);
|
|
6895
|
-
if (scheduleMatch) return scheduleMatch[1].trim();
|
|
6896
|
-
const asStatedMatch = normalized.match(/(?:as\s+stated\s+in|see|shown\s+in(?:\s+the)?)\s+(.+)/i);
|
|
6897
|
-
if (asStatedMatch) {
|
|
6898
|
-
let target = asStatedMatch[1].trim().replace(/\s+of\s+the\s+policy$/i, "").trim();
|
|
6899
|
-
target = target.replace(/\.+$/, "").trim();
|
|
6900
|
-
if (target) return target;
|
|
6901
|
-
}
|
|
6902
|
-
if (/if applicable/i.test(normalized)) return void 0;
|
|
6903
|
-
return void 0;
|
|
6779
|
+
return normalized || void 0;
|
|
6904
6780
|
}
|
|
6905
6781
|
var PageLocationSchema = import_zod40.z.object({
|
|
6906
6782
|
startPage: import_zod40.z.number(),
|
|
@@ -6909,8 +6785,6 @@ var PageLocationSchema = import_zod40.z.object({
|
|
|
6909
6785
|
async function findReferencedPages(params) {
|
|
6910
6786
|
const {
|
|
6911
6787
|
referenceTarget,
|
|
6912
|
-
sections,
|
|
6913
|
-
formInventory,
|
|
6914
6788
|
pdfInput,
|
|
6915
6789
|
pageCount,
|
|
6916
6790
|
generateObject,
|
|
@@ -6920,29 +6794,6 @@ async function findReferencedPages(params) {
|
|
|
6920
6794
|
modelBudgetConstraints,
|
|
6921
6795
|
log
|
|
6922
6796
|
} = params;
|
|
6923
|
-
const localPageRange = findLocalReferentialPages({
|
|
6924
|
-
referenceTarget,
|
|
6925
|
-
sections,
|
|
6926
|
-
formInventory
|
|
6927
|
-
});
|
|
6928
|
-
const action = decideReferentialResolutionAction({
|
|
6929
|
-
referenceTarget,
|
|
6930
|
-
sections,
|
|
6931
|
-
formInventory,
|
|
6932
|
-
localPageRange
|
|
6933
|
-
});
|
|
6934
|
-
if (action.kind === "lookup_pages") {
|
|
6935
|
-
await log?.(
|
|
6936
|
-
`Referential target "${referenceTarget}" resolved to pages ${action.pageRange.startPage}-${action.pageRange.endPage} via ${action.source}.`
|
|
6937
|
-
);
|
|
6938
|
-
return action.pageRange;
|
|
6939
|
-
}
|
|
6940
|
-
if (action.kind === "skip") {
|
|
6941
|
-
await log?.(
|
|
6942
|
-
`Skipping referential target "${referenceTarget}": ${action.reason}.`
|
|
6943
|
-
);
|
|
6944
|
-
return void 0;
|
|
6945
|
-
}
|
|
6946
6797
|
try {
|
|
6947
6798
|
const budget = resolveModelBudget({
|
|
6948
6799
|
taskKind: "extraction_referential_lookup",
|
|
@@ -7021,7 +6872,7 @@ async function resolveReferentialCoverages(params) {
|
|
|
7021
6872
|
const referentialCoverages = coverages.filter((cov) => {
|
|
7022
6873
|
const limitType = cov.limitValueType;
|
|
7023
6874
|
const deductibleType = cov.deductibleValueType;
|
|
7024
|
-
return limitType === "referential" || limitType === "as_stated" || deductibleType === "referential" || deductibleType === "as_stated"
|
|
6875
|
+
return limitType === "referential" || limitType === "as_stated" || deductibleType === "referential" || deductibleType === "as_stated";
|
|
7025
6876
|
});
|
|
7026
6877
|
const attempts = referentialCoverages.length;
|
|
7027
6878
|
if (attempts === 0) {
|
|
@@ -7039,9 +6890,9 @@ async function resolveReferentialCoverages(params) {
|
|
|
7039
6890
|
const targetGroups = /* @__PURE__ */ new Map();
|
|
7040
6891
|
for (let i = 0; i < referentialCoverages.length; i++) {
|
|
7041
6892
|
const cov = referentialCoverages[i];
|
|
7042
|
-
const refString =
|
|
6893
|
+
const refString = cov.limit ?? "";
|
|
7043
6894
|
const sectionRef = typeof cov.sectionRef === "string" ? cov.sectionRef : "";
|
|
7044
|
-
const parsedTarget =
|
|
6895
|
+
const parsedTarget = sectionRef || parseReferenceTarget(refString);
|
|
7045
6896
|
const target = parsedTarget || "unknown";
|
|
7046
6897
|
const group = targetGroups.get(target) ?? [];
|
|
7047
6898
|
group.push({ coverage: cov, index: i });
|
|
@@ -7135,8 +6986,8 @@ async function resolveReferentialCoverages(params) {
|
|
|
7135
6986
|
unresolved++;
|
|
7136
6987
|
continue;
|
|
7137
6988
|
}
|
|
7138
|
-
const limitResolved = rc.resolvedLimit && rc.resolvedLimitValueType !== "referential" && rc.resolvedLimitValueType !== "as_stated"
|
|
7139
|
-
const deductibleResolved = rc.resolvedDeductible && rc.resolvedDeductibleValueType !== "referential" && rc.resolvedDeductibleValueType !== "as_stated"
|
|
6989
|
+
const limitResolved = rc.resolvedLimit && rc.resolvedLimitValueType !== "referential" && rc.resolvedLimitValueType !== "as_stated";
|
|
6990
|
+
const deductibleResolved = rc.resolvedDeductible && rc.resolvedDeductibleValueType !== "referential" && rc.resolvedDeductibleValueType !== "as_stated";
|
|
7140
6991
|
if (limitResolved || deductibleResolved) {
|
|
7141
6992
|
if (limitResolved) {
|
|
7142
6993
|
coverage.limit = rc.resolvedLimit;
|
|
@@ -7315,6 +7166,13 @@ function shouldFailQualityGate(mode, status) {
|
|
|
7315
7166
|
return mode === "strict" && status === "failed";
|
|
7316
7167
|
}
|
|
7317
7168
|
|
|
7169
|
+
// src/extraction/heuristics.ts
|
|
7170
|
+
function looksCoveredReasonSection(section) {
|
|
7171
|
+
const title = String(section.title ?? "").toLowerCase();
|
|
7172
|
+
const type = String(section.type ?? "").toLowerCase();
|
|
7173
|
+
return type === "covered_reason" || title.includes("covered cause") || title.includes("covered reason") || title.includes("covered peril");
|
|
7174
|
+
}
|
|
7175
|
+
|
|
7318
7176
|
// src/extraction/quality.ts
|
|
7319
7177
|
function normalizeFormNumber(value) {
|
|
7320
7178
|
if (typeof value !== "string") return void 0;
|
|
@@ -7353,6 +7211,20 @@ function sourcePrecedence(sectionRef) {
|
|
|
7353
7211
|
if (normalized.includes("coverage form") || normalized.includes("policy form")) return 1;
|
|
7354
7212
|
return 0;
|
|
7355
7213
|
}
|
|
7214
|
+
function looksDeductibleOnlyCoverageRow(coverage) {
|
|
7215
|
+
const name = typeof coverage.name === "string" ? coverage.name : "";
|
|
7216
|
+
const originalContent = typeof coverage.originalContent === "string" ? coverage.originalContent : "";
|
|
7217
|
+
const evidenceText = originalContent || name;
|
|
7218
|
+
const normalizedEvidence = evidenceText.toLowerCase();
|
|
7219
|
+
const normalizedName = name.toLowerCase();
|
|
7220
|
+
if (!/\b(deductible|retention|self[-\s]?insured retention|sir)\b/.test(`${normalizedName} ${normalizedEvidence}`)) return false;
|
|
7221
|
+
if (coverage.deductible || coverage.deductibleAmount !== void 0) return false;
|
|
7222
|
+
if (!coverage.limit && coverage.limitAmount === void 0) return false;
|
|
7223
|
+
if (originalContent && /\b(deductible|retention|self[-\s]?insured retention|sir)\b/.test(normalizedEvidence) && !/\b(?:sub[-\s]?limit|limit|coverage)\b/.test(normalizedEvidence)) {
|
|
7224
|
+
return true;
|
|
7225
|
+
}
|
|
7226
|
+
return /[-–—]\s*(?:enhanced\s+|standard\s+)?(?:deductible|retention|sir)\b/.test(normalizedName);
|
|
7227
|
+
}
|
|
7356
7228
|
function buildExtractionReviewReport(params) {
|
|
7357
7229
|
const { memory, reviewRounds } = params;
|
|
7358
7230
|
const deterministicIssues = [];
|
|
@@ -7458,6 +7330,17 @@ function buildExtractionReviewReport(params) {
|
|
|
7458
7330
|
itemName: coverage.name
|
|
7459
7331
|
});
|
|
7460
7332
|
}
|
|
7333
|
+
if (looksDeductibleOnlyCoverageRow(coverage)) {
|
|
7334
|
+
deterministicIssues.push({
|
|
7335
|
+
code: "deductible_row_as_coverage_limit",
|
|
7336
|
+
severity: "blocking",
|
|
7337
|
+
message: `Coverage "${String(coverage.name ?? "unknown")}" appears to store a deductible or retention value as a coverage limit.`,
|
|
7338
|
+
extractorName: "coverage_limits",
|
|
7339
|
+
formNumber,
|
|
7340
|
+
pageNumber: typeof coverage.pageNumber === "number" ? coverage.pageNumber : void 0,
|
|
7341
|
+
itemName: typeof coverage.name === "string" ? coverage.name : void 0
|
|
7342
|
+
});
|
|
7343
|
+
}
|
|
7461
7344
|
if (typeof coverage.pageNumber !== "number") {
|
|
7462
7345
|
deterministicIssues.push({
|
|
7463
7346
|
code: "coverage_missing_page_number",
|
|
@@ -7490,17 +7373,6 @@ function buildExtractionReviewReport(params) {
|
|
|
7490
7373
|
itemName: typeof coverage.name === "string" ? coverage.name : void 0
|
|
7491
7374
|
});
|
|
7492
7375
|
}
|
|
7493
|
-
if (looksReferential(coverage.limit) || looksReferential(coverage.deductible)) {
|
|
7494
|
-
deterministicIssues.push({
|
|
7495
|
-
code: "coverage_referential_value",
|
|
7496
|
-
severity: "warning",
|
|
7497
|
-
message: `Coverage "${String(coverage.name ?? "unknown")}" contains referential language instead of a concrete scheduled term.`,
|
|
7498
|
-
extractorName: "coverage_limits",
|
|
7499
|
-
formNumber,
|
|
7500
|
-
pageNumber: typeof coverage.pageNumber === "number" ? coverage.pageNumber : void 0,
|
|
7501
|
-
itemName: typeof coverage.name === "string" ? coverage.name : void 0
|
|
7502
|
-
});
|
|
7503
|
-
}
|
|
7504
7376
|
if (formNumber && !inventory.has(formNumber)) {
|
|
7505
7377
|
deterministicIssues.push({
|
|
7506
7378
|
code: "coverage_form_missing_from_inventory",
|
|
@@ -7640,17 +7512,6 @@ function buildExtractionReviewReport(params) {
|
|
|
7640
7512
|
itemName
|
|
7641
7513
|
});
|
|
7642
7514
|
}
|
|
7643
|
-
if (looksReferential(content) || looksReferential(coveredReason.reason)) {
|
|
7644
|
-
deterministicIssues.push({
|
|
7645
|
-
code: "covered_reason_referential_value",
|
|
7646
|
-
severity: "warning",
|
|
7647
|
-
message: `Covered reason "${itemName}" contains referential language instead of the extracted covered cause wording.`,
|
|
7648
|
-
extractorName: "covered_reasons",
|
|
7649
|
-
formNumber: normalizeFormNumber(coveredReason.formNumber),
|
|
7650
|
-
pageNumber: typeof coveredReason.pageNumber === "number" ? coveredReason.pageNumber : typeof coveredReason.pageStart === "number" ? coveredReason.pageStart : void 0,
|
|
7651
|
-
itemName
|
|
7652
|
-
});
|
|
7653
|
-
}
|
|
7654
7515
|
}
|
|
7655
7516
|
for (const section of sections) {
|
|
7656
7517
|
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)) {
|