import { useState, type ReactNode } from "react"; import { createPortal } from "react-dom"; import { Trans, useTranslation } from "react-i18next"; import { CapabilityMentionToken } from "@/components/CliAppMentionText"; import type { CapabilityMentionSegment } from "@/lib/composer-mention-text"; import { DeleteConfirm } from "@/components/DeleteConfirm"; import { FileActions } from "@/components/FileActions"; import { InlineTokenHighlight, INLINE_TOKEN_HIGHLIGHT_COLOR } from "@/components/InlineTokenHighlight"; import { RenameDialog } from "@/components/RenameDialog"; import { SessionHandleLabel } from "@/components/SessionHandleLabel"; import { SlashCommandText } from "@/components/SlashCommandText"; import { StartupShell } from "@/components/StartupShell"; import { UserMessageText } from "@/components/UserMessageText"; import * as ProductIcons from "@/components/icons/product-icons"; import { HostCompatibilityDialog } from "@/components/remote/HostCompatibilityDialog"; import { HostConnectionStatus } from "@/components/remote/HostConnectionStatus"; import type { HostConnectionState } from "@/components/remote/remote-context"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { PaneWorkbench, type WorkbenchPane } from "@/components/workbench/PaneWorkbench"; import type { HostCompatibility, RemoteProfile } from "@/lib/remote-instances"; import type { CliAppInfo, McpPresetInfo, SessionAutomationJob, SessionMention, WorkbenchLayout } from "@/lib/types"; import { cn } from "@/lib/utils"; import { Sample, StatePicker, type ComponentExample } from "./example"; import { useGalleryTranslation } from "./i18n"; const cliApp: CliAppInfo = { name: "nanobot", display_name: "Nanobot", category: "assistant", description: "Local assistant", requires: "Python", source: "local", entry_point: "nanobot", install_supported: true, installed: true, available: true, status: "installed", skill_installed: true, logo_url: "/brand/nanobot_icon_512.png", brand_color: "var(--inline-token-highlight)", }; const mcpPreset: McpPresetInfo = { name: "files", display_name: "Workspace files", category: "files", description: "Workspace files", docs_url: "", transport: "stdio", requires: "", note: "", install_supported: true, installed: true, configured: true, available: true, status: "configured", required_fields: [], connection_summary: "Local files", }; const sessionMention: SessionMention = { id: "gallery-session", name: "design", session_key: "webui:gallery-design", title: "组件设计", }; function RenamePreview() { const { t } = useTranslation(); const { t: g } = useGalleryTranslation(); const [open, setOpen] = useState(false); const [title, setTitle] = useState("组件设计"); return

{title}

setOpen(false)} onConfirm={(next) => { setTitle(next); setOpen(false); }} />

{g("previews.rename.hint")}

; } const automations: SessionAutomationJob[] = [ { id: "gallery-daily", name: "每日项目摘要", enabled: true, schedule: { kind: "cron", expr: "0 9 * * *", tz: "Asia/Shanghai" }, payload: { message: "Summarize project updates" }, state: { next_run_at_ms: Date.UTC(2026, 9, 14, 1) } }, { id: "gallery-hourly", name: "每小时检查", enabled: false, schedule: { kind: "every", every_ms: 3_600_000 }, payload: { message: "Check updates" }, state: {} }, { id: "gallery-trigger", name: "发布后检查", enabled: true, schedule: { kind: "local" }, payload: { message: "Check the release", kind: "local_trigger" }, state: {} }, { id: "gallery-once", name: "一次性提醒", enabled: true, schedule: { kind: "at", at_ms: Date.UTC(2026, 9, 15, 2) }, payload: { message: "Review the result" }, state: { next_run_at_ms: Date.UTC(2026, 9, 15, 2) } }, { id: "gallery-weekly", name: "每周回顾", enabled: true, schedule: { kind: "every", every_ms: 604_800_000 }, payload: { message: "Review the week" }, state: {} }, ]; function DeletePreview() { const { t } = useGalleryTranslation(); const [scenario, setScenario] = useState<"single" | "multiple" | "automations">("single"); const [open, setOpen] = useState(false); const [deleted, setDeleted] = useState(false); return <> { setScenario(next); setDeleted(false); }} /> setOpen(false)} onConfirm={() => { setDeleted(true); setOpen(false); }} />

{t(deleted ? "previews.delete.confirmed" : "previews.delete.hint")}

; } function InlineTokensPreview() { const { t } = useGalleryTranslation(); const [command, setCommand] = useState("/status"); const [handle, setHandle] = useState("gallery-session"); return
setCommand(event.target.value)} />

}} />

setHandle(event.target.value)} />

@design }} />

review }} />

; } function SessionLinksPreview({ children }: { children: ReactNode }) { const { t } = useGalleryTranslation(); const [selected, setSelected] = useState(false); return
{ if (!(event.target instanceof Element)) return; const link = event.target.closest('a[href^="#/chat/"]'); if (!link) return; event.preventDefault(); setSelected(true); }}> {children}

{selected ? t("previews.sessionLinks.selected", { name: sessionMention.title }) : t("previews.sessionLinks.hint")}

; } function UserTextPreview() { const { t } = useGalleryTranslation(); const [text, setText] = useState("用 $review 检查 @nanobot 的修改,参考 @design 和 @files。"); return