-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathagent.go
More file actions
2127 lines (1898 loc) · 83.1 KB
/
agent.go
File metadata and controls
2127 lines (1898 loc) · 83.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 gitpod
import (
"context"
"net/http"
"net/url"
"slices"
"time"
"github.com/gitpod-io/gitpod-sdk-go/internal/apijson"
"github.com/gitpod-io/gitpod-sdk-go/internal/apiquery"
"github.com/gitpod-io/gitpod-sdk-go/internal/param"
"github.com/gitpod-io/gitpod-sdk-go/internal/requestconfig"
"github.com/gitpod-io/gitpod-sdk-go/option"
"github.com/gitpod-io/gitpod-sdk-go/packages/pagination"
"github.com/gitpod-io/gitpod-sdk-go/shared"
)
// AgentService contains methods and other services that help with interacting with
// the gitpod 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 [NewAgentService] method instead.
type AgentService struct {
Options []option.RequestOption
}
// NewAgentService 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 NewAgentService(opts ...option.RequestOption) (r *AgentService) {
r = &AgentService{}
r.Options = opts
return
}
// Creates a token for conversation access with a specific agent run.
//
// This method generates a temporary token that can be used to securely connect to
// an ongoing agent conversation, for example in a web UI.
//
// ### Examples
//
// - Create a token to join an agent run conversation in a front-end application:
//
// ```yaml
// agentExecutionId: "6fa1a3c7-fbb7-49d1-ba56-1890dc7c4c35"
// ```
func (r *AgentService) NewExecutionConversationToken(ctx context.Context, body AgentNewExecutionConversationTokenParams, opts ...option.RequestOption) (res *AgentNewExecutionConversationTokenResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "gitpod.v1.AgentService/CreateAgentExecutionConversationToken"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Creates a new prompt.
//
// Use this method to:
//
// - Define new prompts for templates or commands
// - Set up organization-wide prompt libraries
func (r *AgentService) NewPrompt(ctx context.Context, body AgentNewPromptParams, opts ...option.RequestOption) (res *AgentNewPromptResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "gitpod.v1.AgentService/CreatePrompt"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Deletes an agent run.
//
// Use this method to:
//
// - Clean up agent runs that are no longer needed
//
// ### Examples
//
// - Delete an agent run by ID:
//
// ```yaml
// agentExecutionId: "6fa1a3c7-fbb7-49d1-ba56-1890dc7c4c35"
// ```
func (r *AgentService) DeleteExecution(ctx context.Context, body AgentDeleteExecutionParams, opts ...option.RequestOption) (res *AgentDeleteExecutionResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "gitpod.v1.AgentService/DeleteAgentExecution"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Deletes a prompt.
//
// Use this method to:
//
// - Remove unused prompts
func (r *AgentService) DeletePrompt(ctx context.Context, body AgentDeletePromptParams, opts ...option.RequestOption) (res *AgentDeletePromptResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "gitpod.v1.AgentService/DeletePrompt"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Lists all agent runs matching the specified filter.
//
// Use this method to track multiple agent runs and their associated resources.
// Results are ordered by their creation time with the newest first.
//
// ### Examples
//
// - List agent runs by agent ID:
//
// ```yaml
// filter:
// agentIds: ["b8a64cfa-43e2-4b9d-9fb3-07edc63f5971"]
// pagination:
// pageSize: 10
// ```
func (r *AgentService) ListExecutions(ctx context.Context, params AgentListExecutionsParams, opts ...option.RequestOption) (res *pagination.AgentExecutionsPage[AgentExecution], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "gitpod.v1.AgentService/ListAgentExecutions"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, params, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Lists all agent runs matching the specified filter.
//
// Use this method to track multiple agent runs and their associated resources.
// Results are ordered by their creation time with the newest first.
//
// ### Examples
//
// - List agent runs by agent ID:
//
// ```yaml
// filter:
// agentIds: ["b8a64cfa-43e2-4b9d-9fb3-07edc63f5971"]
// pagination:
// pageSize: 10
// ```
func (r *AgentService) ListExecutionsAutoPaging(ctx context.Context, params AgentListExecutionsParams, opts ...option.RequestOption) *pagination.AgentExecutionsPageAutoPager[AgentExecution] {
return pagination.NewAgentExecutionsPageAutoPager(r.ListExecutions(ctx, params, opts...))
}
// Lists all prompts matching the specified criteria.
//
// Use this method to find and browse prompts across your organization. Results are
// ordered by their creation time with the newest first.
//
// ### Examples
//
// - List all prompts:
//
// Retrieves all prompts with pagination.
//
// ```yaml
// pagination:
// pageSize: 10
// ```
func (r *AgentService) ListPrompts(ctx context.Context, params AgentListPromptsParams, opts ...option.RequestOption) (res *pagination.PromptsPage[Prompt], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "gitpod.v1.AgentService/ListPrompts"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, params, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Lists all prompts matching the specified criteria.
//
// Use this method to find and browse prompts across your organization. Results are
// ordered by their creation time with the newest first.
//
// ### Examples
//
// - List all prompts:
//
// Retrieves all prompts with pagination.
//
// ```yaml
// pagination:
// pageSize: 10
// ```
func (r *AgentService) ListPromptsAutoPaging(ctx context.Context, params AgentListPromptsParams, opts ...option.RequestOption) *pagination.PromptsPageAutoPager[Prompt] {
return pagination.NewPromptsPageAutoPager(r.ListPrompts(ctx, params, opts...))
}
// Gets details about a specific agent run, including its metadata, specification,
// and status (phase, error messages, and usage statistics).
//
// Use this method to:
//
// - Monitor the run's progress
// - Retrieve the agent's conversation URL
// - Check if an agent run is actively producing output
//
// ### Examples
//
// - Get agent run details by ID:
//
// ```yaml
// agentExecutionId: "6fa1a3c7-fbb7-49d1-ba56-1890dc7c4c35"
// ```
func (r *AgentService) GetExecution(ctx context.Context, body AgentGetExecutionParams, opts ...option.RequestOption) (res *AgentGetExecutionResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "gitpod.v1.AgentService/GetAgentExecution"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Gets details about a specific prompt including name, description, and prompt
// content.
//
// Use this method to:
//
// - Retrieve prompt details for editing
// - Get prompt content for execution
//
// ### Examples
//
// - Get prompt details:
//
// ```yaml
// promptId: "07e03a28-65a5-4d98-b532-8ea67b188048"
// ```
func (r *AgentService) GetPrompt(ctx context.Context, body AgentGetPromptParams, opts ...option.RequestOption) (res *AgentGetPromptResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "gitpod.v1.AgentService/GetPrompt"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Sends user input to an active agent run.
//
// This method is used to provide interactive or conversation-based input to an
// agent. The agent can respond with output blocks containing text, file changes,
// or tool usage requests.
//
// ### Examples
//
// - Send a text message to an agent:
//
// ```yaml
// agentExecutionId: "6fa1a3c7-fbb7-49d1-ba56-1890dc7c4c35"
// userInput:
// text:
// content: "Generate a report based on the latest logs."
// ```
func (r *AgentService) SendToExecution(ctx context.Context, body AgentSendToExecutionParams, opts ...option.RequestOption) (res *AgentSendToExecutionResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "gitpod.v1.AgentService/SendToAgentExecution"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Starts (or triggers) an agent run using a provided agent.
//
// Use this method to:
//
// - Launch an agent based on a known agent
//
// ### Examples
//
// - Start an agent with a project ID:
//
// ```yaml
// agentId: "b8a64cfa-43e2-4b9d-9fb3-07edc63f5971"
// codeContext:
// projectId: "2d22e4eb-31da-467f-882c-27e21550992f"
// ```
func (r *AgentService) StartExecution(ctx context.Context, body AgentStartExecutionParams, opts ...option.RequestOption) (res *AgentStartExecutionResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "gitpod.v1.AgentService/StartAgent"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Stops an active agent execution.
//
// Use this method to:
//
// - Stop an agent that is currently running
// - Prevent further processing or resource usage
//
// ### Examples
//
// - Stop an agent execution by ID:
//
// ```yaml
// agentExecutionId: "6fa1a3c7-fbb7-49d1-ba56-1890dc7c4c35"
// ```
func (r *AgentService) StopExecution(ctx context.Context, body AgentStopExecutionParams, opts ...option.RequestOption) (res *AgentStopExecutionResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "gitpod.v1.AgentService/StopAgentExecution"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Updates an existing prompt.
//
// Use this method to:
//
// - Modify prompt content or metadata
// - Change prompt type (template/command)
func (r *AgentService) UpdatePrompt(ctx context.Context, body AgentUpdatePromptParams, opts ...option.RequestOption) (res *AgentUpdatePromptResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "gitpod.v1.AgentService/UpdatePrompt"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
type AgentCodeContext struct {
ContextURL AgentCodeContextContextURL `json:"contextUrl"`
EnvironmentID string `json:"environmentId" format:"uuid"`
ProjectID string `json:"projectId" format:"uuid"`
// Pull request context - optional metadata about the PR being worked on This is
// populated when the agent execution is triggered by a PR workflow or when
// explicitly provided through the browser extension
PullRequest AgentCodeContextPullRequest `json:"pullRequest" api:"nullable"`
JSON agentCodeContextJSON `json:"-"`
}
// agentCodeContextJSON contains the JSON metadata for the struct
// [AgentCodeContext]
type agentCodeContextJSON struct {
ContextURL apijson.Field
EnvironmentID apijson.Field
ProjectID apijson.Field
PullRequest apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentCodeContext) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentCodeContextJSON) RawJSON() string {
return r.raw
}
type AgentCodeContextContextURL struct {
EnvironmentClassID string `json:"environmentClassId" format:"uuid"`
URL string `json:"url" format:"uri"`
JSON agentCodeContextContextURLJSON `json:"-"`
}
// agentCodeContextContextURLJSON contains the JSON metadata for the struct
// [AgentCodeContextContextURL]
type agentCodeContextContextURLJSON struct {
EnvironmentClassID apijson.Field
URL apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentCodeContextContextURL) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentCodeContextContextURLJSON) RawJSON() string {
return r.raw
}
// Pull request context - optional metadata about the PR being worked on This is
// populated when the agent execution is triggered by a PR workflow or when
// explicitly provided through the browser extension
type AgentCodeContextPullRequest struct {
// Unique identifier from the source system (e.g., "123" for GitHub PR #123)
ID string `json:"id"`
// Author name as provided by the SCM system
Author string `json:"author"`
// Whether this is a draft pull request
Draft bool `json:"draft"`
// Source branch name (the branch being merged from)
FromBranch string `json:"fromBranch"`
// Repository information
Repository AgentCodeContextPullRequestRepository `json:"repository"`
// Current state of the pull request
State shared.State `json:"state"`
// Pull request title
Title string `json:"title"`
// Target branch name (the branch being merged into)
ToBranch string `json:"toBranch"`
// Pull request URL (e.g., "https://github.com/owner/repo/pull/123")
URL string `json:"url"`
JSON agentCodeContextPullRequestJSON `json:"-"`
}
// agentCodeContextPullRequestJSON contains the JSON metadata for the struct
// [AgentCodeContextPullRequest]
type agentCodeContextPullRequestJSON struct {
ID apijson.Field
Author apijson.Field
Draft apijson.Field
FromBranch apijson.Field
Repository apijson.Field
State apijson.Field
Title apijson.Field
ToBranch apijson.Field
URL apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentCodeContextPullRequest) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentCodeContextPullRequestJSON) RawJSON() string {
return r.raw
}
// Repository information
type AgentCodeContextPullRequestRepository struct {
CloneURL string `json:"cloneUrl"`
Host string `json:"host"`
Name string `json:"name"`
Owner string `json:"owner"`
JSON agentCodeContextPullRequestRepositoryJSON `json:"-"`
}
// agentCodeContextPullRequestRepositoryJSON contains the JSON metadata for the
// struct [AgentCodeContextPullRequestRepository]
type agentCodeContextPullRequestRepositoryJSON struct {
CloneURL apijson.Field
Host apijson.Field
Name apijson.Field
Owner apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentCodeContextPullRequestRepository) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentCodeContextPullRequestRepositoryJSON) RawJSON() string {
return r.raw
}
type AgentCodeContextParam struct {
ContextURL param.Field[AgentCodeContextContextURLParam] `json:"contextUrl"`
EnvironmentID param.Field[string] `json:"environmentId" format:"uuid"`
ProjectID param.Field[string] `json:"projectId" format:"uuid"`
// Pull request context - optional metadata about the PR being worked on This is
// populated when the agent execution is triggered by a PR workflow or when
// explicitly provided through the browser extension
PullRequest param.Field[AgentCodeContextPullRequestParam] `json:"pullRequest"`
}
func (r AgentCodeContextParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type AgentCodeContextContextURLParam struct {
EnvironmentClassID param.Field[string] `json:"environmentClassId" format:"uuid"`
URL param.Field[string] `json:"url" format:"uri"`
}
func (r AgentCodeContextContextURLParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Pull request context - optional metadata about the PR being worked on This is
// populated when the agent execution is triggered by a PR workflow or when
// explicitly provided through the browser extension
type AgentCodeContextPullRequestParam struct {
// Unique identifier from the source system (e.g., "123" for GitHub PR #123)
ID param.Field[string] `json:"id"`
// Author name as provided by the SCM system
Author param.Field[string] `json:"author"`
// Whether this is a draft pull request
Draft param.Field[bool] `json:"draft"`
// Source branch name (the branch being merged from)
FromBranch param.Field[string] `json:"fromBranch"`
// Repository information
Repository param.Field[AgentCodeContextPullRequestRepositoryParam] `json:"repository"`
// Current state of the pull request
State param.Field[shared.State] `json:"state"`
// Pull request title
Title param.Field[string] `json:"title"`
// Target branch name (the branch being merged into)
ToBranch param.Field[string] `json:"toBranch"`
// Pull request URL (e.g., "https://github.com/owner/repo/pull/123")
URL param.Field[string] `json:"url"`
}
func (r AgentCodeContextPullRequestParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Repository information
type AgentCodeContextPullRequestRepositoryParam struct {
CloneURL param.Field[string] `json:"cloneUrl"`
Host param.Field[string] `json:"host"`
Name param.Field[string] `json:"name"`
Owner param.Field[string] `json:"owner"`
}
func (r AgentCodeContextPullRequestRepositoryParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type AgentExecution struct {
// ID is a unique identifier of this agent run. No other agent run with the same
// name must be managed by this agent manager
ID string `json:"id"`
// Metadata is data associated with this agent that's required for other parts of
// Gitpod to function
Metadata AgentExecutionMetadata `json:"metadata"`
// Spec is the configuration of the agent that's required for the runner to start
// the agent
Spec AgentExecutionSpec `json:"spec"`
// Status is the current status of the agent
Status AgentExecutionStatus `json:"status"`
JSON agentExecutionJSON `json:"-"`
}
// agentExecutionJSON contains the JSON metadata for the struct [AgentExecution]
type agentExecutionJSON struct {
ID apijson.Field
Metadata apijson.Field
Spec apijson.Field
Status apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentExecution) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentExecutionJSON) RawJSON() string {
return r.raw
}
// Metadata is data associated with this agent that's required for other parts of
// Gitpod to function
type AgentExecutionMetadata struct {
// annotations are key-value pairs for tracking external context.
Annotations map[string]string `json:"annotations"`
// A Timestamp represents a point in time independent of any time zone or local
// calendar, encoded as a count of seconds and fractions of seconds at nanosecond
// resolution. The count is relative to an epoch at UTC midnight on January 1,
// 1970, in the proleptic Gregorian calendar which extends the Gregorian calendar
// backwards to year one.
//
// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
// second table is needed for interpretation, using a
// [24-hour linear smear](https://developers.google.com/time/smear).
//
// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
// restricting to that range, we ensure that we can convert to and from
// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
//
// # Examples
//
// Example 1: Compute Timestamp from POSIX `time()`.
//
// Timestamp timestamp;
// timestamp.set_seconds(time(NULL));
// timestamp.set_nanos(0);
//
// Example 2: Compute Timestamp from POSIX `gettimeofday()`.
//
// struct timeval tv;
// gettimeofday(&tv, NULL);
//
// Timestamp timestamp;
// timestamp.set_seconds(tv.tv_sec);
// timestamp.set_nanos(tv.tv_usec * 1000);
//
// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
//
// FILETIME ft;
// GetSystemTimeAsFileTime(&ft);
// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
//
// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
// Timestamp timestamp;
// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
//
// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
//
// long millis = System.currentTimeMillis();
//
// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
// .setNanos((int) ((millis % 1000) * 1000000)).build();
//
// Example 5: Compute Timestamp from Java `Instant.now()`.
//
// Instant now = Instant.now();
//
// Timestamp timestamp =
// Timestamp.newBuilder().setSeconds(now.getEpochSecond())
// .setNanos(now.getNano()).build();
//
// Example 6: Compute Timestamp from current time in Python.
//
// timestamp = Timestamp()
// timestamp.GetCurrentTime()
//
// # JSON Mapping
//
// In JSON format, the Timestamp type is encoded as a string in the
// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the format is
// "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" where {year} is always
// expressed using four digits while {month}, {day}, {hour}, {min}, and {sec} are
// zero-padded to two digits each. The fractional seconds, which can go up to 9
// digits (i.e. up to 1 nanosecond resolution), are optional. The "Z" suffix
// indicates the timezone ("UTC"); the timezone is required. A proto3 JSON
// serializer should always use UTC (as indicated by "Z") when printing the
// Timestamp type and a proto3 JSON parser should be able to accept both UTC and
// other timezones (as indicated by an offset).
//
// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past 01:30 UTC on
// January 15, 2017.
//
// In JavaScript, one can convert a Date object to this format using the standard
// [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
// method. In Python, a standard `datetime.datetime` object can be converted to
// this format using
// [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with the
// time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use the
// Joda Time's
// [`ISODateTimeFormat.dateTime()`](<http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()>)
// to obtain a formatter capable of generating timestamps in this format.
CreatedAt time.Time `json:"createdAt" format:"date-time"`
Creator shared.Subject `json:"creator"`
Description string `json:"description"`
Name string `json:"name"`
// role is the role of the agent execution
Role AgentExecutionMetadataRole `json:"role"`
// A Timestamp represents a point in time independent of any time zone or local
// calendar, encoded as a count of seconds and fractions of seconds at nanosecond
// resolution. The count is relative to an epoch at UTC midnight on January 1,
// 1970, in the proleptic Gregorian calendar which extends the Gregorian calendar
// backwards to year one.
//
// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
// second table is needed for interpretation, using a
// [24-hour linear smear](https://developers.google.com/time/smear).
//
// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
// restricting to that range, we ensure that we can convert to and from
// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
//
// # Examples
//
// Example 1: Compute Timestamp from POSIX `time()`.
//
// Timestamp timestamp;
// timestamp.set_seconds(time(NULL));
// timestamp.set_nanos(0);
//
// Example 2: Compute Timestamp from POSIX `gettimeofday()`.
//
// struct timeval tv;
// gettimeofday(&tv, NULL);
//
// Timestamp timestamp;
// timestamp.set_seconds(tv.tv_sec);
// timestamp.set_nanos(tv.tv_usec * 1000);
//
// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
//
// FILETIME ft;
// GetSystemTimeAsFileTime(&ft);
// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
//
// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
// Timestamp timestamp;
// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
//
// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
//
// long millis = System.currentTimeMillis();
//
// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
// .setNanos((int) ((millis % 1000) * 1000000)).build();
//
// Example 5: Compute Timestamp from Java `Instant.now()`.
//
// Instant now = Instant.now();
//
// Timestamp timestamp =
// Timestamp.newBuilder().setSeconds(now.getEpochSecond())
// .setNanos(now.getNano()).build();
//
// Example 6: Compute Timestamp from current time in Python.
//
// timestamp = Timestamp()
// timestamp.GetCurrentTime()
//
// # JSON Mapping
//
// In JSON format, the Timestamp type is encoded as a string in the
// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the format is
// "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" where {year} is always
// expressed using four digits while {month}, {day}, {hour}, {min}, and {sec} are
// zero-padded to two digits each. The fractional seconds, which can go up to 9
// digits (i.e. up to 1 nanosecond resolution), are optional. The "Z" suffix
// indicates the timezone ("UTC"); the timezone is required. A proto3 JSON
// serializer should always use UTC (as indicated by "Z") when printing the
// Timestamp type and a proto3 JSON parser should be able to accept both UTC and
// other timezones (as indicated by an offset).
//
// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past 01:30 UTC on
// January 15, 2017.
//
// In JavaScript, one can convert a Date object to this format using the standard
// [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
// method. In Python, a standard `datetime.datetime` object can be converted to
// this format using
// [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with the
// time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use the
// Joda Time's
// [`ISODateTimeFormat.dateTime()`](<http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()>)
// to obtain a formatter capable of generating timestamps in this format.
UpdatedAt time.Time `json:"updatedAt" format:"date-time"`
// workflow_action_id is set when this agent execution was created as part of a
// workflow. Used to correlate agent executions with their parent workflow
// execution action.
WorkflowActionID string `json:"workflowActionId" api:"nullable" format:"uuid"`
JSON agentExecutionMetadataJSON `json:"-"`
}
// agentExecutionMetadataJSON contains the JSON metadata for the struct
// [AgentExecutionMetadata]
type agentExecutionMetadataJSON struct {
Annotations apijson.Field
CreatedAt apijson.Field
Creator apijson.Field
Description apijson.Field
Name apijson.Field
Role apijson.Field
UpdatedAt apijson.Field
WorkflowActionID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentExecutionMetadata) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentExecutionMetadataJSON) RawJSON() string {
return r.raw
}
// role is the role of the agent execution
type AgentExecutionMetadataRole string
const (
AgentExecutionMetadataRoleAgentExecutionRoleUnspecified AgentExecutionMetadataRole = "AGENT_EXECUTION_ROLE_UNSPECIFIED"
AgentExecutionMetadataRoleAgentExecutionRoleDefault AgentExecutionMetadataRole = "AGENT_EXECUTION_ROLE_DEFAULT"
AgentExecutionMetadataRoleAgentExecutionRoleWorkflow AgentExecutionMetadataRole = "AGENT_EXECUTION_ROLE_WORKFLOW"
)
func (r AgentExecutionMetadataRole) IsKnown() bool {
switch r {
case AgentExecutionMetadataRoleAgentExecutionRoleUnspecified, AgentExecutionMetadataRoleAgentExecutionRoleDefault, AgentExecutionMetadataRoleAgentExecutionRoleWorkflow:
return true
}
return false
}
// Spec is the configuration of the agent that's required for the runner to start
// the agent
type AgentExecutionSpec struct {
AgentID string `json:"agentId" format:"uuid"`
CodeContext AgentCodeContext `json:"codeContext"`
// desired_phase is the desired phase of the agent run
DesiredPhase AgentExecutionSpecDesiredPhase `json:"desiredPhase"`
Limits AgentExecutionSpecLimits `json:"limits"`
LoopConditions []AgentExecutionSpecLoopCondition `json:"loopConditions"`
Session string `json:"session"`
// version of the spec. The value of this field has no semantic meaning (e.g. don't
// interpret it as as a timestamp), but it can be used to impose a partial order.
// If a.spec_version < b.spec_version then a was the spec before b.
SpecVersion string `json:"specVersion"`
JSON agentExecutionSpecJSON `json:"-"`
}
// agentExecutionSpecJSON contains the JSON metadata for the struct
// [AgentExecutionSpec]
type agentExecutionSpecJSON struct {
AgentID apijson.Field
CodeContext apijson.Field
DesiredPhase apijson.Field
Limits apijson.Field
LoopConditions apijson.Field
Session apijson.Field
SpecVersion apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentExecutionSpec) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentExecutionSpecJSON) RawJSON() string {
return r.raw
}
// desired_phase is the desired phase of the agent run
type AgentExecutionSpecDesiredPhase string
const (
AgentExecutionSpecDesiredPhasePhaseUnspecified AgentExecutionSpecDesiredPhase = "PHASE_UNSPECIFIED"
AgentExecutionSpecDesiredPhasePhasePending AgentExecutionSpecDesiredPhase = "PHASE_PENDING"
AgentExecutionSpecDesiredPhasePhaseRunning AgentExecutionSpecDesiredPhase = "PHASE_RUNNING"
AgentExecutionSpecDesiredPhasePhaseWaitingForInput AgentExecutionSpecDesiredPhase = "PHASE_WAITING_FOR_INPUT"
AgentExecutionSpecDesiredPhasePhaseStopped AgentExecutionSpecDesiredPhase = "PHASE_STOPPED"
)
func (r AgentExecutionSpecDesiredPhase) IsKnown() bool {
switch r {
case AgentExecutionSpecDesiredPhasePhaseUnspecified, AgentExecutionSpecDesiredPhasePhasePending, AgentExecutionSpecDesiredPhasePhaseRunning, AgentExecutionSpecDesiredPhasePhaseWaitingForInput, AgentExecutionSpecDesiredPhasePhaseStopped:
return true
}
return false
}
type AgentExecutionSpecLimits struct {
MaxInputTokens string `json:"maxInputTokens"`
MaxIterations string `json:"maxIterations"`
MaxOutputTokens string `json:"maxOutputTokens"`
JSON agentExecutionSpecLimitsJSON `json:"-"`
}
// agentExecutionSpecLimitsJSON contains the JSON metadata for the struct
// [AgentExecutionSpecLimits]
type agentExecutionSpecLimitsJSON struct {
MaxInputTokens apijson.Field
MaxIterations apijson.Field
MaxOutputTokens apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentExecutionSpecLimits) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentExecutionSpecLimitsJSON) RawJSON() string {
return r.raw
}
type AgentExecutionSpecLoopCondition struct {
ID string `json:"id"`
Description string `json:"description"`
Expression string `json:"expression"`
JSON agentExecutionSpecLoopConditionJSON `json:"-"`
}
// agentExecutionSpecLoopConditionJSON contains the JSON metadata for the struct
// [AgentExecutionSpecLoopCondition]
type agentExecutionSpecLoopConditionJSON struct {
ID apijson.Field
Description apijson.Field
Expression apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentExecutionSpecLoopCondition) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentExecutionSpecLoopConditionJSON) RawJSON() string {
return r.raw
}
// Status is the current status of the agent
type AgentExecutionStatus struct {
CachedCreationTokensUsed string `json:"cachedCreationTokensUsed"`
CachedInputTokensUsed string `json:"cachedInputTokensUsed"`
ContextWindowLength string `json:"contextWindowLength"`
// conversation_url is the URL to the conversation (all messages exchanged between
// the agent and the user) of the agent run.
ConversationURL string `json:"conversationUrl"`
// current_activity is the current activity description of the agent execution.
CurrentActivity string `json:"currentActivity"`
// current_operation is the current operation of the agent execution.
CurrentOperation AgentExecutionStatusCurrentOperation `json:"currentOperation"`
// failure_message contains the reason the agent run failed to operate.
FailureMessage string `json:"failureMessage"`
// failure_reason contains a structured reason code for the failure.
FailureReason AgentExecutionStatusFailureReason `json:"failureReason"`
InputTokensUsed string `json:"inputTokensUsed"`
Iterations string `json:"iterations"`
// judgement is the judgement of the agent run produced by the judgement prompt.
Judgement string `json:"judgement"`
// mcp_integration_statuses contains the status of all MCP integrations used by
// this agent execution
McpIntegrationStatuses []AgentExecutionStatusMcpIntegrationStatus `json:"mcpIntegrationStatuses"`
// mode is the current operational mode of the agent execution. This is set by the
// agent when entering different modes (e.g., Ralph mode via /ona:ralph command).
Mode AgentMode `json:"mode"`
// outputs is a map of key-value pairs that can be set by the agent during
// execution. Similar to task execution outputs, but with typed values for
// structured data.
Outputs map[string]AgentExecutionStatusOutput `json:"outputs"`
OutputTokensUsed string `json:"outputTokensUsed"`
Phase AgentExecutionStatusPhase `json:"phase"`
Session string `json:"session"`
// version of the status. The value of this field has no semantic meaning (e.g.
// don't interpret it as as a timestamp), but it can be used to impose a partial
// order. If a.status_version < b.status_version then a was the status before b.
StatusVersion string `json:"statusVersion"`
// supported_model is the LLM model being used by the agent execution.
SupportedModel AgentExecutionStatusSupportedModel `json:"supportedModel"`
// transcript_url is the URL to the LLM transcript (all messages exchanged between
// the agent and the LLM) of the agent run.
TranscriptURL string `json:"transcriptUrl"`
// used_environments is the list of environments that were used by the agent
// execution.
UsedEnvironments []AgentExecutionStatusUsedEnvironment `json:"usedEnvironments"`
// warning_message contains warnings, e.g. when the LLM is overloaded.
WarningMessage string `json:"warningMessage"`
JSON agentExecutionStatusJSON `json:"-"`
}
// agentExecutionStatusJSON contains the JSON metadata for the struct
// [AgentExecutionStatus]
type agentExecutionStatusJSON struct {
CachedCreationTokensUsed apijson.Field
CachedInputTokensUsed apijson.Field
ContextWindowLength apijson.Field
ConversationURL apijson.Field
CurrentActivity apijson.Field
CurrentOperation apijson.Field
FailureMessage apijson.Field
FailureReason apijson.Field
InputTokensUsed apijson.Field
Iterations apijson.Field
Judgement apijson.Field
McpIntegrationStatuses apijson.Field
Mode apijson.Field
Outputs apijson.Field
OutputTokensUsed apijson.Field
Phase apijson.Field
Session apijson.Field
StatusVersion apijson.Field
SupportedModel apijson.Field
TranscriptURL apijson.Field
UsedEnvironments apijson.Field
WarningMessage apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentExecutionStatus) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentExecutionStatusJSON) RawJSON() string {
return r.raw
}
// current_operation is the current operation of the agent execution.
type AgentExecutionStatusCurrentOperation struct {
Llm AgentExecutionStatusCurrentOperationLlm `json:"llm"`
// retries is the number of times the agent run has retried one or more steps
Retries string `json:"retries"`
Session string `json:"session"`
ToolUse AgentExecutionStatusCurrentOperationToolUse `json:"toolUse"`
JSON agentExecutionStatusCurrentOperationJSON `json:"-"`
}
// agentExecutionStatusCurrentOperationJSON contains the JSON metadata for the
// struct [AgentExecutionStatusCurrentOperation]
type agentExecutionStatusCurrentOperationJSON struct {
Llm apijson.Field
Retries apijson.Field