@doclo/core 0.1.5
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/LICENSE +21 -0
- package/README.md +34 -0
- package/dist/index.d.ts +931 -0
- package/dist/index.js +2293 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/validation-utils.d.ts +1 -0
- package/dist/internal/validation-utils.js +650 -0
- package/dist/internal/validation-utils.js.map +1 -0
- package/dist/observability/index.d.ts +933 -0
- package/dist/observability/index.js +630 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/pdf-utils.d.ts +123 -0
- package/dist/pdf-utils.js +106 -0
- package/dist/pdf-utils.js.map +1 -0
- package/dist/runtime/base64.d.ts +100 -0
- package/dist/runtime/base64.js +52 -0
- package/dist/runtime/base64.js.map +1 -0
- package/dist/runtime/crypto.d.ts +56 -0
- package/dist/runtime/crypto.js +35 -0
- package/dist/runtime/crypto.js.map +1 -0
- package/dist/runtime/env.d.ts +130 -0
- package/dist/runtime/env.js +76 -0
- package/dist/runtime/env.js.map +1 -0
- package/dist/security/index.d.ts +236 -0
- package/dist/security/index.js +260 -0
- package/dist/security/index.js.map +1 -0
- package/dist/validation-CzOz6fwq.d.ts +1126 -0
- package/dist/validation.d.ts +1 -0
- package/dist/validation.js +445 -0
- package/dist/validation.js.map +1 -0
- package/package.json +70 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
import { P as ProviderVendor, A as AccessMethod } from './validation-CzOz6fwq.js';
|
|
2
|
+
export { z as AggregatedMetrics, B as BBox, r as CategorizeNodeConfig, s as ChunkMetadata, u as ChunkNodeConfig, t as ChunkOutput, n as CitationConfig, k as CitationSourceType, v as CombineNodeConfig, T as CompatibilityRule, C as ConsensusConfig, e as ConsensusMetadata, d as ConsensusRunResult, D as DocumentIR, b as DocumentIRExtras, x as EnhancedExtractionSchema, E as ExtractNodeConfig, $ as ExtractedImage, m as FieldCitation, F as FieldVotingDetails, G as FlowContext, a6 as FlowExecutionError, h as FlowInput, i as FlowInputValidation, j as FlowResult, a7 as FlowValidationError, I as IRLine, a as IRPage, W as JSONSchemaNode, c as LLMJsonProvider, L as LLMProvider, Z as LanguageOptions, l as LineCitation, g as MaybeWithConsensusMetadata, M as MultimodalInput, a8 as NODE_COMPATIBILITY_MATRIX, H as NodeCtx, K as NodeDef, J as NodeTypeInfo, Q as NodeTypeName, N as NormalizedBBox, O as OCRProvider, a0 as OCRProviderOptions, w as OutputNodeConfig, o as OutputWithCitations, f as OutputWithConsensus, Y as PageRangeOptions, p as ParseNodeConfig, X as ProcessingMode, a2 as ProviderCitation, aj as ProviderIdentity, ah as RESERVED_VARIABLES, R as ReasoningConfig, _ as SegmentationResult, S as SplitDocument, q as SplitNodeConfig, y as StepMetric, V as VLMProvider, a1 as VLMProviderOptions, U as ValidationResult, a3 as aggregateMetrics, af as canStartForEachItemFlow, an as createIdentity, ab as getCompatibleTargets, aa as getNodeTypeInfo, a9 as getNodeTypeName, ac as getSuggestedConnections, ae as getValidForEachStarters, am as isLocalEndpoint, a4 as node, al as parseProviderString, ai as protectReservedVariables, a5 as runPipeline, ak as toProviderString, ag as validateJson, ad as validateNodeConnection } from './validation-CzOz6fwq.js';
|
|
3
|
+
export { getDocumentPageCount, getPDFPageCount, getPageCountMetadata, getTotalPageCount, splitPDFIntoChunks } from './pdf-utils.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* File utilities for universal runtime (Edge Runtime + Node.js compatible)
|
|
7
|
+
*
|
|
8
|
+
* These utilities work in both Edge Runtime and Node.js environments.
|
|
9
|
+
* File system operations have been removed for Edge Runtime compatibility.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Supported document MIME types that can be detected.
|
|
13
|
+
* This includes all formats supported by at least one provider:
|
|
14
|
+
* - Datalab: PDF, images, Office, OpenDocument, HTML, EPUB
|
|
15
|
+
* - Reducto: PDF, images (incl. HEIC, BMP, PSD), Office, RTF, TXT, CSV
|
|
16
|
+
* - Unsiloed: PDF, images, Office (DOCX, XLSX, PPTX)
|
|
17
|
+
*/
|
|
18
|
+
type DocumentMimeType = 'application/pdf' | 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp' | 'image/tiff' | 'image/bmp' | 'image/heic' | 'image/heif' | 'image/vnd.adobe.photoshop' | 'application/msword' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/vnd.ms-excel' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'application/vnd.ms-powerpoint' | 'application/vnd.openxmlformats-officedocument.presentationml.presentation' | 'application/vnd.oasis.opendocument.text' | 'application/vnd.oasis.opendocument.spreadsheet' | 'application/vnd.oasis.opendocument.presentation' | 'text/plain' | 'text/csv' | 'text/html' | 'application/rtf' | 'application/epub+zip' | 'unknown';
|
|
19
|
+
/**
|
|
20
|
+
* Security limits configuration for file operations
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
interface FileLimitsConfig {
|
|
24
|
+
/** Maximum file size in bytes (default: 100MB) - ⚠️ WARNING: Increasing this exposes to resource exhaustion attacks */
|
|
25
|
+
maxFileSize?: number;
|
|
26
|
+
/** Request timeout in milliseconds (default: 30s) - ⚠️ WARNING: Decreasing this may cause legitimate requests to fail */
|
|
27
|
+
requestTimeout?: number;
|
|
28
|
+
}
|
|
29
|
+
declare function detectDocumentType(input: string | undefined): DocumentMimeType;
|
|
30
|
+
/**
|
|
31
|
+
* Check if input represents a PDF document
|
|
32
|
+
*
|
|
33
|
+
* Handles various input formats:
|
|
34
|
+
* - Data URLs with MIME type
|
|
35
|
+
* - File paths with .pdf extension
|
|
36
|
+
* - HTTP/HTTPS URLs (with or without query parameters)
|
|
37
|
+
* - Raw base64 strings (detected via magic bytes)
|
|
38
|
+
*
|
|
39
|
+
* @param input - Document input (data URL, file path, URL, or raw base64)
|
|
40
|
+
* @returns true if input appears to be a PDF
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* isPDFDocument('data:application/pdf;base64,...') // true
|
|
45
|
+
* isPDFDocument('./document.pdf') // true
|
|
46
|
+
* isPDFDocument('https://example.com/doc.pdf?token=123') // true
|
|
47
|
+
* isPDFDocument('JVBERi0xLjQK...') // true (raw base64 PDF)
|
|
48
|
+
* isPDFDocument('data:image/jpeg;base64,...') // false
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare function isPDFDocument(input: string | undefined): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Resolve document from any source (URL or data URI) to base64 data URL
|
|
54
|
+
*
|
|
55
|
+
* Supports two input types:
|
|
56
|
+
* - HTTP/HTTPS URLs: 'https://example.com/document.pdf'
|
|
57
|
+
* - Data URIs: 'data:application/pdf;base64,JVBERi0x...'
|
|
58
|
+
*
|
|
59
|
+
* Note: File paths are NOT supported in Edge Runtime.
|
|
60
|
+
* Use HTTP URLs, data URIs, or pass ArrayBuffer/base64 directly.
|
|
61
|
+
*
|
|
62
|
+
* @param input - Document source (URL or data URI)
|
|
63
|
+
* @param limits - Optional security limits for file size and request timeout (uses secure defaults if not specified)
|
|
64
|
+
* @returns Promise resolving to base64 data URL
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Remote URL
|
|
69
|
+
* const dataUrl = await resolveDocument('https://example.com/doc.pdf');
|
|
70
|
+
*
|
|
71
|
+
* // Remote URL with custom timeout
|
|
72
|
+
* const dataUrl = await resolveDocument('https://example.com/doc.pdf', { requestTimeout: 60000 });
|
|
73
|
+
*
|
|
74
|
+
* // Data URI (pass-through)
|
|
75
|
+
* const dataUrl = await resolveDocument('data:application/pdf;base64,JVBERi0x...');
|
|
76
|
+
*
|
|
77
|
+
* // For ArrayBuffer, use bufferToDataUri() instead
|
|
78
|
+
* const dataUrl = bufferToDataUri(arrayBuffer, 'application/pdf');
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function resolveDocument(input: string, limits?: FileLimitsConfig): Promise<string>;
|
|
82
|
+
/**
|
|
83
|
+
* Convert ArrayBuffer or Uint8Array to base64 data URI
|
|
84
|
+
*
|
|
85
|
+
* Edge Runtime compatible - no file system access required.
|
|
86
|
+
*
|
|
87
|
+
* @param buffer - File buffer (ArrayBuffer or Uint8Array)
|
|
88
|
+
* @param mimeType - MIME type (e.g., 'application/pdf', 'image/jpeg')
|
|
89
|
+
* @returns Base64 data URI string
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // From ArrayBuffer
|
|
94
|
+
* const buffer = await response.arrayBuffer();
|
|
95
|
+
* const dataUri = bufferToDataUri(buffer, 'application/pdf');
|
|
96
|
+
*
|
|
97
|
+
* // From Uint8Array
|
|
98
|
+
* const bytes = new Uint8Array([72, 101, 108, 108, 111]);
|
|
99
|
+
* const dataUri = bufferToDataUri(bytes, 'text/plain');
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare function bufferToDataUri(buffer: ArrayBuffer | Uint8Array, mimeType: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated Use bufferToDataUri() instead. This function will be removed in v0.2.0.
|
|
105
|
+
*/
|
|
106
|
+
declare function bufferToBase64(buffer: ArrayBuffer | Uint8Array, mimeType: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* Accepted MIME types for flow input validation.
|
|
109
|
+
* Excludes 'unknown' - only known provider-supported formats.
|
|
110
|
+
*/
|
|
111
|
+
type AcceptedMimeType = Exclude<DocumentMimeType, 'unknown'>;
|
|
112
|
+
/**
|
|
113
|
+
* Error thrown when flow input doesn't match accepted formats
|
|
114
|
+
*/
|
|
115
|
+
declare class FlowInputValidationError extends Error {
|
|
116
|
+
readonly detectedType: string;
|
|
117
|
+
readonly acceptedTypes: string[];
|
|
118
|
+
/**
|
|
119
|
+
* @param message - Human-readable error message
|
|
120
|
+
* @param detectedType - The actual MIME type detected from the input
|
|
121
|
+
* @param acceptedTypes - List of MIME types that would have been accepted
|
|
122
|
+
*/
|
|
123
|
+
constructor(message: string, detectedType: string, acceptedTypes: string[]);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Validate flow input against accepted MIME type formats
|
|
127
|
+
*
|
|
128
|
+
* @param input - Flow input string (base64, data URL, or URL)
|
|
129
|
+
* @param acceptedFormats - List of accepted MIME types
|
|
130
|
+
* @returns The detected MIME type if valid
|
|
131
|
+
* @throws FlowInputValidationError if format doesn't match accepted types
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* // Validate PDF only
|
|
136
|
+
* const mimeType = validateFlowInputFormat(pdfBase64, ['application/pdf']);
|
|
137
|
+
*
|
|
138
|
+
* // Validate images only
|
|
139
|
+
* const mimeType = validateFlowInputFormat(jpgBase64, ['image/jpeg', 'image/png']);
|
|
140
|
+
*
|
|
141
|
+
* // Will throw FlowInputValidationError if input is a PDF but only images accepted
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
declare function validateFlowInputFormat(input: string | undefined, acceptedFormats: AcceptedMimeType[]): AcceptedMimeType;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Provider Configuration
|
|
148
|
+
*
|
|
149
|
+
* Serializable provider configurations for doclo-sdk.
|
|
150
|
+
* These configs can be stored in databases and reconstructed at runtime.
|
|
151
|
+
*/
|
|
152
|
+
/**
|
|
153
|
+
* Base provider configuration
|
|
154
|
+
*/
|
|
155
|
+
type BaseProviderConfig = {
|
|
156
|
+
id: string;
|
|
157
|
+
name?: string;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* VLM (Vision Language Model) provider configuration
|
|
161
|
+
*/
|
|
162
|
+
type VLMProviderConfig = BaseProviderConfig & {
|
|
163
|
+
type: 'vlm';
|
|
164
|
+
provider: 'openai' | 'anthropic' | 'google' | 'xai';
|
|
165
|
+
model: string;
|
|
166
|
+
via?: 'openrouter' | 'native';
|
|
167
|
+
baseUrl?: string;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* OCR provider configuration
|
|
171
|
+
*/
|
|
172
|
+
type OCRProviderConfig = BaseProviderConfig & ({
|
|
173
|
+
type: 'ocr';
|
|
174
|
+
provider: 'surya';
|
|
175
|
+
endpoint?: string;
|
|
176
|
+
} | {
|
|
177
|
+
type: 'ocr';
|
|
178
|
+
provider: 'marker';
|
|
179
|
+
force_ocr?: boolean;
|
|
180
|
+
use_llm?: boolean;
|
|
181
|
+
});
|
|
182
|
+
/**
|
|
183
|
+
* All provider configurations
|
|
184
|
+
*/
|
|
185
|
+
type ProviderConfig = VLMProviderConfig | OCRProviderConfig;
|
|
186
|
+
/**
|
|
187
|
+
* Provider secrets (API keys, credentials)
|
|
188
|
+
* Stored separately from provider configs for security
|
|
189
|
+
*/
|
|
190
|
+
type ProviderSecrets = Record<string, {
|
|
191
|
+
apiKey?: string;
|
|
192
|
+
/** Additional secret values (e.g., endpoint URLs, tokens) */
|
|
193
|
+
[key: string]: string | undefined;
|
|
194
|
+
}>;
|
|
195
|
+
/**
|
|
196
|
+
* Base provider interface - common methods shared by all providers
|
|
197
|
+
*/
|
|
198
|
+
interface ProviderInstance {
|
|
199
|
+
/** Optional provider name for identification */
|
|
200
|
+
name?: string;
|
|
201
|
+
/** Capabilities of this provider instance */
|
|
202
|
+
capabilities?: Record<string, unknown>;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Provider registry - maps provider IDs to instantiated providers
|
|
206
|
+
* Uses a generic constraint to allow type narrowing when the provider type is known
|
|
207
|
+
*/
|
|
208
|
+
type ProviderRegistry<T extends ProviderInstance = ProviderInstance> = Record<string, T>;
|
|
209
|
+
/**
|
|
210
|
+
* Helper to create VLM provider config
|
|
211
|
+
*/
|
|
212
|
+
declare function defineVLMProvider(config: Omit<VLMProviderConfig, 'type'>): VLMProviderConfig;
|
|
213
|
+
/**
|
|
214
|
+
* Helper to create Surya OCR provider config
|
|
215
|
+
*/
|
|
216
|
+
declare function defineSuryaProvider(config: Omit<Extract<OCRProviderConfig, {
|
|
217
|
+
provider: 'surya';
|
|
218
|
+
}>, 'type'>): OCRProviderConfig;
|
|
219
|
+
/**
|
|
220
|
+
* Helper to create Marker OCR provider config
|
|
221
|
+
*/
|
|
222
|
+
declare function defineMarkerProvider(config: Omit<Extract<OCRProviderConfig, {
|
|
223
|
+
provider: 'marker';
|
|
224
|
+
}>, 'type'>): OCRProviderConfig;
|
|
225
|
+
/**
|
|
226
|
+
* Build a provider instance from config and secrets
|
|
227
|
+
*
|
|
228
|
+
* @param config - Provider configuration
|
|
229
|
+
* @param secrets - Provider secrets (API keys)
|
|
230
|
+
* @returns Provider instance
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const config: VLMProviderConfig = {
|
|
235
|
+
* type: 'vlm',
|
|
236
|
+
* id: 'gemini-flash',
|
|
237
|
+
* provider: 'google',
|
|
238
|
+
* model: 'google/gemini-2.5-flash-preview-09-2025',
|
|
239
|
+
* via: 'openrouter'
|
|
240
|
+
* };
|
|
241
|
+
*
|
|
242
|
+
* const secrets: ProviderSecrets = {
|
|
243
|
+
* 'gemini-flash': {
|
|
244
|
+
* apiKey: process.env.OPENROUTER_API_KEY
|
|
245
|
+
* }
|
|
246
|
+
* };
|
|
247
|
+
*
|
|
248
|
+
* const provider = await buildProviderFromConfig(config, secrets);
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
declare function buildProviderFromConfig(config: ProviderConfig, secrets: ProviderSecrets): Promise<ProviderInstance>;
|
|
252
|
+
/**
|
|
253
|
+
* Build multiple providers from configs
|
|
254
|
+
*
|
|
255
|
+
* @param configs - Array of provider configurations
|
|
256
|
+
* @param secrets - Provider secrets
|
|
257
|
+
* @returns Provider registry (map of IDs to instances)
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* const configs: ProviderConfig[] = [
|
|
262
|
+
* { type: 'vlm', id: 'gemini', provider: 'google', model: '...', via: 'openrouter' },
|
|
263
|
+
* { type: 'ocr', id: 'surya', provider: 'surya' }
|
|
264
|
+
* ];
|
|
265
|
+
*
|
|
266
|
+
* const secrets: ProviderSecrets = {
|
|
267
|
+
* 'gemini': { apiKey: process.env.OPENROUTER_API_KEY },
|
|
268
|
+
* 'surya': { apiKey: process.env.SURYA_API_KEY }
|
|
269
|
+
* };
|
|
270
|
+
*
|
|
271
|
+
* const providers = await buildProvidersFromConfigs(configs, secrets);
|
|
272
|
+
* // providers = { gemini: VLMProvider, surya: OCRProvider }
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
declare function buildProvidersFromConfigs(configs: ProviderConfig[], secrets: ProviderSecrets): Promise<ProviderRegistry>;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* TypeScript utility types for auto-injected prompt variables
|
|
279
|
+
*
|
|
280
|
+
* These types document which variables are automatically injected by each node type,
|
|
281
|
+
* helping users understand what's available in their prompt templates.
|
|
282
|
+
*/
|
|
283
|
+
/**
|
|
284
|
+
* Variables auto-injected by the Extract node
|
|
285
|
+
*/
|
|
286
|
+
interface ExtractAutoVariables {
|
|
287
|
+
/**
|
|
288
|
+
* The JSON schema for extraction, from config.schema
|
|
289
|
+
*/
|
|
290
|
+
schema: object;
|
|
291
|
+
/**
|
|
292
|
+
* The document text extracted from DocumentIR or FlowInput
|
|
293
|
+
*/
|
|
294
|
+
documentText: string;
|
|
295
|
+
/**
|
|
296
|
+
* Schema title from schema.title or default value
|
|
297
|
+
* Default: "the provided schema"
|
|
298
|
+
*/
|
|
299
|
+
schemaTitle: string;
|
|
300
|
+
/**
|
|
301
|
+
* Schema description from schema.description or empty string
|
|
302
|
+
*/
|
|
303
|
+
schemaDescription: string;
|
|
304
|
+
/**
|
|
305
|
+
* Generated formatting instructions for markdown/html output
|
|
306
|
+
* Only present when using structured formats
|
|
307
|
+
*/
|
|
308
|
+
structuredFormat?: string;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Variables auto-injected by the Categorize node
|
|
312
|
+
*/
|
|
313
|
+
interface CategorizeAutoVariables {
|
|
314
|
+
/**
|
|
315
|
+
* Array of available categories from config.categories
|
|
316
|
+
*/
|
|
317
|
+
categories: string[];
|
|
318
|
+
/**
|
|
319
|
+
* The document text extracted from DocumentIR or FlowInput
|
|
320
|
+
*/
|
|
321
|
+
documentText: string;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Variables auto-injected by the Parse node
|
|
325
|
+
*/
|
|
326
|
+
interface ParseAutoVariables {
|
|
327
|
+
/**
|
|
328
|
+
* Output format from config.format
|
|
329
|
+
* Default: 'text'
|
|
330
|
+
*/
|
|
331
|
+
format: 'text' | 'markdown' | 'html';
|
|
332
|
+
/**
|
|
333
|
+
* Schema for structured parsing, if provided in config
|
|
334
|
+
*/
|
|
335
|
+
schema?: object;
|
|
336
|
+
/**
|
|
337
|
+
* Whether to describe figures/charts/diagrams from config.describeFigures
|
|
338
|
+
* Default: false
|
|
339
|
+
*/
|
|
340
|
+
describeFigures: boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Whether citation tracking is enabled from config.citations?.enabled
|
|
343
|
+
*/
|
|
344
|
+
citationsEnabled: boolean | undefined;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Union type of all auto-injected variables across all node types
|
|
348
|
+
*/
|
|
349
|
+
type AllAutoVariables = ExtractAutoVariables | CategorizeAutoVariables | ParseAutoVariables;
|
|
350
|
+
/**
|
|
351
|
+
* Utility type to get the auto-injected variables for a specific node type
|
|
352
|
+
*/
|
|
353
|
+
type AutoVariablesForNode<T extends 'extract' | 'categorize' | 'parse'> = T extends 'extract' ? ExtractAutoVariables : T extends 'categorize' ? CategorizeAutoVariables : T extends 'parse' ? ParseAutoVariables : never;
|
|
354
|
+
/**
|
|
355
|
+
* Helper type for custom promptVariables that combines auto-injected vars with user vars
|
|
356
|
+
*/
|
|
357
|
+
type PromptVariables<TNodeType extends 'extract' | 'categorize' | 'parse', TCustomVars extends Record<string, any> = {}> = AutoVariablesForNode<TNodeType> & TCustomVars;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* MIME Type Detection Utility
|
|
361
|
+
*
|
|
362
|
+
* Detects MIME types from actual file data (magic bytes) to prevent mismatches
|
|
363
|
+
* between declared MIME types and actual file content.
|
|
364
|
+
*
|
|
365
|
+
* Uses the `file-type` package for comprehensive format detection, with
|
|
366
|
+
* manual fallback for basic types in synchronous contexts.
|
|
367
|
+
*/
|
|
368
|
+
/**
|
|
369
|
+
* Detects MIME type from base64-encoded data using the file-type package.
|
|
370
|
+
* This is the preferred async method that supports 100+ file formats.
|
|
371
|
+
*
|
|
372
|
+
* @param base64Data - Base64 string (with or without data URI prefix)
|
|
373
|
+
* @returns Detected MIME type (e.g., "image/jpeg", "application/pdf")
|
|
374
|
+
* @throws Error if format is unsupported or data is invalid
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* const base64 = "data:image/jpeg;base64,/9j/4AAQSkZJRg...";
|
|
379
|
+
* const mimeType = await detectMimeTypeFromBase64Async(base64);
|
|
380
|
+
* console.log(mimeType); // "image/jpeg"
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
declare function detectMimeTypeFromBase64Async(base64Data: string): Promise<string>;
|
|
384
|
+
/**
|
|
385
|
+
* Detects MIME type from base64-encoded data by examining magic bytes.
|
|
386
|
+
* This is a synchronous fallback for basic formats.
|
|
387
|
+
*
|
|
388
|
+
* Supports:
|
|
389
|
+
* - Images: JPEG, PNG, WebP, GIF, TIFF, BMP
|
|
390
|
+
* - Documents: PDF, RTF
|
|
391
|
+
* - Archives: ZIP (for DOCX, XLSX, PPTX, EPUB detection via extension)
|
|
392
|
+
*
|
|
393
|
+
* @param base64Data - Base64 string (with or without data URI prefix)
|
|
394
|
+
* @returns Detected MIME type (e.g., "image/jpeg", "application/pdf")
|
|
395
|
+
* @throws Error if format is unsupported or data is invalid
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```typescript
|
|
399
|
+
* const base64 = "data:image/jpeg;base64,/9j/4AAQSkZJRg...";
|
|
400
|
+
* const mimeType = detectMimeTypeFromBase64(base64);
|
|
401
|
+
* console.log(mimeType); // "image/jpeg"
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
declare function detectMimeTypeFromBase64(base64Data: string): string;
|
|
405
|
+
/**
|
|
406
|
+
* Detects MIME type from raw byte array.
|
|
407
|
+
*
|
|
408
|
+
* @param bytes - Uint8Array containing file data
|
|
409
|
+
* @returns Detected MIME type
|
|
410
|
+
* @throws Error if format is unsupported
|
|
411
|
+
*/
|
|
412
|
+
declare function detectMimeTypeFromBytes(bytes: Uint8Array): string;
|
|
413
|
+
/**
|
|
414
|
+
* Validates that declared MIME type matches actual file data.
|
|
415
|
+
*
|
|
416
|
+
* @param base64Data - Base64 string (with or without data URI prefix)
|
|
417
|
+
* @param declaredMimeType - MIME type that was declared/expected
|
|
418
|
+
* @returns Object with validation result and actual MIME type
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* const result = validateMimeType(base64Data, "image/jpeg");
|
|
423
|
+
* if (!result.isValid) {
|
|
424
|
+
* console.warn(`MIME mismatch: declared ${result.declaredMimeType}, actual ${result.actualMimeType}`);
|
|
425
|
+
* }
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
declare function validateMimeType(base64Data: string, declaredMimeType: string): {
|
|
429
|
+
isValid: boolean;
|
|
430
|
+
actualMimeType: string;
|
|
431
|
+
declaredMimeType: string;
|
|
432
|
+
};
|
|
433
|
+
/**
|
|
434
|
+
* Async version of validateMimeType using file-type for comprehensive detection.
|
|
435
|
+
*/
|
|
436
|
+
declare function validateMimeTypeAsync(base64Data: string, declaredMimeType: string): Promise<{
|
|
437
|
+
isValid: boolean;
|
|
438
|
+
actualMimeType: string;
|
|
439
|
+
declaredMimeType: string;
|
|
440
|
+
}>;
|
|
441
|
+
/**
|
|
442
|
+
* Extracts base64 data from a data URI or returns the data as-is if already base64.
|
|
443
|
+
*
|
|
444
|
+
* @param data - Data URI or base64 string
|
|
445
|
+
* @returns Pure base64 string without prefix
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```typescript
|
|
449
|
+
* extractBase64("data:image/jpeg;base64,/9j/4AAQ...") // "/9j/4AAQ..."
|
|
450
|
+
* extractBase64("/9j/4AAQ...") // "/9j/4AAQ..."
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
declare function extractBase64(data: string): string;
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Unified Provider Query Interface
|
|
457
|
+
*
|
|
458
|
+
* Provides a unified way to query and filter provider metadata across
|
|
459
|
+
* all provider packages (@doclo/providers-llm, @doclo/providers-datalab).
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* import { queryProviders, registerProviderMetadata } from '@doclo/core';
|
|
464
|
+
*
|
|
465
|
+
* // Register metadata from provider packages (done automatically if packages are imported)
|
|
466
|
+
* import { PROVIDER_METADATA as LLM_METADATA } from '@doclo/providers-llm';
|
|
467
|
+
* import { PROVIDER_METADATA as DATALAB_METADATA } from '@doclo/providers-datalab';
|
|
468
|
+
*
|
|
469
|
+
* registerProviderMetadata('llm', LLM_METADATA);
|
|
470
|
+
* registerProviderMetadata('datalab', DATALAB_METADATA);
|
|
471
|
+
*
|
|
472
|
+
* // Query providers
|
|
473
|
+
* const pdfProviders = queryProviders({ supports: { pdfs: true } });
|
|
474
|
+
* const cheapProviders = queryProviders({ maxCostPerPage: 0.01 });
|
|
475
|
+
* const largeFileProviders = queryProviders({ minFileSize: 100 }); // 100 MB+
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
/**
|
|
479
|
+
* Input type requirements for providers/models.
|
|
480
|
+
* More normalized than a boolean - allows for future extensibility.
|
|
481
|
+
*
|
|
482
|
+
* - 'raw-document': Needs FlowInput with base64/url (OCR/VLM providers like marker-vlm)
|
|
483
|
+
* - 'parsed-text': Needs DocumentIR text output from parse step (text-only processors)
|
|
484
|
+
* - 'any': Can work with either (most vision LLMs like GPT-4o, Claude with vision)
|
|
485
|
+
*/
|
|
486
|
+
type ProviderInputType = 'raw-document' | 'parsed-text' | 'any';
|
|
487
|
+
/**
|
|
488
|
+
* Input requirements specification for a provider or model.
|
|
489
|
+
* Determines what form of document input is expected.
|
|
490
|
+
*/
|
|
491
|
+
type InputRequirements = {
|
|
492
|
+
/**
|
|
493
|
+
* What type of input this provider accepts.
|
|
494
|
+
* - 'raw-document': Needs PDF/image bytes directly (marker-vlm, reducto-extract)
|
|
495
|
+
* - 'parsed-text': Needs DocumentIR text (text-only processors)
|
|
496
|
+
* - 'any': Can work with either (vision LLMs like GPT-4o, Claude)
|
|
497
|
+
*/
|
|
498
|
+
inputType: ProviderInputType;
|
|
499
|
+
/**
|
|
500
|
+
* Accepted input methods when inputType is 'raw-document'.
|
|
501
|
+
* Inherited from inputFormats.inputMethods if not specified.
|
|
502
|
+
*/
|
|
503
|
+
acceptedMethods?: readonly ('url' | 'base64' | 'fileId')[];
|
|
504
|
+
};
|
|
505
|
+
/**
|
|
506
|
+
* Output format support flags
|
|
507
|
+
*/
|
|
508
|
+
type OutputFormatSupport = {
|
|
509
|
+
text: boolean;
|
|
510
|
+
markdown: boolean;
|
|
511
|
+
html: boolean;
|
|
512
|
+
json: boolean;
|
|
513
|
+
};
|
|
514
|
+
/**
|
|
515
|
+
* Normalized features across all providers.
|
|
516
|
+
* Maps provider-specific option names to unified names.
|
|
517
|
+
*
|
|
518
|
+
* This enables UIs to query "what features does this provider support?"
|
|
519
|
+
* and get a consistent answer across all providers.
|
|
520
|
+
*/
|
|
521
|
+
type NormalizedFeatures = {
|
|
522
|
+
/** Limit to first N pages */
|
|
523
|
+
maxPages: boolean;
|
|
524
|
+
/** Specific page range selection */
|
|
525
|
+
pageRange: boolean;
|
|
526
|
+
/** OCR language hints (maps from 'langs') */
|
|
527
|
+
languageHints: boolean;
|
|
528
|
+
/** Quality/speed modes (fast/balanced/high_accuracy) */
|
|
529
|
+
processingModes: boolean;
|
|
530
|
+
/** Reducto agentic mode (higher accuracy, more cost) */
|
|
531
|
+
agenticMode: boolean;
|
|
532
|
+
/** Custom prompts (maps from blockCorrectionPrompt, additionalPrompt, systemPrompt) */
|
|
533
|
+
customPrompts: boolean;
|
|
534
|
+
/** Extract embedded images (maps from extractImages, returnImages) */
|
|
535
|
+
imageExtraction: boolean;
|
|
536
|
+
/** Page delimiters (maps from paginate, addPageMarkers) */
|
|
537
|
+
pageMarkers: boolean;
|
|
538
|
+
/** Field-level citations with source references */
|
|
539
|
+
citations: boolean;
|
|
540
|
+
/** Document chunking modes (RAG-optimized) */
|
|
541
|
+
chunking: boolean;
|
|
542
|
+
/** Auto-segmentation for multi-document PDFs */
|
|
543
|
+
segmentation: boolean;
|
|
544
|
+
/** Re-run OCR on already-OCR'd documents */
|
|
545
|
+
stripExistingOCR: boolean;
|
|
546
|
+
/** Format lines in output */
|
|
547
|
+
formatLines: boolean;
|
|
548
|
+
/** Force OCR even if text layer exists */
|
|
549
|
+
forceOCR: boolean;
|
|
550
|
+
/** Table format options (html/json/md/csv) */
|
|
551
|
+
tableOutputFormats: boolean;
|
|
552
|
+
/** Merge consecutive tables */
|
|
553
|
+
tableMerging: boolean;
|
|
554
|
+
/** Block-level confidence scores */
|
|
555
|
+
confidence: boolean;
|
|
556
|
+
/** Bounding box coordinates for text/elements */
|
|
557
|
+
boundingBoxes: boolean;
|
|
558
|
+
/** JSON schema validation for structured output */
|
|
559
|
+
schemaValidation: boolean;
|
|
560
|
+
/** Handwritten text recognition support */
|
|
561
|
+
handwrittenText: boolean;
|
|
562
|
+
/** Supported output formats */
|
|
563
|
+
outputFormats: OutputFormatSupport;
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
type NormalizedProviderMetadata = {
|
|
567
|
+
id: string;
|
|
568
|
+
name: string;
|
|
569
|
+
source: 'llm' | 'datalab' | 'unsiloed' | 'reducto' | string;
|
|
570
|
+
type: 'LLM' | 'OCR' | 'VLM' | 'Split';
|
|
571
|
+
identity?: {
|
|
572
|
+
/** Provider vendor (company) */
|
|
573
|
+
provider: ProviderVendor | string;
|
|
574
|
+
/** Model identifier */
|
|
575
|
+
model: string;
|
|
576
|
+
/** Access method (native, openrouter, self-hosted) */
|
|
577
|
+
method?: AccessMethod;
|
|
578
|
+
};
|
|
579
|
+
capabilities: {
|
|
580
|
+
supportsImages: boolean;
|
|
581
|
+
supportsPDFs: boolean;
|
|
582
|
+
supportsDocuments: boolean;
|
|
583
|
+
supportsReasoning: boolean;
|
|
584
|
+
supportsStructuredOutput: boolean;
|
|
585
|
+
supportsPrompts: boolean;
|
|
586
|
+
supportsCitations: boolean;
|
|
587
|
+
supportsChunking: boolean;
|
|
588
|
+
supportsImageExtraction: boolean;
|
|
589
|
+
supportsPageMarkers: boolean;
|
|
590
|
+
supportsLanguageHints: boolean;
|
|
591
|
+
supportsProcessingModes: boolean;
|
|
592
|
+
supportsSegmentation: boolean;
|
|
593
|
+
outputFormats: OutputFormatSupport;
|
|
594
|
+
};
|
|
595
|
+
features: NormalizedFeatures;
|
|
596
|
+
inputRequirements: InputRequirements;
|
|
597
|
+
compatibleNodes: {
|
|
598
|
+
parse: boolean;
|
|
599
|
+
extract: boolean;
|
|
600
|
+
categorize: boolean;
|
|
601
|
+
qualify: boolean;
|
|
602
|
+
split: boolean;
|
|
603
|
+
};
|
|
604
|
+
inputFormats: {
|
|
605
|
+
imageMimeTypes: readonly string[];
|
|
606
|
+
documentMimeTypes: readonly string[];
|
|
607
|
+
inputMethods: readonly ('url' | 'base64' | 'fileId')[];
|
|
608
|
+
maxImageSize?: number;
|
|
609
|
+
maxPdfSize?: number;
|
|
610
|
+
maxFileSize?: number;
|
|
611
|
+
maxPages?: number;
|
|
612
|
+
};
|
|
613
|
+
pricing: {
|
|
614
|
+
model: 'per-token' | 'per-page';
|
|
615
|
+
inputPer1kTokens?: number;
|
|
616
|
+
outputPer1kTokens?: number;
|
|
617
|
+
perPage?: number;
|
|
618
|
+
currency: 'USD';
|
|
619
|
+
notes?: string;
|
|
620
|
+
};
|
|
621
|
+
rateLimits?: {
|
|
622
|
+
requestsPerMinute?: number;
|
|
623
|
+
docsPerMinute?: number;
|
|
624
|
+
};
|
|
625
|
+
raw: unknown;
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* Feature names that can be queried (excludes outputFormats which is nested)
|
|
629
|
+
*/
|
|
630
|
+
type FeatureName = Exclude<keyof NormalizedFeatures, 'outputFormats'>;
|
|
631
|
+
type ProviderQueryFilter = {
|
|
632
|
+
source?: 'llm' | 'datalab' | 'unsiloed' | 'reducto' | string | string[];
|
|
633
|
+
type?: 'LLM' | 'OCR' | 'VLM' | 'Split' | ('LLM' | 'OCR' | 'VLM' | 'Split')[];
|
|
634
|
+
/** Filter by provider vendor (company) */
|
|
635
|
+
provider?: ProviderVendor | ProviderVendor[] | string | string[];
|
|
636
|
+
/** Filter by model ID (requires provider to be specified for best results) */
|
|
637
|
+
model?: string | string[];
|
|
638
|
+
/** Filter by access method */
|
|
639
|
+
method?: AccessMethod | AccessMethod[];
|
|
640
|
+
supports?: {
|
|
641
|
+
images?: boolean;
|
|
642
|
+
pdfs?: boolean;
|
|
643
|
+
documents?: boolean;
|
|
644
|
+
reasoning?: boolean;
|
|
645
|
+
structuredOutput?: boolean;
|
|
646
|
+
prompts?: boolean;
|
|
647
|
+
citations?: boolean;
|
|
648
|
+
chunking?: boolean;
|
|
649
|
+
imageExtraction?: boolean;
|
|
650
|
+
pageMarkers?: boolean;
|
|
651
|
+
languageHints?: boolean;
|
|
652
|
+
processingModes?: boolean;
|
|
653
|
+
segmentation?: boolean;
|
|
654
|
+
};
|
|
655
|
+
hasFeatures?: FeatureName[];
|
|
656
|
+
outputFormat?: 'text' | 'markdown' | 'html' | 'json';
|
|
657
|
+
inputRequirements?: {
|
|
658
|
+
/**
|
|
659
|
+
* Filter by input type requirement.
|
|
660
|
+
* - 'raw-document': Only providers that need raw document input
|
|
661
|
+
* - 'parsed-text': Only providers that need parsed text
|
|
662
|
+
* - 'any': Only providers that accept any input type
|
|
663
|
+
* - ['raw-document', 'any']: Providers that accept raw documents (raw-document OR any)
|
|
664
|
+
*/
|
|
665
|
+
inputType?: ProviderInputType | ProviderInputType[];
|
|
666
|
+
};
|
|
667
|
+
compatibleWith?: ('parse' | 'extract' | 'categorize' | 'qualify' | 'split')[];
|
|
668
|
+
mimeType?: string | string[];
|
|
669
|
+
minFileSize?: number;
|
|
670
|
+
maxFileSize?: number;
|
|
671
|
+
maxCostPerPage?: number;
|
|
672
|
+
maxCostPer1kTokens?: number;
|
|
673
|
+
filter?: (provider: NormalizedProviderMetadata) => boolean;
|
|
674
|
+
};
|
|
675
|
+
/**
|
|
676
|
+
* Register provider metadata from a provider package
|
|
677
|
+
*
|
|
678
|
+
* @param source - Source identifier (e.g., 'llm', 'datalab')
|
|
679
|
+
* @param metadata - Raw metadata object from the provider package
|
|
680
|
+
* @param normalizer - Function to normalize the metadata
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```typescript
|
|
684
|
+
* import { PROVIDER_METADATA } from '@doclo/providers-llm';
|
|
685
|
+
* registerProviderMetadata('llm', PROVIDER_METADATA, normalizeLLMMetadata);
|
|
686
|
+
* ```
|
|
687
|
+
*/
|
|
688
|
+
declare function registerProviderMetadata(source: string, metadata: Record<string, unknown>, normalizer?: (id: string, data: unknown, source: string) => NormalizedProviderMetadata): void;
|
|
689
|
+
/**
|
|
690
|
+
* Get all registered providers (normalized)
|
|
691
|
+
*/
|
|
692
|
+
declare function getAllProviders(): NormalizedProviderMetadata[];
|
|
693
|
+
/**
|
|
694
|
+
* Query providers with filters
|
|
695
|
+
*
|
|
696
|
+
* @param filter - Query filters
|
|
697
|
+
* @returns Array of matching providers
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* ```typescript
|
|
701
|
+
* // Get all providers that support PDFs
|
|
702
|
+
* const pdfProviders = queryProviders({ supports: { pdfs: true } });
|
|
703
|
+
*
|
|
704
|
+
* // Get cheap OCR providers
|
|
705
|
+
* const cheapOcr = queryProviders({
|
|
706
|
+
* type: 'OCR',
|
|
707
|
+
* maxCostPerPage: 0.02
|
|
708
|
+
* });
|
|
709
|
+
*
|
|
710
|
+
* // Get providers that can handle large files
|
|
711
|
+
* const largeFileProviders = queryProviders({ minFileSize: 100 });
|
|
712
|
+
*
|
|
713
|
+
* // Get providers compatible with extract() node
|
|
714
|
+
* const extractProviders = queryProviders({
|
|
715
|
+
* compatibleWith: ['extract']
|
|
716
|
+
* });
|
|
717
|
+
* ```
|
|
718
|
+
*/
|
|
719
|
+
declare function queryProviders(filter?: ProviderQueryFilter): NormalizedProviderMetadata[];
|
|
720
|
+
/**
|
|
721
|
+
* Get a single provider by ID
|
|
722
|
+
*/
|
|
723
|
+
declare function getProviderById(id: string): NormalizedProviderMetadata | undefined;
|
|
724
|
+
/**
|
|
725
|
+
* Get providers by source
|
|
726
|
+
*/
|
|
727
|
+
declare function getProvidersBySource(source: string): NormalizedProviderMetadata[];
|
|
728
|
+
/**
|
|
729
|
+
* Clear all registered providers (useful for testing)
|
|
730
|
+
*/
|
|
731
|
+
declare function clearProviderRegistry(): void;
|
|
732
|
+
/**
|
|
733
|
+
* Get providers that support a specific MIME type
|
|
734
|
+
*/
|
|
735
|
+
declare function getProvidersForMimeType(mimeType: string): NormalizedProviderMetadata[];
|
|
736
|
+
/**
|
|
737
|
+
* Get the cheapest provider for a specific capability
|
|
738
|
+
*/
|
|
739
|
+
declare function getCheapestProviderFor(capability: 'ocr' | 'extraction' | 'parse'): NormalizedProviderMetadata | undefined;
|
|
740
|
+
/**
|
|
741
|
+
* Get providers with the largest file size support
|
|
742
|
+
*/
|
|
743
|
+
declare function getProvidersForLargeFiles(minSizeMB?: number): NormalizedProviderMetadata[];
|
|
744
|
+
/**
|
|
745
|
+
* Type alias for capabilities object (for model override typing)
|
|
746
|
+
*/
|
|
747
|
+
type NormalizedCapabilities = NormalizedProviderMetadata['capabilities'];
|
|
748
|
+
/**
|
|
749
|
+
* Type alias for node compatibility object
|
|
750
|
+
*/
|
|
751
|
+
type NodeCompatibility = NormalizedProviderMetadata['compatibleNodes'];
|
|
752
|
+
/**
|
|
753
|
+
* Type alias for pricing configuration
|
|
754
|
+
*/
|
|
755
|
+
type NormalizedPricing = NormalizedProviderMetadata['pricing'];
|
|
756
|
+
/**
|
|
757
|
+
* Node type names for querying
|
|
758
|
+
*/
|
|
759
|
+
type NodeTypeName = 'parse' | 'extract' | 'categorize' | 'qualify' | 'split';
|
|
760
|
+
/**
|
|
761
|
+
* Model-level limits that may differ from provider defaults
|
|
762
|
+
*/
|
|
763
|
+
type ModelLimits = {
|
|
764
|
+
maxContextTokens?: number;
|
|
765
|
+
maxOutputTokens?: number;
|
|
766
|
+
maxFileSize?: number;
|
|
767
|
+
maxPages?: number;
|
|
768
|
+
};
|
|
769
|
+
/**
|
|
770
|
+
* Model-level metadata that can override provider defaults.
|
|
771
|
+
* Unspecified fields inherit from the provider.
|
|
772
|
+
*/
|
|
773
|
+
type ModelMetadata = {
|
|
774
|
+
/** Model ID as used in API calls */
|
|
775
|
+
id: string;
|
|
776
|
+
/** Human-readable name (optional, defaults to id) */
|
|
777
|
+
name?: string;
|
|
778
|
+
/** OpenRouter model ID (e.g., 'openai/gpt-4.1') */
|
|
779
|
+
openRouterId?: string;
|
|
780
|
+
/** Override provider capabilities */
|
|
781
|
+
capabilities?: Partial<NormalizedCapabilities>;
|
|
782
|
+
/** Override provider input requirements */
|
|
783
|
+
inputRequirements?: Partial<InputRequirements>;
|
|
784
|
+
/** Override provider node compatibility */
|
|
785
|
+
compatibleNodes?: Partial<NodeCompatibility>;
|
|
786
|
+
/** Model-specific pricing */
|
|
787
|
+
pricing?: {
|
|
788
|
+
inputPer1kTokens?: number;
|
|
789
|
+
outputPer1kTokens?: number;
|
|
790
|
+
perPage?: number;
|
|
791
|
+
};
|
|
792
|
+
/** Model-specific limits */
|
|
793
|
+
limits?: ModelLimits;
|
|
794
|
+
};
|
|
795
|
+
/**
|
|
796
|
+
* Provider metadata extended with model array
|
|
797
|
+
*/
|
|
798
|
+
type ProviderMetadataWithModels = NormalizedProviderMetadata & {
|
|
799
|
+
/** Per-model metadata with override capabilities */
|
|
800
|
+
models?: ModelMetadata[];
|
|
801
|
+
};
|
|
802
|
+
/**
|
|
803
|
+
* Fully resolved model metadata (all inheritance applied)
|
|
804
|
+
*/
|
|
805
|
+
type ResolvedModelMetadata = {
|
|
806
|
+
modelId: string;
|
|
807
|
+
modelName: string;
|
|
808
|
+
openRouterId?: string;
|
|
809
|
+
providerId: string;
|
|
810
|
+
providerName: string;
|
|
811
|
+
providerSource: string;
|
|
812
|
+
capabilities: NormalizedCapabilities;
|
|
813
|
+
features: NormalizedFeatures;
|
|
814
|
+
inputRequirements: InputRequirements;
|
|
815
|
+
compatibleNodes: NodeCompatibility;
|
|
816
|
+
pricing: NormalizedPricing;
|
|
817
|
+
limits?: ModelLimits;
|
|
818
|
+
};
|
|
819
|
+
/**
|
|
820
|
+
* Filter options for model queries
|
|
821
|
+
*/
|
|
822
|
+
type ModelQueryFilter = {
|
|
823
|
+
/** Filter by provider ID */
|
|
824
|
+
providerId?: string | string[];
|
|
825
|
+
/** Filter by provider source */
|
|
826
|
+
source?: string | string[];
|
|
827
|
+
/** Filter by capabilities */
|
|
828
|
+
supports?: {
|
|
829
|
+
images?: boolean;
|
|
830
|
+
pdfs?: boolean;
|
|
831
|
+
documents?: boolean;
|
|
832
|
+
reasoning?: boolean;
|
|
833
|
+
structuredOutput?: boolean;
|
|
834
|
+
prompts?: boolean;
|
|
835
|
+
citations?: boolean;
|
|
836
|
+
chunking?: boolean;
|
|
837
|
+
imageExtraction?: boolean;
|
|
838
|
+
pageMarkers?: boolean;
|
|
839
|
+
languageHints?: boolean;
|
|
840
|
+
processingModes?: boolean;
|
|
841
|
+
segmentation?: boolean;
|
|
842
|
+
};
|
|
843
|
+
/** Filter by specific features (all must be supported) */
|
|
844
|
+
hasFeatures?: FeatureName[];
|
|
845
|
+
/** Filter by output format support */
|
|
846
|
+
outputFormat?: 'text' | 'markdown' | 'html' | 'json';
|
|
847
|
+
/** Filter by input requirements */
|
|
848
|
+
inputRequirements?: {
|
|
849
|
+
inputType?: ProviderInputType | ProviderInputType[];
|
|
850
|
+
};
|
|
851
|
+
/** Filter by node compatibility */
|
|
852
|
+
compatibleWith?: NodeTypeName[];
|
|
853
|
+
/** Filter by context window (minimum) */
|
|
854
|
+
minContextTokens?: number;
|
|
855
|
+
/** Custom filter function */
|
|
856
|
+
filter?: (model: ResolvedModelMetadata) => boolean;
|
|
857
|
+
};
|
|
858
|
+
/**
|
|
859
|
+
* Register provider metadata with model information
|
|
860
|
+
*
|
|
861
|
+
* @param providerId - Provider identifier
|
|
862
|
+
* @param metadata - Provider metadata with models array
|
|
863
|
+
*/
|
|
864
|
+
declare function registerProviderWithModels(providerId: string, metadata: ProviderMetadataWithModels): void;
|
|
865
|
+
/**
|
|
866
|
+
* Resolve model metadata by applying inheritance from provider.
|
|
867
|
+
* Returns fully resolved metadata for a specific model.
|
|
868
|
+
*
|
|
869
|
+
* @param providerId - Provider ID (e.g., 'openai', 'anthropic')
|
|
870
|
+
* @param modelId - Model ID (e.g., 'gpt-4.1', 'claude-sonnet-4.5'). If not provided, returns provider defaults.
|
|
871
|
+
* @returns Resolved model metadata or undefined if not found
|
|
872
|
+
*
|
|
873
|
+
* @example
|
|
874
|
+
* ```typescript
|
|
875
|
+
* const gpt4 = resolveModelMetadata('openai', 'gpt-4.1');
|
|
876
|
+
* console.log(gpt4?.capabilities.supportsReasoning); // false
|
|
877
|
+
*
|
|
878
|
+
* const o3 = resolveModelMetadata('openai', 'o3');
|
|
879
|
+
* console.log(o3?.capabilities.supportsReasoning); // true
|
|
880
|
+
* ```
|
|
881
|
+
*/
|
|
882
|
+
declare function resolveModelMetadata(providerId: string, modelId?: string): ResolvedModelMetadata | undefined;
|
|
883
|
+
/**
|
|
884
|
+
* Query models with filters.
|
|
885
|
+
* Returns all models that match the filter criteria.
|
|
886
|
+
*
|
|
887
|
+
* @param filter - Query filters
|
|
888
|
+
* @returns Array of matching resolved model metadata
|
|
889
|
+
*
|
|
890
|
+
* @example
|
|
891
|
+
* ```typescript
|
|
892
|
+
* // Get all reasoning models
|
|
893
|
+
* const reasoningModels = queryModels({ supports: { reasoning: true } });
|
|
894
|
+
*
|
|
895
|
+
* // Get models with large context windows
|
|
896
|
+
* const largeContextModels = queryModels({ minContextTokens: 100000 });
|
|
897
|
+
*
|
|
898
|
+
* // Get OpenAI models compatible with extract()
|
|
899
|
+
* const openaiExtract = queryModels({
|
|
900
|
+
* providerId: 'openai',
|
|
901
|
+
* compatibleWith: ['extract']
|
|
902
|
+
* });
|
|
903
|
+
* ```
|
|
904
|
+
*/
|
|
905
|
+
declare function queryModels(filter?: ModelQueryFilter): ResolvedModelMetadata[];
|
|
906
|
+
/**
|
|
907
|
+
* Get all models compatible with a specific node type.
|
|
908
|
+
*
|
|
909
|
+
* @param nodeType - Node type to check compatibility
|
|
910
|
+
* @returns Array of resolved model metadata
|
|
911
|
+
*
|
|
912
|
+
* @example
|
|
913
|
+
* ```typescript
|
|
914
|
+
* // Get all models that can be used with extract()
|
|
915
|
+
* const extractModels = getModelsForNode('extract');
|
|
916
|
+
*
|
|
917
|
+
* // Get all models that can be used with parse()
|
|
918
|
+
* const parseModels = getModelsForNode('parse');
|
|
919
|
+
* ```
|
|
920
|
+
*/
|
|
921
|
+
declare function getModelsForNode(nodeType: NodeTypeName): ResolvedModelMetadata[];
|
|
922
|
+
/**
|
|
923
|
+
* Get all registered models (resolved)
|
|
924
|
+
*/
|
|
925
|
+
declare function getAllModels(): ResolvedModelMetadata[];
|
|
926
|
+
/**
|
|
927
|
+
* Clear model registry (useful for testing)
|
|
928
|
+
*/
|
|
929
|
+
declare function clearModelRegistry(): void;
|
|
930
|
+
|
|
931
|
+
export { type AcceptedMimeType, AccessMethod, type AllAutoVariables, type AutoVariablesForNode, type BaseProviderConfig, type CategorizeAutoVariables, type DocumentMimeType, type ExtractAutoVariables, type FeatureName, FlowInputValidationError, type InputRequirements, type ModelMetadata, type ModelQueryFilter, type NormalizedCapabilities, type NormalizedFeatures, type NormalizedProviderMetadata, type OCRProviderConfig, type OutputFormatSupport, type ParseAutoVariables, type PromptVariables, type ProviderConfig, type ProviderInputType, type ProviderInstance, type ProviderMetadataWithModels, type ProviderQueryFilter, type ProviderRegistry, type ProviderSecrets, ProviderVendor, type ResolvedModelMetadata, type VLMProviderConfig, bufferToBase64, bufferToDataUri, buildProviderFromConfig, buildProvidersFromConfigs, clearModelRegistry, clearProviderRegistry, defineMarkerProvider, defineSuryaProvider, defineVLMProvider, detectDocumentType, detectMimeTypeFromBase64, detectMimeTypeFromBase64Async, detectMimeTypeFromBytes, extractBase64, getAllModels, getAllProviders, getCheapestProviderFor, getModelsForNode, getProviderById, getProvidersBySource, getProvidersForLargeFiles, getProvidersForMimeType, isPDFDocument, queryModels, queryProviders, registerProviderMetadata, registerProviderWithModels, resolveDocument, resolveModelMetadata, validateFlowInputFormat, validateMimeType, validateMimeTypeAsync };
|