fix: improve startup readiness performance
This commit is contained in:
@@ -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() };
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -968,6 +968,24 @@ const handleLocalApiRequest = async (input: RequestInfo | URL, url: URL, init: R
|
||||
}
|
||||
}
|
||||
|
||||
if (pathname === '/api/opencode/version' && method === 'GET') {
|
||||
try {
|
||||
const data = await sendBridgeMessage('api:opencode/version');
|
||||
return new Response(JSON.stringify(data), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
return new Response(JSON.stringify({ version: null, error: message }), { status: 502, headers: { 'Content-Type': 'application/json' } });
|
||||
}
|
||||
}
|
||||
|
||||
if (pathname === '/api/opencode/health' && method === 'GET') {
|
||||
const connectionStatus = window.__OPENCHAMBER_CONNECTION__?.status;
|
||||
return new Response(JSON.stringify({ healthy: connectionStatus === 'connected' }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
if (pathname === '/api/zen/models' && method === 'GET') {
|
||||
try {
|
||||
const data = await sendBridgeMessage('api:zen:models');
|
||||
|
||||
Reference in New Issue
Block a user