@claritylabs/cl-sdk 0.7.5 → 0.8.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.d.mts CHANGED
@@ -12,7 +12,16 @@ type GenerateText = (params: {
12
12
  text: string;
13
13
  usage?: TokenUsage;
14
14
  }>;
15
- /** Callback to generate a typed object from a prompt + Zod schema. Provider-agnostic. */
15
+ /**
16
+ * Callback to generate a typed object from a prompt + Zod schema. Provider-agnostic.
17
+ *
18
+ * The extraction pipeline passes document content via `providerOptions`:
19
+ * - `providerOptions.pdfBase64` — base64-encoded PDF to include as document context
20
+ * - `providerOptions.images` — `Array<{ imageBase64: string; mimeType: string }>` page images
21
+ *
22
+ * Your callback should check for these fields and include them as multi-part
23
+ * message content (e.g. file/image parts) when calling your AI provider.
24
+ */
16
25
  type GenerateObject<T = unknown> = (params: {
17
26
  prompt: string;
18
27
  system?: string;
package/dist/index.d.ts CHANGED
@@ -12,7 +12,16 @@ type GenerateText = (params: {
12
12
  text: string;
13
13
  usage?: TokenUsage;
14
14
  }>;
15
- /** Callback to generate a typed object from a prompt + Zod schema. Provider-agnostic. */
15
+ /**
16
+ * Callback to generate a typed object from a prompt + Zod schema. Provider-agnostic.
17
+ *
18
+ * The extraction pipeline passes document content via `providerOptions`:
19
+ * - `providerOptions.pdfBase64` — base64-encoded PDF to include as document context
20
+ * - `providerOptions.images` — `Array<{ imageBase64: string; mimeType: string }>` page images
21
+ *
22
+ * Your callback should check for these fields and include them as multi-part
23
+ * message content (e.g. file/image parts) when calling your AI provider.
24
+ */
16
25
  type GenerateObject<T = unknown> = (params: {
17
26
  prompt: string;
18
27
  system?: string;
package/dist/index.js CHANGED
@@ -1758,19 +1758,28 @@ async function runExtractor(params) {
1758
1758
  maxTokens = 4096,
1759
1759
  providerOptions
1760
1760
  } = params;
1761
- const pagesPdf = await extractPageRange(pdfBase64, startPage, endPage);
1762
- const fullPrompt = convertPdfToImages ? `${prompt}
1763
-
1764
- [Document pages ${startPage}-${endPage} are provided as images above.]` : `${prompt}
1761
+ const extractorProviderOptions = { ...providerOptions };
1762
+ let fullPrompt;
1763
+ if (convertPdfToImages) {
1764
+ const images = await convertPdfToImages(pdfBase64, startPage, endPage);
1765
+ extractorProviderOptions.images = images;
1766
+ fullPrompt = `${prompt}
1767
+
1768
+ [Document pages ${startPage}-${endPage} are provided as images.]`;
1769
+ } else {
1770
+ const pagesPdf = await extractPageRange(pdfBase64, startPage, endPage);
1771
+ extractorProviderOptions.pdfBase64 = pagesPdf;
1772
+ fullPrompt = `${prompt}
1765
1773
 
1766
- [Document pages ${startPage}-${endPage} are provided as a PDF file above.]`;
1774
+ [Document pages ${startPage}-${endPage} are provided as a PDF file.]`;
1775
+ }
1767
1776
  const strictSchema = toStrictSchema(schema);
1768
1777
  const result = await withRetry(
1769
1778
  () => generateObject({
1770
1779
  prompt: fullPrompt,
1771
1780
  schema: strictSchema,
1772
1781
  maxTokens,
1773
- providerOptions
1782
+ providerOptions: extractorProviderOptions
1774
1783
  })
1775
1784
  );
1776
1785
  return {
@@ -3590,7 +3599,7 @@ function createExtractor(config) {
3590
3599
  prompt: buildClassifyPrompt(),
3591
3600
  schema: ClassifyResultSchema,
3592
3601
  maxTokens: 512,
3593
- providerOptions
3602
+ providerOptions: { ...providerOptions, pdfBase64 }
3594
3603
  },
3595
3604
  {
3596
3605
  fallback: { documentType: "policy", policyTypes: ["other"], confidence: 0 },
@@ -3634,7 +3643,7 @@ function createExtractor(config) {
3634
3643
  prompt: buildPlanPrompt(templateHints),
3635
3644
  schema: ExtractionPlanSchema,
3636
3645
  maxTokens: 2048,
3637
- providerOptions
3646
+ providerOptions: { ...providerOptions, pdfBase64 }
3638
3647
  },
3639
3648
  {
3640
3649
  fallback: {