287 lines · 10.5 KB
import { DurableObject } from "cloudflare:workers";
import { containerLimits } from "./container-config";
import { closeContainerSession, openContainerSession } from "./container-meter";

const MINUTE_MS = 60 * 1000;
const CHECK_MS = MINUTE_MS;
const READY_ATTEMPTS = 60;
const READY_DELAY_MS = 500;
const ACTIVITY_WRITE_MS = 30 * 1000;
const MAX_SYNC_FILES = 300;
const DEFAULT_COLS = 120;
const DEFAULT_ROWS = 32;
const MAX_TERMINALS = 8;
const WORKSPACE = "/workspace";

type Meta = {
  accountId: string;
  repoId: string;
  branch: string;
  repoDir: string;
  sessionId: string;
  startedAt: number;
  lastActivity: number;
};

export type ContainerStart = {
  accountId: string;
  repoId: string;
  branch: string;
  repoName: string;
  cloneUrl: string;
  publicRemote: string;
  author: { name: string; email: string };
};

export type ContainerState = {
  state: "stopped" | "running";
  startedAt: number | null;
  lastActivity: number | null;
  repoDir: string | null;