diff --git a/CHANGELOG.md b/CHANGELOG.md index 94996ccaa1..b25f3cce28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ WeChat original voice can be prepared for playback, native quotes and retained l ### Added +- Supported pixel Window Companions open and close their mouths as committed message text appears, pause at punctuation, and restore the saved face after completion, cancellation or backgrounding; roster portraits and image fallbacks keep their existing identity ([#1143](https://github.com/BotHarness/DeepSeekBot/issues/1143)). + - Window Companions follow archive and deletion independently of Bot mode, preserve image/unknown-version snapshot fallbacks, and support keyboard reading and controls. Keyboard menus receive focus after placement and return it to the invoking control when dismissed. Motion preference changes settle immediately; offscreen presentation and obsolete animations stop without restarting old messages ([#1142](https://github.com/BotHarness/DeepSeekBot/issues/1142)). - Window Companions recover a bounded set of unplayed eligible replies after a brief same-Host disconnect, retry temporarily closed streams, preserve reading progress and pause presentation while the page is hidden. Reopening a source starts with future replies; first selection and Client/Host restart never replay history ([#1141](https://github.com/BotHarness/DeepSeekBot/issues/1141)). diff --git a/CHANGELOG.zh.md b/CHANGELOG.zh.md index 97c846e3a2..d069608292 100644 --- a/CHANGELOG.zh.md +++ b/CHANGELOG.zh.md @@ -13,6 +13,8 @@ ### Added +- 支持的像素窗口伙伴会随着已提交消息逐字呈现而开合嘴,在标点处闭嘴,播放结束、取消或切到后台后恢复保存的表情;名册头像与图片降级保留原有形象([#1143](https://github.com/BotHarness/DeepSeekBot/issues/1143))。 + - 窗口伙伴独立于 Bot 模式跟随归档和删除,保留图片及未知版本快照回退,并支持键盘阅读与操作;键盘菜单在定位完成后接收焦点,关闭时将焦点交还原控件;动态效果偏好变化立即归位,离屏呈现和旧动画停止,不重播旧消息 ([#1142](https://github.com/BotHarness/DeepSeekBot/issues/1142)). - 窗口伙伴在同一 Host 的短暂断线后,有界恢复尚未播放且仍符合范围的回复,暂时关闭的消息流会重试,保留阅读进度;页面隐藏时暂停呈现。重新开启来源只播放后续消息,首次钉选及 Client/Host 重启不重播历史([#1141](https://github.com/BotHarness/DeepSeekBot/issues/1141))。 diff --git a/docs/architecture/botharness-architecture.en.md b/docs/architecture/botharness-architecture.en.md index 1319d29089..8d03268e40 100644 --- a/docs/architecture/botharness-architecture.en.md +++ b/docs/architecture/botharness-architecture.en.md @@ -592,3 +592,5 @@ The application-defined `WindowCompanions` collection owns Profile selection and The shared feed supplies the existing Client Activity store in place of its separate SSE. Slow consumers independently coalesce Activity and selection snapshots, bound queued output per Bot, and drain Bot queues in rotation. Capacity defaults to 3 layers/20 retained cards; layers span 1–10, retention 1–100, and layers never exceed retention. Each Bot's Host output queue, Client retained cards and reading-arrival queue are independently bounded by retention. Reading keeps at most twice retention before merging the latest arrivals on leave; existing text continues by whole graphemes. Views use basic bubble avoidance and viewport clamping, without a selection limit or automatic character folding. Removing one Bot releases only its playback; removing the last closes the shared stream. PixelFigure's public body/head structure omits the tile only for the companion surface; normal portraits keep their recipe and background. Per-Bot DM, Group and Activity-card switches are independent; message-kind switches intersect own-dm/shared/all-bot visibility. The Channel owner's `observeOutput` reads one canonical message and returns safe text, author, current membership and independent Human read eligibility. Feed qualifies the selected Bot and rechecks queued references on selection changes and before draining. Source/scope changes remove only newly ineligible shown and queued cards; a same-Host confirmation baseline preserves eligible content and reading progress, while newly enabled sources do not replay their disabled period. Source clicks refresh the owner roster when missing and check anchored timeline access before opening; failures are explained on the card. Cards identify the Channel, both Bot-DM participants and original-context read availability, without joining or marking read. Broad observation exposes only the selected Bot's output and does not expand general timeline or model capabilities. Same-Host EventSource reconnection uses `Last-Event-ID` to identify a process-local lease: at most 60 seconds and 128 detached leases, with canonical references bounded per Bot by retention. The Channel owner reads the latest placement through `outputCheckpoint` and returns each message position through `observeOutput`; first selection and newly enabled sources establish Host baselines, excluding delayed old notifications. Four source epochs fence offline source/scope changes; recovery rereads canonical body and current membership for continuously enabled eligible references. Recovery takes over admission atomically through repeated GET/POST handshakes; duplicate canonical references do not consume queue capacity. Selection confirmation precedes replay; Clients retain same-Host reading progress and deduplicate Channel/message identities. Expired leases, new generations and Client restart start future-only baselines, without full-history scans, durable message copies or read-position writes. Hidden pages cancel frame sampling and pause text/expiry time. Lifecycle expansion remains sequenced by specification [#1135](https://github.com/BotHarness/DeepSeekBot/issues/1135). The Companion Feed observes committed `bot-registry` notifications directly, independently of Bot mode, through one disposable subscription. Selected archives remain labelled and still; canonical pause/reactivation changes reset the bounded message references and source checkpoints. A process-local lifecycle token survives stream recovery and makes a coalesced archive/reactivation transition observable without creating durable identity state. Confirmed deletion sends removed IDs through the acknowledged shared snapshot; the collection releases only those children, preferences and cards, while stale revisions cannot restore them. Current owning attention facts remain navigation-only. Uploaded images keep their media and whole-object interaction; unsupported rig/schema versions retain the saved recipe and versioned snapshot with an explicit animation limitation. The image owner refuses an obsolete version URL instead of serving a different Avatar. Keyboard focus expands reading like hover, Context Menu/Shift+F10 opens native options, Escape returns focus, and card dismissal selects a surviving control. Effective reduced-motion changes settle immediately, offscreen/hidden stages stop sampling, and all observers, frames and morph/fade animations are cancelled on disposal; obsolete animation completions cannot enqueue fresh motion. Actual multi-Bot frame/memory/asset measurements and Human-agreed budgets remain required before performance acceptance. + +Supported pixel companions request the optional BotPixel `mouthLayers` contract with pre-rendered saved/closed/half-open/open groups; ordinary portraits and Host snapshots retain default output. `WindowCompanion` derives one mouth from existing safe-grapheme text progress, adding no speaking Activity, second message queue, timer or durable expression. The production Avatar requests these groups only for the companion surface. Its independent `AvatarSpeech` resource fades groups inside the same SVG without rebuilding the character or restarting gaze/blink/head animation. Speech temporarily reveals the face while outer Activity and attention remain truthful. Punctuation closes the mouth; completion, cancellation, archive, disconnect and disposal restore the saved expression. Shared reduced-motion, hidden and offscreen gates settle immediately. The first card still revealing text drives the single bounded mouth. Images and unsupported families/versions keep existing fallbacks, with no substituted parts. No TTS, phonemes, model action markup or private Tool data is needed ([#1143](https://github.com/BotHarness/DeepSeekBot/issues/1143)). diff --git a/docs/architecture/botharness-architecture.md b/docs/architecture/botharness-architecture.md index ac12542cae..8ebf29edfa 100644 --- a/docs/architecture/botharness-architecture.md +++ b/docs/architecture/botharness-architecture.md @@ -712,3 +712,5 @@ Client 独立的 `CompanionMotion` 拥有有界拖拽姿态、速度采样、连 选中伙伴时,共享 feed 同时供给现有 Client Activity store,替代其独立 Activity SSE。慢消费者分别合并 Activity 和选择快照,按 Bot 有界保留消息并轮流排出。容量默认层叠 3/保留 20,层数 1–10、保留 1–100 且层数不超过保留;每个 Bot 的 Host 待发队列、Client 保留卡片与阅读到达队列各受保留数量约束。阅读中最多两倍保留数量的卡片,离开时合并最新消息;已有文字按完整字素继续播放。View 做基本气泡避让与视口夹取,不设钉选数量上限或自动折叠人物。移除一个 Bot 只释放自身播放,最后一个移除后关闭共享流。透明半身使用 PixelFigure 公共 body/head 结构,仅伙伴 surface 去掉底板,普通头像配方与背景保持原样。每个 Bot 的 DM、群聊与 Activity 标签独立开关;消息开关与 own-dm/shared/all-bot 范围相交。Channel owner 的 `observeOutput` 单条规范查询返回安全正文、作者、当前成员关系与独立的 Human 读取判定,Feed 验证所选 Bot 后推送,队列在范围变化及排出时重新资格判断。来源或范围变化只移除不再符合条件的显示及排队卡片,同一 Host 的确认基线保留仍可见内容与阅读进度,新启用来源不回放禁用期;点击来源先按需刷新 owner 会话列表,再检查锚点 timeline 读取权限,失败在卡片解释。卡片标明 Channel、Bot DM 双方和原会话可读性,不自动加入或改变已读位置。宽范围仅新增所选 Bot 的输出观察,既有通用 timeline 和模型能力不扩权。同一 Host 的 EventSource 断线重连通过 `Last-Event-ID` 识别过程租约;最多保留 60 秒、128 个已断开的租约,每 Bot 的规范消息引用受保留数量约束。Channel owner 的 `outputCheckpoint` 读取最新 placement 位置,`observeOutput` 返回单条位置;首次选择及新开启来源建立 Host 基线,延迟的旧通知不能成为新消息。四类来源各有 Client 过程 epoch,离线开关或范围变更后只恢复连续启用且仍合格的引用;补播重新查询规范正文和成员关系。恢复 GET 原子接管持续收件,等待 POST 确认或握手再次中断时仍有界留存;重复规范引用不占用额外队列容量。订阅确认先于补播;Client 保留同 Host 的阅读进度,按 Channel/message 标识去重。租约或 generation 失效、Client 重启均开始未来基线;无全历史扫描、耐久消息副本或共享已读写入。页面隐藏取消帧采样并暂停文字和到期时间。生命周期扩展仍按规格 [#1135](https://github.com/BotHarness/DeepSeekBot/issues/1135) 交付。 Companion Feed 通过一条可释放的订阅直接观察已提交的 `bot-registry` 通知,独立于 Bot 模式。归档保留带标签的静止形象;规范的暂停/重新启用变化重置有界消息引用和来源检查点。过程生命周期标识随流恢复保留,让合并过的归档/重新启用变化仍可被 Client 识别,不新增耐久身份状态。确认删除通过已确认选择快照发送移除 ID;collection 只释放对应子项、偏好和卡片,旧 revision 不能恢复已删除项。当前 owner 的 attention 事实仅用于导航。上传图片保留原媒体与整体交互;不支持的 rig/schema 保留配方和带版本的保存快照,并明确说明动作限制。图片 owner 拒绝过期版本 URL,不以另一形象替换该版本。键盘焦点与 hover 同样展开阅读;菜单键/Shift+F10 打开原生菜单,Escape 返回焦点,关闭气泡选取存活控件。减少动态效果立即归位,离屏/隐藏停止采样,销毁释放 observer、帧及 morph/fade 动画;旧动画完成回调不能再排入动作。性能验收仍须真实多 Bot 帧、内存、资源测量及 Human 同意的预算。 + +支持的像素伙伴通过 BotPixel 的可选 `mouthLayers` 公共合约预绘制 saved/closed/half-open/open 四层,普通头像与 Host 保存快照保持默认输出。`WindowCompanion` 从既有安全字素播放进度派生一份嘴型,不引入说话 Activity、第二个消息队列、计时器或耐久表情状态。生产 Avatar 仅在 companion surface 请求这些层,独立 `AvatarSpeech` 资源在既有 SVG 内做短透明度过渡,不重建人物或重启眨眼/转头;说话时暂时显露脸部,外层 Activity 和 attention 仍反映真实事实。标点闭嘴,播放结束、取消、归档、断线及销毁恢复保存表情;减少动态效果、隐藏与离屏由现有共享策略立即归静。多卡片选择第一条仍在逐字呈现的卡片驱动一套有界嘴型。上传图片、不支持的 family/版本保留原有降级,不拼接替代部件。该呈现不需要 TTS、音素、模型动作标记或 Tool 私有内容([#1143](https://github.com/BotHarness/DeepSeekBot/issues/1143))。 diff --git a/packages/client/src/client/avatar-speech.tsx b/packages/client/src/client/avatar-speech.tsx new file mode 100644 index 0000000000..8e0b8933c9 --- /dev/null +++ b/packages/client/src/client/avatar-speech.tsx @@ -0,0 +1,93 @@ +import { useRef, type ReactElement } from 'react'; +import type { PixelMouthState } from '../../../core/src/bots/avatar-appearance.js'; +import { useMountedResource } from './mounted-resource.js'; + +export function AvatarSpeech({ + markup, + mouth, + still, +}: { + markup: string; + mouth: PixelMouthState; + still: boolean; +}): ReactElement { + const visible = useRef(true); + const mount = useMountedResource( + (marker) => { + const root = marker.previousElementSibling; + if (!(root instanceof HTMLElement)) return; + const layers = [...root.querySelectorAll('[data-avatar-mouth]')]; + const cover = root.querySelector('[data-avatar-pixel-morph]'); + const svg = cover?.ownerSVGElement; + if (cover) layers.push(cover); + const animations = new Map(); + let active = true; + const cancel = () => { + for (const [layer, animation] of animations) { + layer.style.opacity = getComputedStyle(layer).opacity; + animation.cancel(); + } + animations.clear(); + }; + const sync = () => { + if (!active) return; + const moving = + !still && + visible.current && + !document.hidden && + document.documentElement.dataset['botharnessMotion'] !== 'reduce' && + document.documentElement.dataset['botharnessActivity'] !== 'stale'; + const state = moving ? mouth : 'saved'; + cancel(); + root.dataset['avatarMouthState'] = state; + svg?.toggleAttribute('data-avatar-speaking', state !== 'saved'); + for (const layer of layers) { + const from = getComputedStyle(layer).opacity || layer.getAttribute('opacity') || '0'; + const to = (layer === cover ? state === 'saved' : layer.dataset['avatarMouth'] === state) + ? '1' + : '0'; + layer.style.opacity = to; + if (moving && from !== to && typeof layer.animate === 'function') { + const animation = layer.animate([{ opacity: from }, { opacity: to }], { + duration: 80, + easing: 'ease-out', + }); + animations.set(layer, animation); + void animation.finished + .then(() => { + if (animations.get(layer) === animation) animations.delete(layer); + }) + .catch(() => undefined); + } + } + }; + const observer = + typeof IntersectionObserver === 'undefined' + ? undefined + : new IntersectionObserver((entries) => { + if (!active) return; + const next = entries.some((entry) => entry.isIntersecting); + if (next === visible.current) return; + visible.current = next; + sync(); + }); + observer?.observe(root); + const motion = new MutationObserver(sync); + motion.observe(document.documentElement, { + attributes: true, + attributeFilter: ['data-botharness-motion', 'data-botharness-activity'], + }); + document.addEventListener('visibilitychange', sync); + sync(); + return () => { + active = false; + cancel(); + observer?.disconnect(); + motion.disconnect(); + document.removeEventListener('visibilitychange', sync); + }; + }, + [markup, mouth, still], + ); + return