Skip to content

Commit 41e5f6f

Browse files
authored
Add stagehand template (#3)
1 parent 4988d45 commit 41e5f6f

File tree

16 files changed

+476
-347
lines changed

16 files changed

+476
-347
lines changed

.github/workflows/publish.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,36 @@ jobs:
3838
- name: Build
3939
run: bun run build
4040

41-
- name: Bump version and push
41+
- name: Bump version and create PR
4242
run: |
4343
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
44+
# Create a new branch for the version bump
45+
BRANCH_NAME="chore/bump-version-$(date +%s)"
46+
git checkout -b $BRANCH_NAME
47+
# Bump version
4448
npm version patch -m "chore: bump version to %s [skip ci]"
45-
git push origin HEAD:main --tags
49+
# Push the new branch
50+
git push origin $BRANCH_NAME
51+
# Create PR using GitHub CLI
52+
gh pr create \
53+
--title "chore: bump version" \
54+
--body "Automated version bump" \
55+
--base main \
56+
--head $BRANCH_NAME \
57+
--label "automated" \
58+
--label "version-bump"
4659
env:
4760
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
GITHUB_CLI_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
63+
- name: Setup GitHub CLI
64+
run: |
65+
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
66+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
67+
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
68+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
69+
&& sudo apt update \
70+
&& sudo apt install gh -y
4871
4972
- name: Publish to NPM
5073
run: npm publish

README.md

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ A CLI tool to create the scaffolding for a new Kernel applications. This tool h
1111
- 📦 Multiple template options:
1212
- Sample App: A basic template that extracts page titles using Playwright
1313
- Browser Use: A template implementing the Browser Use SDK
14+
- Stagehand: A template implementing the Stagehand SDK
1415
- ⚡️ Automatic dependency setup
15-
- 🫶 Interactive CLI with helpful prompts
16+
- 🫶 Interactive CLI
1617

1718
## Set-Up
1819

@@ -36,6 +37,7 @@ create-kernel-app [app-name] [options]
3637
- `-t, --template <template>`: Select a template
3738
- `sample-app`: Basic template with Playwright integration
3839
- `browser-use`: Template with Browser Use SDK (Python only)
40+
- `stagehand`: Template with Stagehand SDK (Typescript only)
3941

4042
### Examples
4143

@@ -44,6 +46,11 @@ Create a TypeScript application with a sample app:
4446
npx @onkernel/create-kernel-app my-app --language typescript --template sample-app
4547
```
4648

49+
Create a Typescript application with Stagehand template:
50+
```bash
51+
npx @onkernel/create-kernel-app my-app --language typescript --template stagehand
52+
```
53+
4754
Create a Python application with a sample app:
4855
```bash
4956
npx @onkernel/create-kernel-app my-app --language python --template sample-app
@@ -59,26 +66,54 @@ npx @onkernel/create-kernel-app my-app --language python --template browser-use
5966
After creating your application:
6067

6168
1. Navigate to your project directory:
62-
```bash
63-
cd my-app
64-
```
69+
```bash
70+
cd my-app
71+
```
6572

6673
2. Set up your environment:
67-
- For TypeScript: `npm install`
68-
- For Python: `uv venv && source .venv/bin/activate && uv sync`
74+
- For TypeScript: `npm install`
75+
- For Python: `uv venv && source .venv/bin/activate && uv sync`
6976

7077
3. Set your Kernel API key:
71-
```bash
72-
export KERNEL_API_KEY=<YOUR_API_KEY>
73-
```
78+
```bash
79+
export KERNEL_API_KEY=<YOUR_API_KEY>
80+
```
7481

7582
4. Deploy your application:
76-
```bash
77-
kernel deploy index.ts # for TypeScript
78-
kernel deploy main.py # for Python
79-
```
83+
```bash
84+
# Typscript
85+
kernel deploy index.ts # --env OPENAI_API_KEY=XXX if Stagehand
86+
87+
# Python
88+
kernel deploy main.py # --env OPENAI_API_KEY=XXX if Browser Use
89+
```
90+
91+
If deploying an app that requires environment variables, make sure to [set them](https://docs.onkernel.com/launch/deploy#environment-variables) when you `deploy`.
92+
93+
5. Invoke your application:
94+
```bash
95+
# Typescript + Sample App
96+
kernel invoke ts-basic get-page-title --payload '{"url": "https://www.google.com"}'
97+
98+
# Typescript + Stagehand
99+
kernel invoke ts-stagehand stagehand-task --payload '{"query": "Best wired earbuds"}'
100+
101+
# Python + Sample App
102+
kernel invoke python-basic get-page-title --payload '{"url": "https://www.google.com"}'
103+
104+
# Python + Browser Use
105+
kernel invoke python-bu bu-task --payload '{"task": "Compare the price of gpt-4o and DeepSeek-V3"}'
106+
```
107+
108+
## Sample apps reference
109+
110+
These are the sample apps currently available when you run `npx @onkernel/create-kernel-app`:
80111

81-
5. Try out your application using the provided sample commands in the project README.
112+
| Template | Description | Framework | Query Parameters |
113+
|----------|-------------|-----------|------------------|
114+
| **sample-app** | Returns the page title of a specified URL | Playwright | `{ url }` |
115+
| **browser-use** | Completes a specified task | Browser Use | `{ task }` |
116+
| **stagehand** | Returns the first result of a specified Google search | Stagehand | `{ query }` |
82117

83118
## Documentation
84119

bunfig.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# Use exact versions for dependencies
33
exact = true
44

5-
[test]
6-
# Enable TypeScript for tests
7-
preload = ["./test/setup.ts"]
8-
95
[debug]
106
# Enable source maps for better debugging
117
sourcemap = true

index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const __dirname = path.dirname(__filename);
1313

1414
// Types for better type safety
1515
type LanguageKey = 'typescript' | 'python';
16-
type TemplateKey = 'sample-app' | 'browser-use';
16+
type TemplateKey = 'sample-app' | 'browser-use' | 'stagehand';
1717
type LanguageInfo = { name: string; shorthand: string };
1818
type TemplateInfo = { name: string; description: string; languages: LanguageKey[] };
1919

@@ -22,6 +22,7 @@ const LANGUAGE_TYPESCRIPT = 'typescript';
2222
const LANGUAGE_PYTHON = 'python';
2323
const TEMPLATE_SAMPLE_APP = 'sample-app';
2424
const TEMPLATE_BROWSER_USE = 'browser-use';
25+
const TEMPLATE_STAGEHAND = 'stagehand';
2526
const LANGUAGE_SHORTHAND_TS = 'ts';
2627
const LANGUAGE_SHORTHAND_PY = 'py';
2728

@@ -41,13 +42,19 @@ const TEMPLATES: Record<TemplateKey, TemplateInfo> = {
4142
name: 'Browser Use',
4243
description: 'Implements Browser Use SDK',
4344
languages: [LANGUAGE_PYTHON]
44-
}
45+
},
46+
[TEMPLATE_STAGEHAND]: {
47+
name: 'Stagehand',
48+
description: 'Implements the Stagehand SDK',
49+
languages: [LANGUAGE_TYPESCRIPT]
50+
},
4551
};
4652

