Skip to content

Commit 46fb6f3

Browse files
authored
Remove API key copy and move to kernel login (#52)
* init * env and login * bugbot
1 parent 801f79f commit 46fb6f3

File tree

8 files changed

+90
-78
lines changed

8 files changed

+90
-78
lines changed

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<a href="https://x.com/rfgarcia"><img src="https://img.shields.io/twitter/follow/rfgarcia" alt="Follow @rfgarcia"></a>
88
</p>
99

10-
A CLI tool to create the scaffolding for a new Kernel applications. This tool helps you get started with building browser automation applications using Kernel's platform.
10+
A CLI tool to create the scaffolding for a new Kernel applications. This tool helps you get started with building browser automation applications using Kernel's platform.
1111

1212
## Features
1313

@@ -52,30 +52,36 @@ create-kernel-app [app-name] [options]
5252
### Examples
5353

5454
Create a TypeScript application with a sample app:
55+
5556
```bash
5657
npx @onkernel/create-kernel-app my-app --language typescript --template sample-app
5758
```
5859

5960
Create a Typescript application with Stagehand template:
61+
6062
```bash
6163
npx @onkernel/create-kernel-app my-app --language typescript --template stagehand
6264
```
6365

6466
Create a Typescript application with Computer Use template:
67+
6568
```bash
6669
npx @onkernel/create-kernel-app my-app --language typescript --template computer-use
6770
```
6871

6972
Create a Python application with a sample app:
73+
7074
```bash
7175
npx @onkernel/create-kernel-app my-app --language python --template sample-app
7276
```
7377

7478
Create a Python application with Browser Use template:
79+
7580
```bash
7681
npx @onkernel/create-kernel-app my-app --language python --template browser-use
7782
```
78-
```
83+
84+
````
7985
8086
## Next Steps
8187
@@ -84,18 +90,21 @@ After creating your application:
8490
1. Navigate to your project directory:
8591
```bash
8692
cd my-app
87-
```
93+
````
8894

8995
2. Set up your environment:
96+
9097
- For TypeScript: `npm install`
9198
- For Python: `uv venv && source .venv/bin/activate && uv sync`
9299

93100
3. Set your Kernel API key:
101+
94102
```bash
95-
export KERNEL_API_KEY=<YOUR_API_KEY>
103+
kernel login # or: export KERNEL_API_KEY=<YOUR_API_KEY>
96104
```
97105

98106
4. Deploy your application:
107+
99108
```bash
100109
# Typscript
101110
kernel deploy index.ts # --env OPENAI_API_KEY=XXX if Stagehand; --env ANTHROPIC_API_KEY=XXX if Computer Use
@@ -107,6 +116,7 @@ kernel deploy main.py # --env OPENAI_API_KEY=XXX if Browser Use
107116
If deploying an app that requires environment variables, make sure to [set them](https://docs.onkernel.com/launch/deploy#environment-variables) when you `deploy`.
108117

109118
5. Invoke your application:
119+
110120
```bash
111121
# Typescript + Sample App
112122
kernel invoke ts-basic get-page-title --payload '{"url": "https://www.google.com"}'
@@ -134,18 +144,19 @@ kernel invoke python-cua cua-task --payload '{"task": "Get current market price
134144

135145
These are the sample apps currently available when you run `npx @onkernel/create-kernel-app`:
136146

137-
| Template | Description | Framework | Query Parameters |
138-
|----------|-------------|-----------|------------------|
139-
| **sample-app** | Returns the page title of a specified URL | Playwright | `{ url }` |
140-
| **browser-use** | Completes a specified task | Browser Use | `{ task }` |
141-
| **stagehand** | Returns the first result of a specified Google search | Stagehand | `{ query }` |
142-
| **advanced-sample** | Implements sample apps using advanced Kernel configs | n/a |
143-
| **computer-use** | Implements a prompt loop | Anthropic Computer Use API | `{ query }` |
144-
| **cua** | Implements the OpenAI Computer Using Agent (CUA) | OpenAI CUA | `{ task }` |
147+
| Template | Description | Framework | Query Parameters |
148+
| ------------------- | ----------------------------------------------------- | -------------------------- | ---------------- |
149+
| **sample-app** | Returns the page title of a specified URL | Playwright | `{ url }` |
150+
| **browser-use** | Completes a specified task | Browser Use | `{ task }` |
151+
| **stagehand** | Returns the first result of a specified Google search | Stagehand | `{ query }` |
152+
| **advanced-sample** | Implements sample apps using advanced Kernel configs | n/a |
153+
| **computer-use** | Implements a prompt loop | Anthropic Computer Use API | `{ query }` |
154+
| **cua** | Implements the OpenAI Computer Using Agent (CUA) | OpenAI CUA | `{ task }` |
145155

146156
## Documentation
147157

148158
For more information about Kernel and its features, visit:
159+
149160
- [Kernel Documentation](https://docs.onkernel.com/quickstart)
150161
- [Kernel Homepage](https://onkernel.com)
151162

@@ -156,4 +167,3 @@ Contributions are welcome! Please feel free to submit a pull request. See [Contr
156167
## License
157168

158169
MIT © [Kernel](https://onkernel.com)
159-

index.ts

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ const TEMPLATES: Record<TemplateKey, TemplateInfo> = {
6666
},
6767
[TEMPLATE_ADVANCED_SAMPLE]: {
6868
name: "Advanced Samples",
69-
description:
70-
"Implements sample actions with advanced Kernel configs",
69+
description: "Implements sample actions with advanced Kernel configs",
7170
languages: [LANGUAGE_TYPESCRIPT, LANGUAGE_PYTHON],
7271
},
7372
[TEMPLATE_COMPUTER_USE]: {
@@ -91,8 +90,7 @@ const INVOKE_SAMPLES: Record<
9190
'kernel invoke ts-basic get-page-title --payload \'{"url": "https://www.google.com"}\'',
9291
[TEMPLATE_STAGEHAND]:
9392
'kernel invoke ts-stagehand stagehand-task --payload \'{"query": "Best wired earbuds"}\'',
94-
[TEMPLATE_ADVANCED_SAMPLE]:
95-
'kernel invoke ts-advanced test-captcha-solver',
93+
[TEMPLATE_ADVANCED_SAMPLE]: "kernel invoke ts-advanced test-captcha-solver",
9694
[TEMPLATE_COMPUTER_USE]:
9795
'kernel invoke ts-cu cu-task --payload \'{"query": "Return the first url of a search result for NYC restaurant reviews Pete Wells"}\'',
9896
[TEMPLATE_CUA]:
@@ -104,7 +102,7 @@ const INVOKE_SAMPLES: Record<
104102
[TEMPLATE_BROWSER_USE]:
105103
'kernel invoke python-bu bu-task --payload \'{"task": "Compare the price of gpt-4o and DeepSeek-V3"}\'',
106104
[TEMPLATE_ADVANCED_SAMPLE]:
107-
'kernel invoke python-advanced test-captcha-solver',
105+
"kernel invoke python-advanced test-captcha-solver",
108106
[TEMPLATE_COMPUTER_USE]:
109107
'kernel invoke python-cu cu-task --payload \'{"query": "Return the first url of a search result for NYC restaurant reviews Pete Wells"}\'',
110108
[TEMPLATE_CUA]:
@@ -117,28 +115,18 @@ const REGISTERED_APP_NAMES: Record<
117115
Partial<Record<TemplateKey, string>>
118116
> = {
119117
[LANGUAGE_TYPESCRIPT]: {
120-
[TEMPLATE_SAMPLE_APP]:
121-
'ts-basic',
122-
[TEMPLATE_STAGEHAND]:
123-
'ts-stagehand',
124-
[TEMPLATE_ADVANCED_SAMPLE]:
125-
'ts-advanced',
126-
[TEMPLATE_COMPUTER_USE]:
127-
'ts-cu',
128-
[TEMPLATE_CUA]:
129-
'ts-cua',
118+
[TEMPLATE_SAMPLE_APP]: "ts-basic",
119+
[TEMPLATE_STAGEHAND]: "ts-stagehand",
120+
[TEMPLATE_ADVANCED_SAMPLE]: "ts-advanced",
121+
[TEMPLATE_COMPUTER_USE]: "ts-cu",
122+
[TEMPLATE_CUA]: "ts-cua",
130123
},
131124
[LANGUAGE_PYTHON]: {
132-
[TEMPLATE_SAMPLE_APP]:
133-
'python-basic',
134-
[TEMPLATE_BROWSER_USE]:
135-
'python-bu',
136-
[TEMPLATE_ADVANCED_SAMPLE]:
137-
'python-advanced',
138-
[TEMPLATE_COMPUTER_USE]:
139-
'python-cu',
140-
[TEMPLATE_CUA]:
141-
'python-cua',
125+
[TEMPLATE_SAMPLE_APP]: "python-basic",
126+
[TEMPLATE_BROWSER_USE]: "python-bu",
127+
[TEMPLATE_ADVANCED_SAMPLE]: "python-advanced",
128+
[TEMPLATE_COMPUTER_USE]: "python-cu",
129+
[TEMPLATE_CUA]: "python-cua",
142130
},
143131
};
144132

@@ -311,14 +299,14 @@ function copyTemplateFiles(
311299
fs.copySync(templatePath, appPath, {
312300
filter: (src, dest) => {
313301
const filename = path.basename(src);
314-
if (filename === '_gitignore') {
302+
if (filename === "_gitignore") {
315303
fs.copyFileSync(src, dest);
316304
// Rename it to .gitignore
317-
fs.renameSync(dest, path.join(path.dirname(dest), '.gitignore'));
305+
fs.renameSync(dest, path.join(path.dirname(dest), ".gitignore"));
318306
return false; // Skip the original copy since we handled it
319307
}
320308
return true; // Copy all other files normally
321-
}
309+
},
322310
});
323311
}
324312

@@ -363,15 +351,18 @@ function printNextSteps(
363351
): void {
364352
// Determine which sample command to show based on language and template
365353
const deployCommand =
366-
language === LANGUAGE_TYPESCRIPT && (template === TEMPLATE_SAMPLE_APP || template === TEMPLATE_ADVANCED_SAMPLE)
354+
language === LANGUAGE_TYPESCRIPT &&
355+
(template === TEMPLATE_SAMPLE_APP || template === TEMPLATE_ADVANCED_SAMPLE)
367356
? "kernel deploy index.ts"
368357
: language === LANGUAGE_TYPESCRIPT && template === TEMPLATE_STAGEHAND
369358
? "kernel deploy index.ts --env OPENAI_API_KEY=XXX"
370359
: language === LANGUAGE_TYPESCRIPT && template === TEMPLATE_COMPUTER_USE
371360
? "kernel deploy index.ts --env ANTHROPIC_API_KEY=XXX"
372361
: language === LANGUAGE_TYPESCRIPT && template === TEMPLATE_CUA
373362
? "kernel deploy index.ts --env OPENAI_API_KEY=XXX"
374-
: language === LANGUAGE_PYTHON && (template === TEMPLATE_SAMPLE_APP || template === TEMPLATE_ADVANCED_SAMPLE)
363+
: language === LANGUAGE_PYTHON &&
364+
(template === TEMPLATE_SAMPLE_APP ||
365+
template === TEMPLATE_ADVANCED_SAMPLE)
375366
? "kernel deploy main.py"
376367
: language === LANGUAGE_PYTHON && template === TEMPLATE_BROWSER_USE
377368
? "kernel deploy main.py --env OPENAI_API_KEY=XXX"
@@ -388,11 +379,11 @@ function printNextSteps(
388379
Next steps:
389380
brew install onkernel/tap/kernel
390381
cd ${appName}
391-
export KERNEL_API_KEY=<YOUR_API_KEY>
382+
kernel login # or: export KERNEL_API_KEY=<YOUR_API_KEY>
392383
${deployCommand}
393384
${INVOKE_SAMPLES[language][template]}
394385
# Do this in a separate tab
395-
export KERNEL_API_KEY=<YOUR_API_KEY>
386+
kernel login # or: export KERNEL_API_KEY=<YOUR_API_KEY>
396387
kernel logs ${REGISTERED_APP_NAMES[language][template]} --follow
397388
`)
398389
);

