Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ create-kernel-app [app-name] [options]
- `sample-app`: Basic template with Playwright integration
- `browser-use`: Template with Browser Use SDK (Python only)
- `stagehand`: Template with Stagehand SDK (Typescript only)
- `persistent-browser`: Implements `sample-app` using a persistent browser
- `advanced-sample`: Implements sample apps using advanced Kernel configs
- `computer-use`: Implements a prompt loop using Anthropic Computer Use

### Examples
Expand Down Expand Up @@ -125,7 +125,7 @@ These are the sample apps currently available when you run `npx @onkernel/create
| **sample-app** | Returns the page title of a specified URL | Playwright | `{ url }` |
| **browser-use** | Completes a specified task | Browser Use | `{ task }` |
| **stagehand** | Returns the first result of a specified Google search | Stagehand | `{ query }` |
| **persistent-browser** | Implements `sample-app` using a persistent browser | Playwright | `{ url }` |
| **advanced-sample** | Implements sample apps using advanced Kernel configs | n/a |
| **computer-use** | Implements a prompt loop | Anthropic Computer Use API | `{ query }` |

## Documentation
Expand Down
32 changes: 16 additions & 16 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type TemplateKey =
| "sample-app"
| "browser-use"
| "stagehand"
| "persistent-browser"
| "advanced-sample"
| "computer-use";
type LanguageInfo = { name: string; shorthand: string };
type TemplateInfo = {
Expand All @@ -32,7 +32,7 @@ const LANGUAGE_PYTHON = "python";
const TEMPLATE_SAMPLE_APP = "sample-app";
const TEMPLATE_BROWSER_USE = "browser-use";
const TEMPLATE_STAGEHAND = "stagehand";
const TEMPLATE_PERSISTENT_BROWSER = "persistent-browser";
const TEMPLATE_ADVANCED_SAMPLE = "advanced-sample";
const TEMPLATE_COMPUTER_USE = "computer-use";
const LANGUAGE_SHORTHAND_TS = "ts";
const LANGUAGE_SHORTHAND_PY = "py";
Expand Down Expand Up @@ -62,10 +62,10 @@ const TEMPLATES: Record<TemplateKey, TemplateInfo> = {
description: "Implements the Stagehand SDK",
languages: [LANGUAGE_TYPESCRIPT],
},
[TEMPLATE_PERSISTENT_BROWSER]: {
name: "Persistent Browser",
[TEMPLATE_ADVANCED_SAMPLE]: {
name: "Advanced Samples",
description:
"Implements a persistent browser that maintains state across invocations",
"Implements sample actions with advanced Kernel configs",
languages: [LANGUAGE_TYPESCRIPT, LANGUAGE_PYTHON],
},
[TEMPLATE_COMPUTER_USE]: {
Expand All @@ -84,8 +84,8 @@ const INVOKE_SAMPLES: Record<
'kernel invoke ts-basic get-page-title --payload \'{"url": "https://www.google.com"}\'',
[TEMPLATE_STAGEHAND]:
'kernel invoke ts-stagehand stagehand-task --payload \'{"query": "Best wired earbuds"}\'',
[TEMPLATE_PERSISTENT_BROWSER]:
'kernel invoke ts-persistent-browser persistent-browser-task --payload \'{"url": "https://news.ycombinator.com/"}\'',
[TEMPLATE_ADVANCED_SAMPLE]:
'kernel invoke ts-advanced test-captcha-solver',
[TEMPLATE_COMPUTER_USE]:
'kernel invoke ts-cu cu-task --payload \'{"query": "Return the first url of a search result for NYC restaurant reviews Pete Wells"}\'',
},
Expand All @@ -94,8 +94,8 @@ const INVOKE_SAMPLES: Record<
'kernel invoke python-basic get-page-title --payload \'{"url": "https://www.google.com"}\'',
[TEMPLATE_BROWSER_USE]:
'kernel invoke python-bu bu-task --payload \'{"task": "Compare the price of gpt-4o and DeepSeek-V3"}\'',
[TEMPLATE_PERSISTENT_BROWSER]:
'kernel invoke python-persistent-browser persistent-browser-task --payload \'{"url": "https://news.ycombinator.com/"}\'',
[TEMPLATE_ADVANCED_SAMPLE]:
'kernel invoke python-advanced test-captcha-solver',
[TEMPLATE_COMPUTER_USE]:
'kernel invoke python-cu cu-task --payload \'{"query": "Return the first url of a search result for NYC restaurant reviews Pete Wells"}\'',
},
Expand All @@ -110,8 +110,8 @@ const REGISTERED_APP_NAMES: Record<
'ts-basic',
[TEMPLATE_STAGEHAND]:
'ts-stagehand',
[TEMPLATE_PERSISTENT_BROWSER]:
'ts-persistent-browser',
[TEMPLATE_ADVANCED_SAMPLE]:
'ts-advanced',
[TEMPLATE_COMPUTER_USE]:
'ts-cu',
},
Expand All @@ -120,8 +120,8 @@ const REGISTERED_APP_NAMES: Record<
'python-basic',
[TEMPLATE_BROWSER_USE]:
'python-bu',
[TEMPLATE_PERSISTENT_BROWSER]:
'python-persistent-browser',
[TEMPLATE_ADVANCED_SAMPLE]:
'python-advanced',
[TEMPLATE_COMPUTER_USE]:
'python-cu',
},
Expand Down Expand Up @@ -336,13 +336,13 @@ function printNextSteps(
): void {
// Determine which sample command to show based on language and template
const deployCommand =
language === LANGUAGE_TYPESCRIPT && (template === TEMPLATE_SAMPLE_APP || template === TEMPLATE_PERSISTENT_BROWSER)
language === LANGUAGE_TYPESCRIPT && (template === TEMPLATE_SAMPLE_APP || template === TEMPLATE_ADVANCED_SAMPLE)
? "kernel deploy index.ts"
: language === LANGUAGE_TYPESCRIPT && template === TEMPLATE_STAGEHAND
? "kernel deploy index.ts --env OPENAI_API_KEY=XXX"
: language === LANGUAGE_TYPESCRIPT && template === TEMPLATE_COMPUTER_USE
? "kernel deploy index.ts --env ANTHROPIC_API_KEY=XXX"
: language === LANGUAGE_PYTHON && template === TEMPLATE_SAMPLE_APP
: language === LANGUAGE_PYTHON && (template === TEMPLATE_SAMPLE_APP || template === TEMPLATE_ADVANCED_SAMPLE)
? "kernel deploy main.py"
: language === LANGUAGE_PYTHON && template === TEMPLATE_BROWSER_USE
? "kernel deploy main.py --env OPENAI_API_KEY=XXX"
Expand Down Expand Up @@ -384,7 +384,7 @@ program
)
.option(
"-t, --template <template>",
`Template type (${TEMPLATE_SAMPLE_APP}, ${TEMPLATE_BROWSER_USE}, ${TEMPLATE_STAGEHAND}, ${TEMPLATE_PERSISTENT_BROWSER}, ${TEMPLATE_COMPUTER_USE})`
`Template type (${TEMPLATE_SAMPLE_APP}, ${TEMPLATE_BROWSER_USE}, ${TEMPLATE_STAGEHAND}, ${TEMPLATE_ADVANCED_SAMPLE}, ${TEMPLATE_COMPUTER_USE})`
)
.action(
async (
Expand Down
3 changes: 3 additions & 0 deletions templates/python/advanced-sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Kernel Python Advanced Sample App

This is a collection of Kernel actions that demonstrate how to use the Kernel SDK.
54 changes: 54 additions & 0 deletions templates/python/advanced-sample/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import kernel
from kernel import Kernel
from playwright.async_api import async_playwright

client = Kernel()
app = kernel.App("python-advanced")

"""
Example showing Kernel's auto-CAPTCHA solver.
Visit the live view url to see the Kernel browser auto-solve the CAPTCHA on the site.

Args:
ctx: Kernel context containing invocation information
Returns:
None

Invoke this via CLI:
export KERNEL_API_KEY=<your_api_key>
kernel deploy main.py # If you haven't already deployed this app
kernel invoke py-advanced test_captcha_solver
kernel logs py-advanced -f # Open in separate tab
"""
@app.action("test-captcha-solver")
async def test_captcha_solver(ctx: kernel.KernelContext) -> None:
kernel_browser = client.browsers.create(
invocation_id=ctx.invocation_id,
stealth=True,
persistence={"id": "captcha-solver"}
)

async with async_playwright() as playwright:
browser = await playwright.chromium.connect_over_cdp(kernel_browser.cdp_ws_url)

# Get or create context and page
contexts = browser.contexts
context = contexts[0] if contexts else await browser.new_context()
pages = context.pages
page = pages[0] if pages else await context.new_page()

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

# Navigate to a site with a CAPTCHA
try:
await page.wait_for_timeout(10000) # Add a delay to give you time to visit the live view url
await page.goto("https://www.google.com/recaptcha/api2/demo")
except Exception as e:
print(f"Error during navigation: {e}")
raise
# Watch Kernel auto-solve the CAPTCHA!
await browser.close()

13 changes: 13 additions & 0 deletions templates/python/advanced-sample/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "kernel-python-advanced"
version = "0.1.0"
description = "Sample application implementing advanced Kernel configs"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"kernel>=0.5.0",
"playwright>=1.52.0"
]

[dependency-groups]
dev = ["mypy>=1.15.0"]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions templates/python/persistent-browser/README.md

This file was deleted.

77 changes: 0 additions & 77 deletions templates/python/persistent-browser/main.py

This file was deleted.

Loading