@claritylabs/cl-sdk 1.0.3 → 1.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/dist/index.mjs CHANGED
@@ -2512,6 +2512,8 @@ async function runExtractor(params) {
2512
2512
  generateObject,
2513
2513
  convertPdfToImages,
2514
2514
  maxTokens = 4096,
2515
+ taskKind,
2516
+ budgetDiagnostics,
2515
2517
  providerOptions,
2516
2518
  pageRangeCache
2517
2519
  } = params;
@@ -2545,6 +2547,8 @@ async function runExtractor(params) {
2545
2547
  prompt: fullPrompt,
2546
2548
  schema: strictSchema,
2547
2549
  maxTokens,
2550
+ taskKind,
2551
+ budgetDiagnostics,
2548
2552
  providerOptions: extractorProviderOptions
2549
2553
  })
2550
2554
  );
@@ -3524,6 +3528,8 @@ async function formatDocumentContent(doc, generateText, options) {
3524
3528
  () => generateText({
3525
3529
  prompt,
3526
3530
  maxTokens: options?.maxTokens ?? 16384,
3531
+ taskKind: options?.taskKind,
3532
+ budgetDiagnostics: options?.budgetDiagnostics,
3527
3533
  providerOptions: options?.providerOptions
3528
3534
  })
3529
3535
  );
