Skip to content

add js/wasm browser build with OpenRouter PKCE, agentic loop, and demo page#2672

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/bfc57c2a96de22d9
May 6, 2026
Merged

add js/wasm browser build with OpenRouter PKCE, agentic loop, and demo page#2672
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/bfc57c2a96de22d9

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented May 6, 2026

What this is

A GOOS=js GOARCH=wasm entry point under cmd/wasm that exposes a slice of docker-agent — config parsing plus a streaming agentic loop with tool calling — to a JavaScript host (browser or Node). It is a proof-of-concept, not a port of the full agent (see Limits below).

The static demo at cmd/wasm/web/index.html runs against OpenRouter via the PKCE OAuth flow.

See cmd/wasm/README.md for full build / run instructions and architecture notes.

What it does

  • Config parsing (any version → latest via pkg/config)
  • Agent enumeration (lists agents, models, instructions)
  • Full agentic loop: streaming chat with tool calling, multi-agent handoffs, fallback models with retry + backoff, hooks (session_start, turn_start, pre_tool_use, post_tool_use)
  • Remote MCP tools (HTTP/SSE transport — no stdio)
  • Request cancellation via dockerAgent.abort()

A JS API is registered on globalThis.dockerAgent:

dockerAgent.parseConfig(yamlString)
dockerAgent.listAgents(yamlString)
dockerAgent.chat({yaml, agentName?, env?, messages}, onEvent)
dockerAgent.abort()

What it intentionally does NOT do

  • Run shell commands (no os/exec under js/wasm)
  • Open files or listen on sockets
  • Persist sessions to sqlite
  • Render a TUI
  • Use pkg/runtime or pkg/teamloader directly (both are blocked by sqlite under wasm) — instead cmd/wasm/runtime_wasm.go builds agents from config using pkg/agent directly and runs a simplified streaming loop

Build & test

# Compile (~94 MB unoptimised .wasm).
GOOS=js GOARCH=wasm go build -o cmd/wasm/web/docker-agent.wasm ./cmd/wasm

# Copy the matching shim from the Go toolchain.
cp "\$(go env GOROOT)/lib/wasm/wasm_exec.js" cmd/wasm/web/wasm_exec.js

# Node smoke test (proves runtime + parseConfig + listAgents + abort work).
node cmd/wasm/smoke_test.js

The generated artifacts (cmd/wasm/web/docker-agent.wasm, cmd/wasm/web/wasm_exec.js, and a wasm debug binary) are in .gitignore — they are built locally.

Cross-platform plumbing this required

Several packages had unix-only files that incidentally matched GOOS=js. To make the wasm target compile, a small set of _js.go stubs was added alongside the existing _unix.go / _windows.go files:

  • pkg/cache/lock_js.go — file-lock no-op (single-process under wasm)
  • pkg/desktop/connection_js.go + sockets_js.go — Docker Desktop connection stubs
  • pkg/desktop/connection_other.go — tightened build tag to !windows && !js
  • pkg/model/provider/factory_js.go — provider factory without OS-specific deps
  • pkg/tools/builtin/shell/cmd_js.go — process-group stubs
  • pkg/tools/builtin/shell/cmd_unix.go — tightened build tag to !windows && !js (it was using `syscall.SysProcAttr.Setpgid` which doesn't exist under js/wasm)

Validation

  • `go build ./...` — ok
  • `GOOS=js GOARCH=wasm go build -o cmd/wasm/web/docker-agent.wasm ./cmd/wasm` — ok
  • `GOOS=windows go build ./...` — ok
  • `task test` — all packages pass
  • `task lint` — 0 issues
  • `node cmd/wasm/smoke_test.js` — OK — all smoke tests pass (parseConfig, listAgents, abort)

Assisted-By: docker-agent

@dgageot dgageot requested a review from a team as a code owner May 6, 2026 15:14
@docker-agent
Copy link
Copy Markdown

docker-agent Bot commented May 6, 2026

PR Review Failed — The review agent encountered an error and could not complete the review. View logs.

@dgageot dgageot merged commit f2be0bf into docker:main May 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants