Merge main into PR #221 to resolve conflicts

Resolved merge conflicts in public/views/settings.html:
- Fixed HTML entity escaping for quote characters in presetHint text
- Fixed HTML entity escaping for pendingPresetName text
This commit is contained in:
Badri Narayanan S
2026-02-01 16:20:55 +05:30
9 changed files with 82 additions and 36 deletions

View File

@@ -141,9 +141,10 @@ export function extractCodeFromInput(input) {
* Attempt to bind server to a specific port
* @param {http.Server} server - HTTP server instance
* @param {number} port - Port to bind to
* @param {string} host - Host to bind to
* @returns {Promise<number>} Resolves with port on success, rejects on error
*/
function tryBindPort(server, port) {
function tryBindPort(server, port, host = '0.0.0.0') {
return new Promise((resolve, reject) => {
const onError = (err) => {
server.removeListener('listening', onSuccess);
@@ -155,7 +156,7 @@ function tryBindPort(server, port) {
};
server.once('error', onError);
server.once('listening', onSuccess);
server.listen(port);
server.listen(port, host);
});
}
@@ -173,6 +174,7 @@ export function startCallbackServer(expectedState, timeoutMs = 120000) {
let timeoutId = null;
let isAborted = false;
let actualPort = OAUTH_CONFIG.callbackPort;
const host = process.env.HOST || '0.0.0.0';
const promise = new Promise(async (resolve, reject) => {
// Build list of ports to try: primary + fallbacks
@@ -180,7 +182,7 @@ export function startCallbackServer(expectedState, timeoutMs = 120000) {
const errors = [];
server = http.createServer((req, res) => {
const url = new URL(req.url, `http://localhost:${actualPort}`);
const url = new URL(req.url, `http://${host === '0.0.0.0' ? 'localhost' : host}:${actualPort}`);
if (url.pathname !== '/oauth-callback') {
res.writeHead(404);
@@ -264,14 +266,14 @@ export function startCallbackServer(expectedState, timeoutMs = 120000) {
let boundSuccessfully = false;
for (const port of portsToTry) {
try {
await tryBindPort(server, port);
await tryBindPort(server, port, host);
actualPort = port;
boundSuccessfully = true;
if (port !== OAUTH_CONFIG.callbackPort) {
logger.warn(`[OAuth] Primary port ${OAUTH_CONFIG.callbackPort} unavailable, using fallback port ${port}`);
} else {
logger.info(`[OAuth] Callback server listening on port ${port}`);
logger.info(`[OAuth] Callback server listening on ${host}:${port}`);
}
break;
} catch (err) {

View File

@@ -8,9 +8,12 @@ import { DEFAULT_PORT } from './constants.js';
import { logger } from './utils/logger.js';
import { config } from './config.js';
import { getStrategyLabel, STRATEGY_NAMES, DEFAULT_STRATEGY } from './account-manager/strategies/index.js';
import { getPackageVersion } from './utils/helpers.js';
import path from 'path';
import os from 'os';
const packageVersion = getPackageVersion();
// Parse command line arguments
const args = process.argv.slice(2);
const isDebug = args.includes('--debug') || process.env.DEBUG === 'true';
@@ -46,12 +49,22 @@ if (isFallbackEnabled) {
export const FALLBACK_ENABLED = isFallbackEnabled;
const PORT = process.env.PORT || DEFAULT_PORT;
const HOST = process.env.HOST || '0.0.0.0';
if (process.env.HOST) {
logger.info(`[Startup] Using HOST environment variable: ${process.env.HOST}`);
}
// Home directory for account storage
const HOME_DIR = os.homedir();
const CONFIG_DIR = path.join(HOME_DIR, '.antigravity-claude-proxy');
const server = app.listen(PORT, () => {
const server = app.listen(PORT, HOST, () => {
// Get actual bound address
const address = server.address();
const boundHost = typeof address === 'string' ? address : address.address;
const boundPort = typeof address === 'string' ? null : address.port;
// Clear console for a clean start
console.clear();
@@ -90,10 +103,11 @@ const server = app.listen(PORT, () => {
logger.log(`
╔══════════════════════════════════════════════════════════════╗
║ Antigravity Claude Proxy Server
Antigravity Claude Proxy Server v${packageVersion}
╠══════════════════════════════════════════════════════════════╣
║ ║
${border} ${align(`Server and WebUI running at: http://localhost:${PORT}`)}${border}
${border} ${align(`Server and WebUI running at: http://${HOST === '0.0.0.0' ? 'localhost' : HOST}:${PORT}`)}${border}
${border} ${align(`Bound to: ${boundHost}:${boundPort}`)}${border}
${statusSection}║ ║
${controlSection}
║ ║

View File

@@ -186,10 +186,10 @@ app.use((req, res, next) => {
res.on('finish', () => {
const duration = Date.now() - start;
const status = res.statusCode;
const logMsg = `[${req.method}] ${req.path} ${status} (${duration}ms)`;
const logMsg = `[${req.method}] ${req.originalUrl} ${status} (${duration}ms)`;
// Skip standard logging for event logging batch unless in debug mode
if (req.path === '/api/event_logging/batch' || req.path === '/v1/messages/count_tokens') {
if (req.originalUrl === '/api/event_logging/batch' || req.originalUrl === '/v1/messages/count_tokens' || req.originalUrl.startsWith('/.well-known/')) {
if (logger.isDebugEnabled) {
logger.debug(logMsg);
}

View File

@@ -1,9 +1,30 @@
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import path from 'path';
/**
* Shared Utility Functions
*
* General-purpose helper functions used across multiple modules.
*/
/**
* Get the package version from package.json
* @param {string} [defaultVersion='1.0.0'] - Default version if package.json cannot be read
* @returns {string} The package version
*/
export function getPackageVersion(defaultVersion = '1.0.0') {
try {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageJsonPath = path.join(__dirname, '../../package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
return packageJson.version || defaultVersion;
} catch {
return defaultVersion;
}
}
/**
* Format duration in milliseconds to human-readable string
* @param {number} ms - Duration in milliseconds

View File

@@ -13,8 +13,6 @@
*/
import path from 'path';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import express from 'express';
import { getPublicConfig, saveConfig, config } from '../config.js';
import { DEFAULT_PORT, ACCOUNT_CONFIG_PATH, MAX_ACCOUNTS, DEFAULT_PRESETS } from '../constants.js';
@@ -22,18 +20,10 @@ import { readClaudeConfig, updateClaudeConfig, replaceClaudeConfig, getClaudeCon
import { logger } from '../utils/logger.js';
import { getAuthorizationUrl, completeOAuthFlow, startCallbackServer } from '../auth/oauth.js';
import { loadAccounts, saveAccounts } from '../account-manager/storage.js';
import { getPackageVersion } from '../utils/helpers.js';
// Get package version
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let packageVersion = '1.0.0';
try {
const packageJsonPath = path.join(__dirname, '../../package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
packageVersion = packageJson.version;
} catch (error) {
logger.warn('[WebUI] Could not read package.json version, using default');
}
const packageVersion = getPackageVersion();
// OAuth state storage (state -> { server, verifier, state, timestamp })
// Maps state ID to active OAuth flow data