@claritylabs/cl-sdk 0.10.3 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +762 -313
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +762 -313
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1814,6 +1814,358 @@ async function runExtractor(params) {
|
|
|
1814
1814
|
};
|
|
1815
1815
|
}
|
|
1816
1816
|
|
|
1817
|
+
// src/extraction/promote.ts
|
|
1818
|
+
function getDeclarationFields(doc) {
|
|
1819
|
+
const decl = doc.declarations;
|
|
1820
|
+
return Array.isArray(decl?.fields) ? decl.fields : [];
|
|
1821
|
+
}
|
|
1822
|
+
function fieldMatches(fieldName, patterns) {
|
|
1823
|
+
const lower = fieldName.toLowerCase().replace(/[\s_-]/g, "");
|
|
1824
|
+
return patterns.some((p) => lower === p.toLowerCase().replace(/[\s_-]/g, ""));
|
|
1825
|
+
}
|
|
1826
|
+
function findFieldValue(fields, patterns) {
|
|
1827
|
+
const match = fields.find((f) => fieldMatches(f.field, patterns));
|
|
1828
|
+
return match?.value;
|
|
1829
|
+
}
|
|
1830
|
+
function promoteCarrierFields(doc) {
|
|
1831
|
+
const raw = doc;
|
|
1832
|
+
if (!raw.carrierNaicNumber && raw.naicNumber) {
|
|
1833
|
+
raw.carrierNaicNumber = raw.naicNumber;
|
|
1834
|
+
}
|
|
1835
|
+
if (!raw.carrierAmBestRating && raw.amBestRating) {
|
|
1836
|
+
raw.carrierAmBestRating = raw.amBestRating;
|
|
1837
|
+
}
|
|
1838
|
+
if (!raw.carrierAdmittedStatus && raw.admittedStatus) {
|
|
1839
|
+
raw.carrierAdmittedStatus = raw.admittedStatus;
|
|
1840
|
+
}
|
|
1841
|
+
delete raw.naicNumber;
|
|
1842
|
+
delete raw.amBestRating;
|
|
1843
|
+
delete raw.admittedStatus;
|
|
1844
|
+
if (!raw.insurer && raw.carrierLegalName) {
|
|
1845
|
+
raw.insurer = {
|
|
1846
|
+
legalName: raw.carrierLegalName,
|
|
1847
|
+
...raw.carrierNaicNumber ? { naicNumber: raw.carrierNaicNumber } : {},
|
|
1848
|
+
...raw.carrierAmBestRating ? { amBestRating: raw.carrierAmBestRating } : {},
|
|
1849
|
+
...raw.carrierAdmittedStatus ? { admittedStatus: raw.carrierAdmittedStatus } : {}
|
|
1850
|
+
};
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
var BROKER_NAME_PATTERNS = [
|
|
1854
|
+
"brokerName",
|
|
1855
|
+
"broker",
|
|
1856
|
+
"agentName",
|
|
1857
|
+
"agent",
|
|
1858
|
+
"producerName",
|
|
1859
|
+
"producerAgency",
|
|
1860
|
+
"agencyName",
|
|
1861
|
+
"brokerAgency"
|
|
1862
|
+
];
|
|
1863
|
+
var BROKER_CONTACT_PATTERNS = [
|
|
1864
|
+
"brokerContactName",
|
|
1865
|
+
"brokerContact",
|
|
1866
|
+
"agentContactName",
|
|
1867
|
+
"producerContactName",
|
|
1868
|
+
"producerContact"
|
|
1869
|
+
];
|
|
1870
|
+
var BROKER_LICENSE_PATTERNS = [
|
|
1871
|
+
"brokerLicenseNumber",
|
|
1872
|
+
"brokerNumber",
|
|
1873
|
+
"agentLicenseNumber",
|
|
1874
|
+
"producerLicenseNumber",
|
|
1875
|
+
"producerNumber",
|
|
1876
|
+
"agentNumber"
|
|
1877
|
+
];
|
|
1878
|
+
var BROKER_PHONE_PATTERNS = ["brokerPhone", "agentPhone", "producerPhone"];
|
|
1879
|
+
var BROKER_EMAIL_PATTERNS = ["brokerEmail", "agentEmail", "producerEmail"];
|
|
1880
|
+
var BROKER_ADDRESS_PATTERNS = ["brokerAddress", "agentAddress", "producerAddress"];
|
|
1881
|
+
function promoteBroker(doc) {
|
|
1882
|
+
const raw = doc;
|
|
1883
|
+
const fields = getDeclarationFields(doc);
|
|
1884
|
+
const brokerAgency = raw.brokerAgency || findFieldValue(fields, BROKER_NAME_PATTERNS);
|
|
1885
|
+
const brokerContact = raw.brokerContactName || findFieldValue(fields, BROKER_CONTACT_PATTERNS);
|
|
1886
|
+
const brokerLicense = raw.brokerLicenseNumber || findFieldValue(fields, BROKER_LICENSE_PATTERNS);
|
|
1887
|
+
const brokerPhone = findFieldValue(fields, BROKER_PHONE_PATTERNS);
|
|
1888
|
+
const brokerEmail = findFieldValue(fields, BROKER_EMAIL_PATTERNS);
|
|
1889
|
+
const brokerAddress = findFieldValue(fields, BROKER_ADDRESS_PATTERNS);
|
|
1890
|
+
if (brokerAgency) raw.brokerAgency = brokerAgency;
|
|
1891
|
+
if (brokerContact) raw.brokerContactName = brokerContact;
|
|
1892
|
+
if (brokerLicense) raw.brokerLicenseNumber = brokerLicense;
|
|
1893
|
+
if (!raw.producer && brokerAgency) {
|
|
1894
|
+
raw.producer = {
|
|
1895
|
+
agencyName: brokerAgency,
|
|
1896
|
+
...brokerContact ? { contactName: brokerContact } : {},
|
|
1897
|
+
...brokerLicense ? { licenseNumber: brokerLicense } : {},
|
|
1898
|
+
...brokerPhone ? { phone: brokerPhone } : {},
|
|
1899
|
+
...brokerEmail ? { email: brokerEmail } : {},
|
|
1900
|
+
...brokerAddress ? { address: { street1: brokerAddress } } : {}
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
var LOSS_PAYEE_NAME_PATTERNS = [
|
|
1905
|
+
"lossPayeeName",
|
|
1906
|
+
"lossPayee",
|
|
1907
|
+
"lossPayeeHolder"
|
|
1908
|
+
];
|
|
1909
|
+
var LOSS_PAYEE_ADDRESS_PATTERNS = ["lossPayeeAddress"];
|
|
1910
|
+
var MORTGAGE_HOLDER_NAME_PATTERNS = [
|
|
1911
|
+
"mortgagee",
|
|
1912
|
+
"mortgageHolder",
|
|
1913
|
+
"mortgageHolderName",
|
|
1914
|
+
"mortgageeName",
|
|
1915
|
+
"lienholder",
|
|
1916
|
+
"lienholderName"
|
|
1917
|
+
];
|
|
1918
|
+
var MORTGAGE_HOLDER_ADDRESS_PATTERNS = [
|
|
1919
|
+
"mortgageeAddress",
|
|
1920
|
+
"mortgageHolderAddress",
|
|
1921
|
+
"lienholderAddress"
|
|
1922
|
+
];
|
|
1923
|
+
function promoteLossPayees(doc) {
|
|
1924
|
+
const raw = doc;
|
|
1925
|
+
const fields = getDeclarationFields(doc);
|
|
1926
|
+
if (!raw.lossPayees || Array.isArray(raw.lossPayees) && raw.lossPayees.length === 0) {
|
|
1927
|
+
const name = findFieldValue(fields, LOSS_PAYEE_NAME_PATTERNS);
|
|
1928
|
+
if (name) {
|
|
1929
|
+
const address = findFieldValue(fields, LOSS_PAYEE_ADDRESS_PATTERNS);
|
|
1930
|
+
raw.lossPayees = [{
|
|
1931
|
+
name,
|
|
1932
|
+
role: "loss_payee",
|
|
1933
|
+
...address ? { address: { street1: address } } : {}
|
|
1934
|
+
}];
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
if (!raw.mortgageHolders || Array.isArray(raw.mortgageHolders) && raw.mortgageHolders.length === 0) {
|
|
1938
|
+
const name = findFieldValue(fields, MORTGAGE_HOLDER_NAME_PATTERNS);
|
|
1939
|
+
if (name) {
|
|
1940
|
+
const address = findFieldValue(fields, MORTGAGE_HOLDER_ADDRESS_PATTERNS);
|
|
1941
|
+
raw.mortgageHolders = [{
|
|
1942
|
+
name,
|
|
1943
|
+
role: "mortgage_holder",
|
|
1944
|
+
...address ? { address: { street1: address } } : {}
|
|
1945
|
+
}];
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
function promoteLocations(doc) {
|
|
1950
|
+
const raw = doc;
|
|
1951
|
+
if (Array.isArray(raw.locations) && raw.locations.length > 0) return;
|
|
1952
|
+
const fields = getDeclarationFields(doc);
|
|
1953
|
+
if (fields.length === 0) return;
|
|
1954
|
+
const locationGroups = /* @__PURE__ */ new Map();
|
|
1955
|
+
for (const f of fields) {
|
|
1956
|
+
const lower = f.field.toLowerCase().replace(/[\s_-]/g, "");
|
|
1957
|
+
if (lower.includes("locationnumber") || lower.includes("locnumber") || lower.includes("locno")) {
|
|
1958
|
+
const key = f.value;
|
|
1959
|
+
if (!locationGroups.has(key)) locationGroups.set(key, /* @__PURE__ */ new Map());
|
|
1960
|
+
locationGroups.get(key).set("number", f.value);
|
|
1961
|
+
continue;
|
|
1962
|
+
}
|
|
1963
|
+
if (lower.includes("buildingnumber") || lower.includes("bldgnumber") || lower.includes("bldgno")) {
|
|
1964
|
+
const lastKey2 = [...locationGroups.keys()].pop();
|
|
1965
|
+
if (lastKey2) locationGroups.get(lastKey2).set("buildingNumber", f.value);
|
|
1966
|
+
continue;
|
|
1967
|
+
}
|
|
1968
|
+
const section = (f.section ?? "").toLowerCase();
|
|
1969
|
+
const isLocationField = section.includes("location") || section.includes("building") || section.includes("premises") || section.includes("schedule of locations");
|
|
1970
|
+
if (!isLocationField) continue;
|
|
1971
|
+
if (locationGroups.size === 0) {
|
|
1972
|
+
locationGroups.set("1", /* @__PURE__ */ new Map([["number", "1"]]));
|
|
1973
|
+
}
|
|
1974
|
+
const lastKey = [...locationGroups.keys()].pop();
|
|
1975
|
+
const group = locationGroups.get(lastKey);
|
|
1976
|
+
if (lower.includes("construction") || lower.includes("constructiontype")) {
|
|
1977
|
+
group.set("constructionType", f.value);
|
|
1978
|
+
} else if (lower.includes("occupancy") || lower.includes("occupancytype")) {
|
|
1979
|
+
group.set("occupancy", f.value);
|
|
1980
|
+
} else if (lower.includes("yearbuilt")) {
|
|
1981
|
+
group.set("yearBuilt", f.value);
|
|
1982
|
+
} else if (lower.includes("squarefootage") || lower.includes("sqft") || lower.includes("area")) {
|
|
1983
|
+
group.set("squareFootage", f.value);
|
|
1984
|
+
} else if (lower.includes("protectionclass") || lower.includes("fireprotection")) {
|
|
1985
|
+
group.set("protectionClass", f.value);
|
|
1986
|
+
} else if (lower.includes("sprinkler")) {
|
|
1987
|
+
group.set("sprinklered", f.value);
|
|
1988
|
+
} else if (lower.includes("buildingvalue") || lower.includes("buildingamt") || lower.includes("buildingcoverage")) {
|
|
1989
|
+
group.set("buildingValue", f.value);
|
|
1990
|
+
} else if (lower.includes("contentsvalue") || lower.includes("contentsamt") || lower.includes("contentscoverage")) {
|
|
1991
|
+
group.set("contentsValue", f.value);
|
|
1992
|
+
} else if (lower.includes("businessincome") || lower.includes("bivalue") || lower.includes("businessincomevalue")) {
|
|
1993
|
+
group.set("businessIncomeValue", f.value);
|
|
1994
|
+
} else if (lower.includes("description") || lower.includes("buildingdescription") || lower.includes("locationdescription")) {
|
|
1995
|
+
group.set("description", f.value);
|
|
1996
|
+
} else if (lower.includes("address") || lower.includes("industryaddress") || lower.includes("locationaddress") || lower.includes("premisesaddress")) {
|
|
1997
|
+
group.set("address", f.value);
|
|
1998
|
+
} else if (lower.includes("alarm") || lower.includes("alarmtype")) {
|
|
1999
|
+
group.set("alarmType", f.value);
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
if (locationGroups.size === 0) return;
|
|
2003
|
+
const locations = [];
|
|
2004
|
+
for (const [, group] of locationGroups) {
|
|
2005
|
+
const num = parseInt(group.get("number") ?? "0", 10) || locations.length + 1;
|
|
2006
|
+
const addressStr = group.get("address");
|
|
2007
|
+
locations.push({
|
|
2008
|
+
number: num,
|
|
2009
|
+
address: addressStr ? { street1: addressStr } : { street1: "See declarations" },
|
|
2010
|
+
...group.get("description") ? { description: group.get("description") } : {},
|
|
2011
|
+
...group.get("constructionType") ? { constructionType: group.get("constructionType") } : {},
|
|
2012
|
+
...group.get("occupancy") ? { occupancy: group.get("occupancy") } : {},
|
|
2013
|
+
...group.get("yearBuilt") ? { yearBuilt: parseInt(group.get("yearBuilt"), 10) || void 0 } : {},
|
|
2014
|
+
...group.get("squareFootage") ? { squareFootage: parseInt(group.get("squareFootage").replace(/[^0-9]/g, ""), 10) || void 0 } : {},
|
|
2015
|
+
...group.get("protectionClass") ? { protectionClass: group.get("protectionClass") } : {},
|
|
2016
|
+
...group.get("sprinklered") ? { sprinklered: /yes|true/i.test(group.get("sprinklered")) } : {},
|
|
2017
|
+
...group.get("buildingValue") ? { buildingValue: group.get("buildingValue") } : {},
|
|
2018
|
+
...group.get("contentsValue") ? { contentsValue: group.get("contentsValue") } : {},
|
|
2019
|
+
...group.get("businessIncomeValue") ? { businessIncomeValue: group.get("businessIncomeValue") } : {},
|
|
2020
|
+
...group.get("alarmType") ? { alarmType: group.get("alarmType") } : {}
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
if (locations.length > 0) {
|
|
2024
|
+
raw.locations = locations;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
function normalizeName(name) {
|
|
2028
|
+
return name.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
2029
|
+
}
|
|
2030
|
+
var LIMIT_COVERAGE_MAP = [
|
|
2031
|
+
// GL standard
|
|
2032
|
+
[["eachoccurrence", "peroccurrence", "occurrencecombined"], "perOccurrence"],
|
|
2033
|
+
[["generalaggregate"], "generalAggregate"],
|
|
2034
|
+
[["productscompletedoperationsaggregate", "productscompletedopsaggregate", "prodcompopsagg"], "productsCompletedOpsAggregate"],
|
|
2035
|
+
[["personaladvertisinginjury", "personaladvinjury", "pai"], "personalAdvertisingInjury"],
|
|
2036
|
+
[["firedamage", "firedamagelegalliability", "damagetorentedpremises", "damagetopremisesrentedtoyou"], "fireDamage"],
|
|
2037
|
+
[["medicalexpense", "medexp", "medicalexpenseanypersonanyperson", "medicalexpenseanyone"], "medicalExpense"],
|
|
2038
|
+
// Auto
|
|
2039
|
+
[["combinedsingle", "combinedsinglelimit", "csl"], "combinedSingleLimit"],
|
|
2040
|
+
[["bodilyinjuryperperson", "biperperson"], "bodilyInjuryPerPerson"],
|
|
2041
|
+
[["bodilyinjuryperaccident", "biperaccident"], "bodilyInjuryPerAccident"],
|
|
2042
|
+
[["propertydamage", "pdperaccident"], "propertyDamage"],
|
|
2043
|
+
// Umbrella/Excess
|
|
2044
|
+
[["umbrellaoccurrence", "eachoccurrenceumbrella", "excessoccurrence", "excesseachoccurrence"], "eachOccurrenceUmbrella"],
|
|
2045
|
+
[["umbrellaaggregate", "excessaggregate"], "umbrellaAggregate"],
|
|
2046
|
+
[["umbrella retention", "selfinsuredretention", "sir", "excessretention"], "umbrellaRetention"]
|
|
2047
|
+
];
|
|
2048
|
+
function synthesizeLimits(doc) {
|
|
2049
|
+
const raw = doc;
|
|
2050
|
+
if (raw.limits && typeof raw.limits === "object" && Object.keys(raw.limits).length > 0) return;
|
|
2051
|
+
const coverages = doc.coverages;
|
|
2052
|
+
if (!coverages || coverages.length === 0) return;
|
|
2053
|
+
const limits = {};
|
|
2054
|
+
for (const cov of coverages) {
|
|
2055
|
+
if (!cov.name || !cov.limit) continue;
|
|
2056
|
+
const normalized = normalizeName(cov.name);
|
|
2057
|
+
for (const [patterns, fieldName] of LIMIT_COVERAGE_MAP) {
|
|
2058
|
+
if (patterns.some((p) => normalized.includes(p) || p.includes(normalized))) {
|
|
2059
|
+
if (fieldName.includes("Aggregate") || fieldName.includes("aggregate")) {
|
|
2060
|
+
if (!cov.limitType || cov.limitType === "aggregate") {
|
|
2061
|
+
limits[fieldName] = cov.limit;
|
|
2062
|
+
}
|
|
2063
|
+
} else {
|
|
2064
|
+
if (!limits[fieldName]) {
|
|
2065
|
+
limits[fieldName] = cov.limit;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
break;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
const hasStatutory = coverages.some(
|
|
2073
|
+
(c) => c.limitType === "statutory" || normalizeName(c.name ?? "").includes("statutory")
|
|
2074
|
+
);
|
|
2075
|
+
if (hasStatutory) {
|
|
2076
|
+
limits.statutory = "true";
|
|
2077
|
+
}
|
|
2078
|
+
const elCoverages = coverages.filter(
|
|
2079
|
+
(c) => normalizeName(c.name ?? "").includes("employersliability")
|
|
2080
|
+
);
|
|
2081
|
+
if (elCoverages.length > 0) {
|
|
2082
|
+
const el = {};
|
|
2083
|
+
for (const c of elCoverages) {
|
|
2084
|
+
if (!c.limit) continue;
|
|
2085
|
+
const n = normalizeName(c.name ?? "");
|
|
2086
|
+
if (n.includes("accident") || n.includes("eachaccident")) el.eachAccident = c.limit;
|
|
2087
|
+
else if (n.includes("diseasepolicy") || n.includes("diseasepolicylimit")) el.diseasePolicyLimit = c.limit;
|
|
2088
|
+
else if (n.includes("diseaseemployee") || n.includes("diseaseeachemployee")) el.diseaseEachEmployee = c.limit;
|
|
2089
|
+
else if (!el.eachAccident) el.eachAccident = c.limit;
|
|
2090
|
+
}
|
|
2091
|
+
if (Object.keys(el).length > 0) {
|
|
2092
|
+
limits.employersLiability = el;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
if (Object.keys(limits).length > 0) {
|
|
2096
|
+
const result = { ...limits };
|
|
2097
|
+
if (result.statutory === "true") result.statutory = true;
|
|
2098
|
+
raw.limits = result;
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
function synthesizeDeductibles(doc) {
|
|
2102
|
+
const raw = doc;
|
|
2103
|
+
if (raw.deductibles && typeof raw.deductibles === "object" && Object.keys(raw.deductibles).length > 0) return;
|
|
2104
|
+
const coverages = doc.coverages;
|
|
2105
|
+
if (!coverages || coverages.length === 0) return;
|
|
2106
|
+
const deductibleValues = coverages.filter((c) => c.deductible && c.deductible.trim() !== "" && c.deductible !== "N/A" && c.deductible !== "None").map((c) => c.deductible);
|
|
2107
|
+
if (deductibleValues.length === 0) return;
|
|
2108
|
+
const freq = /* @__PURE__ */ new Map();
|
|
2109
|
+
for (const d of deductibleValues) {
|
|
2110
|
+
freq.set(d, (freq.get(d) ?? 0) + 1);
|
|
2111
|
+
}
|
|
2112
|
+
let mostCommon = deductibleValues[0];
|
|
2113
|
+
let maxFreq = 0;
|
|
2114
|
+
for (const [val, count] of freq) {
|
|
2115
|
+
if (count > maxFreq) {
|
|
2116
|
+
mostCommon = val;
|
|
2117
|
+
maxFreq = count;
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
const deductibles = {};
|
|
2121
|
+
const hasPerClaim = coverages.some(
|
|
2122
|
+
(c) => c.deductible && normalizeName(c.name ?? "").includes("perclaim")
|
|
2123
|
+
);
|
|
2124
|
+
if (hasPerClaim) {
|
|
2125
|
+
deductibles.perClaim = mostCommon;
|
|
2126
|
+
} else {
|
|
2127
|
+
deductibles.perOccurrence = mostCommon;
|
|
2128
|
+
}
|
|
2129
|
+
const sirCoverage = coverages.find(
|
|
2130
|
+
(c) => c.deductible && (normalizeName(c.name ?? "").includes("selfinsuredretention") || normalizeName(c.name ?? "").includes("sir"))
|
|
2131
|
+
);
|
|
2132
|
+
if (sirCoverage?.deductible) {
|
|
2133
|
+
deductibles.selfInsuredRetention = sirCoverage.deductible;
|
|
2134
|
+
}
|
|
2135
|
+
const aggDed = coverages.find(
|
|
2136
|
+
(c) => c.deductible && normalizeName(c.name ?? "").includes("aggregatedeductible")
|
|
2137
|
+
);
|
|
2138
|
+
if (aggDed?.deductible) {
|
|
2139
|
+
deductibles.aggregateDeductible = aggDed.deductible;
|
|
2140
|
+
}
|
|
2141
|
+
if (Object.keys(deductibles).length > 0) {
|
|
2142
|
+
raw.deductibles = deductibles;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
var PREMIUM_PATTERNS = ["premium", "totalPremium", "annualPremium", "policyPremium", "basePremium"];
|
|
2146
|
+
var TOTAL_COST_PATTERNS = ["totalCost", "totalDue", "totalAmount", "totalPolicyPremium"];
|
|
2147
|
+
function promotePremium(doc) {
|
|
2148
|
+
const raw = doc;
|
|
2149
|
+
const fields = getDeclarationFields(doc);
|
|
2150
|
+
if (!raw.premium) {
|
|
2151
|
+
const premium = findFieldValue(fields, PREMIUM_PATTERNS);
|
|
2152
|
+
if (premium) raw.premium = premium;
|
|
2153
|
+
}
|
|
2154
|
+
if (!raw.totalCost) {
|
|
2155
|
+
const totalCost = findFieldValue(fields, TOTAL_COST_PATTERNS);
|
|
2156
|
+
if (totalCost) raw.totalCost = totalCost;
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
function promoteExtractedFields(doc) {
|
|
2160
|
+
promoteCarrierFields(doc);
|
|
2161
|
+
promoteBroker(doc);
|
|
2162
|
+
promoteLossPayees(doc);
|
|
2163
|
+
promoteLocations(doc);
|
|
2164
|
+
synthesizeLimits(doc);
|
|
2165
|
+
synthesizeDeductibles(doc);
|
|
2166
|
+
promotePremium(doc);
|
|
2167
|
+
}
|
|
2168
|
+
|
|
1817
2169
|
// src/extraction/assembler.ts
|
|
1818
2170
|
function assembleDocument(documentId, documentType, memory) {
|
|
1819
2171
|
const carrier = memory.get("carrier_info");
|
|
@@ -1837,6 +2189,9 @@ function assembleDocument(documentId, documentType, memory) {
|
|
|
1837
2189
|
policyTypes: classify?.policyTypes,
|
|
1838
2190
|
...sanitizeNulls(carrier ?? {}),
|
|
1839
2191
|
...sanitizeNulls(insured ?? {}),
|
|
2192
|
+
// Map named_insured extractor's loss payees/mortgage holders to EndorsementParty shape
|
|
2193
|
+
...Array.isArray(insured?.lossPayees) && insured.lossPayees.length > 0 ? { lossPayees: insured.lossPayees.map((lp) => ({ ...lp, role: "loss_payee" })) } : {},
|
|
2194
|
+
...Array.isArray(insured?.mortgageHolders) && insured.mortgageHolders.length > 0 ? { mortgageHolders: insured.mortgageHolders.map((mh) => ({ ...mh, role: "mortgage_holder" })) } : {},
|
|
1840
2195
|
...sanitizeNulls(coverages ?? {}),
|
|
1841
2196
|
...sanitizeNulls(premium ?? {}),
|
|
1842
2197
|
...sanitizeNulls(supplementary ?? {}),
|
|
@@ -1848,8 +2203,9 @@ function assembleDocument(documentId, documentType, memory) {
|
|
|
1848
2203
|
declarations: declarations ? sanitizeNulls(declarations) : void 0,
|
|
1849
2204
|
...sanitizeNulls(lossHistory ?? {})
|
|
1850
2205
|
};
|
|
2206
|
+
let doc;
|
|
1851
2207
|
if (documentType === "policy") {
|
|
1852
|
-
|
|
2208
|
+
doc = {
|
|
1853
2209
|
...base,
|
|
1854
2210
|
type: "policy",
|
|
1855
2211
|
policyNumber: carrier?.policyNumber ?? insured?.policyNumber ?? "Unknown",
|
|
@@ -1857,17 +2213,20 @@ function assembleDocument(documentId, documentType, memory) {
|
|
|
1857
2213
|
expirationDate: carrier?.expirationDate,
|
|
1858
2214
|
policyTermType: carrier?.policyTermType
|
|
1859
2215
|
};
|
|
2216
|
+
} else {
|
|
2217
|
+
doc = {
|
|
2218
|
+
...base,
|
|
2219
|
+
type: "quote",
|
|
2220
|
+
quoteNumber: carrier?.quoteNumber ?? "Unknown",
|
|
2221
|
+
proposedEffectiveDate: carrier?.proposedEffectiveDate,
|
|
2222
|
+
proposedExpirationDate: carrier?.proposedExpirationDate,
|
|
2223
|
+
subjectivities: coverages?.subjectivities,
|
|
2224
|
+
underwritingConditions: coverages?.underwritingConditions,
|
|
2225
|
+
premiumBreakdown: premium?.premiumBreakdown
|
|
2226
|
+
};
|
|
1860
2227
|
}
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
type: "quote",
|
|
1864
|
-
quoteNumber: carrier?.quoteNumber ?? "Unknown",
|
|
1865
|
-
proposedEffectiveDate: carrier?.proposedEffectiveDate,
|
|
1866
|
-
proposedExpirationDate: carrier?.proposedExpirationDate,
|
|
1867
|
-
subjectivities: coverages?.subjectivities,
|
|
1868
|
-
underwritingConditions: coverages?.underwritingConditions,
|
|
1869
|
-
premiumBreakdown: premium?.premiumBreakdown
|
|
1870
|
-
};
|
|
2228
|
+
promoteExtractedFields(doc);
|
|
2229
|
+
return doc;
|
|
1871
2230
|
}
|
|
1872
2231
|
|
|
1873
2232
|
// src/prompts/coordinator/format.ts
|
|
@@ -3301,21 +3660,69 @@ Use the page map to target follow-up extraction pages precisely. Prefer narrow,
|
|
|
3301
3660
|
Respond with JSON only.`;
|
|
3302
3661
|
}
|
|
3303
3662
|
|
|
3304
|
-
// src/prompts/
|
|
3663
|
+
// src/prompts/coordinator/summarize.ts
|
|
3305
3664
|
var import_zod22 = require("zod");
|
|
3306
|
-
var
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3665
|
+
var SummaryResultSchema = import_zod22.z.object({
|
|
3666
|
+
summary: import_zod22.z.string().describe("A 1-3 sentence overview of this insurance document")
|
|
3667
|
+
});
|
|
3668
|
+
function buildSummaryPrompt(doc) {
|
|
3669
|
+
const snapshot = {
|
|
3670
|
+
type: doc.type,
|
|
3671
|
+
carrier: doc.carrier,
|
|
3672
|
+
insuredName: doc.insuredName,
|
|
3673
|
+
policyTypes: doc.policyTypes,
|
|
3674
|
+
premium: doc.premium,
|
|
3675
|
+
coverageCount: doc.coverages?.length ?? 0
|
|
3676
|
+
};
|
|
3677
|
+
if (doc.type === "policy") {
|
|
3678
|
+
snapshot.policyNumber = doc.policyNumber;
|
|
3679
|
+
snapshot.effectiveDate = doc.effectiveDate;
|
|
3680
|
+
snapshot.expirationDate = doc.expirationDate;
|
|
3681
|
+
} else {
|
|
3682
|
+
snapshot.quoteNumber = doc.quoteNumber;
|
|
3683
|
+
snapshot.proposedEffectiveDate = doc.proposedEffectiveDate;
|
|
3684
|
+
}
|
|
3685
|
+
const raw = doc;
|
|
3686
|
+
if (raw.limits) snapshot.limits = raw.limits;
|
|
3687
|
+
if (raw.deductibles) snapshot.deductibles = raw.deductibles;
|
|
3688
|
+
if (raw.brokerAgency) snapshot.brokerAgency = raw.brokerAgency;
|
|
3689
|
+
if (doc.endorsements?.length) snapshot.endorsementCount = doc.endorsements.length;
|
|
3690
|
+
if (doc.exclusions?.length) snapshot.exclusionCount = doc.exclusions.length;
|
|
3691
|
+
if (doc.coverages?.length) {
|
|
3692
|
+
snapshot.topCoverages = doc.coverages.slice(0, 5).map((c) => c.name);
|
|
3693
|
+
}
|
|
3694
|
+
return `You are an expert insurance document analyst. Generate a brief summary of this insurance document.
|
|
3695
|
+
|
|
3696
|
+
Write 1-3 sentences that capture the essential facts a broker or underwriter would want at a glance:
|
|
3697
|
+
- Who is insured and by whom
|
|
3698
|
+
- What type of policy/quote and the key coverages
|
|
3699
|
+
- Policy period and premium if available
|
|
3700
|
+
- Any notable features (high limits, unusual exclusions, etc.)
|
|
3701
|
+
|
|
3702
|
+
Document data:
|
|
3703
|
+
${JSON.stringify(snapshot, null, 2)}
|
|
3704
|
+
|
|
3705
|
+
Return JSON only with a "summary" field.`;
|
|
3706
|
+
}
|
|
3707
|
+
|
|
3708
|
+
// src/prompts/extractors/carrier-info.ts
|
|
3709
|
+
var import_zod23 = require("zod");
|
|
3710
|
+
var CarrierInfoSchema = import_zod23.z.object({
|
|
3711
|
+
carrierName: import_zod23.z.string().describe("Primary insurance company name for display"),
|
|
3712
|
+
carrierLegalName: import_zod23.z.string().optional().describe("Legal entity name of insurer"),
|
|
3713
|
+
naicNumber: import_zod23.z.string().optional().describe("NAIC company code"),
|
|
3714
|
+
amBestRating: import_zod23.z.string().optional().describe("AM Best rating, e.g. 'A+ XV'"),
|
|
3715
|
+
admittedStatus: import_zod23.z.enum(["admitted", "non_admitted", "surplus_lines"]).optional().describe("Admitted status of the carrier"),
|
|
3716
|
+
mga: import_zod23.z.string().optional().describe("Managing General Agent or Program Administrator name"),
|
|
3717
|
+
underwriter: import_zod23.z.string().optional().describe("Named individual underwriter"),
|
|
3718
|
+
brokerAgency: import_zod23.z.string().optional().describe("Broker or producer agency name"),
|
|
3719
|
+
brokerContactName: import_zod23.z.string().optional().describe("Broker or producer contact person name"),
|
|
3720
|
+
brokerLicenseNumber: import_zod23.z.string().optional().describe("Broker or producer license number"),
|
|
3721
|
+
policyNumber: import_zod23.z.string().optional().describe("Policy or quote reference number"),
|
|
3722
|
+
effectiveDate: import_zod23.z.string().optional().describe("Policy effective date (MM/DD/YYYY)"),
|
|
3723
|
+
expirationDate: import_zod23.z.string().optional().describe("Policy expiration date (MM/DD/YYYY)"),
|
|
3724
|
+
quoteNumber: import_zod23.z.string().optional().describe("Quote or proposal reference number"),
|
|
3725
|
+
proposedEffectiveDate: import_zod23.z.string().optional().describe("Proposed effective date for quotes (MM/DD/YYYY)")
|
|
3319
3726
|
});
|
|
3320
3727
|
function buildCarrierInfoPrompt() {
|
|
3321
3728
|
return `You are an expert insurance document analyst. Extract carrier and policy identification information from this document.
|
|
@@ -3326,27 +3733,30 @@ Focus on:
|
|
|
3326
3733
|
- Whether the carrier is admitted, non-admitted, or surplus lines
|
|
3327
3734
|
- Managing General Agent (MGA) or Program Administrator if applicable
|
|
3328
3735
|
- Named individual underwriter if listed
|
|
3736
|
+
- Broker/producer/agent: agency name, contact person name, and license number
|
|
3329
3737
|
- Policy number and effective/expiration dates
|
|
3330
3738
|
- For quotes: quote number and proposed effective date
|
|
3331
3739
|
|
|
3332
3740
|
For carrier vs. security distinction: "carrier" is the primary company name; the legal entity on risk (e.g. "Lloyd's Underwriters") may differ from the display name.
|
|
3333
3741
|
|
|
3742
|
+
Look for broker/producer/agent information near the carrier or on the declarations page. This may be labeled "Producer", "Agent", "Broker", or similar.
|
|
3743
|
+
|
|
3334
3744
|
Return JSON only.`;
|
|
3335
3745
|
}
|
|
3336
3746
|
|
|
3337
3747
|
// src/prompts/extractors/named-insured.ts
|
|
3338
|
-
var
|
|
3339
|
-
var AddressSchema2 =
|
|
3340
|
-
street1:
|
|
3341
|
-
city:
|
|
3342
|
-
state:
|
|
3343
|
-
zip:
|
|
3748
|
+
var import_zod24 = require("zod");
|
|
3749
|
+
var AddressSchema2 = import_zod24.z.object({
|
|
3750
|
+
street1: import_zod24.z.string(),
|
|
3751
|
+
city: import_zod24.z.string(),
|
|
3752
|
+
state: import_zod24.z.string(),
|
|
3753
|
+
zip: import_zod24.z.string()
|
|
3344
3754
|
});
|
|
3345
|
-
var NamedInsuredSchema2 =
|
|
3346
|
-
insuredName:
|
|
3347
|
-
insuredDba:
|
|
3755
|
+
var NamedInsuredSchema2 = import_zod24.z.object({
|
|
3756
|
+
insuredName: import_zod24.z.string().describe("Name of primary named insured"),
|
|
3757
|
+
insuredDba: import_zod24.z.string().optional().describe("Doing-business-as name"),
|
|
3348
3758
|
insuredAddress: AddressSchema2.optional().describe("Primary insured mailing address"),
|
|
3349
|
-
insuredEntityType:
|
|
3759
|
+
insuredEntityType: import_zod24.z.enum([
|
|
3350
3760
|
"corporation",
|
|
3351
3761
|
"llc",
|
|
3352
3762
|
"partnership",
|
|
@@ -3359,16 +3769,28 @@ var NamedInsuredSchema2 = import_zod23.z.object({
|
|
|
3359
3769
|
"married_couple",
|
|
3360
3770
|
"other"
|
|
3361
3771
|
]).optional().describe("Legal entity type of the insured"),
|
|
3362
|
-
insuredFein:
|
|
3363
|
-
insuredSicCode:
|
|
3364
|
-
insuredNaicsCode:
|
|
3365
|
-
additionalNamedInsureds:
|
|
3366
|
-
|
|
3367
|
-
name:
|
|
3368
|
-
relationship:
|
|
3772
|
+
insuredFein: import_zod24.z.string().optional().describe("Federal Employer Identification Number"),
|
|
3773
|
+
insuredSicCode: import_zod24.z.string().optional().describe("SIC code"),
|
|
3774
|
+
insuredNaicsCode: import_zod24.z.string().optional().describe("NAICS code"),
|
|
3775
|
+
additionalNamedInsureds: import_zod24.z.array(
|
|
3776
|
+
import_zod24.z.object({
|
|
3777
|
+
name: import_zod24.z.string(),
|
|
3778
|
+
relationship: import_zod24.z.string().optional().describe("e.g. subsidiary, affiliate"),
|
|
3779
|
+
address: AddressSchema2.optional()
|
|
3780
|
+
})
|
|
3781
|
+
).optional().describe("Additional named insureds listed on the policy"),
|
|
3782
|
+
lossPayees: import_zod24.z.array(
|
|
3783
|
+
import_zod24.z.object({
|
|
3784
|
+
name: import_zod24.z.string(),
|
|
3369
3785
|
address: AddressSchema2.optional()
|
|
3370
3786
|
})
|
|
3371
|
-
).optional().describe("
|
|
3787
|
+
).optional().describe("Loss payees listed on the policy"),
|
|
3788
|
+
mortgageHolders: import_zod24.z.array(
|
|
3789
|
+
import_zod24.z.object({
|
|
3790
|
+
name: import_zod24.z.string(),
|
|
3791
|
+
address: AddressSchema2.optional()
|
|
3792
|
+
})
|
|
3793
|
+
).optional().describe("Mortgage holders / lienholders listed on the policy")
|
|
3372
3794
|
});
|
|
3373
3795
|
function buildNamedInsuredPrompt() {
|
|
3374
3796
|
return `You are an expert insurance document analyst. Extract all named insured information from this document.
|
|
@@ -3379,21 +3801,23 @@ Focus on:
|
|
|
3379
3801
|
- FEIN (Federal Employer Identification Number) if listed
|
|
3380
3802
|
- SIC code and NAICS code if listed
|
|
3381
3803
|
- ALL additional named insureds with their relationship (subsidiary, affiliate, etc.) and address if provided
|
|
3804
|
+
- ALL loss payees with name and address (e.g. "Loss Payee: BMO Bank of Montreal")
|
|
3805
|
+
- ALL mortgage holders / lienholders / mortgagees with name and address
|
|
3382
3806
|
|
|
3383
|
-
Look on the declarations page, named insured schedule, and any endorsements that add or modify named insureds.
|
|
3807
|
+
Look on the declarations page, named insured schedule, loss payee schedule, mortgagee schedule, and any endorsements that add or modify named insureds, loss payees, or mortgage holders.
|
|
3384
3808
|
|
|
3385
3809
|
Return JSON only.`;
|
|
3386
3810
|
}
|
|
3387
3811
|
|
|
3388
3812
|
// src/prompts/extractors/coverage-limits.ts
|
|
3389
|
-
var
|
|
3813
|
+
var import_zod25 = require("zod");
|
|
3390
3814
|
var ExtractorCoverageSchema = CoverageSchema.extend({
|
|
3391
|
-
coverageCode:
|
|
3815
|
+
coverageCode: import_zod25.z.string().optional().describe("Coverage code or class code")
|
|
3392
3816
|
});
|
|
3393
|
-
var CoverageLimitsSchema =
|
|
3394
|
-
coverages:
|
|
3395
|
-
coverageForm:
|
|
3396
|
-
retroactiveDate:
|
|
3817
|
+
var CoverageLimitsSchema = import_zod25.z.object({
|
|
3818
|
+
coverages: import_zod25.z.array(ExtractorCoverageSchema).describe("All coverages with their limits"),
|
|
3819
|
+
coverageForm: import_zod25.z.enum(["occurrence", "claims_made", "accident"]).optional().describe("Primary coverage trigger type"),
|
|
3820
|
+
retroactiveDate: import_zod25.z.string().optional().describe("Retroactive date for claims-made policies (MM/DD/YYYY)")
|
|
3397
3821
|
});
|
|
3398
3822
|
function buildCoverageLimitsPrompt() {
|
|
3399
3823
|
return `You are an expert insurance document analyst. Extract all coverage limits and deductibles from this document.
|
|
@@ -3432,14 +3856,14 @@ Return JSON only.`;
|
|
|
3432
3856
|
}
|
|
3433
3857
|
|
|
3434
3858
|
// src/prompts/extractors/endorsements.ts
|
|
3435
|
-
var
|
|
3436
|
-
var EndorsementsSchema =
|
|
3437
|
-
endorsements:
|
|
3438
|
-
|
|
3439
|
-
formNumber:
|
|
3440
|
-
editionDate:
|
|
3441
|
-
title:
|
|
3442
|
-
endorsementType:
|
|
3859
|
+
var import_zod26 = require("zod");
|
|
3860
|
+
var EndorsementsSchema = import_zod26.z.object({
|
|
3861
|
+
endorsements: import_zod26.z.array(
|
|
3862
|
+
import_zod26.z.object({
|
|
3863
|
+
formNumber: import_zod26.z.string().describe("Form number, e.g. 'CG 21 47'"),
|
|
3864
|
+
editionDate: import_zod26.z.string().optional().describe("Edition date, e.g. '12 07'"),
|
|
3865
|
+
title: import_zod26.z.string().describe("Endorsement title"),
|
|
3866
|
+
endorsementType: import_zod26.z.enum([
|
|
3443
3867
|
"additional_insured",
|
|
3444
3868
|
"waiver_of_subrogation",
|
|
3445
3869
|
"primary_noncontributory",
|
|
@@ -3459,12 +3883,12 @@ var EndorsementsSchema = import_zod25.z.object({
|
|
|
3459
3883
|
"territorial_extension",
|
|
3460
3884
|
"other"
|
|
3461
3885
|
]).describe("Endorsement type classification"),
|
|
3462
|
-
effectiveDate:
|
|
3463
|
-
affectedCoverageParts:
|
|
3464
|
-
namedParties:
|
|
3465
|
-
|
|
3466
|
-
name:
|
|
3467
|
-
role:
|
|
3886
|
+
effectiveDate: import_zod26.z.string().optional().describe("Endorsement effective date"),
|
|
3887
|
+
affectedCoverageParts: import_zod26.z.array(import_zod26.z.string()).optional().describe("Coverage parts affected by this endorsement"),
|
|
3888
|
+
namedParties: import_zod26.z.array(
|
|
3889
|
+
import_zod26.z.object({
|
|
3890
|
+
name: import_zod26.z.string().describe("Party name"),
|
|
3891
|
+
role: import_zod26.z.enum([
|
|
3468
3892
|
"additional_insured",
|
|
3469
3893
|
"loss_payee",
|
|
3470
3894
|
"mortgage_holder",
|
|
@@ -3473,15 +3897,15 @@ var EndorsementsSchema = import_zod25.z.object({
|
|
|
3473
3897
|
"designated_person",
|
|
3474
3898
|
"other"
|
|
3475
3899
|
]).describe("Party role"),
|
|
3476
|
-
relationship:
|
|
3477
|
-
scope:
|
|
3900
|
+
relationship: import_zod26.z.string().optional().describe("Relationship to insured"),
|
|
3901
|
+
scope: import_zod26.z.string().optional().describe("Scope of coverage for this party")
|
|
3478
3902
|
})
|
|
3479
3903
|
).optional().describe("Named parties (additional insureds, loss payees, etc.)"),
|
|
3480
|
-
keyTerms:
|
|
3481
|
-
premiumImpact:
|
|
3482
|
-
content:
|
|
3483
|
-
pageStart:
|
|
3484
|
-
pageEnd:
|
|
3904
|
+
keyTerms: import_zod26.z.array(import_zod26.z.string()).optional().describe("Key terms or notable provisions in the endorsement"),
|
|
3905
|
+
premiumImpact: import_zod26.z.string().optional().describe("Additional premium or credit"),
|
|
3906
|
+
content: import_zod26.z.string().describe("Full verbatim text of the endorsement"),
|
|
3907
|
+
pageStart: import_zod26.z.number().describe("Starting page number of this endorsement"),
|
|
3908
|
+
pageEnd: import_zod26.z.number().optional().describe("Ending page number of this endorsement")
|
|
3485
3909
|
})
|
|
3486
3910
|
).describe("All endorsements found in the document")
|
|
3487
3911
|
});
|
|
@@ -3512,20 +3936,20 @@ Return JSON only.`;
|
|
|
3512
3936
|
}
|
|
3513
3937
|
|
|
3514
3938
|
// src/prompts/extractors/exclusions.ts
|
|
3515
|
-
var
|
|
3516
|
-
var ExclusionsSchema =
|
|
3517
|
-
exclusions:
|
|
3518
|
-
|
|
3519
|
-
name:
|
|
3520
|
-
formNumber:
|
|
3521
|
-
excludedPerils:
|
|
3522
|
-
isAbsolute:
|
|
3523
|
-
exceptions:
|
|
3524
|
-
buybackAvailable:
|
|
3525
|
-
buybackEndorsement:
|
|
3526
|
-
appliesTo:
|
|
3527
|
-
content:
|
|
3528
|
-
pageNumber:
|
|
3939
|
+
var import_zod27 = require("zod");
|
|
3940
|
+
var ExclusionsSchema = import_zod27.z.object({
|
|
3941
|
+
exclusions: import_zod27.z.array(
|
|
3942
|
+
import_zod27.z.object({
|
|
3943
|
+
name: import_zod27.z.string().describe("Exclusion title or short description"),
|
|
3944
|
+
formNumber: import_zod27.z.string().optional().describe("Form number if part of a named endorsement"),
|
|
3945
|
+
excludedPerils: import_zod27.z.array(import_zod27.z.string()).optional().describe("Specific perils excluded"),
|
|
3946
|
+
isAbsolute: import_zod27.z.boolean().optional().describe("Whether the exclusion is absolute (no exceptions)"),
|
|
3947
|
+
exceptions: import_zod27.z.array(import_zod27.z.string()).optional().describe("Exceptions to the exclusion, if any"),
|
|
3948
|
+
buybackAvailable: import_zod27.z.boolean().optional().describe("Whether coverage can be bought back via endorsement"),
|
|
3949
|
+
buybackEndorsement: import_zod27.z.string().optional().describe("Form number of the buyback endorsement if available"),
|
|
3950
|
+
appliesTo: import_zod27.z.array(import_zod27.z.string()).optional().describe("Coverage types this exclusion applies to"),
|
|
3951
|
+
content: import_zod27.z.string().describe("Full verbatim exclusion text"),
|
|
3952
|
+
pageNumber: import_zod27.z.number().optional().describe("Page number where exclusion appears")
|
|
3529
3953
|
})
|
|
3530
3954
|
).describe("All exclusions found in the document")
|
|
3531
3955
|
});
|
|
@@ -3561,12 +3985,12 @@ Return JSON only.`;
|
|
|
3561
3985
|
}
|
|
3562
3986
|
|
|
3563
3987
|
// src/prompts/extractors/conditions.ts
|
|
3564
|
-
var
|
|
3565
|
-
var ConditionsSchema =
|
|
3566
|
-
conditions:
|
|
3567
|
-
|
|
3568
|
-
name:
|
|
3569
|
-
conditionType:
|
|
3988
|
+
var import_zod28 = require("zod");
|
|
3989
|
+
var ConditionsSchema = import_zod28.z.object({
|
|
3990
|
+
conditions: import_zod28.z.array(
|
|
3991
|
+
import_zod28.z.object({
|
|
3992
|
+
name: import_zod28.z.string().describe("Condition title"),
|
|
3993
|
+
conditionType: import_zod28.z.enum([
|
|
3570
3994
|
"duties_after_loss",
|
|
3571
3995
|
"notice_requirements",
|
|
3572
3996
|
"other_insurance",
|
|
@@ -3585,14 +4009,14 @@ var ConditionsSchema = import_zod27.z.object({
|
|
|
3585
4009
|
"separation_of_insureds",
|
|
3586
4010
|
"other"
|
|
3587
4011
|
]).describe("Condition category"),
|
|
3588
|
-
content:
|
|
3589
|
-
keyValues:
|
|
3590
|
-
|
|
3591
|
-
key:
|
|
3592
|
-
value:
|
|
4012
|
+
content: import_zod28.z.string().describe("Full verbatim condition text"),
|
|
4013
|
+
keyValues: import_zod28.z.array(
|
|
4014
|
+
import_zod28.z.object({
|
|
4015
|
+
key: import_zod28.z.string().describe("Key name (e.g. 'noticePeriod', 'suitDeadline')"),
|
|
4016
|
+
value: import_zod28.z.string().describe("Value (e.g. '30 days', '2 years')")
|
|
3593
4017
|
})
|
|
3594
4018
|
).optional().describe("Key values extracted from the condition (notice periods, deadlines, etc.)"),
|
|
3595
|
-
pageNumber:
|
|
4019
|
+
pageNumber: import_zod28.z.number().optional().describe("Page number where condition appears")
|
|
3596
4020
|
})
|
|
3597
4021
|
).describe("All policy conditions found in the document")
|
|
3598
4022
|
});
|
|
@@ -3630,28 +4054,28 @@ Return JSON only.`;
|
|
|
3630
4054
|
}
|
|
3631
4055
|
|
|
3632
4056
|
// src/prompts/extractors/premium-breakdown.ts
|
|
3633
|
-
var
|
|
3634
|
-
var PremiumBreakdownSchema =
|
|
3635
|
-
premium:
|
|
3636
|
-
totalCost:
|
|
3637
|
-
premiumBreakdown:
|
|
3638
|
-
|
|
3639
|
-
line:
|
|
3640
|
-
amount:
|
|
4057
|
+
var import_zod29 = require("zod");
|
|
4058
|
+
var PremiumBreakdownSchema = import_zod29.z.object({
|
|
4059
|
+
premium: import_zod29.z.string().optional().describe("Total premium amount, e.g. '$5,000'"),
|
|
4060
|
+
totalCost: import_zod29.z.string().optional().describe("Total cost including taxes and fees, e.g. '$5,250'"),
|
|
4061
|
+
premiumBreakdown: import_zod29.z.array(
|
|
4062
|
+
import_zod29.z.object({
|
|
4063
|
+
line: import_zod29.z.string().describe("Coverage line name"),
|
|
4064
|
+
amount: import_zod29.z.string().describe("Premium amount for this line")
|
|
3641
4065
|
})
|
|
3642
4066
|
).optional().describe("Per-coverage-line premium breakdown"),
|
|
3643
|
-
taxesAndFees:
|
|
3644
|
-
|
|
3645
|
-
name:
|
|
3646
|
-
amount:
|
|
3647
|
-
type:
|
|
4067
|
+
taxesAndFees: import_zod29.z.array(
|
|
4068
|
+
import_zod29.z.object({
|
|
4069
|
+
name: import_zod29.z.string().describe("Fee or tax name"),
|
|
4070
|
+
amount: import_zod29.z.string().describe("Dollar amount"),
|
|
4071
|
+
type: import_zod29.z.enum(["tax", "fee", "surcharge", "assessment"]).optional().describe("Fee category")
|
|
3648
4072
|
})
|
|
3649
4073
|
).optional().describe("Taxes, fees, surcharges, and assessments"),
|
|
3650
|
-
minimumPremium:
|
|
3651
|
-
depositPremium:
|
|
3652
|
-
paymentPlan:
|
|
3653
|
-
auditType:
|
|
3654
|
-
ratingBasis:
|
|
4074
|
+
minimumPremium: import_zod29.z.string().optional().describe("Minimum premium if stated"),
|
|
4075
|
+
depositPremium: import_zod29.z.string().optional().describe("Deposit premium if stated"),
|
|
4076
|
+
paymentPlan: import_zod29.z.string().optional().describe("Payment plan description"),
|
|
4077
|
+
auditType: import_zod29.z.enum(["annual", "semi_annual", "quarterly", "monthly", "final", "self"]).optional().describe("Premium audit type"),
|
|
4078
|
+
ratingBasis: import_zod29.z.string().optional().describe("Rating basis, e.g. payroll, revenue, area, units")
|
|
3655
4079
|
});
|
|
3656
4080
|
function buildPremiumBreakdownPrompt() {
|
|
3657
4081
|
return `You are an expert insurance document analyst. Extract all premium and cost information from this document.
|
|
@@ -3671,14 +4095,14 @@ Return JSON only.`;
|
|
|
3671
4095
|
}
|
|
3672
4096
|
|
|
3673
4097
|
// src/prompts/extractors/declarations.ts
|
|
3674
|
-
var
|
|
3675
|
-
var DeclarationsFieldSchema =
|
|
3676
|
-
field:
|
|
3677
|
-
value:
|
|
3678
|
-
section:
|
|
4098
|
+
var import_zod30 = require("zod");
|
|
4099
|
+
var DeclarationsFieldSchema = import_zod30.z.object({
|
|
4100
|
+
field: import_zod30.z.string().describe("Descriptive field name (e.g. 'policyNumber', 'effectiveDate', 'coverageALimit')"),
|
|
4101
|
+
value: import_zod30.z.string().describe("Extracted value exactly as it appears in the document"),
|
|
4102
|
+
section: import_zod30.z.string().optional().describe("Section or grouping this field belongs to (e.g. 'Coverage Limits', 'Vehicle Schedule')")
|
|
3679
4103
|
});
|
|
3680
|
-
var DeclarationsExtractSchema =
|
|
3681
|
-
fields:
|
|
4104
|
+
var DeclarationsExtractSchema = import_zod30.z.object({
|
|
4105
|
+
fields: import_zod30.z.array(DeclarationsFieldSchema).describe("All declarations page fields extracted as key-value pairs. Structure varies by line of business.")
|
|
3682
4106
|
});
|
|
3683
4107
|
function buildDeclarationsPrompt() {
|
|
3684
4108
|
return `You are an expert insurance document analyst. Extract all declarations page data from this document into a flexible key-value structure.
|
|
@@ -3718,21 +4142,21 @@ Preserve original values exactly as they appear. Return JSON only.`;
|
|
|
3718
4142
|
}
|
|
3719
4143
|
|
|
3720
4144
|
// src/prompts/extractors/loss-history.ts
|
|
3721
|
-
var
|
|
3722
|
-
var LossHistorySchema =
|
|
3723
|
-
lossSummary:
|
|
3724
|
-
individualClaims:
|
|
3725
|
-
|
|
3726
|
-
date:
|
|
3727
|
-
type:
|
|
3728
|
-
description:
|
|
3729
|
-
amountPaid:
|
|
3730
|
-
amountReserved:
|
|
3731
|
-
status:
|
|
3732
|
-
claimNumber:
|
|
4145
|
+
var import_zod31 = require("zod");
|
|
4146
|
+
var LossHistorySchema = import_zod31.z.object({
|
|
4147
|
+
lossSummary: import_zod31.z.string().optional().describe("Summary of loss history, e.g. '3 claims in past 5 years totaling $125,000'"),
|
|
4148
|
+
individualClaims: import_zod31.z.array(
|
|
4149
|
+
import_zod31.z.object({
|
|
4150
|
+
date: import_zod31.z.string().optional().describe("Date of loss or claim"),
|
|
4151
|
+
type: import_zod31.z.string().optional().describe("Type of claim, e.g. 'property damage', 'bodily injury'"),
|
|
4152
|
+
description: import_zod31.z.string().optional().describe("Brief description of the claim"),
|
|
4153
|
+
amountPaid: import_zod31.z.string().optional().describe("Amount paid"),
|
|
4154
|
+
amountReserved: import_zod31.z.string().optional().describe("Amount reserved"),
|
|
4155
|
+
status: import_zod31.z.enum(["open", "closed", "reopened"]).optional().describe("Claim status"),
|
|
4156
|
+
claimNumber: import_zod31.z.string().optional().describe("Claim reference number")
|
|
3733
4157
|
})
|
|
3734
4158
|
).optional().describe("Individual claim records"),
|
|
3735
|
-
experienceMod:
|
|
4159
|
+
experienceMod: import_zod31.z.string().optional().describe("Experience modification factor for workers comp, e.g. '0.85'")
|
|
3736
4160
|
});
|
|
3737
4161
|
function buildLossHistoryPrompt() {
|
|
3738
4162
|
return `You are an expert insurance document analyst. Extract all loss history and claims information from this document.
|
|
@@ -3749,18 +4173,18 @@ Return JSON only.`;
|
|
|
3749
4173
|
}
|
|
3750
4174
|
|
|
3751
4175
|
// src/prompts/extractors/sections.ts
|
|
3752
|
-
var
|
|
3753
|
-
var SubsectionSchema2 =
|
|
3754
|
-
title:
|
|
3755
|
-
sectionNumber:
|
|
3756
|
-
pageNumber:
|
|
3757
|
-
content:
|
|
4176
|
+
var import_zod32 = require("zod");
|
|
4177
|
+
var SubsectionSchema2 = import_zod32.z.object({
|
|
4178
|
+
title: import_zod32.z.string().describe("Subsection title"),
|
|
4179
|
+
sectionNumber: import_zod32.z.string().optional().describe("Subsection number"),
|
|
4180
|
+
pageNumber: import_zod32.z.number().optional().describe("Page number"),
|
|
4181
|
+
content: import_zod32.z.string().describe("Full verbatim text")
|
|
3758
4182
|
});
|
|
3759
|
-
var SectionsSchema =
|
|
3760
|
-
sections:
|
|
3761
|
-
|
|
3762
|
-
title:
|
|
3763
|
-
type:
|
|
4183
|
+
var SectionsSchema = import_zod32.z.object({
|
|
4184
|
+
sections: import_zod32.z.array(
|
|
4185
|
+
import_zod32.z.object({
|
|
4186
|
+
title: import_zod32.z.string().describe("Section title"),
|
|
4187
|
+
type: import_zod32.z.enum([
|
|
3764
4188
|
"declarations",
|
|
3765
4189
|
"insuring_agreement",
|
|
3766
4190
|
"policy_form",
|
|
@@ -3774,10 +4198,10 @@ var SectionsSchema = import_zod31.z.object({
|
|
|
3774
4198
|
"regulatory",
|
|
3775
4199
|
"other"
|
|
3776
4200
|
]).describe("Section type classification"),
|
|
3777
|
-
content:
|
|
3778
|
-
pageStart:
|
|
3779
|
-
pageEnd:
|
|
3780
|
-
subsections:
|
|
4201
|
+
content: import_zod32.z.string().describe("Full verbatim text of the section"),
|
|
4202
|
+
pageStart: import_zod32.z.number().describe("Starting page number"),
|
|
4203
|
+
pageEnd: import_zod32.z.number().optional().describe("Ending page number"),
|
|
4204
|
+
subsections: import_zod32.z.array(SubsectionSchema2).optional().describe("Subsections within this section")
|
|
3781
4205
|
})
|
|
3782
4206
|
).describe("All document sections")
|
|
3783
4207
|
});
|
|
@@ -3807,20 +4231,20 @@ Return JSON only.`;
|
|
|
3807
4231
|
}
|
|
3808
4232
|
|
|
3809
4233
|
// src/prompts/extractors/supplementary.ts
|
|
3810
|
-
var
|
|
3811
|
-
var ContactSchema2 =
|
|
3812
|
-
name:
|
|
3813
|
-
phone:
|
|
3814
|
-
email:
|
|
3815
|
-
address:
|
|
3816
|
-
type:
|
|
4234
|
+
var import_zod33 = require("zod");
|
|
4235
|
+
var ContactSchema2 = import_zod33.z.object({
|
|
4236
|
+
name: import_zod33.z.string().optional().describe("Organization or person name"),
|
|
4237
|
+
phone: import_zod33.z.string().optional().describe("Phone number"),
|
|
4238
|
+
email: import_zod33.z.string().optional().describe("Email address"),
|
|
4239
|
+
address: import_zod33.z.string().optional().describe("Mailing address"),
|
|
4240
|
+
type: import_zod33.z.string().optional().describe("Contact type, e.g. 'State Department of Insurance'")
|
|
3817
4241
|
});
|
|
3818
|
-
var SupplementarySchema =
|
|
3819
|
-
regulatoryContacts:
|
|
3820
|
-
claimsContacts:
|
|
3821
|
-
thirdPartyAdministrators:
|
|
3822
|
-
cancellationNoticeDays:
|
|
3823
|
-
nonrenewalNoticeDays:
|
|
4242
|
+
var SupplementarySchema = import_zod33.z.object({
|
|
4243
|
+
regulatoryContacts: import_zod33.z.array(ContactSchema2).optional().describe("Regulatory body contacts (state department of insurance, ombudsman)"),
|
|
4244
|
+
claimsContacts: import_zod33.z.array(ContactSchema2).optional().describe("Claims reporting contacts and instructions"),
|
|
4245
|
+
thirdPartyAdministrators: import_zod33.z.array(ContactSchema2).optional().describe("Third-party administrators for claims handling"),
|
|
4246
|
+
cancellationNoticeDays: import_zod33.z.number().optional().describe("Required notice period for cancellation in days"),
|
|
4247
|
+
nonrenewalNoticeDays: import_zod33.z.number().optional().describe("Required notice period for nonrenewal in days")
|
|
3824
4248
|
});
|
|
3825
4249
|
function buildSupplementaryPrompt() {
|
|
3826
4250
|
return `You are an expert insurance document analyst. Extract supplementary and regulatory information from this document.
|
|
@@ -4679,6 +5103,31 @@ function createExtractor(config) {
|
|
|
4679
5103
|
memory: Object.fromEntries(memory),
|
|
4680
5104
|
document
|
|
4681
5105
|
});
|
|
5106
|
+
if (!document.summary) {
|
|
5107
|
+
onProgress?.("Generating document summary...");
|
|
5108
|
+
try {
|
|
5109
|
+
const summaryResponse = await safeGenerateObject(
|
|
5110
|
+
generateObject,
|
|
5111
|
+
{
|
|
5112
|
+
prompt: buildSummaryPrompt(document),
|
|
5113
|
+
schema: SummaryResultSchema,
|
|
5114
|
+
maxTokens: 512,
|
|
5115
|
+
providerOptions
|
|
5116
|
+
},
|
|
5117
|
+
{
|
|
5118
|
+
fallback: { summary: "" },
|
|
5119
|
+
log,
|
|
5120
|
+
onError: (err, attempt) => log?.(`Summary attempt ${attempt + 1} failed: ${err instanceof Error ? err.message : String(err)}`)
|
|
5121
|
+
}
|
|
5122
|
+
);
|
|
5123
|
+
trackUsage(summaryResponse.usage);
|
|
5124
|
+
if (summaryResponse.object.summary) {
|
|
5125
|
+
document.summary = summaryResponse.object.summary;
|
|
5126
|
+
}
|
|
5127
|
+
} catch (error) {
|
|
5128
|
+
await log?.(`Summary generation failed, skipping: ${error instanceof Error ? error.message : String(error)}`);
|
|
5129
|
+
}
|
|
5130
|
+
}
|
|
4682
5131
|
onProgress?.("Formatting extracted content...");
|
|
4683
5132
|
const formatResult = await formatDocumentContent(document, generateText, {
|
|
4684
5133
|
providerOptions,
|
|
@@ -4922,8 +5371,8 @@ Respond with JSON only:
|
|
|
4922
5371
|
}`;
|
|
4923
5372
|
|
|
4924
5373
|
// src/schemas/application.ts
|
|
4925
|
-
var
|
|
4926
|
-
var FieldTypeSchema =
|
|
5374
|
+
var import_zod34 = require("zod");
|
|
5375
|
+
var FieldTypeSchema = import_zod34.z.enum([
|
|
4927
5376
|
"text",
|
|
4928
5377
|
"numeric",
|
|
4929
5378
|
"currency",
|
|
@@ -4932,131 +5381,131 @@ var FieldTypeSchema = import_zod33.z.enum([
|
|
|
4932
5381
|
"table",
|
|
4933
5382
|
"declaration"
|
|
4934
5383
|
]);
|
|
4935
|
-
var ApplicationFieldSchema =
|
|
4936
|
-
id:
|
|
4937
|
-
label:
|
|
4938
|
-
section:
|
|
5384
|
+
var ApplicationFieldSchema = import_zod34.z.object({
|
|
5385
|
+
id: import_zod34.z.string(),
|
|
5386
|
+
label: import_zod34.z.string(),
|
|
5387
|
+
section: import_zod34.z.string(),
|
|
4939
5388
|
fieldType: FieldTypeSchema,
|
|
4940
|
-
required:
|
|
4941
|
-
options:
|
|
4942
|
-
columns:
|
|
4943
|
-
requiresExplanationIfYes:
|
|
4944
|
-
condition:
|
|
4945
|
-
dependsOn:
|
|
4946
|
-
whenValue:
|
|
5389
|
+
required: import_zod34.z.boolean(),
|
|
5390
|
+
options: import_zod34.z.array(import_zod34.z.string()).optional(),
|
|
5391
|
+
columns: import_zod34.z.array(import_zod34.z.string()).optional(),
|
|
5392
|
+
requiresExplanationIfYes: import_zod34.z.boolean().optional(),
|
|
5393
|
+
condition: import_zod34.z.object({
|
|
5394
|
+
dependsOn: import_zod34.z.string(),
|
|
5395
|
+
whenValue: import_zod34.z.string()
|
|
4947
5396
|
}).optional(),
|
|
4948
|
-
value:
|
|
4949
|
-
source:
|
|
4950
|
-
confidence:
|
|
5397
|
+
value: import_zod34.z.string().optional(),
|
|
5398
|
+
source: import_zod34.z.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
|
|
5399
|
+
confidence: import_zod34.z.enum(["confirmed", "high", "medium", "low"]).optional()
|
|
4951
5400
|
});
|
|
4952
|
-
var ApplicationClassifyResultSchema =
|
|
4953
|
-
isApplication:
|
|
4954
|
-
confidence:
|
|
4955
|
-
applicationType:
|
|
5401
|
+
var ApplicationClassifyResultSchema = import_zod34.z.object({
|
|
5402
|
+
isApplication: import_zod34.z.boolean(),
|
|
5403
|
+
confidence: import_zod34.z.number().min(0).max(1),
|
|
5404
|
+
applicationType: import_zod34.z.string().nullable()
|
|
4956
5405
|
});
|
|
4957
|
-
var FieldExtractionResultSchema =
|
|
4958
|
-
fields:
|
|
5406
|
+
var FieldExtractionResultSchema = import_zod34.z.object({
|
|
5407
|
+
fields: import_zod34.z.array(ApplicationFieldSchema)
|
|
4959
5408
|
});
|
|
4960
|
-
var AutoFillMatchSchema =
|
|
4961
|
-
fieldId:
|
|
4962
|
-
value:
|
|
4963
|
-
confidence:
|
|
4964
|
-
contextKey:
|
|
5409
|
+
var AutoFillMatchSchema = import_zod34.z.object({
|
|
5410
|
+
fieldId: import_zod34.z.string(),
|
|
5411
|
+
value: import_zod34.z.string(),
|
|
5412
|
+
confidence: import_zod34.z.enum(["confirmed"]),
|
|
5413
|
+
contextKey: import_zod34.z.string()
|
|
4965
5414
|
});
|
|
4966
|
-
var AutoFillResultSchema =
|
|
4967
|
-
matches:
|
|
5415
|
+
var AutoFillResultSchema = import_zod34.z.object({
|
|
5416
|
+
matches: import_zod34.z.array(AutoFillMatchSchema)
|
|
4968
5417
|
});
|
|
4969
|
-
var QuestionBatchResultSchema =
|
|
4970
|
-
batches:
|
|
5418
|
+
var QuestionBatchResultSchema = import_zod34.z.object({
|
|
5419
|
+
batches: import_zod34.z.array(import_zod34.z.array(import_zod34.z.string()).describe("Array of field IDs in this batch"))
|
|
4971
5420
|
});
|
|
4972
|
-
var LookupRequestSchema =
|
|
4973
|
-
type:
|
|
4974
|
-
description:
|
|
4975
|
-
url:
|
|
4976
|
-
targetFieldIds:
|
|
5421
|
+
var LookupRequestSchema = import_zod34.z.object({
|
|
5422
|
+
type: import_zod34.z.string().describe("Type of lookup: 'records', 'website', 'policy'"),
|
|
5423
|
+
description: import_zod34.z.string(),
|
|
5424
|
+
url: import_zod34.z.string().optional(),
|
|
5425
|
+
targetFieldIds: import_zod34.z.array(import_zod34.z.string())
|
|
4977
5426
|
});
|
|
4978
|
-
var ReplyIntentSchema =
|
|
4979
|
-
primaryIntent:
|
|
4980
|
-
hasAnswers:
|
|
4981
|
-
questionText:
|
|
4982
|
-
questionFieldIds:
|
|
4983
|
-
lookupRequests:
|
|
5427
|
+
var ReplyIntentSchema = import_zod34.z.object({
|
|
5428
|
+
primaryIntent: import_zod34.z.enum(["answers_only", "question", "lookup_request", "mixed"]),
|
|
5429
|
+
hasAnswers: import_zod34.z.boolean(),
|
|
5430
|
+
questionText: import_zod34.z.string().optional(),
|
|
5431
|
+
questionFieldIds: import_zod34.z.array(import_zod34.z.string()).optional(),
|
|
5432
|
+
lookupRequests: import_zod34.z.array(LookupRequestSchema).optional()
|
|
4984
5433
|
});
|
|
4985
|
-
var ParsedAnswerSchema =
|
|
4986
|
-
fieldId:
|
|
4987
|
-
value:
|
|
4988
|
-
explanation:
|
|
5434
|
+
var ParsedAnswerSchema = import_zod34.z.object({
|
|
5435
|
+
fieldId: import_zod34.z.string(),
|
|
5436
|
+
value: import_zod34.z.string(),
|
|
5437
|
+
explanation: import_zod34.z.string().optional()
|
|
4989
5438
|
});
|
|
4990
|
-
var AnswerParsingResultSchema =
|
|
4991
|
-
answers:
|
|
4992
|
-
unanswered:
|
|
5439
|
+
var AnswerParsingResultSchema = import_zod34.z.object({
|
|
5440
|
+
answers: import_zod34.z.array(ParsedAnswerSchema),
|
|
5441
|
+
unanswered: import_zod34.z.array(import_zod34.z.string()).describe("Field IDs that were not answered")
|
|
4993
5442
|
});
|
|
4994
|
-
var LookupFillSchema =
|
|
4995
|
-
fieldId:
|
|
4996
|
-
value:
|
|
4997
|
-
source:
|
|
5443
|
+
var LookupFillSchema = import_zod34.z.object({
|
|
5444
|
+
fieldId: import_zod34.z.string(),
|
|
5445
|
+
value: import_zod34.z.string(),
|
|
5446
|
+
source: import_zod34.z.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'")
|
|
4998
5447
|
});
|
|
4999
|
-
var LookupFillResultSchema =
|
|
5000
|
-
fills:
|
|
5001
|
-
unfillable:
|
|
5002
|
-
explanation:
|
|
5448
|
+
var LookupFillResultSchema = import_zod34.z.object({
|
|
5449
|
+
fills: import_zod34.z.array(LookupFillSchema),
|
|
5450
|
+
unfillable: import_zod34.z.array(import_zod34.z.string()),
|
|
5451
|
+
explanation: import_zod34.z.string().optional()
|
|
5003
5452
|
});
|
|
5004
|
-
var FlatPdfPlacementSchema =
|
|
5005
|
-
fieldId:
|
|
5006
|
-
page:
|
|
5007
|
-
x:
|
|
5008
|
-
y:
|
|
5009
|
-
text:
|
|
5010
|
-
fontSize:
|
|
5011
|
-
isCheckmark:
|
|
5453
|
+
var FlatPdfPlacementSchema = import_zod34.z.object({
|
|
5454
|
+
fieldId: import_zod34.z.string(),
|
|
5455
|
+
page: import_zod34.z.number(),
|
|
5456
|
+
x: import_zod34.z.number().describe("Percentage from left edge (0-100)"),
|
|
5457
|
+
y: import_zod34.z.number().describe("Percentage from top edge (0-100)"),
|
|
5458
|
+
text: import_zod34.z.string(),
|
|
5459
|
+
fontSize: import_zod34.z.number().optional(),
|
|
5460
|
+
isCheckmark: import_zod34.z.boolean().optional()
|
|
5012
5461
|
});
|
|
5013
|
-
var AcroFormMappingSchema =
|
|
5014
|
-
fieldId:
|
|
5015
|
-
acroFormName:
|
|
5016
|
-
value:
|
|
5462
|
+
var AcroFormMappingSchema = import_zod34.z.object({
|
|
5463
|
+
fieldId: import_zod34.z.string(),
|
|
5464
|
+
acroFormName: import_zod34.z.string(),
|
|
5465
|
+
value: import_zod34.z.string()
|
|
5017
5466
|
});
|
|
5018
|
-
var QualityGateStatusSchema =
|
|
5019
|
-
var QualitySeveritySchema =
|
|
5020
|
-
var ApplicationQualityIssueSchema =
|
|
5021
|
-
code:
|
|
5467
|
+
var QualityGateStatusSchema = import_zod34.z.enum(["passed", "warning", "failed"]);
|
|
5468
|
+
var QualitySeveritySchema = import_zod34.z.enum(["info", "warning", "blocking"]);
|
|
5469
|
+
var ApplicationQualityIssueSchema = import_zod34.z.object({
|
|
5470
|
+
code: import_zod34.z.string(),
|
|
5022
5471
|
severity: QualitySeveritySchema,
|
|
5023
|
-
message:
|
|
5024
|
-
fieldId:
|
|
5472
|
+
message: import_zod34.z.string(),
|
|
5473
|
+
fieldId: import_zod34.z.string().optional()
|
|
5025
5474
|
});
|
|
5026
|
-
var ApplicationQualityRoundSchema =
|
|
5027
|
-
round:
|
|
5028
|
-
kind:
|
|
5475
|
+
var ApplicationQualityRoundSchema = import_zod34.z.object({
|
|
5476
|
+
round: import_zod34.z.number(),
|
|
5477
|
+
kind: import_zod34.z.string(),
|
|
5029
5478
|
status: QualityGateStatusSchema,
|
|
5030
|
-
summary:
|
|
5479
|
+
summary: import_zod34.z.string().optional()
|
|
5031
5480
|
});
|
|
5032
|
-
var ApplicationQualityArtifactSchema =
|
|
5033
|
-
kind:
|
|
5034
|
-
label:
|
|
5035
|
-
itemCount:
|
|
5481
|
+
var ApplicationQualityArtifactSchema = import_zod34.z.object({
|
|
5482
|
+
kind: import_zod34.z.string(),
|
|
5483
|
+
label: import_zod34.z.string().optional(),
|
|
5484
|
+
itemCount: import_zod34.z.number().optional()
|
|
5036
5485
|
});
|
|
5037
|
-
var ApplicationEmailReviewSchema =
|
|
5038
|
-
issues:
|
|
5486
|
+
var ApplicationEmailReviewSchema = import_zod34.z.object({
|
|
5487
|
+
issues: import_zod34.z.array(ApplicationQualityIssueSchema),
|
|
5039
5488
|
qualityGateStatus: QualityGateStatusSchema
|
|
5040
5489
|
});
|
|
5041
|
-
var ApplicationQualityReportSchema =
|
|
5042
|
-
issues:
|
|
5043
|
-
rounds:
|
|
5044
|
-
artifacts:
|
|
5490
|
+
var ApplicationQualityReportSchema = import_zod34.z.object({
|
|
5491
|
+
issues: import_zod34.z.array(ApplicationQualityIssueSchema),
|
|
5492
|
+
rounds: import_zod34.z.array(ApplicationQualityRoundSchema).optional(),
|
|
5493
|
+
artifacts: import_zod34.z.array(ApplicationQualityArtifactSchema).optional(),
|
|
5045
5494
|
emailReview: ApplicationEmailReviewSchema.optional(),
|
|
5046
5495
|
qualityGateStatus: QualityGateStatusSchema
|
|
5047
5496
|
});
|
|
5048
|
-
var ApplicationStateSchema =
|
|
5049
|
-
id:
|
|
5050
|
-
pdfBase64:
|
|
5051
|
-
title:
|
|
5052
|
-
applicationType:
|
|
5053
|
-
fields:
|
|
5054
|
-
batches:
|
|
5055
|
-
currentBatchIndex:
|
|
5497
|
+
var ApplicationStateSchema = import_zod34.z.object({
|
|
5498
|
+
id: import_zod34.z.string(),
|
|
5499
|
+
pdfBase64: import_zod34.z.string().optional().describe("Original PDF, omitted after extraction"),
|
|
5500
|
+
title: import_zod34.z.string().optional(),
|
|
5501
|
+
applicationType: import_zod34.z.string().nullable().optional(),
|
|
5502
|
+
fields: import_zod34.z.array(ApplicationFieldSchema),
|
|
5503
|
+
batches: import_zod34.z.array(import_zod34.z.array(import_zod34.z.string())).optional(),
|
|
5504
|
+
currentBatchIndex: import_zod34.z.number().default(0),
|
|
5056
5505
|
qualityReport: ApplicationQualityReportSchema.optional(),
|
|
5057
|
-
status:
|
|
5058
|
-
createdAt:
|
|
5059
|
-
updatedAt:
|
|
5506
|
+
status: import_zod34.z.enum(["classifying", "extracting", "auto_filling", "batching", "collecting", "confirming", "mapping", "complete"]),
|
|
5507
|
+
createdAt: import_zod34.z.number(),
|
|
5508
|
+
updatedAt: import_zod34.z.number()
|
|
5060
5509
|
});
|
|
5061
5510
|
|
|
5062
5511
|
// src/application/agents/classifier.ts
|
|
@@ -6189,73 +6638,73 @@ Respond with the final answer, deduplicated citations array, overall confidence
|
|
|
6189
6638
|
}
|
|
6190
6639
|
|
|
6191
6640
|
// src/schemas/query.ts
|
|
6192
|
-
var
|
|
6193
|
-
var QueryIntentSchema =
|
|
6641
|
+
var import_zod35 = require("zod");
|
|
6642
|
+
var QueryIntentSchema = import_zod35.z.enum([
|
|
6194
6643
|
"policy_question",
|
|
6195
6644
|
"coverage_comparison",
|
|
6196
6645
|
"document_search",
|
|
6197
6646
|
"claims_inquiry",
|
|
6198
6647
|
"general_knowledge"
|
|
6199
6648
|
]);
|
|
6200
|
-
var SubQuestionSchema =
|
|
6201
|
-
question:
|
|
6649
|
+
var SubQuestionSchema = import_zod35.z.object({
|
|
6650
|
+
question: import_zod35.z.string().describe("Atomic sub-question to retrieve and answer independently"),
|
|
6202
6651
|
intent: QueryIntentSchema,
|
|
6203
|
-
chunkTypes:
|
|
6204
|
-
documentFilters:
|
|
6205
|
-
type:
|
|
6206
|
-
carrier:
|
|
6207
|
-
insuredName:
|
|
6208
|
-
policyNumber:
|
|
6209
|
-
quoteNumber:
|
|
6652
|
+
chunkTypes: import_zod35.z.array(import_zod35.z.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
|
|
6653
|
+
documentFilters: import_zod35.z.object({
|
|
6654
|
+
type: import_zod35.z.enum(["policy", "quote"]).optional(),
|
|
6655
|
+
carrier: import_zod35.z.string().optional(),
|
|
6656
|
+
insuredName: import_zod35.z.string().optional(),
|
|
6657
|
+
policyNumber: import_zod35.z.string().optional(),
|
|
6658
|
+
quoteNumber: import_zod35.z.string().optional()
|
|
6210
6659
|
}).optional().describe("Structured filters to narrow document lookup")
|
|
6211
6660
|
});
|
|
6212
|
-
var QueryClassifyResultSchema =
|
|
6661
|
+
var QueryClassifyResultSchema = import_zod35.z.object({
|
|
6213
6662
|
intent: QueryIntentSchema,
|
|
6214
|
-
subQuestions:
|
|
6215
|
-
requiresDocumentLookup:
|
|
6216
|
-
requiresChunkSearch:
|
|
6217
|
-
requiresConversationHistory:
|
|
6663
|
+
subQuestions: import_zod35.z.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
|
|
6664
|
+
requiresDocumentLookup: import_zod35.z.boolean().describe("Whether structured document lookup is needed"),
|
|
6665
|
+
requiresChunkSearch: import_zod35.z.boolean().describe("Whether semantic chunk search is needed"),
|
|
6666
|
+
requiresConversationHistory: import_zod35.z.boolean().describe("Whether conversation history is relevant")
|
|
6218
6667
|
});
|
|
6219
|
-
var EvidenceItemSchema =
|
|
6220
|
-
source:
|
|
6221
|
-
chunkId:
|
|
6222
|
-
documentId:
|
|
6223
|
-
turnId:
|
|
6224
|
-
text:
|
|
6225
|
-
relevance:
|
|
6226
|
-
metadata:
|
|
6668
|
+
var EvidenceItemSchema = import_zod35.z.object({
|
|
6669
|
+
source: import_zod35.z.enum(["chunk", "document", "conversation"]),
|
|
6670
|
+
chunkId: import_zod35.z.string().optional(),
|
|
6671
|
+
documentId: import_zod35.z.string().optional(),
|
|
6672
|
+
turnId: import_zod35.z.string().optional(),
|
|
6673
|
+
text: import_zod35.z.string().describe("Text excerpt from the source"),
|
|
6674
|
+
relevance: import_zod35.z.number().min(0).max(1),
|
|
6675
|
+
metadata: import_zod35.z.array(import_zod35.z.object({ key: import_zod35.z.string(), value: import_zod35.z.string() })).optional()
|
|
6227
6676
|
});
|
|
6228
|
-
var RetrievalResultSchema =
|
|
6229
|
-
subQuestion:
|
|
6230
|
-
evidence:
|
|
6677
|
+
var RetrievalResultSchema = import_zod35.z.object({
|
|
6678
|
+
subQuestion: import_zod35.z.string(),
|
|
6679
|
+
evidence: import_zod35.z.array(EvidenceItemSchema)
|
|
6231
6680
|
});
|
|
6232
|
-
var CitationSchema =
|
|
6233
|
-
index:
|
|
6234
|
-
chunkId:
|
|
6235
|
-
documentId:
|
|
6236
|
-
documentType:
|
|
6237
|
-
field:
|
|
6238
|
-
quote:
|
|
6239
|
-
relevance:
|
|
6681
|
+
var CitationSchema = import_zod35.z.object({
|
|
6682
|
+
index: import_zod35.z.number().describe("Citation number [1], [2], etc."),
|
|
6683
|
+
chunkId: import_zod35.z.string().describe("Source chunk ID, e.g. doc-123:coverage:2"),
|
|
6684
|
+
documentId: import_zod35.z.string(),
|
|
6685
|
+
documentType: import_zod35.z.enum(["policy", "quote"]).optional(),
|
|
6686
|
+
field: import_zod35.z.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
|
|
6687
|
+
quote: import_zod35.z.string().describe("Exact text from source that supports the claim"),
|
|
6688
|
+
relevance: import_zod35.z.number().min(0).max(1)
|
|
6240
6689
|
});
|
|
6241
|
-
var SubAnswerSchema =
|
|
6242
|
-
subQuestion:
|
|
6243
|
-
answer:
|
|
6244
|
-
citations:
|
|
6245
|
-
confidence:
|
|
6246
|
-
needsMoreContext:
|
|
6690
|
+
var SubAnswerSchema = import_zod35.z.object({
|
|
6691
|
+
subQuestion: import_zod35.z.string(),
|
|
6692
|
+
answer: import_zod35.z.string(),
|
|
6693
|
+
citations: import_zod35.z.array(CitationSchema),
|
|
6694
|
+
confidence: import_zod35.z.number().min(0).max(1),
|
|
6695
|
+
needsMoreContext: import_zod35.z.boolean().describe("True if evidence was insufficient to answer fully")
|
|
6247
6696
|
});
|
|
6248
|
-
var VerifyResultSchema =
|
|
6249
|
-
approved:
|
|
6250
|
-
issues:
|
|
6251
|
-
retrySubQuestions:
|
|
6697
|
+
var VerifyResultSchema = import_zod35.z.object({
|
|
6698
|
+
approved: import_zod35.z.boolean().describe("Whether all sub-answers are adequately grounded"),
|
|
6699
|
+
issues: import_zod35.z.array(import_zod35.z.string()).describe("Specific grounding or consistency issues found"),
|
|
6700
|
+
retrySubQuestions: import_zod35.z.array(import_zod35.z.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
|
|
6252
6701
|
});
|
|
6253
|
-
var QueryResultSchema =
|
|
6254
|
-
answer:
|
|
6255
|
-
citations:
|
|
6702
|
+
var QueryResultSchema = import_zod35.z.object({
|
|
6703
|
+
answer: import_zod35.z.string(),
|
|
6704
|
+
citations: import_zod35.z.array(CitationSchema),
|
|
6256
6705
|
intent: QueryIntentSchema,
|
|
6257
|
-
confidence:
|
|
6258
|
-
followUp:
|
|
6706
|
+
confidence: import_zod35.z.number().min(0).max(1),
|
|
6707
|
+
followUp: import_zod35.z.string().optional().describe("Suggested follow-up question if applicable")
|
|
6259
6708
|
});
|
|
6260
6709
|
|
|
6261
6710
|
// src/query/retriever.ts
|