@linxin666/dsh-pet 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +46 -6
- package/README.zh.md +46 -6
- package/lib/client.js +244 -47
- package/lib/client.js.map +1 -1
- package/lib/index.js +287 -28
- package/lib/types/announce.d.ts +16 -0
- package/lib/types/announce.d.ts.map +1 -1
- package/lib/types/announce.js +16 -0
- package/lib/types/client/PetDockEntry.d.ts +6 -0
- package/lib/types/client/PetDockEntry.d.ts.map +1 -1
- package/lib/types/client/PetDockEntry.js +1 -1
- package/lib/types/client/PetSettingsCard.d.ts +4 -0
- package/lib/types/client/PetSettingsCard.d.ts.map +1 -1
- package/lib/types/client/PetSettingsCard.js +16 -1
- package/lib/types/client/PetSprite.d.ts +7 -0
- package/lib/types/client/PetSprite.d.ts.map +1 -1
- package/lib/types/client/PetSprite.js +23 -13
- package/lib/types/client/index.d.ts +2 -0
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/index.js +224 -28
- package/lib/types/client/locales.d.ts +4 -0
- package/lib/types/client/locales.d.ts.map +1 -1
- package/lib/types/client/locales.js +4 -0
- package/lib/types/index.d.ts +14 -3
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +32 -3
- package/lib/types/panel-actions.d.ts +96 -0
- package/lib/types/panel-actions.d.ts.map +1 -0
- package/lib/types/panel-actions.js +134 -0
- package/lib/types/routes.d.ts.map +1 -1
- package/lib/types/routes.js +10 -0
- package/lib/types/service.d.ts +137 -9
- package/lib/types/service.d.ts.map +1 -1
- package/lib/types/service.js +163 -21
- package/package.json +1 -1
- package/src/announce.ts +17 -0
- package/src/client/PetDockEntry.test.tsx +1 -0
- package/src/client/PetDockEntry.tsx +7 -0
- package/src/client/PetSettingsCard.test.tsx +88 -0
- package/src/client/PetSettingsCard.tsx +31 -0
- package/src/client/PetSprite.test.tsx +197 -0
- package/src/client/PetSprite.tsx +56 -12
- package/src/client/index.test.tsx +152 -4
- package/src/client/index.ts +228 -29
- package/src/client/locales.ts +4 -0
- package/src/index.test.ts +22 -0
- package/src/index.ts +45 -3
- package/src/panel-actions.test.ts +130 -0
- package/src/panel-actions.ts +182 -0
- package/src/registry.test.ts +11 -1
- package/src/routes.ts +9 -0
- package/src/service.test.ts +128 -0
- package/src/service.ts +218 -24
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# node scripts/verify-docs.mjs --write <dir>
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 6167cf9133204ac9c9df28ee08b5b1c722f440bf
|
|
6
|
+
README.zh.md: d7238f47aa9d1de79ccdd87b9e0cea24b381a9f0
|
package/README.md
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
# dsh-pet
|
|
1
|
+
# dsh-pet · Desktop Pet Companion & Interactive Live2D Widget for DeepSeek Harness (DSH)
|
|
2
2
|
|
|
3
3
|
English | [中文](README.zh.md)
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="https://img.shields.io/npm/v/@linxin666/dsh-client-ui-pet?style=flat-square" alt="Version">
|
|
7
|
+
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.0--rc.2-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
|
+
|
|
10
|
+
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
|
+
</p>
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
<p align="center">
|
|
14
|
+
<strong>Interactive Desktop Pet Companion & Live2D Widget for DeepSeek Harness (DSH)</strong><br>
|
|
15
|
+
<em>Agent State Tracking · Live2D & Sprite Pets · Interactive Feeding · Status Bubbles · DSH Workshop</em>
|
|
16
|
+
</p>
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
> A registry-driven desktop companion for DeepSeek Harness — featuring the built-in anime whale girl plus one-click installs for any custom Live2D or sprite pet from the Workshop.
|
|
19
|
+
|
|
20
|
+
While the AI model thinks, you wait — your desktop companion swims and interacts on screen. It dynamically tracks the official DeepSeek Harness session lifecycle, switching fluid animations during waiting, thinking, tool execution (Bash, code editing, web searches), reply generation, celebration on success, and alert on error; you can pat its head, feed it dried fish, and watch affinity grow. Pets are driven by an extensible asset registry rather than hard-coded logic: each pet consists of a `pet.json` manifest and an atlas image (or Live2D model pack), auto-discovered by the host at startup.
|
|
21
|
+
|
|
22
|
+
Re-engineered from desktop companion concepts into an official DSH cordis bundle (host backend + client frontend in a single integrated package).
|
|
10
23
|
|
|
11
24
|
## Features
|
|
12
25
|
|
|
@@ -23,10 +36,11 @@ Re-implemented from the pet feature of the Codex desktop app, as an official DSH
|
|
|
23
36
|
| Dragging | Hold and drag the pet to reposition; position persisted |
|
|
24
37
|
| Hide/Summon | The hover panel sits below the pet (lifted above the status bubbles when there is no room below) and provides 隐藏 (Hide); after hiding, a 召唤{name} (Summon {name}) button appears |
|
|
25
38
|
| Witty remarks | Built-in remark library (10 lines per event) plus per-pet custom lines; success lines rotate by persisted success counts and cooldown lines by persisted rejection counts |
|
|
26
|
-
| Status bubbles | Only one top-level session speaks by default — the session the GUI is currently on when it is reported, otherwise the most recently active one — and the rest collapse behind a +N badge on the main bubble instead of stacking a tall column; hover the bubble (or tap the badge, for touch) to fan every session's bubble out above it and click one to jump to its session; subagent sessions report through their spawning conversation and never occupy a bubble of their own; transient interaction feedback temporarily takes priority. Bubble copy comes from generous rotating pools per scene (waiting / thinking / writing / done / failed...), tool calls map onto per-family witty lines carrying the real argument hint (e.g. 跑跑 npm test), and a long-lived scene re-phrases itself every few seconds |
|
|
39
|
+
| Status bubbles | Only one top-level session speaks by default — the session the GUI is currently on when it is reported, otherwise the most recently active one — and the rest collapse behind a +N badge on the main bubble instead of stacking a tall column; hover the bubble (or tap the badge, for touch) to fan every session's bubble out above it and click one to jump to its session; subagent sessions report through their spawning conversation and never occupy a bubble of their own; transient interaction feedback temporarily takes priority. Bubble copy comes from generous rotating pools per scene (waiting / thinking / writing / done / failed...), tool calls map onto per-family witty lines carrying the real argument hint (e.g. 跑跑 npm test), and a long-lived scene re-phrases itself every few seconds. The pet's own status bubbles can be silenced in Settings > Pet > Status bubbles, which leaves the row to a plugin driving its own bubble surface; announcements pushed through `pet.announce` keep rendering either way |
|
|
27
40
|
| Inner whispers | 碎碎念: while a session streams, the pet occasionally speaks its inner voice through that session's own bubble — a fresh whisper takes over the bubble and marks it with 「」 quotes — sharing the same DeepSeek-blue glass as every status bubble, so stacked bubbles never clash — instead of stacking a second bubble — category lines woken by the SITUATION (thinking / writing / the running tool family) plus outcome lines woken only by structured results (test green from a passed test tool, error from a failed tool result, completion from a completed turn) — never from the model's words, so a discussion that merely mentions a keyword cannot wake a mood, and a whisper never quotes real content (no tool names, paths or model text); paced by cooldowns (9 s category, 5 s outcome) and an 8 s display TTL, the status copy returns after a few seconds |
|
|
28
41
|
| Multi-session activity | The pet is host-global: the most recent meaningful event drives the sprite animation while every active top-level session reports its own state in a separate bubble; completed turns from every session (subagents included) contribute affinity and treats |
|
|
29
42
|
| Voice packs and panel DIY | A per-pet voice.json plus the global $DSH_HOME/pets/.voice.json override replace every bubble word and the hover panel (button labels, stat formats, button visibility); merge precedence per-pet > global > built-in, broken packs warn and never reject a pet |
|
|
43
|
+
| Plugin panel actions | A sibling plugin registers its own action into the hover panel's action row through the in-process pet service (`ctx.pet.registerPanelAction({ id, label, onSelect })`); the pet renders the button and dispatches the click back to the plugin's own callback, and the action goes away with the registration |
|
|
30
44
|
|
|
31
45
|
## Pet contract
|
|
32
46
|
|
|
@@ -200,7 +214,32 @@ A status bubble can carry a small ornament ahead of its text (built-in: the spou
|
|
|
200
214
|
- Switch: Settings > Pet > Status decoration (on by default). The built-in whale derives from the DeepSeek wordmark (MIT); see THIRD_PARTY_NOTICES.md.
|
|
201
215
|
## Announcement bubbles (pet.announce)
|
|
202
216
|
|
|
203
|
-
Host-side sibling plugins can push one structured announcement through the `pet` cordis service (`ctx.pet.announce({ source, kind, title, ... })`); the browser half renders it as a dedicated, specially styled bubble riding the top of the session bubble stack — its own glass style with a tone accent (`ok`/`warn`/`low`), an amount pill for balance or today-spend kinds, a mini meter for plan-percent windows, and the reset instant. The payload is validated into a bounded shape (src/announce.ts): unknown fields drop, text truncates, TTL clamps to 1 s - 2 h (default 10 s; a repeating announcer declares its poll cadence so an always-mode bubble stays continuous, and the ceiling still unmounts a dead source's bubble within one missed refresh), and a malformed announcement is dropped silently. Announcements are in-memory only:
|
|
217
|
+
Host-side sibling plugins can push one structured announcement through the `pet` cordis service (`ctx.pet.announce({ source, kind, title, ... })`); the browser half renders it as a dedicated, specially styled bubble riding the top of the session bubble stack — its own glass style with a tone accent (`ok`/`warn`/`low`), an amount pill for balance or today-spend kinds, a mini meter for plan-percent windows, and the reset instant. The payload is validated into a bounded shape (src/announce.ts): unknown fields drop, text truncates, TTL clamps to 1 s - 2 h (default 10 s; a repeating announcer declares its poll cadence so an always-mode bubble stays continuous, and the ceiling still unmounts a dead source's bubble within one missed refresh), and a malformed announcement is dropped silently. Announcements are in-memory only: each publisher holds its own slot keyed by `source`, an expired one stops rendering, and neither pet.json nor the ledger is touched. There is deliberately no HTTP surface — the API is the in-process service, per the cross-plugin collaboration rule.
|
|
218
|
+
|
|
219
|
+
**Several publishers on one pet.** The contract started with a single slot, so a second announcing plugin displaced the first; `source` is now the slot key — the payload already carried it — and each publisher keeps its own TTL. Every fresh slot renders as its own bubble, stacked above the session bubbles in the order each publisher first arrived: a repeating publisher refreshes its own bubble in place, so two publishers on different cadences never swap positions and the stack never flickers. The table is bounded (`MAX_ANNOUNCEMENTS`, 4). A lapsed publisher frees its own slot; a genuinely full table hands its oldest slot to the arriving publisher rather than refusing it, so a publisher that keeps refreshing is never the one evicted. For a rolling upgrade the freshest slot is also served under the original singular `announcement` field, so a browser half predating the array keeps rendering one bubble instead of none.
|
|
220
|
+
|
|
221
|
+
## Plugin panel actions (pet.registerPanelAction)
|
|
222
|
+
|
|
223
|
+
Host-side sibling plugins can add their own button to the pet's hover panel action row, next to the built-in Feed / Rename / Hide:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
ctx.effect(() => ctx.pet.registerPanelAction({
|
|
227
|
+
id: 'pet-quota-swap', // kebab id; a click dispatches back on it
|
|
228
|
+
label: '换装', // bounded label (the row wraps past it)
|
|
229
|
+
title: '切换到下一只宠物', // optional tooltip
|
|
230
|
+
order: 0, // optional sort key within the registered block
|
|
231
|
+
onSelect: async ({ petId }) => { /* the plugin does the work */ },
|
|
232
|
+
}))
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
- The pet owns the row and the plugin owns the button: the host validates every registration (src/panel-actions.ts), serves the registered actions in the state snapshot (`panelActions`), and dispatches a click from `POST /api/pet/panel-action` back to `onSelect`. Extensions render after the built-in buttons, so they survive a voice pack that hides the built-in row.
|
|
236
|
+
- Lifecycle: registering the same id again replaces the earlier action (a superseded disposer no longer owns the row), and the disposer `registerPanelAction` returns removes it — bind it to the registering plugin's fiber with `ctx.effect` as above. At most `MAX_PANEL_ACTIONS` (8) registrations fit in the row.
|
|
237
|
+
- Failures stay the plugin's: a malformed registration throws at the registering plugin's own apply (a click could not be dispatched back to it), a throwing callback answers `{ ok: false, error: 'panel-action-failed' }`, and a click on an action the plugin already disposed is a stale click (`{ ok: false, error: 'unknown-panel-action' }`). None of them surfaces as pet breakage.
|
|
238
|
+
- Like `pet.announce`, registration is a host-side (in-process) contract. A browser-half plugin drives the pet through the existing `/api/pet/*` endpoints instead.
|
|
239
|
+
|
|
240
|
+
## Status bubble switch (statusBubbles)
|
|
241
|
+
|
|
242
|
+
Settings > Pet > Status bubbles (`auto` by default, `off` to silence the pet). `off` hides ONLY the pet's own session/status bubbles — the per-session stack (正在思考 / 正在使用 ...) and the legacy single status bubble — while the interaction feedback bubble and a sibling plugin's announcement bubble keep rendering, which is what a plugin that drives its own bubble surface needs. The state snapshot still carries the bubble facts either way: only the rendering is gated, so switching it back on restores them immediately, and a host that predates the field serves no mode at all, which reads as `auto`.
|
|
204
243
|
|
|
205
244
|
## Built-in pets
|
|
206
245
|
|
|
@@ -209,6 +248,7 @@ Host-side sibling plugins can push one structured announcement through the `pet`
|
|
|
209
248
|
| `blue-throated-bee-eater` | 蓝喉蜂虎 | Companion art contributed by the repository contributor under Apache-2.0 (12 AI-illustrated pose references in the palette of the blue-throated-bee-eater skin; composed by docs/archive/blue-throated-bee-eater-pet/gen-pet.py with per-track standalone poses: perched, flight, front hover, waving, landing, droop, tilt, review; ship 小蜜蜂 as the treat name) |
|
|
210
249
|
| `doro` | doro | Frames2d gameplay pet (contributed by stushansusu under MIT): 11 tracks / 802 frames of 42 ms webp sequences — breathing idle, a work trio, sleep, a wash mode (mood +3/s), a four-direction crawl used by random roaming, three idle-director acts (cola / orange / tongue) and a drag-only struggle loop. Doro is an unofficial, fan-made derivative of Dorothy from *Goddess of Victory: Nikke*; the character and all related rights belong to SHIFT UP — personal non-commercial use only, unofficial and not affiliated with SHIFT UP (see THIRD_PARTY_NOTICES.md) |
|
|
211
250
|
| `jyn` | 女仆鲸鱼娘 | Frames2d gameplay pet (contributed by stushansusu under MIT): maid-whale desktop pet with work/sleep/touch gameplay and three selectable skins (暗夜鎏金 / 蓝海霓裳 / 冰晶公主), each with a probability-rolled click action; 暗夜鎏金 also swaps its own rest loop into the sleep gameplay |
|
|
251
|
+
| `jyn-foxtail` | 鲸鱼娘·狗尾巴草 | Frames2d gameplay pet (contributed by stushansusu under MIT): papercut whale-girl with thirteen 3.00 s frame tracks (idle, tease, eat, heart, face, work, work-success, work-fail, sleep, sleeping, snack, sneeze, yawn) carrying click, work, sleep and idle-director gameplay, plus one static webp cover per track under previews/ |
|
|
212
252
|
| `ouo-neko` | OUO Neko | Pink-sakura cat-eared companion contributed by `Pessimist0906` under MIT |
|
|
213
253
|
| `whale-girl` | 鲸鱼娘(原版) | The repository's original whale-girl atlas |
|
|
214
254
|
| `whale-girl-refined` | 鲸鱼娘(精致版) | An AI-assisted derivative with repaired and refined details, based on the whale-girl design direction |
|
package/README.zh.md
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
# dsh-pet
|
|
1
|
+
# dsh-pet · DeepSeek Harness (DSH) 桌面宠物伴侣与 Live2D 互动挂件插件
|
|
2
2
|
|
|
3
3
|
[English](README.md) | 中文
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="https://img.shields.io/npm/v/@linxin666/dsh-client-ui-pet?style=flat-square" alt="Version">
|
|
7
|
+
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.0--rc.2-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
|
+
|
|
10
|
+
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
|
+
</p>
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
<p align="center">
|
|
14
|
+
<strong>DeepSeek Harness(DSH)官方 Web GUI 与桌面客户端专属桌面宠物伴侣生态</strong><br>
|
|
15
|
+
<em>智能体思考跟随 · Live2D / 精灵图桌宠 · 摸头喂食互动 · 实时状态气泡 · 创意工坊宠物下载</em>
|
|
16
|
+
</p>
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
> 一个注册表驱动的桌面宠物伴侣:内置萌系鲸鱼娘,同时支持从创意工坊一键下载安装任意 Live2D 与精灵图桌宠。
|
|
19
|
+
|
|
20
|
+
模型思考时你在等待,你的桌面宠物在屏幕上畅游交互。它深度跟随 DeepSeek Harness 官方智能体会话生命周期,在空闲等待、模型思考、调用工具(Bash / 代码编写 / 网页检索)、整理回复、庆祝完成与报告失败时自动无缝切换动画;你还可以随时摸摸头、喂食小鱼干互动,看着专属亲密度与等级不断提升。桌面宠物基于资产注册表驱动而不是硬编码:每只宠物只需一份 `pet.json` manifest 加一张贴图集(或 Live2D 动作模型包),宿主启动时自动发现并支持热切换。
|
|
21
|
+
|
|
22
|
+
从桌面应用的经典宠物系统重构演进,完美适配官方 DSH 插件形态(cordis bundle:host 宿主半区 + client 浏览器半区一站式融合)。
|
|
10
23
|
|
|
11
24
|
## 功能
|
|
12
25
|
|
|
@@ -23,10 +36,11 @@
|
|
|
23
36
|
| 拖动 | 按住拖动宠物换位置;位置持久化 |
|
|
24
37
|
| 隐藏/召唤 | 悬浮面板位于宠物下方(下方空间不足时上移到状态气泡之上)并提供 隐藏;隐藏后出现 召唤{name} 按钮 |
|
|
25
38
|
| 妙语库 | 内置默认妙语库(每类事件 10 句)+ 宠物自定义台词;成功文案按持久化成功次数轮换,冷却文案按持久化拒绝次数轮换 |
|
|
26
|
-
| 状态气泡 | 默认只有一个顶层会话说话——上报 GUI 当前会话时优先它,否则是最近活动的一个——其余会话收进主气泡右上角的 +N 角标,不再叠出一长列;悬停气泡(触屏点按角标)即可向上展开所有会话的气泡,点击任一气泡跳转到对应会话;子代理会话借由其发起会话体现,不占用独立气泡;瞬时互动反馈临时优先。气泡文案按场景准备了大量轮换词库(等待 / 思考 / 整理 / 完成 / 失败……),工具调用按工具族映射俏皮文案并带上真实参数(如 跑跑 npm test
|
|
39
|
+
| 状态气泡 | 默认只有一个顶层会话说话——上报 GUI 当前会话时优先它,否则是最近活动的一个——其余会话收进主气泡右上角的 +N 角标,不再叠出一长列;悬停气泡(触屏点按角标)即可向上展开所有会话的气泡,点击任一气泡跳转到对应会话;子代理会话借由其发起会话体现,不占用独立气泡;瞬时互动反馈临时优先。气泡文案按场景准备了大量轮换词库(等待 / 思考 / 整理 / 完成 / 失败……),工具调用按工具族映射俏皮文案并带上真实参数(如 跑跑 npm test),同一场景持续数秒会自动换一种说法。宠物自带的这些状态气泡可在 设置 → 宠物 → 状态气泡 关掉,此时整行气泡留给自建气泡面的插件;通过 `pet.announce` 推送的公告气泡两种模式下都照常渲染 |
|
|
27
40
|
| 碎碎念 | 会话流式输出期间,宠物会偶尔借该会话自己的气泡说出内心独白——新鲜的碎碎念接管所属会话的气泡并以「」引号标记——与状态气泡共用同一片 DeepSeek 蓝黑玻璃,气泡栈内颜色统一不再色差——不再叠出第二只气泡——分类台词由「正在干什么」触发(思考 / 写回复 / 正在跑的工具族),结果台词只由结构化结果触发(测试工具通过 → 全绿、工具失败 → 报错、回合完成 → 收工)——决不读模型说的话,讨论里提到关键词也不会误触发心境;碎碎念也从不引用真实内容(无工具名、路径、模型原文);分类冷却 9 秒、结果冷却 5 秒,展示 8 秒后气泡恢复状态文案 |
|
|
28
41
|
| 多会话活动 | 宠物是宿主全局的:最近一次有意义事件驱动精灵动画,同时每个活动的顶层会话用自己的气泡报告各自状态;每个会话(含子代理)完成的轮次都计入亲密度与小鱼干 |
|
|
29
42
|
| 语音包与面板 DIY | 宠物目录 voice.json + 全局 $DSH_HOME/pets/.voice.json 覆盖气泡全部文案与悬浮面板(按钮标签/统计格式/按钮显隐);合并优先级 宠物自带 > 全局 > 内置,坏包警告不拒载 |
|
|
43
|
+
| 面板动作扩展点 | 兄弟插件通过进程内 pet 服务(`ctx.pet.registerPanelAction({ id, label, onSelect })`)把自己的动作注册进悬浮面板的动作行;宠物渲染按钮并把点击派发回插件自己的回调,动作随注册一起回收 |
|
|
30
44
|
|
|
31
45
|
## 宠物契约
|
|
32
46
|
|
|
@@ -200,7 +214,32 @@ frames2d 宠物可声明 `gameplay` 块——从 miku 桌宠泛化而来的可
|
|
|
200
214
|
- 开关:设置 → 宠物 → 状态装饰(默认开)。内置鲸鱼素材派生自 DeepSeek wordmark(MIT),完整声明见 THIRD_PARTY_NOTICES.md。
|
|
201
215
|
## 公告气泡(pet.announce)
|
|
202
216
|
|
|
203
|
-
宿主侧的兄弟插件可通过 `pet` cordis 服务推送一条结构化公告(`ctx.pet.announce({ source, kind, title, ... })`);客户端半区将其渲染为一只专用、特别设计的气泡,挂在会话气泡栈顶部——独立玻璃样式与色调描边(`ok`/`warn`/`low`)、余额与今日消费类金额胶囊、套餐百分比窗口带微型计量条、展示重置时间。载荷经有界校验(src/announce.ts):未知字段丢弃、超长文本截断、TTL 收敛到 1 秒 - 2 小时(默认 10 秒;周期型发布方按自身轮询节奏声明 TTL
|
|
217
|
+
宿主侧的兄弟插件可通过 `pet` cordis 服务推送一条结构化公告(`ctx.pet.announce({ source, kind, title, ... })`);客户端半区将其渲染为一只专用、特别设计的气泡,挂在会话气泡栈顶部——独立玻璃样式与色调描边(`ok`/`warn`/`low`)、余额与今日消费类金额胶囊、套餐百分比窗口带微型计量条、展示重置时间。载荷经有界校验(src/announce.ts):未知字段丢弃、超长文本截断、TTL 收敛到 1 秒 - 2 小时(默认 10 秒;周期型发布方按自身轮询节奏声明 TTL,常驻气泡因此跨轮询连续,上限仍保证失活来源的气泡至多一个刷新周期内消失),畸形公告静默丢弃。公告仅存内存:每个发布方按 `source` 各占一个槽位,各自持有自己的 TTL,过期即不再渲染,不触碰 pet.json 与台账。刻意不提供 HTTP 面——按跨插件协作规则,API 就是进程内服务。
|
|
218
|
+
|
|
219
|
+
**一只宠物上的多个发布方。** 该契约最初只有一个槽位,第二个公告插件会把第一个顶掉;现在 `source`(载荷本来就带)就是槽位键,各发布方 TTL 独立。每条新鲜槽位各渲染一只气泡,按各发布方首次到达的顺序叠在会话气泡之上——周期型发布方就地刷新自己那只,两个节奏不同的发布方不会互换位置,气泡栈也不会抖动。槽位表有上限(`MAX_ANNOUNCEMENTS` = 4):过期发布方的槽位自动释放;表真的满时,新来的发布方拿走沉默最久的那只而不是被拒绝,因此持续刷新的发布方永远不会被挤掉。为兼容灰度升级,最新鲜的那条同时仍以旧的单数字段 `announcement` 下发,旧浏览器半区照常渲染一只气泡而不会空白。
|
|
220
|
+
|
|
221
|
+
## 面板动作扩展点(pet.registerPanelAction)
|
|
222
|
+
|
|
223
|
+
宿主侧的兄弟插件可以往宠物悬浮面板的动作行里追加自己的按钮,与内置的喂食 / 改名 / 隐藏并存:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
ctx.effect(() => ctx.pet.registerPanelAction({
|
|
227
|
+
id: 'pet-quota-swap', // kebab id,点击按它派发回插件
|
|
228
|
+
label: '换装', // 有界标签(超过就会撑换行)
|
|
229
|
+
title: '切换到下一只宠物', // 可选 tooltip
|
|
230
|
+
order: 0, // 可选:在已注册动作块内的排序键
|
|
231
|
+
onSelect: async ({ petId }) => { /* 插件自己做事 */ },
|
|
232
|
+
}))
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
- 宠物拥有这一行,插件拥有这个按钮:宿主对每次注册做校验(src/panel-actions.ts),把已注册动作放进状态快照(`panelActions`)下发,点击经 `POST /api/pet/panel-action` 派发回 `onSelect`。扩展动作渲染在内置按钮之后,因此语音包隐藏内置动作行时它们依然可见。
|
|
236
|
+
- 生命周期:同一 id 再次注册会替换旧动作(被替换的 disposer 不再拥有这一行),`registerPanelAction` 返回的 disposer 负责移除它——按上面的写法用 `ctx.effect` 绑到注册插件自己的 fiber 上即可。动作行最多容纳 `MAX_PANEL_ACTIONS`(8)个注册。
|
|
237
|
+
- 失败只算插件自己的问题:畸形注册会在注册插件自己的 apply 里抛错(点击无法派发回它),回调抛错返回 `{ ok: false, error: 'panel-action-failed' }`,点击一个插件已经注销的动作属于过期点击(`{ ok: false, error: 'unknown-panel-action' }`),都不会表现为宠物故障。
|
|
238
|
+
- 与 `pet.announce` 一样,注册是宿主侧(进程内)契约;浏览器半区的插件走既有的 `/api/pet/*` 端点驱动宠物即可。
|
|
239
|
+
|
|
240
|
+
## 状态气泡开关(statusBubbles)
|
|
241
|
+
|
|
242
|
+
设置 → 宠物 → 状态气泡(默认 `auto`,改为 `off` 即让宠物闭嘴)。`off` 只隐藏宠物自带的会话/状态气泡——每个会话的气泡栈(正在思考 / 正在使用……)与旧式单状态气泡——互动反馈气泡与兄弟插件通过公告契约推送的气泡照常渲染,这正是自建气泡面的插件需要的。两种模式下状态快照都照常携带气泡数据:只有渲染被关掉,随时切回即刻恢复;早于该字段的宿主不带模式,读取时按 `auto` 处理。
|
|
204
243
|
|
|
205
244
|
## 内置宠物
|
|
206
245
|
|
|
@@ -209,6 +248,7 @@ frames2d 宠物可声明 `gameplay` 块——从 miku 桌宠泛化而来的可
|
|
|
209
248
|
| `blue-throated-bee-eater` | 蓝喉蜂虎 | 贡献者以 Apache-2.0 贡献的伙伴插画(12 张同角色 AI 立绘素材,配色取蓝喉蜂虎皮肤同源;由 docs/archive/blue-throated-bee-eater-pet/gen-pet.py 组装,各轨道独立姿态:栖枝/飞行/正面悬停/挥翅/降落/垂头/歪头/昂首;饲料以「小蜜蜂」命名) |
|
|
210
249
|
| `doro` | doro | 由 stushansusu 以 MIT 许可证贡献的 frames2d 玩法宠物:11 条轨道 / 802 帧 42ms webp 序列——呼吸待机、打工三件套、睡觉、洗澡模式(心情 +3/秒)、随机漫游用的四向爬行、三个待机小动作(cola / orange / tongue)与仅拖拽期间播放的挣扎循环。Doro 是《胜利女神:妮姬》桃乐丝的非官方同人二创/梗衍生形象,角色及相关权利归 SHIFT UP 所有——仅限个人非商业使用,与官方无隶属或背书关系(见 THIRD_PARTY_NOTICES.md)。 |
|
|
211
250
|
| `jyn` | 女仆鲸鱼娘 | frames2d 玩法宠物(stushansusu 以 MIT 贡献):带打工/睡觉/触摸玩法与三款可选皮肤(暗夜鎏金 / 蓝海霓裳 / 冰晶公主)的女仆鲸鱼同桌宠,每款皮肤各带一个概率掷骰点击动作;暗夜鎏金另将专属休息循环换入睡觉玩法 |
|
|
251
|
+
| `jyn-foxtail` | 鲸鱼娘·狗尾巴草 | 由 stushansusu 以 MIT 贡献的 frames2d 玩法宠物:剪纸风格的鲸鱼娘,13 条 3.00s 帧序列轨道(idle / tease / eat / heart / face / work / work-success / work-fail / sleep / sleeping / snack / sneeze / yawn),带点击、打工、睡觉与四个待机小动作玩法;previews/ 下每条轨道一张静态 webp 封面 |
|
|
212
252
|
| `ouo-neko` | OUO Neko | `Pessimist0906` 以 MIT 许可证贡献的粉色樱花猫耳伙伴 |
|
|
213
253
|
| `whale-girl` | 鲸鱼娘(原版) | 仓库原有的鲸鱼娘图集 |
|
|
214
254
|
| `whale-girl-refined` | 鲸鱼娘(精致版) | 以鲸鱼娘设计方向为基础,经 AI 辅助二次创作、修复和细节精修的衍生版本 |
|
package/lib/client.js
CHANGED
|
@@ -784,13 +784,15 @@ window.__ModuleLoader__.load({
|
|
|
784
784
|
spriteWidth
|
|
785
785
|
]);
|
|
786
786
|
const bubbleScale = bubbleScaleFor(display);
|
|
787
|
-
const
|
|
787
|
+
const statusBubblesOn = (snapshot?.statusBubbles ?? "auto") !== "off";
|
|
788
|
+
const sessionBubbles = statusBubblesOn ? snapshot?.sessions ?? [] : [];
|
|
788
789
|
const stackOpen = stackPeek || stackPinned;
|
|
789
790
|
const visibleSessions = !stackOpen && sessionBubbles.length > 1 ? sessionBubbles.slice(0, 1) : sessionBubbles;
|
|
790
|
-
const statusBubble = feedback === null && sessionBubbles.length === 0 ? snapshot?.bubble : void 0;
|
|
791
|
-
const
|
|
792
|
-
const
|
|
793
|
-
const
|
|
791
|
+
const statusBubble = statusBubblesOn && feedback === null && sessionBubbles.length === 0 ? snapshot?.bubble : void 0;
|
|
792
|
+
const announced = snapshot?.announcements ?? (snapshot?.announcement !== void 0 ? [snapshot.announcement] : []);
|
|
793
|
+
const now = Date.now();
|
|
794
|
+
const usageAnnouncements = feedback === null ? announced.filter((entry) => announcementFresh(entry, now)) : [];
|
|
795
|
+
const bubblePresent = feedback !== null || sessionBubbles.length > 0 || statusBubble !== void 0 || usageAnnouncements.length > 0;
|
|
794
796
|
const displayName = snapshot?.name ?? definition.displayName;
|
|
795
797
|
const decoration = snapshot?.decoration;
|
|
796
798
|
(0, react.useEffect)(() => {
|
|
@@ -889,7 +891,7 @@ window.__ModuleLoader__.load({
|
|
|
889
891
|
className: clsx(pet_module_css_default.bubble, feedback.kind === "feed" ? pet_module_css_default.bubbleFeed : pet_module_css_default.bubblePet),
|
|
890
892
|
children: feedback.text
|
|
891
893
|
}, feedback.at),
|
|
892
|
-
feedback === null && (sessionBubbles.length > 0 || statusBubble !== void 0 ||
|
|
894
|
+
feedback === null && (sessionBubbles.length > 0 || statusBubble !== void 0 || usageAnnouncements.length > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
893
895
|
ref: bubbleRef,
|
|
894
896
|
className: pet_module_css_default.bubbleStack,
|
|
895
897
|
onPointerEnter: () => setStackPeek(true),
|
|
@@ -935,7 +937,7 @@ window.__ModuleLoader__.load({
|
|
|
935
937
|
phase
|
|
936
938
|
}), statusBubble]
|
|
937
939
|
}, "status"),
|
|
938
|
-
|
|
940
|
+
usageAnnouncements.map((entry) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageAnnouncementBubble, { announcement: entry }, entry.source))
|
|
939
941
|
]
|
|
940
942
|
}),
|
|
941
943
|
hovered && dragRef.current === null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -1039,7 +1041,17 @@ window.__ModuleLoader__.load({
|
|
|
1039
1041
|
className: pet_module_css_default.action,
|
|
1040
1042
|
onClick: props.onGameplayMenu,
|
|
1041
1043
|
children: props.t("pet.gameplay.menu")
|
|
1042
|
-
})
|
|
1044
|
+
}),
|
|
1045
|
+
(snapshot?.panelActions ?? []).map((action) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1046
|
+
type: "button",
|
|
1047
|
+
className: pet_module_css_default.action,
|
|
1048
|
+
"data-dsh-pet-panel-action": action.id,
|
|
1049
|
+
...action.title === void 0 ? {} : { title: action.title },
|
|
1050
|
+
onClick: () => {
|
|
1051
|
+
props.onPanelAction(action.id);
|
|
1052
|
+
},
|
|
1053
|
+
children: action.label
|
|
1054
|
+
}, action.id))
|
|
1043
1055
|
]
|
|
1044
1056
|
})
|
|
1045
1057
|
] })
|
|
@@ -1992,6 +2004,7 @@ window.__ModuleLoader__.load({
|
|
|
1992
2004
|
onHide: props.hide,
|
|
1993
2005
|
onDragEnd: props.dragEnd,
|
|
1994
2006
|
onRename: props.rename,
|
|
2007
|
+
onPanelAction: props.panelAction,
|
|
1995
2008
|
onOpenSession: props.openSession,
|
|
1996
2009
|
onFeedbackDone: props.feedbackDone,
|
|
1997
2010
|
portalTarget: props.portalTarget,
|
|
@@ -3525,6 +3538,12 @@ window.__ModuleLoader__.load({
|
|
|
3525
3538
|
var settings_section_module_css_default = { "sectionList": "c5M8OW_sectionList" };
|
|
3526
3539
|
//#endregion
|
|
3527
3540
|
//#region src/client/PetSettingsCard.tsx
|
|
3541
|
+
/**
|
|
3542
|
+
* The bubble modes this card can write, in render order. Mirrors the host
|
|
3543
|
+
* schema's union (see PetStatusBubbleMode); the browser half never imports the
|
|
3544
|
+
* host module for a value, so the accepted set is spelled here as literals.
|
|
3545
|
+
*/
|
|
3546
|
+
const STATUS_BUBBLE_CHOICES = ["auto", "off"];
|
|
3528
3547
|
/** Fetch the registry list (the same data the sprite renders from). */
|
|
3529
3548
|
async function fetchPetChoices() {
|
|
3530
3549
|
const response = await fetch("/api/pet/pets");
|
|
@@ -3564,6 +3583,7 @@ window.__ModuleLoader__.load({
|
|
|
3564
3583
|
this.form = new CardForm(scope, [
|
|
3565
3584
|
booleanField("enabled"),
|
|
3566
3585
|
booleanField("decorationEnabled"),
|
|
3586
|
+
choiceField("statusBubbles", STATUS_BUBBLE_CHOICES),
|
|
3567
3587
|
booleanField("visible"),
|
|
3568
3588
|
numberField("size"),
|
|
3569
3589
|
numberField("right"),
|
|
@@ -3689,6 +3709,7 @@ window.__ModuleLoader__.load({
|
|
|
3689
3709
|
petSelectionFallback: fallback,
|
|
3690
3710
|
enabled: this.form.field("enabled"),
|
|
3691
3711
|
decorationEnabled: this.form.field("decorationEnabled"),
|
|
3712
|
+
statusBubbles: this.form.field("statusBubbles"),
|
|
3692
3713
|
visible: fallback ? this.fallbackVisible() : this.form.field("visible"),
|
|
3693
3714
|
size: this.form.field("size"),
|
|
3694
3715
|
right: this.form.field("right"),
|
|
@@ -3816,6 +3837,27 @@ window.__ModuleLoader__.load({
|
|
|
3816
3837
|
props.resetField("decorationEnabled");
|
|
3817
3838
|
}
|
|
3818
3839
|
}),
|
|
3840
|
+
state.petSelectionFallback ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChoiceField, {
|
|
3841
|
+
id: "settings-pet-status-bubbles",
|
|
3842
|
+
label: t("settings.statusBubbles"),
|
|
3843
|
+
hint: t("settings.statusBubblesHint"),
|
|
3844
|
+
inheritLabel: t("settings.inherit"),
|
|
3845
|
+
...fieldProps,
|
|
3846
|
+
...state.statusBubbles,
|
|
3847
|
+
choices: [{
|
|
3848
|
+
value: STATUS_BUBBLE_CHOICES[0],
|
|
3849
|
+
label: t("settings.on")
|
|
3850
|
+
}, {
|
|
3851
|
+
value: STATUS_BUBBLE_CHOICES[1],
|
|
3852
|
+
label: t("settings.off")
|
|
3853
|
+
}],
|
|
3854
|
+
onEdit: (text) => {
|
|
3855
|
+
props.edit("statusBubbles", text);
|
|
3856
|
+
},
|
|
3857
|
+
onReset: () => {
|
|
3858
|
+
props.resetField("statusBubbles");
|
|
3859
|
+
}
|
|
3860
|
+
}),
|
|
3819
3861
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChoiceField, {
|
|
3820
3862
|
id: "settings-pet-pet",
|
|
3821
3863
|
label: t("settings.pet"),
|
|
@@ -3979,6 +4021,8 @@ window.__ModuleLoader__.load({
|
|
|
3979
4021
|
"settings.enabledHint": "关闭后隐藏宠物并停止轮询,可在设置里重新启用。",
|
|
3980
4022
|
"settings.decoration": "状态装饰",
|
|
3981
4023
|
"settings.decorationHint": "在宠物状态气泡里显示喷水鲸鱼等状态装饰;关闭后气泡只剩文字。",
|
|
4024
|
+
"settings.statusBubbles": "状态气泡",
|
|
4025
|
+
"settings.statusBubblesHint": "宠物自带的会话/状态气泡(正在思考、正在使用 xxx)。关掉后只剩第三方插件通过公告契约推送的气泡与互动反馈气泡;默认开启。",
|
|
3982
4026
|
"settings.visible": "显示宠物",
|
|
3983
4027
|
"settings.visibleHint": "关闭后宠物隐藏,可从聊天输入区重新召唤。",
|
|
3984
4028
|
"settings.size": "大小(px)",
|
|
@@ -4061,6 +4105,8 @@ window.__ModuleLoader__.load({
|
|
|
4061
4105
|
"settings.enabledHint": "When off, the pet hides and polling stops; re-enable it here.",
|
|
4062
4106
|
"settings.decoration": "Status decoration",
|
|
4063
4107
|
"settings.decorationHint": "Show ornaments like the spouting whale inside the pet status bubbles; when off, bubbles stay text-only.",
|
|
4108
|
+
"settings.statusBubbles": "Status bubbles",
|
|
4109
|
+
"settings.statusBubblesHint": "The pet's own session/status bubbles (thinking, using ...). Turning them off leaves only bubbles a third-party plugin pushes through the announcement contract, plus the interaction feedback bubble; on by default.",
|
|
4064
4110
|
"settings.visible": "Show the pet",
|
|
4065
4111
|
"settings.visibleHint": "When off, the pet hides; summon it again from the input row.",
|
|
4066
4112
|
"settings.size": "Size (px)",
|
|
@@ -4087,28 +4133,6 @@ window.__ModuleLoader__.load({
|
|
|
4087
4133
|
"settings.saveFailed": "The deployment did not accept these values; they were left for you to correct.",
|
|
4088
4134
|
"settings.invalidNumber": "Enter a number, or leave blank to use the default."
|
|
4089
4135
|
};
|
|
4090
|
-
/**
|
|
4091
|
-
* Active dictionary, picked by the document language at call time. The pet
|
|
4092
|
-
* mounts as a global floating surface (not a session-scoped slot), so it has
|
|
4093
|
-
* no framework locale seat and resolves its copy the same tiny way the
|
|
4094
|
-
* task-board's DOM-injected surface does.
|
|
4095
|
-
*/
|
|
4096
|
-
function dictionary() {
|
|
4097
|
-
return (typeof document !== "undefined" ? document.documentElement.lang : "zh").toLowerCase().startsWith("en") ? en : zh;
|
|
4098
|
-
}
|
|
4099
|
-
/**
|
|
4100
|
-
* Translate a key with optional `{name}` template params. Mirrors the slot
|
|
4101
|
-
* `Translate` contract `(key, params?) => string` so it can be handed to the
|
|
4102
|
-
* same components that used to receive the framework-injected `t` seat. The
|
|
4103
|
-
* key is typed loosely (`string`) so the function is assignable to the slot's
|
|
4104
|
-
* `TranslateNS<'pet'>` (whose key domain also spans the shared common
|
|
4105
|
-
* vocabulary); a missing key degrades to the key itself rather than throwing.
|
|
4106
|
-
*/
|
|
4107
|
-
function t(key, params) {
|
|
4108
|
-
let text = dictionary()[key] ?? key;
|
|
4109
|
-
if (params !== void 0) for (const [name, value] of Object.entries(params)) text = text.replaceAll(`{${name}}`, String(value));
|
|
4110
|
-
return text;
|
|
4111
|
-
}
|
|
4112
4136
|
//#endregion
|
|
4113
4137
|
//#region src/client/main-session.ts
|
|
4114
4138
|
/**
|
|
@@ -4132,7 +4156,7 @@ window.__ModuleLoader__.load({
|
|
|
4132
4156
|
/** The building package's version, when the bundle carries it. */
|
|
4133
4157
|
function bakedVersion() {
|
|
4134
4158
|
try {
|
|
4135
|
-
return "0.4.
|
|
4159
|
+
return "0.4.6";
|
|
4136
4160
|
} catch {
|
|
4137
4161
|
return;
|
|
4138
4162
|
}
|
|
@@ -4215,6 +4239,7 @@ window.__ModuleLoader__.load({
|
|
|
4215
4239
|
setConfig: (patch) => petFetch("/api/pet/set-config", patch),
|
|
4216
4240
|
setName: (name) => petFetch("/api/pet/set-name", { name }),
|
|
4217
4241
|
setPet: (petId) => petFetch("/api/pet/set-pet", { petId }),
|
|
4242
|
+
panelAction: (id) => petFetch("/api/pet/panel-action", { id }),
|
|
4218
4243
|
setSkin: (skin) => petFetch("/api/pet/set-skin", skin === void 0 ? {} : { skin }),
|
|
4219
4244
|
gameplayTouch: (zone) => petFetch("/api/pet/gameplay/touch", zone === void 0 ? {} : { zone }),
|
|
4220
4245
|
gameplaySetMode: (mode) => petFetch("/api/pet/gameplay/mode", { mode }),
|
|
@@ -4240,22 +4265,187 @@ window.__ModuleLoader__.load({
|
|
|
4240
4265
|
"ui-pet",
|
|
4241
4266
|
PET_SETTINGS_NS
|
|
4242
4267
|
];
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4268
|
+
/** How long the deferred form keeps retrying before it settles on the fallback. */
|
|
4269
|
+
const BINDER_RETRY_MS = 250;
|
|
4270
|
+
const BINDER_ATTEMPTS = 24;
|
|
4271
|
+
/** The snapshot an unresolved (or resolvable-but-unbound) form publishes. */
|
|
4272
|
+
function pendingSnapshot(status) {
|
|
4273
|
+
return {
|
|
4274
|
+
status,
|
|
4275
|
+
value: void 0,
|
|
4276
|
+
base: void 0,
|
|
4277
|
+
user: void 0,
|
|
4278
|
+
revision: void 0,
|
|
4279
|
+
writable: false,
|
|
4280
|
+
mode: "host"
|
|
4281
|
+
};
|
|
4257
4282
|
}
|
|
4258
4283
|
/**
|
|
4284
|
+
* A ConfigForm that late-binds to the family settings binder.
|
|
4285
|
+
*
|
|
4286
|
+
* The binder service (dsh-web-settings) is not guaranteed to be published by the
|
|
4287
|
+
* time this plugin's apply() runs: the aggregate bundle mounts its inlined
|
|
4288
|
+
* children — including the binder — inside an async mount that awaits the
|
|
4289
|
+
* active-rows fetch, while standalone loader entries like this one apply
|
|
4290
|
+
* synchronously in that window. A single early probe then permanently falls
|
|
4291
|
+
* back to `configForms.get('pet')`, which is never a served row id under the
|
|
4292
|
+
* aggregate (the row is `web-ui-pet`), so the settings card renders "not
|
|
4293
|
+
* exposed" forever even though the Host serves the namespace.
|
|
4294
|
+
*
|
|
4295
|
+
* This form resolves through the binder as soon as the service appears and
|
|
4296
|
+
* delegates the whole ConfigForm surface to it, re-publishing to its own
|
|
4297
|
+
* subscribers on every swap. Until a form is resolved it publishes a loading
|
|
4298
|
+
* (then unavailable) snapshot so the card shows a transient state, never a
|
|
4299
|
+
* false "not exposed". If the binder never appears it retries for a bounded
|
|
4300
|
+
* window, then permanently binds the non-bridge fallback by SERVED entry id.
|
|
4301
|
+
*/
|
|
4302
|
+
var DeferredSettingsForm = class {
|
|
4303
|
+
ctx;
|
|
4304
|
+
current;
|
|
4305
|
+
listeners = /* @__PURE__ */ new Set();
|
|
4306
|
+
unsubscribeCurrent;
|
|
4307
|
+
retryTimer;
|
|
4308
|
+
attempts = 0;
|
|
4309
|
+
disposed = false;
|
|
4310
|
+
fallback;
|
|
4311
|
+
fallbackUnsubscribe;
|
|
4312
|
+
constructor(ctx) {
|
|
4313
|
+
this.ctx = ctx;
|
|
4314
|
+
this.fallback = ctx.configForms.get(this.resolveFallbackEntryId());
|
|
4315
|
+
if (!this.resolve() && !this.fallbackSettled()) this.scheduleRetry();
|
|
4316
|
+
else if (this.current === void 0) this.adoptFallback();
|
|
4317
|
+
}
|
|
4318
|
+
/**
|
|
4319
|
+
* True only once the shared mirror answers for the pet namespace itself.
|
|
4320
|
+
*
|
|
4321
|
+
* 'ready' is the only state that answers (#1813). A host-persisted row starts
|
|
4322
|
+
* out as 'loading' — the mirror has published no view yet — and that is not
|
|
4323
|
+
* an answer: adopting it on sight drops the retry window, and under the
|
|
4324
|
+
* aggregate, which serves only the renamed 'web-ui-pet' row, the form then
|
|
4325
|
+
* settles into 'unavailable' and the page stays "not exposed" for good. So
|
|
4326
|
+
* 'loading' and 'unavailable' both keep the window open and let the binder be
|
|
4327
|
+
* adopted the moment the aggregate publishes it.
|
|
4328
|
+
*/
|
|
4329
|
+
fallbackSettled() {
|
|
4330
|
+
try {
|
|
4331
|
+
return this.fallback.getSnapshot().status === "ready";
|
|
4332
|
+
} catch {
|
|
4333
|
+
return false;
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
/**
|
|
4337
|
+
* Bind the fallback to a SERVED row id when the mirror can name one; a mirror
|
|
4338
|
+
* that cannot is left to report its own unavailable state.
|
|
4339
|
+
*/
|
|
4340
|
+
resolveFallbackEntryId() {
|
|
4341
|
+
try {
|
|
4342
|
+
const served = this.ctx.configForms.describe().getSnapshot().view?.namespaces.map((view) => view.ns);
|
|
4343
|
+
if (served && served.length > 0) {
|
|
4344
|
+
const hit = PET_ENTRY_IDS.find((id) => served.includes(id));
|
|
4345
|
+
if (hit !== void 0) return hit;
|
|
4346
|
+
}
|
|
4347
|
+
} catch {}
|
|
4348
|
+
return PET_SETTINGS_NS;
|
|
4349
|
+
}
|
|
4350
|
+
/**
|
|
4351
|
+
* Adopt the family binder the moment it is published.
|
|
4352
|
+
* @returns true when a binder was bound, false when none is available yet.
|
|
4353
|
+
*/
|
|
4354
|
+
resolve() {
|
|
4355
|
+
if (this.disposed) return false;
|
|
4356
|
+
let binder;
|
|
4357
|
+
try {
|
|
4358
|
+
binder = this.ctx.get("webUiSettings");
|
|
4359
|
+
} catch {
|
|
4360
|
+
binder = void 0;
|
|
4361
|
+
}
|
|
4362
|
+
if (binder === void 0 || typeof binder.bind !== "function") return false;
|
|
4363
|
+
let bound;
|
|
4364
|
+
try {
|
|
4365
|
+
bound = binder.bind({ namespace: PET_SETTINGS_NS });
|
|
4366
|
+
} catch {
|
|
4367
|
+
return false;
|
|
4368
|
+
}
|
|
4369
|
+
this.current = bound;
|
|
4370
|
+
this.unsubscribeCurrent?.();
|
|
4371
|
+
this.unsubscribeCurrent = bound.subscribe(() => this.publish());
|
|
4372
|
+
this.publish();
|
|
4373
|
+
return true;
|
|
4374
|
+
}
|
|
4375
|
+
/**
|
|
4376
|
+
* Adopt the shared per-entry form. It is used immediately unless it cannot
|
|
4377
|
+
* answer yet (still loading, or reporting the namespace unavailable), in which
|
|
4378
|
+
* case the binder may still be on its way and the retry window takes over
|
|
4379
|
+
* (see scheduleRetry).
|
|
4380
|
+
*/
|
|
4381
|
+
adoptFallback() {
|
|
4382
|
+
this.current = this.fallback;
|
|
4383
|
+
this.fallbackUnsubscribe ??= this.fallback.subscribe(() => this.publish());
|
|
4384
|
+
this.unsubscribeCurrent = this.fallbackUnsubscribe;
|
|
4385
|
+
this.publish();
|
|
4386
|
+
}
|
|
4387
|
+
/** Retry the binder lookup a few times across the aggregate's async mount. */
|
|
4388
|
+
scheduleRetry() {
|
|
4389
|
+
if (this.disposed) return;
|
|
4390
|
+
if (this.attempts >= BINDER_ATTEMPTS) {
|
|
4391
|
+
this.adoptFallback();
|
|
4392
|
+
return;
|
|
4393
|
+
}
|
|
4394
|
+
this.attempts += 1;
|
|
4395
|
+
this.retryTimer = window.setTimeout(() => {
|
|
4396
|
+
this.retryTimer = void 0;
|
|
4397
|
+
if (this.disposed) return;
|
|
4398
|
+
if (this.resolve()) return;
|
|
4399
|
+
if (this.fallbackSettled()) {
|
|
4400
|
+
this.attempts = BINDER_ATTEMPTS;
|
|
4401
|
+
this.adoptFallback();
|
|
4402
|
+
return;
|
|
4403
|
+
}
|
|
4404
|
+
this.scheduleRetry();
|
|
4405
|
+
}, 250);
|
|
4406
|
+
}
|
|
4407
|
+
publish() {
|
|
4408
|
+
for (const listener of this.listeners) listener();
|
|
4409
|
+
}
|
|
4410
|
+
/** The resolved form, or a placeholder snapshot when still pending. */
|
|
4411
|
+
snapshot() {
|
|
4412
|
+
return this.current?.getSnapshot() ?? pendingSnapshot(this.attempts >= BINDER_ATTEMPTS ? "unavailable" : "loading");
|
|
4413
|
+
}
|
|
4414
|
+
getSnapshot() {
|
|
4415
|
+
return this.snapshot();
|
|
4416
|
+
}
|
|
4417
|
+
subscribe(listener) {
|
|
4418
|
+
this.listeners.add(listener);
|
|
4419
|
+
return () => {
|
|
4420
|
+
this.listeners.delete(listener);
|
|
4421
|
+
};
|
|
4422
|
+
}
|
|
4423
|
+
mutate(ops, expectedRevision) {
|
|
4424
|
+
return this.current?.mutate(ops, expectedRevision) ?? Promise.resolve(false);
|
|
4425
|
+
}
|
|
4426
|
+
set(field, value) {
|
|
4427
|
+
return this.current?.set(field, value) ?? Promise.resolve(false);
|
|
4428
|
+
}
|
|
4429
|
+
unset(field) {
|
|
4430
|
+
return this.current?.unset(field) ?? Promise.resolve(false);
|
|
4431
|
+
}
|
|
4432
|
+
/** Release the retry timer and mirror subscription; not part of ConfigForm. */
|
|
4433
|
+
dispose() {
|
|
4434
|
+
if (this.disposed) return;
|
|
4435
|
+
this.disposed = true;
|
|
4436
|
+
if (this.retryTimer !== void 0) {
|
|
4437
|
+
window.clearTimeout(this.retryTimer);
|
|
4438
|
+
this.retryTimer = void 0;
|
|
4439
|
+
}
|
|
4440
|
+
this.unsubscribeCurrent?.();
|
|
4441
|
+
this.unsubscribeCurrent = void 0;
|
|
4442
|
+
this.current = void 0;
|
|
4443
|
+
this.listeners.clear();
|
|
4444
|
+
this.fallbackUnsubscribe?.();
|
|
4445
|
+
this.fallbackUnsubscribe = void 0;
|
|
4446
|
+
}
|
|
4447
|
+
};
|
|
4448
|
+
/**
|
|
4259
4449
|
* Client plugin body: register dictionaries, mount the global pet entry and
|
|
4260
4450
|
* poll loop while the plugin is enabled, and seat the settings card as a
|
|
4261
4451
|
* first-level settings section.
|
|
@@ -4286,7 +4476,7 @@ window.__ModuleLoader__.load({
|
|
|
4286
4476
|
}, "pet: dictionaries");
|
|
4287
4477
|
defaultPetRendererRegistry.register(live2dRenderer);
|
|
4288
4478
|
defaultPetRendererRegistry.register(frames2dRenderer);
|
|
4289
|
-
const settingsForm =
|
|
4479
|
+
const settingsForm = new DeferredSettingsForm(ctx);
|
|
4290
4480
|
const enabled = () => {
|
|
4291
4481
|
const snapshot = settingsForm.getSnapshot();
|
|
4292
4482
|
return snapshot.status === "ready" ? snapshot.value?.enabled ?? true : snapshot.status === "unavailable";
|
|
@@ -4425,6 +4615,11 @@ window.__ModuleLoader__.load({
|
|
|
4425
4615
|
if (result.ok) pollNow();
|
|
4426
4616
|
}, () => {});
|
|
4427
4617
|
},
|
|
4618
|
+
panelAction: (id) => {
|
|
4619
|
+
petApi.panelAction(id).then((result) => {
|
|
4620
|
+
if (result.ok) pollNow();
|
|
4621
|
+
}, () => {});
|
|
4622
|
+
},
|
|
4428
4623
|
feedbackDone: () => {
|
|
4429
4624
|
setFeedback(null);
|
|
4430
4625
|
},
|
|
@@ -4457,7 +4652,7 @@ window.__ModuleLoader__.load({
|
|
|
4457
4652
|
const petRoot = (0, react_dom_client.createRoot)(container);
|
|
4458
4653
|
petRoot.render((0, react.createElement)(PetDockEntry, {
|
|
4459
4654
|
...injected(),
|
|
4460
|
-
t,
|
|
4655
|
+
t: ctx.locale.bind("pet"),
|
|
4461
4656
|
portalTarget: container
|
|
4462
4657
|
}));
|
|
4463
4658
|
let uiGone = false;
|
|
@@ -4484,11 +4679,13 @@ window.__ModuleLoader__.load({
|
|
|
4484
4679
|
const unsubscribeSettings = settingsForm.subscribe(syncUi);
|
|
4485
4680
|
ctx.effect(() => () => {
|
|
4486
4681
|
unsubscribeSettings();
|
|
4682
|
+
settingsForm.dispose();
|
|
4487
4683
|
killUi();
|
|
4488
4684
|
}, "pet: client lifecycle");
|
|
4489
4685
|
syncUi();
|
|
4490
4686
|
}
|
|
4491
4687
|
//#endregion
|
|
4688
|
+
exports.BINDER_RETRY_MS = BINDER_RETRY_MS;
|
|
4492
4689
|
exports.apply = apply;
|
|
4493
4690
|
exports.inject = inject;
|
|
4494
4691
|
return module.exports;
|