@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.js
CHANGED
|
@@ -3224,20 +3224,15 @@ function getCoveredReasons(memory) {
|
|
|
3224
3224
|
}
|
|
3225
3225
|
|
|
3226
3226
|
// src/extraction/promote.ts
|
|
3227
|
-
function
|
|
3228
|
-
|
|
3229
|
-
return Array.isArray(decl?.fields) ? decl.fields : [];
|
|
3227
|
+
function stringValue(value) {
|
|
3228
|
+
return typeof value === "string" && value.trim() ? value : void 0;
|
|
3230
3229
|
}
|
|
3231
|
-
function
|
|
3232
|
-
const
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
return
|
|
3237
|
-
}
|
|
3238
|
-
function findFieldValue(fields, patterns, reject) {
|
|
3239
|
-
const match = fields.find((f) => fieldMatches(f.field, patterns) && !reject?.(f));
|
|
3240
|
-
return match?.value;
|
|
3230
|
+
function findRawString(raw, keys) {
|
|
3231
|
+
for (const key of keys) {
|
|
3232
|
+
const value = stringValue(raw[key]);
|
|
3233
|
+
if (value) return value;
|
|
3234
|
+
}
|
|
3235
|
+
return void 0;
|
|
3241
3236
|
}
|
|
3242
3237
|
function promoteRawFields(raw, mappings) {
|
|
3243
3238
|
for (const { from, to } of mappings) {
|
|
@@ -3247,9 +3242,6 @@ function promoteRawFields(raw, mappings) {
|
|
|
3247
3242
|
delete raw[from];
|
|
3248
3243
|
}
|
|
3249
3244
|
}
|
|
3250
|
-
function findRawOrDeclarationValue(raw, fields, lookup) {
|
|
3251
|
-
return (lookup.rawKey ? raw[lookup.rawKey] : void 0) || findFieldValue(fields, lookup.patterns, lookup.reject);
|
|
3252
|
-
}
|
|
3253
3245
|
function promoteCarrierFields(doc) {
|
|
3254
3246
|
const raw = doc;
|
|
3255
3247
|
promoteRawFields(raw, [
|
|
@@ -3266,55 +3258,14 @@ function promoteCarrierFields(doc) {
|
|
|
3266
3258
|
};
|
|
3267
3259
|
}
|
|
3268
3260
|
}
|
|
3269
|
-
var BROKER_NAME_PATTERNS = [
|
|
3270
|
-
"brokerName",
|
|
3271
|
-
"broker",
|
|
3272
|
-
"agentName",
|
|
3273
|
-
"agent",
|
|
3274
|
-
"producerName",
|
|
3275
|
-
"producerAgency",
|
|
3276
|
-
"agencyName",
|
|
3277
|
-
"brokerAgency"
|
|
3278
|
-
];
|
|
3279
|
-
var BROKER_CONTACT_PATTERNS = [
|
|
3280
|
-
"brokerContactName",
|
|
3281
|
-
"brokerContact",
|
|
3282
|
-
"agentContactName",
|
|
3283
|
-
"producerContactName",
|
|
3284
|
-
"producerContact"
|
|
3285
|
-
];
|
|
3286
|
-
var BROKER_LICENSE_PATTERNS = [
|
|
3287
|
-
"brokerLicenseNumber",
|
|
3288
|
-
"brokerNumber",
|
|
3289
|
-
"agentLicenseNumber",
|
|
3290
|
-
"producerLicenseNumber",
|
|
3291
|
-
"producerNumber",
|
|
3292
|
-
"agentNumber"
|
|
3293
|
-
];
|
|
3294
|
-
var BROKER_PHONE_PATTERNS = ["brokerPhone", "agentPhone", "producerPhone"];
|
|
3295
|
-
var BROKER_EMAIL_PATTERNS = ["brokerEmail", "agentEmail", "producerEmail"];
|
|
3296
|
-
var BROKER_ADDRESS_PATTERNS = ["brokerAddress", "agentAddress", "producerAddress"];
|
|
3297
3261
|
function promoteBroker(doc) {
|
|
3298
3262
|
const raw = doc;
|
|
3299
|
-
const
|
|
3300
|
-
const
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
const
|
|
3305
|
-
rawKey: "brokerContactName",
|
|
3306
|
-
patterns: BROKER_CONTACT_PATTERNS
|
|
3307
|
-
});
|
|
3308
|
-
const brokerLicense = findRawOrDeclarationValue(raw, fields, {
|
|
3309
|
-
rawKey: "brokerLicenseNumber",
|
|
3310
|
-
patterns: BROKER_LICENSE_PATTERNS
|
|
3311
|
-
});
|
|
3312
|
-
const brokerPhone = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_PHONE_PATTERNS });
|
|
3313
|
-
const brokerEmail = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_EMAIL_PATTERNS });
|
|
3314
|
-
const brokerAddress = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_ADDRESS_PATTERNS });
|
|
3315
|
-
if (brokerAgency) raw.brokerAgency = brokerAgency;
|
|
3316
|
-
if (brokerContact) raw.brokerContactName = brokerContact;
|
|
3317
|
-
if (brokerLicense) raw.brokerLicenseNumber = brokerLicense;
|
|
3263
|
+
const brokerAgency = findRawString(raw, ["brokerAgency"]);
|
|
3264
|
+
const brokerContact = findRawString(raw, ["brokerContactName"]);
|
|
3265
|
+
const brokerLicense = findRawString(raw, ["brokerLicenseNumber"]);
|
|
3266
|
+
const brokerPhone = findRawString(raw, ["brokerPhone"]);
|
|
3267
|
+
const brokerEmail = findRawString(raw, ["brokerEmail"]);
|
|
3268
|
+
const brokerAddress = findRawString(raw, ["brokerAddress"]);
|
|
3318
3269
|
if (!raw.producer && brokerAgency) {
|
|
3319
3270
|
raw.producer = {
|
|
3320
3271
|
agencyName: brokerAgency,
|
|
@@ -3326,134 +3277,9 @@ function promoteBroker(doc) {
|
|
|
3326
3277
|
};
|
|
3327
3278
|
}
|
|
3328
3279
|
}
|
|
3329
|
-
var LOSS_PAYEE_NAME_PATTERNS = [
|
|
3330
|
-
"lossPayeeName",
|
|
3331
|
-
"lossPayee",
|
|
3332
|
-
"lossPayeeHolder"
|
|
3333
|
-
];
|
|
3334
|
-
var LOSS_PAYEE_ADDRESS_PATTERNS = ["lossPayeeAddress"];
|
|
3335
|
-
var MORTGAGE_HOLDER_NAME_PATTERNS = [
|
|
3336
|
-
"mortgagee",
|
|
3337
|
-
"mortgageHolder",
|
|
3338
|
-
"mortgageHolderName",
|
|
3339
|
-
"mortgageeName",
|
|
3340
|
-
"lienholder",
|
|
3341
|
-
"lienholderName"
|
|
3342
|
-
];
|
|
3343
|
-
var MORTGAGE_HOLDER_ADDRESS_PATTERNS = [
|
|
3344
|
-
"mortgageeAddress",
|
|
3345
|
-
"mortgageHolderAddress",
|
|
3346
|
-
"lienholderAddress"
|
|
3347
|
-
];
|
|
3348
|
-
function promoteLossPayees(doc) {
|
|
3349
|
-
const raw = doc;
|
|
3350
|
-
const fields = getDeclarationFields(doc);
|
|
3351
|
-
if (!raw.lossPayees || Array.isArray(raw.lossPayees) && raw.lossPayees.length === 0) {
|
|
3352
|
-
const name = findFieldValue(fields, LOSS_PAYEE_NAME_PATTERNS);
|
|
3353
|
-
if (name) {
|
|
3354
|
-
const address = findFieldValue(fields, LOSS_PAYEE_ADDRESS_PATTERNS);
|
|
3355
|
-
raw.lossPayees = [{
|
|
3356
|
-
name,
|
|
3357
|
-
role: "loss_payee",
|
|
3358
|
-
...address ? { address: { street1: address } } : {}
|
|
3359
|
-
}];
|
|
3360
|
-
}
|
|
3361
|
-
}
|
|
3362
|
-
if (!raw.mortgageHolders || Array.isArray(raw.mortgageHolders) && raw.mortgageHolders.length === 0) {
|
|
3363
|
-
const name = findFieldValue(fields, MORTGAGE_HOLDER_NAME_PATTERNS);
|
|
3364
|
-
if (name) {
|
|
3365
|
-
const address = findFieldValue(fields, MORTGAGE_HOLDER_ADDRESS_PATTERNS);
|
|
3366
|
-
raw.mortgageHolders = [{
|
|
3367
|
-
name,
|
|
3368
|
-
role: "mortgage_holder",
|
|
3369
|
-
...address ? { address: { street1: address } } : {}
|
|
3370
|
-
}];
|
|
3371
|
-
}
|
|
3372
|
-
}
|
|
3373
|
-
}
|
|
3374
|
-
function promoteLocations(doc) {
|
|
3375
|
-
const raw = doc;
|
|
3376
|
-
if (Array.isArray(raw.locations) && raw.locations.length > 0) return;
|
|
3377
|
-
const fields = getDeclarationFields(doc);
|
|
3378
|
-
if (fields.length === 0) return;
|
|
3379
|
-
const locationGroups = /* @__PURE__ */ new Map();
|
|
3380
|
-
for (const f of fields) {
|
|
3381
|
-
const lower = f.field.toLowerCase().replace(/[\s_-]/g, "");
|
|
3382
|
-
if (lower.includes("locationnumber") || lower.includes("locnumber") || lower.includes("locno")) {
|
|
3383
|
-
const key = f.value;
|
|
3384
|
-
if (!locationGroups.has(key)) locationGroups.set(key, /* @__PURE__ */ new Map());
|
|
3385
|
-
locationGroups.get(key).set("number", f.value);
|
|
3386
|
-
continue;
|
|
3387
|
-
}
|
|
3388
|
-
if (lower.includes("buildingnumber") || lower.includes("bldgnumber") || lower.includes("bldgno")) {
|
|
3389
|
-
const lastKey2 = [...locationGroups.keys()].pop();
|
|
3390
|
-
if (lastKey2) locationGroups.get(lastKey2).set("buildingNumber", f.value);
|
|
3391
|
-
continue;
|
|
3392
|
-
}
|
|
3393
|
-
const section = (f.section ?? "").toLowerCase();
|
|
3394
|
-
const isLocationField = section.includes("location") || section.includes("building") || section.includes("premises") || section.includes("schedule of locations");
|
|
3395
|
-
if (!isLocationField) continue;
|
|
3396
|
-
if (locationGroups.size === 0) {
|
|
3397
|
-
locationGroups.set("1", /* @__PURE__ */ new Map([["number", "1"]]));
|
|
3398
|
-
}
|
|
3399
|
-
const lastKey = [...locationGroups.keys()].pop();
|
|
3400
|
-
const group = locationGroups.get(lastKey);
|
|
3401
|
-
if (lower.includes("construction") || lower.includes("constructiontype")) {
|
|
3402
|
-
group.set("constructionType", f.value);
|
|
3403
|
-
} else if (lower.includes("occupancy") || lower.includes("occupancytype")) {
|
|
3404
|
-
group.set("occupancy", f.value);
|
|
3405
|
-
} else if (lower.includes("yearbuilt")) {
|
|
3406
|
-
group.set("yearBuilt", f.value);
|
|
3407
|
-
} else if (lower.includes("squarefootage") || lower.includes("sqft") || lower.includes("area")) {
|
|
3408
|
-
group.set("squareFootage", f.value);
|
|
3409
|
-
} else if (lower.includes("protectionclass") || lower.includes("fireprotection")) {
|
|
3410
|
-
group.set("protectionClass", f.value);
|
|
3411
|
-
} else if (lower.includes("sprinkler")) {
|
|
3412
|
-
group.set("sprinklered", f.value);
|
|
3413
|
-
} else if (lower.includes("buildingvalue") || lower.includes("buildingamt") || lower.includes("buildingcoverage")) {
|
|
3414
|
-
group.set("buildingValue", f.value);
|
|
3415
|
-
} else if (lower.includes("contentsvalue") || lower.includes("contentsamt") || lower.includes("contentscoverage")) {
|
|
3416
|
-
group.set("contentsValue", f.value);
|
|
3417
|
-
} else if (lower.includes("businessincome") || lower.includes("bivalue") || lower.includes("businessincomevalue")) {
|
|
3418
|
-
group.set("businessIncomeValue", f.value);
|
|
3419
|
-
} else if (lower.includes("description") || lower.includes("buildingdescription") || lower.includes("locationdescription")) {
|
|
3420
|
-
group.set("description", f.value);
|
|
3421
|
-
} else if (lower.includes("address") || lower.includes("industryaddress") || lower.includes("locationaddress") || lower.includes("premisesaddress")) {
|
|
3422
|
-
group.set("address", f.value);
|
|
3423
|
-
} else if (lower.includes("alarm") || lower.includes("alarmtype")) {
|
|
3424
|
-
group.set("alarmType", f.value);
|
|
3425
|
-
}
|
|
3426
|
-
}
|
|
3427
|
-
if (locationGroups.size === 0) return;
|
|
3428
|
-
const locations = [];
|
|
3429
|
-
for (const [, group] of locationGroups) {
|
|
3430
|
-
const num = parseInt(group.get("number") ?? "0", 10) || locations.length + 1;
|
|
3431
|
-
const addressStr = group.get("address");
|
|
3432
|
-
locations.push({
|
|
3433
|
-
number: num,
|
|
3434
|
-
address: addressStr ? { street1: addressStr } : { street1: "See declarations" },
|
|
3435
|
-
...group.get("description") ? { description: group.get("description") } : {},
|
|
3436
|
-
...group.get("constructionType") ? { constructionType: group.get("constructionType") } : {},
|
|
3437
|
-
...group.get("occupancy") ? { occupancy: group.get("occupancy") } : {},
|
|
3438
|
-
...group.get("yearBuilt") ? { yearBuilt: parseInt(group.get("yearBuilt"), 10) || void 0 } : {},
|
|
3439
|
-
...group.get("squareFootage") ? { squareFootage: parseInt(group.get("squareFootage").replace(/[^0-9]/g, ""), 10) || void 0 } : {},
|
|
3440
|
-
...group.get("protectionClass") ? { protectionClass: group.get("protectionClass") } : {},
|
|
3441
|
-
...group.get("sprinklered") ? { sprinklered: /yes|true/i.test(group.get("sprinklered")) } : {},
|
|
3442
|
-
...group.get("buildingValue") ? { buildingValue: group.get("buildingValue") } : {},
|
|
3443
|
-
...group.get("contentsValue") ? { contentsValue: group.get("contentsValue") } : {},
|
|
3444
|
-
...group.get("businessIncomeValue") ? { businessIncomeValue: group.get("businessIncomeValue") } : {},
|
|
3445
|
-
...group.get("alarmType") ? { alarmType: group.get("alarmType") } : {}
|
|
3446
|
-
});
|
|
3447
|
-
}
|
|
3448
|
-
if (locations.length > 0) {
|
|
3449
|
-
raw.locations = locations;
|
|
3450
|
-
}
|
|
3451
|
-
}
|
|
3452
3280
|
function promoteExtractedFields(doc) {
|
|
3453
3281
|
promoteCarrierFields(doc);
|
|
3454
3282
|
promoteBroker(doc);
|
|
3455
|
-
promoteLossPayees(doc);
|
|
3456
|
-
promoteLocations(doc);
|
|
3457
3283
|
}
|
|
3458
3284
|
|
|
3459
3285
|
// src/extraction/alignment.ts
|
|
@@ -6938,113 +6764,6 @@ Your task:
|
|
|
6938
6764
|
Return JSON only.`;
|
|
6939
6765
|
}
|
|
6940
6766
|
|
|
6941
|
-
// src/extraction/heuristics.ts
|
|
6942
|
-
function looksReferential(value) {
|
|
6943
|
-
if (typeof value !== "string") return false;
|
|
6944
|
-
const normalized = value.toLowerCase();
|
|
6945
|
-
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");
|
|
6946
|
-
}
|
|
6947
|
-
function looksCoveredReasonSection(section) {
|
|
6948
|
-
const title = String(section.title ?? "").toLowerCase();
|
|
6949
|
-
const type = String(section.type ?? "").toLowerCase();
|
|
6950
|
-
return type === "covered_reason" || title.includes("covered cause") || title.includes("covered reason") || title.includes("covered peril");
|
|
6951
|
-
}
|
|
6952
|
-
|
|
6953
|
-
// src/extraction/referential-workflow.ts
|
|
6954
|
-
function normalizeText2(value) {
|
|
6955
|
-
return typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
6956
|
-
}
|
|
6957
|
-
function containsTarget(value, target) {
|
|
6958
|
-
const normalizedValue = normalizeText2(value);
|
|
6959
|
-
return Boolean(normalizedValue && target && normalizedValue.includes(target));
|
|
6960
|
-
}
|
|
6961
|
-
function pageRangeFrom(startPage, endPage) {
|
|
6962
|
-
if (typeof startPage !== "number" || !Number.isFinite(startPage) || startPage <= 0) {
|
|
6963
|
-
return void 0;
|
|
6964
|
-
}
|
|
6965
|
-
const normalizedEnd = typeof endPage === "number" && Number.isFinite(endPage) && endPage >= startPage ? endPage : startPage;
|
|
6966
|
-
return { startPage, endPage: normalizedEnd };
|
|
6967
|
-
}
|
|
6968
|
-
function parseReferentialTarget(rawTarget) {
|
|
6969
|
-
const raw = rawTarget?.trim() || "unknown";
|
|
6970
|
-
const normalized = raw.toLowerCase();
|
|
6971
|
-
if (normalized === "unknown") return { raw, normalized, kind: "unknown" };
|
|
6972
|
-
if (/declarations?|dec\b|decs\b/.test(normalized)) return { raw, normalized, kind: "declarations" };
|
|
6973
|
-
if (/schedule|scheduled/.test(normalized)) return { raw, normalized, kind: "schedule" };
|
|
6974
|
-
if (/\bitem\b/.test(normalized)) return { raw, normalized, kind: "item" };
|
|
6975
|
-
if (/premises?|location|building/.test(normalized)) return { raw, normalized, kind: "premises" };
|
|
6976
|
-
if (/\bsection\b/.test(normalized)) return { raw, normalized, kind: "section" };
|
|
6977
|
-
if (/policy|coverage\s+part|coverage\s+form/.test(normalized)) return { raw, normalized, kind: "policy" };
|
|
6978
|
-
return { raw, normalized, kind: "unknown" };
|
|
6979
|
-
}
|
|
6980
|
-
function findLocalReferentialPages(params) {
|
|
6981
|
-
const targetLower = params.referenceTarget.toLowerCase();
|
|
6982
|
-
for (const section of params.sections) {
|
|
6983
|
-
if (containsTarget(section.title, targetLower)) {
|
|
6984
|
-
const range = pageRangeFrom(section.pageStart, section.pageEnd);
|
|
6985
|
-
if (range) return range;
|
|
6986
|
-
}
|
|
6987
|
-
}
|
|
6988
|
-
for (const form of params.formInventory) {
|
|
6989
|
-
const titleMatch = containsTarget(form.title, targetLower);
|
|
6990
|
-
const typeMatch = containsTarget(form.formType, targetLower);
|
|
6991
|
-
const numberMatch = containsTarget(form.formNumber, targetLower);
|
|
6992
|
-
if (titleMatch || typeMatch || numberMatch) {
|
|
6993
|
-
const range = pageRangeFrom(form.pageStart, form.pageEnd);
|
|
6994
|
-
if (range) return range;
|
|
6995
|
-
}
|
|
6996
|
-
}
|
|
6997
|
-
return void 0;
|
|
6998
|
-
}
|
|
6999
|
-
function findDeclarationsSchedulePages(parsedTarget, formInventory) {
|
|
7000
|
-
for (const form of formInventory) {
|
|
7001
|
-
const formType = normalizeText2(form.formType);
|
|
7002
|
-
const title = normalizeText2(form.title);
|
|
7003
|
-
const matchesDeclarations = formType === "declarations" || /declarations?|dec\b|decs\b/.test(title);
|
|
7004
|
-
const matchesSchedule = /schedule|scheduled|coverage/.test(title) || formType === "coverage";
|
|
7005
|
-
const shouldUse = parsedTarget.kind === "declarations" ? matchesDeclarations : parsedTarget.kind === "schedule" || parsedTarget.kind === "item" || parsedTarget.kind === "premises" ? matchesSchedule || matchesDeclarations : parsedTarget.kind === "policy" ? matchesDeclarations || matchesSchedule : false;
|
|
7006
|
-
if (shouldUse) {
|
|
7007
|
-
const range = pageRangeFrom(form.pageStart, form.pageEnd);
|
|
7008
|
-
if (range) return range;
|
|
7009
|
-
}
|
|
7010
|
-
}
|
|
7011
|
-
return void 0;
|
|
7012
|
-
}
|
|
7013
|
-
function findSectionPages(parsedTarget, sections) {
|
|
7014
|
-
for (const section of sections) {
|
|
7015
|
-
const title = normalizeText2(section.title);
|
|
7016
|
-
const type = normalizeText2(section.type);
|
|
7017
|
-
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);
|
|
7018
|
-
if (matchesKind) {
|
|
7019
|
-
const range = pageRangeFrom(section.pageStart, section.pageEnd);
|
|
7020
|
-
if (range) return range;
|
|
7021
|
-
}
|
|
7022
|
-
}
|
|
7023
|
-
return void 0;
|
|
7024
|
-
}
|
|
7025
|
-
function decideReferentialResolutionAction(params) {
|
|
7026
|
-
if (params.localPageRange) {
|
|
7027
|
-
return { kind: "lookup_pages", source: "local", pageRange: params.localPageRange };
|
|
7028
|
-
}
|
|
7029
|
-
const parsedTarget = parseReferentialTarget(params.referenceTarget);
|
|
7030
|
-
const declarationsScheduleRange = findDeclarationsSchedulePages(parsedTarget, params.formInventory);
|
|
7031
|
-
if (declarationsScheduleRange) {
|
|
7032
|
-
return {
|
|
7033
|
-
kind: "lookup_pages",
|
|
7034
|
-
source: "declarations_schedule",
|
|
7035
|
-
pageRange: declarationsScheduleRange
|
|
7036
|
-
};
|
|
7037
|
-
}
|
|
7038
|
-
const sectionRange = findSectionPages(parsedTarget, params.sections);
|
|
7039
|
-
if (sectionRange) {
|
|
7040
|
-
return { kind: "lookup_pages", source: "sections", pageRange: sectionRange };
|
|
7041
|
-
}
|
|
7042
|
-
if (parsedTarget.kind === "unknown") {
|
|
7043
|
-
return { kind: "skip", reason: "no concrete reference target" };
|
|
7044
|
-
}
|
|
7045
|
-
return { kind: "page_location" };
|
|
7046
|
-
}
|
|
7047
|
-
|
|
7048
6767
|
// src/extraction/resolve-referential.ts
|
|
7049
6768
|
function formatDoclingTextContext(providerOptions) {
|
|
7050
6769
|
const doclingText = providerOptions?.doclingText;
|
|
@@ -7057,24 +6776,7 @@ ${doclingText}`;
|
|
|
7057
6776
|
function parseReferenceTarget(text) {
|
|
7058
6777
|
if (typeof text !== "string") return void 0;
|
|
7059
6778
|
const normalized = text.trim();
|
|
7060
|
-
|
|
7061
|
-
const sectionMatch = normalized.match(/\b(Section\s+\d+[A-Za-z]?)/i);
|
|
7062
|
-
if (sectionMatch) return sectionMatch[1];
|
|
7063
|
-
const itemMatch = normalized.match(/\b(Item\s+\d+[A-Za-z]?)/i);
|
|
7064
|
-
if (itemMatch) return itemMatch[1];
|
|
7065
|
-
const premisesMatch = normalized.match(/\b(Premises?(?:\s+No\.?\s*\d+[A-Za-z]?|\s+\d+[A-Za-z]?)?)/i);
|
|
7066
|
-
if (premisesMatch) return premisesMatch[1].trim();
|
|
7067
|
-
if (/declarations/i.test(normalized)) return "Declarations";
|
|
7068
|
-
const scheduleMatch = normalized.match(/\b(Schedule(?:\s+of\s+[A-Za-z ]+)?)/i);
|
|
7069
|
-
if (scheduleMatch) return scheduleMatch[1].trim();
|
|
7070
|
-
const asStatedMatch = normalized.match(/(?:as\s+stated\s+in|see|shown\s+in(?:\s+the)?)\s+(.+)/i);
|
|
7071
|
-
if (asStatedMatch) {
|
|
7072
|
-
let target = asStatedMatch[1].trim().replace(/\s+of\s+the\s+policy$/i, "").trim();
|
|
7073
|
-
target = target.replace(/\.+$/, "").trim();
|
|
7074
|
-
if (target) return target;
|
|
7075
|
-
}
|
|
7076
|
-
if (/if applicable/i.test(normalized)) return void 0;
|
|
7077
|
-
return void 0;
|
|
6779
|
+
return normalized || void 0;
|
|
7078
6780
|
}
|
|
7079
6781
|
var PageLocationSchema = import_zod40.z.object({
|
|
7080
6782
|
startPage: import_zod40.z.number(),
|
|
@@ -7083,8 +6785,6 @@ var PageLocationSchema = import_zod40.z.object({
|
|
|
7083
6785
|
async function findReferencedPages(params) {
|
|
7084
6786
|
const {
|
|
7085
6787
|
referenceTarget,
|
|
7086
|
-
sections,
|
|
7087
|
-
formInventory,
|
|
7088
6788
|
pdfInput,
|
|
7089
6789
|
pageCount,
|
|
7090
6790
|
generateObject,
|
|
@@ -7094,29 +6794,6 @@ async function findReferencedPages(params) {
|
|
|
7094
6794
|
modelBudgetConstraints,
|
|
7095
6795
|
log
|
|
7096
6796
|
} = params;
|
|
7097
|
-
const localPageRange = findLocalReferentialPages({
|
|
7098
|
-
referenceTarget,
|
|
7099
|
-
sections,
|
|
7100
|
-
formInventory
|
|
7101
|
-
});
|
|
7102
|
-
const action = decideReferentialResolutionAction({
|
|
7103
|
-
referenceTarget,
|
|
7104
|
-
sections,
|
|
7105
|
-
formInventory,
|
|
7106
|
-
localPageRange
|
|
7107
|
-
});
|
|
7108
|
-
if (action.kind === "lookup_pages") {
|
|
7109
|
-
await log?.(
|
|
7110
|
-
`Referential target "${referenceTarget}" resolved to pages ${action.pageRange.startPage}-${action.pageRange.endPage} via ${action.source}.`
|
|
7111
|
-
);
|
|
7112
|
-
return action.pageRange;
|
|
7113
|
-
}
|
|
7114
|
-
if (action.kind === "skip") {
|
|
7115
|
-
await log?.(
|
|
7116
|
-
`Skipping referential target "${referenceTarget}": ${action.reason}.`
|
|
7117
|
-
);
|
|
7118
|
-
return void 0;
|
|
7119
|
-
}
|
|
7120
6797
|
try {
|
|
7121
6798
|
const budget = resolveModelBudget({
|
|
7122
6799
|
taskKind: "extraction_referential_lookup",
|
|
@@ -7195,7 +6872,7 @@ async function resolveReferentialCoverages(params) {
|
|
|
7195
6872
|
const referentialCoverages = coverages.filter((cov) => {
|
|
7196
6873
|
const limitType = cov.limitValueType;
|
|
7197
6874
|
const deductibleType = cov.deductibleValueType;
|
|
7198
|
-
return limitType === "referential" || limitType === "as_stated" || deductibleType === "referential" || deductibleType === "as_stated"
|
|
6875
|
+
return limitType === "referential" || limitType === "as_stated" || deductibleType === "referential" || deductibleType === "as_stated";
|
|
7199
6876
|
});
|
|
7200
6877
|
const attempts = referentialCoverages.length;
|
|
7201
6878
|
if (attempts === 0) {
|
|
@@ -7213,9 +6890,9 @@ async function resolveReferentialCoverages(params) {
|
|
|
7213
6890
|
const targetGroups = /* @__PURE__ */ new Map();
|
|
7214
6891
|
for (let i = 0; i < referentialCoverages.length; i++) {
|
|
7215
6892
|
const cov = referentialCoverages[i];
|
|
7216
|
-
const refString =
|
|
6893
|
+
const refString = cov.limit ?? "";
|
|
7217
6894
|
const sectionRef = typeof cov.sectionRef === "string" ? cov.sectionRef : "";
|
|
7218
|
-
const parsedTarget =
|
|
6895
|
+
const parsedTarget = sectionRef || parseReferenceTarget(refString);
|
|
7219
6896
|
const target = parsedTarget || "unknown";
|
|
7220
6897
|
const group = targetGroups.get(target) ?? [];
|
|
7221
6898
|
group.push({ coverage: cov, index: i });
|
|
@@ -7309,8 +6986,8 @@ async function resolveReferentialCoverages(params) {
|
|
|
7309
6986
|
unresolved++;
|
|
7310
6987
|
continue;
|
|
7311
6988
|
}
|
|
7312
|
-
const limitResolved = rc.resolvedLimit && rc.resolvedLimitValueType !== "referential" && rc.resolvedLimitValueType !== "as_stated"
|
|
7313
|
-
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";
|
|
7314
6991
|
if (limitResolved || deductibleResolved) {
|
|
7315
6992
|
if (limitResolved) {
|
|
7316
6993
|
coverage.limit = rc.resolvedLimit;
|
|
@@ -7489,6 +7166,13 @@ function shouldFailQualityGate(mode, status) {
|
|
|
7489
7166
|
return mode === "strict" && status === "failed";
|
|
7490
7167
|
}
|
|
7491
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
|
+
|
|
7492
7176
|
// src/extraction/quality.ts
|
|
7493
7177
|
function normalizeFormNumber(value) {
|
|
7494
7178
|
if (typeof value !== "string") return void 0;
|
|
@@ -7664,17 +7348,6 @@ function buildExtractionReviewReport(params) {
|
|
|
7664
7348
|
itemName: typeof coverage.name === "string" ? coverage.name : void 0
|
|
7665
7349
|
});
|
|
7666
7350
|
}
|
|
7667
|
-
if (looksReferential(coverage.limit) || looksReferential(coverage.deductible)) {
|
|
7668
|
-
deterministicIssues.push({
|
|
7669
|
-
code: "coverage_referential_value",
|
|
7670
|
-
severity: "warning",
|
|
7671
|
-
message: `Coverage "${String(coverage.name ?? "unknown")}" contains referential language instead of a concrete scheduled term.`,
|
|
7672
|
-
extractorName: "coverage_limits",
|
|
7673
|
-
formNumber,
|
|
7674
|
-
pageNumber: typeof coverage.pageNumber === "number" ? coverage.pageNumber : void 0,
|
|
7675
|
-
itemName: typeof coverage.name === "string" ? coverage.name : void 0
|
|
7676
|
-
});
|
|
7677
|
-
}
|
|
7678
7351
|
if (formNumber && !inventory.has(formNumber)) {
|
|
7679
7352
|
deterministicIssues.push({
|
|
7680
7353
|
code: "coverage_form_missing_from_inventory",
|
|
@@ -7814,17 +7487,6 @@ function buildExtractionReviewReport(params) {
|
|
|
7814
7487
|
itemName
|
|
7815
7488
|
});
|
|
7816
7489
|
}
|
|
7817
|
-
if (looksReferential(content) || looksReferential(coveredReason.reason)) {
|
|
7818
|
-
deterministicIssues.push({
|
|
7819
|
-
code: "covered_reason_referential_value",
|
|
7820
|
-
severity: "warning",
|
|
7821
|
-
message: `Covered reason "${itemName}" contains referential language instead of the extracted covered cause wording.`,
|
|
7822
|
-
extractorName: "covered_reasons",
|
|
7823
|
-
formNumber: normalizeFormNumber(coveredReason.formNumber),
|
|
7824
|
-
pageNumber: typeof coveredReason.pageNumber === "number" ? coveredReason.pageNumber : typeof coveredReason.pageStart === "number" ? coveredReason.pageStart : void 0,
|
|
7825
|
-
itemName
|
|
7826
|
-
});
|
|
7827
|
-
}
|
|
7828
7490
|
}
|
|
7829
7491
|
for (const section of sections) {
|
|
7830
7492
|
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)) {
|