DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(pet): 会话状态动画资产缺失时降级,修复拖拽结束卡死循环
hairyf84d627d936a3
diff --git a/src/pet/components/pet.tsx b/src/pet/components/pet.tsxindex d2614c38..073754d2 100644--- a/src/pet/components/pet.tsx+++ b/src/pet/components/pet.tsx@@ -8,6 +8,7 @@ import { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'reactimport { If } from 'react-if-lite'import { PET_STATUSES } from '../hooks/use-pet'import {+ fallbackPresetName,isLoopingAnimation,pick,pickCategoryAction,@@ -307,9 +308,14 @@ export function Pet(props: PetProps) {return undefined// 预设配置池条目 = 动画名 = webm 文件名主名;adHoc 已携带动画名时直接命中,// 会话状态(waiting/running/review/failed/bubble)经 PRESET_SESSION_ANIMATIONS- // 叠加映射到具体动画名(写代码/轻快记录/玩游戏气急败坏…),映射名无资产时- // resolvePresetName 返回 null → 保持当前动画。+ // 叠加映射到具体动画名(写代码/轻快记录/玩游戏气急败坏…)。const name = resolvePresetName(activity, pools, assets)+ // 会话状态(override/props 驱动)解析不到资产时不得静默保持当前动画——旧语义+ // 会让宠物永久卡在上一个循环上:细分工作档资产缺失的旧预设(e1ff8c1 资产差集+ // 前的安装)中,会话运行显示待机、拖拽结束后永远循环拖拽动画。改为降级链+ // (细分工作档 → 粗态写代码 → 待机池,见 fallbackPresetName);adHoc(点击+ // 回应/待机插播)缺失仍保持当前动画,避免把一次性风味动画错播成工作/待机动画。+ ?? (adHoc === null ? fallbackPresetName(activity, pools, assets) : null)if (name === null)return undefinedconst source = assets[name]diff --git a/src/pet/pet-config.test.ts b/src/pet/pet-config.test.tsindex 35ed2272..813bcb49 100644--- a/src/pet/pet-config.test.ts+++ b/src/pet/pet-config.test.ts@@ -1,6 +1,7 @@import type { PetCategory, PetWeights } from './pet-config'import { describe, expect, it, vi } from 'vitest'import {+ fallbackPresetName,isLoopingAnimation,pick,pickCategoryAction,@@ -190,3 +191,41 @@ describe('resolvePresetName', () => {expect(resolvePresetName('idle', { ...pools, idlePool: [] }, assets)).toBeNull()})})++describe('fallbackPresetName', () => {+ // 旧预设(e1ff8c1 资产差集前的安装):无 工作状态-*,但有待机与写代码。+ const stale: Record<string, string> = {+ 待机呼吸休闲: 'dsh-pet://localhost/maid-deepseek-whale/webm/idle.webm',+ 写代码: 'dsh-pet://localhost/maid-deepseek-whale/webm/code.webm',+ }+ const pools = { idlePool: ['待机呼吸休闲'] } as const++ it('降级细分工作档到粗态写代码(资产缺失时不再卡旧循环)', () => {+ vi.spyOn(Math, 'random').mockReturnValue(0.0)+ expect(fallbackPresetName('thinking', pools, stale)).toBe('写代码')+ expect(fallbackPresetName('working', pools, stale)).toBe('写代码')+ expect(fallbackPresetName('result', pools, stale)).toBe('写代码')+ expect(fallbackPresetName('waiting', pools, stale)).toBe('写代码')+ expect(fallbackPresetName('running', pools, stale)).toBe('写代码')+ vi.restoreAllMocks()+ })++ it('细分档资产存在时无需降级(fallback 只作 resolve 失败的后备)', () => {+ expect(fallbackPresetName('thinking', pools, { '待机呼吸休闲': 'idle.webm', '工作状态-思考冒泡': 'think.webm', '写代码': 'code.webm' })).toBe('写代码')+ })++ it('终态档/其他状态降到待机池', () => {+ vi.spyOn(Math, 'random').mockReturnValue(0.0)+ expect(fallbackPresetName('success', pools, stale)).toBe('待机呼吸休闲')+ expect(fallbackPresetName('error', pools, stale)).toBe('待机呼吸休闲')+ expect(fallbackPresetName('review', pools, stale)).toBe('待机呼吸休闲')+ expect(fallbackPresetName('failed', pools, stale)).toBe('待机呼吸休闲')+ expect(fallbackPresetName('bubble', pools, stale)).toBe('待机呼吸休闲')+ vi.restoreAllMocks()+ })++ it('待机池也无资产时返回 null(调用方保持当前动画)', () => {+ expect(fallbackPresetName('working', pools, {})).toBeNull()+ expect(fallbackPresetName('working', { idlePool: [] }, {})).toBeNull()+ })+})diff --git a/src/pet/pet-config.ts b/src/pet/pet-config.tsindex cdcfa91c..00cb841a 100644--- a/src/pet/pet-config.ts+++ b/src/pet/pet-config.ts@@ -166,7 +166,8 @@ export function poolEntryToStatus(entry: string): string {* 雀跃庆祝/垂头叹气冒汗,e1ff8c1 起的新预设资产)。* 2. 旧粗态兼容(无细分档的会话展示路径):running 写代码、review 轻快记录、* failed 玩游戏气急败坏、bubble 鲸鱼吐泡泡特效。- * 资产缺失时 resolvePresetName 仍返回 null(调用方保持当前动画,不做静默兜底)。+ * 资产缺失时 resolvePresetName 仍返回 null:会话状态(override/props 驱动)由调用方+ * 走 fallbackPresetName 降级(避免卡在旧循环),adHoc(点击回应/待机插播)保持当前动画。*/export const PRESET_SESSION_ANIMATIONS: Record<string, string> = {// 细分工作状态档位(workStatus)@@ -219,3 +220,37 @@ export function resolvePresetName(const name = pick(pool)return assets[name] !== undefined ? name : null}++/**+ * 会话状态解析不到资产时的降级动画名(与 resolvePresetName 的「保持当前动画」+ * 语义互补):resolve 失败若不切换,宠物会永久卡在上一个循环动画上 —— 典型故障+ * 是细分工作档(thinking/working/result/waiting)资产缺失的旧预设中,会话运行+ * 显示待机、拖拽结束后永远循环拖拽动画。+ *+ * 降级链:+ * 1. 细分工作档/粗态 running → 粗态「写代码」(旧预设普遍存在,保留「在干活」+ * 的观感,而非退回待机);+ * 2. 其余状态(终态档/待机链)→ 待机池兜底;+ * 3. 无可播资产时返回 null(调用方保持当前动画)。+ *+ * 仅用于会话状态(override/props 驱动);adHoc(点击回应/待机插播)缺失时+ * 仍保持当前动画 —— 一次性风味动画不应被错播成工作/待机动画。+ */+export function fallbackPresetName(+ activity: string,+ pools: { idlePool: readonly string[] },+ assets: Record<string, string>,+): string | null {+ if (activity === 'thinking' || activity === 'working'+ || activity === 'result' || activity === 'waiting' || activity === 'running') {+ const running = PRESET_SESSION_ANIMATIONS.running+ if (running !== undefined && assets[running] !== undefined)+ return running+ }+ if (pools.idlePool.length > 0) {+ const name = pick(pools.idlePool)+ if (assets[name] !== undefined)+ return name+ }+ return null+}