@@ -6787,6 +6793,8 @@ If you cannot find the section, return startPage: 0 and endPage: 0.
6787
6793
  Return JSON only.`,
6788
6794
  schema: PageLocationSchema,
6789
6795
  maxTokens: budget.maxTokens,
6796
+ taskKind: "extraction_referential_lookup",
6797
+ budgetDiagnostics: budget,
6790
6798
  providerOptions: await buildPdfProviderOptions(pdfInput, providerOptions)
6791
6799
  },
6792
6800
  {
@@ -6933,6 +6941,8 @@ async function resolveReferentialCoverages(params) {
6933
6941
  getPageRangePdf,
6934
6942
  getPageImages,
6935
6943
  maxTokens: budget.maxTokens,
6944
+ taskKind: "extraction_referential_lookup",
6945
+ budgetDiagnostics: budget,
6936
6946
  providerOptions
6937
6947
  });
6938
6948
  trackUsage(result.usage);
@@ -7049,6 +7059,8 @@ async function runFocusedExtractorWithFallback(params) {
7049
7059
  generateObject,
7050
7060
  convertPdfToImages,
7051
7061
  maxTokens: budget.maxTokens,
7062
+ taskKind,
7063
+ budgetDiagnostics: budget,
7052
7064
  providerOptions,
7053
7065
  pageRangeCache,
7054
7066
  getPageRangePdf,
@@ -7092,6 +7104,8 @@ async function runFocusedExtractorWithFallback(params) {
7092
7104
  generateObject,
7093
7105
  convertPdfToImages,
7094
7106
  maxTokens: budget.maxTokens,
7107
+ taskKind,
7108
+ budgetDiagnostics: budget,
7095
7109
  providerOptions,
7096
7110
  pageRangeCache,
7097
7111
  getPageRangePdf,
@@ -7954,6 +7968,8 @@ function createExtractor(config) {
7954
7968
  generateObject,
7955
7969
  convertPdfToImages,
7956
7970
  maxTokens: budget.maxTokens,
7971
+ taskKind: "extraction_focused",
7972
+ budgetDiagnostics: budget,
7957
7973
  providerOptions: activeProviderOptions,
7958
7974
  pageRangeCache,
7959
7975
  getPageRangePdf,
@@ -8102,6 +8118,8 @@ function createExtractor(config) {
8102
8118
  prompt: buildClassifyPrompt(),
8103
8119
  schema: ClassifyResultSchema,
8104
8120
  maxTokens: budget.maxTokens,
8121
+ taskKind: "extraction_classify",
8122
+ budgetDiagnostics: budget,
8105
8123
  providerOptions: await getFullPdfProviderOptions()
8106
8124
  },
8107
8125
  {
@@ -8150,6 +8168,8 @@ function createExtractor(config) {
8150
8168
  prompt: buildFormInventoryPrompt(templateHints),
8151
8169
  schema: FormInventorySchema,
8152
8170
  maxTokens: budget.maxTokens,
8171
+ taskKind: "extraction_form_inventory",
8172
+ budgetDiagnostics: budget,
8153
8173
  providerOptions: await getFullPdfProviderOptions()
8154
8174
  },
8155
8175
  {
@@ -8202,6 +8222,8 @@ function createExtractor(config) {
8202
8222
  prompt: buildPageMapPrompt(templateHints, startPage, endPage, formInventoryHint),
8203
8223
  schema: PageMapChunkSchema,
8204
8224
  maxTokens: budget.maxTokens,
8225
+ taskKind: "extraction_page_map",
8226
+ budgetDiagnostics: budget,
8205
8227
  providerOptions: { ...activeProviderOptions, pdfBase64: pagesPdf }
8206
8228
  },
8207
8229
  {
@@ -8318,6 +8340,8 @@ function createExtractor(config) {
8318
8340
  generateObject,
8319
8341
  convertPdfToImages,
8320
8342
  maxTokens: budget.maxTokens,
8343
+ taskKind: "extraction_focused",
8344
+ budgetDiagnostics: budget,
8321
8345
  providerOptions: activeProviderOptions,
8322
8346
  pageRangeCache: completedPageRangePdfCache,
8323
8347
  getPageRangePdf,
@@ -8408,10 +8432,19 @@ function createExtractor(config) {
8408
8432
  prompt: buildReviewPrompt(template.required, extractedKeys, extractionSummary, pageMapSummary, extractorCatalog),
8409
8433
  schema: ReviewResultSchema,
8410
8434
  maxTokens: budget.maxTokens,
8435
+ taskKind: "extraction_review",
8436
+ budgetDiagnostics: budget,
8411
8437
  providerOptions: await getFullPdfProviderOptions()
8412
8438
  },
8413
8439
  {
8414
- fallback: { complete: true, missingFields: [], qualityIssues: [], additionalTasks: [] },
8440
+ fallback: {
8441
+ complete: false,
8442
+ missingFields: ["llm_review_unavailable"],
8443
+ qualityIssues: [
8444
+ "LLM extraction review failed; deterministic review was used and the result needs review."
8445
+ ],
8446
+ additionalTasks: []
8447
+ },
8415
8448
  log,
8416
8449
  onError: (err, attempt) => log?.(`Review round ${round + 1} attempt ${attempt + 1} failed: ${err}`)
8417
8450
  }
@@ -8512,6 +8545,8 @@ function createExtractor(config) {
8512
8545
  prompt: buildSummaryPrompt(document),
8513
8546
  schema: SummaryResultSchema,
8514
8547
  maxTokens: budget.maxTokens,
8548
+ taskKind: "extraction_summary",
8549
+ budgetDiagnostics: budget,
8515
8550
  providerOptions: activeProviderOptions
8516
8551
  },
8517
8552
  {
@@ -8539,6 +8574,8 @@ function createExtractor(config) {
8539
8574
  const formatResult = await formatDocumentContent(document, generateText, {
8540
8575
  providerOptions: activeProviderOptions,
8541
8576
  maxTokens: formatBudget.maxTokens,
8577
+ taskKind: "extraction_format",
8578
+ budgetDiagnostics: formatBudget,
8542
8579
  concurrency: formatConcurrency ?? concurrency,
8543
8580
  onProgress,
8544
8581
  log
@@ -8941,6 +8978,7 @@ async function classifyApplication(pdfContent, generateObject, providerOptions,
8941
8978
  Analyze the attached insurance document. If text source units are provided in provider options, use them as supporting context. Do not infer from base64 text.`,
8942
8979
  schema: ApplicationClassifyResultSchema,
8943
8980
  maxTokens,
