Skip to content

Commit bbe6c23

Browse files
committed
init
1 parent 801f79f commit bbe6c23

File tree

7 files changed

+68
-65
lines changed

7 files changed

+68
-65
lines changed

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
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
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
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
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
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
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
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
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
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 = (await browser.contexts()[0]) || (await browser.newContext());
43+
const page = (await 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
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

templates/typescript/sample-app/index.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Kernel, type KernelContext } from '@onkernel/sdk';
2-
import { chromium } from 'playwright';
1+
import { Kernel, type KernelContext } from "@onkernel/sdk";
2+
import { chromium } from "playwright";
33

44
const kernel = new Kernel();
55

6-
const app = kernel.app('ts-basic');
6+
const app = kernel.app("ts-basic");
77

88
/**
99
* Example app that extracts the title of a webpage
@@ -13,7 +13,7 @@ const app = kernel.app('ts-basic');
1313
* Returns:
1414
* A dictionary containing the page title
1515
* Invoke this via CLI:
16-
* export KERNEL_API_KEY=<your_api_key>
16+
* kernel login
1717
* kernel deploy index.ts # If you haven't already deployed this app
1818
* kernel invoke ts-basic get-page-title -p '{"url": "https://www.google.com"}'
1919
* kernel logs ts-basic -f # Open in separate tab
@@ -26,13 +26,19 @@ interface PageTitleOutput {
2626
title: string;
2727
}
2828
app.action<PageTitleInput, PageTitleOutput>(
29-
'get-page-title',
30-
async (ctx: KernelContext, payload?: PageTitleInput): Promise<PageTitleOutput> => {
29+
"get-page-title",
30+
async (
31+
ctx: KernelContext,
32+
payload?: PageTitleInput
33+
): Promise<PageTitleOutput> => {
3134
if (!payload?.url) {
32-
throw new Error('URL is required');
35+
throw new Error("URL is required");
3336
}
34-
35-
if (!payload.url.startsWith('http://') && !payload.url.startsWith('https://')) {
37+
38+
if (
39+
!payload.url.startsWith("http://") &&
40+
!payload.url.startsWith("https://")
41+
) {
3642
payload.url = `https://${payload.url}`;
3743
}
3844

@@ -47,11 +53,15 @@ app.action<PageTitleInput, PageTitleOutput>(
4753
invocation_id: ctx.invocation_id,
4854
});
4955

50-
console.log("Kernel browser live view url: ", kernelBrowser.browser_live_view_url);
56+
console.log(
57+
"Kernel browser live view url: ",
58+
kernelBrowser.browser_live_view_url
59+
);
5160

5261
const browser = await chromium.connectOverCDP(kernelBrowser.cdp_ws_url);
53-
const context = await browser.contexts()[0] || (await browser.newContext());
54-
const page = await context.pages()[0] || (await context.newPage());
62+
const context =
63+
(await browser.contexts()[0]) || (await browser.newContext());
64+
const page = (await context.pages()[0]) || (await context.newPage());
5565

5666
try {
5767
//////////////////////////////////////
@@ -63,7 +73,7 @@ app.action<PageTitleInput, PageTitleOutput>(
6373
} finally {
6474
await browser.close();
6575
}
66-
},
76+
}
6777
);
6878

6979
/**
@@ -75,17 +85,17 @@ app.action<PageTitleInput, PageTitleOutput>(
7585
* Returns:
7686
* A dictionary containing the browser live view url
7787
* Invoke this via CLI:
78-
* export KERNEL_API_KEY=<your_api_key>
88+
* kernel login
7989
* kernel deploy index.ts # If you haven't already deployed this app
8090
* kernel invoke ts-basic create-persisted-browser
8191
* kernel logs ts-basic -f # Open in separate tab
8292
*/
8393
interface CreatePersistedBrowserOutput {
8494
browser_live_view_url: string;
8595
}
86-
app.action("create-persisted-browser",
96+
app.action(
97+
"create-persisted-browser",
8798
async (ctx: KernelContext): Promise<CreatePersistedBrowserOutput> => {
88-
8999
const kernelBrowser = await kernel.browsers.create({
90100
invocation_id: ctx.invocation_id,
91101
persistence: {
@@ -98,4 +108,4 @@ app.action("create-persisted-browser",
98108
browser_live_view_url: kernelBrowser.browser_live_view_url,
99109
};
100110
}
101-
);
111+
);

0 commit comments

Comments
 (0)