@claritylabs/cl-sdk 4.3.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -179,10 +179,15 @@ __export(src_exports, {
179
179
  NamedInsuredSchema: () => NamedInsuredSchema,
180
180
  OperationalAddressSchema: () => OperationalAddressSchema,
181
181
  OperationalCoverageLineSchema: () => OperationalCoverageLineSchema,
182
+ OperationalCoverageScheduleItemSchema: () => OperationalCoverageScheduleItemSchema,
183
+ OperationalCoverageScheduleSchema: () => OperationalCoverageScheduleSchema,
184
+ OperationalCoverageScheduleValueSchema: () => OperationalCoverageScheduleValueSchema,
182
185
  OperationalCoverageTermSchema: () => OperationalCoverageTermSchema,
183
186
  OperationalDeclarationFactSchema: () => OperationalDeclarationFactSchema,
184
187
  OperationalEndorsementSupportSchema: () => OperationalEndorsementSupportSchema,
185
188
  OperationalPartySchema: () => OperationalPartySchema,
189
+ OperationalPremiumLineSchema: () => OperationalPremiumLineSchema,
190
+ OperationalTaxFeeItemSchema: () => OperationalTaxFeeItemSchema,
186
191
  PERSONAL_AUTO_USAGES: () => PERSONAL_AUTO_USAGES,
187
192
  PERSONAL_LOB_CODES: () => PERSONAL_LOB_CODES,
188
193
  PET_SPECIES: () => PET_SPECIES,
@@ -369,6 +374,8 @@ __export(src_exports, {
369
374
  proposeContextWrites: () => proposeContextWrites,
370
375
  resolveModelBudget: () => resolveModelBudget,
371
376
  resolveOperationalProfileLinesOfBusiness: () => resolveOperationalProfileLinesOfBusiness,
377
+ runCoverageRecovery: () => runCoverageRecovery,
378
+ runSourceTreeExtraction: () => runSourceTreeExtraction,
372
379
  safeGenerateObject: () => safeGenerateObject,
373
380
  sanitizeNulls: () => sanitizeNulls,
374
381
  scoreCaseProposal: () => scoreCaseProposal,
@@ -2009,251 +2016,541 @@ var DeclarationsSchema = import_zod16.z.discriminatedUnion("line", [
2009
2016
  ]);
2010
2017
 
2011
2018
  // src/schemas/document.ts
2019
+ var import_zod18 = require("zod");
2020
+
2021
+ // src/source/schemas.ts
2012
2022
  var import_zod17 = require("zod");
2013
- var SubsectionSchema = import_zod17.z.object({
2014
- title: import_zod17.z.string(),
2015
- sectionNumber: import_zod17.z.string().optional(),
2016
- pageNumber: import_zod17.z.number().optional(),
2017
- excerpt: import_zod17.z.string().optional(),
2018
- content: import_zod17.z.string().optional(),
2019
- documentNodeId: import_zod17.z.string().optional(),
2020
- sourceSpanIds: import_zod17.z.array(import_zod17.z.string()).optional(),
2021
- sourceTextHash: import_zod17.z.string().optional()
2022
- });
2023
- var SectionSchema = import_zod17.z.object({
2023
+ var SourceSpanKindSchema = import_zod17.z.enum([
2024
+ "pdf_text",
2025
+ "pdf_image",
2026
+ "html",
2027
+ "markdown",
2028
+ "plain_text",
2029
+ "structured_field"
2030
+ ]);
2031
+ var SourceSpanUnitSchema = import_zod17.z.enum([
2032
+ "page",
2033
+ "section",
2034
+ "table",
2035
+ "table_row",
2036
+ "table_cell",
2037
+ "key_value",
2038
+ "text"
2039
+ ]);
2040
+ var SourceKindSchema = import_zod17.z.enum([
2041
+ "policy_pdf",
2042
+ "application_pdf",
2043
+ "email",
2044
+ "attachment",
2045
+ "manual_note"
2046
+ ]);
2047
+ var SourceSpanBBoxSchema = import_zod17.z.object({
2048
+ page: import_zod17.z.number().int().positive(),
2049
+ x: import_zod17.z.number(),
2050
+ y: import_zod17.z.number(),
2051
+ width: import_zod17.z.number(),
2052
+ height: import_zod17.z.number()
2053
+ });
2054
+ var SourceSpanLocationSchema = import_zod17.z.object({
2055
+ page: import_zod17.z.number().int().positive().optional(),
2056
+ startPage: import_zod17.z.number().int().positive().optional(),
2057
+ endPage: import_zod17.z.number().int().positive().optional(),
2058
+ charStart: import_zod17.z.number().int().nonnegative().optional(),
2059
+ charEnd: import_zod17.z.number().int().nonnegative().optional(),
2060
+ lineStart: import_zod17.z.number().int().positive().optional(),
2061
+ lineEnd: import_zod17.z.number().int().positive().optional(),
2062
+ fieldPath: import_zod17.z.string().optional()
2063
+ });
2064
+ var SourceSpanTableLocationSchema = import_zod17.z.object({
2065
+ tableId: import_zod17.z.string().optional(),
2066
+ rowIndex: import_zod17.z.number().int().nonnegative().optional(),
2067
+ columnIndex: import_zod17.z.number().int().nonnegative().optional(),
2068
+ columnName: import_zod17.z.string().optional(),
2069
+ rowSpanId: import_zod17.z.string().optional(),
2070
+ tableSpanId: import_zod17.z.string().optional(),
2071
+ isHeader: import_zod17.z.boolean().optional()
2072
+ });
2073
+ var SourceSpanSchema = import_zod17.z.object({
2074
+ id: import_zod17.z.string().min(1),
2075
+ documentId: import_zod17.z.string().min(1),
2076
+ sourceKind: SourceKindSchema.optional(),
2077
+ chunkId: import_zod17.z.string().optional(),
2078
+ kind: SourceSpanKindSchema,
2079
+ text: import_zod17.z.string(),
2080
+ hash: import_zod17.z.string().min(1),
2081
+ textHash: import_zod17.z.string().optional(),
2082
+ pageStart: import_zod17.z.number().int().positive().optional(),
2083
+ pageEnd: import_zod17.z.number().int().positive().optional(),
2084
+ sectionId: import_zod17.z.string().optional(),
2085
+ formNumber: import_zod17.z.string().optional(),
2086
+ sourceUnit: SourceSpanUnitSchema.optional(),
2087
+ parentSpanId: import_zod17.z.string().optional(),
2088
+ table: SourceSpanTableLocationSchema.optional(),
2089
+ bbox: import_zod17.z.array(SourceSpanBBoxSchema).optional(),
2090
+ location: SourceSpanLocationSchema.optional(),
2091
+ metadata: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.string()).optional()
2092
+ });
2093
+ var SourceSpanRefSchema = import_zod17.z.object({
2094
+ sourceSpanId: import_zod17.z.string().min(1),
2095
+ documentId: import_zod17.z.string().min(1).optional(),
2096
+ chunkId: import_zod17.z.string().optional(),
2097
+ quote: import_zod17.z.string().optional(),
2098
+ hash: import_zod17.z.string().optional(),
2099
+ location: SourceSpanLocationSchema.optional()
2100
+ });
2101
+ var SourceChunkSchema = import_zod17.z.object({
2102
+ id: import_zod17.z.string().min(1),
2103
+ documentId: import_zod17.z.string().min(1),
2104
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)),
2105
+ text: import_zod17.z.string(),
2106
+ textHash: import_zod17.z.string().min(1),
2107
+ pageStart: import_zod17.z.number().int().positive().optional(),
2108
+ pageEnd: import_zod17.z.number().int().positive().optional(),
2109
+ metadata: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.string()).default({})
2110
+ });
2111
+ var DocumentSourceNodeKindSchema = import_zod17.z.enum([
2112
+ "document",
2113
+ "page_group",
2114
+ "page",
2115
+ "form",
2116
+ "endorsement",
2117
+ "section",
2118
+ "schedule",
2119
+ "clause",
2120
+ "table",
2121
+ "table_row",
2122
+ "table_cell",
2123
+ "text"
2124
+ ]);
2125
+ var DocumentSourceNodeSchema = import_zod17.z.object({
2126
+ id: import_zod17.z.string().min(1),
2127
+ documentId: import_zod17.z.string().min(1),
2128
+ parentId: import_zod17.z.string().optional(),
2129
+ kind: DocumentSourceNodeKindSchema,
2024
2130
  title: import_zod17.z.string(),
2025
- sectionNumber: import_zod17.z.string().optional(),
2026
- pageStart: import_zod17.z.number(),
2027
- pageEnd: import_zod17.z.number().optional(),
2028
- type: import_zod17.z.string(),
2029
- coverageType: import_zod17.z.string().optional(),
2030
- excerpt: import_zod17.z.string().optional(),
2031
- content: import_zod17.z.string().optional(),
2032
- subsections: import_zod17.z.array(SubsectionSchema).optional(),
2033
- recordId: import_zod17.z.string().optional(),
2034
- documentNodeId: import_zod17.z.string().optional(),
2035
- sourceSpanIds: import_zod17.z.array(import_zod17.z.string()).optional(),
2036
- sourceTextHash: import_zod17.z.string().optional()
2037
- });
2038
- var SubjectivitySchema = import_zod17.z.object({
2039
2131
  description: import_zod17.z.string(),
2040
- category: import_zod17.z.string().optional()
2132
+ textExcerpt: import_zod17.z.string().optional(),
2133
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)),
2134
+ pageStart: import_zod17.z.number().int().positive().optional(),
2135
+ pageEnd: import_zod17.z.number().int().positive().optional(),
2136
+ bbox: import_zod17.z.array(SourceSpanBBoxSchema).optional(),
2137
+ order: import_zod17.z.number().int().nonnegative(),
2138
+ path: import_zod17.z.string(),
2139
+ metadata: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.unknown()).optional()
2140
+ });
2141
+ var SourceBackedValueSchema = import_zod17.z.object({
2142
+ value: import_zod17.z.string(),
2143
+ normalizedValue: import_zod17.z.string().optional(),
2144
+ confidence: import_zod17.z.enum(["low", "medium", "high"]).default("medium"),
2145
+ sourceNodeIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2146
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([])
2147
+ });
2148
+ var OperationalAddressSchema = import_zod17.z.object({
2149
+ street1: import_zod17.z.string().optional(),
2150
+ street2: import_zod17.z.string().optional(),
2151
+ city: import_zod17.z.string().optional(),
2152
+ state: import_zod17.z.string().optional(),
2153
+ zip: import_zod17.z.string().optional(),
2154
+ country: import_zod17.z.string().optional(),
2155
+ formatted: import_zod17.z.string().optional()
2156
+ });
2157
+ var OperationalDeclarationFactSchema = import_zod17.z.object({
2158
+ field: import_zod17.z.enum([
2159
+ "namedInsured",
2160
+ "mailingAddress",
2161
+ "dba",
2162
+ "entityType",
2163
+ "taxId",
2164
+ "additionalNamedInsured",
2165
+ "policyNumber",
2166
+ "insurer",
2167
+ "broker",
2168
+ "effectiveDate",
2169
+ "expirationDate",
2170
+ "premium",
2171
+ "other"
2172
+ ]),
2173
+ label: import_zod17.z.string().optional(),
2174
+ value: import_zod17.z.string(),
2175
+ normalizedValue: import_zod17.z.string().optional(),
2176
+ valueKind: import_zod17.z.enum(["string", "number", "date", "money", "address", "list", "unknown"]).default("string"),
2177
+ address: OperationalAddressSchema.optional(),
2178
+ confidence: import_zod17.z.enum(["low", "medium", "high"]).default("medium"),
2179
+ sourceNodeIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2180
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([])
2041
2181
  });
