Gateway: fallback routes per host, for the laptop's VPN address
Gateway / check (push) Successful in 9s
Gateway / image (push) Successful in 22s

This commit is contained in:
gib committed 2026-11-01 13:20:02 -05:00
1 parent f46c803ad4
commit 42b6a4920c
8 files changed
+151 -20

No files matched your search

+16 -5
View File
@@ -4,14 +4,17 @@
import { loadConfig } from "./config.ts";
import { openDb } from "./db.ts";
import { hostUrls } from "./hub.ts";
import { ORCHESTRATION_PROTOCOL_VERSION, type EnvironmentDescriptor } from "./t3/types.ts";
const USAGE = `wristcode <command>
host add <url> <pairing-credential> [--label <name>]
host add <url> <pairing-credential> [--label <name>] [--alt-url <url>]...
Connect a T3 Code server. Make the credential on that host with:
t3 auth pairing create --scope orchestration:read --scope orchestration:operate --label "WristCode gateway"
Run it again with a fresh credential to renew the gateway's token.
--alt-url adds a fallback route to the same server, such as a VPN address, tried in order
when <url> does not answer. Repeat it for more.
host list
host remove <id or label>
pair
@@ -39,7 +42,7 @@ async function run() {
return hostAdd(rest);
case "host list":
for (const host of db.hosts.list()) {
console.log(`${host.label}\t${host.url}\t${host.id}\ttoken expires ${host.token_expires_at ?? "unknown"}`);
console.log(`${host.label}\t${hostUrls(host).join(" ")}\t${host.id}\ttoken expires ${host.token_expires_at ?? "unknown"}`);
}
return;
case "host remove":
@@ -69,9 +72,16 @@ async function run() {
/** Exchanges a T3 pairing credential for a bearer session and saves the host. */
async function hostAdd(args: string[]) {
const labelFlag = args.indexOf("--label");
const label = labelFlag === -1 ? undefined : args[labelFlag + 1];
const [rawUrl, credential] = args.filter((_, index) => labelFlag === -1 || (index !== labelFlag && index !== labelFlag + 1));
const positional: string[] = [];
const altUrls: string[] = [];
let label: string | undefined;
for (let index = 0; index < args.length; index++) {
const arg = args[index]!;
if (arg === "--label") label = args[++index];
else if (arg === "--alt-url") altUrls.push(new URL(args[++index] ?? "").origin);
else positional.push(arg);
}
const [rawUrl, credential] = positional;
if (!rawUrl || !credential) throw new Error(USAGE);
const url = new URL(rawUrl).origin;
@@ -104,6 +114,7 @@ async function hostAdd(args: string[]) {
id: descriptor.environmentId,
label: label ?? descriptor.label,
url,
alt_urls: altUrls.length > 0 ? JSON.stringify(altUrls) : null,
environment_id: descriptor.environmentId,
token: token.access_token,
token_expires_at: token.expires_in ? new Date(Date.now() + token.expires_in * 1000).toISOString() : null,