templates/python/advanced-sample/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
None
1616
1717
Invoke this via CLI:
18-
export KERNEL_API_KEY=<your_api_key>
18+
kernel login # or: export KERNEL_API_KEY=<your_api_key>
1919
kernel deploy main.py # If you haven't already deployed this app
2020
kernel invoke py-advanced test_captcha_solver
2121
kernel logs py-advanced -f # Open in separate tab
@@ -36,7 +36,7 @@ async def test_captcha_solver(ctx: kernel.KernelContext) -> None:
3636
page = context.pages[0] if context.pages else await context.new_page()
3737

3838
# Access the live view. Retrieve this live_view_url from the Kernel logs in your CLI:
39-
# export KERNEL_API_KEY=<Your API key>
39+
# kernel login # or: export KERNEL_API_KEY=<Your API key>
4040
# kernel logs py-advanced --follow
4141
print("Kernel browser live view url: ", kernel_browser.browser_live_view_url)
4242

templates/python/cua/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Returns:
1616
An answer to the task, elapsed time and optionally the messages stack
1717
Invoke this via CLI:
18-
export KERNEL_API_KEY=<your_api_key>
18+
kernel login # or: export KERNEL_API_KEY=<your_api_key>
1919
kernel deploy main.py -e OPENAI_API_KEY=XXXXX --force
2020
kernel invoke python-cua cua-task -p '{"task":"go to https://news.ycombinator.com and list top 5 articles"}'
2121
kernel logs python-cua -f # Open in separate tab

