import { useLayoutEffect, useState } from "react"; import { LinearMemberAccessView } from "../../nanobot/channels/linear/webui/LinearMemberAccessView"; import type { LinearMembersPayload } from "../../nanobot/channels/linear/webui/types"; import { ChatList } from "@/components/ChatList"; import { SettingsPage } from "@/components/settings/SettingsPage"; import type { SettingsSectionKey } from "@/components/settings/contracts"; import { SkillsCatalogSettings } from "@/components/settings/SkillsCatalogSettings"; import { AutomationsSettings } from "@/components/settings/system/AutomationsSettings"; import { RUNTIME_CONFIG_FIELDS } from "@/components/settings/system/runtime-config-fields"; import { useSettingsController } from "@/components/settings/useSettingsController"; import { SessionInfoPopoverView } from "@/components/thread/SessionInfoPopoverView"; import { settings } from "@/dev/gallery/settings"; import { setAppLanguage } from "@/i18n"; import type { ChatSummary, SessionAutomationJob, SettingsPayload, SkillDetail } from "@/lib/types"; const noop = () => {}; const now = Date.now(); const names = ["Project summary", "Review changes", "Release checklist", "Documentation"]; const jobs: SessionAutomationJob[] = names.slice(0, 3).map((name, index) => ({ id: `preview-${index}`, name, enabled: true, schedule: { kind: "every", every_ms: 3_600_000 }, payload: { message: "Summarize the project." }, state: { next_run_at_ms: now + index * 86_400_000 + 3_600_000 }, })); const sessions: ChatSummary[] = names.map((title, index) => ({ key: `websocket:preview-${index}`, chatId: `preview-${index}`, channel: "websocket", title, preview: "", handle: { id: `preview-${index}`, name: `topic${index}` }, createdAt: new Date(now).toISOString(), updatedAt: new Date(now).toISOString(), })); const skill: SkillDetail = { name: "project-review", description: "Review the repository and summarize actionable changes.", source: "builtin", available: true, enabled: true, requirements: { bins: [], env: [], missing_bins: [], missing_env: [] }, raw_markdown: "# Project review\n\nRead the repository instructions before reviewing changes.", }; const members: LinearMembersPayload = { session_id: "", status: "members", organization_id: "preview", legacy_allow_all: false, members: names.slice(0, 3).map((_, index) => ({ id: `member-${index}`, name: ["Alex Chen", "Morgan Lee", "Sam Rivera"][index], teams: [], allowed: index === 0 })), }; const previewSettings: SettingsPayload = { ...settings, advanced: { ...settings.advanced, exec_max_runtime_limit: 86400 }, model_presets: [{ name: "default", model: "gpt-5.4", provider: "openai", resolved_provider: "openai", active: true, is_default: true, max_tokens: 8192, context_window_tokens: 200_000, temperature: 0.1, reasoning_effort: null }], model_call_order: ["default"], runtime_config: Object.fromEntries(RUNTIME_CONFIG_FIELDS.map((field) => [field.path, field.kind === "boolean" ? true : field.kind === "toggle" ? field.options?.[1] ?? "" : field.kind === "list" ? [] : field.kind === "number" ? 20 : field.kind === "duration" ? 3600 : "", ])), }; let detailState = "loaded"; export function installSkeletonPreviewApi() { // Windows headless Chromium can report denied even after a context permission grant. if (new URLSearchParams(location.search).get("notificationPermission") === "granted") { Object.defineProperty(Notification, "permission", { configurable: true, value: "granted" }); } const fetch = window.fetch.bind(window); window.fetch = async (input, init) => { const url = new URL(input instanceof Request ? input.url : String(input), location.href); if (url.origin !== location.origin || !url.pathname.startsWith("/api/")) return fetch(input, init); if ((init?.method ?? "GET") !== "GET") return Response.json({ error: "Read-only preview" }, { status: 403 }); if (url.pathname.startsWith("/api/webui/skills/")) { if (detailState === "loading") await new Promise(() => {}); return detailState === "error" ? Response.json({ error: "Preview read failed" }, { status: 503 }) : Response.json(skill); } const bodies: Record = { "/api/settings": previewSettings, "/api/settings/usage": { usage: null }, "/api/webui/automations": { jobs }, "/api/settings/nanobot-features": { features: [], enabled_count: 0, requires_restart: false }, "/api/settings/cli-apps": { apps: [], installed_count: 0 }, "/api/settings/mcp-presets": { presets: [], installed_count: 0 }, "/api/settings/api-service": { installed: false, running: false, managed: false, host: "127.0.0.1", port: 8900, timeout: 120, endpoint: "http://127.0.0.1:8900/v1", command: "nanobot serve" }, }; return Response.json(bodies[url.pathname] ?? {}); }; } export function SkeletonAdditionsFixture() { return new URLSearchParams(location.search).has("preview") ? : ; } function SkeletonPreview() { const params = new URLSearchParams(location.search); const [surface, setSurface] = useState(params.get("surface") ?? "chats"); const [state, setState] = useState(params.get("state") ?? "loaded"); const [section, setSection] = useState((params.get("section") ?? "appearance") as SettingsSectionKey); const [density, setDensity] = useState<"compact" | "comfortable">(params.has("compact") ? "compact" : "comfortable"); const [dark, setDark] = useState(false); const [language, setLanguage] = useState(document.documentElement.lang); const source = new URLSearchParams({ case: "skeleton-additions", surface, state, section }); if (density === "compact") source.set("compact", ""); if (dark) source.set("dark", ""); const changeLanguage = (next: Parameters[0]) => { void setAppLanguage(next).then(() => setLanguage(next)); }; return