-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreset.go
More file actions
285 lines (229 loc) · 7.94 KB
/
preset.go
File metadata and controls
285 lines (229 loc) · 7.94 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
package config
import (
"bytes"
"encoding/json"
"fmt"
"github.com/ethpandaops/claude-agent-sdk-go/internal/mcp"
"github.com/ethpandaops/claude-agent-sdk-go/internal/permission"
)
// Beta represents a beta feature flag for the SDK.
type Beta string
const (
// BetaContext1M enables 1 million token context window.
BetaContext1M Beta = "context-1m-2025-08-07"
)
// SettingSource represents where settings should be loaded from.
type SettingSource string
const (
// SettingSourceUser loads from user-level settings.
SettingSourceUser SettingSource = "user"
// SettingSourceProject loads from project-level settings.
SettingSourceProject SettingSource = "project"
// SettingSourceLocal loads from local-level settings.
SettingSourceLocal SettingSource = "local"
)
// ToolsPreset represents a preset configuration for available tools.
type ToolsPreset struct {
Type string `json:"type"` // "preset"
Preset string `json:"preset"` // "claude_code"
}
// AgentMCPServerSpec represents one agent-scoped MCP server requirement.
// It is encoded as either a string reference to an existing server or an inline
// map of server definitions keyed by server name.
type AgentMCPServerSpec struct {
Reference *string
Inline map[string]mcp.ServerConfig
}
// MarshalJSON preserves the upstream union wire shape.
func (s AgentMCPServerSpec) MarshalJSON() ([]byte, error) {
if s.Reference != nil && s.Inline != nil {
return nil, fmt.Errorf("agent mcp server spec cannot contain both reference and inline config")
}
if s.Reference != nil {
return json.Marshal(*s.Reference)
}
if s.Inline != nil {
return json.Marshal(s.Inline)
}
return []byte("null"), nil
}
// UnmarshalJSON decodes the upstream union wire shape.
func (s *AgentMCPServerSpec) UnmarshalJSON(data []byte) error {
trimmed := bytes.TrimSpace(data)
if bytes.Equal(trimmed, []byte("null")) {
*s = AgentMCPServerSpec{}
return nil
}
if len(trimmed) > 0 && trimmed[0] == '"' {
var ref string
if err := json.Unmarshal(trimmed, &ref); err != nil {
return err
}
s.Reference = &ref
s.Inline = nil
return nil
}
var raw map[string]json.RawMessage
if err := json.Unmarshal(trimmed, &raw); err != nil {
return fmt.Errorf("unmarshal agent mcp server spec: %w", err)
}
inline := make(map[string]mcp.ServerConfig, len(raw))
for name, rawConfig := range raw {
cfg, err := unmarshalAgentProcessServerConfig(rawConfig)
if err != nil {
return fmt.Errorf("unmarshal agent mcp server %q: %w", name, err)
}
inline[name] = cfg
}
s.Reference = nil
s.Inline = inline
return nil
}
func unmarshalAgentProcessServerConfig(data []byte) (mcp.ServerConfig, error) {
var probe struct {
Type mcp.ServerType `json:"type"`
}
if err := json.Unmarshal(data, &probe); err != nil {
return nil, fmt.Errorf("decode mcp server type: %w", err)
}
switch probe.Type {
case mcp.ServerTypeStdio:
var cfg mcp.StdioServerConfig
if err := json.Unmarshal(data, &cfg); err != nil {
return nil, err
}
return &cfg, nil
case mcp.ServerTypeSSE:
var cfg mcp.SSEServerConfig
if err := json.Unmarshal(data, &cfg); err != nil {
return nil, err
}
return &cfg, nil
case mcp.ServerTypeHTTP:
var cfg mcp.HTTPServerConfig
if err := json.Unmarshal(data, &cfg); err != nil {
return nil, err
}
return &cfg, nil
case mcp.ServerTypeWS:
var cfg mcp.WebSocketServerConfig
if err := json.Unmarshal(data, &cfg); err != nil {
return nil, err
}
return &cfg, nil
case "":
return nil, fmt.Errorf("missing mcp server type")
default:
return nil, fmt.Errorf("unsupported agent mcp server transport %q", probe.Type)
}
}
// AgentMCPServerReference creates a reference spec for an existing MCP server.
func AgentMCPServerReference(name string) AgentMCPServerSpec {
return AgentMCPServerSpec{Reference: &name}
}
// AgentMCPServerInline creates an inline spec for a single MCP server config.
func AgentMCPServerInline(name string, cfg mcp.ServerConfig) AgentMCPServerSpec {
return AgentMCPServerSpec{Inline: map[string]mcp.ServerConfig{name: cfg}}
}
// AgentEffort encodes the upstream agent effort union: named level or integer.
type AgentEffort struct {
level *Effort
value *int
}
// NewAgentEffortLevel creates an agent effort value from a named level.
func NewAgentEffortLevel(level Effort) *AgentEffort {
return &AgentEffort{level: &level}
}
// NewAgentEffortValue creates an agent effort value from an integer.
func NewAgentEffortValue(value int) *AgentEffort {
return &AgentEffort{value: &value}
}
// Level returns the named effort level when present.
func (e *AgentEffort) Level() *Effort {
if e == nil {
return nil
}
return e.level
}
// Value returns the numeric effort value when present.
func (e *AgentEffort) Value() *int {
if e == nil {
return nil
}
return e.value
}
// MarshalJSON preserves the upstream union wire shape.
func (e AgentEffort) MarshalJSON() ([]byte, error) {
if e.level != nil && e.value != nil {
return nil, fmt.Errorf("agent effort cannot contain both level and numeric value")
}
if e.level != nil {
return json.Marshal(*e.level)
}
if e.value != nil {
return json.Marshal(*e.value)
}
return []byte("null"), nil
}
// UnmarshalJSON decodes the upstream union wire shape.
func (e *AgentEffort) UnmarshalJSON(data []byte) error {
trimmed := bytes.TrimSpace(data)
if bytes.Equal(trimmed, []byte("null")) {
*e = AgentEffort{}
return nil
}
if len(trimmed) > 0 && trimmed[0] == '"' {
var level Effort
if err := json.Unmarshal(trimmed, &level); err != nil {
return err
}
e.level = &level
e.value = nil
return nil
}
var value int
if err := json.Unmarshal(trimmed, &value); err != nil {
return fmt.Errorf("unmarshal agent effort: %w", err)
}
e.value = &value
e.level = nil
return nil
}
// AgentDefinition defines a custom agent configuration.
type AgentDefinition struct {
Description string `json:"description"`
Prompt string `json:"prompt"`
Tools []string `json:"tools,omitempty"`
DisallowedTools []string `json:"disallowedTools,omitempty"`
Model *string `json:"model,omitempty"` // Any valid model identifier
McpServers []AgentMCPServerSpec `json:"mcpServers,omitempty"`
CriticalSystemReminderExperimental *string `json:"criticalSystemReminder_EXPERIMENTAL,omitempty"` //nolint:tagliatelle // upstream schema uses experimental suffix
Skills []string `json:"skills,omitempty"`
InitialPrompt string `json:"initialPrompt,omitempty"`
MaxTurns *int `json:"maxTurns,omitempty"`
Background *bool `json:"background,omitempty"`
Memory *string `json:"memory,omitempty"`
Effort *AgentEffort `json:"effort,omitempty"`
PermissionMode *permission.Mode `json:"permissionMode,omitempty"`
}
// SystemPromptPreset defines a system prompt preset configuration.
type SystemPromptPreset struct {
Type string `json:"type"` // "preset"
Preset string `json:"preset"` // "claude_code"
Append *string `json:"append,omitempty"`
ExcludeDynamicSections *bool `json:"excludeDynamicSections,omitempty"` // strip per-user dynamic sections for cross-user prompt caching
}
// PluginConfig configures a plugin to load.
type PluginConfig struct {
Type string `json:"type"` // "local"
Path string `json:"path"`
}
// ToolsConfig is an interface for configuring available tools.
// It represents either a list of tool names or a preset configuration.
type ToolsConfig interface {
toolsConfig() // marker method
}
// ToolsList is a list of tool names to make available.
type ToolsList []string
func (ToolsList) toolsConfig() {}
func (*ToolsPreset) toolsConfig() {}