Commit d52581b
Simplify TS computer-use templates with @onkernel/cua-agent (#191)
## Summary
Replaces the hand-written per-provider sampling loops and action
adapters in the **Anthropic**, **OpenAI**, and **Gemini** TypeScript
computer-use templates with the `CuaAgent` class from
[`@onkernel/cua-agent`](https://www.npmjs.com/package/@onkernel/cua-agent).
Each template now provisions a Kernel browser, hands it to `CuaAgent`,
and returns the final assistant text. `CuaAgent` owns the
screenshot/tool loop and the provider-specific tool-call translation, so
the bespoke `loop.ts` / `tools/**` / `lib/agent.ts` /
`lib/kernel-computer.ts` code is deleted — about 3,500 lines of provider
plumbing removed across the three templates.
The Kernel app wrapper (`app.action("cua-task")`), payload/output
shapes, custom system prompts, and replay recording are preserved, so
the existing `kernel invoke` samples still work unchanged.
## What changed per template
| Template | Before | After |
|---|---|---|
| `anthropic-computer-use` | `index.ts` + `loop.ts` + `tools/**` +
`utils/**` (~1,385 LOC TS) | `index.ts` + `session.ts` over `CuaAgent`
(`anthropic:claude-sonnet-4-6`) |
| `openai-computer-use` | `index.ts` + `lib/agent.ts` +
`lib/kernel-computer.ts` + `lib/toolset.ts` + event logging +
`run_local.ts` (~1,934 LOC TS) | `index.ts` + `lib/replay.ts` over
`CuaAgent` (`openai:gpt-5.5`, `computerUseExtra`) |
| `gemini-computer-use` | `index.ts` + `loop.ts` + `tools/**` (~983 LOC
TS) | `index.ts` + `session.ts` over `CuaAgent`
(`google:gemini-3-flash-preview`) |
`session.ts` is retained (Anthropic/Gemini) as a provider-neutral
browser-lifecycle + replay helper; it gains a `browser` getter so the
`BrowserCreateResponse` can be handed to `CuaAgent`.
## Notable behavior changes
- **Model updates**, required because `@onkernel/cua-ai` curates the
supported computer-use models:
- Gemini: `gemini-2.5-computer-use-preview-10-2025` →
`gemini-3-flash-preview` (the old preview model is intentionally
unsupported by cua-ai — it needs Google's native `tools.computer_use`
wrapper).
- OpenAI: `gpt-5.4` → `gpt-5.5`.
- **OpenAI navigation:** OpenAI's computer tool has no native URL
navigation. The old template pre-navigated to DuckDuckGo; this enables
`computerUseExtra` so the model gets a `goto`/`back`/`forward`/`url`
helper instead.
- **`@onkernel/sdk` pinned to `0.49.0`** in each template to match
`@onkernel/cua-agent`'s dependency, so the `Kernel` client and browser
types are a single instance (the SDK `Kernel` class is nominally typed).
- **Removed** the OpenAI bespoke JSONL event-logging system,
`run_local.ts`, and `dotenv`; dropped the OpenAI `logs` and Gemini
`error` output fields. Errors now surface by throwing (Anthropic/Gemini)
or as `answer: null` (OpenAI), matching each template's prior contract
otherwise.
- Lockfiles regenerated; Gemini gains a `pnpm-lock.yaml` (it previously
had none).
## Scope
- TypeScript only, three templates. Yutori, Tzafon, and all Python
templates are untouched.
- No Go changes: app names, action names, and payload field names are
preserved, so the `kernel create` / `kernel deploy` / `kernel invoke`
flows and samples in `pkg/create/templates.go` are unaffected.
## Test plan
- [x] `tsc --noEmit` passes for each migrated template against the
published cua packages.
- [x] `make build` (Go `//go:embed` re-embeds the cleaned template tree;
no `node_modules` embedded).
- [x] `make test` (`go vet ./...` + `go test ./...`) passes.
- [x] Not yet deployed/invoked live against a Kernel browser — recommend
a `kernel deploy` + `kernel invoke` smoke test per template before
marking ready.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Large deletion of custom agent logic shifts runtime behavior to
external packages and newer model IDs; invoke/deploy contracts are
preserved but live smoke tests are still recommended.
>
> **Overview**
> The **Anthropic**, **Gemini**, and **OpenAI** TypeScript computer-use
templates stop using in-repo sampling loops and hand-rolled tool
adapters (`loop.ts`, `tools/**`, OpenAI `lib/agent.ts` /
`kernel-computer.ts`, etc.) and instead wire **`CuaAgent`** from
`@onkernel/cua-agent` after provisioning a Kernel browser.
>
> Each `index.ts` now creates a session (or browser), runs
`agent.prompt(...)`, and returns the last assistant text; replay and
`cua-task` payload shapes stay the same. **`session.ts`**
(Anthropic/Gemini) exposes a **`browser`** getter on the create response
for `CuaAgent`. Dependencies shift to `@onkernel/cua-agent`,
`@onkernel/cua-ai`, and **`@onkernel/sdk` pinned to `0.49.0`**; READMEs
document the Playwright escape hatch.
>
> **Behavior deltas:** Gemini model **`google:gemini-3-flash-preview`**
(replacing the old preview id); OpenAI **`openai:gpt-5.5`** with
**`computerUseExtra: true`** instead of pre-navigating to DuckDuckGo and
custom batch/goto tooling; OpenAI drops local `run_local.ts`, dotenv,
JSONL event logging, and optional **`logs`** / Gemini **`error`**
response fields.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
fe1101e. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent c2d845a commit d52581b
34 files changed
Lines changed: 3837 additions & 3893 deletions
File tree
- pkg/templates/typescript
- anthropic-computer-use
- tools
- types
- utils
- types
- utils
- gemini-computer-use
- tools
- types
- openai-computer-use
- lib
Lines changed: 18 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
43 | 55 | | |
44 | 56 | | |
45 | 57 | | |
| 58 | + | |
46 | 59 | | |
47 | 60 | | |
Lines changed: 52 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 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 | + | |
22 | 49 | | |
23 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
24 | 54 | | |
25 | 55 | | |
26 | 56 | | |
| |||
42 | 72 | | |
43 | 73 | | |
44 | 74 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
56 | 84 | | |
57 | 85 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 86 | + | |
67 | 87 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
73 | 94 | | |
74 | | - | |
75 | 95 | | |
76 | 96 | | |
77 | 97 | | |
78 | 98 | | |
79 | 99 | | |
80 | 100 | | |
81 | 101 | | |
82 | | - | |
| 102 | + | |
83 | 103 | | |
84 | 104 | | |
85 | 105 | | |
| |||
This file was deleted.
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
0 commit comments