Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
e2e spec: an explicit routes field in the descriptor
milind-soni0da1205c8460
diff --git a/companion/src/e2e/README.md b/companion/src/e2e/README.mdindex c72ab42aea..1b5e1de28c 100644--- a/companion/src/e2e/README.md+++ b/companion/src/e2e/README.md@@ -60,6 +60,10 @@ reveals nothing about `psk`: the two are separate HMAC outputs under different l- `h` and `r` are present only when the computer has a relay token (signed in, relay enabled, and the device isn't restricted to "Wi-Fi andTailscale only").- `r` lists 1 to 4 hostnames in the order to try. Each MUST match `^relay[1-9][0-9]?\.openmausbot\.com$`.+ - `routes` is optional, `"any"` or `"local"`. `"local"` means the computer restricted this device to Wi-Fi and+ Tailscale; it never comes with `h` or `r`. Absent means `"any"`, so a descriptor without `h` and `r` and without+ `"local"` only says the computer has no relay right now (signed out, or outside the rollout). The QR never carries+ `"local"`: a restriction is set per phone after pairing, and reaches it through the endpoint list.- The encoded value is at most 1,024 bytes.- **Phone parsing rules:**- A malformed `e2e` rejects the whole invite. That includes bad base64, bad JSON, a bad point, `h` without `r` or `r` without `h`, and a host@@ -348,6 +352,7 @@ These make the sections above exact where an implementation could otherwise choo- `v` must be an integer. `v > 1` means "update the app" whatever the other fields hold; `v < 1`, a string, or a missing`v` rejects.- Unknown fields are ignored. Field order is free.+- `routes`, when present, must be the string `"any"` or `"local"`, and `"local"` with `h` or `r` rejects.- base64url is strict everywhere (descriptor, keys, `h`, `conn`, tokens): the URL-safe alphabet only, no padding, andcanonical (unused low bits of the last character are zero). Decode, re-encode and compare is enough.diff --git a/companion/src/e2e/descriptor.ts b/companion/src/e2e/descriptor.tsindex ac74efcf59..35f47bb3d7 100644--- a/companion/src/e2e/descriptor.ts+++ b/companion/src/e2e/descriptor.ts@@ -8,6 +8,8 @@ export const MAX_DESCRIPTOR_CHARS = 1024;export const MAX_RELAY_NODES = 4;export const RELAY_HOST = /^relay[1-9][0-9]?\.openmausbot\.com$/;+export type DescriptorRoutes = "any" | "local";+export interface E2EDescriptor {v: 1;/** b64u of the 65-byte transport key `T.pub` */@@ -16,16 +18,24 @@ export interface E2EDescriptor {h?: string;/** relay hostnames in the order to try */r?: string[];+ /** "local": the computer restricted this device to Wi-Fi and Tailscale, so it never has `h` or `r`. Absent means+ * "any"; then a missing relay only means the computer has none (signed out, or outside the rollout). */+ routes?: DescriptorRoutes;}export function encodeDescriptor(descriptor: E2EDescriptor): string {- const json = JSON.stringify(- descriptor.h && descriptor.r ? { v: 1, k: descriptor.k, h: descriptor.h, r: descriptor.r } : { v: 1, k: descriptor.k },- );+ const relay = descriptor.h && descriptor.r ? { h: descriptor.h, r: descriptor.r } : {};+ const json = JSON.stringify({ v: 1, k: descriptor.k, ...relay, ...(descriptor.routes ? { routes: descriptor.routes } : {}) });return b64u(Buffer.from(json, "utf8"));}-export function descriptorFor(transportPublicKey: Uint8Array, relay?: { hostId: Uint8Array; nodes: readonly string[] }): E2EDescriptor {+/** A restricted device's descriptor says so and never carries the relay. */+export function descriptorFor(+ transportPublicKey: Uint8Array,+ relay?: { hostId: Uint8Array; nodes: readonly string[] },+ routes?: DescriptorRoutes,+): E2EDescriptor {+ if (routes === "local") return { v: 1, k: b64u(transportPublicKey), routes: "local" };return relay && relay.nodes.length > 0? { v: 1, k: b64u(transportPublicKey), h: b64u(relay.hostId), r: [...relay.nodes] }: { v: 1, k: b64u(transportPublicKey) };@@ -61,11 +71,14 @@ export function parseDescriptor(input: unknown): DescriptorParse {const hasHost = fields.h !== undefined;const hasRelays = fields.r !== undefined;if (hasHost !== hasRelays) return reject("relay_pair");- if (!hasHost) return { outcome: "ok", descriptor: { v: 1, k: fields.k as string }, transportKey, hostId: null };+ if (fields.routes !== undefined && fields.routes !== "any" && fields.routes !== "local") return reject("routes");+ const routes = fields.routes === undefined ? {} : { routes: fields.routes as DescriptorRoutes };+ if (routes.routes === "local" && hasHost) return reject("local_with_relay");+ if (!hasHost) return { outcome: "ok", descriptor: { v: 1, k: fields.k as string, ...routes }, transportKey, hostId: null };const hostId = typeof fields.h === "string" ? fromB64u(fields.h) : null;if (!hostId || hostId.length !== HOST_ID_BYTES) return reject("host_id");const relays = fields.r;if (!Array.isArray(relays) || relays.length < 1 || relays.length > MAX_RELAY_NODES) return reject("relays");if (!relays.every((host): host is string => typeof host === "string" && RELAY_HOST.test(host))) return reject("relay_host");- return { outcome: "ok", descriptor: { v: 1, k: fields.k as string, h: fields.h as string, r: [...relays] }, transportKey, hostId };+ return { outcome: "ok", descriptor: { v: 1, k: fields.k as string, h: fields.h as string, r: [...relays], ...routes }, transportKey, hostId };}diff --git a/companion/src/e2e/gen-vectors.ts b/companion/src/e2e/gen-vectors.tsindex a51ebd20ce..d7b6dbc28c 100644--- a/companion/src/e2e/gen-vectors.ts+++ b/companion/src/e2e/gen-vectors.ts@@ -519,6 +519,9 @@ function v7() {{ name: "four_relays", value: raw({ v: 1, k, h, r: ["relay1.openmausbot.com", "relay2.openmausbot.com", "relay3.openmausbot.com", "relay99.openmausbot.com"] }) },{ name: "key_order_and_unknown_field", value: raw({ r, x: 1, h, k, v: 1 }) },{ name: "at_1024_chars", value: padded(768) },+ { name: "routes_local", value: encodeDescriptor({ v: 1, k, routes: "local" }) },+ { name: "routes_any_with_relay", value: encodeDescriptor({ v: 1, k, h, r, routes: "any" }) },+ { name: "routes_any_without_relay", value: raw({ v: 1, k, routes: "any" }) },];const offCurve = b64u(flip(T.publicKey, 64));const invalid = [@@ -544,6 +547,9 @@ function v7() {{ name: "key_standard_alphabet", value: raw({ v: 1, k: Buffer.from(T.publicKey).toString("base64") }) },{ name: "not_json", value: b64u(Buffer.from("not json")) },{ name: "json_array", value: raw([1]) },+ { name: "routes_unknown", value: raw({ v: 1, k, routes: "wifi" }) },+ { name: "routes_not_a_string", value: raw({ v: 1, k, routes: 1 }) },+ { name: "routes_local_with_relay", value: raw({ v: 1, k, h, r, routes: "local" }) },{ name: "v2", value: raw({ v: 2, k }) },{ name: "v2_unknown_shape", value: raw({ v: 2, keys: [1, 2, 3] }) },];diff --git a/companion/src/e2e/vectors/v1.json b/companion/src/e2e/vectors/v1.jsonindex f3e542b50e..f1e46cc34f 100644--- a/companion/src/e2e/vectors/v1.json+++ b/companion/src/e2e/vectors/v1.json@@ -2141,6 +2141,41 @@"relay2.openmausbot.com"]}+ },+ {+ "name": "routes_local",+ "value": "eyJ2IjoxLCJrIjoiQkppRm1pM2J6cFFVYXlNSkVybDZlcXQyNG1VT3ZIRVVSNnV6dXRQVEhmdW5kSWd5WnhzM2JTelVNeWRHT2ZnYldkd1FzaEl5enpsTVdxeE1rTkhubWQwIiwicm91dGVzIjoibG9jYWwifQ",+ "chars": 158,+ "parsed": {+ "v": 1,+ "k": "BJiFmi3bzpQUayMJErl6eqt24mUOvHEUR6uzutPTHfundIgyZxs3bSzUMydGOfgbWdwQshIyzzlMWqxMkNHnmd0",+ "routes": "local"+ }+ },+ {+ "name": "routes_any_with_relay",+ "value": "eyJ2IjoxLCJrIjoiQkppRm1pM2J6cFFVYXlNSkVybDZlcXQyNG1VT3ZIRVVSNnV6dXRQVEhmdW5kSWd5WnhzM2JTelVNeWRHT2ZnYldkd1FzaEl5enpsTVdxeE1rTkhubWQwIiwiaCI6Imx6ODFpc0IzQnVOVjZySGdZZ0czV2ciLCJyIjpbInJlbGF5MS5vcGVubWF1c2JvdC5jb20iLCJyZWxheTIub3Blbm1hdXNib3QuY29tIl0sInJvdXRlcyI6ImFueSJ9",+ "chars": 268,+ "parsed": {+ "v": 1,+ "k": "BJiFmi3bzpQUayMJErl6eqt24mUOvHEUR6uzutPTHfundIgyZxs3bSzUMydGOfgbWdwQshIyzzlMWqxMkNHnmd0",+ "h": "lz81isB3BuNV6rHgYgG3Wg",+ "r": [+ "relay1.openmausbot.com",+ "relay2.openmausbot.com"+ ],+ "routes": "any"+ }+ },+ {+ "name": "routes_any_without_relay",+ "value": "eyJ2IjoxLCJrIjoiQkppRm1pM2J6cFFVYXlNSkVybDZlcXQyNG1VT3ZIRVVSNnV6dXRQVEhmdW5kSWd5WnhzM2JTelVNeWRHT2ZnYldkd1FzaEl5enpsTVdxeE1rTkhubWQwIiwicm91dGVzIjoiYW55In0",+ "chars": 155,+ "parsed": {+ "v": 1,+ "k": "BJiFmi3bzpQUayMJErl6eqt24mUOvHEUR6uzutPTHfundIgyZxs3bSzUMydGOfgbWdwQshIyzzlMWqxMkNHnmd0",+ "routes": "any"+ }}],"invalid": [@@ -2276,6 +2311,24 @@"chars": 4,"outcome": "reject"},+ {+ "name": "routes_unknown",+ "value": "eyJ2IjoxLCJrIjoiQkppRm1pM2J6cFFVYXlNSkVybDZlcXQyNG1VT3ZIRVVSNnV6dXRQVEhmdW5kSWd5WnhzM2JTelVNeWRHT2ZnYldkd1FzaEl5enpsTVdxeE1rTkhubWQwIiwicm91dGVzIjoid2lmaSJ9",+ "chars": 156,+ "outcome": "reject"+ },+ {+ "name": "routes_not_a_string",+ "value": "eyJ2IjoxLCJrIjoiQkppRm1pM2J6cFFVYXlNSkVybDZlcXQyNG1VT3ZIRVVSNnV6dXRQVEhmdW5kSWd5WnhzM2JTelVNeWRHT2ZnYldkd1FzaEl5enpsTVdxeE1rTkhubWQwIiwicm91dGVzIjoxfQ",+ "chars": 150,+ "outcome": "reject"+ },+ {+ "name": "routes_local_with_relay",+ "value": "eyJ2IjoxLCJrIjoiQkppRm1pM2J6cFFVYXlNSkVybDZlcXQyNG1VT3ZIRVVSNnV6dXRQVEhmdW5kSWd5WnhzM2JTelVNeWRHT2ZnYldkd1FzaEl5enpsTVdxeE1rTkhubWQwIiwiaCI6Imx6ODFpc0IzQnVOVjZySGdZZ0czV2ciLCJyIjpbInJlbGF5MS5vcGVubWF1c2JvdC5jb20iLCJyZWxheTIub3Blbm1hdXNib3QuY29tIl0sInJvdXRlcyI6ImxvY2FsIn0",+ "chars": 271,+ "outcome": "reject"+ },{"name": "v2","value": "eyJ2IjoyLCJrIjoiQkppRm1pM2J6cFFVYXlNSkVybDZlcXQyNG1VT3ZIRVVSNnV6dXRQVEhmdW5kSWd5WnhzM2JTelVNeWRHT2ZnYldkd1FzaEl5enpsTVdxeE1rTkhubWQwIn0",diff --git a/companion/src/e2e/vectors/v1.sha256 b/companion/src/e2e/vectors/v1.sha256index 81a71f720b..489b193b30 100644--- a/companion/src/e2e/vectors/v1.sha256+++ b/companion/src/e2e/vectors/v1.sha256@@ -1 +1 @@-57550129e3b4cd98c3289523926413d5382172247b8991e133c128c0fd56aac3 v1.json+734415cc7b8aa2f57de6788a72b058c2eb48a11fcfb20d0fab489cf46668ed00 v1.json