2026-07-20 12:34:56 +08:00
|
|
|
|
import { invoke } from "@tauri-apps/api/core";
|
2026-07-18 20:34:47 +08:00
|
|
|
|
import { useCallback, useEffect, useState } from "react";
|
|
|
|
|
|
|
2026-07-20 11:31:41 +08:00
|
|
|
|
import { ChatPanel } from "./features/chat/ChatPanel";
|
|
|
|
|
|
import { StatusBubble } from "./features/chat/StatusBubble";
|
2026-07-18 23:36:59 +08:00
|
|
|
|
import { ProfileManager } from "./features/profiles/ProfileManager";
|
2026-07-18 22:17:29 +08:00
|
|
|
|
import { bootstrapStatusSchema, type BootstrapStatus } from "./types/bootstrap";
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
|
|
|
|
|
const initialStatus: BootstrapStatus = {
|
|
|
|
|
|
appVersion: "unknown",
|
|
|
|
|
|
platform: "unknown",
|
|
|
|
|
|
rustCore: "pending",
|
|
|
|
|
|
protocolVersion: "desktop-v1alpha1",
|
2026-07-20 11:31:41 +08:00
|
|
|
|
databaseSchemaVersion: 4,
|
2026-07-18 20:34:47 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export function App() {
|
2026-07-20 11:31:41 +08:00
|
|
|
|
const view = new URLSearchParams(window.location.search).get("view");
|
|
|
|
|
|
const isQuickView = view === "quick";
|
|
|
|
|
|
const isBubbleView = view === "bubble";
|
2026-07-20 12:34:56 +08:00
|
|
|
|
const quickSlot = new URLSearchParams(window.location.search).get("slot");
|
2026-07-18 20:34:47 +08:00
|
|
|
|
const [status, setStatus] = useState(initialStatus);
|
|
|
|
|
|
const [error, setError] = useState<string | null>(null);
|
2026-07-20 12:30:12 +08:00
|
|
|
|
const [chatLayout, setChatLayout] = useState<
|
|
|
|
|
|
"single" | "focus-companion" | "focus-operations"
|
|
|
|
|
|
>("single");
|
2026-07-20 12:34:56 +08:00
|
|
|
|
const [quickTarget, setQuickTarget] = useState<"companion" | "operations">(
|
|
|
|
|
|
() =>
|
|
|
|
|
|
localStorage.getItem("astrbot.quickTarget") === "operations"
|
|
|
|
|
|
? "operations"
|
|
|
|
|
|
: "companion",
|
|
|
|
|
|
);
|
|
|
|
|
|
const [bubbleTarget, setBubbleTarget] = useState<"main" | "quick">(() =>
|
|
|
|
|
|
localStorage.getItem("astrbot.bubbleTarget") === "quick" ? "quick" : "main",
|
|
|
|
|
|
);
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
|
|
|
|
|
const refreshStatus = useCallback(async () => {
|
|
|
|
|
|
try {
|
2026-07-18 22:17:29 +08:00
|
|
|
|
const result = await invoke<unknown>("bootstrap_status");
|
|
|
|
|
|
setStatus(bootstrapStatusSchema.parse(result));
|
2026-07-18 20:34:47 +08:00
|
|
|
|
setError(null);
|
|
|
|
|
|
} catch (reason) {
|
|
|
|
|
|
setError(reason instanceof Error ? reason.message : String(reason));
|
|
|
|
|
|
}
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
void refreshStatus();
|
|
|
|
|
|
}, [refreshStatus]);
|
|
|
|
|
|
|
2026-07-20 11:31:41 +08:00
|
|
|
|
if (isBubbleView) return <StatusBubble />;
|
|
|
|
|
|
if (isQuickView)
|
|
|
|
|
|
return (
|
|
|
|
|
|
<main className="quick-app-shell">
|
2026-07-20 12:34:56 +08:00
|
|
|
|
<ChatPanel
|
|
|
|
|
|
fixedSlot={
|
|
|
|
|
|
quickSlot === "operations"
|
|
|
|
|
|
? "operations"
|
|
|
|
|
|
: quickSlot === "companion"
|
|
|
|
|
|
? "companion"
|
|
|
|
|
|
: undefined
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
2026-07-20 11:31:41 +08:00
|
|
|
|
</main>
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2026-07-18 20:34:47 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<main className="app-shell">
|
|
|
|
|
|
<header className="hero">
|
2026-07-20 11:31:41 +08:00
|
|
|
|
<p className="eyebrow">P02 路 dual connections</p>
|
2026-07-18 20:34:47 +08:00
|
|
|
|
<h1>AstrBot Desktop</h1>
|
|
|
|
|
|
<p className="subtitle">
|
2026-07-20 11:31:41 +08:00
|
|
|
|
鍙屽疄渚嬮櫔浼翠笌鏈満鍔╂墜鐨勫畨鍏?Windows
|
|
|
|
|
|
瀹㈡埛绔伐绋嬪簳搴с€?{" "}
|
2026-07-18 20:34:47 +08:00
|
|
|
|
</p>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
<section className="status-grid" aria-label="bootstrap status">
|
|
|
|
|
|
<StatusCard label="Rust Core" value={status.rustCore} />
|
|
|
|
|
|
<StatusCard label="Platform" value={status.platform} />
|
|
|
|
|
|
<StatusCard label="App Version" value={status.appVersion} />
|
|
|
|
|
|
<StatusCard label="Protocol" value={status.protocolVersion} />
|
|
|
|
|
|
</section>
|
2026-07-18 22:17:29 +08:00
|
|
|
|
<StatusCard
|
|
|
|
|
|
label="Database Schema"
|
|
|
|
|
|
value={String(status.databaseSchemaVersion)}
|
|
|
|
|
|
/>
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
|
|
|
|
|
{error ? <p className="error-banner">IPC unavailable: {error}</p> : null}
|
|
|
|
|
|
|
|
|
|
|
|
<section className="boundaries">
|
2026-07-20 11:31:41 +08:00
|
|
|
|
<h2>瀹夊叏杈圭晫</h2>
|
2026-07-18 20:34:47 +08:00
|
|
|
|
<ul>
|
|
|
|
|
|
<li>凭据只在 Rust 与 Windows 安全存储之间流动。</li>
|
|
|
|
|
|
<li>两个 REST/SSE 槽位保持独立状态与事件来源。</li>
|
|
|
|
|
|
<li>本机操作必须经过白名单、策略与用户授权。</li>
|
|
|
|
|
|
<li>文件事务默认保留源文件,且不会静默覆盖。</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</section>
|
2026-07-20 11:31:41 +08:00
|
|
|
|
<div className="chat-actions">
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
2026-07-20 12:34:56 +08:00
|
|
|
|
onClick={() =>
|
|
|
|
|
|
void invoke("open_quick_chat_window", { slot: quickTarget })
|
|
|
|
|
|
}
|
2026-07-20 11:31:41 +08:00
|
|
|
|
>
|
|
|
|
|
|
打开快速聊天
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
2026-07-20 12:34:56 +08:00
|
|
|
|
<section className="desktop-behavior-settings" aria-label="??????">
|
|
|
|
|
|
<label>
|
|
|
|
|
|
<span>????????</span>
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={quickTarget}
|
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
|
const value =
|
|
|
|
|
|
event.target.value === "operations"
|
|
|
|
|
|
? "operations"
|
|
|
|
|
|
: "companion";
|
|
|
|
|
|
setQuickTarget(value);
|
|
|
|
|
|
localStorage.setItem("astrbot.quickTarget", value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<option value="companion">Companion / ??</option>
|
|
|
|
|
|
<option value="operations">Operations / ??</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<label>
|
|
|
|
|
|
<span>??????</span>
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={bubbleTarget}
|
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
|
const value = event.target.value === "quick" ? "quick" : "main";
|
|
|
|
|
|
setBubbleTarget(value);
|
|
|
|
|
|
localStorage.setItem("astrbot.bubbleTarget", value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<option value="main">?????</option>
|
|
|
|
|
|
<option value="quick">??????</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
2026-07-20 12:30:12 +08:00
|
|
|
|
<section className="chat-workspace" aria-label="???????">
|
|
|
|
|
|
<div className="chat-workspace-toolbar">
|
|
|
|
|
|
<strong>????</strong>
|
|
|
|
|
|
<button
|
|
|
|
|
|
className={
|
|
|
|
|
|
chatLayout === "single"
|
|
|
|
|
|
? "button-secondary active"
|
|
|
|
|
|
: "button-secondary"
|
|
|
|
|
|
}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => setChatLayout("single")}
|
|
|
|
|
|
>
|
|
|
|
|
|
???
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
className={
|
|
|
|
|
|
chatLayout === "focus-companion"
|
|
|
|
|
|
? "button-secondary active"
|
|
|
|
|
|
: "button-secondary"
|
|
|
|
|
|
}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => setChatLayout("focus-companion")}
|
|
|
|
|
|
>
|
|
|
|
|
|
????
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
className={
|
|
|
|
|
|
chatLayout === "focus-operations"
|
|
|
|
|
|
? "button-secondary active"
|
|
|
|
|
|
: "button-secondary"
|
|
|
|
|
|
}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => setChatLayout("focus-operations")}
|
|
|
|
|
|
>
|
|
|
|
|
|
????
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<ChatPanel
|
|
|
|
|
|
fixedSlot={
|
|
|
|
|
|
chatLayout === "focus-companion"
|
|
|
|
|
|
? "companion"
|
|
|
|
|
|
: chatLayout === "focus-operations"
|
|
|
|
|
|
? "operations"
|
|
|
|
|
|
: undefined
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</section>
|
2026-07-18 23:36:59 +08:00
|
|
|
|
<ProfileManager />
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
|
|
|
|
|
<button type="button" onClick={() => void refreshStatus()}>
|
2026-07-20 11:31:41 +08:00
|
|
|
|
閲嶆柊妫€鏌?IPC
|
2026-07-18 20:34:47 +08:00
|
|
|
|
</button>
|
|
|
|
|
|
</main>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface StatusCardProps {
|
|
|
|
|
|
label: string;
|
|
|
|
|
|
value: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function StatusCard({ label, value }: StatusCardProps) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<article className="status-card">
|
|
|
|
|
|
<span>{label}</span>
|
|
|
|
|
|
<strong>{value}</strong>
|
|
|
|
|
|
</article>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|