-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbash.go
More file actions
1592 lines (1384 loc) · 48.7 KB
/
bash.go
File metadata and controls
1592 lines (1384 loc) · 48.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
// Code generated by Fern. DO NOT EDIT.
package api
import (
json "encoding/json"
fmt "fmt"
internal "github.com/agent-infra/sandbox-sdk-go/internal"
big "math/big"
time "time"
)
var (
bashSessionCreateRequestFieldSessionId = big.NewInt(1 << 0)
bashSessionCreateRequestFieldExecDir = big.NewInt(1 << 1)
bashSessionCreateRequestFieldSnapshotPath = big.NewInt(1 << 2)
)
type BashSessionCreateRequest struct {
// Session ID. Auto-generated if not provided.
SessionId *string `json:"session_id,omitempty" url:"-"`
// Working directory for the new session (absolute path)
ExecDir *string `json:"exec_dir,omitempty" url:"-"`
// Path to a shell snapshot script to source on session init
SnapshotPath *string `json:"snapshot_path,omitempty" url:"-"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
}
func (b *BashSessionCreateRequest) require(field *big.Int) {
if b.explicitFields == nil {
b.explicitFields = big.NewInt(0)
}
b.explicitFields.Or(b.explicitFields, field)
}
// SetSessionId sets the SessionId field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashSessionCreateRequest) SetSessionId(sessionId *string) {
b.SessionId = sessionId
b.require(bashSessionCreateRequestFieldSessionId)
}
// SetExecDir sets the ExecDir field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashSessionCreateRequest) SetExecDir(execDir *string) {
b.ExecDir = execDir
b.require(bashSessionCreateRequestFieldExecDir)
}
// SetSnapshotPath sets the SnapshotPath field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashSessionCreateRequest) SetSnapshotPath(snapshotPath *string) {
b.SnapshotPath = snapshotPath
b.require(bashSessionCreateRequestFieldSnapshotPath)
}
var (
bashExecRequestFieldSessionId = big.NewInt(1 << 0)
bashExecRequestFieldCommand = big.NewInt(1 << 1)
bashExecRequestFieldExecDir = big.NewInt(1 << 2)
bashExecRequestFieldEnv = big.NewInt(1 << 3)
bashExecRequestFieldAsyncMode = big.NewInt(1 << 4)
bashExecRequestFieldTimeout = big.NewInt(1 << 5)
bashExecRequestFieldHardTimeout = big.NewInt(1 << 6)
bashExecRequestFieldMaxOutputLength = big.NewInt(1 << 7)
)
type BashExecRequest struct {
// Target session ID. If not provided, a new session is created automatically. Reuse the same session_id to maintain state (env vars, cwd, etc.) across commands.
SessionId *string `json:"session_id,omitempty" url:"-"`
// Shell command to execute
Command string `json:"command" url:"-"`
// Working directory (absolute path). Takes effect on every call — if the session already exists, the working directory is updated persistently.
ExecDir *string `json:"exec_dir,omitempty" url:"-"`
// Extra environment variables to inject for this command only.
Env map[string]*string `json:"env,omitempty" url:"-"`
// If true, return immediately with running status. Use /output to poll results.
AsyncMode *bool `json:"async_mode,omitempty" url:"-"`
// HTTP timeout (seconds). Only effective when async_mode=false. If the command does not complete within this time, HTTP returns running status and the command continues in the background. Use /output to get results.
Timeout *float64 `json:"timeout,omitempty" url:"-"`
// Hard execution timeout (seconds). When reached, the process is killed and status becomes timed_out. None means no limit.
HardTimeout *float64 `json:"hard_timeout,omitempty" url:"-"`
// Maximum character length for stdout/stderr in the response. When output exceeds this limit, middle truncation is applied (head and tail preserved, middle replaced with a marker). Only effective in sync mode (async_mode=false). Set to 0 to disable truncation.
MaxOutputLength *int `json:"max_output_length,omitempty" url:"-"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
}
func (b *BashExecRequest) require(field *big.Int) {
if b.explicitFields == nil {
b.explicitFields = big.NewInt(0)
}
b.explicitFields.Or(b.explicitFields, field)
}
// SetSessionId sets the SessionId field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecRequest) SetSessionId(sessionId *string) {
b.SessionId = sessionId
b.require(bashExecRequestFieldSessionId)
}
// SetCommand sets the Command field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecRequest) SetCommand(command string) {
b.Command = command
b.require(bashExecRequestFieldCommand)
}
// SetExecDir sets the ExecDir field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecRequest) SetExecDir(execDir *string) {
b.ExecDir = execDir
b.require(bashExecRequestFieldExecDir)
}
// SetEnv sets the Env field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecRequest) SetEnv(env map[string]*string) {
b.Env = env
b.require(bashExecRequestFieldEnv)
}
// SetAsyncMode sets the AsyncMode field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecRequest) SetAsyncMode(asyncMode *bool) {
b.AsyncMode = asyncMode
b.require(bashExecRequestFieldAsyncMode)
}
// SetTimeout sets the Timeout field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecRequest) SetTimeout(timeout *float64) {
b.Timeout = timeout
b.require(bashExecRequestFieldTimeout)
}
// SetHardTimeout sets the HardTimeout field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecRequest) SetHardTimeout(hardTimeout *float64) {
b.HardTimeout = hardTimeout
b.require(bashExecRequestFieldHardTimeout)
}
// SetMaxOutputLength sets the MaxOutputLength field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecRequest) SetMaxOutputLength(maxOutputLength *int) {
b.MaxOutputLength = maxOutputLength
b.require(bashExecRequestFieldMaxOutputLength)
}
var (
bashKillRequestFieldSessionId = big.NewInt(1 << 0)
bashKillRequestFieldSignal = big.NewInt(1 << 1)
)
type BashKillRequest struct {
// Target session ID
SessionId string `json:"session_id" url:"-"`
// Signal to send: SIGTERM, SIGKILL, or SIGINT
Signal *string `json:"signal,omitempty" url:"-"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
}
func (b *BashKillRequest) require(field *big.Int) {
if b.explicitFields == nil {
b.explicitFields = big.NewInt(0)
}
b.explicitFields.Or(b.explicitFields, field)
}
// SetSessionId sets the SessionId field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashKillRequest) SetSessionId(sessionId string) {
b.SessionId = sessionId
b.require(bashKillRequestFieldSessionId)
}
// SetSignal sets the Signal field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashKillRequest) SetSignal(signal *string) {
b.Signal = signal
b.require(bashKillRequestFieldSignal)
}
var (
bashOutputRequestFieldSessionId = big.NewInt(1 << 0)
bashOutputRequestFieldCommandId = big.NewInt(1 << 1)
bashOutputRequestFieldOffset = big.NewInt(1 << 2)
bashOutputRequestFieldStderrOffset = big.NewInt(1 << 3)
bashOutputRequestFieldWait = big.NewInt(1 << 4)
bashOutputRequestFieldWaitTimeout = big.NewInt(1 << 5)
)
type BashOutputRequest struct {
// Target session ID
SessionId string `json:"session_id" url:"-"`
// Target a specific async command. If not set, uses session-level output.
CommandId *string `json:"command_id,omitempty" url:"-"`
// Stdout byte offset to read from
Offset *int `json:"offset,omitempty" url:"-"`
// Stderr byte offset to read from
StderrOffset *int `json:"stderr_offset,omitempty" url:"-"`
// If true, long-poll until new output is available or wait_timeout is reached.
Wait *bool `json:"wait,omitempty" url:"-"`
// Max seconds to wait for new output when wait=true.
WaitTimeout *float64 `json:"wait_timeout,omitempty" url:"-"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
}
func (b *BashOutputRequest) require(field *big.Int) {
if b.explicitFields == nil {
b.explicitFields = big.NewInt(0)
}
b.explicitFields.Or(b.explicitFields, field)
}
// SetSessionId sets the SessionId field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputRequest) SetSessionId(sessionId string) {
b.SessionId = sessionId
b.require(bashOutputRequestFieldSessionId)
}
// SetCommandId sets the CommandId field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputRequest) SetCommandId(commandId *string) {
b.CommandId = commandId
b.require(bashOutputRequestFieldCommandId)
}
// SetOffset sets the Offset field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputRequest) SetOffset(offset *int) {
b.Offset = offset
b.require(bashOutputRequestFieldOffset)
}
// SetStderrOffset sets the StderrOffset field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputRequest) SetStderrOffset(stderrOffset *int) {
b.StderrOffset = stderrOffset
b.require(bashOutputRequestFieldStderrOffset)
}
// SetWait sets the Wait field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputRequest) SetWait(wait *bool) {
b.Wait = wait
b.require(bashOutputRequestFieldWait)
}
// SetWaitTimeout sets the WaitTimeout field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputRequest) SetWaitTimeout(waitTimeout *float64) {
b.WaitTimeout = waitTimeout
b.require(bashOutputRequestFieldWaitTimeout)
}
// Serializable command status info (for API responses).
var (
bashCommandInfoFieldCommandId = big.NewInt(1 << 0)
bashCommandInfoFieldCommand = big.NewInt(1 << 1)
bashCommandInfoFieldStatus = big.NewInt(1 << 2)
bashCommandInfoFieldExitCode = big.NewInt(1 << 3)
)
type BashCommandInfo struct {
// Unique command identifier
CommandId string `json:"command_id" url:"command_id"`
// The command string
Command string `json:"command" url:"command"`
// Command execution status
Status CommandStatus `json:"status" url:"status"`
// Exit code (when completed)
ExitCode *int `json:"exit_code,omitempty" url:"exit_code,omitempty"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
extraProperties map[string]interface{}
rawJSON json.RawMessage
}
func (b *BashCommandInfo) GetCommandId() string {
if b == nil {
return ""
}
return b.CommandId
}
func (b *BashCommandInfo) GetCommand() string {
if b == nil {
return ""
}
return b.Command
}
func (b *BashCommandInfo) GetStatus() CommandStatus {
if b == nil {
return ""
}
return b.Status
}
func (b *BashCommandInfo) GetExitCode() *int {
if b == nil {
return nil
}
return b.ExitCode
}
func (b *BashCommandInfo) GetExtraProperties() map[string]interface{} {
return b.extraProperties
}
func (b *BashCommandInfo) require(field *big.Int) {
if b.explicitFields == nil {
b.explicitFields = big.NewInt(0)
}
b.explicitFields.Or(b.explicitFields, field)
}
// SetCommandId sets the CommandId field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashCommandInfo) SetCommandId(commandId string) {
b.CommandId = commandId
b.require(bashCommandInfoFieldCommandId)
}
// SetCommand sets the Command field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashCommandInfo) SetCommand(command string) {
b.Command = command
b.require(bashCommandInfoFieldCommand)
}
// SetStatus sets the Status field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashCommandInfo) SetStatus(status CommandStatus) {
b.Status = status
b.require(bashCommandInfoFieldStatus)
}
// SetExitCode sets the ExitCode field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashCommandInfo) SetExitCode(exitCode *int) {
b.ExitCode = exitCode
b.require(bashCommandInfoFieldExitCode)
}
func (b *BashCommandInfo) UnmarshalJSON(data []byte) error {
type unmarshaler BashCommandInfo
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*b = BashCommandInfo(value)
extraProperties, err := internal.ExtractExtraProperties(data, *b)
if err != nil {
return err
}
b.extraProperties = extraProperties
b.rawJSON = json.RawMessage(data)
return nil
}
func (b *BashCommandInfo) MarshalJSON() ([]byte, error) {
type embed BashCommandInfo
var marshaler = struct {
embed
}{
embed: embed(*b),
}
explicitMarshaler := internal.HandleExplicitFields(marshaler, b.explicitFields)
return json.Marshal(explicitMarshaler)
}
func (b *BashCommandInfo) String() string {
if len(b.rawJSON) > 0 {
if value, err := internal.StringifyJSON(b.rawJSON); err == nil {
return value
}
}
if value, err := internal.StringifyJSON(b); err == nil {
return value
}
return fmt.Sprintf("%#v", b)
}
// Result of exec_command — returned by POST /v1/bash/exec.
var (
bashExecResultFieldSessionId = big.NewInt(1 << 0)
bashExecResultFieldCommandId = big.NewInt(1 << 1)
bashExecResultFieldCommand = big.NewInt(1 << 2)
bashExecResultFieldStatus = big.NewInt(1 << 3)
bashExecResultFieldStdout = big.NewInt(1 << 4)
bashExecResultFieldStderr = big.NewInt(1 << 5)
bashExecResultFieldExitCode = big.NewInt(1 << 6)
bashExecResultFieldOffset = big.NewInt(1 << 7)
bashExecResultFieldStderrOffset = big.NewInt(1 << 8)
)
type BashExecResult struct {
// Session identifier
SessionId string `json:"session_id" url:"session_id"`
// Unique command identifier
CommandId string `json:"command_id" url:"command_id"`
// The executed command
Command string `json:"command" url:"command"`
// Command status
Status CommandStatus `json:"status" url:"status"`
// Stdout output up to this point
Stdout *string `json:"stdout,omitempty" url:"stdout,omitempty"`
// Stderr output up to this point
Stderr *string `json:"stderr,omitempty" url:"stderr,omitempty"`
// Exit code (when completed)
ExitCode *int `json:"exit_code,omitempty" url:"exit_code,omitempty"`
// Current stdout offset for subsequent /output calls
Offset *int `json:"offset,omitempty" url:"offset,omitempty"`
// Current stderr offset
StderrOffset *int `json:"stderr_offset,omitempty" url:"stderr_offset,omitempty"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
extraProperties map[string]interface{}
rawJSON json.RawMessage
}
func (b *BashExecResult) GetSessionId() string {
if b == nil {
return ""
}
return b.SessionId
}
func (b *BashExecResult) GetCommandId() string {
if b == nil {
return ""
}
return b.CommandId
}
func (b *BashExecResult) GetCommand() string {
if b == nil {
return ""
}
return b.Command
}
func (b *BashExecResult) GetStatus() CommandStatus {
if b == nil {
return ""
}
return b.Status
}
func (b *BashExecResult) GetStdout() *string {
if b == nil {
return nil
}
return b.Stdout
}
func (b *BashExecResult) GetStderr() *string {
if b == nil {
return nil
}
return b.Stderr
}
func (b *BashExecResult) GetExitCode() *int {
if b == nil {
return nil
}
return b.ExitCode
}
func (b *BashExecResult) GetOffset() *int {
if b == nil {
return nil
}
return b.Offset
}
func (b *BashExecResult) GetStderrOffset() *int {
if b == nil {
return nil
}
return b.StderrOffset
}
func (b *BashExecResult) GetExtraProperties() map[string]interface{} {
return b.extraProperties
}
func (b *BashExecResult) require(field *big.Int) {
if b.explicitFields == nil {
b.explicitFields = big.NewInt(0)
}
b.explicitFields.Or(b.explicitFields, field)
}
// SetSessionId sets the SessionId field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecResult) SetSessionId(sessionId string) {
b.SessionId = sessionId
b.require(bashExecResultFieldSessionId)
}
// SetCommandId sets the CommandId field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecResult) SetCommandId(commandId string) {
b.CommandId = commandId
b.require(bashExecResultFieldCommandId)
}
// SetCommand sets the Command field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecResult) SetCommand(command string) {
b.Command = command
b.require(bashExecResultFieldCommand)
}
// SetStatus sets the Status field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecResult) SetStatus(status CommandStatus) {
b.Status = status
b.require(bashExecResultFieldStatus)
}
// SetStdout sets the Stdout field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecResult) SetStdout(stdout *string) {
b.Stdout = stdout
b.require(bashExecResultFieldStdout)
}
// SetStderr sets the Stderr field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecResult) SetStderr(stderr *string) {
b.Stderr = stderr
b.require(bashExecResultFieldStderr)
}
// SetExitCode sets the ExitCode field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecResult) SetExitCode(exitCode *int) {
b.ExitCode = exitCode
b.require(bashExecResultFieldExitCode)
}
// SetOffset sets the Offset field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecResult) SetOffset(offset *int) {
b.Offset = offset
b.require(bashExecResultFieldOffset)
}
// SetStderrOffset sets the StderrOffset field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashExecResult) SetStderrOffset(stderrOffset *int) {
b.StderrOffset = stderrOffset
b.require(bashExecResultFieldStderrOffset)
}
func (b *BashExecResult) UnmarshalJSON(data []byte) error {
type unmarshaler BashExecResult
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*b = BashExecResult(value)
extraProperties, err := internal.ExtractExtraProperties(data, *b)
if err != nil {
return err
}
b.extraProperties = extraProperties
b.rawJSON = json.RawMessage(data)
return nil
}
func (b *BashExecResult) MarshalJSON() ([]byte, error) {
type embed BashExecResult
var marshaler = struct {
embed
}{
embed: embed(*b),
}
explicitMarshaler := internal.HandleExplicitFields(marshaler, b.explicitFields)
return json.Marshal(explicitMarshaler)
}
func (b *BashExecResult) String() string {
if len(b.rawJSON) > 0 {
if value, err := internal.StringifyJSON(b.rawJSON); err == nil {
return value
}
}
if value, err := internal.StringifyJSON(b); err == nil {
return value
}
return fmt.Sprintf("%#v", b)
}
// Result of get_output — returned by POST /v1/bash/output.
var (
bashOutputResultFieldSessionId = big.NewInt(1 << 0)
bashOutputResultFieldStdout = big.NewInt(1 << 1)
bashOutputResultFieldStderr = big.NewInt(1 << 2)
bashOutputResultFieldOffset = big.NewInt(1 << 3)
bashOutputResultFieldStderrOffset = big.NewInt(1 << 4)
bashOutputResultFieldCommand = big.NewInt(1 << 5)
)
type BashOutputResult struct {
// Session identifier
SessionId string `json:"session_id" url:"session_id"`
// New stdout data since last offset
Stdout *string `json:"stdout,omitempty" url:"stdout,omitempty"`
// New stderr data since last offset
Stderr *string `json:"stderr,omitempty" url:"stderr,omitempty"`
// Current stdout offset (use for next request)
Offset *int `json:"offset,omitempty" url:"offset,omitempty"`
// Current stderr offset (use for next request)
StderrOffset *int `json:"stderr_offset,omitempty" url:"stderr_offset,omitempty"`
// Current or most recent command status
Command *BashCommandInfo `json:"command,omitempty" url:"command,omitempty"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
extraProperties map[string]interface{}
rawJSON json.RawMessage
}
func (b *BashOutputResult) GetSessionId() string {
if b == nil {
return ""
}
return b.SessionId
}
func (b *BashOutputResult) GetStdout() *string {
if b == nil {
return nil
}
return b.Stdout
}
func (b *BashOutputResult) GetStderr() *string {
if b == nil {
return nil
}
return b.Stderr
}
func (b *BashOutputResult) GetOffset() *int {
if b == nil {
return nil
}
return b.Offset
}
func (b *BashOutputResult) GetStderrOffset() *int {
if b == nil {
return nil
}
return b.StderrOffset
}
func (b *BashOutputResult) GetCommand() *BashCommandInfo {
if b == nil {
return nil
}
return b.Command
}
func (b *BashOutputResult) GetExtraProperties() map[string]interface{} {
return b.extraProperties
}
func (b *BashOutputResult) require(field *big.Int) {
if b.explicitFields == nil {
b.explicitFields = big.NewInt(0)
}
b.explicitFields.Or(b.explicitFields, field)
}
// SetSessionId sets the SessionId field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputResult) SetSessionId(sessionId string) {
b.SessionId = sessionId
b.require(bashOutputResultFieldSessionId)
}
// SetStdout sets the Stdout field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputResult) SetStdout(stdout *string) {
b.Stdout = stdout
b.require(bashOutputResultFieldStdout)
}
// SetStderr sets the Stderr field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputResult) SetStderr(stderr *string) {
b.Stderr = stderr
b.require(bashOutputResultFieldStderr)
}
// SetOffset sets the Offset field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputResult) SetOffset(offset *int) {
b.Offset = offset
b.require(bashOutputResultFieldOffset)
}
// SetStderrOffset sets the StderrOffset field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputResult) SetStderrOffset(stderrOffset *int) {
b.StderrOffset = stderrOffset
b.require(bashOutputResultFieldStderrOffset)
}
// SetCommand sets the Command field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashOutputResult) SetCommand(command *BashCommandInfo) {
b.Command = command
b.require(bashOutputResultFieldCommand)
}
func (b *BashOutputResult) UnmarshalJSON(data []byte) error {
type unmarshaler BashOutputResult
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*b = BashOutputResult(value)
extraProperties, err := internal.ExtractExtraProperties(data, *b)
if err != nil {
return err
}
b.extraProperties = extraProperties
b.rawJSON = json.RawMessage(data)
return nil
}
func (b *BashOutputResult) MarshalJSON() ([]byte, error) {
type embed BashOutputResult
var marshaler = struct {
embed
}{
embed: embed(*b),
}
explicitMarshaler := internal.HandleExplicitFields(marshaler, b.explicitFields)
return json.Marshal(explicitMarshaler)
}
func (b *BashOutputResult) String() string {
if len(b.rawJSON) > 0 {
if value, err := internal.StringifyJSON(b.rawJSON); err == nil {
return value
}
}
if value, err := internal.StringifyJSON(b); err == nil {
return value
}
return fmt.Sprintf("%#v", b)
}
// Session info for listing — returned by GET /v1/bash/sessions.
var (
bashSessionInfoFieldSessionId = big.NewInt(1 << 0)
bashSessionInfoFieldStatus = big.NewInt(1 << 1)
bashSessionInfoFieldWorkingDir = big.NewInt(1 << 2)
bashSessionInfoFieldCreatedAt = big.NewInt(1 << 3)
bashSessionInfoFieldLastUsedAt = big.NewInt(1 << 4)
bashSessionInfoFieldCurrentCommand = big.NewInt(1 << 5)
bashSessionInfoFieldCommandCount = big.NewInt(1 << 6)
)
type BashSessionInfo struct {
// Session identifier
SessionId string `json:"session_id" url:"session_id"`
// Session status
Status SessionStatus `json:"status" url:"status"`
// Working directory
WorkingDir string `json:"working_dir" url:"working_dir"`
// Creation timestamp
CreatedAt time.Time `json:"created_at" url:"created_at"`
// Last used timestamp
LastUsedAt time.Time `json:"last_used_at" url:"last_used_at"`
// Currently executing command
CurrentCommand *string `json:"current_command,omitempty" url:"current_command,omitempty"`
// Total commands executed
CommandCount *int `json:"command_count,omitempty" url:"command_count,omitempty"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
extraProperties map[string]interface{}
rawJSON json.RawMessage
}
func (b *BashSessionInfo) GetSessionId() string {
if b == nil {
return ""
}
return b.SessionId
}
func (b *BashSessionInfo) GetStatus() SessionStatus {
if b == nil {
return ""
}
return b.Status
}
func (b *BashSessionInfo) GetWorkingDir() string {
if b == nil {
return ""
}
return b.WorkingDir
}
func (b *BashSessionInfo) GetCreatedAt() time.Time {
if b == nil {
return time.Time{}
}
return b.CreatedAt
}
func (b *BashSessionInfo) GetLastUsedAt() time.Time {
if b == nil {
return time.Time{}
}
return b.LastUsedAt
}
func (b *BashSessionInfo) GetCurrentCommand() *string {
if b == nil {
return nil
}
return b.CurrentCommand
}
func (b *BashSessionInfo) GetCommandCount() *int {
if b == nil {
return nil
}
return b.CommandCount
}
func (b *BashSessionInfo) GetExtraProperties() map[string]interface{} {
return b.extraProperties
}
func (b *BashSessionInfo) require(field *big.Int) {
if b.explicitFields == nil {
b.explicitFields = big.NewInt(0)
}
b.explicitFields.Or(b.explicitFields, field)
}
// SetSessionId sets the SessionId field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashSessionInfo) SetSessionId(sessionId string) {
b.SessionId = sessionId
b.require(bashSessionInfoFieldSessionId)
}
// SetStatus sets the Status field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashSessionInfo) SetStatus(status SessionStatus) {
b.Status = status
b.require(bashSessionInfoFieldStatus)
}
// SetWorkingDir sets the WorkingDir field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashSessionInfo) SetWorkingDir(workingDir string) {
b.WorkingDir = workingDir
b.require(bashSessionInfoFieldWorkingDir)
}
// SetCreatedAt sets the CreatedAt field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashSessionInfo) SetCreatedAt(createdAt time.Time) {
b.CreatedAt = createdAt
b.require(bashSessionInfoFieldCreatedAt)
}
// SetLastUsedAt sets the LastUsedAt field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashSessionInfo) SetLastUsedAt(lastUsedAt time.Time) {
b.LastUsedAt = lastUsedAt
b.require(bashSessionInfoFieldLastUsedAt)
}
// SetCurrentCommand sets the CurrentCommand field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashSessionInfo) SetCurrentCommand(currentCommand *string) {
b.CurrentCommand = currentCommand
b.require(bashSessionInfoFieldCurrentCommand)
}
// SetCommandCount sets the CommandCount field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (b *BashSessionInfo) SetCommandCount(commandCount *int) {
b.CommandCount = commandCount
b.require(bashSessionInfoFieldCommandCount)
}
func (b *BashSessionInfo) UnmarshalJSON(data []byte) error {
type embed BashSessionInfo
var unmarshaler = struct {
embed
CreatedAt *internal.DateTime `json:"created_at"`
LastUsedAt *internal.DateTime `json:"last_used_at"`
}{
embed: embed(*b),
}
if err := json.Unmarshal(data, &unmarshaler); err != nil {
return err
}
*b = BashSessionInfo(unmarshaler.embed)
b.CreatedAt = unmarshaler.CreatedAt.Time()
b.LastUsedAt = unmarshaler.LastUsedAt.Time()
extraProperties, err := internal.ExtractExtraProperties(data, *b)
if err != nil {
return err
}
b.extraProperties = extraProperties
b.rawJSON = json.RawMessage(data)
return nil
}
func (b *BashSessionInfo) MarshalJSON() ([]byte, error) {
type embed BashSessionInfo
var marshaler = struct {
embed
CreatedAt *internal.DateTime `json:"created_at"`
LastUsedAt *internal.DateTime `json:"last_used_at"`
}{
embed: embed(*b),
CreatedAt: internal.NewDateTime(b.CreatedAt),
LastUsedAt: internal.NewDateTime(b.LastUsedAt),
}
explicitMarshaler := internal.HandleExplicitFields(marshaler, b.explicitFields)
return json.Marshal(explicitMarshaler)
}
func (b *BashSessionInfo) String() string {
if len(b.rawJSON) > 0 {
if value, err := internal.StringifyJSON(b.rawJSON); err == nil {
return value
}
}
if value, err := internal.StringifyJSON(b); err == nil {
return value
}
return fmt.Sprintf("%#v", b)
}
// Status of a bash command execution.
type CommandStatus string
const (
CommandStatusPending CommandStatus = "pending"
CommandStatusRunning CommandStatus = "running"
CommandStatusCompleted CommandStatus = "completed"
CommandStatusTimedOut CommandStatus = "timed_out"
CommandStatusKilled CommandStatus = "killed"
)
func NewCommandStatusFromString(s string) (CommandStatus, error) {
switch s {
case "pending":
return CommandStatusPending, nil
case "running":
return CommandStatusRunning, nil
case "completed":
return CommandStatusCompleted, nil
case "timed_out":
return CommandStatusTimedOut, nil
case "killed":
return CommandStatusKilled, nil
}
var t CommandStatus
return "", fmt.Errorf("%s is not a valid %T", s, t)
}