@teamclaws/teamclaw 2026.11.0 → 2026.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.mjs +272 -2
- package/dist/index.js +54 -32
- package/dist/src/config.js +24 -0
- package/dist/src/controller/auth-routes.js +129 -0
- package/dist/src/controller/clarification-routes.js +1 -1
- package/dist/src/controller/controller-planning.js +1 -0
- package/dist/src/controller/controller-routes.js +195 -0
- package/dist/src/controller/controller-service.js +67 -10
- package/dist/src/controller/controller-tools.js +3 -1
- package/dist/src/controller/github-auth.js +2 -1
- package/dist/src/controller/http-server.js +51 -16
- package/dist/src/controller/kickoff-orchestrator.js +3 -39
- package/dist/src/controller/message-delivery.js +4 -1
- package/dist/src/controller/orchestration-manifest.js +5 -65
- package/dist/src/controller/preview-manager.js +51 -3
- package/dist/src/controller/profile-switch.js +42 -22
- package/dist/src/controller/provisioning/backend-contract.js +9 -0
- package/dist/src/controller/provisioning/container-shared.js +64 -0
- package/dist/src/controller/provisioning/docker.js +214 -0
- package/dist/src/controller/provisioning/kubernetes.js +244 -0
- package/dist/src/controller/provisioning/plugin-root.js +41 -0
- package/dist/src/controller/provisioning/process-supervisor.js +190 -0
- package/dist/src/controller/provisioning-config.js +239 -0
- package/dist/src/controller/repo-routes.js +70 -4
- package/dist/src/controller/report-routes.js +56 -0
- package/dist/src/controller/route-table.js +67 -1045
- package/dist/src/controller/security.js +775 -0
- package/dist/src/controller/status-routes.js +287 -0
- package/dist/src/controller/task-assignment.js +5 -2
- package/dist/src/controller/task-execution.js +31 -0
- package/dist/src/controller/task-results.js +10 -0
- package/dist/src/controller/tunnel-manager.js +41 -8
- package/dist/src/controller/tunnel-routes.js +225 -0
- package/dist/src/controller/websocket.js +6 -2
- package/dist/src/controller/webui-routes.js +49 -0
- package/dist/src/controller/worker-provisioning.js +39 -949
- package/dist/src/controller/workflow-routes.js +407 -0
- package/dist/src/controller/workspace-routes.js +200 -0
- package/dist/src/git-collaboration.js +4 -9
- package/dist/src/identity.js +12 -1
- package/dist/src/profile-loader.js +119 -1
- package/dist/src/profiles/banking.json +26 -2
- package/dist/src/profiles/schema.json +82 -2
- package/dist/src/prompt-policy.js +18 -6
- package/dist/src/protocol.js +66 -3
- package/dist/src/shared/clarification-schema.js +65 -0
- package/dist/src/shared/github-auth.js +15 -0
- package/dist/src/shared/kickoff-prompt.js +37 -0
- package/dist/src/shared/utils.js +47 -0
- package/dist/src/state.js +89 -3
- package/dist/src/types.js +15 -1
- package/dist/src/ui/app.js +846 -62
- package/dist/src/ui/github-login.html +1 -0
- package/dist/src/ui/index.html +102 -36
- package/dist/src/worker/http-handler.js +59 -0
- package/dist/src/worker/skill-installer.js +3 -9
- package/dist/src/worker/tools.js +20 -10
- package/dist/src/worker/worker-service.js +17 -4
- package/index.ts +61 -32
- package/openclaw.plugin.json +23 -2
- package/package.json +1 -1
- package/src/config.ts +24 -0
- package/src/controller/auth-routes.ts +157 -0
- package/src/controller/clarification-routes.ts +1 -1
- package/src/controller/controller-planning.ts +8 -0
- package/src/controller/controller-routes.ts +237 -0
- package/src/controller/controller-service.ts +128 -10
- package/src/controller/controller-tools.ts +5 -2
- package/src/controller/github-auth.ts +28 -63
- package/src/controller/http-server.ts +66 -17
- package/src/controller/kickoff-orchestrator.ts +3 -42
- package/src/controller/message-delivery.ts +4 -1
- package/src/controller/orchestration-manifest.ts +8 -71
- package/src/controller/preview-manager.ts +53 -3
- package/src/controller/profile-switch.ts +53 -23
- package/src/controller/provisioning/backend-contract.ts +51 -0
- package/src/controller/provisioning/container-shared.ts +84 -0
- package/src/controller/provisioning/docker.ts +260 -0
- package/src/controller/provisioning/kubernetes.ts +263 -0
- package/src/controller/provisioning/plugin-root.ts +42 -0
- package/src/controller/provisioning/process-supervisor.ts +214 -0
- package/src/controller/provisioning-config.ts +289 -0
- package/src/controller/repo-routes.ts +84 -12
- package/src/controller/report-routes.ts +64 -0
- package/src/controller/route-table.ts +133 -1152
- package/src/controller/security.ts +899 -0
- package/src/controller/status-routes.ts +354 -0
- package/src/controller/task-assignment.ts +5 -1
- package/src/controller/task-execution.ts +43 -0
- package/src/controller/task-results.ts +12 -0
- package/src/controller/tunnel-manager.ts +45 -8
- package/src/controller/tunnel-routes.ts +231 -0
- package/src/controller/websocket.ts +19 -3
- package/src/controller/webui-routes.ts +55 -0
- package/src/controller/worker-provisioning.ts +51 -1117
- package/src/controller/workflow-routes.ts +498 -0
- package/src/controller/workspace-routes.ts +222 -0
- package/src/git-collaboration.ts +4 -9
- package/src/identity.ts +13 -1
- package/src/profile-loader.ts +167 -1
- package/src/profiles/banking.json +26 -2
- package/src/profiles/schema.json +82 -2
- package/src/prompt-policy.ts +19 -6
- package/src/protocol.ts +72 -2
- package/src/shared/clarification-schema.ts +81 -0
- package/src/shared/github-auth.ts +92 -0
- package/src/shared/kickoff-prompt.ts +47 -0
- package/src/shared/utils.ts +51 -0
- package/src/state.ts +92 -3
- package/src/teamauto/github-client.ts +2 -1
- package/src/teamauto/repo-sync.ts +2 -1
- package/src/teamauto/scheduler.ts +2 -1
- package/src/types.ts +130 -1
- package/src/ui/app.js +846 -62
- package/src/ui/github-login.html +1 -0
- package/src/ui/index.html +102 -36
- package/src/worker/http-handler.ts +64 -1
- package/src/worker/skill-installer.ts +3 -9
- package/src/worker/tools.ts +21 -10
- package/src/worker/worker-service.ts +18 -4
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// Issue #226 W2 (route-table carve-up): the tunnel-side route tables (the
|
|
2
|
+
// pre-PR-D http-server.ts outer callback's tunnel branch, moved into
|
|
3
|
+
// route-table.ts verbatim by PR-D) moved verbatim into this module -
|
|
4
|
+
// bodies byte-identical, only the module home changed. route-table.ts
|
|
5
|
+
// re-exports both factories so http-server.ts's imports are unchanged.
|
|
6
|
+
// The tunnel gate-page HTML rendering (gatePageHtml calls below) and the
|
|
7
|
+
// form reader live here with their only consumers. This module imports
|
|
8
|
+
// http-server.js as TYPE ONLY (ControllerHttpDeps), so the module graph
|
|
9
|
+
// stays acyclic - same discipline as security.ts.
|
|
10
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
11
|
+
import { sendJson, sendError } from "../protocol.js";
|
|
12
|
+
import { getGithubAuthManager } from "./github-auth.js";
|
|
13
|
+
import { gatePageHtml, computeGateCookie, GATE_COOKIE_NAME, selfHostedTokenFromEnv, type TunnelManager } from "./tunnel-manager.js";
|
|
14
|
+
import { isLanIp, isProtectionOn, secretsEqual } from "./security.js";
|
|
15
|
+
import type { ControllerHttpDeps } from "./http-server.js";
|
|
16
|
+
import type { RouteDef } from "./route-table.js";
|
|
17
|
+
|
|
18
|
+
async function readFormBody(request: IncomingMessage): Promise<Record<string, unknown>> {
|
|
19
|
+
const chunks: Buffer[] = [];
|
|
20
|
+
for await (const chunk of request) chunks.push(chunk as Buffer);
|
|
21
|
+
const raw = Buffer.concat(chunks).toString("utf8");
|
|
22
|
+
const out: Record<string, unknown> = {};
|
|
23
|
+
for (const [k, v] of new URLSearchParams(raw)) out[k] = v;
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// ===========================================================================
|
|
29
|
+
// Tunnel-side route tables (pre-PR-D http-server.ts lines 348-432, the
|
|
30
|
+
// outer server callback's tunnel branch). These run BEFORE handleRequest
|
|
31
|
+
// and are split exactly along the old viaTunnel if/else:
|
|
32
|
+
// - viaTunnel: the gate page routes answer; every other tunnel request
|
|
33
|
+
// must pass the gate cookie (403 gate page), then continues to the
|
|
34
|
+
// controller route table;
|
|
35
|
+
// - direct (non-tunnel): the tunnel management API answers, everything
|
|
36
|
+
// else continues to the controller route table.
|
|
37
|
+
// ===========================================================================
|
|
38
|
+
|
|
39
|
+
// Issue #237 W3: online-guessing throttle for POST /__tunnel_gate/verify.
|
|
40
|
+
// The endpoint answers on the PUBLIC tunnel URL, so repeated failures cool
|
|
41
|
+
// the gate down. Deliberately GLOBAL (not per-IP): every via-tunnel request
|
|
42
|
+
// arrives from the local cloudflared socket, so a per-IP key would collapse
|
|
43
|
+
// to one bucket for the whole internet anyway - this mirrors the pairing
|
|
44
|
+
// code throttle in security.ts (timestamps pruned against a sliding window).
|
|
45
|
+
const GATE_VERIFY_FAILURE_MAX = 10;
|
|
46
|
+
const GATE_VERIFY_COOLDOWN_MS = 60_000;
|
|
47
|
+
const gateVerifyFailures: number[] = [];
|
|
48
|
+
|
|
49
|
+
function gateVerifyThrottled(): boolean {
|
|
50
|
+
const now = Date.now();
|
|
51
|
+
while (gateVerifyFailures.length > 0 && now - gateVerifyFailures[0]! >= GATE_VERIFY_COOLDOWN_MS) {
|
|
52
|
+
gateVerifyFailures.shift();
|
|
53
|
+
}
|
|
54
|
+
return gateVerifyFailures.length >= GATE_VERIFY_FAILURE_MAX;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function recordGateVerifyFailure(): void {
|
|
58
|
+
gateVerifyFailures.push(Date.now());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** GET /__tunnel_gate + GET / + POST /__tunnel_gate/verify (via tunnel only). */
|
|
62
|
+
export function createTunnelGateRoutes(tunnelManager: TunnelManager): readonly RouteDef[] {
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
method: "GET",
|
|
66
|
+
path: "/__tunnel_gate",
|
|
67
|
+
handler: ({ res, req }) => {
|
|
68
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
69
|
+
res.end(gatePageHtml(String(req.headers.host), false));
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
// Valid gate cookie on "/" goes straight to the dashboard; the gate
|
|
74
|
+
// page only greets visitors who have not authenticated yet.
|
|
75
|
+
method: "GET",
|
|
76
|
+
path: "/",
|
|
77
|
+
handler: ({ res, req, pathname }) => {
|
|
78
|
+
if (pathname === "/" && tunnelManager.gateAllows(req)) {
|
|
79
|
+
res.writeHead(302, { Location: "/ui/" });
|
|
80
|
+
res.end();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
84
|
+
res.end(gatePageHtml(String(req.headers.host), false));
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
method: "POST",
|
|
89
|
+
path: "/__tunnel_gate/verify",
|
|
90
|
+
handler: async ({ res, req }) => {
|
|
91
|
+
// Issue #237 W3: check the throttle BEFORE touching the token - a
|
|
92
|
+
// cooled-down gate answers 429 without comparing anything, so
|
|
93
|
+
// brute-force attempts cannot outrun the cooldown.
|
|
94
|
+
if (gateVerifyThrottled()) {
|
|
95
|
+
res.setHeader("Retry-After", "60");
|
|
96
|
+
sendJson(res, 429, { error: "Too many gate verification attempts. Wait a minute and try again." });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const form = await readFormBody(req);
|
|
100
|
+
// Issue #237 W3: gate tokens are 128-bit base64url and therefore
|
|
101
|
+
// case-sensitive - only surrounding whitespace is normalized (the
|
|
102
|
+
// old .toUpperCase() fold belonged to the retired 8-char token).
|
|
103
|
+
const submitted = String((form as { token?: unknown }).token ?? "").trim();
|
|
104
|
+
const st = tunnelManager.status();
|
|
105
|
+
// Issue #237 W3: constant-time comparison (plain === was
|
|
106
|
+
// timing-leaky on this internet-reachable endpoint).
|
|
107
|
+
if (st.active && st.gateToken && secretsEqual(submitted, st.gateToken)) {
|
|
108
|
+
const cookie = `${GATE_COOKIE_NAME}=${computeGateCookie(st.gateToken, st.tunnelId ?? "")}; Path=/; Max-Age=43200; HttpOnly; SameSite=Lax`;
|
|
109
|
+
res.writeHead(302, { "Set-Cookie": cookie, Location: "/" });
|
|
110
|
+
res.end();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
recordGateVerifyFailure();
|
|
114
|
+
res.writeHead(403, { "Content-Type": "text/html; charset=utf-8" });
|
|
115
|
+
res.end(gatePageHtml(String(req.headers.host), true));
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** /api/v1/tunnel/* management API (direct requests only, never via tunnel). */
|
|
122
|
+
export function createTunnelManagementRoutes(tunnelManager: TunnelManager, deps: ControllerHttpDeps): readonly RouteDef[] {
|
|
123
|
+
const { config, logger } = deps;
|
|
124
|
+
|
|
125
|
+
// Issue #222 (coordinated scope): creating a public tunnel is an
|
|
126
|
+
// internet-EXPOSURE escalation, so in L0 (protection off) the three start
|
|
127
|
+
// endpoints accept only loopback/LAN origins - a public-network peer that
|
|
128
|
+
// merely reached the port must never be able to open a share URL into
|
|
129
|
+
// this controller. While protection is on, the device gate in
|
|
130
|
+
// http-server.ts has already authenticated the caller (#23) and stays the
|
|
131
|
+
// governing rule: a deliberately paired device may share, including
|
|
132
|
+
// remotely. Loopback/LAN classification reuses the security module's
|
|
133
|
+
// isLanIp (via-tunnel requests never reach this table - they dispatch to
|
|
134
|
+
// the gate table instead - so the raw socket peer is authoritative).
|
|
135
|
+
const tunnelStartAllowedFrom = (req: IncomingMessage, res: ServerResponse): boolean => {
|
|
136
|
+
if (isProtectionOn(deps.getTeamState())) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
if (isLanIp(req.socket.remoteAddress)) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
sendJson(res, 403, {
|
|
143
|
+
error: "forbidden",
|
|
144
|
+
hint: "Creating a public tunnel exposes this controller to the internet. Start tunnels from the controller host (loopback or LAN), or enable device pairing (POST /api/v1/security/enable from the controller host) and share from a paired device.",
|
|
145
|
+
});
|
|
146
|
+
return false;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return [
|
|
150
|
+
{
|
|
151
|
+
method: "GET",
|
|
152
|
+
path: "/api/v1/tunnel/status",
|
|
153
|
+
handler: ({ res }) => {
|
|
154
|
+
sendJson(res, 200, tunnelManager.status());
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
method: "POST",
|
|
159
|
+
path: "/api/v1/tunnel/start",
|
|
160
|
+
handler: async ({ req, res }) => {
|
|
161
|
+
if (!tunnelStartAllowedFrom(req, res)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const authStatus = await getGithubAuthManager(config, logger).getStatus();
|
|
165
|
+
const account = authStatus.account;
|
|
166
|
+
if (!account?.login) { sendError(res, 401, "GitHub login required to share a tunnel"); return; }
|
|
167
|
+
// Async launch: poll /tunnel/status for phase progress and the
|
|
168
|
+
// resulting hostname/gateToken once startOp.phase === "done".
|
|
169
|
+
const launched = tunnelManager.start(account.login);
|
|
170
|
+
sendJson(res, 202, { launched, status: tunnelManager.status() });
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
// Self-hosted: user-owned Cloudflare tunnel via connector token (no
|
|
175
|
+
// GitHub login, no platform tunnel server). Token from the request
|
|
176
|
+
// body, or the TEAMCLAW_TUNNEL_TOKEN env injection when body is empty.
|
|
177
|
+
method: "POST",
|
|
178
|
+
path: "/api/v1/tunnel/start-self-hosted",
|
|
179
|
+
handler: async ({ req, res }) => {
|
|
180
|
+
if (!tunnelStartAllowedFrom(req, res)) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
let token = "";
|
|
184
|
+
try {
|
|
185
|
+
const body = await readFormBody(req) as { token?: unknown };
|
|
186
|
+
token = String(body.token ?? "");
|
|
187
|
+
} catch { /* fall through to env */ }
|
|
188
|
+
if (!token.trim()) {
|
|
189
|
+
const envToken = selfHostedTokenFromEnv();
|
|
190
|
+
if (!envToken) { sendError(res, 400, "connector token required (or set TEAMCLAW_TUNNEL_TOKEN)"); return; }
|
|
191
|
+
token = envToken;
|
|
192
|
+
}
|
|
193
|
+
const r = tunnelManager.startSelfHosted(token);
|
|
194
|
+
if (!r.launched) { sendError(res, 400, r.error ?? "failed to start self-hosted tunnel"); return; }
|
|
195
|
+
sendJson(res, 202, { launched: true, status: tunnelManager.status() });
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
method: "POST",
|
|
200
|
+
path: "/api/v1/tunnel/start-quick",
|
|
201
|
+
handler: ({ req, res }) => {
|
|
202
|
+
if (!tunnelStartAllowedFrom(req, res)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const r = tunnelManager.startQuick();
|
|
206
|
+
if (!r.launched) { sendError(res, 400, r.error ?? "failed to start quick tunnel"); return; }
|
|
207
|
+
sendJson(res, 202, { launched: true, status: tunnelManager.status() });
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
method: "POST",
|
|
212
|
+
path: "/api/v1/tunnel/stop",
|
|
213
|
+
handler: async ({ res }) => {
|
|
214
|
+
await tunnelManager.stop();
|
|
215
|
+
sendJson(res, 200, tunnelManager.status());
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
method: "POST",
|
|
220
|
+
path: "/api/v1/tunnel/install-cloudflared",
|
|
221
|
+
handler: async ({ res }) => {
|
|
222
|
+
try {
|
|
223
|
+
const result = await tunnelManager.installCloudflared();
|
|
224
|
+
sendJson(res, result.ok ? 200 : 500, { ...result, status: tunnelManager.status() });
|
|
225
|
+
} catch (err) {
|
|
226
|
+
sendError(res, 500, err instanceof Error ? err.message : "install failed");
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocketServer, WebSocket } from "ws";
|
|
2
|
-
import type { Server } from "node:http";
|
|
2
|
+
import type { IncomingMessage, Server } from "node:http";
|
|
3
3
|
import type { PluginLogger } from "../../api.js";
|
|
4
4
|
|
|
5
5
|
export type WsEvent =
|
|
@@ -34,6 +34,18 @@ export type WsEvent =
|
|
|
34
34
|
// switched and a restart is the reliable way back to a known-good team.
|
|
35
35
|
| { type: "team.switch_failed"; data: { previousProfileId: string; targetProfileId: string; reason: string } };
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Issue #23: optional upgrade guard. While device protection is on, the
|
|
39
|
+
* composition root passes a `verifyUpgrade` predicate that validates the
|
|
40
|
+
* upgrade request's device token (query ?token= / cookie / Bearer header,
|
|
41
|
+
* see controller/security.ts createWebSocketUpgradeGuard); returning false
|
|
42
|
+
* makes ws answer the upgrade with 401. Without the option the server is
|
|
43
|
+
* wide open - the pre-issue L0 behavior.
|
|
44
|
+
*/
|
|
45
|
+
export type TeamWebSocketAttachOptions = {
|
|
46
|
+
verifyUpgrade?: (req: IncomingMessage) => boolean;
|
|
47
|
+
};
|
|
48
|
+
|
|
37
49
|
export class TeamWebSocketServer {
|
|
38
50
|
private wss: WebSocketServer | null = null;
|
|
39
51
|
private logger: PluginLogger;
|
|
@@ -42,8 +54,12 @@ export class TeamWebSocketServer {
|
|
|
42
54
|
this.logger = logger;
|
|
43
55
|
}
|
|
44
56
|
|
|
45
|
-
attach(server: Server): void {
|
|
46
|
-
this.wss = new WebSocketServer({
|
|
57
|
+
attach(server: Server, options?: TeamWebSocketAttachOptions): void {
|
|
58
|
+
this.wss = new WebSocketServer({
|
|
59
|
+
server,
|
|
60
|
+
path: "/ws",
|
|
61
|
+
...(options?.verifyUpgrade ? { verifyClient: (info: { req: IncomingMessage }) => options.verifyUpgrade!(info.req) } : {}),
|
|
62
|
+
});
|
|
47
63
|
|
|
48
64
|
this.wss.on("connection", (ws) => {
|
|
49
65
|
this.logger.info("WebSocket: client connected");
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Issue #226 W2 (route-table carve-up): the Web UI static-serving handlers
|
|
2
|
+
// moved verbatim from route-table.ts (PR-D had moved them verbatim from
|
|
3
|
+
// http-server.ts before that) - bodies byte-identical, only the module home
|
|
4
|
+
// changed. route-table.ts keeps the table entries that bind these handlers.
|
|
5
|
+
// Like security.ts, this module imports route-table.js as TYPE ONLY
|
|
6
|
+
// (RouteContext), so the module graph stays acyclic.
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import type { RouteContext } from "./route-table.js";
|
|
9
|
+
import { serveStaticFile, serveVersionedHtml } from "./ui-assets.js";
|
|
10
|
+
|
|
11
|
+
function webUiRootRoute(ctx: RouteContext): void {
|
|
12
|
+
const { res } = ctx;
|
|
13
|
+
res.statusCode = 302;
|
|
14
|
+
res.setHeader("Location", "/ui");
|
|
15
|
+
res.end();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function webUiIndexRoute(ctx: RouteContext): void {
|
|
19
|
+
const { res } = ctx;
|
|
20
|
+
const uiPath = path.join(import.meta.dirname, "..", "ui");
|
|
21
|
+
serveVersionedHtml(res, path.join(uiPath, "index.html"));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Standalone GitHub device-login page (big user code + prefilled link + polling).
|
|
25
|
+
function webUiGithubLoginPageRoute(ctx: RouteContext): void {
|
|
26
|
+
const { res } = ctx;
|
|
27
|
+
const uiPath = path.join(import.meta.dirname, "..", "ui");
|
|
28
|
+
serveStaticFile(res, path.join(uiPath, "github-login.html"), "text/html; charset=utf-8");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function webUiAssetsRoute(ctx: RouteContext): void {
|
|
32
|
+
const { res, pathname } = ctx;
|
|
33
|
+
const uiPath = path.join(import.meta.dirname, "..", "ui");
|
|
34
|
+
const file = pathname.slice(4); // remove "/ui/"
|
|
35
|
+
if (file.endsWith(".css")) {
|
|
36
|
+
serveStaticFile(res, path.join(uiPath, file), "text/css; charset=utf-8");
|
|
37
|
+
} else if (file.endsWith(".js")) {
|
|
38
|
+
serveStaticFile(res, path.join(uiPath, file), "application/javascript; charset=utf-8");
|
|
39
|
+
} else if (file.endsWith(".png")) {
|
|
40
|
+
serveStaticFile(res, path.join(uiPath, file), "image/png");
|
|
41
|
+
} else if (file.endsWith(".svg")) {
|
|
42
|
+
serveStaticFile(res, path.join(uiPath, file), "image/svg+xml; charset=utf-8");
|
|
43
|
+
} else if (file.endsWith(".ico")) {
|
|
44
|
+
serveStaticFile(res, path.join(uiPath, file), "image/x-icon");
|
|
45
|
+
} else {
|
|
46
|
+
serveStaticFile(res, path.join(uiPath, file), "application/octet-stream");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
webUiRootRoute,
|
|
52
|
+
webUiIndexRoute,
|
|
53
|
+
webUiGithubLoginPageRoute,
|
|
54
|
+
webUiAssetsRoute,
|
|
55
|
+
};
|