Files
claw-code-parity/ts-worker/state/TaskStore.ts
T
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

83 lines
2.1 KiB
TypeScript

/**
* TaskStore — manages task lists and runtime tasks.
*
* Tracks the todo-list style tasks (TaskListRecord) and the
* background runtime tasks (RuntimeTaskRecord) like agents and
* shell processes.
*/
import type {
TaskListRecord,
TaskListStatus,
RuntimeTaskRecord,
RuntimeTaskStatus,
} from './records.js'
export class TaskStore {
private taskListId = 'default'
private tasks = new Map<string, TaskListRecord>()
private runtimeTasks = new Map<string, RuntimeTaskRecord>()
getTaskListId(): string {
return this.taskListId
}
// ── Task list (todos) ─────────────────────────────────────────────
upsertTask(task: TaskListRecord): void {
this.tasks.set(task.id, task)
}
getTask(id: string): TaskListRecord | undefined {
return this.tasks.get(id)
}
listTasks(): TaskListRecord[] {
return Array.from(this.tasks.values())
}
removeTask(id: string): boolean {
return this.tasks.delete(id)
}
// ── Runtime tasks (agents, shells) ────────────────────────────────
upsertRuntimeTask(task: RuntimeTaskRecord): void {
this.runtimeTasks.set(task.task_id, task)
}
getRuntimeTask(taskId: string): RuntimeTaskRecord | undefined {
return this.runtimeTasks.get(taskId)
}
listRuntimeTasks(): RuntimeTaskRecord[] {
return Array.from(this.runtimeTasks.values())
}
listAgents(): RuntimeTaskRecord[] {
return this.listRuntimeTasks().filter((t) => t.kind === 'agent')
}
getAgent(agentId: string): RuntimeTaskRecord | undefined {
for (const task of this.runtimeTasks.values()) {
if (task.kind === 'agent' && (task.agent_id === agentId || task.task_id === agentId)) {
return task
}
}
return undefined
}
stopRuntimeTask(taskId: string): boolean {
const task = this.runtimeTasks.get(taskId)
if (!task || task.status !== 'running') return false
task.status = 'stopped'
task.completed_at = Date.now()
return true
}
reset(): void {
this.tasks.clear()
this.runtimeTasks.clear()
}
}