forked from kernel/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.go
More file actions
317 lines (295 loc) · 10.1 KB
/
templates.go
File metadata and controls
317 lines (295 loc) · 10.1 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
package create
import (
"fmt"
"slices"
"sort"
)
// Template key constants
const (
TemplateSampleApp = "sample-app"
TemplateCaptchaSolver = "captcha-solver"
TemplateAnthropicComputerUse = "anthropic-computer-use"
TemplateOpenAIComputerUse = "openai-computer-use"
TemplateMagnitude = "magnitude"
TemplateGeminiComputerUse = "gemini-computer-use"
TemplateBrowserUse = "browser-use"
TemplateStagehand = "stagehand"
TemplateOpenAGIComputerUse = "openagi-computer-use"
TemplateClaudeAgentSDK = "claude-agent-sdk"
TemplateYutoriComputerUse = "yutori"
TemplateTzafonComputerUse = "tzafon"
)
type TemplateInfo struct {
Name string
Description string
Languages []string
}
type TemplateKeyValue struct {
Key string
Value string
}
type TemplateKeyValues []TemplateKeyValue
var Templates = map[string]TemplateInfo{
TemplateSampleApp: {
Name: "Sample App",
Description: "Implements a basic Kernel app",
Languages: []string{LanguageTypeScript, LanguagePython},
},
TemplateCaptchaSolver: {
Name: "CAPTCHA Solver",
Description: "Demo of Kernel's auto-CAPTCHA solving capability",
Languages: []string{LanguageTypeScript, LanguagePython},
},
TemplateAnthropicComputerUse: {
Name: "Anthropic Computer Use",
Description: "Implements an Anthropic computer use agent",
Languages: []string{LanguageTypeScript, LanguagePython},
},
TemplateOpenAIComputerUse: {
Name: "OpenAI Computer Use",
Description: "Implements an OpenAI computer use agent",
Languages: []string{LanguageTypeScript, LanguagePython},
},
TemplateMagnitude: {
Name: "Magnitude",
Description: "Implements the Magnitude.run SDK",
Languages: []string{LanguageTypeScript},
},
TemplateGeminiComputerUse: {
Name: "Gemini Computer Use",
Description: "Implements a Gemini computer use agent",
Languages: []string{LanguageTypeScript, LanguagePython},
},
TemplateBrowserUse: {
Name: "Browser Use",
Description: "Implements Browser Use SDK",
Languages: []string{LanguagePython},
},
TemplateStagehand: {
Name: "Stagehand",
Description: "Implements the Stagehand v3 SDK",
Languages: []string{LanguageTypeScript},
},
TemplateOpenAGIComputerUse: {
Name: "OpenAGI Computer Use",
Description: "Implements an OpenAGI computer use agent",
Languages: []string{LanguagePython},
},
TemplateClaudeAgentSDK: {
Name: "Claude Agent SDK",
Description: "Implements a Claude Agent SDK browser automation agent",
Languages: []string{LanguageTypeScript, LanguagePython},
},
TemplateYutoriComputerUse: {
Name: "Yutori n1 Computer Use",
Description: "Implements a Yutori n1 computer use agent",
Languages: []string{LanguageTypeScript, LanguagePython},
},
TemplateTzafonComputerUse: {
Name: "Tzafon Northstar Computer Use",
Description: "Implements a Tzafon Northstar CUA Fast computer use agent",
Languages: []string{LanguageTypeScript, LanguagePython},
},
}
// GetSupportedTemplatesForLanguage returns a list of all supported template names for a given language
func GetSupportedTemplatesForLanguage(language string) TemplateKeyValues {
templates := make(TemplateKeyValues, 0, len(Templates))
for tn := range Templates {
if slices.Contains(Templates[tn].Languages, language) {
templates = append(templates, TemplateKeyValue{
Key: tn,
Value: fmt.Sprintf("%s - %s", Templates[tn].Name, Templates[tn].Description),
})
}
}
sort.Slice(templates, func(i, j int) bool {
// Put computer-use templates first (Anthropic/OpenAI/Gemini), then sort alphabetically.
priority := func(key string) int {
switch key {
case TemplateAnthropicComputerUse:
return 0
case TemplateOpenAIComputerUse:
return 1
case TemplateGeminiComputerUse:
return 2
case TemplateYutoriComputerUse:
return 3
case TemplateTzafonComputerUse:
return 4
default:
return 10
}
}
pi, pj := priority(templates[i].Key), priority(templates[j].Key)
if pi != pj {
return pi < pj
}
return templates[i].Key < templates[j].Key
})
return templates
}
// GetTemplateDisplayValues extracts display values from TemplateKeyValue slice
func (tkv TemplateKeyValues) GetTemplateDisplayValues() []string {
options := make([]string, len(tkv))
for i, kv := range tkv {
options[i] = kv.Value
}
return options
}
// GetTemplateKeyFromValue maps the selected display value back to the template key
func (tkv TemplateKeyValues) GetTemplateKeyFromValue(selectedValue string) (string, error) {
for _, kv := range tkv {
if kv.Value == selectedValue {
return kv.Key, nil
}
}
return "", fmt.Errorf("template not found: %s", selectedValue)
}
// ContainsKey checks if a template key exists in the TemplateKeyValues
func (tkv TemplateKeyValues) ContainsKey(key string) bool {
for _, kv := range tkv {
if kv.Key == key {
return true
}
}
return false
}
type DeployConfig struct {
EntryPoint string
NeedsEnvFile bool
InvokeCommand string
}
var Commands = map[string]map[string]DeployConfig{
LanguageTypeScript: {
TemplateSampleApp: {
EntryPoint: "index.ts",
NeedsEnvFile: false,
InvokeCommand: `kernel invoke ts-basic get-page-title --payload '{"url": "https://www.google.com"}'`,
},
TemplateCaptchaSolver: {
EntryPoint: "index.ts",
NeedsEnvFile: false,
InvokeCommand: "kernel invoke ts-captcha-solver test-captcha-solver",
},
TemplateStagehand: {
EntryPoint: "index.ts",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke ts-stagehand teamsize-task --payload '{"company": "Kernel"}'`,
},
TemplateAnthropicComputerUse: {
EntryPoint: "index.ts",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke ts-anthropic-cua cua-task --payload '{"query": "Navigate to http://magnitasks.com and click on Tasks in the sidebar"}'`,
},
TemplateMagnitude: {
EntryPoint: "index.ts",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke ts-magnitude mag-url-extract --payload '{"url": "https://en.wikipedia.org/wiki/Special:Random"}'`,
},
TemplateOpenAIComputerUse: {
EntryPoint: "index.ts",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke ts-openai-cua cua-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 5 articles"}'`,
},
TemplateGeminiComputerUse: {
EntryPoint: "index.ts",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke ts-gemini-cua cua-task --payload '{"query": "Navigate to http://magnitasks.com and click on Tasks in the sidebar"}'`,
},
TemplateClaudeAgentSDK: {
EntryPoint: "index.ts",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke ts-claude-agent-sdk agent-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 3 stories"}'`,
},
TemplateYutoriComputerUse: {
EntryPoint: "index.ts",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke ts-yutori-cua cua-task --payload '{"query": "Navigate to https://example.com and describe the page"}'`,
},
TemplateTzafonComputerUse: {
EntryPoint: "index.ts",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke ts-tzafon-cua cua-task --payload '{"query": "Go to wikipedia.org and search for Alan Turing"}'`,
},
},
LanguagePython: {
TemplateSampleApp: {
EntryPoint: "main.py",
NeedsEnvFile: false,
InvokeCommand: `kernel invoke python-basic get-page-title --payload '{"url": "https://www.google.com"}'`,
},
TemplateCaptchaSolver: {
EntryPoint: "main.py",
NeedsEnvFile: false,
InvokeCommand: "kernel invoke python-captcha-solver test-captcha-solver",
},
TemplateBrowserUse: {
EntryPoint: "main.py",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke python-bu bu-task --payload '{"task": "Compare the price of gpt-4o and DeepSeek-V3"}'`,
},
TemplateAnthropicComputerUse: {
EntryPoint: "main.py",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke python-anthropic-cua cua-task --payload '{"query": "Navigate to http://magnitasks.com and click on Tasks in the sidebar"}'`,
},
TemplateOpenAIComputerUse: {
EntryPoint: "main.py",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke python-openai-cua cua-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 5 articles"}'`,
},
TemplateOpenAGIComputerUse: {
EntryPoint: "main.py",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke python-openagi-cua openagi-default-task -p '{"instruction": "Navigate to https://agiopen.org and click the What is Computer Use? button", "record_replay": "True"}'`,
},
TemplateClaudeAgentSDK: {
EntryPoint: "main.py",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke py-claude-agent-sdk agent-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 3 stories"}'`,
},
TemplateGeminiComputerUse: {
EntryPoint: "main.py",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke python-gemini-cua cua-task --payload '{"query": "Navigate to http://magnitasks.com and click on Tasks in the sidebar"}'`,
},
TemplateYutoriComputerUse: {
EntryPoint: "main.py",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke python-yutori-cua cua-task --payload '{"query": "Navigate to https://example.com and describe the page"}'`,
},
TemplateTzafonComputerUse: {
EntryPoint: "main.py",
NeedsEnvFile: true,
InvokeCommand: `kernel invoke python-tzafon-cua cua-task --payload '{"query": "Go to wikipedia.org and search for Alan Turing"}'`,
},
},
}
// GetDeployCommand returns the full deploy command string for a given language and template
func GetDeployCommand(language, template string) string {
langCommands, ok := Commands[language]
if !ok {
return ""
}
config, ok := langCommands[template]
if !ok {
return ""
}
cmd := "kernel deploy " + config.EntryPoint
if config.NeedsEnvFile {
cmd += " --env-file .env"
}
return cmd
}
// GetInvokeSample returns the sample invoke command for a given language and template
func GetInvokeSample(language, template string) string {
langSamples, ok := Commands[language]
if !ok {
return ""
}
config, ok := langSamples[template]
if !ok {
return ""
}
return config.InvokeCommand
}