-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathzrpc_encoding.go
More file actions
2599 lines (2441 loc) · 66.5 KB
/
zrpc_encoding.go
File metadata and controls
2599 lines (2441 loc) · 66.5 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 scripts/codegen/go.ts; DO NOT EDIT.
// Source: api.schema.json
package rpc
import (
"encoding/json"
"errors"
)
func unmarshalAuthInfo(data []byte) (AuthInfo, error) {
if string(data) == "null" {
return nil, nil
}
type rawUnion struct {
Type AuthInfoType `json:"type"`
}
var raw rawUnion
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
switch raw.Type {
case AuthInfoTypeAPIKey:
var d APIKeyAuthInfo
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case AuthInfoTypeCopilotAPIToken:
var d CopilotAPITokenAuthInfo
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case AuthInfoTypeEnv:
var d EnvAuthInfo
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case AuthInfoTypeGhCli:
var d GhCliAuthInfo
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case AuthInfoTypeHmac:
var d HMACAuthInfo
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case AuthInfoTypeToken:
var d TokenAuthInfo
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case AuthInfoTypeUser:
var d UserAuthInfo
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
default:
return &RawAuthInfoData{Discriminator: raw.Type, Raw: data}, nil
}
}
func (r RawAuthInfoData) MarshalJSON() ([]byte, error) {
if r.Raw != nil {
return r.Raw, nil
}
return json.Marshal(struct {
Type AuthInfoType `json:"type"`
}{
Type: r.Discriminator,
})
}
func (r APIKeyAuthInfo) MarshalJSON() ([]byte, error) {
type alias APIKeyAuthInfo
return json.Marshal(struct {
Type AuthInfoType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r CopilotAPITokenAuthInfo) MarshalJSON() ([]byte, error) {
type alias CopilotAPITokenAuthInfo
return json.Marshal(struct {
Type AuthInfoType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r EnvAuthInfo) MarshalJSON() ([]byte, error) {
type alias EnvAuthInfo
return json.Marshal(struct {
Type AuthInfoType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r GhCliAuthInfo) MarshalJSON() ([]byte, error) {
type alias GhCliAuthInfo
return json.Marshal(struct {
Type AuthInfoType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r HMACAuthInfo) MarshalJSON() ([]byte, error) {
type alias HMACAuthInfo
return json.Marshal(struct {
Type AuthInfoType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r TokenAuthInfo) MarshalJSON() ([]byte, error) {
type alias TokenAuthInfo
return json.Marshal(struct {
Type AuthInfoType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r UserAuthInfo) MarshalJSON() ([]byte, error) {
type alias UserAuthInfo
return json.Marshal(struct {
Type AuthInfoType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func unmarshalQueuedCommandResult(data []byte) (QueuedCommandResult, error) {
if string(data) == "null" {
return nil, nil
}
type rawUnion struct {
Handled *bool `json:"handled"`
}
var raw rawUnion
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
if raw.Handled == nil {
return nil, errors.New("data did not match any union variant for QueuedCommandResult")
}
switch *raw.Handled {
case false:
var d QueuedCommandNotHandled
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case true:
var d QueuedCommandHandled
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
}
return nil, errors.New("data did not match any union variant for QueuedCommandResult")
}
func (r QueuedCommandHandled) MarshalJSON() ([]byte, error) {
type alias QueuedCommandHandled
return json.Marshal(struct {
Handled bool `json:"handled"`
alias
}{
Handled: r.Handled(),
alias: alias(r),
})
}
func (r QueuedCommandNotHandled) MarshalJSON() ([]byte, error) {
type alias QueuedCommandNotHandled
return json.Marshal(struct {
Handled bool `json:"handled"`
alias
}{
Handled: r.Handled(),
alias: alias(r),
})
}
func (r *CommandsRespondToQueuedCommandRequest) UnmarshalJSON(data []byte) error {
type rawCommandsRespondToQueuedCommandRequest struct {
RequestID string `json:"requestId"`
Result json.RawMessage `json:"result"`
}
var raw rawCommandsRespondToQueuedCommandRequest
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
r.RequestID = raw.RequestID
if raw.Result != nil {
value, err := unmarshalQueuedCommandResult(raw.Result)
if err != nil {
return err
}
r.Result = value
}
return nil
}
func (r EventLogTypes) MarshalJSON() ([]byte, error) {
if r.String != nil {
return json.Marshal(r.String)
}
if r.StringArray != nil {
return json.Marshal(r.StringArray)
}
return []byte("null"), nil
}
func (r *EventLogTypes) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
*r = EventLogTypes{}
return nil
}
{
var value EventLogTypesString
if err := json.Unmarshal(data, &value); err == nil {
*r = EventLogTypes{String: &value}
return nil
}
}
{
var value []string
if err := json.Unmarshal(data, &value); err == nil {
*r = EventLogTypes{StringArray: value}
return nil
}
}
return errors.New("data did not match any union variant for EventLogTypes")
}
func unmarshalExternalToolTextResultForLlmContent(data []byte) (ExternalToolTextResultForLlmContent, error) {
if string(data) == "null" {
return nil, nil
}
type rawUnion struct {
Type ExternalToolTextResultForLlmContentType `json:"type"`
}
var raw rawUnion
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
switch raw.Type {
case ExternalToolTextResultForLlmContentTypeAudio:
var d ExternalToolTextResultForLlmContentAudio
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case ExternalToolTextResultForLlmContentTypeImage:
var d ExternalToolTextResultForLlmContentImage
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case ExternalToolTextResultForLlmContentTypeResource:
var d ExternalToolTextResultForLlmContentResource
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case ExternalToolTextResultForLlmContentTypeResourceLink:
var d ExternalToolTextResultForLlmContentResourceLink
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case ExternalToolTextResultForLlmContentTypeTerminal:
var d ExternalToolTextResultForLlmContentTerminal
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case ExternalToolTextResultForLlmContentTypeText:
var d ExternalToolTextResultForLlmContentText
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
default:
return &RawExternalToolTextResultForLlmContentData{Discriminator: raw.Type, Raw: data}, nil
}
}
func (r RawExternalToolTextResultForLlmContentData) MarshalJSON() ([]byte, error) {
if r.Raw != nil {
return r.Raw, nil
}
return json.Marshal(struct {
Type ExternalToolTextResultForLlmContentType `json:"type"`
}{
Type: r.Discriminator,
})
}
func (r ExternalToolTextResultForLlmContentAudio) MarshalJSON() ([]byte, error) {
type alias ExternalToolTextResultForLlmContentAudio
return json.Marshal(struct {
Type ExternalToolTextResultForLlmContentType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r ExternalToolTextResultForLlmContentImage) MarshalJSON() ([]byte, error) {
type alias ExternalToolTextResultForLlmContentImage
return json.Marshal(struct {
Type ExternalToolTextResultForLlmContentType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func matchesEmbeddedBlobResourceContents(data []byte) bool {
var rawGroup0 struct {
Blob json.RawMessage `json:"blob"`
Text json.RawMessage `json:"text"`
}
if err := json.Unmarshal(data, &rawGroup0); err != nil {
return false
}
if rawGroup0.Blob == nil {
return false
}
return rawGroup0.Text == nil
}
func matchesEmbeddedTextResourceContents(data []byte) bool {
var rawGroup0 struct {
Blob json.RawMessage `json:"blob"`
Text json.RawMessage `json:"text"`
}
if err := json.Unmarshal(data, &rawGroup0); err != nil {
return false
}
if rawGroup0.Text == nil {
return false
}
return rawGroup0.Blob == nil
}
func unmarshalExternalToolTextResultForLlmContentResourceDetails(data []byte) (ExternalToolTextResultForLlmContentResourceDetails, error) {
if string(data) == "null" {
return nil, nil
}
if matchesEmbeddedBlobResourceContents(data) {
var d EmbeddedBlobResourceContents
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
}
if matchesEmbeddedTextResourceContents(data) {
var d EmbeddedTextResourceContents
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
}
return &RawExternalToolTextResultForLlmContentResourceDetailsData{Raw: data}, nil
}
func (r RawExternalToolTextResultForLlmContentResourceDetailsData) MarshalJSON() ([]byte, error) {
if r.Raw != nil {
return r.Raw, nil
}
return []byte("null"), nil
}
func (r *ExternalToolTextResultForLlmContentResource) UnmarshalJSON(data []byte) error {
type rawExternalToolTextResultForLlmContentResource struct {
Resource json.RawMessage `json:"resource"`
}
var raw rawExternalToolTextResultForLlmContentResource
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
if raw.Resource != nil {
value, err := unmarshalExternalToolTextResultForLlmContentResourceDetails(raw.Resource)
if err != nil {
return err
}
r.Resource = value
}
return nil
}
func (r ExternalToolTextResultForLlmContentResource) MarshalJSON() ([]byte, error) {
type alias ExternalToolTextResultForLlmContentResource
return json.Marshal(struct {
Type ExternalToolTextResultForLlmContentType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r ExternalToolTextResultForLlmContentResourceLink) MarshalJSON() ([]byte, error) {
type alias ExternalToolTextResultForLlmContentResourceLink
return json.Marshal(struct {
Type ExternalToolTextResultForLlmContentType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r ExternalToolTextResultForLlmContentTerminal) MarshalJSON() ([]byte, error) {
type alias ExternalToolTextResultForLlmContentTerminal
return json.Marshal(struct {
Type ExternalToolTextResultForLlmContentType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r ExternalToolTextResultForLlmContentText) MarshalJSON() ([]byte, error) {
type alias ExternalToolTextResultForLlmContentText
return json.Marshal(struct {
Type ExternalToolTextResultForLlmContentType `json:"type"`
alias
}{
Type: r.Type(),
alias: alias(r),
})
}
func (r *ExternalToolTextResultForLlm) UnmarshalJSON(data []byte) error {
type rawExternalToolTextResultForLlm struct {
BinaryResultsForLlm []ExternalToolTextResultForLlmBinaryResultsForLlm `json:"binaryResultsForLlm,omitempty"`
Contents []json.RawMessage `json:"contents,omitempty"`
Error *string `json:"error,omitempty"`
ResultType *string `json:"resultType,omitempty"`
SessionLog *string `json:"sessionLog,omitempty"`
TextResultForLlm string `json:"textResultForLlm"`
ToolTelemetry map[string]any `json:"toolTelemetry,omitempty"`
}
var raw rawExternalToolTextResultForLlm
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
r.BinaryResultsForLlm = raw.BinaryResultsForLlm
if raw.Contents != nil {
r.Contents = make([]ExternalToolTextResultForLlmContent, 0, len(raw.Contents))
for _, rawItem := range raw.Contents {
value, err := unmarshalExternalToolTextResultForLlmContent(rawItem)
if err != nil {
return err
}
r.Contents = append(r.Contents, value)
}
}
r.Error = raw.Error
r.ResultType = raw.ResultType
r.SessionLog = raw.SessionLog
r.TextResultForLlm = raw.TextResultForLlm
r.ToolTelemetry = raw.ToolTelemetry
return nil
}
func unmarshalExternalToolResult(data []byte) (ExternalToolResult, error) {
if string(data) == "null" {
return nil, nil
}
{
var value string
if err := json.Unmarshal(data, &value); err == nil {
return ExternalToolStringResult(value), nil
}
}
{
var value ExternalToolTextResultForLlm
if err := json.Unmarshal(data, &value); err == nil {
return &value, nil
}
}
return nil, errors.New("data did not match any union variant for ExternalToolResult")
}
func unmarshalFilterMapping(data []byte) (FilterMapping, error) {
if string(data) == "null" {
return nil, nil
}
{
var value FilterMappingEnumMap
if err := json.Unmarshal(data, &value); err == nil {
return value, nil
}
}
{
var value ContentFilterMode
if err := json.Unmarshal(data, &value); err == nil {
return value, nil
}
}
return nil, errors.New("data did not match any union variant for FilterMapping")
}
func (r *HandlePendingToolCallRequest) UnmarshalJSON(data []byte) error {
type rawHandlePendingToolCallRequest struct {
Error *string `json:"error,omitempty"`
RequestID string `json:"requestId"`
Result json.RawMessage `json:"result,omitempty"`
}
var raw rawHandlePendingToolCallRequest
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
r.Error = raw.Error
r.RequestID = raw.RequestID
if raw.Result != nil {
value, err := unmarshalExternalToolResult(raw.Result)
if err != nil {
return err
}
r.Result = value
}
return nil
}
func (r InstalledPluginSource) MarshalJSON() ([]byte, error) {
if r.InstalledPluginSourceGithub != nil {
return json.Marshal(r.InstalledPluginSourceGithub)
}
if r.InstalledPluginSourceLocal != nil {
return json.Marshal(r.InstalledPluginSourceLocal)
}
if r.InstalledPluginSourceURL != nil {
return json.Marshal(r.InstalledPluginSourceURL)
}
if r.String != nil {
return json.Marshal(r.String)
}
return []byte("null"), nil
}
func (r *InstalledPluginSource) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
*r = InstalledPluginSource{}
return nil
}
{
var value InstalledPluginSourceGithub
if err := json.Unmarshal(data, &value); err == nil {
*r = InstalledPluginSource{InstalledPluginSourceGithub: &value}
return nil
}
}
{
var value InstalledPluginSourceLocal
if err := json.Unmarshal(data, &value); err == nil {
*r = InstalledPluginSource{InstalledPluginSourceLocal: &value}
return nil
}
}
{
var value InstalledPluginSourceURL
if err := json.Unmarshal(data, &value); err == nil {
*r = InstalledPluginSource{InstalledPluginSourceURL: &value}
return nil
}
}
{
var value string
if err := json.Unmarshal(data, &value); err == nil {
*r = InstalledPluginSource{String: &value}
return nil
}
}
return errors.New("data did not match any union variant for InstalledPluginSource")
}
func matchesMcpServerConfigHTTP(data []byte) bool {
var rawGroup0 struct {
Command json.RawMessage `json:"command"`
URL json.RawMessage `json:"url"`
}
if err := json.Unmarshal(data, &rawGroup0); err != nil {
return false
}
if rawGroup0.URL == nil {
return false
}
return rawGroup0.Command == nil
}
func matchesMcpServerConfigStdio(data []byte) bool {
var rawGroup0 struct {
Command json.RawMessage `json:"command"`
URL json.RawMessage `json:"url"`
}
if err := json.Unmarshal(data, &rawGroup0); err != nil {
return false
}
if rawGroup0.Command == nil {
return false
}
return rawGroup0.URL == nil
}
func unmarshalMcpServerConfig(data []byte) (McpServerConfig, error) {
if string(data) == "null" {
return nil, nil
}
if matchesMcpServerConfigHTTP(data) {
var d McpServerConfigHTTP
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
}
if matchesMcpServerConfigStdio(data) {
var d McpServerConfigStdio
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
}
return &RawMcpServerConfigData{Raw: data}, nil
}
func (r RawMcpServerConfigData) MarshalJSON() ([]byte, error) {
if r.Raw != nil {
return r.Raw, nil
}
return []byte("null"), nil
}
func (r *McpServerConfigHTTP) UnmarshalJSON(data []byte) error {
type rawMcpServerConfigHTTP struct {
Auth *McpServerConfigHTTPAuth `json:"auth,omitempty"`
FilterMapping json.RawMessage `json:"filterMapping,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
IsDefaultServer *bool `json:"isDefaultServer,omitempty"`
OauthClientID *string `json:"oauthClientId,omitempty"`
OauthGrantType *McpServerConfigHTTPOauthGrantType `json:"oauthGrantType,omitempty"`
OauthPublicClient *bool `json:"oauthPublicClient,omitempty"`
Timeout *int64 `json:"timeout,omitempty"`
Tools []string `json:"tools,omitempty"`
Type *McpServerConfigHTTPType `json:"type,omitempty"`
URL string `json:"url"`
}
var raw rawMcpServerConfigHTTP
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
r.Auth = raw.Auth
if raw.FilterMapping != nil {
value, err := unmarshalFilterMapping(raw.FilterMapping)
if err != nil {
return err
}
r.FilterMapping = value
}
r.Headers = raw.Headers
r.IsDefaultServer = raw.IsDefaultServer
r.OauthClientID = raw.OauthClientID
r.OauthGrantType = raw.OauthGrantType
r.OauthPublicClient = raw.OauthPublicClient
r.Timeout = raw.Timeout
r.Tools = raw.Tools
r.Type = raw.Type
r.URL = raw.URL
return nil
}
func (r *McpServerConfigStdio) UnmarshalJSON(data []byte) error {
type rawMcpServerConfigStdio struct {
Args []string `json:"args,omitempty"`
Command string `json:"command"`
Cwd *string `json:"cwd,omitempty"`
Env map[string]string `json:"env,omitempty"`
FilterMapping json.RawMessage `json:"filterMapping,omitempty"`
IsDefaultServer *bool `json:"isDefaultServer,omitempty"`
Timeout *int64 `json:"timeout,omitempty"`
Tools []string `json:"tools,omitempty"`
}
var raw rawMcpServerConfigStdio
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
r.Args = raw.Args
r.Command = raw.Command
r.Cwd = raw.Cwd
r.Env = raw.Env
if raw.FilterMapping != nil {
value, err := unmarshalFilterMapping(raw.FilterMapping)
if err != nil {
return err
}
r.FilterMapping = value
}
r.IsDefaultServer = raw.IsDefaultServer
r.Timeout = raw.Timeout
r.Tools = raw.Tools
return nil
}
func (r *McpConfigAddRequest) UnmarshalJSON(data []byte) error {
type rawMcpConfigAddRequest struct {
Config json.RawMessage `json:"config"`
Name string `json:"name"`
}
var raw rawMcpConfigAddRequest
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
if raw.Config != nil {
value, err := unmarshalMcpServerConfig(raw.Config)
if err != nil {
return err
}
r.Config = value
}
r.Name = raw.Name
return nil
}
func (r *McpConfigList) UnmarshalJSON(data []byte) error {
type rawMcpConfigList struct {
Servers map[string]json.RawMessage `json:"servers"`
}
var raw rawMcpConfigList
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
if raw.Servers != nil {
r.Servers = make(map[string]McpServerConfig, len(raw.Servers))
for key, rawValue := range raw.Servers {
value, err := unmarshalMcpServerConfig(rawValue)
if err != nil {
return err
}
r.Servers[key] = value
}
}
return nil
}
func (r *McpConfigUpdateRequest) UnmarshalJSON(data []byte) error {
type rawMcpConfigUpdateRequest struct {
Config json.RawMessage `json:"config"`
Name string `json:"name"`
}
var raw rawMcpConfigUpdateRequest
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
if raw.Config != nil {
value, err := unmarshalMcpServerConfig(raw.Config)
if err != nil {
return err
}
r.Config = value
}
r.Name = raw.Name
return nil
}
func unmarshalPermissionDecision(data []byte) (PermissionDecision, error) {
if string(data) == "null" {
return nil, nil
}
type rawUnion struct {
Kind PermissionDecisionKind `json:"kind"`
}
var raw rawUnion
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
switch raw.Kind {
case PermissionDecisionKindApproveForLocation:
var d PermissionDecisionApproveForLocation
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindApproveForSession:
var d PermissionDecisionApproveForSession
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindApproveOnce:
var d PermissionDecisionApproveOnce
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindApprovePermanently:
var d PermissionDecisionApprovePermanently
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindApproved:
var d PermissionDecisionApproved
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindApprovedForLocation:
var d PermissionDecisionApprovedForLocation
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindApprovedForSession:
var d PermissionDecisionApprovedForSession
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindCancelled:
var d PermissionDecisionCancelled
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindDeniedByContentExclusionPolicy:
var d PermissionDecisionDeniedByContentExclusionPolicy
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindDeniedByPermissionRequestHook:
var d PermissionDecisionDeniedByPermissionRequestHook
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindDeniedByRules:
var d PermissionDecisionDeniedByRules
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindDeniedInteractivelyByUser:
var d PermissionDecisionDeniedInteractivelyByUser
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindDeniedNoApprovalRuleAndCouldNotRequestFromUser:
var d PermissionDecisionDeniedNoApprovalRuleAndCouldNotRequestFromUser
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindReject:
var d PermissionDecisionReject
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case PermissionDecisionKindUserNotAvailable:
var d PermissionDecisionUserNotAvailable
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
default:
return &RawPermissionDecisionData{Discriminator: raw.Kind, Raw: data}, nil
}
}
func (r RawPermissionDecisionData) MarshalJSON() ([]byte, error) {
if r.Raw != nil {
return r.Raw, nil
}
return json.Marshal(struct {
Kind PermissionDecisionKind `json:"kind"`
}{
Kind: r.Discriminator,
})
}
func (r PermissionDecisionApproved) MarshalJSON() ([]byte, error) {
type alias PermissionDecisionApproved
return json.Marshal(struct {
Kind PermissionDecisionKind `json:"kind"`
alias
}{
Kind: r.Kind(),
alias: alias(r),
})
}
func unmarshalUserToolSessionApproval(data []byte) (UserToolSessionApproval, error) {
if string(data) == "null" {
return nil, nil
}
type rawUnion struct {
Kind UserToolSessionApprovalKind `json:"kind"`
}
var raw rawUnion
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
switch raw.Kind {
case UserToolSessionApprovalKindCommands:
var d UserToolSessionApprovalCommands
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case UserToolSessionApprovalKindCustomTool:
var d UserToolSessionApprovalCustomTool
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case UserToolSessionApprovalKindExtensionManagement:
var d UserToolSessionApprovalExtensionManagement
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case UserToolSessionApprovalKindExtensionPermissionAccess:
var d UserToolSessionApprovalExtensionPermissionAccess
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case UserToolSessionApprovalKindMcp:
var d UserToolSessionApprovalMcp
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case UserToolSessionApprovalKindMemory:
var d UserToolSessionApprovalMemory
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case UserToolSessionApprovalKindRead:
var d UserToolSessionApprovalRead
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
case UserToolSessionApprovalKindWrite:
var d UserToolSessionApprovalWrite
if err := json.Unmarshal(data, &d); err != nil {
return nil, err
}
return &d, nil
default:
return &RawUserToolSessionApprovalData{Discriminator: raw.Kind, Raw: data}, nil
}
}
func (r RawUserToolSessionApprovalData) MarshalJSON() ([]byte, error) {
if r.Raw != nil {
return r.Raw, nil