(sandboxId: string)
| 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 | */ |
| 157 | export function sandboxIdFromHostnameLabel(label: string): string | null { |
| 158 | const normalized = label.toLowerCase(); |
| 159 | const instanceMatch = INSTANCE_LABEL_RE.exec(normalized); |
no test coverage detected