@claritylabs/cl-sdk 0.12.0 → 0.13.0
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.d.mts +130 -1
- package/dist/index.d.ts +130 -1
- package/dist/index.js +117 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -4
- package/dist/index.mjs.map +1 -1
- package/dist/storage-sqlite.d.mts +56 -0
- package/dist/storage-sqlite.d.ts +56 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
AuditTypeSchema: () => AuditTypeSchema,
|
|
41
41
|
AutoFillMatchSchema: () => AutoFillMatchSchema,
|
|
42
42
|
AutoFillResultSchema: () => AutoFillResultSchema,
|
|
43
|
+
AuxiliaryFactSchema: () => AuxiliaryFactSchema,
|
|
43
44
|
BOAT_TYPES: () => BOAT_TYPES,
|
|
44
45
|
BindingAuthoritySchema: () => BindingAuthoritySchema,
|
|
45
46
|
BoatTypeSchema: () => BoatTypeSchema,
|
|
@@ -1471,6 +1472,12 @@ var PremiumLineSchema = import_zod16.z.object({
|
|
|
1471
1472
|
line: import_zod16.z.string(),
|
|
1472
1473
|
amount: import_zod16.z.string()
|
|
1473
1474
|
});
|
|
1475
|
+
var AuxiliaryFactSchema = import_zod16.z.object({
|
|
1476
|
+
key: import_zod16.z.string(),
|
|
1477
|
+
value: import_zod16.z.string(),
|
|
1478
|
+
subject: import_zod16.z.string().optional(),
|
|
1479
|
+
context: import_zod16.z.string().optional()
|
|
1480
|
+
});
|
|
1474
1481
|
var BaseDocumentFields = {
|
|
1475
1482
|
id: import_zod16.z.string(),
|
|
1476
1483
|
carrier: import_zod16.z.string(),
|
|
@@ -1536,7 +1543,8 @@ var BaseDocumentFields = {
|
|
|
1536
1543
|
individualClaims: import_zod16.z.array(ClaimRecordSchema).optional(),
|
|
1537
1544
|
experienceMod: ExperienceModSchema.optional(),
|
|
1538
1545
|
cancellationNoticeDays: import_zod16.z.number().optional(),
|
|
1539
|
-
nonrenewalNoticeDays: import_zod16.z.number().optional()
|
|
1546
|
+
nonrenewalNoticeDays: import_zod16.z.number().optional(),
|
|
1547
|
+
supplementaryFacts: import_zod16.z.array(AuxiliaryFactSchema).optional()
|
|
1540
1548
|
};
|
|
1541
1549
|
var PolicyDocumentSchema = import_zod16.z.object({
|
|
1542
1550
|
...BaseDocumentFields,
|
|
@@ -2199,6 +2207,7 @@ function assembleDocument(documentId, documentType, memory) {
|
|
|
2199
2207
|
...sanitizeNulls(coverages ?? {}),
|
|
2200
2208
|
...sanitizeNulls(premium ?? {}),
|
|
2201
2209
|
...sanitizeNulls(supplementary ?? {}),
|
|
2210
|
+
supplementaryFacts: supplementary?.auxiliaryFacts,
|
|
2202
2211
|
endorsements: endorsements?.endorsements,
|
|
2203
2212
|
exclusions: exclusions?.exclusions,
|
|
2204
2213
|
conditions: conditions?.conditions,
|
|
@@ -2551,6 +2560,43 @@ Total Cost: ${doc.totalCost}` : ""}`,
|
|
|
2551
2560
|
metadata: stringMetadata({ premium: doc.premium, documentType: doc.type })
|
|
2552
2561
|
});
|
|
2553
2562
|
}
|
|
2563
|
+
const supplementaryLines = [
|
|
2564
|
+
...doc.claimsContacts?.map((contact) => `Claims Contact: ${[
|
|
2565
|
+
contact.name,
|
|
2566
|
+
contact.phone,
|
|
2567
|
+
contact.email,
|
|
2568
|
+
contact.hours
|
|
2569
|
+
].filter(Boolean).join(" | ")}`) ?? [],
|
|
2570
|
+
...doc.regulatoryContacts?.map((contact) => `Regulatory Contact: ${[
|
|
2571
|
+
contact.name,
|
|
2572
|
+
contact.phone,
|
|
2573
|
+
contact.email
|
|
2574
|
+
].filter(Boolean).join(" | ")}`) ?? [],
|
|
2575
|
+
...doc.thirdPartyAdministrators?.map((contact) => `TPA: ${[
|
|
2576
|
+
contact.name,
|
|
2577
|
+
contact.phone,
|
|
2578
|
+
contact.email
|
|
2579
|
+
].filter(Boolean).join(" | ")}`) ?? [],
|
|
2580
|
+
...doc.supplementaryFacts?.map((fact) => [
|
|
2581
|
+
fact.subject ? `Subject: ${fact.subject}` : null,
|
|
2582
|
+
`${fact.key}: ${fact.value}`,
|
|
2583
|
+
fact.context ? `Context: ${fact.context}` : null
|
|
2584
|
+
].filter(Boolean).join(" | ")) ?? [],
|
|
2585
|
+
doc.cancellationNoticeDays != null ? `Cancellation Notice Days: ${doc.cancellationNoticeDays}` : null,
|
|
2586
|
+
doc.nonrenewalNoticeDays != null ? `Nonrenewal Notice Days: ${doc.nonrenewalNoticeDays}` : null
|
|
2587
|
+
].filter((line) => Boolean(line));
|
|
2588
|
+
if (supplementaryLines.length > 0) {
|
|
2589
|
+
chunks.push({
|
|
2590
|
+
id: `${docId}:supplementary:0`,
|
|
2591
|
+
documentId: docId,
|
|
2592
|
+
type: "supplementary",
|
|
2593
|
+
text: supplementaryLines.join("\n"),
|
|
2594
|
+
metadata: stringMetadata({
|
|
2595
|
+
documentType: doc.type,
|
|
2596
|
+
supplementaryFactCount: doc.supplementaryFacts?.length
|
|
2597
|
+
})
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2554
2600
|
return chunks;
|
|
2555
2601
|
}
|
|
2556
2602
|
|
|
@@ -2634,6 +2680,32 @@ function mergeArrayPayload(existing, incoming, arrayKey, keyFn) {
|
|
|
2634
2680
|
merged[arrayKey] = mergeUniqueObjects(existingItems, incomingItems, keyFn);
|
|
2635
2681
|
return merged;
|
|
2636
2682
|
}
|
|
2683
|
+
function mergeSupplementary(existing, incoming) {
|
|
2684
|
+
const merged = mergeShallowPreferPresent(existing, incoming);
|
|
2685
|
+
const mergeContactArray = (arrayKey) => {
|
|
2686
|
+
const existingItems = Array.isArray(existing[arrayKey]) ? existing[arrayKey] : [];
|
|
2687
|
+
const incomingItems = Array.isArray(incoming[arrayKey]) ? incoming[arrayKey] : [];
|
|
2688
|
+
merged[arrayKey] = mergeUniqueObjects(existingItems, incomingItems, (item) => [
|
|
2689
|
+
String(item.name ?? "").toLowerCase(),
|
|
2690
|
+
String(item.phone ?? "").toLowerCase(),
|
|
2691
|
+
String(item.email ?? "").toLowerCase(),
|
|
2692
|
+
String(item.address ?? "").toLowerCase(),
|
|
2693
|
+
String(item.type ?? "").toLowerCase()
|
|
2694
|
+
].join("|"));
|
|
2695
|
+
};
|
|
2696
|
+
mergeContactArray("regulatoryContacts");
|
|
2697
|
+
mergeContactArray("claimsContacts");
|
|
2698
|
+
mergeContactArray("thirdPartyAdministrators");
|
|
2699
|
+
const existingFacts = Array.isArray(existing.auxiliaryFacts) ? existing.auxiliaryFacts : [];
|
|
2700
|
+
const incomingFacts = Array.isArray(incoming.auxiliaryFacts) ? incoming.auxiliaryFacts : [];
|
|
2701
|
+
merged.auxiliaryFacts = mergeUniqueObjects(existingFacts, incomingFacts, (item) => [
|
|
2702
|
+
String(item.key ?? "").toLowerCase(),
|
|
2703
|
+
String(item.value ?? "").toLowerCase(),
|
|
2704
|
+
String(item.subject ?? "").toLowerCase(),
|
|
2705
|
+
String(item.context ?? "").toLowerCase()
|
|
2706
|
+
].join("|"));
|
|
2707
|
+
return merged;
|
|
2708
|
+
}
|
|
2637
2709
|
function mergeExtractorResult(extractorName, existing, incoming) {
|
|
2638
2710
|
if (!existing) return incoming;
|
|
2639
2711
|
if (!incoming) return existing;
|
|
@@ -2644,9 +2716,10 @@ function mergeExtractorResult(extractorName, existing, incoming) {
|
|
|
2644
2716
|
case "carrier_info":
|
|
2645
2717
|
case "named_insured":
|
|
2646
2718
|
case "loss_history":
|
|
2647
|
-
case "supplementary":
|
|
2648
2719
|
case "premium_breakdown":
|
|
2649
2720
|
return mergeShallowPreferPresent(current, next);
|
|
2721
|
+
case "supplementary":
|
|
2722
|
+
return mergeSupplementary(current, next);
|
|
2650
2723
|
case "coverage_limits":
|
|
2651
2724
|
return mergeCoverageLimits(current, next);
|
|
2652
2725
|
case "declarations":
|
|
@@ -4243,15 +4316,22 @@ var ContactSchema2 = import_zod33.z.object({
|
|
|
4243
4316
|
address: import_zod33.z.string().optional().describe("Mailing address"),
|
|
4244
4317
|
type: import_zod33.z.string().optional().describe("Contact type, e.g. 'State Department of Insurance'")
|
|
4245
4318
|
});
|
|
4319
|
+
var AuxiliaryFactSchema2 = import_zod33.z.object({
|
|
4320
|
+
key: import_zod33.z.string().describe("Normalized machine-readable fact key, e.g. 'policyholder_age' or 'insured_name'"),
|
|
4321
|
+
value: import_zod33.z.string().describe("Concrete extracted fact value"),
|
|
4322
|
+
subject: import_zod33.z.string().optional().describe("Person, entity, vehicle, property, or schedule item this fact belongs to"),
|
|
4323
|
+
context: import_zod33.z.string().optional().describe("Short disambiguating context, such as 'Driver Schedule' or 'Named Insured'")
|
|
4324
|
+
});
|
|
4246
4325
|
var SupplementarySchema = import_zod33.z.object({
|
|
4247
4326
|
regulatoryContacts: import_zod33.z.array(ContactSchema2).optional().describe("Regulatory body contacts (state department of insurance, ombudsman)"),
|
|
4248
4327
|
claimsContacts: import_zod33.z.array(ContactSchema2).optional().describe("Claims reporting contacts and instructions"),
|
|
4249
4328
|
thirdPartyAdministrators: import_zod33.z.array(ContactSchema2).optional().describe("Third-party administrators for claims handling"),
|
|
4250
4329
|
cancellationNoticeDays: import_zod33.z.number().optional().describe("Required notice period for cancellation in days"),
|
|
4251
|
-
nonrenewalNoticeDays: import_zod33.z.number().optional().describe("Required notice period for nonrenewal in days")
|
|
4330
|
+
nonrenewalNoticeDays: import_zod33.z.number().optional().describe("Required notice period for nonrenewal in days"),
|
|
4331
|
+
auxiliaryFacts: import_zod33.z.array(AuxiliaryFactSchema2).optional().describe("Additional retrieval-only facts that do not fit the strict primary schema")
|
|
4252
4332
|
});
|
|
4253
4333
|
function buildSupplementaryPrompt() {
|
|
4254
|
-
return `You are an expert insurance document analyst. Extract supplementary
|
|
4334
|
+
return `You are an expert insurance document analyst. Extract supplementary, retrieval-only information from this document.
|
|
4255
4335
|
|
|
4256
4336
|
Focus on:
|
|
4257
4337
|
- Regulatory contacts: state department of insurance, regulatory bodies, ombudsman offices \u2014 with phone, email, address
|
|
@@ -4261,9 +4341,19 @@ Focus on:
|
|
|
4261
4341
|
- Nonrenewal notice period in days
|
|
4262
4342
|
- Complaint filing procedures and contacts
|
|
4263
4343
|
- Governing law or jurisdiction provisions
|
|
4344
|
+
- Additional policy-specific facts that are useful for memory and retrieval even if they do not belong in the strict primary schema
|
|
4264
4345
|
|
|
4265
4346
|
Look for regulatory notices, complaint contact sections, claims reporting instructions, and cancellation/nonrenewal provisions throughout the document.
|
|
4266
4347
|
|
|
4348
|
+
For auxiliaryFacts:
|
|
4349
|
+
- Capture concrete, policy-specific facts as structured key/value pairs.
|
|
4350
|
+
- Prioritize facts that agents may need later but that are often omitted from strict schemas: policyholder names, insured person names, driver names, ages, dates of birth, marital status, garaging information, lienholders, household members, vehicle assignments, schedule row details, and other discrete identifiers.
|
|
4351
|
+
- Use short normalized keys like "policyholder_name", "policyholder_age", "insured_name", "driver_age", "driver_date_of_birth", "garaging_zip", "vehicle_principal_driver".
|
|
4352
|
+
- Use subject when the fact belongs to a specific person, vehicle, property, or scheduled item.
|
|
4353
|
+
- Do not invent facts.
|
|
4354
|
+
- Do not include vague boilerplate or generic form language.
|
|
4355
|
+
- Do not repeat large narrative excerpts; keep facts atomic.
|
|
4356
|
+
|
|
4267
4357
|
Return JSON only.`;
|
|
4268
4358
|
}
|
|
4269
4359
|
|
|
@@ -4990,6 +5080,28 @@ function createExtractor(config) {
|
|
|
4990
5080
|
mergeMemoryResult(result.name, result.data, memory);
|
|
4991
5081
|
}
|
|
4992
5082
|
}
|
|
5083
|
+
const supplementaryExtractor = getExtractor("supplementary");
|
|
5084
|
+
if (supplementaryExtractor) {
|
|
5085
|
+
onProgress?.("Extracting supplementary retrieval facts...");
|
|
5086
|
+
try {
|
|
5087
|
+
const supplementaryResult = await runExtractor({
|
|
5088
|
+
name: "supplementary",
|
|
5089
|
+
prompt: supplementaryExtractor.buildPrompt(),
|
|
5090
|
+
schema: supplementaryExtractor.schema,
|
|
5091
|
+
pdfBase64,
|
|
5092
|
+
startPage: 1,
|
|
5093
|
+
endPage: pageCount,
|
|
5094
|
+
generateObject,
|
|
5095
|
+
convertPdfToImages,
|
|
5096
|
+
maxTokens: supplementaryExtractor.maxTokens ?? 4096,
|
|
5097
|
+
providerOptions
|
|
5098
|
+
});
|
|
5099
|
+
trackUsage(supplementaryResult.usage);
|
|
5100
|
+
mergeMemoryResult(supplementaryResult.name, supplementaryResult.data, memory);
|
|
5101
|
+
} catch (error) {
|
|
5102
|
+
await log?.(`Supplementary extractor failed: ${error}`);
|
|
5103
|
+
}
|
|
5104
|
+
}
|
|
4993
5105
|
await pipelineCtx.save("extract", {
|
|
4994
5106
|
id,
|
|
4995
5107
|
pageCount,
|
|
@@ -7706,6 +7818,7 @@ var AGENT_TOOLS = [
|
|
|
7706
7818
|
AuditTypeSchema,
|
|
7707
7819
|
AutoFillMatchSchema,
|
|
7708
7820
|
AutoFillResultSchema,
|
|
7821
|
+
AuxiliaryFactSchema,
|
|
7709
7822
|
BOAT_TYPES,
|
|
7710
7823
|
BindingAuthoritySchema,
|
|
7711
7824
|
BoatTypeSchema,
|