Files
claw-code-parity/ts-worker/main.ts
Wylabb f7c23fb325
Build Claw Telegram / build (push) Successful in 5m26s
Build Claw Telegram / cleanup (push) Successful in 0s
Replace Rust worker with TS worker in single image
Add ts-worker/ with the Bun/TypeScript worker that replaces
claw-profile-worker. The Dockerfile now builds a single image
containing both the Rust gateway (claw-telegram) and the TS worker.

The image defaults to worker mode (bun run ts-worker/main.ts).
The gateway Unraid XML overrides with --entrypoint claw-telegram.
Worker containers use the same image with the default CMD.

- Add ts-worker/ (12 files): HTTP/SSE server, Anthropic SDK engine,
  approval broker, event translator, state stores
- Add package.json with @anthropic-ai/sdk dependency
- Rewrite Dockerfile: three-stage build (Rust + Bun + runtime)
- Revert CLAW_GATEWAY_WORKER_IMAGE to claw-telegram:latest
- Remove image pull from docker_worker_manager (same image, already local)
- Add ts-worker paths to CI trigger

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 23:44:57 +02:00

60 lines
2.2 KiB
TypeScript

#!/usr/bin/env bun
/**
* Worker entrypoint — reads CLAW_WORKER_* env vars and starts the
* Bun HTTP server that speaks the worker protocol.
*
* Usage:
* CLAW_WORKER_BIND_ADDR=0.0.0.0 \
* CLAW_WORKER_PORT=8780 \
* CLAW_WORKER_AUTH_TOKEN=secret \
* CLAW_WORKER_PROFILE_ID=default \
* CLAW_WORKER_STATE_ROOT=/state \
* CLAW_WORKER_DEFAULT_CWD=/workspace \
* CLAW_WORKER_MODEL=claude-sonnet-4-6 \
* CLAW_WORKER_PERMISSION_MODE=default \
* CLAUDE_CONFIG_DIR=/state/claude-home \
* bun src/worker/main.ts
*/
import { startWorkerServer } from './server.js'
// The gateway passes CLAW_WORKER_BIND_ADDR as "host:port" (e.g. "0.0.0.0:8080").
// Parse both address and port from it, with CLAW_WORKER_PORT as override.
const rawBindAddr = process.env.CLAW_WORKER_BIND_ADDR ?? '0.0.0.0:8080'
const colonIdx = rawBindAddr.lastIndexOf(':')
const bindAddr = colonIdx > 0 ? rawBindAddr.slice(0, colonIdx) : rawBindAddr
const port = parseInt(
process.env.CLAW_WORKER_PORT ?? (colonIdx > 0 ? rawBindAddr.slice(colonIdx + 1) : '8080'),
10,
)
const authToken = process.env.CLAW_WORKER_AUTH_TOKEN
const profileId = process.env.CLAW_WORKER_PROFILE_ID ?? 'default'
const stateRoot = process.env.CLAW_WORKER_STATE_ROOT ?? '/tmp/claw-worker-state'
const defaultCwd = process.env.CLAW_WORKER_DEFAULT_CWD ?? process.cwd()
const model = process.env.CLAW_WORKER_MODEL ?? 'claude-sonnet-4-6'
const permissionMode = process.env.CLAW_WORKER_PERMISSION_MODE ?? 'default'
const claudeConfigDir = process.env.CLAUDE_CONFIG_DIR ?? `${stateRoot}/claude-home`
console.log('[worker] starting with config:')
console.log(` bind_addr: ${bindAddr}`)
console.log(` port: ${port}`)
console.log(` profile_id: ${profileId}`)
console.log(` state_root: ${stateRoot}`)
console.log(` default_cwd: ${defaultCwd}`)
console.log(` model: ${model}`)
console.log(` permission_mode: ${permissionMode}`)
console.log(` claude_config: ${claudeConfigDir}`)
console.log(` auth: ${authToken ? 'configured' : 'none'}`)
await startWorkerServer({
bindAddr,
port,
authToken,
profileId,
stateRoot,
defaultCwd,
model,
permissionMode,
claudeConfigDir,
})