@anyformat/sdk 0.1.0 → 0.2.1

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
@@ -404,6 +404,10 @@ type BooleanField = {
404
404
  * Free-form description shown to the extraction model.
405
405
  */
406
406
  description: string;
407
+ /**
408
+ * Lookup
409
+ */
410
+ lookup?: boolean;
407
411
  /**
408
412
  * Name
409
413
  *
@@ -498,6 +502,10 @@ type DateField = {
498
502
  * Free-form description shown to the extraction model.
499
503
  */
500
504
  description: string;
505
+ /**
506
+ * Lookup
507
+ */
508
+ lookup?: boolean;
501
509
  /**
502
510
  * Name
503
511
  *
@@ -519,6 +527,10 @@ type DatetimeField = {
519
527
  * Free-form description shown to the extraction model.
520
528
  */
521
529
  description: string;
530
+ /**
531
+ * Lookup
532
+ */
533
+ lookup?: boolean;
522
534
  /**
523
535
  * Name
524
536
  *
@@ -566,6 +578,10 @@ type EnumField = {
566
578
  * Enum Options
567
579
  */
568
580
  enum_options: Array<EnumOption>;
581
+ /**
582
+ * Lookup
583
+ */
584
+ lookup?: boolean;
569
585
  /**
570
586
  * Name
571
587
  *
@@ -621,6 +637,12 @@ type ExtractNode = {
621
637
  * Stable identifier for this node within the graph.
622
638
  */
623
639
  id: string;
640
+ /**
641
+ * Lookup File Uploads
642
+ *
643
+ * Inline lookup-file content for the typed create call. The backend uploads each entry to S3 and stores the resulting URI in ``lookup_files``; this field is never persisted in GraphNode.config.
644
+ */
645
+ lookup_file_uploads?: Array<LookupFileUpload>;
624
646
  /**
625
647
  * Lookup Files
626
648
  *
@@ -818,6 +840,10 @@ type FloatField = {
818
840
  * Free-form description shown to the extraction model.
819
841
  */
820
842
  description: string;
843
+ /**
844
+ * Lookup
845
+ */
846
+ lookup?: boolean;
821
847
  /**
822
848
  * Name
823
849
  *
@@ -858,6 +884,10 @@ type IntegerField = {
858
884
  * Free-form description shown to the extraction model.
859
885
  */
860
886
  description: string;
887
+ /**
888
+ * Lookup
889
+ */
890
+ lookup?: boolean;
861
891
  /**
862
892
  * Name
863
893
  *
@@ -865,6 +895,28 @@ type IntegerField = {
865
895
  */
866
896
  name: string;
867
897
  };
898
+ /**
899
+ * LookupFileUpload
900
+ *
901
+ * Inline lookup-file content carried on the typed create call.
902
+ *
903
+ * The backend reads ``filename`` + ``content`` (base64-encoded bytes),
904
+ * uploads the file to S3 during workflow create, and stores the resulting
905
+ * URI in ``ExtractNode.lookup_files``. This field is stripped from the
906
+ * persisted ``GraphNode.config`` — it is create-input only.
907
+ */
908
+ type LookupFileUpload = {
909
+ /**
910
+ * Content
911
+ *
912
+ * Base64-encoded file bytes.
913
+ */
914
+ content: string;
915
+ /**
916
+ * Filename
917
+ */
918
+ filename: string;
919
+ };
868
920
  /**
869
921
  * MultiSelectField
870
922
  */
