@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.js
CHANGED
|
@@ -11104,6 +11104,19 @@ function isSourceTreeHeaderRow(row) {
|
|
|
11104
11104
|
function tableCellText(cell) {
|
|
11105
11105
|
return cleanText(cell.textExcerpt ?? cell.description ?? cell.title, "");
|
|
11106
11106
|
}
|
|
11107
|
+
function tableCellValueText(cell) {
|
|
11108
|
+
return cleanText(cell.textExcerpt ?? cell.description ?? "", "");
|
|
11109
|
+
}
|
|
11110
|
+
function tableRowTextFromCells(cells) {
|
|
11111
|
+
const text = cells.map((cell) => {
|
|
11112
|
+
const label = cleanText(cell.title, "");
|
|
11113
|
+
const value = tableCellValueText(cell);
|
|
11114
|
+
if (!value) return label;
|
|
11115
|
+
if (!label || value.toLowerCase() === label.toLowerCase()) return value;
|
|
11116
|
+
return `${label}: ${value}`;
|
|
11117
|
+
}).filter(Boolean).join(" | ");
|
|
11118
|
+
return text ? cleanText(text, text) : void 0;
|
|
11119
|
+
}
|
|
11107
11120
|
function tableRowTextForPrompt(row, cells) {
|
|
11108
11121
|
return cleanText(
|
|
11109
11122
|
cells.length ? cells.map(tableCellText).filter(Boolean).join(" | ") : row.textExcerpt ?? row.description ?? row.title,
|
|
@@ -11118,6 +11131,17 @@ function isGenericColumnTitle(value) {
|
|
|
11118
11131
|
const title = cleanText(value, "");
|
|
11119
11132
|
return !title || /^(?:column\s+\d+|table cell|value)$/i.test(title);
|
|
11120
11133
|
}
|
|
11134
|
+
function metadataColumnName(metadata) {
|
|
11135
|
+
const value = metadata?.columnName;
|
|
11136
|
+
return typeof value === "string" ? cleanText(value, "") || void 0 : void 0;
|
|
11137
|
+
}
|
|
11138
|
+
function metadataTableColumnName(metadata) {
|
|
11139
|
+
const table = metadata?.table;
|
|
11140
|
+
if (!table || typeof table !== "object" || Array.isArray(table)) return void 0;
|
|
11141
|
+
if (!("columnName" in table)) return void 0;
|
|
11142
|
+
const value = table.columnName;
|
|
11143
|
+
return typeof value === "string" ? cleanText(value, "") || void 0 : void 0;
|
|
11144
|
+
}
|
|
11121
11145
|
function bboxSummary(node) {
|
|
11122
11146
|
const box = node.bbox?.[0];
|
|
11123
11147
|
if (!box) return void 0;
|
|
@@ -11294,6 +11318,7 @@ function applyVisualTableRepair(sourceTree, repair) {
|
|
|
11294
11318
|
const byParent = nodesByParent(sourceTree);
|
|
11295
11319
|
const updates = /* @__PURE__ */ new Map();
|
|
11296
11320
|
const removeIds = /* @__PURE__ */ new Set();
|
|
11321
|
+
const rowsToRebuildText = /* @__PURE__ */ new Set();
|
|
11297
11322
|
const currentNode = (id) => updates.get(id) ?? byId.get(id);
|
|
11298
11323
|
for (const tableRepair of repair.tables) {
|
|
11299
11324
|
const table = byId.get(tableRepair.tableNodeId);
|
|
@@ -11308,19 +11333,39 @@ function applyVisualTableRepair(sourceTree, repair) {
|
|
|
11308
11333
|
}
|
|
11309
11334
|
if (columnLabels.size > 0) {
|
|
11310
11335
|
const firstLabelRowIndex = columnLabelStartIndex(rows);
|
|
11336
|
+
const normalizedLabels = new Set([...columnLabels.values()].map((label) => label.toLowerCase()));
|
|
11311
11337
|
for (const [rowIndex, { row, cells }] of rows.entries()) {
|
|
11312
11338
|
if (removeIds.has(row.id)) continue;
|
|
11313
|
-
if (rowIndex < firstLabelRowIndex)
|
|
11339
|
+
if (rowIndex < firstLabelRowIndex) {
|
|
11340
|
+
for (const cell of cells) {
|
|
11341
|
+
const metadataLabel = metadataColumnName(cell.metadata);
|
|
11342
|
+
if (metadataLabel && isGenericColumnTitle(metadataLabel) && normalizedLabels.has(cleanText(cell.title, "").toLowerCase())) {
|
|
11343
|
+
updates.set(cell.id, {
|
|
11344
|
+
...currentNode(cell.id) ?? cell,
|
|
11345
|
+
title: metadataLabel,
|
|
11346
|
+
description: tableCellDescription(cell, metadataLabel),
|
|
11347
|
+
metadata: metadataWithColumnLabel(cell.metadata, metadataLabel)
|
|
11348
|
+
});
|
|
11349
|
+
rowsToRebuildText.add(row.id);
|
|
11350
|
+
}
|
|
11351
|
+
}
|
|
11352
|
+
continue;
|
|
11353
|
+
}
|
|
11314
11354
|
for (const [fallbackIndex, cell] of cells.entries()) {
|
|
11315
11355
|
const columnIndex = tableCellColumnIndex(cell, fallbackIndex);
|
|
11316
11356
|
const label = columnLabels.get(columnIndex);
|
|
11317
|
-
if (!label
|
|
11357
|
+
if (!label) continue;
|
|
11358
|
+
const current = currentNode(cell.id) ?? cell;
|
|
11359
|
+
if (current.title === label && metadataColumnName(current.metadata) === label && (metadataTableColumnName(current.metadata) ?? label) === label) {
|
|
11360
|
+
continue;
|
|
11361
|
+
}
|
|
11318
11362
|
updates.set(cell.id, {
|
|
11319
|
-
...
|
|
11363
|
+
...current,
|
|
11320
11364
|
title: label,
|
|
11321
|
-
description: tableCellDescription(
|
|
11322
|
-
metadata: metadataWithColumnLabel(
|
|
11365
|
+
description: tableCellDescription(current, label),
|
|
11366
|
+
metadata: metadataWithColumnLabel(current.metadata, label)
|
|
11323
11367
|
});
|
|
11368
|
+
rowsToRebuildText.add(row.id);
|
|
11324
11369
|
}
|
|
11325
11370
|
}
|
|
11326
11371
|
}
|
|
@@ -11361,6 +11406,7 @@ function applyVisualTableRepair(sourceTree, repair) {
|
|
|
11361
11406
|
visualTableRepair: "merged_continuation"
|
|
11362
11407
|
}
|
|
11363
11408
|
});
|
|
11409
|
+
rowsToRebuildText.add(targetRow.id);
|
|
11364
11410
|
}
|
|
11365
11411
|
}
|
|
11366
11412
|
const nextRowText = appendDistinctText(targetRow.textExcerpt ?? targetRow.description, sourceText);
|
|
@@ -11379,6 +11425,21 @@ function applyVisualTableRepair(sourceTree, repair) {
|
|
|
11379
11425
|
for (const sourceCell of sourceCells) removeIds.add(sourceCell.id);
|
|
11380
11426
|
}
|
|
11381
11427
|
}
|
|
11428
|
+
for (const rowId of rowsToRebuildText) {
|
|
11429
|
+
if (removeIds.has(rowId)) continue;
|
|
11430
|
+
const row = currentNode(rowId);
|
|
11431
|
+
if (!row || row.kind !== "table_row") continue;
|
|
11432
|
+
const cells = (byParent.get(row.id) ?? []).filter((node) => node.kind === "table_cell" && !removeIds.has(node.id)).map((node) => currentNode(node.id) ?? node).sort(
|
|
11433
|
+
(left, right) => tableCellColumnIndex(left, 0) - tableCellColumnIndex(right, 0) || left.order - right.order || left.id.localeCompare(right.id)
|
|
11434
|
+
);
|
|
11435
|
+
const textExcerpt = tableRowTextFromCells(cells);
|
|
11436
|
+
if (!textExcerpt) continue;
|
|
11437
|
+
updates.set(row.id, {
|
|
11438
|
+
...row,
|
|
11439
|
+
textExcerpt,
|
|
11440
|
+
description: cleanText([row.title, textExcerpt].filter(Boolean).join(" | "), row.description)
|
|
11441
|
+
});
|
|
11442
|
+
}
|
|
11382
11443
|
if (updates.size === 0 && removeIds.size === 0) return sourceTree;
|
|
11383
11444
|
const repaired = sourceTree.filter((node) => !removeIds.has(node.id)).map((node) => updates.get(node.id) ?? node);
|
|
11384
11445
|
return normalizeDocumentSourceTreePaths(normalizeContainerEvidenceFromChildren(repaired));
|