feat(identity): add jwt and paper pet actions
这个提交存在于:
父节点
8ec7fa9612
当前提交
058bfc7029
共有 10 个文件被更改,包括 64 次插入 和 27 次删除
|
|
@ -23,6 +23,7 @@ pub enum AstrBotProfileRole {
|
|||
pub enum AuthenticationType {
|
||||
DeviceToken,
|
||||
ApiKey,
|
||||
Jwt,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
"AuthenticationType": {
|
||||
"enum": [
|
||||
"device-token",
|
||||
"api-key"
|
||||
"api-key",
|
||||
"jwt"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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<ProfileMessageStore>,
|
||||
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -227,7 +227,8 @@ fn profile_from_row(row: &Row<'_>) -> Result<ConnectionProfile, DatabaseError> {
|
|||
};
|
||||
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",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<section className="pet-pack-importer" aria-label="???????">
|
||||
<section className="pet-pack-importer" aria-label="桌宠素材包导入">
|
||||
<div>
|
||||
<p className="eyebrow">Q6 pet pack</p>
|
||||
<h2>?????</h2>
|
||||
<p className="eyebrow">Q6 2D paper pet</p>
|
||||
<h2>桌宠素材包</h2>
|
||||
<p className="form-note">
|
||||
????? JSON manifest?????????????????????????
|
||||
当前支持 PNG/WebP spritesheet、状态动作片段和受限移动策略。
|
||||
</p>
|
||||
</div>
|
||||
<input
|
||||
accept=".json,application/json"
|
||||
aria-label="???? manifest"
|
||||
aria-label="选择桌宠 manifest"
|
||||
type="file"
|
||||
onChange={(event) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (file) void importManifest(file);
|
||||
}}
|
||||
/>
|
||||
{fileName ? <p className="form-note">???{fileName}</p> : null}
|
||||
{fileName ? <p className="form-note">已选择:{fileName}</p> : null}
|
||||
{error ? <p className="error-banner">{error}</p> : null}
|
||||
{manifest ? (
|
||||
<div className="pet-pack-preview">
|
||||
<strong>{manifest.name}</strong>
|
||||
<span>{manifest.version}</span>
|
||||
<span>
|
||||
{manifest.width} ? {manifest.height}
|
||||
{manifest.width} × {manifest.height}
|
||||
</span>
|
||||
<span>{manifest.animations.length} 个动作片段</span>
|
||||
<span>
|
||||
{manifest.animations.filter((animation) => animation.movement !== "stationary").length} 个移动动作
|
||||
</span>
|
||||
<span>{manifest.animations.length} ?????</span>
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -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<typeof companionStateSchema>;
|
||||
export type PetMovement = z.infer<typeof petMovementSchema>;
|
||||
export type PetPackManifest = z.infer<typeof petPackManifestSchema>;
|
||||
export type CompanionPresentationSettings = z.infer<
|
||||
typeof companionPresentationSettingsSchema
|
||||
|
|
|
|||
|
|
@ -390,7 +390,8 @@ export function ProfileManager() {
|
|||
}
|
||||
>
|
||||
<option value="device-token">设备 Token</option>
|
||||
<option value="api-key">API Key</option>
|
||||
<option value="api-key">API Key</option>
|
||||
<option value="jwt">AstrBot JWT</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用