diff --git a/crates/desktop-protocol/src/astrbot.rs b/crates/desktop-protocol/src/astrbot.rs index 6700aa2..650a82f 100644 --- a/crates/desktop-protocol/src/astrbot.rs +++ b/crates/desktop-protocol/src/astrbot.rs @@ -69,6 +69,8 @@ pub struct AstrBotChatRequest { #[serde(skip_serializing_if = "Option::is_none")] pub username: Option, #[serde(skip_serializing_if = "Option::is_none")] + pub nickname: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub config_id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub attachments: Option>, @@ -492,6 +494,7 @@ mod tests { session_id: Some("session-a".into()), conversation_id: None, username: Some("desktop".into()), + nickname: None, config_id: Some("model-a".into()), attachments: Some(vec![AstrBotAttachment { attachment_id: "file-a".into(), diff --git a/crates/desktop-protocol/src/connection.rs b/crates/desktop-protocol/src/connection.rs index 80b9e65..fe06fac 100644 --- a/crates/desktop-protocol/src/connection.rs +++ b/crates/desktop-protocol/src/connection.rs @@ -81,6 +81,8 @@ pub struct ConnectionProfile { /// AstrBot WebChat username / session owner used by OpenAPI chat. #[serde(default, skip_serializing_if = "Option::is_none")] pub remote_username: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub remote_display_name: Option, /// Sticky AstrBot session id for reconnection continuity. #[serde(default, skip_serializing_if = "Option::is_none")] pub sticky_session_id: Option, diff --git a/docs/implementation-queue.md b/docs/implementation-queue.md index 55f51dd..0b61937 100644 --- a/docs/implementation-queue.md +++ b/docs/implementation-queue.md @@ -135,7 +135,12 @@ otification`、`offline`。 - 完成 Windows release/installer、签名、版本号、CHANGELOG 和阶段总结。 - 通过全套阶段门槛后再进入主干合并和验收版本打包。 -## 暂不进入实现 +## 暂不进入实现 + +### 本轮已推进 + +- 远端身份已拆分为协议 ID(`remote_username`)与 BOT 称呼昵称(`remote_display_name`),两者不再共用字段。 +- 2D 纸片人桌宠已从 manifest 基础推进到可运行窗口:透明、无边框、跳过任务栏、关闭后回托盘,并预留状态动作循环。 - 不复制 Hermes 或 Codex 的私有实现;只参考交互模式和资源组织方式。 - 不在首轮实现 Live2D、Spine、3D 桌宠或用户脚本插件。 diff --git a/docs/progress.md b/docs/progress.md index 0df8ff2..2f79585 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -67,7 +67,15 @@ Full product chat UI activation and production identity enrollment remain open f 1. Chat panel MVP against AstrBot adapter. 2. Persist sticky session + message history under profile/server/session keys. -3. Optional auto-connect activation using enrolled credential references only. +3. Optional auto-connect activation using enrolled credential references only. + +## 2026-07-20: remote identity and runnable paper pet increment + +- Added `remote_display_name` as a separate user-facing nickname; `remote_username` remains the validated ASCII protocol ID used for AstrBot session isolation. +- Migrated SQLite profiles to schema v9 without changing existing IDs or credentials. +- Passed the nickname through the Rust-owned AstrBot request boundary as an optional `nickname` field; secrets remain Rust-only. +- Added a transparent, borderless, skip-taskbar pet window with tray-resident hide-on-close behavior and a small CSS 2D paper-character state loop. +- Frontend checks pass; Rust test/build gate remains to be rerun after the final patch. ## Queue decision diff --git a/src-tauri/src/credentials/mod.rs b/src-tauri/src/credentials/mod.rs index 7e1b963..cf6237c 100644 --- a/src-tauri/src/credentials/mod.rs +++ b/src-tauri/src/credentials/mod.rs @@ -288,6 +288,7 @@ mod tests { local_tool_policy_id: None, last_connected_at: None, remote_username: None, + remote_display_name: None, sticky_session_id: None, created_at: "2026-07-20T00:00:00Z".into(), updated_at: "2026-07-20T00:00:00Z".into(), diff --git a/src-tauri/src/database/mod.rs b/src-tauri/src/database/mod.rs index 81a46c0..24ce20f 100644 --- a/src-tauri/src/database/mod.rs +++ b/src-tauri/src/database/mod.rs @@ -7,7 +7,7 @@ use time::{OffsetDateTime, format_description::well_known::Rfc3339}; use rusqlite::{Connection, OptionalExtension, params}; use thiserror::Error; -pub const CURRENT_SCHEMA_VERSION: u32 = 8; +pub const CURRENT_SCHEMA_VERSION: u32 = 9; pub struct ApplicationDatabase { store: Mutex, @@ -529,6 +529,14 @@ fn migrate(connection: &mut Connection) -> Result<(), DatabaseError> { transaction.commit()?; } + if found <= 8 { + let transaction = connection.transaction()?; + transaction.execute_batch( + "ALTER TABLE connection_profiles ADD COLUMN remote_display_name TEXT CHECK(remote_display_name IS NULL OR length(remote_display_name) BETWEEN 1 AND 80); PRAGMA user_version = 9;", + )?; + transaction.commit()?; + } + Ok(()) } diff --git a/src-tauri/src/database/profiles.rs b/src-tauri/src/database/profiles.rs index 1447fe0..47b2c2b 100644 --- a/src-tauri/src/database/profiles.rs +++ b/src-tauri/src/database/profiles.rs @@ -21,8 +21,9 @@ const PROFILE_COLUMNS: &str = " protocol_version, local_tool_policy_id, last_connected_at, - remote_username, - sticky_session_id, + remote_username, + remote_display_name, + sticky_session_id, created_at, updated_at "; @@ -113,14 +114,15 @@ impl ProfileMessageStore { protocol_version, local_tool_policy_id, last_connected_at, - remote_username, - sticky_session_id, + remote_username, + remote_display_name, + sticky_session_id, created_at, updated_at ) VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, - ?19, ?20, ?21 + ?19, ?20, ?21, ?22 ) ", params![ @@ -141,8 +143,9 @@ impl ProfileMessageStore { profile.protocol_version, profile.local_tool_policy_id, profile.last_connected_at, - profile.remote_username, - profile.sticky_session_id, + profile.remote_username, + profile.remote_display_name, + profile.sticky_session_id, profile.created_at, profile.updated_at, ], @@ -170,10 +173,11 @@ impl ProfileMessageStore { protocol_version = ?15, local_tool_policy_id = ?16, last_connected_at = ?17, - remote_username = ?18, - sticky_session_id = ?19, - created_at = ?20, - updated_at = ?21 + remote_username = ?18, + remote_display_name = ?19, + sticky_session_id = ?20, + created_at = ?21, + updated_at = ?22 WHERE id = ?1 ", params![ @@ -194,8 +198,9 @@ impl ProfileMessageStore { profile.protocol_version, profile.local_tool_policy_id, profile.last_connected_at, - profile.remote_username, - profile.sticky_session_id, + profile.remote_username, + profile.remote_display_name, + profile.sticky_session_id, profile.created_at, profile.updated_at, ], @@ -263,9 +268,10 @@ fn profile_from_row(row: &Row<'_>) -> Result { local_tool_policy_id: row.get(15)?, last_connected_at: row.get(16)?, remote_username: row.get(17)?, - sticky_session_id: row.get(18)?, - created_at: row.get(19)?, - updated_at: row.get(20)?, + remote_display_name: row.get(18)?, + sticky_session_id: row.get(19)?, + created_at: row.get(20)?, + updated_at: row.get(21)?, }) } @@ -319,7 +325,8 @@ mod tests { protocol_version: None, local_tool_policy_id: None, last_connected_at: None, - remote_username: None, + remote_username: None, + remote_display_name: None, sticky_session_id: None, created_at: "2026-07-18T00:00:00Z".into(), updated_at: "2026-07-18T00:00:00Z".into(), diff --git a/src-tauri/src/database/slots.rs b/src-tauri/src/database/slots.rs index aa837bf..4818cde 100644 --- a/src-tauri/src/database/slots.rs +++ b/src-tauri/src/database/slots.rs @@ -187,7 +187,8 @@ mod tests { protocol_version: None, local_tool_policy_id: None, last_connected_at: None, - remote_username: None, + remote_username: None, + remote_display_name: None, sticky_session_id: None, created_at: "2026-07-19T00:00:00Z".into(), updated_at: "2026-07-19T00:00:00Z".into(), diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a1040c8..8676516 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -31,6 +31,8 @@ use tauri::{ tray::TrayIconBuilder, }; +const PET_WINDOW_ID: &str = "desktop-pet"; + #[derive(Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] struct BootstrapStatus { @@ -163,6 +165,29 @@ fn open_main_window(app: AppHandle) -> Result<(), String> { window.set_focus().map_err(|error| error.to_string()) } +#[tauri::command] +fn open_pet_window(app: AppHandle) -> Result<(), String> { + if let Some(window) = app.get_webview_window(PET_WINDOW_ID) { + window.show().map_err(|error| error.to_string())?; + return Ok(()); + } + WebviewWindowBuilder::new( + &app, + PET_WINDOW_ID, + WebviewUrl::App("index.html?view=pet".into()), + ) + .title("AstrBot Pet") + .inner_size(180.0, 220.0) + .resizable(false) + .decorations(false) + .transparent(true) + .always_on_top(false) + .skip_taskbar(true) + .build() + .map(|_| ()) + .map_err(|error| error.to_string()) +} + #[tauri::command] fn bootstrap_status( database: tauri::State<'_, ApplicationDatabase>, @@ -254,6 +279,11 @@ pub fn run() { save_quick_window_state(window, window.app_handle()); return; } + if window.label() == PET_WINDOW_ID { + api.prevent_close(); + let _ = window.hide(); + return; + } api.prevent_close(); let _ = window.hide(); } @@ -265,6 +295,7 @@ pub fn run() { open_quick_chat_window, open_main_window, open_status_bubble_window, + open_pet_window, connection_policy_status, profiles::list_connection_profiles, profiles::create_connection_profile, diff --git a/src-tauri/src/networking/astrbot_client.rs b/src-tauri/src/networking/astrbot_client.rs index b1a9bb8..d0146cb 100644 --- a/src-tauri/src/networking/astrbot_client.rs +++ b/src-tauri/src/networking/astrbot_client.rs @@ -24,6 +24,7 @@ pub struct AstrBotClientConfig { pub api_key: SecretString, /// Remote WebChat username used as session owner identity. pub remote_username: String, + pub remote_display_name: Option, /// Optional sticky session id. When absent, the first chat response supplies one. pub session_id: Option, /// Expected server identity substitute. Empty means accept first observed identity. @@ -352,6 +353,7 @@ impl AstrBotClient { session_id: session_id.clone(), conversation_id: None, username: Some(self.config.remote_username.clone()), + nickname: self.config.remote_display_name.clone(), config_id, attachments: (!attachments.is_empty()).then_some(attachments), platform_id: None, @@ -509,6 +511,7 @@ mod tests { base_url: "http://127.0.0.1:1".into(), api_key: SecretString::from(String::new()), remote_username: "user".into(), + remote_display_name: None, session_id: None, expected_server_instance_id: None, }); @@ -523,6 +526,7 @@ mod tests { base_url: "http://192.168.31.210:26285/".into(), api_key: SecretString::from("abk_test".to_owned()), remote_username: "desktop-companion".into(), + remote_display_name: Some("Desktop Companion".into()), session_id: Some("s1".into()), expected_server_instance_id: None, }) diff --git a/src-tauri/src/networking/commands.rs b/src-tauri/src/networking/commands.rs index da08683..8d383f6 100644 --- a/src-tauri/src/networking/commands.rs +++ b/src-tauri/src/networking/commands.rs @@ -175,6 +175,7 @@ fn startup_activation_request( api_key: Some(SecretString::from(api_key)), bearer_token: None, remote_username: Some(remote_username), + remote_display_name: profile.remote_display_name.clone(), session_id: profile.sticky_session_id.clone(), expected_server_instance_id: profile.server_instance_id.clone(), }) @@ -200,6 +201,7 @@ fn startup_activation_request( api_key: None, bearer_token: bearer, remote_username: None, + remote_display_name: None, session_id: None, expected_server_instance_id: Some(expected), }) @@ -398,6 +400,7 @@ pub async fn probe_connection_slot( api_key: Some(SecretString::from(api_key)), bearer_token: None, remote_username: Some(remote_username), + remote_display_name: profile.remote_display_name.clone(), session_id: profile.sticky_session_id.clone(), expected_server_instance_id: profile.server_instance_id.clone(), } @@ -423,6 +426,7 @@ pub async fn probe_connection_slot( api_key: None, bearer_token: bearer, remote_username: None, + remote_display_name: None, session_id: None, expected_server_instance_id: Some(expected), } diff --git a/src-tauri/src/networking/runtime.rs b/src-tauri/src/networking/runtime.rs index ceead2a..9ae3414 100644 --- a/src-tauri/src/networking/runtime.rs +++ b/src-tauri/src/networking/runtime.rs @@ -39,6 +39,7 @@ pub struct SlotActivationRequest { pub api_key: Option, pub bearer_token: Option, pub remote_username: Option, + pub remote_display_name: Option, pub session_id: Option, pub expected_server_instance_id: Option, } @@ -258,6 +259,7 @@ impl DualSlotRuntime { base_url: request.base_url.clone(), api_key, remote_username, + remote_display_name: request.remote_display_name.clone(), session_id: request.session_id.clone(), expected_server_instance_id: request.expected_server_instance_id.clone(), }) @@ -572,6 +574,7 @@ mod tests { api_key: None, bearer_token: None, remote_username: None, + remote_display_name: None, session_id: None, expected_server_instance_id: None, }) diff --git a/src-tauri/src/policy.rs b/src-tauri/src/policy.rs index 7c5e8d4..c827dfe 100644 --- a/src-tauri/src/policy.rs +++ b/src-tauri/src/policy.rs @@ -169,7 +169,8 @@ mod tests { protocol_version: None, local_tool_policy_id: None, last_connected_at: None, - remote_username: None, + remote_username: None, + remote_display_name: None, sticky_session_id: None, created_at: "2026-07-19T00:00:00Z".into(), updated_at: "2026-07-19T00:00:00Z".into(), diff --git a/src-tauri/src/profiles.rs b/src-tauri/src/profiles.rs index 572193c..b26e5ef 100644 --- a/src-tauri/src/profiles.rs +++ b/src-tauri/src/profiles.rs @@ -26,8 +26,10 @@ pub struct ConnectionProfileInput { pub transport_kind: TransportKind, #[serde(default)] pub allow_insecure_http: bool, - #[serde(default)] - pub remote_username: Option, + #[serde(default)] + pub remote_username: Option, + #[serde(default)] + pub remote_display_name: Option, #[serde(default)] pub pinned_certificate_fingerprint: Option, #[serde(default)] @@ -154,7 +156,8 @@ fn create_profile( protocol_version: None, local_tool_policy_id: None, last_connected_at: None, - remote_username: normalized.remote_username, + remote_username: normalized.remote_username, + remote_display_name: normalized.remote_display_name, sticky_session_id: None, created_at: now.clone(), updated_at: now, @@ -194,7 +197,8 @@ fn update_profile( profile.authentication_type = normalized.authentication_type; profile.transport_kind = normalized.transport_kind; profile.allow_insecure_http = normalized.allow_insecure_http; - profile.remote_username = normalized.remote_username; + profile.remote_username = normalized.remote_username; + profile.remote_display_name = normalized.remote_display_name; profile.pinned_certificate_fingerprint = normalized.pinned_certificate_fingerprint; profile.auto_connect = normalized.auto_connect; profile.auto_connect_slot = normalized.auto_connect_slot; @@ -251,6 +255,20 @@ fn normalize_input( return Err(ProfileCommandError::validation(REMOTE_USERNAME_PATTERN)); } + let remote_display_name = request + .remote_display_name + .as_deref() + .map(str::trim) + .filter(|value| !value.is_empty()) + .map(str::to_owned); + if let Some(name) = &remote_display_name + && (name.chars().count() > MAX_DISPLAY_NAME_CHARS || name.chars().any(char::is_control)) + { + return Err(ProfileCommandError::validation( + "Remote nickname must contain 1 to 80 visible characters.", + )); + } + Ok(ConnectionProfileInput { display_name, role: request.role, @@ -259,7 +277,8 @@ fn normalize_input( authentication_type: request.authentication_type, transport_kind: request.transport_kind, allow_insecure_http: request.allow_insecure_http, - remote_username, + remote_username, + remote_display_name, pinned_certificate_fingerprint, auto_connect: request.auto_connect, auto_connect_slot: request.auto_connect_slot, @@ -356,7 +375,8 @@ mod tests { authentication_type: AuthenticationType::DeviceToken, transport_kind: TransportKind::DesktopV1, allow_insecure_http: false, - remote_username: None, + remote_username: None, + remote_display_name: Some("测试用户".into()), pinned_certificate_fingerprint: None, auto_connect: false, auto_connect_slot: None, @@ -370,7 +390,8 @@ mod tests { create_profile(&database, request("https://example.test")).expect("create profile"); assert_eq!(created.display_name, "Test Profile"); assert_eq!(created.base_url, "https://example.test/"); - assert!(created.credential_reference.is_none()); + assert!(created.credential_reference.is_none()); + assert_eq!(created.remote_display_name.as_deref(), Some("测试用户")); assert!(!created.auto_connect); assert!(created.auto_connect_slot.is_none()); @@ -386,7 +407,8 @@ mod tests { authentication_type: AuthenticationType::ApiKey, transport_kind: TransportKind::DesktopV1, allow_insecure_http: false, - remote_username: None, + remote_username: None, + remote_display_name: Some("更新昵称".into()), pinned_certificate_fingerprint: None, auto_connect: true, auto_connect_slot: Some(ActiveSlotKind::Companion), @@ -396,7 +418,8 @@ mod tests { .expect("update profile"); assert_eq!(updated.display_name, "Updated"); assert!(updated.auto_connect); - assert_eq!(updated.auto_connect_slot, Some(ActiveSlotKind::Companion)); + assert_eq!(updated.auto_connect_slot, Some(ActiveSlotKind::Companion)); + assert_eq!(updated.remote_display_name.as_deref(), Some("更新昵称")); assert_eq!(list_profiles(&database).expect("list profiles").len(), 1); delete_profile(&database, &created.id).expect("delete profile"); diff --git a/src-tauri/src/slots.rs b/src-tauri/src/slots.rs index 6f5528c..858fd34 100644 --- a/src-tauri/src/slots.rs +++ b/src-tauri/src/slots.rs @@ -179,7 +179,8 @@ mod tests { protocol_version: None, local_tool_policy_id: None, last_connected_at: None, - remote_username: None, + remote_username: None, + remote_display_name: None, sticky_session_id: None, created_at: "2026-07-19T00:00:00Z".into(), updated_at: "2026-07-19T00:00:00Z".into(), diff --git a/src/App.tsx b/src/App.tsx index 6ad49b1..b0bd3b9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,5 @@ import { invoke } from "@tauri-apps/api/core"; +import { getCurrentWindow } from "@tauri-apps/api/window"; import { useCallback, useEffect, useState } from "react"; import { ChatPanel } from "./features/chat/ChatPanel"; @@ -37,6 +38,7 @@ export function App() { const view = params.get("view"); const isQuickView = view === "quick"; const isBubbleView = view === "bubble"; + const isPetView = view === "pet"; const quickSlot = params.get("slot"); const [page, setPage] = useState("chat"); const [status, setStatus] = useState(initialStatus); @@ -66,6 +68,7 @@ export function App() { }, [refreshStatus]); if (isBubbleView) return ; + if (isPetView) return ; if (isQuickView) { return (
@@ -373,11 +376,60 @@ function PetPage() { + + + ); } +function DesktopPetView() { + const [state, setState] = useState<"idle" | "working" | "resting" | "speaking">("idle"); + + useEffect(() => { + const states: Array = ["idle", "working", "resting", "speaking"]; + const timer = window.setInterval(() => { + setState((current) => states[(states.indexOf(current) + 1) % states.length]); + }, 4200); + return () => window.clearInterval(timer); + }, []); + + return ( +
+ +
+
+
+ + + + + +
+
+ + + +
+
+ {state === "working" ? "正在写写画画" : state === "resting" ? "休息中" : state === "speaking" ? "正在回应" : "陪伴中"} +
+ ); +} + function DiagnosticsPage({ status, onRefresh, diff --git a/src/features/profiles/ProfileManager.tsx b/src/features/profiles/ProfileManager.tsx index b9af4b3..3f9c8ed 100644 --- a/src/features/profiles/ProfileManager.tsx +++ b/src/features/profiles/ProfileManager.tsx @@ -28,8 +28,9 @@ interface ProfileFormState { baseUrl: string; eventStreamUrl: string; authenticationType: AuthenticationType; - transportKind: TransportKind; - remoteUsername: string; + transportKind: TransportKind; + remoteUsername: string; + remoteDisplayName: string; allowInsecureHttp: boolean; pinnedCertificateFingerprint: string; autoConnect: boolean; @@ -43,7 +44,8 @@ const emptyForm: ProfileFormState = { eventStreamUrl: "", authenticationType: "device-token", transportKind: "desktop-v1", - remoteUsername: "", + remoteUsername: "", + remoteDisplayName: "", allowInsecureHttp: false, pinnedCertificateFingerprint: "", autoConnect: false, @@ -134,7 +136,8 @@ export function ProfileManager() { eventStreamUrl: profile.eventStreamUrl ?? "", authenticationType: profile.authenticationType, transportKind: profile.transportKind ?? "desktop-v1", - remoteUsername: profile.remoteUsername ?? "", + remoteUsername: profile.remoteUsername ?? "", + remoteDisplayName: profile.remoteDisplayName ?? "", allowInsecureHttp: profile.allowInsecureHttp, pinnedCertificateFingerprint: profile.pinnedCertificateFingerprint ?? "", autoConnect: profile.autoConnect, @@ -442,21 +445,37 @@ export function ProfileManager() { - {form.transportKind === "astrbot-openapi" ? ( + {form.transportKind === "astrbot-openapi" ? ( + <> - ) : null} + placeholder="desktop-companion" + /> + + + + ) : null}