@claritylabs/cl-sdk 3.2.0 → 3.2.2
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/application.d.mts +1 -1
- package/dist/application.d.ts +1 -1
- package/dist/application.js.map +1 -1
- package/dist/application.mjs.map +1 -1
- package/dist/{index-D9C8e9BL.d.mts → index-BGyy2VS6.d.mts} +1 -1
- package/dist/{index-D9C8e9BL.d.ts → index-BGyy2VS6.d.ts} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +77 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5168,6 +5168,74 @@ function nodesByParent(sourceTree) {
|
|
|
5168
5168
|
}
|
|
5169
5169
|
return byParent;
|
|
5170
5170
|
}
|
|
5171
|
+
function sourceNodeIdsBySpanId(sourceTree) {
|
|
5172
|
+
const bySpan = /* @__PURE__ */ new Map();
|
|
5173
|
+
for (const node of sourceTree) {
|
|
5174
|
+
for (const spanId of node.sourceSpanIds) {
|
|
5175
|
+
const nodes = bySpan.get(spanId) ?? [];
|
|
5176
|
+
nodes.push(node.id);
|
|
5177
|
+
bySpan.set(spanId, nodes);
|
|
5178
|
+
}
|
|
5179
|
+
}
|
|
5180
|
+
return bySpan;
|
|
5181
|
+
}
|
|
5182
|
+
function operationalEvidenceScore(span) {
|
|
5183
|
+
const text = cleanText([
|
|
5184
|
+
span.text,
|
|
5185
|
+
span.formNumber,
|
|
5186
|
+
span.sourceUnit,
|
|
5187
|
+
span.metadata?.elementType,
|
|
5188
|
+
span.metadata?.sourceUnit
|
|
5189
|
+
].filter(Boolean).join(" "), "");
|
|
5190
|
+
if (!text) return 0;
|
|
5191
|
+
let score = 0;
|
|
5192
|
+
if (span.sourceUnit === "table_row" || span.sourceUnit === "table") score += 5;
|
|
5193
|
+
if (span.metadata?.elementType === "title") score += 4;
|
|
5194
|
+
if (span.sourceUnit === "page") score -= 3;
|
|
5195
|
+
if (/\b(policy\s*(number|period|term)|effective date|expiration date|expiry date|named insured|insurer|carrier|security|broker|producer|premium|total due)\b/i.test(text)) score += 12;
|
|
5196
|
+
if (/\b(coverage part|limit(?:s)? of liability|deductible|retention|retroactive date|aggregate|sublimit|sub-limit|each claim|each loss|each occurrence|coinsurance)\b/i.test(text)) score += 14;
|
|
5197
|
+
if (/\bendorsement\s+(?:no\.?|number|#)?\s*[A-Z0-9]|forms? and endorsements?|attached at inception|schedule\b/i.test(text)) score += 8;
|
|
5198
|
+
if (/\bitem\s+\d+\.?\s*(?:named insured|policy number|policy period|renewal|form of business|coverage parts?|premium|extended reporting|producer|forms? and endorsements?)\b/i.test(text)) score += 10;
|
|
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
|
+
return score;
|
|
5201
|
+
}
|
|
5202
|
+
function operationalProfileEvidence(sourceTree, sourceSpans) {
|
|
5203
|
+
const sorted = [...sourceSpans].sort(
|
|
5204
|
+
(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
|
+
);
|
|
5206
|
+
const selected = /* @__PURE__ */ new Set();
|
|
5207
|
+
for (let index = 0; index < sorted.length; index += 1) {
|
|
5208
|
+
const score = operationalEvidenceScore(sorted[index]);
|
|
5209
|
+
if (score < 8) continue;
|
|
5210
|
+
const page = spanPageStart(sorted[index]);
|
|
5211
|
+
for (let offset = -2; offset <= 2; offset += 1) {
|
|
5212
|
+
const neighborIndex = index + offset;
|
|
5213
|
+
const neighbor = sorted[neighborIndex];
|
|
5214
|
+
if (!neighbor || spanPageStart(neighbor) !== page) continue;
|
|
5215
|
+
const neighborText = cleanText(neighbor.text, "");
|
|
5216
|
+
if (!neighborText || neighborText.length > 5e3) continue;
|
|
5217
|
+
selected.add(neighborIndex);
|
|
5218
|
+
}
|
|
5219
|
+
}
|
|
5220
|
+
const nodeIdsBySpanId = sourceNodeIdsBySpanId(sourceTree);
|
|
5221
|
+
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) => {
|
|
5223
|
+
const text = cleanText(span.text, "");
|
|
5224
|
+
if (!text) return [];
|
|
5225
|
+
const key = `${spanPageStart(span) ?? "na"}:${text.toLowerCase().slice(0, 240)}`;
|
|
5226
|
+
if (seenText.has(key)) return [];
|
|
5227
|
+
seenText.add(key);
|
|
5228
|
+
return [{
|
|
5229
|
+
sourceSpanId: span.id,
|
|
5230
|
+
sourceNodeIds: [...new Set(nodeIdsBySpanId.get(span.id) ?? [])].slice(0, 4),
|
|
5231
|
+
pageStart: spanPageStart(span),
|
|
5232
|
+
pageEnd: spanPageEnd(span),
|
|
5233
|
+
sourceUnit: spanSourceUnit(span),
|
|
5234
|
+
formNumber: span.formNumber,
|
|
5235
|
+
text: text.slice(0, span.sourceUnit === "page" ? 1200 : 900)
|
|
5236
|
+
}];
|
|
5237
|
+
}).slice(0, 180);
|
|
5238
|
+
}
|
|
5171
5239
|
function sourceTreeRootId(sourceTree) {
|
|
5172
5240
|
return sourceTree.find((node) => node.kind === "document")?.id;
|
|
5173
5241
|
}
|
|
@@ -5192,8 +5260,9 @@ function emptyOperationalProfile() {
|
|
|
5192
5260
|
warnings: []
|
|
5193
5261
|
};
|
|
5194
5262
|
}
|
|
5195
|
-
function buildOperationalProfilePrompt(sourceTree) {
|
|
5196
|
-
const
|
|
5263
|
+
function buildOperationalProfilePrompt(sourceTree, sourceSpans) {
|
|
5264
|
+
const evidence = operationalProfileEvidence(sourceTree, sourceSpans);
|
|
5265
|
+
const fallbackNodes = evidence.length ? [] : operationalProfilePromptNodes(sourceTree).map(
|
|
5197
5266
|
(node) => compactNode2(node, node.kind === "page" || node.kind === "endorsement" ? 900 : 700)
|
|
5198
5267
|
);
|
|
5199
5268
|
return `Extract a source-backed operational profile for an insurance policy or quote.
|
|
@@ -5204,7 +5273,8 @@ Return only high-value operational facts needed for policy lists, Q&A, complianc
|
|
|
5204
5273
|
- coverage type labels
|
|
5205
5274
|
|
|
5206
5275
|
Rules:
|
|
5207
|
-
- Every returned value must include sourceNodeIds or sourceSpanIds from the provided
|
|
5276
|
+
- Every returned value must include sourceNodeIds or sourceSpanIds from the provided evidence.
|
|
5277
|
+
- When citing an evidence entry, copy its sourceSpanId into the returned sourceSpanIds array.
|
|
5208
5278
|
- If a value is not directly supported, omit it.
|
|
5209
5279
|
- Prefer declarations, schedules, premium tables, and endorsement schedules over generic policy wording.
|
|
5210
5280
|
- For broker/producer, extract the agency or company legal name, not the license role, credential, or type. In a block like "Bayshore Insurance Brokers, LLC" followed by "Surplus Lines Broker - CA License No. ...", broker.value must be "Bayshore Insurance Brokers, LLC"; the surplus-lines role and license number are not the broker name.
|
|
@@ -5220,10 +5290,10 @@ Rules:
|
|
|
5220
5290
|
- For coverage schedules, put each claim, aggregate, sublimit, retention, deductible, and retroactive date values in coverages[].limits with labels and source IDs. Keep the legacy coverages[].limit as the primary display value only.
|
|
5221
5291
|
- Extract coinsurance, participation percentage, or insurer/named-insured split terms as coverages[].limits entries with kind "other" when they are part of a coverage schedule.
|
|
5222
5292
|
- Do not copy entire policy wording into fields.
|
|
5223
|
-
- Extract facts directly from source
|
|
5293
|
+
- Extract facts directly from source evidence. There is no deterministic fact baseline.
|
|
5224
5294
|
|
|
5225
|
-
Source
|
|
5226
|
-
${JSON.stringify(
|
|
5295
|
+
Source evidence:
|
|
5296
|
+
${JSON.stringify(evidence.length ? evidence : fallbackNodes, null, 2)}
|
|
5227
5297
|
|
|
5228
5298
|
Return JSON for the operational profile.`;
|
|
5229
5299
|
}
|
|
@@ -5483,7 +5553,7 @@ async function runSourceTreeExtraction(params) {
|
|
|
5483
5553
|
const response = await safeGenerateObject(
|
|
5484
5554
|
params.generateObject,
|
|
5485
5555
|
{
|
|
5486
|
-
prompt: buildOperationalProfilePrompt(sourceTree),
|
|
5556
|
+
prompt: buildOperationalProfilePrompt(sourceTree, sourceSpans),
|
|
5487
5557
|
schema: OperationalProfilePromptSchema,
|
|
5488
5558
|
maxTokens: budget.maxTokens,
|
|
5489
5559
|
taskKind: "extraction_operational_profile",
|