8981
+ taskKind: "application_classify",
8944
8982
  providerOptions: {
8945
8983
  ...providerOptions,
8946
8984
  pdfBase64: providerOptions?.pdfBase64 ?? pdfContent
@@ -9043,6 +9081,7 @@ Extract fields from the attached application PDF. Use provider-supplied source u
9043
9081
  prompt,
9044
9082
  schema: FieldExtractionResultSchema,
9045
9083
  maxTokens,
9084
+ taskKind: "application_extract_fields",
9046
9085
  providerOptions: {
9047
9086
  ...providerOptions,
9048
9087
  pdfBase64: providerOptions?.pdfBase64 ?? pdfContent
@@ -9096,6 +9135,7 @@ async function autoFillFromContext(fields, orgContext, generateObject, providerO
9096
9135
  prompt,
9097
9136
  schema: AutoFillResultSchema,
9098
9137
  maxTokens,
9138
+ taskKind: "application_auto_fill",
9099
9139
  providerOptions
9100
9140
  })
9101
9141
  );
@@ -9166,6 +9206,7 @@ async function batchQuestions(unfilledFields, generateObject, providerOptions, m
9166
9206
  prompt,
9167
9207
  schema: QuestionBatchResultSchema,
9168
9208
  maxTokens,
9209
+ taskKind: "application_batch",
9169
9210
  providerOptions
9170
9211
  })
9171
9212
  );
@@ -9217,6 +9258,7 @@ async function classifyReplyIntent(fields, replyText, generateObject, providerOp
9217
9258
  prompt,
9218
9259
  schema: ReplyIntentSchema,
9219
9260
  maxTokens,
9261
+ taskKind: "application_classify",
9220
9262
  providerOptions
9221
9263
  })
9222
9264
  );
@@ -9276,6 +9318,7 @@ async function parseAnswers(fields, replyText, generateObject, providerOptions,
9276
9318
  prompt,
9277
9319
  schema: AnswerParsingResultSchema,
9278
9320
  maxTokens,
9321
+ taskKind: "application_parse_answers",
9279
9322
  providerOptions
9280
9323
  })
9281
9324
  );
@@ -9405,6 +9448,7 @@ async function fillFromLookup(requests, targetFields, availableData, generateObj
9405
9448
  prompt,
9406
9449
  schema: LookupFillResultSchema,
9407
9450
  maxTokens,
9451
+ taskKind: "application_lookup",
9408
9452
  providerOptions
9409
9453
  })
9410
9454
  );
@@ -9487,6 +9531,7 @@ async function generateBatchEmail(batchFields, batchIndex, totalBatches, opts, g
9487
9531
  () => generateText({
9488
9532
  prompt,
9489
9533
  maxTokens,
9534
+ taskKind: "application_email",
9490
9535
  providerOptions
9491
9536
  })
9492
9537
  );
@@ -10009,11 +10054,14 @@ function createApplicationPipeline(config) {
10009
10054
  }
