MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / hostnameLabelFromSandboxId

Function hostnameLabelFromSandboxId

packages/worker-utils/src/hostname-label.ts:141–156  ·  view source on GitHub ↗
(sandboxId: string)

Source from the content-addressed store, hash-verified

139 }
140
141 const legacyUserIdBytes = base64urlToBytesOrNull(sandboxId);
142 if (!legacyUserIdBytes || legacyUserIdBytes.length === 0) return null;
143
144 const label = `u-${bytesToBase32Hex(legacyUserIdBytes)}`;
145 if (label.length > MAX_HOSTNAME_LABEL_LENGTH) return null;
146 return label;
147}
148
149/**
150 * Reverse of `hostnameLabelFromSandboxId`: parse a hostname label back
151 * into its sandboxId, returning `null` if the label doesn't match either
152 * scheme.
153 *
154 * Used by the host-based router in a follow-up PR to resolve
155 * `<label>.kiloclaw.ai` to the owning Instance DO.
156 */
157export function sandboxIdFromHostnameLabel(label: string): string | null {
158 const normalized = label.toLowerCase();
159 const instanceMatch = INSTANCE_LABEL_RE.exec(normalized);

Callers 5

workerUrlForInstanceFunction · 0.90
buildEnvVarsFunction · 0.90
index.test.tsFile · 0.85

Calls 3

isInstanceKeyedSandboxIdFunction · 0.90
bytesToBase32HexFunction · 0.85
base64urlToBytesFunction · 0.70

Tested by

no test coverage detected