@claritylabs/cl-sdk 3.1.2 → 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 +677 -323
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +677 -323
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3757,15 +3757,6 @@ function sourceIds(nodes) {
|
|
|
3757
3757
|
sourceSpanIds: [...new Set(nodes.flatMap((node) => node.sourceSpanIds))]
|
|
3758
3758
|
};
|
|
3759
3759
|
}
|
|
3760
|
-
function relabelGenericTerm(term, label) {
|
|
3761
|
-
const cleanLabel = cleanValue(label);
|
|
3762
|
-
if (!cleanLabel || !/^column\s+\d+$/i.test(term.label)) return term;
|
|
3763
|
-
return {
|
|
3764
|
-
...term,
|
|
3765
|
-
kind: termKind(cleanLabel, term.value),
|
|
3766
|
-
label: cleanLabel
|
|
3767
|
-
};
|
|
3768
|
-
}
|
|
3769
3760
|
function termFromCell(params) {
|
|
3770
3761
|
const value = cleanCoverageTermValue(params.value);
|
|
3771
3762
|
if (!value) return void 0;
|
|
@@ -3915,8 +3906,7 @@ function coverageFromEndorsement(endorsement, children) {
|
|
|
3915
3906
|
const terms = uniqueTerms(rows.flatMap(
|
|
3916
3907
|
(row) => termsFromRow(row, children).map((term) => {
|
|
3917
3908
|
const appliesTo = nameFromRow(row, children);
|
|
3918
|
-
|
|
3919
|
-
return appliesTo && labelled.label !== appliesTo ? { ...labelled, appliesTo } : labelled;
|
|
3909
|
+
return appliesTo && term.label !== appliesTo ? { ...term, appliesTo } : term;
|
|
3920
3910
|
})
|
|
3921
3911
|
));
|
|
3922
3912
|
if (terms.length === 0) return void 0;
|
|
@@ -10111,7 +10101,343 @@ function groundExtractionMemoryWithSourceSpans(memory, sourceSpans) {
|
|
|
10111
10101
|
}
|
|
10112
10102
|
|
|
10113
10103
|
// src/extraction/source-tree-extractor.ts
|
|
10104
|
+
var import_zod42 = require("zod");
|
|
10105
|
+
|
|
10106
|
+
// src/extraction/operational-profile-cleanup.ts
|
|
10114
10107
|
var import_zod41 = require("zod");
|
|
10108
|
+
var OPERATIONAL_COVERAGE_TERM_KINDS2 = [
|
|
10109
|
+
"each_claim_limit",
|
|
10110
|
+
"each_occurrence_limit",
|
|
10111
|
+
"each_loss_limit",
|
|
10112
|
+
"aggregate_limit",
|
|
10113
|
+
"sublimit",
|
|
10114
|
+
"retention",
|
|
10115
|
+
"deductible",
|
|
10116
|
+
"retroactive_date",
|
|
10117
|
+
"premium",
|
|
10118
|
+
"other"
|
|
10119
|
+
];
|
|
10120
|
+
var OperationalCoverageTermKindSchema = import_zod41.z.enum(OPERATIONAL_COVERAGE_TERM_KINDS2);
|
|
10121
|
+
var OperationalProfileCleanupSchema = import_zod41.z.object({
|
|
10122
|
+
coverageDecisions: import_zod41.z.array(import_zod41.z.object({
|
|
10123
|
+
coverageIndex: import_zod41.z.number().int().nonnegative(),
|
|
10124
|
+
action: import_zod41.z.enum(["keep", "drop", "update"]),
|
|
10125
|
+
reason: import_zod41.z.string().optional(),
|
|
10126
|
+
name: import_zod41.z.string().optional(),
|
|
10127
|
+
limit: import_zod41.z.string().nullable().optional(),
|
|
10128
|
+
deductible: import_zod41.z.string().nullable().optional(),
|
|
10129
|
+
premium: import_zod41.z.string().nullable().optional(),
|
|
10130
|
+
retroactiveDate: import_zod41.z.string().nullable().optional(),
|
|
10131
|
+
coverageOrigin: import_zod41.z.enum(["core", "endorsement"]).optional(),
|
|
10132
|
+
sourceNodeIds: import_zod41.z.array(import_zod41.z.string()).optional(),
|
|
10133
|
+
sourceSpanIds: import_zod41.z.array(import_zod41.z.string()).optional(),
|
|
10134
|
+
termDecisions: import_zod41.z.array(import_zod41.z.object({
|
|
10135
|
+
termIndex: import_zod41.z.number().int().nonnegative(),
|
|
10136
|
+
action: import_zod41.z.enum(["keep", "drop", "update"]),
|
|
10137
|
+
reason: import_zod41.z.string().optional(),
|
|
10138
|
+
kind: OperationalCoverageTermKindSchema.optional(),
|
|
10139
|
+
label: import_zod41.z.string().optional(),
|
|
10140
|
+
value: import_zod41.z.string().optional(),
|
|
10141
|
+
amount: import_zod41.z.number().nullable().optional(),
|
|
10142
|
+
appliesTo: import_zod41.z.string().nullable().optional(),
|
|
10143
|
+
sourceNodeIds: import_zod41.z.array(import_zod41.z.string()).optional(),
|
|
10144
|
+
sourceSpanIds: import_zod41.z.array(import_zod41.z.string()).optional()
|
|
10145
|
+
})).optional()
|
|
10146
|
+
})).default([]),
|
|
10147
|
+
warnings: import_zod41.z.array(import_zod41.z.string()).default([])
|
|
10148
|
+
});
|
|
10149
|
+
function compactNode(node, maxText = 700) {
|
|
10150
|
+
return {
|
|
10151
|
+
id: node.id,
|
|
10152
|
+
kind: node.kind,
|
|
10153
|
+
title: node.title,
|
|
10154
|
+
path: node.path,
|
|
10155
|
+
pageStart: node.pageStart,
|
|
10156
|
+
pageEnd: node.pageEnd,
|
|
10157
|
+
sourceSpanIds: node.sourceSpanIds.slice(0, 8),
|
|
10158
|
+
text: (node.textExcerpt ?? node.description).slice(0, maxText)
|
|
10159
|
+
};
|
|
10160
|
+
}
|
|
10161
|
+
function compactCoverageForCleanup(coverage, coverageIndex) {
|
|
10162
|
+
return {
|
|
10163
|
+
coverageIndex,
|
|
10164
|
+
name: coverage.name,
|
|
10165
|
+
limit: coverage.limit,
|
|
10166
|
+
deductible: coverage.deductible,
|
|
10167
|
+
premium: coverage.premium,
|
|
10168
|
+
retroactiveDate: coverage.retroactiveDate,
|
|
10169
|
+
coverageOrigin: coverage.coverageOrigin,
|
|
10170
|
+
sourceNodeIds: coverage.sourceNodeIds,
|
|
10171
|
+
sourceSpanIds: coverage.sourceSpanIds,
|
|
10172
|
+
terms: coverage.limits.map((term, termIndex) => ({
|
|
10173
|
+
termIndex,
|
|
10174
|
+
kind: term.kind,
|
|
10175
|
+
label: term.label,
|
|
10176
|
+
value: term.value,
|
|
10177
|
+
amount: term.amount,
|
|
10178
|
+
appliesTo: term.appliesTo,
|
|
10179
|
+
sourceNodeIds: term.sourceNodeIds,
|
|
10180
|
+
sourceSpanIds: term.sourceSpanIds
|
|
10181
|
+
}))
|
|
10182
|
+
};
|
|
10183
|
+
}
|
|
10184
|
+
function buildOperationalProfileCleanupPrompt(sourceTree, profile) {
|
|
10185
|
+
const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 320).map((node) => compactNode(node, node.kind === "page" ? 900 : 700));
|
|
10186
|
+
const candidate = {
|
|
10187
|
+
documentType: profile.documentType,
|
|
10188
|
+
policyTypes: profile.policyTypes,
|
|
10189
|
+
coverageTypes: profile.coverageTypes,
|
|
10190
|
+
coverages: profile.coverages.map(compactCoverageForCleanup)
|
|
10191
|
+
};
|
|
10192
|
+
return `Review and clean a source-backed operational profile projection for an insurance policy.
|
|
10193
|
+
|
|
10194
|
+
Task:
|
|
10195
|
+
- Inspect the candidate coverage projection against the source nodes.
|
|
10196
|
+
- Return cleanup decisions only for coverage rows or terms that are malformed, unsupported, mismatched, or misleading.
|
|
10197
|
+
- If the projection is already acceptable, return an empty coverageDecisions array.
|
|
10198
|
+
|
|
10199
|
+
Projection defects to look for:
|
|
10200
|
+
- Generic labels such as "Column 3" that should be renamed from nearby row/header evidence.
|
|
10201
|
+
- 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.
|
|
10202
|
+
- Dangling continuation punctuation such as a trailing "/" copied into values.
|
|
10203
|
+
- Item references such as "shown in Item 7" or bare item numbers treated as money amounts.
|
|
10204
|
+
- Policy wording, exclusions, or unsupported prose copied into operational limit/deductible fields.
|
|
10205
|
+
- Header/value splits where "Limit of Liability", "Deductible", "Retroactive Date", "Aggregate", "Each Claim", or similar terms are attached to the wrong coverage row.
|
|
10206
|
+
- Repeated schedule headings projected as separate coverages when they only introduce the next coverage group.
|
|
10207
|
+
|
|
10208
|
+
Rules:
|
|
10209
|
+
- Use internal reasoning, but return JSON decisions only.
|
|
10210
|
+
- Do not invent policy facts. Keep, drop, or update only existing coverageIndex and termIndex entries.
|
|
10211
|
+
- Use sourceNodeIds and sourceSpanIds only from the provided source nodes or from the existing candidate entry.
|
|
10212
|
+
- Prefer dropping a malformed fact over speculative rewriting.
|
|
10213
|
+
- Keep a coverage when it is a real operational coverage/benefit even if only one term needs cleanup.
|
|
10214
|
+
- When changing a term's semantic meaning, set kind to the corrected normalized term kind.
|
|
10215
|
+
- Do not add new coverage rows or new terms; this pass cleans the existing projection.
|
|
10216
|
+
- Keep reasons concise and factual.
|
|
10217
|
+
|
|
10218
|
+
Candidate projection:
|
|
10219
|
+
${JSON.stringify(candidate, null, 2)}
|
|
10220
|
+
|
|
10221
|
+
Source nodes:
|
|
10222
|
+
${JSON.stringify(nodes, null, 2)}
|
|
10223
|
+
|
|
10224
|
+
Return JSON with coverageDecisions and warnings only.`;
|
|
10225
|
+
}
|
|
10226
|
+
function hasOwn(object, key) {
|
|
10227
|
+
return Object.prototype.hasOwnProperty.call(object, key);
|
|
10228
|
+
}
|
|
10229
|
+
function uniqueStrings(values) {
|
|
10230
|
+
return [...new Set(values.filter((value) => value.length > 0))];
|
|
10231
|
+
}
|
|
10232
|
+
function cleanProfileValue(value) {
|
|
10233
|
+
if (typeof value !== "string") return void 0;
|
|
10234
|
+
const cleaned = value.replace(/\s+\/\s*$/, "").replace(/\s+/g, " ").replace(/^[\s:;#-]+|[\s;,.]+$/g, "").trim();
|
|
10235
|
+
return cleaned || void 0;
|
|
10236
|
+
}
|
|
10237
|
+
function validIds(ids, valid) {
|
|
10238
|
+
return uniqueStrings((ids ?? []).filter((id) => valid.has(id)));
|
|
10239
|
+
}
|
|
10240
|
+
function cleanupIds(ids, valid, fallback) {
|
|
10241
|
+
if (ids === void 0) return validIds(fallback, valid);
|
|
10242
|
+
const next = validIds(ids, valid);
|
|
10243
|
+
return next.length > 0 ? next : validIds(fallback, valid);
|
|
10244
|
+
}
|
|
10245
|
+
function amountFromOperationalValue(value) {
|
|
10246
|
+
const match = value.match(/\$\s*([0-9][0-9,]*(?:\.\d+)?)/) ?? value.match(/\b([0-9][0-9,]*(?:\.\d+)?)\s*%/);
|
|
10247
|
+
if (!match) return void 0;
|
|
10248
|
+
const amount = Number(match[1].replace(/,/g, ""));
|
|
10249
|
+
return Number.isFinite(amount) ? amount : void 0;
|
|
10250
|
+
}
|
|
10251
|
+
function normalizedTermText(term) {
|
|
10252
|
+
return `${term.kind} ${term.label} ${term.value}`.toLowerCase();
|
|
10253
|
+
}
|
|
10254
|
+
function isLimitTerm(term) {
|
|
10255
|
+
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));
|
|
10256
|
+
}
|
|
10257
|
+
function isDeductibleTerm(term) {
|
|
10258
|
+
return term.kind === "deductible" || term.kind === "retention" || /\b(deductible|retention|sir)\b/i.test(normalizedTermText(term));
|
|
10259
|
+
}
|
|
10260
|
+
function isPremiumTerm(term) {
|
|
10261
|
+
return term.kind === "premium" || /\bpremium\b/i.test(normalizedTermText(term));
|
|
10262
|
+
}
|
|
10263
|
+
function isRetroactiveDateTerm(term) {
|
|
10264
|
+
return term.kind === "retroactive_date" || /\bretroactive\b/i.test(normalizedTermText(term));
|
|
10265
|
+
}
|
|
10266
|
+
function primaryLimitFromTerms(terms) {
|
|
10267
|
+
return terms.find(isLimitTerm)?.value;
|
|
10268
|
+
}
|
|
10269
|
+
function deductibleFromTerms(terms) {
|
|
10270
|
+
return terms.find(isDeductibleTerm)?.value;
|
|
10271
|
+
}
|
|
10272
|
+
function premiumFromTerms(terms) {
|
|
10273
|
+
return terms.find(isPremiumTerm)?.value;
|
|
10274
|
+
}
|
|
10275
|
+
function retroactiveDateFromTerms(terms) {
|
|
10276
|
+
return terms.find(isRetroactiveDateTerm)?.value;
|
|
10277
|
+
}
|
|
10278
|
+
function termDecisionTouches(coverage, decision, predicate) {
|
|
10279
|
+
const existing = coverage.limits[decision.termIndex];
|
|
10280
|
+
if (existing && predicate(existing)) return true;
|
|
10281
|
+
if (!decision.kind && !decision.label && !decision.value) return false;
|
|
10282
|
+
return predicate({
|
|
10283
|
+
kind: decision.kind ?? existing?.kind ?? "other",
|
|
10284
|
+
label: cleanProfileValue(decision.label) ?? existing?.label ?? "",
|
|
10285
|
+
value: cleanProfileValue(decision.value) ?? existing?.value ?? ""
|
|
10286
|
+
});
|
|
10287
|
+
}
|
|
10288
|
+
function applyTermCleanupDecision(term, decision, validNodeIds, validSpanIds) {
|
|
10289
|
+
if (!decision || decision.action === "keep") return term;
|
|
10290
|
+
if (decision.action === "drop") return void 0;
|
|
10291
|
+
const label = cleanProfileValue(decision.label) ?? term.label;
|
|
10292
|
+
const value = cleanProfileValue(decision.value) ?? term.value;
|
|
10293
|
+
if (!label || !value) return term;
|
|
10294
|
+
const next = {
|
|
10295
|
+
...term,
|
|
10296
|
+
kind: decision.kind ?? term.kind,
|
|
10297
|
+
label,
|
|
10298
|
+
value,
|
|
10299
|
+
sourceNodeIds: cleanupIds(decision.sourceNodeIds, validNodeIds, term.sourceNodeIds),
|
|
10300
|
+
sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, term.sourceSpanIds)
|
|
10301
|
+
};
|
|
10302
|
+
if (next.sourceNodeIds.length === 0 && next.sourceSpanIds.length === 0) return term;
|
|
10303
|
+
if (hasOwn(decision, "amount")) {
|
|
10304
|
+
if (typeof decision.amount === "number" && Number.isFinite(decision.amount)) next.amount = decision.amount;
|
|
10305
|
+
else delete next.amount;
|
|
10306
|
+
} else if (decision.value || decision.kind) {
|
|
10307
|
+
const amount = next.kind === "retroactive_date" ? void 0 : amountFromOperationalValue(next.value);
|
|
10308
|
+
if (amount === void 0) delete next.amount;
|
|
10309
|
+
else next.amount = amount;
|
|
10310
|
+
}
|
|
10311
|
+
if (hasOwn(decision, "appliesTo")) {
|
|
10312
|
+
const appliesTo = cleanProfileValue(decision.appliesTo);
|
|
10313
|
+
if (appliesTo) next.appliesTo = appliesTo;
|
|
10314
|
+
else delete next.appliesTo;
|
|
10315
|
+
}
|
|
10316
|
+
return next;
|
|
10317
|
+
}
|
|
10318
|
+
function termDecisionsTouch(coverage, decisions, predicate) {
|
|
10319
|
+
return decisions.filter((decision) => decision.action !== "keep").some((decision) => termDecisionTouches(coverage, decision, predicate));
|
|
10320
|
+
}
|
|
10321
|
+
function applyCoverageCleanupDecision(coverage, decision, validNodeIds, validSpanIds) {
|
|
10322
|
+
if (!decision || decision.action === "keep") return coverage;
|
|
10323
|
+
if (decision.action === "drop") return void 0;
|
|
10324
|
+
const next = {
|
|
10325
|
+
...coverage,
|
|
10326
|
+
limits: [...coverage.limits],
|
|
10327
|
+
sourceNodeIds: cleanupIds(decision.sourceNodeIds, validNodeIds, coverage.sourceNodeIds),
|
|
10328
|
+
sourceSpanIds: cleanupIds(decision.sourceSpanIds, validSpanIds, coverage.sourceSpanIds)
|
|
10329
|
+
};
|
|
10330
|
+
const name = cleanProfileValue(decision.name);
|
|
10331
|
+
if (name) next.name = name;
|
|
10332
|
+
if (decision.coverageOrigin) next.coverageOrigin = decision.coverageOrigin;
|
|
10333
|
+
if (hasOwn(decision, "limit")) {
|
|
10334
|
+
const value = cleanProfileValue(decision.limit);
|
|
10335
|
+
if (value) next.limit = value;
|
|
10336
|
+
else delete next.limit;
|
|
10337
|
+
}
|
|
10338
|
+
if (hasOwn(decision, "deductible")) {
|
|
10339
|
+
const value = cleanProfileValue(decision.deductible);
|
|
10340
|
+
if (value) next.deductible = value;
|
|
10341
|
+
else delete next.deductible;
|
|
10342
|
+
}
|
|
10343
|
+
if (hasOwn(decision, "premium")) {
|
|
10344
|
+
const value = cleanProfileValue(decision.premium);
|
|
10345
|
+
if (value) next.premium = value;
|
|
10346
|
+
else delete next.premium;
|
|
10347
|
+
}
|
|
10348
|
+
if (hasOwn(decision, "retroactiveDate")) {
|
|
10349
|
+
const value = cleanProfileValue(decision.retroactiveDate);
|
|
10350
|
+
if (value) next.retroactiveDate = value;
|
|
10351
|
+
else delete next.retroactiveDate;
|
|
10352
|
+
}
|
|
10353
|
+
const termDecisions = (decision.termDecisions ?? []).filter((termDecision) => termDecision.termIndex < coverage.limits.length);
|
|
10354
|
+
const termDecisionByIndex = new Map(termDecisions.map((termDecision) => [termDecision.termIndex, termDecision]));
|
|
10355
|
+
next.limits = coverage.limits.map((term, index) => applyTermCleanupDecision(term, termDecisionByIndex.get(index), validNodeIds, validSpanIds)).filter((term) => Boolean(term));
|
|
10356
|
+
if (termDecisions.length > 0) {
|
|
10357
|
+
if (!hasOwn(decision, "limit") && termDecisionsTouch(coverage, termDecisions, isLimitTerm)) {
|
|
10358
|
+
const value = primaryLimitFromTerms(next.limits);
|
|
10359
|
+
if (value) next.limit = value;
|
|
10360
|
+
else delete next.limit;
|
|
10361
|
+
}
|
|
10362
|
+
if (!hasOwn(decision, "deductible") && termDecisionsTouch(coverage, termDecisions, isDeductibleTerm)) {
|
|
10363
|
+
const value = deductibleFromTerms(next.limits);
|
|
10364
|
+
if (value) next.deductible = value;
|
|
10365
|
+
else delete next.deductible;
|
|
10366
|
+
}
|
|
10367
|
+
if (!hasOwn(decision, "premium") && termDecisionsTouch(coverage, termDecisions, isPremiumTerm)) {
|
|
10368
|
+
const value = premiumFromTerms(next.limits);
|
|
10369
|
+
if (value) next.premium = value;
|
|
10370
|
+
else delete next.premium;
|
|
10371
|
+
}
|
|
10372
|
+
if (!hasOwn(decision, "retroactiveDate") && termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm)) {
|
|
10373
|
+
const value = retroactiveDateFromTerms(next.limits);
|
|
10374
|
+
if (value) next.retroactiveDate = value;
|
|
10375
|
+
else delete next.retroactiveDate;
|
|
10376
|
+
}
|
|
10377
|
+
}
|
|
10378
|
+
next.sourceNodeIds = uniqueStrings([
|
|
10379
|
+
...next.sourceNodeIds,
|
|
10380
|
+
...next.limits.flatMap((term) => term.sourceNodeIds)
|
|
10381
|
+
]);
|
|
10382
|
+
next.sourceSpanIds = uniqueStrings([
|
|
10383
|
+
...next.sourceSpanIds,
|
|
10384
|
+
...next.limits.flatMap((term) => term.sourceSpanIds)
|
|
10385
|
+
]);
|
|
10386
|
+
return next.name ? next : coverage;
|
|
10387
|
+
}
|
|
10388
|
+
function sourceIdsFromOperationalProfile(profile) {
|
|
10389
|
+
const backedValues = [
|
|
10390
|
+
profile.policyNumber,
|
|
10391
|
+
profile.namedInsured,
|
|
10392
|
+
profile.insurer,
|
|
10393
|
+
profile.broker,
|
|
10394
|
+
profile.effectiveDate,
|
|
10395
|
+
profile.expirationDate,
|
|
10396
|
+
profile.retroactiveDate,
|
|
10397
|
+
profile.premium
|
|
10398
|
+
].filter(Boolean);
|
|
10399
|
+
return {
|
|
10400
|
+
sourceNodeIds: uniqueStrings([
|
|
10401
|
+
...backedValues.flatMap((value) => value?.sourceNodeIds ?? []),
|
|
10402
|
+
...profile.coverages.flatMap((coverage) => coverage.sourceNodeIds),
|
|
10403
|
+
...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceNodeIds)),
|
|
10404
|
+
...profile.parties.flatMap((party) => party.sourceNodeIds),
|
|
10405
|
+
...profile.endorsementSupport.flatMap((support) => support.sourceNodeIds)
|
|
10406
|
+
]),
|
|
10407
|
+
sourceSpanIds: uniqueStrings([
|
|
10408
|
+
...backedValues.flatMap((value) => value?.sourceSpanIds ?? []),
|
|
10409
|
+
...profile.coverages.flatMap((coverage) => coverage.sourceSpanIds),
|
|
10410
|
+
...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceSpanIds)),
|
|
10411
|
+
...profile.parties.flatMap((party) => party.sourceSpanIds),
|
|
10412
|
+
...profile.endorsementSupport.flatMap((support) => support.sourceSpanIds)
|
|
10413
|
+
])
|
|
10414
|
+
};
|
|
10415
|
+
}
|
|
10416
|
+
function applyOperationalProfileCleanup(profile, cleanup, validNodeIds, validSpanIds) {
|
|
10417
|
+
const coverageDecisionByIndex = /* @__PURE__ */ new Map();
|
|
10418
|
+
for (const decision of cleanup.coverageDecisions) {
|
|
10419
|
+
if (decision.coverageIndex < profile.coverages.length) coverageDecisionByIndex.set(decision.coverageIndex, decision);
|
|
10420
|
+
}
|
|
10421
|
+
const coverages = profile.coverages.map(
|
|
10422
|
+
(coverage, index) => applyCoverageCleanupDecision(coverage, coverageDecisionByIndex.get(index), validNodeIds, validSpanIds)
|
|
10423
|
+
).filter((coverage) => Boolean(coverage));
|
|
10424
|
+
const cleanupWarnings = cleanup.warnings.map((warning) => cleanProfileValue(warning)).filter((warning) => Boolean(warning));
|
|
10425
|
+
const nextProfile = {
|
|
10426
|
+
...profile,
|
|
10427
|
+
coverages,
|
|
10428
|
+
coverageTypes: uniqueStrings(coverages.map((coverage) => coverage.name)),
|
|
10429
|
+
warnings: uniqueStrings([
|
|
10430
|
+
...profile.warnings,
|
|
10431
|
+
...cleanupWarnings.map((warning) => `Operational profile cleanup warning: ${warning}`)
|
|
10432
|
+
])
|
|
10433
|
+
};
|
|
10434
|
+
return PolicyOperationalProfileSchema.parse({
|
|
10435
|
+
...nextProfile,
|
|
10436
|
+
...sourceIdsFromOperationalProfile(nextProfile)
|
|
10437
|
+
});
|
|
10438
|
+
}
|
|
10439
|
+
|
|
10440
|
+
// src/extraction/source-tree-extractor.ts
|
|
10115
10441
|
var ORGANIZABLE_KINDS = [
|
|
10116
10442
|
"page_group",
|
|
10117
10443
|
"form",
|
|
@@ -10124,10 +10450,10 @@ var ORGANIZATION_TOP_LEVEL_BATCH_SIZE = 80;
|
|
|
10124
10450
|
var ORGANIZER_MAX_SOURCE_SPANS = 400;
|
|
10125
10451
|
var ORGANIZER_MAX_TOP_LEVEL_NODES = 18;
|
|
10126
10452
|
var OUTLINE_CLEANUP_MAX_TOP_LEVEL_NODES = 80;
|
|
10127
|
-
var SourceTreeOrganizationSchema =
|
|
10128
|
-
labels:
|
|
10129
|
-
nodeId:
|
|
10130
|
-
kind:
|
|
10453
|
+
var SourceTreeOrganizationSchema = import_zod42.z.object({
|
|
10454
|
+
labels: import_zod42.z.array(import_zod42.z.object({
|
|
10455
|
+
nodeId: import_zod42.z.string(),
|
|
10456
|
+
kind: import_zod42.z.enum([
|
|
10131
10457
|
"document",
|
|
10132
10458
|
"page_group",
|
|
10133
10459
|
"page",
|
|
@@ -10141,26 +10467,26 @@ var SourceTreeOrganizationSchema = import_zod41.z.object({
|
|
|
10141
10467
|
"table_cell",
|
|
10142
10468
|
"text"
|
|
10143
10469
|
]).optional(),
|
|
10144
|
-
title:
|
|
10145
|
-
description:
|
|
10470
|
+
title: import_zod42.z.string().optional(),
|
|
10471
|
+
description: import_zod42.z.string().optional()
|
|
10146
10472
|
})),
|
|
10147
|
-
groups:
|
|
10148
|
-
kind:
|
|
10149
|
-
title:
|
|
10150
|
-
description:
|
|
10151
|
-
childNodeIds:
|
|
10473
|
+
groups: import_zod42.z.array(import_zod42.z.object({
|
|
10474
|
+
kind: import_zod42.z.enum(ORGANIZABLE_KINDS),
|
|
10475
|
+
title: import_zod42.z.string(),
|
|
10476
|
+
description: import_zod42.z.string().optional(),
|
|
10477
|
+
childNodeIds: import_zod42.z.array(import_zod42.z.string()).min(1)
|
|
10152
10478
|
}))
|
|
10153
10479
|
});
|
|
10154
|
-
var SourceBackedValueForPromptSchema =
|
|
10155
|
-
value:
|
|
10156
|
-
normalizedValue:
|
|
10157
|
-
confidence:
|
|
10158
|
-
sourceNodeIds:
|
|
10159
|
-
sourceSpanIds:
|
|
10480
|
+
var SourceBackedValueForPromptSchema = import_zod42.z.object({
|
|
10481
|
+
value: import_zod42.z.string(),
|
|
10482
|
+
normalizedValue: import_zod42.z.string().optional(),
|
|
10483
|
+
confidence: import_zod42.z.enum(["low", "medium", "high"]).optional(),
|
|
10484
|
+
sourceNodeIds: import_zod42.z.array(import_zod42.z.string()),
|
|
10485
|
+
sourceSpanIds: import_zod42.z.array(import_zod42.z.string())
|
|
10160
10486
|
});
|
|
10161
|
-
var OperationalProfilePromptSchema =
|
|
10162
|
-
documentType:
|
|
10163
|
-
policyTypes:
|
|
10487
|
+
var OperationalProfilePromptSchema = import_zod42.z.object({
|
|
10488
|
+
documentType: import_zod42.z.enum(["policy", "quote"]).optional(),
|
|
10489
|
+
policyTypes: import_zod42.z.array(import_zod42.z.string()).optional(),
|
|
10164
10490
|
policyNumber: SourceBackedValueForPromptSchema.optional(),
|
|
10165
10491
|
namedInsured: SourceBackedValueForPromptSchema.optional(),
|
|
10166
10492
|
insurer: SourceBackedValueForPromptSchema.optional(),
|
|
@@ -10169,43 +10495,32 @@ var OperationalProfilePromptSchema = import_zod41.z.object({
|
|
|
10169
10495
|
expirationDate: SourceBackedValueForPromptSchema.optional(),
|
|
10170
10496
|
retroactiveDate: SourceBackedValueForPromptSchema.optional(),
|
|
10171
10497
|
premium: SourceBackedValueForPromptSchema.optional(),
|
|
10172
|
-
coverageTypes:
|
|
10173
|
-
coverages:
|
|
10174
|
-
name:
|
|
10175
|
-
coverageCode:
|
|
10176
|
-
limit:
|
|
10177
|
-
deductible:
|
|
10178
|
-
premium:
|
|
10179
|
-
retroactiveDate:
|
|
10180
|
-
formNumber:
|
|
10181
|
-
sectionRef:
|
|
10182
|
-
coverageOrigin:
|
|
10183
|
-
endorsementNumber:
|
|
10184
|
-
limits:
|
|
10185
|
-
kind:
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10189
|
-
|
|
10190
|
-
|
|
10191
|
-
|
|
10192
|
-
"deductible",
|
|
10193
|
-
"retroactive_date",
|
|
10194
|
-
"premium",
|
|
10195
|
-
"other"
|
|
10196
|
-
]).optional(),
|
|
10197
|
-
label: import_zod41.z.string(),
|
|
10198
|
-
value: import_zod41.z.string(),
|
|
10199
|
-
amount: import_zod41.z.number().optional(),
|
|
10200
|
-
appliesTo: import_zod41.z.string().optional(),
|
|
10201
|
-
sourceNodeIds: import_zod41.z.array(import_zod41.z.string()),
|
|
10202
|
-
sourceSpanIds: import_zod41.z.array(import_zod41.z.string())
|
|
10498
|
+
coverageTypes: import_zod42.z.array(import_zod42.z.string()).optional(),
|
|
10499
|
+
coverages: import_zod42.z.array(import_zod42.z.object({
|
|
10500
|
+
name: import_zod42.z.string(),
|
|
10501
|
+
coverageCode: import_zod42.z.string().optional(),
|
|
10502
|
+
limit: import_zod42.z.string().optional(),
|
|
10503
|
+
deductible: import_zod42.z.string().optional(),
|
|
10504
|
+
premium: import_zod42.z.string().optional(),
|
|
10505
|
+
retroactiveDate: import_zod42.z.string().optional(),
|
|
10506
|
+
formNumber: import_zod42.z.string().optional(),
|
|
10507
|
+
sectionRef: import_zod42.z.string().optional(),
|
|
10508
|
+
coverageOrigin: import_zod42.z.enum(["core", "endorsement"]).optional(),
|
|
10509
|
+
endorsementNumber: import_zod42.z.string().optional(),
|
|
10510
|
+
limits: import_zod42.z.array(import_zod42.z.object({
|
|
10511
|
+
kind: OperationalCoverageTermKindSchema.optional(),
|
|
10512
|
+
label: import_zod42.z.string(),
|
|
10513
|
+
value: import_zod42.z.string(),
|
|
10514
|
+
amount: import_zod42.z.number().optional(),
|
|
10515
|
+
appliesTo: import_zod42.z.string().optional(),
|
|
10516
|
+
sourceNodeIds: import_zod42.z.array(import_zod42.z.string()),
|
|
10517
|
+
sourceSpanIds: import_zod42.z.array(import_zod42.z.string())
|
|
10203
10518
|
})).optional(),
|
|
10204
|
-
sourceNodeIds:
|
|
10205
|
-
sourceSpanIds:
|
|
10519
|
+
sourceNodeIds: import_zod42.z.array(import_zod42.z.string()),
|
|
10520
|
+
sourceSpanIds: import_zod42.z.array(import_zod42.z.string())
|
|
10206
10521
|
})).optional(),
|
|
10207
|
-
sourceNodeIds:
|
|
10208
|
-
sourceSpanIds:
|
|
10522
|
+
sourceNodeIds: import_zod42.z.array(import_zod42.z.string()).optional(),
|
|
10523
|
+
sourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional()
|
|
10209
10524
|
});
|
|
10210
10525
|
function formatFormHintsForPrompt(forms) {
|
|
10211
10526
|
const usable = forms.filter((form) => typeof form.pageStart === "number" && typeof form.pageEnd === "number").slice(0, 120).map((form) => ({
|
|
@@ -11197,7 +11512,7 @@ function applyEndorsementGrouping(sourceTree) {
|
|
|
11197
11512
|
}
|
|
11198
11513
|
return normalizeSemanticHierarchy(nextTree);
|
|
11199
11514
|
}
|
|
11200
|
-
function
|
|
11515
|
+
function compactNode2(node, maxText = 700) {
|
|
11201
11516
|
return {
|
|
11202
11517
|
id: node.id,
|
|
11203
11518
|
kind: node.kind,
|
|
@@ -11287,7 +11602,7 @@ function mergeOrganizationResults(results) {
|
|
|
11287
11602
|
};
|
|
11288
11603
|
}
|
|
11289
11604
|
function buildOrganizationPrompt(batch, formHints) {
|
|
11290
|
-
const nodes = batch.nodes.map((node) =>
|
|
11605
|
+
const nodes = batch.nodes.map((node) => compactNode2(node, node.kind === "page" ? 900 : 320));
|
|
11291
11606
|
return `You organize an insurance document source tree.
|
|
11292
11607
|
|
|
11293
11608
|
Scope:
|
|
@@ -11329,7 +11644,7 @@ function shouldRunOutlineCleanup(sourceTree) {
|
|
|
11329
11644
|
}
|
|
11330
11645
|
function buildOutlineCleanupPrompt(sourceTree, formHints) {
|
|
11331
11646
|
const topLevel = rootChildren(sourceTree).slice(0, OUTLINE_CLEANUP_MAX_TOP_LEVEL_NODES);
|
|
11332
|
-
const nodes = topLevel.map((node) =>
|
|
11647
|
+
const nodes = topLevel.map((node) => compactNode2(node, 900));
|
|
11333
11648
|
return `You clean a top-level source outline for an insurance policy.
|
|
11334
11649
|
|
|
11335
11650
|
Expected product-facing order:
|
|
@@ -11358,7 +11673,7 @@ ${JSON.stringify(nodes, null, 2)}
|
|
|
11358
11673
|
Return JSON with labels and groups only.`;
|
|
11359
11674
|
}
|
|
11360
11675
|
function buildOperationalProfilePrompt(sourceTree, fallback) {
|
|
11361
|
-
const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 240).map(
|
|
11676
|
+
const nodes = sourceTree.filter((node) => node.kind !== "document").slice(0, 240).map(compactNode2);
|
|
11362
11677
|
return `Extract a source-backed operational profile for an insurance policy or quote.
|
|
11363
11678
|
|
|
11364
11679
|
Return only high-value operational facts needed for policy lists, Q&A, compliance, and certificate generation:
|
|
@@ -11722,6 +12037,45 @@ async function runSourceTreeExtraction(params) {
|
|
|
11722
12037
|
} catch (error) {
|
|
11723
12038
|
warnings.push(`Operational profile model pass failed; deterministic profile used (${error instanceof Error ? error.message : String(error)})`);
|
|
11724
12039
|
}
|
|
12040
|
+
if (operationalProfile.coverages.length > 0) {
|
|
12041
|
+
try {
|
|
12042
|
+
const validNodeIds = new Set(sourceTree.map((node) => node.id));
|
|
12043
|
+
const validSpanIds = new Set(sourceSpans.map((span) => span.id));
|
|
12044
|
+
const budget = params.resolveBudget("extraction_operational_profile", 4096);
|
|
12045
|
+
const startedAt = Date.now();
|
|
12046
|
+
const response = await safeGenerateObject(
|
|
12047
|
+
params.generateObject,
|
|
12048
|
+
{
|
|
12049
|
+
prompt: buildOperationalProfileCleanupPrompt(sourceTree, operationalProfile),
|
|
12050
|
+
schema: OperationalProfileCleanupSchema,
|
|
12051
|
+
maxTokens: budget.maxTokens,
|
|
12052
|
+
taskKind: "extraction_operational_profile",
|
|
12053
|
+
budgetDiagnostics: budget,
|
|
12054
|
+
providerOptions: params.providerOptions
|
|
12055
|
+
},
|
|
12056
|
+
{
|
|
12057
|
+
fallback: { coverageDecisions: [], warnings: [] },
|
|
12058
|
+
log: params.log
|
|
12059
|
+
}
|
|
12060
|
+
);
|
|
12061
|
+
localTrack(response.usage, {
|
|
12062
|
+
taskKind: "extraction_operational_profile",
|
|
12063
|
+
label: "operational_profile_cleanup",
|
|
12064
|
+
maxTokens: budget.maxTokens,
|
|
12065
|
+
durationMs: Date.now() - startedAt
|
|
12066
|
+
});
|
|
12067
|
+
operationalProfile = applyOperationalProfileCleanup(
|
|
12068
|
+
operationalProfile,
|
|
12069
|
+
response.object,
|
|
12070
|
+
validNodeIds,
|
|
12071
|
+
validSpanIds
|
|
12072
|
+
);
|
|
12073
|
+
} catch (error) {
|
|
12074
|
+
warnings.push(`Operational profile cleanup pass failed; uncleaned profile used (${error instanceof Error ? error.message : String(error)})`);
|
|
12075
|
+
}
|
|
12076
|
+
} else {
|
|
12077
|
+
await params.log?.("Operational profile has no coverage rows; skipped model cleanup");
|
|
12078
|
+
}
|
|
11725
12079
|
const document = materializeDocument({
|
|
11726
12080
|
id: params.id,
|
|
11727
12081
|
sourceTree,
|
|
@@ -13048,8 +13402,8 @@ Respond with JSON only:
|
|
|
13048
13402
|
}`;
|
|
13049
13403
|
|
|
13050
13404
|
// src/schemas/application.ts
|
|
13051
|
-
var
|
|
13052
|
-
var FieldTypeSchema =
|
|
13405
|
+
var import_zod43 = require("zod");
|
|
13406
|
+
var FieldTypeSchema = import_zod43.z.enum([
|
|
13053
13407
|
"text",
|
|
13054
13408
|
"numeric",
|
|
13055
13409
|
"currency",
|
|
@@ -13058,223 +13412,223 @@ var FieldTypeSchema = import_zod42.z.enum([
|
|
|
13058
13412
|
"table",
|
|
13059
13413
|
"declaration"
|
|
13060
13414
|
]);
|
|
13061
|
-
var ApplicationFieldSchema =
|
|
13062
|
-
id:
|
|
13063
|
-
label:
|
|
13064
|
-
section:
|
|
13415
|
+
var ApplicationFieldSchema = import_zod43.z.object({
|
|
13416
|
+
id: import_zod43.z.string(),
|
|
13417
|
+
label: import_zod43.z.string(),
|
|
13418
|
+
section: import_zod43.z.string(),
|
|
13065
13419
|
fieldType: FieldTypeSchema,
|
|
13066
|
-
required:
|
|
13067
|
-
options:
|
|
13068
|
-
columns:
|
|
13069
|
-
requiresExplanationIfYes:
|
|
13070
|
-
condition:
|
|
13071
|
-
dependsOn:
|
|
13072
|
-
whenValue:
|
|
13420
|
+
required: import_zod43.z.boolean(),
|
|
13421
|
+
options: import_zod43.z.array(import_zod43.z.string()).optional(),
|
|
13422
|
+
columns: import_zod43.z.array(import_zod43.z.string()).optional(),
|
|
13423
|
+
requiresExplanationIfYes: import_zod43.z.boolean().optional(),
|
|
13424
|
+
condition: import_zod43.z.object({
|
|
13425
|
+
dependsOn: import_zod43.z.string(),
|
|
13426
|
+
whenValue: import_zod43.z.string()
|
|
13073
13427
|
}).optional(),
|
|
13074
|
-
value:
|
|
13075
|
-
source:
|
|
13076
|
-
confidence:
|
|
13077
|
-
sourceSpanIds:
|
|
13078
|
-
userSourceSpanIds:
|
|
13079
|
-
pageNumber:
|
|
13080
|
-
fieldAnchorId:
|
|
13081
|
-
acroFormName:
|
|
13082
|
-
validationStatus:
|
|
13428
|
+
value: import_zod43.z.string().optional(),
|
|
13429
|
+
source: import_zod43.z.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
|
|
13430
|
+
confidence: import_zod43.z.enum(["confirmed", "high", "medium", "low"]).optional(),
|
|
13431
|
+
sourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional().describe("Stable source spans that support the field value or field anchor"),
|
|
13432
|
+
userSourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional().describe("Message or attachment spans that support user-provided values"),
|
|
13433
|
+
pageNumber: import_zod43.z.number().int().positive().optional().describe("Application page where the field label or anchor appears"),
|
|
13434
|
+
fieldAnchorId: import_zod43.z.string().optional().describe("Stable field anchor ID derived from page, section, label, and form metadata"),
|
|
13435
|
+
acroFormName: import_zod43.z.string().optional().describe("Native PDF AcroForm field name when available"),
|
|
13436
|
+
validationStatus: import_zod43.z.enum(["valid", "needs_review", "unsupported", "missing"]).optional()
|
|
13083
13437
|
});
|
|
13084
|
-
var ApplicationQuestionConditionSchema =
|
|
13085
|
-
dependsOn:
|
|
13086
|
-
operator:
|
|
13087
|
-
value:
|
|
13088
|
-
whenValue:
|
|
13089
|
-
values:
|
|
13438
|
+
var ApplicationQuestionConditionSchema = import_zod43.z.object({
|
|
13439
|
+
dependsOn: import_zod43.z.string(),
|
|
13440
|
+
operator: import_zod43.z.enum(["equals", "not_equals", "in", "not_in", "exists"]).optional(),
|
|
13441
|
+
value: import_zod43.z.string().optional(),
|
|
13442
|
+
whenValue: import_zod43.z.string().optional(),
|
|
13443
|
+
values: import_zod43.z.array(import_zod43.z.string()).optional()
|
|
13090
13444
|
});
|
|
13091
|
-
var ApplicationRepeatSchema =
|
|
13092
|
-
min:
|
|
13093
|
-
max:
|
|
13094
|
-
label:
|
|
13445
|
+
var ApplicationRepeatSchema = import_zod43.z.object({
|
|
13446
|
+
min: import_zod43.z.number().int().nonnegative().optional(),
|
|
13447
|
+
max: import_zod43.z.number().int().positive().optional(),
|
|
13448
|
+
label: import_zod43.z.string().optional()
|
|
13095
13449
|
});
|
|
13096
|
-
var ApplicationQuestionNodeSchema =
|
|
13097
|
-
() =>
|
|
13098
|
-
id:
|
|
13099
|
-
nodeType:
|
|
13100
|
-
fieldId:
|
|
13101
|
-
fieldPath:
|
|
13102
|
-
parentId:
|
|
13103
|
-
order:
|
|
13104
|
-
label:
|
|
13105
|
-
section:
|
|
13450
|
+
var ApplicationQuestionNodeSchema = import_zod43.z.lazy(
|
|
13451
|
+
() => import_zod43.z.object({
|
|
13452
|
+
id: import_zod43.z.string(),
|
|
13453
|
+
nodeType: import_zod43.z.enum(["group", "question", "repeat_group", "table"]),
|
|
13454
|
+
fieldId: import_zod43.z.string().optional(),
|
|
13455
|
+
fieldPath: import_zod43.z.string().optional(),
|
|
13456
|
+
parentId: import_zod43.z.string().optional(),
|
|
13457
|
+
order: import_zod43.z.number().int().nonnegative().optional(),
|
|
13458
|
+
label: import_zod43.z.string(),
|
|
13459
|
+
section: import_zod43.z.string().optional(),
|
|
13106
13460
|
fieldType: FieldTypeSchema.optional(),
|
|
13107
|
-
required:
|
|
13108
|
-
prompt:
|
|
13109
|
-
options:
|
|
13110
|
-
columns:
|
|
13461
|
+
required: import_zod43.z.boolean().optional(),
|
|
13462
|
+
prompt: import_zod43.z.string().optional(),
|
|
13463
|
+
options: import_zod43.z.array(import_zod43.z.string()).optional(),
|
|
13464
|
+
columns: import_zod43.z.array(import_zod43.z.string()).optional(),
|
|
13111
13465
|
condition: ApplicationQuestionConditionSchema.optional(),
|
|
13112
13466
|
repeat: ApplicationRepeatSchema.optional(),
|
|
13113
|
-
children:
|
|
13467
|
+
children: import_zod43.z.array(ApplicationQuestionNodeSchema).optional()
|
|
13114
13468
|
})
|
|
13115
13469
|
);
|
|
13116
|
-
var ApplicationQuestionGraphSchema =
|
|
13117
|
-
id:
|
|
13118
|
-
version:
|
|
13119
|
-
title:
|
|
13120
|
-
applicationType:
|
|
13121
|
-
source:
|
|
13122
|
-
rootNodeIds:
|
|
13123
|
-
nodes:
|
|
13470
|
+
var ApplicationQuestionGraphSchema = import_zod43.z.object({
|
|
13471
|
+
id: import_zod43.z.string(),
|
|
13472
|
+
version: import_zod43.z.string(),
|
|
13473
|
+
title: import_zod43.z.string().optional(),
|
|
13474
|
+
applicationType: import_zod43.z.string().nullable().optional(),
|
|
13475
|
+
source: import_zod43.z.enum(["pdf", "manual", "imported", "generated"]).default("generated"),
|
|
13476
|
+
rootNodeIds: import_zod43.z.array(import_zod43.z.string()).optional(),
|
|
13477
|
+
nodes: import_zod43.z.array(ApplicationQuestionNodeSchema)
|
|
13124
13478
|
});
|
|
13125
|
-
var ApplicationTemplateSchema =
|
|
13126
|
-
id:
|
|
13127
|
-
version:
|
|
13128
|
-
title:
|
|
13129
|
-
applicationType:
|
|
13479
|
+
var ApplicationTemplateSchema = import_zod43.z.object({
|
|
13480
|
+
id: import_zod43.z.string(),
|
|
13481
|
+
version: import_zod43.z.string(),
|
|
13482
|
+
title: import_zod43.z.string(),
|
|
13483
|
+
applicationType: import_zod43.z.string().nullable().optional(),
|
|
13130
13484
|
questionGraph: ApplicationQuestionGraphSchema,
|
|
13131
|
-
fields:
|
|
13485
|
+
fields: import_zod43.z.array(ApplicationFieldSchema).optional()
|
|
13132
13486
|
});
|
|
13133
|
-
var ApplicationClassifyResultSchema =
|
|
13134
|
-
isApplication:
|
|
13135
|
-
confidence:
|
|
13136
|
-
applicationType:
|
|
13487
|
+
var ApplicationClassifyResultSchema = import_zod43.z.object({
|
|
13488
|
+
isApplication: import_zod43.z.boolean(),
|
|
13489
|
+
confidence: import_zod43.z.number().min(0).max(1),
|
|
13490
|
+
applicationType: import_zod43.z.string().nullable()
|
|
13137
13491
|
});
|
|
13138
|
-
var FieldExtractionResultSchema =
|
|
13139
|
-
fields:
|
|
13492
|
+
var FieldExtractionResultSchema = import_zod43.z.object({
|
|
13493
|
+
fields: import_zod43.z.array(ApplicationFieldSchema)
|
|
13140
13494
|
});
|
|
13141
|
-
var AutoFillMatchSchema =
|
|
13142
|
-
fieldId:
|
|
13143
|
-
value:
|
|
13144
|
-
confidence:
|
|
13145
|
-
contextKey:
|
|
13495
|
+
var AutoFillMatchSchema = import_zod43.z.object({
|
|
13496
|
+
fieldId: import_zod43.z.string(),
|
|
13497
|
+
value: import_zod43.z.string(),
|
|
13498
|
+
confidence: import_zod43.z.enum(["confirmed"]),
|
|
13499
|
+
contextKey: import_zod43.z.string()
|
|
13146
13500
|
});
|
|
13147
|
-
var AutoFillResultSchema =
|
|
13148
|
-
matches:
|
|
13501
|
+
var AutoFillResultSchema = import_zod43.z.object({
|
|
13502
|
+
matches: import_zod43.z.array(AutoFillMatchSchema)
|
|
13149
13503
|
});
|
|
13150
|
-
var QuestionBatchResultSchema =
|
|
13151
|
-
batches:
|
|
13504
|
+
var QuestionBatchResultSchema = import_zod43.z.object({
|
|
13505
|
+
batches: import_zod43.z.array(import_zod43.z.array(import_zod43.z.string()).describe("Array of field IDs in this batch"))
|
|
13152
13506
|
});
|
|
13153
|
-
var LookupRequestSchema =
|
|
13154
|
-
type:
|
|
13155
|
-
description:
|
|
13156
|
-
url:
|
|
13157
|
-
targetFieldIds:
|
|
13507
|
+
var LookupRequestSchema = import_zod43.z.object({
|
|
13508
|
+
type: import_zod43.z.string().describe("Type of lookup: 'records', 'website', 'policy'"),
|
|
13509
|
+
description: import_zod43.z.string(),
|
|
13510
|
+
url: import_zod43.z.string().optional(),
|
|
13511
|
+
targetFieldIds: import_zod43.z.array(import_zod43.z.string())
|
|
13158
13512
|
});
|
|
13159
|
-
var ReplyIntentSchema =
|
|
13160
|
-
primaryIntent:
|
|
13161
|
-
hasAnswers:
|
|
13162
|
-
questionText:
|
|
13163
|
-
questionFieldIds:
|
|
13164
|
-
lookupRequests:
|
|
13513
|
+
var ReplyIntentSchema = import_zod43.z.object({
|
|
13514
|
+
primaryIntent: import_zod43.z.enum(["answers_only", "question", "lookup_request", "mixed"]),
|
|
13515
|
+
hasAnswers: import_zod43.z.boolean(),
|
|
13516
|
+
questionText: import_zod43.z.string().optional(),
|
|
13517
|
+
questionFieldIds: import_zod43.z.array(import_zod43.z.string()).optional(),
|
|
13518
|
+
lookupRequests: import_zod43.z.array(LookupRequestSchema).optional()
|
|
13165
13519
|
});
|
|
13166
|
-
var ParsedAnswerSchema =
|
|
13167
|
-
fieldId:
|
|
13168
|
-
value:
|
|
13169
|
-
explanation:
|
|
13520
|
+
var ParsedAnswerSchema = import_zod43.z.object({
|
|
13521
|
+
fieldId: import_zod43.z.string(),
|
|
13522
|
+
value: import_zod43.z.string(),
|
|
13523
|
+
explanation: import_zod43.z.string().optional()
|
|
13170
13524
|
});
|
|
13171
|
-
var AnswerParsingResultSchema =
|
|
13172
|
-
answers:
|
|
13173
|
-
unanswered:
|
|
13525
|
+
var AnswerParsingResultSchema = import_zod43.z.object({
|
|
13526
|
+
answers: import_zod43.z.array(ParsedAnswerSchema),
|
|
13527
|
+
unanswered: import_zod43.z.array(import_zod43.z.string()).describe("Field IDs that were not answered")
|
|
13174
13528
|
});
|
|
13175
|
-
var LookupFillSchema =
|
|
13176
|
-
fieldId:
|
|
13177
|
-
value:
|
|
13178
|
-
source:
|
|
13179
|
-
sourceSpanIds:
|
|
13529
|
+
var LookupFillSchema = import_zod43.z.object({
|
|
13530
|
+
fieldId: import_zod43.z.string(),
|
|
13531
|
+
value: import_zod43.z.string(),
|
|
13532
|
+
source: import_zod43.z.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'"),
|
|
13533
|
+
sourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional()
|
|
13180
13534
|
});
|
|
13181
|
-
var LookupFillResultSchema =
|
|
13182
|
-
fills:
|
|
13183
|
-
unfillable:
|
|
13184
|
-
explanation:
|
|
13535
|
+
var LookupFillResultSchema = import_zod43.z.object({
|
|
13536
|
+
fills: import_zod43.z.array(LookupFillSchema),
|
|
13537
|
+
unfillable: import_zod43.z.array(import_zod43.z.string()),
|
|
13538
|
+
explanation: import_zod43.z.string().optional()
|
|
13185
13539
|
});
|
|
13186
|
-
var FlatPdfPlacementSchema =
|
|
13187
|
-
fieldId:
|
|
13188
|
-
page:
|
|
13189
|
-
x:
|
|
13190
|
-
y:
|
|
13191
|
-
text:
|
|
13192
|
-
fontSize:
|
|
13193
|
-
isCheckmark:
|
|
13540
|
+
var FlatPdfPlacementSchema = import_zod43.z.object({
|
|
13541
|
+
fieldId: import_zod43.z.string(),
|
|
13542
|
+
page: import_zod43.z.number(),
|
|
13543
|
+
x: import_zod43.z.number().describe("Percentage from left edge (0-100)"),
|
|
13544
|
+
y: import_zod43.z.number().describe("Percentage from top edge (0-100)"),
|
|
13545
|
+
text: import_zod43.z.string(),
|
|
13546
|
+
fontSize: import_zod43.z.number().optional(),
|
|
13547
|
+
isCheckmark: import_zod43.z.boolean().optional()
|
|
13194
13548
|
});
|
|
13195
|
-
var AcroFormMappingSchema =
|
|
13196
|
-
fieldId:
|
|
13197
|
-
acroFormName:
|
|
13198
|
-
value:
|
|
13549
|
+
var AcroFormMappingSchema = import_zod43.z.object({
|
|
13550
|
+
fieldId: import_zod43.z.string(),
|
|
13551
|
+
acroFormName: import_zod43.z.string(),
|
|
13552
|
+
value: import_zod43.z.string()
|
|
13199
13553
|
});
|
|
13200
|
-
var QualityGateStatusSchema =
|
|
13201
|
-
var QualitySeveritySchema =
|
|
13202
|
-
var ApplicationQualityIssueSchema =
|
|
13203
|
-
code:
|
|
13554
|
+
var QualityGateStatusSchema = import_zod43.z.enum(["passed", "warning", "failed"]);
|
|
13555
|
+
var QualitySeveritySchema = import_zod43.z.enum(["info", "warning", "blocking"]);
|
|
13556
|
+
var ApplicationQualityIssueSchema = import_zod43.z.object({
|
|
13557
|
+
code: import_zod43.z.string(),
|
|
13204
13558
|
severity: QualitySeveritySchema,
|
|
13205
|
-
message:
|
|
13206
|
-
fieldId:
|
|
13559
|
+
message: import_zod43.z.string(),
|
|
13560
|
+
fieldId: import_zod43.z.string().optional()
|
|
13207
13561
|
});
|
|
13208
|
-
var ApplicationQualityRoundSchema =
|
|
13209
|
-
round:
|
|
13210
|
-
kind:
|
|
13562
|
+
var ApplicationQualityRoundSchema = import_zod43.z.object({
|
|
13563
|
+
round: import_zod43.z.number(),
|
|
13564
|
+
kind: import_zod43.z.string(),
|
|
13211
13565
|
status: QualityGateStatusSchema,
|
|
13212
|
-
summary:
|
|
13566
|
+
summary: import_zod43.z.string().optional()
|
|
13213
13567
|
});
|
|
13214
|
-
var ApplicationQualityArtifactSchema =
|
|
13215
|
-
kind:
|
|
13216
|
-
label:
|
|
13217
|
-
itemCount:
|
|
13568
|
+
var ApplicationQualityArtifactSchema = import_zod43.z.object({
|
|
13569
|
+
kind: import_zod43.z.string(),
|
|
13570
|
+
label: import_zod43.z.string().optional(),
|
|
13571
|
+
itemCount: import_zod43.z.number().optional()
|
|
13218
13572
|
});
|
|
13219
|
-
var ApplicationEmailReviewSchema =
|
|
13220
|
-
issues:
|
|
13573
|
+
var ApplicationEmailReviewSchema = import_zod43.z.object({
|
|
13574
|
+
issues: import_zod43.z.array(ApplicationQualityIssueSchema),
|
|
13221
13575
|
qualityGateStatus: QualityGateStatusSchema
|
|
13222
13576
|
});
|
|
13223
|
-
var ApplicationQualityReportSchema =
|
|
13224
|
-
issues:
|
|
13225
|
-
rounds:
|
|
13226
|
-
artifacts:
|
|
13577
|
+
var ApplicationQualityReportSchema = import_zod43.z.object({
|
|
13578
|
+
issues: import_zod43.z.array(ApplicationQualityIssueSchema),
|
|
13579
|
+
rounds: import_zod43.z.array(ApplicationQualityRoundSchema).optional(),
|
|
13580
|
+
artifacts: import_zod43.z.array(ApplicationQualityArtifactSchema).optional(),
|
|
13227
13581
|
emailReview: ApplicationEmailReviewSchema.optional(),
|
|
13228
13582
|
qualityGateStatus: QualityGateStatusSchema
|
|
13229
13583
|
});
|
|
13230
|
-
var ApplicationContextProposalSchema =
|
|
13231
|
-
id:
|
|
13232
|
-
fieldId:
|
|
13233
|
-
key:
|
|
13234
|
-
value:
|
|
13235
|
-
category:
|
|
13236
|
-
source:
|
|
13237
|
-
confidence:
|
|
13238
|
-
sourceSpanIds:
|
|
13239
|
-
userSourceSpanIds:
|
|
13584
|
+
var ApplicationContextProposalSchema = import_zod43.z.object({
|
|
13585
|
+
id: import_zod43.z.string(),
|
|
13586
|
+
fieldId: import_zod43.z.string().optional(),
|
|
13587
|
+
key: import_zod43.z.string(),
|
|
13588
|
+
value: import_zod43.z.string(),
|
|
13589
|
+
category: import_zod43.z.string(),
|
|
13590
|
+
source: import_zod43.z.enum(["application", "user", "lookup", "policy", "email", "chat", "imessage", "mcp"]),
|
|
13591
|
+
confidence: import_zod43.z.enum(["confirmed", "high", "medium", "low"]),
|
|
13592
|
+
sourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional(),
|
|
13593
|
+
userSourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional()
|
|
13240
13594
|
});
|
|
13241
|
-
var ApplicationPacketAnswerSchema =
|
|
13242
|
-
fieldId:
|
|
13243
|
-
label:
|
|
13244
|
-
section:
|
|
13245
|
-
value:
|
|
13246
|
-
source:
|
|
13247
|
-
confidence:
|
|
13248
|
-
sourceSpanIds:
|
|
13249
|
-
userSourceSpanIds:
|
|
13595
|
+
var ApplicationPacketAnswerSchema = import_zod43.z.object({
|
|
13596
|
+
fieldId: import_zod43.z.string(),
|
|
13597
|
+
label: import_zod43.z.string(),
|
|
13598
|
+
section: import_zod43.z.string(),
|
|
13599
|
+
value: import_zod43.z.string(),
|
|
13600
|
+
source: import_zod43.z.string(),
|
|
13601
|
+
confidence: import_zod43.z.enum(["confirmed", "high", "medium", "low"]).optional(),
|
|
13602
|
+
sourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional(),
|
|
13603
|
+
userSourceSpanIds: import_zod43.z.array(import_zod43.z.string()).optional()
|
|
13250
13604
|
});
|
|
13251
|
-
var ApplicationPacketSchema =
|
|
13252
|
-
id:
|
|
13253
|
-
applicationId:
|
|
13254
|
-
title:
|
|
13255
|
-
status:
|
|
13256
|
-
answers:
|
|
13257
|
-
missingFieldIds:
|
|
13605
|
+
var ApplicationPacketSchema = import_zod43.z.object({
|
|
13606
|
+
id: import_zod43.z.string(),
|
|
13607
|
+
applicationId: import_zod43.z.string(),
|
|
13608
|
+
title: import_zod43.z.string(),
|
|
13609
|
+
status: import_zod43.z.enum(["draft", "broker_ready", "submitted"]),
|
|
13610
|
+
answers: import_zod43.z.array(ApplicationPacketAnswerSchema),
|
|
13611
|
+
missingFieldIds: import_zod43.z.array(import_zod43.z.string()),
|
|
13258
13612
|
qualityReport: ApplicationQualityReportSchema,
|
|
13259
|
-
submissionNotes:
|
|
13260
|
-
createdAt:
|
|
13613
|
+
submissionNotes: import_zod43.z.string().optional(),
|
|
13614
|
+
createdAt: import_zod43.z.number()
|
|
13261
13615
|
});
|
|
13262
|
-
var ApplicationStateSchema =
|
|
13263
|
-
id:
|
|
13264
|
-
pdfBase64:
|
|
13265
|
-
templateId:
|
|
13266
|
-
templateVersion:
|
|
13616
|
+
var ApplicationStateSchema = import_zod43.z.object({
|
|
13617
|
+
id: import_zod43.z.string(),
|
|
13618
|
+
pdfBase64: import_zod43.z.string().optional().describe("Original PDF, omitted after extraction"),
|
|
13619
|
+
templateId: import_zod43.z.string().optional(),
|
|
13620
|
+
templateVersion: import_zod43.z.string().optional(),
|
|
13267
13621
|
templateSnapshot: ApplicationTemplateSchema.optional(),
|
|
13268
|
-
title:
|
|
13269
|
-
applicationType:
|
|
13622
|
+
title: import_zod43.z.string().optional(),
|
|
13623
|
+
applicationType: import_zod43.z.string().nullable().optional(),
|
|
13270
13624
|
questionGraph: ApplicationQuestionGraphSchema.optional(),
|
|
13271
|
-
fields:
|
|
13272
|
-
batches:
|
|
13273
|
-
currentBatchIndex:
|
|
13274
|
-
contextProposals:
|
|
13625
|
+
fields: import_zod43.z.array(ApplicationFieldSchema),
|
|
13626
|
+
batches: import_zod43.z.array(import_zod43.z.array(import_zod43.z.string())).optional(),
|
|
13627
|
+
currentBatchIndex: import_zod43.z.number().default(0),
|
|
13628
|
+
contextProposals: import_zod43.z.array(ApplicationContextProposalSchema).optional(),
|
|
13275
13629
|
packet: ApplicationPacketSchema.optional(),
|
|
13276
13630
|
qualityReport: ApplicationQualityReportSchema.optional(),
|
|
13277
|
-
status:
|
|
13631
|
+
status: import_zod43.z.enum([
|
|
13278
13632
|
"classifying",
|
|
13279
13633
|
"extracting",
|
|
13280
13634
|
"auto_filling",
|
|
@@ -13288,8 +13642,8 @@ var ApplicationStateSchema = import_zod42.z.object({
|
|
|
13288
13642
|
"cancelled",
|
|
13289
13643
|
"complete"
|
|
13290
13644
|
]),
|
|
13291
|
-
createdAt:
|
|
13292
|
-
updatedAt:
|
|
13645
|
+
createdAt: import_zod43.z.number(),
|
|
13646
|
+
updatedAt: import_zod43.z.number()
|
|
13293
13647
|
});
|
|
13294
13648
|
|
|
13295
13649
|
// src/application/agents/classifier.ts
|
|
@@ -15023,106 +15377,106 @@ Respond with the final answer, deduplicated citations array, overall confidence
|
|
|
15023
15377
|
}
|
|
15024
15378
|
|
|
15025
15379
|
// src/schemas/query.ts
|
|
15026
|
-
var
|
|
15027
|
-
var QueryIntentSchema =
|
|
15380
|
+
var import_zod44 = require("zod");
|
|
15381
|
+
var QueryIntentSchema = import_zod44.z.enum([
|
|
15028
15382
|
"policy_question",
|
|
15029
15383
|
"coverage_comparison",
|
|
15030
15384
|
"document_search",
|
|
15031
15385
|
"claims_inquiry",
|
|
15032
15386
|
"general_knowledge"
|
|
15033
15387
|
]);
|
|
15034
|
-
var QueryAttachmentKindSchema =
|
|
15035
|
-
var QueryAttachmentSchema =
|
|
15036
|
-
id:
|
|
15388
|
+
var QueryAttachmentKindSchema = import_zod44.z.enum(["image", "pdf", "text"]);
|
|
15389
|
+
var QueryAttachmentSchema = import_zod44.z.object({
|
|
15390
|
+
id: import_zod44.z.string().optional().describe("Optional stable attachment ID from the caller"),
|
|
15037
15391
|
kind: QueryAttachmentKindSchema,
|
|
15038
|
-
name:
|
|
15039
|
-
mimeType:
|
|
15040
|
-
base64:
|
|
15041
|
-
text:
|
|
15042
|
-
description:
|
|
15392
|
+
name: import_zod44.z.string().optional().describe("Original filename or user-facing label"),
|
|
15393
|
+
mimeType: import_zod44.z.string().optional().describe("MIME type such as image/jpeg or application/pdf"),
|
|
15394
|
+
base64: import_zod44.z.string().optional().describe("Base64-encoded file content for image/pdf attachments"),
|
|
15395
|
+
text: import_zod44.z.string().optional().describe("Plain-text attachment content when available"),
|
|
15396
|
+
description: import_zod44.z.string().optional().describe("Caller-provided description of the attachment")
|
|
15043
15397
|
});
|
|
15044
|
-
var QueryRetrievalModeSchema =
|
|
15398
|
+
var QueryRetrievalModeSchema = import_zod44.z.enum([
|
|
15045
15399
|
"graph_only",
|
|
15046
15400
|
"source_rag",
|
|
15047
15401
|
"long_context",
|
|
15048
15402
|
"hybrid"
|
|
15049
15403
|
]);
|
|
15050
|
-
var SubQuestionSchema =
|
|
15051
|
-
question:
|
|
15404
|
+
var SubQuestionSchema = import_zod44.z.object({
|
|
15405
|
+
question: import_zod44.z.string().describe("Atomic sub-question to retrieve and answer independently"),
|
|
15052
15406
|
intent: QueryIntentSchema,
|
|
15053
|
-
chunkTypes:
|
|
15054
|
-
documentFilters:
|
|
15055
|
-
type:
|
|
15056
|
-
carrier:
|
|
15057
|
-
insuredName:
|
|
15058
|
-
policyNumber:
|
|
15059
|
-
quoteNumber:
|
|
15060
|
-
policyTypes:
|
|
15407
|
+
chunkTypes: import_zod44.z.array(import_zod44.z.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
|
|
15408
|
+
documentFilters: import_zod44.z.object({
|
|
15409
|
+
type: import_zod44.z.enum(["policy", "quote"]).optional(),
|
|
15410
|
+
carrier: import_zod44.z.string().optional(),
|
|
15411
|
+
insuredName: import_zod44.z.string().optional(),
|
|
15412
|
+
policyNumber: import_zod44.z.string().optional(),
|
|
15413
|
+
quoteNumber: import_zod44.z.string().optional(),
|
|
15414
|
+
policyTypes: import_zod44.z.array(PolicyTypeSchema).optional().describe("Filter by policy type (e.g. homeowners_ho3, renters_ho4, pet) to avoid mixing up similar policies")
|
|
15061
15415
|
}).optional().describe("Structured filters to narrow document lookup")
|
|
15062
15416
|
});
|
|
15063
|
-
var QueryClassifyResultSchema =
|
|
15417
|
+
var QueryClassifyResultSchema = import_zod44.z.object({
|
|
15064
15418
|
intent: QueryIntentSchema,
|
|
15065
|
-
subQuestions:
|
|
15066
|
-
requiresDocumentLookup:
|
|
15067
|
-
requiresChunkSearch:
|
|
15068
|
-
requiresConversationHistory:
|
|
15419
|
+
subQuestions: import_zod44.z.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
|
|
15420
|
+
requiresDocumentLookup: import_zod44.z.boolean().describe("Whether structured document lookup is needed"),
|
|
15421
|
+
requiresChunkSearch: import_zod44.z.boolean().describe("Whether semantic chunk search is needed"),
|
|
15422
|
+
requiresConversationHistory: import_zod44.z.boolean().describe("Whether conversation history is relevant"),
|
|
15069
15423
|
retrievalMode: QueryRetrievalModeSchema.optional().describe("Preferred retrieval strategy for the query when source-span retrieval is available")
|
|
15070
15424
|
});
|
|
15071
|
-
var EvidenceItemSchema =
|
|
15072
|
-
source:
|
|
15073
|
-
chunkId:
|
|
15074
|
-
sourceNodeId:
|
|
15075
|
-
sourceSpanId:
|
|
15076
|
-
documentId:
|
|
15077
|
-
turnId:
|
|
15078
|
-
attachmentId:
|
|
15079
|
-
text:
|
|
15080
|
-
relevance:
|
|
15425
|
+
var EvidenceItemSchema = import_zod44.z.object({
|
|
15426
|
+
source: import_zod44.z.enum(["chunk", "document", "conversation", "attachment", "source_span", "source_node"]),
|
|
15427
|
+
chunkId: import_zod44.z.string().optional(),
|
|
15428
|
+
sourceNodeId: import_zod44.z.string().optional(),
|
|
15429
|
+
sourceSpanId: import_zod44.z.string().optional(),
|
|
15430
|
+
documentId: import_zod44.z.string().optional(),
|
|
15431
|
+
turnId: import_zod44.z.string().optional(),
|
|
15432
|
+
attachmentId: import_zod44.z.string().optional(),
|
|
15433
|
+
text: import_zod44.z.string().describe("Text excerpt from the source"),
|
|
15434
|
+
relevance: import_zod44.z.number().min(0).max(1),
|
|
15081
15435
|
retrievalMode: QueryRetrievalModeSchema.optional(),
|
|
15082
15436
|
sourceLocation: SourceSpanLocationSchema.optional(),
|
|
15083
|
-
metadata:
|
|
15437
|
+
metadata: import_zod44.z.array(import_zod44.z.object({ key: import_zod44.z.string(), value: import_zod44.z.string() })).optional()
|
|
15084
15438
|
});
|
|
15085
|
-
var AttachmentInterpretationSchema =
|
|
15086
|
-
summary:
|
|
15087
|
-
extractedFacts:
|
|
15088
|
-
recommendedFocus:
|
|
15089
|
-
confidence:
|
|
15439
|
+
var AttachmentInterpretationSchema = import_zod44.z.object({
|
|
15440
|
+
summary: import_zod44.z.string().describe("Concise summary of what the attachment shows or contains"),
|
|
15441
|
+
extractedFacts: import_zod44.z.array(import_zod44.z.string()).describe("Specific observable or document facts grounded in the attachment"),
|
|
15442
|
+
recommendedFocus: import_zod44.z.array(import_zod44.z.string()).describe("Important details to incorporate when answering follow-up questions"),
|
|
15443
|
+
confidence: import_zod44.z.number().min(0).max(1)
|
|
15090
15444
|
});
|
|
15091
|
-
var RetrievalResultSchema =
|
|
15092
|
-
subQuestion:
|
|
15093
|
-
evidence:
|
|
15445
|
+
var RetrievalResultSchema = import_zod44.z.object({
|
|
15446
|
+
subQuestion: import_zod44.z.string(),
|
|
15447
|
+
evidence: import_zod44.z.array(EvidenceItemSchema)
|
|
15094
15448
|
});
|
|
15095
|
-
var CitationSchema =
|
|
15096
|
-
index:
|
|
15097
|
-
chunkId:
|
|
15098
|
-
sourceNodeId:
|
|
15099
|
-
sourceSpanId:
|
|
15100
|
-
documentId:
|
|
15101
|
-
documentType:
|
|
15102
|
-
field:
|
|
15103
|
-
quote:
|
|
15104
|
-
relevance:
|
|
15449
|
+
var CitationSchema = import_zod44.z.object({
|
|
15450
|
+
index: import_zod44.z.number().describe("Citation number [1], [2], etc."),
|
|
15451
|
+
chunkId: import_zod44.z.string().optional().describe("Source chunk ID, e.g. doc-123:coverage:2"),
|
|
15452
|
+
sourceNodeId: import_zod44.z.string().optional().describe("Source tree node ID when available"),
|
|
15453
|
+
sourceSpanId: import_zod44.z.string().optional().describe("Precise source span ID when available"),
|
|
15454
|
+
documentId: import_zod44.z.string(),
|
|
15455
|
+
documentType: import_zod44.z.enum(["policy", "quote"]).optional(),
|
|
15456
|
+
field: import_zod44.z.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
|
|
15457
|
+
quote: import_zod44.z.string().describe("Exact text from source that supports the claim"),
|
|
15458
|
+
relevance: import_zod44.z.number().min(0).max(1),
|
|
15105
15459
|
retrievalMode: QueryRetrievalModeSchema.optional(),
|
|
15106
15460
|
sourceLocation: SourceSpanLocationSchema.optional()
|
|
15107
15461
|
});
|
|
15108
|
-
var SubAnswerSchema =
|
|
15109
|
-
subQuestion:
|
|
15110
|
-
answer:
|
|
15111
|
-
citations:
|
|
15112
|
-
confidence:
|
|
15113
|
-
needsMoreContext:
|
|
15462
|
+
var SubAnswerSchema = import_zod44.z.object({
|
|
15463
|
+
subQuestion: import_zod44.z.string(),
|
|
15464
|
+
answer: import_zod44.z.string(),
|
|
15465
|
+
citations: import_zod44.z.array(CitationSchema),
|
|
15466
|
+
confidence: import_zod44.z.number().min(0).max(1),
|
|
15467
|
+
needsMoreContext: import_zod44.z.boolean().describe("True if evidence was insufficient to answer fully")
|
|
15114
15468
|
});
|
|
15115
|
-
var VerifyResultSchema =
|
|
15116
|
-
approved:
|
|
15117
|
-
issues:
|
|
15118
|
-
retrySubQuestions:
|
|
15469
|
+
var VerifyResultSchema = import_zod44.z.object({
|
|
15470
|
+
approved: import_zod44.z.boolean().describe("Whether all sub-answers are adequately grounded"),
|
|
15471
|
+
issues: import_zod44.z.array(import_zod44.z.string()).describe("Specific grounding or consistency issues found"),
|
|
15472
|
+
retrySubQuestions: import_zod44.z.array(import_zod44.z.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
|
|
15119
15473
|
});
|
|
15120
|
-
var QueryResultSchema =
|
|
15121
|
-
answer:
|
|
15122
|
-
citations:
|
|
15474
|
+
var QueryResultSchema = import_zod44.z.object({
|
|
15475
|
+
answer: import_zod44.z.string(),
|
|
15476
|
+
citations: import_zod44.z.array(CitationSchema),
|
|
15123
15477
|
intent: QueryIntentSchema,
|
|
15124
|
-
confidence:
|
|
15125
|
-
followUp:
|
|
15478
|
+
confidence: import_zod44.z.number().min(0).max(1),
|
|
15479
|
+
followUp: import_zod44.z.string().optional().describe("Suggested follow-up question if applicable")
|
|
15126
15480
|
});
|
|
15127
15481
|
|
|
15128
15482
|
// src/query/retriever.ts
|
|
@@ -16189,7 +16543,7 @@ ${sa.answer}`).join("\n\n"),
|
|
|
16189
16543
|
}
|
|
16190
16544
|
|
|
16191
16545
|
// src/pce/index.ts
|
|
16192
|
-
var
|
|
16546
|
+
var import_zod45 = require("zod");
|
|
16193
16547
|
|
|
16194
16548
|
// src/prompts/pce/index.ts
|
|
16195
16549
|
function buildPceNormalizePrompt(input) {
|
|
@@ -16223,11 +16577,11 @@ ${input.openQuestions.map((question) => `- ${question.id}${question.fieldPath ?
|
|
|
16223
16577
|
}
|
|
16224
16578
|
|
|
16225
16579
|
// src/pce/index.ts
|
|
16226
|
-
var ReplyAnswersSchema =
|
|
16227
|
-
answers:
|
|
16228
|
-
questionId:
|
|
16229
|
-
fieldPath:
|
|
16230
|
-
answer:
|
|
16580
|
+
var ReplyAnswersSchema = import_zod45.z.object({
|
|
16581
|
+
answers: import_zod45.z.array(import_zod45.z.object({
|
|
16582
|
+
questionId: import_zod45.z.string().optional(),
|
|
16583
|
+
fieldPath: import_zod45.z.string().optional(),
|
|
16584
|
+
answer: import_zod45.z.string()
|
|
16231
16585
|
}))
|
|
16232
16586
|
});
|
|
16233
16587
|
function createPceAgent(config = {}) {
|