@claritylabs/cl-sdk 3.1.9 → 3.1.10
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 +66 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10736,6 +10736,19 @@ function isSourceTreeHeaderRow(row) {
|
|
|
10736
10736
|
function tableCellText(cell) {
|
|
10737
10737
|
return cleanText(cell.textExcerpt ?? cell.description ?? cell.title, "");
|
|
10738
10738
|
}
|
|
10739
|
+
function tableCellValueText(cell) {
|
|
10740
|
+
return cleanText(cell.textExcerpt ?? cell.description ?? "", "");
|
|
10741
|
+
}
|
|
10742
|
+
function tableRowTextFromCells(cells) {
|
|
10743
|
+
const text = cells.map((cell) => {
|
|
10744
|
+
const label = cleanText(cell.title, "");
|
|
10745
|
+
const value = tableCellValueText(cell);
|
|
10746
|
+
if (!value) return label;
|
|
10747
|
+
if (!label || value.toLowerCase() === label.toLowerCase()) return value;
|
|
10748
|
+
return `${label}: ${value}`;
|
|
10749
|
+
}).filter(Boolean).join(" | ");
|
|
10750
|
+
return text ? cleanText(text, text) : void 0;
|
|
10751
|
+
}
|
|
10739
10752
|
function tableRowTextForPrompt(row, cells) {
|
|
10740
10753
|
return cleanText(
|
|
10741
10754
|
cells.length ? cells.map(tableCellText).filter(Boolean).join(" | ") : row.textExcerpt ?? row.description ?? row.title,
|
|
@@ -10750,6 +10763,17 @@ function isGenericColumnTitle(value) {
|
|
|
10750
10763
|
const title = cleanText(value, "");
|
|
10751
10764
|
return !title || /^(?:column\s+\d+|table cell|value)$/i.test(title);
|
|
10752
10765
|
}
|
|
10766
|
+
function metadataColumnName(metadata) {
|
|
10767
|
+
const value = metadata?.columnName;
|
|
10768
|
+
return typeof value === "string" ? cleanText(value, "") || void 0 : void 0;
|
|
10769
|
+
}
|
|
10770
|
+
function metadataTableColumnName(metadata) {
|
|
10771
|
+
const table = metadata?.table;
|
|
10772
|
+
if (!table || typeof table !== "object" || Array.isArray(table)) return void 0;
|
|
10773
|
+
if (!("columnName" in table)) return void 0;
|
|
10774
|
+
const value = table.columnName;
|
|
10775
|
+
return typeof value === "string" ? cleanText(value, "") || void 0 : void 0;
|
|
10776
|
+
}
|
|
10753
10777
|
function bboxSummary(node) {
|
|
10754
10778
|
const box = node.bbox?.[0];
|
|
10755
10779
|
if (!box) return void 0;
|
|
@@ -10926,6 +10950,7 @@ function applyVisualTableRepair(sourceTree, repair) {
|
|
|
10926
10950
|
const byParent = nodesByParent(sourceTree);
|
|
10927
10951
|
const updates = /* @__PURE__ */ new Map();
|
|
10928
10952
|
const removeIds = /* @__PURE__ */ new Set();
|
|
10953
|
+
const rowsToRebuildText = /* @__PURE__ */ new Set();
|
|
10929
10954
|
const currentNode = (id) => updates.get(id) ?? byId.get(id);
|
|
10930
10955
|
for (const tableRepair of repair.tables) {
|
|
10931
10956
|
const table = byId.get(tableRepair.tableNodeId);
|
|
@@ -10940,19 +10965,39 @@ function applyVisualTableRepair(sourceTree, repair) {
|
|
|
10940
10965
|
}
|
|
10941
10966
|
if (columnLabels.size > 0) {
|
|
10942
10967
|
const firstLabelRowIndex = columnLabelStartIndex(rows);
|
|
10968
|
+
const normalizedLabels = new Set([...columnLabels.values()].map((label) => label.toLowerCase()));
|
|
10943
10969
|
for (const [rowIndex, { row, cells }] of rows.entries()) {
|
|
10944
10970
|
if (removeIds.has(row.id)) continue;
|
|
10945
|
-
if (rowIndex < firstLabelRowIndex)
|
|
10971
|
+
if (rowIndex < firstLabelRowIndex) {
|
|
10972
|
+
for (const cell of cells) {
|
|
10973
|
+
const metadataLabel = metadataColumnName(cell.metadata);
|
|
10974
|
+
if (metadataLabel && isGenericColumnTitle(metadataLabel) && normalizedLabels.has(cleanText(cell.title, "").toLowerCase())) {
|
|
10975
|
+
updates.set(cell.id, {
|
|
10976
|
+
...currentNode(cell.id) ?? cell,
|
|
10977
|
+
title: metadataLabel,
|
|
10978
|
+
description: tableCellDescription(cell, metadataLabel),
|
|
10979
|
+
metadata: metadataWithColumnLabel(cell.metadata, metadataLabel)
|
|
10980
|
+
});
|
|
10981
|
+
rowsToRebuildText.add(row.id);
|
|
10982
|
+
}
|
|
10983
|
+
}
|
|
10984
|
+
continue;
|
|
10985
|
+
}
|
|
10946
10986
|
for (const [fallbackIndex, cell] of cells.entries()) {
|
|
10947
10987
|
const columnIndex = tableCellColumnIndex(cell, fallbackIndex);
|
|
10948
10988
|
const label = columnLabels.get(columnIndex);
|
|
10949
|
-
if (!label
|
|
10989
|
+
if (!label) continue;
|
|
10990
|
+
const current = currentNode(cell.id) ?? cell;
|
|
10991
|
+
if (current.title === label && metadataColumnName(current.metadata) === label && (metadataTableColumnName(current.metadata) ?? label) === label) {
|
|
10992
|
+
continue;
|
|
10993
|
+
}
|
|
10950
10994
|
updates.set(cell.id, {
|
|
10951
|
-
...
|
|
10995
|
+
...current,
|
|
10952
10996
|
title: label,
|
|
10953
|
-
description: tableCellDescription(
|
|
10954
|
-
metadata: metadataWithColumnLabel(
|
|
10997
|
+
description: tableCellDescription(current, label),
|
|
10998
|
+
metadata: metadataWithColumnLabel(current.metadata, label)
|
|
10955
10999
|
});
|
|
11000
|
+
rowsToRebuildText.add(row.id);
|
|
10956
11001
|
}
|
|
10957
11002
|
}
|
|
10958
11003
|
}
|
|
@@ -10993,6 +11038,7 @@ function applyVisualTableRepair(sourceTree, repair) {
|
|
|
10993
11038
|
visualTableRepair: "merged_continuation"
|
|
10994
11039
|
}
|
|
10995
11040
|
});
|
|
11041
|
+
rowsToRebuildText.add(targetRow.id);
|
|
10996
11042
|
}
|
|
10997
11043
|
}
|
|
10998
11044
|
const nextRowText = appendDistinctText(targetRow.textExcerpt ?? targetRow.description, sourceText);
|
|
@@ -11011,6 +11057,21 @@ function applyVisualTableRepair(sourceTree, repair) {
|
|
|
11011
11057
|
for (const sourceCell of sourceCells) removeIds.add(sourceCell.id);
|
|
11012
11058
|
}
|
|
11013
11059
|
}
|
|
11060
|
+
for (const rowId of rowsToRebuildText) {
|
|
11061
|
+
if (removeIds.has(rowId)) continue;
|
|
11062
|
+
const row = currentNode(rowId);
|
|
11063
|
+
if (!row || row.kind !== "table_row") continue;
|
|
11064
|
+
const cells = (byParent.get(row.id) ?? []).filter((node) => node.kind === "table_cell" && !removeIds.has(node.id)).map((node) => currentNode(node.id) ?? node).sort(
|
|
11065
|
+
(left, right) => tableCellColumnIndex(left, 0) - tableCellColumnIndex(right, 0) || left.order - right.order || left.id.localeCompare(right.id)
|
|
11066
|
+
);
|
|
11067
|
+
const textExcerpt = tableRowTextFromCells(cells);
|
|
11068
|
+
if (!textExcerpt) continue;
|
|
11069
|
+
updates.set(row.id, {
|
|
11070
|
+
...row,
|
|
11071
|
+
textExcerpt,
|
|
11072
|
+
description: cleanText([row.title, textExcerpt].filter(Boolean).join(" | "), row.description)
|
|
11073
|
+
});
|
|
11074
|
+
}
|
|
11014
11075
|
if (updates.size === 0 && removeIds.size === 0) return sourceTree;
|
|
11015
11076
|
const repaired = sourceTree.filter((node) => !removeIds.has(node.id)).map((node) => updates.get(node.id) ?? node);
|
|
11016
11077
|
return normalizeDocumentSourceTreePaths(normalizeContainerEvidenceFromChildren(repaired));
|