@anyformat/sdk 0.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/README.md +55 -0
- package/dist/index.cjs +1237 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1420 -0
- package/dist/index.d.ts +1420 -0
- package/dist/index.js +1196 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1420 @@
|
|
|
1
|
+
type AuthToken = string | undefined;
|
|
2
|
+
interface Auth {
|
|
3
|
+
/**
|
|
4
|
+
* Which part of the request do we use to send the auth?
|
|
5
|
+
*
|
|
6
|
+
* @default 'header'
|
|
7
|
+
*/
|
|
8
|
+
in?: 'header' | 'query' | 'cookie';
|
|
9
|
+
/**
|
|
10
|
+
* Header or query parameter name.
|
|
11
|
+
*
|
|
12
|
+
* @default 'Authorization'
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
scheme?: 'basic' | 'bearer';
|
|
16
|
+
type: 'apiKey' | 'http';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface SerializerOptions<T> {
|
|
20
|
+
/**
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
explode: boolean;
|
|
24
|
+
style: T;
|
|
25
|
+
}
|
|
26
|
+
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
|
|
27
|
+
type ObjectStyle = 'form' | 'deepObject';
|
|
28
|
+
|
|
29
|
+
type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
30
|
+
type BodySerializer = (body: unknown) => unknown;
|
|
31
|
+
type QuerySerializerOptionsObject = {
|
|
32
|
+
allowReserved?: boolean;
|
|
33
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
34
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
35
|
+
};
|
|
36
|
+
type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
37
|
+
/**
|
|
38
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
39
|
+
* override the global array/object settings for specific parameter names.
|
|
40
|
+
*/
|
|
41
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
|
|
45
|
+
type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
|
|
46
|
+
/**
|
|
47
|
+
* Returns the final request URL.
|
|
48
|
+
*/
|
|
49
|
+
buildUrl: BuildUrlFn;
|
|
50
|
+
getConfig: () => Config;
|
|
51
|
+
request: RequestFn;
|
|
52
|
+
setConfig: (config: Config) => Config;
|
|
53
|
+
} & {
|
|
54
|
+
[K in HttpMethod]: MethodFn;
|
|
55
|
+
} & ([SseFn] extends [never] ? {
|
|
56
|
+
sse?: never;
|
|
57
|
+
} : {
|
|
58
|
+
sse: {
|
|
59
|
+
[K in HttpMethod]: SseFn;
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
interface Config$1 {
|
|
63
|
+
/**
|
|
64
|
+
* Auth token or a function returning auth token. The resolved value will be
|
|
65
|
+
* added to the request payload as defined by its `security` array.
|
|
66
|
+
*/
|
|
67
|
+
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
|
|
68
|
+
/**
|
|
69
|
+
* A function for serializing request body parameter. By default,
|
|
70
|
+
* {@link JSON.stringify()} will be used.
|
|
71
|
+
*/
|
|
72
|
+
bodySerializer?: BodySerializer | null;
|
|
73
|
+
/**
|
|
74
|
+
* An object containing any HTTP headers that you want to pre-populate your
|
|
75
|
+
* `Headers` object with.
|
|
76
|
+
*
|
|
77
|
+
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
|
78
|
+
*/
|
|
79
|
+
headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
|
|
80
|
+
/**
|
|
81
|
+
* The request method.
|
|
82
|
+
*
|
|
83
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
|
|
84
|
+
*/
|
|
85
|
+
method?: Uppercase<HttpMethod>;
|
|
86
|
+
/**
|
|
87
|
+
* A function for serializing request query parameters. By default, arrays
|
|
88
|
+
* will be exploded in form style, objects will be exploded in deepObject
|
|
89
|
+
* style, and reserved characters are percent-encoded.
|
|
90
|
+
*
|
|
91
|
+
* This method will have no effect if the native `paramsSerializer()` Axios
|
|
92
|
+
* API function is used.
|
|
93
|
+
*
|
|
94
|
+
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
|
|
95
|
+
*/
|
|
96
|
+
querySerializer?: QuerySerializer | QuerySerializerOptions;
|
|
97
|
+
/**
|
|
98
|
+
* A function validating request data. This is useful if you want to ensure
|
|
99
|
+
* the request conforms to the desired shape, so it can be safely sent to
|
|
100
|
+
* the server.
|
|
101
|
+
*/
|
|
102
|
+
requestValidator?: (data: unknown) => Promise<unknown>;
|
|
103
|
+
/**
|
|
104
|
+
* A function transforming response data before it's returned. This is useful
|
|
105
|
+
* for post-processing data, e.g., converting ISO strings into Date objects.
|
|
106
|
+
*/
|
|
107
|
+
responseTransformer?: (data: unknown) => Promise<unknown>;
|
|
108
|
+
/**
|
|
109
|
+
* A function validating response data. This is useful if you want to ensure
|
|
110
|
+
* the response conforms to the desired shape, so it can be safely passed to
|
|
111
|
+
* the transformers and returned to the user.
|
|
112
|
+
*/
|
|
113
|
+
responseValidator?: (data: unknown) => Promise<unknown>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & {
|
|
117
|
+
/**
|
|
118
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
119
|
+
* fetch instance.
|
|
120
|
+
*
|
|
121
|
+
* @default globalThis.fetch
|
|
122
|
+
*/
|
|
123
|
+
fetch?: typeof fetch;
|
|
124
|
+
/**
|
|
125
|
+
* Implementing clients can call request interceptors inside this hook.
|
|
126
|
+
*/
|
|
127
|
+
onRequest?: (url: string, init: RequestInit) => Promise<Request>;
|
|
128
|
+
/**
|
|
129
|
+
* Callback invoked when a network or parsing error occurs during streaming.
|
|
130
|
+
*
|
|
131
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
132
|
+
*
|
|
133
|
+
* @param error The error that occurred.
|
|
134
|
+
*/
|
|
135
|
+
onSseError?: (error: unknown) => void;
|
|
136
|
+
/**
|
|
137
|
+
* Callback invoked when an event is streamed from the server.
|
|
138
|
+
*
|
|
139
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
140
|
+
*
|
|
141
|
+
* @param event Event streamed from the server.
|
|
142
|
+
* @returns Nothing (void).
|
|
143
|
+
*/
|
|
144
|
+
onSseEvent?: (event: StreamEvent<TData>) => void;
|
|
145
|
+
serializedBody?: RequestInit['body'];
|
|
146
|
+
/**
|
|
147
|
+
* Default retry delay in milliseconds.
|
|
148
|
+
*
|
|
149
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
150
|
+
*
|
|
151
|
+
* @default 3000
|
|
152
|
+
*/
|
|
153
|
+
sseDefaultRetryDelay?: number;
|
|
154
|
+
/**
|
|
155
|
+
* Maximum number of retry attempts before giving up.
|
|
156
|
+
*/
|
|
157
|
+
sseMaxRetryAttempts?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Maximum retry delay in milliseconds.
|
|
160
|
+
*
|
|
161
|
+
* Applies only when exponential backoff is used.
|
|
162
|
+
*
|
|
163
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
164
|
+
*
|
|
165
|
+
* @default 30000
|
|
166
|
+
*/
|
|
167
|
+
sseMaxRetryDelay?: number;
|
|
168
|
+
/**
|
|
169
|
+
* Optional sleep function for retry backoff.
|
|
170
|
+
*
|
|
171
|
+
* Defaults to using `setTimeout`.
|
|
172
|
+
*/
|
|
173
|
+
sseSleepFn?: (ms: number) => Promise<void>;
|
|
174
|
+
url: string;
|
|
175
|
+
};
|
|
176
|
+
interface StreamEvent<TData = unknown> {
|
|
177
|
+
data: TData;
|
|
178
|
+
event?: string;
|
|
179
|
+
id?: string;
|
|
180
|
+
retry?: number;
|
|
181
|
+
}
|
|
182
|
+
type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
|
183
|
+
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err,
|
|
187
|
+
/** response may be undefined due to a network error where no response object is produced */
|
|
188
|
+
response: Res | undefined,
|
|
189
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
190
|
+
request: Req | undefined, options: Options) => Err | Promise<Err>;
|
|
191
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
192
|
+
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
193
|
+
declare class Interceptors<Interceptor> {
|
|
194
|
+
fns: Array<Interceptor | null>;
|
|
195
|
+
clear(): void;
|
|
196
|
+
eject(id: number | Interceptor): void;
|
|
197
|
+
exists(id: number | Interceptor): boolean;
|
|
198
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
199
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
200
|
+
use(fn: Interceptor): number;
|
|
201
|
+
}
|
|
202
|
+
interface Middleware<Req, Res, Err, Options> {
|
|
203
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
204
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
205
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
type ResponseStyle = 'data' | 'fields';
|
|
209
|
+
interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Config$1 {
|
|
210
|
+
/**
|
|
211
|
+
* Base URL for all requests made by this client.
|
|
212
|
+
*/
|
|
213
|
+
baseUrl?: T['baseUrl'];
|
|
214
|
+
/**
|
|
215
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
216
|
+
* fetch instance.
|
|
217
|
+
*
|
|
218
|
+
* @default globalThis.fetch
|
|
219
|
+
*/
|
|
220
|
+
fetch?: typeof fetch;
|
|
221
|
+
/**
|
|
222
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
223
|
+
* options won't have any effect.
|
|
224
|
+
*
|
|
225
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
226
|
+
*/
|
|
227
|
+
next?: never;
|
|
228
|
+
/**
|
|
229
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
230
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
231
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
232
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
233
|
+
*
|
|
234
|
+
* @default 'auto'
|
|
235
|
+
*/
|
|
236
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
237
|
+
/**
|
|
238
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
239
|
+
*
|
|
240
|
+
* @default 'fields'
|
|
241
|
+
*/
|
|
242
|
+
responseStyle?: ResponseStyle;
|
|
243
|
+
/**
|
|
244
|
+
* Throw an error instead of returning it in the response?
|
|
245
|
+
*
|
|
246
|
+
* @default false
|
|
247
|
+
*/
|
|
248
|
+
throwOnError?: T['throwOnError'];
|
|
249
|
+
}
|
|
250
|
+
interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
251
|
+
responseStyle: TResponseStyle;
|
|
252
|
+
throwOnError: ThrowOnError;
|
|
253
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
254
|
+
/**
|
|
255
|
+
* Any body that you want to add to your request.
|
|
256
|
+
*
|
|
257
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
258
|
+
*/
|
|
259
|
+
body?: unknown;
|
|
260
|
+
path?: Record<string, unknown>;
|
|
261
|
+
query?: Record<string, unknown>;
|
|
262
|
+
/**
|
|
263
|
+
* Security mechanism(s) to use for the request.
|
|
264
|
+
*/
|
|
265
|
+
security?: ReadonlyArray<Auth>;
|
|
266
|
+
url: Url;
|
|
267
|
+
}
|
|
268
|
+
interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
269
|
+
headers: Headers;
|
|
270
|
+
serializedBody?: string;
|
|
271
|
+
}
|
|
272
|
+
type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = ThrowOnError extends true ? Promise<TResponseStyle extends 'data' ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
273
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
274
|
+
request: Request;
|
|
275
|
+
response: Response;
|
|
276
|
+
}> : Promise<TResponseStyle extends 'data' ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
277
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
278
|
+
error: undefined;
|
|
279
|
+
} | {
|
|
280
|
+
data: undefined;
|
|
281
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
282
|
+
}) & {
|
|
283
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
284
|
+
request?: Request;
|
|
285
|
+
/** response may be undefined, because error may be from building the request object itself or from a network error */
|
|
286
|
+
response?: Response;
|
|
287
|
+
}>;
|
|
288
|
+
interface ClientOptions {
|
|
289
|
+
baseUrl?: string;
|
|
290
|
+
responseStyle?: ResponseStyle;
|
|
291
|
+
throwOnError?: boolean;
|
|
292
|
+
}
|
|
293
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
294
|
+
type SseFn = <TData = unknown, _TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData>>;
|
|
295
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
296
|
+
type BuildUrlFn = <TData extends {
|
|
297
|
+
body?: unknown;
|
|
298
|
+
path?: Record<string, unknown>;
|
|
299
|
+
query?: Record<string, unknown>;
|
|
300
|
+
url: string;
|
|
301
|
+
}>(options: TData & Options<TData>) => string;
|
|
302
|
+
type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
303
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
304
|
+
};
|
|
305
|
+
interface TDataShape {
|
|
306
|
+
body?: unknown;
|
|
307
|
+
headers?: unknown;
|
|
308
|
+
path?: unknown;
|
|
309
|
+
query?: unknown;
|
|
310
|
+
url: string;
|
|
311
|
+
}
|
|
312
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
313
|
+
type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Block
|
|
317
|
+
*
|
|
318
|
+
* One semantic block of a parsed document — a structured alternative to
|
|
319
|
+
* walking `<a id></a>` anchors in `markdown`.
|
|
320
|
+
*
|
|
321
|
+
* All blocks expose the common fields (`id`, `type`, `page`, `bbox`,
|
|
322
|
+
* `confidence`, `content`). Type-specific structured data lives in the
|
|
323
|
+
* optional fields (`rows` for tables, `image_base64` for pictures).
|
|
324
|
+
* Consumers can switch on `type` to access the per-type fields, or treat
|
|
325
|
+
* `content` as the universal fallback.
|
|
326
|
+
*/
|
|
327
|
+
type Block = {
|
|
328
|
+
/**
|
|
329
|
+
* Bbox
|
|
330
|
+
*
|
|
331
|
+
* Normalised bounding box in [0, 1] page coordinates with keys `x0`/`y0`/`x1`/`y1`.
|
|
332
|
+
*/
|
|
333
|
+
bbox: {
|
|
334
|
+
[key: string]: number;
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Content
|
|
338
|
+
*
|
|
339
|
+
* Raw section body — markdown for text/title blocks, HTML for tables, `<figure-content>` for pictures.
|
|
340
|
+
*/
|
|
341
|
+
content: string;
|
|
342
|
+
/**
|
|
343
|
+
* Hyperlinks
|
|
344
|
+
*
|
|
345
|
+
* Hyperlinks found in the content via `[text](uri)` markdown syntax.
|
|
346
|
+
*/
|
|
347
|
+
hyperlinks?: Array<Hyperlink>;
|
|
348
|
+
/**
|
|
349
|
+
* Id
|
|
350
|
+
*
|
|
351
|
+
* Stable block identifier in the form `p<page>_b<index>`.
|
|
352
|
+
*/
|
|
353
|
+
id: string;
|
|
354
|
+
/**
|
|
355
|
+
* Image Base64
|
|
356
|
+
*
|
|
357
|
+
* Inline base64-encoded cropped image for `type=picture` blocks. Currently `null` for all blocks — image hydration is performed client-side by the SDK consumer.
|
|
358
|
+
*/
|
|
359
|
+
image_base64?: string | null;
|
|
360
|
+
/**
|
|
361
|
+
* Layout Confidence
|
|
362
|
+
*
|
|
363
|
+
* 0-100 YOLO layout detection confidence for this block.
|
|
364
|
+
*/
|
|
365
|
+
layout_confidence: number;
|
|
366
|
+
/**
|
|
367
|
+
* Page
|
|
368
|
+
*
|
|
369
|
+
* 1-indexed page number this block belongs to.
|
|
370
|
+
*/
|
|
371
|
+
page: number;
|
|
372
|
+
/**
|
|
373
|
+
* Parse Confidence
|
|
374
|
+
*
|
|
375
|
+
* 0-100 parse confidence calibrated from LLM logprobs. `null` when logprobs were unavailable (e.g. text-bytes strategy).
|
|
376
|
+
*/
|
|
377
|
+
parse_confidence?: number | null;
|
|
378
|
+
/**
|
|
379
|
+
* Rows
|
|
380
|
+
*
|
|
381
|
+
* 2D array of table cells for `type=table` blocks — each cell is `{cell_id, text}`. `null` for non-table blocks.
|
|
382
|
+
*/
|
|
383
|
+
rows?: Array<Array<{
|
|
384
|
+
[key: string]: string;
|
|
385
|
+
}>> | null;
|
|
386
|
+
/**
|
|
387
|
+
* Type
|
|
388
|
+
*
|
|
389
|
+
* Semantic type: `text`, `title`, `section-header`, `table`, `picture`, `other`.
|
|
390
|
+
*/
|
|
391
|
+
type: string;
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* BooleanField
|
|
395
|
+
*/
|
|
396
|
+
type BooleanField = {
|
|
397
|
+
/**
|
|
398
|
+
* Data Type
|
|
399
|
+
*/
|
|
400
|
+
data_type: 'boolean';
|
|
401
|
+
/**
|
|
402
|
+
* Description
|
|
403
|
+
*
|
|
404
|
+
* Free-form description shown to the extraction model.
|
|
405
|
+
*/
|
|
406
|
+
description: string;
|
|
407
|
+
/**
|
|
408
|
+
* Name
|
|
409
|
+
*
|
|
410
|
+
* Field name. Used as the key in the extraction response.
|
|
411
|
+
*/
|
|
412
|
+
name: string;
|
|
413
|
+
};
|
|
414
|
+
/**
|
|
415
|
+
* ClassificationResult
|
|
416
|
+
*
|
|
417
|
+
* One classifier verdict for the collection.
|
|
418
|
+
*/
|
|
419
|
+
type ClassificationResult = {
|
|
420
|
+
/**
|
|
421
|
+
* Category
|
|
422
|
+
*
|
|
423
|
+
* The category the document was classified as.
|
|
424
|
+
*/
|
|
425
|
+
category: string;
|
|
426
|
+
/**
|
|
427
|
+
* Confidence
|
|
428
|
+
*
|
|
429
|
+
* 0-100 model confidence in the verdict.
|
|
430
|
+
*/
|
|
431
|
+
confidence: number;
|
|
432
|
+
/**
|
|
433
|
+
* Evidence
|
|
434
|
+
*
|
|
435
|
+
* Free-form evidence text (the snippets the classifier cited). `null` when none captured.
|
|
436
|
+
*/
|
|
437
|
+
evidence?: string | null;
|
|
438
|
+
};
|
|
439
|
+
/**
|
|
440
|
+
* ClassifyCategory
|
|
441
|
+
*/
|
|
442
|
+
type ClassifyCategory = {
|
|
443
|
+
/**
|
|
444
|
+
* Description
|
|
445
|
+
*
|
|
446
|
+
* Free-form description shown to the LLM.
|
|
447
|
+
*/
|
|
448
|
+
description: string;
|
|
449
|
+
/**
|
|
450
|
+
* Id
|
|
451
|
+
*
|
|
452
|
+
* Stable category id used as the edge `branch` value when routing.
|
|
453
|
+
*/
|
|
454
|
+
id: string;
|
|
455
|
+
/**
|
|
456
|
+
* Name
|
|
457
|
+
*
|
|
458
|
+
* Display name shown to the LLM.
|
|
459
|
+
*/
|
|
460
|
+
name: string;
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* ClassifyNode
|
|
464
|
+
*/
|
|
465
|
+
type ClassifyNode = {
|
|
466
|
+
/**
|
|
467
|
+
* Categories
|
|
468
|
+
*/
|
|
469
|
+
categories: Array<ClassifyCategory>;
|
|
470
|
+
/**
|
|
471
|
+
* Id
|
|
472
|
+
*
|
|
473
|
+
* Stable identifier for this node within the graph.
|
|
474
|
+
*/
|
|
475
|
+
id: string;
|
|
476
|
+
/**
|
|
477
|
+
* Type
|
|
478
|
+
*/
|
|
479
|
+
type: 'classify';
|
|
480
|
+
/**
|
|
481
|
+
* User Prompt
|
|
482
|
+
*
|
|
483
|
+
* Optional prompt prefix for the classifier.
|
|
484
|
+
*/
|
|
485
|
+
user_prompt?: string | null;
|
|
486
|
+
};
|
|
487
|
+
/**
|
|
488
|
+
* DateField
|
|
489
|
+
*/
|
|
490
|
+
type DateField = {
|
|
491
|
+
/**
|
|
492
|
+
* Data Type
|
|
493
|
+
*/
|
|
494
|
+
data_type: 'date';
|
|
495
|
+
/**
|
|
496
|
+
* Description
|
|
497
|
+
*
|
|
498
|
+
* Free-form description shown to the extraction model.
|
|
499
|
+
*/
|
|
500
|
+
description: string;
|
|
501
|
+
/**
|
|
502
|
+
* Name
|
|
503
|
+
*
|
|
504
|
+
* Field name. Used as the key in the extraction response.
|
|
505
|
+
*/
|
|
506
|
+
name: string;
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* DatetimeField
|
|
510
|
+
*/
|
|
511
|
+
type DatetimeField = {
|
|
512
|
+
/**
|
|
513
|
+
* Data Type
|
|
514
|
+
*/
|
|
515
|
+
data_type: 'datetime';
|
|
516
|
+
/**
|
|
517
|
+
* Description
|
|
518
|
+
*
|
|
519
|
+
* Free-form description shown to the extraction model.
|
|
520
|
+
*/
|
|
521
|
+
description: string;
|
|
522
|
+
/**
|
|
523
|
+
* Name
|
|
524
|
+
*
|
|
525
|
+
* Field name. Used as the key in the extraction response.
|
|
526
|
+
*/
|
|
527
|
+
name: string;
|
|
528
|
+
};
|
|
529
|
+
/**
|
|
530
|
+
* Edge
|
|
531
|
+
*
|
|
532
|
+
* A directed edge between two nodes. ``branch`` carries the source-port label
|
|
533
|
+
* used for routing out of ``classify`` (category id) or ``splitter`` (rule id) nodes.
|
|
534
|
+
*/
|
|
535
|
+
type Edge = {
|
|
536
|
+
/**
|
|
537
|
+
* Branch
|
|
538
|
+
*
|
|
539
|
+
* Source-port label for branch routing. Required when leaving a classify or splitter node by category/rule.
|
|
540
|
+
*/
|
|
541
|
+
branch?: string | null;
|
|
542
|
+
/**
|
|
543
|
+
* Source
|
|
544
|
+
*/
|
|
545
|
+
source: string;
|
|
546
|
+
/**
|
|
547
|
+
* Target
|
|
548
|
+
*/
|
|
549
|
+
target: string;
|
|
550
|
+
};
|
|
551
|
+
/**
|
|
552
|
+
* EnumField
|
|
553
|
+
*/
|
|
554
|
+
type EnumField = {
|
|
555
|
+
/**
|
|
556
|
+
* Data Type
|
|
557
|
+
*/
|
|
558
|
+
data_type: 'enum';
|
|
559
|
+
/**
|
|
560
|
+
* Description
|
|
561
|
+
*
|
|
562
|
+
* Free-form description shown to the extraction model.
|
|
563
|
+
*/
|
|
564
|
+
description: string;
|
|
565
|
+
/**
|
|
566
|
+
* Enum Options
|
|
567
|
+
*/
|
|
568
|
+
enum_options: Array<EnumOption>;
|
|
569
|
+
/**
|
|
570
|
+
* Name
|
|
571
|
+
*
|
|
572
|
+
* Field name. Used as the key in the extraction response.
|
|
573
|
+
*/
|
|
574
|
+
name: string;
|
|
575
|
+
};
|
|
576
|
+
/**
|
|
577
|
+
* EnumOption
|
|
578
|
+
*/
|
|
579
|
+
type EnumOption = {
|
|
580
|
+
/**
|
|
581
|
+
* Description
|
|
582
|
+
*
|
|
583
|
+
* Free-form description shown to the model.
|
|
584
|
+
*/
|
|
585
|
+
description: string;
|
|
586
|
+
/**
|
|
587
|
+
* Name
|
|
588
|
+
*/
|
|
589
|
+
name: string;
|
|
590
|
+
};
|
|
591
|
+
/**
|
|
592
|
+
* Evidence
|
|
593
|
+
*
|
|
594
|
+
* A snippet of source text supporting an extracted value, with the page it came from.
|
|
595
|
+
*/
|
|
596
|
+
type Evidence = {
|
|
597
|
+
/**
|
|
598
|
+
* Page Number
|
|
599
|
+
*
|
|
600
|
+
* 1-indexed page number where the snippet was found.
|
|
601
|
+
*/
|
|
602
|
+
page_number: number;
|
|
603
|
+
/**
|
|
604
|
+
* Text
|
|
605
|
+
*
|
|
606
|
+
* The exact source-text snippet that supports the extracted value.
|
|
607
|
+
*/
|
|
608
|
+
text: string;
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* ExtractNode
|
|
612
|
+
*/
|
|
613
|
+
type ExtractNode = {
|
|
614
|
+
/**
|
|
615
|
+
* Schema for the fields this node extracts. Required. The backend executor populates this from the ORM field tree before constructing the typed node; nothing else should be able to build an ExtractNode without it.
|
|
616
|
+
*/
|
|
617
|
+
extraction_schema: ExtractionSchema;
|
|
618
|
+
/**
|
|
619
|
+
* Id
|
|
620
|
+
*
|
|
621
|
+
* Stable identifier for this node within the graph.
|
|
622
|
+
*/
|
|
623
|
+
id: string;
|
|
624
|
+
/**
|
|
625
|
+
* Lookup Files
|
|
626
|
+
*
|
|
627
|
+
* Smart-lookup reference document URIs persisted on the extract node.
|
|
628
|
+
*/
|
|
629
|
+
lookup_files?: Array<string>;
|
|
630
|
+
/**
|
|
631
|
+
* Lookup Schema
|
|
632
|
+
*
|
|
633
|
+
* Typed schema of fields the smart-lookup pass should produce. The *backend* derives this from the field tree (FieldWorkflowVersion rows whose source is SMART_LOOKUP) and attaches it to the node before the message hits the wire — the worker then reads it directly off the node, with no DB round-trip. Default empty: a node without smart-lookup fields carries an empty list.
|
|
634
|
+
*/
|
|
635
|
+
lookup_schema?: Array<({
|
|
636
|
+
data_type: 'string';
|
|
637
|
+
} & StringField) | ({
|
|
638
|
+
data_type: 'integer';
|
|
639
|
+
} & IntegerField) | ({
|
|
640
|
+
data_type: 'float';
|
|
641
|
+
} & FloatField) | ({
|
|
642
|
+
data_type: 'boolean';
|
|
643
|
+
} & BooleanField) | ({
|
|
644
|
+
data_type: 'date';
|
|
645
|
+
} & DateField) | ({
|
|
646
|
+
data_type: 'datetime';
|
|
647
|
+
} & DatetimeField) | ({
|
|
648
|
+
data_type: 'enum';
|
|
649
|
+
} & EnumField) | ({
|
|
650
|
+
data_type: 'multi_select';
|
|
651
|
+
} & MultiSelectField) | ({
|
|
652
|
+
data_type: 'object';
|
|
653
|
+
} & ObjectField)>;
|
|
654
|
+
/**
|
|
655
|
+
* Lookup Suggestion
|
|
656
|
+
*
|
|
657
|
+
* Free-form hint shown to the smart-lookup matcher.
|
|
658
|
+
*/
|
|
659
|
+
lookup_suggestion?: string | null;
|
|
660
|
+
/**
|
|
661
|
+
* Mode
|
|
662
|
+
*/
|
|
663
|
+
mode?: 'standard' | 'agentic';
|
|
664
|
+
/**
|
|
665
|
+
* Type
|
|
666
|
+
*/
|
|
667
|
+
type: 'extract';
|
|
668
|
+
/**
|
|
669
|
+
* Use Images
|
|
670
|
+
*/
|
|
671
|
+
use_images?: boolean;
|
|
672
|
+
};
|
|
673
|
+
/**
|
|
674
|
+
* ExtractedField
|
|
675
|
+
*
|
|
676
|
+
* One extracted field's value, confidence, and supporting evidence.
|
|
677
|
+
*/
|
|
678
|
+
type ExtractedField = {
|
|
679
|
+
/**
|
|
680
|
+
* Confidence
|
|
681
|
+
*
|
|
682
|
+
* Model confidence in the extracted value, on a 0-100 scale. `null` when the backend did not produce a confidence (e.g. manual entry).
|
|
683
|
+
*/
|
|
684
|
+
confidence?: number | null;
|
|
685
|
+
/**
|
|
686
|
+
* Evidence
|
|
687
|
+
*
|
|
688
|
+
* Source-text snippets the model used to derive this value.
|
|
689
|
+
*/
|
|
690
|
+
evidence?: Array<Evidence>;
|
|
691
|
+
/**
|
|
692
|
+
* Value
|
|
693
|
+
*
|
|
694
|
+
* The extracted value. Type depends on the field's `data_type` (string, number, date, etc.). `null` when extraction could not produce a value.
|
|
695
|
+
*/
|
|
696
|
+
value: unknown | null;
|
|
697
|
+
/**
|
|
698
|
+
* Value Override
|
|
699
|
+
*
|
|
700
|
+
* A human-supplied override of the extracted `value`, if one was set during verification. `null` when no override exists.
|
|
701
|
+
*/
|
|
702
|
+
value_override?: unknown | null;
|
|
703
|
+
/**
|
|
704
|
+
* Verification Status
|
|
705
|
+
*
|
|
706
|
+
* Verification state for this datapoint (e.g. `not_verified`, `verified`). `null` when not yet reviewed.
|
|
707
|
+
*/
|
|
708
|
+
verification_status?: string | null;
|
|
709
|
+
};
|
|
710
|
+
/**
|
|
711
|
+
* Extraction
|
|
712
|
+
*
|
|
713
|
+
* One unit of extracted data. For linear (parse->extract) workflows there
|
|
714
|
+
* is exactly one entry with `split_name=null` and `partition=null`. For split
|
|
715
|
+
* workflows there is one entry per (split, partition) pair; join with
|
|
716
|
+
* `splits[]` by `split_name` to look up geometry.
|
|
717
|
+
*/
|
|
718
|
+
type Extraction = {
|
|
719
|
+
/**
|
|
720
|
+
* Fields
|
|
721
|
+
*
|
|
722
|
+
* Extracted fields keyed by field name. Same shape as the legacy top-level `extraction`.
|
|
723
|
+
*/
|
|
724
|
+
fields: {
|
|
725
|
+
[key: string]: ExtractedField | Array<{
|
|
726
|
+
[key: string]: ExtractedField;
|
|
727
|
+
}>;
|
|
728
|
+
};
|
|
729
|
+
/**
|
|
730
|
+
* Partition
|
|
731
|
+
*
|
|
732
|
+
* The partition value within the split. `null` when the split has no partitions.
|
|
733
|
+
*/
|
|
734
|
+
partition?: string | null;
|
|
735
|
+
/**
|
|
736
|
+
* Split Name
|
|
737
|
+
*
|
|
738
|
+
* The split category this extraction belongs to. `null` for linear workflows.
|
|
739
|
+
*/
|
|
740
|
+
split_name?: string | null;
|
|
741
|
+
};
|
|
742
|
+
/**
|
|
743
|
+
* ExtractionSchema
|
|
744
|
+
*
|
|
745
|
+
* Schema describing what an extract node produces. Modeled as a typed
|
|
746
|
+
* object (not a bare ``list[AnyField]``) so metadata can be added later
|
|
747
|
+
* (versioning, derived flags, output-shape hints) without another
|
|
748
|
+
* wire-format break.
|
|
749
|
+
*
|
|
750
|
+
* Every extraction schema must declare at least one field. The backend
|
|
751
|
+
* executor populates this list from ``FieldWorkflowVersion`` rows
|
|
752
|
+
* *before* constructing the typed ExtractNode; extract nodes without
|
|
753
|
+
* any assigned fields are skipped at the executor layer rather than
|
|
754
|
+
* sent to the worker with an empty schema.
|
|
755
|
+
*/
|
|
756
|
+
type ExtractionSchema = {
|
|
757
|
+
/**
|
|
758
|
+
* Fields
|
|
759
|
+
*
|
|
760
|
+
* Field definitions making up this extract's output.
|
|
761
|
+
*/
|
|
762
|
+
fields: Array<({
|
|
763
|
+
data_type: 'string';
|
|
764
|
+
} & StringField) | ({
|
|
765
|
+
data_type: 'integer';
|
|
766
|
+
} & IntegerField) | ({
|
|
767
|
+
data_type: 'float';
|
|
768
|
+
} & FloatField) | ({
|
|
769
|
+
data_type: 'boolean';
|
|
770
|
+
} & BooleanField) | ({
|
|
771
|
+
data_type: 'date';
|
|
772
|
+
} & DateField) | ({
|
|
773
|
+
data_type: 'datetime';
|
|
774
|
+
} & DatetimeField) | ({
|
|
775
|
+
data_type: 'enum';
|
|
776
|
+
} & EnumField) | ({
|
|
777
|
+
data_type: 'multi_select';
|
|
778
|
+
} & MultiSelectField) | ({
|
|
779
|
+
data_type: 'object';
|
|
780
|
+
} & ObjectField)>;
|
|
781
|
+
};
|
|
782
|
+
/**
|
|
783
|
+
* FilePages
|
|
784
|
+
*
|
|
785
|
+
* A file's contribution of pages to a split or partition. 1-indexed.
|
|
786
|
+
*/
|
|
787
|
+
type FilePages = {
|
|
788
|
+
/**
|
|
789
|
+
* File Id
|
|
790
|
+
*
|
|
791
|
+
* The file's UUID.
|
|
792
|
+
*/
|
|
793
|
+
file_id: string;
|
|
794
|
+
/**
|
|
795
|
+
* File Name
|
|
796
|
+
*
|
|
797
|
+
* The file's display name.
|
|
798
|
+
*/
|
|
799
|
+
file_name: string;
|
|
800
|
+
/**
|
|
801
|
+
* Pages
|
|
802
|
+
*
|
|
803
|
+
* 1-indexed page numbers from this file.
|
|
804
|
+
*/
|
|
805
|
+
pages: Array<number>;
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* FloatField
|
|
809
|
+
*/
|
|
810
|
+
type FloatField = {
|
|
811
|
+
/**
|
|
812
|
+
* Data Type
|
|
813
|
+
*/
|
|
814
|
+
data_type: 'float';
|
|
815
|
+
/**
|
|
816
|
+
* Description
|
|
817
|
+
*
|
|
818
|
+
* Free-form description shown to the extraction model.
|
|
819
|
+
*/
|
|
820
|
+
description: string;
|
|
821
|
+
/**
|
|
822
|
+
* Name
|
|
823
|
+
*
|
|
824
|
+
* Field name. Used as the key in the extraction response.
|
|
825
|
+
*/
|
|
826
|
+
name: string;
|
|
827
|
+
};
|
|
828
|
+
/**
|
|
829
|
+
* Hyperlink
|
|
830
|
+
*
|
|
831
|
+
* A hyperlink found inside a block's content.
|
|
832
|
+
*/
|
|
833
|
+
type Hyperlink = {
|
|
834
|
+
/**
|
|
835
|
+
* Text
|
|
836
|
+
*
|
|
837
|
+
* The display text of the link.
|
|
838
|
+
*/
|
|
839
|
+
text: string;
|
|
840
|
+
/**
|
|
841
|
+
* Uri
|
|
842
|
+
*
|
|
843
|
+
* The link target (URL, mailto:, etc.).
|
|
844
|
+
*/
|
|
845
|
+
uri: string;
|
|
846
|
+
};
|
|
847
|
+
/**
|
|
848
|
+
* IntegerField
|
|
849
|
+
*/
|
|
850
|
+
type IntegerField = {
|
|
851
|
+
/**
|
|
852
|
+
* Data Type
|
|
853
|
+
*/
|
|
854
|
+
data_type: 'integer';
|
|
855
|
+
/**
|
|
856
|
+
* Description
|
|
857
|
+
*
|
|
858
|
+
* Free-form description shown to the extraction model.
|
|
859
|
+
*/
|
|
860
|
+
description: string;
|
|
861
|
+
/**
|
|
862
|
+
* Name
|
|
863
|
+
*
|
|
864
|
+
* Field name. Used as the key in the extraction response.
|
|
865
|
+
*/
|
|
866
|
+
name: string;
|
|
867
|
+
};
|
|
868
|
+
/**
|
|
869
|
+
* MultiSelectField
|
|
870
|
+
*/
|
|
871
|
+
type MultiSelectField = {
|
|
872
|
+
/**
|
|
873
|
+
* Data Type
|
|
874
|
+
*/
|
|
875
|
+
data_type: 'multi_select';
|
|
876
|
+
/**
|
|
877
|
+
* Description
|
|
878
|
+
*
|
|
879
|
+
* Free-form description shown to the extraction model.
|
|
880
|
+
*/
|
|
881
|
+
description: string;
|
|
882
|
+
/**
|
|
883
|
+
* Enum Options
|
|
884
|
+
*/
|
|
885
|
+
enum_options: Array<EnumOption>;
|
|
886
|
+
/**
|
|
887
|
+
* Name
|
|
888
|
+
*
|
|
889
|
+
* Field name. Used as the key in the extraction response.
|
|
890
|
+
*/
|
|
891
|
+
name: string;
|
|
892
|
+
};
|
|
893
|
+
/**
|
|
894
|
+
* ObjectField
|
|
895
|
+
*/
|
|
896
|
+
type ObjectField = {
|
|
897
|
+
/**
|
|
898
|
+
* Data Type
|
|
899
|
+
*/
|
|
900
|
+
data_type: 'object';
|
|
901
|
+
/**
|
|
902
|
+
* Description
|
|
903
|
+
*
|
|
904
|
+
* Free-form description shown to the extraction model.
|
|
905
|
+
*/
|
|
906
|
+
description: string;
|
|
907
|
+
/**
|
|
908
|
+
* Name
|
|
909
|
+
*
|
|
910
|
+
* Field name. Used as the key in the extraction response.
|
|
911
|
+
*/
|
|
912
|
+
name: string;
|
|
913
|
+
/**
|
|
914
|
+
* Nested Fields
|
|
915
|
+
*/
|
|
916
|
+
nested_fields: Array<({
|
|
917
|
+
data_type: 'string';
|
|
918
|
+
} & StringField) | ({
|
|
919
|
+
data_type: 'integer';
|
|
920
|
+
} & IntegerField) | ({
|
|
921
|
+
data_type: 'float';
|
|
922
|
+
} & FloatField) | ({
|
|
923
|
+
data_type: 'boolean';
|
|
924
|
+
} & BooleanField) | ({
|
|
925
|
+
data_type: 'date';
|
|
926
|
+
} & DateField) | ({
|
|
927
|
+
data_type: 'datetime';
|
|
928
|
+
} & DatetimeField) | ({
|
|
929
|
+
data_type: 'enum';
|
|
930
|
+
} & EnumField) | ({
|
|
931
|
+
data_type: 'multi_select';
|
|
932
|
+
} & MultiSelectField) | ({
|
|
933
|
+
data_type: 'object';
|
|
934
|
+
} & ObjectField)>;
|
|
935
|
+
};
|
|
936
|
+
/**
|
|
937
|
+
* ParseNode
|
|
938
|
+
*/
|
|
939
|
+
type ParseNode = {
|
|
940
|
+
/**
|
|
941
|
+
* Figure Enhancement
|
|
942
|
+
*/
|
|
943
|
+
figure_enhancement?: boolean;
|
|
944
|
+
/**
|
|
945
|
+
* Id
|
|
946
|
+
*
|
|
947
|
+
* Stable identifier for this node within the graph.
|
|
948
|
+
*/
|
|
949
|
+
id: string;
|
|
950
|
+
/**
|
|
951
|
+
* Mode
|
|
952
|
+
*/
|
|
953
|
+
mode?: 'standard' | 'agentic';
|
|
954
|
+
/**
|
|
955
|
+
* Prompt Hint
|
|
956
|
+
*
|
|
957
|
+
* Free-form hint shown to the parse model to bias output.
|
|
958
|
+
*/
|
|
959
|
+
prompt_hint?: string | null;
|
|
960
|
+
/**
|
|
961
|
+
* Type
|
|
962
|
+
*/
|
|
963
|
+
type: 'parse';
|
|
964
|
+
};
|
|
965
|
+
/**
|
|
966
|
+
* ParseResult
|
|
967
|
+
*
|
|
968
|
+
* Parsed markdown for a file.
|
|
969
|
+
*/
|
|
970
|
+
type ParseResult = {
|
|
971
|
+
/**
|
|
972
|
+
* Blocks
|
|
973
|
+
*
|
|
974
|
+
* Structured per-block representation of the parsed document. One entry per `<a id></a>` anchor in document order, with type-specific structured data (`rows` for tables, `image_base64` for pictures) surfaced as first-class fields so consumers don't have to HTML-parse.
|
|
975
|
+
*/
|
|
976
|
+
blocks?: Array<Block>;
|
|
977
|
+
/**
|
|
978
|
+
* Layout Confidence
|
|
979
|
+
*
|
|
980
|
+
* Document-level YOLO layout confidence on a 0-100 scale, char-weighted mean across all blocks. `null` if no annotated sections.
|
|
981
|
+
*/
|
|
982
|
+
layout_confidence?: number | null;
|
|
983
|
+
/**
|
|
984
|
+
* Markdown
|
|
985
|
+
*
|
|
986
|
+
* Document content rendered as structured markdown. Each block is preceded by an empty `<a id="p{page}_b{idx}"></a>` anchor (invisible in any markdown renderer; the id joins to `blocks[].id` and can be used as an in-page link target). Image hydration for picture/figure blocks happens client-side. `null` if parsing failed.
|
|
987
|
+
*/
|
|
988
|
+
markdown: string | null;
|
|
989
|
+
/**
|
|
990
|
+
* Parse Confidence
|
|
991
|
+
*
|
|
992
|
+
* Document-level parse confidence on a 0-100 scale, char-weighted mean of per-block LLM logprob scores. `null` when no blocks have logprob-based confidence.
|
|
993
|
+
*/
|
|
994
|
+
parse_confidence?: number | null;
|
|
995
|
+
/**
|
|
996
|
+
* Text
|
|
997
|
+
*
|
|
998
|
+
* Plain markdown with structural HTML removed — `<DOCUMENT>` framing, block anchors, `<img>` tags, and `<figure-content>` wrappers stripped. Useful when feeding the parsed output into an LLM or a search index that doesn't need the block-level metadata. `null` if `markdown` is null.
|
|
999
|
+
*/
|
|
1000
|
+
text?: string | null;
|
|
1001
|
+
};
|
|
1002
|
+
/**
|
|
1003
|
+
* ResultsResponse
|
|
1004
|
+
*
|
|
1005
|
+
* Canonical response shape for the file-collection results endpoint.
|
|
1006
|
+
*
|
|
1007
|
+
* Returned with HTTP 200 once processing completes. Returns 412 while processing is
|
|
1008
|
+
* in progress; poll until 200, or use webhooks.
|
|
1009
|
+
*/
|
|
1010
|
+
type ResultsResponse = {
|
|
1011
|
+
/**
|
|
1012
|
+
* Classifications
|
|
1013
|
+
*
|
|
1014
|
+
* Per-classifier-node verdicts. Empty when the workflow has no classifier.
|
|
1015
|
+
*/
|
|
1016
|
+
classifications?: Array<ClassificationResult>;
|
|
1017
|
+
/**
|
|
1018
|
+
* Collection Id
|
|
1019
|
+
*
|
|
1020
|
+
* The file collection's UUID. Same value as the `id` returned by `POST /v2/workflows/{wid}/run/`.
|
|
1021
|
+
*/
|
|
1022
|
+
collection_id: string;
|
|
1023
|
+
/**
|
|
1024
|
+
* Extraction
|
|
1025
|
+
*
|
|
1026
|
+
* **Deprecated** — use `extractions` instead. Extracted fields keyed by field name, populated only for linear workflows (single extract node, no splitter). `null` for split workflows; read `extractions[]` instead.
|
|
1027
|
+
*
|
|
1028
|
+
* @deprecated
|
|
1029
|
+
*/
|
|
1030
|
+
extraction?: {
|
|
1031
|
+
[key: string]: ExtractedField | Array<{
|
|
1032
|
+
[key: string]: ExtractedField;
|
|
1033
|
+
}>;
|
|
1034
|
+
} | null;
|
|
1035
|
+
/**
|
|
1036
|
+
* Extractions
|
|
1037
|
+
*
|
|
1038
|
+
* Flat list of extraction datapoints. Linear workflows produce one entry with `split_name=null` and `partition=null`. Split workflows produce one entry per (split, partition). Empty when no extraction has run yet.
|
|
1039
|
+
*/
|
|
1040
|
+
extractions?: Array<Extraction>;
|
|
1041
|
+
/**
|
|
1042
|
+
* Parse-node output (rendered markdown). `null` when the workflow has no parse node. Always present in the response.
|
|
1043
|
+
*/
|
|
1044
|
+
parse?: ParseResult | null;
|
|
1045
|
+
/**
|
|
1046
|
+
* Splits
|
|
1047
|
+
*
|
|
1048
|
+
* Splitter output: category-level geometry with optional partitions. Empty when the workflow has no splitter.
|
|
1049
|
+
*/
|
|
1050
|
+
splits?: Array<SplitResult>;
|
|
1051
|
+
/**
|
|
1052
|
+
* Verification Url
|
|
1053
|
+
*
|
|
1054
|
+
* Link to the AnyFormat dashboard for human review of this collection's results. `null` if the dashboard URL cannot be constructed (e.g. no files in the collection, or the deployment has no frontend URL configured).
|
|
1055
|
+
*/
|
|
1056
|
+
verification_url?: string | null;
|
|
1057
|
+
};
|
|
1058
|
+
/**
|
|
1059
|
+
* SplitPartition
|
|
1060
|
+
*
|
|
1061
|
+
* A partition value within a split (e.g. `1234-5678` under `Account Holdings`).
|
|
1062
|
+
*/
|
|
1063
|
+
type SplitPartition = {
|
|
1064
|
+
/**
|
|
1065
|
+
* Confidence
|
|
1066
|
+
*
|
|
1067
|
+
* 0-100 minimum confidence across the partition's ranges.
|
|
1068
|
+
*/
|
|
1069
|
+
confidence: number;
|
|
1070
|
+
/**
|
|
1071
|
+
* Files
|
|
1072
|
+
*/
|
|
1073
|
+
files: Array<FilePages>;
|
|
1074
|
+
/**
|
|
1075
|
+
* Name
|
|
1076
|
+
*
|
|
1077
|
+
* The partition value (free-form string).
|
|
1078
|
+
*/
|
|
1079
|
+
name: string;
|
|
1080
|
+
};
|
|
1081
|
+
/**
|
|
1082
|
+
* SplitResult
|
|
1083
|
+
*
|
|
1084
|
+
* A category-level split: which pages of which files fall under it, plus
|
|
1085
|
+
* any partitions inside it. Extraction data lives under `extractions[]` —
|
|
1086
|
+
* join by `split_name`.
|
|
1087
|
+
*/
|
|
1088
|
+
type SplitResult = {
|
|
1089
|
+
/**
|
|
1090
|
+
* Confidence
|
|
1091
|
+
*
|
|
1092
|
+
* 0-100 aggregate confidence (min across partitions).
|
|
1093
|
+
*/
|
|
1094
|
+
confidence: number;
|
|
1095
|
+
/**
|
|
1096
|
+
* Files
|
|
1097
|
+
*
|
|
1098
|
+
* Per-file page lists, union of all partitions.
|
|
1099
|
+
*/
|
|
1100
|
+
files: Array<FilePages>;
|
|
1101
|
+
/**
|
|
1102
|
+
* Name
|
|
1103
|
+
*
|
|
1104
|
+
* The split's category name.
|
|
1105
|
+
*/
|
|
1106
|
+
name: string;
|
|
1107
|
+
/**
|
|
1108
|
+
* Partitions
|
|
1109
|
+
*/
|
|
1110
|
+
partitions?: Array<SplitPartition>;
|
|
1111
|
+
};
|
|
1112
|
+
/**
|
|
1113
|
+
* SplitterNode
|
|
1114
|
+
*/
|
|
1115
|
+
type SplitterNode = {
|
|
1116
|
+
/**
|
|
1117
|
+
* Id
|
|
1118
|
+
*
|
|
1119
|
+
* Stable identifier for this node within the graph.
|
|
1120
|
+
*/
|
|
1121
|
+
id: string;
|
|
1122
|
+
/**
|
|
1123
|
+
* Rules
|
|
1124
|
+
*/
|
|
1125
|
+
rules: Array<SplitterRule>;
|
|
1126
|
+
/**
|
|
1127
|
+
* Type
|
|
1128
|
+
*/
|
|
1129
|
+
type: 'splitter';
|
|
1130
|
+
};
|
|
1131
|
+
/**
|
|
1132
|
+
* SplitterRule
|
|
1133
|
+
*/
|
|
1134
|
+
type SplitterRule = {
|
|
1135
|
+
/**
|
|
1136
|
+
* Description
|
|
1137
|
+
*/
|
|
1138
|
+
description: string;
|
|
1139
|
+
/**
|
|
1140
|
+
* Id
|
|
1141
|
+
*/
|
|
1142
|
+
id: string;
|
|
1143
|
+
/**
|
|
1144
|
+
* Name
|
|
1145
|
+
*/
|
|
1146
|
+
name: string;
|
|
1147
|
+
/**
|
|
1148
|
+
* Partition Key
|
|
1149
|
+
*/
|
|
1150
|
+
partition_key?: string;
|
|
1151
|
+
};
|
|
1152
|
+
/**
|
|
1153
|
+
* StringField
|
|
1154
|
+
*/
|
|
1155
|
+
type StringField = {
|
|
1156
|
+
/**
|
|
1157
|
+
* Data Type
|
|
1158
|
+
*/
|
|
1159
|
+
data_type: 'string';
|
|
1160
|
+
/**
|
|
1161
|
+
* Description
|
|
1162
|
+
*
|
|
1163
|
+
* Free-form description shown to the extraction model.
|
|
1164
|
+
*/
|
|
1165
|
+
description: string;
|
|
1166
|
+
/**
|
|
1167
|
+
* Name
|
|
1168
|
+
*
|
|
1169
|
+
* Field name. Used as the key in the extraction response.
|
|
1170
|
+
*/
|
|
1171
|
+
name: string;
|
|
1172
|
+
};
|
|
1173
|
+
/**
|
|
1174
|
+
* ValidateNode
|
|
1175
|
+
*/
|
|
1176
|
+
type ValidateNode = {
|
|
1177
|
+
/**
|
|
1178
|
+
* Id
|
|
1179
|
+
*
|
|
1180
|
+
* Stable identifier for this node within the graph.
|
|
1181
|
+
*/
|
|
1182
|
+
id: string;
|
|
1183
|
+
/**
|
|
1184
|
+
* Rules
|
|
1185
|
+
*/
|
|
1186
|
+
rules: Array<ValidationRule>;
|
|
1187
|
+
/**
|
|
1188
|
+
* Type
|
|
1189
|
+
*/
|
|
1190
|
+
type: 'validate';
|
|
1191
|
+
};
|
|
1192
|
+
/**
|
|
1193
|
+
* ValidationRule
|
|
1194
|
+
*/
|
|
1195
|
+
type ValidationRule = {
|
|
1196
|
+
/**
|
|
1197
|
+
* Description
|
|
1198
|
+
*
|
|
1199
|
+
* Natural-language description shown to the validation model.
|
|
1200
|
+
*/
|
|
1201
|
+
description: string;
|
|
1202
|
+
/**
|
|
1203
|
+
* Id
|
|
1204
|
+
*
|
|
1205
|
+
* Stable rule id; round-trips through ValidationResult.rule_id.
|
|
1206
|
+
*/
|
|
1207
|
+
id: string;
|
|
1208
|
+
/**
|
|
1209
|
+
* Name
|
|
1210
|
+
*
|
|
1211
|
+
* Optional human-readable rule name shown on the rule card in the Studio. Stored verbatim on the GraphNode config and surfaced back through the config endpoint so renames round-trip.
|
|
1212
|
+
*/
|
|
1213
|
+
name?: string | null;
|
|
1214
|
+
/**
|
|
1215
|
+
* Severity
|
|
1216
|
+
*/
|
|
1217
|
+
severity?: 'error' | 'warning';
|
|
1218
|
+
/**
|
|
1219
|
+
* Source Fields
|
|
1220
|
+
*
|
|
1221
|
+
* Persistent ids of fields this rule references.
|
|
1222
|
+
*/
|
|
1223
|
+
source_fields?: Array<string>;
|
|
1224
|
+
};
|
|
1225
|
+
/**
|
|
1226
|
+
* WorkflowCreateRequest
|
|
1227
|
+
*
|
|
1228
|
+
* Public-surface workflow create body — typed graph of parse / classify / splitter / extract nodes.
|
|
1229
|
+
*
|
|
1230
|
+
* Defined as a thin subclass so the FastAPI-generated OpenAPI components
|
|
1231
|
+
* entry is named ``WorkflowCreateRequest`` (FastAPI uses the model's
|
|
1232
|
+
* ``__name__``). Behaviour is fully inherited from
|
|
1233
|
+
* ``WorkflowDefinition`` in ``anyformat.workflow``.
|
|
1234
|
+
*/
|
|
1235
|
+
type WorkflowCreateRequest = {
|
|
1236
|
+
/**
|
|
1237
|
+
* Description
|
|
1238
|
+
*/
|
|
1239
|
+
description?: string | null;
|
|
1240
|
+
/**
|
|
1241
|
+
* Edges
|
|
1242
|
+
*/
|
|
1243
|
+
edges?: Array<Edge>;
|
|
1244
|
+
/**
|
|
1245
|
+
* Name
|
|
1246
|
+
*/
|
|
1247
|
+
name: string;
|
|
1248
|
+
/**
|
|
1249
|
+
* Nodes
|
|
1250
|
+
*/
|
|
1251
|
+
nodes: Array<({
|
|
1252
|
+
type: 'parse';
|
|
1253
|
+
} & ParseNode) | ({
|
|
1254
|
+
type: 'classify';
|
|
1255
|
+
} & ClassifyNode) | ({
|
|
1256
|
+
type: 'splitter';
|
|
1257
|
+
} & SplitterNode) | ({
|
|
1258
|
+
type: 'extract';
|
|
1259
|
+
} & ExtractNode) | ({
|
|
1260
|
+
type: 'validate';
|
|
1261
|
+
} & ValidateNode)>;
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1264
|
+
/** Typed wrapper over a completed run's results. */
|
|
1265
|
+
declare class Result {
|
|
1266
|
+
readonly raw: ResultsResponse;
|
|
1267
|
+
constructor(raw: ResultsResponse);
|
|
1268
|
+
get collectionId(): string;
|
|
1269
|
+
get extractions(): Extraction[];
|
|
1270
|
+
/**
|
|
1271
|
+
* Convenience accessor for a top-level scalar field on the first
|
|
1272
|
+
* extraction (linear workflows). Returns `undefined` for missing fields
|
|
1273
|
+
* or list-valued fields — read `extractions` directly for those.
|
|
1274
|
+
*/
|
|
1275
|
+
field(name: string): ExtractedField | undefined;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
interface WaitOptions {
|
|
1279
|
+
/** Overall budget before giving up. Default 120s. */
|
|
1280
|
+
timeoutMs?: number;
|
|
1281
|
+
/** Delay between result polls. Default 2s. */
|
|
1282
|
+
pollMs?: number;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* A pending run. Lazily creates the workflow, submits the document, and
|
|
1286
|
+
* polls for results when `wait()` is awaited.
|
|
1287
|
+
*/
|
|
1288
|
+
declare class Run {
|
|
1289
|
+
private readonly client;
|
|
1290
|
+
private readonly request;
|
|
1291
|
+
private readonly file;
|
|
1292
|
+
private readonly text;
|
|
1293
|
+
private workflowId;
|
|
1294
|
+
private collectionId;
|
|
1295
|
+
constructor(client: Client, request: WorkflowCreateRequest, file: Blob | File | null, text: string | null);
|
|
1296
|
+
/**
|
|
1297
|
+
* Create the workflow and submit the document — exactly once per `Run`.
|
|
1298
|
+
* Memoized so that retrying `wait()` after an `SDKTimeout` resumes polling
|
|
1299
|
+
* the in-flight run instead of creating a duplicate workflow + submission.
|
|
1300
|
+
*/
|
|
1301
|
+
private submit;
|
|
1302
|
+
wait(opts?: WaitOptions): Promise<Result>;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
/** Any extraction field — the discriminated union on `data_type`. */
|
|
1306
|
+
type Field = ExtractionSchema["fields"][number];
|
|
1307
|
+
/**
|
|
1308
|
+
* Factory for extraction-schema fields — the TS mirror of the Python
|
|
1309
|
+
* `Schema` facade. Each method returns the typed wire model the API
|
|
1310
|
+
* validates against; the discriminator (`data_type`) is filled in for you.
|
|
1311
|
+
*/
|
|
1312
|
+
declare const Schema: {
|
|
1313
|
+
readonly string: (name: string, description: string) => StringField;
|
|
1314
|
+
readonly integer: (name: string, description: string) => IntegerField;
|
|
1315
|
+
readonly float: (name: string, description: string) => FloatField;
|
|
1316
|
+
readonly boolean: (name: string, description: string) => BooleanField;
|
|
1317
|
+
readonly date: (name: string, description: string) => DateField;
|
|
1318
|
+
readonly datetime: (name: string, description: string) => DatetimeField;
|
|
1319
|
+
readonly enum: (name: string, description: string, options: EnumOption[]) => EnumField;
|
|
1320
|
+
readonly multiSelect: (name: string, description: string, options: EnumOption[]) => MultiSelectField;
|
|
1321
|
+
readonly object: (name: string, description: string, fields: Field[]) => ObjectField;
|
|
1322
|
+
readonly option: (name: string, description: string) => EnumOption;
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1325
|
+
type ParseMode = "standard" | "agentic";
|
|
1326
|
+
/** Source-port label routing into an extract/validate node. */
|
|
1327
|
+
type Branch = string | ClassifyCategory | SplitterRule;
|
|
1328
|
+
interface ParseOptions {
|
|
1329
|
+
mode?: ParseMode;
|
|
1330
|
+
promptHint?: string;
|
|
1331
|
+
figureEnhancement?: boolean;
|
|
1332
|
+
id?: string;
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* Fluent assembler for a typed workflow graph — a faithful TS port of the
|
|
1336
|
+
* Python `WorkflowBuilder`. `parse`/`classify`/`split` are singletons;
|
|
1337
|
+
* `extract`/`validate` are repeatable and carry their edge metadata. Call
|
|
1338
|
+
* `build()` (or `create()`/`run()`) to emit the wire request.
|
|
1339
|
+
*/
|
|
1340
|
+
declare class WorkflowBuilder {
|
|
1341
|
+
private readonly client;
|
|
1342
|
+
private readonly name;
|
|
1343
|
+
private readonly description?;
|
|
1344
|
+
private parseNode;
|
|
1345
|
+
private classifyNode;
|
|
1346
|
+
private splitNode;
|
|
1347
|
+
private splitRouteFrom;
|
|
1348
|
+
private readonly extracts;
|
|
1349
|
+
private readonly validates;
|
|
1350
|
+
private readonly idCounters;
|
|
1351
|
+
constructor(client: Client, name: string, description?: string | undefined);
|
|
1352
|
+
private nextId;
|
|
1353
|
+
private require;
|
|
1354
|
+
parse(opts?: ParseOptions): this;
|
|
1355
|
+
classify(categories: ClassifyCategory[], opts?: {
|
|
1356
|
+
id?: string;
|
|
1357
|
+
}): this;
|
|
1358
|
+
split(rules: SplitterRule[], opts?: {
|
|
1359
|
+
routeFrom?: string | ClassifyCategory;
|
|
1360
|
+
id?: string;
|
|
1361
|
+
}): this;
|
|
1362
|
+
extract(fields: Field[], opts?: {
|
|
1363
|
+
branch?: Branch;
|
|
1364
|
+
id?: string;
|
|
1365
|
+
}): this;
|
|
1366
|
+
validate(rules: ValidationRule[], opts?: {
|
|
1367
|
+
branch?: Branch;
|
|
1368
|
+
id?: string;
|
|
1369
|
+
}): this;
|
|
1370
|
+
private normalizeClassifyBranch;
|
|
1371
|
+
private normalizeExtractBranch;
|
|
1372
|
+
/** Assemble the wire request (branch-routed edges). Pure — no network. */
|
|
1373
|
+
build(): WorkflowCreateRequest;
|
|
1374
|
+
/** Persist the workflow and return its id. */
|
|
1375
|
+
create(): Promise<string>;
|
|
1376
|
+
/** Create the workflow, submit a document, and return a pending `Run`. */
|
|
1377
|
+
run(file?: Blob | File | null, opts?: {
|
|
1378
|
+
text?: string;
|
|
1379
|
+
}): Run;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
interface AnyformatOptions {
|
|
1383
|
+
apiKey: string;
|
|
1384
|
+
/** Override the API base URL (defaults to production). */
|
|
1385
|
+
baseUrl?: string;
|
|
1386
|
+
}
|
|
1387
|
+
/** Entry point. `new Anyformat({ apiKey }).workflow("name").parse()...` */
|
|
1388
|
+
declare class Anyformat {
|
|
1389
|
+
/** @internal */
|
|
1390
|
+
readonly _client: Client;
|
|
1391
|
+
constructor(opts: AnyformatOptions);
|
|
1392
|
+
workflow(name: string, description?: string): WorkflowBuilder;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
declare class AnyformatError extends Error {
|
|
1396
|
+
}
|
|
1397
|
+
declare class APIError extends AnyformatError {
|
|
1398
|
+
readonly status: number;
|
|
1399
|
+
readonly body?: unknown | undefined;
|
|
1400
|
+
constructor(status: number, message: string, body?: unknown | undefined);
|
|
1401
|
+
}
|
|
1402
|
+
declare class BadRequest extends APIError {
|
|
1403
|
+
}
|
|
1404
|
+
declare class Unauthorized extends APIError {
|
|
1405
|
+
}
|
|
1406
|
+
declare class Forbidden extends APIError {
|
|
1407
|
+
}
|
|
1408
|
+
declare class NotFound extends APIError {
|
|
1409
|
+
}
|
|
1410
|
+
declare class RateLimited extends APIError {
|
|
1411
|
+
}
|
|
1412
|
+
declare class ServerError extends APIError {
|
|
1413
|
+
}
|
|
1414
|
+
declare class SDKTimeout extends AnyformatError {
|
|
1415
|
+
}
|
|
1416
|
+
/** Raised by the fluent `WorkflowBuilder` for builder-API misuse. */
|
|
1417
|
+
declare class WorkflowBuilderError extends AnyformatError {
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
export { APIError, Anyformat, AnyformatError, type AnyformatOptions, BadRequest, type BooleanField, type Branch, type ClassifyCategory, type DateField, type DatetimeField, type EnumField, type EnumOption, type ExtractedField, type Extraction, type ExtractionSchema, type Field, type FloatField, Forbidden, type IntegerField, type MultiSelectField, NotFound, type ObjectField, RateLimited, Result, type ResultsResponse, Run, SDKTimeout, Schema, ServerError, type SplitterRule, type StringField, Unauthorized, type ValidationRule, type WaitOptions, WorkflowBuilder, WorkflowBuilderError, type WorkflowCreateRequest };
|