@claritylabs/cl-sdk 3.1.0 → 3.1.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/README.md +1 -1
- package/dist/index.js +737 -334
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +737 -334
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3235,6 +3235,12 @@ function moneyAmount(value) {
|
|
|
3235
3235
|
function normalizeLabel(value) {
|
|
3236
3236
|
return normalizeWhitespace3(value ?? "").toLowerCase();
|
|
3237
3237
|
}
|
|
3238
|
+
function isGenericColumnLabel(value) {
|
|
3239
|
+
return /^column\s+\d+$/i.test(cleanValue(value) ?? "");
|
|
3240
|
+
}
|
|
3241
|
+
function isHeaderRow(row) {
|
|
3242
|
+
return row.metadata?.isHeader === true || row.metadata?.isHeader === "true";
|
|
3243
|
+
}
|
|
3238
3244
|
var OPERATIONAL_COVERAGE_TERM_KINDS = /* @__PURE__ */ new Set([
|
|
3239
3245
|
"each_claim_limit",
|
|
3240
3246
|
"each_occurrence_limit",
|
|
@@ -3255,6 +3261,7 @@ function termKind(label, value) {
|
|
|
3255
3261
|
if (/\bpremium\b/.test(text)) return "premium";
|
|
3256
3262
|
if (/\bsub[-\s]?limit\b/.test(text)) return "sublimit";
|
|
3257
3263
|
if (/\baggregate\b/.test(text)) return "aggregate_limit";
|
|
3264
|
+
if (/\beach\s+proceeding|per\s+proceeding\b/.test(text)) return "sublimit";
|
|
3258
3265
|
if (/\beach\s+claim|per\s+claim\b/.test(text)) return "each_claim_limit";
|
|
3259
3266
|
if (/\beach\s+occurrence|per\s+occurrence\b/.test(text)) return "each_occurrence_limit";
|
|
3260
3267
|
if (/\beach\s+loss|per\s+loss\b/.test(text)) return "each_loss_limit";
|
|
@@ -3281,9 +3288,13 @@ function isNameCell(label, value) {
|
|
|
3281
3288
|
const normalizedLabel = normalizeLabel(label);
|
|
3282
3289
|
const normalizedValue = normalizeLabel(value);
|
|
3283
3290
|
if (!value || moneyAmount(value) !== void 0) return false;
|
|
3291
|
+
if (/^item\s+\d+[.)]?\s*limits?\s+of\s+liability\b/.test(normalizedValue)) return false;
|
|
3284
3292
|
if (/\b(coverage|coverage part|insuring agreement|description|item|name)\b/.test(normalizedLabel)) {
|
|
3285
3293
|
return true;
|
|
3286
3294
|
}
|
|
3295
|
+
if (/\b(sub[-\s]?limit|aggregate(?:\s+policy)?\s+limit|limit\s+of\s+liability)\b/.test(normalizedLabel) && /\b[a-z][a-z0-9&/ -]{2,}\b/.test(normalizedValue) && !/\bcoverage\s+part\s+[a-z]\)?$/.test(normalizedValue)) {
|
|
3296
|
+
return true;
|
|
3297
|
+
}
|
|
3287
3298
|
if (/^column\s+1$/.test(normalizedLabel) && !/^(item\s+\d+|nwc-|iso-|cg |il |form\b|page\b)/i.test(normalizedValue)) {
|
|
3288
3299
|
return true;
|
|
3289
3300
|
}
|
|
@@ -3302,13 +3313,32 @@ function childMap(nodes) {
|
|
|
3302
3313
|
for (const group of children.values()) group.sort((left, right) => left.order - right.order);
|
|
3303
3314
|
return children;
|
|
3304
3315
|
}
|
|
3305
|
-
function
|
|
3316
|
+
function rawCellRows(row, children) {
|
|
3306
3317
|
return (children.get(row.id) ?? []).filter((child) => child.kind === "table_cell").map((cell) => ({
|
|
3307
3318
|
label: cleanValue(cell.title) ?? "Value",
|
|
3308
3319
|
value: cleanValue(cell.textExcerpt ?? cell.description ?? cell.title) ?? "",
|
|
3309
3320
|
node: cell
|
|
3310
3321
|
})).filter((cell) => cell.value);
|
|
3311
3322
|
}
|
|
3323
|
+
function headerLabelsForRow(row, children) {
|
|
3324
|
+
if (!row.parentId) return [];
|
|
3325
|
+
const labels = [];
|
|
3326
|
+
const siblingRows = (children.get(row.parentId) ?? []).filter((candidate) => candidate.kind === "table_row" && candidate.order < row.order).sort((left, right) => left.order - right.order);
|
|
3327
|
+
for (const sibling of siblingRows) {
|
|
3328
|
+
if (!isHeaderRow(sibling)) continue;
|
|
3329
|
+
for (const [index, cell] of rawCellRows(sibling, children).entries()) {
|
|
3330
|
+
const label = cleanValue(cell.value) ?? cleanValue(cell.label);
|
|
3331
|
+
if (label && !isGenericColumnLabel(label)) labels[index] = label;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
return labels;
|
|
3335
|
+
}
|
|
3336
|
+
function cellRows(row, children, headerLabels = []) {
|
|
3337
|
+
return rawCellRows(row, children).map((cell, index) => ({
|
|
3338
|
+
...cell,
|
|
3339
|
+
label: isGenericColumnLabel(cell.label) && headerLabels[index] ? headerLabels[index] : cell.label
|
|
3340
|
+
}));
|
|
3341
|
+
}
|
|
3312
3342
|
function directChildren(parent, children) {
|
|
3313
3343
|
return children.get(parent.id) ?? [];
|
|
3314
3344
|
}
|
|
@@ -3351,18 +3381,10 @@ function sourceIds(nodes) {
|
|
|
3351
3381
|
sourceSpanIds: [...new Set(nodes.flatMap((node) => node.sourceSpanIds))]
|
|
3352
3382
|
};
|
|
3353
3383
|
}
|
|
3354
|
-
function relabelGenericTerm(term, label) {
|
|
3355
|
-
const cleanLabel = cleanValue(label);
|
|
3356
|
-
if (!cleanLabel || !/^column\s+\d+$/i.test(term.label)) return term;
|
|
3357
|
-
return {
|
|
3358
|
-
...term,
|
|
3359
|
-
kind: termKind(cleanLabel, term.value),
|
|
3360
|
-
label: cleanLabel
|
|
3361
|
-
};
|
|
3362
|
-
}
|
|
3363
3384
|
function termFromCell(params) {
|
|
3364
|
-
const value =
|
|
3385
|
+
const value = cleanCoverageTermValue(params.value);
|
|
3365
3386
|
if (!value) return void 0;
|
|
3387
|
+
if (isRejectedCoverageTermValue(params.label, value)) return void 0;
|
|
3366
3388
|
const nodes = [params.row, params.cell].filter((node) => Boolean(node));
|
|
3367
3389
|
const kind = termKind(params.label, value);
|
|
3368
3390
|
const amount = moneyAmount(value);
|
|
@@ -3375,20 +3397,38 @@ function termFromCell(params) {
|
|
|
3375
3397
|
...sourceIds(nodes)
|
|
3376
3398
|
};
|
|
3377
3399
|
}
|
|
3400
|
+
function cleanCoverageTermValue(value) {
|
|
3401
|
+
return cleanValue(value)?.replace(/\s+\/\s*$/, "").trim();
|
|
3402
|
+
}
|
|
3403
|
+
function isRejectedCoverageTermValue(label, value) {
|
|
3404
|
+
if (/\bshown\s+in\s+item\s*\d+\b/i.test(value) && moneyAmount(value) === void 0) return true;
|
|
3405
|
+
if (/\b(does not afford coverage|doesn't afford coverage|no coverage|remains excluded|is excluded|are excluded|shall not cover|will not cover)\b/i.test(value) && moneyAmount(value) === void 0) {
|
|
3406
|
+
return true;
|
|
3407
|
+
}
|
|
3408
|
+
if (/^for:\s*\(\d+\)/i.test(label) && moneyAmount(value) === void 0) return true;
|
|
3409
|
+
if (value.length > 80 && /\b(exclusion|excluded|shall not|will not|does not|failure to)\b/i.test(value) && moneyAmount(value) === void 0) return true;
|
|
3410
|
+
return false;
|
|
3411
|
+
}
|
|
3378
3412
|
function termsFromRow(row, children) {
|
|
3379
|
-
const cells = cellRows(row, children);
|
|
3413
|
+
const cells = cellRows(row, children, headerLabelsForRow(row, children));
|
|
3380
3414
|
if (cells.length > 0) {
|
|
3381
3415
|
const pairedTerms = [];
|
|
3416
|
+
const pairedIndexes = /* @__PURE__ */ new Set();
|
|
3382
3417
|
for (const [index, cell] of cells.entries()) {
|
|
3383
3418
|
const next = cells[index + 1];
|
|
3384
3419
|
if (!next) continue;
|
|
3420
|
+
if (!isGenericColumnLabel(cell.label) && isNameCell(cell.label, cell.value)) continue;
|
|
3385
3421
|
if (!isCoverageTermLabel(cell.value)) continue;
|
|
3386
3422
|
if (isCoverageTermLabel(next.value) && moneyAmount(next.value) === void 0) continue;
|
|
3387
3423
|
const term = termFromCell({ row, cell: next.node, label: cell.value, value: next.value });
|
|
3388
|
-
if (term)
|
|
3424
|
+
if (term) {
|
|
3425
|
+
pairedTerms.push(term);
|
|
3426
|
+
pairedIndexes.add(index);
|
|
3427
|
+
pairedIndexes.add(index + 1);
|
|
3428
|
+
}
|
|
3389
3429
|
}
|
|
3390
|
-
|
|
3391
|
-
return
|
|
3430
|
+
const valueTerms = cells.filter((_, index) => !pairedIndexes.has(index)).filter((cell) => isValueCell(cell.label, cell.value)).map((cell) => termFromCell({ row, cell: cell.node, label: cell.label, value: cell.value })).filter((term) => Boolean(term));
|
|
3431
|
+
return [...pairedTerms, ...valueTerms];
|
|
3392
3432
|
}
|
|
3393
3433
|
const text = normalizeWhitespace3(row.textExcerpt ?? row.description ?? nodeText(row));
|
|
3394
3434
|
const terms = [];
|
|
@@ -3414,11 +3454,11 @@ function termsFromRow(row, children) {
|
|
|
3414
3454
|
return terms;
|
|
3415
3455
|
}
|
|
3416
3456
|
function nameFromRow(row, children) {
|
|
3417
|
-
const
|
|
3418
|
-
if (declarationName) return declarationName;
|
|
3419
|
-
const cells = cellRows(row, children);
|
|
3457
|
+
const cells = cellRows(row, children, headerLabelsForRow(row, children));
|
|
3420
3458
|
const named = cells.find((cell) => isNameCell(cell.label, cell.value));
|
|
3421
3459
|
if (named) return cleanValue(named.value);
|
|
3460
|
+
const declarationName = declarationCoverageNameFromRow(row, children);
|
|
3461
|
+
if (declarationName) return declarationName;
|
|
3422
3462
|
return coverageNameFromRow(row.textExcerpt ?? row.description ?? nodeText(row));
|
|
3423
3463
|
}
|
|
3424
3464
|
function legacyLimit(terms) {
|
|
@@ -3451,7 +3491,7 @@ function isOperationalCoverageRow(coverage) {
|
|
|
3451
3491
|
if (coverage.name.split(/\s+/).length > 16 && !/\b(coverage|liability|sub[-\s]?limit|aggregate|each\s+(claim|loss|occurrence)|limit)\b/i.test(coverage.name)) {
|
|
3452
3492
|
return false;
|
|
3453
3493
|
}
|
|
3454
|
-
return /\b(coverage|coverage part|liability|sub[-\s]?limit|aggregate|each\s+(claim|loss|occurrence)|bricking|cyber|privacy|media|regulatory|defense|ai\/ml|errors?\s*&?\s*omissions|technology)\b/i.test(coverage.name);
|
|
3494
|
+
return /\b(coverage|coverage part|liability|sub[-\s]?limit|aggregate|each\s+(claim|loss|occurrence|proceeding)|bricking|cyber|privacy|media|regulatory|defense|fraud|social engineering|ai\/ml|errors?\s*&?\s*omissions|technology)\b/i.test(coverage.name);
|
|
3455
3495
|
}
|
|
3456
3496
|
function uniqueTerms(terms) {
|
|
3457
3497
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -3465,7 +3505,7 @@ function uniqueTerms(terms) {
|
|
|
3465
3505
|
return result;
|
|
3466
3506
|
}
|
|
3467
3507
|
function coverageFromTableRow(row, children, byId) {
|
|
3468
|
-
if (row
|
|
3508
|
+
if (isHeaderRow(row)) return void 0;
|
|
3469
3509
|
const name = nameFromRow(row, children);
|
|
3470
3510
|
const terms = uniqueTerms(termsFromRow(row, children));
|
|
3471
3511
|
if (!name || terms.length === 0) return void 0;
|
|
@@ -3490,8 +3530,7 @@ function coverageFromEndorsement(endorsement, children) {
|
|
|
3490
3530
|
const terms = uniqueTerms(rows.flatMap(
|
|
3491
3531
|
(row) => termsFromRow(row, children).map((term) => {
|
|
3492
3532
|
const appliesTo = nameFromRow(row, children);
|
|
3493
|
-
|
|
3494
|
-
return appliesTo && labelled.label !== appliesTo ? { ...labelled, appliesTo } : labelled;
|
|
3533
|
+
return appliesTo && term.label !== appliesTo ? { ...term, appliesTo } : term;
|
|
3495
3534
|
})
|
|
3496
3535
|
));
|
|
3497
3536
|
if (terms.length === 0) return void 0;
|
|
@@ -9694,7 +9733,343 @@ function groundExtractionMemoryWithSourceSpans(memory, sourceSpans) {
|
|
|
9694
9733
|
}
|
|
9695
9734
|
|
|
9696
9735
|
// src/extraction/source-tree-extractor.ts
|
|
9736
|
+
import { z as z42 } from "zod";
|
|
9737
|
+
|
|
9738
|
+
// src/extraction/operational-profile-cleanup.ts
|
|
9697
9739
|
import { z as z41 } from "zod";
|
|
9740
|
+
var OPERATIONAL_COVERAGE_TERM_KINDS2 = [
|
|
9741
|
+
"each_claim_limit",
|
|
9742
|
+
"each_occurrence_limit",
|
|
9743
|
+
"each_loss_limit",
|
|
9744
|
+
"aggregate_limit",
|
|
9745
|
+
"sublimit",
|
|
9746
|
+
"retention",
|
|
9747
|
+
"deductible",
|
|
9748
|
+
"retroactive_date",
|
|
9749
|
+
"premium",
|
|
9750
|
+
"other"
|
|
9751
|
+
];
|
|
9752
|
+
var OperationalCoverageTermKindSchema = z41.enum(OPERATIONAL_COVERAGE_TERM_KINDS2);
|
|
9753
|
+
var OperationalProfileCleanupSchema = z41.object({
|
|
9754
|
+
coverageDecisions: z41.array(z41.object({
|
|
9755
|
+
coverageIndex: z41.number().int().nonnegative(),
|
|
9756
|
+
action: z41.enum(["keep", "drop", "update"]),
|
|
9757
|
+
reason: z41.string().optional(),
|
|
9758
|
+
name: z41.string().optional(),
|
|
9759
|
+
limit: z41.string().nullable().optional(),
|
|
9760
|
+
deductible: z41.string().nullable().optional(),
|
|
9761
|
+
premium: z41.string().nullable().optional(),
|
|
9762
|
+
retroactiveDate: z41.string().nullable().optional(),
|
|
9763
|
+
coverageOrigin: z41.enum(["core", "endorsement"]).optional(),
|
|
9764
|
+
sourceNodeIds: z41.array(z41.string()).optional(),
|
|
9765
|
+
sourceSpanIds: z41.array(z41.string()).optional(),
|
|
9766
|
+
termDecisions: z41.array(z41.object({
|
|
9767
|
+
termIndex: z41.number().int().nonnegative(),
|
|
9768
|
+
action: z41.enum(["keep", "drop", "update"]),
|
|
9769
|
+
reason: z41.string().optional(),
|
|
9770
|
+
kind: OperationalCoverageTermKindSchema.optional(),
|
|
9771
|
+
label: z41.string().optional(),
|
|
9772
|
+
value: z41.string().optional(),
|
|
9773
|
+
amount: z41.number().nullable().optional(),
|
|
9774
|
+
appliesTo: z41.string().nullable().optional(),
|
|
9775
|
+
sourceNodeIds: z41.array(z41.string()).optional(),
|
|
9776
|
+
sourceSpanIds: z41.array(z41.string()).optional()
|
|
9777
|
+
})).optional()
|
|
9778
|
+
})).default([]),
|
|
9779
|
+
warnings: z41.array(z41.string()).default([])
|
|
9780
|
+
});
|
|
9781
|
+
function compactNode(node, maxText = 700) {
|
|
9782
|
+
return {
|
|
9783
|
+
id: node.id,
|
|
9784
|
+
kind: node.kind,
|
|
9785
|
+
title: node.title,
|
|
9786
|
+
path: node.path,
|
|
9787
|
+
pageStart: node.pageStart,
|
|
9788
|
+
pageEnd: node.pageEnd,
|
|
9789
|
+
sourceSpanIds: node.sourceSpanIds.slice(0, 8),
|
|
9790
|
+
text: (node.textExcerpt ?? node.description).slice(0, maxText)
|
|
9791
|
+
};
|
|
9792
|
+
}
|
|
9793
|
+
function compactCoverageForCleanup(coverage, coverageIndex) {
|
|
9794
|
+
return {
|
|
9795
|
+
coverageIndex,
|
|
9796
|
+
name: coverage.name,
|
|
9797
|
+
limit: coverage.limit,
|
|
9798
|
+
deductible: coverage.deductible,
|
|
9799
|
+
premium: coverage.premium,
|
|
9800
|
+
retroactiveDate: coverage.retroactiveDate,
|
|
9801
|
+
coverageOrigin: coverage.coverageOrigin,
|
|
9802
|
+
sourceNodeIds: coverage.sourceNodeIds,
|
|
9803
|
+
sourceSpanIds: coverage.sourceSpanIds,
|
|
9804
|
+
terms: coverage.limits.map((term, termIndex) => ({
|
|
9805
|
+
termIndex,
|
|
9806
|
+
kind: term.kind,
|
|
9807
|
+
label: term.label,
|
|
9808
|
+
value: term.value,
|
|
9809
|
+
amount: term.amount,
|
|
9810
|
+
appliesTo: term.appliesTo,
|
|
9811
|
+
sourceNodeIds: term.sourceNodeIds,
|
|
9812
|
+
sourceSpanIds: term.sourceSpanIds
|
|
9813
|
+
}))
|
|
9814
|
+
};
|
|
9815
|
+
}
|
|
9816
|
+
function buildOperationalProfileCleanupPrompt(sourceTree, profile) {
|
|
9817
|
+
const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 320).map((node) => compactNode(node, node.kind === "page" ? 900 : 700));
|
|
9818
|
+
const candidate = {
|
|
9819
|
+
documentType: profile.documentType,
|
|
9820
|
+
policyTypes: profile.policyTypes,
|
|
9821
|
+
coverageTypes: profile.coverageTypes,
|
|
9822
|
+
coverages: profile.coverages.map(compactCoverageForCleanup)
|
|
9823
|
+
};
|
|
9824
|
+
return `Review and clean a source-backed operational profile projection for an insurance policy.
|
|
9825
|
+
|
|
9826
|
+
Task:
|
|
9827
|
+
- Inspect the candidate coverage projection against the source nodes.
|
|
9828
|
+
- Return cleanup decisions only for coverage rows or terms that are malformed, unsupported, mismatched, or misleading.
|
|
9829
|
+
- If the projection is already acceptable, return an empty coverageDecisions array.
|
|
9830
|
+
|
|
9831
|
+
Projection defects to look for:
|
|
9832
|
+
- Generic labels such as "Column 3" that should be renamed from nearby row/header evidence.
|
|
9833
|
+
- Declaration or section headers projected as coverage names when the row evidence is actually a specific coverage, sub-limit, deductible, retention, retroactive date, or premium.
|
|
9834
|
+
- Dangling continuation punctuation such as a trailing "/" copied into values.
|
|
9835
|
+
- Item references such as "shown in Item 7" or bare item numbers treated as money amounts.
|
|
9836
|
+
- Policy wording, exclusions, or unsupported prose copied into operational limit/deductible fields.
|
|
9837
|
+
- Header/value splits where "Limit of Liability", "Deductible", "Retroactive Date", "Aggregate", "Each Claim", or similar terms are attached to the wrong coverage row.
|
|
9838
|
+
- Repeated schedule headings projected as separate coverages when they only introduce the next coverage group.
|
|
9839
|
+
|
|
9840
|
+
Rules:
|
|
9841
|
+
- Use internal reasoning, but return JSON decisions only.
|
|
9842
|
+
- Do not invent policy facts. Keep, drop, or update only existing coverageIndex and termIndex entries.
|
|
9843
|
+
- Use sourceNodeIds and sourceSpanIds only from the provided source nodes or from the existing candidate entry.
|
|
9844
|
+
- Prefer dropping a malformed fact over speculative rewriting.
|
|
9845
|
+
- Keep a coverage when it is a real operational coverage/benefit even if only one term needs cleanup.
|
|
9846
|
+
- When changing a term's semantic meaning, set kind to the corrected normalized term kind.
|
|
9847
|
+
- Do not add new coverage rows or new terms; this pass cleans the existing projection.
|
|
9848
|
+
- Keep reasons concise and factual.
|
|
9849
|
+
|
|
9850
|
+
Candidate projection:
|
|
9851
|
+
${JSON.stringify(candidate, null, 2)}
|
|
9852
|
+
|
|
9853
|
+
Source nodes:
|
|
9854
|
+
${JSON.stringify(nodes, null, 2)}
|
|
9855
|
+
|
|
9856
|
+
Return JSON with coverageDecisions and warnings only.`;
|
|
9857
|
+
}
|
|
9858
|
+
function hasOwn(object, key) {
|
|
9859
|
+
return Object.prototype.hasOwnProperty.call(object, key);
|
|
9860
|
+
}
|
|
9861
|
+
function uniqueStrings(values) {
|
|
9862
|
+
return [...new Set(values.filter((value) => value.length > 0))];
|
|
9863
|
+
}
|
|
9864
|
+
function cleanProfileValue(value) {
|
|
9865
|
+
if (typeof value !== "string") return void 0;
|
|
9866
|
+
const cleaned = value.replace(/\s+\/\s*$/, "").replace(/\s+/g, " ").replace(/^[\s:;#-]+|[\s;,.]+$/g, "").trim();
|
|
9867
|
+
return cleaned || void 0;
|
|
9868
|
+
}
|
|
9869
|
+
function validIds(ids, valid) {
|
|
9870
|
+
return uniqueStrings((ids ?? []).filter((id) => valid.has(id)));
|
|
9871
|
+
}
|
|
9872
|
+
function cleanupIds(ids, valid, fallback) {
|
|
9873
|
+
if (ids === void 0) return validIds(fallback, valid);
|
|
9874
|
+
const next = validIds(ids, valid);
|
|
9875
|
+
return next.length > 0 ? next : validIds(fallback, valid);
|
|
9876
|
+
}
|
|
9877
|
+
function amountFromOperationalValue(value) {
|
|
9878
|
+
const match = value.match(/\$\s*([0-9][0-9,]*(?:\.\d+)?)/) ?? value.match(/\b([0-9][0-9,]*(?:\.\d+)?)\s*%/);
|
|
9879
|
+
if (!match) return void 0;
|
|
9880
|
+
const amount = Number(match[1].replace(/,/g, ""));
|
|
9881
|
+
return Number.isFinite(amount) ? amount : void 0;
|
|
9882
|
+
}
|
|
9883
|
+
function normalizedTermText(term) {
|
|
9884
|
+
return `${term.kind} ${term.label} ${term.value}`.toLowerCase();
|
|
9885
|
+
}
|
|
9886
|
+
function isLimitTerm(term) {
|
|
9887
|
+
return ["each_claim_limit", "each_occurrence_limit", "each_loss_limit", "aggregate_limit", "sublimit"].includes(term.kind) || term.kind === "other" && /\b(limit|aggregate|claim|occurrence|loss|proceeding)\b/i.test(normalizedTermText(term));
|
|
9888
|
+
}
|
|
9889
|
+
function isDeductibleTerm(term) {
|
|
9890
|
+
return term.kind === "deductible" || term.kind === "retention" || /\b(deductible|retention|sir)\b/i.test(normalizedTermText(term));
|
|
9891
|
+
}
|
|
9892
|
+
function isPremiumTerm(term) {
|
|
9893
|
+
return term.kind === "premium" || /\bpremium\b/i.test(normalizedTermText(term));
|
|
9894
|
+
}
|
|
9895
|
+
function isRetroactiveDateTerm(term) {
|
|
9896
|
+
return term.kind === "retroactive_date" || /\bretroactive\b/i.test(normalizedTermText(term));
|
|
9897
|
+
}
|
|
9898
|
+
function primaryLimitFromTerms(terms) {
|
|
9899
|
+
return terms.find(isLimitTerm)?.value;
|
|
9900
|
+
}
|
|
9901
|
+
function deductibleFromTerms(terms) {
|
|
9902
|
+
return terms.find(isDeductibleTerm)?.value;
|
|
9903
|
+
}
|
|
9904
|
+
function premiumFromTerms(terms) {
|
|
9905
|
+
return terms.find(isPremiumTerm)?.value;
|
|
9906
|
+
}
|
|
9907
|
+
function retroactiveDateFromTerms(terms) {
|
|
9908
|
+
return terms.find(isRetroactiveDateTerm)?.value;
|
|
9909
|
+
}
|
|
9910
|
+
function termDecisionTouches(coverage, decision, predicate) {
|
|
9911
|
+
const existing = coverage.limits[decision.termIndex];
|
|
9912
|
+
if (existing && predicate(existing)) return true;
|
|
9913
|
+
if (!decision.kind && !decision.label && !decision.value) return false;
|
|
9914
|
+
return predicate({
|
|
9915
|
+
kind: decision.kind ?? existing?.kind ?? "other",
|
|
9916
|
+
label: cleanProfileValue(decision.label) ?? existing?.label ?? "",
|
|
9917
|
+
value: cleanProfileValue(decision.value) ?? existing?.value ?? ""
|
|
9918
|
+
});
|
|
9919
|
+
}
|
|
9920
|
+
function applyTermCleanupDecision(term, decision, validNodeIds, validSpanIds) {
|
|
9921
|
+
if (!decision || decision.action === "keep") return term;
|
|
9922
|
+
if (decision.action === "drop") return void 0;
|
|
9923
|
+
const label = cleanProfileValue(decision.label) ?? term.label;
|
|
9924
|
+
const value = cleanProfileValue(decision.value) ?? term.value;
|
|
9925
|
+
if (!label || !value) return term;
|
|
9926
|
+
const next = {
|
|
9927
|
+
...term,
|
|
9928
|
+
kind: decision.kind ?? term.kind,
|
|
9929
|
+
label,
|
|
9930
|
+
value,
|
|
9931
|
+
sourceNodeIds: cleanupIds(decision.sourceNodeIds, validNodeIds, term.sourceNodeIds),
|
|
9932
|
+
sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, term.sourceSpanIds)
|
|
9933
|
+
};
|
|
9934
|
+
if (next.sourceNodeIds.length === 0 && next.sourceSpanIds.length === 0) return term;
|
|
9935
|
+
if (hasOwn(decision, "amount")) {
|
|
9936
|
+
if (typeof decision.amount === "number" && Number.isFinite(decision.amount)) next.amount = decision.amount;
|
|
9937
|
+
else delete next.amount;
|
|
9938
|
+
} else if (decision.value || decision.kind) {
|
|
9939
|
+
const amount = next.kind === "retroactive_date" ? void 0 : amountFromOperationalValue(next.value);
|
|
9940
|
+
if (amount === void 0) delete next.amount;
|
|
9941
|
+
else next.amount = amount;
|
|
9942
|
+
}
|
|
9943
|
+
if (hasOwn(decision, "appliesTo")) {
|
|
9944
|
+
const appliesTo = cleanProfileValue(decision.appliesTo);
|
|
9945
|
+
if (appliesTo) next.appliesTo = appliesTo;
|
|
9946
|
+
else delete next.appliesTo;
|
|
9947
|
+
}
|
|
9948
|
+
return next;
|
|
9949
|
+
}
|
|
9950
|
+
function termDecisionsTouch(coverage, decisions, predicate) {
|
|
9951
|
+
return decisions.filter((decision) => decision.action !== "keep").some((decision) => termDecisionTouches(coverage, decision, predicate));
|
|
9952
|
+
}
|
|
9953
|
+
function applyCoverageCleanupDecision(coverage, decision, validNodeIds, validSpanIds) {
|
|
9954
|
+
if (!decision || decision.action === "keep") return coverage;
|
|
9955
|
+
if (decision.action === "drop") return void 0;
|
|
9956
|
+
const next = {
|
|
9957
|
+
...coverage,
|
|
9958
|
+
limits: [...coverage.limits],
|
|
9959
|
+
sourceNodeIds: cleanupIds(decision.sourceNodeIds, validNodeIds, coverage.sourceNodeIds),
|
|
9960
|
+
sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, coverage.sourceSpanIds)
|
|
9961
|
+
};
|
|
9962
|
+
const name = cleanProfileValue(decision.name);
|
|
9963
|
+
if (name) next.name = name;
|
|
9964
|
+
if (decision.coverageOrigin) next.coverageOrigin = decision.coverageOrigin;
|
|
9965
|
+
if (hasOwn(decision, "limit")) {
|
|
9966
|
+
const value = cleanProfileValue(decision.limit);
|
|
9967
|
+
if (value) next.limit = value;
|
|
9968
|
+
else delete next.limit;
|
|
9969
|
+
}
|
|
9970
|
+
if (hasOwn(decision, "deductible")) {
|
|
9971
|
+
const value = cleanProfileValue(decision.deductible);
|
|
9972
|
+
if (value) next.deductible = value;
|
|
9973
|
+
else delete next.deductible;
|
|
9974
|
+
}
|
|
9975
|
+
if (hasOwn(decision, "premium")) {
|
|
9976
|
+
const value = cleanProfileValue(decision.premium);
|
|
9977
|
+
if (value) next.premium = value;
|
|
9978
|
+
else delete next.premium;
|
|
9979
|
+
}
|
|
9980
|
+
if (hasOwn(decision, "retroactiveDate")) {
|
|
9981
|
+
const value = cleanProfileValue(decision.retroactiveDate);
|
|
9982
|
+
if (value) next.retroactiveDate = value;
|
|
9983
|
+
else delete next.retroactiveDate;
|
|
9984
|
+
}
|
|
9985
|
+
const termDecisions = (decision.termDecisions ?? []).filter((termDecision) => termDecision.termIndex < coverage.limits.length);
|
|
9986
|
+
const termDecisionByIndex = new Map(termDecisions.map((termDecision) => [termDecision.termIndex, termDecision]));
|
|
9987
|
+
next.limits = coverage.limits.map((term, index) => applyTermCleanupDecision(term, termDecisionByIndex.get(index), validNodeIds, validSpanIds)).filter((term) => Boolean(term));
|
|
9988
|
+
if (termDecisions.length > 0) {
|
|
9989
|
+
if (!hasOwn(decision, "limit") && termDecisionsTouch(coverage, termDecisions, isLimitTerm)) {
|
|
9990
|
+
const value = primaryLimitFromTerms(next.limits);
|
|
9991
|
+
if (value) next.limit = value;
|
|
9992
|
+
else delete next.limit;
|
|
9993
|
+
}
|
|
9994
|
+
if (!hasOwn(decision, "deductible") && termDecisionsTouch(coverage, termDecisions, isDeductibleTerm)) {
|
|
9995
|
+
const value = deductibleFromTerms(next.limits);
|
|
9996
|
+
if (value) next.deductible = value;
|
|
9997
|
+
else delete next.deductible;
|
|
9998
|
+
}
|
|
9999
|
+
if (!hasOwn(decision, "premium") && termDecisionsTouch(coverage, termDecisions, isPremiumTerm)) {
|
|
10000
|
+
const value = premiumFromTerms(next.limits);
|
|
10001
|
+
if (value) next.premium = value;
|
|
10002
|
+
else delete next.premium;
|
|
10003
|
+
}
|
|
10004
|
+
if (!hasOwn(decision, "retroactiveDate") && termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm)) {
|
|
10005
|
+
const value = retroactiveDateFromTerms(next.limits);
|
|
10006
|
+
if (value) next.retroactiveDate = value;
|
|
10007
|
+
else delete next.retroactiveDate;
|
|
10008
|
+
}
|
|
10009
|
+
}
|
|
10010
|
+
next.sourceNodeIds = uniqueStrings([
|
|
10011
|
+
...next.sourceNodeIds,
|
|
10012
|
+
...next.limits.flatMap((term) => term.sourceNodeIds)
|
|
10013
|
+
]);
|
|
10014
|
+
next.sourceSpanIds = uniqueStrings([
|
|
10015
|
+
...next.sourceSpanIds,
|
|
10016
|
+
...next.limits.flatMap((term) => term.sourceSpanIds)
|
|
10017
|
+
]);
|
|
10018
|
+
return next.name ? next : coverage;
|
|
10019
|
+
}
|
|
10020
|
+
function sourceIdsFromOperationalProfile(profile) {
|
|
10021
|
+
const backedValues = [
|
|
10022
|
+
profile.policyNumber,
|
|
10023
|
+
profile.namedInsured,
|
|
10024
|
+
profile.insurer,
|
|
10025
|
+
profile.broker,
|
|
10026
|
+
profile.effectiveDate,
|
|
10027
|
+
profile.expirationDate,
|
|
10028
|
+
profile.retroactiveDate,
|
|
10029
|
+
profile.premium
|
|
10030
|
+
].filter(Boolean);
|
|
10031
|
+
return {
|
|
10032
|
+
sourceNodeIds: uniqueStrings([
|
|
10033
|
+
...backedValues.flatMap((value) => value?.sourceNodeIds ?? []),
|
|
10034
|
+
...profile.coverages.flatMap((coverage) => coverage.sourceNodeIds),
|
|
10035
|
+
...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceNodeIds)),
|
|
10036
|
+
...profile.parties.flatMap((party) => party.sourceNodeIds),
|
|
10037
|
+
...profile.endorsementSupport.flatMap((support) => support.sourceNodeIds)
|
|
10038
|
+
]),
|
|
10039
|
+
sourceSpanIds: uniqueStrings([
|
|
10040
|
+
...backedValues.flatMap((value) => value?.sourceSpanIds ?? []),
|
|
10041
|
+
...profile.coverages.flatMap((coverage) => coverage.sourceSpanIds),
|
|
10042
|
+
...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceSpanIds)),
|
|
10043
|
+
...profile.parties.flatMap((party) => party.sourceSpanIds),
|
|
10044
|
+
...profile.endorsementSupport.flatMap((support) => support.sourceSpanIds)
|
|
10045
|
+
])
|
|
10046
|
+
};
|
|
10047
|
+
}
|
|
10048
|
+
function applyOperationalProfileCleanup(profile, cleanup, validNodeIds, validSpanIds) {
|
|
10049
|
+
const coverageDecisionByIndex = /* @__PURE__ */ new Map();
|
|
10050
|
+
for (const decision of cleanup.coverageDecisions) {
|
|
10051
|
+
if (decision.coverageIndex < profile.coverages.length) coverageDecisionByIndex.set(decision.coverageIndex, decision);
|
|
10052
|
+
}
|
|
10053
|
+
const coverages = profile.coverages.map(
|
|
10054
|
+
(coverage, index) => applyCoverageCleanupDecision(coverage, coverageDecisionByIndex.get(index), validNodeIds, validSpanIds)
|
|
10055
|
+
).filter((coverage) => Boolean(coverage));
|
|
10056
|
+
const cleanupWarnings = cleanup.warnings.map((warning) => cleanProfileValue(warning)).filter((warning) => Boolean(warning));
|
|
10057
|
+
const nextProfile = {
|
|
10058
|
+
...profile,
|
|
10059
|
+
coverages,
|
|
10060
|
+
coverageTypes: uniqueStrings(coverages.map((coverage) => coverage.name)),
|
|
10061
|
+
warnings: uniqueStrings([
|
|
10062
|
+
...profile.warnings,
|
|
10063
|
+
...cleanupWarnings.map((warning) => `Operational profile cleanup warning: ${warning}`)
|
|
10064
|
+
])
|
|
10065
|
+
};
|
|
10066
|
+
return PolicyOperationalProfileSchema.parse({
|
|
10067
|
+
...nextProfile,
|
|
10068
|
+
...sourceIdsFromOperationalProfile(nextProfile)
|
|
10069
|
+
});
|
|
10070
|
+
}
|
|
10071
|
+
|
|
10072
|
+
// src/extraction/source-tree-extractor.ts
|
|
9698
10073
|
var ORGANIZABLE_KINDS = [
|
|
9699
10074
|
"page_group",
|
|
9700
10075
|
"form",
|
|
@@ -9707,10 +10082,10 @@ var ORGANIZATION_TOP_LEVEL_BATCH_SIZE = 80;
|
|
|
9707
10082
|
var ORGANIZER_MAX_SOURCE_SPANS = 400;
|
|
9708
10083
|
var ORGANIZER_MAX_TOP_LEVEL_NODES = 18;
|
|
9709
10084
|
var OUTLINE_CLEANUP_MAX_TOP_LEVEL_NODES = 80;
|
|
9710
|
-
var SourceTreeOrganizationSchema =
|
|
9711
|
-
labels:
|
|
9712
|
-
nodeId:
|
|
9713
|
-
kind:
|
|
10085
|
+
var SourceTreeOrganizationSchema = z42.object({
|
|
10086
|
+
labels: z42.array(z42.object({
|
|
10087
|
+
nodeId: z42.string(),
|
|
10088
|
+
kind: z42.enum([
|
|
9714
10089
|
"document",
|
|
9715
10090
|
"page_group",
|
|
9716
10091
|
"page",
|
|
@@ -9724,26 +10099,26 @@ var SourceTreeOrganizationSchema = z41.object({
|
|
|
9724
10099
|
"table_cell",
|
|
9725
10100
|
"text"
|
|
9726
10101
|
]).optional(),
|
|
9727
|
-
title:
|
|
9728
|
-
description:
|
|
10102
|
+
title: z42.string().optional(),
|
|
10103
|
+
description: z42.string().optional()
|
|
9729
10104
|
})),
|
|
9730
|
-
groups:
|
|
9731
|
-
kind:
|
|
9732
|
-
title:
|
|
9733
|
-
description:
|
|
9734
|
-
childNodeIds:
|
|
10105
|
+
groups: z42.array(z42.object({
|
|
10106
|
+
kind: z42.enum(ORGANIZABLE_KINDS),
|
|
10107
|
+
title: z42.string(),
|
|
10108
|
+
description: z42.string().optional(),
|
|
10109
|
+
childNodeIds: z42.array(z42.string()).min(1)
|
|
9735
10110
|
}))
|
|
9736
10111
|
});
|
|
9737
|
-
var SourceBackedValueForPromptSchema =
|
|
9738
|
-
value:
|
|
9739
|
-
normalizedValue:
|
|
9740
|
-
confidence:
|
|
9741
|
-
sourceNodeIds:
|
|
9742
|
-
sourceSpanIds:
|
|
10112
|
+
var SourceBackedValueForPromptSchema = z42.object({
|
|
10113
|
+
value: z42.string(),
|
|
10114
|
+
normalizedValue: z42.string().optional(),
|
|
10115
|
+
confidence: z42.enum(["low", "medium", "high"]).optional(),
|
|
10116
|
+
sourceNodeIds: z42.array(z42.string()),
|
|
10117
|
+
sourceSpanIds: z42.array(z42.string())
|
|
9743
10118
|
});
|
|
9744
|
-
var OperationalProfilePromptSchema =
|
|
9745
|
-
documentType:
|
|
9746
|
-
policyTypes:
|
|
10119
|
+
var OperationalProfilePromptSchema = z42.object({
|
|
10120
|
+
documentType: z42.enum(["policy", "quote"]).optional(),
|
|
10121
|
+
policyTypes: z42.array(z42.string()).optional(),
|
|
9747
10122
|
policyNumber: SourceBackedValueForPromptSchema.optional(),
|
|
9748
10123
|
namedInsured: SourceBackedValueForPromptSchema.optional(),
|
|
9749
10124
|
insurer: SourceBackedValueForPromptSchema.optional(),
|
|
@@ -9752,43 +10127,32 @@ var OperationalProfilePromptSchema = z41.object({
|
|
|
9752
10127
|
expirationDate: SourceBackedValueForPromptSchema.optional(),
|
|
9753
10128
|
retroactiveDate: SourceBackedValueForPromptSchema.optional(),
|
|
9754
10129
|
premium: SourceBackedValueForPromptSchema.optional(),
|
|
9755
|
-
coverageTypes:
|
|
9756
|
-
coverages:
|
|
9757
|
-
name:
|
|
9758
|
-
coverageCode:
|
|
9759
|
-
limit:
|
|
9760
|
-
deductible:
|
|
9761
|
-
premium:
|
|
9762
|
-
retroactiveDate:
|
|
9763
|
-
formNumber:
|
|
9764
|
-
sectionRef:
|
|
9765
|
-
coverageOrigin:
|
|
9766
|
-
endorsementNumber:
|
|
9767
|
-
limits:
|
|
9768
|
-
kind:
|
|
9769
|
-
|
|
9770
|
-
|
|
9771
|
-
|
|
9772
|
-
|
|
9773
|
-
|
|
9774
|
-
|
|
9775
|
-
"deductible",
|
|
9776
|
-
"retroactive_date",
|
|
9777
|
-
"premium",
|
|
9778
|
-
"other"
|
|
9779
|
-
]).optional(),
|
|
9780
|
-
label: z41.string(),
|
|
9781
|
-
value: z41.string(),
|
|
9782
|
-
amount: z41.number().optional(),
|
|
9783
|
-
appliesTo: z41.string().optional(),
|
|
9784
|
-
sourceNodeIds: z41.array(z41.string()),
|
|
9785
|
-
sourceSpanIds: z41.array(z41.string())
|
|
10130
|
+
coverageTypes: z42.array(z42.string()).optional(),
|
|
10131
|
+
coverages: z42.array(z42.object({
|
|
10132
|
+
name: z42.string(),
|
|
10133
|
+
coverageCode: z42.string().optional(),
|
|
10134
|
+
limit: z42.string().optional(),
|
|
10135
|
+
deductible: z42.string().optional(),
|
|
10136
|
+
premium: z42.string().optional(),
|
|
10137
|
+
retroactiveDate: z42.string().optional(),
|
|
10138
|
+
formNumber: z42.string().optional(),
|
|
10139
|
+
sectionRef: z42.string().optional(),
|
|
10140
|
+
coverageOrigin: z42.enum(["core", "endorsement"]).optional(),
|
|
10141
|
+
endorsementNumber: z42.string().optional(),
|
|
10142
|
+
limits: z42.array(z42.object({
|
|
10143
|
+
kind: OperationalCoverageTermKindSchema.optional(),
|
|
10144
|
+
label: z42.string(),
|
|
10145
|
+
value: z42.string(),
|
|
10146
|
+
amount: z42.number().optional(),
|
|
10147
|
+
appliesTo: z42.string().optional(),
|
|
10148
|
+
sourceNodeIds: z42.array(z42.string()),
|
|
10149
|
+
sourceSpanIds: z42.array(z42.string())
|
|
9786
10150
|
})).optional(),
|
|
9787
|
-
sourceNodeIds:
|
|
9788
|
-
sourceSpanIds:
|
|
10151
|
+
sourceNodeIds: z42.array(z42.string()),
|
|
10152
|
+
sourceSpanIds: z42.array(z42.string())
|
|
9789
10153
|
})).optional(),
|
|
9790
|
-
sourceNodeIds:
|
|
9791
|
-
sourceSpanIds:
|
|
10154
|
+
sourceNodeIds: z42.array(z42.string()).optional(),
|
|
10155
|
+
sourceSpanIds: z42.array(z42.string()).optional()
|
|
9792
10156
|
});
|
|
9793
10157
|
function formatFormHintsForPrompt(forms) {
|
|
9794
10158
|
const usable = forms.filter((form) => typeof form.pageStart === "number" && typeof form.pageEnd === "number").slice(0, 120).map((form) => ({
|
|
@@ -10780,7 +11144,7 @@ function applyEndorsementGrouping(sourceTree) {
|
|
|
10780
11144
|
}
|
|
10781
11145
|
return normalizeSemanticHierarchy(nextTree);
|
|
10782
11146
|
}
|
|
10783
|
-
function
|
|
11147
|
+
function compactNode2(node, maxText = 700) {
|
|
10784
11148
|
return {
|
|
10785
11149
|
id: node.id,
|
|
10786
11150
|
kind: node.kind,
|
|
@@ -10870,7 +11234,7 @@ function mergeOrganizationResults(results) {
|
|
|
10870
11234
|
};
|
|
10871
11235
|
}
|
|
10872
11236
|
function buildOrganizationPrompt(batch, formHints) {
|
|
10873
|
-
const nodes = batch.nodes.map((node) =>
|
|
11237
|
+
const nodes = batch.nodes.map((node) => compactNode2(node, node.kind === "page" ? 900 : 320));
|
|
10874
11238
|
return `You organize an insurance document source tree.
|
|
10875
11239
|
|
|
10876
11240
|
Scope:
|
|
@@ -10912,7 +11276,7 @@ function shouldRunOutlineCleanup(sourceTree) {
|
|
|
10912
11276
|
}
|
|
10913
11277
|
function buildOutlineCleanupPrompt(sourceTree, formHints) {
|
|
10914
11278
|
const topLevel = rootChildren(sourceTree).slice(0, OUTLINE_CLEANUP_MAX_TOP_LEVEL_NODES);
|
|
10915
|
-
const nodes = topLevel.map((node) =>
|
|
11279
|
+
const nodes = topLevel.map((node) => compactNode2(node, 900));
|
|
10916
11280
|
return `You clean a top-level source outline for an insurance policy.
|
|
10917
11281
|
|
|
10918
11282
|
Expected product-facing order:
|
|
@@ -10941,7 +11305,7 @@ ${JSON.stringify(nodes, null, 2)}
|
|
|
10941
11305
|
Return JSON with labels and groups only.`;
|
|
10942
11306
|
}
|
|
10943
11307
|
function buildOperationalProfilePrompt(sourceTree, fallback) {
|
|
10944
|
-
const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 240).map(
|
|
11308
|
+
const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 240).map(compactNode2);
|
|
10945
11309
|
return `Extract a source-backed operational profile for an insurance policy or quote.
|
|
10946
11310
|
|
|
10947
11311
|
Return only high-value operational facts needed for policy lists, Q&A, compliance, and certificate generation:
|
|
@@ -11305,6 +11669,45 @@ async function runSourceTreeExtraction(params) {
|
|
|
11305
11669
|
} catch (error) {
|
|
11306
11670
|
warnings.push(`Operational profile model pass failed; deterministic profile used (${error instanceof Error ? error.message : String(error)})`);
|
|
11307
11671
|
}
|
|
11672
|
+
if (operationalProfile.coverages.length > 0) {
|
|
11673
|
+
try {
|
|
11674
|
+
const validNodeIds = new Set(sourceTree.map((node) => node.id));
|
|
11675
|
+
const validSpanIds = new Set(sourceSpans.map((span) => span.id));
|
|
11676
|
+
const budget = params.resolveBudget("extraction_operational_profile", 4096);
|
|
11677
|
+
const startedAt = Date.now();
|
|
11678
|
+
const response = await safeGenerateObject(
|
|
11679
|
+
params.generateObject,
|
|
11680
|
+
{
|
|
11681
|
+
prompt: buildOperationalProfileCleanupPrompt(sourceTree, operationalProfile),
|
|
11682
|
+
schema: OperationalProfileCleanupSchema,
|
|
11683
|
+
maxTokens: budget.maxTokens,
|
|
11684
|
+
taskKind: "extraction_operational_profile",
|
|
11685
|
+
budgetDiagnostics: budget,
|
|
11686
|
+
providerOptions: params.providerOptions
|
|
11687
|
+
},
|
|
11688
|
+
{
|
|
11689
|
+
fallback: { coverageDecisions: [], warnings: [] },
|
|
11690
|
+
log: params.log
|
|
11691
|
+
}
|
|
11692
|
+
);
|
|
11693
|
+
localTrack(response.usage, {
|
|
11694
|
+
taskKind: "extraction_operational_profile",
|
|
11695
|
+
label: "operational_profile_cleanup",
|
|
11696
|
+
maxTokens: budget.maxTokens,
|
|
11697
|
+
durationMs: Date.now() - startedAt
|
|
11698
|
+
});
|
|
11699
|
+
operationalProfile = applyOperationalProfileCleanup(
|
|
11700
|
+
operationalProfile,
|
|
11701
|
+
response.object,
|
|
11702
|
+
validNodeIds,
|
|
11703
|
+
validSpanIds
|
|
11704
|
+
);
|
|
11705
|
+
} catch (error) {
|
|
11706
|
+
warnings.push(`Operational profile cleanup pass failed; uncleaned profile used (${error instanceof Error ? error.message : String(error)})`);
|
|
11707
|
+
}
|
|
11708
|
+
} else {
|
|
11709
|
+
await params.log?.("Operational profile has no coverage rows; skipped model cleanup");
|
|
11710
|
+
}
|
|
11308
11711
|
const document = materializeDocument({
|
|
11309
11712
|
id: params.id,
|
|
11310
11713
|
sourceTree,
|
|
@@ -12631,8 +13034,8 @@ Respond with JSON only:
|
|
|
12631
13034
|
}`;
|
|
12632
13035
|
|
|
12633
13036
|
// src/schemas/application.ts
|
|
12634
|
-
import { z as
|
|
12635
|
-
var FieldTypeSchema =
|
|
13037
|
+
import { z as z43 } from "zod";
|
|
13038
|
+
var FieldTypeSchema = z43.enum([
|
|
12636
13039
|
"text",
|
|
12637
13040
|
"numeric",
|
|
12638
13041
|
"currency",
|
|
@@ -12641,223 +13044,223 @@ var FieldTypeSchema = z42.enum([
|
|
|
12641
13044
|
"table",
|
|
12642
13045
|
"declaration"
|
|
12643
13046
|
]);
|
|
12644
|
-
var ApplicationFieldSchema =
|
|
12645
|
-
id:
|
|
12646
|
-
label:
|
|
12647
|
-
section:
|
|
13047
|
+
var ApplicationFieldSchema = z43.object({
|
|
13048
|
+
id: z43.string(),
|
|
13049
|
+
label: z43.string(),
|
|
13050
|
+
section: z43.string(),
|
|
12648
13051
|
fieldType: FieldTypeSchema,
|
|
12649
|
-
required:
|
|
12650
|
-
options:
|
|
12651
|
-
columns:
|
|
12652
|
-
requiresExplanationIfYes:
|
|
12653
|
-
condition:
|
|
12654
|
-
dependsOn:
|
|
12655
|
-
whenValue:
|
|
13052
|
+
required: z43.boolean(),
|
|
13053
|
+
options: z43.array(z43.string()).optional(),
|
|
13054
|
+
columns: z43.array(z43.string()).optional(),
|
|
13055
|
+
requiresExplanationIfYes: z43.boolean().optional(),
|
|
13056
|
+
condition: z43.object({
|
|
13057
|
+
dependsOn: z43.string(),
|
|
13058
|
+
whenValue: z43.string()
|
|
12656
13059
|
}).optional(),
|
|
12657
|
-
value:
|
|
12658
|
-
source:
|
|
12659
|
-
confidence:
|
|
12660
|
-
sourceSpanIds:
|
|
12661
|
-
userSourceSpanIds:
|
|
12662
|
-
pageNumber:
|
|
12663
|
-
fieldAnchorId:
|
|
12664
|
-
acroFormName:
|
|
12665
|
-
validationStatus:
|
|
13060
|
+
value: z43.string().optional(),
|
|
13061
|
+
source: z43.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
|
|
13062
|
+
confidence: z43.enum(["confirmed", "high", "medium", "low"]).optional(),
|
|
13063
|
+
sourceSpanIds: z43.array(z43.string()).optional().describe("Stable source spans that support the field value or field anchor"),
|
|
13064
|
+
userSourceSpanIds: z43.array(z43.string()).optional().describe("Message or attachment spans that support user-provided values"),
|
|
13065
|
+
pageNumber: z43.number().int().positive().optional().describe("Application page where the field label or anchor appears"),
|
|
13066
|
+
fieldAnchorId: z43.string().optional().describe("Stable field anchor ID derived from page, section, label, and form metadata"),
|
|
13067
|
+
acroFormName: z43.string().optional().describe("Native PDF AcroForm field name when available"),
|
|
13068
|
+
validationStatus: z43.enum(["valid", "needs_review", "unsupported", "missing"]).optional()
|
|
12666
13069
|
});
|
|
12667
|
-
var ApplicationQuestionConditionSchema =
|
|
12668
|
-
dependsOn:
|
|
12669
|
-
operator:
|
|
12670
|
-
value:
|
|
12671
|
-
whenValue:
|
|
12672
|
-
values:
|
|
13070
|
+
var ApplicationQuestionConditionSchema = z43.object({
|
|
13071
|
+
dependsOn: z43.string(),
|
|
13072
|
+
operator: z43.enum(["equals", "not_equals", "in", "not_in", "exists"]).optional(),
|
|
13073
|
+
value: z43.string().optional(),
|
|
13074
|
+
whenValue: z43.string().optional(),
|
|
13075
|
+
values: z43.array(z43.string()).optional()
|
|
12673
13076
|
});
|
|
12674
|
-
var ApplicationRepeatSchema =
|
|
12675
|
-
min:
|
|
12676
|
-
max:
|
|
12677
|
-
label:
|
|
13077
|
+
var ApplicationRepeatSchema = z43.object({
|
|
13078
|
+
min: z43.number().int().nonnegative().optional(),
|
|
13079
|
+
max: z43.number().int().positive().optional(),
|
|
13080
|
+
label: z43.string().optional()
|
|
12678
13081
|
});
|
|
12679
|
-
var ApplicationQuestionNodeSchema =
|
|
12680
|
-
() =>
|
|
12681
|
-
id:
|
|
12682
|
-
nodeType:
|
|
12683
|
-
fieldId:
|
|
12684
|
-
fieldPath:
|
|
12685
|
-
parentId:
|
|
12686
|
-
order:
|
|
12687
|
-
label:
|
|
12688
|
-
section:
|
|
13082
|
+
var ApplicationQuestionNodeSchema = z43.lazy(
|
|
13083
|
+
() => z43.object({
|
|
13084
|
+
id: z43.string(),
|
|
13085
|
+
nodeType: z43.enum(["group", "question", "repeat_group", "table"]),
|
|
13086
|
+
fieldId: z43.string().optional(),
|
|
13087
|
+
fieldPath: z43.string().optional(),
|
|
13088
|
+
parentId: z43.string().optional(),
|
|
13089
|
+
order: z43.number().int().nonnegative().optional(),
|
|
13090
|
+
label: z43.string(),
|
|
13091
|
+
section: z43.string().optional(),
|
|
12689
13092
|
fieldType: FieldTypeSchema.optional(),
|
|
12690
|
-
required:
|
|
12691
|
-
prompt:
|
|
12692
|
-
options:
|
|
12693
|
-
columns:
|
|
13093
|
+
required: z43.boolean().optional(),
|
|
13094
|
+
prompt: z43.string().optional(),
|
|
13095
|
+
options: z43.array(z43.string()).optional(),
|
|
13096
|
+
columns: z43.array(z43.string()).optional(),
|
|
12694
13097
|
condition: ApplicationQuestionConditionSchema.optional(),
|
|
12695
13098
|
repeat: ApplicationRepeatSchema.optional(),
|
|
12696
|
-
children:
|
|
13099
|
+
children: z43.array(ApplicationQuestionNodeSchema).optional()
|
|
12697
13100
|
})
|
|
12698
13101
|
);
|
|
12699
|
-
var ApplicationQuestionGraphSchema =
|
|
12700
|
-
id:
|
|
12701
|
-
version:
|
|
12702
|
-
title:
|
|
12703
|
-
applicationType:
|
|
12704
|
-
source:
|
|
12705
|
-
rootNodeIds:
|
|
12706
|
-
nodes:
|
|
13102
|
+
var ApplicationQuestionGraphSchema = z43.object({
|
|
13103
|
+
id: z43.string(),
|
|
13104
|
+
version: z43.string(),
|
|
13105
|
+
title: z43.string().optional(),
|
|
13106
|
+
applicationType: z43.string().nullable().optional(),
|
|
13107
|
+
source: z43.enum(["pdf", "manual", "imported", "generated"]).default("generated"),
|
|
13108
|
+
rootNodeIds: z43.array(z43.string()).optional(),
|
|
13109
|
+
nodes: z43.array(ApplicationQuestionNodeSchema)
|
|
12707
13110
|
});
|
|
12708
|
-
var ApplicationTemplateSchema =
|
|
12709
|
-
id:
|
|
12710
|
-
version:
|
|
12711
|
-
title:
|
|
12712
|
-
applicationType:
|
|
13111
|
+
var ApplicationTemplateSchema = z43.object({
|
|
13112
|
+
id: z43.string(),
|
|
13113
|
+
version: z43.string(),
|
|
13114
|
+
title: z43.string(),
|
|
13115
|
+
applicationType: z43.string().nullable().optional(),
|
|
12713
13116
|
questionGraph: ApplicationQuestionGraphSchema,
|
|
12714
|
-
fields:
|
|
13117
|
+
fields: z43.array(ApplicationFieldSchema).optional()
|
|
12715
13118
|
});
|
|
12716
|
-
var ApplicationClassifyResultSchema =
|
|
12717
|
-
isApplication:
|
|
12718
|
-
confidence:
|
|
12719
|
-
applicationType:
|
|
13119
|
+
var ApplicationClassifyResultSchema = z43.object({
|
|
13120
|
+
isApplication: z43.boolean(),
|
|
13121
|
+
confidence: z43.number().min(0).max(1),
|
|
13122
|
+
applicationType: z43.string().nullable()
|
|
12720
13123
|
});
|
|
12721
|
-
var FieldExtractionResultSchema =
|
|
12722
|
-
fields:
|
|
13124
|
+
var FieldExtractionResultSchema = z43.object({
|
|
13125
|
+
fields: z43.array(ApplicationFieldSchema)
|
|
12723
13126
|
});
|
|
12724
|
-
var AutoFillMatchSchema =
|
|
12725
|
-
fieldId:
|
|
12726
|
-
value:
|
|
12727
|
-
confidence:
|
|
12728
|
-
contextKey:
|
|
13127
|
+
var AutoFillMatchSchema = z43.object({
|
|
13128
|
+
fieldId: z43.string(),
|
|
13129
|
+
value: z43.string(),
|
|
13130
|
+
confidence: z43.enum(["confirmed"]),
|
|
13131
|
+
contextKey: z43.string()
|
|
12729
13132
|
});
|
|
12730
|
-
var AutoFillResultSchema =
|
|
12731
|
-
matches:
|
|
13133
|
+
var AutoFillResultSchema = z43.object({
|
|
13134
|
+
matches: z43.array(AutoFillMatchSchema)
|
|
12732
13135
|
});
|
|
12733
|
-
var QuestionBatchResultSchema =
|
|
12734
|
-
batches:
|
|
13136
|
+
var QuestionBatchResultSchema = z43.object({
|
|
13137
|
+
batches: z43.array(z43.array(z43.string()).describe("Array of field IDs in this batch"))
|
|
12735
13138
|
});
|
|
12736
|
-
var LookupRequestSchema =
|
|
12737
|
-
type:
|
|
12738
|
-
description:
|
|
12739
|
-
url:
|
|
12740
|
-
targetFieldIds:
|
|
13139
|
+
var LookupRequestSchema = z43.object({
|
|
13140
|
+
type: z43.string().describe("Type of lookup: 'records', 'website', 'policy'"),
|
|
13141
|
+
description: z43.string(),
|
|
13142
|
+
url: z43.string().optional(),
|
|
13143
|
+
targetFieldIds: z43.array(z43.string())
|
|
12741
13144
|
});
|
|
12742
|
-
var ReplyIntentSchema =
|
|
12743
|
-
primaryIntent:
|
|
12744
|
-
hasAnswers:
|
|
12745
|
-
questionText:
|
|
12746
|
-
questionFieldIds:
|
|
12747
|
-
lookupRequests:
|
|
13145
|
+
var ReplyIntentSchema = z43.object({
|
|
13146
|
+
primaryIntent: z43.enum(["answers_only", "question", "lookup_request", "mixed"]),
|
|
13147
|
+
hasAnswers: z43.boolean(),
|
|
13148
|
+
questionText: z43.string().optional(),
|
|
13149
|
+
questionFieldIds: z43.array(z43.string()).optional(),
|
|
13150
|
+
lookupRequests: z43.array(LookupRequestSchema).optional()
|
|
12748
13151
|
});
|
|
12749
|
-
var ParsedAnswerSchema =
|
|
12750
|
-
fieldId:
|
|
12751
|
-
value:
|
|
12752
|
-
explanation:
|
|
13152
|
+
var ParsedAnswerSchema = z43.object({
|
|
13153
|
+
fieldId: z43.string(),
|
|
13154
|
+
value: z43.string(),
|
|
13155
|
+
explanation: z43.string().optional()
|
|
12753
13156
|
});
|
|
12754
|
-
var AnswerParsingResultSchema =
|
|
12755
|
-
answers:
|
|
12756
|
-
unanswered:
|
|
13157
|
+
var AnswerParsingResultSchema = z43.object({
|
|
13158
|
+
answers: z43.array(ParsedAnswerSchema),
|
|
13159
|
+
unanswered: z43.array(z43.string()).describe("Field IDs that were not answered")
|
|
12757
13160
|
});
|
|
12758
|
-
var LookupFillSchema =
|
|
12759
|
-
fieldId:
|
|
12760
|
-
value:
|
|
12761
|
-
source:
|
|
12762
|
-
sourceSpanIds:
|
|
13161
|
+
var LookupFillSchema = z43.object({
|
|
13162
|
+
fieldId: z43.string(),
|
|
13163
|
+
value: z43.string(),
|
|
13164
|
+
source: z43.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'"),
|
|
13165
|
+
sourceSpanIds: z43.array(z43.string()).optional()
|
|
12763
13166
|
});
|
|
12764
|
-
var LookupFillResultSchema =
|
|
12765
|
-
fills:
|
|
12766
|
-
unfillable:
|
|
12767
|
-
explanation:
|
|
13167
|
+
var LookupFillResultSchema = z43.object({
|
|
13168
|
+
fills: z43.array(LookupFillSchema),
|
|
13169
|
+
unfillable: z43.array(z43.string()),
|
|
13170
|
+
explanation: z43.string().optional()
|
|
12768
13171
|
});
|
|
12769
|
-
var FlatPdfPlacementSchema =
|
|
12770
|
-
fieldId:
|
|
12771
|
-
page:
|
|
12772
|
-
x:
|
|
12773
|
-
y:
|
|
12774
|
-
text:
|
|
12775
|
-
fontSize:
|
|
12776
|
-
isCheckmark:
|
|
13172
|
+
var FlatPdfPlacementSchema = z43.object({
|
|
13173
|
+
fieldId: z43.string(),
|
|
13174
|
+
page: z43.number(),
|
|
13175
|
+
x: z43.number().describe("Percentage from left edge (0-100)"),
|
|
13176
|
+
y: z43.number().describe("Percentage from top edge (0-100)"),
|
|
13177
|
+
text: z43.string(),
|
|
13178
|
+
fontSize: z43.number().optional(),
|
|
13179
|
+
isCheckmark: z43.boolean().optional()
|
|
12777
13180
|
});
|
|
12778
|
-
var AcroFormMappingSchema =
|
|
12779
|
-
fieldId:
|
|
12780
|
-
acroFormName:
|
|
12781
|
-
value:
|
|
13181
|
+
var AcroFormMappingSchema = z43.object({
|
|
13182
|
+
fieldId: z43.string(),
|
|
13183
|
+
acroFormName: z43.string(),
|
|
13184
|
+
value: z43.string()
|
|
12782
13185
|
});
|
|
12783
|
-
var QualityGateStatusSchema =
|
|
12784
|
-
var QualitySeveritySchema =
|
|
12785
|
-
var ApplicationQualityIssueSchema =
|
|
12786
|
-
code:
|
|
13186
|
+
var QualityGateStatusSchema = z43.enum(["passed", "warning", "failed"]);
|
|
13187
|
+
var QualitySeveritySchema = z43.enum(["info", "warning", "blocking"]);
|
|
13188
|
+
var ApplicationQualityIssueSchema = z43.object({
|
|
13189
|
+
code: z43.string(),
|
|
12787
13190
|
severity: QualitySeveritySchema,
|
|
12788
|
-
message:
|
|
12789
|
-
fieldId:
|
|
13191
|
+
message: z43.string(),
|
|
13192
|
+
fieldId: z43.string().optional()
|
|
12790
13193
|
});
|
|
12791
|
-
var ApplicationQualityRoundSchema =
|
|
12792
|
-
round:
|
|
12793
|
-
kind:
|
|
13194
|
+
var ApplicationQualityRoundSchema = z43.object({
|
|
13195
|
+
round: z43.number(),
|
|
13196
|
+
kind: z43.string(),
|
|
12794
13197
|
status: QualityGateStatusSchema,
|
|
12795
|
-
summary:
|
|
13198
|
+
summary: z43.string().optional()
|
|
12796
13199
|
});
|
|
12797
|
-
var ApplicationQualityArtifactSchema =
|
|
12798
|
-
kind:
|
|
12799
|
-
label:
|
|
12800
|
-
itemCount:
|
|
13200
|
+
var ApplicationQualityArtifactSchema = z43.object({
|
|
13201
|
+
kind: z43.string(),
|
|
13202
|
+
label: z43.string().optional(),
|
|
13203
|
+
itemCount: z43.number().optional()
|
|
12801
13204
|
});
|
|
12802
|
-
var ApplicationEmailReviewSchema =
|
|
12803
|
-
issues:
|
|
13205
|
+
var ApplicationEmailReviewSchema = z43.object({
|
|
13206
|
+
issues: z43.array(ApplicationQualityIssueSchema),
|
|
12804
13207
|
qualityGateStatus: QualityGateStatusSchema
|
|
12805
13208
|
});
|
|
12806
|
-
var ApplicationQualityReportSchema =
|
|
12807
|
-
issues:
|
|
12808
|
-
rounds:
|
|
12809
|
-
artifacts:
|
|
13209
|
+
var ApplicationQualityReportSchema = z43.object({
|
|
13210
|
+
issues: z43.array(ApplicationQualityIssueSchema),
|
|
13211
|
+
rounds: z43.array(ApplicationQualityRoundSchema).optional(),
|
|
13212
|
+
artifacts: z43.array(ApplicationQualityArtifactSchema).optional(),
|
|
12810
13213
|
emailReview: ApplicationEmailReviewSchema.optional(),
|
|
12811
13214
|
qualityGateStatus: QualityGateStatusSchema
|
|
12812
13215
|
});
|
|
12813
|
-
var ApplicationContextProposalSchema =
|
|
12814
|
-
id:
|
|
12815
|
-
fieldId:
|
|
12816
|
-
key:
|
|
12817
|
-
value:
|
|
12818
|
-
category:
|
|
12819
|
-
source:
|
|
12820
|
-
confidence:
|
|
12821
|
-
sourceSpanIds:
|
|
12822
|
-
userSourceSpanIds:
|
|
13216
|
+
var ApplicationContextProposalSchema = z43.object({
|
|
13217
|
+
id: z43.string(),
|
|
13218
|
+
fieldId: z43.string().optional(),
|
|
13219
|
+
key: z43.string(),
|
|
13220
|
+
value: z43.string(),
|
|
13221
|
+
category: z43.string(),
|
|
13222
|
+
source: z43.enum(["application", "user", "lookup", "policy", "email", "chat", "imessage", "mcp"]),
|
|
13223
|
+
confidence: z43.enum(["confirmed", "high", "medium", "low"]),
|
|
13224
|
+
sourceSpanIds: z43.array(z43.string()).optional(),
|
|
13225
|
+
userSourceSpanIds: z43.array(z43.string()).optional()
|
|
12823
13226
|
});
|
|
12824
|
-
var ApplicationPacketAnswerSchema =
|
|
12825
|
-
fieldId:
|
|
12826
|
-
label:
|
|
12827
|
-
section:
|
|
12828
|
-
value:
|
|
12829
|
-
source:
|
|
12830
|
-
confidence:
|
|
12831
|
-
sourceSpanIds:
|
|
12832
|
-
userSourceSpanIds:
|
|
13227
|
+
var ApplicationPacketAnswerSchema = z43.object({
|
|
13228
|
+
fieldId: z43.string(),
|
|
13229
|
+
label: z43.string(),
|
|
13230
|
+
section: z43.string(),
|
|
13231
|
+
value: z43.string(),
|
|
13232
|
+
source: z43.string(),
|
|
13233
|
+
confidence: z43.enum(["confirmed", "high", "medium", "low"]).optional(),
|
|
13234
|
+
sourceSpanIds: z43.array(z43.string()).optional(),
|
|
13235
|
+
userSourceSpanIds: z43.array(z43.string()).optional()
|
|
12833
13236
|
});
|
|
12834
|
-
var ApplicationPacketSchema =
|
|
12835
|
-
id:
|
|
12836
|
-
applicationId:
|
|
12837
|
-
title:
|
|
12838
|
-
status:
|
|
12839
|
-
answers:
|
|
12840
|
-
missingFieldIds:
|
|
13237
|
+
var ApplicationPacketSchema = z43.object({
|
|
13238
|
+
id: z43.string(),
|
|
13239
|
+
applicationId: z43.string(),
|
|
13240
|
+
title: z43.string(),
|
|
13241
|
+
status: z43.enum(["draft", "broker_ready", "submitted"]),
|
|
13242
|
+
answers: z43.array(ApplicationPacketAnswerSchema),
|
|
13243
|
+
missingFieldIds: z43.array(z43.string()),
|
|
12841
13244
|
qualityReport: ApplicationQualityReportSchema,
|
|
12842
|
-
submissionNotes:
|
|
12843
|
-
createdAt:
|
|
13245
|
+
submissionNotes: z43.string().optional(),
|
|
13246
|
+
createdAt: z43.number()
|
|
12844
13247
|
});
|
|
12845
|
-
var ApplicationStateSchema =
|
|
12846
|
-
id:
|
|
12847
|
-
pdfBase64:
|
|
12848
|
-
templateId:
|
|
12849
|
-
templateVersion:
|
|
13248
|
+
var ApplicationStateSchema = z43.object({
|
|
13249
|
+
id: z43.string(),
|
|
13250
|
+
pdfBase64: z43.string().optional().describe("Original PDF, omitted after extraction"),
|
|
13251
|
+
templateId: z43.string().optional(),
|
|
13252
|
+
templateVersion: z43.string().optional(),
|
|
12850
13253
|
templateSnapshot: ApplicationTemplateSchema.optional(),
|
|
12851
|
-
title:
|
|
12852
|
-
applicationType:
|
|
13254
|
+
title: z43.string().optional(),
|
|
13255
|
+
applicationType: z43.string().nullable().optional(),
|
|
12853
13256
|
questionGraph: ApplicationQuestionGraphSchema.optional(),
|
|
12854
|
-
fields:
|
|
12855
|
-
batches:
|
|
12856
|
-
currentBatchIndex:
|
|
12857
|
-
contextProposals:
|
|
13257
|
+
fields: z43.array(ApplicationFieldSchema),
|
|
13258
|
+
batches: z43.array(z43.array(z43.string())).optional(),
|
|
13259
|
+
currentBatchIndex: z43.number().default(0),
|
|
13260
|
+
contextProposals: z43.array(ApplicationContextProposalSchema).optional(),
|
|
12858
13261
|
packet: ApplicationPacketSchema.optional(),
|
|
12859
13262
|
qualityReport: ApplicationQualityReportSchema.optional(),
|
|
12860
|
-
status:
|
|
13263
|
+
status: z43.enum([
|
|
12861
13264
|
"classifying",
|
|
12862
13265
|
"extracting",
|
|
12863
13266
|
"auto_filling",
|
|
@@ -12871,8 +13274,8 @@ var ApplicationStateSchema = z42.object({
|
|
|
12871
13274
|
"cancelled",
|
|
12872
13275
|
"complete"
|
|
12873
13276
|
]),
|
|
12874
|
-
createdAt:
|
|
12875
|
-
updatedAt:
|
|
13277
|
+
createdAt: z43.number(),
|
|
13278
|
+
updatedAt: z43.number()
|
|
12876
13279
|
});
|
|
12877
13280
|
|
|
12878
13281
|
// src/application/agents/classifier.ts
|
|
@@ -14606,106 +15009,106 @@ Respond with the final answer, deduplicated citations array, overall confidence
|
|
|
14606
15009
|
}
|
|
14607
15010
|
|
|
14608
15011
|
// src/schemas/query.ts
|
|
14609
|
-
import { z as
|
|
14610
|
-
var QueryIntentSchema =
|
|
15012
|
+
import { z as z44 } from "zod";
|
|
15013
|
+
var QueryIntentSchema = z44.enum([
|
|
14611
15014
|
"policy_question",
|
|
14612
15015
|
"coverage_comparison",
|
|
14613
15016
|
"document_search",
|
|
14614
15017
|
"claims_inquiry",
|
|
14615
15018
|
"general_knowledge"
|
|
14616
15019
|
]);
|
|
14617
|
-
var QueryAttachmentKindSchema =
|
|
14618
|
-
var QueryAttachmentSchema =
|
|
14619
|
-
id:
|
|
15020
|
+
var QueryAttachmentKindSchema = z44.enum(["image", "pdf", "text"]);
|
|
15021
|
+
var QueryAttachmentSchema = z44.object({
|
|
15022
|
+
id: z44.string().optional().describe("Optional stable attachment ID from the caller"),
|
|
14620
15023
|
kind: QueryAttachmentKindSchema,
|
|
14621
|
-
name:
|
|
14622
|
-
mimeType:
|
|
14623
|
-
base64:
|
|
14624
|
-
text:
|
|
14625
|
-
description:
|
|
15024
|
+
name: z44.string().optional().describe("Original filename or user-facing label"),
|
|
15025
|
+
mimeType: z44.string().optional().describe("MIME type such as image/jpeg or application/pdf"),
|
|
15026
|
+
base64: z44.string().optional().describe("Base64-encoded file content for image/pdf attachments"),
|
|
15027
|
+
text: z44.string().optional().describe("Plain-text attachment content when available"),
|
|
15028
|
+
description: z44.string().optional().describe("Caller-provided description of the attachment")
|
|
14626
15029
|
});
|
|
14627
|
-
var QueryRetrievalModeSchema =
|
|
15030
|
+
var QueryRetrievalModeSchema = z44.enum([
|
|
14628
15031
|
"graph_only",
|
|
14629
15032
|
"source_rag",
|
|
14630
15033
|
"long_context",
|
|
14631
15034
|
"hybrid"
|
|
14632
15035
|
]);
|
|
14633
|
-
var SubQuestionSchema =
|
|
14634
|
-
question:
|
|
15036
|
+
var SubQuestionSchema = z44.object({
|
|
15037
|
+
question: z44.string().describe("Atomic sub-question to retrieve and answer independently"),
|
|
14635
15038
|
intent: QueryIntentSchema,
|
|
14636
|
-
chunkTypes:
|
|
14637
|
-
documentFilters:
|
|
14638
|
-
type:
|
|
14639
|
-
carrier:
|
|
14640
|
-
insuredName:
|
|
14641
|
-
policyNumber:
|
|
14642
|
-
quoteNumber:
|
|
14643
|
-
policyTypes:
|
|
15039
|
+
chunkTypes: z44.array(z44.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
|
|
15040
|
+
documentFilters: z44.object({
|
|
15041
|
+
type: z44.enum(["policy", "quote"]).optional(),
|
|
15042
|
+
carrier: z44.string().optional(),
|
|
15043
|
+
insuredName: z44.string().optional(),
|
|
15044
|
+
policyNumber: z44.string().optional(),
|
|
15045
|
+
quoteNumber: z44.string().optional(),
|
|
15046
|
+
policyTypes: z44.array(PolicyTypeSchema).optional().describe("Filter by policy type (e.g. homeowners_ho3, renters_ho4, pet) to avoid mixing up similar policies")
|
|
14644
15047
|
}).optional().describe("Structured filters to narrow document lookup")
|
|
14645
15048
|
});
|
|
14646
|
-
var QueryClassifyResultSchema =
|
|
15049
|
+
var QueryClassifyResultSchema = z44.object({
|
|
14647
15050
|
intent: QueryIntentSchema,
|
|
14648
|
-
subQuestions:
|
|
14649
|
-
requiresDocumentLookup:
|
|
14650
|
-
requiresChunkSearch:
|
|
14651
|
-
requiresConversationHistory:
|
|
15051
|
+
subQuestions: z44.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
|
|
15052
|
+
requiresDocumentLookup: z44.boolean().describe("Whether structured document lookup is needed"),
|
|
15053
|
+
requiresChunkSearch: z44.boolean().describe("Whether semantic chunk search is needed"),
|
|
15054
|
+
requiresConversationHistory: z44.boolean().describe("Whether conversation history is relevant"),
|
|
14652
15055
|
retrievalMode: QueryRetrievalModeSchema.optional().describe("Preferred retrieval strategy for the query when source-span retrieval is available")
|
|
14653
15056
|
});
|
|
14654
|
-
var EvidenceItemSchema =
|
|
14655
|
-
source:
|
|
14656
|
-
chunkId:
|
|
14657
|
-
sourceNodeId:
|
|
14658
|
-
sourceSpanId:
|
|
14659
|
-
documentId:
|
|
14660
|
-
turnId:
|
|
14661
|
-
attachmentId:
|
|
14662
|
-
text:
|
|
14663
|
-
relevance:
|
|
15057
|
+
var EvidenceItemSchema = z44.object({
|
|
15058
|
+
source: z44.enum(["chunk", "document", "conversation", "attachment", "source_span", "source_node"]),
|
|
15059
|
+
chunkId: z44.string().optional(),
|
|
15060
|
+
sourceNodeId: z44.string().optional(),
|
|
15061
|
+
sourceSpanId: z44.string().optional(),
|
|
15062
|
+
documentId: z44.string().optional(),
|
|
15063
|
+
turnId: z44.string().optional(),
|
|
15064
|
+
attachmentId: z44.string().optional(),
|
|
15065
|
+
text: z44.string().describe("Text excerpt from the source"),
|
|
15066
|
+
relevance: z44.number().min(0).max(1),
|
|
14664
15067
|
retrievalMode: QueryRetrievalModeSchema.optional(),
|
|
14665
15068
|
sourceLocation: SourceSpanLocationSchema.optional(),
|
|
14666
|
-
metadata:
|
|
15069
|
+
metadata: z44.array(z44.object({ key: z44.string(), value: z44.string() })).optional()
|
|
14667
15070
|
});
|
|
14668
|
-
var AttachmentInterpretationSchema =
|
|
14669
|
-
summary:
|
|
14670
|
-
extractedFacts:
|
|
14671
|
-
recommendedFocus:
|
|
14672
|
-
confidence:
|
|
15071
|
+
var AttachmentInterpretationSchema = z44.object({
|
|
15072
|
+
summary: z44.string().describe("Concise summary of what the attachment shows or contains"),
|
|
15073
|
+
extractedFacts: z44.array(z44.string()).describe("Specific observable or document facts grounded in the attachment"),
|
|
15074
|
+
recommendedFocus: z44.array(z44.string()).describe("Important details to incorporate when answering follow-up questions"),
|
|
15075
|
+
confidence: z44.number().min(0).max(1)
|
|
14673
15076
|
});
|
|
14674
|
-
var RetrievalResultSchema =
|
|
14675
|
-
subQuestion:
|
|
14676
|
-
evidence:
|
|
15077
|
+
var RetrievalResultSchema = z44.object({
|
|
15078
|
+
subQuestion: z44.string(),
|
|
15079
|
+
evidence: z44.array(EvidenceItemSchema)
|
|
14677
15080
|
});
|
|
14678
|
-
var CitationSchema =
|
|
14679
|
-
index:
|
|
14680
|
-
chunkId:
|
|
14681
|
-
sourceNodeId:
|
|
14682
|
-
sourceSpanId:
|
|
14683
|
-
documentId:
|
|
14684
|
-
documentType:
|
|
14685
|
-
field:
|
|
14686
|
-
quote:
|
|
14687
|
-
relevance:
|
|
15081
|
+
var CitationSchema = z44.object({
|
|
15082
|
+
index: z44.number().describe("Citation number [1], [2], etc."),
|
|
15083
|
+
chunkId: z44.string().optional().describe("Source chunk ID, e.g. doc-123:coverage:2"),
|
|
15084
|
+
sourceNodeId: z44.string().optional().describe("Source tree node ID when available"),
|
|
15085
|
+
sourceSpanId: z44.string().optional().describe("Precise source span ID when available"),
|
|
15086
|
+
documentId: z44.string(),
|
|
15087
|
+
documentType: z44.enum(["policy", "quote"]).optional(),
|
|
15088
|
+
field: z44.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
|
|
15089
|
+
quote: z44.string().describe("Exact text from source that supports the claim"),
|
|
15090
|
+
relevance: z44.number().min(0).max(1),
|
|
14688
15091
|
retrievalMode: QueryRetrievalModeSchema.optional(),
|
|
14689
15092
|
sourceLocation: SourceSpanLocationSchema.optional()
|
|
14690
15093
|
});
|
|
14691
|
-
var SubAnswerSchema =
|
|
14692
|
-
subQuestion:
|
|
14693
|
-
answer:
|
|
14694
|
-
citations:
|
|
14695
|
-
confidence:
|
|
14696
|
-
needsMoreContext:
|
|
15094
|
+
var SubAnswerSchema = z44.object({
|
|
15095
|
+
subQuestion: z44.string(),
|
|
15096
|
+
answer: z44.string(),
|
|
15097
|
+
citations: z44.array(CitationSchema),
|
|
15098
|
+
confidence: z44.number().min(0).max(1),
|
|
15099
|
+
needsMoreContext: z44.boolean().describe("True if evidence was insufficient to answer fully")
|
|
14697
15100
|
});
|
|
14698
|
-
var VerifyResultSchema =
|
|
14699
|
-
approved:
|
|
14700
|
-
issues:
|
|
14701
|
-
retrySubQuestions:
|
|
15101
|
+
var VerifyResultSchema = z44.object({
|
|
15102
|
+
approved: z44.boolean().describe("Whether all sub-answers are adequately grounded"),
|
|
15103
|
+
issues: z44.array(z44.string()).describe("Specific grounding or consistency issues found"),
|
|
15104
|
+
retrySubQuestions: z44.array(z44.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
|
|
14702
15105
|
});
|
|
14703
|
-
var QueryResultSchema =
|
|
14704
|
-
answer:
|
|
14705
|
-
citations:
|
|
15106
|
+
var QueryResultSchema = z44.object({
|
|
15107
|
+
answer: z44.string(),
|
|
15108
|
+
citations: z44.array(CitationSchema),
|
|
14706
15109
|
intent: QueryIntentSchema,
|
|
14707
|
-
confidence:
|
|
14708
|
-
followUp:
|
|
15110
|
+
confidence: z44.number().min(0).max(1),
|
|
15111
|
+
followUp: z44.string().optional().describe("Suggested follow-up question if applicable")
|
|
14709
15112
|
});
|
|
14710
15113
|
|
|
14711
15114
|
// src/query/retriever.ts
|
|
@@ -15772,7 +16175,7 @@ ${sa.answer}`).join("\n\n"),
|
|
|
15772
16175
|
}
|
|
15773
16176
|
|
|
15774
16177
|
// src/pce/index.ts
|
|
15775
|
-
import { z as
|
|
16178
|
+
import { z as z45 } from "zod";
|
|
15776
16179
|
|
|
15777
16180
|
// src/prompts/pce/index.ts
|
|
15778
16181
|
function buildPceNormalizePrompt(input) {
|
|
@@ -15806,11 +16209,11 @@ ${input.openQuestions.map((question) => `- ${question.id}${question.fieldPath ?
|
|
|
15806
16209
|
}
|
|
15807
16210
|
|
|
15808
16211
|
// src/pce/index.ts
|
|
15809
|
-
var ReplyAnswersSchema =
|
|
15810
|
-
answers:
|
|
15811
|
-
questionId:
|
|
15812
|
-
fieldPath:
|
|
15813
|
-
answer:
|
|
16212
|
+
var ReplyAnswersSchema = z45.object({
|
|
16213
|
+
answers: z45.array(z45.object({
|
|
16214
|
+
questionId: z45.string().optional(),
|
|
16215
|
+
fieldPath: z45.string().optional(),
|
|
16216
|
+
answer: z45.string()
|
|
15814
16217
|
}))
|
|
15815
16218
|
});
|
|
15816
16219
|
function createPceAgent(config = {}) {
|