@claritylabs/cl-sdk 1.3.4 → 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 +27 -365
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -365
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2896,20 +2896,15 @@ function getCoveredReasons(memory) {
|
|
|
2896
2896
|
}
|
|
2897
2897
|
|
|
2898
2898
|
// src/extraction/promote.ts
|
|
2899
|
-
function
|
|
2900
|
-
|
|
2901
|
-
return Array.isArray(decl?.fields) ? decl.fields : [];
|
|
2899
|
+
function stringValue(value) {
|
|
2900
|
+
return typeof value === "string" && value.trim() ? value : void 0;
|
|
2902
2901
|
}
|
|
2903
|
-
function
|
|
2904
|
-
const
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
return
|
|
2909
|
-
}
|
|
2910
|
-
function findFieldValue(fields, patterns, reject) {
|
|
2911
|
-
const match = fields.find((f) => fieldMatches(f.field, patterns) && !reject?.(f));
|
|
2912
|
-
return match?.value;
|
|
2902
|
+
function findRawString(raw, keys) {
|
|
2903
|
+
for (const key of keys) {
|
|
2904
|
+
const value = stringValue(raw[key]);
|
|
2905
|
+
if (value) return value;
|
|
2906
|
+
}
|
|
2907
|
+
return void 0;
|
|
2913
2908
|
}
|
|
2914
2909
|
function promoteRawFields(raw, mappings) {
|
|
2915
2910
|
for (const { from, to } of mappings) {
|
|
@@ -2919,9 +2914,6 @@ function promoteRawFields(raw, mappings) {
|
|
|
2919
2914
|
delete raw[from];
|
|
2920
2915
|
}
|
|
2921
2916
|
}
|
|
2922
|
-
function findRawOrDeclarationValue(raw, fields, lookup) {
|
|
2923
|
-
return (lookup.rawKey ? raw[lookup.rawKey] : void 0) || findFieldValue(fields, lookup.patterns, lookup.reject);
|
|
2924
|
-
}
|
|
2925
2917
|
function promoteCarrierFields(doc) {
|
|
2926
2918
|
const raw = doc;
|
|
2927
2919
|
promoteRawFields(raw, [
|
|
@@ -2938,55 +2930,14 @@ function promoteCarrierFields(doc) {
|
|
|
2938
2930
|
};
|
|
2939
2931
|
}
|
|
2940
2932
|
}
|
|
2941
|
-
var BROKER_NAME_PATTERNS = [
|
|
2942
|
-
"brokerName",
|
|
2943
|
-
"broker",
|
|
2944
|
-
"agentName",
|
|
2945
|
-
"agent",
|
|
2946
|
-
"producerName",
|
|
2947
|
-
"producerAgency",
|
|
2948
|
-
"agencyName",
|
|
2949
|
-
"brokerAgency"
|
|
2950
|
-
];
|
|
2951
|
-
var BROKER_CONTACT_PATTERNS = [
|
|
2952
|
-
"brokerContactName",
|
|
2953
|
-
"brokerContact",
|
|
2954
|
-
"agentContactName",
|
|
2955
|
-
"producerContactName",
|
|
2956
|
-
"producerContact"
|
|
2957
|
-
];
|
|
2958
|
-
var BROKER_LICENSE_PATTERNS = [
|
|
2959
|
-
"brokerLicenseNumber",
|
|
2960
|
-
"brokerNumber",
|
|
2961
|
-
"agentLicenseNumber",
|
|
2962
|
-
"producerLicenseNumber",
|
|
2963
|
-
"producerNumber",
|
|
2964
|
-
"agentNumber"
|
|
2965
|
-
];
|
|
2966
|
-
var BROKER_PHONE_PATTERNS = ["brokerPhone", "agentPhone", "producerPhone"];
|
|
2967
|
-
var BROKER_EMAIL_PATTERNS = ["brokerEmail", "agentEmail", "producerEmail"];
|
|
2968
|
-
var BROKER_ADDRESS_PATTERNS = ["brokerAddress", "agentAddress", "producerAddress"];
|
|
2969
2933
|
function promoteBroker(doc) {
|
|
2970
2934
|
const raw = doc;
|
|
2971
|
-
const
|
|
2972
|
-
const
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
const
|
|
2977
|
-
rawKey: "brokerContactName",
|
|
2978
|
-
patterns: BROKER_CONTACT_PATTERNS
|
|
2979
|
-
});
|
|
2980
|
-
const brokerLicense = findRawOrDeclarationValue(raw, fields, {
|
|
2981
|
-
rawKey: "brokerLicenseNumber",
|
|
2982
|
-
patterns: BROKER_LICENSE_PATTERNS
|
|
2983
|
-
});
|
|
2984
|
-
const brokerPhone = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_PHONE_PATTERNS });
|
|
2985
|
-
const brokerEmail = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_EMAIL_PATTERNS });
|
|
2986
|
-
const brokerAddress = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_ADDRESS_PATTERNS });
|
|
2987
|
-
if (brokerAgency) raw.brokerAgency = brokerAgency;
|
|
2988
|
-
if (brokerContact) raw.brokerContactName = brokerContact;
|
|
2989
|
-
if (brokerLicense) raw.brokerLicenseNumber = brokerLicense;
|
|
2935
|
+
const brokerAgency = findRawString(raw, ["brokerAgency"]);
|
|
2936
|
+
const brokerContact = findRawString(raw, ["brokerContactName"]);
|
|
2937
|
+
const brokerLicense = findRawString(raw, ["brokerLicenseNumber"]);
|
|
2938
|
+
const brokerPhone = findRawString(raw, ["brokerPhone"]);
|
|
2939
|
+
const brokerEmail = findRawString(raw, ["brokerEmail"]);
|
|
2940
|
+
const brokerAddress = findRawString(raw, ["brokerAddress"]);
|
|
2990
2941
|
if (!raw.producer && brokerAgency) {
|
|
2991
2942
|
raw.producer = {
|
|
2992
2943
|
agencyName: brokerAgency,
|
|
@@ -2998,134 +2949,9 @@ function promoteBroker(doc) {
|
|
|
2998
2949
|
};
|
|
2999
2950
|
}
|
|
3000
2951
|
}
|
|
3001
|
-
var LOSS_PAYEE_NAME_PATTERNS = [
|
|
3002
|
-
"lossPayeeName",
|
|
3003
|
-
"lossPayee",
|
|
3004
|
-
"lossPayeeHolder"
|
|
3005
|
-
];
|
|
3006
|
-
var LOSS_PAYEE_ADDRESS_PATTERNS = ["lossPayeeAddress"];
|
|
3007
|
-
var MORTGAGE_HOLDER_NAME_PATTERNS = [
|
|
3008
|
-
"mortgagee",
|
|
3009
|
-
"mortgageHolder",
|
|
3010
|
-
"mortgageHolderName",
|
|
3011
|
-
"mortgageeName",
|
|
3012
|
-
"lienholder",
|
|
3013
|
-
"lienholderName"
|
|
3014
|
-
];
|
|
3015
|
-
var MORTGAGE_HOLDER_ADDRESS_PATTERNS = [
|
|
3016
|
-
"mortgageeAddress",
|
|
3017
|
-
"mortgageHolderAddress",
|
|
3018
|
-
"lienholderAddress"
|
|
3019
|
-
];
|
|
3020
|
-
function promoteLossPayees(doc) {
|
|
3021
|
-
const raw = doc;
|
|
3022
|
-
const fields = getDeclarationFields(doc);
|
|
3023
|
-
if (!raw.lossPayees || Array.isArray(raw.lossPayees) && raw.lossPayees.length === 0) {
|
|
3024
|
-
const name = findFieldValue(fields, LOSS_PAYEE_NAME_PATTERNS);
|
|
3025
|
-
if (name) {
|
|
3026
|
-
const address = findFieldValue(fields, LOSS_PAYEE_ADDRESS_PATTERNS);
|
|
3027
|
-
raw.lossPayees = [{
|
|
3028
|
-
name,
|
|
3029
|
-
role: "loss_payee",
|
|
3030
|
-
...address ? { address: { street1: address } } : {}
|
|
3031
|
-
}];
|
|
3032
|
-
}
|
|
3033
|
-
}
|
|
3034
|
-
if (!raw.mortgageHolders || Array.isArray(raw.mortgageHolders) && raw.mortgageHolders.length === 0) {
|
|
3035
|
-
const name = findFieldValue(fields, MORTGAGE_HOLDER_NAME_PATTERNS);
|
|
3036
|
-
if (name) {
|
|
3037
|
-
const address = findFieldValue(fields, MORTGAGE_HOLDER_ADDRESS_PATTERNS);
|
|
3038
|
-
raw.mortgageHolders = [{
|
|
3039
|
-
name,
|
|
3040
|
-
role: "mortgage_holder",
|
|
3041
|
-
...address ? { address: { street1: address } } : {}
|
|
3042
|
-
}];
|
|
3043
|
-
}
|
|
3044
|
-
}
|
|
3045
|
-
}
|
|
3046
|
-
function promoteLocations(doc) {
|
|
3047
|
-
const raw = doc;
|
|
3048
|
-
if (Array.isArray(raw.locations) && raw.locations.length > 0) return;
|
|
3049
|
-
const fields = getDeclarationFields(doc);
|
|
3050
|
-
if (fields.length === 0) return;
|
|
3051
|
-
const locationGroups = /* @__PURE__ */ new Map();
|
|
3052
|
-
for (const f of fields) {
|
|
3053
|
-
const lower = f.field.toLowerCase().replace(/[\s_-]/g, "");
|
|
3054
|
-
if (lower.includes("locationnumber") || lower.includes("locnumber") || lower.includes("locno")) {
|
|
3055
|
-
const key = f.value;
|
|
3056
|
-
if (!locationGroups.has(key)) locationGroups.set(key, /* @__PURE__ */ new Map());
|
|
3057
|
-
locationGroups.get(key).set("number", f.value);
|
|
3058
|
-
continue;
|
|
3059
|
-
}
|
|
3060
|
-
if (lower.includes("buildingnumber") || lower.includes("bldgnumber") || lower.includes("bldgno")) {
|
|
3061
|
-
const lastKey2 = [...locationGroups.keys()].pop();
|
|
3062
|
-
if (lastKey2) locationGroups.get(lastKey2).set("buildingNumber", f.value);
|
|
3063
|
-
continue;
|
|
3064
|
-
}
|
|
3065
|
-
const section = (f.section ?? "").toLowerCase();
|
|
3066
|
-
const isLocationField = section.includes("location") || section.includes("building") || section.includes("premises") || section.includes("schedule of locations");
|
|
3067
|
-
if (!isLocationField) continue;
|
|
3068
|
-
if (locationGroups.size === 0) {
|
|
3069
|
-
locationGroups.set("1", /* @__PURE__ */ new Map([["number", "1"]]));
|
|
3070
|
-
}
|
|
3071
|
-
const lastKey = [...locationGroups.keys()].pop();
|
|
3072
|
-
const group = locationGroups.get(lastKey);
|
|
3073
|
-
if (lower.includes("construction") || lower.includes("constructiontype")) {
|
|
3074
|
-
group.set("constructionType", f.value);
|
|
3075
|
-
} else if (lower.includes("occupancy") || lower.includes("occupancytype")) {
|
|
3076
|
-
group.set("occupancy", f.value);
|
|
3077
|
-
} else if (lower.includes("yearbuilt")) {
|
|
3078
|
-
group.set("yearBuilt", f.value);
|
|
3079
|
-
} else if (lower.includes("squarefootage") || lower.includes("sqft") || lower.includes("area")) {
|
|
3080
|
-
group.set("squareFootage", f.value);
|
|
3081
|
-
} else if (lower.includes("protectionclass") || lower.includes("fireprotection")) {
|
|
3082
|
-
group.set("protectionClass", f.value);
|
|
3083
|
-
} else if (lower.includes("sprinkler")) {
|
|
3084
|
-
group.set("sprinklered", f.value);
|
|
3085
|
-
} else if (lower.includes("buildingvalue") || lower.includes("buildingamt") || lower.includes("buildingcoverage")) {
|
|
3086
|
-
group.set("buildingValue", f.value);
|
|
3087
|
-
} else if (lower.includes("contentsvalue") || lower.includes("contentsamt") || lower.includes("contentscoverage")) {
|
|
3088
|
-
group.set("contentsValue", f.value);
|
|
3089
|
-
} else if (lower.includes("businessincome") || lower.includes("bivalue") || lower.includes("businessincomevalue")) {
|
|
3090
|
-
group.set("businessIncomeValue", f.value);
|
|
3091
|
-
} else if (lower.includes("description") || lower.includes("buildingdescription") || lower.includes("locationdescription")) {
|
|
3092
|
-
group.set("description", f.value);
|
|
3093
|
-
} else if (lower.includes("address") || lower.includes("industryaddress") || lower.includes("locationaddress") || lower.includes("premisesaddress")) {
|
|
3094
|
-
group.set("address", f.value);
|
|
3095
|
-
} else if (lower.includes("alarm") || lower.includes("alarmtype")) {
|
|
3096
|
-
group.set("alarmType", f.value);
|
|
3097
|
-
}
|
|
3098
|
-
}
|
|
3099
|
-
if (locationGroups.size === 0) return;
|
|
3100
|
-
const locations = [];
|
|
3101
|
-
for (const [, group] of locationGroups) {
|
|
3102
|
-
const num = parseInt(group.get("number") ?? "0", 10) || locations.length + 1;
|
|
3103
|
-
const addressStr = group.get("address");
|
|
3104
|
-
locations.push({
|
|
3105
|
-
number: num,
|
|
3106
|
-
address: addressStr ? { street1: addressStr } : { street1: "See declarations" },
|
|
3107
|
-
...group.get("description") ? { description: group.get("description") } : {},
|
|
3108
|
-
...group.get("constructionType") ? { constructionType: group.get("constructionType") } : {},
|
|
3109
|
-
...group.get("occupancy") ? { occupancy: group.get("occupancy") } : {},
|
|
3110
|
-
...group.get("yearBuilt") ? { yearBuilt: parseInt(group.get("yearBuilt"), 10) || void 0 } : {},
|
|
3111
|
-
...group.get("squareFootage") ? { squareFootage: parseInt(group.get("squareFootage").replace(/[^0-9]/g, ""), 10) || void 0 } : {},
|
|
3112
|
-
...group.get("protectionClass") ? { protectionClass: group.get("protectionClass") } : {},
|
|
3113
|
-
...group.get("sprinklered") ? { sprinklered: /yes|true/i.test(group.get("sprinklered")) } : {},
|
|
3114
|
-
...group.get("buildingValue") ? { buildingValue: group.get("buildingValue") } : {},
|
|
3115
|
-
...group.get("contentsValue") ? { contentsValue: group.get("contentsValue") } : {},
|
|
3116
|
-
...group.get("businessIncomeValue") ? { businessIncomeValue: group.get("businessIncomeValue") } : {},
|
|
3117
|
-
...group.get("alarmType") ? { alarmType: group.get("alarmType") } : {}
|
|
3118
|
-
});
|
|
3119
|
-
}
|
|
3120
|
-
if (locations.length > 0) {
|
|
3121
|
-
raw.locations = locations;
|
|
3122
|
-
}
|
|
3123
|
-
}
|
|
3124
2952
|
function promoteExtractedFields(doc) {
|
|
3125
2953
|
promoteCarrierFields(doc);
|
|
3126
2954
|
promoteBroker(doc);
|
|
3127
|
-
promoteLossPayees(doc);
|
|
3128
|
-
promoteLocations(doc);
|
|
3129
2955
|
}
|
|
3130
2956
|
|
|
3131
2957
|
// src/extraction/alignment.ts
|
|
@@ -6610,113 +6436,6 @@ Your task:
|
|
|
6610
6436
|
Return JSON only.`;
|
|
6611
6437
|
}
|
|
6612
6438
|
|
|
6613
|
-
// src/extraction/heuristics.ts
|
|
6614
|
-
function looksReferential(value) {
|
|
6615
|
-
if (typeof value !== "string") return false;
|
|
6616
|
-
const normalized = value.toLowerCase();
|
|
6617
|
-
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");
|
|
6618
|
-
}
|
|
6619
|
-
function looksCoveredReasonSection(section) {
|
|
6620
|
-
const title = String(section.title ?? "").toLowerCase();
|
|
6621
|
-
const type = String(section.type ?? "").toLowerCase();
|
|
6622
|
-
return type === "covered_reason" || title.includes("covered cause") || title.includes("covered reason") || title.includes("covered peril");
|
|
6623
|
-
}
|
|
6624
|
-
|
|
6625
|
-
// src/extraction/referential-workflow.ts
|
|
6626
|
-
function normalizeText2(value) {
|
|
6627
|
-
return typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
6628
|
-
}
|
|
6629
|
-
function containsTarget(value, target) {
|
|
6630
|
-
const normalizedValue = normalizeText2(value);
|
|
6631
|
-
return Boolean(normalizedValue && target && normalizedValue.includes(target));
|
|
6632
|
-
}
|
|
6633
|
-
function pageRangeFrom(startPage, endPage) {
|
|
6634
|
-
if (typeof startPage !== "number" || !Number.isFinite(startPage) || startPage <= 0) {
|
|
6635
|
-
return void 0;
|
|
6636
|
-
}
|
|
6637
|
-
const normalizedEnd = typeof endPage === "number" && Number.isFinite(endPage) && endPage >= startPage ? endPage : startPage;
|
|
6638
|
-
return { startPage, endPage: normalizedEnd };
|
|
6639
|
-
}
|
|
6640
|
-
function parseReferentialTarget(rawTarget) {
|
|
6641
|
-
const raw = rawTarget?.trim() || "unknown";
|
|
6642
|
-
const normalized = raw.toLowerCase();
|
|
6643
|
-
if (normalized === "unknown") return { raw, normalized, kind: "unknown" };
|
|
6644
|
-
if (/declarations?|dec\b|decs\b/.test(normalized)) return { raw, normalized, kind: "declarations" };
|
|
6645
|
-
if (/schedule|scheduled/.test(normalized)) return { raw, normalized, kind: "schedule" };
|
|
6646
|
-
if (/\bitem\b/.test(normalized)) return { raw, normalized, kind: "item" };
|
|
6647
|
-
if (/premises?|location|building/.test(normalized)) return { raw, normalized, kind: "premises" };
|
|
6648
|
-
if (/\bsection\b/.test(normalized)) return { raw, normalized, kind: "section" };
|
|
6649
|
-
if (/policy|coverage\s+part|coverage\s+form/.test(normalized)) return { raw, normalized, kind: "policy" };
|
|
6650
|
-
return { raw, normalized, kind: "unknown" };
|
|
6651
|
-
}
|
|
6652
|
-
function findLocalReferentialPages(params) {
|
|
6653
|
-
const targetLower = params.referenceTarget.toLowerCase();
|
|
6654
|
-
for (const section of params.sections) {
|
|
6655
|
-
if (containsTarget(section.title, targetLower)) {
|
|
6656
|
-
const range = pageRangeFrom(section.pageStart, section.pageEnd);
|
|
6657
|
-
if (range) return range;
|
|
6658
|
-
}
|
|
6659
|
-
}
|
|
6660
|
-
for (const form of params.formInventory) {
|
|
6661
|
-
const titleMatch = containsTarget(form.title, targetLower);
|
|
6662
|
-
const typeMatch = containsTarget(form.formType, targetLower);
|
|
6663
|
-
const numberMatch = containsTarget(form.formNumber, targetLower);
|
|
6664
|
-
if (titleMatch || typeMatch || numberMatch) {
|
|
6665
|
-
const range = pageRangeFrom(form.pageStart, form.pageEnd);
|
|
6666
|
-
if (range) return range;
|
|
6667
|
-
}
|
|
6668
|
-
}
|
|
6669
|
-
return void 0;
|
|
6670
|
-
}
|
|
6671
|
-
function findDeclarationsSchedulePages(parsedTarget, formInventory) {
|
|
6672
|
-
for (const form of formInventory) {
|
|
6673
|
-
const formType = normalizeText2(form.formType);
|
|
6674
|
-
const title = normalizeText2(form.title);
|
|
6675
|
-
const matchesDeclarations = formType === "declarations" || /declarations?|dec\b|decs\b/.test(title);
|
|
6676
|
-
const matchesSchedule = /schedule|scheduled|coverage/.test(title) || formType === "coverage";
|
|
6677
|
-
const shouldUse = parsedTarget.kind === "declarations" ? matchesDeclarations : parsedTarget.kind === "schedule" || parsedTarget.kind === "item" || parsedTarget.kind === "premises" ? matchesSchedule || matchesDeclarations : parsedTarget.kind === "policy" ? matchesDeclarations || matchesSchedule : false;
|
|
6678
|
-
if (shouldUse) {
|
|
6679
|
-
const range = pageRangeFrom(form.pageStart, form.pageEnd);
|
|
6680
|
-
if (range) return range;
|
|
6681
|
-
}
|
|
6682
|
-
}
|
|
6683
|
-
return void 0;
|
|
6684
|
-
}
|
|
6685
|
-
function findSectionPages(parsedTarget, sections) {
|
|
6686
|
-
for (const section of sections) {
|
|
6687
|
-
const title = normalizeText2(section.title);
|
|
6688
|
-
const type = normalizeText2(section.type);
|
|
6689
|
-
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);
|
|
6690
|
-
if (matchesKind) {
|
|
6691
|
-
const range = pageRangeFrom(section.pageStart, section.pageEnd);
|
|
6692
|
-
if (range) return range;
|
|
6693
|
-
}
|
|
6694
|
-
}
|
|
6695
|
-
return void 0;
|
|
6696
|
-
}
|
|
6697
|
-
function decideReferentialResolutionAction(params) {
|
|
6698
|
-
if (params.localPageRange) {
|
|
6699
|
-
return { kind: "lookup_pages", source: "local", pageRange: params.localPageRange };
|
|
6700
|
-
}
|
|
6701
|
-
const parsedTarget = parseReferentialTarget(params.referenceTarget);
|
|
6702
|
-
const declarationsScheduleRange = findDeclarationsSchedulePages(parsedTarget, params.formInventory);
|
|
6703
|
-
if (declarationsScheduleRange) {
|
|
6704
|
-
return {
|
|
6705
|
-
kind: "lookup_pages",
|
|
6706
|
-
source: "declarations_schedule",
|
|
6707
|
-
pageRange: declarationsScheduleRange
|
|
6708
|
-
};
|
|
6709
|
-
}
|
|
6710
|
-
const sectionRange = findSectionPages(parsedTarget, params.sections);
|
|
6711
|
-
if (sectionRange) {
|
|
6712
|
-
return { kind: "lookup_pages", source: "sections", pageRange: sectionRange };
|
|
6713
|
-
}
|
|
6714
|
-
if (parsedTarget.kind === "unknown") {
|
|
6715
|
-
return { kind: "skip", reason: "no concrete reference target" };
|
|
6716
|
-
}
|
|
6717
|
-
return { kind: "page_location" };
|
|
6718
|
-
}
|
|
6719
|
-
|
|
6720
6439
|
// src/extraction/resolve-referential.ts
|
|
6721
6440
|
function formatDoclingTextContext(providerOptions) {
|
|
6722
6441
|
const doclingText = providerOptions?.doclingText;
|
|
@@ -6729,24 +6448,7 @@ ${doclingText}`;
|
|
|
6729
6448
|
function parseReferenceTarget(text) {
|
|
6730
6449
|
if (typeof text !== "string") return void 0;
|
|
6731
6450
|
const normalized = text.trim();
|
|
6732
|
-
|
|
6733
|
-
const sectionMatch = normalized.match(/\b(Section\s+\d+[A-Za-z]?)/i);
|
|
6734
|
-
if (sectionMatch) return sectionMatch[1];
|
|
6735
|
-
const itemMatch = normalized.match(/\b(Item\s+\d+[A-Za-z]?)/i);
|
|
6736
|
-
if (itemMatch) return itemMatch[1];
|
|
6737
|
-
const premisesMatch = normalized.match(/\b(Premises?(?:\s+No\.?\s*\d+[A-Za-z]?|\s+\d+[A-Za-z]?)?)/i);
|
|
6738
|
-
if (premisesMatch) return premisesMatch[1].trim();
|
|
6739
|
-
if (/declarations/i.test(normalized)) return "Declarations";
|
|
6740
|
-
const scheduleMatch = normalized.match(/\b(Schedule(?:\s+of\s+[A-Za-z ]+)?)/i);
|
|
6741
|
-
if (scheduleMatch) return scheduleMatch[1].trim();
|
|
6742
|
-
const asStatedMatch = normalized.match(/(?:as\s+stated\s+in|see|shown\s+in(?:\s+the)?)\s+(.+)/i);
|
|
6743
|
-
if (asStatedMatch) {
|
|
6744
|
-
let target = asStatedMatch[1].trim().replace(/\s+of\s+the\s+policy$/i, "").trim();
|
|
6745
|
-
target = target.replace(/\.+$/, "").trim();
|
|
6746
|
-
if (target) return target;
|
|
6747
|
-
}
|
|
6748
|
-
if (/if applicable/i.test(normalized)) return void 0;
|
|
6749
|
-
return void 0;
|
|
6451
|
+
return normalized || void 0;
|
|
6750
6452
|
}
|
|
6751
6453
|
var PageLocationSchema = z40.object({
|
|
6752
6454
|
startPage: z40.number(),
|
|
@@ -6755,8 +6457,6 @@ var PageLocationSchema = z40.object({
|
|
|
6755
6457
|
async function findReferencedPages(params) {
|
|
6756
6458
|
const {
|
|
6757
6459
|
referenceTarget,
|
|
6758
|
-
sections,
|
|
6759
|
-
formInventory,
|
|
6760
6460
|
pdfInput,
|
|
6761
6461
|
pageCount,
|
|
6762
6462
|
generateObject,
|
|
@@ -6766,29 +6466,6 @@ async function findReferencedPages(params) {
|
|
|
6766
6466
|
modelBudgetConstraints,
|
|
6767
6467
|
log
|
|
6768
6468
|
} = params;
|
|
6769
|
-
const localPageRange = findLocalReferentialPages({
|
|
6770
|
-
referenceTarget,
|
|
6771
|
-
sections,
|
|
6772
|
-
formInventory
|
|
6773
|
-
});
|
|
6774
|
-
const action = decideReferentialResolutionAction({
|
|
6775
|
-
referenceTarget,
|
|
6776
|
-
sections,
|
|
6777
|
-
formInventory,
|
|
6778
|
-
localPageRange
|
|
6779
|
-
});
|
|
6780
|
-
if (action.kind === "lookup_pages") {
|
|
6781
|
-
await log?.(
|
|
6782
|
-
`Referential target "${referenceTarget}" resolved to pages ${action.pageRange.startPage}-${action.pageRange.endPage} via ${action.source}.`
|
|
6783
|
-
);
|
|
6784
|
-
return action.pageRange;
|
|
6785
|
-
}
|
|
6786
|
-
if (action.kind === "skip") {
|
|
6787
|
-
await log?.(
|
|
6788
|
-
`Skipping referential target "${referenceTarget}": ${action.reason}.`
|
|
6789
|
-
);
|
|
6790
|
-
return void 0;
|
|
6791
|
-
}
|
|
6792
6469
|
try {
|
|
6793
6470
|
const budget = resolveModelBudget({
|
|
6794
6471
|
taskKind: "extraction_referential_lookup",
|
|
@@ -6867,7 +6544,7 @@ async function resolveReferentialCoverages(params) {
|
|
|
6867
6544
|
const referentialCoverages = coverages.filter((cov) => {
|
|
6868
6545
|
const limitType = cov.limitValueType;
|
|
6869
6546
|
const deductibleType = cov.deductibleValueType;
|
|
6870
|
-
return limitType === "referential" || limitType === "as_stated" || deductibleType === "referential" || deductibleType === "as_stated"
|
|
6547
|
+
return limitType === "referential" || limitType === "as_stated" || deductibleType === "referential" || deductibleType === "as_stated";
|
|
6871
6548
|
});
|
|
6872
6549
|
const attempts = referentialCoverages.length;
|
|
6873
6550
|
if (attempts === 0) {
|
|
@@ -6885,9 +6562,9 @@ async function resolveReferentialCoverages(params) {
|
|
|
6885
6562
|
const targetGroups = /* @__PURE__ */ new Map();
|
|
6886
6563
|
for (let i = 0; i < referentialCoverages.length; i++) {
|
|
6887
6564
|
const cov = referentialCoverages[i];
|
|
6888
|
-
const refString =
|
|
6565
|
+
const refString = cov.limit ?? "";
|
|
6889
6566
|
const sectionRef = typeof cov.sectionRef === "string" ? cov.sectionRef : "";
|
|
6890
|
-
const parsedTarget =
|
|
6567
|
+
const parsedTarget = sectionRef || parseReferenceTarget(refString);
|
|
6891
6568
|
const target = parsedTarget || "unknown";
|
|
6892
6569
|
const group = targetGroups.get(target) ?? [];
|
|
6893
6570
|
group.push({ coverage: cov, index: i });
|
|
@@ -6981,8 +6658,8 @@ async function resolveReferentialCoverages(params) {
|
|
|
6981
6658
|
unresolved++;
|
|
6982
6659
|
continue;
|
|
6983
6660
|
}
|
|
6984
|
-
const limitResolved = rc.resolvedLimit && rc.resolvedLimitValueType !== "referential" && rc.resolvedLimitValueType !== "as_stated"
|
|
6985
|
-
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";
|
|
6986
6663
|
if (limitResolved || deductibleResolved) {
|
|
6987
6664
|
if (limitResolved) {
|
|
6988
6665
|
coverage.limit = rc.resolvedLimit;
|
|
@@ -7161,6 +6838,13 @@ function shouldFailQualityGate(mode, status) {
|
|
|
7161
6838
|
return mode === "strict" && status === "failed";
|
|
7162
6839
|
}
|
|
7163
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
|
+
|
|
7164
6848
|
// src/extraction/quality.ts
|
|
7165
6849
|
function normalizeFormNumber(value) {
|
|
7166
6850
|
if (typeof value !== "string") return void 0;
|
|
@@ -7336,17 +7020,6 @@ function buildExtractionReviewReport(params) {
|
|
|
7336
7020
|
itemName: typeof coverage.name === "string" ? coverage.name : void 0
|
|
7337
7021
|
});
|
|
7338
7022
|
}
|
|
7339
|
-
if (looksReferential(coverage.limit) || looksReferential(coverage.deductible)) {
|
|
7340
|
-
deterministicIssues.push({
|
|
7341
|
-
code: "coverage_referential_value",
|
|
7342
|
-
severity: "warning",
|
|
7343
|
-
message: `Coverage "${String(coverage.name ?? "unknown")}" contains referential language instead of a concrete scheduled term.`,
|
|
7344
|
-
extractorName: "coverage_limits",
|
|
7345
|
-
formNumber,
|
|
7346
|
-
pageNumber: typeof coverage.pageNumber === "number" ? coverage.pageNumber : void 0,
|
|
7347
|
-
itemName: typeof coverage.name === "string" ? coverage.name : void 0
|
|
7348
|
-
});
|
|
7349
|
-
}
|
|
7350
7023
|
if (formNumber && !inventory.has(formNumber)) {
|
|
7351
7024
|
deterministicIssues.push({
|
|
7352
7025
|
code: "coverage_form_missing_from_inventory",
|
|
@@ -7486,17 +7159,6 @@ function buildExtractionReviewReport(params) {
|
|
|
7486
7159
|
itemName
|
|
7487
7160
|
});
|
|
7488
7161
|
}
|
|
7489
|
-
if (looksReferential(content) || looksReferential(coveredReason.reason)) {
|
|
7490
|
-
deterministicIssues.push({
|
|
7491
|
-
code: "covered_reason_referential_value",
|
|
7492
|
-
severity: "warning",
|
|
7493
|
-
message: `Covered reason "${itemName}" contains referential language instead of the extracted covered cause wording.`,
|
|
7494
|
-
extractorName: "covered_reasons",
|
|
7495
|
-
formNumber: normalizeFormNumber(coveredReason.formNumber),
|
|
7496
|
-
pageNumber: typeof coveredReason.pageNumber === "number" ? coveredReason.pageNumber : typeof coveredReason.pageStart === "number" ? coveredReason.pageStart : void 0,
|
|
7497
|
-
itemName
|
|
7498
|
-
});
|
|
7499
|
-
}
|
|
7500
7162
|
}
|
|
7501
7163
|
for (const section of sections) {
|
|
7502
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)) {
|