pr_01m47d15m3e54sn21z27rpy5n9/deploy/self-host/workers/off/index.js

73 lines2,052 bytesCodeBlame
1// A service that is turned off on this installation.
2//
3// Self-hosted phase 1 runs the core forge only. The site and the services
4// still hold bindings to the runner (agents), the context hub and the
5// deployments' builders; this Worker stands in for each of them, so a
6// page that asks "are agents on here?" is told no instead of failing.
7//
8// - As the runner (RunnerApi in packages/contracts/src/runner.ts): agents
9// are not enabled, no model is reachable, and starting anything fails with
10// a message that says why.
11// - For the JSON protocol the Rust services speak (`POST /rpc/<method>`):
12// every method answers with a failed Result.
13//
14// OFF_NAME names the feature in those messages, such as "Agents".
15
16import { WorkerEntrypoint } from "cloudflare:workers";
17
18function off(env) {
19 const name = env.OFF_NAME ?? "This feature";
20 return {
21 ok: false,
22 error: { code: "forbidden", message: `${name} are off on this installation of g1t.` },
23 };
24}
25
26export default class Off extends WorkerEntrypoint {
27 // ── The runner's methods, as the site calls them ──
28 async enabled() {
29 return false;
30 }
31 async modelAccess() {
32 return { own: null, hosted: false, trial: null };
33 }
34 async instructions() {
35 return off(this.env);
36 }
37 async run() {
38 return off(this.env);
39 }
40 async plan() {
41 return off(this.env);
42 }
43 async applyPlan() {
44 return off(this.env);
45 }
46 async update() {
47 return off(this.env);
48 }
49 async review() {
50 return off(this.env);
51 }
52 async recheck() {
53 return off(this.env);
54 }
55 async stopRun() {
56 return off(this.env);
57 }
58
59 // ── The JSON protocol ──
60 async fetch(request) {
61 const { pathname } = new URL(request.url);
62 if (request.method === "POST" && pathname.startsWith("/rpc/")) {
63 return Response.json(off(this.env));
64 }
65 return new Response("Off on this installation.", { status: 404 });
66 }
67
68 // Events and schedules for a service that is off are dropped.
69 async queue(batch) {
70 batch.ackAll();
71 }
72 async scheduled() {}
73}