Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
import type { PreviewSessionSnapshot } from "@akeru/contracts";
interface PreviewAutomationSessionIndex {
readonly snapshot: PreviewSessionSnapshot | null;
readonly sessions: Readonly<Record<string, PreviewSessionSnapshot>>;
}
export function needsPreviewAutomationSessionSync(
state: PreviewAutomationSessionIndex,
requestedTabId: string | undefined,
): boolean {
return (
Object.keys(state.sessions).length === 0 ||
requestedTabId === undefined ||
state.sessions[requestedTabId] === undefined
);
}
export function resolvePreviewAutomationTarget(
state: PreviewAutomationSessionIndex,
requestedTabId: string | null,
) {
const snapshot = requestedTabId ? (state.sessions[requestedTabId] ?? null) : state.snapshot;
return { tabId: snapshot?.tabId ?? null, snapshot };
}
export function resolvePreviewAutomationOpenTab(
state: PreviewAutomationSessionIndex,
requestedTabId: string | undefined,
reuseExistingTab: boolean,
): string | null {
if (!reuseExistingTab) return null;
if (requestedTabId !== undefined) {
return state.sessions[requestedTabId]?.tabId ?? null;
}
return state.snapshot?.tabId ?? null;
}