@@ -883,6 +935,10 @@ type MultiSelectField = {
883
935
  * Enum Options
884
936
  */
885
937
  enum_options: Array<EnumOption>;
938
+ /**
939
+ * Lookup
940
+ */
941
+ lookup?: boolean;
886
942
  /**
887
943
  * Name
888
944
  *
@@ -904,6 +960,10 @@ type ObjectField = {
904
960
  * Free-form description shown to the extraction model.
905
961
  */
906
962
  description: string;
963
+ /**
964
+ * Lookup
965
+ */
966
+ lookup?: boolean;
907
967
  /**
908
968
  * Name
909
969
  *
@@ -1163,6 +1223,10 @@ type StringField = {
1163
1223
  * Free-form description shown to the extraction model.
1164
1224
  */
1165
1225
  description: string;
1226
+ /**
1227
+ * Lookup
1228
+ */
1229
+ lookup?: boolean;
1166
1230
  /**
1167
1231
  * Name
1168
1232
  *
@@ -1304,22 +1368,25 @@ declare class Run {
1304
1368
 
1305
1369
  /** Any extraction field — the discriminated union on `data_type`. */
1306
1370
  type Field = ExtractionSchema["fields"][number];
1371
+ type LookupOpt = {
1372
+ lookup?: boolean;
1373
+ };
1307
1374
  /**
1308
1375
  * Factory for extraction-schema fields — the TS mirror of the Python
1309
1376
  * `Schema` facade. Each method returns the typed wire model the API
1310
1377
  * validates against; the discriminator (`data_type`) is filled in for you.
1311
1378
  */
1312
1379
  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;
1380
+ string: (name: string, description: string, opts?: LookupOpt) => StringField;
1381
+ integer: (name: string, description: string, opts?: LookupOpt) => IntegerField;
1382
+ float: (name: string, description: string, opts?: LookupOpt) => FloatField;
1383
+ boolean: (name: string, description: string, opts?: LookupOpt) => BooleanField;
1384
+ date: (name: string, description: string, opts?: LookupOpt) => DateField;
1385
+ datetime: (name: string, description: string, opts?: LookupOpt) => DatetimeField;
1386
+ enum: (name: string, description: string, options: EnumOption[], opts?: LookupOpt) => EnumField;
1387
+ multiSelect: (name: string, description: string, options: EnumOption[], opts?: LookupOpt) => MultiSelectField;
1388
+ object: (name: string, description: string, fields: Field[], opts?: LookupOpt) => ObjectField;
1389
+ option: (name: string, description: string) => EnumOption;
1323
1390
  };
1324
1391
 
1325
1392
  type ParseMode = "standard" | "agentic";
