Skip to content

Commit 7c46ece

Browse files
Go fix
1 parent 4ff8ce2 commit 7c46ece

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

go/types.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,32 @@ type PermissionRequest struct {
106106
Extra map[string]any `json:"-"` // Additional fields vary by kind
107107
}
108108

109+
// UnmarshalJSON implements custom JSON unmarshaling for PermissionRequest
110+
// to capture additional fields (varying by kind) into the Extra map.
111+
func (p *PermissionRequest) UnmarshalJSON(data []byte) error {
112+
// Unmarshal known fields via an alias to avoid infinite recursion
113+
type Alias PermissionRequest
114+
var alias Alias
115+
if err := json.Unmarshal(data, &alias); err != nil {
116+
return err
117+
}
118+
*p = PermissionRequest(alias)
119+
120+
// Unmarshal all fields into a generic map
121+
var raw map[string]any
122+
if err := json.Unmarshal(data, &raw); err != nil {
123+
return err
124+
}
125+
126+
// Remove known fields, keep the rest as Extra
127+
delete(raw, "kind")
128+
delete(raw, "toolCallId")
129+
if len(raw) > 0 {
130+
p.Extra = raw
131+
}
132+
return nil
133+
}
134+
109135
// PermissionRequestResult represents the result of a permission request
110136
type PermissionRequestResult struct {
111137
Kind string `json:"kind"`

0 commit comments

Comments
 (0)