2042
- var UnderwritingConditionSchema = import_zod17.z.object({
2043
- description: import_zod17.z.string()
2182
+ var OperationalCoverageTermSchema = import_zod17.z.object({
2183
+ kind: import_zod17.z.enum([
2184
+ "each_claim_limit",
2185
+ "each_occurrence_limit",
2186
+ "each_loss_limit",
2187
+ "aggregate_limit",
2188
+ "sublimit",
2189
+ "retention",
2190
+ "deductible",
2191
+ "retroactive_date",
2192
+ "premium",
2193
+ "other"
2194
+ ]).default("other"),
2195
+ label: import_zod17.z.string(),
2196
+ value: import_zod17.z.string(),
2197
+ amount: import_zod17.z.number().optional(),
2198
+ appliesTo: import_zod17.z.string().optional(),
2199
+ sourceNodeIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2200
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([])
2044
2201
  });
2045
- var PremiumLineSchema = import_zod17.z.object({
2202
+ var OperationalCoverageLineSchema = import_zod17.z.object({
2203
+ name: import_zod17.z.string(),
2204
+ lineOfBusiness: AcordLobCodeSchema.optional(),
2205
+ coverageCode: import_zod17.z.string().optional(),
2206
+ limit: import_zod17.z.string().optional(),
2207
+ deductible: import_zod17.z.string().optional(),
2208
+ premium: import_zod17.z.string().optional(),
2209
+ retroactiveDate: import_zod17.z.string().optional(),
2210
+ formNumber: import_zod17.z.string().optional(),
2211
+ sectionRef: import_zod17.z.string().optional(),
2212
+ endorsementNumber: import_zod17.z.string().optional(),
2213
+ limits: import_zod17.z.array(OperationalCoverageTermSchema).default([]),
2214
+ sourceNodeIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2215
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([])
2216
+ });
2217
+ var OperationalCoverageScheduleValueSchema = import_zod17.z.object({
2218
+ label: import_zod17.z.string(),
2219
+ value: import_zod17.z.string()
2220
+ });
2221
+ var OperationalCoverageScheduleItemSchema = import_zod17.z.object({
2222
+ label: import_zod17.z.string(),
2223
+ description: import_zod17.z.string().optional(),
2224
+ values: import_zod17.z.array(OperationalCoverageScheduleValueSchema).default([]),
2225
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([])
2226
+ });
2227
+ var OperationalCoverageScheduleSchema = import_zod17.z.object({
2228
+ name: import_zod17.z.string(),
2229
+ kind: import_zod17.z.enum(["vehicle", "property", "location", "other"]),
2230
+ description: import_zod17.z.string().optional(),
2231
+ items: import_zod17.z.array(OperationalCoverageScheduleItemSchema).default([]),
2232
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2233
+ pageStart: import_zod17.z.number().int().positive().optional(),
2234
+ pageEnd: import_zod17.z.number().int().positive().optional()
2235
+ });
2236
+ var OperationalPremiumLineSchema = import_zod17.z.object({
2046
2237
  line: import_zod17.z.string(),
2047
2238
  amount: import_zod17.z.string(),
2048
2239
  amountValue: import_zod17.z.number().optional(),
2049
- documentNodeId: import_zod17.z.string().optional(),
2050
- sourceSpanIds: import_zod17.z.array(import_zod17.z.string()).optional(),
2051
- sourceTextHash: import_zod17.z.string().optional()
2240
+ sourceNodeIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2241
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([])
2052
2242
  });
2053
- var AuxiliaryFactSchema = import_zod17.z.object({
2054
- key: import_zod17.z.string(),
2055
- value: import_zod17.z.string(),
2056
- subject: import_zod17.z.string().optional(),
2057
- context: import_zod17.z.string().optional(),
2058
- documentNodeId: import_zod17.z.string().optional(),
2059
- sourceSpanIds: import_zod17.z.array(import_zod17.z.string()).optional(),
2060
- sourceTextHash: import_zod17.z.string().optional()
2061
- });
2062
- var DefinitionSchema = import_zod17.z.object({
2063
- term: import_zod17.z.string(),
2064
- definition: import_zod17.z.string(),
2065
- pageNumber: import_zod17.z.number().optional(),
2066
- formNumber: import_zod17.z.string().optional(),
2067
- formTitle: import_zod17.z.string().optional(),
2068
- sectionRef: import_zod17.z.string().optional(),
2069
- originalContent: import_zod17.z.string().optional(),
2070
- recordId: import_zod17.z.string().optional(),
2071
- documentNodeId: import_zod17.z.string().optional(),
2072
- sourceSpanIds: import_zod17.z.array(import_zod17.z.string()).optional(),
2073
- sourceTextHash: import_zod17.z.string().optional()
2074
- });
2075
- var CoveredReasonSchema = import_zod17.z.object({
2076
- coverageName: import_zod17.z.string(),
2077
- reasonNumber: import_zod17.z.string().optional(),
2078
- title: import_zod17.z.string().optional(),
2079
- content: import_zod17.z.string(),
2080
- conditions: import_zod17.z.array(import_zod17.z.string()).optional(),
2081
- exceptions: import_zod17.z.array(import_zod17.z.string()).optional(),
2082
- appliesTo: import_zod17.z.array(import_zod17.z.string()).optional(),
2083
- pageNumber: import_zod17.z.number().optional(),
2084
- formNumber: import_zod17.z.string().optional(),
2085
- formTitle: import_zod17.z.string().optional(),
2086
- sectionRef: import_zod17.z.string().optional(),
2087
- originalContent: import_zod17.z.string().optional(),
2088
- recordId: import_zod17.z.string().optional(),
2089
- documentNodeId: import_zod17.z.string().optional(),
2090
- sourceSpanIds: import_zod17.z.array(import_zod17.z.string()).optional(),
2091
- sourceTextHash: import_zod17.z.string().optional()
2092
- });
2093
- var DocumentTableOfContentsEntrySchema = import_zod17.z.object({
2094
- title: import_zod17.z.string(),
2095
- level: import_zod17.z.number().int().positive().optional(),
2096
- pageStart: import_zod17.z.number().optional(),
2097
- pageEnd: import_zod17.z.number().optional(),
2098
- documentNodeId: import_zod17.z.string().optional(),
2099
- sourceSpanIds: import_zod17.z.array(import_zod17.z.string()).optional()
2100
- });
2101
- var DocumentPageMapEntrySchema = import_zod17.z.object({
2102
- page: import_zod17.z.number().int().positive(),
2103
- label: import_zod17.z.string().optional(),
2104
- formNumber: import_zod17.z.string().optional(),
2105
- formTitle: import_zod17.z.string().optional(),
2106
- sectionTitle: import_zod17.z.string().optional(),
2107
- extractorNames: import_zod17.z.array(import_zod17.z.string()).optional(),
2108
- sourceSpanIds: import_zod17.z.array(import_zod17.z.string()).optional()
2243
+ var OperationalTaxFeeItemSchema = import_zod17.z.object({
2244
+ name: import_zod17.z.string(),
2245
+ amount: import_zod17.z.string(),
2246
+ amountValue: import_zod17.z.number().optional(),
2247
+ type: import_zod17.z.string().optional(),
2248
+ description: import_zod17.z.string().optional(),
2249
+ sourceNodeIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2250
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([])
2251
+ });
2252
+ var OperationalPartySchema = import_zod17.z.object({
2253
+ role: import_zod17.z.string(),
2254
+ name: import_zod17.z.string(),
2255
+ address: OperationalAddressSchema.optional(),
2256
+ sourceNodeIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2257
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([])
2109
2258
  });
2110
- var DocumentAgentGuidanceSchema = import_zod17.z.object({
2259
+ var OperationalEndorsementSupportSchema = import_zod17.z.object({
2111
2260
  kind: import_zod17.z.string(),
2112
- title: import_zod17.z.string(),
2113
- detail: import_zod17.z.string(),
2114
- sourceSpanIds: import_zod17.z.array(import_zod17.z.string()).optional()
2115
- });
2116
- var DocumentMetadataSchema = import_zod17.z.object({
2117
- sourceTreeVersion: import_zod17.z.string().optional(),
2118
- sourceTreeCanonical: import_zod17.z.boolean().optional(),
2119
- formInventory: import_zod17.z.array(FormReferenceSchema).optional(),
2120
- tableOfContents: import_zod17.z.array(DocumentTableOfContentsEntrySchema).optional(),
2121
- pageMap: import_zod17.z.array(DocumentPageMapEntrySchema).optional(),
2122
- agentGuidance: import_zod17.z.array(DocumentAgentGuidanceSchema).optional()
2123
- });
2124
- var DocumentNodeSchema = import_zod17.z.lazy(
2125
- () => import_zod17.z.object({
2126
- id: import_zod17.z.string(),
2127
- title: import_zod17.z.string(),
2128
- originalTitle: import_zod17.z.string().optional(),
2129
- type: import_zod17.z.string().optional(),
2130
- label: import_zod17.z.string().optional(),
2131
- level: import_zod17.z.number().int().positive().optional(),
2132
- sectionNumber: import_zod17.z.string().optional(),
2133
- pageStart: import_zod17.z.number().optional(),
2134
- pageEnd: import_zod17.z.number().optional(),
2135
- formNumber: import_zod17.z.string().optional(),
2136
- formTitle: import_zod17.z.string().optional(),
2137
- excerpt: import_zod17.z.string().optional(),
2138
- content: import_zod17.z.string().optional(),
2139
- interpretationLabels: import_zod17.z.array(import_zod17.z.string()).optional(),
2140
- sourceSpanIds: import_zod17.z.array(import_zod17.z.string()).optional(),
2141
- sourceTextHash: import_zod17.z.string().optional(),
2142
- children: import_zod17.z.array(DocumentNodeSchema).optional()
2261
+ status: import_zod17.z.enum(["supported", "excluded", "requires_review"]),
2262
+ summary: import_zod17.z.string(),
2263
+ sourceNodeIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2264
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([])
2265
+ });
2266
+ function legacyOperationalProfileInput(value) {
2267
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
2268
+ const record = value;
2269
+ if ("linesOfBusiness" in record) return value;
2270
+ if (!("policyTypes" in record)) return value;
2271
+ return {
2272
+ ...record,
2273
+ linesOfBusiness: record.policyTypes
2274
+ };
2275
+ }
2276
+ var OperationalLinesOfBusinessSchema = import_zod17.z.preprocess(
2277
+ (value) => Array.isArray(value) ? toLobCodes(value.filter((item) => typeof item === "string")) : void 0,
2278
+ import_zod17.z.array(AcordLobCodeSchema).default(["UN"])
2279
+ );
2280
+ var PolicyOperationalProfileSchema = import_zod17.z.preprocess(
2281
+ legacyOperationalProfileInput,
2282
+ import_zod17.z.object({
2283
+ documentType: import_zod17.z.enum(["policy", "quote"]).default("policy"),
2284
+ linesOfBusiness: OperationalLinesOfBusinessSchema,
2285
+ policyNumber: SourceBackedValueSchema.optional(),
2286
+ namedInsured: SourceBackedValueSchema.optional(),
2287
+ insurer: SourceBackedValueSchema.optional(),
2288
+ broker: SourceBackedValueSchema.optional(),
2289
+ effectiveDate: SourceBackedValueSchema.optional(),
2290
+ expirationDate: SourceBackedValueSchema.optional(),
2291
+ retroactiveDate: SourceBackedValueSchema.optional(),
2292
+ premium: SourceBackedValueSchema.optional(),
2293
+ operationsDescription: SourceBackedValueSchema.optional(),
2294
+ declarationFacts: import_zod17.z.array(OperationalDeclarationFactSchema).default([]),
2295
+ coverages: import_zod17.z.array(OperationalCoverageLineSchema).default([]),
2296
+ coverageSchedules: import_zod17.z.array(OperationalCoverageScheduleSchema).optional(),
2297
+ premiumBreakdown: import_zod17.z.array(OperationalPremiumLineSchema).optional(),
2298
+ taxesAndFees: import_zod17.z.array(OperationalTaxFeeItemSchema).optional(),
2299
+ totalCost: SourceBackedValueSchema.optional(),
2300
+ parties: import_zod17.z.array(OperationalPartySchema).default([]),
2301
+ endorsementSupport: import_zod17.z.array(OperationalEndorsementSupportSchema).default([]),
2302
+ sourceNodeIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2303
+ sourceSpanIds: import_zod17.z.array(import_zod17.z.string().min(1)).default([]),
2304
+ warnings: import_zod17.z.array(import_zod17.z.string()).default([])
2305
+ })
2306
+ );
2307
+
2308
+ // src/schemas/document.ts
2309
+ var SubsectionSchema = import_zod18.z.object({
2310
+ title: import_zod18.z.string(),
2311
+ sectionNumber: import_zod18.z.string().optional(),
2312
+ pageNumber: import_zod18.z.number().optional(),
2313
+ excerpt: import_zod18.z.string().optional(),
2314
+ content: import_zod18.z.string().optional(),
2315
+ documentNodeId: import_zod18.z.string().optional(),
2316
+ sourceSpanIds: import_zod18.z.array(import_zod18.z.string()).optional(),
2317
+ sourceTextHash: import_zod18.z.string().optional()
2318
+ });
2319
+ var SectionSchema = import_zod18.z.object({
2320
+ title: import_zod18.z.string(),
2321
+ sectionNumber: import_zod18.z.string().optional(),
2322
+ pageStart: import_zod18.z.number(),
2323
+ pageEnd: import_zod18.z.number().optional(),
2324
+ type: import_zod18.z.string(),
2325
+ coverageType: import_zod18.z.string().optional(),
2326
+ excerpt: import_zod18.z.string().optional(),
2327
+ content: import_zod18.z.string().optional(),
2328
+ subsections: import_zod18.z.array(SubsectionSchema).optional(),
2329
+ recordId: import_zod18.z.string().optional(),
2330
+ documentNodeId: import_zod18.z.string().optional(),
2331
+ sourceSpanIds: import_zod18.z.array(import_zod18.z.string()).optional(),
2332
+ sourceTextHash: import_zod18.z.string().optional()
2333
+ });
2334
+ var SubjectivitySchema = import_zod18.z.object({
2335
+ description: import_zod18.z.string(),
2336
+ category: import_zod18.z.string().optional()
2337
+ });
2338
+ var UnderwritingConditionSchema = import_zod18.z.object({
2339
+ description: import_zod18.z.string()
2340
+ });
2341
+ var PremiumLineSchema = import_zod18.z.object({
2342
+ line: import_zod18.z.string(),
2343
+ amount: import_zod18.z.string(),
2344
+ amountValue: import_zod18.z.number().optional(),
2345
+ documentNodeId: import_zod18.z.string().optional(),
2346
+ sourceSpanIds: import_zod18.z.array(import_zod18.z.string()).optional(),
2347
+ sourceTextHash: import_zod18.z.string().optional()
2348
+ });
2349
+ var AuxiliaryFactSchema = import_zod18.z.object({
2350
+ key: import_zod18.z.string(),
2351
+ value: import_zod18.z.string(),
2352
+ subject: import_zod18.z.string().optional(),
2353
+ context: import_zod18.z.string().optional(),
2354
+ documentNodeId: import_zod18.z.string().optional(),
2355
+ sourceSpanIds: import_zod18.z.array(import_zod18.z.string()).optional(),
2356
+ sourceTextHash: import_zod18.z.string().optional()
2357
+ });
2358
+ var DefinitionSchema = import_zod18.z.object({
2359
+ term: import_zod18.z.string(),
2360
+ definition: import_zod18.z.string(),
2361
+ pageNumber: import_zod18.z.number().optional(),
2362
+ formNumber: import_zod18.z.string().optional(),
2363
+ formTitle: import_zod18.z.string().optional(),
2364
+ sectionRef: import_zod18.z.string().optional(),
2365
+ originalContent: import_zod18.z.string().optional(),
2366
+ recordId: import_zod18.z.string().optional(),
2367
+ documentNodeId: import_zod18.z.string().optional(),
2368
+ sourceSpanIds: import_zod18.z.array(import_zod18.z.string()).optional(),
2369
+ sourceTextHash: import_zod18.z.string().optional()
2370
+ });
2371
+ var CoveredReasonSchema = import_zod18.z.object({
2372
+ coverageName: import_zod18.z.string(),
2373
+ reasonNumber: import_zod18.z.string().optional(),
2374
+ title: import_zod18.z.string().optional(),
2375
+ content: import_zod18.z.string(),
2376
+ conditions: import_zod18.z.array(import_zod18.z.string()).optional(),
2377
+ exceptions: import_zod18.z.array(import_zod18.z.string()).optional(),
2378
+ appliesTo: import_zod18.z.array(import_zod18.z.string()).optional(),
2379
+ pageNumber: import_zod18.z.number().optional(),
2380
+ formNumber: import_zod18.z.string().optional(),
2381
+ formTitle: import_zod18.z.string().optional(),
2382
+ sectionRef: import_zod18.z.string().optional(),
2383
+ originalContent: import_zod18.z.string().optional(),
2384
+ recordId: import_zod18.z.string().optional(),
2385
+ documentNodeId: import_zod18.z.string().optional(),
2386
+ sourceSpanIds: import_zod18.z.array(import_zod18.z.string()).optional(),
2387
+ sourceTextHash: import_zod18.z.string().optional()
2388
+ });
2389
+ var DocumentTableOfContentsEntrySchema = import_zod18.z.object({
2390
+ title: import_zod18.z.string(),
2391
+ level: import_zod18.z.number().int().positive().optional(),
2392
+ pageStart: import_zod18.z.number().optional(),
2393
+ pageEnd: import_zod18.z.number().optional(),
2394
+ documentNodeId: import_zod18.z.string().optional(),
2395
+ sourceSpanIds: import_zod18.z.array(import_zod18.z.string()).optional()
2396
+ });
2397
+ var DocumentPageMapEntrySchema = import_zod18.z.object({
2398
+ page: import_zod18.z.number().int().positive(),
2399
+ label: import_zod18.z.string().optional(),
2400
+ formNumber: import_zod18.z.string().optional(),
2401
+ formTitle: import_zod18.z.string().optional(),
2402
+ sectionTitle: import_zod18.z.string().optional(),
2403
+ extractorNames: import_zod18.z.array(import_zod18.z.string()).optional(),
2404
+ sourceSpanIds: import_zod18.z.array(import_zod18.z.string()).optional()
2405
+ });
2406
+ var DocumentAgentGuidanceSchema = import_zod18.z.object({
2407
+ kind: import_zod18.z.string(),
2408
+ title: import_zod18.z.string(),
2409
+ detail: import_zod18.z.string(),
2410
+ sourceSpanIds: import_zod18.z.array(import_zod18.z.string()).optional()
2411
+ });
2412
+ var DocumentMetadataSchema = import_zod18.z.object({
2413
+ sourceTreeVersion: import_zod18.z.string().optional(),
2414
+ sourceTreeCanonical: import_zod18.z.boolean().optional(),
2415
+ formInventory: import_zod18.z.array(FormReferenceSchema).optional(),
2416
+ tableOfContents: import_zod18.z.array(DocumentTableOfContentsEntrySchema).optional(),
2417
+ pageMap: import_zod18.z.array(DocumentPageMapEntrySchema).optional(),
2418
+ agentGuidance: import_zod18.z.array(DocumentAgentGuidanceSchema).optional()
2419
+ });
2420
+ var DocumentNodeSchema = import_zod18.z.lazy(
2421
+ () => import_zod18.z.object({
2422
+ id: import_zod18.z.string(),
2423
+ title: import_zod18.z.string(),
2424
+ originalTitle: import_zod18.z.string().optional(),
2425
+ type: import_zod18.z.string().optional(),
2426
+ label: import_zod18.z.string().optional(),
2427
+ level: import_zod18.z.number().int().positive().optional(),
2428
+ sectionNumber: import_zod18.z.string().optional(),
2429
+ pageStart: import_zod18.z.number().optional(),
2430
+ pageEnd: import_zod18.z.number().optional(),
2431
+ formNumber: import_zod18.z.string().optional(),
2432
+ formTitle: import_zod18.z.string().optional(),
2433
+ excerpt: import_zod18.z.string().optional(),
2434
+ content: import_zod18.z.string().optional(),
2435
+ interpretationLabels: import_zod18.z.array(import_zod18.z.string()).optional(),
2436
+ sourceSpanIds: import_zod18.z.array(import_zod18.z.string()).optional(),
2437
+ sourceTextHash: import_zod18.z.string().optional(),
2438
+ children: import_zod18.z.array(DocumentNodeSchema).optional()
2143
2439
  })
2144
2440
  );
2145
2441
  var BaseDocumentFields = {
2146
- id: import_zod17.z.string(),
2147
- carrier: import_zod17.z.string(),
2148
- security: import_zod17.z.string().optional(),
2149
- insuredName: import_zod17.z.string(),
2150
- premium: import_zod17.z.string().optional(),
2151
- premiumAmount: import_zod17.z.number().optional(),
2152
- summary: import_zod17.z.string().optional(),
2153
- linesOfBusiness: import_zod17.z.array(import_zod17.z.string()).optional(),
2154
- coverages: import_zod17.z.array(CoverageSchema),
2442
+ id: import_zod18.z.string(),
2443
+ carrier: import_zod18.z.string(),
2444
+ security: import_zod18.z.string().optional(),
2445
+ insuredName: import_zod18.z.string(),
2446
+ premium: import_zod18.z.string().optional(),
2447
+ premiumAmount: import_zod18.z.number().optional(),
2448
+ premiumBreakdown: import_zod18.z.array(PremiumLineSchema).optional(),
2449
+ summary: import_zod18.z.string().optional(),
2450
+ linesOfBusiness: import_zod18.z.array(import_zod18.z.string()).optional(),
2451
+ coverages: import_zod18.z.array(CoverageSchema),
2155
2452
  documentMetadata: DocumentMetadataSchema,
2156
- documentOutline: import_zod17.z.array(DocumentNodeSchema),
2157
- sections: import_zod17.z.array(SectionSchema).optional(),
2158
- definitions: import_zod17.z.array(DefinitionSchema).optional(),
2159
- coveredReasons: import_zod17.z.array(CoveredReasonSchema).optional(),
2453
+ documentOutline: import_zod18.z.array(DocumentNodeSchema),
2454
+ sections: import_zod18.z.array(SectionSchema).optional(),
2455
+ definitions: import_zod18.z.array(DefinitionSchema).optional(),
2456
+ coveredReasons: import_zod18.z.array(CoveredReasonSchema).optional(),
2160
2457
  // Enriched fields (v1.2+)
2161
- carrierLegalName: import_zod17.z.string().optional(),
2162
- carrierNaicNumber: import_zod17.z.string().optional(),
2163
- carrierAmBestRating: import_zod17.z.string().optional(),
2164
- carrierAdmittedStatus: import_zod17.z.string().optional(),
2165
- mga: import_zod17.z.string().optional(),
2166
- underwriter: import_zod17.z.string().optional(),
2167
- brokerAgency: import_zod17.z.string().optional(),
2168
- brokerContactName: import_zod17.z.string().optional(),
2169
- brokerLicenseNumber: import_zod17.z.string().optional(),
2170
- priorPolicyNumber: import_zod17.z.string().optional(),
2171
- programName: import_zod17.z.string().optional(),
2172
- isRenewal: import_zod17.z.boolean().optional(),
2173
- isPackage: import_zod17.z.boolean().optional(),
2174
- insuredDba: import_zod17.z.string().optional(),
2458
+ carrierLegalName: import_zod18.z.string().optional(),
2459
+ carrierNaicNumber: import_zod18.z.string().optional(),
2460
+ carrierAmBestRating: import_zod18.z.string().optional(),
2461
+ carrierAdmittedStatus: import_zod18.z.string().optional(),
2462
+ mga: import_zod18.z.string().optional(),
2463
+ underwriter: import_zod18.z.string().optional(),
2464
+ brokerAgency: import_zod18.z.string().optional(),
2465
+ brokerContactName: import_zod18.z.string().optional(),
2466
+ brokerLicenseNumber: import_zod18.z.string().optional(),
2467
+ priorPolicyNumber: import_zod18.z.string().optional(),
2468
+ programName: import_zod18.z.string().optional(),
2469
+ isRenewal: import_zod18.z.boolean().optional(),
2470
+ isPackage: import_zod18.z.boolean().optional(),
2471
+ insuredDba: import_zod18.z.string().optional(),
2175
2472
  insuredAddress: SourceBackedAddressSchema.optional(),
2176
2473
  insuredEntityType: EntityTypeSchema.optional(),
2177
- additionalNamedInsureds: import_zod17.z.array(NamedInsuredSchema).optional(),
2178
- insuredSicCode: import_zod17.z.string().optional(),
2179
- insuredNaicsCode: import_zod17.z.string().optional(),
2180
- insuredFein: import_zod17.z.string().optional(),
2181
- enrichedCoverages: import_zod17.z.array(EnrichedCoverageSchema).optional(),
2182
- endorsements: import_zod17.z.array(EndorsementSchema).optional(),
2183
- exclusions: import_zod17.z.array(ExclusionSchema).optional(),
2184
- conditions: import_zod17.z.array(PolicyConditionSchema).optional(),
2474
+ additionalNamedInsureds: import_zod18.z.array(NamedInsuredSchema).optional(),
2475
+ insuredSicCode: import_zod18.z.string().optional(),
2476
+ insuredNaicsCode: import_zod18.z.string().optional(),
2477
+ insuredFein: import_zod18.z.string().optional(),
2478
+ enrichedCoverages: import_zod18.z.array(EnrichedCoverageSchema).optional(),
2479
+ endorsements: import_zod18.z.array(EndorsementSchema).optional(),
2480
+ exclusions: import_zod18.z.array(ExclusionSchema).optional(),
2481
+ conditions: import_zod18.z.array(PolicyConditionSchema).optional(),
2185
2482
  limits: LimitScheduleSchema.optional(),
2186
2483
  deductibles: DeductibleScheduleSchema.optional(),
2187
- locations: import_zod17.z.array(InsuredLocationSchema).optional(),
2188
- vehicles: import_zod17.z.array(InsuredVehicleSchema).optional(),
2189
- classifications: import_zod17.z.array(ClassificationCodeSchema).optional(),
2190
- formInventory: import_zod17.z.array(FormReferenceSchema).optional(),
2484
+ locations: import_zod18.z.array(InsuredLocationSchema).optional(),
2485
+ vehicles: import_zod18.z.array(InsuredVehicleSchema).optional(),
2486
+ classifications: import_zod18.z.array(ClassificationCodeSchema).optional(),
2487
+ coverageSchedules: import_zod18.z.array(OperationalCoverageScheduleSchema).optional(),
2488
+ formInventory: import_zod18.z.array(FormReferenceSchema).optional(),
2191
2489
  declarations: DeclarationsSchema.optional(),
2192
2490
  coverageForm: CoverageFormSchema.optional(),
2193
- retroactiveDate: import_zod17.z.string().optional(),
2491
+ retroactiveDate: import_zod18.z.string().optional(),
2194
2492
  extendedReportingPeriod: ExtendedReportingPeriodSchema.optional(),
2195
2493
  insurer: InsurerInfoSchema.optional(),
2196
2494
  producer: ProducerInfoSchema.optional(),
2197
- claimsContacts: import_zod17.z.array(ContactSchema).optional(),
2198
- regulatoryContacts: import_zod17.z.array(ContactSchema).optional(),
2199
- thirdPartyAdministrators: import_zod17.z.array(ContactSchema).optional(),
2200
- additionalInsureds: import_zod17.z.array(EndorsementPartySchema).optional(),
2201
- lossPayees: import_zod17.z.array(EndorsementPartySchema).optional(),
2202
- mortgageHolders: import_zod17.z.array(EndorsementPartySchema).optional(),
2203
- taxesAndFees: import_zod17.z.array(TaxFeeItemSchema).optional(),
2204
- totalCost: import_zod17.z.string().optional(),
2205
- totalCostAmount: import_zod17.z.number().optional(),
2206
- minimumPremium: import_zod17.z.string().optional(),
2207
- minimumPremiumAmount: import_zod17.z.number().optional(),
2208
- depositPremium: import_zod17.z.string().optional(),
2209
- depositPremiumAmount: import_zod17.z.number().optional(),
2495
+ claimsContacts: import_zod18.z.array(ContactSchema).optional(),
2496
+ regulatoryContacts: import_zod18.z.array(ContactSchema).optional(),
2497
+ thirdPartyAdministrators: import_zod18.z.array(ContactSchema).optional(),
2498
+ additionalInsureds: import_zod18.z.array(EndorsementPartySchema).optional(),
2499
+ lossPayees: import_zod18.z.array(EndorsementPartySchema).optional(),
2500
+ mortgageHolders: import_zod18.z.array(EndorsementPartySchema).optional(),
2501
+ taxesAndFees: import_zod18.z.array(TaxFeeItemSchema).optional(),
2502
+ totalCost: import_zod18.z.string().optional(),
2503
+ totalCostAmount: import_zod18.z.number().optional(),
2504
+ minimumPremium: import_zod18.z.string().optional(),
2505
+ minimumPremiumAmount: import_zod18.z.number().optional(),
2506
+ depositPremium: import_zod18.z.string().optional(),
2507
+ depositPremiumAmount: import_zod18.z.number().optional(),
2210
2508
  paymentPlan: PaymentPlanSchema.optional(),
2211
2509
  auditType: AuditTypeSchema.optional(),
2212
- ratingBasis: import_zod17.z.array(RatingBasisSchema).optional(),
2213
- premiumByLocation: import_zod17.z.array(LocationPremiumSchema).optional(),
2510
+ ratingBasis: import_zod18.z.array(RatingBasisSchema).optional(),
2511
+ premiumByLocation: import_zod18.z.array(LocationPremiumSchema).optional(),
2214
2512
  lossSummary: LossSummarySchema.optional(),
2215
- individualClaims: import_zod17.z.array(ClaimRecordSchema).optional(),
2513
+ individualClaims: import_zod18.z.array(ClaimRecordSchema).optional(),
2216
2514
  experienceMod: ExperienceModSchema.optional(),
2217
- cancellationNoticeDays: import_zod17.z.number().optional(),
2218
- nonrenewalNoticeDays: import_zod17.z.number().optional(),
2219
- supplementaryFacts: import_zod17.z.array(AuxiliaryFactSchema).optional()
2515
+ cancellationNoticeDays: import_zod18.z.number().optional(),
2516
+ nonrenewalNoticeDays: import_zod18.z.number().optional(),
2517
+ supplementaryFacts: import_zod18.z.array(AuxiliaryFactSchema).optional()
2220
2518
  };
2221
- var PolicyDocumentSchema = import_zod17.z.object({
2519
+ var PolicyDocumentSchema = import_zod18.z.object({
2222
2520
  ...BaseDocumentFields,
2223
- type: import_zod17.z.literal("policy"),
2224
- policyNumber: import_zod17.z.string(),
2225
- effectiveDate: import_zod17.z.string(),
2226
- expirationDate: import_zod17.z.string().optional(),
2521
+ type: import_zod18.z.literal("policy"),
2522
+ policyNumber: import_zod18.z.string(),
2523
+ effectiveDate: import_zod18.z.string(),
2524
+ expirationDate: import_zod18.z.string().optional(),
2227
2525
  policyTermType: PolicyTermTypeSchema.optional(),
2228
- nextReviewDate: import_zod17.z.string().optional(),
2229
- effectiveTime: import_zod17.z.string().optional()
2526
+ nextReviewDate: import_zod18.z.string().optional(),
2527
+ effectiveTime: import_zod18.z.string().optional()
2230
2528
  });
2231
- var QuoteDocumentSchema = import_zod17.z.object({
2529
+ var QuoteDocumentSchema = import_zod18.z.object({
2232
2530
  ...BaseDocumentFields,
2233
- type: import_zod17.z.literal("quote"),
2234
- quoteNumber: import_zod17.z.string(),
2235
- proposedEffectiveDate: import_zod17.z.string().optional(),
2236
- proposedExpirationDate: import_zod17.z.string().optional(),
2237
- quoteExpirationDate: import_zod17.z.string().optional(),
2238
- subjectivities: import_zod17.z.array(SubjectivitySchema).optional(),
2239
- underwritingConditions: import_zod17.z.array(UnderwritingConditionSchema).optional(),
2240
- premiumBreakdown: import_zod17.z.array(PremiumLineSchema).optional(),
2531
+ type: import_zod18.z.literal("quote"),
2532
+ quoteNumber: import_zod18.z.string(),
2533
+ proposedEffectiveDate: import_zod18.z.string().optional(),
2534
+ proposedExpirationDate: import_zod18.z.string().optional(),
2535
+ quoteExpirationDate: import_zod18.z.string().optional(),
2536
+ subjectivities: import_zod18.z.array(SubjectivitySchema).optional(),
2537
+ underwritingConditions: import_zod18.z.array(UnderwritingConditionSchema).optional(),
2241
2538
  // Enriched quote fields (v1.2+)
2242
- enrichedSubjectivities: import_zod17.z.array(EnrichedSubjectivitySchema).optional(),
2243
- enrichedUnderwritingConditions: import_zod17.z.array(EnrichedUnderwritingConditionSchema).optional(),
2244
- warrantyRequirements: import_zod17.z.array(import_zod17.z.string()).optional(),
2245
- lossControlRecommendations: import_zod17.z.array(import_zod17.z.string()).optional(),
2539
+ enrichedSubjectivities: import_zod18.z.array(EnrichedSubjectivitySchema).optional(),
2540
+ enrichedUnderwritingConditions: import_zod18.z.array(EnrichedUnderwritingConditionSchema).optional(),
2541
+ warrantyRequirements: import_zod18.z.array(import_zod18.z.string()).optional(),
2542
+ lossControlRecommendations: import_zod18.z.array(import_zod18.z.string()).optional(),
2246
2543
  bindingAuthority: BindingAuthoritySchema.optional()
2247
2544
  });
2248
- var InsuranceDocumentSchema = import_zod17.z.discriminatedUnion("type", [
2545
+ var InsuranceDocumentSchema = import_zod18.z.discriminatedUnion("type", [
2249
2546
  PolicyDocumentSchema,
2250
2547
  QuoteDocumentSchema
2251
2548
  ]);
2252
2549
 
2253
2550
  // src/schemas/platform.ts
2254
- var import_zod18 = require("zod");
2255
- var PlatformSchema = import_zod18.z.enum(["email", "chat", "sms", "slack", "discord"]);
2256
- var CommunicationIntentSchema = import_zod18.z.enum(["direct", "mediated", "observed"]);
2551
+ var import_zod19 = require("zod");
2552
+ var PlatformSchema = import_zod19.z.enum(["email", "chat", "sms", "slack", "discord"]);
2553
+ var CommunicationIntentSchema = import_zod19.z.enum(["direct", "mediated", "observed"]);
2257
2554
  var PLATFORM_CONFIGS = {
2258
2555
  email: {
2259
2556
  supportsMarkdown: false,
@@ -2286,65 +2583,65 @@ var PLATFORM_CONFIGS = {
2286
2583
  };
2287
2584
 
2288
2585
  // src/schemas/pce.ts
2289
- var import_zod20 = require("zod");
2586
+ var import_zod21 = require("zod");
2290
2587
 
2291
2588
  // src/case/index.ts
2292
- var import_zod19 = require("zod");
2293
- var CaseEvidenceSourceSchema = import_zod19.z.object({
2294
- id: import_zod19.z.string(),
2295
- label: import_zod19.z.string().optional(),
2296
- documentId: import_zod19.z.string().optional(),
2297
- page: import_zod19.z.number().optional(),
2298
- fieldPath: import_zod19.z.string().optional(),
2299
- text: import_zod19.z.string().describe("Source text available for span validation and citation"),
2300
- metadata: import_zod19.z.record(import_zod19.z.string(), import_zod19.z.string()).optional()
2301
- });
2302
- var CaseCitationSchema = import_zod19.z.object({
2303
- sourceId: import_zod19.z.string(),
2304
- quote: import_zod19.z.string(),
2305
- page: import_zod19.z.number().optional(),
2306
- fieldPath: import_zod19.z.string().optional()
2307
- });
2308
- var ValidationIssueSeveritySchema = import_zod19.z.enum(["info", "warning", "blocking"]);
2309
- var CaseValidationIssueSchema = import_zod19.z.object({
2310
- code: import_zod19.z.string(),
2589
+ var import_zod20 = require("zod");
2590
+ var CaseEvidenceSourceSchema = import_zod20.z.object({
2591
+ id: import_zod20.z.string(),
2592
+ label: import_zod20.z.string().optional(),
2593
+ documentId: import_zod20.z.string().optional(),
2594
+ page: import_zod20.z.number().optional(),
2595
+ fieldPath: import_zod20.z.string().optional(),
2596
+ text: import_zod20.z.string().describe("Source text available for span validation and citation"),
2597
+ metadata: import_zod20.z.record(import_zod20.z.string(), import_zod20.z.string()).optional()
2598
+ });
2599
+ var CaseCitationSchema = import_zod20.z.object({
2600
+ sourceId: import_zod20.z.string(),
2601
+ quote: import_zod20.z.string(),
2602
+ page: import_zod20.z.number().optional(),
2603
+ fieldPath: import_zod20.z.string().optional()
2604
+ });
2605
+ var ValidationIssueSeveritySchema = import_zod20.z.enum(["info", "warning", "blocking"]);
2606
+ var CaseValidationIssueSchema = import_zod20.z.object({
2607
+ code: import_zod20.z.string(),
2311
2608
  severity: ValidationIssueSeveritySchema,
2312
- message: import_zod19.z.string(),
2313
- itemId: import_zod19.z.string().optional(),
2314
- fieldPath: import_zod19.z.string().optional(),
2315
- sourceId: import_zod19.z.string().optional()
2316
- });
2317
- var MissingInfoQuestionSchema = import_zod19.z.object({
2318
- id: import_zod19.z.string(),
2319
- itemId: import_zod19.z.string().optional(),
2320
- fieldPath: import_zod19.z.string().optional(),
2321
- question: import_zod19.z.string(),
2322
- reason: import_zod19.z.string(),
2323
- answer: import_zod19.z.string().optional()
2324
- });
2325
- var CasePacketArtifactKindSchema = import_zod19.z.enum([
2609
+ message: import_zod20.z.string(),
2610
+ itemId: import_zod20.z.string().optional(),
2611
+ fieldPath: import_zod20.z.string().optional(),
2612
+ sourceId: import_zod20.z.string().optional()
2613
+ });
2614
+ var MissingInfoQuestionSchema = import_zod20.z.object({
2615
+ id: import_zod20.z.string(),
2616
+ itemId: import_zod20.z.string().optional(),
2617
+ fieldPath: import_zod20.z.string().optional(),
2618
+ question: import_zod20.z.string(),
2619
+ reason: import_zod20.z.string(),
2620
+ answer: import_zod20.z.string().optional()
2621
+ });
2622
+ var CasePacketArtifactKindSchema = import_zod20.z.enum([
2326
2623
  "underwriter_summary",
2327
2624
  "carrier_email",
2328
2625
  "missing_info_request",
2329
2626
  "json_packet",
2330
2627
  "validation_report"
2331
2628
  ]);
2332
- var CasePacketArtifactSchema = import_zod19.z.object({
2333
- id: import_zod19.z.string(),
2629
+ var CasePacketArtifactSchema = import_zod20.z.object({
2630
+ id: import_zod20.z.string(),
2334
2631
  kind: CasePacketArtifactKindSchema,
2335
- title: import_zod19.z.string(),
2336
- content: import_zod19.z.string(),
2337
- citations: import_zod19.z.array(CaseCitationSchema).default([])
2338
- });
2339
- var CaseSubmissionPacketSchema = import_zod19.z.object({
2340
- id: import_zod19.z.string(),
2341
- caseId: import_zod19.z.string(),
2342
- artifacts: import_zod19.z.array(CasePacketArtifactSchema),
2343
- validationIssues: import_zod19.z.array(CaseValidationIssueSchema),
2344
- missingInfoQuestions: import_zod19.z.array(MissingInfoQuestionSchema),
2345
- createdAt: import_zod19.z.number()
2346
- });
2347
- var CaseActionSchema = import_zod19.z.enum([
2632
+ title: import_zod20.z.string(),
2633
+ content: import_zod20.z.string(),
2634
+ citations: import_zod20.z.array(CaseCitationSchema).default([])
2635
+ });
2636
+ var CaseSubmissionPacketSchema = import_zod20.z.object({
2637
+ id: import_zod20.z.string(),
2638
+ caseId: import_zod20.z.string(),
2639
+ artifacts: import_zod20.z.array(CasePacketArtifactSchema),
2640
+ validationIssues: import_zod20.z.array(CaseValidationIssueSchema),
2641
+ missingInfoQuestions: import_zod20.z.array(MissingInfoQuestionSchema),
2642
+ createdAt: import_zod20.z.number()
2643
+ });
2644
+ var CaseActionSchema = import_zod20.z.enum([
2348
2645
  "inspect_attachments",
2349
2646
  "retrieve_policy_evidence",
2350
2647
  "retrieve_prior_applications",
@@ -2357,23 +2654,23 @@ var CaseActionSchema = import_zod19.z.enum([
2357
2654
  "generate_packet",
2358
2655
  "answer_field_or_case_question"
2359
2656
  ]);
2360
- var AgenticExecutionModeSchema = import_zod19.z.enum(["deterministic_tree", "market_eval", "hybrid"]);
2361
- var CaseProposalScoreSchema = import_zod19.z.object({
2362
- grounding: import_zod19.z.number().min(0).max(1),
2363
- completeness: import_zod19.z.number().min(0).max(1),
2364
- consistency: import_zod19.z.number().min(0).max(1),
2365
- determinism: import_zod19.z.number().min(0).max(1),
2366
- risk: import_zod19.z.number().min(0).max(1),
2367
- cost: import_zod19.z.number().min(0).max(1)
2368
- });
2369
- var CaseProposalSchema = import_zod19.z.object({
2370
- id: import_zod19.z.string(),
2371
- sourceSpanIds: import_zod19.z.array(import_zod19.z.string()).default([]),
2372
- confidence: import_zod19.z.number().min(0).max(1),
2373
- missingInfo: import_zod19.z.array(import_zod19.z.string()).default([]),
2374
- validationIssues: import_zod19.z.array(CaseValidationIssueSchema).default([]),
2375
- estimatedRisk: import_zod19.z.number().min(0).max(1).default(0.5),
2376
- estimatedCost: import_zod19.z.number().min(0).max(1).default(0.5),
2657
+ var AgenticExecutionModeSchema = import_zod20.z.enum(["deterministic_tree", "market_eval", "hybrid"]);
2658
+ var CaseProposalScoreSchema = import_zod20.z.object({
2659
+ grounding: import_zod20.z.number().min(0).max(1),
2660
+ completeness: import_zod20.z.number().min(0).max(1),
2661
+ consistency: import_zod20.z.number().min(0).max(1),
2662
+ determinism: import_zod20.z.number().min(0).max(1),
2663
+ risk: import_zod20.z.number().min(0).max(1),
2664
+ cost: import_zod20.z.number().min(0).max(1)
2665
+ });
2666
+ var CaseProposalSchema = import_zod20.z.object({
2667
+ id: import_zod20.z.string(),
2668
+ sourceSpanIds: import_zod20.z.array(import_zod20.z.string()).default([]),
2669
+ confidence: import_zod20.z.number().min(0).max(1),
2670
+ missingInfo: import_zod20.z.array(import_zod20.z.string()).default([]),
2671
+ validationIssues: import_zod20.z.array(CaseValidationIssueSchema).default([]),
2672
+ estimatedRisk: import_zod20.z.number().min(0).max(1).default(0.5),
2673
+ estimatedCost: import_zod20.z.number().min(0).max(1).default(0.5),
2377
2674
  score: CaseProposalScoreSchema.optional()
2378
2675
  });
2379
2676
  function stableCaseId(prefix, parts) {
@@ -2492,8 +2789,8 @@ function totalProposalScore(score) {
2492
2789
  }
2493
2790
 
2494
2791
  // src/schemas/pce.ts
2495
- var PolicyChangeActionSchema = import_zod20.z.enum(["add", "remove", "update", "replace", "clarify"]);
2496
- var PolicyChangeKindSchema = import_zod20.z.enum([
2792
+ var PolicyChangeActionSchema = import_zod21.z.enum(["add", "remove", "update", "replace", "clarify"]);
2793
+ var PolicyChangeKindSchema = import_zod21.z.enum([
2497
2794
  "named_insured_change",
2498
2795
  "additional_insured_change",
2499
2796
  "coverage_change",
@@ -2507,70 +2804,70 @@ var PolicyChangeKindSchema = import_zod20.z.enum([
2507
2804
  "renewal_submission_update",
2508
2805
  "general_endorsement"
2509
2806
  ]);
2510
- var PolicyChangeConfidenceSchema = import_zod20.z.enum(["high", "medium", "low"]);
2511
- var PolicyChangeStatusSchema = import_zod20.z.enum(["draft", "needs_info", "ready", "blocked"]);
2512
- var PolicyChangeItemSchema = import_zod20.z.object({
2513
- id: import_zod20.z.string(),
2807
+ var PolicyChangeConfidenceSchema = import_zod21.z.enum(["high", "medium", "low"]);
2808
+ var PolicyChangeStatusSchema = import_zod21.z.enum(["draft", "needs_info", "ready", "blocked"]);
2809
+ var PolicyChangeItemSchema = import_zod21.z.object({
2810
+ id: import_zod21.z.string(),
2514
2811
  kind: PolicyChangeKindSchema.default("general_endorsement"),
2515
2812
  action: PolicyChangeActionSchema,
2516
- affectedPolicyId: import_zod20.z.string().default("unknown"),
2517
- fieldPath: import_zod20.z.string().describe("Stable policy field path or business field name"),
2518
- label: import_zod20.z.string(),
2519
- beforeValue: import_zod20.z.string().optional().describe("Existing policy value, when cited from policy evidence"),
2520
- afterValue: import_zod20.z.string().optional().describe("Requested new value"),
2521
- requestedValue: import_zod20.z.string().optional().describe("Alias for afterValue used by policy-change workflows"),
2522
- effectiveDate: import_zod20.z.string().optional(),
2523
- reason: import_zod20.z.string().optional(),
2524
- sourceIds: import_zod20.z.array(import_zod20.z.string()).default([]),
2525
- sourceSpanIds: import_zod20.z.array(import_zod20.z.string()).default([]),
2526
- userSourceSpanIds: import_zod20.z.array(import_zod20.z.string()).optional(),
2527
- citations: import_zod20.z.array(CaseCitationSchema).default([]),
2813
+ affectedPolicyId: import_zod21.z.string().default("unknown"),
2814
+ fieldPath: import_zod21.z.string().describe("Stable policy field path or business field name"),
2815
+ label: import_zod21.z.string(),
2816
+ beforeValue: import_zod21.z.string().optional().describe("Existing policy value, when cited from policy evidence"),
2817
+ afterValue: import_zod21.z.string().optional().describe("Requested new value"),
2818
+ requestedValue: import_zod21.z.string().optional().describe("Alias for afterValue used by policy-change workflows"),
2819
+ effectiveDate: import_zod21.z.string().optional(),
2820
+ reason: import_zod21.z.string().optional(),
2821
+ sourceIds: import_zod21.z.array(import_zod21.z.string()).default([]),
2822
+ sourceSpanIds: import_zod21.z.array(import_zod21.z.string()).default([]),
2823
+ userSourceSpanIds: import_zod21.z.array(import_zod21.z.string()).optional(),
2824
+ citations: import_zod21.z.array(CaseCitationSchema).default([]),
2528
2825
  confidence: PolicyChangeConfidenceSchema.default("medium"),
2529
- confidenceScore: import_zod20.z.number().min(0).max(1).optional(),
2826
+ confidenceScore: import_zod21.z.number().min(0).max(1).optional(),
2530
2827
  status: PolicyChangeStatusSchema.default("ready")
2531
2828
  });
2532
- var PceNormalizationResultSchema = import_zod20.z.object({
2533
- summary: import_zod20.z.string(),
2534
- items: import_zod20.z.array(PolicyChangeItemSchema.omit({ id: true, status: true }).extend({
2535
- id: import_zod20.z.string().optional(),
2829
+ var PceNormalizationResultSchema = import_zod21.z.object({
2830
+ summary: import_zod21.z.string(),
2831
+ items: import_zod21.z.array(PolicyChangeItemSchema.omit({ id: true, status: true }).extend({
2832
+ id: import_zod21.z.string().optional(),
2536
2833
  status: PolicyChangeStatusSchema.optional()
2537
2834
  })),
2538
- missingInfoQuestions: import_zod20.z.array(MissingInfoQuestionSchema.omit({ id: true }).extend({
2539
- id: import_zod20.z.string().optional()
2835
+ missingInfoQuestions: import_zod21.z.array(MissingInfoQuestionSchema.omit({ id: true }).extend({
2836
+ id: import_zod21.z.string().optional()
2540
2837
  })).default([])
2541
2838
  });
2542
- var PolicyChangeImpactSchema = import_zod20.z.object({
2543
- itemId: import_zod20.z.string(),
2544
- beforeValue: import_zod20.z.string().optional(),
2545
- requestedValue: import_zod20.z.string().optional(),
2546
- likelyEndorsementRequired: import_zod20.z.boolean().default(true),
2547
- carrierApprovalLikelyRequired: import_zod20.z.boolean().default(true),
2548
- affectedCoverageForms: import_zod20.z.array(import_zod20.z.string()).default([]),
2549
- sourceSpanIds: import_zod20.z.array(import_zod20.z.string()).default([])
2550
- });
2551
- var PceCaseStateSchema = import_zod20.z.object({
2552
- id: import_zod20.z.string(),
2553
- requestText: import_zod20.z.string(),
2554
- summary: import_zod20.z.string(),
2839
+ var PolicyChangeImpactSchema = import_zod21.z.object({
2840
+ itemId: import_zod21.z.string(),
2841
+ beforeValue: import_zod21.z.string().optional(),
2842
+ requestedValue: import_zod21.z.string().optional(),
2843
+ likelyEndorsementRequired: import_zod21.z.boolean().default(true),
2844
+ carrierApprovalLikelyRequired: import_zod21.z.boolean().default(true),
2845
+ affectedCoverageForms: import_zod21.z.array(import_zod21.z.string()).default([]),
2846
+ sourceSpanIds: import_zod21.z.array(import_zod21.z.string()).default([])
2847
+ });
2848
+ var PceCaseStateSchema = import_zod21.z.object({
2849
+ id: import_zod21.z.string(),
2850
+ requestText: import_zod21.z.string(),
2851
+ summary: import_zod21.z.string(),
2555
2852
  executionMode: AgenticExecutionModeSchema.default("deterministic_tree"),
2556
- items: import_zod20.z.array(PolicyChangeItemSchema),
2557
- impacts: import_zod20.z.array(PolicyChangeImpactSchema),
2558
- evidenceSources: import_zod20.z.array(CaseEvidenceSourceSchema),
2559
- validationIssues: import_zod20.z.array(CaseValidationIssueSchema),
2560
- missingInfoQuestions: import_zod20.z.array(MissingInfoQuestionSchema),
2561
- createdAt: import_zod20.z.number(),
2562
- updatedAt: import_zod20.z.number()
2563
- });
2564
- var PolicyChangeRequestSchema = import_zod20.z.object({
2565
- id: import_zod20.z.string(),
2566
- text: import_zod20.z.string(),
2853
+ items: import_zod21.z.array(PolicyChangeItemSchema),
2854
+ impacts: import_zod21.z.array(PolicyChangeImpactSchema),
2855
+ evidenceSources: import_zod21.z.array(CaseEvidenceSourceSchema),
2856
+ validationIssues: import_zod21.z.array(CaseValidationIssueSchema),
2857
+ missingInfoQuestions: import_zod21.z.array(MissingInfoQuestionSchema),
2858
+ createdAt: import_zod21.z.number(),
2859
+ updatedAt: import_zod21.z.number()
2860
+ });
2861
+ var PolicyChangeRequestSchema = import_zod21.z.object({
2862
+ id: import_zod21.z.string(),
2863
+ text: import_zod21.z.string(),
2567
2864
  executionMode: AgenticExecutionModeSchema.optional(),
2568
- userSourceSpanIds: import_zod20.z.array(import_zod20.z.string()).optional(),
2569
- createdAt: import_zod20.z.number().optional()
2865
+ userSourceSpanIds: import_zod21.z.array(import_zod21.z.string()).optional(),
2866
+ createdAt: import_zod21.z.number().optional()
2570
2867
  });
2571
2868
  var PceSubmissionPacketSchema = CaseSubmissionPacketSchema.extend({
2572
2869
  pceCase: PceCaseStateSchema,
2573
- artifacts: import_zod20.z.array(CasePacketArtifactSchema)
2870
+ artifacts: import_zod21.z.array(CasePacketArtifactSchema)
2574
2871
  });
2575
2872
 
2576
2873
  // src/schemas/context-keys.ts
@@ -2625,254 +2922,6 @@ var CONTEXT_KEY_MAP = [
2625
2922
  { extractedField: "declarations.breed", category: "pet_info", contextKey: "pet_breed", description: "Pet breed" }
2626
2923
  ];
2627
2924
 
2628
- // src/source/schemas.ts
2629
- var import_zod21 = require("zod");
2630
- var SourceSpanKindSchema = import_zod21.z.enum([
2631
- "pdf_text",
2632
- "pdf_image",
2633
- "html",
2634
- "markdown",
2635
- "plain_text",
2636
- "structured_field"
2637
- ]);
2638
- var SourceSpanUnitSchema = import_zod21.z.enum([
2639
- "page",
2640
- "section",
2641
- "table",
2642
- "table_row",
2643
- "table_cell",
2644
- "key_value",
2645
- "text"
2646
- ]);
2647
- var SourceKindSchema = import_zod21.z.enum([
2648
- "policy_pdf",
2649
- "application_pdf",
2650
- "email",
2651
- "attachment",
2652
- "manual_note"
2653
- ]);
2654
- var SourceSpanBBoxSchema = import_zod21.z.object({
2655
- page: import_zod21.z.number().int().positive(),
2656
- x: import_zod21.z.number(),
2657
- y: import_zod21.z.number(),
2658
- width: import_zod21.z.number(),
2659
- height: import_zod21.z.number()
2660
- });
2661
- var SourceSpanLocationSchema = import_zod21.z.object({
2662
- page: import_zod21.z.number().int().positive().optional(),
2663
- startPage: import_zod21.z.number().int().positive().optional(),
2664
- endPage: import_zod21.z.number().int().positive().optional(),
2665
- charStart: import_zod21.z.number().int().nonnegative().optional(),
2666
- charEnd: import_zod21.z.number().int().nonnegative().optional(),
2667
- lineStart: import_zod21.z.number().int().positive().optional(),
2668
- lineEnd: import_zod21.z.number().int().positive().optional(),
2669
- fieldPath: import_zod21.z.string().optional()
2670
- });
2671
- var SourceSpanTableLocationSchema = import_zod21.z.object({
2672
- tableId: import_zod21.z.string().optional(),
2673
- rowIndex: import_zod21.z.number().int().nonnegative().optional(),
2674
- columnIndex: import_zod21.z.number().int().nonnegative().optional(),
2675
- columnName: import_zod21.z.string().optional(),
2676
- rowSpanId: import_zod21.z.string().optional(),
2677
- tableSpanId: import_zod21.z.string().optional(),
2678
- isHeader: import_zod21.z.boolean().optional()
2679
- });
2680
- var SourceSpanSchema = import_zod21.z.object({
2681
- id: import_zod21.z.string().min(1),
2682
- documentId: import_zod21.z.string().min(1),
2683
- sourceKind: SourceKindSchema.optional(),
2684
- chunkId: import_zod21.z.string().optional(),
2685
- kind: SourceSpanKindSchema,
2686
- text: import_zod21.z.string(),
2687
- hash: import_zod21.z.string().min(1),
2688
- textHash: import_zod21.z.string().optional(),
2689
- pageStart: import_zod21.z.number().int().positive().optional(),
2690
- pageEnd: import_zod21.z.number().int().positive().optional(),
2691
- sectionId: import_zod21.z.string().optional(),
2692
- formNumber: import_zod21.z.string().optional(),
2693
- sourceUnit: SourceSpanUnitSchema.optional(),
2694
- parentSpanId: import_zod21.z.string().optional(),
2695
- table: SourceSpanTableLocationSchema.optional(),
2696
- bbox: import_zod21.z.array(SourceSpanBBoxSchema).optional(),
2697
- location: SourceSpanLocationSchema.optional(),
2698
- metadata: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.string()).optional()
2699
- });
2700
- var SourceSpanRefSchema = import_zod21.z.object({
2701
- sourceSpanId: import_zod21.z.string().min(1),
2702
- documentId: import_zod21.z.string().min(1).optional(),
2703
- chunkId: import_zod21.z.string().optional(),
2704
- quote: import_zod21.z.string().optional(),
2705
- hash: import_zod21.z.string().optional(),
2706
- location: SourceSpanLocationSchema.optional()
2707
- });
2708
- var SourceChunkSchema = import_zod21.z.object({
2709
- id: import_zod21.z.string().min(1),
2710
- documentId: import_zod21.z.string().min(1),
2711
- sourceSpanIds: import_zod21.z.array(import_zod21.z.string().min(1)),
2712
- text: import_zod21.z.string(),
2713
- textHash: import_zod21.z.string().min(1),
2714
- pageStart: import_zod21.z.number().int().positive().optional(),
2715
- pageEnd: import_zod21.z.number().int().positive().optional(),
2716
- metadata: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.string()).default({})
2717
- });
2718
- var DocumentSourceNodeKindSchema = import_zod21.z.enum([
2719
- "document",
2720
- "page_group",
2721
- "page",
2722
- "form",
2723
- "endorsement",
2724
- "section",
2725
- "schedule",
2726
- "clause",
2727
- "table",
2728
- "table_row",
2729
- "table_cell",
2730
- "text"
2731
- ]);
2732
- var DocumentSourceNodeSchema = import_zod21.z.object({
2733
- id: import_zod21.z.string().min(1),
2734
- documentId: import_zod21.z.string().min(1),
2735
- parentId: import_zod21.z.string().optional(),
2736
- kind: DocumentSourceNodeKindSchema,
2737
- title: import_zod21.z.string(),
2738
- description: import_zod21.z.string(),
2739
- textExcerpt: import_zod21.z.string().optional(),
2740
- sourceSpanIds: import_zod21.z.array(import_zod21.z.string().min(1)),
2741
- pageStart: import_zod21.z.number().int().positive().optional(),
2742
- pageEnd: import_zod21.z.number().int().positive().optional(),
2743
- bbox: import_zod21.z.array(SourceSpanBBoxSchema).optional(),
2744
- order: import_zod21.z.number().int().nonnegative(),
2745
- path: import_zod21.z.string(),
2746
- metadata: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.unknown()).optional()
2747
- });
2748
- var SourceBackedValueSchema = import_zod21.z.object({
2749
- value: import_zod21.z.string(),
2750
- normalizedValue: import_zod21.z.string().optional(),
2751
- confidence: import_zod21.z.enum(["low", "medium", "high"]).default("medium"),
2752
- sourceNodeIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([]),
2753
- sourceSpanIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([])
2754
- });
2755
- var OperationalAddressSchema = import_zod21.z.object({
2756
- street1: import_zod21.z.string().optional(),
2757
- street2: import_zod21.z.string().optional(),
2758
- city: import_zod21.z.string().optional(),
2759
- state: import_zod21.z.string().optional(),
2760
- zip: import_zod21.z.string().optional(),
2761
- country: import_zod21.z.string().optional(),
2762
- formatted: import_zod21.z.string().optional()
2763
- });
2764
- var OperationalDeclarationFactSchema = import_zod21.z.object({
2765
- field: import_zod21.z.enum([
2766
- "namedInsured",
2767
- "mailingAddress",
2768
- "dba",
2769
- "entityType",
2770
- "taxId",
2771
- "additionalNamedInsured",
2772
- "policyNumber",
2773
- "insurer",
2774
- "broker",
2775
- "effectiveDate",
2776
- "expirationDate",
2777
- "premium",
2778
- "other"
2779
- ]),
2780
- label: import_zod21.z.string().optional(),
2781
- value: import_zod21.z.string(),
2782
- normalizedValue: import_zod21.z.string().optional(),
2783
- valueKind: import_zod21.z.enum(["string", "number", "date", "money", "address", "list", "unknown"]).default("string"),
2784
- address: OperationalAddressSchema.optional(),
2785
- confidence: import_zod21.z.enum(["low", "medium", "high"]).default("medium"),
2786
- sourceNodeIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([]),
2787
- sourceSpanIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([])
2788
- });
2789
- var OperationalCoverageTermSchema = import_zod21.z.object({
2790
- kind: import_zod21.z.enum([
2791
- "each_claim_limit",
2792
- "each_occurrence_limit",
2793
- "each_loss_limit",
2794
- "aggregate_limit",
2795
- "sublimit",
2796
- "retention",
2797
- "deductible",
2798
- "retroactive_date",
2799
- "premium",
2800
- "other"
2801
- ]).default("other"),
2802
- label: import_zod21.z.string(),
2803
- value: import_zod21.z.string(),
2804
- amount: import_zod21.z.number().optional(),
2805
- appliesTo: import_zod21.z.string().optional(),
2806
- sourceNodeIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([]),
2807
- sourceSpanIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([])
2808
- });
2809
- var OperationalCoverageLineSchema = import_zod21.z.object({
2810
- name: import_zod21.z.string(),
2811
- lineOfBusiness: AcordLobCodeSchema.optional(),
2812
- coverageCode: import_zod21.z.string().optional(),
2813
- limit: import_zod21.z.string().optional(),
2814
- deductible: import_zod21.z.string().optional(),
2815
- premium: import_zod21.z.string().optional(),
2816
- retroactiveDate: import_zod21.z.string().optional(),
2817
- formNumber: import_zod21.z.string().optional(),
2818
- sectionRef: import_zod21.z.string().optional(),
2819
- endorsementNumber: import_zod21.z.string().optional(),
2820
- limits: import_zod21.z.array(OperationalCoverageTermSchema).default([]),
2821
- sourceNodeIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([]),
2822
- sourceSpanIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([])
2823
- });
2824
- var OperationalPartySchema = import_zod21.z.object({
2825
- role: import_zod21.z.string(),
2826
- name: import_zod21.z.string(),
2827
- address: OperationalAddressSchema.optional(),
2828
- sourceNodeIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([]),
2829
- sourceSpanIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([])
2830
- });
2831
- var OperationalEndorsementSupportSchema = import_zod21.z.object({
2832
- kind: import_zod21.z.string(),
2833
- status: import_zod21.z.enum(["supported", "excluded", "requires_review"]),
2834
- summary: import_zod21.z.string(),
2835
- sourceNodeIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([]),
2836
- sourceSpanIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([])
2837
- });
2838
- function legacyOperationalProfileInput(value) {
2839
- if (!value || typeof value !== "object" || Array.isArray(value)) return value;
2840
- const record = value;
2841
- if ("linesOfBusiness" in record) return value;
2842
- if (!("policyTypes" in record)) return value;
2843
- return {
2844
- ...record,
2845
- linesOfBusiness: record.policyTypes
2846
- };
2847
- }
2848
- var OperationalLinesOfBusinessSchema = import_zod21.z.preprocess(
2849
- (value) => Array.isArray(value) ? toLobCodes(value.filter((item) => typeof item === "string")) : void 0,
2850
- import_zod21.z.array(AcordLobCodeSchema).default(["UN"])
2851
- );
2852
- var PolicyOperationalProfileSchema = import_zod21.z.preprocess(
2853
- legacyOperationalProfileInput,
2854
- import_zod21.z.object({
2855
- documentType: import_zod21.z.enum(["policy", "quote"]).default("policy"),
2856
- linesOfBusiness: OperationalLinesOfBusinessSchema,
2857
- policyNumber: SourceBackedValueSchema.optional(),
2858
- namedInsured: SourceBackedValueSchema.optional(),
2859
- insurer: SourceBackedValueSchema.optional(),
2860
- broker: SourceBackedValueSchema.optional(),
2861
- effectiveDate: SourceBackedValueSchema.optional(),
2862
- expirationDate: SourceBackedValueSchema.optional(),
2863
- retroactiveDate: SourceBackedValueSchema.optional(),
2864
- premium: SourceBackedValueSchema.optional(),
2865
- operationsDescription: SourceBackedValueSchema.optional(),
2866
- declarationFacts: import_zod21.z.array(OperationalDeclarationFactSchema).default([]),
2867
- coverages: import_zod21.z.array(OperationalCoverageLineSchema).default([]),
2868
- parties: import_zod21.z.array(OperationalPartySchema).default([]),
2869
- endorsementSupport: import_zod21.z.array(OperationalEndorsementSupportSchema).default([]),
2870
- sourceNodeIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([]),
2871
- sourceSpanIds: import_zod21.z.array(import_zod21.z.string().min(1)).default([]),
2872
- warnings: import_zod21.z.array(import_zod21.z.string()).default([])
2873
- })
2874
- );
2875
-
2876
2925
  // src/source/policy-types.ts
2877
2926
  var LOB_TEXT_PATTERNS = [
2878
2927
  { codes: ["CGL"], pattern: /\b(?:commercial\s+)?general\s+liability\b|\bcgl\b/i },
@@ -4223,7 +4272,7 @@ function shouldFailQualityGate(mode, status) {
4223
4272
  }
4224
4273
 
4225
4274
  // src/extraction/source-tree-extractor.ts
4226
- var import_zod23 = require("zod");
4275
+ var import_zod24 = require("zod");
4227
4276
 
4228
4277
  // src/source/operational-profile.ts
4229
4278
  function normalizeWhitespace4(value) {
@@ -4966,116 +5015,831 @@ function applyCoverageCleanupDecision(coverage, decision, validNodeIds, validSpa
4966
5015
  const value = cleanProfileValue(decision.retroactiveDate);
4967
5016
  if (value) next.retroactiveDate = value;
4968
5017
  }
4969
- const termDecisions = (decision.termDecisions ?? []).filter((termDecision) => termDecision.termIndex < coverage.limits.length);
4970
- const termDecisionByIndex = new Map(termDecisions.map((termDecision) => [termDecision.termIndex, termDecision]));
4971
- next.limits = coverage.limits.map((term, index) => applyTermCleanupDecision(term, termDecisionByIndex.get(index), validNodeIds, validSpanIds)).filter((term) => Boolean(term));
4972
- if (termDecisions.length > 0) {
4973
- if (decision.limit == null && termDecisionsTouch(coverage, termDecisions, isLimitTerm)) {
4974
- const value = primaryLimitFromTerms(next.limits);
4975
- if (value) next.limit = value;
4976
- else delete next.limit;
5018
+ const termDecisions = (decision.termDecisions ?? []).filter((termDecision) => termDecision.termIndex < coverage.limits.length);
5019
+ const termDecisionByIndex = new Map(termDecisions.map((termDecision) => [termDecision.termIndex, termDecision]));
5020
+ next.limits = coverage.limits.map((term, index) => applyTermCleanupDecision(term, termDecisionByIndex.get(index), validNodeIds, validSpanIds)).filter((term) => Boolean(term));
5021
+ if (termDecisions.length > 0) {
5022
+ if (decision.limit == null && termDecisionsTouch(coverage, termDecisions, isLimitTerm)) {
5023
+ const value = primaryLimitFromTerms(next.limits);
5024
+ if (value) next.limit = value;
5025
+ else delete next.limit;
5026
+ }
5027
+ if (decision.deductible == null && termDecisionsTouch(coverage, termDecisions, isDeductibleTerm)) {
5028
+ const value = deductibleFromTerms(next.limits);
5029
+ if (value) next.deductible = value;
5030
+ else delete next.deductible;
5031
+ }
5032
+ if (decision.premium == null && termDecisionsTouch(coverage, termDecisions, isPremiumTerm)) {
5033
+ const value = premiumFromTerms(next.limits);
5034
+ if (value) next.premium = value;
5035
+ else delete next.premium;
5036
+ }
5037
+ if (decision.retroactiveDate == null && termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm)) {
5038
+ const value = retroactiveDateFromTerms(next.limits);
5039
+ if (value) next.retroactiveDate = value;
5040
+ else delete next.retroactiveDate;
5041
+ }
5042
+ }
5043
+ const termLimit = primaryLimitFromTerms(next.limits);
5044
+ if (termLimit && shouldUseTermLimitDisplay(next.limit, termLimit)) {
5045
+ next.limit = termLimit;
5046
+ }
5047
+ next.sourceNodeIds = uniqueStrings([
5048
+ ...next.sourceNodeIds,
5049
+ ...next.limits.flatMap((term) => term.sourceNodeIds)
5050
+ ]);
5051
+ next.sourceSpanIds = uniqueStrings([
5052
+ ...next.sourceSpanIds,
5053
+ ...next.limits.flatMap((term) => term.sourceSpanIds)
5054
+ ]);
5055
+ return next.name ? next : coverage;
5056
+ }
5057
+ function sourceIdsFromOperationalProfile(profile) {
5058
+ const backedValues = [
5059
+ profile.policyNumber,
5060
+ profile.namedInsured,
5061
+ profile.insurer,
5062
+ profile.broker,
5063
+ profile.effectiveDate,
5064
+ profile.expirationDate,
5065
+ profile.retroactiveDate,
5066
+ profile.premium,
5067
+ profile.totalCost,
5068
+ profile.operationsDescription
5069
+ ].filter(Boolean);
5070
+ return {
5071
+ sourceNodeIds: uniqueStrings([
5072
+ ...backedValues.flatMap((value) => value?.sourceNodeIds ?? []),
5073
+ ...profile.coverages.flatMap((coverage) => coverage.sourceNodeIds),
5074
+ ...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceNodeIds)),
5075
+ ...(profile.premiumBreakdown ?? []).flatMap((row) => row.sourceNodeIds),
5076
+ ...(profile.taxesAndFees ?? []).flatMap((row) => row.sourceNodeIds),
5077
+ ...profile.parties.flatMap((party) => party.sourceNodeIds),
5078
+ ...profile.endorsementSupport.flatMap((support) => support.sourceNodeIds)
5079
+ ]),
5080
+ sourceSpanIds: uniqueStrings([
5081
+ ...backedValues.flatMap((value) => value?.sourceSpanIds ?? []),
5082
+ ...profile.coverages.flatMap((coverage) => coverage.sourceSpanIds),
5083
+ ...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceSpanIds)),
5084
+ ...(profile.coverageSchedules ?? []).flatMap((schedule) => [
5085
+ ...schedule.sourceSpanIds,
5086
+ ...schedule.items.flatMap((item) => item.sourceSpanIds)
5087
+ ]),
5088
+ ...(profile.premiumBreakdown ?? []).flatMap((row) => row.sourceSpanIds),
5089
+ ...(profile.taxesAndFees ?? []).flatMap((row) => row.sourceSpanIds),
5090
+ ...profile.parties.flatMap((party) => party.sourceSpanIds),
5091
+ ...profile.endorsementSupport.flatMap((support) => support.sourceSpanIds)
5092
+ ])
5093
+ };
5094
+ }
5095
+ function applyOperationalProfileCleanup(profile, cleanup, validNodeIds, validSpanIds) {
5096
+ const coverageDecisionByIndex = /* @__PURE__ */ new Map();
5097
+ for (const decision of cleanup.coverageDecisions) {
5098
+ if (decision.coverageIndex < profile.coverages.length) coverageDecisionByIndex.set(decision.coverageIndex, decision);
5099
+ }
5100
+ const coverages = profile.coverages.map(
5101
+ (coverage, index) => applyCoverageCleanupDecision(coverage, coverageDecisionByIndex.get(index), validNodeIds, validSpanIds)
5102
+ ).filter((coverage) => Boolean(coverage));
5103
+ const cleanupWarnings = cleanup.warnings.map((warning) => cleanProfileValue(warning)).filter((warning) => Boolean(warning));
5104
+ const nextProfile = {
5105
+ ...profile,
5106
+ coverages,
5107
+ warnings: uniqueStrings([
5108
+ ...profile.warnings,
5109
+ ...cleanupWarnings.map((warning) => `Operational profile cleanup warning: ${warning}`)
5110
+ ])
5111
+ };
5112
+ return PolicyOperationalProfileSchema.parse({
5113
+ ...nextProfile,
5114
+ ...sourceIdsFromOperationalProfile(nextProfile)
5115
+ });
5116
+ }
5117
+
5118
+ // src/extraction/coverage-recovery.ts
5119
+ var import_zod23 = require("zod");
5120
+ var COVERAGE_RECOVERY_VERSION = "coverage-recovery-v2";
5121
+ var DISCOVERY_PAGE_BATCH_SIZE = 32;
5122
+ var REGION_PAGE_BATCH_SIZE = 4;
5123
+ var RECOVERY_EVIDENCE_CHAR_LIMIT = 42e3;
5124
+ var RecoveryRegionSchema = import_zod23.z.object({
5125
+ pageStart: import_zod23.z.number().int().positive(),
5126
+ pageEnd: import_zod23.z.number().int().positive(),
5127
+ reason: import_zod23.z.string(),
5128
+ priorContext: import_zod23.z.string().optional(),
5129
+ sourceNodeIds: import_zod23.z.array(import_zod23.z.string()).default([]),
5130
+ sourceSpanIds: import_zod23.z.array(import_zod23.z.string()).default([])
5131
+ });
5132
+ var RecoveryRegionDiscoverySchema = import_zod23.z.object({
5133
+ regions: import_zod23.z.array(RecoveryRegionSchema).default([]),
5134
+ warnings: import_zod23.z.array(import_zod23.z.string()).default([])
5135
+ });
5136
+ var CoverageRecoveryCandidateSchema = import_zod23.z.object({
5137
+ coverages: import_zod23.z.array(OperationalCoverageLineSchema).default([]),
5138
+ coverageSchedules: import_zod23.z.array(OperationalCoverageScheduleSchema).default([]),
5139
+ premiumBreakdown: import_zod23.z.array(OperationalPremiumLineSchema).default([]),
5140
+ taxesAndFees: import_zod23.z.array(OperationalTaxFeeItemSchema).default([]),
5141
+ totalCost: SourceBackedValueSchema.optional(),
5142
+ warnings: import_zod23.z.array(import_zod23.z.string()).default([])
5143
+ });
5144
+ function cleanText(value) {
5145
+ if (typeof value !== "string") return void 0;
5146
+ const text = value.replace(/\s+/g, " ").trim();
5147
+ return text || void 0;
5148
+ }
5149
+ function uniqueStrings2(values) {
5150
+ return [...new Set(values.filter((value) => Boolean(value)))];
5151
+ }
5152
+ function spanPageStart(span) {
5153
+ return span.pageStart ?? span.location?.startPage ?? span.location?.page;
5154
+ }
5155
+ function spanPageEnd(span) {
5156
+ return span.pageEnd ?? span.location?.endPage ?? span.location?.page ?? spanPageStart(span);
5157
+ }
5158
+ function spanSourceUnit(span) {
5159
+ return span.sourceUnit ?? span.metadata?.sourceUnit;
5160
+ }
5161
+ function overlapsPageRange(value, pageStart2, pageEnd2) {
5162
+ const start = value.pageStart ?? value.pageEnd;
5163
+ const end = value.pageEnd ?? value.pageStart;
5164
+ return typeof start === "number" && typeof end === "number" && start <= pageEnd2 && end >= pageStart2;
5165
+ }
5166
+ function chunkValues(values, size) {
5167
+ const chunks = [];
5168
+ for (let index = 0; index < values.length; index += size) {
5169
+ chunks.push(values.slice(index, index + size));
5170
+ }
5171
+ return chunks;
5172
+ }
5173
+ function evenlySample(values, limit) {
5174
+ if (values.length <= limit) return values;
5175
+ if (limit <= 1) return [values[0]];
5176
+ return Array.from(
5177
+ { length: limit },
5178
+ (_, index) => values[Math.round(index * (values.length - 1) / (limit - 1))]
5179
+ );
5180
+ }
5181
+ function sourceNodeIdsBySpanId(sourceTree) {
5182
+ const result = /* @__PURE__ */ new Map();
5183
+ for (const node of sourceTree) {
5184
+ for (const sourceSpanId of node.sourceSpanIds) {
5185
+ const ids = result.get(sourceSpanId) ?? [];
5186
+ ids.push(node.id);
5187
+ result.set(sourceSpanId, ids);
5188
+ }
5189
+ }
5190
+ return result;
5191
+ }
5192
+ function documentPages(sourceTree, sourceSpans) {
5193
+ const pages = /* @__PURE__ */ new Set();
5194
+ for (const span of sourceSpans) {
5195
+ const start = spanPageStart(span);
5196
+ const end = spanPageEnd(span) ?? start;
5197
+ if (!start || !end) continue;
5198
+ for (let page = start; page <= end; page += 1) pages.add(page);
5199
+ }
5200
+ for (const node of sourceTree) {
5201
+ if (node.pageStart) pages.add(node.pageStart);
5202
+ if (node.pageEnd) pages.add(node.pageEnd);
5203
+ }
5204
+ return [...pages].sort((left, right) => left - right);
5205
+ }
5206
+ function pageSketch(page, sourceTree, sourceSpans) {
5207
+ const pageNodes = sourceTree.filter((node) => node.kind !== "document" && overlapsPageRange(node, page, page)).sort((left, right) => left.order - right.order || left.id.localeCompare(right.id));
5208
+ const pageSpans = sourceSpans.filter((span) => overlapsPageRange({ pageStart: spanPageStart(span), pageEnd: spanPageEnd(span) }, page, page)).sort(
5209
+ (left, right) => (left.location?.charStart ?? Number.MAX_SAFE_INTEGER) - (right.location?.charStart ?? Number.MAX_SAFE_INTEGER) || left.id.localeCompare(right.id)
5210
+ );
5211
+ const tableIds = uniqueStrings2(pageSpans.map((span) => span.table?.tableId ?? span.metadata?.tableId));
5212
+ const units = pageSpans.reduce((counts, span) => {
5213
+ const unit = spanSourceUnit(span) ?? "unknown";
5214
+ counts[unit] = (counts[unit] ?? 0) + 1;
5215
+ return counts;
5216
+ }, {});
5217
+ const textSamples = evenlySample(
5218
+ pageSpans.filter((span) => cleanText(span.text)).map((span) => ({
5219
+ sourceSpanId: span.id,
5220
+ sourceUnit: spanSourceUnit(span),
5221
+ tableId: span.table?.tableId ?? span.metadata?.tableId,
5222
+ rowIndex: span.table?.rowIndex,
5223
+ columnIndex: span.table?.columnIndex,
5224
+ columnName: span.table?.columnName,
5225
+ bbox: span.bbox?.[0],
5226
+ text: cleanText(span.text)?.slice(0, 280)
5227
+ })),
5228
+ 18
5229
+ );
5230
+ return {
5231
+ page,
5232
+ forms: uniqueStrings2(pageSpans.map((span) => span.formNumber)),
5233
+ structure: evenlySample(pageNodes.map((node) => ({
5234
+ id: node.id,
5235
+ kind: node.kind,
5236
+ title: node.title,
5237
+ path: node.path,
5238
+ sourceSpanIds: node.sourceSpanIds.slice(0, 6)
5239
+ })), 20),
5240
+ layout: {
5241
+ units,
5242
+ tableCount: tableIds.length,
5243
+ rowCount: pageSpans.filter((span) => spanSourceUnit(span) === "table_row").length,
5244
+ cellCount: pageSpans.filter((span) => spanSourceUnit(span) === "table_cell").length
5245
+ },
5246
+ textSamples
5247
+ };
5248
+ }
5249
+ function discoveryPrompt(sketches) {
5250
+ return `Discover every document region that may contain policy-specific coverage facts, asset schedules, or financial facts.
5251
+
5252
+ This is semantic region discovery, not keyword or heading matching. Inspect the layout and source-tree sketch for every supplied page, including unusual terminology and late-document schedules.
5253
+
5254
+ Select regions containing or continuing any of:
5255
+ - coverage, benefit, insuring-agreement, limit, sublimit, deductible, retention, or per-asset terms
5256
+ - covered-auto, vehicle, property, location, building, equipment, or similar asset schedules
5257
+ - premium breakdowns, taxes, fees, surcharges, assessments, or total payable
5258
+ - declarations, forms, endorsements, options, exclusions, or cross-references that establish the status or scope of those facts
5259
+
5260
+ Continuation rules:
5261
+ - A repeated heading is not required. Carry prior section and table-header context onto continuation pages.
5262
+ - Continue through compatible row numbering, column geometry, form identity, and table shape.
5263
+ - Stop at a new form, incompatible table structure, terminal language, or unrelated section.
5264
+ - Include declined, excluded, and unselected-option regions so the extraction pass can keep them out of active coverage rows.
5265
+
5266
+ Use only page numbers and source IDs from the sketches. Return no region for pages that contain no relevant policy-specific evidence.
5267
+
5268
+ Page sketches:
5269
+ ${JSON.stringify(sketches, null, 2)}`;
5270
+ }
5271
+ function normalizeRegions(regions, pages) {
5272
+ if (pages.length === 0) return [];
5273
+ const minPage = pages[0];
5274
+ const maxPage = pages[pages.length - 1];
5275
+ const normalized = regions.flatMap((region) => {
5276
+ const start = Math.max(minPage, Math.min(maxPage, region.pageStart));
5277
+ const end = Math.max(start, Math.min(maxPage, region.pageEnd));
5278
+ if (!pages.some((page) => page >= start && page <= end)) return [];
5279
+ return [{ ...region, pageStart: start, pageEnd: end }];
5280
+ });
5281
+ normalized.sort((left, right) => left.pageStart - right.pageStart || left.pageEnd - right.pageEnd);
5282
+ return normalized.reduce((rows, region) => {
5283
+ const previous = rows[rows.length - 1];
5284
+ if (!previous || region.pageStart > previous.pageEnd + 1) {
5285
+ rows.push(region);
5286
+ return rows;
5287
+ }
5288
+ previous.pageEnd = Math.max(previous.pageEnd, region.pageEnd);
5289
+ previous.reason = uniqueStrings2([previous.reason, region.reason]).join("; ");
5290
+ previous.priorContext = uniqueStrings2([previous.priorContext, region.priorContext]).join("; ") || void 0;
5291
+ previous.sourceNodeIds = uniqueStrings2([...previous.sourceNodeIds, ...region.sourceNodeIds]);
5292
+ previous.sourceSpanIds = uniqueStrings2([...previous.sourceSpanIds, ...region.sourceSpanIds]);
5293
+ return rows;
5294
+ }, []);
5295
+ }
5296
+ function splitRegions(regions) {
5297
+ return regions.flatMap((region) => {
5298
+ const result = [];
5299
+ for (let page = region.pageStart; page <= region.pageEnd; page += REGION_PAGE_BATCH_SIZE) {
5300
+ result.push({
5301
+ ...region,
5302
+ pageStart: page,
5303
+ pageEnd: Math.min(region.pageEnd, page + REGION_PAGE_BATCH_SIZE - 1)
5304
+ });
5305
+ }
5306
+ return result;
5307
+ });
5308
+ }
5309
+ function priorStructuralContext(region, sourceTree, sourceSpans) {
5310
+ const precedingNodes = sourceTree.filter((node) => node.kind !== "document" && (node.pageStart ?? 0) <= region.pageStart).filter((node) => ["page_group", "form", "endorsement", "section", "schedule", "table"].includes(node.kind)).sort(
5311
+ (left, right) => (right.pageStart ?? 0) - (left.pageStart ?? 0) || right.order - left.order
5312
+ ).slice(0, 12).map((node) => ({
5313
+ id: node.id,
5314
+ kind: node.kind,
5315
+ title: node.title,
5316
+ path: node.path,
5317
+ pageStart: node.pageStart,
5318
+ pageEnd: node.pageEnd,
5319
+ sourceSpanIds: node.sourceSpanIds.slice(0, 8)
5320
+ }));
5321
+ const headerSpans = sourceSpans.filter((span) => {
5322
+ const page = spanPageStart(span);
5323
+ return typeof page === "number" && page >= Math.max(1, region.pageStart - 2) && page <= region.pageStart && (span.table?.isHeader || span.table?.columnName || span.metadata?.isHeader === "true");
5324
+ }).map((span) => ({
5325
+ sourceSpanId: span.id,
5326
+ pageStart: spanPageStart(span),
5327
+ table: span.table,
5328
+ text: cleanText(span.text)?.slice(0, 600)
5329
+ }));
5330
+ return { priorContext: region.priorContext, precedingNodes, tableHeaders: headerSpans };
5331
+ }
5332
+ function regionEvidence(region, sourceTree, sourceSpans) {
5333
+ const nodeIdsBySpanId = sourceNodeIdsBySpanId(sourceTree);
5334
+ const spans = sourceSpans.filter((span) => overlapsPageRange(
5335
+ { pageStart: spanPageStart(span), pageEnd: spanPageEnd(span) },
5336
+ region.pageStart,
5337
+ region.pageEnd
5338
+ )).sort(
5339
+ (left, right) => (spanPageStart(left) ?? Number.MAX_SAFE_INTEGER) - (spanPageStart(right) ?? Number.MAX_SAFE_INTEGER) || (left.location?.charStart ?? Number.MAX_SAFE_INTEGER) - (right.location?.charStart ?? Number.MAX_SAFE_INTEGER) || left.id.localeCompare(right.id)
5340
+ );
5341
+ return spans.flatMap((span) => {
5342
+ const text = cleanText(span.text);
5343
+ if (!text) return [];
5344
+ const parts = text.match(/[\s\S]{1,1400}/g) ?? [text];
5345
+ return parts.map((part) => ({
5346
+ sourceSpanId: span.id,
5347
+ sourceNodeIds: (nodeIdsBySpanId.get(span.id) ?? []).slice(0, 6),
5348
+ pageStart: spanPageStart(span),
5349
+ pageEnd: spanPageEnd(span),
5350
+ sourceUnit: spanSourceUnit(span),
5351
+ formNumber: span.formNumber,
5352
+ table: span.table,
5353
+ text: part
5354
+ }));
5355
+ });
5356
+ }
5357
+ function evidenceBatches(entries) {
5358
+ const batches = [];
5359
+ let current = [];
5360
+ let chars = 0;
5361
+ for (const entry of entries) {
5362
+ const size = entry.text.length + 260;
5363
+ if (current.length > 0 && chars + size > RECOVERY_EVIDENCE_CHAR_LIMIT) {
5364
+ batches.push(current);
5365
+ current = [];
5366
+ chars = 0;
5367
+ }
5368
+ current.push(entry);
5369
+ chars += size;
5370
+ }
5371
+ if (current.length > 0) batches.push(current);
5372
+ return batches;
5373
+ }
5374
+ function recoveryPrompt(params) {
5375
+ return `Recover missing source-backed policy coverage, schedule, and financial facts from one semantically selected document region.
5376
+
5377
+ Region: pages ${params.region.pageStart}-${params.region.pageEnd}
5378
+ Reason: ${params.region.reason}
5379
+ Evidence batch: ${params.batchIndex}/${params.batchCount}
5380
+
5381
+ Rules:
5382
+ - Preserve the source's coverage terminology as coverages[].name. ACORD lineOfBusiness and coverageCode may supplement it but may not replace it with unsupported wording.
5383
+ - A repeated heading is not required. Use the prior section and table-header context to interpret compatible continuation rows.
5384
+ - Keep declaration/core-form and endorsement facts separate when their source scopes differ, even if names match.
5385
+ - Put per occurrence, per claim, aggregate, per vehicle, per location, retention, deductible, sublimit, and similar values in coverages[].limits with the source label preserved.
5386
+ - Do not emit premium, taxes, fees, surcharges, assessments, rating bases, insured values, or exposures as coverage rows or coverage terms.
5387
+ - Do not emit declined, excluded, not-covered, or optional-unselected entries as active coverages.
5388
+ - Store covered-auto, vehicle, property, location, building, and equipment listings in coverageSchedules. Partial or redacted items are allowed there.
5389
+ - Put premium rows in premiumBreakdown, taxes/fees/surcharges/assessments in taxesAndFees, and total payable in totalCost.
5390
+ - Every returned fact must cite existing sourceSpanIds or sourceNodeIds from the supplied evidence. Prefer exact row/cell sourceSpanIds.
5391
+ - Numeric, monetary, percentage, date, VIN, form, and policy identifiers must be copied exactly enough to appear in their cited evidence after punctuation and spacing normalization.
5392
+ - Omit ambiguous or unsupported facts. Do not replace or rewrite source values.
5393
+
5394
+ Prior structural context:
5395
+ ${JSON.stringify(params.context, null, 2)}
5396
+
5397
+ Source evidence:
5398
+ ${JSON.stringify(params.evidence, null, 2)}`;
5399
+ }
5400
+ function normalizedText(value) {
5401
+ return value.toLowerCase().replace(/[^a-z0-9]+/g, "");
5402
+ }
5403
+ function mechanicallyCheckableTokens(value) {
5404
+ const numeric = [...value.matchAll(/\d[\d,./:%-]*/g)].map((match) => match[0].replace(/^0+(?=\d)/, "").replace(/[^0-9a-z]/gi, "")).filter((token) => token.length >= 2);
5405
+ const identifiers = [...value.matchAll(/\b(?=[A-Z0-9-]*\d)[A-Z0-9-]{5,}\b/gi)].map((match) => normalizedText(match[0]));
5406
+ return uniqueStrings2([...numeric, ...identifiers]);
5407
+ }
5408
+ function valueGroundedInText(value, evidenceText) {
5409
+ if (!value) return true;
5410
+ const tokens = mechanicallyCheckableTokens(value);
5411
+ if (tokens.length === 0) return true;
5412
+ const normalizedEvidence = normalizedText(evidenceText);
5413
+ return tokens.every((token) => normalizedEvidence.includes(normalizedText(token)));
5414
+ }
5415
+ function citedText(ids, spansById) {
5416
+ return ids.map((id) => spansById.get(id)?.text ?? "").join(" ");
5417
+ }
5418
+ function validIds2(ids, valid) {
5419
+ return uniqueStrings2(ids.filter((id) => valid.has(id)));
5420
+ }
5421
+ function validateCandidate(candidate, sourceTree, sourceSpans) {
5422
+ const validNodeIds = new Set(sourceTree.map((node) => node.id));
5423
+ const validSpanIds = new Set(sourceSpans.map((span) => span.id));
5424
+ const spansById = new Map(sourceSpans.map((span) => [span.id, span]));
5425
+ let citationRejectionCount = 0;
5426
+ const validateCitation = (sourceNodeIds, sourceSpanIds, values) => {
5427
+ const nodes = validIds2(sourceNodeIds, validNodeIds);
5428
+ const spans = validIds2(sourceSpanIds, validSpanIds);
5429
+ if (nodes.length === 0 && spans.length === 0) {
5430
+ citationRejectionCount += 1;
5431
+ return void 0;
4977
5432
  }
4978
- if (decision.deductible == null && termDecisionsTouch(coverage, termDecisions, isDeductibleTerm)) {
4979
- const value = deductibleFromTerms(next.limits);
4980
- if (value) next.deductible = value;
4981
- else delete next.deductible;
5433
+ const evidenceText = citedText(spans, spansById);
5434
+ if (values.some((value) => !valueGroundedInText(value, evidenceText))) {
5435
+ citationRejectionCount += 1;
5436
+ return void 0;
4982
5437
  }
4983
- if (decision.premium == null && termDecisionsTouch(coverage, termDecisions, isPremiumTerm)) {
4984
- const value = premiumFromTerms(next.limits);
4985
- if (value) next.premium = value;
4986
- else delete next.premium;
5438
+ return { sourceNodeIds: nodes, sourceSpanIds: spans };
5439
+ };
5440
+ const coverages = candidate.coverages.flatMap((coverage) => {
5441
+ const coverageCitation = validateCitation(
5442
+ coverage.sourceNodeIds,
5443
+ coverage.sourceSpanIds,
5444
+ [coverage.name, coverage.limit, coverage.deductible, coverage.premium, coverage.retroactiveDate, coverage.formNumber, coverage.endorsementNumber]
5445
+ );
5446
+ if (!coverageCitation) return [];
5447
+ if (/\b(?:declined|excluded|not covered|not selected|optional\s*[-:]?\s*no)\b/i.test(coverage.name)) return [];
5448
+ if (/\b(?:premium|tax|fee|surcharge|assessment|rating basis|exposure|insured value)\b/i.test(coverage.name) && coverage.limits.length === 0 && !coverage.limit && !coverage.deductible) return [];
5449
+ const limits = coverage.limits.flatMap((term) => {
5450
+ if (term.kind === "premium") return [];
5451
+ const citation = validateCitation(
5452
+ term.sourceNodeIds,
5453
+ term.sourceSpanIds,
5454
+ [term.label, term.value, term.appliesTo]
5455
+ );
5456
+ return citation ? [{ ...term, ...citation }] : [];
5457
+ });
5458
+ const hasCoverageFact = limits.length > 0 || coverage.limit || coverage.deductible || coverage.retroactiveDate || coverage.formNumber || coverage.endorsementNumber;
5459
+ return hasCoverageFact ? [{ ...coverage, ...coverageCitation, limits }] : [];
5460
+ });
5461
+ const coverageSchedules = candidate.coverageSchedules.flatMap((schedule) => {
5462
+ const sourceSpanIds = validIds2(schedule.sourceSpanIds, validSpanIds);
5463
+ if (sourceSpanIds.length === 0 || !valueGroundedInText(schedule.name, citedText(sourceSpanIds, spansById))) {
5464
+ citationRejectionCount += 1;
5465
+ return [];
4987
5466
  }
4988
- if (decision.retroactiveDate == null && termDecisionsTouch(coverage, termDecisions, isRetroactiveDateTerm)) {
4989
- const value = retroactiveDateFromTerms(next.limits);
4990
- if (value) next.retroactiveDate = value;
4991
- else delete next.retroactiveDate;
5467
+ const items = schedule.items.flatMap((item) => {
5468
+ const itemSpanIds = validIds2(item.sourceSpanIds, validSpanIds);
5469
+ if (itemSpanIds.length === 0) {
5470
+ citationRejectionCount += 1;
5471
+ return [];
5472
+ }
5473
+ const evidenceText = citedText(itemSpanIds, spansById);
5474
+ const values = item.values.filter((value) => {
5475
+ const valid = valueGroundedInText(value.value, evidenceText);
5476
+ if (!valid) citationRejectionCount += 1;
5477
+ return valid;
5478
+ });
5479
+ return values.length > 0 && valueGroundedInText(item.label, evidenceText) ? [{ ...item, values, sourceSpanIds: itemSpanIds }] : [];
5480
+ });
5481
+ return items.length > 0 ? [{ ...schedule, items, sourceSpanIds }] : [];
5482
+ });
5483
+ const premiumBreakdown = candidate.premiumBreakdown.flatMap((row) => {
5484
+ const citation = validateCitation(row.sourceNodeIds, row.sourceSpanIds, [row.line, row.amount]);
5485
+ return citation ? [{ ...row, ...citation }] : [];
5486
+ });
5487
+ const taxesAndFees = candidate.taxesAndFees.flatMap((row) => {
5488
+ const citation = validateCitation(row.sourceNodeIds, row.sourceSpanIds, [row.name, row.amount]);
5489
+ return citation ? [{ ...row, ...citation }] : [];
5490
+ });
5491
+ const totalCostCitation = candidate.totalCost ? validateCitation(candidate.totalCost.sourceNodeIds, candidate.totalCost.sourceSpanIds, [candidate.totalCost.value]) : void 0;
5492
+ return {
5493
+ candidate: {
5494
+ ...candidate,
5495
+ coverages,
5496
+ coverageSchedules,
5497
+ premiumBreakdown,
5498
+ taxesAndFees,
5499
+ totalCost: candidate.totalCost && totalCostCitation ? { ...candidate.totalCost, ...totalCostCitation } : void 0
5500
+ },
5501
+ citationRejectionCount
5502
+ };
5503
+ }
5504
+ function normalizedLabel(value) {
5505
+ return value.toLowerCase().replace(/&/g, " and ").replace(/[^a-z0-9]+/g, " ").trim();
5506
+ }
5507
+ function sourcePages(ids, spansById) {
5508
+ const pages = ids.flatMap((id) => {
5509
+ const span = spansById.get(id);
5510
+ const start = span ? spanPageStart(span) : void 0;
5511
+ const end = span ? spanPageEnd(span) : void 0;
5512
+ return [start, end].filter((page) => typeof page === "number");
5513
+ });
5514
+ return pages.length > 0 ? [Math.min(...pages), Math.max(...pages)] : void 0;
5515
+ }
5516
+ function sameCoverageScope(primary, recovery, spansById) {
5517
+ if (normalizedLabel(primary.name) !== normalizedLabel(recovery.name)) return false;
5518
+ if (primary.lineOfBusiness && recovery.lineOfBusiness && primary.lineOfBusiness !== recovery.lineOfBusiness) return false;
5519
+ for (const key of ["formNumber", "sectionRef", "endorsementNumber"]) {
5520
+ const left = cleanText(primary[key]);
5521
+ const right = cleanText(recovery[key]);
5522
+ if (left && right && normalizedLabel(left) !== normalizedLabel(right)) return false;
5523
+ if (key === "endorsementNumber" && Boolean(left) !== Boolean(right)) return false;
5524
+ }
5525
+ const primaryPages = sourcePages(primary.sourceSpanIds, spansById);
5526
+ const recoveryPages = sourcePages(recovery.sourceSpanIds, spansById);
5527
+ if (!primaryPages || !recoveryPages) return true;
5528
+ return primaryPages[0] <= recoveryPages[1] + 1 && recoveryPages[0] <= primaryPages[1] + 1;
5529
+ }
5530
+ function termIdentity(term) {
5531
+ return [term.kind, normalizedLabel(term.label), normalizedLabel(term.value), normalizedLabel(term.appliesTo ?? "")].join("|");
5532
+ }
5533
+ function mergeCoverage(primary, recovery, warnings) {
5534
+ const limits = [...primary.limits];
5535
+ const identities = new Set(limits.map(termIdentity));
5536
+ for (const term of recovery.limits) {
5537
+ const identity = termIdentity(term);
5538
+ if (identities.has(identity)) continue;
5539
+ const conflict = limits.find(
5540
+ (current) => current.kind === term.kind && normalizedLabel(current.label) === normalizedLabel(term.label) && normalizedLabel(current.appliesTo ?? "") === normalizedLabel(term.appliesTo ?? "") && normalizedLabel(current.value) !== normalizedLabel(term.value)
5541
+ );
5542
+ if (conflict) {
5543
+ warnings.push(`Coverage recovery preserved conflicting cited ${term.label} terms for ${primary.name}.`);
4992
5544
  }
5545
+ limits.push(term);
5546
+ identities.add(identity);
4993
5547
  }
4994
- const termLimit = primaryLimitFromTerms(next.limits);
4995
- if (termLimit && shouldUseTermLimitDisplay(next.limit, termLimit)) {
4996
- next.limit = termLimit;
5548
+ return {
5549
+ ...recovery,
5550
+ ...primary,
5551
+ limit: primary.limit ?? recovery.limit,
5552
+ deductible: primary.deductible ?? recovery.deductible,
5553
+ premium: primary.premium ?? recovery.premium,
5554
+ retroactiveDate: primary.retroactiveDate ?? recovery.retroactiveDate,
5555
+ formNumber: primary.formNumber ?? recovery.formNumber,
5556
+ sectionRef: primary.sectionRef ?? recovery.sectionRef,
5557
+ endorsementNumber: primary.endorsementNumber ?? recovery.endorsementNumber,
5558
+ limits,
5559
+ sourceNodeIds: uniqueStrings2([...primary.sourceNodeIds, ...recovery.sourceNodeIds]),
5560
+ sourceSpanIds: uniqueStrings2([...primary.sourceSpanIds, ...recovery.sourceSpanIds])
5561
+ };
5562
+ }
5563
+ function appendUnique(primary, additions, key) {
5564
+ const result = [...primary];
5565
+ const seen = new Set(primary.map(key));
5566
+ for (const value of additions) {
5567
+ const identity = key(value);
5568
+ if (seen.has(identity)) continue;
5569
+ seen.add(identity);
5570
+ result.push(value);
4997
5571
  }
4998
- next.sourceNodeIds = uniqueStrings([
4999
- ...next.sourceNodeIds,
5000
- ...next.limits.flatMap((term) => term.sourceNodeIds)
5572
+ return result;
5573
+ }
5574
+ function mergeRecoveryCandidate(profile, candidate, sourceSpans) {
5575
+ const warnings = [...candidate.warnings];
5576
+ const spansById = new Map(sourceSpans.map((span) => [span.id, span]));
5577
+ const coverages = [...profile.coverages];
5578
+ let recoveredCoverageCount = 0;
5579
+ let recoveredTermCount = 0;
5580
+ for (const recovery of candidate.coverages) {
5581
+ const matchIndex = coverages.findIndex((primary) => sameCoverageScope(primary, recovery, spansById));
5582
+ if (matchIndex < 0) {
5583
+ coverages.push(recovery);
5584
+ recoveredCoverageCount += 1;
5585
+ recoveredTermCount += recovery.limits.length;
5586
+ continue;
5587
+ }
5588
+ const before = coverages[matchIndex].limits.length;
5589
+ coverages[matchIndex] = mergeCoverage(coverages[matchIndex], recovery, warnings);
5590
+ recoveredTermCount += coverages[matchIndex].limits.length - before;
5591
+ }
5592
+ const coverageSchedules = appendUnique(
5593
+ profile.coverageSchedules ?? [],
5594
+ candidate.coverageSchedules,
5595
+ (schedule) => `${schedule.kind}|${normalizedLabel(schedule.name)}|${schedule.pageStart ?? ""}|${schedule.pageEnd ?? ""}`
5596
+ );
5597
+ const premiumBreakdown = appendUnique(
5598
+ profile.premiumBreakdown ?? [],
5599
+ candidate.premiumBreakdown,
5600
+ (row) => `${normalizedLabel(row.line)}|${normalizedLabel(row.amount)}|${row.sourceSpanIds.join(",")}`
5601
+ );
5602
+ const taxesAndFees = appendUnique(
5603
+ profile.taxesAndFees ?? [],
5604
+ candidate.taxesAndFees,
5605
+ (row) => `${normalizedLabel(row.name)}|${normalizedLabel(row.amount)}|${row.sourceSpanIds.join(",")}`
5606
+ );
5607
+ const totalCost = profile.totalCost ?? candidate.totalCost;
5608
+ const sourceNodeIds = uniqueStrings2([
5609
+ ...profile.sourceNodeIds,
5610
+ ...coverages.flatMap((coverage) => [
5611
+ ...coverage.sourceNodeIds,
5612
+ ...coverage.limits.flatMap((term) => term.sourceNodeIds)
5613
+ ]),
5614
+ ...premiumBreakdown.flatMap((row) => row.sourceNodeIds),
5615
+ ...taxesAndFees.flatMap((row) => row.sourceNodeIds),
5616
+ ...totalCost?.sourceNodeIds ?? []
5001
5617
  ]);
5002
- next.sourceSpanIds = uniqueStrings([
5003
- ...next.sourceSpanIds,
5004
- ...next.limits.flatMap((term) => term.sourceSpanIds)
5618
+ const sourceSpanIds = uniqueStrings2([
5619
+ ...profile.sourceSpanIds,
5620
+ ...coverages.flatMap((coverage) => [
5621
+ ...coverage.sourceSpanIds,
5622
+ ...coverage.limits.flatMap((term) => term.sourceSpanIds)
5623
+ ]),
5624
+ ...coverageSchedules.flatMap((schedule) => [
5625
+ ...schedule.sourceSpanIds,
5626
+ ...schedule.items.flatMap((item) => item.sourceSpanIds)
5627
+ ]),
5628
+ ...premiumBreakdown.flatMap((row) => row.sourceSpanIds),
5629
+ ...taxesAndFees.flatMap((row) => row.sourceSpanIds),
5630
+ ...totalCost?.sourceSpanIds ?? []
5005
5631
  ]);
5006
- return next.name ? next : coverage;
5632
+ return {
5633
+ operationalProfile: {
5634
+ ...profile,
5635
+ coverages,
5636
+ coverageSchedules,
5637
+ premiumBreakdown,
5638
+ taxesAndFees,
5639
+ totalCost,
5640
+ sourceNodeIds,
5641
+ sourceSpanIds,
5642
+ warnings: uniqueStrings2([...profile.warnings, ...warnings])
5643
+ },
5644
+ warnings,
5645
+ recoveredCoverageCount,
5646
+ recoveredTermCount,
5647
+ recoveredScheduleCount: coverageSchedules.length - (profile.coverageSchedules?.length ?? 0),
5648
+ recoveredFinancialFactCount: premiumBreakdown.length - (profile.premiumBreakdown?.length ?? 0) + taxesAndFees.length - (profile.taxesAndFees?.length ?? 0) + (!profile.totalCost && totalCost ? 1 : 0)
5649
+ };
5007
5650
  }
5008
- function sourceIdsFromOperationalProfile(profile) {
5009
- const backedValues = [
5010
- profile.policyNumber,
5011
- profile.namedInsured,
5012
- profile.insurer,
5013
- profile.broker,
5014
- profile.effectiveDate,
5015
- profile.expirationDate,
5016
- profile.retroactiveDate,
5017
- profile.premium,
5018
- profile.operationsDescription
5019
- ].filter(Boolean);
5651
+ function emptyDiagnostics(status) {
5020
5652
  return {
5021
- sourceNodeIds: uniqueStrings([
5022
- ...backedValues.flatMap((value) => value?.sourceNodeIds ?? []),
5023
- ...profile.coverages.flatMap((coverage) => coverage.sourceNodeIds),
5024
- ...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceNodeIds)),
5025
- ...profile.parties.flatMap((party) => party.sourceNodeIds),
5026
- ...profile.endorsementSupport.flatMap((support) => support.sourceNodeIds)
5027
- ]),
5028
- sourceSpanIds: uniqueStrings([
5029
- ...backedValues.flatMap((value) => value?.sourceSpanIds ?? []),
5030
- ...profile.coverages.flatMap((coverage) => coverage.sourceSpanIds),
5031
- ...profile.coverages.flatMap((coverage) => coverage.limits.flatMap((term) => term.sourceSpanIds)),
5032
- ...profile.parties.flatMap((party) => party.sourceSpanIds),
5033
- ...profile.endorsementSupport.flatMap((support) => support.sourceSpanIds)
5034
- ])
5653
+ version: COVERAGE_RECOVERY_VERSION,
5654
+ status,
5655
+ regionCount: 0,
5656
+ modelCallCount: 0,
5657
+ recoveredCoverageCount: 0,
5658
+ recoveredTermCount: 0,
5659
+ recoveredScheduleCount: 0,
5660
+ recoveredFinancialFactCount: 0,
5661
+ citationRejectionCount: 0,
5662
+ warnings: []
5035
5663
  };
5036
5664
  }
5037
- function applyOperationalProfileCleanup(profile, cleanup, validNodeIds, validSpanIds) {
5038
- const coverageDecisionByIndex = /* @__PURE__ */ new Map();
5039
- for (const decision of cleanup.coverageDecisions) {
5040
- if (decision.coverageIndex < profile.coverages.length) coverageDecisionByIndex.set(decision.coverageIndex, decision);
5665
+ function disabledCoverageRecoveryDiagnostics() {
5666
+ return emptyDiagnostics("disabled");
5667
+ }
5668
+ async function recoverOperationalProfileCoverage(params) {
5669
+ const diagnostics = emptyDiagnostics("succeeded");
5670
+ try {
5671
+ const pages = documentPages(params.sourceTree, params.sourceSpans);
5672
+ const discoveredRegions = [];
5673
+ for (const [batchIndex, pageBatch] of chunkValues(pages, DISCOVERY_PAGE_BATCH_SIZE).entries()) {
5674
+ const sketches = pageBatch.map((page) => pageSketch(page, params.sourceTree, params.sourceSpans));
5675
+ const budget = params.resolveBudget("extraction_coverage_recovery", 8192);
5676
+ const startedAt = Date.now();
5677
+ diagnostics.modelCallCount += 1;
5678
+ const response = await safeGenerateObject(
5679
+ params.generateObject,
5680
+ {
5681
+ prompt: discoveryPrompt(sketches),
5682
+ schema: RecoveryRegionDiscoverySchema,
5683
+ maxTokens: budget.maxTokens,
5684
+ taskKind: "extraction_coverage_recovery",
5685
+ budgetDiagnostics: budget,
5686
+ providerOptions: params.providerOptions,
5687
+ trace: {
5688
+ phase: "coverage_recovery_discovery",
5689
+ label: "coverage_recovery_discovery",
5690
+ startPage: pageBatch[0],
5691
+ endPage: pageBatch[pageBatch.length - 1],
5692
+ batchIndex: batchIndex + 1,
5693
+ batchCount: Math.ceil(pages.length / DISCOVERY_PAGE_BATCH_SIZE),
5694
+ sourceBacked: true
5695
+ }
5696
+ },
5697
+ { maxRetries: 0, log: params.log, retry: false }
5698
+ );
5699
+ params.trackUsage(response.usage, {
5700
+ taskKind: "extraction_coverage_recovery",
5701
+ label: "coverage_recovery_discovery",
5702
+ maxTokens: budget.maxTokens,
5703
+ durationMs: Date.now() - startedAt
5704
+ });
5705
+ const discovery = response.object;
5706
+ discoveredRegions.push(...discovery.regions);
5707
+ diagnostics.warnings.push(...discovery.warnings);
5708
+ }
5709
+ const regions = splitRegions(normalizeRegions(discoveredRegions, pages));
5710
+ diagnostics.regionCount = regions.length;
5711
+ let operationalProfile = params.operationalProfile;
5712
+ for (const [regionIndex, region] of regions.entries()) {
5713
+ const evidence = regionEvidence(region, params.sourceTree, params.sourceSpans);
5714
+ const batches = evidenceBatches(evidence);
5715
+ const context = priorStructuralContext(region, params.sourceTree, params.sourceSpans);
5716
+ for (const [batchIndex, batch] of batches.entries()) {
5717
+ const budget = params.resolveBudget("extraction_coverage_recovery", 12288);
5718
+ const startedAt = Date.now();
5719
+ diagnostics.modelCallCount += 1;
5720
+ const response = await safeGenerateObject(
5721
+ params.generateObject,
5722
+ {
5723
+ prompt: recoveryPrompt({
5724
+ region,
5725
+ context,
5726
+ evidence: batch,
5727
+ batchIndex: batchIndex + 1,
5728
+ batchCount: batches.length
5729
+ }),
5730
+ schema: CoverageRecoveryCandidateSchema,
5731
+ maxTokens: budget.maxTokens,
5732
+ taskKind: "extraction_coverage_recovery",
5733
+ budgetDiagnostics: budget,
5734
+ providerOptions: params.providerOptions,
5735
+ trace: {
5736
+ phase: "coverage_recovery",
5737
+ label: "coverage_recovery",
5738
+ startPage: region.pageStart,
5739
+ endPage: region.pageEnd,
5740
+ batchIndex: batchIndex + 1,
5741
+ batchCount: batches.length,
5742
+ sourceBacked: true
5743
+ }
5744
+ },
5745
+ { maxRetries: 0, log: params.log, retry: false }
5746
+ );
5747
+ params.trackUsage(response.usage, {
5748
+ taskKind: "extraction_coverage_recovery",
5749
+ label: `coverage_recovery_${regionIndex + 1}`,
5750
+ maxTokens: budget.maxTokens,
5751
+ durationMs: Date.now() - startedAt
5752
+ });
5753
+ const validated = validateCandidate(
5754
+ response.object,
5755
+ params.sourceTree,
5756
+ params.sourceSpans
5757
+ );
5758
+ diagnostics.citationRejectionCount += validated.citationRejectionCount;
5759
+ const merged = mergeRecoveryCandidate(operationalProfile, validated.candidate, params.sourceSpans);
5760
+ operationalProfile = merged.operationalProfile;
5761
+ diagnostics.recoveredCoverageCount += merged.recoveredCoverageCount;
5762
+ diagnostics.recoveredTermCount += merged.recoveredTermCount;
5763
+ diagnostics.recoveredScheduleCount += merged.recoveredScheduleCount;
5764
+ diagnostics.recoveredFinancialFactCount += merged.recoveredFinancialFactCount;
5765
+ diagnostics.warnings.push(...merged.warnings);
5766
+ }
5767
+ }
5768
+ diagnostics.warnings = uniqueStrings2(diagnostics.warnings);
5769
+ return { operationalProfile, diagnostics };
5770
+ } catch (error) {
5771
+ diagnostics.status = "failed";
5772
+ diagnostics.warnings = uniqueStrings2([
5773
+ ...diagnostics.warnings,
5774
+ `Coverage recovery failed: ${error instanceof Error ? error.message : String(error)}`
5775
+ ]);
5776
+ await params.log?.(diagnostics.warnings[diagnostics.warnings.length - 1]);
5777
+ return { operationalProfile: params.operationalProfile, diagnostics };
5041
5778
  }
5042
- const coverages = profile.coverages.map(
5043
- (coverage, index) => applyCoverageCleanupDecision(coverage, coverageDecisionByIndex.get(index), validNodeIds, validSpanIds)
5044
- ).filter((coverage) => Boolean(coverage));
5045
- const cleanupWarnings = cleanup.warnings.map((warning) => cleanProfileValue(warning)).filter((warning) => Boolean(warning));
5046
- const nextProfile = {
5047
- ...profile,
5048
- coverages,
5049
- warnings: uniqueStrings([
5050
- ...profile.warnings,
5051
- ...cleanupWarnings.map((warning) => `Operational profile cleanup warning: ${warning}`)
5052
- ])
5779
+ }
5780
+ async function runCoverageRecovery(params) {
5781
+ const tokenUsage = { inputTokens: 0, outputTokens: 0 };
5782
+ const performanceReport = {
5783
+ modelCalls: [],
5784
+ totalModelCallDurationMs: 0
5053
5785
  };
5054
- return PolicyOperationalProfileSchema.parse({
5055
- ...nextProfile,
5056
- ...sourceIdsFromOperationalProfile(nextProfile)
5786
+ const recovery = await recoverOperationalProfileCoverage({
5787
+ sourceTree: params.sourceTree,
5788
+ sourceSpans: params.sourceSpans,
5789
+ operationalProfile: params.operationalProfile,
5790
+ generateObject: params.generateObject,
5791
+ providerOptions: params.providerOptions,
5792
+ resolveBudget: (taskKind, hintTokens) => resolveModelBudget({
5793
+ taskKind,
5794
+ hintTokens,
5795
+ modelCapabilities: params.modelCapabilities,
5796
+ constraint: params.modelBudgetConstraint
5797
+ }),
5798
+ trackUsage: (usage, report) => {
5799
+ if (usage) {
5800
+ tokenUsage.inputTokens += usage.inputTokens;
5801
+ tokenUsage.outputTokens += usage.outputTokens;
5802
+ params.onTokenUsage?.(usage);
5803
+ }
5804
+ if (report) {
5805
+ performanceReport.modelCalls.push({
5806
+ ...report,
5807
+ usage,
5808
+ usageReported: Boolean(usage)
5809
+ });
5810
+ if (report.durationMs != null) {
5811
+ performanceReport.totalModelCallDurationMs += report.durationMs;
5812
+ }
5813
+ }
5814
+ },
5815
+ log: params.log
5057
5816
  });
5817
+ return {
5818
+ ...recovery,
5819
+ tokenUsage,
5820
+ performanceReport
5821
+ };
5058
5822
  }
5059
5823
 
5060
5824
  // src/extraction/source-tree-extractor.ts
5061
- var SourceBackedValueForPromptSchema = import_zod23.z.object({
5062
- value: import_zod23.z.string(),
5063
- normalizedValue: import_zod23.z.string().optional(),
5064
- confidence: import_zod23.z.enum(["low", "medium", "high"]).optional(),
5065
- sourceNodeIds: import_zod23.z.array(import_zod23.z.string()),
5066
- sourceSpanIds: import_zod23.z.array(import_zod23.z.string())
5067
- });
5068
- var OperationalAddressForPromptSchema = import_zod23.z.object({
5069
- street1: import_zod23.z.string().optional(),
5070
- street2: import_zod23.z.string().optional(),
5071
- city: import_zod23.z.string().optional(),
5072
- state: import_zod23.z.string().optional(),
5073
- zip: import_zod23.z.string().optional(),
5074
- country: import_zod23.z.string().optional(),
5075
- formatted: import_zod23.z.string().optional()
5076
- });
5077
- var OperationalDeclarationFactForPromptSchema = import_zod23.z.object({
5078
- field: import_zod23.z.enum([
5825
+ var SourceBackedValueForPromptSchema = import_zod24.z.object({
5826
+ value: import_zod24.z.string(),
5827
+ normalizedValue: import_zod24.z.string().optional(),
5828
+ confidence: import_zod24.z.enum(["low", "medium", "high"]).optional(),
5829
+ sourceNodeIds: import_zod24.z.array(import_zod24.z.string()),
5830
+ sourceSpanIds: import_zod24.z.array(import_zod24.z.string())
5831
+ });
5832
+ var OperationalAddressForPromptSchema = import_zod24.z.object({
5833
+ street1: import_zod24.z.string().optional(),
5834
+ street2: import_zod24.z.string().optional(),
5835
+ city: import_zod24.z.string().optional(),
5836
+ state: import_zod24.z.string().optional(),
5837
+ zip: import_zod24.z.string().optional(),
5838
+ country: import_zod24.z.string().optional(),
5839
+ formatted: import_zod24.z.string().optional()
5840
+ });
5841
+ var OperationalDeclarationFactForPromptSchema = import_zod24.z.object({
5842
+ field: import_zod24.z.enum([
5079
5843
  "namedInsured",
5080
5844
  "mailingAddress",
5081
5845
  "dba",
@@ -5090,17 +5854,17 @@ var OperationalDeclarationFactForPromptSchema = import_zod23.z.object({
5090
5854
  "premium",
5091
5855
  "other"
5092
5856
  ]),
5093
- label: import_zod23.z.string().optional(),
5094
- value: import_zod23.z.string(),
5095
- normalizedValue: import_zod23.z.string().optional(),
5096
- valueKind: import_zod23.z.enum(["string", "number", "date", "money", "address", "list", "unknown"]).optional(),
5857
+ label: import_zod24.z.string().optional(),
5858
+ value: import_zod24.z.string(),
5859
+ normalizedValue: import_zod24.z.string().optional(),
5860
+ valueKind: import_zod24.z.enum(["string", "number", "date", "money", "address", "list", "unknown"]).optional(),
5097
5861
  address: OperationalAddressForPromptSchema.optional(),
5098
- confidence: import_zod23.z.enum(["low", "medium", "high"]).optional(),
5099
- sourceNodeIds: import_zod23.z.array(import_zod23.z.string()),
5100
- sourceSpanIds: import_zod23.z.array(import_zod23.z.string())
5862
+ confidence: import_zod24.z.enum(["low", "medium", "high"]).optional(),
5863
+ sourceNodeIds: import_zod24.z.array(import_zod24.z.string()),
5864
+ sourceSpanIds: import_zod24.z.array(import_zod24.z.string())
5101
5865
  });
5102
- var OperationalPartyForPromptSchema = import_zod23.z.object({
5103
- role: import_zod23.z.enum([
5866
+ var OperationalPartyForPromptSchema = import_zod24.z.object({
5867
+ role: import_zod24.z.enum([
5104
5868
  "named_insured",
5105
5869
  "producer",
5106
5870
  "broker",
@@ -5109,14 +5873,14 @@ var OperationalPartyForPromptSchema = import_zod23.z.object({
5109
5873
  "mga",
5110
5874
  "administrator"
5111
5875
  ]),
5112
- name: import_zod23.z.string(),
5876
+ name: import_zod24.z.string(),
5113
5877
  address: OperationalAddressForPromptSchema.optional(),
5114
- sourceNodeIds: import_zod23.z.array(import_zod23.z.string()),
5115
- sourceSpanIds: import_zod23.z.array(import_zod23.z.string())
5878
+ sourceNodeIds: import_zod24.z.array(import_zod24.z.string()),
5879
+ sourceSpanIds: import_zod24.z.array(import_zod24.z.string())
5116
5880
  });
5117
- var OperationalProfilePromptSchema = import_zod23.z.object({
5118
- documentType: import_zod23.z.enum(["policy", "quote"]).optional(),
5119
- linesOfBusiness: import_zod23.z.array(import_zod23.z.string()).optional(),
5881
+ var OperationalProfilePromptSchema = import_zod24.z.object({
5882
+ documentType: import_zod24.z.enum(["policy", "quote"]).optional(),
5883
+ linesOfBusiness: import_zod24.z.array(import_zod24.z.string()).optional(),
5120
5884
  policyNumber: SourceBackedValueForPromptSchema.optional(),
5121
5885
  namedInsured: SourceBackedValueForPromptSchema.optional(),
5122
5886
  insurer: SourceBackedValueForPromptSchema.optional(),
@@ -5126,40 +5890,40 @@ var OperationalProfilePromptSchema = import_zod23.z.object({
5126
5890
  retroactiveDate: SourceBackedValueForPromptSchema.optional(),
5127
5891
  premium: SourceBackedValueForPromptSchema.optional(),
5128
5892
  operationsDescription: SourceBackedValueForPromptSchema.optional(),
5129
- declarationFacts: import_zod23.z.array(OperationalDeclarationFactForPromptSchema).optional(),
5130
- parties: import_zod23.z.array(OperationalPartyForPromptSchema).optional(),
5131
- coverages: import_zod23.z.array(import_zod23.z.object({
5132
- name: import_zod23.z.string(),
5133
- lineOfBusiness: import_zod23.z.string().optional(),
5134
- coverageCode: import_zod23.z.string().optional(),
5135
- limit: import_zod23.z.string().optional(),
5136
- deductible: import_zod23.z.string().optional(),
5137
- premium: import_zod23.z.string().optional(),
5138
- retroactiveDate: import_zod23.z.string().optional(),
5139
- formNumber: import_zod23.z.string().optional(),
5140
- sectionRef: import_zod23.z.string().optional(),
5141
- endorsementNumber: import_zod23.z.string().optional(),
5142
- limits: import_zod23.z.array(import_zod23.z.object({
5893
+ declarationFacts: import_zod24.z.array(OperationalDeclarationFactForPromptSchema).optional(),
5894
+ parties: import_zod24.z.array(OperationalPartyForPromptSchema).optional(),
5895
+ coverages: import_zod24.z.array(import_zod24.z.object({
5896
+ name: import_zod24.z.string(),
5897
+ lineOfBusiness: import_zod24.z.string().optional(),
5898
+ coverageCode: import_zod24.z.string().optional(),
5899
+ limit: import_zod24.z.string().optional(),
5900
+ deductible: import_zod24.z.string().optional(),
5901
+ premium: import_zod24.z.string().optional(),
5902
+ retroactiveDate: import_zod24.z.string().optional(),
5903
+ formNumber: import_zod24.z.string().optional(),
5904
+ sectionRef: import_zod24.z.string().optional(),
5905
+ endorsementNumber: import_zod24.z.string().optional(),
5906
+ limits: import_zod24.z.array(import_zod24.z.object({
5143
5907
  kind: OperationalCoverageTermKindSchema.optional(),
5144
- label: import_zod23.z.string(),
5145
- value: import_zod23.z.string(),
5146
- amount: import_zod23.z.number().optional(),
5147
- appliesTo: import_zod23.z.string().optional(),
5148
- sourceNodeIds: import_zod23.z.array(import_zod23.z.string()),
5149
- sourceSpanIds: import_zod23.z.array(import_zod23.z.string())
5908
+ label: import_zod24.z.string(),
5909
+ value: import_zod24.z.string(),
5910
+ amount: import_zod24.z.number().optional(),
5911
+ appliesTo: import_zod24.z.string().optional(),
5912
+ sourceNodeIds: import_zod24.z.array(import_zod24.z.string()),
5913
+ sourceSpanIds: import_zod24.z.array(import_zod24.z.string())
5150
5914
  })).optional(),
5151
- sourceNodeIds: import_zod23.z.array(import_zod23.z.string()),
5152
- sourceSpanIds: import_zod23.z.array(import_zod23.z.string())
5915
+ sourceNodeIds: import_zod24.z.array(import_zod24.z.string()),
5916
+ sourceSpanIds: import_zod24.z.array(import_zod24.z.string())
5153
5917
  })).optional(),
5154
- sourceNodeIds: import_zod23.z.array(import_zod23.z.string()).optional(),
5155
- sourceSpanIds: import_zod23.z.array(import_zod23.z.string()).optional()
5918
+ sourceNodeIds: import_zod24.z.array(import_zod24.z.string()).optional(),
5919
+ sourceSpanIds: import_zod24.z.array(import_zod24.z.string()).optional()
5156
5920
  });
5157
- function cleanText(value, fallback) {
5921
+ function cleanText2(value, fallback) {
5158
5922
  const text = value?.replace(/\s+/g, " ").trim();
5159
5923
  return text || fallback;
5160
5924
  }
5161
5925
  function simplifyOrganizerTitle(value, fallback, kind) {
5162
- const title = cleanText(value, fallback);
5926
+ const title = cleanText2(value, fallback);
5163
5927
  if (/^declarations\b/i.test(title)) return "Declarations";
5164
5928
  if (/^policy\s+form\b/i.test(title)) return "Policy Form";
5165
5929
  if (/^definitions\b/i.test(title)) return "Definitions";
@@ -5172,23 +5936,23 @@ function simplifyOrganizerTitle(value, fallback, kind) {
5172
5936
  return title;
5173
5937
  }
5174
5938
  function endorsementReference(value) {
5175
- const text = cleanText(value, "");
5939
+ const text = cleanText2(value, "");
5176
5940
  const explicit = text.match(/\bendorsement\s+(?:no\.?|number|#)?\s*([A-Z0-9][A-Z0-9.-]*)\b/i)?.[1]?.toUpperCase();
5177
5941
  if (explicit) return explicit;
5178
5942
  return text.match(/\b(?:[A-Z]{2,}-)?END\s+0*([0-9]{1,4})\b/i)?.[1]?.toUpperCase();
5179
5943
  }
5180
5944
  function endorsementTitle(value) {
5181
- const text = cleanText(value, "");
5945
+ const text = cleanText2(value, "");
5182
5946
  const explicit = text.match(/\bendorsement\s+(?:no\.?|number|#)\s*([A-Z0-9][A-Z0-9.-]*)\b/i)?.[1]?.toUpperCase();
5183
5947
  const number = explicit ?? text.match(/\b(?:[A-Z]{2,}-)?END\s+0*([0-9]{1,4})\b/i)?.[1]?.toUpperCase();
5184
5948
  return number ? `Endorsement No. ${number}` : void 0;
5185
5949
  }
5186
5950
  function sourceNodeText(node) {
5187
- return cleanText([node.title, node.description, node.textExcerpt].filter(Boolean).join(" "), "");
5951
+ return cleanText2([node.title, node.description, node.textExcerpt].filter(Boolean).join(" "), "");
5188
5952
  }
5189
5953
  function looksLikeEndorsementStart(node) {
5190
- const title = cleanText(node.title, "");
5191
- const body = cleanText([node.textExcerpt, node.description].filter(Boolean).join(" "), "");
5954
+ const title = cleanText2(node.title, "");
5955
+ const body = cleanText2([node.textExcerpt, node.description].filter(Boolean).join(" "), "");
5192
5956
  const start = body.slice(0, 260);
5193
5957
  if (/\bthis endorsement changes the policy\b/i.test(start) && endorsementReference(start)) return true;
5194
5958
  if (/^(?:[A-Z]{2,}-)?END\s+0*[0-9]{1,4}\b/i.test(start)) return true;
@@ -5197,7 +5961,7 @@ function looksLikeEndorsementStart(node) {
5197
5961
  }
5198
5962
  function looksLikeEndorsementContinuation(node) {
5199
5963
  if (looksLikeEndorsementStart(node)) return false;
5200
- const title = cleanText(node.title, "");
5964
+ const title = cleanText2(node.title, "");
5201
5965
  const text = sourceNodeText(node);
5202
5966
  return /\bendorsement\b/i.test(text) || /\bcontinuation\b/i.test(title) || /\ball\s+other\s+terms\s+and\s+conditions\b/i.test(text);
5203
5967
  }
@@ -5205,7 +5969,7 @@ function endorsementStartTitle(node) {
5205
5969
  return looksLikeEndorsementStart(node) ? endorsementTitle(sourceNodeText(node)) : void 0;
5206
5970
  }
5207
5971
  function endorsementDescription(title, node) {
5208
- return cleanText(
5972
+ return cleanText2(
5209
5973
  [title, "endorsement", node.pageStart ? `page ${node.pageStart}` : void 0].filter(Boolean).join(" | "),
5210
5974
  title
5211
5975
  );
@@ -5213,7 +5977,7 @@ function endorsementDescription(title, node) {
5213
5977
  function endorsementTitleKey(node) {
5214
5978
  const title = endorsementTitle(sourceNodeText(node));
5215
5979
  if (title) return title.toLowerCase();
5216
- const fallback = cleanText(node.title, "");
5980
+ const fallback = cleanText2(node.title, "");
5217
5981
  return fallback ? fallback.toLowerCase() : void 0;
5218
5982
  }
5219
5983
  function nodePageEnd2(node) {
@@ -5257,17 +6021,17 @@ function semanticGroupNodeId(documentId, kind, title, childNodeIds) {
5257
6021
  childNodeIds.join("_").replace(/[^a-zA-Z0-9_.:-]/g, "_").slice(0, 80)
5258
6022
  ].join(":");
5259
6023
  }
5260
- function spanPageStart(span) {
6024
+ function spanPageStart2(span) {
5261
6025
  return span.pageStart ?? span.location?.page ?? span.location?.startPage;
5262
6026
  }
5263
- function spanPageEnd(span) {
5264
- return span.pageEnd ?? span.location?.endPage ?? spanPageStart(span);
6027
+ function spanPageEnd2(span) {
6028
+ return span.pageEnd ?? span.location?.endPage ?? spanPageStart2(span);
5265
6029
  }
5266
- function spanSourceUnit(span) {
6030
+ function spanSourceUnit2(span) {
5267
6031
  return span.sourceUnit ?? span.metadata?.sourceUnit ?? span.metadata?.elementType;
5268
6032
  }
5269
6033
  function pageHeadingTitleFromText(text, fallback) {
5270
- const normalized = cleanText(text, "");
6034
+ const normalized = cleanText2(text, "");
5271
6035
  const headingText = normalized.replace(/^page\s+\d+\s*(?:\|\s*page\s*\|\s*page\s+\d+\s*\|?)?/i, "").slice(0, 700);
5272
6036
  const patterns = [
5273
6037
  /\bIMPORTANT NOTICE\s+[—-]\s+HOW TO REPORT A CLAIM\b/i,
@@ -5281,7 +6045,7 @@ function pageHeadingTitleFromText(text, fallback) {
5281
6045
  ];
5282
6046
  for (const pattern of patterns) {
5283
6047
  const match = headingText.match(pattern)?.[0];
5284
- if (match) return cleanText(match, fallback);
6048
+ if (match) return cleanText2(match, fallback);
5285
6049
  }
5286
6050
  return fallback;
5287
6051
  }
@@ -5289,12 +6053,12 @@ function hasSubstantiveDeclarationsScheduleText(text) {
5289
6053
  return /\bitem\s+\d+\.?\s*(?:named insured|policy number|policy period|renewal|form of business|coverage parts?|limits?|premium|extended reporting|producer|forms? and endorsements?)\b/i.test(text) || /\bforms? and endorsements attached at inception\b/i.test(text) || /\bcoverage parts?,?\s+limits? of liability,?\s+deductibles?,?\s+and retroactive dates\b/i.test(text) || /\bannual premium\s*\(all coverage parts?\)\b/i.test(text) || /\berp option\b/i.test(text) || /\bproducer\b[\s\S]{0,240}\blicense\b/i.test(text);
5290
6054
  }
5291
6055
  function looksLikeDeclarationsStart(node) {
5292
- const title = cleanText(node.title, "");
6056
+ const title = cleanText2(node.title, "");
5293
6057
  const text = sourceNodeText(node);
5294
6058
  if (/\b(important notice|privacy notice|ofac advisory|terrorism risk insurance act|how to report a claim)\b/i.test(text)) {
5295
6059
  return false;
5296
6060
  }
5297
- return /^declarations?$/i.test(title) || /\bdeclarations?\s+(page|schedule|section)\b/i.test(text) || /^declarations?\b/i.test(cleanText(node.textExcerpt, ""));
6061
+ return /^declarations?$/i.test(title) || /\bdeclarations?\s+(page|schedule|section)\b/i.test(text) || /^declarations?\b/i.test(cleanText2(node.textExcerpt, ""));
5298
6062
  }
5299
6063
  function looksLikeDeclarationsContinuation(node) {
5300
6064
  const text = sourceNodeText(node);
@@ -5302,7 +6066,7 @@ function looksLikeDeclarationsContinuation(node) {
5302
6066
  }
5303
6067
  function looksLikePolicyFormStart(node) {
5304
6068
  const text = sourceNodeText(node);
5305
- const excerpt = cleanText(node.textExcerpt, "");
6069
+ const excerpt = cleanText2(node.textExcerpt, "");
5306
6070
  if (isAdministrativeNoticeNode(node) || looksLikeDeclarationsStart(node)) return false;
5307
6071
  return /\bpolicy form\b/i.test(node.title) || /^policy\s+form\b/i.test(excerpt) || /\btechnology errors?\s*&?\s*omissions\b/i.test(text) && /\bplease read this entire policy carefully\b/i.test(text) || /\bsection\s+[IVX0-9]+\s*[—-]\s*(insuring agreements?|definitions?|exclusions?|conditions?)\b/i.test(text) || /\bform\s+[A-Z]{2,}-[A-Z0-9-]+\s+\d{2}\s+\d{2}\b/i.test(text);
5308
6072
  }
@@ -5391,7 +6155,7 @@ function applySemanticPageGrouping(sourceTree) {
5391
6155
  return {
5392
6156
  ...nextNode,
5393
6157
  title: "Declarations",
5394
- description: cleanText([nextNode.description, "Declarations"].join(" "), "Declarations"),
6158
+ description: cleanText2([nextNode.description, "Declarations"].join(" "), "Declarations"),
5395
6159
  metadata: { ...nextNode.metadata, organizerRepair: "semantic_page_grouping" }
5396
6160
  };
5397
6161
  }
@@ -5399,7 +6163,7 @@ function applySemanticPageGrouping(sourceTree) {
5399
6163
  return {
5400
6164
  ...nextNode,
5401
6165
  title: "Policy Form",
5402
- description: cleanText([nextNode.description, "Policy Form"].join(" "), "Policy Form"),
6166
+ description: cleanText2([nextNode.description, "Policy Form"].join(" "), "Policy Form"),
5403
6167
  metadata: { ...nextNode.metadata, organizerRepair: "semantic_page_grouping" }
5404
6168
  };
5405
6169
  }
@@ -5667,7 +6431,7 @@ function isTitleBlockNode(node) {
5667
6431
  return metadataText(node, "organizer") === "title_block" || metadataText(node, "elementType") === "title" || metadataText(node, "sourceUnit") === "title";
5668
6432
  }
5669
6433
  function isRejectableSectionHeading(text, container) {
5670
- const normalized = cleanText(text, "");
6434
+ const normalized = cleanText2(text, "");
5671
6435
  if (!normalized) return true;
5672
6436
  if (normalized.length > 160) return true;
5673
6437
  if (/^page\s+\d+$/i.test(normalized)) return true;
@@ -5683,7 +6447,7 @@ function isRejectableSectionHeading(text, container) {
5683
6447
  }
5684
6448
  function sectionHeadingTitle(node, container) {
5685
6449
  if (!isTitleBlockNode(node)) return void 0;
5686
- const text = cleanText(node.title || node.textExcerpt, "");
6450
+ const text = cleanText2(node.title || node.textExcerpt, "");
5687
6451
  if (isRejectableSectionHeading(text, container)) return void 0;
5688
6452
  const words = text.split(/\s+/);
5689
6453
  if (words.length > 18) return void 0;
@@ -5757,7 +6521,7 @@ function applyTitleSectionHierarchy(sourceTree) {
5757
6521
  parentId: container.id,
5758
6522
  kind: sectionKindForTitle(heading),
5759
6523
  title: heading,
5760
- description: descriptionWithPages(cleanText([heading, "section"].join(" "), heading), [current, ...descendants]),
6524
+ description: descriptionWithPages(cleanText2([heading, "section"].join(" "), heading), [current, ...descendants]),
5761
6525
  metadata: {
5762
6526
  ...current.metadata,
5763
6527
  organizer: "title_section",
@@ -5805,7 +6569,7 @@ function applyEndorsementGrouping(sourceTree) {
5805
6569
  return {
5806
6570
  ...node,
5807
6571
  kind: "page",
5808
- title: node.pageStart ? `Page ${node.pageStart}` : cleanText(node.title, "Page"),
6572
+ title: node.pageStart ? `Page ${node.pageStart}` : cleanText2(node.title, "Page"),
5809
6573
  metadata: {
5810
6574
  ...node.metadata,
5811
6575
  organizerRepair: "demote_incidental_endorsement_reference"
@@ -5835,7 +6599,7 @@ function applyEndorsementGrouping(sourceTree) {
5835
6599
  ...node,
5836
6600
  kind: "page_group",
5837
6601
  title: "Endorsements",
5838
- description: descriptionWithPages(cleanText(node.description, "Endorsement forms grouped by source order"), byParent.get(node.id) ?? [node]),
6602
+ description: descriptionWithPages(cleanText2(node.description, "Endorsement forms grouped by source order"), byParent.get(node.id) ?? [node]),
5839
6603
  metadata: {
5840
6604
  ...node.metadata,
5841
6605
  sourceTreeVersion: "v3",
@@ -6014,7 +6778,7 @@ function nodesByParent(sourceTree) {
6014
6778
  }
6015
6779
  return byParent;
6016
6780
  }
6017
- function sourceNodeIdsBySpanId(sourceTree) {
6781
+ function sourceNodeIdsBySpanId2(sourceTree) {
6018
6782
  const bySpan = /* @__PURE__ */ new Map();
6019
6783
  for (const node of sourceTree) {
6020
6784
  for (const spanId of node.sourceSpanIds) {
@@ -6026,7 +6790,7 @@ function sourceNodeIdsBySpanId(sourceTree) {
6026
6790
  return bySpan;
6027
6791
  }
6028
6792
  function operationalEvidenceScore(span) {
6029
- const text = cleanText([
6793
+ const text = cleanText2([
6030
6794
  span.text,
6031
6795
  span.formNumber,
6032
6796
  span.sourceUnit,
@@ -6052,13 +6816,13 @@ function spanTableId(span) {
6052
6816
  return span.table?.tableId ?? span.metadata?.tableId;
6053
6817
  }
6054
6818
  function isTableCellSpan(span) {
6055
- return spanSourceUnit(span) === "table_cell";
6819
+ return spanSourceUnit2(span) === "table_cell";
6056
6820
  }
6057
6821
  function isOperationalEvidenceAnchor(span) {
6058
- const sourceUnit3 = spanSourceUnit(span);
6822
+ const sourceUnit3 = spanSourceUnit2(span);
6059
6823
  if (sourceUnit3 === "table_cell") return false;
6060
6824
  if (sourceUnit3 === "table" || sourceUnit3 === "table_row") return true;
6061
- const text = cleanText([span.text, span.formNumber].filter(Boolean).join(" "), "");
6825
+ const text = cleanText2([span.text, span.formNumber].filter(Boolean).join(" "), "");
6062
6826
  if (!text) return false;
6063
6827
  if (sourceUnit3 === "page") {
6064
6828
  return hasSubstantiveDeclarationsScheduleText(text) || /\b(declarations?|named insured|policy number|policy period|effective date|expiration date|premium|total due|producer|mailing address|mga|administrator|description of operations|nature of business|business description)\b/i.test(text);
@@ -6075,9 +6839,9 @@ function isOperationalEvidenceAnchor(span) {
6075
6839
  function operationalEvidencePages(sourceSpans) {
6076
6840
  const scores = /* @__PURE__ */ new Map();
6077
6841
  for (const span of sourceSpans) {
6078
- const page = spanPageStart(span);
6842
+ const page = spanPageStart2(span);
6079
6843
  if (typeof page !== "number") continue;
6080
- const text = cleanText([span.text, span.formNumber, spanSourceUnit(span)].filter(Boolean).join(" "), "");
6844
+ const text = cleanText2([span.text, span.formNumber, spanSourceUnit2(span)].filter(Boolean).join(" "), "");
6081
6845
  if (!text) continue;
6082
6846
  let score = Math.max(0, operationalEvidenceScore(span));
6083
6847
  if (/\bdeclarations?\s+(page|schedule)?\b/i.test(text)) score += 24;
@@ -6096,7 +6860,7 @@ function operationalEvidencePages(sourceSpans) {
6096
6860
  }
6097
6861
  function operationalProfileEvidence(sourceTree, sourceSpans) {
6098
6862
  const sorted = [...sourceSpans].sort(
6099
- (left, right) => (spanPageStart(left) ?? Number.MAX_SAFE_INTEGER) - (spanPageStart(right) ?? Number.MAX_SAFE_INTEGER) || (left.location?.charStart ?? Number.MAX_SAFE_INTEGER) - (right.location?.charStart ?? Number.MAX_SAFE_INTEGER) || left.id.localeCompare(right.id)
6863
+ (left, right) => (spanPageStart2(left) ?? Number.MAX_SAFE_INTEGER) - (spanPageStart2(right) ?? Number.MAX_SAFE_INTEGER) || (left.location?.charStart ?? Number.MAX_SAFE_INTEGER) - (right.location?.charStart ?? Number.MAX_SAFE_INTEGER) || left.id.localeCompare(right.id)
6100
6864
  );
6101
6865
  const selectedPages = operationalEvidencePages(sorted);
6102
6866
  const selected = /* @__PURE__ */ new Set();
@@ -6106,7 +6870,7 @@ function operationalProfileEvidence(sourceTree, sourceSpans) {
6106
6870
  const score = operationalEvidenceScore(span);
6107
6871
  if (score < 8) continue;
6108
6872
  if (!isOperationalEvidenceAnchor(span)) continue;
6109
- const page = spanPageStart(span);
6873
+ const page = spanPageStart2(span);
6110
6874
  if (selectedPages.size > 0 && typeof page === "number" && !selectedPages.has(page) && score < 30) continue;
6111
6875
  const tableId2 = spanTableId(span);
6112
6876
  if (tableId2 && !isTableCellSpan(span)) selectedTableIds.add(tableId2);
@@ -6114,9 +6878,9 @@ function operationalProfileEvidence(sourceTree, sourceSpans) {
6114
6878
  for (let offset = -neighborWindow; offset <= neighborWindow; offset += 1) {
6115
6879
  const neighborIndex = index + offset;
6116
6880
  const neighbor = sorted[neighborIndex];
6117
- if (!neighbor || spanPageStart(neighbor) !== page) continue;
6881
+ if (!neighbor || spanPageStart2(neighbor) !== page) continue;
6118
6882
  if (selectedPages.size > 0 && typeof page === "number" && !selectedPages.has(page) && operationalEvidenceScore(neighbor) < 30) continue;
6119
- const neighborText = cleanText(neighbor.text, "");
6883
+ const neighborText = cleanText2(neighbor.text, "");
6120
6884
  if (!neighborText || neighborText.length > 3e3) continue;
6121
6885
  selected.add(neighborIndex);
6122
6886
  }
@@ -6125,31 +6889,31 @@ function operationalProfileEvidence(sourceTree, sourceSpans) {
6125
6889
  sorted.forEach((span, index) => {
6126
6890
  const tableId2 = spanTableId(span);
6127
6891
  if (!tableId2 || !selectedTableIds.has(tableId2) || isTableCellSpan(span)) return;
6128
- const text = cleanText(span.text, "");
6892
+ const text = cleanText2(span.text, "");
6129
6893
  if (text && text.length <= 3e3) selected.add(index);
6130
6894
  });
6131
6895
  }
6132
- const nodeIdsBySpanId = sourceNodeIdsBySpanId(sourceTree);
6896
+ const nodeIdsBySpanId = sourceNodeIdsBySpanId2(sourceTree);
6133
6897
  const seenText = /* @__PURE__ */ new Set();
6134
6898
  const entries = [...selected].sort((left, right) => left - right).map((index) => sorted[index]).filter((span) => !isTableCellSpan(span)).flatMap((span) => {
6135
- const text = cleanText(span.text, "");
6899
+ const text = cleanText2(span.text, "");
6136
6900
  if (!text) return [];
6137
- const key = `${spanPageStart(span) ?? "na"}:${text.toLowerCase().slice(0, 240)}`;
6901
+ const key = `${spanPageStart2(span) ?? "na"}:${text.toLowerCase().slice(0, 240)}`;
6138
6902
  if (seenText.has(key)) return [];
6139
6903
  seenText.add(key);
6140
6904
  return [{
6141
6905
  sourceSpanId: span.id,
6142
6906
  sourceNodeIds: [...new Set(nodeIdsBySpanId.get(span.id) ?? [])].slice(0, 4),
6143
- pageStart: spanPageStart(span),
6144
- pageEnd: spanPageEnd(span),
6145
- sourceUnit: spanSourceUnit(span),
6907
+ pageStart: spanPageStart2(span),
6908
+ pageEnd: spanPageEnd2(span),
6909
+ sourceUnit: spanSourceUnit2(span),
6146
6910
  formNumber: span.formNumber,
6147
6911
  text: text.slice(0, span.sourceUnit === "page" ? 900 : 700)
6148
6912
  }];
6149
6913
  });
6150
6914
  const detailEntries = entries.filter((entry) => entry.sourceUnit !== "page");
6151
6915
  const pageEntries = entries.filter((entry) => entry.sourceUnit === "page");
6152
- return [...detailEntries.slice(0, 80), ...pageEntries.slice(0, 8)];
6916
+ return [...detailEntries, ...pageEntries];
6153
6917
  }
6154
6918
  function sourceTreeRootId(sourceTree) {
6155
6919
  return sourceTree.find((node) => node.kind === "document")?.id;
@@ -6169,6 +6933,9 @@ function emptyOperationalProfile() {
6169
6933
  linesOfBusiness: ["UN"],
6170
6934
  declarationFacts: [],
6171
6935
  coverages: [],
6936
+ coverageSchedules: [],
6937
+ premiumBreakdown: [],
6938
+ taxesAndFees: [],
6172
6939
  parties: [],
6173
6940
  endorsementSupport: [],
6174
6941
  sourceNodeIds: [],
@@ -6324,7 +7091,7 @@ function sourceBackedAddressFromFact(fact) {
6324
7091
  };
6325
7092
  }
6326
7093
  function normalizedEntityType(value) {
6327
- const normalized = cleanText(value, "").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
7094
+ const normalized = cleanText2(value, "").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
6328
7095
  if (normalized === "inc" || normalized === "incorporated" || normalized === "c_corporation" || normalized === "s_corporation") {
6329
7096
  return "corporation";
6330
7097
  }
@@ -6350,6 +7117,65 @@ function declarationFieldName(fact) {
6350
7117
  if (fact.field === "additionalNamedInsured") return "additionalNamedInsured";
6351
7118
  return fact.field;
6352
7119
  }
7120
+ function scheduleValueMap(item) {
7121
+ return new Map(item.values.map((value) => [
7122
+ value.label.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim(),
7123
+ value.value
7124
+ ]));
7125
+ }
7126
+ function firstScheduleValue(values, labels) {
7127
+ for (const label of labels) {
7128
+ const direct = values.get(label);
7129
+ if (direct) return direct;
7130
+ const match = [...values.entries()].find(([key]) => key.includes(label));
7131
+ if (match?.[1]) return match[1];
7132
+ }
7133
+ return void 0;
7134
+ }
7135
+ function positiveInteger2(value) {
7136
+ const parsed = Number.parseInt(value?.match(/\d+/)?.[0] ?? "", 10);
7137
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
7138
+ }
7139
+ function structuredVehicles(profile) {
7140
+ return (profile.coverageSchedules ?? []).filter((schedule) => schedule.kind === "vehicle").flatMap((schedule) => schedule.items).flatMap((item, index) => {
7141
+ const values = scheduleValueMap(item);
7142
+ const year = positiveInteger2(firstScheduleValue(values, ["year", "model year"]));
7143
+ const make = firstScheduleValue(values, ["make"]);
7144
+ const model = firstScheduleValue(values, ["model"]);
7145
+ const vin = firstScheduleValue(values, ["vin", "vehicle identification number"]);
7146
+ if (!year || !make || !model || !vin) return [];
7147
+ return [{
7148
+ number: positiveInteger2(item.label) ?? index + 1,
7149
+ year,
7150
+ make,
7151
+ model,
7152
+ vin
7153
+ }];
7154
+ });
7155
+ }
7156
+ function structuredLocations(profile) {
7157
+ return (profile.coverageSchedules ?? []).filter((schedule) => schedule.kind === "location" || schedule.kind === "property").flatMap((schedule) => schedule.items).flatMap((item, index) => {
7158
+ const values = scheduleValueMap(item);
7159
+ const street1 = firstScheduleValue(values, ["street 1", "street address", "address"]);
7160
+ const city = firstScheduleValue(values, ["city"]);
7161
+ const state = firstScheduleValue(values, ["state", "province"]);
7162
+ const zip = firstScheduleValue(values, ["zip", "postal code"]);
7163
+ if (!street1 || !city || !state || !zip) return [];
7164
+ return [{
7165
+ number: positiveInteger2(item.label) ?? index + 1,
7166
+ address: {
7167
+ street1,
7168
+ city,
7169
+ state,
7170
+ zip,
7171
+ country: firstScheduleValue(values, ["country"])
7172
+ },
7173
+ description: item.description,
7174
+ buildingValue: firstScheduleValue(values, ["building value", "building"]),
7175
+ contentsValue: firstScheduleValue(values, ["contents value", "contents"])
7176
+ }];
7177
+ });
7178
+ }
6353
7179
  function materializeDocument(params) {
6354
7180
  const profile = params.operationalProfile;
6355
7181
  const policyNumber = valueOf(profile, "policyNumber") ?? "Unknown";
@@ -6394,6 +7220,30 @@ function materializeDocument(params) {
6394
7220
  ...coverage.limits?.length ? coverage.limits.map((term) => `${term.label}: ${term.value}`) : [coverage.limit, coverage.deductible, coverage.premium]
6395
7221
  ].filter(Boolean).join(" | ")
6396
7222
  }));
7223
+ const coverageSchedules = (profile.coverageSchedules ?? []).map((schedule) => ({
7224
+ ...schedule,
7225
+ items: schedule.items.map((item) => ({ ...item }))
7226
+ }));
7227
+ const premiumBreakdown = (profile.premiumBreakdown ?? []).map((row) => ({
7228
+ line: row.line,
7229
+ amount: row.amount,
7230
+ amountValue: row.amountValue,
7231
+ documentNodeId: row.sourceNodeIds[0],
7232
+ sourceSpanIds: row.sourceSpanIds
7233
+ }));
7234
+ const taxesAndFees = (profile.taxesAndFees ?? []).map((row) => ({
7235
+ name: row.name,
7236
+ amount: row.amount,
7237
+ amountValue: row.amountValue,
7238
+ type: row.type,
7239
+ description: row.description,
7240
+ documentNodeId: row.sourceNodeIds[0],
7241
+ sourceSpanIds: row.sourceSpanIds
7242
+ }));
7243
+ const totalCost = valueOf(profile, "totalCost");
7244
+ const totalCostAmount = totalCost ? Number(totalCost.replace(/[^0-9.-]/g, "")) : void 0;
7245
+ const vehicles = structuredVehicles(profile);
7246
+ const locations = structuredLocations(profile);
6397
7247
  const documentOutline = sourceTreeToOutline(params.sourceTree);
6398
7248
  const documentMetadata = {
6399
7249
  sourceTreeVersion: "v3",
@@ -6426,6 +7276,10 @@ function materializeDocument(params) {
6426
7276
  security: carrier,
6427
7277
  insuredName,
6428
7278
  premium,
7279
+ ...premiumBreakdown.length > 0 ? { premiumBreakdown } : {},
7280
+ ...taxesAndFees.length > 0 ? { taxesAndFees } : {},
7281
+ ...totalCost ? { totalCost } : {},
7282
+ ...typeof totalCostAmount === "number" && Number.isFinite(totalCostAmount) ? { totalCostAmount } : {},
6429
7283
  insuredDba,
6430
7284
  insuredAddress,
6431
7285
  insuredEntityType,
@@ -6456,6 +7310,9 @@ function materializeDocument(params) {
6456
7310
  pageEnd: form.pageEnd
6457
7311
  })),
6458
7312
  coverages,
7313
+ ...coverageSchedules.length > 0 ? { coverageSchedules } : {},
7314
+ ...vehicles.length > 0 ? { vehicles } : {},
7315
+ ...locations.length > 0 ? { locations } : {},
6459
7316
  documentMetadata,
6460
7317
  documentOutline,
6461
7318
  declarations: {
@@ -6587,6 +7444,7 @@ async function runSourceTreeExtraction(params) {
6587
7444
  };
6588
7445
  const emptyProfile = emptyOperationalProfile();
6589
7446
  let operationalProfile = emptyProfile;
7447
+ let coverageRecovery = disabledCoverageRecoveryDiagnostics();
6590
7448
  try {
6591
7449
  const validNodeIds = new Set(sourceTree.map((node) => node.id));
6592
7450
  const validSpanIds = new Set(sourceSpans.map((span) => span.id));
@@ -6624,6 +7482,21 @@ async function runSourceTreeExtraction(params) {
6624
7482
  } catch (error) {
6625
7483
  warnings.push(`Operational profile model pass failed; coverage rows omitted (${error instanceof Error ? error.message : String(error)})`);
6626
7484
  }
7485
+ if (params.coverageRecovery?.enabled) {
7486
+ const recovery = await recoverOperationalProfileCoverage({
7487
+ sourceTree,
7488
+ sourceSpans,
7489
+ operationalProfile,
7490
+ generateObject: params.generateObject,
7491
+ providerOptions: params.providerOptions,
7492
+ resolveBudget: params.resolveBudget,
7493
+ trackUsage: localTrack,
7494
+ log: params.log
7495
+ });
7496
+ operationalProfile = recovery.operationalProfile;
7497
+ coverageRecovery = recovery.diagnostics;
7498
+ warnings.push(...coverageRecovery.warnings);
7499
+ }
6627
7500
  if (operationalProfile.coverages.length > 0) {
6628
7501
  try {
6629
7502
  const cleanup = await cleanupOperationalCoverageSchedules({
@@ -6656,6 +7529,7 @@ async function runSourceTreeExtraction(params) {
6656
7529
  sourceChunks: chunkSourceSpans(sourceSpans),
6657
7530
  formInventory: formHints,
6658
7531
  operationalProfile,
7532
+ coverageRecovery,
6659
7533
  document,
6660
7534
  chunks: [],
6661
7535
  warnings: [...warnings, ...operationalProfile.warnings],
@@ -6758,7 +7632,8 @@ function createExtractor(config) {
6758
7632
  providerOptions: activeProviderOptions,
6759
7633
  resolveBudget,
6760
7634
  trackUsage,
6761
- log
7635
+ log,
7636
+ coverageRecovery: options?.coverageRecovery
6762
7637
  });
6763
7638
  const sourceTreeFormInventory = v3.formInventory.flatMap((form) => {
6764
7639
  const formNumber = typeof form.formNumber === "string" ? form.formNumber.trim() : "";
@@ -6798,6 +7673,7 @@ function createExtractor(config) {
6798
7673
  sourceChunks: v3.sourceChunks,
6799
7674
  sourceTree: v3.sourceTree,
6800
7675
  operationalProfile: v3.operationalProfile,
7676
+ coverageRecovery: v3.coverageRecovery,
6801
7677
  warnings: v3.warnings,
6802
7678
  tokenUsage: v3.tokenUsage,
6803
7679
  usageReporting: v3.usageReporting,
@@ -8204,8 +9080,8 @@ Respond with JSON only:
8204
9080
  }`;
8205
9081
 
8206
9082
  // src/schemas/application.ts
8207
- var import_zod24 = require("zod");
8208
- var FieldTypeSchema = import_zod24.z.enum([
9083
+ var import_zod25 = require("zod");
9084
+ var FieldTypeSchema = import_zod25.z.enum([
8209
9085
  "text",
8210
9086
  "numeric",
8211
9087
  "currency",
@@ -8214,223 +9090,223 @@ var FieldTypeSchema = import_zod24.z.enum([
8214
9090
  "table",
8215
9091
  "declaration"
8216
9092
  ]);
8217
- var ApplicationFieldSchema = import_zod24.z.object({
8218
- id: import_zod24.z.string(),
8219
- label: import_zod24.z.string(),
8220
- section: import_zod24.z.string(),
9093
+ var ApplicationFieldSchema = import_zod25.z.object({
9094
+ id: import_zod25.z.string(),
9095
+ label: import_zod25.z.string(),
9096
+ section: import_zod25.z.string(),
8221
9097
  fieldType: FieldTypeSchema,
8222
- required: import_zod24.z.boolean(),
8223
- options: import_zod24.z.array(import_zod24.z.string()).optional(),
8224
- columns: import_zod24.z.array(import_zod24.z.string()).optional(),
8225
- requiresExplanationIfYes: import_zod24.z.boolean().optional(),
8226
- condition: import_zod24.z.object({
8227
- dependsOn: import_zod24.z.string(),
8228
- whenValue: import_zod24.z.string()
9098
+ required: import_zod25.z.boolean(),
9099
+ options: import_zod25.z.array(import_zod25.z.string()).optional(),
9100
+ columns: import_zod25.z.array(import_zod25.z.string()).optional(),
9101
+ requiresExplanationIfYes: import_zod25.z.boolean().optional(),
9102
+ condition: import_zod25.z.object({
9103
+ dependsOn: import_zod25.z.string(),
9104
+ whenValue: import_zod25.z.string()
8229
9105
  }).optional(),
8230
- value: import_zod24.z.string().optional(),
8231
- source: import_zod24.z.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
8232
- confidence: import_zod24.z.enum(["confirmed", "high", "medium", "low"]).optional(),
8233
- sourceSpanIds: import_zod24.z.array(import_zod24.z.string()).optional().describe("Stable source spans that support the field value or field anchor"),
8234
- userSourceSpanIds: import_zod24.z.array(import_zod24.z.string()).optional().describe("Message or attachment spans that support user-provided values"),
8235
- pageNumber: import_zod24.z.number().int().positive().optional().describe("Application page where the field label or anchor appears"),
8236
- fieldAnchorId: import_zod24.z.string().optional().describe("Stable field anchor ID derived from page, section, label, and form metadata"),
8237
- acroFormName: import_zod24.z.string().optional().describe("Native PDF AcroForm field name when available"),
8238
- validationStatus: import_zod24.z.enum(["valid", "needs_review", "unsupported", "missing"]).optional()
8239
- });
8240
- var ApplicationQuestionConditionSchema = import_zod24.z.object({
8241
- dependsOn: import_zod24.z.string(),
8242
- operator: import_zod24.z.enum(["equals", "not_equals", "in", "not_in", "exists"]).optional(),
8243
- value: import_zod24.z.string().optional(),
8244
- whenValue: import_zod24.z.string().optional(),
8245
- values: import_zod24.z.array(import_zod24.z.string()).optional()
8246
- });
8247
- var ApplicationRepeatSchema = import_zod24.z.object({
8248
- min: import_zod24.z.number().int().nonnegative().optional(),
8249
- max: import_zod24.z.number().int().positive().optional(),
8250
- label: import_zod24.z.string().optional()
8251
- });
8252
- var ApplicationQuestionNodeSchema = import_zod24.z.lazy(
8253
- () => import_zod24.z.object({
8254
- id: import_zod24.z.string(),
8255
- nodeType: import_zod24.z.enum(["group", "question", "repeat_group", "table"]),
8256
- fieldId: import_zod24.z.string().optional(),
8257
- fieldPath: import_zod24.z.string().optional(),
8258
- parentId: import_zod24.z.string().optional(),
8259
- order: import_zod24.z.number().int().nonnegative().optional(),
8260
- label: import_zod24.z.string(),
8261
- section: import_zod24.z.string().optional(),
9106
+ value: import_zod25.z.string().optional(),
9107
+ source: import_zod25.z.string().optional().describe("Where the value came from: auto-fill, user, lookup"),
9108
+ confidence: import_zod25.z.enum(["confirmed", "high", "medium", "low"]).optional(),
9109
+ sourceSpanIds: import_zod25.z.array(import_zod25.z.string()).optional().describe("Stable source spans that support the field value or field anchor"),
9110
+ userSourceSpanIds: import_zod25.z.array(import_zod25.z.string()).optional().describe("Message or attachment spans that support user-provided values"),
9111
+ pageNumber: import_zod25.z.number().int().positive().optional().describe("Application page where the field label or anchor appears"),
9112
+ fieldAnchorId: import_zod25.z.string().optional().describe("Stable field anchor ID derived from page, section, label, and form metadata"),
9113
+ acroFormName: import_zod25.z.string().optional().describe("Native PDF AcroForm field name when available"),
9114
+ validationStatus: import_zod25.z.enum(["valid", "needs_review", "unsupported", "missing"]).optional()
9115
+ });
9116
+ var ApplicationQuestionConditionSchema = import_zod25.z.object({
9117
+ dependsOn: import_zod25.z.string(),
9118
+ operator: import_zod25.z.enum(["equals", "not_equals", "in", "not_in", "exists"]).optional(),
9119
+ value: import_zod25.z.string().optional(),
9120
+ whenValue: import_zod25.z.string().optional(),
9121
+ values: import_zod25.z.array(import_zod25.z.string()).optional()
9122
+ });
9123
+ var ApplicationRepeatSchema = import_zod25.z.object({
9124
+ min: import_zod25.z.number().int().nonnegative().optional(),
9125
+ max: import_zod25.z.number().int().positive().optional(),
9126
+ label: import_zod25.z.string().optional()
9127
+ });
9128
+ var ApplicationQuestionNodeSchema = import_zod25.z.lazy(
9129
+ () => import_zod25.z.object({
9130
+ id: import_zod25.z.string(),
9131
+ nodeType: import_zod25.z.enum(["group", "question", "repeat_group", "table"]),
9132
+ fieldId: import_zod25.z.string().optional(),
9133
+ fieldPath: import_zod25.z.string().optional(),
9134
+ parentId: import_zod25.z.string().optional(),
9135
+ order: import_zod25.z.number().int().nonnegative().optional(),
9136
+ label: import_zod25.z.string(),
9137
+ section: import_zod25.z.string().optional(),
8262
9138
  fieldType: FieldTypeSchema.optional(),
8263
- required: import_zod24.z.boolean().optional(),
8264
- prompt: import_zod24.z.string().optional(),
8265
- options: import_zod24.z.array(import_zod24.z.string()).optional(),
8266
- columns: import_zod24.z.array(import_zod24.z.string()).optional(),
9139
+ required: import_zod25.z.boolean().optional(),
9140
+ prompt: import_zod25.z.string().optional(),
9141
+ options: import_zod25.z.array(import_zod25.z.string()).optional(),
9142
+ columns: import_zod25.z.array(import_zod25.z.string()).optional(),
8267
9143
  condition: ApplicationQuestionConditionSchema.optional(),
8268
9144
  repeat: ApplicationRepeatSchema.optional(),
8269
- children: import_zod24.z.array(ApplicationQuestionNodeSchema).optional()
9145
+ children: import_zod25.z.array(ApplicationQuestionNodeSchema).optional()
8270
9146
  })
8271
9147
  );
8272
- var ApplicationQuestionGraphSchema = import_zod24.z.object({
8273
- id: import_zod24.z.string(),
8274
- version: import_zod24.z.string(),
8275
- title: import_zod24.z.string().optional(),
8276
- applicationType: import_zod24.z.string().nullable().optional(),
8277
- source: import_zod24.z.enum(["pdf", "manual", "imported", "generated"]).default("generated"),
8278
- rootNodeIds: import_zod24.z.array(import_zod24.z.string()).optional(),
8279
- nodes: import_zod24.z.array(ApplicationQuestionNodeSchema)
8280
- });
8281
- var ApplicationTemplateSchema = import_zod24.z.object({
8282
- id: import_zod24.z.string(),
8283
- version: import_zod24.z.string(),
8284
- title: import_zod24.z.string(),
8285
- applicationType: import_zod24.z.string().nullable().optional(),
9148
+ var ApplicationQuestionGraphSchema = import_zod25.z.object({
9149
+ id: import_zod25.z.string(),
9150
+ version: import_zod25.z.string(),
9151
+ title: import_zod25.z.string().optional(),
9152
+ applicationType: import_zod25.z.string().nullable().optional(),
9153
+ source: import_zod25.z.enum(["pdf", "manual", "imported", "generated"]).default("generated"),
9154
+ rootNodeIds: import_zod25.z.array(import_zod25.z.string()).optional(),
9155
+ nodes: import_zod25.z.array(ApplicationQuestionNodeSchema)
9156
+ });
9157
+ var ApplicationTemplateSchema = import_zod25.z.object({
9158
+ id: import_zod25.z.string(),
9159
+ version: import_zod25.z.string(),
9160
+ title: import_zod25.z.string(),
9161
+ applicationType: import_zod25.z.string().nullable().optional(),
8286
9162
  questionGraph: ApplicationQuestionGraphSchema,
8287
- fields: import_zod24.z.array(ApplicationFieldSchema).optional()
8288
- });
8289
- var ApplicationClassifyResultSchema = import_zod24.z.object({
8290
- isApplication: import_zod24.z.boolean(),
8291
- confidence: import_zod24.z.number().min(0).max(1),
8292
- applicationType: import_zod24.z.string().nullable()
8293
- });
8294
- var FieldExtractionResultSchema = import_zod24.z.object({
8295
- fields: import_zod24.z.array(ApplicationFieldSchema)
8296
- });
8297
- var AutoFillMatchSchema = import_zod24.z.object({
8298
- fieldId: import_zod24.z.string(),
8299
- value: import_zod24.z.string(),
8300
- confidence: import_zod24.z.enum(["confirmed"]),
8301
- contextKey: import_zod24.z.string()
8302
- });
8303
- var AutoFillResultSchema = import_zod24.z.object({
8304
- matches: import_zod24.z.array(AutoFillMatchSchema)
8305
- });
8306
- var QuestionBatchResultSchema = import_zod24.z.object({
8307
- batches: import_zod24.z.array(import_zod24.z.array(import_zod24.z.string()).describe("Array of field IDs in this batch"))
8308
- });
8309
- var LookupRequestSchema = import_zod24.z.object({
8310
- type: import_zod24.z.string().describe("Type of lookup: 'records', 'website', 'policy'"),
8311
- description: import_zod24.z.string(),
8312
- url: import_zod24.z.string().optional(),
8313
- targetFieldIds: import_zod24.z.array(import_zod24.z.string())
8314
- });
8315
- var ReplyIntentSchema = import_zod24.z.object({
8316
- primaryIntent: import_zod24.z.enum(["answers_only", "question", "lookup_request", "mixed"]),
8317
- hasAnswers: import_zod24.z.boolean(),
8318
- questionText: import_zod24.z.string().optional(),
8319
- questionFieldIds: import_zod24.z.array(import_zod24.z.string()).optional(),
8320
- lookupRequests: import_zod24.z.array(LookupRequestSchema).optional()
8321
- });
8322
- var ParsedAnswerSchema = import_zod24.z.object({
8323
- fieldId: import_zod24.z.string(),
8324
- value: import_zod24.z.string(),
8325
- explanation: import_zod24.z.string().optional()
8326
- });
8327
- var AnswerParsingResultSchema = import_zod24.z.object({
8328
- answers: import_zod24.z.array(ParsedAnswerSchema),
8329
- unanswered: import_zod24.z.array(import_zod24.z.string()).describe("Field IDs that were not answered")
8330
- });
8331
- var LookupFillSchema = import_zod24.z.object({
8332
- fieldId: import_zod24.z.string(),
8333
- value: import_zod24.z.string(),
8334
- source: import_zod24.z.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'"),
8335
- sourceSpanIds: import_zod24.z.array(import_zod24.z.string()).optional()
9163
+ fields: import_zod25.z.array(ApplicationFieldSchema).optional()
8336
9164
  });
8337
- var LookupFillResultSchema = import_zod24.z.object({
8338
- fills: import_zod24.z.array(LookupFillSchema),
8339
- unfillable: import_zod24.z.array(import_zod24.z.string()),
8340
- explanation: import_zod24.z.string().optional()
8341
- });
8342
- var FlatPdfPlacementSchema = import_zod24.z.object({
8343
- fieldId: import_zod24.z.string(),
8344
- page: import_zod24.z.number(),
8345
- x: import_zod24.z.number().describe("Percentage from left edge (0-100)"),
8346
- y: import_zod24.z.number().describe("Percentage from top edge (0-100)"),
8347
- text: import_zod24.z.string(),
8348
- fontSize: import_zod24.z.number().optional(),
8349
- isCheckmark: import_zod24.z.boolean().optional()
8350
- });
8351
- var AcroFormMappingSchema = import_zod24.z.object({
8352
- fieldId: import_zod24.z.string(),
8353
- acroFormName: import_zod24.z.string(),
8354
- value: import_zod24.z.string()
8355
- });
8356
- var QualityGateStatusSchema = import_zod24.z.enum(["passed", "warning", "failed"]);
8357
- var QualitySeveritySchema = import_zod24.z.enum(["info", "warning", "blocking"]);
8358
- var ApplicationQualityIssueSchema = import_zod24.z.object({
8359
- code: import_zod24.z.string(),
9165
+ var ApplicationClassifyResultSchema = import_zod25.z.object({
9166
+ isApplication: import_zod25.z.boolean(),
9167
+ confidence: import_zod25.z.number().min(0).max(1),
9168
+ applicationType: import_zod25.z.string().nullable()
9169
+ });
9170
+ var FieldExtractionResultSchema = import_zod25.z.object({
9171
+ fields: import_zod25.z.array(ApplicationFieldSchema)
9172
+ });
9173
+ var AutoFillMatchSchema = import_zod25.z.object({
9174
+ fieldId: import_zod25.z.string(),
9175
+ value: import_zod25.z.string(),
9176
+ confidence: import_zod25.z.enum(["confirmed"]),
9177
+ contextKey: import_zod25.z.string()
9178
+ });
9179
+ var AutoFillResultSchema = import_zod25.z.object({
9180
+ matches: import_zod25.z.array(AutoFillMatchSchema)
9181
+ });
9182
+ var QuestionBatchResultSchema = import_zod25.z.object({
9183
+ batches: import_zod25.z.array(import_zod25.z.array(import_zod25.z.string()).describe("Array of field IDs in this batch"))
9184
+ });
9185
+ var LookupRequestSchema = import_zod25.z.object({
9186
+ type: import_zod25.z.string().describe("Type of lookup: 'records', 'website', 'policy'"),
9187
+ description: import_zod25.z.string(),
9188
+ url: import_zod25.z.string().optional(),
9189
+ targetFieldIds: import_zod25.z.array(import_zod25.z.string())
9190
+ });
9191
+ var ReplyIntentSchema = import_zod25.z.object({
9192
+ primaryIntent: import_zod25.z.enum(["answers_only", "question", "lookup_request", "mixed"]),
9193
+ hasAnswers: import_zod25.z.boolean(),
9194
+ questionText: import_zod25.z.string().optional(),
9195
+ questionFieldIds: import_zod25.z.array(import_zod25.z.string()).optional(),
9196
+ lookupRequests: import_zod25.z.array(LookupRequestSchema).optional()
9197
+ });
9198
+ var ParsedAnswerSchema = import_zod25.z.object({
9199
+ fieldId: import_zod25.z.string(),
9200
+ value: import_zod25.z.string(),
9201
+ explanation: import_zod25.z.string().optional()
9202
+ });
9203
+ var AnswerParsingResultSchema = import_zod25.z.object({
9204
+ answers: import_zod25.z.array(ParsedAnswerSchema),
9205
+ unanswered: import_zod25.z.array(import_zod25.z.string()).describe("Field IDs that were not answered")
9206
+ });
9207
+ var LookupFillSchema = import_zod25.z.object({
9208
+ fieldId: import_zod25.z.string(),
9209
+ value: import_zod25.z.string(),
9210
+ source: import_zod25.z.string().describe("Specific citable reference, e.g. 'GL Policy #POL-12345 (Hartford)'"),
9211
+ sourceSpanIds: import_zod25.z.array(import_zod25.z.string()).optional()
9212
+ });
9213
+ var LookupFillResultSchema = import_zod25.z.object({
9214
+ fills: import_zod25.z.array(LookupFillSchema),
9215
+ unfillable: import_zod25.z.array(import_zod25.z.string()),
9216
+ explanation: import_zod25.z.string().optional()
9217
+ });
9218
+ var FlatPdfPlacementSchema = import_zod25.z.object({
9219
+ fieldId: import_zod25.z.string(),
9220
+ page: import_zod25.z.number(),
9221
+ x: import_zod25.z.number().describe("Percentage from left edge (0-100)"),
9222
+ y: import_zod25.z.number().describe("Percentage from top edge (0-100)"),
9223
+ text: import_zod25.z.string(),
9224
+ fontSize: import_zod25.z.number().optional(),
9225
+ isCheckmark: import_zod25.z.boolean().optional()
9226
+ });
9227
+ var AcroFormMappingSchema = import_zod25.z.object({
9228
+ fieldId: import_zod25.z.string(),
9229
+ acroFormName: import_zod25.z.string(),
9230
+ value: import_zod25.z.string()
9231
+ });
9232
+ var QualityGateStatusSchema = import_zod25.z.enum(["passed", "warning", "failed"]);
9233
+ var QualitySeveritySchema = import_zod25.z.enum(["info", "warning", "blocking"]);
9234
+ var ApplicationQualityIssueSchema = import_zod25.z.object({
9235
+ code: import_zod25.z.string(),
8360
9236
  severity: QualitySeveritySchema,
8361
- message: import_zod24.z.string(),
8362
- fieldId: import_zod24.z.string().optional()
9237
+ message: import_zod25.z.string(),
9238
+ fieldId: import_zod25.z.string().optional()
8363
9239
  });
8364
- var ApplicationQualityRoundSchema = import_zod24.z.object({
8365
- round: import_zod24.z.number(),
8366
- kind: import_zod24.z.string(),
9240
+ var ApplicationQualityRoundSchema = import_zod25.z.object({
9241
+ round: import_zod25.z.number(),
9242
+ kind: import_zod25.z.string(),
8367
9243
  status: QualityGateStatusSchema,
8368
- summary: import_zod24.z.string().optional()
9244
+ summary: import_zod25.z.string().optional()
8369
9245
  });
8370
- var ApplicationQualityArtifactSchema = import_zod24.z.object({
8371
- kind: import_zod24.z.string(),
8372
- label: import_zod24.z.string().optional(),
8373
- itemCount: import_zod24.z.number().optional()
9246
+ var ApplicationQualityArtifactSchema = import_zod25.z.object({
9247
+ kind: import_zod25.z.string(),
9248
+ label: import_zod25.z.string().optional(),
9249
+ itemCount: import_zod25.z.number().optional()
8374
9250
  });
8375
- var ApplicationEmailReviewSchema = import_zod24.z.object({
8376
- issues: import_zod24.z.array(ApplicationQualityIssueSchema),
9251
+ var ApplicationEmailReviewSchema = import_zod25.z.object({
9252
+ issues: import_zod25.z.array(ApplicationQualityIssueSchema),
8377
9253
  qualityGateStatus: QualityGateStatusSchema
8378
9254
  });
8379
- var ApplicationQualityReportSchema = import_zod24.z.object({
8380
- issues: import_zod24.z.array(ApplicationQualityIssueSchema),
8381
- rounds: import_zod24.z.array(ApplicationQualityRoundSchema).optional(),
8382
- artifacts: import_zod24.z.array(ApplicationQualityArtifactSchema).optional(),
9255
+ var ApplicationQualityReportSchema = import_zod25.z.object({
9256
+ issues: import_zod25.z.array(ApplicationQualityIssueSchema),
9257
+ rounds: import_zod25.z.array(ApplicationQualityRoundSchema).optional(),
9258
+ artifacts: import_zod25.z.array(ApplicationQualityArtifactSchema).optional(),
8383
9259
  emailReview: ApplicationEmailReviewSchema.optional(),
8384
9260
  qualityGateStatus: QualityGateStatusSchema
8385
9261
  });
8386
- var ApplicationContextProposalSchema = import_zod24.z.object({
8387
- id: import_zod24.z.string(),
8388
- fieldId: import_zod24.z.string().optional(),
8389
- key: import_zod24.z.string(),
8390
- value: import_zod24.z.string(),
8391
- category: import_zod24.z.string(),
8392
- source: import_zod24.z.enum(["application", "user", "lookup", "policy", "email", "chat", "imessage", "mcp"]),
8393
- confidence: import_zod24.z.enum(["confirmed", "high", "medium", "low"]),
8394
- sourceSpanIds: import_zod24.z.array(import_zod24.z.string()).optional(),
8395
- userSourceSpanIds: import_zod24.z.array(import_zod24.z.string()).optional()
8396
- });
8397
- var ApplicationPacketAnswerSchema = import_zod24.z.object({
8398
- fieldId: import_zod24.z.string(),
8399
- label: import_zod24.z.string(),
8400
- section: import_zod24.z.string(),
8401
- value: import_zod24.z.string(),
8402
- source: import_zod24.z.string(),
8403
- confidence: import_zod24.z.enum(["confirmed", "high", "medium", "low"]).optional(),
8404
- sourceSpanIds: import_zod24.z.array(import_zod24.z.string()).optional(),
8405
- userSourceSpanIds: import_zod24.z.array(import_zod24.z.string()).optional()
8406
- });
8407
- var ApplicationPacketSchema = import_zod24.z.object({
8408
- id: import_zod24.z.string(),
8409
- applicationId: import_zod24.z.string(),
8410
- title: import_zod24.z.string(),
8411
- status: import_zod24.z.enum(["draft", "broker_ready", "submitted"]),
8412
- answers: import_zod24.z.array(ApplicationPacketAnswerSchema),
8413
- missingFieldIds: import_zod24.z.array(import_zod24.z.string()),
9262
+ var ApplicationContextProposalSchema = import_zod25.z.object({
9263
+ id: import_zod25.z.string(),
9264
+ fieldId: import_zod25.z.string().optional(),
9265
+ key: import_zod25.z.string(),
9266
+ value: import_zod25.z.string(),
9267
+ category: import_zod25.z.string(),
9268
+ source: import_zod25.z.enum(["application", "user", "lookup", "policy", "email", "chat", "imessage", "mcp"]),
9269
+ confidence: import_zod25.z.enum(["confirmed", "high", "medium", "low"]),
9270
+ sourceSpanIds: import_zod25.z.array(import_zod25.z.string()).optional(),
9271
+ userSourceSpanIds: import_zod25.z.array(import_zod25.z.string()).optional()
9272
+ });
9273
+ var ApplicationPacketAnswerSchema = import_zod25.z.object({
9274
+ fieldId: import_zod25.z.string(),
9275
+ label: import_zod25.z.string(),
9276
+ section: import_zod25.z.string(),
9277
+ value: import_zod25.z.string(),
9278
+ source: import_zod25.z.string(),
9279
+ confidence: import_zod25.z.enum(["confirmed", "high", "medium", "low"]).optional(),
9280
+ sourceSpanIds: import_zod25.z.array(import_zod25.z.string()).optional(),
9281
+ userSourceSpanIds: import_zod25.z.array(import_zod25.z.string()).optional()
9282
+ });
9283
+ var ApplicationPacketSchema = import_zod25.z.object({
9284
+ id: import_zod25.z.string(),
9285
+ applicationId: import_zod25.z.string(),
9286
+ title: import_zod25.z.string(),
9287
+ status: import_zod25.z.enum(["draft", "broker_ready", "submitted"]),
9288
+ answers: import_zod25.z.array(ApplicationPacketAnswerSchema),
9289
+ missingFieldIds: import_zod25.z.array(import_zod25.z.string()),
8414
9290
  qualityReport: ApplicationQualityReportSchema,
8415
- submissionNotes: import_zod24.z.string().optional(),
8416
- createdAt: import_zod24.z.number()
8417
- });
8418
- var ApplicationStateSchema = import_zod24.z.object({
8419
- id: import_zod24.z.string(),
8420
- pdfBase64: import_zod24.z.string().optional().describe("Original PDF, omitted after extraction"),
8421
- templateId: import_zod24.z.string().optional(),
8422
- templateVersion: import_zod24.z.string().optional(),
9291
+ submissionNotes: import_zod25.z.string().optional(),
9292
+ createdAt: import_zod25.z.number()
9293
+ });
9294
+ var ApplicationStateSchema = import_zod25.z.object({
9295
+ id: import_zod25.z.string(),
9296
+ pdfBase64: import_zod25.z.string().optional().describe("Original PDF, omitted after extraction"),
9297
+ templateId: import_zod25.z.string().optional(),
9298
+ templateVersion: import_zod25.z.string().optional(),
8423
9299
  templateSnapshot: ApplicationTemplateSchema.optional(),
8424
- title: import_zod24.z.string().optional(),
8425
- applicationType: import_zod24.z.string().nullable().optional(),
9300
+ title: import_zod25.z.string().optional(),
9301
+ applicationType: import_zod25.z.string().nullable().optional(),
8426
9302
  questionGraph: ApplicationQuestionGraphSchema.optional(),
8427
- fields: import_zod24.z.array(ApplicationFieldSchema),
8428
- batches: import_zod24.z.array(import_zod24.z.array(import_zod24.z.string())).optional(),
8429
- currentBatchIndex: import_zod24.z.number().default(0),
8430
- contextProposals: import_zod24.z.array(ApplicationContextProposalSchema).optional(),
9303
+ fields: import_zod25.z.array(ApplicationFieldSchema),
9304
+ batches: import_zod25.z.array(import_zod25.z.array(import_zod25.z.string())).optional(),
9305
+ currentBatchIndex: import_zod25.z.number().default(0),
9306
+ contextProposals: import_zod25.z.array(ApplicationContextProposalSchema).optional(),
8431
9307
  packet: ApplicationPacketSchema.optional(),
8432
9308
  qualityReport: ApplicationQualityReportSchema.optional(),
8433
- status: import_zod24.z.enum([
9309
+ status: import_zod25.z.enum([
8434
9310
  "classifying",
8435
9311
  "extracting",
8436
9312
  "auto_filling",
@@ -8444,8 +9320,8 @@ var ApplicationStateSchema = import_zod24.z.object({
8444
9320
  "cancelled",
8445
9321
  "complete"
8446
9322
  ]),
8447
- createdAt: import_zod24.z.number(),
8448
- updatedAt: import_zod24.z.number()
9323
+ createdAt: import_zod25.z.number(),
9324
+ updatedAt: import_zod25.z.number()
8449
9325
  });
8450
9326
 
8451
9327
  // src/application/agents/classifier.ts
@@ -10179,106 +11055,106 @@ Respond with the final answer, deduplicated citations array, overall confidence
10179
11055
  }
10180
11056
 
10181
11057
  // src/schemas/query.ts
10182
- var import_zod25 = require("zod");
10183
- var QueryIntentSchema = import_zod25.z.enum([
11058
+ var import_zod26 = require("zod");
11059
+ var QueryIntentSchema = import_zod26.z.enum([
10184
11060
  "policy_question",
10185
11061
  "coverage_comparison",
10186
11062
  "document_search",
10187
11063
  "claims_inquiry",
10188
11064
  "general_knowledge"
10189
11065
  ]);
10190
- var QueryAttachmentKindSchema = import_zod25.z.enum(["image", "pdf", "text"]);
10191
- var QueryAttachmentSchema = import_zod25.z.object({
10192
- id: import_zod25.z.string().optional().describe("Optional stable attachment ID from the caller"),
11066
+ var QueryAttachmentKindSchema = import_zod26.z.enum(["image", "pdf", "text"]);
11067
+ var QueryAttachmentSchema = import_zod26.z.object({
11068
+ id: import_zod26.z.string().optional().describe("Optional stable attachment ID from the caller"),
10193
11069
  kind: QueryAttachmentKindSchema,
10194
- name: import_zod25.z.string().optional().describe("Original filename or user-facing label"),
10195
- mimeType: import_zod25.z.string().optional().describe("MIME type such as image/jpeg or application/pdf"),
10196
- base64: import_zod25.z.string().optional().describe("Base64-encoded file content for image/pdf attachments"),
10197
- text: import_zod25.z.string().optional().describe("Plain-text attachment content when available"),
10198
- description: import_zod25.z.string().optional().describe("Caller-provided description of the attachment")
11070
+ name: import_zod26.z.string().optional().describe("Original filename or user-facing label"),
11071
+ mimeType: import_zod26.z.string().optional().describe("MIME type such as image/jpeg or application/pdf"),
11072
+ base64: import_zod26.z.string().optional().describe("Base64-encoded file content for image/pdf attachments"),
11073
+ text: import_zod26.z.string().optional().describe("Plain-text attachment content when available"),
11074
+ description: import_zod26.z.string().optional().describe("Caller-provided description of the attachment")
10199
11075
  });
10200
- var QueryRetrievalModeSchema = import_zod25.z.enum([
11076
+ var QueryRetrievalModeSchema = import_zod26.z.enum([
10201
11077
  "graph_only",
10202
11078
  "source_rag",
10203
11079
  "long_context",
10204
11080
  "hybrid"
10205
11081
  ]);
10206
- var SubQuestionSchema = import_zod25.z.object({
10207
- question: import_zod25.z.string().describe("Atomic sub-question to retrieve and answer independently"),
11082
+ var SubQuestionSchema = import_zod26.z.object({
11083
+ question: import_zod26.z.string().describe("Atomic sub-question to retrieve and answer independently"),
10208
11084
  intent: QueryIntentSchema,
10209
- chunkTypes: import_zod25.z.array(import_zod25.z.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
10210
- documentFilters: import_zod25.z.object({
10211
- type: import_zod25.z.enum(["policy", "quote"]).optional(),
10212
- carrier: import_zod25.z.string().optional(),
10213
- insuredName: import_zod25.z.string().optional(),
10214
- policyNumber: import_zod25.z.string().optional(),
10215
- quoteNumber: import_zod25.z.string().optional(),
10216
- linesOfBusiness: import_zod25.z.array(AcordLobCodeSchema).optional().describe("Filter by ACORD line of business code (e.g. HOME, AUTOP, DISAB) to avoid mixing up similar policies")
11085
+ chunkTypes: import_zod26.z.array(import_zod26.z.string()).optional().describe("Chunk types to filter retrieval (e.g. coverage, endorsement, declaration)"),
11086
+ documentFilters: import_zod26.z.object({
11087
+ type: import_zod26.z.enum(["policy", "quote"]).optional(),
11088
+ carrier: import_zod26.z.string().optional(),
11089
+ insuredName: import_zod26.z.string().optional(),
11090
+ policyNumber: import_zod26.z.string().optional(),
11091
+ quoteNumber: import_zod26.z.string().optional(),
11092
+ linesOfBusiness: import_zod26.z.array(AcordLobCodeSchema).optional().describe("Filter by ACORD line of business code (e.g. HOME, AUTOP, DISAB) to avoid mixing up similar policies")
10217
11093
  }).optional().describe("Structured filters to narrow document lookup")
10218
11094
  });
10219
- var QueryClassifyResultSchema = import_zod25.z.object({
11095
+ var QueryClassifyResultSchema = import_zod26.z.object({
10220
11096
  intent: QueryIntentSchema,
10221
- subQuestions: import_zod25.z.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
10222
- requiresDocumentLookup: import_zod25.z.boolean().describe("Whether structured document lookup is needed"),
10223
- requiresChunkSearch: import_zod25.z.boolean().describe("Whether semantic chunk search is needed"),
10224
- requiresConversationHistory: import_zod25.z.boolean().describe("Whether conversation history is relevant"),
11097
+ subQuestions: import_zod26.z.array(SubQuestionSchema).min(1).describe("Decomposed atomic sub-questions"),
11098
+ requiresDocumentLookup: import_zod26.z.boolean().describe("Whether structured document lookup is needed"),
11099
+ requiresChunkSearch: import_zod26.z.boolean().describe("Whether semantic chunk search is needed"),
11100
+ requiresConversationHistory: import_zod26.z.boolean().describe("Whether conversation history is relevant"),
10225
11101
  retrievalMode: QueryRetrievalModeSchema.optional().describe("Preferred retrieval strategy for the query when source-span retrieval is available")
10226
11102
  });
10227
- var EvidenceItemSchema = import_zod25.z.object({
10228
- source: import_zod25.z.enum(["chunk", "document", "conversation", "attachment", "source_span", "source_node"]),
10229
- chunkId: import_zod25.z.string().optional(),
10230
- sourceNodeId: import_zod25.z.string().optional(),
10231
- sourceSpanId: import_zod25.z.string().optional(),
10232
- documentId: import_zod25.z.string().optional(),
10233
- turnId: import_zod25.z.string().optional(),
10234
- attachmentId: import_zod25.z.string().optional(),
10235
- text: import_zod25.z.string().describe("Text excerpt from the source"),
10236
- relevance: import_zod25.z.number().min(0).max(1),
11103
+ var EvidenceItemSchema = import_zod26.z.object({
11104
+ source: import_zod26.z.enum(["chunk", "document", "conversation", "attachment", "source_span", "source_node"]),
11105
+ chunkId: import_zod26.z.string().optional(),
11106
+ sourceNodeId: import_zod26.z.string().optional(),
11107
+ sourceSpanId: import_zod26.z.string().optional(),
11108
+ documentId: import_zod26.z.string().optional(),
11109
+ turnId: import_zod26.z.string().optional(),
11110
+ attachmentId: import_zod26.z.string().optional(),
11111
+ text: import_zod26.z.string().describe("Text excerpt from the source"),
11112
+ relevance: import_zod26.z.number().min(0).max(1),
10237
11113
  retrievalMode: QueryRetrievalModeSchema.optional(),
10238
11114
  sourceLocation: SourceSpanLocationSchema.optional(),
10239
- metadata: import_zod25.z.array(import_zod25.z.object({ key: import_zod25.z.string(), value: import_zod25.z.string() })).optional()
10240
- });
10241
- var AttachmentInterpretationSchema = import_zod25.z.object({
10242
- summary: import_zod25.z.string().describe("Concise summary of what the attachment shows or contains"),
10243
- extractedFacts: import_zod25.z.array(import_zod25.z.string()).describe("Specific observable or document facts grounded in the attachment"),
10244
- recommendedFocus: import_zod25.z.array(import_zod25.z.string()).describe("Important details to incorporate when answering follow-up questions"),
10245
- confidence: import_zod25.z.number().min(0).max(1)
10246
- });
10247
- var RetrievalResultSchema = import_zod25.z.object({
10248
- subQuestion: import_zod25.z.string(),
10249
- evidence: import_zod25.z.array(EvidenceItemSchema)
10250
- });
10251
- var CitationSchema = import_zod25.z.object({
10252
- index: import_zod25.z.number().describe("Citation number [1], [2], etc."),
10253
- chunkId: import_zod25.z.string().optional().describe("Source chunk ID, e.g. doc-123:coverage:2"),
10254
- sourceNodeId: import_zod25.z.string().optional().describe("Source tree node ID when available"),
10255
- sourceSpanId: import_zod25.z.string().optional().describe("Precise source span ID when available"),
10256
- documentId: import_zod25.z.string(),
10257
- documentType: import_zod25.z.enum(["policy", "quote"]).optional(),
10258
- field: import_zod25.z.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
10259
- quote: import_zod25.z.string().describe("Exact text from source that supports the claim"),
10260
- relevance: import_zod25.z.number().min(0).max(1),
11115
+ metadata: import_zod26.z.array(import_zod26.z.object({ key: import_zod26.z.string(), value: import_zod26.z.string() })).optional()
11116
+ });
11117
+ var AttachmentInterpretationSchema = import_zod26.z.object({
11118
+ summary: import_zod26.z.string().describe("Concise summary of what the attachment shows or contains"),
11119
+ extractedFacts: import_zod26.z.array(import_zod26.z.string()).describe("Specific observable or document facts grounded in the attachment"),
11120
+ recommendedFocus: import_zod26.z.array(import_zod26.z.string()).describe("Important details to incorporate when answering follow-up questions"),
11121
+ confidence: import_zod26.z.number().min(0).max(1)
11122
+ });
11123
+ var RetrievalResultSchema = import_zod26.z.object({
11124
+ subQuestion: import_zod26.z.string(),
11125
+ evidence: import_zod26.z.array(EvidenceItemSchema)
11126
+ });
11127
+ var CitationSchema = import_zod26.z.object({
11128
+ index: import_zod26.z.number().describe("Citation number [1], [2], etc."),
11129
+ chunkId: import_zod26.z.string().optional().describe("Source chunk ID, e.g. doc-123:coverage:2"),
11130
+ sourceNodeId: import_zod26.z.string().optional().describe("Source tree node ID when available"),
11131
+ sourceSpanId: import_zod26.z.string().optional().describe("Precise source span ID when available"),
11132
+ documentId: import_zod26.z.string(),
11133
+ documentType: import_zod26.z.enum(["policy", "quote"]).optional(),
11134
+ field: import_zod26.z.string().optional().describe("Specific field path, e.g. coverages[0].deductible"),
11135
+ quote: import_zod26.z.string().describe("Exact text from source that supports the claim"),
11136
+ relevance: import_zod26.z.number().min(0).max(1),
10261
11137
  retrievalMode: QueryRetrievalModeSchema.optional(),
10262
11138
  sourceLocation: SourceSpanLocationSchema.optional()
10263
11139
  });
10264
- var SubAnswerSchema = import_zod25.z.object({
10265
- subQuestion: import_zod25.z.string(),
10266
- answer: import_zod25.z.string(),
10267
- citations: import_zod25.z.array(CitationSchema),
10268
- confidence: import_zod25.z.number().min(0).max(1),
10269
- needsMoreContext: import_zod25.z.boolean().describe("True if evidence was insufficient to answer fully")
10270
- });
10271
- var VerifyResultSchema = import_zod25.z.object({
10272
- approved: import_zod25.z.boolean().describe("Whether all sub-answers are adequately grounded"),
10273
- issues: import_zod25.z.array(import_zod25.z.string()).describe("Specific grounding or consistency issues found"),
10274
- retrySubQuestions: import_zod25.z.array(import_zod25.z.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
10275
- });
10276
- var QueryResultSchema = import_zod25.z.object({
10277
- answer: import_zod25.z.string(),
10278
- citations: import_zod25.z.array(CitationSchema),
11140
+ var SubAnswerSchema = import_zod26.z.object({
11141
+ subQuestion: import_zod26.z.string(),
11142
+ answer: import_zod26.z.string(),
11143
+ citations: import_zod26.z.array(CitationSchema),
11144
+ confidence: import_zod26.z.number().min(0).max(1),
11145
+ needsMoreContext: import_zod26.z.boolean().describe("True if evidence was insufficient to answer fully")
11146
+ });
11147
+ var VerifyResultSchema = import_zod26.z.object({
11148
+ approved: import_zod26.z.boolean().describe("Whether all sub-answers are adequately grounded"),
11149
+ issues: import_zod26.z.array(import_zod26.z.string()).describe("Specific grounding or consistency issues found"),
11150
+ retrySubQuestions: import_zod26.z.array(import_zod26.z.string()).optional().describe("Sub-questions that need additional retrieval or re-reasoning")
11151
+ });
11152
+ var QueryResultSchema = import_zod26.z.object({
11153
+ answer: import_zod26.z.string(),
11154
+ citations: import_zod26.z.array(CitationSchema),
10279
11155
  intent: QueryIntentSchema,
10280
- confidence: import_zod25.z.number().min(0).max(1),
10281
- followUp: import_zod25.z.string().optional().describe("Suggested follow-up question if applicable")
11156
+ confidence: import_zod26.z.number().min(0).max(1),
11157
+ followUp: import_zod26.z.string().optional().describe("Suggested follow-up question if applicable")
10282
11158
  });
10283
11159
 
10284
11160
  // src/query/retriever.ts
@@ -11345,7 +12221,7 @@ ${sa.answer}`).join("\n\n"),
11345
12221
  }
11346
12222
 
11347
12223
  // src/pce/index.ts
11348
- var import_zod26 = require("zod");
12224
+ var import_zod27 = require("zod");
11349
12225
 
11350
12226
  // src/prompts/pce/index.ts
11351
12227
  function buildPceNormalizePrompt(input) {
@@ -11379,11 +12255,11 @@ ${input.openQuestions.map((question) => `- ${question.id}${question.fieldPath ?
11379
12255
  }
11380
12256
 
11381
12257
  // src/pce/index.ts
11382
- var ReplyAnswersSchema = import_zod26.z.object({
11383
- answers: import_zod26.z.array(import_zod26.z.object({
11384
- questionId: import_zod26.z.string().optional(),
11385
- fieldPath: import_zod26.z.string().optional(),
11386
- answer: import_zod26.z.string()
12258
+ var ReplyAnswersSchema = import_zod27.z.object({
12259
+ answers: import_zod27.z.array(import_zod27.z.object({
12260
+ questionId: import_zod27.z.string().optional(),
12261
+ fieldPath: import_zod27.z.string().optional(),
12262
+ answer: import_zod27.z.string()
11387
12263
  }))
11388
12264
  });
11389
12265
  function createPceAgent(config = {}) {
@@ -12137,23 +13013,23 @@ var AGENT_TOOLS = [
12137
13013
  ];
12138
13014
 
12139
13015
  // src/prompts/extractors/carrier-info.ts
12140
- var import_zod27 = require("zod");
12141
- var CarrierInfoSchema = import_zod27.z.object({
12142
- carrierName: import_zod27.z.string().describe("Primary insurance company name for display"),
12143
- carrierLegalName: import_zod27.z.string().optional().describe("Legal entity name of insurer"),
12144
- naicNumber: import_zod27.z.string().optional().describe("NAIC company code"),
12145
- amBestRating: import_zod27.z.string().optional().describe("AM Best rating, e.g. 'A+ XV'"),
12146
- admittedStatus: import_zod27.z.enum(["admitted", "non_admitted", "surplus_lines"]).optional().describe("Admitted status of the carrier"),
12147
- mga: import_zod27.z.string().optional().describe("Managing General Agent or Program Administrator name"),
12148
- underwriter: import_zod27.z.string().optional().describe("Named individual underwriter"),
12149
- brokerAgency: import_zod27.z.string().optional().describe("Broker or producer agency name"),
12150
- brokerContactName: import_zod27.z.string().optional().describe("Broker or producer contact person name"),
12151
- brokerLicenseNumber: import_zod27.z.string().optional().describe("Broker or producer license number"),
12152
- policyNumber: import_zod27.z.string().optional().describe("Policy or quote reference number"),
12153
- effectiveDate: import_zod27.z.string().optional().describe("Policy effective date (MM/DD/YYYY)"),
12154
- expirationDate: import_zod27.z.string().optional().describe("Policy expiration date (MM/DD/YYYY)"),
12155
- quoteNumber: import_zod27.z.string().optional().describe("Quote or proposal reference number"),
12156
- proposedEffectiveDate: import_zod27.z.string().optional().describe("Proposed effective date for quotes (MM/DD/YYYY)")
13016
+ var import_zod28 = require("zod");
13017
+ var CarrierInfoSchema = import_zod28.z.object({
13018
+ carrierName: import_zod28.z.string().describe("Primary insurance company name for display"),
13019
+ carrierLegalName: import_zod28.z.string().optional().describe("Legal entity name of insurer"),
13020
+ naicNumber: import_zod28.z.string().optional().describe("NAIC company code"),
13021
+ amBestRating: import_zod28.z.string().optional().describe("AM Best rating, e.g. 'A+ XV'"),
13022
+ admittedStatus: import_zod28.z.enum(["admitted", "non_admitted", "surplus_lines"]).optional().describe("Admitted status of the carrier"),
13023
+ mga: import_zod28.z.string().optional().describe("Managing General Agent or Program Administrator name"),
13024
+ underwriter: import_zod28.z.string().optional().describe("Named individual underwriter"),
13025
+ brokerAgency: import_zod28.z.string().optional().describe("Broker or producer agency name"),
13026
+ brokerContactName: import_zod28.z.string().optional().describe("Broker or producer contact person name"),
13027
+ brokerLicenseNumber: import_zod28.z.string().optional().describe("Broker or producer license number"),
13028
+ policyNumber: import_zod28.z.string().optional().describe("Policy or quote reference number"),
13029
+ effectiveDate: import_zod28.z.string().optional().describe("Policy effective date (MM/DD/YYYY)"),
13030
+ expirationDate: import_zod28.z.string().optional().describe("Policy expiration date (MM/DD/YYYY)"),
13031
+ quoteNumber: import_zod28.z.string().optional().describe("Quote or proposal reference number"),
13032
+ proposedEffectiveDate: import_zod28.z.string().optional().describe("Proposed effective date for quotes (MM/DD/YYYY)")
12157
13033
  });
12158
13034
  function buildCarrierInfoPrompt() {
12159
13035
  return `You are an expert insurance document analyst. Extract carrier and policy identification information from this document.
@@ -12176,21 +13052,21 @@ Return JSON only.`;
12176
13052
  }
12177
13053
 
12178
13054
  // src/prompts/extractors/named-insured.ts
12179
- var import_zod28 = require("zod");
12180
- var AdditionalNamedInsuredSchema = import_zod28.z.object({
12181
- name: import_zod28.z.string(),
12182
- relationship: import_zod28.z.string().optional().describe("e.g. subsidiary, affiliate"),
13055
+ var import_zod29 = require("zod");
13056
+ var AdditionalNamedInsuredSchema = import_zod29.z.object({
13057
+ name: import_zod29.z.string(),
13058
+ relationship: import_zod29.z.string().optional().describe("e.g. subsidiary, affiliate"),
12183
13059
  address: SourceBackedAddressSchema.optional()
12184
13060
  }).merge(SourceProvenanceSchema);
12185
- var ScheduledPartySchema = import_zod28.z.object({
12186
- name: import_zod28.z.string(),
13061
+ var ScheduledPartySchema = import_zod29.z.object({
13062
+ name: import_zod29.z.string(),
12187
13063
  address: SourceBackedAddressSchema.optional()
12188
13064
  }).merge(SourceProvenanceSchema);
12189
- var NamedInsuredSchema2 = import_zod28.z.object({
12190
- insuredName: import_zod28.z.string().describe("Name of primary named insured"),
12191
- insuredDba: import_zod28.z.string().optional().describe("Doing-business-as name"),
13065
+ var NamedInsuredSchema2 = import_zod29.z.object({
13066
+ insuredName: import_zod29.z.string().describe("Name of primary named insured"),
13067
+ insuredDba: import_zod29.z.string().optional().describe("Doing-business-as name"),
12192
13068
  insuredAddress: SourceBackedAddressSchema.optional().describe("Primary insured mailing address"),
12193
- insuredEntityType: import_zod28.z.enum([
13069
+ insuredEntityType: import_zod29.z.enum([
12194
13070
  "corporation",
12195
13071
  "llc",
12196
13072
  "partnership",
@@ -12203,12 +13079,12 @@ var NamedInsuredSchema2 = import_zod28.z.object({
12203
13079
  "married_couple",
12204
13080
  "other"
12205
13081
  ]).optional().describe("Legal entity type of the insured"),
12206
- insuredFein: import_zod28.z.string().optional().describe("Federal Employer Identification Number"),
12207
- insuredSicCode: import_zod28.z.string().optional().describe("SIC code"),
12208
- insuredNaicsCode: import_zod28.z.string().optional().describe("NAICS code"),
12209
- additionalNamedInsureds: import_zod28.z.array(AdditionalNamedInsuredSchema).optional().describe("Additional named insureds listed on the policy"),
12210
- lossPayees: import_zod28.z.array(ScheduledPartySchema).optional().describe("Loss payees listed on the policy"),
12211
- mortgageHolders: import_zod28.z.array(ScheduledPartySchema).optional().describe("Mortgage holders / lienholders listed on the policy")
13082
+ insuredFein: import_zod29.z.string().optional().describe("Federal Employer Identification Number"),
13083
+ insuredSicCode: import_zod29.z.string().optional().describe("SIC code"),
13084
+ insuredNaicsCode: import_zod29.z.string().optional().describe("NAICS code"),
13085
+ additionalNamedInsureds: import_zod29.z.array(AdditionalNamedInsuredSchema).optional().describe("Additional named insureds listed on the policy"),
13086
+ lossPayees: import_zod29.z.array(ScheduledPartySchema).optional().describe("Loss payees listed on the policy"),
13087
+ mortgageHolders: import_zod29.z.array(ScheduledPartySchema).optional().describe("Mortgage holders / lienholders listed on the policy")
12212
13088
  });
12213
13089
  function buildNamedInsuredPrompt() {
12214
13090
  return `You are an expert insurance document analyst. Extract all named insured information from this document.
@@ -12235,14 +13111,14 @@ Return JSON only.`;
12235
13111
  }
12236
13112
 
12237
13113
  // src/prompts/extractors/coverage-limits.ts
12238
- var import_zod29 = require("zod");
13114
+ var import_zod30 = require("zod");
12239
13115
  var ExtractorCoverageSchema = CoverageSchema.extend({
12240
- coverageCode: import_zod29.z.string().optional().describe("Coverage code or class code")
13116
+ coverageCode: import_zod30.z.string().optional().describe("Coverage code or class code")
12241
13117
  });
12242
- var CoverageLimitsSchema = import_zod29.z.object({
12243
- coverages: import_zod29.z.array(ExtractorCoverageSchema).describe("All coverages with their limits"),
12244
- coverageForm: import_zod29.z.enum(["occurrence", "claims_made", "accident"]).optional().describe("Primary coverage trigger type"),
12245
- retroactiveDate: import_zod29.z.string().optional().describe("Retroactive date for claims-made policies (MM/DD/YYYY)")
13118
+ var CoverageLimitsSchema = import_zod30.z.object({
13119
+ coverages: import_zod30.z.array(ExtractorCoverageSchema).describe("All coverages with their limits"),
13120
+ coverageForm: import_zod30.z.enum(["occurrence", "claims_made", "accident"]).optional().describe("Primary coverage trigger type"),
13121
+ retroactiveDate: import_zod30.z.string().optional().describe("Retroactive date for claims-made policies (MM/DD/YYYY)")
12246
13122
  });
12247
13123
  function buildCoverageLimitsPrompt() {
12248
13124
  return `You are an expert insurance document analyst. Extract all coverage limits and deductibles from this document.
@@ -12284,14 +13160,14 @@ Return JSON only.`;
12284
13160
  }
12285
13161
 
12286
13162
  // src/prompts/extractors/endorsements.ts
12287
- var import_zod30 = require("zod");
12288
- var EndorsementsSchema = import_zod30.z.object({
12289
- endorsements: import_zod30.z.array(
12290
- import_zod30.z.object({
12291
- formNumber: import_zod30.z.string().describe("Form number, e.g. 'CG 21 47'"),
12292
- editionDate: import_zod30.z.string().optional().describe("Edition date, e.g. '12 07'"),
12293
- title: import_zod30.z.string().describe("Endorsement title"),
12294
- endorsementType: import_zod30.z.enum([
13163
+ var import_zod31 = require("zod");
13164
+ var EndorsementsSchema = import_zod31.z.object({
13165
+ endorsements: import_zod31.z.array(
13166
+ import_zod31.z.object({
13167
+ formNumber: import_zod31.z.string().describe("Form number, e.g. 'CG 21 47'"),
13168
+ editionDate: import_zod31.z.string().optional().describe("Edition date, e.g. '12 07'"),
13169
+ title: import_zod31.z.string().describe("Endorsement title"),
13170
+ endorsementType: import_zod31.z.enum([
12295
13171
  "additional_insured",
12296
13172
  "waiver_of_subrogation",
12297
13173
  "primary_noncontributory",
@@ -12311,12 +13187,12 @@ var EndorsementsSchema = import_zod30.z.object({
12311
13187
  "territorial_extension",
12312
13188
  "other"
12313
13189
  ]).describe("Endorsement type classification"),
12314
- effectiveDate: import_zod30.z.string().optional().describe("Endorsement effective date"),
12315
- affectedCoverageParts: import_zod30.z.array(import_zod30.z.string()).optional().describe("Coverage parts affected by this endorsement"),
12316
- namedParties: import_zod30.z.array(
12317
- import_zod30.z.object({
12318
- name: import_zod30.z.string().describe("Party name"),
12319
- role: import_zod30.z.enum([
13190
+ effectiveDate: import_zod31.z.string().optional().describe("Endorsement effective date"),
13191
+ affectedCoverageParts: import_zod31.z.array(import_zod31.z.string()).optional().describe("Coverage parts affected by this endorsement"),
13192
+ namedParties: import_zod31.z.array(
13193
+ import_zod31.z.object({
13194
+ name: import_zod31.z.string().describe("Party name"),
13195
+ role: import_zod31.z.enum([
12320
13196
  "additional_insured",
12321
13197
  "loss_payee",
12322
13198
  "mortgage_holder",
@@ -12325,18 +13201,18 @@ var EndorsementsSchema = import_zod30.z.object({
12325
13201
  "designated_person",
12326
13202
  "other"
12327
13203
  ]).describe("Party role"),
12328
- relationship: import_zod30.z.string().optional().describe("Relationship to insured"),
12329
- scope: import_zod30.z.string().optional().describe("Scope of coverage for this party")
13204
+ relationship: import_zod31.z.string().optional().describe("Relationship to insured"),
13205
+ scope: import_zod31.z.string().optional().describe("Scope of coverage for this party")
12330
13206
  })
12331
13207
  ).optional().describe("Named parties (additional insureds, loss payees, etc.)"),
12332
- keyTerms: import_zod30.z.array(import_zod30.z.string()).optional().describe("Key terms or notable provisions in the endorsement"),
12333
- premiumImpact: import_zod30.z.string().optional().describe("Additional premium or credit"),
12334
- excerpt: import_zod30.z.string().optional().describe("Short source excerpt, not full verbatim text"),
12335
- content: import_zod30.z.string().optional().describe("Legacy fallback only; do not return full text when sourceSpanIds are available"),
12336
- pageStart: import_zod30.z.number().describe("Starting page number of this endorsement"),
12337
- pageEnd: import_zod30.z.number().optional().describe("Ending page number of this endorsement"),
12338
- sourceSpanIds: import_zod30.z.array(import_zod30.z.string()).optional().describe("Source span IDs grounding this endorsement"),
12339
- sourceTextHash: import_zod30.z.string().optional().describe("Hash of the source text when available")
13208
+ keyTerms: import_zod31.z.array(import_zod31.z.string()).optional().describe("Key terms or notable provisions in the endorsement"),
13209
+ premiumImpact: import_zod31.z.string().optional().describe("Additional premium or credit"),
13210
+ excerpt: import_zod31.z.string().optional().describe("Short source excerpt, not full verbatim text"),
13211
+ content: import_zod31.z.string().optional().describe("Legacy fallback only; do not return full text when sourceSpanIds are available"),
13212
+ pageStart: import_zod31.z.number().describe("Starting page number of this endorsement"),
13213
+ pageEnd: import_zod31.z.number().optional().describe("Ending page number of this endorsement"),
13214
+ sourceSpanIds: import_zod31.z.array(import_zod31.z.string()).optional().describe("Source span IDs grounding this endorsement"),
13215
+ sourceTextHash: import_zod31.z.string().optional().describe("Hash of the source text when available")
12340
13216
  })
12341
13217
  ).describe("All endorsements found in the document")
12342
13218
  });
@@ -12374,20 +13250,20 @@ Return JSON only.`;
12374
13250
  }
12375
13251
 
12376
13252
  // src/prompts/extractors/exclusions.ts
12377
- var import_zod31 = require("zod");
12378
- var ExclusionsSchema = import_zod31.z.object({
12379
- exclusions: import_zod31.z.array(
12380
- import_zod31.z.object({
12381
- name: import_zod31.z.string().describe("Exclusion title or short description"),
12382
- formNumber: import_zod31.z.string().optional().describe("Form number if part of a named endorsement"),
12383
- excludedPerils: import_zod31.z.array(import_zod31.z.string()).optional().describe("Specific perils excluded"),
12384
- isAbsolute: import_zod31.z.boolean().optional().describe("Whether the exclusion is absolute (no exceptions)"),
12385
- exceptions: import_zod31.z.array(import_zod31.z.string()).optional().describe("Exceptions to the exclusion, if any"),
12386
- buybackAvailable: import_zod31.z.boolean().optional().describe("Whether coverage can be bought back via endorsement"),
12387
- buybackEndorsement: import_zod31.z.string().optional().describe("Form number of the buyback endorsement if available"),
12388
- appliesTo: import_zod31.z.array(import_zod31.z.string()).optional().describe("Policy types this exclusion applies to"),
12389
- content: import_zod31.z.string().describe("Full verbatim exclusion text"),
12390
- pageNumber: import_zod31.z.number().optional().describe("Page number where exclusion appears")
13253
+ var import_zod32 = require("zod");
13254
+ var ExclusionsSchema = import_zod32.z.object({
13255
+ exclusions: import_zod32.z.array(
13256
+ import_zod32.z.object({
13257
+ name: import_zod32.z.string().describe("Exclusion title or short description"),
13258
+ formNumber: import_zod32.z.string().optional().describe("Form number if part of a named endorsement"),
13259
+ excludedPerils: import_zod32.z.array(import_zod32.z.string()).optional().describe("Specific perils excluded"),
13260
+ isAbsolute: import_zod32.z.boolean().optional().describe("Whether the exclusion is absolute (no exceptions)"),
13261
+ exceptions: import_zod32.z.array(import_zod32.z.string()).optional().describe("Exceptions to the exclusion, if any"),
13262
+ buybackAvailable: import_zod32.z.boolean().optional().describe("Whether coverage can be bought back via endorsement"),
13263
+ buybackEndorsement: import_zod32.z.string().optional().describe("Form number of the buyback endorsement if available"),
13264
+ appliesTo: import_zod32.z.array(import_zod32.z.string()).optional().describe("Policy types this exclusion applies to"),
13265
+ content: import_zod32.z.string().describe("Full verbatim exclusion text"),
13266
+ pageNumber: import_zod32.z.number().optional().describe("Page number where exclusion appears")
12391
13267
  })
12392
13268
  ).describe("All exclusions found in the document")
12393
13269
  });
@@ -12423,12 +13299,12 @@ Return JSON only.`;
12423
13299
  }
12424
13300
 
12425
13301
  // src/prompts/extractors/conditions.ts
12426
- var import_zod32 = require("zod");
12427
- var ConditionsSchema = import_zod32.z.object({
12428
- conditions: import_zod32.z.array(
12429
- import_zod32.z.object({
12430
- name: import_zod32.z.string().describe("Condition title"),
12431
- conditionType: import_zod32.z.enum([
13302
+ var import_zod33 = require("zod");
13303
+ var ConditionsSchema = import_zod33.z.object({
13304
+ conditions: import_zod33.z.array(
13305
+ import_zod33.z.object({
13306
+ name: import_zod33.z.string().describe("Condition title"),
13307
+ conditionType: import_zod33.z.enum([
12432
13308
  "duties_after_loss",
12433
13309
  "notice_requirements",
12434
13310
  "other_insurance",
@@ -12447,14 +13323,14 @@ var ConditionsSchema = import_zod32.z.object({
12447
13323
  "separation_of_insureds",
12448
13324
  "other"
12449
13325
  ]).describe("Condition category"),
12450
- content: import_zod32.z.string().describe("Full verbatim condition text"),
12451
- keyValues: import_zod32.z.array(
12452
- import_zod32.z.object({
12453
- key: import_zod32.z.string().describe("Key name (e.g. 'noticePeriod', 'suitDeadline')"),
12454
- value: import_zod32.z.string().describe("Value (e.g. '30 days', '2 years')")
13326
+ content: import_zod33.z.string().describe("Full verbatim condition text"),
13327
+ keyValues: import_zod33.z.array(
13328
+ import_zod33.z.object({
13329
+ key: import_zod33.z.string().describe("Key name (e.g. 'noticePeriod', 'suitDeadline')"),
13330
+ value: import_zod33.z.string().describe("Value (e.g. '30 days', '2 years')")
12455
13331
  })
12456
13332
  ).optional().describe("Key values extracted from the condition (notice periods, deadlines, etc.)"),
12457
- pageNumber: import_zod32.z.number().optional().describe("Page number where condition appears")
13333
+ pageNumber: import_zod33.z.number().optional().describe("Page number where condition appears")
12458
13334
  })
12459
13335
  ).describe("All policy conditions found in the document")
12460
13336
  });
@@ -12492,34 +13368,34 @@ Return JSON only.`;
12492
13368
  }
12493
13369
 
12494
13370
  // src/prompts/extractors/premium-breakdown.ts
12495
- var import_zod33 = require("zod");
12496
- var PremiumBreakdownSchema = import_zod33.z.object({
12497
- premium: import_zod33.z.string().optional().describe("Total premium amount, e.g. '$5,000'"),
12498
- premiumAmount: import_zod33.z.number().optional().describe("Total premium as a plain number with no currency symbols or commas"),
12499
- totalCost: import_zod33.z.string().optional().describe("Total cost including taxes and fees, e.g. '$5,250'"),
12500
- totalCostAmount: import_zod33.z.number().optional().describe("Total cost as a plain number with no currency symbols or commas"),
12501
- premiumBreakdown: import_zod33.z.array(
12502
- import_zod33.z.object({
12503
- line: import_zod33.z.string().describe("Coverage line name"),
12504
- amount: import_zod33.z.string().describe("Premium amount for this line"),
12505
- amountValue: import_zod33.z.number().optional().describe("Premium amount as a plain number with no currency symbols or commas")
13371
+ var import_zod34 = require("zod");
13372
+ var PremiumBreakdownSchema = import_zod34.z.object({
13373
+ premium: import_zod34.z.string().optional().describe("Total premium amount, e.g. '$5,000'"),
13374
+ premiumAmount: import_zod34.z.number().optional().describe("Total premium as a plain number with no currency symbols or commas"),
13375
+ totalCost: import_zod34.z.string().optional().describe("Total cost including taxes and fees, e.g. '$5,250'"),
13376
+ totalCostAmount: import_zod34.z.number().optional().describe("Total cost as a plain number with no currency symbols or commas"),
13377
+ premiumBreakdown: import_zod34.z.array(
13378
+ import_zod34.z.object({
13379
+ line: import_zod34.z.string().describe("Coverage line name"),
13380
+ amount: import_zod34.z.string().describe("Premium amount for this line"),
13381
+ amountValue: import_zod34.z.number().optional().describe("Premium amount as a plain number with no currency symbols or commas")
12506
13382
  })
12507
13383
  ).optional().describe("Per-coverage-line premium breakdown"),
12508
- taxesAndFees: import_zod33.z.array(
12509
- import_zod33.z.object({
12510
- name: import_zod33.z.string().describe("Fee or tax name"),
12511
- amount: import_zod33.z.string().describe("Dollar amount"),
12512
- amountValue: import_zod33.z.number().optional().describe("Fee or tax amount as a plain number with no currency symbols or commas"),
12513
- type: import_zod33.z.enum(["tax", "fee", "surcharge", "assessment"]).optional().describe("Fee category")
13384
+ taxesAndFees: import_zod34.z.array(
13385
+ import_zod34.z.object({
13386
+ name: import_zod34.z.string().describe("Fee or tax name"),
13387
+ amount: import_zod34.z.string().describe("Dollar amount"),
13388
+ amountValue: import_zod34.z.number().optional().describe("Fee or tax amount as a plain number with no currency symbols or commas"),
13389
+ type: import_zod34.z.enum(["tax", "fee", "surcharge", "assessment"]).optional().describe("Fee category")
12514
13390
  })
12515
13391
  ).optional().describe("Taxes, fees, surcharges, and assessments"),
12516
- minimumPremium: import_zod33.z.string().optional().describe("Minimum premium if stated"),
12517
- minimumPremiumAmount: import_zod33.z.number().optional().describe("Minimum premium as a plain number when the source states a fixed amount"),
12518
- depositPremium: import_zod33.z.string().optional().describe("Deposit premium if stated"),
12519
- depositPremiumAmount: import_zod33.z.number().optional().describe("Deposit premium as a plain number when the source states a fixed amount"),
12520
- paymentPlan: import_zod33.z.string().optional().describe("Payment plan description"),
12521
- auditType: import_zod33.z.enum(["annual", "semi_annual", "quarterly", "monthly", "final", "self"]).optional().describe("Premium audit type"),
12522
- ratingBasis: import_zod33.z.string().optional().describe("Rating basis, e.g. payroll, revenue, area, units")
13392
+ minimumPremium: import_zod34.z.string().optional().describe("Minimum premium if stated"),
13393
+ minimumPremiumAmount: import_zod34.z.number().optional().describe("Minimum premium as a plain number when the source states a fixed amount"),
13394
+ depositPremium: import_zod34.z.string().optional().describe("Deposit premium if stated"),
13395
+ depositPremiumAmount: import_zod34.z.number().optional().describe("Deposit premium as a plain number when the source states a fixed amount"),
13396
+ paymentPlan: import_zod34.z.string().optional().describe("Payment plan description"),
13397
+ auditType: import_zod34.z.enum(["annual", "semi_annual", "quarterly", "monthly", "final", "self"]).optional().describe("Premium audit type"),
13398
+ ratingBasis: import_zod34.z.string().optional().describe("Rating basis, e.g. payroll, revenue, area, units")
12523
13399
  });
12524
13400
  function buildPremiumBreakdownPrompt() {
12525
13401
  return `You are an expert insurance document analyst. Extract all premium and cost information from this document.
@@ -12541,14 +13417,14 @@ Return JSON only.`;
12541
13417
  }
12542
13418
 
12543
13419
  // src/prompts/extractors/declarations.ts
12544
- var import_zod34 = require("zod");
12545
- var DeclarationsFieldSchema = import_zod34.z.object({
12546
- field: import_zod34.z.string().describe("Descriptive field name (e.g. 'policyNumber', 'effectiveDate', 'coverageALimit')"),
12547
- value: import_zod34.z.string().describe("Extracted value exactly as it appears in the document"),
12548
- section: import_zod34.z.string().optional().describe("Section or grouping this field belongs to (e.g. 'Coverage Limits', 'Vehicle Schedule')")
13420
+ var import_zod35 = require("zod");
13421
+ var DeclarationsFieldSchema = import_zod35.z.object({
13422
+ field: import_zod35.z.string().describe("Descriptive field name (e.g. 'policyNumber', 'effectiveDate', 'coverageALimit')"),
13423
+ value: import_zod35.z.string().describe("Extracted value exactly as it appears in the document"),
13424
+ section: import_zod35.z.string().optional().describe("Section or grouping this field belongs to (e.g. 'Coverage Limits', 'Vehicle Schedule')")
12549
13425
  });
12550
- var DeclarationsExtractSchema = import_zod34.z.object({
12551
- fields: import_zod34.z.array(DeclarationsFieldSchema).describe("All declarations page fields extracted as key-value pairs. Structure varies by line of business.")
13426
+ var DeclarationsExtractSchema = import_zod35.z.object({
13427
+ fields: import_zod35.z.array(DeclarationsFieldSchema).describe("All declarations page fields extracted as key-value pairs. Structure varies by line of business.")
12552
13428
  });
12553
13429
  function buildDeclarationsPrompt() {
12554
13430
  return `You are an expert insurance document analyst. Extract all declarations page data from this document into a flexible key-value structure.
@@ -12588,21 +13464,21 @@ Preserve original values exactly as they appear. Return JSON only.`;
12588
13464
  }
12589
13465
 
12590
13466
  // src/prompts/extractors/loss-history.ts
12591
- var import_zod35 = require("zod");
12592
- var LossHistorySchema = import_zod35.z.object({
12593
- lossSummary: import_zod35.z.string().optional().describe("Summary of loss history, e.g. '3 claims in past 5 years totaling $125,000'"),
12594
- individualClaims: import_zod35.z.array(
12595
- import_zod35.z.object({
12596
- date: import_zod35.z.string().optional().describe("Date of loss or claim"),
12597
- type: import_zod35.z.string().optional().describe("Type of claim, e.g. 'property damage', 'bodily injury'"),
12598
- description: import_zod35.z.string().optional().describe("Brief description of the claim"),
12599
- amountPaid: import_zod35.z.string().optional().describe("Amount paid"),
12600
- amountReserved: import_zod35.z.string().optional().describe("Amount reserved"),
12601
- status: import_zod35.z.enum(["open", "closed", "reopened"]).optional().describe("Claim status"),
12602
- claimNumber: import_zod35.z.string().optional().describe("Claim reference number")
13467
+ var import_zod36 = require("zod");
13468
+ var LossHistorySchema = import_zod36.z.object({
13469
+ lossSummary: import_zod36.z.string().optional().describe("Summary of loss history, e.g. '3 claims in past 5 years totaling $125,000'"),
13470
+ individualClaims: import_zod36.z.array(
13471
+ import_zod36.z.object({
13472
+ date: import_zod36.z.string().optional().describe("Date of loss or claim"),
13473
+ type: import_zod36.z.string().optional().describe("Type of claim, e.g. 'property damage', 'bodily injury'"),
13474
+ description: import_zod36.z.string().optional().describe("Brief description of the claim"),
13475
+ amountPaid: import_zod36.z.string().optional().describe("Amount paid"),
13476
+ amountReserved: import_zod36.z.string().optional().describe("Amount reserved"),
13477
+ status: import_zod36.z.enum(["open", "closed", "reopened"]).optional().describe("Claim status"),
13478
+ claimNumber: import_zod36.z.string().optional().describe("Claim reference number")
12603
13479
  })
12604
13480
  ).optional().describe("Individual claim records"),
12605
- experienceMod: import_zod35.z.string().optional().describe("Experience modification factor for workers comp, e.g. '0.85'")
13481
+ experienceMod: import_zod36.z.string().optional().describe("Experience modification factor for workers comp, e.g. '0.85'")
12606
13482
  });
12607
13483
  function buildLossHistoryPrompt() {
12608
13484
  return `You are an expert insurance document analyst. Extract all loss history and claims information from this document.
@@ -12619,21 +13495,21 @@ Return JSON only.`;
12619
13495
  }
12620
13496
 
12621
13497
  // src/prompts/extractors/sections.ts
12622
- var import_zod36 = require("zod");
12623
- var SubsectionSchema2 = import_zod36.z.object({
12624
- title: import_zod36.z.string().describe("Subsection title"),
12625
- sectionNumber: import_zod36.z.string().optional().describe("Subsection number"),
12626
- pageNumber: import_zod36.z.number().optional().describe("Page number"),
12627
- excerpt: import_zod36.z.string().optional().describe("Short source excerpt, not full verbatim text"),
12628
- content: import_zod36.z.string().optional().describe("Legacy fallback only; do not return full text when sourceSpanIds are available"),
12629
- sourceSpanIds: import_zod36.z.array(import_zod36.z.string()).optional().describe("Source span IDs grounding this subsection"),
12630
- sourceTextHash: import_zod36.z.string().optional().describe("Hash of the source text when available")
12631
- });
12632
- var SectionsSchema = import_zod36.z.object({
12633
- sections: import_zod36.z.array(
12634
- import_zod36.z.object({
12635
- title: import_zod36.z.string().describe("Section title"),
12636
- type: import_zod36.z.enum([
13498
+ var import_zod37 = require("zod");
13499
+ var SubsectionSchema2 = import_zod37.z.object({
13500
+ title: import_zod37.z.string().describe("Subsection title"),
13501
+ sectionNumber: import_zod37.z.string().optional().describe("Subsection number"),
13502
+ pageNumber: import_zod37.z.number().optional().describe("Page number"),
13503
+ excerpt: import_zod37.z.string().optional().describe("Short source excerpt, not full verbatim text"),
13504
+ content: import_zod37.z.string().optional().describe("Legacy fallback only; do not return full text when sourceSpanIds are available"),
13505
+ sourceSpanIds: import_zod37.z.array(import_zod37.z.string()).optional().describe("Source span IDs grounding this subsection"),
13506
+ sourceTextHash: import_zod37.z.string().optional().describe("Hash of the source text when available")
13507
+ });
13508
+ var SectionsSchema = import_zod37.z.object({
13509
+ sections: import_zod37.z.array(
13510
+ import_zod37.z.object({
13511
+ title: import_zod37.z.string().describe("Section title"),
13512
+ type: import_zod37.z.enum([
12637
13513
  "declarations",
12638
13514
  "insuring_agreement",
12639
13515
  "policy_form",
@@ -12648,13 +13524,13 @@ var SectionsSchema = import_zod36.z.object({
12648
13524
  "regulatory",
12649
13525
  "other"
12650
13526
  ]).describe("Section type classification"),
12651
- excerpt: import_zod36.z.string().optional().describe("Short source excerpt, not full verbatim text"),
12652
- content: import_zod36.z.string().optional().describe("Legacy fallback only; do not return full text when sourceSpanIds are available"),
12653
- pageStart: import_zod36.z.number().describe("Starting page number"),
12654
- pageEnd: import_zod36.z.number().optional().describe("Ending page number"),
12655
- sourceSpanIds: import_zod36.z.array(import_zod36.z.string()).optional().describe("Source span IDs grounding this section"),
12656
- sourceTextHash: import_zod36.z.string().optional().describe("Hash of the source text when available"),
12657
- subsections: import_zod36.z.array(SubsectionSchema2).optional().describe("Subsections within this section")
13527
+ excerpt: import_zod37.z.string().optional().describe("Short source excerpt, not full verbatim text"),
13528
+ content: import_zod37.z.string().optional().describe("Legacy fallback only; do not return full text when sourceSpanIds are available"),
13529
+ pageStart: import_zod37.z.number().describe("Starting page number"),
13530
+ pageEnd: import_zod37.z.number().optional().describe("Ending page number"),
13531
+ sourceSpanIds: import_zod37.z.array(import_zod37.z.string()).optional().describe("Source span IDs grounding this section"),
13532
+ sourceTextHash: import_zod37.z.string().optional().describe("Hash of the source text when available"),
13533
+ subsections: import_zod37.z.array(SubsectionSchema2).optional().describe("Subsections within this section")
12658
13534
  })
12659
13535
  ).describe("All document sections")
12660
13536
  });
@@ -12688,20 +13564,20 @@ Return JSON only.`;
12688
13564
  }
12689
13565
 
12690
13566
  // src/prompts/extractors/supplementary.ts
12691
- var import_zod37 = require("zod");
12692
- var AuxiliaryFactSchema2 = import_zod37.z.object({
12693
- key: import_zod37.z.string().describe("Normalized machine-readable fact key, e.g. 'policyholder_age' or 'insured_name'"),
12694
- value: import_zod37.z.string().describe("Concrete extracted fact value"),
12695
- subject: import_zod37.z.string().optional().describe("Person, entity, vehicle, property, or schedule item this fact belongs to"),
12696
- context: import_zod37.z.string().optional().describe("Short disambiguating context, such as 'Driver Schedule' or 'Named Insured'")
12697
- });
12698
- var SupplementarySchema = import_zod37.z.object({
12699
- regulatoryContacts: import_zod37.z.array(ContactSchema).optional().describe("Regulatory body contacts (state department of insurance, ombudsman)"),
12700
- claimsContacts: import_zod37.z.array(ContactSchema).optional().describe("Claims reporting contacts and instructions"),
12701
- thirdPartyAdministrators: import_zod37.z.array(ContactSchema).optional().describe("Third-party administrators for claims handling"),
12702
- cancellationNoticeDays: import_zod37.z.number().optional().describe("Required notice period for cancellation in days"),
12703
- nonrenewalNoticeDays: import_zod37.z.number().optional().describe("Required notice period for nonrenewal in days"),
12704
- auxiliaryFacts: import_zod37.z.array(AuxiliaryFactSchema2).optional().describe("Additional retrieval-only facts that do not fit the strict primary schema")
13567
+ var import_zod38 = require("zod");
13568
+ var AuxiliaryFactSchema2 = import_zod38.z.object({
13569
+ key: import_zod38.z.string().describe("Normalized machine-readable fact key, e.g. 'policyholder_age' or 'insured_name'"),
13570
+ value: import_zod38.z.string().describe("Concrete extracted fact value"),
13571
+ subject: import_zod38.z.string().optional().describe("Person, entity, vehicle, property, or schedule item this fact belongs to"),
13572
+ context: import_zod38.z.string().optional().describe("Short disambiguating context, such as 'Driver Schedule' or 'Named Insured'")
13573
+ });
13574
+ var SupplementarySchema = import_zod38.z.object({
13575
+ regulatoryContacts: import_zod38.z.array(ContactSchema).optional().describe("Regulatory body contacts (state department of insurance, ombudsman)"),
13576
+ claimsContacts: import_zod38.z.array(ContactSchema).optional().describe("Claims reporting contacts and instructions"),
13577
+ thirdPartyAdministrators: import_zod38.z.array(ContactSchema).optional().describe("Third-party administrators for claims handling"),
13578
+ cancellationNoticeDays: import_zod38.z.number().optional().describe("Required notice period for cancellation in days"),
13579
+ nonrenewalNoticeDays: import_zod38.z.number().optional().describe("Required notice period for nonrenewal in days"),
13580
+ auxiliaryFacts: import_zod38.z.array(AuxiliaryFactSchema2).optional().describe("Additional retrieval-only facts that do not fit the strict primary schema")
12705
13581
  });
12706
13582
  function buildSupplementaryPrompt(alreadyExtractedSummary) {
12707
13583
  const exclusionBlock = alreadyExtractedSummary ? `
@@ -12741,17 +13617,17 @@ Return JSON only.`;
12741
13617
  }
12742
13618
 
12743
13619
  // src/prompts/extractors/definitions.ts
12744
- var import_zod38 = require("zod");
12745
- var DefinitionsSchema = import_zod38.z.object({
12746
- definitions: import_zod38.z.array(
12747
- import_zod38.z.object({
12748
- term: import_zod38.z.string().describe("Defined term exactly as shown in the document"),
12749
- definition: import_zod38.z.string().describe("Full verbatim definition text, preserving original wording"),
12750
- pageNumber: import_zod38.z.number().optional().describe("Original document page number"),
12751
- formNumber: import_zod38.z.string().optional().describe("Form number where this definition appears"),
12752
- formTitle: import_zod38.z.string().optional().describe("Form title where this definition appears"),
12753
- sectionRef: import_zod38.z.string().optional().describe("Definition section heading or subsection reference"),
12754
- originalContent: import_zod38.z.string().optional().describe("Short verbatim source snippet containing the term and definition")
13620
+ var import_zod39 = require("zod");
13621
+ var DefinitionsSchema = import_zod39.z.object({
13622
+ definitions: import_zod39.z.array(
13623
+ import_zod39.z.object({
13624
+ term: import_zod39.z.string().describe("Defined term exactly as shown in the document"),
13625
+ definition: import_zod39.z.string().describe("Full verbatim definition text, preserving original wording"),
13626
+ pageNumber: import_zod39.z.number().optional().describe("Original document page number"),
13627
+ formNumber: import_zod39.z.string().optional().describe("Form number where this definition appears"),
13628
+ formTitle: import_zod39.z.string().optional().describe("Form title where this definition appears"),
13629
+ sectionRef: import_zod39.z.string().optional().describe("Definition section heading or subsection reference"),
13630
+ originalContent: import_zod39.z.string().optional().describe("Short verbatim source snippet containing the term and definition")
12755
13631
  })
12756
13632
  ).describe("All substantive insurance definitions found in the document")
12757
13633
  });
@@ -12785,22 +13661,22 @@ Return JSON only.`;
12785
13661
  }
12786
13662
 
12787
13663
  // src/prompts/extractors/covered-reasons.ts
12788
- var import_zod39 = require("zod");
12789
- var CoveredReasonsSchema = import_zod39.z.object({
12790
- coveredReasons: import_zod39.z.array(
12791
- import_zod39.z.object({
12792
- coverageName: import_zod39.z.string().describe("Coverage, coverage part, or form this covered reason belongs to"),
12793
- reasonNumber: import_zod39.z.string().optional().describe("Source number or letter for the covered reason, if shown"),
12794
- title: import_zod39.z.string().optional().describe("Covered reason title, peril, cause of loss, trigger, or short name"),
12795
- content: import_zod39.z.string().describe("Full verbatim covered-reason or insuring-agreement text"),
12796
- conditions: import_zod39.z.array(import_zod39.z.string()).optional().describe("Conditions, timing rules, documentation requirements, or prerequisites attached to this covered reason"),
12797
- exceptions: import_zod39.z.array(import_zod39.z.string()).optional().describe("Exceptions or limitations attached to this covered reason"),
12798
- appliesTo: import_zod39.z.array(import_zod39.z.string()).optional().describe("Covered property, persons, autos, locations, operations, or coverage parts this reason applies to"),
12799
- pageNumber: import_zod39.z.number().optional().describe("Original document page number"),
12800
- formNumber: import_zod39.z.string().optional().describe("Form number where this covered reason appears"),
12801
- formTitle: import_zod39.z.string().optional().describe("Form title where this covered reason appears"),
12802
- sectionRef: import_zod39.z.string().optional().describe("Section heading where this covered reason appears"),
12803
- originalContent: import_zod39.z.string().optional().describe("Short verbatim source snippet used for this covered reason")
13664
+ var import_zod40 = require("zod");
13665
+ var CoveredReasonsSchema = import_zod40.z.object({
13666
+ coveredReasons: import_zod40.z.array(
13667
+ import_zod40.z.object({
13668
+ coverageName: import_zod40.z.string().describe("Coverage, coverage part, or form this covered reason belongs to"),
13669
+ reasonNumber: import_zod40.z.string().optional().describe("Source number or letter for the covered reason, if shown"),
13670
+ title: import_zod40.z.string().optional().describe("Covered reason title, peril, cause of loss, trigger, or short name"),
13671
+ content: import_zod40.z.string().describe("Full verbatim covered-reason or insuring-agreement text"),
13672
+ conditions: import_zod40.z.array(import_zod40.z.string()).optional().describe("Conditions, timing rules, documentation requirements, or prerequisites attached to this covered reason"),
13673
+ exceptions: import_zod40.z.array(import_zod40.z.string()).optional().describe("Exceptions or limitations attached to this covered reason"),
13674
+ appliesTo: import_zod40.z.array(import_zod40.z.string()).optional().describe("Covered property, persons, autos, locations, operations, or coverage parts this reason applies to"),
13675
+ pageNumber: import_zod40.z.number().optional().describe("Original document page number"),
13676
+ formNumber: import_zod40.z.string().optional().describe("Form number where this covered reason appears"),
13677
+ formTitle: import_zod40.z.string().optional().describe("Form title where this covered reason appears"),
13678
+ sectionRef: import_zod40.z.string().optional().describe("Section heading where this covered reason appears"),
13679
+ originalContent: import_zod40.z.string().optional().describe("Short verbatim source snippet used for this covered reason")
12804
13680
  })
12805
13681
  ).describe("Covered causes, perils, triggers, or reasons that affirmatively grant coverage")
12806
13682
  });
@@ -13793,10 +14669,15 @@ function getTemplate(policyType) {
13793
14669
  NamedInsuredSchema,
13794
14670
  OperationalAddressSchema,
13795
14671
  OperationalCoverageLineSchema,
14672
+ OperationalCoverageScheduleItemSchema,
14673
+ OperationalCoverageScheduleSchema,
14674
+ OperationalCoverageScheduleValueSchema,
13796
14675
  OperationalCoverageTermSchema,
13797
14676
  OperationalDeclarationFactSchema,
13798
14677
  OperationalEndorsementSupportSchema,
13799
14678
  OperationalPartySchema,
14679
+ OperationalPremiumLineSchema,
14680
+ OperationalTaxFeeItemSchema,
13800
14681
  PERSONAL_AUTO_USAGES,
13801
14682
  PERSONAL_LOB_CODES,
13802
14683
  PET_SPECIES,
@@ -13983,6 +14864,8 @@ function getTemplate(policyType) {
13983
14864
  proposeContextWrites,
13984
14865
  resolveModelBudget,
13985
14866
  resolveOperationalProfileLinesOfBusiness,
14867
+ runCoverageRecovery,
14868
+ runSourceTreeExtraction,
13986
14869
  safeGenerateObject,
13987
14870
  sanitizeNulls,
13988
14871
  scoreCaseProposal,