10010
10055
  if (replyPlan.answerQuestion && intent.questionText) {
10011
10056
  try {
10057
+ const budget = resolveBudget("application_email", 512);
10012
10058
  const { text, usage } = await generateText({
10013
10059
  prompt: `The user is filling out an insurance application and asked: "${intent.questionText}"
10014
10060
 
10015
10061
  Provide a brief, helpful explanation (2-3 sentences). End with "Just reply with the answer when you're ready and I'll fill it in."`,
10016
- maxTokens: resolveBudget("application_email", 512).maxTokens,
10062
+ maxTokens: budget.maxTokens,
10063
+ taskKind: "application_email",
10064
+ budgetDiagnostics: budget,
10017
10065
  providerOptions
10018
10066
  });
10019
10067
  trackUsage(usage);
@@ -10138,6 +10186,7 @@ ${emailText}`;
10138
10186
  if (!state) throw new Error(`Application ${applicationId} not found`);
10139
10187
  const filledFields = state.fields.filter((f) => f.value);
10140
10188
  const fieldSummary = filledFields.map((f) => `${f.section} > ${f.label}: ${f.value} (source: ${f.source ?? "unknown"})`).join("\n");
10189
+ const budget = resolveBudget("application_email", 4096);
10141
10190
  const { text, usage } = await generateText({
10142
10191
  prompt: `Format these filled insurance application fields as a clean confirmation summary for the user to review. Group by section, show each field as "Label: Value". End with a note asking them to confirm or request changes.
10143
10192
 
@@ -10145,7 +10194,9 @@ Application: ${state.title ?? "Insurance Application"}
10145
10194
 
10146
10195
  Fields:
10147
10196
  ${fieldSummary}`,
10148
- maxTokens: resolveBudget("application_email", 4096).maxTokens,
10197
+ maxTokens: budget.maxTokens,
10198
+ taskKind: "application_email",
10199
+ budgetDiagnostics: budget,
10149
10200
  providerOptions
10150
10201
  });
10151
10202
  trackUsage(usage);
@@ -10619,6 +10670,8 @@ ${e.text}`;
10619
10670
  prompt,
10620
10671
  schema: SubAnswerSchema,
10621
10672
  maxTokens: budget.maxTokens,
10673
+ taskKind: "query_reason",
10674
+ budgetDiagnostics: budget,
10622
10675
  providerOptions
10623
10676
  })
10624
10677
  );
@@ -10842,6 +10895,8 @@ async function verify(originalQuestion, subAnswers, allEvidence, config) {
10842
10895
  prompt,
10843
10896
  schema: VerifyResultSchema,
10844
10897
  maxTokens: budget.maxTokens,
10898
+ taskKind: "query_verify",
10899
+ budgetDiagnostics: budget,
10845
10900
  providerOptions
10846
10901
  })
10847
10902
  );
@@ -10984,6 +11039,8 @@ async function interpretAttachments(params) {
10984
11039
  prompt,
10985
11040
  schema: AttachmentInterpretationSchema,
10986
11041
  maxTokens: budget.maxTokens,
11042
+ taskKind: "query_attachment",
11043
+ budgetDiagnostics: budget,
10987
11044
  providerOptions: buildAttachmentProviderOptions(attachment, providerOptions)
10988
11045
  },
10989
11046
  {
@@ -11321,6 +11378,8 @@ function createQueryAgent(config) {
11321
11378
  prompt,
11322
11379
  schema: QueryClassifyResultSchema,
11323
11380
  maxTokens: budget.maxTokens,
11381
+ taskKind: "query_classify",
11382
+ budgetDiagnostics: budget,
11324
11383
  providerOptions
11325
11384
  },
11326
11385
  {
@@ -11372,6 +11431,8 @@ function createQueryAgent(config) {
11372
11431
  prompt,
11373
11432
  schema: QueryResultSchema,
11374
11433
  maxTokens: budget.maxTokens,
11434
+ taskKind: "query_respond",
11435
+ budgetDiagnostics: budget,
11375
11436
  providerOptions
11376
11437
  },
11377
11438
  {
@@ -11467,6 +11528,8 @@ function createPceAgent(config = {}) {
11467
11528
  prompt: buildPceNormalizePrompt({ requestText: input.requestText, evidenceSources }),
11468
11529
  schema: PceNormalizationResultSchema,
11469
11530
  maxTokens: budget.maxTokens,
11531
+ taskKind: "pce_impact_analysis",
11532
+ budgetDiagnostics: budget,
11470
11533
  providerOptions: config.providerOptions
11471
11534
  },
11472
11535
  { fallback, maxRetries: 1, log: config.log }
@@ -11528,6 +11591,8 @@ function createPceAgent(config = {}) {
11528
11591
  }),
11529
11592
  schema: ReplyAnswersSchema,
11530
11593
  maxTokens: budget.maxTokens,
11594
+ taskKind: "pce_reply_parse",
11595
+ budgetDiagnostics: budget,
11531
11596
  providerOptions: config.providerOptions
11532
11597
  },
11533
11598
  { fallback: { answers }, maxRetries: 1, log: config.log }