@linxin666/dsh-pet 0.1.13 → 0.1.14
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 +11 -7
- package/README.zh.md +11 -7
- package/lib/client.js +9 -1
- package/lib/client.js.map +1 -1
- package/lib/index.js +164 -25
- package/lib/invariant.js +1 -1
- package/lib/{state-C9EyycwI.js → state-P-wsVJ6O.js} +7 -6
- package/lib/types/client/WhalePet.d.ts.map +1 -1
- package/lib/types/client/WhalePet.js +2 -1
- package/lib/types/service.d.ts +16 -5
- package/lib/types/service.d.ts.map +1 -1
- package/lib/types/service.js +159 -35
- package/lib/types/state.d.ts +10 -12
- package/lib/types/state.d.ts.map +1 -1
- package/lib/types/state.js +14 -10
- package/package.json +1 -1
- package/src/client/WhalePet.test.tsx +25 -1
- package/src/client/WhalePet.tsx +6 -0
- package/src/client/pet.module.css +9 -0
- package/src/service.ts +187 -34
- package/src/state.test.ts +4 -1
- package/src/state.ts +17 -13
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: 437e1068038cb013e2880441e69cf1c259f51e79
|
|
6
|
+
README.zh.md: 46511480ae653cc8d6c9b164e9e84ff5645f5945
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ English | [中文](README.zh.md)
|
|
|
4
4
|
|
|
5
5
|
> A soft, healing whale-girl who works alongside you in DeepSeek Harness.
|
|
6
6
|
|
|
7
|
-
While the model thinks, you wait — she swims. She follows
|
|
7
|
+
While the model thinks, you wait — she swims. She follows official session activity and switches animations while waiting, thinking, using tools, composing a reply, celebrating completion, or reporting failure; you can also pat her head, feed her dried fish, and watch her grow from a baby whale into your deep-sea bond.
|
|
8
8
|
|
|
9
9
|
Re-implemented from the pet feature of the Codex desktop app, as an official DSH plugin shape (cordis bundle: host half + client half in one package).
|
|
10
10
|
|
|
@@ -12,7 +12,7 @@ Re-implemented from the pet feature of the Codex desktop app, as an official DSH
|
|
|
12
12
|
|
|
13
13
|
| Feature | Description |
|
|
14
14
|
|---|---|
|
|
15
|
-
| State animation |
|
|
15
|
+
| State animation | Official session activity → whale-girl animation: `thinking → running`, `tool → running-right`, `review → review`, `waiting → waiting`, `done → jumping`, `failed → failed` |
|
|
16
16
|
| Head-pat interaction | Click the whale-girl → bubble feedback + affinity +1 (10s cooldown) |
|
|
17
17
|
| Feeding | Hover panel "喂食" (Feed) → consumes 1 dried fish + affinity +5 (30s cooldown) |
|
|
18
18
|
| Treat economy | Dried-fish stock (cap 20): +1 every 3 rounds of work, +1 every 30 minutes; when low it prompts "多陪鲸鱼娘工作一会儿" (Work with the whale-girl a bit more) |
|
|
@@ -20,7 +20,8 @@ Re-implemented from the pet feature of the Codex desktop app, as an official DSH
|
|
|
20
20
|
| Custom naming | Hover panel "改名" (Rename) → 1–20 characters, persisted, echoed in the summon button/panel |
|
|
21
21
|
| Dragging | Hold and drag the whale-girl to reposition; position persisted |
|
|
22
22
|
| Hide/Summon | Hover panel "隐藏" (Hide); after hiding, a "召唤{name}" (Summon {name}) button appears in the input selector row |
|
|
23
|
-
| Status bubble |
|
|
23
|
+
| Status bubble | Shows the current session stage or tool name; transient interaction feedback temporarily takes priority |
|
|
24
|
+
| Multi-session activity | The pet is host-global: the most recent meaningful event controls its display, while completed turns from every session contribute affinity and treats |
|
|
24
25
|
|
|
25
26
|
## Animation preview
|
|
26
27
|
|
|
@@ -41,7 +42,7 @@ dsh-pet/
|
|
|
41
42
|
|-- src/
|
|
42
43
|
| |-- index.ts # host half: plugin entry (cordis apply, route registration)
|
|
43
44
|
| |-- service.ts # PetService: pet state machine + affinity + config (HTTP API service face)
|
|
44
|
-
| |-- state.ts # pet state machine: activity
|
|
45
|
+
| |-- state.ts # pet state machine: projected session activity → 9 state animations
|
|
45
46
|
| |-- affinity.ts # affinity ledger (pure functions + cooldowns)
|
|
46
47
|
| |-- treats.ts # dried-fish stock ledger
|
|
47
48
|
| |-- persist.ts # persistence ($DSH_HOME/pet.json, atomic write)
|
|
@@ -59,14 +60,17 @@ dsh-pet/
|
|
|
59
60
|
### Data flow
|
|
60
61
|
|
|
61
62
|
```
|
|
62
|
-
|
|
63
|
+
official session events (turn/step/chunk/tool) ----\
|
|
64
|
+
> PetService (host)
|
|
65
|
+
optional legacy activity/status ------------------/
|
|
63
66
|
| /api/pet/* JSON
|
|
64
67
|
global React root (createRoot → document.body) <-- polling 800ms -- pet-client (browser)
|
|
65
68
|
|
|
|
66
69
|
WhalePet floating layer (portal + rAF)
|
|
67
70
|
```
|
|
68
71
|
|
|
69
|
-
- **Status source**:
|
|
72
|
+
- **Status source**: the host projects official `turn/start`, `step/start`, `assistant/chunk`, `assistant/message`, `tool/call`, `tool/result`, and `turn/end` events into waiting/thinking/tool/review/done/failed states. Optional legacy `activity/status` events remain a compatibility input.
|
|
73
|
+
- **Multi-session semantics**: the API and browser mount are host-global and expose no foreground-session identity, so the most recent meaningful event wins the display. Every session's completed turns are still rewarded independently, and disposing a non-current session does not reset the visible state.
|
|
70
74
|
- **Mount point**: `document.body` (global React root, always shown: no session / new session / mid-session — the old mount point `conversation.composer.dock` only rendered in an active session, hiding the pet in new sessions); the component uses `createPortal` internally to render the global floating layer.
|
|
71
75
|
- **Rendering**: CSS sprite (background-position) per-frame animation, frame durations from the track definitions in `spritesheet.ts`.
|
|
72
76
|
- **Communication**: browser ↔ host over the same-origin `/api/pet/*` JSON endpoints (state/interact/set-visible/set-config); the atlas loads from `/pet/whale/spritesheet.webp` — both the RPC domain and the `/plugins/` static service are platform-registered, and the plugin self-sufficiently provides its own API and assets (the same pattern as dsh-remote-web-ui's `/api/pair`).
|
|
@@ -93,7 +97,7 @@ After installing, **restart `dsh web`** — the whale-girl appears at the bottom
|
|
|
93
97
|
|
|
94
98
|
```sh
|
|
95
99
|
pnpm build # tsc -b (types+declarations) && tsdown (node half + browser bundle)
|
|
96
|
-
pnpm test # vitest unit tests (
|
|
100
|
+
pnpm test # vitest unit/component tests (event projection / state / UI / ledgers)
|
|
97
101
|
pnpm prepare # transpile-only build (no type checking, for consumer installs)
|
|
98
102
|
pnpm typecheck # type check only
|
|
99
103
|
```
|
package/README.zh.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
> 一只软萌治愈的鲸鱼娘,陪你在 DeepSeek Harness 里工作。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
模型思考的时候你在等,她在游。她会跟随官方会话活动,在等待、思考、使用工具、整理回复、庆祝完成或报告失败时切换动画;你还可以摸头、喂小鱼干,看着她从幼鲸慢慢长成你的深海羁绊。
|
|
8
8
|
|
|
9
9
|
复刻自 Codex 桌面版的宠物功能,以 DSH 官方插件形态实现(cordis bundle:host 半区 + client 半区单包)。
|
|
10
10
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
| 功能 | 说明 |
|
|
14
14
|
|---|---|
|
|
15
|
-
| 状态动画 |
|
|
15
|
+
| 状态动画 | 官方会话活动 → 鲸鱼娘动画:`thinking → running`、`tool → running-right`、`review → review`、`waiting → waiting`、`done → jumping`、`failed → failed` |
|
|
16
16
|
| 摸头互动 | 点击鲸鱼娘 → 气泡反馈 + 亲密度 +1(10s 冷却) |
|
|
17
17
|
| 喂食 | 悬浮面板「喂食」→ 消耗 1 条小鱼干 + 亲密度 +5(30s 冷却) |
|
|
18
18
|
| 饲料经济 | 小鱼干库存(上限 20):工作每 3 回合 +1 条、每 30 分钟 +1 条;库存不足会提示「多陪鲸鱼娘工作一会儿」 |
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
| 自定义命名 | 悬浮面板「改名」→ 1–20 字符,持久化,召唤按钮/面板同步显示 |
|
|
21
21
|
| 拖动 | 按住鲸鱼娘拖动重新摆放,位置持久化 |
|
|
22
22
|
| 隐藏/召唤 | 悬浮面板「隐藏」;隐藏后输入选择行出现「召唤{名字}」按钮 |
|
|
23
|
-
| 状态气泡 |
|
|
23
|
+
| 状态气泡 | 显示当前会话阶段或工具名;短暂的交互反馈会临时优先显示 |
|
|
24
|
+
| 多会话活动 | 宠物是 host 全局的:最近一条有效事件决定显示,所有会话的完成回合都会计入亲密度与小鱼干 |
|
|
24
25
|
|
|
25
26
|
## 动画演示
|
|
26
27
|
|
|
@@ -41,7 +42,7 @@ dsh-pet/
|
|
|
41
42
|
|-- src/
|
|
42
43
|
| |-- index.ts # host 半区:插件入口(cordis apply,注册路由)
|
|
43
44
|
| |-- service.ts # PetService:宠物状态机 + 亲密度 + 配置(HTTP API 服务面)
|
|
44
|
-
| |-- state.ts #
|
|
45
|
+
| |-- state.ts # 宠物状态机:投影后的会话活动 → 9 状态动画
|
|
45
46
|
| |-- affinity.ts # 亲密度账本(纯函数 + 冷却)
|
|
46
47
|
| |-- treats.ts # 小鱼干库存账本
|
|
47
48
|
| |-- persist.ts # 持久化($DSH_HOME/pet.json,原子写入)
|
|
@@ -59,14 +60,17 @@ dsh-pet/
|
|
|
59
60
|
### 数据流
|
|
60
61
|
|
|
61
62
|
```
|
|
62
|
-
|
|
63
|
+
官方会话事件(turn/step/chunk/tool) ----\
|
|
64
|
+
> PetService(host)
|
|
65
|
+
可选的兼容事件 activity/status --------------/
|
|
63
66
|
| /api/pet/* JSON
|
|
64
67
|
global React root(createRoot → document.body) <-- 轮询 800ms -- pet-client(浏览器)
|
|
65
68
|
|
|
|
66
69
|
WhalePet 浮层(portal + rAF)
|
|
67
70
|
```
|
|
68
71
|
|
|
69
|
-
-
|
|
72
|
+
- **状态源**:host 将官方 `turn/start`、`step/start`、`assistant/chunk`、`assistant/message`、`tool/call`、`tool/result` 和 `turn/end` 事件投影为 waiting/thinking/tool/review/done/failed 状态。可选的旧版 `activity/status` 事件仍作为兼容输入。
|
|
73
|
+
- **多会话语义**:API 和浏览器挂载是 host 全局的,也不提供前台会话标识,因此最近一条有效事件决定显示。各会话的完成回合仍独立奖励,销毁非当前会话不会重置可见状态。
|
|
70
74
|
- **挂载点**:`document.body`(全局 React root,无会话/新会话/会话中全程显示——旧挂载点 `conversation.composer.dock` 只在活跃会话渲染,导致新会话界面看不到宠物),组件内部 `createPortal` 渲染全局浮层。
|
|
71
75
|
- **渲染**:CSS sprite(background-position)逐帧动画,帧时长来自 `spritesheet.ts` 的轨道定义。
|
|
72
76
|
- **通信**:浏览器 ↔ host 走同源 `/api/pet/*` JSON 端点(state/interact/set-visible/set-config),图集从 `/pet/whale/spritesheet.webp` 加载——RPC 域与 `/plugins/` 静态服务都是平台注册的,插件自足地提供自己的 API 与素材(与 dsh-remote-web-ui 的 `/api/pair` 同一模式)。
|
|
@@ -93,7 +97,7 @@ dsh plugin --profile web add link:$(pwd)/packages/dsh-pet
|
|
|
93
97
|
|
|
94
98
|
```sh
|
|
95
99
|
pnpm build # tsc -b(类型+声明)&& tsdown(node 半区 + 浏览器 bundle)
|
|
96
|
-
pnpm test # vitest
|
|
100
|
+
pnpm test # vitest 单元/组件测试(事件投影 / state / UI / 账本)
|
|
97
101
|
pnpm prepare # 仅转译构建(无类型检查,供消费者安装)
|
|
98
102
|
pnpm typecheck # 仅类型检查
|
|
99
103
|
```
|
package/lib/client.js
CHANGED
|
@@ -305,7 +305,7 @@ window.__ModuleLoader__.load({
|
|
|
305
305
|
}
|
|
306
306
|
//#endregion
|
|
307
307
|
//#region \0dsh-css:packages/dsh-pet/src/client/pet.module.css.mjs
|
|
308
|
-
const css$1 = ".kz2Bea_float{pointer-events:auto;-webkit-user-select:none;user-select:none;flex-direction:column;align-items:center;display:flex;position:fixed}.kz2Bea_sprite{image-rendering:auto;touch-action:none;position:relative}.kz2Bea_bubble{white-space:nowrap;color:#fff;pointer-events:none;border-radius:999px;margin-bottom:6px;padding:4px 10px;font-size:12px;line-height:1.4;animation:2.6s ease-out forwards kz2Bea_pet-bubble-pop;position:absolute;bottom:100%;box-shadow:0 2px 8px #00000040}.kz2Bea_bubblePet{background:#f472b6eb}.kz2Bea_bubbleFeed{background:#38bdf8eb}@keyframes kz2Bea_pet-bubble-pop{0%{opacity:0;transform:translateY(6px)scale(.85)}15%{opacity:1;transform:translateY(0)scale(1.05)}25%{transform:translateY(0)scale(1)}75%{opacity:1}to{opacity:0;transform:translateY(-8px)scale(.95)}}.kz2Bea_panel{color:#e2e8f0;backdrop-filter:blur(6px);background:#0f172aeb;border:1px solid #94a3b859;border-radius:10px;flex-direction:column;gap:6px;min-width:132px;padding:8px 10px;font-size:12px;display:flex;position:absolute;bottom:100%;box-shadow:0 4px 16px #00000059}.kz2Bea_panel:after{content:\"\";height:14px;position:absolute;top:100%;left:0;right:0}.kz2Bea_rankRow{white-space:nowrap;justify-content:space-between;gap:10px;display:flex}.kz2Bea_nameCell{font-weight:600}.kz2Bea_renameRow{align-items:center;gap:6px;display:flex}.kz2Bea_nameInput{color:#e2e8f0;background:#1e293be6;border:1px solid #7dd3fc80;border-radius:6px;outline:none;flex:1;min-width:0;padding:3px 6px;font-size:12px}.kz2Bea_nameInput:focus{border-color:#38bdf8;box-shadow:0 0 0 2px #38bdf873}.kz2Bea_actions{gap:6px;display:flex}.kz2Bea_action{cursor:pointer;color:#0f172a;background:linear-gradient(#7dd3fc,#38bdf8);border:none;border-radius:6px;flex:1;padding:4px 8px;font-size:12px;transition:filter .12s,box-shadow .12s}.kz2Bea_action:hover{filter:brightness(1.08)}.kz2Bea_action:active{filter:brightness(.94)}.kz2Bea_action:focus-visible{outline:none;box-shadow:0 0 0 2px #38bdf8d9}.kz2Bea_summon{color:#7dd3fc;cursor:pointer;background:#0f172abf;border:1px dashed #7dd3fc99;border-radius:999px;padding:2px 10px;font-size:11px;transition:border-color .12s,color .12s,background .12s,box-shadow .12s}.kz2Bea_summon:hover{color:#bae6fd;background:#0f172ae6;border-color:#7dd3fcf2}.kz2Bea_summon:active{color:#7dd3fc;border-color:#7dd3fccc}.kz2Bea_summon:focus-visible{outline:none;box-shadow:0 0 0 2px #38bdf8d9}@media (prefers-reduced-motion:reduce){.kz2Bea_bubble{opacity:1;animation:none}.kz2Bea_action,.kz2Bea_summon{transition:none}}";
|
|
308
|
+
const css$1 = ".kz2Bea_float{pointer-events:auto;-webkit-user-select:none;user-select:none;flex-direction:column;align-items:center;display:flex;position:fixed}.kz2Bea_sprite{image-rendering:auto;touch-action:none;position:relative}.kz2Bea_bubble{white-space:nowrap;color:#fff;pointer-events:none;border-radius:999px;margin-bottom:6px;padding:4px 10px;font-size:12px;line-height:1.4;animation:2.6s ease-out forwards kz2Bea_pet-bubble-pop;position:absolute;bottom:100%;box-shadow:0 2px 8px #00000040}.kz2Bea_bubblePet{background:#f472b6eb}.kz2Bea_bubbleFeed{background:#38bdf8eb}.kz2Bea_bubbleStatus{text-overflow:ellipsis;background:#0f172ae6;border:1px solid #7dd3fc80;max-width:min(280px,100vw - 24px);animation:none;overflow:hidden}@keyframes kz2Bea_pet-bubble-pop{0%{opacity:0;transform:translateY(6px)scale(.85)}15%{opacity:1;transform:translateY(0)scale(1.05)}25%{transform:translateY(0)scale(1)}75%{opacity:1}to{opacity:0;transform:translateY(-8px)scale(.95)}}.kz2Bea_panel{color:#e2e8f0;backdrop-filter:blur(6px);background:#0f172aeb;border:1px solid #94a3b859;border-radius:10px;flex-direction:column;gap:6px;min-width:132px;padding:8px 10px;font-size:12px;display:flex;position:absolute;bottom:100%;box-shadow:0 4px 16px #00000059}.kz2Bea_panel:after{content:\"\";height:14px;position:absolute;top:100%;left:0;right:0}.kz2Bea_rankRow{white-space:nowrap;justify-content:space-between;gap:10px;display:flex}.kz2Bea_nameCell{font-weight:600}.kz2Bea_renameRow{align-items:center;gap:6px;display:flex}.kz2Bea_nameInput{color:#e2e8f0;background:#1e293be6;border:1px solid #7dd3fc80;border-radius:6px;outline:none;flex:1;min-width:0;padding:3px 6px;font-size:12px}.kz2Bea_nameInput:focus{border-color:#38bdf8;box-shadow:0 0 0 2px #38bdf873}.kz2Bea_actions{gap:6px;display:flex}.kz2Bea_action{cursor:pointer;color:#0f172a;background:linear-gradient(#7dd3fc,#38bdf8);border:none;border-radius:6px;flex:1;padding:4px 8px;font-size:12px;transition:filter .12s,box-shadow .12s}.kz2Bea_action:hover{filter:brightness(1.08)}.kz2Bea_action:active{filter:brightness(.94)}.kz2Bea_action:focus-visible{outline:none;box-shadow:0 0 0 2px #38bdf8d9}.kz2Bea_summon{color:#7dd3fc;cursor:pointer;background:#0f172abf;border:1px dashed #7dd3fc99;border-radius:999px;padding:2px 10px;font-size:11px;transition:border-color .12s,color .12s,background .12s,box-shadow .12s}.kz2Bea_summon:hover{color:#bae6fd;background:#0f172ae6;border-color:#7dd3fcf2}.kz2Bea_summon:active{color:#7dd3fc;border-color:#7dd3fccc}.kz2Bea_summon:focus-visible{outline:none;box-shadow:0 0 0 2px #38bdf8d9}@media (prefers-reduced-motion:reduce){.kz2Bea_bubble{opacity:1;animation:none}.kz2Bea_action,.kz2Bea_summon{transition:none}}";
|
|
309
309
|
const tagId$1 = "@linxin666/dsh-pet/pet.module.css";
|
|
310
310
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
|
|
311
311
|
const tag = document.createElement("style");
|
|
@@ -320,6 +320,7 @@ window.__ModuleLoader__.load({
|
|
|
320
320
|
"bubble": "kz2Bea_bubble",
|
|
321
321
|
"bubbleFeed": "kz2Bea_bubbleFeed",
|
|
322
322
|
"bubblePet": "kz2Bea_bubblePet",
|
|
323
|
+
"bubbleStatus": "kz2Bea_bubbleStatus",
|
|
323
324
|
"float": "kz2Bea_float",
|
|
324
325
|
"nameCell": "kz2Bea_nameCell",
|
|
325
326
|
"nameInput": "kz2Bea_nameInput",
|
|
@@ -487,6 +488,7 @@ window.__ModuleLoader__.load({
|
|
|
487
488
|
};
|
|
488
489
|
const spriteWidth = Math.round(192 * spriteScale);
|
|
489
490
|
const spriteHeight = Math.round(208 * spriteScale);
|
|
491
|
+
const statusBubble = feedback === null && !hovered ? snapshot?.bubble : void 0;
|
|
490
492
|
return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
491
493
|
ref: floatRef,
|
|
492
494
|
className: pet_module_css_default.float,
|
|
@@ -532,6 +534,12 @@ window.__ModuleLoader__.load({
|
|
|
532
534
|
className: `${pet_module_css_default.bubble} ${feedback.kind === "feed" ? pet_module_css_default.bubbleFeed : pet_module_css_default.bubblePet}`,
|
|
533
535
|
children: feedback.text
|
|
534
536
|
}, feedback.at),
|
|
537
|
+
statusBubble !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
538
|
+
className: `${pet_module_css_default.bubble} ${pet_module_css_default.bubbleStatus}`,
|
|
539
|
+
role: "status",
|
|
540
|
+
"aria-live": "polite",
|
|
541
|
+
children: statusBubble
|
|
542
|
+
}),
|
|
535
543
|
hovered && dragRef.current === null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
536
544
|
className: pet_module_css_default.panel,
|
|
537
545
|
onPointerEnter: () => {
|