@claritylabs/cl-sdk 3.0.33 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/application.d.mts +2 -0
- package/dist/application.d.ts +2 -0
- package/dist/application.js +2351 -0
- package/dist/application.js.map +1 -0
- package/dist/application.mjs +2283 -0
- package/dist/application.mjs.map +1 -0
- package/dist/index-D23NUbxr.d.mts +28983 -0
- package/dist/index-D23NUbxr.d.ts +28983 -0
- package/dist/index.d.mts +2169 -29743
- package/dist/index.d.ts +2169 -29743
- package/dist/index.js +534 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +511 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -1
package/dist/index.js
CHANGED
|
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
33
|
ADMITTED_STATUSES: () => ADMITTED_STATUSES,
|
|
34
34
|
AGENT_TOOLS: () => AGENT_TOOLS,
|
|
35
35
|
APPLICATION_CLASSIFY_PROMPT: () => APPLICATION_CLASSIFY_PROMPT,
|
|
@@ -40,13 +40,21 @@ __export(index_exports, {
|
|
|
40
40
|
AgenticExecutionModeSchema: () => AgenticExecutionModeSchema,
|
|
41
41
|
AnswerParsingResultSchema: () => AnswerParsingResultSchema,
|
|
42
42
|
ApplicationClassifyResultSchema: () => ApplicationClassifyResultSchema,
|
|
43
|
+
ApplicationContextProposalSchema: () => ApplicationContextProposalSchema,
|
|
43
44
|
ApplicationEmailReviewSchema: () => ApplicationEmailReviewSchema,
|
|
44
45
|
ApplicationFieldSchema: () => ApplicationFieldSchema,
|
|
46
|
+
ApplicationPacketAnswerSchema: () => ApplicationPacketAnswerSchema,
|
|
47
|
+
ApplicationPacketSchema: () => ApplicationPacketSchema,
|
|
45
48
|
ApplicationQualityArtifactSchema: () => ApplicationQualityArtifactSchema,
|
|
46
49
|
ApplicationQualityIssueSchema: () => ApplicationQualityIssueSchema,
|
|
47
50
|
ApplicationQualityReportSchema: () => ApplicationQualityReportSchema,
|
|
48
51
|
ApplicationQualityRoundSchema: () => ApplicationQualityRoundSchema,
|
|
52
|
+
ApplicationQuestionConditionSchema: () => ApplicationQuestionConditionSchema,
|
|
53
|
+
ApplicationQuestionGraphSchema: () => ApplicationQuestionGraphSchema,
|
|
54
|
+
ApplicationQuestionNodeSchema: () => ApplicationQuestionNodeSchema,
|
|
55
|
+
ApplicationRepeatSchema: () => ApplicationRepeatSchema,
|
|
49
56
|
ApplicationStateSchema: () => ApplicationStateSchema,
|
|
57
|
+
ApplicationTemplateSchema: () => ApplicationTemplateSchema,
|
|
50
58
|
AttachmentInterpretationSchema: () => AttachmentInterpretationSchema,
|
|
51
59
|
AuditTypeSchema: () => AuditTypeSchema,
|
|
52
60
|
AutoFillMatchSchema: () => AutoFillMatchSchema,
|
|
@@ -261,9 +269,11 @@ __export(index_exports, {
|
|
|
261
269
|
VerifyResultSchema: () => VerifyResultSchema,
|
|
262
270
|
WatercraftDeclarationsSchema: () => WatercraftDeclarationsSchema,
|
|
263
271
|
WorkersCompDeclarationsSchema: () => WorkersCompDeclarationsSchema,
|
|
272
|
+
applyApplicationAnswers: () => applyApplicationAnswers,
|
|
264
273
|
buildAcroFormMappingPrompt: () => buildAcroFormMappingPrompt,
|
|
265
274
|
buildAgentSystemPrompt: () => buildAgentSystemPrompt,
|
|
266
275
|
buildAnswerParsingPrompt: () => buildAnswerParsingPrompt,
|
|
276
|
+
buildApplicationPacket: () => buildApplicationPacket,
|
|
267
277
|
buildAutoFillPrompt: () => buildAutoFillPrompt,
|
|
268
278
|
buildBatchEmailGenerationPrompt: () => buildBatchEmailGenerationPrompt,
|
|
269
279
|
buildClassifyMessagePrompt: () => buildClassifyMessagePrompt,
|
|
@@ -290,6 +300,7 @@ __export(index_exports, {
|
|
|
290
300
|
buildPdfProviderOptions: () => buildPdfProviderOptions,
|
|
291
301
|
buildQueryClassifyPrompt: () => buildQueryClassifyPrompt,
|
|
292
302
|
buildQuestionBatchPrompt: () => buildQuestionBatchPrompt,
|
|
303
|
+
buildQuestionGraphFromFields: () => buildQuestionGraphFromFields,
|
|
293
304
|
buildQuotesPoliciesPrompt: () => buildQuotesPoliciesPrompt,
|
|
294
305
|
buildReasonPrompt: () => buildReasonPrompt,
|
|
295
306
|
buildReplyIntentClassificationPrompt: () => buildReplyIntentClassificationPrompt,
|
|
@@ -305,6 +316,7 @@ __export(index_exports, {
|
|
|
305
316
|
collectPceEvidenceSources: () => collectPceEvidenceSources,
|
|
306
317
|
compareSourceEvidence: () => compareSourceEvidence,
|
|
307
318
|
createApplicationPipeline: () => createApplicationPipeline,
|
|
319
|
+
createApplicationRun: () => createApplicationRun,
|
|
308
320
|
createExtractor: () => createExtractor,
|
|
309
321
|
createPceAgent: () => createPceAgent,
|
|
310
322
|
createPipelineContext: () => createPipelineContext,
|
|
@@ -312,12 +324,16 @@ __export(index_exports, {
|
|
|
312
324
|
evaluateCaseProposals: () => evaluateCaseProposals,
|
|
313
325
|
evidenceContainsQuote: () => evidenceContainsQuote,
|
|
314
326
|
extractPageRange: () => extractPageRange,
|
|
327
|
+
extractQuestionGraphFromFields: () => extractQuestionGraphFromFields,
|
|
315
328
|
fillAcroForm: () => fillAcroForm,
|
|
329
|
+
flattenQuestionGraph: () => flattenQuestionGraph,
|
|
316
330
|
generateNextMessage: () => generateNextMessage,
|
|
317
331
|
getAcroFormFields: () => getAcroFormFields,
|
|
332
|
+
getActiveApplicationFields: () => getActiveApplicationFields,
|
|
318
333
|
getDoclingPageRangeText: () => getDoclingPageRangeText,
|
|
319
334
|
getExtractor: () => getExtractor,
|
|
320
335
|
getFileIdentifier: () => getFileIdentifier,
|
|
336
|
+
getNextApplicationQuestions: () => getNextApplicationQuestions,
|
|
321
337
|
getPdfPageCount: () => getPdfPageCount,
|
|
322
338
|
getTemplate: () => getTemplate,
|
|
323
339
|
isDoclingExtractionInput: () => isDoclingExtractionInput,
|
|
@@ -325,6 +341,7 @@ __export(index_exports, {
|
|
|
325
341
|
mergeOperationalProfile: () => mergeOperationalProfile,
|
|
326
342
|
mergeQuestionAnswers: () => mergeQuestionAnswers,
|
|
327
343
|
mergeSourceSpans: () => mergeSourceSpans,
|
|
344
|
+
normalizeApplicationQuestionGraph: () => normalizeApplicationQuestionGraph,
|
|
328
345
|
normalizeDoclingDocument: () => normalizeDoclingDocument,
|
|
329
346
|
normalizeDocumentSourceTreePaths: () => normalizeDocumentSourceTreePaths,
|
|
330
347
|
normalizeForMatch: () => normalizeForMatch,
|
|
@@ -334,7 +351,9 @@ __export(index_exports, {
|
|
|
334
351
|
pLimit: () => pLimit,
|
|
335
352
|
pdfInputToBase64: () => pdfInputToBase64,
|
|
336
353
|
pdfInputToBytes: () => pdfInputToBytes,
|
|
354
|
+
planNextApplicationQuestions: () => planNextApplicationQuestions,
|
|
337
355
|
processReply: () => processReply,
|
|
356
|
+
proposeContextWrites: () => proposeContextWrites,
|
|
338
357
|
resolveModelBudget: () => resolveModelBudget,
|
|
339
358
|
safeGenerateObject: () => safeGenerateObject,
|
|
340
359
|
sanitizeNulls: () => sanitizeNulls,
|
|
@@ -347,12 +366,13 @@ __export(index_exports, {
|
|
|
347
366
|
stableStringify: () => stableStringify,
|
|
348
367
|
stripFences: () => stripFences,
|
|
349
368
|
toStrictSchema: () => toStrictSchema,
|
|
369
|
+
validateApplicationPacket: () => validateApplicationPacket,
|
|
350
370
|
validateEvidence: () => validateEvidence,
|
|
351
371
|
validatePceItems: () => validatePceItems,
|
|
352
372
|
validateQuotedEvidence: () => validateQuotedEvidence,
|
|
353
373
|
withRetry: () => withRetry
|
|
354
374
|
});
|
|
355
|
-
module.exports = __toCommonJS(
|
|
375
|
+
module.exports = __toCommonJS(src_exports);
|
|
356
376
|
|
|
357
377
|
// src/core/retry.ts
|
|
358
378
|
var MAX_RETRIES = 5;
|
|
@@ -13012,6 +13032,55 @@ var ApplicationFieldSchema = import_zod42.z.object({
|
|
|
13012
13032
|
acroFormName: import_zod42.z.string().optional().describe("Native PDF AcroForm field name when available"),
|
|
13013
13033
|
validationStatus: import_zod42.z.enum(["valid", "needs_review", "unsupported", "missing"]).optional()
|
|
13014
13034
|
});
|
|
13035
|
+
var ApplicationQuestionConditionSchema = import_zod42.z.object({
|
|
13036
|
+
dependsOn: import_zod42.z.string(),
|
|
13037
|
+
operator: import_zod42.z.enum(["equals", "not_equals", "in", "not_in", "exists"]).optional(),
|
|
13038
|
+
value: import_zod42.z.string().optional(),
|
|
13039
|
+
whenValue: import_zod42.z.string().optional(),
|
|
13040
|
+
values: import_zod42.z.array(import_zod42.z.string()).optional()
|
|
13041
|
+
});
|
|
13042
|
+
var ApplicationRepeatSchema = import_zod42.z.object({
|
|
13043
|
+
min: import_zod42.z.number().int().nonnegative().optional(),
|
|
13044
|
+
max: import_zod42.z.number().int().positive().optional(),
|
|
13045
|
+
label: import_zod42.z.string().optional()
|
|
13046
|
+
});
|
|
13047
|
+
var ApplicationQuestionNodeSchema = import_zod42.z.lazy(
|
|
13048
|
+
() => import_zod42.z.object({
|
|
13049
|
+
id: import_zod42.z.string(),
|
|
13050
|
+
nodeType: import_zod42.z.enum(["group", "question", "repeat_group", "table"]),
|
|
13051
|
+
fieldId: import_zod42.z.string().optional(),
|
|
13052
|
+
fieldPath: import_zod42.z.string().optional(),
|
|
13053
|
+
parentId: import_zod42.z.string().optional(),
|
|
13054
|
+
order: import_zod42.z.number().int().nonnegative().optional(),
|
|
13055
|
+
label: import_zod42.z.string(),
|
|
13056
|
+
section: import_zod42.z.string().optional(),
|
|
13057
|
+
fieldType: FieldTypeSchema.optional(),
|
|
13058
|
+
required: import_zod42.z.boolean().optional(),
|
|
13059
|
+
prompt: import_zod42.z.string().optional(),
|
|
13060
|
+
options: import_zod42.z.array(import_zod42.z.string()).optional(),
|
|
13061
|
+
columns: import_zod42.z.array(import_zod42.z.string()).optional(),
|
|
13062
|
+
condition: ApplicationQuestionConditionSchema.optional(),
|
|
13063
|
+
repeat: ApplicationRepeatSchema.optional(),
|
|
13064
|
+
children: import_zod42.z.array(ApplicationQuestionNodeSchema).optional()
|
|
13065
|
+
})
|
|
13066
|
+
);
|
|
13067
|
+
var ApplicationQuestionGraphSchema = import_zod42.z.object({
|
|
13068
|
+
id: import_zod42.z.string(),
|
|
13069
|
+
version: import_zod42.z.string(),
|
|
13070
|
+
title: import_zod42.z.string().optional(),
|
|
13071
|
+
applicationType: import_zod42.z.string().nullable().optional(),
|
|
13072
|
+
source: import_zod42.z.enum(["pdf", "manual", "imported", "generated"]).default("generated"),
|
|
13073
|
+
rootNodeIds: import_zod42.z.array(import_zod42.z.string()).optional(),
|
|
13074
|
+
nodes: import_zod42.z.array(ApplicationQuestionNodeSchema)
|
|
13075
|
+
});
|
|
13076
|
+
var ApplicationTemplateSchema = import_zod42.z.object({
|
|
13077
|
+
id: import_zod42.z.string(),
|
|
13078
|
+
version: import_zod42.z.string(),
|
|
13079
|
+
title: import_zod42.z.string(),
|
|
13080
|
+
applicationType: import_zod42.z.string().nullable().optional(),
|
|
13081
|
+
questionGraph: ApplicationQuestionGraphSchema,
|
|
13082
|
+
fields: import_zod42.z.array(ApplicationFieldSchema).optional()
|
|
13083
|
+
});
|
|
13015
13084
|
var ApplicationClassifyResultSchema = import_zod42.z.object({
|
|
13016
13085
|
isApplication: import_zod42.z.boolean(),
|
|
13017
13086
|
confidence: import_zod42.z.number().min(0).max(1),
|
|
@@ -13109,16 +13178,67 @@ var ApplicationQualityReportSchema = import_zod42.z.object({
|
|
|
13109
13178
|
emailReview: ApplicationEmailReviewSchema.optional(),
|
|
13110
13179
|
qualityGateStatus: QualityGateStatusSchema
|
|
13111
13180
|
});
|
|
13181
|
+
var ApplicationContextProposalSchema = import_zod42.z.object({
|
|
13182
|
+
id: import_zod42.z.string(),
|
|
13183
|
+
fieldId: import_zod42.z.string().optional(),
|
|
13184
|
+
key: import_zod42.z.string(),
|
|
13185
|
+
value: import_zod42.z.string(),
|
|
13186
|
+
category: import_zod42.z.string(),
|
|
13187
|
+
source: import_zod42.z.enum(["application", "user", "lookup", "policy", "email", "chat", "imessage", "mcp"]),
|
|
13188
|
+
confidence: import_zod42.z.enum(["confirmed", "high", "medium", "low"]),
|
|
13189
|
+
sourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional(),
|
|
13190
|
+
userSourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional()
|
|
13191
|
+
});
|
|
13192
|
+
var ApplicationPacketAnswerSchema = import_zod42.z.object({
|
|
13193
|
+
fieldId: import_zod42.z.string(),
|
|
13194
|
+
label: import_zod42.z.string(),
|
|
13195
|
+
section: import_zod42.z.string(),
|
|
13196
|
+
value: import_zod42.z.string(),
|
|
13197
|
+
source: import_zod42.z.string(),
|
|
13198
|
+
confidence: import_zod42.z.enum(["confirmed", "high", "medium", "low"]).optional(),
|
|
13199
|
+
sourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional(),
|
|
13200
|
+
userSourceSpanIds: import_zod42.z.array(import_zod42.z.string()).optional()
|
|
13201
|
+
});
|
|
13202
|
+
var ApplicationPacketSchema = import_zod42.z.object({
|
|
13203
|
+
id: import_zod42.z.string(),
|
|
13204
|
+
applicationId: import_zod42.z.string(),
|
|
13205
|
+
title: import_zod42.z.string(),
|
|
13206
|
+
status: import_zod42.z.enum(["draft", "broker_ready", "submitted"]),
|
|
13207
|
+
answers: import_zod42.z.array(ApplicationPacketAnswerSchema),
|
|
13208
|
+
missingFieldIds: import_zod42.z.array(import_zod42.z.string()),
|
|
13209
|
+
qualityReport: ApplicationQualityReportSchema,
|
|
13210
|
+
submissionNotes: import_zod42.z.string().optional(),
|
|
13211
|
+
createdAt: import_zod42.z.number()
|
|
13212
|
+
});
|
|
13112
13213
|
var ApplicationStateSchema = import_zod42.z.object({
|
|
13113
13214
|
id: import_zod42.z.string(),
|
|
13114
13215
|
pdfBase64: import_zod42.z.string().optional().describe("Original PDF, omitted after extraction"),
|
|
13216
|
+
templateId: import_zod42.z.string().optional(),
|
|
13217
|
+
templateVersion: import_zod42.z.string().optional(),
|
|
13218
|
+
templateSnapshot: ApplicationTemplateSchema.optional(),
|
|
13115
13219
|
title: import_zod42.z.string().optional(),
|
|
13116
13220
|
applicationType: import_zod42.z.string().nullable().optional(),
|
|
13221
|
+
questionGraph: ApplicationQuestionGraphSchema.optional(),
|
|
13117
13222
|
fields: import_zod42.z.array(ApplicationFieldSchema),
|
|
13118
13223
|
batches: import_zod42.z.array(import_zod42.z.array(import_zod42.z.string())).optional(),
|
|
13119
13224
|
currentBatchIndex: import_zod42.z.number().default(0),
|
|
13225
|
+
contextProposals: import_zod42.z.array(ApplicationContextProposalSchema).optional(),
|
|
13226
|
+
packet: ApplicationPacketSchema.optional(),
|
|
13120
13227
|
qualityReport: ApplicationQualityReportSchema.optional(),
|
|
13121
|
-
status: import_zod42.z.enum([
|
|
13228
|
+
status: import_zod42.z.enum([
|
|
13229
|
+
"classifying",
|
|
13230
|
+
"extracting",
|
|
13231
|
+
"auto_filling",
|
|
13232
|
+
"batching",
|
|
13233
|
+
"collecting",
|
|
13234
|
+
"confirming",
|
|
13235
|
+
"mapping",
|
|
13236
|
+
"broker_review",
|
|
13237
|
+
"packet_ready",
|
|
13238
|
+
"submitted",
|
|
13239
|
+
"cancelled",
|
|
13240
|
+
"complete"
|
|
13241
|
+
]),
|
|
13122
13242
|
createdAt: import_zod42.z.number(),
|
|
13123
13243
|
updatedAt: import_zod42.z.number()
|
|
13124
13244
|
});
|
|
@@ -13817,7 +13937,7 @@ function planReplyActions(input) {
|
|
|
13817
13937
|
parseAnswers: input.intent.hasAnswers && hasCurrentFields,
|
|
13818
13938
|
runLookup: hasLookupRequests && input.hasDocumentStore,
|
|
13819
13939
|
answerQuestion: Boolean(input.intent.questionText) && (input.intent.primaryIntent === "question" || input.intent.primaryIntent === "mixed"),
|
|
13820
|
-
advanceBatch: hasCurrentFields && input.currentBatchFields.every((field) => !isUnfilled(field)),
|
|
13940
|
+
advanceBatch: hasCurrentFields && input.currentBatchFields.every((field) => !isUnfilled(field)) || !hasCurrentFields && nextBatchNeedsAnswers,
|
|
13821
13941
|
generateNextEmail: nextBatchNeedsAnswers
|
|
13822
13942
|
};
|
|
13823
13943
|
}
|
|
@@ -13856,12 +13976,287 @@ function isHighValueLookupField(field) {
|
|
|
13856
13976
|
].some((term) => text.includes(term));
|
|
13857
13977
|
}
|
|
13858
13978
|
|
|
13979
|
+
// src/application/question-graph.ts
|
|
13980
|
+
function buildQuestionGraphFromFields(fields, options) {
|
|
13981
|
+
const sectionNodes = /* @__PURE__ */ new Map();
|
|
13982
|
+
const nodes = [];
|
|
13983
|
+
for (const [index, field] of fields.entries()) {
|
|
13984
|
+
const sectionId = stableNodeId(["section", field.section]);
|
|
13985
|
+
let sectionNode = sectionNodes.get(sectionId);
|
|
13986
|
+
if (!sectionNode) {
|
|
13987
|
+
sectionNode = {
|
|
13988
|
+
id: sectionId,
|
|
13989
|
+
nodeType: "group",
|
|
13990
|
+
label: field.section,
|
|
13991
|
+
order: sectionNodes.size,
|
|
13992
|
+
children: []
|
|
13993
|
+
};
|
|
13994
|
+
sectionNodes.set(sectionId, sectionNode);
|
|
13995
|
+
nodes.push(sectionNode);
|
|
13996
|
+
}
|
|
13997
|
+
const child = {
|
|
13998
|
+
id: field.fieldAnchorId ?? stableNodeId(["field", field.section, field.id || field.label]),
|
|
13999
|
+
nodeType: field.fieldType === "table" ? "table" : "question",
|
|
14000
|
+
fieldId: field.id,
|
|
14001
|
+
fieldPath: `${field.section}.${field.id}`,
|
|
14002
|
+
parentId: sectionId,
|
|
14003
|
+
order: index,
|
|
14004
|
+
label: field.label,
|
|
14005
|
+
section: field.section,
|
|
14006
|
+
fieldType: field.fieldType,
|
|
14007
|
+
required: field.required,
|
|
14008
|
+
options: field.options,
|
|
14009
|
+
columns: field.columns,
|
|
14010
|
+
condition: field.condition ? {
|
|
14011
|
+
dependsOn: field.condition.dependsOn,
|
|
14012
|
+
operator: "equals",
|
|
14013
|
+
value: field.condition.whenValue,
|
|
14014
|
+
whenValue: field.condition.whenValue
|
|
14015
|
+
} : void 0
|
|
14016
|
+
};
|
|
14017
|
+
sectionNode.children = [...sectionNode.children ?? [], child];
|
|
14018
|
+
}
|
|
14019
|
+
return normalizeApplicationQuestionGraph({
|
|
14020
|
+
id: options.id,
|
|
14021
|
+
version: options.version ?? "v1",
|
|
14022
|
+
title: options.title,
|
|
14023
|
+
applicationType: options.applicationType,
|
|
14024
|
+
source: options.source ?? "generated",
|
|
14025
|
+
rootNodeIds: nodes.map((node) => node.id),
|
|
14026
|
+
nodes
|
|
14027
|
+
});
|
|
14028
|
+
}
|
|
14029
|
+
function normalizeApplicationQuestionGraph(graph) {
|
|
14030
|
+
const normalizedNodes = graph.nodes.map((node, index) => normalizeNode(node, void 0, index)).sort(compareNodes);
|
|
14031
|
+
return {
|
|
14032
|
+
...graph,
|
|
14033
|
+
rootNodeIds: graph.rootNodeIds?.length ? graph.rootNodeIds : normalizedNodes.map((node) => node.id),
|
|
14034
|
+
nodes: normalizedNodes
|
|
14035
|
+
};
|
|
14036
|
+
}
|
|
14037
|
+
function flattenQuestionGraph(graph) {
|
|
14038
|
+
const fields = [];
|
|
14039
|
+
for (const node of graph.nodes.sort(compareNodes)) {
|
|
14040
|
+
collectFields(node, fields);
|
|
14041
|
+
}
|
|
14042
|
+
return fields;
|
|
14043
|
+
}
|
|
14044
|
+
function getActiveApplicationFields(state) {
|
|
14045
|
+
const valueByFieldId = new Map(
|
|
14046
|
+
state.fields.filter((field) => field.value !== void 0 && field.value.trim() !== "").map((field) => [field.id, field.value ?? ""])
|
|
14047
|
+
);
|
|
14048
|
+
const graphConditions = /* @__PURE__ */ new Map();
|
|
14049
|
+
for (const node of state.questionGraph?.nodes ?? []) {
|
|
14050
|
+
collectNodeConditions(node, graphConditions);
|
|
14051
|
+
}
|
|
14052
|
+
return state.fields.filter((field) => {
|
|
14053
|
+
const graphCondition = graphConditions.get(field.id);
|
|
14054
|
+
return isConditionSatisfied(field.condition, valueByFieldId) && isQuestionConditionSatisfied(graphCondition, valueByFieldId);
|
|
14055
|
+
});
|
|
14056
|
+
}
|
|
14057
|
+
function getNextApplicationQuestions(state, limit = 8) {
|
|
14058
|
+
const activeUnfilled = getActiveApplicationFields(state).filter((field) => !field.value);
|
|
14059
|
+
if (activeUnfilled.length === 0) return [];
|
|
14060
|
+
const currentBatchIds = state.batches?.[state.currentBatchIndex] ?? [];
|
|
14061
|
+
const currentBatchFields = activeUnfilled.filter((field) => currentBatchIds.includes(field.id));
|
|
14062
|
+
return (currentBatchFields.length > 0 ? currentBatchFields : activeUnfilled).slice(0, limit);
|
|
14063
|
+
}
|
|
14064
|
+
function normalizeNode(node, parentId, index) {
|
|
14065
|
+
const children = node.children?.map((child, childIndex) => normalizeNode(child, node.id, childIndex));
|
|
14066
|
+
return {
|
|
14067
|
+
...node,
|
|
14068
|
+
parentId: node.parentId ?? parentId,
|
|
14069
|
+
order: node.order ?? index,
|
|
14070
|
+
fieldPath: node.fieldPath ?? (node.fieldId ? [node.section, node.fieldId].filter(Boolean).join(".") : void 0),
|
|
14071
|
+
children
|
|
14072
|
+
};
|
|
14073
|
+
}
|
|
14074
|
+
function collectFields(node, fields) {
|
|
14075
|
+
if ((node.nodeType === "question" || node.nodeType === "table") && node.fieldId) {
|
|
14076
|
+
fields.push({
|
|
14077
|
+
id: node.fieldId,
|
|
14078
|
+
label: node.label,
|
|
14079
|
+
section: node.section ?? "General",
|
|
14080
|
+
fieldType: node.fieldType ?? (node.nodeType === "table" ? "table" : "text"),
|
|
14081
|
+
required: node.required ?? false,
|
|
14082
|
+
options: node.options,
|
|
14083
|
+
columns: node.columns,
|
|
14084
|
+
condition: node.condition ? {
|
|
14085
|
+
dependsOn: node.condition.dependsOn,
|
|
14086
|
+
whenValue: node.condition.value ?? node.condition.whenValue ?? ""
|
|
14087
|
+
} : void 0,
|
|
14088
|
+
fieldAnchorId: node.id
|
|
14089
|
+
});
|
|
14090
|
+
}
|
|
14091
|
+
for (const child of node.children ?? []) {
|
|
14092
|
+
collectFields(child, fields);
|
|
14093
|
+
}
|
|
14094
|
+
}
|
|
14095
|
+
function collectNodeConditions(node, conditions) {
|
|
14096
|
+
if (node.fieldId && node.condition) {
|
|
14097
|
+
conditions.set(node.fieldId, node.condition);
|
|
14098
|
+
}
|
|
14099
|
+
for (const child of node.children ?? []) {
|
|
14100
|
+
collectNodeConditions(child, conditions);
|
|
14101
|
+
}
|
|
14102
|
+
}
|
|
14103
|
+
function isConditionSatisfied(condition, valueByFieldId) {
|
|
14104
|
+
if (!condition) return true;
|
|
14105
|
+
const current = valueByFieldId.get(condition.dependsOn);
|
|
14106
|
+
return normalizeValue(current) === normalizeValue(condition.whenValue);
|
|
14107
|
+
}
|
|
14108
|
+
function isQuestionConditionSatisfied(condition, valueByFieldId) {
|
|
14109
|
+
if (!condition) return true;
|
|
14110
|
+
const current = valueByFieldId.get(condition.dependsOn);
|
|
14111
|
+
const expected = condition.value ?? condition.whenValue;
|
|
14112
|
+
const values = condition.values ?? (expected !== void 0 ? [expected] : []);
|
|
14113
|
+
switch (condition.operator) {
|
|
14114
|
+
case "exists":
|
|
14115
|
+
return current !== void 0 && current.trim() !== "";
|
|
14116
|
+
case "not_equals":
|
|
14117
|
+
return normalizeValue(current) !== normalizeValue(expected);
|
|
14118
|
+
case "in":
|
|
14119
|
+
return values.map(normalizeValue).includes(normalizeValue(current));
|
|
14120
|
+
case "not_in":
|
|
14121
|
+
return !values.map(normalizeValue).includes(normalizeValue(current));
|
|
14122
|
+
case "equals":
|
|
14123
|
+
default:
|
|
14124
|
+
return normalizeValue(current) === normalizeValue(expected);
|
|
14125
|
+
}
|
|
14126
|
+
}
|
|
14127
|
+
function compareNodes(a, b) {
|
|
14128
|
+
return (a.order ?? 0) - (b.order ?? 0) || a.id.localeCompare(b.id);
|
|
14129
|
+
}
|
|
14130
|
+
function normalizeValue(value) {
|
|
14131
|
+
return (value ?? "").trim().toLowerCase();
|
|
14132
|
+
}
|
|
14133
|
+
function stableNodeId(parts) {
|
|
14134
|
+
return parts.join(":").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "node";
|
|
14135
|
+
}
|
|
14136
|
+
|
|
14137
|
+
// src/application/intake.ts
|
|
14138
|
+
function extractQuestionGraphFromFields(fields, options) {
|
|
14139
|
+
return buildQuestionGraphFromFields(fields, options);
|
|
14140
|
+
}
|
|
14141
|
+
function createApplicationRun(params) {
|
|
14142
|
+
const now = params.now ?? Date.now();
|
|
14143
|
+
const graph = normalizeApplicationQuestionGraph(params.template.questionGraph);
|
|
14144
|
+
const fields = params.template.fields?.length ? params.template.fields : flattenQuestionGraph(graph);
|
|
14145
|
+
return {
|
|
14146
|
+
id: params.applicationId,
|
|
14147
|
+
templateId: params.template.id,
|
|
14148
|
+
templateVersion: params.template.version,
|
|
14149
|
+
templateSnapshot: params.template,
|
|
14150
|
+
title: params.template.title,
|
|
14151
|
+
applicationType: params.template.applicationType,
|
|
14152
|
+
questionGraph: graph,
|
|
14153
|
+
fields,
|
|
14154
|
+
currentBatchIndex: 0,
|
|
14155
|
+
status: "collecting",
|
|
14156
|
+
createdAt: now,
|
|
14157
|
+
updatedAt: now
|
|
14158
|
+
};
|
|
14159
|
+
}
|
|
14160
|
+
function planNextApplicationQuestions(state, limit) {
|
|
14161
|
+
const fields = getNextApplicationQuestions(state, limit);
|
|
14162
|
+
return {
|
|
14163
|
+
status: fields.length === 0 ? "complete" : "needs_answers",
|
|
14164
|
+
fieldIds: fields.map((field) => field.id),
|
|
14165
|
+
fields
|
|
14166
|
+
};
|
|
14167
|
+
}
|
|
14168
|
+
function applyApplicationAnswers(state, answers, now = Date.now()) {
|
|
14169
|
+
const answerByFieldId = new Map(answers.map((answer) => [answer.fieldId, answer]));
|
|
14170
|
+
const fields = state.fields.map((field) => {
|
|
14171
|
+
const answer = answerByFieldId.get(field.id);
|
|
14172
|
+
if (!answer) return field;
|
|
14173
|
+
return {
|
|
14174
|
+
...field,
|
|
14175
|
+
value: answer.value,
|
|
14176
|
+
source: answer.source ?? "user",
|
|
14177
|
+
confidence: answer.confidence ?? "confirmed",
|
|
14178
|
+
sourceSpanIds: answer.sourceSpanIds ?? field.sourceSpanIds,
|
|
14179
|
+
userSourceSpanIds: answer.userSourceSpanIds ?? field.userSourceSpanIds,
|
|
14180
|
+
validationStatus: "valid"
|
|
14181
|
+
};
|
|
14182
|
+
});
|
|
14183
|
+
const nextState = {
|
|
14184
|
+
...state,
|
|
14185
|
+
fields,
|
|
14186
|
+
updatedAt: now
|
|
14187
|
+
};
|
|
14188
|
+
const nextQuestions = planNextApplicationQuestions(nextState);
|
|
14189
|
+
return {
|
|
14190
|
+
...nextState,
|
|
14191
|
+
status: nextQuestions.status === "complete" ? "confirming" : nextState.status,
|
|
14192
|
+
qualityReport: buildApplicationQualityReport(nextState)
|
|
14193
|
+
};
|
|
14194
|
+
}
|
|
14195
|
+
function proposeContextWrites(state) {
|
|
14196
|
+
return getActiveApplicationFields(state).filter((field) => field.value && field.confidence && field.confidence !== "low").map((field) => ({
|
|
14197
|
+
id: `${state.id}:${field.id}:context`,
|
|
14198
|
+
fieldId: field.id,
|
|
14199
|
+
key: stableContextKey(field),
|
|
14200
|
+
value: field.value ?? "",
|
|
14201
|
+
category: field.section,
|
|
14202
|
+
source: field.source?.startsWith("lookup:") ? "lookup" : "application",
|
|
14203
|
+
confidence: field.confidence ?? "medium",
|
|
14204
|
+
sourceSpanIds: field.sourceSpanIds,
|
|
14205
|
+
userSourceSpanIds: field.userSourceSpanIds
|
|
14206
|
+
}));
|
|
14207
|
+
}
|
|
14208
|
+
function buildApplicationPacket(state, options = {}) {
|
|
14209
|
+
const qualityReport = buildApplicationQualityReport(state);
|
|
14210
|
+
const activeFields = getActiveApplicationFields(state);
|
|
14211
|
+
const answers = activeFields.filter((field) => field.value).map((field) => ({
|
|
14212
|
+
fieldId: field.id,
|
|
14213
|
+
label: field.label,
|
|
14214
|
+
section: field.section,
|
|
14215
|
+
value: field.value ?? "",
|
|
14216
|
+
source: field.source ?? "unknown",
|
|
14217
|
+
confidence: field.confidence,
|
|
14218
|
+
sourceSpanIds: field.sourceSpanIds,
|
|
14219
|
+
userSourceSpanIds: field.userSourceSpanIds
|
|
14220
|
+
}));
|
|
14221
|
+
const missingFieldIds = activeFields.filter((field) => field.required && !field.value).map((field) => field.id);
|
|
14222
|
+
return {
|
|
14223
|
+
id: `${state.id}:packet`,
|
|
14224
|
+
applicationId: state.id,
|
|
14225
|
+
title: state.title ?? state.applicationType ?? "Insurance Application",
|
|
14226
|
+
status: qualityReport.qualityGateStatus === "failed" || missingFieldIds.length > 0 ? "draft" : "broker_ready",
|
|
14227
|
+
answers,
|
|
14228
|
+
missingFieldIds,
|
|
14229
|
+
qualityReport,
|
|
14230
|
+
submissionNotes: options.submissionNotes,
|
|
14231
|
+
createdAt: options.now ?? Date.now()
|
|
14232
|
+
};
|
|
14233
|
+
}
|
|
14234
|
+
function validateApplicationPacket(packet) {
|
|
14235
|
+
const issues = [...packet.qualityReport.issues];
|
|
14236
|
+
if (packet.missingFieldIds.length > 0) {
|
|
14237
|
+
issues.push({
|
|
14238
|
+
code: "packet_missing_required_answers",
|
|
14239
|
+
severity: "blocking",
|
|
14240
|
+
message: "Packet still has required unanswered application fields."
|
|
14241
|
+
});
|
|
14242
|
+
}
|
|
14243
|
+
return {
|
|
14244
|
+
...packet.qualityReport,
|
|
14245
|
+
issues,
|
|
14246
|
+
qualityGateStatus: issues.some((issue) => issue.severity === "blocking") ? "failed" : packet.qualityReport.qualityGateStatus
|
|
14247
|
+
};
|
|
14248
|
+
}
|
|
14249
|
+
function stableContextKey(field) {
|
|
14250
|
+
return `${field.section}.${field.label}`.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
14251
|
+
}
|
|
14252
|
+
|
|
13859
14253
|
// src/application/coordinator.ts
|
|
13860
14254
|
function createApplicationPipeline(config) {
|
|
13861
14255
|
const {
|
|
13862
14256
|
generateText,
|
|
13863
14257
|
generateObject,
|
|
13864
14258
|
applicationStore,
|
|
14259
|
+
templateStore,
|
|
13865
14260
|
documentStore,
|
|
13866
14261
|
memoryStore,
|
|
13867
14262
|
backfillProvider,
|
|
@@ -13898,11 +14293,18 @@ function createApplicationPipeline(config) {
|
|
|
13898
14293
|
const applicationProviderOptions = input.sourceSpans?.length ? { ...providerOptions, sourceSpans: input.sourceSpans } : providerOptions;
|
|
13899
14294
|
const id = input.applicationId ?? `app-${Date.now()}`;
|
|
13900
14295
|
const now = Date.now();
|
|
14296
|
+
if (input.template) {
|
|
14297
|
+
await templateStore?.saveTemplate(input.template);
|
|
14298
|
+
}
|
|
13901
14299
|
let state = {
|
|
13902
14300
|
id,
|
|
14301
|
+
templateId: input.template?.id,
|
|
14302
|
+
templateVersion: input.template?.version,
|
|
14303
|
+
templateSnapshot: input.template,
|
|
13903
14304
|
pdfBase64: void 0,
|
|
13904
14305
|
title: void 0,
|
|
13905
14306
|
applicationType: null,
|
|
14307
|
+
questionGraph: input.questionGraph ?? input.template?.questionGraph,
|
|
13906
14308
|
fields: [],
|
|
13907
14309
|
qualityReport: void 0,
|
|
13908
14310
|
batches: void 0,
|
|
@@ -13962,6 +14364,12 @@ function createApplicationPipeline(config) {
|
|
|
13962
14364
|
return { state, tokenUsage: totalUsage, reviewReport: state.qualityReport };
|
|
13963
14365
|
}
|
|
13964
14366
|
state.fields = fields;
|
|
14367
|
+
state.questionGraph = input.questionGraph ?? input.template?.questionGraph ?? buildQuestionGraphFromFields(fields, {
|
|
14368
|
+
id: `${id}:graph`,
|
|
14369
|
+
title: classifyResult.applicationType ?? void 0,
|
|
14370
|
+
applicationType: classifyResult.applicationType,
|
|
14371
|
+
source: "pdf"
|
|
14372
|
+
});
|
|
13965
14373
|
state.title = classifyResult.applicationType ?? void 0;
|
|
13966
14374
|
state.status = "auto_filling";
|
|
13967
14375
|
state.updatedAt = Date.now();
|
|
@@ -13982,8 +14390,10 @@ function createApplicationPipeline(config) {
|
|
|
13982
14390
|
if (field && !field.value && pa.relevance > 0.8) {
|
|
13983
14391
|
field.value = pa.value;
|
|
13984
14392
|
field.source = `backfill: ${pa.source}`;
|
|
13985
|
-
field.confidence = "high";
|
|
13986
|
-
field.validationStatus = "needs_review";
|
|
14393
|
+
field.confidence = pa.confidence ?? "high";
|
|
14394
|
+
field.validationStatus = pa.sourceSpanIds?.length ? "valid" : "needs_review";
|
|
14395
|
+
field.sourceSpanIds = pa.sourceSpanIds;
|
|
14396
|
+
field.userSourceSpanIds = pa.userSourceSpanIds;
|
|
13987
14397
|
}
|
|
13988
14398
|
}
|
|
13989
14399
|
} catch (e) {
|
|
@@ -14033,7 +14443,18 @@ function createApplicationPipeline(config) {
|
|
|
14033
14443
|
try {
|
|
14034
14444
|
const searchPromises = workflowPlan.documentSearchFields.map(
|
|
14035
14445
|
(f) => limit(async () => {
|
|
14036
|
-
await memoryStore.search(f.label
|
|
14446
|
+
const chunks = await memoryStore.search(`${f.section} ${f.label}`, { limit: 3 });
|
|
14447
|
+
const match = selectMemoryBackfillMatch(f, chunks);
|
|
14448
|
+
if (match) {
|
|
14449
|
+
const field = state.fields.find((candidate) => candidate.id === f.id);
|
|
14450
|
+
if (field && !field.value) {
|
|
14451
|
+
field.value = match.value;
|
|
14452
|
+
field.source = match.source;
|
|
14453
|
+
field.confidence = match.confidence;
|
|
14454
|
+
field.validationStatus = match.sourceSpanIds.length > 0 ? "valid" : "needs_review";
|
|
14455
|
+
field.sourceSpanIds = match.sourceSpanIds.length > 0 ? match.sourceSpanIds : void 0;
|
|
14456
|
+
}
|
|
14457
|
+
}
|
|
14037
14458
|
})
|
|
14038
14459
|
);
|
|
14039
14460
|
await Promise.all(searchPromises);
|
|
@@ -14053,7 +14474,7 @@ function createApplicationPipeline(config) {
|
|
|
14053
14474
|
hasDocumentStore: false,
|
|
14054
14475
|
hasMemoryStore: false
|
|
14055
14476
|
});
|
|
14056
|
-
const unfilledFields =
|
|
14477
|
+
const unfilledFields = getActiveApplicationFields(state).filter((field) => !field.value);
|
|
14057
14478
|
if (workflowPlan.runBatching) {
|
|
14058
14479
|
onProgress?.(`Batching ${unfilledFields.length} remaining questions...`);
|
|
14059
14480
|
state.status = "batching";
|
|
@@ -14075,6 +14496,7 @@ function createApplicationPipeline(config) {
|
|
|
14075
14496
|
} else {
|
|
14076
14497
|
state.status = "confirming";
|
|
14077
14498
|
}
|
|
14499
|
+
state.contextProposals = proposeContextWrites(state);
|
|
14078
14500
|
state.qualityReport = buildApplicationQualityReport(state);
|
|
14079
14501
|
state.updatedAt = Date.now();
|
|
14080
14502
|
await applicationStore?.save(state);
|
|
@@ -14102,7 +14524,8 @@ function createApplicationPipeline(config) {
|
|
|
14102
14524
|
throw new Error(`Application ${applicationId} not found`);
|
|
14103
14525
|
}
|
|
14104
14526
|
const currentBatchFieldIds = state.batches?.[state.currentBatchIndex] ?? [];
|
|
14105
|
-
const
|
|
14527
|
+
const activeFields = getActiveApplicationFields(state);
|
|
14528
|
+
const currentBatchFields = activeFields.filter(
|
|
14106
14529
|
(f) => currentBatchFieldIds.includes(f.id)
|
|
14107
14530
|
);
|
|
14108
14531
|
onProgress?.("Classifying reply...");
|
|
@@ -14225,14 +14648,16 @@ Provide a brief, helpful explanation (2-3 sentences). End with "Just reply with
|
|
|
14225
14648
|
responseText = `I wasn't able to generate an explanation for your question. Could you rephrase it, or just provide the answer directly?`;
|
|
14226
14649
|
}
|
|
14227
14650
|
}
|
|
14228
|
-
const
|
|
14651
|
+
const activeCurrentBatchFieldIds = currentBatchFields.map((field) => field.id);
|
|
14652
|
+
const currentBatchComplete = activeCurrentBatchFieldIds.every(
|
|
14229
14653
|
(fid) => state.fields.find((f) => f.id === fid)?.value
|
|
14230
14654
|
);
|
|
14231
14655
|
let nextBatchIndex;
|
|
14232
14656
|
let nextBatchFields;
|
|
14233
14657
|
if (state.batches) {
|
|
14234
14658
|
for (let index = state.currentBatchIndex + 1; index < state.batches.length; index++) {
|
|
14235
|
-
const
|
|
14659
|
+
const activeCandidateFields = getActiveApplicationFields(state);
|
|
14660
|
+
const candidateFields = activeCandidateFields.filter((f) => state.batches[index].includes(f.id));
|
|
14236
14661
|
if (candidateFields.some((f) => !f.value)) {
|
|
14237
14662
|
nextBatchIndex = index;
|
|
14238
14663
|
nextBatchFields = candidateFields;
|
|
@@ -14288,7 +14713,8 @@ ${emailText}`;
|
|
|
14288
14713
|
}
|
|
14289
14714
|
}
|
|
14290
14715
|
state.updatedAt = Date.now();
|
|
14291
|
-
state.
|
|
14716
|
+
state.contextProposals = proposeContextWrites(state);
|
|
14717
|
+
state.qualityReport = buildApplicationQualityReport(state);
|
|
14292
14718
|
await applicationStore?.save(state);
|
|
14293
14719
|
if (shouldFailQualityGate(qualityGate, state.qualityReport.qualityGateStatus)) {
|
|
14294
14720
|
throw new Error("Application quality gate failed. See state.qualityReport for blocking issues.");
|
|
@@ -14308,7 +14734,7 @@ ${emailText}`;
|
|
|
14308
14734
|
if (!state) throw new Error(`Application ${applicationId} not found`);
|
|
14309
14735
|
if (!state.batches?.length) throw new Error("No batches available");
|
|
14310
14736
|
const batchFieldIds = state.batches[state.currentBatchIndex];
|
|
14311
|
-
const batchFields = state.
|
|
14737
|
+
const batchFields = getActiveApplicationFields(state).filter((f) => batchFieldIds.includes(f.id));
|
|
14312
14738
|
const filledCount = state.fields.filter((f) => f.value).length;
|
|
14313
14739
|
const { text, usage } = await generateBatchEmail(
|
|
14314
14740
|
batchFields,
|
|
@@ -14356,13 +14782,86 @@ ${fieldSummary}`,
|
|
|
14356
14782
|
trackUsage(usage);
|
|
14357
14783
|
return { text, tokenUsage: totalUsage };
|
|
14358
14784
|
}
|
|
14785
|
+
async function createApplicationRun2(input) {
|
|
14786
|
+
const state = createApplicationRun(input);
|
|
14787
|
+
await applicationStore?.save(state);
|
|
14788
|
+
return state;
|
|
14789
|
+
}
|
|
14790
|
+
async function planNextQuestions(applicationId, limit2) {
|
|
14791
|
+
const state = await applicationStore?.get(applicationId);
|
|
14792
|
+
if (!state) throw new Error(`Application ${applicationId} not found`);
|
|
14793
|
+
return planNextApplicationQuestions(state, limit2);
|
|
14794
|
+
}
|
|
14795
|
+
async function proposeContextWrites2(applicationId) {
|
|
14796
|
+
const state = await applicationStore?.get(applicationId);
|
|
14797
|
+
if (!state) throw new Error(`Application ${applicationId} not found`);
|
|
14798
|
+
const proposals = proposeContextWrites(state);
|
|
14799
|
+
await applicationStore?.save({
|
|
14800
|
+
...state,
|
|
14801
|
+
contextProposals: proposals,
|
|
14802
|
+
updatedAt: Date.now()
|
|
14803
|
+
});
|
|
14804
|
+
return { proposals };
|
|
14805
|
+
}
|
|
14806
|
+
async function buildApplicationPacket2(input) {
|
|
14807
|
+
const state = await applicationStore?.get(input.applicationId);
|
|
14808
|
+
if (!state) throw new Error(`Application ${input.applicationId} not found`);
|
|
14809
|
+
const packet = buildApplicationPacket(state, {
|
|
14810
|
+
submissionNotes: input.submissionNotes,
|
|
14811
|
+
now: input.now
|
|
14812
|
+
});
|
|
14813
|
+
const reviewReport = validateApplicationPacket(packet);
|
|
14814
|
+
await applicationStore?.save({
|
|
14815
|
+
...state,
|
|
14816
|
+
packet: { ...packet, qualityReport: reviewReport },
|
|
14817
|
+
status: reviewReport.qualityGateStatus === "failed" ? "broker_review" : "packet_ready",
|
|
14818
|
+
qualityReport: reviewReport,
|
|
14819
|
+
updatedAt: Date.now()
|
|
14820
|
+
});
|
|
14821
|
+
return { packet: { ...packet, qualityReport: reviewReport }, reviewReport };
|
|
14822
|
+
}
|
|
14359
14823
|
return {
|
|
14360
14824
|
processApplication,
|
|
14361
14825
|
processReply: processReply2,
|
|
14362
14826
|
generateCurrentBatchEmail,
|
|
14363
|
-
getConfirmationSummary
|
|
14827
|
+
getConfirmationSummary,
|
|
14828
|
+
createApplicationRun: createApplicationRun2,
|
|
14829
|
+
planNextQuestions,
|
|
14830
|
+
proposeContextWrites: proposeContextWrites2,
|
|
14831
|
+
buildApplicationPacket: buildApplicationPacket2
|
|
14364
14832
|
};
|
|
14365
14833
|
}
|
|
14834
|
+
function selectMemoryBackfillMatch(field, chunks) {
|
|
14835
|
+
for (const chunk of chunks) {
|
|
14836
|
+
const value = chunk.metadata.value ?? chunk.metadata.answer ?? chunk.metadata.fieldValue;
|
|
14837
|
+
if (!value) continue;
|
|
14838
|
+
const metadataFieldId = chunk.metadata.fieldId ?? chunk.metadata.applicationFieldId;
|
|
14839
|
+
const metadataLabel = chunk.metadata.fieldLabel?.toLowerCase();
|
|
14840
|
+
const labelMatches = metadataLabel === field.label.toLowerCase();
|
|
14841
|
+
if (metadataFieldId && metadataFieldId !== field.id && !labelMatches) continue;
|
|
14842
|
+
return {
|
|
14843
|
+
value,
|
|
14844
|
+
source: chunk.metadata.source ?? `memory: ${chunk.documentId}`,
|
|
14845
|
+
confidence: metadataFieldId === field.id || labelMatches ? "high" : "medium",
|
|
14846
|
+
sourceSpanIds: parseSourceSpanIds(chunk.metadata.sourceSpanIds)
|
|
14847
|
+
};
|
|
14848
|
+
}
|
|
14849
|
+
return null;
|
|
14850
|
+
}
|
|
14851
|
+
function parseSourceSpanIds(value) {
|
|
14852
|
+
if (!value) return [];
|
|
14853
|
+
const trimmed = value.trim();
|
|
14854
|
+
if (!trimmed) return [];
|
|
14855
|
+
if (trimmed.startsWith("[")) {
|
|
14856
|
+
try {
|
|
14857
|
+
const parsed = JSON.parse(trimmed);
|
|
14858
|
+
return Array.isArray(parsed) ? parsed.filter((item) => typeof item === "string") : [];
|
|
14859
|
+
} catch {
|
|
14860
|
+
return [];
|
|
14861
|
+
}
|
|
14862
|
+
}
|
|
14863
|
+
return trimmed.split(",").map((item) => item.trim()).filter(Boolean);
|
|
14864
|
+
}
|
|
14366
14865
|
|
|
14367
14866
|
// src/prompts/application/confirmation.ts
|
|
14368
14867
|
function buildConfirmationSummaryPrompt(fields, applicationTitle) {
|
|
@@ -16443,13 +16942,21 @@ var AGENT_TOOLS = [
|
|
|
16443
16942
|
AgenticExecutionModeSchema,
|
|
16444
16943
|
AnswerParsingResultSchema,
|
|
16445
16944
|
ApplicationClassifyResultSchema,
|
|
16945
|
+
ApplicationContextProposalSchema,
|
|
16446
16946
|
ApplicationEmailReviewSchema,
|
|
16447
16947
|
ApplicationFieldSchema,
|
|
16948
|
+
ApplicationPacketAnswerSchema,
|
|
16949
|
+
ApplicationPacketSchema,
|
|
16448
16950
|
ApplicationQualityArtifactSchema,
|
|
16449
16951
|
ApplicationQualityIssueSchema,
|
|
16450
16952
|
ApplicationQualityReportSchema,
|
|
16451
16953
|
ApplicationQualityRoundSchema,
|
|
16954
|
+
ApplicationQuestionConditionSchema,
|
|
16955
|
+
ApplicationQuestionGraphSchema,
|
|
16956
|
+
ApplicationQuestionNodeSchema,
|
|
16957
|
+
ApplicationRepeatSchema,
|
|
16452
16958
|
ApplicationStateSchema,
|
|
16959
|
+
ApplicationTemplateSchema,
|
|
16453
16960
|
AttachmentInterpretationSchema,
|
|
16454
16961
|
AuditTypeSchema,
|
|
16455
16962
|
AutoFillMatchSchema,
|
|
@@ -16664,9 +17171,11 @@ var AGENT_TOOLS = [
|
|
|
16664
17171
|
VerifyResultSchema,
|
|
16665
17172
|
WatercraftDeclarationsSchema,
|
|
16666
17173
|
WorkersCompDeclarationsSchema,
|
|
17174
|
+
applyApplicationAnswers,
|
|
16667
17175
|
buildAcroFormMappingPrompt,
|
|
16668
17176
|
buildAgentSystemPrompt,
|
|
16669
17177
|
buildAnswerParsingPrompt,
|
|
17178
|
+
buildApplicationPacket,
|
|
16670
17179
|
buildAutoFillPrompt,
|
|
16671
17180
|
buildBatchEmailGenerationPrompt,
|
|
16672
17181
|
buildClassifyMessagePrompt,
|
|
@@ -16693,6 +17202,7 @@ var AGENT_TOOLS = [
|
|
|
16693
17202
|
buildPdfProviderOptions,
|
|
16694
17203
|
buildQueryClassifyPrompt,
|
|
16695
17204
|
buildQuestionBatchPrompt,
|
|
17205
|
+
buildQuestionGraphFromFields,
|
|
16696
17206
|
buildQuotesPoliciesPrompt,
|
|
16697
17207
|
buildReasonPrompt,
|
|
16698
17208
|
buildReplyIntentClassificationPrompt,
|
|
@@ -16708,6 +17218,7 @@ var AGENT_TOOLS = [
|
|
|
16708
17218
|
collectPceEvidenceSources,
|
|
16709
17219
|
compareSourceEvidence,
|
|
16710
17220
|
createApplicationPipeline,
|
|
17221
|
+
createApplicationRun,
|
|
16711
17222
|
createExtractor,
|
|
16712
17223
|
createPceAgent,
|
|
16713
17224
|
createPipelineContext,
|
|
@@ -16715,12 +17226,16 @@ var AGENT_TOOLS = [
|
|
|
16715
17226
|
evaluateCaseProposals,
|
|
16716
17227
|
evidenceContainsQuote,
|
|
16717
17228
|
extractPageRange,
|
|
17229
|
+
extractQuestionGraphFromFields,
|
|
16718
17230
|
fillAcroForm,
|
|
17231
|
+
flattenQuestionGraph,
|
|
16719
17232
|
generateNextMessage,
|
|
16720
17233
|
getAcroFormFields,
|
|
17234
|
+
getActiveApplicationFields,
|
|
16721
17235
|
getDoclingPageRangeText,
|
|
16722
17236
|
getExtractor,
|
|
16723
17237
|
getFileIdentifier,
|
|
17238
|
+
getNextApplicationQuestions,
|
|
16724
17239
|
getPdfPageCount,
|
|
16725
17240
|
getTemplate,
|
|
16726
17241
|
isDoclingExtractionInput,
|
|
@@ -16728,6 +17243,7 @@ var AGENT_TOOLS = [
|
|
|
16728
17243
|
mergeOperationalProfile,
|
|
16729
17244
|
mergeQuestionAnswers,
|
|
16730
17245
|
mergeSourceSpans,
|
|
17246
|
+
normalizeApplicationQuestionGraph,
|
|
16731
17247
|
normalizeDoclingDocument,
|
|
16732
17248
|
normalizeDocumentSourceTreePaths,
|
|
16733
17249
|
normalizeForMatch,
|
|
@@ -16737,7 +17253,9 @@ var AGENT_TOOLS = [
|
|
|
16737
17253
|
pLimit,
|
|
16738
17254
|
pdfInputToBase64,
|
|
16739
17255
|
pdfInputToBytes,
|
|
17256
|
+
planNextApplicationQuestions,
|
|
16740
17257
|
processReply,
|
|
17258
|
+
proposeContextWrites,
|
|
16741
17259
|
resolveModelBudget,
|
|
16742
17260
|
safeGenerateObject,
|
|
16743
17261
|
sanitizeNulls,
|
|
@@ -16750,6 +17268,7 @@ var AGENT_TOOLS = [
|
|
|
16750
17268
|
stableStringify,
|
|
16751
17269
|
stripFences,
|
|
16752
17270
|
toStrictSchema,
|
|
17271
|
+
validateApplicationPacket,
|
|
16753
17272
|
validateEvidence,
|
|
16754
17273
|
validatePceItems,
|
|
16755
17274
|
validateQuotedEvidence,
|