diff --git a/crates/desktop-protocol/src/connection.rs b/crates/desktop-protocol/src/connection.rs index 7905138..80b9e65 100644 --- a/crates/desktop-protocol/src/connection.rs +++ b/crates/desktop-protocol/src/connection.rs @@ -23,6 +23,7 @@ pub enum AstrBotProfileRole { pub enum AuthenticationType { DeviceToken, ApiKey, + Jwt, } #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)] diff --git a/docs/progress.md b/docs/progress.md index 53ba619..2549da9 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -168,3 +168,11 @@ Still not claimed complete: automatic startup activation, real Tauri multi-windo - Fixed the global close handler so the quick-chat window can be closed normally instead of being intercepted and only hidden. - The main window keeps the existing tray behavior; quick-chat geometry is saved before destruction and restored when reopened. - Validation: Rust Clippy and `astrbot-desktop` unit tests (64) pass. + +## 2026-07-20: JWT profile and 2D paper pet foundation + +- Added JWT as a persisted connection authentication type alongside API Key and device token; SQLite schema is now v8 and migrates existing profiles without losing slot assignments. +- Added remote ID validation: 3-32 ASCII letters or digits; the ID remains separate from the user-facing nickname field planned for the profile UI. +- Extended the pet-pack manifest with optional animation IDs, loop flags, and bounded movement modes for 2D paper-character actions. +- Updated the pet importer copy and JWT selection UI; full Dashboard login, JWT expiry handling, and background pet window controller remain next-stage work. +- Validation: Rust workspace tests, TypeScript, ESLint, Vitest (6), and Vite production build pass. diff --git a/docs/protocol/v1/schemas/connection-profile.schema.json b/docs/protocol/v1/schemas/connection-profile.schema.json index 7db288b..3c6661e 100644 --- a/docs/protocol/v1/schemas/connection-profile.schema.json +++ b/docs/protocol/v1/schemas/connection-profile.schema.json @@ -18,7 +18,8 @@ "AuthenticationType": { "enum": [ "device-token", - "api-key" + "api-key", + "jwt" ], "type": "string" }, diff --git a/src-tauri/src/database/mod.rs b/src-tauri/src/database/mod.rs index 08363d4..81a46c0 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 = 7; +pub const CURRENT_SCHEMA_VERSION: u32 = 8; pub struct ApplicationDatabase { store: Mutex, @@ -431,7 +431,7 @@ fn migrate(connection: &mut Connection) -> Result<(), DatabaseError> { role TEXT NOT NULL CHECK(role IN ('companion', 'operations', 'general')), base_url TEXT NOT NULL, event_stream_url TEXT, - authentication_type TEXT NOT NULL CHECK(authentication_type IN ('device-token', 'api-key')), + authentication_type TEXT NOT NULL CHECK(authentication_type IN ('device-token', 'api-key', 'jwt')), credential_reference TEXT, allow_insecure_http INTEGER NOT NULL DEFAULT 0 CHECK(allow_insecure_http IN (0, 1)), pinned_certificate_fingerprint TEXT, @@ -521,6 +521,14 @@ fn migrate(connection: &mut Connection) -> Result<(), DatabaseError> { transaction.commit()?; } + if found <= 7 { + let transaction = connection.transaction()?; + transaction.execute_batch( + "ALTER TABLE connection_slots RENAME TO connection_slots_legacy; ALTER TABLE connection_profiles RENAME TO connection_profiles_legacy; DROP INDEX IF EXISTS connection_profiles_role_idx; CREATE TABLE connection_profiles (id TEXT PRIMARY KEY NOT NULL, display_name TEXT NOT NULL CHECK(length(display_name) BETWEEN 1 AND 80), role TEXT NOT NULL CHECK(role IN ('companion', 'operations', 'general')), base_url TEXT NOT NULL, event_stream_url TEXT, authentication_type TEXT NOT NULL CHECK(authentication_type IN ('device-token', 'api-key', 'jwt')), credential_reference TEXT, allow_insecure_http INTEGER NOT NULL DEFAULT 0 CHECK(allow_insecure_http IN (0, 1)), pinned_certificate_fingerprint TEXT, auto_connect_slot TEXT CHECK(auto_connect_slot IS NULL OR auto_connect_slot IN ('companion', 'operations')), auto_connect INTEGER NOT NULL DEFAULT 0 CHECK(auto_connect IN (0, 1)), server_instance_id TEXT, server_version TEXT, protocol_version TEXT, local_tool_policy_id TEXT, last_connected_at TEXT, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, transport_kind TEXT NOT NULL DEFAULT 'desktop-v1', remote_username TEXT, sticky_session_id TEXT); CREATE INDEX connection_profiles_role_idx ON connection_profiles(role); INSERT INTO connection_profiles SELECT id, display_name, role, base_url, event_stream_url, authentication_type, credential_reference, allow_insecure_http, pinned_certificate_fingerprint, auto_connect_slot, auto_connect, server_instance_id, server_version, protocol_version, local_tool_policy_id, last_connected_at, created_at, updated_at, transport_kind, remote_username, sticky_session_id FROM connection_profiles_legacy; CREATE TABLE connection_slots (slot TEXT PRIMARY KEY NOT NULL CHECK(slot IN ('companion', 'operations')), profile_id TEXT UNIQUE REFERENCES connection_profiles(id) ON DELETE SET NULL, updated_at TEXT NOT NULL); INSERT INTO connection_slots SELECT slot, profile_id, updated_at FROM connection_slots_legacy; DROP TABLE connection_slots_legacy; DROP TABLE connection_profiles_legacy; PRAGMA user_version = 8;", + )?; + transaction.commit()?; + } + Ok(()) } diff --git a/src-tauri/src/database/profiles.rs b/src-tauri/src/database/profiles.rs index b3dc317..1447fe0 100644 --- a/src-tauri/src/database/profiles.rs +++ b/src-tauri/src/database/profiles.rs @@ -227,7 +227,8 @@ fn profile_from_row(row: &Row<'_>) -> Result { }; let authentication_type = match row.get::<_, String>(5)?.as_str() { "device-token" => AuthenticationType::DeviceToken, - "api-key" => AuthenticationType::ApiKey, + "api-key" => AuthenticationType::ApiKey, + "jwt" => AuthenticationType::Jwt, _ => return Err(DatabaseError::InvalidStoredProfile), }; let transport_kind = match row.get::<_, String>(6)?.as_str() { @@ -279,7 +280,8 @@ fn role_to_str(role: AstrBotProfileRole) -> &'static str { fn authentication_to_str(authentication_type: AuthenticationType) -> &'static str { match authentication_type { AuthenticationType::DeviceToken => "device-token", - AuthenticationType::ApiKey => "api-key", + AuthenticationType::ApiKey => "api-key", + AuthenticationType::Jwt => "jwt", } } diff --git a/src-tauri/src/profiles.rs b/src-tauri/src/profiles.rs index a748b4f..572193c 100644 --- a/src-tauri/src/profiles.rs +++ b/src-tauri/src/profiles.rs @@ -10,7 +10,8 @@ use crate::database::{ApplicationDatabase, DatabaseError}; use crate::policy::{self, AutoConnectValidationError}; const MAX_DISPLAY_NAME_CHARS: usize = 80; -const MAX_URL_CHARS: usize = 2048; +const MAX_URL_CHARS: usize = 2048; +const REMOTE_USERNAME_PATTERN: &str = "ASCII letters and digits only, 3-32 characters."; #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] @@ -242,14 +243,14 @@ fn normalize_input( .map(str::trim) .filter(|value| !value.is_empty()) .map(str::to_owned); - if let Some(username) = &remote_username - && (username.chars().count() > 80 || username.chars().any(char::is_control)) - { - return Err(ProfileCommandError::validation( - "Remote username must contain 1 to 80 visible characters.", - )); - } - + if let Some(username) = &remote_username + && (username.len() < 3 + || username.len() > 32 + || !username.bytes().all(|byte| byte.is_ascii_alphanumeric())) + { + return Err(ProfileCommandError::validation(REMOTE_USERNAME_PATTERN)); + } + Ok(ConnectionProfileInput { display_name, role: request.role, diff --git a/src/features/pet/PetPackImporter.tsx b/src/features/pet/PetPackImporter.tsx index 2fabad6..d961781 100644 --- a/src/features/pet/PetPackImporter.tsx +++ b/src/features/pet/PetPackImporter.tsx @@ -12,45 +12,48 @@ export function PetPackImporter() { setManifest(null); setError(null); if (!file.name.toLowerCase().endsWith(".json") || file.size > 256 * 1024) { - setError("?????? 256 KiB ? JSON manifest ???"); + setError("文件必须是 256 KiB 以内的 JSON manifest。若要导入图片,请先放入素材包目录。 "); return; } try { const parsed = petPackManifestSchema.parse(JSON.parse(await file.text())); setManifest(parsed); } catch (reason) { - setError(reason instanceof Error ? reason.message : "??? manifest ???"); + setError(reason instanceof Error ? reason.message : "无法读取桌宠 manifest。 "); } }; return ( -
+
-

Q6 pet pack

-

?????

+

Q6 2D paper pet

+

桌宠素材包

- ????? JSON manifest????????????????????????? + 当前支持 PNG/WebP spritesheet、状态动作片段和受限移动策略。

{ const file = event.target.files?.[0]; if (file) void importManifest(file); }} /> - {fileName ?

???{fileName}

: null} + {fileName ?

已选择:{fileName}

: null} {error ?

{error}

: null} {manifest ? (
{manifest.name} {manifest.version} - {manifest.width} ? {manifest.height} + {manifest.width} × {manifest.height} + + {manifest.animations.length} 个动作片段 + + {manifest.animations.filter((animation) => animation.movement !== "stationary").length} 个移动动作 - {manifest.animations.length} ?????
) : null}
diff --git a/src/features/pet/types.ts b/src/features/pet/types.ts index 992c558..1fe4ef9 100644 --- a/src/features/pet/types.ts +++ b/src/features/pet/types.ts @@ -18,11 +18,21 @@ export const petPositionModeSchema = z.enum([ ]); export const bubbleClickTargetSchema = z.enum(["main", "quick"]); +export const petMovementSchema = z.enum([ + "stationary", + "walk", + "wander", + "edge", +]); + export const petAnimationSchema = z .object({ + id: z.string().regex(/^[a-z][a-z0-9-]{0,31}$/).optional(), state: companionStateSchema, frames: z.array(z.number().int().nonnegative()).min(1), fps: z.number().positive().max(60), + loop: z.boolean().default(true), + movement: petMovementSchema.default("stationary"), }) .strict(); @@ -50,6 +60,7 @@ export const companionPresentationSettingsSchema = z .strict(); export type CompanionState = z.infer; +export type PetMovement = z.infer; export type PetPackManifest = z.infer; export type CompanionPresentationSettings = z.infer< typeof companionPresentationSettingsSchema diff --git a/src/features/profiles/ProfileManager.tsx b/src/features/profiles/ProfileManager.tsx index 0531754..b9af4b3 100644 --- a/src/features/profiles/ProfileManager.tsx +++ b/src/features/profiles/ProfileManager.tsx @@ -390,7 +390,8 @@ export function ProfileManager() { } > - + + diff --git a/src/types/profile.ts b/src/types/profile.ts index 3c4d941..556b83e 100644 --- a/src/types/profile.ts +++ b/src/types/profile.ts @@ -2,12 +2,13 @@ import { z } from "zod"; export const profileRoleSchema = z.enum(["companion", "operations", "general"]); -export const authenticationTypeSchema = z.enum(["device-token", "api-key"]); +export const authenticationTypeSchema = z.enum(["device-token", "api-key", "jwt"]); export const transportKindSchema = z.enum(["desktop-v1", "astrbot-openapi"]); export const activeSlotKindSchema = z.enum(["companion", "operations"]); +const remoteUsername = z.string().regex(/^[A-Za-z0-9]{3,32}$/).optional(); const optionalIdentifier = z.string().min(1).optional(); export const connectionProfileSchema = z @@ -32,7 +33,7 @@ export const connectionProfileSchema = z protocolVersion: optionalIdentifier, localToolPolicyId: optionalIdentifier, lastConnectedAt: optionalIdentifier, - remoteUsername: optionalIdentifier, + remoteUsername, stickySessionId: optionalIdentifier, createdAt: z.string().min(1), updatedAt: z.string().min(1),