@claritylabs/cl-sdk 3.1.18 → 3.1.20

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.
@@ -1,6 +1,6 @@
1
1
  import { ZodSchema, z } from 'zod';
2
2
 
3
- type ModelTaskKind = "extraction_classify" | "extraction_source_tree" | "extraction_operational_profile" | "extraction_form_inventory" | "extraction_page_map" | "extraction_focused" | "extraction_long_list" | "extraction_referential_lookup" | "extraction_coverage_cleanup" | "extraction_review" | "extraction_summary" | "extraction_format" | "query_attachment" | "query_classify" | "query_reason" | "query_verify" | "query_respond" | "application_classify" | "application_extract_fields" | "application_auto_fill" | "application_lookup" | "application_parse_answers" | "application_batch" | "application_email" | "application_pdf_mapping" | "pce_impact_analysis" | "pce_reply_parse" | "pce_packet_generation";
3
+ type ModelTaskKind = "extraction_classify" | "extraction_source_tree" | "extraction_operational_profile" | "extraction_form_inventory" | "extraction_visual_table_repair" | "extraction_page_map" | "extraction_focused" | "extraction_long_list" | "extraction_referential_lookup" | "extraction_coverage_cleanup" | "extraction_review" | "extraction_summary" | "extraction_format" | "query_attachment" | "query_classify" | "query_reason" | "query_verify" | "query_respond" | "application_classify" | "application_extract_fields" | "application_auto_fill" | "application_lookup" | "application_parse_answers" | "application_batch" | "application_email" | "application_pdf_mapping" | "pce_impact_analysis" | "pce_reply_parse" | "pce_packet_generation";
4
4
  interface ModelCapabilities {
5
5
  /** Human-readable model identifier for diagnostics. */
6
6
  model?: string;
@@ -1,6 +1,6 @@
1
1
  import { ZodSchema, z } from 'zod';
2
2
 
3
- type ModelTaskKind = "extraction_classify" | "extraction_source_tree" | "extraction_operational_profile" | "extraction_form_inventory" | "extraction_page_map" | "extraction_focused" | "extraction_long_list" | "extraction_referential_lookup" | "extraction_coverage_cleanup" | "extraction_review" | "extraction_summary" | "extraction_format" | "query_attachment" | "query_classify" | "query_reason" | "query_verify" | "query_respond" | "application_classify" | "application_extract_fields" | "application_auto_fill" | "application_lookup" | "application_parse_answers" | "application_batch" | "application_email" | "application_pdf_mapping" | "pce_impact_analysis" | "pce_reply_parse" | "pce_packet_generation";
3
+ type ModelTaskKind = "extraction_classify" | "extraction_source_tree" | "extraction_operational_profile" | "extraction_form_inventory" | "extraction_visual_table_repair" | "extraction_page_map" | "extraction_focused" | "extraction_long_list" | "extraction_referential_lookup" | "extraction_coverage_cleanup" | "extraction_review" | "extraction_summary" | "extraction_format" | "query_attachment" | "query_classify" | "query_reason" | "query_verify" | "query_respond" | "application_classify" | "application_extract_fields" | "application_auto_fill" | "application_lookup" | "application_parse_answers" | "application_batch" | "application_email" | "application_pdf_mapping" | "pce_impact_analysis" | "pce_reply_parse" | "pce_packet_generation";
4
4
  interface ModelCapabilities {
5
5
  /** Human-readable model identifier for diagnostics. */
6
6
  model?: string;
package/dist/index.d.mts CHANGED
@@ -1,10 +1,14 @@
1
- import { L as LogFn, M as ModelTaskKind, a as ModelBudgetResolution, b as ModelCallTrace, G as GenerateObject, T as TokenUsage, S as SourceSpanLocation, c as SourceSpan, D as DocumentSourceNode, d as SourceKind, e as SourceSpanUnit, f as SourceSpanTableLocation, g as SourceChunk, h as SourceSpanBBox, U as UnifiedQualityReport, B as BaseQualityIssue, Q as QualityGateStatus, I as InsuranceDocument, P as PdfInput, i as DocumentChunk, j as PolicyOperationalProfile, k as PerformanceReport, l as GenerateText, C as ConvertPdfToImagesFn, m as QualityGateMode, n as ModelCapabilities, o as ModelBudgetConstraint, A as AgentContext, p as DocumentStore, q as MemoryStore, r as Platform } from './index-q8LQXen9.mjs';
2
- export { s as AcroFormMapping, t as AcroFormMappingSchema, u as AnswerParsingResult, v as AnswerParsingResultSchema, w as ApplicationClassifyResult, x as ApplicationClassifyResultSchema, y as ApplicationContextProposal, z as ApplicationContextProposalSchema, E as ApplicationEmailReviewSchema, F as ApplicationField, H as ApplicationFieldSchema, J as ApplicationListFilters, K as ApplicationNextQuestions, N as ApplicationPacket, O as ApplicationPacketAnswer, R as ApplicationPacketAnswerSchema, V as ApplicationPacketSchema, W as ApplicationPipelineConfig, X as ApplicationQualityArtifactSchema, Y as ApplicationQualityIssueSchema, Z as ApplicationQualityReportSchema, _ as ApplicationQualityRoundSchema, $ as ApplicationQuestionCondition, a0 as ApplicationQuestionConditionSchema, a1 as ApplicationQuestionGraph, a2 as ApplicationQuestionGraphSchema, a3 as ApplicationQuestionNode, a4 as ApplicationQuestionNodeSchema, a5 as ApplicationRepeat, a6 as ApplicationRepeatSchema, a7 as ApplicationState, a8 as ApplicationStateSchema, a9 as ApplicationStore, aa as ApplicationTemplate, ab as ApplicationTemplateListFilters, ac as ApplicationTemplateSchema, ad as ApplicationTemplateStore, ae as AutoFillMatch, af as AutoFillMatchSchema, ag as AutoFillResult, ah as AutoFillResultSchema, ai as AuxiliaryFact, aj as AuxiliaryFactSchema, ak as BackfillProvider, al as BuildApplicationPacketInput, am as BuildApplicationPacketResult, an as ChunkFilter, ao as CommunicationIntent, ap as CommunicationIntentSchema, aq as ContextProposalResult, ar as ConversationTurn, as as CoveredReason, at as CoveredReasonSchema, au as CreateApplicationRunInput, av as Definition, aw as DefinitionSchema, ax as DocumentAgentGuidance, ay as DocumentAgentGuidanceSchema, az as DocumentFilters, aA as DocumentMetadata, aB as DocumentMetadataSchema, aC as DocumentNode, aD as DocumentNodeSchema, aE as DocumentPageMapEntry, aF as DocumentPageMapEntrySchema, aG as DocumentSourceNodeKind, aH as DocumentSourceNodeKindSchema, aI as DocumentSourceNodeSchema, aJ as DocumentTableOfContentsEntry, aK as DocumentTableOfContentsEntrySchema, aL as EmbedText, aM as FieldExtractionResult, aN as FieldExtractionResultSchema, aO as FieldType, aP as FieldTypeSchema, aQ as FlatPdfPlacement, aR as FlatPdfPlacementSchema, aS as InsuranceDocumentSchema, aT as LookupFill, aU as LookupFillResult, aV as LookupFillResultSchema, aW as LookupFillSchema, aX as LookupRequest, aY as LookupRequestSchema, aZ as ModelCallReport, a_ as OperationalCoverageLine, a$ as OperationalCoverageLineSchema, b0 as OperationalCoverageTerm, b1 as OperationalCoverageTermSchema, b2 as OperationalEndorsementSupport, b3 as OperationalEndorsementSupportSchema, b4 as OperationalParty, b5 as OperationalPartySchema, b6 as PLATFORM_CONFIGS, b7 as ParsedAnswer, b8 as ParsedAnswerSchema, b9 as PlatformConfig, ba as PlatformSchema, bb as PolicyDocument, bc as PolicyDocumentSchema, bd as PolicyOperationalProfileSchema, be as PremiumLine, bf as PremiumLineSchema, bg as PriorAnswer, bh as ProcessApplicationInput, bi as ProcessApplicationResult, bj as ProcessReplyInput, bk as ProcessReplyResult, bl as QuestionBatchResult, bm as QuestionBatchResultSchema, bn as QuoteDocument, bo as QuoteDocumentSchema, bp as ReplyIntent, bq as ReplyIntentSchema, br as ResolveModelBudgetParams, bs as Section, bt as SectionSchema, bu as SourceBackedValue, bv as SourceBackedValueSchema, bw as SourceChunkSchema, bx as SourceKindSchema, by as SourceSpanBBoxSchema, bz as SourceSpanKind, bA as SourceSpanKindSchema, bB as SourceSpanLocationSchema, bC as SourceSpanRef, bD as SourceSpanRefSchema, bE as SourceSpanSchema, bF as SourceSpanTableLocationSchema, bG as SourceSpanUnitSchema, bH as Subjectivity, bI as SubjectivitySchema, bJ as Subsection, bK as SubsectionSchema, bL as UnderwritingCondition, bM as UnderwritingConditionSchema, bN as applyApplicationAnswers, bO as buildApplicationPacket, bP as buildQuestionGraphFromFields, bQ as createApplicationPipeline, bR as createApplicationRun, bS as extractQuestionGraphFromFields, bT as flattenQuestionGraph, bU as getActiveApplicationFields, bV as getNextApplicationQuestions, bW as normalizeApplicationQuestionGraph, bX as planNextApplicationQuestions, bY as proposeContextWrites, bZ as resolveModelBudget, b_ as validateApplicationPacket } from './index-q8LQXen9.mjs';
1
+ import { L as LogFn, M as ModelTaskKind, a as ModelBudgetResolution, b as ModelCallTrace, G as GenerateObject, T as TokenUsage, S as SourceSpanLocation, c as SourceSpan, D as DocumentSourceNode, d as SourceKind, e as SourceSpanUnit, f as SourceSpanTableLocation, g as SourceChunk, h as SourceSpanBBox, U as UnifiedQualityReport, B as BaseQualityIssue, Q as QualityGateStatus, I as InsuranceDocument, P as PdfInput, i as DocumentChunk, j as PolicyOperationalProfile, k as PerformanceReport, l as GenerateText, C as ConvertPdfToImagesFn, m as QualityGateMode, n as ModelCapabilities, o as ModelBudgetConstraint, A as AgentContext, p as DocumentStore, q as MemoryStore, r as Platform } from './index-DUBsVEev.mjs';
2
+ export { s as AcroFormMapping, t as AcroFormMappingSchema, u as AnswerParsingResult, v as AnswerParsingResultSchema, w as ApplicationClassifyResult, x as ApplicationClassifyResultSchema, y as ApplicationContextProposal, z as ApplicationContextProposalSchema, E as ApplicationEmailReviewSchema, F as ApplicationField, H as ApplicationFieldSchema, J as ApplicationListFilters, K as ApplicationNextQuestions, N as ApplicationPacket, O as ApplicationPacketAnswer, R as ApplicationPacketAnswerSchema, V as ApplicationPacketSchema, W as ApplicationPipelineConfig, X as ApplicationQualityArtifactSchema, Y as ApplicationQualityIssueSchema, Z as ApplicationQualityReportSchema, _ as ApplicationQualityRoundSchema, $ as ApplicationQuestionCondition, a0 as ApplicationQuestionConditionSchema, a1 as ApplicationQuestionGraph, a2 as ApplicationQuestionGraphSchema, a3 as ApplicationQuestionNode, a4 as ApplicationQuestionNodeSchema, a5 as ApplicationRepeat, a6 as ApplicationRepeatSchema, a7 as ApplicationState, a8 as ApplicationStateSchema, a9 as ApplicationStore, aa as ApplicationTemplate, ab as ApplicationTemplateListFilters, ac as ApplicationTemplateSchema, ad as ApplicationTemplateStore, ae as AutoFillMatch, af as AutoFillMatchSchema, ag as AutoFillResult, ah as AutoFillResultSchema, ai as AuxiliaryFact, aj as AuxiliaryFactSchema, ak as BackfillProvider, al as BuildApplicationPacketInput, am as BuildApplicationPacketResult, an as ChunkFilter, ao as CommunicationIntent, ap as CommunicationIntentSchema, aq as ContextProposalResult, ar as ConversationTurn, as as CoveredReason, at as CoveredReasonSchema, au as CreateApplicationRunInput, av as Definition, aw as DefinitionSchema, ax as DocumentAgentGuidance, ay as DocumentAgentGuidanceSchema, az as DocumentFilters, aA as DocumentMetadata, aB as DocumentMetadataSchema, aC as DocumentNode, aD as DocumentNodeSchema, aE as DocumentPageMapEntry, aF as DocumentPageMapEntrySchema, aG as DocumentSourceNodeKind, aH as DocumentSourceNodeKindSchema, aI as DocumentSourceNodeSchema, aJ as DocumentTableOfContentsEntry, aK as DocumentTableOfContentsEntrySchema, aL as EmbedText, aM as FieldExtractionResult, aN as FieldExtractionResultSchema, aO as FieldType, aP as FieldTypeSchema, aQ as FlatPdfPlacement, aR as FlatPdfPlacementSchema, aS as InsuranceDocumentSchema, aT as LookupFill, aU as LookupFillResult, aV as LookupFillResultSchema, aW as LookupFillSchema, aX as LookupRequest, aY as LookupRequestSchema, aZ as ModelCallReport, a_ as OperationalCoverageLine, a$ as OperationalCoverageLineSchema, b0 as OperationalCoverageTerm, b1 as OperationalCoverageTermSchema, b2 as OperationalEndorsementSupport, b3 as OperationalEndorsementSupportSchema, b4 as OperationalParty, b5 as OperationalPartySchema, b6 as PLATFORM_CONFIGS, b7 as ParsedAnswer, b8 as ParsedAnswerSchema, b9 as PlatformConfig, ba as PlatformSchema, bb as PolicyDocument, bc as PolicyDocumentSchema, bd as PolicyOperationalProfileSchema, be as PremiumLine, bf as PremiumLineSchema, bg as PriorAnswer, bh as ProcessApplicationInput, bi as ProcessApplicationResult, bj as ProcessReplyInput, bk as ProcessReplyResult, bl as QuestionBatchResult, bm as QuestionBatchResultSchema, bn as QuoteDocument, bo as QuoteDocumentSchema, bp as ReplyIntent, bq as ReplyIntentSchema, br as ResolveModelBudgetParams, bs as Section, bt as SectionSchema, bu as SourceBackedValue, bv as SourceBackedValueSchema, bw as SourceChunkSchema, bx as SourceKindSchema, by as SourceSpanBBoxSchema, bz as SourceSpanKind, bA as SourceSpanKindSchema, bB as SourceSpanLocationSchema, bC as SourceSpanRef, bD as SourceSpanRefSchema, bE as SourceSpanSchema, bF as SourceSpanTableLocationSchema, bG as SourceSpanUnitSchema, bH as Subjectivity, bI as SubjectivitySchema, bJ as Subsection, bK as SubsectionSchema, bL as UnderwritingCondition, bM as UnderwritingConditionSchema, bN as applyApplicationAnswers, bO as buildApplicationPacket, bP as buildQuestionGraphFromFields, bQ as createApplicationPipeline, bR as createApplicationRun, bS as extractQuestionGraphFromFields, bT as flattenQuestionGraph, bU as getActiveApplicationFields, bV as getNextApplicationQuestions, bW as normalizeApplicationQuestionGraph, bX as planNextApplicationQuestions, bY as proposeContextWrites, bZ as resolveModelBudget, b_ as validateApplicationPacket } from './index-DUBsVEev.mjs';
3
3
  import * as zod from 'zod';
4
4
  import { ZodTypeAny, z, ZodSchema } from 'zod';
5
5
  import { PDFDocument } from 'pdf-lib';
6
6
 
7
- declare function withRetry<T>(fn: () => Promise<T>, log?: LogFn): Promise<T>;
7
+ interface RetryOptions {
8
+ maxRetries?: number;
9
+ baseDelayMs?: number;
10
+ }
11
+ declare function withRetry<T>(fn: () => Promise<T>, log?: LogFn, options?: RetryOptions): Promise<T>;
8
12
 
9
13
  /**
10
14
  * Concurrency limiter — returns a function that wraps async tasks
@@ -31,6 +35,8 @@ interface SafeGenerateOptions<T> {
31
35
  onError?: (error: unknown, attempt: number) => void;
32
36
  /** Logger for pipeline status messages. */
33
37
  log?: LogFn;
38
+ /** Controls retryable provider-error backoff around the host callback. Use false when the host already owns fallback. */
39
+ retry?: RetryOptions | false;
34
40
  }
35
41
  interface SafeGenerateParams {
36
42
  prompt: string;
@@ -44,7 +50,7 @@ interface SafeGenerateParams {
44
50
  /**
45
51
  * Wraps a `generateObject` call with two layers of resilience:
46
52
  *
47
- * 1. Inner: `withRetry` handles 429 / rate-limit errors with exponential backoff
53
+ * 1. Inner: `withRetry` handles retryable provider errors with exponential backoff unless disabled.
48
54
  * 2. Outer: catches all other errors (schema validation, malformed JSON, transient API errors)
49
55
  * and retries up to `maxRetries` times. If all retries fail, returns `fallback` (if provided)
50
56
  * or re-throws.
package/dist/index.d.ts CHANGED
@@ -1,10 +1,14 @@
1
- import { L as LogFn, M as ModelTaskKind, a as ModelBudgetResolution, b as ModelCallTrace, G as GenerateObject, T as TokenUsage, S as SourceSpanLocation, c as SourceSpan, D as DocumentSourceNode, d as SourceKind, e as SourceSpanUnit, f as SourceSpanTableLocation, g as SourceChunk, h as SourceSpanBBox, U as UnifiedQualityReport, B as BaseQualityIssue, Q as QualityGateStatus, I as InsuranceDocument, P as PdfInput, i as DocumentChunk, j as PolicyOperationalProfile, k as PerformanceReport, l as GenerateText, C as ConvertPdfToImagesFn, m as QualityGateMode, n as ModelCapabilities, o as ModelBudgetConstraint, A as AgentContext, p as DocumentStore, q as MemoryStore, r as Platform } from './index-q8LQXen9.js';
2
- export { s as AcroFormMapping, t as AcroFormMappingSchema, u as AnswerParsingResult, v as AnswerParsingResultSchema, w as ApplicationClassifyResult, x as ApplicationClassifyResultSchema, y as ApplicationContextProposal, z as ApplicationContextProposalSchema, E as ApplicationEmailReviewSchema, F as ApplicationField, H as ApplicationFieldSchema, J as ApplicationListFilters, K as ApplicationNextQuestions, N as ApplicationPacket, O as ApplicationPacketAnswer, R as ApplicationPacketAnswerSchema, V as ApplicationPacketSchema, W as ApplicationPipelineConfig, X as ApplicationQualityArtifactSchema, Y as ApplicationQualityIssueSchema, Z as ApplicationQualityReportSchema, _ as ApplicationQualityRoundSchema, $ as ApplicationQuestionCondition, a0 as ApplicationQuestionConditionSchema, a1 as ApplicationQuestionGraph, a2 as ApplicationQuestionGraphSchema, a3 as ApplicationQuestionNode, a4 as ApplicationQuestionNodeSchema, a5 as ApplicationRepeat, a6 as ApplicationRepeatSchema, a7 as ApplicationState, a8 as ApplicationStateSchema, a9 as ApplicationStore, aa as ApplicationTemplate, ab as ApplicationTemplateListFilters, ac as ApplicationTemplateSchema, ad as ApplicationTemplateStore, ae as AutoFillMatch, af as AutoFillMatchSchema, ag as AutoFillResult, ah as AutoFillResultSchema, ai as AuxiliaryFact, aj as AuxiliaryFactSchema, ak as BackfillProvider, al as BuildApplicationPacketInput, am as BuildApplicationPacketResult, an as ChunkFilter, ao as CommunicationIntent, ap as CommunicationIntentSchema, aq as ContextProposalResult, ar as ConversationTurn, as as CoveredReason, at as CoveredReasonSchema, au as CreateApplicationRunInput, av as Definition, aw as DefinitionSchema, ax as DocumentAgentGuidance, ay as DocumentAgentGuidanceSchema, az as DocumentFilters, aA as DocumentMetadata, aB as DocumentMetadataSchema, aC as DocumentNode, aD as DocumentNodeSchema, aE as DocumentPageMapEntry, aF as DocumentPageMapEntrySchema, aG as DocumentSourceNodeKind, aH as DocumentSourceNodeKindSchema, aI as DocumentSourceNodeSchema, aJ as DocumentTableOfContentsEntry, aK as DocumentTableOfContentsEntrySchema, aL as EmbedText, aM as FieldExtractionResult, aN as FieldExtractionResultSchema, aO as FieldType, aP as FieldTypeSchema, aQ as FlatPdfPlacement, aR as FlatPdfPlacementSchema, aS as InsuranceDocumentSchema, aT as LookupFill, aU as LookupFillResult, aV as LookupFillResultSchema, aW as LookupFillSchema, aX as LookupRequest, aY as LookupRequestSchema, aZ as ModelCallReport, a_ as OperationalCoverageLine, a$ as OperationalCoverageLineSchema, b0 as OperationalCoverageTerm, b1 as OperationalCoverageTermSchema, b2 as OperationalEndorsementSupport, b3 as OperationalEndorsementSupportSchema, b4 as OperationalParty, b5 as OperationalPartySchema, b6 as PLATFORM_CONFIGS, b7 as ParsedAnswer, b8 as ParsedAnswerSchema, b9 as PlatformConfig, ba as PlatformSchema, bb as PolicyDocument, bc as PolicyDocumentSchema, bd as PolicyOperationalProfileSchema, be as PremiumLine, bf as PremiumLineSchema, bg as PriorAnswer, bh as ProcessApplicationInput, bi as ProcessApplicationResult, bj as ProcessReplyInput, bk as ProcessReplyResult, bl as QuestionBatchResult, bm as QuestionBatchResultSchema, bn as QuoteDocument, bo as QuoteDocumentSchema, bp as ReplyIntent, bq as ReplyIntentSchema, br as ResolveModelBudgetParams, bs as Section, bt as SectionSchema, bu as SourceBackedValue, bv as SourceBackedValueSchema, bw as SourceChunkSchema, bx as SourceKindSchema, by as SourceSpanBBoxSchema, bz as SourceSpanKind, bA as SourceSpanKindSchema, bB as SourceSpanLocationSchema, bC as SourceSpanRef, bD as SourceSpanRefSchema, bE as SourceSpanSchema, bF as SourceSpanTableLocationSchema, bG as SourceSpanUnitSchema, bH as Subjectivity, bI as SubjectivitySchema, bJ as Subsection, bK as SubsectionSchema, bL as UnderwritingCondition, bM as UnderwritingConditionSchema, bN as applyApplicationAnswers, bO as buildApplicationPacket, bP as buildQuestionGraphFromFields, bQ as createApplicationPipeline, bR as createApplicationRun, bS as extractQuestionGraphFromFields, bT as flattenQuestionGraph, bU as getActiveApplicationFields, bV as getNextApplicationQuestions, bW as normalizeApplicationQuestionGraph, bX as planNextApplicationQuestions, bY as proposeContextWrites, bZ as resolveModelBudget, b_ as validateApplicationPacket } from './index-q8LQXen9.js';
1
+ import { L as LogFn, M as ModelTaskKind, a as ModelBudgetResolution, b as ModelCallTrace, G as GenerateObject, T as TokenUsage, S as SourceSpanLocation, c as SourceSpan, D as DocumentSourceNode, d as SourceKind, e as SourceSpanUnit, f as SourceSpanTableLocation, g as SourceChunk, h as SourceSpanBBox, U as UnifiedQualityReport, B as BaseQualityIssue, Q as QualityGateStatus, I as InsuranceDocument, P as PdfInput, i as DocumentChunk, j as PolicyOperationalProfile, k as PerformanceReport, l as GenerateText, C as ConvertPdfToImagesFn, m as QualityGateMode, n as ModelCapabilities, o as ModelBudgetConstraint, A as AgentContext, p as DocumentStore, q as MemoryStore, r as Platform } from './index-DUBsVEev.js';
2
+ export { s as AcroFormMapping, t as AcroFormMappingSchema, u as AnswerParsingResult, v as AnswerParsingResultSchema, w as ApplicationClassifyResult, x as ApplicationClassifyResultSchema, y as ApplicationContextProposal, z as ApplicationContextProposalSchema, E as ApplicationEmailReviewSchema, F as ApplicationField, H as ApplicationFieldSchema, J as ApplicationListFilters, K as ApplicationNextQuestions, N as ApplicationPacket, O as ApplicationPacketAnswer, R as ApplicationPacketAnswerSchema, V as ApplicationPacketSchema, W as ApplicationPipelineConfig, X as ApplicationQualityArtifactSchema, Y as ApplicationQualityIssueSchema, Z as ApplicationQualityReportSchema, _ as ApplicationQualityRoundSchema, $ as ApplicationQuestionCondition, a0 as ApplicationQuestionConditionSchema, a1 as ApplicationQuestionGraph, a2 as ApplicationQuestionGraphSchema, a3 as ApplicationQuestionNode, a4 as ApplicationQuestionNodeSchema, a5 as ApplicationRepeat, a6 as ApplicationRepeatSchema, a7 as ApplicationState, a8 as ApplicationStateSchema, a9 as ApplicationStore, aa as ApplicationTemplate, ab as ApplicationTemplateListFilters, ac as ApplicationTemplateSchema, ad as ApplicationTemplateStore, ae as AutoFillMatch, af as AutoFillMatchSchema, ag as AutoFillResult, ah as AutoFillResultSchema, ai as AuxiliaryFact, aj as AuxiliaryFactSchema, ak as BackfillProvider, al as BuildApplicationPacketInput, am as BuildApplicationPacketResult, an as ChunkFilter, ao as CommunicationIntent, ap as CommunicationIntentSchema, aq as ContextProposalResult, ar as ConversationTurn, as as CoveredReason, at as CoveredReasonSchema, au as CreateApplicationRunInput, av as Definition, aw as DefinitionSchema, ax as DocumentAgentGuidance, ay as DocumentAgentGuidanceSchema, az as DocumentFilters, aA as DocumentMetadata, aB as DocumentMetadataSchema, aC as DocumentNode, aD as DocumentNodeSchema, aE as DocumentPageMapEntry, aF as DocumentPageMapEntrySchema, aG as DocumentSourceNodeKind, aH as DocumentSourceNodeKindSchema, aI as DocumentSourceNodeSchema, aJ as DocumentTableOfContentsEntry, aK as DocumentTableOfContentsEntrySchema, aL as EmbedText, aM as FieldExtractionResult, aN as FieldExtractionResultSchema, aO as FieldType, aP as FieldTypeSchema, aQ as FlatPdfPlacement, aR as FlatPdfPlacementSchema, aS as InsuranceDocumentSchema, aT as LookupFill, aU as LookupFillResult, aV as LookupFillResultSchema, aW as LookupFillSchema, aX as LookupRequest, aY as LookupRequestSchema, aZ as ModelCallReport, a_ as OperationalCoverageLine, a$ as OperationalCoverageLineSchema, b0 as OperationalCoverageTerm, b1 as OperationalCoverageTermSchema, b2 as OperationalEndorsementSupport, b3 as OperationalEndorsementSupportSchema, b4 as OperationalParty, b5 as OperationalPartySchema, b6 as PLATFORM_CONFIGS, b7 as ParsedAnswer, b8 as ParsedAnswerSchema, b9 as PlatformConfig, ba as PlatformSchema, bb as PolicyDocument, bc as PolicyDocumentSchema, bd as PolicyOperationalProfileSchema, be as PremiumLine, bf as PremiumLineSchema, bg as PriorAnswer, bh as ProcessApplicationInput, bi as ProcessApplicationResult, bj as ProcessReplyInput, bk as ProcessReplyResult, bl as QuestionBatchResult, bm as QuestionBatchResultSchema, bn as QuoteDocument, bo as QuoteDocumentSchema, bp as ReplyIntent, bq as ReplyIntentSchema, br as ResolveModelBudgetParams, bs as Section, bt as SectionSchema, bu as SourceBackedValue, bv as SourceBackedValueSchema, bw as SourceChunkSchema, bx as SourceKindSchema, by as SourceSpanBBoxSchema, bz as SourceSpanKind, bA as SourceSpanKindSchema, bB as SourceSpanLocationSchema, bC as SourceSpanRef, bD as SourceSpanRefSchema, bE as SourceSpanSchema, bF as SourceSpanTableLocationSchema, bG as SourceSpanUnitSchema, bH as Subjectivity, bI as SubjectivitySchema, bJ as Subsection, bK as SubsectionSchema, bL as UnderwritingCondition, bM as UnderwritingConditionSchema, bN as applyApplicationAnswers, bO as buildApplicationPacket, bP as buildQuestionGraphFromFields, bQ as createApplicationPipeline, bR as createApplicationRun, bS as extractQuestionGraphFromFields, bT as flattenQuestionGraph, bU as getActiveApplicationFields, bV as getNextApplicationQuestions, bW as normalizeApplicationQuestionGraph, bX as planNextApplicationQuestions, bY as proposeContextWrites, bZ as resolveModelBudget, b_ as validateApplicationPacket } from './index-DUBsVEev.js';
3
3
  import * as zod from 'zod';
4
4
  import { ZodTypeAny, z, ZodSchema } from 'zod';
5
5
  import { PDFDocument } from 'pdf-lib';
6
6
 
7
- declare function withRetry<T>(fn: () => Promise<T>, log?: LogFn): Promise<T>;
7
+ interface RetryOptions {
8
+ maxRetries?: number;
9
+ baseDelayMs?: number;
10
+ }
11
+ declare function withRetry<T>(fn: () => Promise<T>, log?: LogFn, options?: RetryOptions): Promise<T>;
8
12
 
9
13
  /**
10
14
  * Concurrency limiter — returns a function that wraps async tasks
@@ -31,6 +35,8 @@ interface SafeGenerateOptions<T> {
31
35
  onError?: (error: unknown, attempt: number) => void;
32
36
  /** Logger for pipeline status messages. */
33
37
  log?: LogFn;
38
+ /** Controls retryable provider-error backoff around the host callback. Use false when the host already owns fallback. */
39
+ retry?: RetryOptions | false;
34
40
  }
35
41
  interface SafeGenerateParams {
36
42
  prompt: string;
@@ -44,7 +50,7 @@ interface SafeGenerateParams {
44
50
  /**
45
51
  * Wraps a `generateObject` call with two layers of resilience:
46
52
  *
47
- * 1. Inner: `withRetry` handles 429 / rate-limit errors with exponential backoff
53
+ * 1. Inner: `withRetry` handles retryable provider errors with exponential backoff unless disabled.
48
54
  * 2. Outer: catches all other errors (schema validation, malformed JSON, transient API errors)
49
55
  * and retries up to `maxRetries` times. If all retries fail, returns `fallback` (if provided)
50
56
  * or re-throws.
package/dist/index.js CHANGED
@@ -396,17 +396,19 @@ function isRetryableError(error) {
396
396
  }
397
397
  return false;
398
398
  }
399
- async function withRetry(fn, log) {
399
+ async function withRetry(fn, log, options) {
400
+ const maxRetries = options?.maxRetries ?? MAX_RETRIES;
401
+ const baseDelayMs = options?.baseDelayMs ?? BASE_DELAY_MS;
400
402
  for (let attempt = 0; ; attempt++) {
401
403
  try {
402
404
  return await fn();
403
405
  } catch (error) {
404
- if (!isRetryableError(error) || attempt >= MAX_RETRIES) {
406
+ if (!isRetryableError(error) || attempt >= maxRetries) {
405
407
  throw error;
406
408
  }
407
409
  const jitter = Math.random() * 1e3;
408
- const delay = BASE_DELAY_MS * Math.pow(2, attempt) + jitter;
409
- await log?.(`Retryable error, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${MAX_RETRIES})...`);
410
+ const delay = baseDelayMs * Math.pow(2, attempt) + jitter;
411
+ await log?.(`Retryable error, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${maxRetries})...`);
410
412
  await new Promise((resolve) => setTimeout(resolve, delay));
411
413
  }
412
414
  }
@@ -533,10 +535,8 @@ async function safeGenerateObject(generateObject, params, options) {
533
535
  const strictParams = { ...params, schema: toStrictSchema(params.schema) };
534
536
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
535
537
  try {
536
- const result = await withRetry(
537
- () => generateObject(strictParams),
538
- options?.log
539
- );
538
+ const generate = () => generateObject(strictParams);
539
+ const result = options?.retry === false ? await generate() : await withRetry(generate, options?.log, options?.retry);
540
540
  return {
541
541
  ...result,
542
542
  object: params.schema.parse(sanitizeNulls(result.object))
@@ -10129,6 +10129,12 @@ function endorsementDescription(title, node) {
10129
10129
  title
10130
10130
  );
10131
10131
  }
10132
+ function endorsementTitleKey(node) {
10133
+ const title = endorsementTitle(sourceNodeText(node));
10134
+ if (title) return title.toLowerCase();
10135
+ const fallback = cleanText(node.title, "");
10136
+ return fallback ? fallback.toLowerCase() : void 0;
10137
+ }
10132
10138
  function nodePageEnd2(node) {
10133
10139
  return node.pageEnd ?? node.pageStart;
10134
10140
  }
@@ -11050,7 +11056,76 @@ function applyEndorsementGrouping(sourceTree) {
11050
11056
  (node) => endorsementGroupChildIds.has(node.id) ? { ...node, parentId: groupId, order: node.order + 1e-3 } : node
11051
11057
  );
11052
11058
  }
11053
- return normalizeSemanticHierarchy(nextTree);
11059
+ return collapseNestedDuplicateEndorsements(normalizeSemanticHierarchy(nextTree));
11060
+ }
11061
+ function nearestEndorsementAncestor(node, byId) {
11062
+ let parentId = node.parentId;
11063
+ const seen = /* @__PURE__ */ new Set();
11064
+ while (parentId) {
11065
+ if (seen.has(parentId)) return void 0;
11066
+ seen.add(parentId);
11067
+ const parent = byId.get(parentId);
11068
+ if (!parent) return void 0;
11069
+ if (parent.kind === "endorsement") return parent;
11070
+ parentId = parent.parentId;
11071
+ }
11072
+ return void 0;
11073
+ }
11074
+ function collapseNestedDuplicateEndorsements(sourceTree) {
11075
+ const byId = new Map(sourceTree.map((node) => [node.id, node]));
11076
+ const replacementById = /* @__PURE__ */ new Map();
11077
+ const duplicateEvidenceByTarget = /* @__PURE__ */ new Map();
11078
+ for (const node of sourceTree) {
11079
+ if (node.kind !== "endorsement") continue;
11080
+ const ancestor = nearestEndorsementAncestor(node, byId);
11081
+ if (!ancestor) continue;
11082
+ if (endorsementTitleKey(node) !== endorsementTitleKey(ancestor)) continue;
11083
+ replacementById.set(node.id, ancestor.id);
11084
+ duplicateEvidenceByTarget.set(ancestor.id, [
11085
+ ...duplicateEvidenceByTarget.get(ancestor.id) ?? [],
11086
+ node
11087
+ ]);
11088
+ }
11089
+ if (replacementById.size === 0) return sourceTree;
11090
+ const replacementParent = (parentId) => {
11091
+ let next = parentId;
11092
+ const seen = /* @__PURE__ */ new Set();
11093
+ while (next && replacementById.has(next) && !seen.has(next)) {
11094
+ seen.add(next);
11095
+ next = replacementById.get(next);
11096
+ }
11097
+ return next;
11098
+ };
11099
+ const updated = sourceTree.filter((node) => !replacementById.has(node.id)).map((node) => {
11100
+ const evidence = duplicateEvidenceByTarget.get(node.id);
11101
+ const parentId = replacementParent(node.parentId);
11102
+ if (!evidence?.length) {
11103
+ return parentId === node.parentId ? node : {
11104
+ ...node,
11105
+ parentId,
11106
+ metadata: {
11107
+ ...node.metadata,
11108
+ organizerRepair: "collapse_duplicate_endorsement_wrapper"
11109
+ }
11110
+ };
11111
+ }
11112
+ const evidenceNodes = [node, ...evidence];
11113
+ const pageStarts = evidenceNodes.map((item) => item.pageStart).filter((page) => typeof page === "number");
11114
+ const pageEnds = evidenceNodes.map((item) => item.pageEnd ?? item.pageStart).filter((page) => typeof page === "number");
11115
+ return {
11116
+ ...node,
11117
+ parentId,
11118
+ sourceSpanIds: [...new Set(evidenceNodes.flatMap((item) => item.sourceSpanIds))],
11119
+ pageStart: pageStarts.length ? Math.min(...pageStarts) : node.pageStart,
11120
+ pageEnd: pageEnds.length ? Math.max(...pageEnds) : node.pageEnd,
11121
+ bbox: evidenceNodes.flatMap((item) => item.bbox ?? []).slice(0, 12),
11122
+ metadata: {
11123
+ ...node.metadata,
11124
+ organizerRepair: "collapse_duplicate_endorsement_wrapper"
11125
+ }
11126
+ };
11127
+ });
11128
+ return normalizeDocumentSourceTreePaths(normalizeContainerEvidenceFromChildren(updated));
11054
11129
  }
11055
11130
  function compactNode2(node, maxText = 700) {
11056
11131
  return {
@@ -11249,9 +11324,13 @@ Rules:
11249
11324
  - Every returned value must include sourceNodeIds or sourceSpanIds from the provided nodes.
11250
11325
  - If a value is not directly supported, omit it.
11251
11326
  - Prefer declarations, schedules, premium tables, and endorsement schedules over generic policy wording.
11327
+ - Keep each coverage unit tied to one evidence scope: a declaration/core schedule row, a core policy form section, or one specific endorsement schedule. Do not merge declaration facts and endorsement schedule facts into the same coverage unit, even when they use the same coverage name.
11328
+ - If the declarations schedule and an endorsement schedule both list Network Security, Social Engineering Fraud, Regulatory Proceedings, or another same-named coverage, return separate coverage units for each supported source scope.
11329
+ - Use the declaration coverage name for declaration/core schedule rows. Use the endorsement title or endorsement schedule coverage name for endorsement rows, and include formNumber and endorsementNumber when source-backed.
11252
11330
  - For life, critical illness, disability, and long-term care policies, keep named benefit units and benefit subconditions as operational facts even when they do not have dollar limits. Examples include death benefit, disability benefit, total disability, catastrophic disability, return of premium, waiver, and conversion options. Put subcondition details in coverages[].limits with kind "other" when they belong under a broader benefit.
11253
11331
  - Treat an endorsement as one coverage unit when it contains a schedule. Do not split an endorsement schedule into generic rows like "Aggregate Limit".
11254
11332
  - For coverage schedules, put each claim, aggregate, sublimit, retention, deductible, and retroactive date values in coverages[].limits with labels and source IDs. Keep the legacy coverages[].limit as the primary display value only.
11333
+ - Extract coinsurance, participation percentage, or insurer/named-insured split terms as coverages[].limits entries with kind "other" when they are part of a coverage schedule.
11255
11334
  - Use coverageOrigin: "endorsement" for endorsement units and "core" for declarations/core policy coverage units.
11256
11335
  - Do not copy entire policy wording into fields.
11257
11336
  - Extract facts directly from source nodes. There is no deterministic fact baseline.
@@ -11509,6 +11588,26 @@ function findCellByVisualPosition(sourceCell, targetCells) {
11509
11588
  );
11510
11589
  return positioned[0]?.cell;
11511
11590
  }
11591
+ function isDateLikeColumn(label) {
11592
+ return /\b(?:date|effective|expiration|retroactive)\b/i.test(cleanText(label, ""));
11593
+ }
11594
+ function containsDateValue(text) {
11595
+ return /\b\d{1,2}[/-]\d{1,2}[/-]\d{2,4}\b/.test(text) || /\b(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\.?\s+\d{1,2},?\s+\d{2,4}\b/i.test(text);
11596
+ }
11597
+ function looksLikePolicyProse(text) {
11598
+ const words = text.split(/\s+/).filter(Boolean);
11599
+ if (words.length < 8) return false;
11600
+ return /\b(?:are|is|will|shall|must|may|includes?|included|reduce|subject|payment|terms?|conditions?|provided|pursuant)\b/i.test(text);
11601
+ }
11602
+ function shouldMergeVisualContinuation(params) {
11603
+ if (startsNewVisualTableItem(params.sourceCells)) return false;
11604
+ const targetLabel = params.targetCell?.title;
11605
+ if (isDateLikeColumn(targetLabel) && !containsDateValue(params.sourceText)) return false;
11606
+ if (looksLikePolicyProse(params.sourceText) && !/\b(?:description|coverage|remarks?|notes?)\b/i.test(cleanText(targetLabel, ""))) {
11607
+ return false;
11608
+ }
11609
+ return true;
11610
+ }
11512
11611
  function columnLabelStartIndex(rows) {
11513
11612
  const headerIndex = rows.findIndex(
11514
11613
  ({ row, cells }) => isSourceTreeHeaderRow(row) && cells.length > 1
@@ -11658,6 +11757,7 @@ function applyVisualTableRepair(sourceTree, repair) {
11658
11757
  targetColumnIndex: continuation.targetColumnIndex,
11659
11758
  targetColumnLabel: continuation.targetColumnLabel
11660
11759
  });
11760
+ if (!shouldMergeVisualContinuation({ sourceText, sourceCells, targetCell })) continue;
11661
11761
  const sourceNodes = [sourceRow, ...sourceCells];
11662
11762
  const sourceSpanIds = sourceSpanIdsForNodes(sourceNodes);
11663
11763
  let mergedIntoCells = false;
@@ -11760,7 +11860,7 @@ async function runVisualTableRepair(params) {
11760
11860
  const repairResults = await Promise.all(candidates.map(async (candidate, index) => {
11761
11861
  const label = `source_tree_visual_table_repair_p${candidate.page}`;
11762
11862
  try {
11763
- const budget = params.resolveBudget("extraction_source_tree", 1800);
11863
+ const budget = params.resolveBudget("extraction_visual_table_repair", 1800);
11764
11864
  const maxTokens = Math.min(budget.maxTokens, 2400);
11765
11865
  const startedAt = Date.now();
11766
11866
  const response = await safeGenerateObject(
@@ -11769,7 +11869,7 @@ async function runVisualTableRepair(params) {
11769
11869
  prompt: buildVisualTableRepairPrompt(candidate),
11770
11870
  schema: SourceTreeVisualTableRepairSchema,
11771
11871
  maxTokens,
11772
- taskKind: "extraction_source_tree",
11872
+ taskKind: "extraction_visual_table_repair",
11773
11873
  budgetDiagnostics: { ...budget, maxTokens },
11774
11874
  trace: {
11775
11875
  label,
@@ -11782,7 +11882,9 @@ async function runVisualTableRepair(params) {
11782
11882
  },
11783
11883
  {
11784
11884
  fallback: { tables: [], warnings: [] },
11785
- log: params.log
11885
+ maxRetries: 0,
11886
+ log: params.log,
11887
+ retry: false
11786
11888
  }
11787
11889
  );
11788
11890
  return {
@@ -11808,7 +11910,7 @@ async function runVisualTableRepair(params) {
11808
11910
  continue;
11809
11911
  }
11810
11912
  params.trackUsage(result.usage, {
11811
- taskKind: "extraction_source_tree",
11913
+ taskKind: "extraction_visual_table_repair",
11812
11914
  label: result.label,
11813
11915
  maxTokens: result.maxTokens,
11814
11916
  durationMs: result.durationMs
@@ -11913,32 +12015,6 @@ var NORMALIZED_COMPATIBILITY_FIELDS = /* @__PURE__ */ new Set([
11913
12015
  "insurer",
11914
12016
  "broker"
11915
12017
  ]);
11916
- function coverageBelongsToEndorsementCleanupChunk(coverage) {
11917
- return coverage.coverageOrigin === "endorsement" || Boolean(coverage.endorsementNumber);
11918
- }
11919
- function coverageCleanupChunks(profile) {
11920
- const basePolicy = [];
11921
- const endorsements = [];
11922
- profile.coverages.forEach((coverage, coverageIndex) => {
11923
- if (coverageBelongsToEndorsementCleanupChunk(coverage)) {
11924
- endorsements.push(coverageIndex);
11925
- } else {
11926
- basePolicy.push(coverageIndex);
11927
- }
11928
- });
11929
- return [
11930
- basePolicy.length ? {
11931
- group: "base_policy",
11932
- label: "Coverage cleanup: base policy",
11933
- coverageIndexes: basePolicy
11934
- } : void 0,
11935
- endorsements.length ? {
11936
- group: "endorsements",
11937
- label: "Coverage cleanup: endorsements",
11938
- coverageIndexes: endorsements
11939
- } : void 0
11940
- ].filter((chunk) => Boolean(chunk));
11941
- }
11942
12018
  function valueOf(profile, key) {
11943
12019
  const value = profile[key];
11944
12020
  if (!value || typeof value !== "object" || Array.isArray(value) || !("value" in value)) return void 0;
@@ -12068,6 +12144,105 @@ function materializeDocument(params) {
12068
12144
  retroactiveDate: valueOf(profile, "retroactiveDate")
12069
12145
  };
12070
12146
  }
12147
+ function coverageCleanupGroups(profile) {
12148
+ const groups = [];
12149
+ const coreIndexes = [];
12150
+ const endorsementIndexes = [];
12151
+ const unclassifiedIndexes = [];
12152
+ profile.coverages.forEach((coverage, coverageIndex) => {
12153
+ if (coverage.coverageOrigin === "core") {
12154
+ coreIndexes.push(coverageIndex);
12155
+ } else if (coverage.coverageOrigin === "endorsement") {
12156
+ endorsementIndexes.push(coverageIndex);
12157
+ } else {
12158
+ unclassifiedIndexes.push(coverageIndex);
12159
+ }
12160
+ });
12161
+ if (coreIndexes.length) {
12162
+ groups.push({
12163
+ id: "policy",
12164
+ label: "Coverage schedule cleanup: policy schedules",
12165
+ coverageIndexes: coreIndexes
12166
+ });
12167
+ }
12168
+ if (endorsementIndexes.length) {
12169
+ groups.push({
12170
+ id: "endorsements",
12171
+ label: "Coverage schedule cleanup: endorsement schedules",
12172
+ coverageIndexes: endorsementIndexes
12173
+ });
12174
+ }
12175
+ if (unclassifiedIndexes.length) {
12176
+ groups.push({
12177
+ id: "source_backed",
12178
+ label: "Coverage schedule cleanup: source-backed schedules",
12179
+ coverageIndexes: unclassifiedIndexes
12180
+ });
12181
+ }
12182
+ return groups.length > 1 ? groups : [{
12183
+ id: "all",
12184
+ label: "Coverage schedule cleanup"
12185
+ }];
12186
+ }
12187
+ async function cleanupOperationalCoverageSchedules(params) {
12188
+ const groups = coverageCleanupGroups(params.operationalProfile);
12189
+ const validNodeIds = new Set(params.sourceTree.map((node) => node.id));
12190
+ const validSpanIds = new Set(params.sourceSpans.map((span) => span.id));
12191
+ const results = await Promise.all(groups.map(async (group, groupIndex) => {
12192
+ const budget = params.resolveBudget("extraction_coverage_cleanup", 4096);
12193
+ const startedAt = Date.now();
12194
+ const response = await safeGenerateObject(
12195
+ params.generateObject,
12196
+ {
12197
+ prompt: buildOperationalProfileCleanupPrompt(
12198
+ params.sourceTree,
12199
+ params.operationalProfile,
12200
+ { coverageIndexes: group.coverageIndexes, label: group.label }
12201
+ ),
12202
+ schema: OperationalProfileCleanupSchema,
12203
+ maxTokens: budget.maxTokens,
12204
+ taskKind: "extraction_coverage_cleanup",
12205
+ budgetDiagnostics: budget,
12206
+ providerOptions: params.providerOptions,
12207
+ trace: {
12208
+ phase: "coverage_cleanup",
12209
+ label: group.label,
12210
+ itemCount: group.coverageIndexes?.length ?? params.operationalProfile.coverages.length,
12211
+ coverageGroup: group.id,
12212
+ batchIndex: groups.length > 1 ? groupIndex + 1 : void 0,
12213
+ batchCount: groups.length > 1 ? groups.length : void 0,
12214
+ sourceBacked: true
12215
+ }
12216
+ },
12217
+ {
12218
+ fallback: { coverageDecisions: [], warnings: [] },
12219
+ maxRetries: 0,
12220
+ log: params.log,
12221
+ retry: false
12222
+ }
12223
+ );
12224
+ params.trackUsage(response.usage, {
12225
+ taskKind: "extraction_coverage_cleanup",
12226
+ label: group.id === "all" ? "coverage_cleanup" : `coverage_cleanup_${group.id}`,
12227
+ maxTokens: budget.maxTokens,
12228
+ durationMs: Date.now() - startedAt
12229
+ });
12230
+ return response.object;
12231
+ }));
12232
+ const cleanup = {
12233
+ coverageDecisions: results.flatMap((result) => result.coverageDecisions ?? []),
12234
+ warnings: results.flatMap((result) => result.warnings ?? [])
12235
+ };
12236
+ return {
12237
+ operationalProfile: applyOperationalProfileCleanup(
12238
+ params.operationalProfile,
12239
+ cleanup,
12240
+ validNodeIds,
12241
+ validSpanIds
12242
+ ),
12243
+ warnings: cleanup.warnings
12244
+ };
12245
+ }
12071
12246
  async function runSourceTreeExtraction(params) {
12072
12247
  const sourceSpans = normalizeSourceSpans(params.sourceSpans);
12073
12248
  const formHints = normalizeFormHints(params.formInventory?.forms, sourceSpans);
@@ -12117,7 +12292,9 @@ async function runSourceTreeExtraction(params) {
12117
12292
  },
12118
12293
  {
12119
12294
  fallback: { labels: [], groups: [] },
12120
- log: params.log
12295
+ maxRetries: 0,
12296
+ log: params.log,
12297
+ retry: false
12121
12298
  }
12122
12299
  );
12123
12300
  return {
@@ -12162,7 +12339,9 @@ async function runSourceTreeExtraction(params) {
12162
12339
  },
12163
12340
  {
12164
12341
  fallback: { labels: [], groups: [] },
12165
- log: params.log
12342
+ maxRetries: 0,
12343
+ log: params.log,
12344
+ retry: false
12166
12345
  }
12167
12346
  );
12168
12347
  localTrack(response.usage, {
@@ -12204,7 +12383,9 @@ async function runSourceTreeExtraction(params) {
12204
12383
  },
12205
12384
  {
12206
12385
  fallback: emptyProfile,
12207
- log: params.log
12386
+ maxRetries: 0,
12387
+ log: params.log,
12388
+ retry: false
12208
12389
  }
12209
12390
  );
12210
12391
  localTrack(response.usage, {
@@ -12224,69 +12405,18 @@ async function runSourceTreeExtraction(params) {
12224
12405
  }
12225
12406
  if (operationalProfile.coverages.length > 0) {
12226
12407
  try {
12227
- const validNodeIds = new Set(sourceTree.map((node) => node.id));
12228
- const validSpanIds = new Set(sourceSpans.map((span) => span.id));
12229
- const chunks = coverageCleanupChunks(operationalProfile);
12230
- if (chunks.length > 1) {
12231
- await params.log?.(`Operational profile coverage cleanup reviewing ${chunks.length} coverage groups in parallel`);
12232
- }
12233
- const cleanupResults = await Promise.all(chunks.map(async (chunk, batchIndex) => {
12234
- const budget = params.resolveBudget("extraction_coverage_cleanup", 4096);
12235
- const startedAt = Date.now();
12236
- const response = await safeGenerateObject(
12237
- params.generateObject,
12238
- {
12239
- prompt: buildOperationalProfileCleanupPrompt(sourceTree, operationalProfile, {
12240
- coverageIndexes: chunk.coverageIndexes,
12241
- label: chunk.label
12242
- }),
12243
- schema: OperationalProfileCleanupSchema,
12244
- maxTokens: budget.maxTokens,
12245
- taskKind: "extraction_coverage_cleanup",
12246
- budgetDiagnostics: budget,
12247
- providerOptions: params.providerOptions,
12248
- trace: {
12249
- phase: "coverage_cleanup",
12250
- label: chunk.label,
12251
- batchIndex: batchIndex + 1,
12252
- batchCount: chunks.length,
12253
- coverageGroup: chunk.group,
12254
- itemCount: chunk.coverageIndexes.length,
12255
- sourceBacked: true
12256
- }
12257
- },
12258
- {
12259
- fallback: { coverageDecisions: [], warnings: [] },
12260
- maxRetries: 0,
12261
- log: params.log
12262
- }
12263
- );
12264
- return {
12265
- batchIndex,
12266
- chunk,
12267
- budget,
12268
- durationMs: Date.now() - startedAt,
12269
- usage: response.usage,
12270
- cleanup: response.object
12271
- };
12272
- }));
12273
- const cleanup = { coverageDecisions: [], warnings: [] };
12274
- for (const result of cleanupResults.sort((left, right) => left.batchIndex - right.batchIndex)) {
12275
- localTrack(result.usage, {
12276
- taskKind: "extraction_coverage_cleanup",
12277
- label: result.chunk.label,
12278
- maxTokens: result.budget.maxTokens,
12279
- durationMs: result.durationMs
12280
- });
12281
- cleanup.coverageDecisions.push(...result.cleanup.coverageDecisions);
12282
- cleanup.warnings.push(...result.cleanup.warnings);
12283
- }
12284
- operationalProfile = applyOperationalProfileCleanup(
12408
+ const cleanup = await cleanupOperationalCoverageSchedules({
12409
+ sourceTree,
12410
+ sourceSpans,
12285
12411
  operationalProfile,
12286
- cleanup,
12287
- validNodeIds,
12288
- validSpanIds
12289
- );
12412
+ generateObject: params.generateObject,
12413
+ providerOptions: params.providerOptions,
12414
+ resolveBudget: params.resolveBudget,
12415
+ trackUsage: localTrack,
12416
+ log: params.log
12417
+ });
12418
+ operationalProfile = cleanup.operationalProfile;
12419
+ warnings.push(...cleanup.warnings);
12290
12420
  } catch (error) {
12291
12421
  warnings.push(`Operational profile cleanup pass failed; uncleaned profile used (${error instanceof Error ? error.message : String(error)})`);
12292
12422
  }
@@ -12681,7 +12811,9 @@ ${sourceText}`;
12681
12811
  },
12682
12812
  {
12683
12813
  fallback: { forms: [] },
12814
+ maxRetries: 0,
12684
12815
  log,
12816
+ retry: false,
12685
12817
  onError: (err, attempt) => log?.(`Form inventory attempt ${attempt + 1} failed: ${err instanceof Error ? err.message : String(err)}`)
12686
12818
  }
12687
12819
  );