fix: improve startup readiness performance

This commit is contained in:
Bohdan Triapitsyn
2026-06-05 15:09:24 +03:00
parent 0b881fec8e
commit e192359da9
32 changed files with 502 additions and 110 deletions
@@ -241,6 +241,32 @@ export async function handleSystemBridgeMessage(
}
}
case 'api:opencode/version': {
try {
const apiUrl = ctx?.manager?.getApiUrl();
if (!apiUrl) {
return { id, type, success: true, data: { version: null, error: 'OpenCode manager unavailable' } };
}
const base = `${apiUrl.replace(/\/+$/, '')}/`;
const response = await fetch(new URL('global/health', base).toString(), {
method: 'GET',
headers: { Accept: 'application/json', ...ctx?.manager?.getOpenCodeAuthHeaders() },
});
const health = await response.json().catch(() => null) as { version?: unknown; error?: unknown } | null;
if (!response.ok) {
const message = typeof health?.error === 'string' ? health.error : response.statusText || 'Failed to read OpenCode version';
return { id, type, success: true, data: { version: null, error: message } };
}
const version = typeof health?.version === 'string' && health.version.trim().length > 0
? health.version.trim().replace(/^v/, '')
: null;
return { id, type, success: true, data: { version } };
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
return { id, type, success: true, data: { version: null, error: errorMessage } };
}
}
case 'api:session-activity:get': {
return { id, type, success: true, data: getSessionActivitySnapshot() };
}
+1 -1
View File
@@ -547,7 +547,7 @@ export async function activate(context: vscode.ExtensionContext) {
};
const probeTargets: Array<{ label: string; path: string; includeDirectory?: boolean; timeoutMs?: number }> = [
{ label: 'health', path: '/global/health', includeDirectory: false },
{ label: 'health', path: '/api/health', includeDirectory: false },
{ label: 'config', path: '/config', includeDirectory: true },
{ label: 'providers', path: '/config/providers', includeDirectory: true },
// Can be slower on large configs; keep the probe from producing false negatives.
+1 -1
View File
@@ -568,7 +568,7 @@ async function waitForReady(
const timeout = setTimeout(() => controller.abort(), 3000);
// OpenCode readiness check.
const url = new URL(`${baseUrl}/global/health`);
const url = new URL(`${baseUrl}/api/health`);
const res = await fetch(url.toString(), {
method: 'GET',
headers: { Accept: 'application/json', ...authHeaders },