| 1 | import type { DiffineryEvent } from "@diffinery/shared"; |
| 2 | import type { RepoDO } from "./repo/RepoDO.js"; |
| 3 | import type { SchedulerDO } from "./scheduler.js"; |
| 4 | import type { ImportContainer } from "./imports/container.js"; |
| 5 | import type { RunnerContainer, SandboxContainer } from "./runner/containers.js"; |
| 6 | import type { MailJob } from "./mail/types.js"; |
| 7 | import type { ProjectDO } from "./agentic/ProjectDO.js"; |
| 8 | |
| 9 | export interface Env { |
| 10 | DB: D1Database; |
| 11 | BUCKET: R2Bucket; |
| 12 | EVENTS: Queue<DiffineryEvent>; |
| 13 | REPO: DurableObjectNamespace<RepoDO>; |
| 14 | /** Fires workflow schedules (src/scheduler.ts). */ |
| 15 | SCHEDULER: DurableObjectNamespace<SchedulerDO>; |
| 16 | /** Minutes between scheduler ticks, 1 to 60 (default 5, GitHub's shortest schedule interval). */ |
| 17 | SCHEDULE_TICK_MINUTES?: string; |
| 18 | /** End-to-end tests only: how long one minute of an environment's wait timer lasts, in ms (default 60000). */ |
| 19 | WAIT_TIMER_MINUTE_MS?: string; |
| 20 | RUNNER: DurableObjectNamespace<RunnerContainer>; |
| 21 | SANDBOX: DurableObjectNamespace<SandboxContainer>; |
| 22 | /** One per repository: its agent tasks (agentic/ProjectDO.ts). */ |
| 23 | PROJECT: DurableObjectNamespace<ProjectDO>; |
| 24 | /** |
| 25 | * Local development and end-to-end tests only: sandboxes run in one `agent.mjs --sandbox-pool` |
| 26 | * process at this URL instead of Cloudflare Containers (which don't run under `wrangler dev`). |
| 27 | */ |
| 28 | SANDBOX_POOL_URL?: string; |
| 29 | SANDBOX_POOL_SECRET?: string; |
| 30 | /** `off` switches web terminals (agentic/terminals.ts) off for the whole instance; on by default. */ |
| 31 | TERMINALS?: string; |
| 32 | /** Local development and end-to-end tests only: where the model proxy forwards instead of the providers' APIs. */ |
| 33 | MODEL_UPSTREAM_ANTHROPIC?: string; |
| 34 | MODEL_UPSTREAM_OPENAI?: string; |
| 35 | MODEL_UPSTREAM_OPENROUTER?: string; |
| 36 | RUN_WORKFLOW: Workflow<{ repoId: string; runId: string }>; |
| 37 | /** Cloudflare Email Sending. Missing when sending isn't set up; emails are then logged as skipped. */ |
| 38 | EMAIL?: SendEmail; |
| 39 | /** Request rate limits (lib/rate-limit.ts); none in local development. */ |
| 40 | RL_AUTH?: RateLimit; |
| 41 | RL_ANON?: RateLimit; |
| 42 | RL_ACCOUNT?: RateLimit; |
| 43 | RL_CREATE?: RateLimit; |
| 44 | /** Email jobs, sent by the queue consumer in mail/send.ts. */ |
| 45 | MAIL?: Queue<MailJob>; |
| 46 | IMPORT_WORKFLOW: Workflow<{ importId: string }>; |
| 47 | /** GitHub imports copy Git data in this container (absent under `wrangler dev`). */ |
| 48 | IMPORTER?: DurableObjectNamespace<ImportContainer>; |
| 49 | /** "external": an import agent started outside the Worker claims the Git transfer (local development and tests). */ |
| 50 | IMPORT_GIT_AGENT?: string; |
| 51 | /** Default per-account quotas (lib/quotas.ts); -1 is unlimited. Site administrators override them per account. */ |
| 52 | QUOTA_HOSTED_MINUTES?: string; |
| 53 | QUOTA_HOSTED_JOBS?: string; |
| 54 | QUOTA_SANDBOXES?: string; |
| 55 | QUOTA_REPOSITORIES?: string; |
| 56 | QUOTA_STORAGE_BYTES?: string; |
| 57 | /** "web": hosted jobs and sandboxes reach only HTTP, HTTPS and DNS (lib/egress.ts). Anything else, or unset, is open. */ |
| 58 | EGRESS?: string; |
| 59 | /** Largest source repository an import will take, in KB (GitHub `size`); default 10 GB. */ |
| 60 | IMPORT_MAX_REPO_KB?: string; |
| 61 | /** Optional GitHub OAuth app, for linking an account through the web flow instead of a gist. */ |
| 62 | GITHUB_OAUTH_CLIENT_ID?: string; |
| 63 | GITHUB_OAUTH_CLIENT_SECRET?: string; |
| 64 | |
| 65 | /** Canonical origin, e.g. https://diffinery.com */ |
| 66 | PUBLIC_URL: string; |
| 67 | /** Sender address for every email, e.g. notifications@diffinery.com. */ |
| 68 | MAIL_FROM?: string; |
| 69 | /** Comma-separated emails or logins that become site admins on first sign-in. */ |
| 70 | BOOTSTRAP_ADMINS: string; |
| 71 | /** e.g. codician.cloudflareaccess.com — empty disables Access verification. */ |
| 72 | ACCESS_TEAM_DOMAIN: string; |
| 73 | /** Access application audience tag. */ |
| 74 | ACCESS_AUD: string; |
| 75 | /** Artifact storage per repository in bytes (live artifacts plus uploads in progress); default 10 GiB. */ |
| 76 | ARTIFACT_QUOTA_BYTES?: string; |
| 77 | /** Local development only: act as this email when Access is not configured. */ |
| 78 | DEV_AUTH?: string; |
| 79 | /** |
| 80 | * "open": anyone can create an account at /signup by confirming an emailed code (auth/signup.ts). |
| 81 | * Anything else, or unset, keeps the instance invite-only. |
| 82 | */ |
| 83 | SIGNUP?: string; |
| 84 | /** Cloudflare Turnstile widget on the sign-up page; open sign-up needs it and TURNSTILE_SECRET outside local development. */ |
| 85 | TURNSTILE_SITE_KEY?: string; |
| 86 | |
| 87 | /** Secret: base64 32 bytes; root key for envelope encryption of secrets. */ |
| 88 | MASTER_KEY?: string; |
| 89 | /** Secret: ES256 private JWK (JSON) used to sign OIDC tokens for jobs. */ |
| 90 | OIDC_PRIVATE_KEY?: string; |
| 91 | /** Secret: Cloudflare Turnstile secret key, to check the sign-up page's widget (siteverify). */ |
| 92 | TURNSTILE_SECRET?: string; |
| 93 | /** Optional GitHub Enterprise host (e.g. github.example.com) the importer may download release assets from. */ |
| 94 | IMPORT_GHE_HOST?: string; |
| 95 | } |