@claritylabs/cl-sdk 3.2.2 → 3.2.3

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.mjs CHANGED
@@ -3542,7 +3542,7 @@ function mergeOperationalProfile(base, candidate, validNodeIds, validSpanIds) {
3542
3542
  ];
3543
3543
  return PolicyOperationalProfileSchema.parse({
3544
3544
  ...base,
3545
- documentType: candidate.documentType === "quote" ? "quote" : candidate.documentType === "policy" ? "policy" : base.documentType,
3545
+ documentType: candidate.documentType === "policy" ? "policy" : base.documentType,
3546
3546
  policyTypes: Array.isArray(candidate.policyTypes) && candidate.policyTypes.length > 0 ? candidate.policyTypes : base.policyTypes,
3547
3547
  policyNumber,
3548
3548
  namedInsured,
@@ -5199,14 +5199,23 @@ function operationalEvidenceScore(span) {
5199
5199
  if (/\$[\d,.]+|[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}|[0-9]{1,2}\s+[A-Za-z]{3,9}\s+[0-9]{4}/.test(text)) score += 3;
5200
5200
  return score;
5201
5201
  }
5202
+ function spanTableId(span) {
5203
+ return span.table?.tableId ?? span.metadata?.tableId;
5204
+ }
5205
+ function isTableCellSpan(span) {
5206
+ return spanSourceUnit(span) === "table_cell";
5207
+ }
5202
5208
  function operationalProfileEvidence(sourceTree, sourceSpans) {
5203
5209
  const sorted = [...sourceSpans].sort(
5204
5210
  (left, right) => (spanPageStart(left) ?? Number.MAX_SAFE_INTEGER) - (spanPageStart(right) ?? Number.MAX_SAFE_INTEGER) || (left.location?.charStart ?? Number.MAX_SAFE_INTEGER) - (right.location?.charStart ?? Number.MAX_SAFE_INTEGER) || left.id.localeCompare(right.id)
5205
5211
  );
5206
5212
  const selected = /* @__PURE__ */ new Set();
5213
+ const selectedTableIds = /* @__PURE__ */ new Set();
5207
5214
  for (let index = 0; index < sorted.length; index += 1) {
5208
5215
  const score = operationalEvidenceScore(sorted[index]);
5209
5216
  if (score < 8) continue;
5217
+ const tableId2 = spanTableId(sorted[index]);
5218
+ if (tableId2 && !isTableCellSpan(sorted[index])) selectedTableIds.add(tableId2);
5210
5219
  const page = spanPageStart(sorted[index]);
5211
5220
  for (let offset = -2; offset <= 2; offset += 1) {
5212
5221
  const neighborIndex = index + offset;
@@ -5217,9 +5226,17 @@ function operationalProfileEvidence(sourceTree, sourceSpans) {
5217
5226
  selected.add(neighborIndex);
5218
5227
  }
5219
5228
  }
5229
+ if (selectedTableIds.size > 0) {
5230
+ sorted.forEach((span, index) => {
5231
+ const tableId2 = spanTableId(span);
5232
+ if (!tableId2 || !selectedTableIds.has(tableId2) || isTableCellSpan(span)) return;
5233
+ const text = cleanText(span.text, "");
5234
+ if (text && text.length <= 5e3) selected.add(index);
5235
+ });
5236
+ }
5220
5237
  const nodeIdsBySpanId = sourceNodeIdsBySpanId(sourceTree);
5221
5238
  const seenText = /* @__PURE__ */ new Set();
5222
- return [...selected].sort((left, right) => left - right).map((index) => sorted[index]).filter((span) => span.sourceUnit !== "table_cell").flatMap((span) => {
5239
+ const entries = [...selected].sort((left, right) => left - right).map((index) => sorted[index]).filter((span) => !isTableCellSpan(span)).flatMap((span) => {
5223
5240
  const text = cleanText(span.text, "");
5224
5241
  if (!text) return [];
5225
5242
  const key = `${spanPageStart(span) ?? "na"}:${text.toLowerCase().slice(0, 240)}`;
@@ -5234,7 +5251,10 @@ function operationalProfileEvidence(sourceTree, sourceSpans) {
5234
5251
  formNumber: span.formNumber,
5235
5252
  text: text.slice(0, span.sourceUnit === "page" ? 1200 : 900)
5236
5253
  }];
5237
- }).slice(0, 180);
5254
+ });
5255
+ const detailEntries = entries.filter((entry) => entry.sourceUnit !== "page");
5256
+ const pageEntries = entries.filter((entry) => entry.sourceUnit === "page");
5257
+ return (detailEntries.length >= 20 ? detailEntries : [...detailEntries, ...pageEntries]).slice(0, 180);
5238
5258
  }
5239
5259
  function sourceTreeRootId(sourceTree) {
5240
5260
  return sourceTree.find((node) => node.kind === "document")?.id;
@@ -5265,7 +5285,7 @@ function buildOperationalProfilePrompt(sourceTree, sourceSpans) {
5265
5285
  const fallbackNodes = evidence.length ? [] : operationalProfilePromptNodes(sourceTree).map(
5266
5286
  (node) => compactNode2(node, node.kind === "page" || node.kind === "endorsement" ? 900 : 700)
5267
5287
  );
5268
- return `Extract a source-backed operational profile for an insurance policy or quote.
5288
+ return `Extract a source-backed operational profile for an insurance policy.
5269
5289
 
5270
5290
  Return only high-value operational facts needed for policy lists, Q&A, compliance, and certificate generation:
5271
5291
  - policy number, named insured, insurer/carrier/security, broker/producer, policy period, retroactive date, premium