Update files

This commit is contained in:
Mohamed Boudra
2026-02-05 12:02:25 +07:00
parent 574bdc16f6
commit ae27a14e3b
17 changed files with 580 additions and 815 deletions
@@ -41,7 +41,7 @@ export class DaemonConnectionTestError extends Error {
export async function probeDaemonEndpoint(
endpoint: string,
options?: { timeoutMs?: number }
): Promise<{ serverId: string }> {
): Promise<{ serverId: string; hostname: string | null }> {
const timeoutMs = options?.timeoutMs ?? 6000;
const url = buildDaemonWebSocketUrl(endpoint);
@@ -51,12 +51,12 @@ export async function probeDaemonEndpoint(
});
try {
return await new Promise<{ serverId: string }>((resolve, reject) => {
return await new Promise<{ serverId: string; hostname: string | null }>((resolve, reject) => {
let cleanedUp = false;
let unsubscribe: (() => void) | null = null;
let unsubscribeStatus: (() => void) | null = null;
let isConnected = false;
let serverId: string | null = null;
let hostname: string | null = null;
const cleanup = () => {
if (cleanedUp) return;
@@ -67,13 +67,13 @@ export async function probeDaemonEndpoint(
};
const maybeFinishOk = () => {
if (!isConnected) return;
if (!serverId) return;
cleanup();
resolve({ serverId });
resolve({ serverId, hostname });
};
const finishErr = (error: Error) => {
if (cleanedUp) return;
cleanup();
reject(error);
};
@@ -88,11 +88,6 @@ export async function probeDaemonEndpoint(
}, timeoutMs);
unsubscribe = client.subscribeConnectionStatus((state) => {
if (state.status === "connected") {
isConnected = true;
maybeFinishOk();
return;
}
if (state.status === "disconnected") {
const reason = normalizeNonEmptyString(state.reason);
const lastError = normalizeNonEmptyString(client.lastError);
@@ -103,11 +98,15 @@ export async function probeDaemonEndpoint(
unsubscribeStatus = client.on("status", (message) => {
if (message.type !== "status") return;
const payload = message.payload as { status?: unknown; serverId?: unknown };
const payload = message.payload as { status?: unknown; serverId?: unknown; hostname?: unknown };
if (payload?.status !== "server_info") return;
const raw = typeof payload.serverId === "string" ? payload.serverId.trim() : "";
if (!raw) return;
serverId = raw;
hostname = typeof payload.hostname === "string" ? payload.hostname.trim() : null;
if (hostname && hostname.length === 0) {
hostname = null;
}
maybeFinishOk();
});