@claritylabs/cl-sdk 3.0.18 → 3.0.19

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
@@ -10961,11 +10961,49 @@ ${span.text}` : span.text;
10961
10961
  }
10962
10962
  }
10963
10963
  if (sourceSpans.length > 0) {
10964
+ const pageCount2 = Math.max(
10965
+ 1,
10966
+ ...sourceSpans.map((span) => span.pageEnd ?? span.pageStart ?? span.location?.endPage ?? span.location?.page ?? 1)
10967
+ );
10968
+ let formInventory2 = options?.formInventory;
10969
+ if (!formInventory2) {
10970
+ onProgress?.("Building form inventory from source spans...");
10971
+ const budget = resolveBudget("extraction_form_inventory", 2048);
10972
+ const startedAt = Date.now();
10973
+ const templateHints2 = buildTemplateHints("other", "policy", pageCount2, getTemplate("other"));
10974
+ const sourceText = formatSourceSpanText(sourceSpans);
10975
+ const prompt = `${buildFormInventoryPrompt(templateHints2)}
10976
+
10977
+ SOURCE SPAN DOCUMENT TEXT:
10978
+ ${sourceText}`;
10979
+ const response = await safeGenerateObject(
10980
+ generateObject,
10981
+ {
10982
+ prompt,
10983
+ schema: FormInventorySchema,
10984
+ maxTokens: budget.maxTokens,
10985
+ taskKind: "extraction_form_inventory",
10986
+ budgetDiagnostics: budget
10987
+ },
10988
+ {
10989
+ fallback: { forms: [] },
10990
+ log,
10991
+ onError: (err, attempt) => log?.(`Form inventory attempt ${attempt + 1} failed: ${err instanceof Error ? err.message : String(err)}`)
10992
+ }
10993
+ );
10994
+ trackUsage(response.usage, {
10995
+ taskKind: "extraction_form_inventory",
10996
+ label: "form_inventory",
10997
+ maxTokens: budget.maxTokens,
10998
+ durationMs: Date.now() - startedAt
10999
+ });
11000
+ formInventory2 = response.object;
11001
+ }
10964
11002
  onProgress?.("Building source-native document tree...");
10965
11003
  const v3 = await runSourceTreeExtraction({
10966
11004
  id,
10967
11005
  sourceSpans,
10968
- formInventory: options?.formInventory,
11006
+ formInventory: formInventory2,
10969
11007
  generateObject,
10970
11008
  providerOptions: activeProviderOptions,
10971
11009
  resolveBudget,