@claritylabs/cl-sdk 3.1.13 → 3.1.15
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 +113 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -9142,6 +9142,10 @@ var OperationalProfileCleanupSchema = z41.object({
|
|
|
9142
9142
|
})).default([]),
|
|
9143
9143
|
warnings: z41.array(z41.string()).default([])
|
|
9144
9144
|
});
|
|
9145
|
+
var CLEANUP_CANDIDATE_ID_LIMIT = 12;
|
|
9146
|
+
var CLEANUP_SOURCE_NODE_LIMIT = 90;
|
|
9147
|
+
var CLEANUP_SIBLING_WINDOW = 4;
|
|
9148
|
+
var CLEANUP_KEYWORD = /\b(coverage|limit|liability|deductible|retention|retroactive|premium|aggregate|sublimit|sub-limit|claim|occurrence|loss|proceeding|endorsement|declarations?)\b|\$[0-9]/i;
|
|
9145
9149
|
function compactNode(node, maxText = 700) {
|
|
9146
9150
|
return {
|
|
9147
9151
|
id: node.id,
|
|
@@ -9154,6 +9158,9 @@ function compactNode(node, maxText = 700) {
|
|
|
9154
9158
|
text: (node.textExcerpt ?? node.description).slice(0, maxText)
|
|
9155
9159
|
};
|
|
9156
9160
|
}
|
|
9161
|
+
function compactIds(ids) {
|
|
9162
|
+
return uniqueStrings([...ids ?? []]).slice(0, CLEANUP_CANDIDATE_ID_LIMIT);
|
|
9163
|
+
}
|
|
9157
9164
|
function compactCoverageForCleanup(coverage, coverageIndex) {
|
|
9158
9165
|
return {
|
|
9159
9166
|
coverageIndex,
|
|
@@ -9163,8 +9170,8 @@ function compactCoverageForCleanup(coverage, coverageIndex) {
|
|
|
9163
9170
|
premium: coverage.premium,
|
|
9164
9171
|
retroactiveDate: coverage.retroactiveDate,
|
|
9165
9172
|
coverageOrigin: coverage.coverageOrigin,
|
|
9166
|
-
sourceNodeIds: coverage.sourceNodeIds,
|
|
9167
|
-
sourceSpanIds: coverage.sourceSpanIds,
|
|
9173
|
+
sourceNodeIds: compactIds(coverage.sourceNodeIds),
|
|
9174
|
+
sourceSpanIds: compactIds(coverage.sourceSpanIds),
|
|
9168
9175
|
terms: coverage.limits.map((term, termIndex) => ({
|
|
9169
9176
|
termIndex,
|
|
9170
9177
|
kind: term.kind,
|
|
@@ -9172,13 +9179,112 @@ function compactCoverageForCleanup(coverage, coverageIndex) {
|
|
|
9172
9179
|
value: term.value,
|
|
9173
9180
|
amount: term.amount,
|
|
9174
9181
|
appliesTo: term.appliesTo,
|
|
9175
|
-
sourceNodeIds: term.sourceNodeIds,
|
|
9176
|
-
sourceSpanIds: term.sourceSpanIds
|
|
9182
|
+
sourceNodeIds: compactIds(term.sourceNodeIds),
|
|
9183
|
+
sourceSpanIds: compactIds(term.sourceSpanIds)
|
|
9177
9184
|
}))
|
|
9178
9185
|
};
|
|
9179
9186
|
}
|
|
9187
|
+
function nodeTextForSelection(node) {
|
|
9188
|
+
return [
|
|
9189
|
+
node.kind,
|
|
9190
|
+
node.title,
|
|
9191
|
+
node.description,
|
|
9192
|
+
node.textExcerpt
|
|
9193
|
+
].filter(Boolean).join(" ");
|
|
9194
|
+
}
|
|
9195
|
+
function coverageTextForSelection(coverage) {
|
|
9196
|
+
return [
|
|
9197
|
+
coverage.name,
|
|
9198
|
+
coverage.coverageCode,
|
|
9199
|
+
coverage.limit,
|
|
9200
|
+
coverage.deductible,
|
|
9201
|
+
coverage.premium,
|
|
9202
|
+
coverage.retroactiveDate,
|
|
9203
|
+
coverage.sectionRef,
|
|
9204
|
+
coverage.endorsementNumber,
|
|
9205
|
+
...coverage.limits.flatMap((term) => [
|
|
9206
|
+
term.kind,
|
|
9207
|
+
term.label,
|
|
9208
|
+
term.value,
|
|
9209
|
+
term.appliesTo
|
|
9210
|
+
])
|
|
9211
|
+
].filter(Boolean).join(" ");
|
|
9212
|
+
}
|
|
9213
|
+
function nodeTextMatchesCoverage(node, coverageTerms) {
|
|
9214
|
+
const text = nodeTextForSelection(node).toLowerCase();
|
|
9215
|
+
return coverageTerms.some((term) => term.length >= 5 && text.includes(term));
|
|
9216
|
+
}
|
|
9217
|
+
function selectCoverageCleanupNodes(sourceTree, profile) {
|
|
9218
|
+
const nodeById = new Map(sourceTree.map((node) => [node.id, node]));
|
|
9219
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
9220
|
+
for (const node of sourceTree) {
|
|
9221
|
+
if (!node.parentId) continue;
|
|
9222
|
+
const children = childrenByParent.get(node.parentId) ?? [];
|
|
9223
|
+
children.push(node);
|
|
9224
|
+
childrenByParent.set(node.parentId, children);
|
|
9225
|
+
}
|
|
9226
|
+
for (const children of childrenByParent.values()) {
|
|
9227
|
+
children.sort((left, right) => left.order - right.order);
|
|
9228
|
+
}
|
|
9229
|
+
const selected = /* @__PURE__ */ new Map();
|
|
9230
|
+
const addNode = (node, score) => {
|
|
9231
|
+
if (!node || node.kind === "document") return;
|
|
9232
|
+
const current = selected.get(node.id);
|
|
9233
|
+
if (!current || score > current.score) selected.set(node.id, { node, score });
|
|
9234
|
+
};
|
|
9235
|
+
const sourceNodeIds = uniqueStrings(profile.coverages.flatMap((coverage) => [
|
|
9236
|
+
...coverage.sourceNodeIds,
|
|
9237
|
+
...coverage.limits.flatMap((term) => term.sourceNodeIds)
|
|
9238
|
+
]));
|
|
9239
|
+
const coveragePages2 = /* @__PURE__ */ new Set();
|
|
9240
|
+
const coverageTerms = uniqueStrings(profile.coverages.flatMap(
|
|
9241
|
+
(coverage) => coverageTextForSelection(coverage).toLowerCase().split(/[^a-z0-9$,.]+/i).filter((part) => part.length >= 5)
|
|
9242
|
+
));
|
|
9243
|
+
for (const id of sourceNodeIds) {
|
|
9244
|
+
const node = nodeById.get(id);
|
|
9245
|
+
if (!node) continue;
|
|
9246
|
+
addNode(node, 1e3);
|
|
9247
|
+
if (node.pageStart) coveragePages2.add(node.pageStart);
|
|
9248
|
+
if (node.pageEnd) coveragePages2.add(node.pageEnd);
|
|
9249
|
+
let parentId = node.parentId;
|
|
9250
|
+
let parentScore = 940;
|
|
9251
|
+
while (parentId) {
|
|
9252
|
+
const parent = nodeById.get(parentId);
|
|
9253
|
+
if (!parent) break;
|
|
9254
|
+
addNode(parent, parentScore);
|
|
9255
|
+
parentId = parent.parentId;
|
|
9256
|
+
parentScore -= 30;
|
|
9257
|
+
}
|
|
9258
|
+
const siblings = node.parentId ? childrenByParent.get(node.parentId) ?? [] : [];
|
|
9259
|
+
for (const sibling of siblings) {
|
|
9260
|
+
if (Math.abs(sibling.order - node.order) <= CLEANUP_SIBLING_WINDOW) {
|
|
9261
|
+
addNode(sibling, 850 - Math.abs(sibling.order - node.order));
|
|
9262
|
+
}
|
|
9263
|
+
}
|
|
9264
|
+
}
|
|
9265
|
+
for (const selectedNode of [...selected.values()].map((entry) => entry.node)) {
|
|
9266
|
+
const children = childrenByParent.get(selectedNode.id) ?? [];
|
|
9267
|
+
for (const child of children.slice(0, 24)) addNode(child, 760);
|
|
9268
|
+
}
|
|
9269
|
+
for (const node of sourceTree) {
|
|
9270
|
+
if (node.kind === "document") continue;
|
|
9271
|
+
if (!node.pageStart || !coveragePages2.has(node.pageStart)) continue;
|
|
9272
|
+
const text = nodeTextForSelection(node);
|
|
9273
|
+
if (CLEANUP_KEYWORD.test(text) || nodeTextMatchesCoverage(node, coverageTerms)) {
|
|
9274
|
+
addNode(node, 600);
|
|
9275
|
+
}
|
|
9276
|
+
}
|
|
9277
|
+
return [...selected.values()].sort(
|
|
9278
|
+
(left, right) => right.score - left.score || (left.node.pageStart ?? Number.MAX_SAFE_INTEGER) - (right.node.pageStart ?? Number.MAX_SAFE_INTEGER) || left.node.order - right.node.order
|
|
9279
|
+
).slice(0, CLEANUP_SOURCE_NODE_LIMIT).sort(
|
|
9280
|
+
(left, right) => (left.node.pageStart ?? Number.MAX_SAFE_INTEGER) - (right.node.pageStart ?? Number.MAX_SAFE_INTEGER) || left.node.order - right.node.order
|
|
9281
|
+
).map((entry) => entry.node);
|
|
9282
|
+
}
|
|
9180
9283
|
function buildOperationalProfileCleanupPrompt(sourceTree, profile) {
|
|
9181
|
-
const nodes = sourceTree
|
|
9284
|
+
const nodes = selectCoverageCleanupNodes(sourceTree, profile).map((node) => compactNode(
|
|
9285
|
+
node,
|
|
9286
|
+
node.kind === "page" || node.kind === "page_group" ? 260 : node.kind === "table_row" || node.kind === "table_cell" ? 520 : 360
|
|
9287
|
+
));
|
|
9182
9288
|
const candidate = {
|
|
9183
9289
|
documentType: profile.documentType,
|
|
9184
9290
|
policyTypes: profile.policyTypes,
|
|
@@ -10888,7 +10994,8 @@ function appendDistinctText(base, addition) {
|
|
|
10888
10994
|
if (!current) return next || void 0;
|
|
10889
10995
|
if (!next) return current;
|
|
10890
10996
|
if (current.toLowerCase().includes(next.toLowerCase())) return current;
|
|
10891
|
-
const
|
|
10997
|
+
const joinsWithSpace = /(?:[/(:;-]|,\s*)$/.test(current) || /\b(?:part of|including|subject to|not in addition to)$/i.test(current) || /^(?:aggregate|claim|loss|proceeding|occurrence|each\s+(?:claim|loss|proceeding|occurrence)|coverage\s+part\b)/i.test(next);
|
|
10998
|
+
const delimiter = joinsWithSpace ? " " : " / ";
|
|
10892
10999
|
return cleanText(`${current}${delimiter}${next}`, current);
|
|
10893
11000
|
}
|
|
10894
11001
|
function mergedBbox(nodes) {
|