Repository navigation
Expand file tree
/
Copy paththread.go
More file actions
1295 lines (1131 loc) · 44.1 KB
/
Copy paththread.go
File metadata and controls
1295 lines (1131 loc) · 44.1 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 cercago
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"reflect"
"slices"
"github.com/matrices/cerca-go/internal/apijson"
"github.com/matrices/cerca-go/internal/apiquery"
"github.com/matrices/cerca-go/internal/param"
"github.com/matrices/cerca-go/internal/requestconfig"
"github.com/matrices/cerca-go/option"
"github.com/matrices/cerca-go/packages/pagination"
"github.com/matrices/cerca-go/shared"
"github.com/tidwall/gjson"
)
// ThreadService contains methods and other services that help with interacting
// with the cerca 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 [NewThreadService] method instead.
type ThreadService struct {
Options []option.RequestOption
}
// NewThreadService 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 NewThreadService(opts ...option.RequestOption) (r *ThreadService) {
r = &ThreadService{}
r.Options = opts
return
}
// Create thread
func (r *ThreadService) New(ctx context.Context, agentID string, body ThreadNewParams, opts ...option.RequestOption) (res *Thread, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/threads", agentID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Retrieve thread
func (r *ThreadService) Get(ctx context.Context, agentID string, threadID string, query ThreadGetParams, opts ...option.RequestOption) (res *Thread, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if threadID == "" {
err = errors.New("missing required threadId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/threads/%s", agentID, threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// List threads
func (r *ThreadService) List(ctx context.Context, agentID string, query ThreadListParams, opts ...option.RequestOption) (res *pagination.ThreadsCursorPage[ThreadSummary], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/threads", agentID)
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 threads
func (r *ThreadService) ListAutoPaging(ctx context.Context, agentID string, query ThreadListParams, opts ...option.RequestOption) *pagination.ThreadsCursorPageAutoPager[ThreadSummary] {
return pagination.NewThreadsCursorPageAutoPager(r.List(ctx, agentID, query, opts...))
}
// Fetch compact current and recent activity for a thread without returning
// transcript content or runtime debug state.
func (r *ThreadService) Activity(ctx context.Context, agentID string, threadID string, query ThreadActivityParams, opts ...option.RequestOption) (res *ActivityDetail, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if threadID == "" {
err = errors.New("missing required threadId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/threads/%s/activity", agentID, threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// Cancel a running or awaiting thread. The underlying runtime treats repeat
// cancellation as an idempotent lifecycle operation when possible.
func (r *ThreadService) Cancel(ctx context.Context, agentID string, threadID string, opts ...option.RequestOption) (res *Thread, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if threadID == "" {
err = errors.New("missing required threadId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/threads/%s/cancel", agentID, threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return res, err
}
// Close an idle thread. Closing a running, awaiting, or already-closed thread
// returns a lifecycle conflict.
func (r *ThreadService) Close(ctx context.Context, agentID string, threadID string, opts ...option.RequestOption) (res *Thread, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if threadID == "" {
err = errors.New("missing required threadId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/threads/%s/close", agentID, threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return res, err
}
// Force context compaction for an idle thread. Compacting a running thread returns
// a lifecycle conflict.
func (r *ThreadService) Compact(ctx context.Context, agentID string, threadID string, opts ...option.RequestOption) (res *Thread, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if threadID == "" {
err = errors.New("missing required threadId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/threads/%s/compact", agentID, threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return res, err
}
// List a bounded page of transcript messages for a thread, newest first. Use the
// returned `cursor` to page older messages.
func (r *ThreadService) ListMessages(ctx context.Context, agentID string, threadID string, query ThreadListMessagesParams, opts ...option.RequestOption) (res *pagination.ThreadMessagesCursorPage[Message], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if threadID == "" {
err = errors.New("missing required threadId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/threads/%s/messages", agentID, threadID)
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 a bounded page of transcript messages for a thread, newest first. Use the
// returned `cursor` to page older messages.
func (r *ThreadService) ListMessagesAutoPaging(ctx context.Context, agentID string, threadID string, query ThreadListMessagesParams, opts ...option.RequestOption) *pagination.ThreadMessagesCursorPageAutoPager[Message] {
return pagination.NewThreadMessagesCursorPageAutoPager(r.ListMessages(ctx, agentID, threadID, query, opts...))
}
// Create turn
func (r *ThreadService) StartTurn(ctx context.Context, agentID string, threadID string, body ThreadStartTurnParams, opts ...option.RequestOption) (res *Turn, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if threadID == "" {
err = errors.New("missing required threadId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/threads/%s/turns", agentID, threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Steer a thread with another user message. Steering a closed thread returns a
// conflict; steering a running or awaiting thread queues the message.
func (r *ThreadService) Steer(ctx context.Context, agentID string, threadID string, body ThreadSteerParams, opts ...option.RequestOption) (res *SteerResult, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if threadID == "" {
err = errors.New("missing required threadId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/threads/%s/steer", agentID, threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
type ActivityDetail struct {
Error string `json:"error" api:"required,nullable"`
RecentTurns []ThreadTurnSummary `json:"recentTurns" api:"required"`
JSON activityDetailJSON `json:"-"`
ActivitySummary
}
// activityDetailJSON contains the JSON metadata for the struct [ActivityDetail]
type activityDetailJSON struct {
Error apijson.Field
RecentTurns apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ActivityDetail) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r activityDetailJSON) RawJSON() string {
return r.raw
}
type ActivitySummary struct {
ID string `json:"id" api:"required"`
CompletedAt string `json:"completedAt" api:"required,nullable"`
CreatedAt string `json:"createdAt" api:"required"`
Goal string `json:"goal" api:"required"`
LatestActivity string `json:"latestActivity" api:"required,nullable"`
MessageCount float64 `json:"messageCount" api:"required"`
Model string `json:"model" api:"required"`
NextStep string `json:"nextStep" api:"required,nullable"`
ParentThreadID string `json:"parentThreadId" api:"required,nullable"`
Result string `json:"result" api:"required,nullable"`
ScheduleID string `json:"scheduleId" api:"required,nullable"`
// `idle` threads can accept a new turn or be closed. `running` threads have an
// active turn. `awaiting` threads are paused on external input such as approvals.
// `closed` threads are terminal.
Status Status `json:"status" api:"required"`
StepCount float64 `json:"stepCount" api:"required"`
UpdatedAt string `json:"updatedAt" api:"required"`
JSON activitySummaryJSON `json:"-"`
}
// activitySummaryJSON contains the JSON metadata for the struct [ActivitySummary]
type activitySummaryJSON struct {
ID apijson.Field
CompletedAt apijson.Field
CreatedAt apijson.Field
Goal apijson.Field
LatestActivity apijson.Field
MessageCount apijson.Field
Model apijson.Field
NextStep apijson.Field
ParentThreadID apijson.Field
Result apijson.Field
ScheduleID apijson.Field
Status apijson.Field
StepCount apijson.Field
UpdatedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ActivitySummary) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r activitySummaryJSON) RawJSON() string {
return r.raw
}
type CompiledContext struct {
EnabledTools []shared.ToolName `json:"enabledTools" api:"required,nullable"`
SystemPrompt string `json:"systemPrompt" api:"required,nullable"`
TurnID string `json:"turnId" api:"required,nullable"`
JSON compiledContextJSON `json:"-"`
}
// compiledContextJSON contains the JSON metadata for the struct [CompiledContext]
type compiledContextJSON struct {
EnabledTools apijson.Field
SystemPrompt apijson.Field
TurnID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CompiledContext) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r compiledContextJSON) RawJSON() string {
return r.raw
}
// Message content block. The `type` field distinguishes text, tool use, tool
// result, server tool use, and web search result blocks.
type ContentBlock struct {
Type ContentBlockType `json:"type" api:"required"`
ID string `json:"id"`
// This field can have the runtime type of [string], [interface{}].
Content interface{} `json:"content"`
DeniedByUser bool `json:"deniedByUser"`
// This field can have the runtime type of [interface{}].
Input interface{} `json:"input"`
IsError bool `json:"isError"`
Name shared.ToolName `json:"name"`
// This field can have the runtime type of [map[string]map[string]string].
ProviderMetadata interface{} `json:"providerMetadata"`
Text string `json:"text"`
ToolUseID string `json:"toolUseId"`
JSON contentBlockJSON `json:"-"`
union ContentBlockUnion
}
// contentBlockJSON contains the JSON metadata for the struct [ContentBlock]
type contentBlockJSON struct {
Type apijson.Field
ID apijson.Field
Content apijson.Field
DeniedByUser apijson.Field
Input apijson.Field
IsError apijson.Field
Name apijson.Field
ProviderMetadata apijson.Field
Text apijson.Field
ToolUseID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r contentBlockJSON) RawJSON() string {
return r.raw
}
func (r *ContentBlock) UnmarshalJSON(data []byte) (err error) {
*r = ContentBlock{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [ContentBlockUnion] interface which you can cast to the
// specific types for more type safety.
//
// Possible runtime types of the union are [ContentBlockTextContentBlock],
// [ContentBlockToolUseContentBlock], [ContentBlockToolResultContentBlock],
// [ContentBlockServerToolUseContentBlock],
// [ContentBlockWebSearchToolResultContentBlock].
func (r ContentBlock) AsUnion() ContentBlockUnion {
return r.union
}
// Message content block. The `type` field distinguishes text, tool use, tool
// result, server tool use, and web search result blocks.
//
// Union satisfied by [ContentBlockTextContentBlock],
// [ContentBlockToolUseContentBlock], [ContentBlockToolResultContentBlock],
// [ContentBlockServerToolUseContentBlock] or
// [ContentBlockWebSearchToolResultContentBlock].
type ContentBlockUnion interface {
implementsContentBlock()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*ContentBlockUnion)(nil)).Elem(),
"type",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ContentBlockTextContentBlock{}),
DiscriminatorValue: "text",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ContentBlockToolUseContentBlock{}),
DiscriminatorValue: "tool_use",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ContentBlockToolResultContentBlock{}),
DiscriminatorValue: "tool_result",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ContentBlockServerToolUseContentBlock{}),
DiscriminatorValue: "server_tool_use",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ContentBlockWebSearchToolResultContentBlock{}),
DiscriminatorValue: "web_search_tool_result",
},
)
}
type ContentBlockTextContentBlock struct {
Text string `json:"text" api:"required"`
Type ContentBlockTextContentBlockType `json:"type" api:"required"`
ProviderMetadata map[string]map[string]string `json:"providerMetadata"`
JSON contentBlockTextContentBlockJSON `json:"-"`
}
// contentBlockTextContentBlockJSON contains the JSON metadata for the struct
// [ContentBlockTextContentBlock]
type contentBlockTextContentBlockJSON struct {
Text apijson.Field
Type apijson.Field
ProviderMetadata apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ContentBlockTextContentBlock) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r contentBlockTextContentBlockJSON) RawJSON() string {
return r.raw
}
func (r ContentBlockTextContentBlock) implementsContentBlock() {}
type ContentBlockTextContentBlockType string
const (
ContentBlockTextContentBlockTypeText ContentBlockTextContentBlockType = "text"
)
func (r ContentBlockTextContentBlockType) IsKnown() bool {
switch r {
case ContentBlockTextContentBlockTypeText:
return true
}
return false
}
type ContentBlockToolUseContentBlock struct {
ID string `json:"id" api:"required"`
// Any JSON value. Generated SDKs may expose this value boundary as unknown or Any.
Input interface{} `json:"input" api:"required"`
Name shared.ToolName `json:"name" api:"required"`
Type ContentBlockToolUseContentBlockType `json:"type" api:"required"`
ProviderMetadata map[string]map[string]string `json:"providerMetadata"`
JSON contentBlockToolUseContentBlockJSON `json:"-"`
}
// contentBlockToolUseContentBlockJSON contains the JSON metadata for the struct
// [ContentBlockToolUseContentBlock]
type contentBlockToolUseContentBlockJSON struct {
ID apijson.Field
Input apijson.Field
Name apijson.Field
Type apijson.Field
ProviderMetadata apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ContentBlockToolUseContentBlock) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r contentBlockToolUseContentBlockJSON) RawJSON() string {
return r.raw
}
func (r ContentBlockToolUseContentBlock) implementsContentBlock() {}
type ContentBlockToolUseContentBlockType string
const (
ContentBlockToolUseContentBlockTypeToolUse ContentBlockToolUseContentBlockType = "tool_use"
)
func (r ContentBlockToolUseContentBlockType) IsKnown() bool {
switch r {
case ContentBlockToolUseContentBlockTypeToolUse:
return true
}
return false
}
type ContentBlockToolResultContentBlock struct {
Content string `json:"content" api:"required"`
IsError bool `json:"isError" api:"required"`
ToolUseID string `json:"toolUseId" api:"required"`
Type ContentBlockToolResultContentBlockType `json:"type" api:"required"`
DeniedByUser bool `json:"deniedByUser"`
ProviderMetadata map[string]map[string]string `json:"providerMetadata"`
JSON contentBlockToolResultContentBlockJSON `json:"-"`
}
// contentBlockToolResultContentBlockJSON contains the JSON metadata for the struct
// [ContentBlockToolResultContentBlock]
type contentBlockToolResultContentBlockJSON struct {
Content apijson.Field
IsError apijson.Field
ToolUseID apijson.Field
Type apijson.Field
DeniedByUser apijson.Field
ProviderMetadata apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ContentBlockToolResultContentBlock) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r contentBlockToolResultContentBlockJSON) RawJSON() string {
return r.raw
}
func (r ContentBlockToolResultContentBlock) implementsContentBlock() {}
type ContentBlockToolResultContentBlockType string
const (
ContentBlockToolResultContentBlockTypeToolResult ContentBlockToolResultContentBlockType = "tool_result"
)
func (r ContentBlockToolResultContentBlockType) IsKnown() bool {
switch r {
case ContentBlockToolResultContentBlockTypeToolResult:
return true
}
return false
}
type ContentBlockServerToolUseContentBlock struct {
ID string `json:"id" api:"required"`
// Any JSON value. Generated SDKs may expose this value boundary as unknown or Any.
Input interface{} `json:"input" api:"required"`
Name string `json:"name" api:"required"`
Type ContentBlockServerToolUseContentBlockType `json:"type" api:"required"`
ProviderMetadata map[string]map[string]string `json:"providerMetadata"`
JSON contentBlockServerToolUseContentBlockJSON `json:"-"`
}
// contentBlockServerToolUseContentBlockJSON contains the JSON metadata for the
// struct [ContentBlockServerToolUseContentBlock]
type contentBlockServerToolUseContentBlockJSON struct {
ID apijson.Field
Input apijson.Field
Name apijson.Field
Type apijson.Field
ProviderMetadata apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ContentBlockServerToolUseContentBlock) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r contentBlockServerToolUseContentBlockJSON) RawJSON() string {
return r.raw
}
func (r ContentBlockServerToolUseContentBlock) implementsContentBlock() {}
type ContentBlockServerToolUseContentBlockType string
const (
ContentBlockServerToolUseContentBlockTypeServerToolUse ContentBlockServerToolUseContentBlockType = "server_tool_use"
)
func (r ContentBlockServerToolUseContentBlockType) IsKnown() bool {
switch r {
case ContentBlockServerToolUseContentBlockTypeServerToolUse:
return true
}
return false
}
type ContentBlockWebSearchToolResultContentBlock struct {
// Web search result payload. The runtime returns either an array of web search
// results or an error object.
Content interface{} `json:"content" api:"required"`
ToolUseID string `json:"toolUseId" api:"required"`
Type ContentBlockWebSearchToolResultContentBlockType `json:"type" api:"required"`
JSON contentBlockWebSearchToolResultContentBlockJSON `json:"-"`
}
// contentBlockWebSearchToolResultContentBlockJSON contains the JSON metadata for
// the struct [ContentBlockWebSearchToolResultContentBlock]
type contentBlockWebSearchToolResultContentBlockJSON struct {
Content apijson.Field
ToolUseID apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ContentBlockWebSearchToolResultContentBlock) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r contentBlockWebSearchToolResultContentBlockJSON) RawJSON() string {
return r.raw
}
func (r ContentBlockWebSearchToolResultContentBlock) implementsContentBlock() {}
type ContentBlockWebSearchToolResultContentBlockType string
const (
ContentBlockWebSearchToolResultContentBlockTypeWebSearchToolResult ContentBlockWebSearchToolResultContentBlockType = "web_search_tool_result"
)
func (r ContentBlockWebSearchToolResultContentBlockType) IsKnown() bool {
switch r {
case ContentBlockWebSearchToolResultContentBlockTypeWebSearchToolResult:
return true
}
return false
}
type ContentBlockType string
const (
ContentBlockTypeText ContentBlockType = "text"
ContentBlockTypeToolUse ContentBlockType = "tool_use"
ContentBlockTypeToolResult ContentBlockType = "tool_result"
ContentBlockTypeServerToolUse ContentBlockType = "server_tool_use"
ContentBlockTypeWebSearchToolResult ContentBlockType = "web_search_tool_result"
)
func (r ContentBlockType) IsKnown() bool {
switch r {
case ContentBlockTypeText, ContentBlockTypeToolUse, ContentBlockTypeToolResult, ContentBlockTypeServerToolUse, ContentBlockTypeWebSearchToolResult:
return true
}
return false
}
type Message struct {
Content []ContentBlock `json:"content" api:"required"`
CreatedAt string `json:"createdAt" api:"required"`
Role MessageRole `json:"role" api:"required"`
Seq float64 `json:"seq" api:"required"`
JSON messageJSON `json:"-"`
}
// messageJSON contains the JSON metadata for the struct [Message]
type messageJSON struct {
Content apijson.Field
CreatedAt apijson.Field
Role apijson.Field
Seq apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Message) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r messageJSON) RawJSON() string {
return r.raw
}
type MessageRole string
const (
MessageRoleUser MessageRole = "user"
MessageRoleAssistant MessageRole = "assistant"
)
func (r MessageRole) IsKnown() bool {
switch r {
case MessageRoleUser, MessageRoleAssistant:
return true
}
return false
}
type MessagePage struct {
Cursor string `json:"cursor" api:"required,nullable"`
HasMore bool `json:"hasMore" api:"required"`
Messages []Message `json:"messages" api:"required"`
JSON messagePageJSON `json:"-"`
}
// messagePageJSON contains the JSON metadata for the struct [MessagePage]
type messagePageJSON struct {
Cursor apijson.Field
HasMore apijson.Field
Messages apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *MessagePage) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r messagePageJSON) RawJSON() string {
return r.raw
}
// `idle` threads can accept a new turn or be closed. `running` threads have an
// active turn. `awaiting` threads are paused on external input such as approvals.
// `closed` threads are terminal.
type Status string
const (
StatusIdle Status = "idle"
StatusRunning Status = "running"
StatusAwaiting Status = "awaiting"
StatusClosed Status = "closed"
)
func (r Status) IsKnown() bool {
switch r {
case StatusIdle, StatusRunning, StatusAwaiting, StatusClosed:
return true
}
return false
}
type SteerResult struct {
Status SteerResultStatus `json:"status" api:"required"`
// `idle` threads can accept a new turn or be closed. `running` threads have an
// active turn. `awaiting` threads are paused on external input such as approvals.
// `closed` threads are terminal.
ThreadStatus Status `json:"threadStatus" api:"required"`
TurnID string `json:"turnId" api:"required"`
JSON steerResultJSON `json:"-"`
}
// steerResultJSON contains the JSON metadata for the struct [SteerResult]
type steerResultJSON struct {
Status apijson.Field
ThreadStatus apijson.Field
TurnID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *SteerResult) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r steerResultJSON) RawJSON() string {
return r.raw
}
type SteerResultStatus string
const (
SteerResultStatusEnqueued SteerResultStatus = "enqueued"
SteerResultStatusTurnStarted SteerResultStatus = "turn_started"
)
func (r SteerResultStatus) IsKnown() bool {
switch r {
case SteerResultStatusEnqueued, SteerResultStatusTurnStarted:
return true
}
return false
}
type SubThreadSummary struct {
ID string `json:"id" api:"required"`
CompletedAt string `json:"completedAt" api:"required,nullable"`
CreatedAt string `json:"createdAt" api:"required"`
MessageCount float64 `json:"messageCount" api:"required"`
Model string `json:"model" api:"required"`
ParentThreadID string `json:"parentThreadId" api:"required,nullable"`
Result string `json:"result" api:"required,nullable"`
ScheduleID string `json:"scheduleId" api:"required,nullable"`
ScheduleSeq float64 `json:"scheduleSeq" api:"required,nullable"`
// `pending` means the parent thread is still waiting on this sub-thread. Other
// values are the child thread lifecycle state.
State SubThreadSummaryState `json:"state" api:"required"`
StepCount float64 `json:"stepCount" api:"required"`
ToolUseID string `json:"toolUseId" api:"required,nullable"`
JSON subThreadSummaryJSON `json:"-"`
}
// subThreadSummaryJSON contains the JSON metadata for the struct
// [SubThreadSummary]
type subThreadSummaryJSON struct {
ID apijson.Field
CompletedAt apijson.Field
CreatedAt apijson.Field
MessageCount apijson.Field
Model apijson.Field
ParentThreadID apijson.Field
Result apijson.Field
ScheduleID apijson.Field
ScheduleSeq apijson.Field
State apijson.Field
StepCount apijson.Field
ToolUseID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *SubThreadSummary) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r subThreadSummaryJSON) RawJSON() string {
return r.raw
}
// `pending` means the parent thread is still waiting on this sub-thread. Other
// values are the child thread lifecycle state.
type SubThreadSummaryState string
const (
SubThreadSummaryStatePending SubThreadSummaryState = "pending"
SubThreadSummaryStateIdle SubThreadSummaryState = "idle"
SubThreadSummaryStateRunning SubThreadSummaryState = "running"
SubThreadSummaryStateAwaiting SubThreadSummaryState = "awaiting"
SubThreadSummaryStateClosed SubThreadSummaryState = "closed"
)
func (r SubThreadSummaryState) IsKnown() bool {
switch r {
case SubThreadSummaryStatePending, SubThreadSummaryStateIdle, SubThreadSummaryStateRunning, SubThreadSummaryStateAwaiting, SubThreadSummaryStateClosed:
return true
}
return false
}
type Thread struct {
ID string `json:"id" api:"required"`
AgentID string `json:"agentId" api:"required"`
CompiledContext CompiledContext `json:"compiledContext" api:"required,nullable"`
CompletedAt string `json:"completedAt" api:"required,nullable"`
CreatedAt string `json:"createdAt" api:"required"`
Depth float64 `json:"depth" api:"required"`
Error string `json:"error" api:"required,nullable"`
HasMoreMessages bool `json:"hasMoreMessages" api:"required"`
Instructions string `json:"instructions" api:"required,nullable"`
LastTurnStatus ThreadLastTurnStatus `json:"lastTurnStatus" api:"required,nullable"`
Message string `json:"message" api:"required"`
MessageCursor float64 `json:"messageCursor" api:"required,nullable"`
Messages []Message `json:"messages" api:"required"`
Model string `json:"model" api:"required"`
ParentThreadID string `json:"parentThreadId" api:"required,nullable"`
Result string `json:"result" api:"required,nullable"`
ScheduleID string `json:"scheduleId" api:"required,nullable"`
ScheduleSeq float64 `json:"scheduleSeq" api:"required,nullable"`
// `idle` threads can accept a new turn or be closed. `running` threads have an
// active turn. `awaiting` threads are paused on external input such as approvals.
// `closed` threads are terminal.
Status Status `json:"status" api:"required"`
SubThreads []SubThreadSummary `json:"subThreads" api:"required"`
Tools []shared.ToolName `json:"tools" api:"required"`
Turns []Turn `json:"turns" api:"required"`
UpdatedAt string `json:"updatedAt" api:"required"`
ExternalToolNamespaces ThreadExternalToolNamespacesUnion `json:"externalToolNamespaces"`
JSON threadJSON `json:"-"`
}
// threadJSON contains the JSON metadata for the struct [Thread]
type threadJSON struct {
ID apijson.Field
AgentID apijson.Field
CompiledContext apijson.Field
CompletedAt apijson.Field
CreatedAt apijson.Field
Depth apijson.Field
Error apijson.Field
HasMoreMessages apijson.Field
Instructions apijson.Field
LastTurnStatus apijson.Field
Message apijson.Field
MessageCursor apijson.Field
Messages apijson.Field
Model apijson.Field
ParentThreadID apijson.Field
Result apijson.Field
ScheduleID apijson.Field
ScheduleSeq apijson.Field
Status apijson.Field
SubThreads apijson.Field
Tools apijson.Field
Turns apijson.Field
UpdatedAt apijson.Field
ExternalToolNamespaces apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Thread) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r threadJSON) RawJSON() string {
return r.raw
}
type ThreadLastTurnStatus string
const (
ThreadLastTurnStatusCompleted ThreadLastTurnStatus = "completed"
ThreadLastTurnStatusFailed ThreadLastTurnStatus = "failed"
)
func (r ThreadLastTurnStatus) IsKnown() bool {
switch r {
case ThreadLastTurnStatusCompleted, ThreadLastTurnStatusFailed:
return true
}
return false
}
// Union satisfied by [ThreadExternalToolNamespacesString] or
// [ThreadExternalToolNamespacesArray].
type ThreadExternalToolNamespacesUnion interface {
implementsThreadExternalToolNamespacesUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*ThreadExternalToolNamespacesUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(ThreadExternalToolNamespacesString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ThreadExternalToolNamespacesArray{}),
},
)
}
type ThreadExternalToolNamespacesString string
const (
ThreadExternalToolNamespacesStringAll ThreadExternalToolNamespacesString = "all"
)
func (r ThreadExternalToolNamespacesString) IsKnown() bool {
switch r {
case ThreadExternalToolNamespacesStringAll:
return true
}
return false
}
func (r ThreadExternalToolNamespacesString) implementsThreadExternalToolNamespacesUnion() {}
type ThreadExternalToolNamespacesArray []string
func (r ThreadExternalToolNamespacesArray) implementsThreadExternalToolNamespacesUnion() {}
type ThreadSummary struct {
ID string `json:"id" api:"required"`
CompletedAt string `json:"completedAt" api:"required,nullable"`
CreatedAt string `json:"createdAt" api:"required"`
MessageCount float64 `json:"messageCount" api:"required"`
Model string `json:"model" api:"required"`
ParentThreadID string `json:"parentThreadId" api:"required,nullable"`
Result string `json:"result" api:"required,nullable"`
ScheduleID string `json:"scheduleId" api:"required,nullable"`
ScheduleSeq float64 `json:"scheduleSeq" api:"required,nullable"`
// `idle` threads can accept a new turn or be closed. `running` threads have an
// active turn. `awaiting` threads are paused on external input such as approvals.