templates/python/sample-app/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Returns:
1818
A dictionary containing the page title
1919
Invoke this via CLI:
20-
export KERNEL_API_KEY=<your_api_key>
20+
kernel login # or: export KERNEL_API_KEY=<your_api_key>
2121
kernel deploy main.py # If you haven't already deployed this app
2222
kernel invoke python-basic get-page-title -p '{"url": "https://www.google.com"}'
2323
kernel logs python-basic -f # Open in separate tab
@@ -74,7 +74,7 @@ async def get_page_title(ctx: kernel.KernelContext, input_data: PageTitleInput)
7474
Returns:
7575
A dictionary containing the browser live view url
7676
Invoke this via CLI:
77-
export KERNEL_API_KEY=<your_api_key>
77+
kernel login # or: export KERNEL_API_KEY=<your_api_key>
7878
kernel deploy main.py # If you haven't already deployed this app
7979
kernel invoke python-basic create-persisted-browser
8080
kernel logs python-basic -f # Open in separate tab

templates/typescript/advanced-sample/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ const app = kernel.app("ts-advanced");
88
/**
99
* Example showing Kernel's auto-CAPTCHA solver
1010
* Visit the live view url to see the Kernel browser auto-solve the CAPTCHA on the site
11-
*
11+
*
1212
* Args:
1313
* ctx: Kernel context containing invocation information
1414
* Returns:
1515
* None
16-
*
16+
*
1717
* Invoke this via CLI:
18-
* export KERNEL_API_KEY=<your_api_key>
18+
* kernel login # or: export KERNEL_API_KEY=<your_api_key>
1919
* kernel deploy index.ts # If you haven't already deployed this app
2020
* kernel invoke ts-advanced test-captcha-solver
2121
* kernel logs ts-advanced -f # Open in separate tab
2222
*/
23-
app.action("test-captcha-solver", async(ctx: KernelContext): Promise<void> => {
24-
23+
app.action("test-captcha-solver", async (ctx: KernelContext): Promise<void> => {
2524
const kernelBrowser = await kernel.browsers.create({
2625
invocation_id: ctx.invocation_id,
2726
stealth: true,
@@ -32,15 +31,18 @@ app.action("test-captcha-solver", async(ctx: KernelContext): Promise<void> => {
3231
const browser = await chromium.connectOverCDP(kernelBrowser.cdp_ws_url);
3332

3433
// Access the live view. Retrieve this live_view_url from the Kernel logs in your CLI:
35-
// export KERNEL_API_KEY=<Your API key>
34+
// kernel login # or: export KERNEL_API_KEY=<Your API key>
3635
// kernel logs ts-advanced --follow
37-
console.log("Kernel browser live view url: ", kernelBrowser.browser_live_view_url);
36+
console.log(
37+
"Kernel browser live view url: ",
38+
kernelBrowser.browser_live_view_url
39+
);
3840

3941
// Navigate to a site with a CAPTCHA
40-
const context = await browser.contexts()[0] || (await browser.newContext());
41-
const page = await context.pages()[0] || (await context.newPage());
42+
const context = browser.contexts()[0] || (await browser.newContext());
43+
const page = context.pages()[0] || (await context.newPage());
4244
await page.waitForTimeout(10000); // Add a delay to give you time to visit the live view url
4345
await page.goto("https://www.google.com/recaptcha/api2/demo");
4446
// Watch Kernel auto-solve the CAPTCHA!
4547
await browser.close();
46-
});
48+
});

templates/typescript/cua/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if (!process.env.OPENAI_API_KEY) {
2828
* Returns:
2929
* An answer to the task, elapsed time and optionally the messages stack
3030
* Invoke this via CLI:
31-
* export KERNEL_API_KEY=<your_api_key>
31+
* kernel login # or: export KERNEL_API_KEY=<your_api_key>
3232
* kernel deploy index.ts -e OPENAI_API_KEY=XXXXX --force
3333
* kernel invoke ts-cua cua-task -p "{\"task\":\"current market price range for a used dreamcast\"}"
3434
* kernel logs ts-cua -f # Open in separate tab

0 commit comments

Comments
 (0)