@anyformat/sdk 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -627,6 +627,10 @@ type Evidence = {
627
627
  * ExtractNode
628
628
  */
629
629
  type ExtractNode = {
630
+ /**
631
+ * Context Tracker
632
+ */
633
+ context_tracker?: string;
630
634
  /**
631
635
  * 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.
632
636
  */
@@ -682,7 +686,15 @@ type ExtractNode = {
682
686
  /**
683
687
  * Mode
684
688
  */
685
- mode?: 'standard' | 'agentic';
689
+ mode?: 'standard' | 'agentic' | 'max';
690
+ /**
691
+ * Page Sum Verification Enabled
692
+ */
693
+ page_sum_verification_enabled?: boolean;
694
+ /**
695
+ * Row Extractor Enabled
696
+ */
697
+ row_extractor_enabled?: boolean;
686
698
  /**
687
699
  * Type
688
700
  */
@@ -972,6 +984,8 @@ type ObjectField = {
972
984
  name: string;
973
985
  /**
974
986
  * Nested Fields
987
+ *
988
+ * Child fields of this object. Only one level of nesting is supported — an object field's children must be non-object types.
975
989
  */
976
990
  nested_fields: Array<({
977
991
  data_type: 'string';
@@ -989,14 +1003,16 @@ type ObjectField = {
989
1003
  data_type: 'enum';
990
1004
  } & EnumField) | ({
991
1005
  data_type: 'multi_select';
992
- } & MultiSelectField) | ({
993
- data_type: 'object';
994
- } & ObjectField)>;
1006
+ } & MultiSelectField)>;
995
1007
  };
996
1008
  /**
997
1009
  * ParseNode
998
1010
  */
999
1011
  type ParseNode = {
1012
+ /**
1013
+ * Cache
1014
+ */
1015
+ cache?: boolean;
1000
1016
  /**
1001
1017
  * Figure Enhancement
1002
1018
  */
@@ -1325,12 +1341,45 @@ type WorkflowCreateRequest = {
1325
1341
  } & ValidateNode)>;
1326
1342
  };
1327
1343
 
1344
+ /**
1345
+ * Typed view over the parse node's output. Returned by `Result.parse` — readers
1346
+ * use it for `.markdown`, `.text`, `.blocks`, `.parseConfidence`, and
1347
+ * `.layoutConfidence` without having to walk `result.raw.parse`.
1348
+ *
1349
+ * No `.draw()` here: rasterising pages requires PDF rendering (pdfium); the
1350
+ * Python SDK ships that, the TS SDK does not.
1351
+ */
1352
+ declare class ParseView {
1353
+ private readonly parse;
1354
+ /** @internal */
1355
+ constructor(parse: ParseResult);
1356
+ get markdown(): string | null;
1357
+ get text(): string | null;
1358
+ get blocks(): Block[];
1359
+ /**
1360
+ * Document-level confidence (0-100) in the parsed content. May be `null` for
1361
+ * some parse modes — fall back to `layoutConfidence`.
1362
+ */
1363
+ get parseConfidence(): number | null;
1364
+ /**
1365
+ * Document-level confidence (0-100) in the page layout (block positions).
1366
+ * `null` when not available.
1367
+ */
1368
+ get layoutConfidence(): number | null;
1369
+ }
1370
+
1328
1371
  /** Typed wrapper over a completed run's results. */
1329
1372
  declare class Result {
1330
1373
  readonly raw: ResultsResponse;
1374
+ private _parse;
1331
1375
  constructor(raw: ResultsResponse);
1332
1376
  get collectionId(): string;
1333
1377
  get extractions(): Extraction[];
1378
+ /**
1379
+ * Typed view over the parse node's output, or `null` when the workflow has
1380
+ * no parse node. Cached so repeated access doesn't re-wrap.
1381
+ */
1382
+ get parse(): ParseView | null;
1334
1383
  /**
1335
1384
  * Convenience accessor for a top-level scalar field on the first
1336
1385
  * extraction (linear workflows). Returns `undefined` for missing fields
@@ -1340,34 +1389,49 @@ declare class Result {
1340
1389
  }
1341
1390
 
1342
1391
  interface WaitOptions {
1343
- /** Overall budget before giving up. Default 120s. */
1392
+ /** Overall budget before giving up. Default 300 000 ms (300s). */
1344
1393
  timeoutMs?: number;
1345
- /** Delay between result polls. Default 2s. */
1394
+ /** Delay between result polls. Default 3 000 ms (3s). */
1346
1395
  pollMs?: number;
1347
1396
  }
1348
1397
  /**
1349
- * A pending run. Lazily creates the workflow, submits the document, and
1350
- * polls for results when `wait()` is awaited.
1398
+ * A submitted run. `wait()` polls for completion. Created eagerly by
1399
+ * `Workflow.run()` — the workflow + file submission have already happened
1400
+ * by the time you hold a `Run`.
1351
1401
  */
1352
1402
  declare class Run {
1353
1403
  private readonly client;
1354
- private readonly request;
1355
- private readonly file;
1356
- private readonly text;
1357
- private workflowId;
1358
- private collectionId;
1359
- constructor(client: Client, request: WorkflowCreateRequest, file: Blob | File | null, text: string | null);
1360
- /**
1361
- * Create the workflow and submit the document — exactly once per `Run`.
1362
- * Memoized so that retrying `wait()` after an `SDKTimeout` resumes polling
1363
- * the in-flight run instead of creating a duplicate workflow + submission.
1364
- */
1365
- private submit;
1404
+ readonly workflowId: string;
1405
+ readonly id: string;
1406
+ /** @internal */
1407
+ constructor(client: Client, workflowId: string, id: string);
1366
1408
  wait(opts?: WaitOptions): Promise<Result>;
1367
1409
  }
1368
1410
 
1411
+ /**
1412
+ * A persisted workflow on the server. Returned by `WorkflowBuilder.create()`.
1413
+ * `run(file | text)` submits a document against this workflow's id and returns
1414
+ * a `Run` you can `.wait()` on for results.
1415
+ */
1416
+ declare class Workflow {
1417
+ private readonly client;
1418
+ readonly id: string;
1419
+ readonly name: string;
1420
+ /** @internal */
1421
+ constructor(client: Client, id: string, name: string);
1422
+ /** Submit a document against this workflow and return a pending `Run`. */
1423
+ run(file?: File | null, opts?: {
1424
+ text?: string;
1425
+ }): Promise<Run>;
1426
+ }
1427
+
1369
1428
  /** Any extraction field — the discriminated union on `data_type`. */
1370
1429
  type Field = ExtractionSchema["fields"][number];
1430
+ /**
1431
+ * A field that may appear inside an object. Excludes `object`: only one
1432
+ * level of nesting is supported, so objects cannot contain objects.
1433
+ */
1434
+ type NestedField = ObjectField["nested_fields"][number];
1371
1435
  type LookupOpt = {
1372
1436
  lookup?: boolean;
1373
1437
  };
@@ -1385,7 +1449,7 @@ declare const Schema: {
1385
1449
  datetime: (name: string, description: string, opts?: LookupOpt) => DatetimeField;
1386
1450
  enum: (name: string, description: string, options: EnumOption[], opts?: LookupOpt) => EnumField;
1387
1451
  multiSelect: (name: string, description: string, options: EnumOption[], opts?: LookupOpt) => MultiSelectField;
1388
- object: (name: string, description: string, fields: Field[], opts?: LookupOpt) => ObjectField;
1452
+ object: (name: string, description: string, fields: NestedField[], opts?: LookupOpt) => ObjectField;
1389
1453
  option: (name: string, description: string) => EnumOption;
1390
1454
  };
1391
1455
 
@@ -1396,13 +1460,15 @@ interface ParseOptions {
1396
1460
  mode?: ParseMode;
1397
1461
  promptHint?: string;
1398
1462
  figureEnhancement?: boolean;
1463
+ cache?: boolean;
1399
1464
  id?: string;
1400
1465
  }
1401
1466
  /**
1402
1467
  * Fluent assembler for a typed workflow graph — a faithful TS port of the
1403
1468
  * Python `WorkflowBuilder`. `parse`/`classify`/`split` are singletons;
1404
1469
  * `extract`/`validate` are repeatable and carry their edge metadata. Call
1405
- * `build()` (or `create()`/`run()`) to emit the wire request.
1470
+ * `build()` (or `create()`) to emit the wire request — submit with
1471
+ * `Workflow.run(file)` on the handle that `create()` returns.
1406
1472
  */
1407
1473
  declare class WorkflowBuilder {
1408
1474
  private readonly client;
@@ -1440,12 +1506,10 @@ declare class WorkflowBuilder {
1440
1506
  private normalizeExtractBranch;
1441
1507
  /** Assemble the wire request (branch-routed edges). Pure — no network. */
1442
1508
  build(): WorkflowCreateRequest;
1443
- /** Persist the workflow and return its id. */
1444
- create(): Promise<string>;
1445
- /** Create the workflow, submit a document, and return a pending `Run`. */
1446
- run(file?: Blob | File | null, opts?: {
1447
- text?: string;
1448
- }): Run;
1509
+ /** Persist the workflow and return a handle you can `.run(file)` on. */
1510
+ create(): Promise<Workflow>;
1511
+ /** Replace an existing workflow's definition and return a handle you can `.run(file)` on. */
1512
+ update(workflowId: string): Promise<Workflow>;
1449
1513
  }
1450
1514
 
1451
1515
  interface AnyformatOptions {
@@ -1459,6 +1523,12 @@ declare class Anyformat {
1459
1523
  readonly _client: Client;
1460
1524
  constructor(opts: AnyformatOptions);
1461
1525
  workflow(name: string, description?: string): WorkflowBuilder;
1526
+ listWorkflows(opts?: {
1527
+ page?: number;
1528
+ pageSize?: number;
1529
+ status?: string;
1530
+ }): Promise<Workflow[]>;
1531
+ deleteWorkflow(workflowId: string): Promise<string>;
1462
1532
  }
1463
1533
 
1464
1534
  declare class AnyformatError extends Error {
@@ -1486,4 +1556,4 @@ declare class SDKTimeout extends AnyformatError {
1486
1556
  declare class WorkflowBuilderError extends AnyformatError {
1487
1557
  }
1488
1558
 
1489
- 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 };
1559
+ export { APIError, Anyformat, AnyformatError, type AnyformatOptions, BadRequest, type Block, 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, type NestedField, NotFound, type ObjectField, ParseView, RateLimited, Result, type ResultsResponse, Run, SDKTimeout, Schema, ServerError, type SplitterRule, type StringField, Unauthorized, type ValidationRule, type WaitOptions, Workflow, WorkflowBuilder, WorkflowBuilderError, type WorkflowCreateRequest };
package/dist/index.d.ts CHANGED
@@ -627,6 +627,10 @@ type Evidence = {
627
627
  * ExtractNode
628
628
  */
629
629
  type ExtractNode = {
630
+ /**
631
+ * Context Tracker
632
+ */
633
+ context_tracker?: string;
630
634
  /**
631
635
  * 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.
632
636
  */
@@ -682,7 +686,15 @@ type ExtractNode = {
682
686
  /**
683
687
  * Mode
684
688
  */
685
- mode?: 'standard' | 'agentic';
689
+ mode?: 'standard' | 'agentic' | 'max';
690
+ /**
691
+ * Page Sum Verification Enabled
692
+ */
693
+ page_sum_verification_enabled?: boolean;
694
+ /**
695
+ * Row Extractor Enabled
696
+ */
697
+ row_extractor_enabled?: boolean;
686
698
  /**
687
699
  * Type
688
700
  */
@@ -972,6 +984,8 @@ type ObjectField = {
972
984
  name: string;
973
985
  /**
974
986
  * Nested Fields
987
+ *
988
+ * Child fields of this object. Only one level of nesting is supported — an object field's children must be non-object types.
975
989
  */
976
990
  nested_fields: Array<({
977
991
  data_type: 'string';
@@ -989,14 +1003,16 @@ type ObjectField = {
989
1003
  data_type: 'enum';
990
1004
  } & EnumField) | ({
991
1005
  data_type: 'multi_select';
992
- } & MultiSelectField) | ({
993
- data_type: 'object';
994
- } & ObjectField)>;
1006
+ } & MultiSelectField)>;
995
1007
  };
996
1008
  /**
997
1009
  * ParseNode
998
1010
  */
999
1011
  type ParseNode = {
1012
+ /**
1013
+ * Cache
1014
+ */
1015
+ cache?: boolean;
1000
1016
  /**
1001
1017
  * Figure Enhancement
1002
1018
  */
@@ -1325,12 +1341,45 @@ type WorkflowCreateRequest = {
1325
1341
  } & ValidateNode)>;
1326
1342
  };
1327
1343
 
1344
+ /**
1345
+ * Typed view over the parse node's output. Returned by `Result.parse` — readers
1346
+ * use it for `.markdown`, `.text`, `.blocks`, `.parseConfidence`, and
1347
+ * `.layoutConfidence` without having to walk `result.raw.parse`.
1348
+ *
1349
+ * No `.draw()` here: rasterising pages requires PDF rendering (pdfium); the
1350
+ * Python SDK ships that, the TS SDK does not.
1351
+ */
1352
+ declare class ParseView {
1353
+ private readonly parse;
1354
+ /** @internal */
1355
+ constructor(parse: ParseResult);
1356
+ get markdown(): string | null;
1357
+ get text(): string | null;
1358
+ get blocks(): Block[];
1359
+ /**
1360
+ * Document-level confidence (0-100) in the parsed content. May be `null` for
1361
+ * some parse modes — fall back to `layoutConfidence`.
1362
+ */
1363
+ get parseConfidence(): number | null;
1364
+ /**
1365
+ * Document-level confidence (0-100) in the page layout (block positions).
1366
+ * `null` when not available.
1367
+ */
1368
+ get layoutConfidence(): number | null;
1369
+ }
1370
+
1328
1371
  /** Typed wrapper over a completed run's results. */
1329
1372
  declare class Result {
1330
1373
  readonly raw: ResultsResponse;
1374
+ private _parse;
1331
1375
  constructor(raw: ResultsResponse);
1332
1376
  get collectionId(): string;
1333
1377
  get extractions(): Extraction[];
1378
+ /**
1379
+ * Typed view over the parse node's output, or `null` when the workflow has
1380
+ * no parse node. Cached so repeated access doesn't re-wrap.
1381
+ */
1382
+ get parse(): ParseView | null;
1334
1383
  /**
1335
1384
  * Convenience accessor for a top-level scalar field on the first
1336
1385
  * extraction (linear workflows). Returns `undefined` for missing fields
@@ -1340,34 +1389,49 @@ declare class Result {
1340
1389
  }
1341
1390
 
1342
1391
  interface WaitOptions {
1343
- /** Overall budget before giving up. Default 120s. */
1392
+ /** Overall budget before giving up. Default 300 000 ms (300s). */
1344
1393
  timeoutMs?: number;
1345
- /** Delay between result polls. Default 2s. */
1394
+ /** Delay between result polls. Default 3 000 ms (3s). */
1346
1395
  pollMs?: number;
1347
1396
  }
1348
1397
  /**
1349
- * A pending run. Lazily creates the workflow, submits the document, and
1350
- * polls for results when `wait()` is awaited.
1398
+ * A submitted run. `wait()` polls for completion. Created eagerly by
1399
+ * `Workflow.run()` — the workflow + file submission have already happened
1400
+ * by the time you hold a `Run`.
1351
1401
  */
1352
1402
  declare class Run {
1353
1403
  private readonly client;
1354
- private readonly request;
1355
- private readonly file;
1356
- private readonly text;
1357
- private workflowId;
1358
- private collectionId;
1359
- constructor(client: Client, request: WorkflowCreateRequest, file: Blob | File | null, text: string | null);
1360
- /**
1361
- * Create the workflow and submit the document — exactly once per `Run`.
1362
- * Memoized so that retrying `wait()` after an `SDKTimeout` resumes polling
1363
- * the in-flight run instead of creating a duplicate workflow + submission.
1364
- */
1365
- private submit;
1404
+ readonly workflowId: string;
1405
+ readonly id: string;
1406
+ /** @internal */
1407
+ constructor(client: Client, workflowId: string, id: string);
1366
1408
  wait(opts?: WaitOptions): Promise<Result>;
1367
1409
  }
1368
1410
 
1411
+ /**
1412
+ * A persisted workflow on the server. Returned by `WorkflowBuilder.create()`.
1413
+ * `run(file | text)` submits a document against this workflow's id and returns
1414
+ * a `Run` you can `.wait()` on for results.
1415
+ */
1416
+ declare class Workflow {
1417
+ private readonly client;
1418
+ readonly id: string;
1419
+ readonly name: string;
1420
+ /** @internal */
1421
+ constructor(client: Client, id: string, name: string);
1422
+ /** Submit a document against this workflow and return a pending `Run`. */
1423
+ run(file?: File | null, opts?: {
1424
+ text?: string;
1425
+ }): Promise<Run>;
1426
+ }
1427
+
1369
1428
  /** Any extraction field — the discriminated union on `data_type`. */
1370
1429
  type Field = ExtractionSchema["fields"][number];
1430
+ /**
1431
+ * A field that may appear inside an object. Excludes `object`: only one
1432
+ * level of nesting is supported, so objects cannot contain objects.
1433
+ */
1434
+ type NestedField = ObjectField["nested_fields"][number];
1371
1435
  type LookupOpt = {
1372
1436
  lookup?: boolean;
1373
1437
  };
@@ -1385,7 +1449,7 @@ declare const Schema: {
1385
1449
  datetime: (name: string, description: string, opts?: LookupOpt) => DatetimeField;
1386
1450
  enum: (name: string, description: string, options: EnumOption[], opts?: LookupOpt) => EnumField;
1387
1451
  multiSelect: (name: string, description: string, options: EnumOption[], opts?: LookupOpt) => MultiSelectField;
1388
- object: (name: string, description: string, fields: Field[], opts?: LookupOpt) => ObjectField;
1452
+ object: (name: string, description: string, fields: NestedField[], opts?: LookupOpt) => ObjectField;
1389
1453
  option: (name: string, description: string) => EnumOption;
1390
1454
  };
1391
1455
 
@@ -1396,13 +1460,15 @@ interface ParseOptions {
1396
1460
  mode?: ParseMode;
1397
1461
  promptHint?: string;
1398
1462
  figureEnhancement?: boolean;
1463
+ cache?: boolean;
1399
1464
  id?: string;
1400
1465
  }
1401
1466
  /**
1402
1467
  * Fluent assembler for a typed workflow graph — a faithful TS port of the
1403
1468
  * Python `WorkflowBuilder`. `parse`/`classify`/`split` are singletons;
1404
1469
  * `extract`/`validate` are repeatable and carry their edge metadata. Call
1405
- * `build()` (or `create()`/`run()`) to emit the wire request.
1470
+ * `build()` (or `create()`) to emit the wire request — submit with
1471
+ * `Workflow.run(file)` on the handle that `create()` returns.
1406
1472
  */
1407
1473
  declare class WorkflowBuilder {
1408
1474
  private readonly client;
@@ -1440,12 +1506,10 @@ declare class WorkflowBuilder {
1440
1506
  private normalizeExtractBranch;
1441
1507
  /** Assemble the wire request (branch-routed edges). Pure — no network. */
1442
1508
  build(): WorkflowCreateRequest;
1443
- /** Persist the workflow and return its id. */
1444
- create(): Promise<string>;
1445
- /** Create the workflow, submit a document, and return a pending `Run`. */
1446
- run(file?: Blob | File | null, opts?: {
1447
- text?: string;
1448
- }): Run;
1509
+ /** Persist the workflow and return a handle you can `.run(file)` on. */
1510
+ create(): Promise<Workflow>;
1511
+ /** Replace an existing workflow's definition and return a handle you can `.run(file)` on. */
1512
+ update(workflowId: string): Promise<Workflow>;
1449
1513
  }
1450
1514
 
1451
1515
  interface AnyformatOptions {
@@ -1459,6 +1523,12 @@ declare class Anyformat {
1459
1523
  readonly _client: Client;
1460
1524
  constructor(opts: AnyformatOptions);
1461
1525
  workflow(name: string, description?: string): WorkflowBuilder;
1526
+ listWorkflows(opts?: {
1527
+ page?: number;
1528
+ pageSize?: number;
1529
+ status?: string;
1530
+ }): Promise<Workflow[]>;
1531
+ deleteWorkflow(workflowId: string): Promise<string>;
1462
1532
  }
1463
1533
 
1464
1534
  declare class AnyformatError extends Error {
@@ -1486,4 +1556,4 @@ declare class SDKTimeout extends AnyformatError {
1486
1556
  declare class WorkflowBuilderError extends AnyformatError {
1487
1557
  }
1488
1558
 
1489
- 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 };
1559
+ export { APIError, Anyformat, AnyformatError, type AnyformatOptions, BadRequest, type Block, 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, type NestedField, NotFound, type ObjectField, ParseView, RateLimited, Result, type ResultsResponse, Run, SDKTimeout, Schema, ServerError, type SplitterRule, type StringField, Unauthorized, type ValidationRule, type WaitOptions, Workflow, WorkflowBuilder, WorkflowBuilderError, type WorkflowCreateRequest };