fix: handle ambiguous prompt transport failures

This commit is contained in:
Bohdan Triapitsyn
2026-07-07 19:49:11 +03:00
parent c801c7a74b
commit 40dfff4a9a
12 changed files with 456 additions and 100 deletions
@@ -2,8 +2,21 @@ export const createOpenCodeNetworkRuntime = (deps) => {
const {
state,
getOpenCodeAuthHeaders,
configuredOpenCodeHostname = '127.0.0.1',
} = deps;
const resolveConnectHostname = () => {
const raw = typeof configuredOpenCodeHostname === 'string' ? configuredOpenCodeHostname.trim() : '';
const hostname = raw || '127.0.0.1';
if (hostname === '0.0.0.0' || hostname === '::' || hostname === '[::]') {
return '127.0.0.1';
}
if (hostname.startsWith('[') && hostname.endsWith(']')) {
return hostname;
}
return hostname.includes(':') ? `[${hostname}]` : hostname;
};
const normalizeApiPrefix = (prefix) => {
if (!prefix) {
return '';
@@ -77,7 +90,7 @@ export const createOpenCodeNetworkRuntime = (deps) => {
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
const prefix = normalizeApiPrefix(prefixOverride !== undefined ? prefixOverride : '');
const fullPath = `${prefix}${normalizedPath}`;
const base = state.openCodeBaseUrl ?? `http://localhost:${state.openCodePort}`;
const base = state.openCodeBaseUrl ?? `http://${resolveConnectHostname()}:${state.openCodePort}`;
return `${base}${fullPath}`;
};