Files
paseo/packages/app/src/runtime/host-features.ts
T
Mohamed Boudra 373a98c64d Restore host directories instantly before reconnect (#3259)
* feat(sync): restore host directories before reconnect

Persist complete project, workspace, and active-agent replicas so every registered host can paint immediately, including offline hosts. Reconcile those replicas through monotonic per-entity cursors on the existing directory RPCs without retaining an event journal.

* fix(sync): preserve active turn identity during catch-up

Own Agent-to-wire projection beside the existing snapshot normalizer so replica persistence does not reach through directory-sync internals. This also keeps identified active turns intact when unchanged agents are folded into an incremental directory response.

* test(e2e): inspect the real IndexedDB replica

Keep cache setup, reload, and hydration coverage on the production browser storage backend after the replica moved off localStorage. Measure writes at the actual IndexedDB put boundary as well.

* fix warm reconnect cache paths

* feat(sync): persist project icons and deepen directory sync

* fix(sync): preserve project update order

* fix(cache): preserve validated replica persistence

* fix(sync): retain cached agents during catch-up
2026-08-13 23:10:44 +02:00

73 lines
2.0 KiB
TypeScript

import { useMemo } from "react";
import { useShallow } from "zustand/shallow";
import type { DaemonServerInfo } from "@/stores/session-store";
import { useSessionStore } from "@/stores/session-store";
export type HostFeatureName = keyof NonNullable<DaemonServerInfo["features"]>;
export interface HostFeatureSessionState {
sessions: Record<
string,
| {
serverInfo: DaemonServerInfo | null;
}
| undefined
>;
}
export function hostSupportsFeature(
serverInfo: DaemonServerInfo | null | undefined,
feature: HostFeatureName,
): boolean {
return serverInfo?.features?.[feature] === true;
}
export function selectHostFeature(
state: HostFeatureSessionState,
serverId: string,
feature: HostFeatureName,
): boolean {
return hostSupportsFeature(state.sessions[serverId]?.serverInfo, feature);
}
export function useHostFeature(
serverId: string | null | undefined,
feature: HostFeatureName,
): boolean {
const normalizedServerId = serverId?.trim() ?? "";
return useSessionStore((state) => selectHostFeature(state, normalizedServerId, feature));
}
export function useHostFeatureMap(
serverIds: readonly string[],
feature: HostFeatureName,
): ReadonlyMap<string, boolean> {
const flags = useSessionStore(
useShallow((state) => serverIds.map((serverId) => selectHostFeature(state, serverId, feature))),
);
return useMemo(
() => new Map(serverIds.map((serverId, index) => [serverId, flags[index] === true] as const)),
[flags, serverIds],
);
}
export function useHostFeatureAvailabilityMap(
serverIds: readonly string[],
feature: HostFeatureName,
): ReadonlyMap<string, boolean | null> {
const flags = useSessionStore(
useShallow((state) =>
serverIds.map((serverId) => {
const serverInfo = state.sessions[serverId]?.serverInfo;
return serverInfo ? hostSupportsFeature(serverInfo, feature) : null;
}),
),
);
return useMemo(
() => new Map(serverIds.map((serverId, index) => [serverId, flags[index]] as const)),
[flags, serverIds],
);
}