@@ -1362,6 +1429,8 @@ declare class WorkflowBuilder {
1362
1429
  extract(fields: Field[], opts?: {
1363
1430
  branch?: Branch;
1364
1431
  id?: string;
1432
+ lookupFiles?: string[];
1433
+ lookupSuggestion?: string;
1365
1434
  }): this;
1366
1435
  validate(rules: ValidationRule[], opts?: {
1367
1436
  branch?: Branch;
@@ -1374,7 +1443,7 @@ declare class WorkflowBuilder {
1374
1443
  /** Persist the workflow and return its id. */
1375
1444
  create(): Promise<string>;
1376
1445
  /** Create the workflow, submit a document, and return a pending `Run`. */
1377
- run(file?: Blob | File | null, opts?: {
1446
+ run(file?: File | null, opts?: {
1378
1447
  text?: string;
1379
1448
  }): Run;
1380
1449
  }
package/dist/index.d.ts CHANGED
@@ -404,6 +404,10 @@ type BooleanField = {
404
404
  * Free-form description shown to the extraction model.
405
405
  */
406
406
  description: string;
407
+ /**
408
+ * Lookup
409
+ */
410
+ lookup?: boolean;
407
411
  /**
408
412
  * Name
409
413
  *
@@ -498,6 +502,10 @@ type DateField = {
498
502
  * Free-form description shown to the extraction model.
499
503
  */
500
504
  description: string;
505
+ /**
506
+ * Lookup
507
+ */
508
+ lookup?: boolean;
501
509
  /**
502
510
  * Name
503
511
  *
@@ -519,6 +527,10 @@ type DatetimeField = {
519
527
  * Free-form description shown to the extraction model.
520
528
  */
521
529
  description: string;
530
+ /**
531
+ * Lookup
532
+ */
533
+ lookup?: boolean;
522
534
  /**
523
535
  * Name
524
536
  *
@@ -566,6 +578,10 @@ type EnumField = {
566
578
  * Enum Options
567
579
  */
568
580
  enum_options: Array<EnumOption>;
581
+ /**
582
+ * Lookup
583
+ */
584
+ lookup?: boolean;
569
585
  /**
570
586
  * Name
571
587
  *
@@ -621,6 +637,12 @@ type ExtractNode = {
621
637
  * Stable identifier for this node within the graph.
622
638
  */
623
639
  id: string;
640
+ /**
641
+ * Lookup File Uploads
642
+ *
643
+ * Inline lookup-file content for the typed create call. The backend uploads each entry to S3 and stores the resulting URI in ``lookup_files``; this field is never persisted in GraphNode.config.
644
+ */
645
+ lookup_file_uploads?: Array<LookupFileUpload>;
624
646
  /**
625
647
  * Lookup Files
626
648
  *
@@ -818,6 +840,10 @@ type FloatField = {
818
840
  * Free-form description shown to the extraction model.
819
841
  */
820
842
  description: string;
843
+ /**
844
+ * Lookup
845
+ */
846
+ lookup?: boolean;
821
847
  /**
822
848
  * Name
823
849
  *
@@ -858,6 +884,10 @@ type IntegerField = {
858
884
  * Free-form description shown to the extraction model.
859
885
  */
860
886
  description: string;
887
+ /**
888
+ * Lookup
889
+ */
890
+ lookup?: boolean;
861
891
  /**
862
892
  * Name
863
893
  *
@@ -865,6 +895,28 @@ type IntegerField = {
865
895
  */
866
896
  name: string;
867
897
  };
898
+ /**
899
+ * LookupFileUpload
900
+ *
901
+ * Inline lookup-file content carried on the typed create call.
902
+ *
903
+ * The backend reads ``filename`` + ``content`` (base64-encoded bytes),
904
+ * uploads the file to S3 during workflow create, and stores the resulting
905
+ * URI in ``ExtractNode.lookup_files``. This field is stripped from the
906
+ * persisted ``GraphNode.config`` — it is create-input only.
907
+ */
908
+ type LookupFileUpload = {
909
+ /**
910
+ * Content
911
+ *
912
+ * Base64-encoded file bytes.
913
+ */
914
+ content: string;
915
+ /**
916
+ * Filename
917
+ */
918
+ filename: string;
919
+ };
868
920
  /**
869
921
  * MultiSelectField
870
922
  */
@@ -883,6 +935,10 @@ type MultiSelectField = {
883
935
  * Enum Options
884
936
  */
885
937
  enum_options: Array<EnumOption>;
938
+ /**
939
+ * Lookup
940
+ */
941
+ lookup?: boolean;
886
942
  /**
887
943
  * Name
888
944
  *
@@ -904,6 +960,10 @@ type ObjectField = {
904
960
  * Free-form description shown to the extraction model.
905
961
  */
906
962
  description: string;
963
+ /**
964
+ * Lookup
965
+ */
966
+ lookup?: boolean;
907
967
  /**
908
968
  * Name
909
969
  *
@@ -1163,6 +1223,10 @@ type StringField = {
1163
1223
  * Free-form description shown to the extraction model.
1164
1224
  */
1165
1225
  description: string;
1226
+ /**
1227
+ * Lookup
1228
+ */
1229
+ lookup?: boolean;
1166
1230
  /**
1167
1231
  * Name
1168
1232
  *
@@ -1304,22 +1368,25 @@ declare class Run {
1304
1368
 
1305
1369
  /** Any extraction field — the discriminated union on `data_type`. */
1306
1370
  type Field = ExtractionSchema["fields"][number];
1371
+ type LookupOpt = {
1372
+ lookup?: boolean;
1373
+ };
1307
1374
  /**
1308
1375
  * Factory for extraction-schema fields — the TS mirror of the Python
1309
1376
  * `Schema` facade. Each method returns the typed wire model the API
1310
1377
  * validates against; the discriminator (`data_type`) is filled in for you.
1311
1378
  */
1312
1379
  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;
1380
+ string: (name: string, description: string, opts?: LookupOpt) => StringField;
1381
+ integer: (name: string, description: string, opts?: LookupOpt) => IntegerField;
1382
+ float: (name: string, description: string, opts?: LookupOpt) => FloatField;
1383
+ boolean: (name: string, description: string, opts?: LookupOpt) => BooleanField;
1384
+ date: (name: string, description: string, opts?: LookupOpt) => DateField;
1385
+ datetime: (name: string, description: string, opts?: LookupOpt) => DatetimeField;
1386
+ enum: (name: string, description: string, options: EnumOption[], opts?: LookupOpt) => EnumField;
1387
+ multiSelect: (name: string, description: string, options: EnumOption[], opts?: LookupOpt) => MultiSelectField;
1388
+ object: (name: string, description: string, fields: Field[], opts?: LookupOpt) => ObjectField;
1389
+ option: (name: string, description: string) => EnumOption;
1323
1390
  };
1324
1391
 
1325
1392
  type ParseMode = "standard" | "agentic";
@@ -1362,6 +1429,8 @@ declare class WorkflowBuilder {
1362
1429
  extract(fields: Field[], opts?: {
1363
1430
  branch?: Branch;
1364
1431
  id?: string;
1432
+ lookupFiles?: string[];
1433
+ lookupSuggestion?: string;
1365
1434
  }): this;
1366
1435
  validate(rules: ValidationRule[], opts?: {
1367
1436
  branch?: Branch;
@@ -1374,7 +1443,7 @@ declare class WorkflowBuilder {
1374
1443
  /** Persist the workflow and return its id. */
1375
1444
  create(): Promise<string>;
1376
1445
  /** Create the workflow, submit a document, and return a pending `Run`. */
1377
- run(file?: Blob | File | null, opts?: {
1446
+ run(file?: File | null, opts?: {
1378
1447
  text?: string;
1379
1448
  }): Run;
1380
1449
  }
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ // src/builder.ts
2
+ import { readFileSync } from "fs";
3
+ import { basename } from "path";
4
+
1
5
  // src/result.ts
2
6
  var Result = class {
3
7
  constructor(raw) {
@@ -1030,10 +1034,16 @@ var WorkflowBuilder = class {
1030
1034
  "extract(fields, { branch }) is only valid after classify() or split()"
1031
1035
  );
1032
1036
  const branchId = this.normalizeExtractBranch(opts.branch);
1037
+ const lookupFileUploads = (opts.lookupFiles ?? []).map((filePath) => ({
1038
+ filename: basename(filePath),
1039
+ content: readFileSync(filePath).toString("base64")
1040
+ }));
1033
1041
  const node = {
1034
1042
  type: "extract",
1035
1043
  id: opts.id ?? this.nextId("extract"),
1036
- extraction_schema: { fields }
1044
+ extraction_schema: { fields },
1045
+ ...lookupFileUploads.length > 0 ? { lookup_file_uploads: lookupFileUploads } : {},
1046
+ ...opts.lookupSuggestion !== void 0 ? { lookup_suggestion: opts.lookupSuggestion } : {}
1037
1047
  };
1038
1048
  this.extracts.push([node, branchId]);
1039
1049
  return this;
@@ -1127,6 +1137,13 @@ var WorkflowBuilder = class {
1127
1137
  !(file === null && opts.text === void 0),
1128
1138
  "run() requires a document \u2014 pass a file or opts.text"
1129
1139
  );
1140
+ if (file !== null) {
1141
+ const filename = file.name;
1142
+ this.require(
1143
+ typeof filename === "string" && filename.length > 0,
1144
+ 'run() needs a named file so the server can detect its type \u2014 pass a File, e.g. new File([bytes], "invoice.pdf"), not a bare Blob'
1145
+ );
1146
+ }
1130
1147
  return new Run(this.client, this.build(), file, opts.text ?? null);
1131
1148
  }
1132
1149
  };
@@ -1149,31 +1166,20 @@ var Anyformat = class {
1149
1166
  };
1150
1167
 
1151
1168
  // src/schema.ts
1169
+ function withLookup(base, opts) {
1170
+ if (opts?.lookup) return { ...base, lookup: true };
1171
+ return base;
1172
+ }
1152
1173
  var Schema = {
1153
- string: (name, description) => ({ data_type: "string", name, description }),
1154
- integer: (name, description) => ({ data_type: "integer", name, description }),
1155
- float: (name, description) => ({ data_type: "float", name, description }),
1156
- boolean: (name, description) => ({ data_type: "boolean", name, description }),
1157
- date: (name, description) => ({ data_type: "date", name, description }),
1158
- datetime: (name, description) => ({ data_type: "datetime", name, description }),
1159
- enum: (name, description, options) => ({
1160
- data_type: "enum",
1161
- name,
1162
- description,
1163
- enum_options: options
1164
- }),
1165
- multiSelect: (name, description, options) => ({
1166
- data_type: "multi_select",
1167
- name,
1168
- description,
1169
- enum_options: options
1170
- }),
1171
- object: (name, description, fields) => ({
1172
- data_type: "object",
1173
- name,
1174
- description,
1175
- nested_fields: fields
1176
- }),
1174
+ string: (name, description, opts) => withLookup({ data_type: "string", name, description }, opts),
1175
+ integer: (name, description, opts) => withLookup({ data_type: "integer", name, description }, opts),
1176
+ float: (name, description, opts) => withLookup({ data_type: "float", name, description }, opts),
1177
+ boolean: (name, description, opts) => withLookup({ data_type: "boolean", name, description }, opts),
1178
+ date: (name, description, opts) => withLookup({ data_type: "date", name, description }, opts),
1179
+ datetime: (name, description, opts) => withLookup({ data_type: "datetime", name, description }, opts),
1180
+ enum: (name, description, options, opts) => withLookup({ data_type: "enum", name, description, enum_options: options }, opts),
1181
+ multiSelect: (name, description, options, opts) => withLookup({ data_type: "multi_select", name, description, enum_options: options }, opts),
1182
+ object: (name, description, fields, opts) => withLookup({ data_type: "object", name, description, nested_fields: fields }, opts),
1177
1183
  option: (name, description) => ({ name, description })
1178
1184
  };
1179
1185
  export {