@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.mjs
CHANGED
|
@@ -9064,6 +9064,29 @@ function cleanText(value, fallback) {
|
|
|
9064
9064
|
const text = value?.replace(/\s+/g, " ").trim();
|
|
9065
9065
|
return text || fallback;
|
|
9066
9066
|
}
|
|
9067
|
+
function simplifyOrganizerTitle(value, fallback, kind) {
|
|
9068
|
+
const title = cleanText(value, fallback);
|
|
9069
|
+
if (/^declarations\b/i.test(title)) return "Declarations";
|
|
9070
|
+
if (/^policy\s+form\b/i.test(title)) return "Policy Form";
|
|
9071
|
+
if (/^definitions\b/i.test(title)) return "Definitions";
|
|
9072
|
+
const endorsementNumber = title.match(/^endorsement\s+(?:no\.?|number|#)?\s*([A-Z0-9][A-Z0-9.-]*)\b/i)?.[1];
|
|
9073
|
+
if (endorsementNumber) return `Endorsement No. ${endorsementNumber}`;
|
|
9074
|
+
if (kind === "endorsement" && /^endorsements?\s+\d+\s*[–-]\s*\d+\b/i.test(title)) {
|
|
9075
|
+
return title.replace(/[–—]/g, "-").replace(/\s*\(.*/, "").trim();
|
|
9076
|
+
}
|
|
9077
|
+
return title;
|
|
9078
|
+
}
|
|
9079
|
+
function endorsementReference(value) {
|
|
9080
|
+
return value?.match(/\bendorsement\s+(?:no\.?|number|#)?\s*([A-Z0-9][A-Z0-9.-]*)\b/i)?.[1]?.toUpperCase();
|
|
9081
|
+
}
|
|
9082
|
+
function rejectsOrganizerGroup(group, children) {
|
|
9083
|
+
if (group.kind !== "endorsement") return false;
|
|
9084
|
+
if (/^endorsements?\s+\d+\s*[–-]\s*\d+\b/i.test(group.title)) return true;
|
|
9085
|
+
const childNumbers = new Set(
|
|
9086
|
+
children.map((child) => endorsementReference([child.title, child.description, child.textExcerpt].filter(Boolean).join(" "))).filter((value) => Boolean(value))
|
|
9087
|
+
);
|
|
9088
|
+
return childNumbers.size > 1;
|
|
9089
|
+
}
|
|
9067
9090
|
function compactNode(node, maxText = 700) {
|
|
9068
9091
|
return {
|
|
9069
9092
|
id: node.id,
|
|
@@ -9151,8 +9174,10 @@ Scope:
|
|
|
9151
9174
|
Rules:
|
|
9152
9175
|
- Use only node IDs from the provided list.
|
|
9153
9176
|
- Do not invent text, page numbers, source spans, limits, or policy facts.
|
|
9154
|
-
- You may relabel existing nodes and group adjacent top-level/page nodes from this batch when they are clearly one form,
|
|
9177
|
+
- 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.
|
|
9178
|
+
- Do not group separately numbered endorsements into one parent. Never create rollup titles such as "Endorsements 1-3 (...)".
|
|
9155
9179
|
- Add concise, human-readable titles to generic text, table, row, and cell nodes when the text makes their role clear.
|
|
9180
|
+
- 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.
|
|
9156
9181
|
- Groups must list existing childNodeIds only.
|
|
9157
9182
|
- Keep descriptions short and useful for search.
|
|
9158
9183
|
- Prefer the document's own form titles, endorsement titles, schedules, declarations headings, and page order over keyword-only guessing.
|
|
@@ -9202,17 +9227,20 @@ function applyOrganization(sourceTree, organization) {
|
|
|
9202
9227
|
return {
|
|
9203
9228
|
...node,
|
|
9204
9229
|
kind: label.kind ?? node.kind,
|
|
9205
|
-
title:
|
|
9230
|
+
title: simplifyOrganizerTitle(label.title, node.title, label.kind ?? node.kind),
|
|
9206
9231
|
description: cleanText(label.description, node.description)
|
|
9207
9232
|
};
|
|
9208
9233
|
});
|
|
9209
9234
|
for (const group of organization.groups) {
|
|
9210
9235
|
const children = group.childNodeIds.map((id2) => byId.get(id2)).filter((node2) => Boolean(node2));
|
|
9211
9236
|
if (children.length === 0) continue;
|
|
9237
|
+
if (rejectsOrganizerGroup(group, children)) continue;
|
|
9212
9238
|
const parentId = children[0].parentId;
|
|
9213
9239
|
if (!children.every((child) => child.parentId === parentId)) continue;
|
|
9214
9240
|
const documentId = children[0].documentId;
|
|
9215
|
-
const
|
|
9241
|
+
const title = simplifyOrganizerTitle(group.title, group.title, group.kind);
|
|
9242
|
+
const description = cleanText(group.description, title);
|
|
9243
|
+
const id = groupNodeId(documentId, { ...group, title });
|
|
9216
9244
|
if (byId.has(id)) continue;
|
|
9217
9245
|
const sourceSpanIds = [...new Set(children.flatMap((child) => child.sourceSpanIds))];
|
|
9218
9246
|
const pageStarts = children.map((child) => child.pageStart).filter((page) => typeof page === "number");
|
|
@@ -9223,8 +9251,8 @@ function applyOrganization(sourceTree, organization) {
|
|
|
9223
9251
|
documentId,
|
|
9224
9252
|
parentId,
|
|
9225
9253
|
kind: group.kind,
|
|
9226
|
-
title
|
|
9227
|
-
description
|
|
9254
|
+
title,
|
|
9255
|
+
description,
|
|
9228
9256
|
textExcerpt: children.map((child) => child.textExcerpt ?? child.description).filter(Boolean).join("\n\n").slice(0, 1600),
|
|
9229
9257
|
sourceSpanIds,
|
|
9230
9258
|
pageStart: pageStarts.length ? Math.min(...pageStarts) : void 0,
|