4753
const INVOKE_SAMPLES: Record<string, string> = {
4854
'typescript-sample-app': 'kernel invoke ts-basic get-page-title --payload \'{"url": "https://www.google.com"}\'',
4955
'python-sample-app': 'kernel invoke python-basic get-page-title --payload \'{"url": "https://www.google.com"}\'',
50-
'python-browser-use': 'kernel invoke python-bu bu-task --payload \'{"task": "Compare the price of gpt-4o and DeepSeek-V3"}\''
56+
'python-browser-use': 'kernel invoke python-bu bu-task --payload \'{"task": "Compare the price of gpt-4o and DeepSeek-V3"}\'',
57+
'typescript-stagehand': 'kernel invoke ts-stagehand stagehand-task --payload \'{"query": "Best wired earbuds"}\''
5158
};
5259

5360
const CONFIG = {
@@ -227,7 +234,8 @@ async function setupDependencies(appPath: string, language: LanguageKey): Promis
227234
// Print success message with next steps
228235
function printNextSteps(appName: string, language: LanguageKey, template: TemplateKey): void {
229236
// Determine which sample command to show based on language and template
230-
const deployCommand = language === LANGUAGE_TYPESCRIPT ? 'kernel deploy index.ts'
237+
const deployCommand = language === LANGUAGE_TYPESCRIPT && template === TEMPLATE_SAMPLE_APP ? 'kernel deploy index.ts'
238+
: language === LANGUAGE_TYPESCRIPT && template === TEMPLATE_STAGEHAND ? 'kernel deploy index.ts --env OPENAI_API_KEY=XXX'
231239
: language === LANGUAGE_PYTHON && template === TEMPLATE_SAMPLE_APP ? 'kernel deploy main.py'
232240
: language === LANGUAGE_PYTHON && template === TEMPLATE_BROWSER_USE ? 'kernel deploy main.py --env OPENAI_API_KEY=XXX'
233241
: '';
@@ -254,7 +262,7 @@ program
254262
.version('0.1.0')
255263
.argument('[app-name]', 'Name of your Kernel app')
256264
.option('-l, --language <language>', `Programming language (${LANGUAGE_TYPESCRIPT}/${LANGUAGE_SHORTHAND_TS}, ${LANGUAGE_PYTHON}/${LANGUAGE_SHORTHAND_PY})`)
257-
.option('-t, --template <template>', `Template type (${TEMPLATE_SAMPLE_APP}, ${TEMPLATE_BROWSER_USE})`)
265+
.option('-t, --template <template>', `Template type (${TEMPLATE_SAMPLE_APP}, ${TEMPLATE_BROWSER_USE}, ${TEMPLATE_STAGEHAND})`)
258266
.action(async (appName: string, options: { language?: string; template?: string }) => {
259267
try {
260268
let normalizedLanguage: LanguageKey | null = null;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onkernel/create-kernel-app",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Create Kernel sample applications",
55
"main": "dist/index.js",
66
"type": "module",

templates/python/browser-use/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import kernel
44
from kernel import Kernel
55
from typing import TypedDict
6-
import os
76

87
client = Kernel()
98

templates/python/browser-use/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "python-bu"
33
version = "0.1.0"
4-
description = "Add your description here"
4+
description = "Kernel sample app for Browser Use"
55
readme = "README.md"
66
requires-python = ">=3.11"
77
dependencies = [

0 commit comments

Comments
 (0)