@claritylabs/cl-sdk 3.0.4 → 3.0.5
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 +33 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9411,6 +9411,29 @@ function cleanText(value, fallback) {
|
|
|
9411
9411
|
const text = value?.replace(/\s+/g, " ").trim();
|
|
9412
9412
|
return text || fallback;
|
|
9413
9413
|
}
|
|
9414
|
+
function simplifyOrganizerTitle(value, fallback, kind) {
|
|
9415
|
+
const title = cleanText(value, fallback);
|
|
9416
|
+
if (/^declarations\b/i.test(title)) return "Declarations";
|
|
9417
|
+
if (/^policy\s+form\b/i.test(title)) return "Policy Form";
|
|
9418
|
+
if (/^definitions\b/i.test(title)) return "Definitions";
|
|
9419
|
+
const endorsementNumber = title.match(/^endorsement\s+(?:no\.?|number|#)?\s*([A-Z0-9][A-Z0-9.-]*)\b/i)?.[1];
|
|
9420
|
+
if (endorsementNumber) return `Endorsement No. ${endorsementNumber}`;
|
|
9421
|
+
if (kind === "endorsement" && /^endorsements?\s+\d+\s*[–-]\s*\d+\b/i.test(title)) {
|
|
9422
|
+
return title.replace(/[–—]/g, "-").replace(/\s*\(.*/, "").trim();
|
|
9423
|
+
}
|
|
9424
|
+
return title;
|
|
9425
|
+
}
|
|
9426
|
+
function endorsementReference(value) {
|
|
9427
|
+
return value?.match(/\bendorsement\s+(?:no\.?|number|#)?\s*([A-Z0-9][A-Z0-9.-]*)\b/i)?.[1]?.toUpperCase();
|
|
9428
|
+
}
|
|
9429
|
+
function rejectsOrganizerGroup(group, children) {
|
|
9430
|
+
if (group.kind !== "endorsement") return false;
|
|
9431
|
+
if (/^endorsements?\s+\d+\s*[–-]\s*\d+\b/i.test(group.title)) return true;
|
|
9432
|
+
const childNumbers = new Set(
|
|
9433
|
+
children.map((child) => endorsementReference([child.title, child.description, child.textExcerpt].filter(Boolean).join(" "))).filter((value) => Boolean(value))
|
|
9434
|
+
);
|
|
9435
|
+
return childNumbers.size > 1;
|
|
9436
|
+
}
|
|
9414
9437
|
function compactNode(node, maxText = 700) {
|
|
9415
9438
|
return {
|
|
9416
9439
|
id: node.id,
|
|
@@ -9498,8 +9521,10 @@ Scope:
|
|
|
9498
9521
|
Rules:
|
|
9499
9522
|
- Use only node IDs from the provided list.
|
|
9500
9523
|
- Do not invent text, page numbers, source spans, limits, or policy facts.
|
|
9501
|
-
- You may relabel existing nodes and group adjacent top-level/page nodes from this batch when they are clearly one form,
|
|
9524
|
+
- You may relabel existing nodes and group adjacent top-level/page nodes from this batch only when they are clearly one continuous form, one declarations set, one schedule, or one clause family.
|
|
9525
|
+
- Do not group separately numbered endorsements into one parent. Never create rollup titles such as "Endorsements 1-3 (...)".
|
|
9502
9526
|
- Add concise, human-readable titles to generic text, table, row, and cell nodes when the text makes their role clear.
|
|
9527
|
+
- Keep organizer titles terse. Use the printed heading or a compact canonical title such as "Declarations", "Policy Form", "Definitions", or "Endorsement No. 3"; do not add parenthetical summaries.
|
|
9503
9528
|
- Groups must list existing childNodeIds only.
|
|
9504
9529
|
- Keep descriptions short and useful for search.
|
|
9505
9530
|
- Prefer the document's own form titles, endorsement titles, schedules, declarations headings, and page order over keyword-only guessing.
|
|
@@ -9549,17 +9574,20 @@ function applyOrganization(sourceTree, organization) {
|
|
|
9549
9574
|
return {
|
|
9550
9575
|
...node,
|
|
9551
9576
|
kind: label.kind ?? node.kind,
|
|
9552
|
-
title:
|
|
9577
|
+
title: simplifyOrganizerTitle(label.title, node.title, label.kind ?? node.kind),
|
|
9553
9578
|
description: cleanText(label.description, node.description)
|
|
9554
9579
|
};
|
|
9555
9580
|
});
|
|
9556
9581
|
for (const group of organization.groups) {
|
|
9557
9582
|
const children = group.childNodeIds.map((id2) => byId.get(id2)).filter((node2) => Boolean(node2));
|
|
9558
9583
|
if (children.length === 0) continue;
|
|
9584
|
+
if (rejectsOrganizerGroup(group, children)) continue;
|
|
9559
9585
|
const parentId = children[0].parentId;
|
|
9560
9586
|
if (!children.every((child) => child.parentId === parentId)) continue;
|
|
9561
9587
|
const documentId = children[0].documentId;
|
|
9562
|
-
const
|
|
9588
|
+
const title = simplifyOrganizerTitle(group.title, group.title, group.kind);
|
|
9589
|
+
const description = cleanText(group.description, title);
|
|
9590
|
+
const id = groupNodeId(documentId, { ...group, title });
|
|
9563
9591
|
if (byId.has(id)) continue;
|
|
9564
9592
|
const sourceSpanIds = [...new Set(children.flatMap((child) => child.sourceSpanIds))];
|
|
9565
9593
|
const pageStarts = children.map((child) => child.pageStart).filter((page) => typeof page === "number");
|
|
@@ -9570,8 +9598,8 @@ function applyOrganization(sourceTree, organization) {
|
|
|
9570
9598
|
documentId,
|
|
9571
9599
|
parentId,
|
|
9572
9600
|
kind: group.kind,
|
|
9573
|
-
title
|
|
9574
|
-
description
|
|
9601
|
+
title,
|
|
9602
|
+
description,
|
|
9575
9603
|
textExcerpt: children.map((child) => child.textExcerpt ?? child.description).filter(Boolean).join("\n\n").slice(0, 1600),
|
|
9576
9604
|
sourceSpanIds,
|
|
9577
9605
|
pageStart: pageStarts.length ? Math.min(...pageStarts) : void 0,
|