Open-source, local-first AI agent for real work.
TypeScript agent-toolsai-agentbyokcoding-agentcross-platformdesktop-appdeveloper-toolselectronharnessknowledge-basellmwikilocal-firstmcpplugin-systemprivacy-firstskillstypescriptvettaworkflow-automation
feat(new-session): Vivi 装饰件改为静态图,去掉动画与隐藏箭头
bent2685e406f596df2b
diff --git a/apps/desktop/src/renderer/domains/conversation/components/new-session/ornament/presets/ViviOrnament.test.tsx b/apps/desktop/src/renderer/domains/conversation/components/new-session/ornament/presets/ViviOrnament.test.tsxindex 452d41a27..d0e623cbc 100644--- a/apps/desktop/src/renderer/domains/conversation/components/new-session/ornament/presets/ViviOrnament.test.tsx+++ b/apps/desktop/src/renderer/domains/conversation/components/new-session/ornament/presets/ViviOrnament.test.tsx@@ -1,14 +1,10 @@// @vitest-environment jsdom/*** Vivi 装饰件按插槽(hero 宽度)决定是否渲染:页面被压窄时(窗口小、活动面板/侧边栏展开)- * 素材右锚会压到选项行与标题上,这时整块 Vivi连同显隐按钮都不该出现。+ * 素材右锚会压到选项行与标题上,这时整块 Vivi 都不该出现。*/import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-vi.mock("react-i18next", () => ({- useTranslation: () => ({ t: (key: string) => key }),-}));-import { act, render, screen } from "@testing-library/react";import { ORNAMENT_MIN_SLOT_WIDTH } from "../../constants";import { ViviOrnament } from "./ViviOrnament";@@ -49,27 +45,29 @@ afterEach(() => {});describe("ViviOrnament", () => {- it("插槽够宽时渲染 Vivi 与显隐按钮", () => {+ it("插槽够宽时渲染 Vivi 静态图,没有显隐按钮", () => {slotWidth = ORNAMENT_MIN_SLOT_WIDTH;render(<ViviOrnament autoplay={false} mounted />);- expect(screen.getByRole("button", { name: "newSession.mascot.hideMascot" })).toBeTruthy();+ expect(screen.getByTestId("vivi-ornament")).toBeTruthy();+ expect(screen.queryByRole("button")).toBeNull();+ expect(document.querySelector("video")).toBeNull();});it("插槽过窄时整块 Vivi不渲染", () => {slotWidth = ORNAMENT_MIN_SLOT_WIDTH - 1;render(<ViviOrnament autoplay={false} mounted />);- expect(screen.queryByRole("button", { name: "newSession.mascot.hideMascot" })).toBeNull();+ expect(screen.queryByTestId("vivi-ornament")).toBeNull();});it("插槽被压窄后收起、变宽后恢复", () => {render(<ViviOrnament autoplay={false} mounted />);resizeSlot(ORNAMENT_MIN_SLOT_WIDTH - 40);- expect(screen.queryByRole("button", { name: "newSession.mascot.hideMascot" })).toBeNull();+ expect(screen.queryByTestId("vivi-ornament")).toBeNull();resizeSlot(ORNAMENT_MIN_SLOT_WIDTH + 40);- expect(screen.getByRole("button", { name: "newSession.mascot.hideMascot" })).toBeTruthy();+ expect(screen.getByTestId("vivi-ornament")).toBeTruthy();});});diff --git a/apps/desktop/src/renderer/domains/conversation/components/new-session/ornament/presets/ViviOrnament.tsx b/apps/desktop/src/renderer/domains/conversation/components/new-session/ornament/presets/ViviOrnament.tsxindex 520926e70..84698265f 100644--- a/apps/desktop/src/renderer/domains/conversation/components/new-session/ornament/presets/ViviOrnament.tsx+++ b/apps/desktop/src/renderer/domains/conversation/components/new-session/ornament/presets/ViviOrnament.tsx@@ -1,255 +1,40 @@-import { Button } from "@shared/components/ui/button";-import { cn } from "@shared/lib/utils";-import { motion, useMotionValue, useReducedMotion } from "motion/react";-import type { SyntheticEvent } from "react";-import { useCallback, useEffect, useRef, useState } from "react";-import { useTranslation } from "react-i18next";+import { motion } from "motion/react";+import type { OrnamentProps } from "../ornament-registry";import { useOrnamentSlot } from "../useOrnamentSlot";-const FERRET_VIDEO_SOURCES = {- blink: "./new-session/ferret-blink.webm",- crawl: "./new-session/ferret-crawl.webm",- wave: "./new-session/ferret-wave.webm",-} as const;-const VIVI_ACTIONS = ["blink", "wave", "crawl"] as const;-const CRAWL_DURATION_SECONDS = 10.066;-const CRAWL_START_PAUSE_SECONDS = 3;-const CENTER_POSITION = "calc(50% - 4.5rem)";-const RIGHT_POSITION = "calc(100% - 9rem)";-const VIVI_VISIBLE_STORAGE_KEY = "vetta-new-session-mascot-visible";-const HOUR_IN_MILLISECONDS = 60 * 60 * 1_000;-const MINIMUM_ACTION_INTERVAL = HOUR_IN_MILLISECONDS;-const MAXIMUM_ACTION_INTERVAL = HOUR_IN_MILLISECONDS * 3;+const VIVI_IMAGE_URL = "./new-session/vivi.webp";-type ViviAction = (typeof VIVI_ACTIONS)[number];--interface ViviOrnamentProps {- autoplay: boolean;- mounted: boolean;-}--export function ViviOrnament({ autoplay, mounted }: ViviOrnamentProps): JSX.Element {- const { t } = useTranslation("chat");- const reduceMotion = useReducedMotion();- const [action, setAction] = useState<ViviAction>(() => pickRandomAction());- const [viviVisible, setViviVisible] = useState(readViviVisible);- const [playing, setPlaying] = useState(false);- // 页面被压窄(窗口小、活动面板/侧边栏展开)时插槽放不下素材,整块 Vivi连同显隐按钮一起不渲染。+/**+ * Vivi:一张静态图,趴在输入框顶边上,前爪和尾巴垂过边沿。+ *+ * 不再播动画、也不给隐藏按钮:不想要就在「设置 - 外观 - 装饰件」里选「无」。+ */+export function ViviOrnament({ mounted }: OrnamentProps): JSX.Element {+ // 页面被压窄(窗口小、活动面板/侧边栏展开)时插槽放不下素材,整块 Vivi 不渲染。const slot = useOrnamentSlot();- const handleComplete = useCallback(() => {- setAction((current) => pickRandomAction(current));- setPlaying(false);- }, []);- const handlePlayOnce = useCallback(() => {- setPlaying(true);- }, []);-- useEffect(() => {- if (!slot.visible || !viviVisible || !autoplay || reduceMotion || playing) return;-- const timer = window.setTimeout(() => {- setPlaying(true);- }, randomActionInterval());-- return () => window.clearTimeout(timer);- }, [autoplay, viviVisible, playing, reduceMotion, slot.visible]);-- const handleVisibilityToggle = useCallback(() => {- setViviVisible((current) => {- const next = !current;- window.localStorage.setItem(VIVI_VISIBLE_STORAGE_KEY, String(next));- return next;- });- setPlaying(false);- }, []);-- const canPlay = slot.visible && viviVisible && autoplay && !reduceMotion;- const actionPlaying = canPlay && playing;-return (<motion.divinitial={{ opacity: 0 }}animate={{ opacity: mounted ? 1 : 0 }}transition={{ duration: 0.5, delay: 0.2 }}// 锚在 hero 根节点上、往下越过「hero mb-3(12) + 选项行 h-7(28) + 行 mb-4(16)」共 56px,- // 再往下 19px:素材自带底部留白,这个量让爪子底缘刚好碰到输入框顶边、不进框 → 75px。- // 选项行尺寸变了要同步这里。+ // 再往下 19px 到容器底 → 75px。选项行尺寸变了要同步这里。className="pointer-events-none absolute inset-x-0 -bottom-[75px] z-30 h-20 select-none"ref={slot.ref}>- {/* 插槽放不下素材时整块 Vivi(含显隐按钮)不渲染,容器仍在,变宽后自动恢复。 */}{slot.visible ? (- <>- <Button- aria-label={t(- viviVisible ? "newSession.mascot.hideMascot" : "newSession.mascot.showMascot",- )}- className={cn(- "no-drag pointer-events-auto absolute right-2 z-20 rounded-md border border-border/40 bg-background/80 text-muted-foreground backdrop-blur-sm transition-[top] duration-200",- viviVisible ? "-top-5" : "top-11",- )}- onClick={handleVisibilityToggle}- size="icon-xs"- variant="ghost"- >- <span- aria-hidden- className={cn(- "icon-[solar--alt-arrow-down-linear] h-3 w-3 transition-transform duration-200",- viviVisible && "rotate-180",- )}- />- </Button>-- {!viviVisible ? null : actionPlaying ? (- action === "crawl" ? (- <CrawlPass onComplete={handleComplete} />- ) : (- <video- aria-hidden="true"- autoPlay- className="pointer-events-none absolute right-0 -bottom-6 h-36 w-36 object-contain object-center"- draggable={false}- muted- onEnded={handleComplete}- playsInline- preload="auto"- src={FERRET_VIDEO_SOURCES[action]}- />- )- ) : (- <>- <video- aria-hidden="true"- // 三个素材首帧的地线实测一致(底部留白 169/576 ≈ 渲染后 42px),- // 统一偏移:容器底在输入框顶下 19px(容器 -bottom-[75px] − 56px 行高),- // 42-19≈23px → -bottom-6 时爪子刚好贴边。按动作分档会让随机初始动作- // 在「悬空/进框」之间跳。- className="pointer-events-none absolute right-0 -bottom-6 h-36 w-36 object-contain object-center"- draggable={false}- muted- playsInline- preload="auto"- src={FERRET_VIDEO_SOURCES[action]}- />- {canPlay ? (- <Button- aria-label={t("newSession.mascot.playOnce")}- className={cn(- "no-drag pointer-events-auto absolute right-0 z-10 h-20 w-36 bg-transparent p-0 hover:bg-transparent",- "-bottom-1",- )}- onClick={handlePlayOnce}- variant="ghost"- >- <span className="sr-only">{t("newSession.mascot.playOnce")}</span>- </Button>- ) : null}- </>- )}- </>+ <img+ alt=""+ // 图宽 128px 时高约 72px,身体底缘在顶下约 42px:图底再往下 11px,+ // 身体底缘正好落在输入框顶边(容器底之上 19px),爪子和尾巴垂进框里。+ // 离右缘留 32px,不贴着输入框右角。+ className="pointer-events-none absolute right-8 -bottom-[11px] h-auto w-32"+ data-testid="vivi-ornament"+ draggable={false}+ src={VIVI_IMAGE_URL}+ />) : null}</motion.div>);}--interface CrawlPassProps {- onComplete: () => void;-}--function CrawlPass({ onComplete }: CrawlPassProps): JSX.Element {- const [returning, setReturning] = useState(false);- const returningRef = useRef(false);- const videoRef = useRef<HTMLVideoElement>(null);- const animationFrameRef = useRef<number | null>(null);- const left = useMotionValue(RIGHT_POSITION);-- const updatePosition = useCallback(() => {- const video = videoRef.current;- if (!video) return;-- const duration = Number.isFinite(video.duration) ? video.duration : CRAWL_DURATION_SECONDS;- const moveProgress = Math.min(- 1,- Math.max(0, (video.currentTime - CRAWL_START_PAUSE_SECONDS) / (duration - CRAWL_START_PAUSE_SECONDS)),- );- const rightness = returningRef.current ? moveProgress : 1 - moveProgress;- left.set(positionForRightness(rightness));-- if (!video.paused && !video.ended) {- animationFrameRef.current = window.requestAnimationFrame(updatePosition);- }- }, [left]);-- const startTracking = useCallback(() => {- if (animationFrameRef.current !== null) {- window.cancelAnimationFrame(animationFrameRef.current);- }- animationFrameRef.current = window.requestAnimationFrame(updatePosition);- }, [updatePosition]);-- useEffect(- () => () => {- if (animationFrameRef.current !== null) {- window.cancelAnimationFrame(animationFrameRef.current);- }- },- [],- );-- const handleEnded = useCallback(- (event: SyntheticEvent<HTMLVideoElement>) => {- left.set(returningRef.current ? RIGHT_POSITION : CENTER_POSITION);- if (returningRef.current) {- onComplete();- return;- }- returningRef.current = true;- setReturning(true);- event.currentTarget.currentTime = 0;- void event.currentTarget.play();- },- [left, onComplete],- );-- return (- <motion.video- aria-hidden="true"- autoPlay- // 爬行素材腿部伸展时地线更低(最深帧底部留白 ≈31.5px,静止帧 ≈42px)。- // 用最深帧对齐输入框顶边(19+12=31),走动全程不进框;起步略悬空是有意取舍。- className="pointer-events-none absolute -bottom-3 h-36 w-36 object-contain object-center"- draggable={false}- muted- onEnded={handleEnded}- onPlaying={startTracking}- playsInline- preload="auto"- ref={videoRef}- src={FERRET_VIDEO_SOURCES.crawl}- style={{ left, scaleX: returning ? -1 : 1 }}- />- );-}--function pickRandomAction(current?: ViviAction): ViviAction {- const candidates = current- ? VIVI_ACTIONS.filter((candidate) => candidate !== current)- : VIVI_ACTIONS;- return candidates[Math.floor(Math.random() * candidates.length)];-}--function randomActionInterval(): number {- return MINIMUM_ACTION_INTERVAL + Math.random() * (MAXIMUM_ACTION_INTERVAL - MINIMUM_ACTION_INTERVAL);-}--function readViviVisible(): boolean {- return window.localStorage.getItem(VIVI_VISIBLE_STORAGE_KEY) !== "false";-}--function positionForRightness(rightness: number): string {- const percentage = 50 + rightness * 50;- const widthOffsetRem = 4.5 + rightness * 4.5;- return `calc(${percentage}% - ${widthOffsetRem}rem)`;-}diff --git a/apps/desktop/src/renderer/public/new-session/ferret-blink.webm b/apps/desktop/src/renderer/public/new-session/ferret-blink.webmdeleted file mode 100644index 9e2edf39a..000000000Binary files a/apps/desktop/src/renderer/public/new-session/ferret-blink.webm and /dev/null differdiff --git a/apps/desktop/src/renderer/public/new-session/ferret-crawl.webm b/apps/desktop/src/renderer/public/new-session/ferret-crawl.webmdeleted file mode 100644index e992e8d62..000000000Binary files a/apps/desktop/src/renderer/public/new-session/ferret-crawl.webm and /dev/null differdiff --git a/apps/desktop/src/renderer/public/new-session/ferret-wave.webm b/apps/desktop/src/renderer/public/new-session/ferret-wave.webmdeleted file mode 100644index 7ce0a1829..000000000Binary files a/apps/desktop/src/renderer/public/new-session/ferret-wave.webm and /dev/null differdiff --git a/apps/desktop/src/renderer/public/new-session/ferret.webp b/apps/desktop/src/renderer/public/new-session/ferret.webpdeleted file mode 100644index eb3d20732..000000000Binary files a/apps/desktop/src/renderer/public/new-session/ferret.webp and /dev/null differdiff --git a/apps/desktop/src/renderer/public/new-session/vivi.webp b/apps/desktop/src/renderer/public/new-session/vivi.webpnew file mode 100644index 000000000..7bf9c82f5Binary files /dev/null and b/apps/desktop/src/renderer/public/new-session/vivi.webp differdiff --git a/apps/desktop/src/renderer/shared/theme/ornament.ts b/apps/desktop/src/renderer/shared/theme/ornament.tsindex 0723c8127..a140a50cb 100644--- a/apps/desktop/src/renderer/shared/theme/ornament.ts+++ b/apps/desktop/src/renderer/shared/theme/ornament.ts@@ -28,8 +28,8 @@ export interface OrnamentCatalogEntry {readonly preview?: string;}-/** Vivi 静帧:与动画素材同目录,走 public 相对路径。 */-const VIVI_PREVIEW_URL = "./new-session/ferret.webp";+/** Vivi 静态图:与新会话页用的是同一张,走 public 相对路径。 */+const VIVI_PREVIEW_URL = "./new-session/vivi.webp";/*** 装饰件目录:新增装饰件只要在这里加一项,再在 ornament-registry 里挂上组件。diff --git a/apps/desktop/src/shared/i18n/locales/en/chat.json b/apps/desktop/src/shared/i18n/locales/en/chat.jsonindex fb157d19e..fdd5dd589 100644--- a/apps/desktop/src/shared/i18n/locales/en/chat.json+++ b/apps/desktop/src/shared/i18n/locales/en/chat.json@@ -930,12 +930,6 @@"defaultContext": "General conversation","teamNewWorkspaceContext": "New workspace","projectContext": "Project · {{name}}",- "mascot": {- "menuTrigger": "Mascot settings",- "hideMascot": "Hide mascot",- "showMascot": "Show mascot",- "playOnce": "Play the current mascot animation once"- },"mario": {"hit": "Bump out the mushroom","reset": "Put the mushroom back"diff --git a/apps/desktop/src/shared/i18n/locales/en/settings.json b/apps/desktop/src/shared/i18n/locales/en/settings.jsonindex 5082d90f1..3f54da226 100644--- a/apps/desktop/src/shared/i18n/locales/en/settings.json+++ b/apps/desktop/src/shared/i18n/locales/en/settings.json@@ -1290,7 +1290,7 @@"ornamentNoneTitle": "None","ornamentNoneHint": "Leave the spot empty for a cleaner page.","ornamentViviTitle": "Vivi",- "ornamentViviHint": "Vetta's stoat Vivi — blinks, waves and crawls across the composer now and then.",+ "ornamentViviHint": "Vetta's stoat Vivi, lying on top of the composer with its paws and tail hanging over the edge.","ornamentMarioTitle": "Mario","ornamentMarioHint": "A row of pixel blocks — bump the question block to pop a mushroom out of it.","section_appearance-texture": "Texture",diff --git a/apps/desktop/src/shared/i18n/locales/zh/chat.json b/apps/desktop/src/shared/i18n/locales/zh/chat.jsonindex 2716b3865..28e505402 100644--- a/apps/desktop/src/shared/i18n/locales/zh/chat.json+++ b/apps/desktop/src/shared/i18n/locales/zh/chat.json@@ -930,12 +930,6 @@"defaultContext": "普通会话","teamNewWorkspaceContext": "新工作空间","projectContext": "项目 · {{name}}",- "mascot": {- "menuTrigger": "吉祥物设置",- "hideMascot": "关闭吉祥物",- "showMascot": "显示吉祥物",- "playOnce": "播放一次当前吉祥物动画"- },"mario": {"hit": "顶出蘑菇","reset": "把蘑菇收回砖块"diff --git a/apps/desktop/src/shared/i18n/locales/zh/settings.json b/apps/desktop/src/shared/i18n/locales/zh/settings.jsonindex 7be454782..89c159415 100644--- a/apps/desktop/src/shared/i18n/locales/zh/settings.json+++ b/apps/desktop/src/shared/i18n/locales/zh/settings.json@@ -1290,7 +1290,7 @@"ornamentNoneTitle": "无","ornamentNoneHint": "空着这块位置,页面更清爽。","ornamentViviTitle": "Vivi",- "ornamentViviHint": "Vetta 的白鼬 Vivi,会不时眨眼、挥手、从输入框上爬过。",+ "ornamentViviHint": "Vetta 的白鼬 Vivi,趴在输入框顶边上,爪子和尾巴垂过边沿。","ornamentMarioTitle": "马里奥","ornamentMarioHint": "一排像素砖块,顶一下中间的问号砖块会蹦出蘑菇。","section_appearance-texture": "纹理",