| 1234567891011121314151617181920212223242526272829303132 |
- export const USAGE = "Usage: codex-app-server-bridge app-server";
- export class ConfigurationError extends Error {
- constructor(message) {
- super(message);
- this.name = "ConfigurationError";
- }
- }
- export function validateInvocation(arguments_) {
- if (arguments_.length !== 1 || arguments_[0] !== "app-server") {
- throw new ConfigurationError(USAGE);
- }
- }
- export function parseEndpoint(value) {
- if (value === undefined || value.length === 0) {
- throw new ConfigurationError("CODEX_APP_SERVER_URL is required");
- }
- const match = /^ws:\/\/(127\.0\.0\.1|\[::1\]):([0-9]+)\/?$/.exec(value);
- if (match === null) {
- throw new ConfigurationError("CODEX_APP_SERVER_URL must be ws://127.0.0.1:<port> or ws://[::1]:<port>");
- }
- const host = match[1];
- const portText = match[2];
- if (host === undefined || portText === undefined) {
- throw new ConfigurationError("CODEX_APP_SERVER_URL is invalid");
- }
- const port = Number(portText);
- if (!Number.isSafeInteger(port) || port < 1 || port > 65_535) {
- throw new ConfigurationError("CODEX_APP_SERVER_URL must contain a valid explicit port");
- }
- const display = `ws://${host}:${port}`;
- return { url: display, display };
- }
|