Switch to double quotes and reformat codebase with Biome
This commit is contained in:
@@ -4,7 +4,7 @@ const DEFAULT_ACTIVITY_FLUSH_INTERVAL_MS = 16;
|
||||
|
||||
export function scheduleAgentLastActivityFlush(
|
||||
callback: () => void,
|
||||
fallbackIntervalMs = DEFAULT_ACTIVITY_FLUSH_INTERVAL_MS
|
||||
fallbackIntervalMs = DEFAULT_ACTIVITY_FLUSH_INTERVAL_MS,
|
||||
): ActivityFlushHandle {
|
||||
if (typeof requestAnimationFrame === "function") {
|
||||
const handle = requestAnimationFrame(callback);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
export type AgentLastActivityUpdates = Map<string, Date>;
|
||||
|
||||
export type AgentLastActivityCommitter = (
|
||||
updates: AgentLastActivityUpdates
|
||||
) => void;
|
||||
export type AgentLastActivityCommitter = (updates: AgentLastActivityUpdates) => void;
|
||||
|
||||
export interface ActivityFlushHandle {
|
||||
cancel: () => void;
|
||||
|
||||
@@ -44,9 +44,7 @@ class FakeDaemonClient {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
subscribeConnectionStatus(
|
||||
listener: (status: ConnectionState) => void
|
||||
): () => void {
|
||||
subscribeConnectionStatus(listener: (status: ConnectionState) => void): () => void {
|
||||
this.listeners.add(listener);
|
||||
listener(this.state);
|
||||
return () => {
|
||||
@@ -59,7 +57,7 @@ class FakeDaemonClient {
|
||||
}
|
||||
|
||||
async fetchAgents(
|
||||
options?: FetchAgentsOptions
|
||||
options?: FetchAgentsOptions,
|
||||
): Promise<Awaited<ReturnType<DaemonClient["fetchAgents"]>>> {
|
||||
this.fetchAgentsCalls.push(options ?? {});
|
||||
const queued = this.fetchAgentsResponses.shift();
|
||||
@@ -146,8 +144,7 @@ function makeFetchAgentsEntry(input: {
|
||||
thinkingOptionId: null,
|
||||
requiresAttention: input.requiresAttention ?? false,
|
||||
attentionReason: input.attentionReason ?? null,
|
||||
attentionTimestamp:
|
||||
input.requiresAttention && input.attentionReason ? input.updatedAt : null,
|
||||
attentionTimestamp: input.requiresAttention && input.attentionReason ? input.updatedAt : null,
|
||||
archivedAt: null,
|
||||
labels: {},
|
||||
},
|
||||
@@ -192,7 +189,7 @@ function makeHost(input?: Partial<HostProfile>): HostProfile {
|
||||
|
||||
function makeDeps(
|
||||
latencyByConnectionId: Record<string, number | Error>,
|
||||
createdClients: FakeDaemonClient[]
|
||||
createdClients: FakeDaemonClient[],
|
||||
): HostRuntimeControllerDeps {
|
||||
return {
|
||||
createClient: () => {
|
||||
@@ -364,9 +361,7 @@ describe("HostRuntimeController", () => {
|
||||
throw new Error("should adopt the probe client");
|
||||
},
|
||||
connectToDaemon: async ({ host, connection }) => {
|
||||
const client = makeConnectedProbeClient(
|
||||
connection.id === "direct:lan:6767" ? 12 : 30
|
||||
);
|
||||
const client = makeConnectedProbeClient(connection.id === "direct:lan:6767" ? 12 : 30);
|
||||
if (connection.id === "relay:relay.paseo.sh:443") {
|
||||
client.ping = async () => ({ rttMs: await slowPing.promise });
|
||||
}
|
||||
@@ -460,9 +455,7 @@ describe("HostRuntimeController", () => {
|
||||
for (let index = 0; index < 6 && !switched; index += 1) {
|
||||
clearProbeBackoff(controller);
|
||||
await controller.runProbeCycleNow();
|
||||
switched =
|
||||
controller.getSnapshot().activeConnectionId ===
|
||||
"relay:relay.paseo.sh:443";
|
||||
switched = controller.getSnapshot().activeConnectionId === "relay:relay.paseo.sh:443";
|
||||
}
|
||||
expect(switched).toBe(true);
|
||||
expect(controller.getSnapshot().client).not.toBeNull();
|
||||
@@ -509,9 +502,7 @@ describe("HostRuntimeController", () => {
|
||||
for (let index = 0; index < 6 && !switched; index += 1) {
|
||||
clearProbeBackoff(controller);
|
||||
await controller.runProbeCycleNow();
|
||||
switched =
|
||||
controller.getSnapshot().activeConnectionId ===
|
||||
"relay:relay.paseo.sh:443";
|
||||
switched = controller.getSnapshot().activeConnectionId === "relay:relay.paseo.sh:443";
|
||||
}
|
||||
expect(switched).toBe(true);
|
||||
});
|
||||
@@ -566,7 +557,7 @@ describe("HostRuntimeController", () => {
|
||||
{
|
||||
"direct:lan:6767": 12,
|
||||
},
|
||||
clients
|
||||
clients,
|
||||
),
|
||||
});
|
||||
|
||||
@@ -579,8 +570,7 @@ describe("HostRuntimeController", () => {
|
||||
const transitionPayloads = infoSpy.mock.calls
|
||||
.filter((call) => call[0] === "[HostRuntimeTransition]")
|
||||
.map((call) => call[1] as { reasonCode?: string | null });
|
||||
const lastTransition =
|
||||
transitionPayloads[transitionPayloads.length - 1] ?? null;
|
||||
const lastTransition = transitionPayloads[transitionPayloads.length - 1] ?? null;
|
||||
|
||||
expect(lastTransition?.reasonCode).toBe("transport_error");
|
||||
} finally {
|
||||
@@ -731,10 +721,7 @@ describe("HostRuntimeController", () => {
|
||||
deps,
|
||||
});
|
||||
|
||||
const waitUntil = async (
|
||||
predicate: () => boolean,
|
||||
timeoutMs = 200
|
||||
): Promise<void> => {
|
||||
const waitUntil = async (predicate: () => boolean, timeoutMs = 200): Promise<void> => {
|
||||
const timeoutAt = Date.now() + timeoutMs;
|
||||
while (!predicate()) {
|
||||
if (Date.now() >= timeoutAt) {
|
||||
@@ -830,9 +817,7 @@ describe("HostRuntimeController", () => {
|
||||
|
||||
fastProbe.resolve(12);
|
||||
await second;
|
||||
const probeAfterSecond = controller
|
||||
.getSnapshot()
|
||||
.probeByConnectionId.get("direct:lan:6767");
|
||||
const probeAfterSecond = controller.getSnapshot().probeByConnectionId.get("direct:lan:6767");
|
||||
expect(probeAfterSecond).toEqual({
|
||||
status: "available",
|
||||
latencyMs: 12,
|
||||
@@ -888,9 +873,7 @@ describe("HostRuntimeController", () => {
|
||||
clearProbeBackoff(controller);
|
||||
await controller.runProbeCycleNow();
|
||||
expect(controller.getSnapshot().client).toBe(activeClientBeforeProbes);
|
||||
expect(controller.getSnapshot().clientGeneration).toBe(
|
||||
generationBeforeProbes
|
||||
);
|
||||
expect(controller.getSnapshot().clientGeneration).toBe(generationBeforeProbes);
|
||||
expect(createdClients).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
@@ -920,10 +903,9 @@ describe("HostRuntimeStore", () => {
|
||||
},
|
||||
});
|
||||
|
||||
useSessionStore.getState().initializeSession(
|
||||
host.serverId,
|
||||
fakeClient as unknown as DaemonClient
|
||||
);
|
||||
useSessionStore
|
||||
.getState()
|
||||
.initializeSession(host.serverId, fakeClient as unknown as DaemonClient);
|
||||
store.syncHosts([host]);
|
||||
|
||||
const timeoutAt = Date.now() + 200;
|
||||
@@ -1029,7 +1011,7 @@ describe("HostRuntimeStore", () => {
|
||||
}),
|
||||
],
|
||||
hasMore: false,
|
||||
})
|
||||
}),
|
||||
);
|
||||
const store = new HostRuntimeStore({
|
||||
deps: {
|
||||
@@ -1043,17 +1025,13 @@ describe("HostRuntimeStore", () => {
|
||||
},
|
||||
});
|
||||
|
||||
useSessionStore.getState().initializeSession(
|
||||
host.serverId,
|
||||
fakeClient as unknown as DaemonClient
|
||||
);
|
||||
useSessionStore
|
||||
.getState()
|
||||
.initializeSession(host.serverId, fakeClient as unknown as DaemonClient);
|
||||
store.syncHosts([host]);
|
||||
|
||||
const timeoutAt = Date.now() + 300;
|
||||
while (
|
||||
fakeClient.fetchAgentsCalls.length < 2 &&
|
||||
Date.now() < timeoutAt
|
||||
) {
|
||||
while (fakeClient.fetchAgentsCalls.length < 2 && Date.now() < timeoutAt) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
}
|
||||
|
||||
@@ -1071,16 +1049,14 @@ describe("HostRuntimeStore", () => {
|
||||
});
|
||||
|
||||
let staleAgent =
|
||||
useSessionStore.getState().sessions[host.serverId]?.agents?.get(
|
||||
"agent-stale-attention"
|
||||
) ?? null;
|
||||
useSessionStore.getState().sessions[host.serverId]?.agents?.get("agent-stale-attention") ??
|
||||
null;
|
||||
const staleTimeoutAt = Date.now() + 300;
|
||||
while (!staleAgent && Date.now() < staleTimeoutAt) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
staleAgent =
|
||||
useSessionStore.getState().sessions[host.serverId]?.agents?.get(
|
||||
"agent-stale-attention"
|
||||
) ?? null;
|
||||
useSessionStore.getState().sessions[host.serverId]?.agents?.get("agent-stale-attention") ??
|
||||
null;
|
||||
}
|
||||
expect(staleAgent?.requiresAttention).toBe(true);
|
||||
expect(staleAgent?.attentionReason).toBe("error");
|
||||
@@ -1118,10 +1094,9 @@ describe("HostRuntimeStore", () => {
|
||||
},
|
||||
});
|
||||
|
||||
useSessionStore.getState().initializeSession(
|
||||
host.serverId,
|
||||
fakeClient as unknown as DaemonClient
|
||||
);
|
||||
useSessionStore
|
||||
.getState()
|
||||
.initializeSession(host.serverId, fakeClient as unknown as DaemonClient);
|
||||
store.syncHosts([host]);
|
||||
|
||||
const initialTimeoutAt = Date.now() + 200;
|
||||
|
||||
@@ -15,15 +15,9 @@ import {
|
||||
} from "@/types/host-connection";
|
||||
import { decodeOfferFragmentPayload, normalizeHostPort } from "@/utils/daemon-endpoints";
|
||||
import { ConnectionOfferSchema, type ConnectionOffer } from "@server/shared/connection-offer";
|
||||
import {
|
||||
shouldUseDesktopDaemon,
|
||||
startDesktopDaemon,
|
||||
} from "@/desktop/daemon/desktop-daemon";
|
||||
import { shouldUseDesktopDaemon, startDesktopDaemon } from "@/desktop/daemon/desktop-daemon";
|
||||
import { connectToDaemon } from "@/utils/test-daemon-connection";
|
||||
import {
|
||||
buildDaemonWebSocketUrl,
|
||||
buildRelayWebSocketUrl,
|
||||
} from "@/utils/daemon-endpoints";
|
||||
import { buildDaemonWebSocketUrl, buildRelayWebSocketUrl } from "@/utils/daemon-endpoints";
|
||||
import { getOrCreateClientId } from "@/utils/client-id";
|
||||
import {
|
||||
selectBestConnection,
|
||||
@@ -37,12 +31,7 @@ import {
|
||||
import { applyFetchedAgentDirectory } from "@/utils/agent-directory-sync";
|
||||
import { useSessionStore, type Agent } from "@/stores/session-store";
|
||||
|
||||
export type HostRuntimeConnectionStatus =
|
||||
| "idle"
|
||||
| "connecting"
|
||||
| "online"
|
||||
| "offline"
|
||||
| "error";
|
||||
export type HostRuntimeConnectionStatus = "idle" | "connecting" | "online" | "offline" | "error";
|
||||
|
||||
export type ActiveConnection =
|
||||
| { type: "directTcp"; endpoint: string; display: string }
|
||||
@@ -73,15 +62,11 @@ export type HostRuntimeSnapshot = {
|
||||
clientGeneration: number;
|
||||
};
|
||||
|
||||
export function isHostRuntimeConnected(
|
||||
snapshot: HostRuntimeSnapshot | null
|
||||
): boolean {
|
||||
export function isHostRuntimeConnected(snapshot: HostRuntimeSnapshot | null): boolean {
|
||||
return snapshot?.connectionStatus === "online";
|
||||
}
|
||||
|
||||
export function isHostRuntimeDirectoryLoading(
|
||||
snapshot: HostRuntimeSnapshot | null
|
||||
): boolean {
|
||||
export function isHostRuntimeDirectoryLoading(snapshot: HostRuntimeSnapshot | null): boolean {
|
||||
if (!snapshot) {
|
||||
return true;
|
||||
}
|
||||
@@ -93,8 +78,7 @@ export function isHostRuntimeDirectoryLoading(
|
||||
}
|
||||
return (
|
||||
!snapshot.hasEverLoadedAgentDirectory &&
|
||||
(snapshot.connectionStatus === "connecting" ||
|
||||
snapshot.connectionStatus === "online")
|
||||
(snapshot.connectionStatus === "connecting" || snapshot.connectionStatus === "online")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -117,10 +101,7 @@ export type HostRuntimeControllerDeps = {
|
||||
clientId: string;
|
||||
runtimeGeneration: number;
|
||||
}) => DaemonClient;
|
||||
connectToDaemon: (input: {
|
||||
host: HostProfile;
|
||||
connection: HostConnection;
|
||||
}) => Promise<{
|
||||
connectToDaemon: (input: { host: HostProfile; connection: HostConnection }) => Promise<{
|
||||
client: DaemonClient;
|
||||
serverId: string;
|
||||
hostname: string | null;
|
||||
@@ -148,7 +129,7 @@ const DEFAULT_AGENT_DIRECTORY_SORT: NonNullable<FetchAgentsOptions["sort"]> = [
|
||||
];
|
||||
|
||||
function readFetchAgentsHasMore(
|
||||
pageInfo: Awaited<ReturnType<DaemonClient["fetchAgents"]>>["pageInfo"]
|
||||
pageInfo: Awaited<ReturnType<DaemonClient["fetchAgents"]>>["pageInfo"],
|
||||
): boolean {
|
||||
const page = pageInfo as {
|
||||
hasMore?: boolean;
|
||||
@@ -164,7 +145,7 @@ function readFetchAgentsHasMore(
|
||||
}
|
||||
|
||||
function readFetchAgentsNextCursor(
|
||||
pageInfo: Awaited<ReturnType<DaemonClient["fetchAgents"]>>["pageInfo"]
|
||||
pageInfo: Awaited<ReturnType<DaemonClient["fetchAgents"]>>["pageInfo"],
|
||||
): string | null {
|
||||
const page = pageInfo as {
|
||||
nextCursor?: string | null;
|
||||
@@ -347,7 +328,7 @@ function nextConnectionMachineState(input: {
|
||||
}
|
||||
|
||||
function toSnapshotConnectionPatch(
|
||||
state: HostRuntimeConnectionMachineState
|
||||
state: HostRuntimeConnectionMachineState,
|
||||
): Pick<
|
||||
HostRuntimeSnapshot,
|
||||
"activeConnectionId" | "activeConnection" | "connectionStatus" | "lastError" | "lastOnlineAt"
|
||||
@@ -404,10 +385,7 @@ function buildConnectionCandidates(host: HostProfile): ConnectionCandidate[] {
|
||||
}));
|
||||
}
|
||||
|
||||
function findConnectionById(
|
||||
host: HostProfile,
|
||||
connectionId: string | null
|
||||
): HostConnection | null {
|
||||
function findConnectionById(host: HostProfile, connectionId: string | null): HostConnection | null {
|
||||
if (!connectionId) {
|
||||
return null;
|
||||
}
|
||||
@@ -417,7 +395,7 @@ function findConnectionById(
|
||||
function probeIntervalForConnection(
|
||||
firstSeenAt: number,
|
||||
isActiveOnline: boolean,
|
||||
now: number
|
||||
now: number,
|
||||
): number {
|
||||
if (isActiveOnline) {
|
||||
return PROBE_STEADY_MS;
|
||||
@@ -583,9 +561,7 @@ export class HostRuntimeController {
|
||||
}
|
||||
|
||||
markAgentDirectorySyncLoading(): void {
|
||||
const status = this.snapshot.hasEverLoadedAgentDirectory
|
||||
? "revalidating"
|
||||
: "initial_loading";
|
||||
const status = this.snapshot.hasEverLoadedAgentDirectory ? "revalidating" : "initial_loading";
|
||||
this.updateSnapshot({
|
||||
agentDirectoryStatus: status,
|
||||
agentDirectoryError: null,
|
||||
@@ -687,7 +663,7 @@ export class HostRuntimeController {
|
||||
|
||||
const maybeActivateFirstAvailable = async (
|
||||
connectionId: string,
|
||||
client: DaemonClient
|
||||
client: DaemonClient,
|
||||
): Promise<boolean> => {
|
||||
while (!this.snapshot.activeConnectionId) {
|
||||
if (!activationLock) {
|
||||
@@ -716,10 +692,7 @@ export class HostRuntimeController {
|
||||
? probeByConnectionId.get(currentActiveConnectionId)
|
||||
: null;
|
||||
|
||||
if (
|
||||
!currentActiveConnectionId ||
|
||||
!findConnectionById(this.host, currentActiveConnectionId)
|
||||
) {
|
||||
if (!currentActiveConnectionId || !findConnectionById(this.host, currentActiveConnectionId)) {
|
||||
const nextConnectionId = selectBestConnection({
|
||||
candidates: buildConnectionCandidates(this.host),
|
||||
probeByConnectionId,
|
||||
@@ -755,10 +728,8 @@ export class HostRuntimeController {
|
||||
|
||||
const available = Array.from(probeByConnectionId.entries())
|
||||
.filter(
|
||||
(
|
||||
entry
|
||||
): entry is [string, Extract<ConnectionProbeState, { status: "available" }>] =>
|
||||
entry[1].status === "available"
|
||||
(entry): entry is [string, Extract<ConnectionProbeState, { status: "available" }>] =>
|
||||
entry[1].status === "available",
|
||||
)
|
||||
.map(([connectionId, probe]) => ({
|
||||
connectionId,
|
||||
@@ -787,9 +758,7 @@ export class HostRuntimeController {
|
||||
this.switchCandidateHitCount = 1;
|
||||
}
|
||||
|
||||
if (
|
||||
this.switchCandidateHitCount >= ADAPTIVE_SWITCH_CONSECUTIVE_PROBES
|
||||
) {
|
||||
if (this.switchCandidateHitCount >= ADAPTIVE_SWITCH_CONSECUTIVE_PROBES) {
|
||||
this.switchCandidateConnectionId = null;
|
||||
this.switchCandidateHitCount = 0;
|
||||
await this.switchToConnection({
|
||||
@@ -857,7 +826,7 @@ export class HostRuntimeController {
|
||||
}
|
||||
|
||||
private updateSnapshot(
|
||||
patch: Partial<Omit<HostRuntimeSnapshot, "serverId" | "clientGeneration">>
|
||||
patch: Partial<Omit<HostRuntimeSnapshot, "serverId" | "clientGeneration">>,
|
||||
): void {
|
||||
const next: HostRuntimeSnapshot = {
|
||||
...this.snapshot,
|
||||
@@ -916,9 +885,7 @@ export class HostRuntimeController {
|
||||
return version === this.probeRequestVersion;
|
||||
}
|
||||
|
||||
private canProceedForProbe(
|
||||
expectedProbeVersion: number | undefined
|
||||
): boolean {
|
||||
private canProceedForProbe(expectedProbeVersion: number | undefined): boolean {
|
||||
if (expectedProbeVersion === undefined) {
|
||||
return true;
|
||||
}
|
||||
@@ -1006,12 +973,14 @@ export class HostRuntimeController {
|
||||
if (existingClient) {
|
||||
existingClient.setReconnectEnabled(true);
|
||||
}
|
||||
const client = existingClient ?? this.deps.createClient({
|
||||
host: this.host,
|
||||
connection,
|
||||
clientId,
|
||||
runtimeGeneration: nextGeneration,
|
||||
});
|
||||
const client =
|
||||
existingClient ??
|
||||
this.deps.createClient({
|
||||
host: this.host,
|
||||
connection,
|
||||
clientId,
|
||||
runtimeGeneration: nextGeneration,
|
||||
});
|
||||
if (!this.isCurrentSwitchRequest(requestVersion)) {
|
||||
await client.close().catch(() => undefined);
|
||||
return;
|
||||
@@ -1038,10 +1007,7 @@ export class HostRuntimeController {
|
||||
}
|
||||
|
||||
this.unsubscribeClientStatus = client.subscribeConnectionStatus((state) => {
|
||||
if (
|
||||
!this.isCurrentSwitchRequest(requestVersion) ||
|
||||
this.activeClient !== client
|
||||
) {
|
||||
if (!this.isCurrentSwitchRequest(requestVersion) || this.activeClient !== client) {
|
||||
return;
|
||||
}
|
||||
this.applyConnectionEvent({
|
||||
@@ -1077,10 +1043,7 @@ export class HostRuntimeController {
|
||||
await client.connect();
|
||||
}
|
||||
} catch (error) {
|
||||
if (
|
||||
!this.isCurrentSwitchRequest(requestVersion) ||
|
||||
this.activeClient !== client
|
||||
) {
|
||||
if (!this.isCurrentSwitchRequest(requestVersion) || this.activeClient !== client) {
|
||||
return;
|
||||
}
|
||||
const message = toErrorMessage(error);
|
||||
@@ -1235,7 +1198,7 @@ export class HostRuntimeStore {
|
||||
type: "directTcp",
|
||||
endpoint: DEFAULT_LOCALHOST_ENDPOINT,
|
||||
},
|
||||
{ timeoutMs: DEFAULT_LOCALHOST_BOOTSTRAP_TIMEOUT_MS }
|
||||
{ timeoutMs: DEFAULT_LOCALHOST_BOOTSTRAP_TIMEOUT_MS },
|
||||
);
|
||||
|
||||
await this.upsertDirectConnection({
|
||||
@@ -1320,9 +1283,7 @@ export class HostRuntimeStore {
|
||||
|
||||
async renameHost(serverId: string, label: string): Promise<void> {
|
||||
const next = this.hosts.map((h) =>
|
||||
h.serverId === serverId
|
||||
? { ...h, label, updatedAt: new Date().toISOString() }
|
||||
: h
|
||||
h.serverId === serverId ? { ...h, label, updatedAt: new Date().toISOString() } : h,
|
||||
);
|
||||
this.setHostsAndSync(next);
|
||||
await this.persistHosts();
|
||||
@@ -1397,7 +1358,7 @@ export class HostRuntimeStore {
|
||||
string,
|
||||
{ connectionId: string; existingClient: DaemonClient }
|
||||
>;
|
||||
}
|
||||
},
|
||||
): void {
|
||||
this.hosts = hosts;
|
||||
this.syncHosts(hosts, options);
|
||||
@@ -1426,7 +1387,7 @@ export class HostRuntimeStore {
|
||||
string,
|
||||
{ connectionId: string; existingClient: DaemonClient }
|
||||
>;
|
||||
}
|
||||
},
|
||||
): void {
|
||||
const nextIds = new Set(hosts.map((host) => host.serverId));
|
||||
for (const [serverId, controller] of this.controllers) {
|
||||
@@ -1459,22 +1420,24 @@ export class HostRuntimeStore {
|
||||
this.controllers.set(host.serverId, controller);
|
||||
this.lastConnectionStatusByServer.set(
|
||||
host.serverId,
|
||||
controller.getSnapshot().connectionStatus
|
||||
controller.getSnapshot().connectionStatus,
|
||||
);
|
||||
controller.subscribe(() => {
|
||||
this.maybeAutoBootstrapAgentDirectory(host.serverId);
|
||||
this.emit(host.serverId);
|
||||
});
|
||||
void controller.start({
|
||||
...(initialConnection
|
||||
? {
|
||||
initialConnection,
|
||||
}
|
||||
: {}),
|
||||
}).catch((error) => {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
controller.markStartupError(message);
|
||||
});
|
||||
void controller
|
||||
.start({
|
||||
...(initialConnection
|
||||
? {
|
||||
initialConnection,
|
||||
}
|
||||
: {}),
|
||||
})
|
||||
.catch((error) => {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
controller.markStartupError(message);
|
||||
});
|
||||
this.emit(host.serverId);
|
||||
}
|
||||
}
|
||||
@@ -1513,7 +1476,7 @@ export class HostRuntimeStore {
|
||||
serverId,
|
||||
subscribe: { subscriptionId: `app:${serverId}` },
|
||||
page: { limit: DEFAULT_AGENT_DIRECTORY_PAGE_LIMIT },
|
||||
})
|
||||
}),
|
||||
)
|
||||
.then(() => undefined)
|
||||
.catch((error) => {
|
||||
@@ -1578,9 +1541,7 @@ export class HostRuntimeStore {
|
||||
return this.controllers.get(serverId)?.runProbeCycleNow() ?? Promise.resolve();
|
||||
}
|
||||
return Promise.all(
|
||||
Array.from(this.controllers.values(), (controller) =>
|
||||
controller.runProbeCycleNow()
|
||||
)
|
||||
Array.from(this.controllers.values(), (controller) => controller.runProbeCycleNow()),
|
||||
).then(() => undefined);
|
||||
}
|
||||
|
||||
@@ -1653,9 +1614,7 @@ export class HostRuntimeStore {
|
||||
}
|
||||
|
||||
refreshAllAgentDirectories(input?: { serverIds?: string[] }): void {
|
||||
const targetServerIds = input?.serverIds
|
||||
? new Set(input.serverIds)
|
||||
: null;
|
||||
const targetServerIds = input?.serverIds ? new Set(input.serverIds) : null;
|
||||
for (const [serverId] of this.controllers) {
|
||||
if (targetServerIds && !targetServerIds.has(serverId)) {
|
||||
continue;
|
||||
@@ -1723,14 +1682,12 @@ export function getHostRuntimeStore(): HostRuntimeStore {
|
||||
return singletonHostRuntimeStore;
|
||||
}
|
||||
|
||||
export function useHostRuntimeSnapshot(
|
||||
serverId: string
|
||||
): HostRuntimeSnapshot | null {
|
||||
export function useHostRuntimeSnapshot(serverId: string): HostRuntimeSnapshot | null {
|
||||
const store = getHostRuntimeStore();
|
||||
return useSyncExternalStore(
|
||||
(onStoreChange) => store.subscribe(serverId, onStoreChange),
|
||||
() => store.getSnapshot(serverId),
|
||||
() => store.getSnapshot(serverId)
|
||||
() => store.getSnapshot(serverId),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1739,7 +1696,7 @@ export function useHostRuntimeClient(serverId: string): DaemonClient | null {
|
||||
return useSyncExternalStore(
|
||||
(onStoreChange) => store.subscribe(serverId, onStoreChange),
|
||||
() => store.getSnapshot(serverId)?.client ?? null,
|
||||
() => store.getSnapshot(serverId)?.client ?? null
|
||||
() => store.getSnapshot(serverId)?.client ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1748,18 +1705,16 @@ export function useHostRuntimeIsConnected(serverId: string): boolean {
|
||||
return useSyncExternalStore(
|
||||
(onStoreChange) => store.subscribe(serverId, onStoreChange),
|
||||
() => isHostRuntimeConnected(store.getSnapshot(serverId)),
|
||||
() => isHostRuntimeConnected(store.getSnapshot(serverId))
|
||||
() => isHostRuntimeConnected(store.getSnapshot(serverId)),
|
||||
);
|
||||
}
|
||||
|
||||
export function useHostRuntimeConnectionStatus(
|
||||
serverId: string
|
||||
): HostRuntimeConnectionStatus {
|
||||
export function useHostRuntimeConnectionStatus(serverId: string): HostRuntimeConnectionStatus {
|
||||
const store = getHostRuntimeStore();
|
||||
return useSyncExternalStore(
|
||||
(onStoreChange) => store.subscribe(serverId, onStoreChange),
|
||||
() => store.getSnapshot(serverId)?.connectionStatus ?? "connecting",
|
||||
() => store.getSnapshot(serverId)?.connectionStatus ?? "connecting"
|
||||
() => store.getSnapshot(serverId)?.connectionStatus ?? "connecting",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1768,18 +1723,18 @@ export function useHostRuntimeLastError(serverId: string): string | null {
|
||||
return useSyncExternalStore(
|
||||
(onStoreChange) => store.subscribe(serverId, onStoreChange),
|
||||
() => store.getSnapshot(serverId)?.lastError ?? null,
|
||||
() => store.getSnapshot(serverId)?.lastError ?? null
|
||||
() => store.getSnapshot(serverId)?.lastError ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
export function useHostRuntimeAgentDirectoryStatus(
|
||||
serverId: string
|
||||
serverId: string,
|
||||
): HostRuntimeAgentDirectoryStatus {
|
||||
const store = getHostRuntimeStore();
|
||||
return useSyncExternalStore(
|
||||
(onStoreChange) => store.subscribe(serverId, onStoreChange),
|
||||
() => store.getSnapshot(serverId)?.agentDirectoryStatus ?? "idle",
|
||||
() => store.getSnapshot(serverId)?.agentDirectoryStatus ?? "idle"
|
||||
() => store.getSnapshot(serverId)?.agentDirectoryStatus ?? "idle",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1788,7 +1743,7 @@ export function useHostRuntimeIsDirectoryLoading(serverId: string): boolean {
|
||||
return useSyncExternalStore(
|
||||
(onStoreChange) => store.subscribe(serverId, onStoreChange),
|
||||
() => isHostRuntimeDirectoryLoading(store.getSnapshot(serverId)),
|
||||
() => isHostRuntimeDirectoryLoading(store.getSnapshot(serverId))
|
||||
() => isHostRuntimeDirectoryLoading(store.getSnapshot(serverId)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1797,7 +1752,7 @@ export function useHosts(): HostProfile[] {
|
||||
return useSyncExternalStore(
|
||||
(onStoreChange) => store.subscribeHostList(onStoreChange),
|
||||
() => store.getHosts(),
|
||||
() => store.getHosts()
|
||||
() => store.getHosts(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1832,6 +1787,6 @@ export function useHostMutations(): HostMutations {
|
||||
removeHost: (serverId) => store.removeHost(serverId),
|
||||
removeConnection: (serverId, connectionId) => store.removeConnection(serverId, connectionId),
|
||||
}),
|
||||
[store]
|
||||
[store],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user