Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

3.0 KB
Raw Blame
// The app_settings tool's wire shapes: a setting's tier (the whole policy), the applied card a change rides on, and the
// preferences that live in the window's localStorage, which the server reaches through an SSE frame.
import { z } from "zod";
import {
  CHAT_WIDTH_IDS,
  COMPOSER_BUTTONS,
  FONT_IDS,
  PLACE_SWATCHES,
  SEND_KEYS,
  SKIN_IDS,
  TALK_KEYS,
  USAGE_INDICATORS,
} from "./app-settings-ids.ts";

export {
  CHAT_WIDTH_IDS,
  COMPOSER_BUTTONS,
  FONT_IDS,
  isSettingsCardId,
  PLACE_SWATCHES,
  SEND_KEYS,
  SETTINGS_CARD_IDS,
  SKIN_IDS,
  TALK_KEYS,
  USAGE_INDICATORS,
  type AppSettingCardField,
  type AppSettingRequest,
  type SettingsCardData,
  type SettingsCardId,
  type SettingTier,
} from "./app-settings-ids.ts";

const pinnedPage = z.object({ name: z.string().trim().min(1).max(40), url: z.string().trim().max(2048).regex(/^https?:\/\/\S+$/, "an http(s) address") }).strict();

/** Preferences kept in the window or behind the desktop app's own bridge, by setting id; the renderer applies a frame with
 * the matching setter. */
export const WINDOW_PREFS = {
  "appearance.skin": z.enum([...SKIN_IDS, "system"]),
  "appearance.advanced": z.boolean(),
  "appearance.font": z.enum(FONT_IDS),
  "appearance.chatWidth": z.enum(CHAT_WIDTH_IDS),
  "general.sendKey": z.enum(SEND_KEYS),
  "general.notificationSounds": z.boolean(),
  "appearance.userBubbles": z.boolean(),
  "appearance.showThreads": z.boolean(),
  "appearance.toolsLayout": z.enum(["rows", "toolbar"]),
  "appearance.pinnedCircles": z.boolean(),
  "appearance.universalPins": z.boolean(),
  "appearance.pinnedPages": z.array(pinnedPage).max(6),
  "appearance.usageIndicator": z.enum(USAGE_INDICATORS),
  "appearance.composerOrder": z.array(z.enum(COMPOSER_BUTTONS)).max(COMPOSER_BUTTONS.length).refine((order) => new Set(order).size === order.length, "each button once"),
  "appearance.showComputers": z.boolean(),
  "appearance.windowFrame": z.boolean(),
  "appearance.sidebarColor": z.enum([...PLACE_SWATCHES, "none"]),
  "general.followUp": z.enum(["steer", "queue"]),
  "general.finishedNotifications": z.boolean(),
  "general.notificationFeed": z.boolean(),
  "general.analytics": z.boolean(),
  "general.openAtLogin": z.boolean(),
  "general.talkShortcut": z.object({ enabled: z.boolean(), key: z.enum(TALK_KEYS) }).strict(),
  "account.productEmails": z.boolean(),
  "remote.wifi": z.boolean(),
  "remote.relay": z.boolean(),
  "remote.tailscale": z.boolean(),
  "remote.keepAwake": z.boolean(),
} as const;
export type WindowPrefId = keyof typeof WINDOW_PREFS;
export type WindowPrefValue<I extends WindowPrefId> = z.infer<(typeof WINDOW_PREFS)[I]>;
export const WINDOW_PREF_IDS = Object.keys(WINDOW_PREFS) as WindowPrefId[];
export const isWindowPrefId = (id: string): id is WindowPrefId => Object.hasOwn(WINDOW_PREFS, id);

export interface WindowPrefFrame {
  kind: "window-pref";
  id: WindowPrefId;
  value: unknown;
}

/** What the window reports as its current values (PUT /api/window-prefs). */
export const windowPrefReportSchema = z.object({ values: z.record(z.string(), z.unknown()) }).strict();