Skip to content

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.

1.1 KB
Raw Blame
import { ClientSettingsSchema, type ClientSettings } from "@akeru/contracts";

import { getFirstLocalStorageItem, setLocalStorageItem } from "./hooks/useLocalStorage";

export const CLIENT_SETTINGS_STORAGE_KEY = "akeru:client-settings:v1";

// Pre-rebrand key, kept so existing installs keep their client settings.
export const LEGACY_CLIENT_SETTINGS_STORAGE_KEY = "t3code:client-settings:v1";

function hasWindow(): boolean {
  return typeof window !== "undefined";
}

export function readBrowserClientSettings(): ClientSettings | null {
  if (!hasWindow()) {
    return null;
  }

  return getFirstLocalStorageItem(
    [CLIENT_SETTINGS_STORAGE_KEY, LEGACY_CLIENT_SETTINGS_STORAGE_KEY],
    ClientSettingsSchema,
    (error) => console.error("Could not read persisted client settings.", error),
  );
}

export function writeBrowserClientSettings(settings: ClientSettings): void {
  if (!hasWindow()) {
    return;
  }

  setLocalStorageItem(CLIENT_SETTINGS_STORAGE_KEY, settings, ClientSettingsSchema);

  try {
    window.localStorage.removeItem(LEGACY_CLIENT_SETTINGS_STORAGE_KEY);
  } catch {
    // Draining the legacy key is best-effort.
  }
}