Repository navigation
Expand file tree
/
Copy pathbatch.go
More file actions
1044 lines (951 loc) · 41.7 KB
/
Copy pathbatch.go
File metadata and controls
1044 lines (951 loc) · 41.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package llamacloud
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/run-llama/llama-parse-go/internal/apijson"
"github.com/run-llama/llama-parse-go/internal/apiquery"
"github.com/run-llama/llama-parse-go/internal/requestconfig"
"github.com/run-llama/llama-parse-go/option"
"github.com/run-llama/llama-parse-go/packages/pagination"
"github.com/run-llama/llama-parse-go/packages/param"
"github.com/run-llama/llama-parse-go/packages/respjson"
)
// BatchService contains methods and other services that help with interacting with
// the llama-cloud API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewBatchService] method instead.
type BatchService struct {
options []option.RequestOption
}
// NewBatchService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewBatchService(opts ...option.RequestOption) (r BatchService) {
r = BatchService{}
r.options = opts
return
}
// Create a batch over a source directory and start processing asynchronously.
//
// To be notified as the batch progresses, pass `webhook_configurations` with
// inline endpoints and/or `webhook_configuration_ids` referencing saved
// configurations. Batches emit `batch.pending` on create, `batch.running` once
// processing starts, and a terminal `batch.success` or `batch.error`.
//
// `batch.success` means the batch finished mapping every source file to a job —
// individual files may still have failed, so read `results` (with
// `expand=results`) for per-file outcomes.
//
// Delivery order across events is not guaranteed; key on the `status` field in the
// payload rather than arrival order.
func (r *BatchService) New(ctx context.Context, params BatchNewParams, opts ...option.RequestOption) (res *BatchNewResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "api/v2/batches"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
// List batches for the current project.
func (r *BatchService) List(ctx context.Context, query BatchListParams, opts ...option.RequestOption) (res *pagination.PaginatedCursor[BatchListResponse], err error) {
var raw *http.Response
opts = slices.Concat(r.options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "api/v2/batches"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List batches for the current project.
func (r *BatchService) ListAutoPaging(ctx context.Context, query BatchListParams, opts ...option.RequestOption) *pagination.PaginatedCursorAutoPager[BatchListResponse] {
return pagination.NewPaginatedCursorAutoPager(r.List(ctx, query, opts...))
}
// Cancel a running batch.
//
// Returns immediately; the batch reaches `CANCELLED` once processing stops. Files
// that already finished keep their results. A batch in a terminal status cannot be
// cancelled.
func (r *BatchService) Cancel(ctx context.Context, batchID string, body BatchCancelParams, opts ...option.RequestOption) (res *BatchCancelResponse, err error) {
opts = slices.Concat(r.options, opts)
if batchID == "" {
err = errors.New("missing required batch_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v2/batches/%s/cancel", url.PathEscape(batchID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Get a batch by ID.
func (r *BatchService) Get(ctx context.Context, batchID string, query BatchGetParams, opts ...option.RequestOption) (res *BatchGetResponse, err error) {
opts = slices.Concat(r.options, opts)
if batchID == "" {
err = errors.New("missing required batch_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v2/batches/%s", url.PathEscape(batchID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// A top-level batch.
//
// Example: { "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "project_id":
// "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "source_directory_id":
// "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "config": { "job": { "type":
// "parse_v2", "configuration_id": "cfg-PARSE_AGENTIC" } }, "status": "COMPLETED",
// "results": [ { "source_directory_file_id":
// "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "job_reference": { "type":
// "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" }, "error_message":
// null } ] }
//
// Batch-level `FAILED` means the orchestration failed and cannot provide a
// reliable per-file result set. `results` is only populated when explicitly
// requested with `expand=results` and may be `null` while a batch is still
// running.
type BatchNewResponse struct {
// Unique identifier
ID string `json:"id" api:"required"`
// Batch configuration snapshot.
Config BatchNewResponseConfig `json:"config" api:"required"`
// Project this batch belongs to.
ProjectID string `json:"project_id" api:"required"`
// Directory being processed.
SourceDirectoryID string `json:"source_directory_id" api:"required"`
// Current batch status.
//
// Any of "CANCELLED", "COMPLETED", "FAILED", "PENDING", "RUNNING", "THROTTLED".
Status BatchNewResponseStatus `json:"status" api:"required"`
// Creation datetime
CreatedAt time.Time `json:"created_at" api:"nullable" format:"date-time"`
// Expanded per-file result mappings. Null unless requested with expand=results, or
// while the batch is still running.
Results []BatchNewResponseResult `json:"results" api:"nullable"`
// Update datetime
UpdatedAt time.Time `json:"updated_at" api:"nullable" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Config respjson.Field
ProjectID respjson.Field
SourceDirectoryID respjson.Field
Status respjson.Field
CreatedAt respjson.Field
Results respjson.Field
UpdatedAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchNewResponse) RawJSON() string { return r.JSON.raw }
func (r *BatchNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Batch configuration snapshot.
type BatchNewResponseConfig struct {
// Job to create for each file in the source directory.
Job BatchNewResponseConfigJob `json:"job" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Job respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchNewResponseConfig) RawJSON() string { return r.JSON.raw }
func (r *BatchNewResponseConfig) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Job to create for each file in the source directory.
type BatchNewResponseConfigJob struct {
// Product configuration ID or built-in preset ID matching the job type.
ConfigurationID string `json:"configuration_id" api:"required"`
// Product job type to run for each source directory file.
//
// Any of "parse_v2", "extract_v2".
Type BatchNewResponseConfigJobType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ConfigurationID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchNewResponseConfigJob) RawJSON() string { return r.JSON.raw }
func (r *BatchNewResponseConfigJob) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Product job type to run for each source directory file.
type BatchNewResponseConfigJobType string
const (
BatchNewResponseConfigJobTypeParseV2 BatchNewResponseConfigJobType = "parse_v2"
BatchNewResponseConfigJobTypeExtractV2 BatchNewResponseConfigJobType = "extract_v2"
)
// Current batch status.
type BatchNewResponseStatus string
const (
BatchNewResponseStatusCancelled BatchNewResponseStatus = "CANCELLED"
BatchNewResponseStatusCompleted BatchNewResponseStatus = "COMPLETED"
BatchNewResponseStatusFailed BatchNewResponseStatus = "FAILED"
BatchNewResponseStatusPending BatchNewResponseStatus = "PENDING"
BatchNewResponseStatusRunning BatchNewResponseStatus = "RUNNING"
BatchNewResponseStatusThrottled BatchNewResponseStatus = "THROTTLED"
)
// Result projection for one source directory file in a batch.
//
// Example: { "source_directory_file_id":
// "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "job_reference": { "type":
// "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" }, "error_message":
// null }
//
// This is a projection of directory-sync state, not a separate child resource that
// callers need to create. The source directory file ID is the stable correlation
// key. Underlying job progress and failures should be resolved through the
// referenced product job endpoint.
type BatchNewResponseResult struct {
// Source directory file processed by this batch.
SourceDirectoryFileID string `json:"source_directory_file_id" api:"required"`
// Batch-level mapping error if the system could not create or associate a job for
// this source file.
ErrorMessage string `json:"error_message" api:"nullable"`
// Reference to a job produced by a batch.
//
// Example: { "type": "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
// }
JobReference BatchNewResponseResultJobReference `json:"job_reference" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
SourceDirectoryFileID respjson.Field
ErrorMessage respjson.Field
JobReference respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchNewResponseResult) RawJSON() string { return r.JSON.raw }
func (r *BatchNewResponseResult) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Reference to a job produced by a batch.
//
// Example: { "type": "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
// }
type BatchNewResponseResultJobReference struct {
// Job ID, such as a parse job ID.
ID string `json:"id" api:"required"`
// Type of job produced for the file.
//
// Any of "parse_v2", "extract_v2".
Type BatchNewResponseResultJobReferenceType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchNewResponseResultJobReference) RawJSON() string { return r.JSON.raw }
func (r *BatchNewResponseResultJobReference) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Type of job produced for the file.
type BatchNewResponseResultJobReferenceType string
const (
BatchNewResponseResultJobReferenceTypeParseV2 BatchNewResponseResultJobReferenceType = "parse_v2"
BatchNewResponseResultJobReferenceTypeExtractV2 BatchNewResponseResultJobReferenceType = "extract_v2"
)
// A top-level batch.
//
// Example: { "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "project_id":
// "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "source_directory_id":
// "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "config": { "job": { "type":
// "parse_v2", "configuration_id": "cfg-PARSE_AGENTIC" } }, "status": "COMPLETED",
// "results": [ { "source_directory_file_id":
// "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "job_reference": { "type":
// "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" }, "error_message":
// null } ] }
//
// Batch-level `FAILED` means the orchestration failed and cannot provide a
// reliable per-file result set. `results` is only populated when explicitly
// requested with `expand=results` and may be `null` while a batch is still
// running.
type BatchListResponse struct {
// Unique identifier
ID string `json:"id" api:"required"`
// Batch configuration snapshot.
Config BatchListResponseConfig `json:"config" api:"required"`
// Project this batch belongs to.
ProjectID string `json:"project_id" api:"required"`
// Directory being processed.
SourceDirectoryID string `json:"source_directory_id" api:"required"`
// Current batch status.
//
// Any of "CANCELLED", "COMPLETED", "FAILED", "PENDING", "RUNNING", "THROTTLED".
Status BatchListResponseStatus `json:"status" api:"required"`
// Creation datetime
CreatedAt time.Time `json:"created_at" api:"nullable" format:"date-time"`
// Expanded per-file result mappings. Null unless requested with expand=results, or
// while the batch is still running.
Results []BatchListResponseResult `json:"results" api:"nullable"`
// Update datetime
UpdatedAt time.Time `json:"updated_at" api:"nullable" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Config respjson.Field
ProjectID respjson.Field
SourceDirectoryID respjson.Field
Status respjson.Field
CreatedAt respjson.Field
Results respjson.Field
UpdatedAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchListResponse) RawJSON() string { return r.JSON.raw }
func (r *BatchListResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Batch configuration snapshot.
type BatchListResponseConfig struct {
// Job to create for each file in the source directory.
Job BatchListResponseConfigJob `json:"job" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Job respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchListResponseConfig) RawJSON() string { return r.JSON.raw }
func (r *BatchListResponseConfig) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Job to create for each file in the source directory.
type BatchListResponseConfigJob struct {
// Product configuration ID or built-in preset ID matching the job type.
ConfigurationID string `json:"configuration_id" api:"required"`
// Product job type to run for each source directory file.
//
// Any of "parse_v2", "extract_v2".
Type BatchListResponseConfigJobType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ConfigurationID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchListResponseConfigJob) RawJSON() string { return r.JSON.raw }
func (r *BatchListResponseConfigJob) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Product job type to run for each source directory file.
type BatchListResponseConfigJobType string
const (
BatchListResponseConfigJobTypeParseV2 BatchListResponseConfigJobType = "parse_v2"
BatchListResponseConfigJobTypeExtractV2 BatchListResponseConfigJobType = "extract_v2"
)
// Current batch status.
type BatchListResponseStatus string
const (
BatchListResponseStatusCancelled BatchListResponseStatus = "CANCELLED"
BatchListResponseStatusCompleted BatchListResponseStatus = "COMPLETED"
BatchListResponseStatusFailed BatchListResponseStatus = "FAILED"
BatchListResponseStatusPending BatchListResponseStatus = "PENDING"
BatchListResponseStatusRunning BatchListResponseStatus = "RUNNING"
BatchListResponseStatusThrottled BatchListResponseStatus = "THROTTLED"
)
// Result projection for one source directory file in a batch.
//
// Example: { "source_directory_file_id":
// "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "job_reference": { "type":
// "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" }, "error_message":
// null }
//
// This is a projection of directory-sync state, not a separate child resource that
// callers need to create. The source directory file ID is the stable correlation
// key. Underlying job progress and failures should be resolved through the
// referenced product job endpoint.
type BatchListResponseResult struct {
// Source directory file processed by this batch.
SourceDirectoryFileID string `json:"source_directory_file_id" api:"required"`
// Batch-level mapping error if the system could not create or associate a job for
// this source file.
ErrorMessage string `json:"error_message" api:"nullable"`
// Reference to a job produced by a batch.
//
// Example: { "type": "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
// }
JobReference BatchListResponseResultJobReference `json:"job_reference" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
SourceDirectoryFileID respjson.Field
ErrorMessage respjson.Field
JobReference respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchListResponseResult) RawJSON() string { return r.JSON.raw }
func (r *BatchListResponseResult) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Reference to a job produced by a batch.
//
// Example: { "type": "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
// }
type BatchListResponseResultJobReference struct {
// Job ID, such as a parse job ID.
ID string `json:"id" api:"required"`
// Type of job produced for the file.
//
// Any of "parse_v2", "extract_v2".
Type BatchListResponseResultJobReferenceType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchListResponseResultJobReference) RawJSON() string { return r.JSON.raw }
func (r *BatchListResponseResultJobReference) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Type of job produced for the file.
type BatchListResponseResultJobReferenceType string
const (
BatchListResponseResultJobReferenceTypeParseV2 BatchListResponseResultJobReferenceType = "parse_v2"
BatchListResponseResultJobReferenceTypeExtractV2 BatchListResponseResultJobReferenceType = "extract_v2"
)
// A top-level batch.
//
// Example: { "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "project_id":
// "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "source_directory_id":
// "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "config": { "job": { "type":
// "parse_v2", "configuration_id": "cfg-PARSE_AGENTIC" } }, "status": "COMPLETED",
// "results": [ { "source_directory_file_id":
// "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "job_reference": { "type":
// "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" }, "error_message":
// null } ] }
//
// Batch-level `FAILED` means the orchestration failed and cannot provide a
// reliable per-file result set. `results` is only populated when explicitly
// requested with `expand=results` and may be `null` while a batch is still
// running.
type BatchCancelResponse struct {
// Unique identifier
ID string `json:"id" api:"required"`
// Batch configuration snapshot.
Config BatchCancelResponseConfig `json:"config" api:"required"`
// Project this batch belongs to.
ProjectID string `json:"project_id" api:"required"`
// Directory being processed.
SourceDirectoryID string `json:"source_directory_id" api:"required"`
// Current batch status.
//
// Any of "CANCELLED", "COMPLETED", "FAILED", "PENDING", "RUNNING", "THROTTLED".
Status BatchCancelResponseStatus `json:"status" api:"required"`
// Creation datetime
CreatedAt time.Time `json:"created_at" api:"nullable" format:"date-time"`
// Expanded per-file result mappings. Null unless requested with expand=results, or
// while the batch is still running.
Results []BatchCancelResponseResult `json:"results" api:"nullable"`
// Update datetime
UpdatedAt time.Time `json:"updated_at" api:"nullable" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Config respjson.Field
ProjectID respjson.Field
SourceDirectoryID respjson.Field
Status respjson.Field
CreatedAt respjson.Field
Results respjson.Field
UpdatedAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchCancelResponse) RawJSON() string { return r.JSON.raw }
func (r *BatchCancelResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Batch configuration snapshot.
type BatchCancelResponseConfig struct {
// Job to create for each file in the source directory.
Job BatchCancelResponseConfigJob `json:"job" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Job respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchCancelResponseConfig) RawJSON() string { return r.JSON.raw }
func (r *BatchCancelResponseConfig) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Job to create for each file in the source directory.
type BatchCancelResponseConfigJob struct {
// Product configuration ID or built-in preset ID matching the job type.
ConfigurationID string `json:"configuration_id" api:"required"`
// Product job type to run for each source directory file.
//
// Any of "parse_v2", "extract_v2".
Type BatchCancelResponseConfigJobType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ConfigurationID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchCancelResponseConfigJob) RawJSON() string { return r.JSON.raw }
func (r *BatchCancelResponseConfigJob) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Product job type to run for each source directory file.
type BatchCancelResponseConfigJobType string
const (
BatchCancelResponseConfigJobTypeParseV2 BatchCancelResponseConfigJobType = "parse_v2"
BatchCancelResponseConfigJobTypeExtractV2 BatchCancelResponseConfigJobType = "extract_v2"
)
// Current batch status.
type BatchCancelResponseStatus string
const (
BatchCancelResponseStatusCancelled BatchCancelResponseStatus = "CANCELLED"
BatchCancelResponseStatusCompleted BatchCancelResponseStatus = "COMPLETED"
BatchCancelResponseStatusFailed BatchCancelResponseStatus = "FAILED"
BatchCancelResponseStatusPending BatchCancelResponseStatus = "PENDING"
BatchCancelResponseStatusRunning BatchCancelResponseStatus = "RUNNING"
BatchCancelResponseStatusThrottled BatchCancelResponseStatus = "THROTTLED"
)
// Result projection for one source directory file in a batch.
//
// Example: { "source_directory_file_id":
// "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "job_reference": { "type":
// "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" }, "error_message":
// null }
//
// This is a projection of directory-sync state, not a separate child resource that
// callers need to create. The source directory file ID is the stable correlation
// key. Underlying job progress and failures should be resolved through the
// referenced product job endpoint.
type BatchCancelResponseResult struct {
// Source directory file processed by this batch.
SourceDirectoryFileID string `json:"source_directory_file_id" api:"required"`
// Batch-level mapping error if the system could not create or associate a job for
// this source file.
ErrorMessage string `json:"error_message" api:"nullable"`
// Reference to a job produced by a batch.
//
// Example: { "type": "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
// }
JobReference BatchCancelResponseResultJobReference `json:"job_reference" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
SourceDirectoryFileID respjson.Field
ErrorMessage respjson.Field
JobReference respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchCancelResponseResult) RawJSON() string { return r.JSON.raw }
func (r *BatchCancelResponseResult) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Reference to a job produced by a batch.
//
// Example: { "type": "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
// }
type BatchCancelResponseResultJobReference struct {
// Job ID, such as a parse job ID.
ID string `json:"id" api:"required"`
// Type of job produced for the file.
//
// Any of "parse_v2", "extract_v2".
Type BatchCancelResponseResultJobReferenceType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchCancelResponseResultJobReference) RawJSON() string { return r.JSON.raw }
func (r *BatchCancelResponseResultJobReference) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Type of job produced for the file.
type BatchCancelResponseResultJobReferenceType string
const (
BatchCancelResponseResultJobReferenceTypeParseV2 BatchCancelResponseResultJobReferenceType = "parse_v2"
BatchCancelResponseResultJobReferenceTypeExtractV2 BatchCancelResponseResultJobReferenceType = "extract_v2"
)
// A top-level batch.
//
// Example: { "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "project_id":
// "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "source_directory_id":
// "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "config": { "job": { "type":
// "parse_v2", "configuration_id": "cfg-PARSE_AGENTIC" } }, "status": "COMPLETED",
// "results": [ { "source_directory_file_id":
// "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "job_reference": { "type":
// "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" }, "error_message":
// null } ] }
//
// Batch-level `FAILED` means the orchestration failed and cannot provide a
// reliable per-file result set. `results` is only populated when explicitly
// requested with `expand=results` and may be `null` while a batch is still
// running.
type BatchGetResponse struct {
// Unique identifier
ID string `json:"id" api:"required"`
// Batch configuration snapshot.
Config BatchGetResponseConfig `json:"config" api:"required"`
// Project this batch belongs to.
ProjectID string `json:"project_id" api:"required"`
// Directory being processed.
SourceDirectoryID string `json:"source_directory_id" api:"required"`
// Current batch status.
//
// Any of "CANCELLED", "COMPLETED", "FAILED", "PENDING", "RUNNING", "THROTTLED".
Status BatchGetResponseStatus `json:"status" api:"required"`
// Creation datetime
CreatedAt time.Time `json:"created_at" api:"nullable" format:"date-time"`
// Expanded per-file result mappings. Null unless requested with expand=results, or
// while the batch is still running.
Results []BatchGetResponseResult `json:"results" api:"nullable"`
// Update datetime
UpdatedAt time.Time `json:"updated_at" api:"nullable" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Config respjson.Field
ProjectID respjson.Field
SourceDirectoryID respjson.Field
Status respjson.Field
CreatedAt respjson.Field
Results respjson.Field
UpdatedAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchGetResponse) RawJSON() string { return r.JSON.raw }
func (r *BatchGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Batch configuration snapshot.
type BatchGetResponseConfig struct {
// Job to create for each file in the source directory.
Job BatchGetResponseConfigJob `json:"job" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Job respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchGetResponseConfig) RawJSON() string { return r.JSON.raw }
func (r *BatchGetResponseConfig) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Job to create for each file in the source directory.
type BatchGetResponseConfigJob struct {
// Product configuration ID or built-in preset ID matching the job type.
ConfigurationID string `json:"configuration_id" api:"required"`
// Product job type to run for each source directory file.
//
// Any of "parse_v2", "extract_v2".
Type BatchGetResponseConfigJobType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ConfigurationID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchGetResponseConfigJob) RawJSON() string { return r.JSON.raw }
func (r *BatchGetResponseConfigJob) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Product job type to run for each source directory file.
type BatchGetResponseConfigJobType string
const (
BatchGetResponseConfigJobTypeParseV2 BatchGetResponseConfigJobType = "parse_v2"
BatchGetResponseConfigJobTypeExtractV2 BatchGetResponseConfigJobType = "extract_v2"
)
// Current batch status.
type BatchGetResponseStatus string
const (
BatchGetResponseStatusCancelled BatchGetResponseStatus = "CANCELLED"
BatchGetResponseStatusCompleted BatchGetResponseStatus = "COMPLETED"
BatchGetResponseStatusFailed BatchGetResponseStatus = "FAILED"
BatchGetResponseStatusPending BatchGetResponseStatus = "PENDING"
BatchGetResponseStatusRunning BatchGetResponseStatus = "RUNNING"
BatchGetResponseStatusThrottled BatchGetResponseStatus = "THROTTLED"
)
// Result projection for one source directory file in a batch.
//
// Example: { "source_directory_file_id":
// "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "job_reference": { "type":
// "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" }, "error_message":
// null }
//
// This is a projection of directory-sync state, not a separate child resource that
// callers need to create. The source directory file ID is the stable correlation
// key. Underlying job progress and failures should be resolved through the
// referenced product job endpoint.
type BatchGetResponseResult struct {
// Source directory file processed by this batch.
SourceDirectoryFileID string `json:"source_directory_file_id" api:"required"`
// Batch-level mapping error if the system could not create or associate a job for
// this source file.
ErrorMessage string `json:"error_message" api:"nullable"`
// Reference to a job produced by a batch.
//
// Example: { "type": "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
// }
JobReference BatchGetResponseResultJobReference `json:"job_reference" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
SourceDirectoryFileID respjson.Field
ErrorMessage respjson.Field
JobReference respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchGetResponseResult) RawJSON() string { return r.JSON.raw }
func (r *BatchGetResponseResult) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Reference to a job produced by a batch.
//
// Example: { "type": "parse_v2", "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
// }
type BatchGetResponseResultJobReference struct {
// Job ID, such as a parse job ID.
ID string `json:"id" api:"required"`
// Type of job produced for the file.
//
// Any of "parse_v2", "extract_v2".
Type BatchGetResponseResultJobReferenceType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BatchGetResponseResultJobReference) RawJSON() string { return r.JSON.raw }
func (r *BatchGetResponseResultJobReference) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Type of job produced for the file.
type BatchGetResponseResultJobReferenceType string
const (
BatchGetResponseResultJobReferenceTypeParseV2 BatchGetResponseResultJobReferenceType = "parse_v2"
BatchGetResponseResultJobReferenceTypeExtractV2 BatchGetResponseResultJobReferenceType = "extract_v2"
)
type BatchNewParams struct {
// Batch configuration snapshot to apply to this source directory.
Config BatchNewParamsConfig `json:"config,omitzero" api:"required"`
// Directory whose files should be processed.
SourceDirectoryID string `json:"source_directory_id" api:"required"`
OrganizationID param.Opt[string] `query:"organization_id,omitzero" format:"uuid" json:"-"`
ProjectID param.Opt[string] `query:"project_id,omitzero" format:"uuid" json:"-"`
// IDs of saved webhook configurations to notify for this job.
WebhookConfigurationIDs []string `json:"webhook_configuration_ids,omitzero"`
// Outbound webhook endpoints to notify on job status changes
WebhookConfigurations []BatchNewParamsWebhookConfiguration `json:"webhook_configurations,omitzero"`
paramObj
}
func (r BatchNewParams) MarshalJSON() (data []byte, err error) {
type shadow BatchNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BatchNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// URLQuery serializes [BatchNewParams]'s query parameters as `url.Values`.
func (r BatchNewParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Batch configuration snapshot to apply to this source directory.
//
// The property Job is required.
type BatchNewParamsConfig struct {
// Job to create for each file in the source directory.
Job BatchNewParamsConfigJob `json:"job,omitzero" api:"required"`
paramObj
}
func (r BatchNewParamsConfig) MarshalJSON() (data []byte, err error) {
type shadow BatchNewParamsConfig
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BatchNewParamsConfig) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Job to create for each file in the source directory.
//
// The properties ConfigurationID, Type are required.
type BatchNewParamsConfigJob struct {
// Product configuration ID or built-in preset ID matching the job type.
ConfigurationID string `json:"configuration_id" api:"required"`
// Product job type to run for each source directory file.
//
// Any of "parse_v2", "extract_v2".
Type BatchNewParamsConfigJobType `json:"type,omitzero" api:"required"`
paramObj
}
func (r BatchNewParamsConfigJob) MarshalJSON() (data []byte, err error) {
type shadow BatchNewParamsConfigJob
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BatchNewParamsConfigJob) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Product job type to run for each source directory file.
type BatchNewParamsConfigJobType string
const (
BatchNewParamsConfigJobTypeParseV2 BatchNewParamsConfigJobType = "parse_v2"
BatchNewParamsConfigJobTypeExtractV2 BatchNewParamsConfigJobType = "extract_v2"
)
// Configuration for a single outbound webhook endpoint.
type BatchNewParamsWebhookConfiguration struct {
// Response format sent to the webhook: 'string' (default) or 'json'
WebhookOutputFormat param.Opt[string] `json:"webhook_output_format,omitzero"`
// Shared signing secret used to sign webhook deliveries. When set, each request
// includes an HMAC-SHA256 signature of the request body in the 'LC-Signature'
// header (value 'sha256=<hex>'). Recompute the HMAC over the raw request body with
// this secret to verify the delivery is authentic.
WebhookSigningSecret param.Opt[string] `json:"webhook_signing_secret,omitzero"`
// URL to receive webhook POST notifications
WebhookURL param.Opt[string] `json:"webhook_url,omitzero"`
// Events to subscribe to (e.g. 'parse.success', 'extract.error'). If null, all
// events are delivered.
//
// Any of "batch.cancelled", "batch.error", "batch.pending", "batch.running",
// "batch.success", "classify.cancelled", "classify.error",
// "classify.partial_success", "classify.pending", "classify.running",
// "classify.success", "extract.cancelled", "extract.error",
// "extract.partial_success", "extract.pending", "extract.success",
// "parse.cancelled", "parse.error", "parse.partial_success", "parse.pending",
// "parse.running", "parse.success", "sheets.cancelled", "sheets.error",
// "sheets.partial_success", "sheets.pending", "sheets.success", "split.cancelled",
// "split.error", "split.pending", "split.processing", "split.success",
// "unmapped_event", "verify.cancelled", "verify.error", "verify.pending",
// "verify.running", "verify.success".
WebhookEvents []string `json:"webhook_events,omitzero"`
// Custom HTTP headers sent with each webhook request (e.g. auth tokens)
WebhookHeaders map[string]string `json:"webhook_headers,omitzero"`
paramObj
}
func (r BatchNewParamsWebhookConfiguration) MarshalJSON() (data []byte, err error) {
type shadow BatchNewParamsWebhookConfiguration
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BatchNewParamsWebhookConfiguration) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BatchListParams struct {
CreatedAtOnOrAfter param.Opt[time.Time] `query:"created_at_on_or_after,omitzero" format:"date-time" json:"-"`
CreatedAtOnOrBefore param.Opt[time.Time] `query:"created_at_on_or_before,omitzero" format:"date-time" json:"-"`
OrganizationID param.Opt[string] `query:"organization_id,omitzero" format:"uuid" json:"-"`
PageSize param.Opt[int64] `query:"page_size,omitzero" json:"-"`
PageToken param.Opt[string] `query:"page_token,omitzero" json:"-"`
ProjectID param.Opt[string] `query:"project_id,omitzero" format:"uuid" json:"-"`
SourceDirectoryID param.Opt[string] `query:"source_directory_id,omitzero" json:"-"`
// Any of "CANCELLED", "COMPLETED", "FAILED", "PENDING", "RUNNING", "THROTTLED".
Status BatchListParamsStatus `query:"status,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [BatchListParams]'s query parameters as `url.Values`.
func (r BatchListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,