@claritylabs/cl-sdk 0.14.1 → 0.15.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 +22 -10
- package/dist/index.d.ts +22 -10
- package/dist/index.js +573 -175
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +573 -175
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2156,6 +2156,9 @@ function synthesizeDeductibles(doc) {
|
|
|
2156
2156
|
}
|
|
2157
2157
|
var PREMIUM_PATTERNS = ["premium", "totalPremium", "annualPremium", "policyPremium", "basePremium"];
|
|
2158
2158
|
var TOTAL_COST_PATTERNS = ["totalCost", "totalDue", "totalAmount", "totalPolicyPremium"];
|
|
2159
|
+
function absorbNegative(value) {
|
|
2160
|
+
return value.replace(/^-\s*/, "").replace(/^\(\s*(.*?)\s*\)$/, "$1");
|
|
2161
|
+
}
|
|
2159
2162
|
function promotePremium(doc) {
|
|
2160
2163
|
const raw = doc;
|
|
2161
2164
|
const fields = getDeclarationFields(doc);
|
|
@@ -2167,6 +2170,8 @@ function promotePremium(doc) {
|
|
|
2167
2170
|
const totalCost = findFieldValue(fields, TOTAL_COST_PATTERNS);
|
|
2168
2171
|
if (totalCost) raw.totalCost = totalCost;
|
|
2169
2172
|
}
|
|
2173
|
+
if (typeof raw.premium === "string") raw.premium = absorbNegative(raw.premium);
|
|
2174
|
+
if (typeof raw.totalCost === "string") raw.totalCost = absorbNegative(raw.totalCost);
|
|
2170
2175
|
}
|
|
2171
2176
|
function promoteExtractedFields(doc) {
|
|
2172
2177
|
promoteCarrierFields(doc);
|
|
@@ -2471,10 +2476,13 @@ function chunkDocument(doc) {
|
|
|
2471
2476
|
};
|
|
2472
2477
|
const chunks = [];
|
|
2473
2478
|
const docId = doc.id;
|
|
2479
|
+
const policyTypesStr = doc.policyTypes?.length ? doc.policyTypes.join(",") : void 0;
|
|
2474
2480
|
function stringMetadata(entries) {
|
|
2475
|
-
|
|
2481
|
+
const base = Object.fromEntries(
|
|
2476
2482
|
Object.entries(entries).filter(([, value]) => value !== void 0 && value !== null && String(value).length > 0).map(([key, value]) => [key, String(value)])
|
|
2477
2483
|
);
|
|
2484
|
+
if (policyTypesStr) base.policyTypes = policyTypesStr;
|
|
2485
|
+
return base;
|
|
2478
2486
|
}
|
|
2479
2487
|
chunks.push({
|
|
2480
2488
|
id: `${docId}:carrier_info:0`,
|
|
@@ -2835,13 +2843,16 @@ ${exc.content}`.trim(),
|
|
|
2835
2843
|
}
|
|
2836
2844
|
}
|
|
2837
2845
|
if (declLines.length > 0) {
|
|
2846
|
+
const declMeta = { documentType: doc.type };
|
|
2847
|
+
if (typeof decl.formType === "string") declMeta.formType = decl.formType;
|
|
2848
|
+
if (typeof decl.line === "string") declMeta.declarationLine = decl.line;
|
|
2838
2849
|
chunks.push({
|
|
2839
2850
|
id: `${docId}:declaration:0`,
|
|
2840
2851
|
documentId: docId,
|
|
2841
2852
|
type: "declaration",
|
|
2842
2853
|
text: `Declarations
|
|
2843
2854
|
${declLines.join("\n")}`,
|
|
2844
|
-
metadata: stringMetadata(
|
|
2855
|
+
metadata: stringMetadata(declMeta)
|
|
2845
2856
|
});
|
|
2846
2857
|
}
|
|
2847
2858
|
}
|
|
@@ -4262,11 +4273,30 @@ COMMERCIAL LINES \u2014 match these values:
|
|
|
4262
4273
|
- "property" \u2014 standalone property
|
|
4263
4274
|
|
|
4264
4275
|
PERSONAL LINES \u2014 match these values:
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
- "
|
|
4268
|
-
|
|
4269
|
-
|
|
4276
|
+
|
|
4277
|
+
HOMEOWNER FORM CLASSIFICATION \u2014 pay close attention to these distinctions:
|
|
4278
|
+
- "homeowners_ho3" \u2014 HO-3 Special Form. Standard homeowner policy for OWNER-OCCUPIED dwellings.
|
|
4279
|
+
Key indicators: Coverage A (Dwelling) present, open-peril dwelling coverage, named-peril personal property,
|
|
4280
|
+
references to "special form", "HO 00 03", or "HO-3". The insured OWNS the home.
|
|
4281
|
+
- "homeowners_ho5" \u2014 HO-5 Comprehensive Form. Premium homeowner policy for OWNER-OCCUPIED dwellings.
|
|
4282
|
+
Key indicators: Coverage A (Dwelling) present, BOTH dwelling AND personal property on open-peril basis,
|
|
4283
|
+
references to "comprehensive form", "HO 00 05", or "HO-5". Higher coverage than HO-3.
|
|
4284
|
+
- "renters_ho4" \u2014 HO-4 Contents Broad Form. Renters/tenants insurance \u2014 NO dwelling coverage.
|
|
4285
|
+
Key indicators: NO Coverage A (Dwelling), only Coverage C (Personal Property) and Coverage E/F (Liability/Medical),
|
|
4286
|
+
references to "contents broad form", "HO 00 04", "HO-4", "renters", "tenants". The insured RENTS, does not own.
|
|
4287
|
+
- "condo_ho6" \u2014 HO-6 Unit-Owners Form. Condo/co-op unit-owner insurance.
|
|
4288
|
+
Key indicators: Coverage A applies to interior walls/improvements only (not full structure),
|
|
4289
|
+
references to "unit-owners form", "HO 00 06", "HO-6", "condominium", "co-op unit". The building's
|
|
4290
|
+
master policy covers the structure; HO-6 covers the unit interior, personal property, and liability.
|
|
4291
|
+
|
|
4292
|
+
DISAMBIGUATION RULES for homeowner forms:
|
|
4293
|
+
1. If the document has Coverage A (Dwelling) with full structure coverage \u2192 HO-3 or HO-5 (check if open-peril on personal property \u2192 HO-5, named-peril \u2192 HO-3)
|
|
4294
|
+
2. If NO Coverage A / no dwelling coverage and the insured is a renter/tenant \u2192 renters_ho4
|
|
4295
|
+
3. If Coverage A covers only unit interior/improvements and mentions condo/co-op \u2192 condo_ho6
|
|
4296
|
+
4. Look for the actual form number (HO 00 03, HO 00 04, HO 00 05, HO 00 06) on the declarations page \u2014 this is the most reliable indicator
|
|
4297
|
+
5. Do NOT default to homeowners_ho3 when uncertain \u2014 check for the distinguishing signals above
|
|
4298
|
+
|
|
4299
|
+
- "dwelling_fire" \u2014 DP-1, DP-3, dwelling fire (non-owner-occupied or investment property)
|
|
4270
4300
|
- "mobile_home" \u2014 mobile home, manufactured home
|
|
4271
4301
|
- "personal_auto" \u2014 personal auto, PAP
|
|
4272
4302
|
- "personal_umbrella" \u2014 personal umbrella
|
|
@@ -4277,7 +4307,10 @@ PERSONAL LINES \u2014 match these values:
|
|
|
4277
4307
|
- "watercraft" \u2014 watercraft, boat
|
|
4278
4308
|
- "recreational_vehicle" \u2014 RV, recreational vehicle, ATV
|
|
4279
4309
|
- "farm_ranch" \u2014 farm, ranch
|
|
4280
|
-
- "pet" \u2014 pet insurance
|
|
4310
|
+
- "pet" \u2014 standalone pet insurance policy. Key indicators: named pet, species/breed, accident/illness coverage,
|
|
4311
|
+
wellness plans, per-incident or annual limits for veterinary costs. Do NOT confuse with pet liability endorsements
|
|
4312
|
+
on a homeowners policy \u2014 those are still homeowner policies (ho3/ho4/ho5/ho6), not "pet".
|
|
4313
|
+
Only classify as "pet" when the ENTIRE policy is dedicated to pet health/accident coverage.
|
|
4281
4314
|
- "travel" \u2014 travel insurance
|
|
4282
4315
|
- "identity_theft" \u2014 identity theft
|
|
4283
4316
|
- "title" \u2014 title insurance
|
|
@@ -5133,6 +5166,338 @@ function getExtractor(name) {
|
|
|
5133
5166
|
return EXTRACTORS[name];
|
|
5134
5167
|
}
|
|
5135
5168
|
|
|
5169
|
+
// src/extraction/resolve-referential.ts
|
|
5170
|
+
var import_zod35 = require("zod");
|
|
5171
|
+
|
|
5172
|
+
// src/prompts/extractors/referential-lookup.ts
|
|
5173
|
+
var import_zod34 = require("zod");
|
|
5174
|
+
var ReferentialLookupSchema = import_zod34.z.object({
|
|
5175
|
+
resolvedCoverages: import_zod34.z.array(
|
|
5176
|
+
import_zod34.z.object({
|
|
5177
|
+
coverageName: import_zod34.z.string().describe("The coverage name that was referenced"),
|
|
5178
|
+
resolvedLimit: import_zod34.z.string().optional().describe("The concrete limit value found, if any"),
|
|
5179
|
+
resolvedLimitValueType: CoverageValueTypeSchema.optional(),
|
|
5180
|
+
resolvedDeductible: import_zod34.z.string().optional().describe("The concrete deductible value found, if any"),
|
|
5181
|
+
resolvedDeductibleValueType: CoverageValueTypeSchema.optional(),
|
|
5182
|
+
pageNumber: import_zod34.z.number().optional().describe("Page where the resolved value was found"),
|
|
5183
|
+
originalContent: import_zod34.z.string().optional().describe("Verbatim source text for the resolved value"),
|
|
5184
|
+
confidence: import_zod34.z.enum(["high", "medium", "low"]).describe("Confidence in the resolution")
|
|
5185
|
+
})
|
|
5186
|
+
)
|
|
5187
|
+
});
|
|
5188
|
+
function buildReferentialLookupPrompt(coverages) {
|
|
5189
|
+
const coverageList = coverages.map((c, i) => {
|
|
5190
|
+
const parts = [` ${i + 1}. Coverage: "${c.name}" \u2014 Limit: "${c.limit}"`];
|
|
5191
|
+
if (c.deductible) {
|
|
5192
|
+
parts.push(` Deductible: "${c.deductible}"`);
|
|
5193
|
+
}
|
|
5194
|
+
if (c.sectionRef) {
|
|
5195
|
+
parts.push(` Referenced section: "${c.sectionRef}"`);
|
|
5196
|
+
}
|
|
5197
|
+
return parts.join("\n");
|
|
5198
|
+
}).join("\n");
|
|
5199
|
+
return `You are an expert insurance document analyst. You are looking at a specific section of an insurance document to resolve referential coverage limits.
|
|
5200
|
+
|
|
5201
|
+
The following coverages had referential limits or deductibles (e.g. "As stated in Policy", "As stated in Section 4 of Policy", "See Declarations") instead of concrete values:
|
|
5202
|
+
|
|
5203
|
+
${coverageList}
|
|
5204
|
+
|
|
5205
|
+
Your task:
|
|
5206
|
+
- Find the concrete/actual limit and deductible values for each coverage listed above.
|
|
5207
|
+
- Search the declarations page, coverage schedules, and any referenced sections for the real numeric or defined values.
|
|
5208
|
+
- Only return values you can actually find in the document \u2014 do not guess or infer values that are not explicitly stated.
|
|
5209
|
+
- For each resolved coverage, include:
|
|
5210
|
+
- pageNumber: the page where the resolved value appears
|
|
5211
|
+
- originalContent: the verbatim text snippet containing the resolved value
|
|
5212
|
+
- confidence: "high" if the value is clearly and unambiguously stated, "medium" if it requires interpretation, "low" if uncertain
|
|
5213
|
+
- If a coverage cannot be resolved (no concrete value found), still include it with confidence "low" and omit the resolved fields.
|
|
5214
|
+
- Classify resolvedLimitValueType and resolvedDeductibleValueType as numeric, included, not_included, as_stated, waiting_period, referential, or other.
|
|
5215
|
+
|
|
5216
|
+
Return JSON only.`;
|
|
5217
|
+
}
|
|
5218
|
+
|
|
5219
|
+
// src/extraction/resolve-referential.ts
|
|
5220
|
+
function looksReferential(value) {
|
|
5221
|
+
if (typeof value !== "string") return false;
|
|
5222
|
+
const normalized = value.toLowerCase();
|
|
5223
|
+
return normalized.includes("shown in the declarations") || normalized.includes("shown in declarations") || normalized.includes("shown in the schedule") || normalized.includes("as stated") || normalized.includes("if applicable");
|
|
5224
|
+
}
|
|
5225
|
+
function parseReferenceTarget(text) {
|
|
5226
|
+
if (typeof text !== "string") return void 0;
|
|
5227
|
+
const normalized = text.trim();
|
|
5228
|
+
if (!normalized) return void 0;
|
|
5229
|
+
const sectionMatch = normalized.match(/\b(Section\s+\d+[A-Za-z]?)/i);
|
|
5230
|
+
if (sectionMatch) return sectionMatch[1];
|
|
5231
|
+
if (/declarations/i.test(normalized)) return "Declarations";
|
|
5232
|
+
const scheduleMatch = normalized.match(/\b(Schedule(?:\s+of\s+[A-Za-z ]+)?)/i);
|
|
5233
|
+
if (scheduleMatch) return scheduleMatch[1].trim();
|
|
5234
|
+
const asStatedMatch = normalized.match(/(?:as\s+stated\s+in|see|shown\s+in(?:\s+the)?)\s+(.+)/i);
|
|
5235
|
+
if (asStatedMatch) {
|
|
5236
|
+
let target = asStatedMatch[1].trim().replace(/\s+of\s+the\s+policy$/i, "").trim();
|
|
5237
|
+
target = target.replace(/\.+$/, "").trim();
|
|
5238
|
+
if (target) return target;
|
|
5239
|
+
}
|
|
5240
|
+
if (/if applicable/i.test(normalized)) return void 0;
|
|
5241
|
+
return void 0;
|
|
5242
|
+
}
|
|
5243
|
+
var PageLocationSchema = import_zod35.z.object({
|
|
5244
|
+
startPage: import_zod35.z.number(),
|
|
5245
|
+
endPage: import_zod35.z.number()
|
|
5246
|
+
});
|
|
5247
|
+
async function findReferencedPages(params) {
|
|
5248
|
+
const {
|
|
5249
|
+
referenceTarget,
|
|
5250
|
+
sections,
|
|
5251
|
+
formInventory,
|
|
5252
|
+
pdfBase64,
|
|
5253
|
+
pageCount,
|
|
5254
|
+
generateObject,
|
|
5255
|
+
providerOptions,
|
|
5256
|
+
log
|
|
5257
|
+
} = params;
|
|
5258
|
+
const targetLower = referenceTarget.toLowerCase();
|
|
5259
|
+
for (const section of sections) {
|
|
5260
|
+
if (section.title && section.pageStart != null && section.title.toLowerCase().includes(targetLower)) {
|
|
5261
|
+
return {
|
|
5262
|
+
startPage: section.pageStart,
|
|
5263
|
+
endPage: section.pageEnd ?? section.pageStart
|
|
5264
|
+
};
|
|
5265
|
+
}
|
|
5266
|
+
}
|
|
5267
|
+
for (const form of formInventory) {
|
|
5268
|
+
const titleMatch = form.title && form.title.toLowerCase().includes(targetLower);
|
|
5269
|
+
const typeMatch = form.formType && form.formType.toLowerCase().includes(targetLower);
|
|
5270
|
+
if ((titleMatch || typeMatch) && form.pageStart != null) {
|
|
5271
|
+
return {
|
|
5272
|
+
startPage: form.pageStart,
|
|
5273
|
+
endPage: form.pageEnd ?? form.pageStart
|
|
5274
|
+
};
|
|
5275
|
+
}
|
|
5276
|
+
}
|
|
5277
|
+
try {
|
|
5278
|
+
const result = await safeGenerateObject(
|
|
5279
|
+
generateObject,
|
|
5280
|
+
{
|
|
5281
|
+
prompt: `You are analyzing an insurance document (${pageCount} pages total).
|
|
5282
|
+
|
|
5283
|
+
Find the pages that contain the section or area referenced as "${referenceTarget}".
|
|
5284
|
+
|
|
5285
|
+
Return the page range (1-indexed) where this section is located. If the section spans a single page, startPage and endPage should be the same.
|
|
5286
|
+
|
|
5287
|
+
If you cannot find the section, return startPage: 0 and endPage: 0.
|
|
5288
|
+
|
|
5289
|
+
Return JSON only.`,
|
|
5290
|
+
schema: PageLocationSchema,
|
|
5291
|
+
maxTokens: 256,
|
|
5292
|
+
providerOptions: { ...providerOptions, pdfBase64 }
|
|
5293
|
+
},
|
|
5294
|
+
{
|
|
5295
|
+
fallback: { startPage: 0, endPage: 0 },
|
|
5296
|
+
maxRetries: 1,
|
|
5297
|
+
log,
|
|
5298
|
+
onError: (err, attempt) => log?.(
|
|
5299
|
+
`Page location attempt ${attempt + 1} failed for "${referenceTarget}": ${err instanceof Error ? err.message : String(err)}`
|
|
5300
|
+
)
|
|
5301
|
+
}
|
|
5302
|
+
);
|
|
5303
|
+
if (result.object.startPage > 0 && result.object.endPage > 0) {
|
|
5304
|
+
return {
|
|
5305
|
+
startPage: result.object.startPage,
|
|
5306
|
+
endPage: result.object.endPage
|
|
5307
|
+
};
|
|
5308
|
+
}
|
|
5309
|
+
} catch (error) {
|
|
5310
|
+
await log?.(
|
|
5311
|
+
`Failed to locate pages for "${referenceTarget}": ${error instanceof Error ? error.message : String(error)}`
|
|
5312
|
+
);
|
|
5313
|
+
}
|
|
5314
|
+
return void 0;
|
|
5315
|
+
}
|
|
5316
|
+
async function resolveReferentialCoverages(params) {
|
|
5317
|
+
const {
|
|
5318
|
+
memory,
|
|
5319
|
+
pdfBase64,
|
|
5320
|
+
pageCount,
|
|
5321
|
+
generateObject,
|
|
5322
|
+
convertPdfToImages,
|
|
5323
|
+
concurrency = 2,
|
|
5324
|
+
providerOptions,
|
|
5325
|
+
log,
|
|
5326
|
+
onProgress
|
|
5327
|
+
} = params;
|
|
5328
|
+
const limit = pLimit(concurrency);
|
|
5329
|
+
let totalUsage = { inputTokens: 0, outputTokens: 0 };
|
|
5330
|
+
function trackUsage(usage) {
|
|
5331
|
+
if (usage) {
|
|
5332
|
+
totalUsage.inputTokens += usage.inputTokens;
|
|
5333
|
+
totalUsage.outputTokens += usage.outputTokens;
|
|
5334
|
+
}
|
|
5335
|
+
}
|
|
5336
|
+
const coverageData = memory.get("coverage_limits");
|
|
5337
|
+
const coverages = coverageData?.coverages ?? [];
|
|
5338
|
+
const referentialCoverages = coverages.filter((cov) => {
|
|
5339
|
+
const limitType = cov.limitValueType;
|
|
5340
|
+
const deductibleType = cov.deductibleValueType;
|
|
5341
|
+
return limitType === "referential" || limitType === "as_stated" || deductibleType === "referential" || deductibleType === "as_stated" || looksReferential(cov.limit) || looksReferential(cov.deductible);
|
|
5342
|
+
});
|
|
5343
|
+
const attempts = referentialCoverages.length;
|
|
5344
|
+
if (attempts === 0) {
|
|
5345
|
+
return {
|
|
5346
|
+
resolved: 0,
|
|
5347
|
+
unresolved: 0,
|
|
5348
|
+
attempts: 0,
|
|
5349
|
+
usage: totalUsage,
|
|
5350
|
+
details: []
|
|
5351
|
+
};
|
|
5352
|
+
}
|
|
5353
|
+
onProgress?.(
|
|
5354
|
+
`Found ${attempts} referential coverage(s) to resolve...`
|
|
5355
|
+
);
|
|
5356
|
+
const targetGroups = /* @__PURE__ */ new Map();
|
|
5357
|
+
for (let i = 0; i < referentialCoverages.length; i++) {
|
|
5358
|
+
const cov = referentialCoverages[i];
|
|
5359
|
+
const refString = (looksReferential(cov.limit) ? cov.limit : void 0) ?? (looksReferential(cov.deductible) ? cov.deductible : void 0) ?? cov.limit ?? "";
|
|
5360
|
+
const target = parseReferenceTarget(refString) ?? "unknown";
|
|
5361
|
+
const group = targetGroups.get(target) ?? [];
|
|
5362
|
+
group.push({ coverage: cov, index: i });
|
|
5363
|
+
targetGroups.set(target, group);
|
|
5364
|
+
}
|
|
5365
|
+
const sectionsData = memory.get("sections");
|
|
5366
|
+
const sections = sectionsData?.sections ?? [];
|
|
5367
|
+
const formInventoryData = memory.get("form_inventory");
|
|
5368
|
+
const formInventory = formInventoryData?.forms ?? [];
|
|
5369
|
+
const details = [];
|
|
5370
|
+
let resolved = 0;
|
|
5371
|
+
let unresolved = 0;
|
|
5372
|
+
const targetEntries = Array.from(targetGroups.entries());
|
|
5373
|
+
await Promise.all(
|
|
5374
|
+
targetEntries.map(
|
|
5375
|
+
([target, group]) => limit(async () => {
|
|
5376
|
+
const pageRange = await findReferencedPages({
|
|
5377
|
+
referenceTarget: target,
|
|
5378
|
+
sections,
|
|
5379
|
+
formInventory,
|
|
5380
|
+
pdfBase64,
|
|
5381
|
+
pageCount,
|
|
5382
|
+
generateObject,
|
|
5383
|
+
providerOptions,
|
|
5384
|
+
log
|
|
5385
|
+
});
|
|
5386
|
+
if (!pageRange) {
|
|
5387
|
+
await log?.(
|
|
5388
|
+
`Could not locate pages for reference target "${target}"`
|
|
5389
|
+
);
|
|
5390
|
+
for (const { coverage } of group) {
|
|
5391
|
+
details.push({
|
|
5392
|
+
coverageName: String(coverage.name ?? "unknown"),
|
|
5393
|
+
referenceTarget: target === "unknown" ? void 0 : target,
|
|
5394
|
+
status: "pages_not_found"
|
|
5395
|
+
});
|
|
5396
|
+
unresolved++;
|
|
5397
|
+
}
|
|
5398
|
+
return;
|
|
5399
|
+
}
|
|
5400
|
+
onProgress?.(
|
|
5401
|
+
`Resolving "${target}" from pages ${pageRange.startPage}-${pageRange.endPage}...`
|
|
5402
|
+
);
|
|
5403
|
+
const promptCoverages = group.map(({ coverage }) => ({
|
|
5404
|
+
name: String(coverage.name ?? "unknown"),
|
|
5405
|
+
limit: String(coverage.limit ?? ""),
|
|
5406
|
+
deductible: coverage.deductible ? String(coverage.deductible) : void 0,
|
|
5407
|
+
sectionRef: coverage.sectionRef ? String(coverage.sectionRef) : void 0
|
|
5408
|
+
}));
|
|
5409
|
+
try {
|
|
5410
|
+
const result = await runExtractor({
|
|
5411
|
+
name: "referential_lookup",
|
|
5412
|
+
prompt: buildReferentialLookupPrompt(promptCoverages),
|
|
5413
|
+
schema: ReferentialLookupSchema,
|
|
5414
|
+
pdfBase64,
|
|
5415
|
+
startPage: pageRange.startPage,
|
|
5416
|
+
endPage: pageRange.endPage,
|
|
5417
|
+
generateObject,
|
|
5418
|
+
convertPdfToImages,
|
|
5419
|
+
maxTokens: 4096,
|
|
5420
|
+
providerOptions
|
|
5421
|
+
});
|
|
5422
|
+
trackUsage(result.usage);
|
|
5423
|
+
const resolvedMap = /* @__PURE__ */ new Map();
|
|
5424
|
+
for (const rc of result.data.resolvedCoverages) {
|
|
5425
|
+
resolvedMap.set(rc.coverageName.toLowerCase(), rc);
|
|
5426
|
+
}
|
|
5427
|
+
for (const { coverage } of group) {
|
|
5428
|
+
const covName = String(coverage.name ?? "unknown");
|
|
5429
|
+
const rc = resolvedMap.get(covName.toLowerCase());
|
|
5430
|
+
if (!rc) {
|
|
5431
|
+
details.push({
|
|
5432
|
+
coverageName: covName,
|
|
5433
|
+
referenceTarget: target === "unknown" ? void 0 : target,
|
|
5434
|
+
status: "unresolved"
|
|
5435
|
+
});
|
|
5436
|
+
unresolved++;
|
|
5437
|
+
continue;
|
|
5438
|
+
}
|
|
5439
|
+
const limitResolved = rc.resolvedLimit && rc.resolvedLimitValueType !== "referential" && rc.resolvedLimitValueType !== "as_stated" && !looksReferential(rc.resolvedLimit);
|
|
5440
|
+
const deductibleResolved = rc.resolvedDeductible && rc.resolvedDeductibleValueType !== "referential" && rc.resolvedDeductibleValueType !== "as_stated" && !looksReferential(rc.resolvedDeductible);
|
|
5441
|
+
if (limitResolved || deductibleResolved) {
|
|
5442
|
+
if (limitResolved) {
|
|
5443
|
+
coverage.limit = rc.resolvedLimit;
|
|
5444
|
+
coverage.limitValueType = rc.resolvedLimitValueType ?? "numeric";
|
|
5445
|
+
}
|
|
5446
|
+
if (deductibleResolved) {
|
|
5447
|
+
coverage.deductible = rc.resolvedDeductible;
|
|
5448
|
+
coverage.deductibleValueType = rc.resolvedDeductibleValueType ?? "numeric";
|
|
5449
|
+
}
|
|
5450
|
+
if (rc.pageNumber != null) {
|
|
5451
|
+
coverage.resolvedFromPage = rc.pageNumber;
|
|
5452
|
+
}
|
|
5453
|
+
if (rc.originalContent) {
|
|
5454
|
+
coverage.resolvedOriginalContent = rc.originalContent;
|
|
5455
|
+
}
|
|
5456
|
+
details.push({
|
|
5457
|
+
coverageName: covName,
|
|
5458
|
+
referenceTarget: target === "unknown" ? void 0 : target,
|
|
5459
|
+
resolvedLimit: limitResolved ? rc.resolvedLimit : void 0,
|
|
5460
|
+
resolvedDeductible: deductibleResolved ? rc.resolvedDeductible : void 0,
|
|
5461
|
+
status: "resolved"
|
|
5462
|
+
});
|
|
5463
|
+
resolved++;
|
|
5464
|
+
} else {
|
|
5465
|
+
details.push({
|
|
5466
|
+
coverageName: covName,
|
|
5467
|
+
referenceTarget: target === "unknown" ? void 0 : target,
|
|
5468
|
+
status: "unresolved"
|
|
5469
|
+
});
|
|
5470
|
+
unresolved++;
|
|
5471
|
+
}
|
|
5472
|
+
}
|
|
5473
|
+
} catch (error) {
|
|
5474
|
+
await log?.(
|
|
5475
|
+
`Referential lookup extraction failed for target "${target}": ${error instanceof Error ? error.message : String(error)}`
|
|
5476
|
+
);
|
|
5477
|
+
for (const { coverage } of group) {
|
|
5478
|
+
details.push({
|
|
5479
|
+
coverageName: String(coverage.name ?? "unknown"),
|
|
5480
|
+
referenceTarget: target === "unknown" ? void 0 : target,
|
|
5481
|
+
status: "unresolved"
|
|
5482
|
+
});
|
|
5483
|
+
unresolved++;
|
|
5484
|
+
}
|
|
5485
|
+
}
|
|
5486
|
+
})
|
|
5487
|
+
)
|
|
5488
|
+
);
|
|
5489
|
+
onProgress?.(
|
|
5490
|
+
`Referential resolution complete: ${resolved} resolved, ${unresolved} unresolved out of ${attempts} attempts.`
|
|
5491
|
+
);
|
|
5492
|
+
return {
|
|
5493
|
+
resolved,
|
|
5494
|
+
unresolved,
|
|
5495
|
+
attempts,
|
|
5496
|
+
usage: totalUsage,
|
|
5497
|
+
details
|
|
5498
|
+
};
|
|
5499
|
+
}
|
|
5500
|
+
|
|
5136
5501
|
// src/core/quality.ts
|
|
5137
5502
|
function evaluateQualityGate(params) {
|
|
5138
5503
|
const { issues, hasRoundWarnings = false } = params;
|
|
@@ -5169,7 +5534,7 @@ function addFormEntry(inventory, formNumber, source, extra) {
|
|
|
5169
5534
|
sources: [source]
|
|
5170
5535
|
});
|
|
5171
5536
|
}
|
|
5172
|
-
function
|
|
5537
|
+
function looksReferential2(value) {
|
|
5173
5538
|
if (typeof value !== "string") return false;
|
|
5174
5539
|
const normalized = value.toLowerCase();
|
|
5175
5540
|
return normalized.includes("shown in the declarations") || normalized.includes("shown in declarations") || normalized.includes("shown in the schedule") || normalized.includes("as stated") || normalized.includes("if applicable");
|
|
@@ -5293,7 +5658,7 @@ function buildExtractionReviewReport(params) {
|
|
|
5293
5658
|
itemName: typeof coverage.name === "string" ? coverage.name : void 0
|
|
5294
5659
|
});
|
|
5295
5660
|
}
|
|
5296
|
-
if (
|
|
5661
|
+
if (looksReferential2(coverage.limit) || looksReferential2(coverage.deductible)) {
|
|
5297
5662
|
deterministicIssues.push({
|
|
5298
5663
|
code: "coverage_referential_value",
|
|
5299
5664
|
severity: "warning",
|
|
@@ -5415,7 +5780,8 @@ function buildExtractionReviewReport(params) {
|
|
|
5415
5780
|
}));
|
|
5416
5781
|
const artifacts = [
|
|
5417
5782
|
{ kind: "form_inventory", label: "Form Inventory", itemCount: formInventory.length },
|
|
5418
|
-
{ kind: "page_map", label: "Page Map", itemCount: params.pageAssignments.length }
|
|
5783
|
+
{ kind: "page_map", label: "Page Map", itemCount: params.pageAssignments.length },
|
|
5784
|
+
{ kind: "referential_resolution", label: "Referential Resolution", itemCount: coverages.filter((c) => c.limitValueType === "referential" || c.limitValueType === "as_stated" || c.deductibleValueType === "referential" || c.deductibleValueType === "as_stated").length }
|
|
5419
5785
|
];
|
|
5420
5786
|
const qualityGateStatus = evaluateQualityGate({
|
|
5421
5787
|
issues: deterministicIssues,
|
|
@@ -5902,6 +6268,37 @@ function createExtractor(config) {
|
|
|
5902
6268
|
memory: Object.fromEntries(memory)
|
|
5903
6269
|
});
|
|
5904
6270
|
}
|
|
6271
|
+
if (!pipelineCtx.isPhaseComplete("resolve_referential")) {
|
|
6272
|
+
onProgress?.("Resolving referential coverage limits...");
|
|
6273
|
+
try {
|
|
6274
|
+
const resolution = await resolveReferentialCoverages({
|
|
6275
|
+
memory,
|
|
6276
|
+
pdfBase64,
|
|
6277
|
+
pageCount,
|
|
6278
|
+
generateObject,
|
|
6279
|
+
convertPdfToImages,
|
|
6280
|
+
concurrency,
|
|
6281
|
+
providerOptions,
|
|
6282
|
+
log,
|
|
6283
|
+
onProgress
|
|
6284
|
+
});
|
|
6285
|
+
trackUsage(resolution.usage);
|
|
6286
|
+
if (resolution.attempts > 0) {
|
|
6287
|
+
await log?.(`Referential resolution: ${resolution.resolved}/${resolution.attempts} resolved, ${resolution.unresolved} unresolved`);
|
|
6288
|
+
}
|
|
6289
|
+
} catch (error) {
|
|
6290
|
+
await log?.(`Referential resolution failed, continuing: ${error instanceof Error ? error.message : String(error)}`);
|
|
6291
|
+
}
|
|
6292
|
+
await pipelineCtx.save("resolve_referential", {
|
|
6293
|
+
id,
|
|
6294
|
+
pageCount,
|
|
6295
|
+
classifyResult,
|
|
6296
|
+
formInventory,
|
|
6297
|
+
pageAssignments,
|
|
6298
|
+
plan,
|
|
6299
|
+
memory: Object.fromEntries(memory)
|
|
6300
|
+
});
|
|
6301
|
+
}
|
|
5905
6302
|
let reviewRounds = resumed?.reviewReport?.reviewRoundRecords ?? [];
|
|
5906
6303
|
let reviewReport = resumed?.reviewReport;
|
|
5907
6304
|
if (!pipelineCtx.isPhaseComplete("review")) {
|
|
@@ -6277,8 +6674,8 @@ Respond with JSON only:
|
|
|
6277
6674
|
}`;
|
|
6278
6675
|
|
|
6279
6676
|
// src/schemas/application.ts
|
|
6280
|
-
var
|
|
6281
|
-
var FieldTypeSchema =
|
|
6677
|
+
var import_zod36 = require("zod");
|
|
6678
|
+
var FieldTypeSchema = import_zod36.z.enum([
|
|
6282
6679
|
"text",
|
|
6283
6680
|
"numeric",
|
|
6284
6681
|
"currency",
|
|
@@ -6287,131 +6684,131 @@ var FieldTypeSchema = import_zod34.z.enum([
|
|
|
6287
6684
|
"table",
|
|
6288
6685
|
"declaration"
|
|
6289
6686
|
]);
|
|
6290
|
-
var ApplicationFieldSchema =
|
|
6291
|
-
id:
|
|
6292
|
-
label:
|
|
6293
|
-
section:
|
|
6687
|
+
var ApplicationFieldSchema = import_zod36.z.object({
|
|
6688
|
+
id: import_zod36.z.string(),
|
|
6689
|
+
label: import_zod36.z.string(),
|
|
6690
|
+
section: import_zod36.z.string(),
|
|
6294
6691
|
fieldType: FieldTypeSchema,
|
|
6295
|
-
required:
|
|
6296
|
-
options:
|
|
6297
|
-
columns:
|
|
6298
|
-
requiresExplanationIfYes:
|
|
6299
|
-
condition:
|
|
6300
|
-
dependsOn:
|
|
6301
|
-
whenValue:
|
|
6692
|
+
required: import_zod36.z.boolean(),
|
|
6693
|
+
options: import_zod36.z.array(import_zod36.z.string()).optional(),
|
|
6694
|
+
columns: import_zod36.z.array(import_zod36.z.string()).optional(),
|
|
6695
|
+
requiresExplanationIfYes: import_zod36.z.boolean().optional(),
|
|
6696
|
+
condition: import_zod36.z.object({
|
|
6697
|
+
dependsOn: import_zod36.z.string(),
|
|
6698
|
+
whenValue: import_zod36.z.string()
|
|
6302
6699
|
}).optional(),
|
|
6303
|
-
value:
|
|
6304
|
-
source:
|
|
6305
|
-
confidence:
|
|
6700
|
+
value: import_zod36.z.string().optional(),
|
|
6701
|
+
source: import_zod36.z.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
|
|
6702
|
+
confidence: import_zod36.z.enum(["confirmed", "high", "medium", "low"]).optional()
|
|
6306
6703
|
});
|
|
6307
|
-
var ApplicationClassifyResultSchema =
|
|
6308
|
-
isApplication:
|
|
6309
|
-
confidence:
|
|
6310
|
-
applicationType:
|
|
6704
|
+
var ApplicationClassifyResultSchema = import_zod36.z.object({
|
|
6705
|
+
isApplication: import_zod36.z.boolean(),
|
|
6706
|
+
confidence: import_zod36.z.number().min(0).max(1),
|
|
6707
|
+
applicationType: import_zod36.z.string().nullable()
|
|
6311
6708
|
});
|
|
6312
|
-
var FieldExtractionResultSchema =
|
|
6313
|
-
fields:
|
|
6709
|
+
var FieldExtractionResultSchema = import_zod36.z.object({
|
|
6710
|
+
fields: import_zod36.z.array(ApplicationFieldSchema)
|
|
6314
6711
|
});
|
|
6315
|
-
var AutoFillMatchSchema =
|
|
6316
|
-
fieldId:
|
|
6317
|
-
value:
|
|
6318
|
-
confidence:
|
|
6319
|
-
contextKey:
|
|
6712
|
+
var AutoFillMatchSchema = import_zod36.z.object({
|
|
6713
|
+
fieldId: import_zod36.z.string(),
|
|
6714
|
+
value: import_zod36.z.string(),
|
|
6715
|
+
confidence: import_zod36.z.enum(["confirmed"]),
|
|
6716
|
+
contextKey: import_zod36.z.string()
|
|
6320
6717
|
});
|
|
6321
|
-
var AutoFillResultSchema =
|
|
6322
|
-
matches:
|
|
6718
|
+
var AutoFillResultSchema = import_zod36.z.object({
|
|
6719
|
+
matches: import_zod36.z.array(AutoFillMatchSchema)
|
|
6323
6720
|
});
|
|
6324
|
-
var QuestionBatchResultSchema =
|
|
6325
|
-
batches:
|
|
6721
|
+
var QuestionBatchResultSchema = import_zod36.z.object({
|
|
6722
|
+
batches: import_zod36.z.array(import_zod36.z.array(import_zod36.z.string()).describe("Array of field IDs in this batch"))
|
|
6326
6723
|
});
|
|
6327
|
-
var LookupRequestSchema =
|
|
6328
|
-
type:
|
|
6329
|
-
description:
|
|
6330
|
-
url:
|
|
6331
|
-
targetFieldIds:
|
|
6724
|
+
var LookupRequestSchema = import_zod36.z.object({
|
|
6725
|
+
type: import_zod36.z.string().describe("Type of lookup: 'records', 'website', 'policy'"),
|
|
6726
|
+
description: import_zod36.z.string(),
|
|
6727
|
+
url: import_zod36.z.string().optional(),
|
|
6728
|
+
targetFieldIds: import_zod36.z.array(import_zod36.z.string())
|
|
6332
6729
|
});
|
|
6333
|
-
var ReplyIntentSchema =
|
|
6334
|
-
primaryIntent:
|
|
6335
|
-
hasAnswers:
|
|
6336
|
-
questionText:
|
|
6337
|
-
questionFieldIds:
|
|
6338
|
-
lookupRequests:
|
|
6730
|
+
var ReplyIntentSchema = import_zod36.z.object({
|
|
6731
|
+
primaryIntent: import_zod36.z.enum(["answers_only", "question", "lookup_request", "mixed"]),
|
|
6732
|
+
hasAnswers: import_zod36.z.boolean(),
|
|
6733
|
+
questionText: import_zod36.z.string().optional(),
|
|
6734
|
+
questionFieldIds: import_zod36.z.array(import_zod36.z.string()).optional(),
|
|
6735
|
+
lookupRequests: import_zod36.z.array(LookupRequestSchema).optional()
|
|
6339
6736
|
});
|
|
6340
|
-
var ParsedAnswerSchema =
|
|
6341
|
-
fieldId:
|
|
6342
|
-
value:
|
|
6343
|
-
explanation:
|
|
6737
|
+
var ParsedAnswerSchema = import_zod36.z.object({
|
|
6738
|
+
fieldId: import_zod36.z.string(),
|
|
6739
|
+
value: import_zod36.z.string(),
|
|
6740
|
+
explanation: import_zod36.z.string().optional()
|
|
6344
6741
|
});
|
|
6345
|
-
var AnswerParsingResultSchema =
|
|
6346
|
-
answers:
|
|
6347
|
-
unanswered:
|
|
6742
|
+
var AnswerParsingResultSchema = import_zod36.z.object({
|
|
6743
|
+
answers: import_zod36.z.array(ParsedAnswerSchema),
|
|
6744
|
+
unanswered: import_zod36.z.array(import_zod36.z.string()).describe("Field IDs that were not answered")
|
|
6348
6745
|
});
|
|
6349
|
-
var LookupFillSchema =
|
|
6350
|
-
fieldId:
|
|
6351
|
-
value:
|
|
6352
|
-
source:
|
|
6746
|
+
var LookupFillSchema = import_zod36.z.object({
|
|
6747
|
+
fieldId: import_zod36.z.string(),
|
|
6748
|
+
value: import_zod36.z.string(),
|
|
6749
|
+
source: import_zod36.z.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'")
|
|
6353
6750
|
});
|
|
6354
|
-
var LookupFillResultSchema =
|
|
6355
|
-
fills:
|
|
6356
|
-
unfillable:
|
|
6357
|
-
explanation:
|
|
6751
|
+
var LookupFillResultSchema = import_zod36.z.object({
|
|
6752
|
+
fills: import_zod36.z.array(LookupFillSchema),
|
|
6753
|
+
unfillable: import_zod36.z.array(import_zod36.z.string()),
|
|
6754
|
+
explanation: import_zod36.z.string().optional()
|
|
6358
6755
|
});
|
|
6359
|
-
var FlatPdfPlacementSchema =
|
|
6360
|
-
fieldId:
|
|
6361
|
-
page:
|
|
6362
|
-
x:
|
|
6363
|
-
y:
|
|
6364
|
-
text:
|
|
6365
|
-
fontSize:
|
|
6366
|
-
isCheckmark:
|
|
6756
|
+
var FlatPdfPlacementSchema = import_zod36.z.object({
|
|
6757
|
+
fieldId: import_zod36.z.string(),
|
|
6758
|
+
page: import_zod36.z.number(),
|
|
6759
|
+
x: import_zod36.z.number().describe("Percentage from left edge (0-100)"),
|
|
6760
|
+
y: import_zod36.z.number().describe("Percentage from top edge (0-100)"),
|
|
6761
|
+
text: import_zod36.z.string(),
|
|
6762
|
+
fontSize: import_zod36.z.number().optional(),
|
|
6763
|
+
isCheckmark: import_zod36.z.boolean().optional()
|
|
6367
6764
|
});
|
|
6368
|
-
var AcroFormMappingSchema =
|
|
6369
|
-
fieldId:
|
|
6370
|
-
acroFormName:
|
|
6371
|
-
value:
|
|
6765
|
+
var AcroFormMappingSchema = import_zod36.z.object({
|
|
6766
|
+
fieldId: import_zod36.z.string(),
|
|
6767
|
+
acroFormName: import_zod36.z.string(),
|
|
6768
|
+
value: import_zod36.z.string()
|
|
6372
6769
|
});
|
|
6373
|
-
var QualityGateStatusSchema =
|
|
6374
|
-
var QualitySeveritySchema =
|
|
6375
|
-
var ApplicationQualityIssueSchema =
|
|
6376
|
-
code:
|
|
6770
|
+
var QualityGateStatusSchema = import_zod36.z.enum(["passed", "warning", "failed"]);
|
|
6771
|
+
var QualitySeveritySchema = import_zod36.z.enum(["info", "warning", "blocking"]);
|
|
6772
|
+
var ApplicationQualityIssueSchema = import_zod36.z.object({
|
|
6773
|
+
code: import_zod36.z.string(),
|
|
6377
6774
|
severity: QualitySeveritySchema,
|
|
6378
|
-
message:
|
|
6379
|
-
fieldId:
|
|
6775
|
+
message: import_zod36.z.string(),
|
|
6776
|
+
fieldId: import_zod36.z.string().optional()
|
|
6380
6777
|
});
|
|
6381
|
-
var ApplicationQualityRoundSchema =
|
|
6382
|
-
round:
|
|
6383
|
-
kind:
|
|
6778
|
+
var ApplicationQualityRoundSchema = import_zod36.z.object({
|
|
6779
|
+
round: import_zod36.z.number(),
|
|
6780
|
+
kind: import_zod36.z.string(),
|
|
6384
6781
|
status: QualityGateStatusSchema,
|
|
6385
|
-
summary:
|
|
6782
|
+
summary: import_zod36.z.string().optional()
|
|
6386
6783
|
});
|
|
6387
|
-
var ApplicationQualityArtifactSchema =
|
|
6388
|
-
kind:
|
|
6389
|
-
label:
|
|
6390
|
-
itemCount:
|
|
6784
|
+
var ApplicationQualityArtifactSchema = import_zod36.z.object({
|
|
6785
|
+
kind: import_zod36.z.string(),
|
|
6786
|
+
label: import_zod36.z.string().optional(),
|
|
6787
|
+
itemCount: import_zod36.z.number().optional()
|
|
6391
6788
|
});
|
|
6392
|
-
var ApplicationEmailReviewSchema =
|
|
6393
|
-
issues:
|
|
6789
|
+
var ApplicationEmailReviewSchema = import_zod36.z.object({
|
|
6790
|
+
issues: import_zod36.z.array(ApplicationQualityIssueSchema),
|
|
6394
6791
|
qualityGateStatus: QualityGateStatusSchema
|
|
6395
6792
|
});
|
|
6396
|
-
var ApplicationQualityReportSchema =
|
|
6397
|
-
issues:
|
|
6398
|
-
rounds:
|
|
6399
|
-
artifacts:
|
|
6793
|
+
var ApplicationQualityReportSchema = import_zod36.z.object({
|
|
6794
|
+
issues: import_zod36.z.array(ApplicationQualityIssueSchema),
|
|
6795
|
+
rounds: import_zod36.z.array(ApplicationQualityRoundSchema).optional(),
|
|
6796
|
+
artifacts: import_zod36.z.array(ApplicationQualityArtifactSchema).optional(),
|
|
6400
6797
|
emailReview: ApplicationEmailReviewSchema.optional(),
|
|
6401
6798
|
qualityGateStatus: QualityGateStatusSchema
|
|
6402
6799
|
});
|
|
6403
|
-
var ApplicationStateSchema =
|
|
6404
|
-
id:
|
|
6405
|
-
pdfBase64:
|
|
6406
|
-
title:
|
|
6407
|
-
applicationType:
|
|
6408
|
-
fields:
|
|
6409
|
-
batches:
|
|
6410
|
-
currentBatchIndex:
|
|
6800
|
+
var ApplicationStateSchema = import_zod36.z.object({
|
|
6801
|
+
id: import_zod36.z.string(),
|
|
6802
|
+
pdfBase64: import_zod36.z.string().optional().describe("Original PDF, omitted after extraction"),
|
|
6803
|
+
title: import_zod36.z.string().optional(),
|
|
6804
|
+
applicationType: import_zod36.z.string().nullable().optional(),
|
|
6805
|
+
fields: import_zod36.z.array(ApplicationFieldSchema),
|
|
6806
|
+
batches: import_zod36.z.array(import_zod36.z.array(import_zod36.z.string())).optional(),
|
|
6807
|
+
currentBatchIndex: import_zod36.z.number().default(0),
|
|
6411
6808
|
qualityReport: ApplicationQualityReportSchema.optional(),
|
|
6412
|
-
status:
|
|
6413
|
-
createdAt:
|
|
6414
|
-
updatedAt:
|
|
6809
|
+
status: import_zod36.z.enum(["classifying", "extracting", "auto_filling", "batching", "collecting", "confirming", "mapping", "complete"]),
|
|
6810
|
+
createdAt: import_zod36.z.number(),
|
|
6811
|
+
updatedAt: import_zod36.z.number()
|
|
6415
6812
|
});
|
|
6416
6813
|
|
|
6417
6814
|
// src/application/agents/classifier.ts
|
|
@@ -7548,90 +7945,91 @@ Respond with the final answer, deduplicated citations array, overall confidence
|
|
|
7548
7945
|
}
|
|
7549
7946
|
|
|
7550
7947
|
// src/schemas/query.ts
|
|
7551
|
-
var
|
|
7552
|
-
var QueryIntentSchema =
|
|
7948
|
+
var import_zod37 = require("zod");
|
|
7949
|
+
var QueryIntentSchema = import_zod37.z.enum([
|
|
7553
7950
|
"policy_question",
|
|
7554
7951
|
"coverage_comparison",
|
|
7555
7952
|
"document_search",
|
|
7556
7953
|
"claims_inquiry",
|
|
7557
7954
|
"general_knowledge"
|
|
7558
7955
|
]);
|
|
7559
|
-
var QueryAttachmentKindSchema =
|
|
7560
|
-
var QueryAttachmentSchema =
|
|
7561
|
-
id:
|
|
7956
|
+
var QueryAttachmentKindSchema = import_zod37.z.enum(["image", "pdf", "text"]);
|
|
7957
|
+
var QueryAttachmentSchema = import_zod37.z.object({
|
|
7958
|
+
id: import_zod37.z.string().optional().describe("Optional stable attachment ID from the caller"),
|
|
7562
7959
|
kind: QueryAttachmentKindSchema,
|
|
7563
|
-
name:
|
|
7564
|
-
mimeType:
|
|
7565
|
-
base64:
|
|
7566
|
-
text:
|
|
7567
|
-
description:
|
|
7960
|
+
name: import_zod37.z.string().optional().describe("Original filename or user-facing label"),
|
|
7961
|
+
mimeType: import_zod37.z.string().optional().describe("MIME type such as image/jpeg or application/pdf"),
|
|
7962
|
+
base64: import_zod37.z.string().optional().describe("Base64-encoded file content for image/pdf attachments"),
|
|
7963
|
+
text: import_zod37.z.string().optional().describe("Plain-text attachment content when available"),
|
|
7964
|
+
description: import_zod37.z.string().optional().describe("Caller-provided description of the attachment")
|
|
7568
7965
|
});
|
|
7569
|
-
var SubQuestionSchema =
|
|
7570
|
-
question:
|
|
7966
|
+
var SubQuestionSchema = import_zod37.z.object({
|
|
7967
|
+
question: import_zod37.z.string().describe("Atomic sub-question to retrieve and answer independently"),
|
|
7571
7968
|
intent: QueryIntentSchema,
|
|
7572
|
-
chunkTypes:
|
|
7573
|
-
documentFilters:
|
|
7574
|
-
type:
|
|
7575
|
-
carrier:
|
|
7576
|
-
insuredName:
|
|
7577
|
-
policyNumber:
|
|
7578
|
-
quoteNumber:
|
|
7969
|
+
chunkTypes: import_zod37.z.array(import_zod37.z.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
|
|
7970
|
+
documentFilters: import_zod37.z.object({
|
|
7971
|
+
type: import_zod37.z.enum(["policy", "quote"]).optional(),
|
|
7972
|
+
carrier: import_zod37.z.string().optional(),
|
|
7973
|
+
insuredName: import_zod37.z.string().optional(),
|
|
7974
|
+
policyNumber: import_zod37.z.string().optional(),
|
|
7975
|
+
quoteNumber: import_zod37.z.string().optional(),
|
|
7976
|
+
policyTypes: import_zod37.z.array(PolicyTypeSchema).optional().describe("Filter by policy type (e.g. homeowners_ho3, renters_ho4, pet) to avoid mixing up similar policies")
|
|
7579
7977
|
}).optional().describe("Structured filters to narrow document lookup")
|
|
7580
7978
|
});
|
|
7581
|
-
var QueryClassifyResultSchema =
|
|
7979
|
+
var QueryClassifyResultSchema = import_zod37.z.object({
|
|
7582
7980
|
intent: QueryIntentSchema,
|
|
7583
|
-
subQuestions:
|
|
7584
|
-
requiresDocumentLookup:
|
|
7585
|
-
requiresChunkSearch:
|
|
7586
|
-
requiresConversationHistory:
|
|
7981
|
+
subQuestions: import_zod37.z.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
|
|
7982
|
+
requiresDocumentLookup: import_zod37.z.boolean().describe("Whether structured document lookup is needed"),
|
|
7983
|
+
requiresChunkSearch: import_zod37.z.boolean().describe("Whether semantic chunk search is needed"),
|
|
7984
|
+
requiresConversationHistory: import_zod37.z.boolean().describe("Whether conversation history is relevant")
|
|
7587
7985
|
});
|
|
7588
|
-
var EvidenceItemSchema =
|
|
7589
|
-
source:
|
|
7590
|
-
chunkId:
|
|
7591
|
-
documentId:
|
|
7592
|
-
turnId:
|
|
7593
|
-
attachmentId:
|
|
7594
|
-
text:
|
|
7595
|
-
relevance:
|
|
7596
|
-
metadata:
|
|
7986
|
+
var EvidenceItemSchema = import_zod37.z.object({
|
|
7987
|
+
source: import_zod37.z.enum(["chunk", "document", "conversation", "attachment"]),
|
|
7988
|
+
chunkId: import_zod37.z.string().optional(),
|
|
7989
|
+
documentId: import_zod37.z.string().optional(),
|
|
7990
|
+
turnId: import_zod37.z.string().optional(),
|
|
7991
|
+
attachmentId: import_zod37.z.string().optional(),
|
|
7992
|
+
text: import_zod37.z.string().describe("Text excerpt from the source"),
|
|
7993
|
+
relevance: import_zod37.z.number().min(0).max(1),
|
|
7994
|
+
metadata: import_zod37.z.array(import_zod37.z.object({ key: import_zod37.z.string(), value: import_zod37.z.string() })).optional()
|
|
7597
7995
|
});
|
|
7598
|
-
var AttachmentInterpretationSchema =
|
|
7599
|
-
summary:
|
|
7600
|
-
extractedFacts:
|
|
7601
|
-
recommendedFocus:
|
|
7602
|
-
confidence:
|
|
7996
|
+
var AttachmentInterpretationSchema = import_zod37.z.object({
|
|
7997
|
+
summary: import_zod37.z.string().describe("Concise summary of what the attachment shows or contains"),
|
|
7998
|
+
extractedFacts: import_zod37.z.array(import_zod37.z.string()).describe("Specific observable or document facts grounded in the attachment"),
|
|
7999
|
+
recommendedFocus: import_zod37.z.array(import_zod37.z.string()).describe("Important details to incorporate when answering follow-up questions"),
|
|
8000
|
+
confidence: import_zod37.z.number().min(0).max(1)
|
|
7603
8001
|
});
|
|
7604
|
-
var RetrievalResultSchema =
|
|
7605
|
-
subQuestion:
|
|
7606
|
-
evidence:
|
|
8002
|
+
var RetrievalResultSchema = import_zod37.z.object({
|
|
8003
|
+
subQuestion: import_zod37.z.string(),
|
|
8004
|
+
evidence: import_zod37.z.array(EvidenceItemSchema)
|
|
7607
8005
|
});
|
|
7608
|
-
var CitationSchema =
|
|
7609
|
-
index:
|
|
7610
|
-
chunkId:
|
|
7611
|
-
documentId:
|
|
7612
|
-
documentType:
|
|
7613
|
-
field:
|
|
7614
|
-
quote:
|
|
7615
|
-
relevance:
|
|
8006
|
+
var CitationSchema = import_zod37.z.object({
|
|
8007
|
+
index: import_zod37.z.number().describe("Citation number [1], [2], etc."),
|
|
8008
|
+
chunkId: import_zod37.z.string().describe("Source chunk ID, e.g. doc-123:coverage:2"),
|
|
8009
|
+
documentId: import_zod37.z.string(),
|
|
8010
|
+
documentType: import_zod37.z.enum(["policy", "quote"]).optional(),
|
|
8011
|
+
field: import_zod37.z.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
|
|
8012
|
+
quote: import_zod37.z.string().describe("Exact text from source that supports the claim"),
|
|
8013
|
+
relevance: import_zod37.z.number().min(0).max(1)
|
|
7616
8014
|
});
|
|
7617
|
-
var SubAnswerSchema =
|
|
7618
|
-
subQuestion:
|
|
7619
|
-
answer:
|
|
7620
|
-
citations:
|
|
7621
|
-
confidence:
|
|
7622
|
-
needsMoreContext:
|
|
8015
|
+
var SubAnswerSchema = import_zod37.z.object({
|
|
8016
|
+
subQuestion: import_zod37.z.string(),
|
|
8017
|
+
answer: import_zod37.z.string(),
|
|
8018
|
+
citations: import_zod37.z.array(CitationSchema),
|
|
8019
|
+
confidence: import_zod37.z.number().min(0).max(1),
|
|
8020
|
+
needsMoreContext: import_zod37.z.boolean().describe("True if evidence was insufficient to answer fully")
|
|
7623
8021
|
});
|
|
7624
|
-
var VerifyResultSchema =
|
|
7625
|
-
approved:
|
|
7626
|
-
issues:
|
|
7627
|
-
retrySubQuestions:
|
|
8022
|
+
var VerifyResultSchema = import_zod37.z.object({
|
|
8023
|
+
approved: import_zod37.z.boolean().describe("Whether all sub-answers are adequately grounded"),
|
|
8024
|
+
issues: import_zod37.z.array(import_zod37.z.string()).describe("Specific grounding or consistency issues found"),
|
|
8025
|
+
retrySubQuestions: import_zod37.z.array(import_zod37.z.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
|
|
7628
8026
|
});
|
|
7629
|
-
var QueryResultSchema =
|
|
7630
|
-
answer:
|
|
7631
|
-
citations:
|
|
8027
|
+
var QueryResultSchema = import_zod37.z.object({
|
|
8028
|
+
answer: import_zod37.z.string(),
|
|
8029
|
+
citations: import_zod37.z.array(CitationSchema),
|
|
7632
8030
|
intent: QueryIntentSchema,
|
|
7633
|
-
confidence:
|
|
7634
|
-
followUp:
|
|
8031
|
+
confidence: import_zod37.z.number().min(0).max(1),
|
|
8032
|
+
followUp: import_zod37.z.string().optional().describe("Suggested follow-up question if applicable")
|
|
7635
8033
|
});
|
|
7636
8034
|
|
|
7637
8035
|
// src/query/retriever.ts
|