This repository was archived by the owner on Sep 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathmain.go
More file actions
319 lines (294 loc) · 8.93 KB
/
main.go
File metadata and controls
319 lines (294 loc) · 8.93 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
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/opencode-ai/opencode/internal/config"
"github.com/opencode-ai/opencode/internal/llm/models"
)
// JSONSchemaType represents a JSON Schema type
type JSONSchemaType struct {
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Properties map[string]any `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
AdditionalProperties any `json:"additionalProperties,omitempty"`
Enum []any `json:"enum,omitempty"`
Items map[string]any `json:"items,omitempty"`
OneOf []map[string]any `json:"oneOf,omitempty"`
AnyOf []map[string]any `json:"anyOf,omitempty"`
Default any `json:"default,omitempty"`
}
func main() {
schema := generateSchema()
// Pretty print the schema
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
if err := encoder.Encode(schema); err != nil {
fmt.Fprintf(os.Stderr, "Error encoding schema: %v\n", err)
os.Exit(1)
}
}
func generateSchema() map[string]any {
schema := map[string]any{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "OpenCode Configuration",
"description": "Configuration schema for the OpenCode application",
"type": "object",
"properties": map[string]any{},
}
// Add Data configuration
schema["properties"].(map[string]any)["data"] = map[string]any{
"type": "object",
"description": "Storage configuration",
"properties": map[string]any{
"directory": map[string]any{
"type": "string",
"description": "Directory where application data is stored",
"default": ".opencode",
},
},
"required": []string{"directory"},
}
// Add working directory
schema["properties"].(map[string]any)["wd"] = map[string]any{
"type": "string",
"description": "Working directory for the application",
}
// Add debug flags
schema["properties"].(map[string]any)["debug"] = map[string]any{
"type": "boolean",
"description": "Enable debug mode",
"default": false,
}
schema["properties"].(map[string]any)["debugLSP"] = map[string]any{
"type": "boolean",
"description": "Enable LSP debug mode",
"default": false,
}
schema["properties"].(map[string]any)["contextPaths"] = map[string]any{
"type": "array",
"description": "Context paths for the application",
"items": map[string]any{
"type": "string",
},
"default": []string{
".github/copilot-instructions.md",
".cursorrules",
".cursor/rules/",
"CLAUDE.md",
"CLAUDE.local.md",
"opencode.md",
"opencode.local.md",
"OpenCode.md",
"OpenCode.local.md",
"OPENCODE.md",
"OPENCODE.local.md",
},
}
schema["properties"].(map[string]any)["tui"] = map[string]any{
"type": "object",
"description": "Terminal User Interface configuration",
"properties": map[string]any{
"theme": map[string]any{
"type": "string",
"description": "TUI theme name",
"default": "opencode",
"enum": []string{
"opencode",
"catppuccin",
"dracula",
"flexoki",
"gruvbox",
"monokai",
"onedark",
"tokyonight",
"tron",
},
},
},
}
// Add MCP servers
schema["properties"].(map[string]any)["mcpServers"] = map[string]any{
"type": "object",
"description": "Model Control Protocol server configurations",
"additionalProperties": map[string]any{
"type": "object",
"description": "MCP server configuration",
"properties": map[string]any{
"command": map[string]any{
"type": "string",
"description": "Command to execute for the MCP server",
},
"env": map[string]any{
"type": "array",
"description": "Environment variables for the MCP server",
"items": map[string]any{
"type": "string",
},
},
"args": map[string]any{
"type": "array",
"description": "Command arguments for the MCP server",
"items": map[string]any{
"type": "string",
},
},
"type": map[string]any{
"type": "string",
"description": "Type of MCP server",
"enum": []string{"stdio", "sse"},
"default": "stdio",
},
"url": map[string]any{
"type": "string",
"description": "URL for SSE type MCP servers",
},
"headers": map[string]any{
"type": "object",
"description": "HTTP headers for SSE type MCP servers",
"additionalProperties": map[string]any{
"type": "string",
},
},
},
"required": []string{"command"},
},
}
// Add providers
providerSchema := map[string]any{
"type": "object",
"description": "LLM provider configurations",
"additionalProperties": map[string]any{
"type": "object",
"description": "Provider configuration",
"properties": map[string]any{
"apiKey": map[string]any{
"type": "string",
"description": "API key for the provider",
},
"disabled": map[string]any{
"type": "boolean",
"description": "Whether the provider is disabled",
"default": false,
},
"baseURL": map[string]any{
"type": "string",
"description": "Base URL for the provider instead of default one",
},
"headers": map[string]any{
"type": "object",
"description": "Extra headers to attach to request",
"additionalProperties": map[string]any{
"type": "string",
},
},
},
},
}
// Add known providers
knownProviders := []string{
string(models.ProviderAnthropic),
string(models.ProviderOpenAI),
string(models.ProviderGemini),
string(models.ProviderGROQ),
string(models.ProviderOpenRouter),
string(models.ProviderBedrock),
string(models.ProviderAzure),
string(models.ProviderVertexAI),
}
providerSchema["additionalProperties"].(map[string]any)["properties"].(map[string]any)["provider"] = map[string]any{
"type": "string",
"description": "Provider type",
"enum": knownProviders,
}
schema["properties"].(map[string]any)["providers"] = providerSchema
// Add agents
agentSchema := map[string]any{
"type": "object",
"description": "Agent configurations",
"additionalProperties": map[string]any{
"type": "object",
"description": "Agent configuration",
"properties": map[string]any{
"model": map[string]any{
"type": "string",
"description": "Model ID for the agent",
},
"maxTokens": map[string]any{
"type": "integer",
"description": "Maximum tokens for the agent",
"minimum": 1,
},
"reasoningEffort": map[string]any{
"type": "string",
"description": "Reasoning effort for models that support it (OpenAI, Anthropic)",
"enum": []string{"low", "medium", "high"},
},
},
"required": []string{"model"},
},
}
// Add model enum
modelEnum := []string{}
for modelID := range models.SupportedModels {
modelEnum = append(modelEnum, string(modelID))
}
agentSchema["additionalProperties"].(map[string]any)["properties"].(map[string]any)["model"].(map[string]any)["enum"] = modelEnum
// Add specific agent properties
agentProperties := map[string]any{}
knownAgents := []string{
string(config.AgentCoder),
string(config.AgentTask),
string(config.AgentTitle),
}
for _, agentName := range knownAgents {
agentProperties[agentName] = map[string]any{
"$ref": "#/definitions/agent",
}
}
// Create a combined schema that allows both specific agents and additional ones
combinedAgentSchema := map[string]any{
"type": "object",
"description": "Agent configurations",
"properties": agentProperties,
"additionalProperties": agentSchema["additionalProperties"],
}
schema["properties"].(map[string]any)["agents"] = combinedAgentSchema
schema["definitions"] = map[string]any{
"agent": agentSchema["additionalProperties"],
}
// Add LSP configuration
schema["properties"].(map[string]any)["lsp"] = map[string]any{
"type": "object",
"description": "Language Server Protocol configurations",
"additionalProperties": map[string]any{
"type": "object",
"description": "LSP configuration for a language",
"properties": map[string]any{
"disabled": map[string]any{
"type": "boolean",
"description": "Whether the LSP is disabled",
"default": false,
},
"command": map[string]any{
"type": "string",
"description": "Command to execute for the LSP server",
},
"args": map[string]any{
"type": "array",
"description": "Command arguments for the LSP server",
"items": map[string]any{
"type": "string",
},
},
"options": map[string]any{
"type": "object",
"description": "Additional options for the LSP server",
},
},
"required": []string{"command"},
},
}
return schema
}