@linxin666/dsh-pet 0.1.13 → 0.1.15
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 +38 -17
- package/lib/client.js.map +1 -1
- package/lib/index.js +393 -150
- package/lib/invariant.js +1 -1
- package/lib/{state-C9EyycwI.js → state-CFyJv0sQ.js} +22 -7
- package/lib/types/affinity.d.ts +15 -0
- package/lib/types/affinity.d.ts.map +1 -1
- package/lib/types/affinity.js +14 -0
- package/lib/types/client/PluginSettingsCard.d.ts +26 -11
- package/lib/types/client/PluginSettingsCard.d.ts.map +1 -1
- package/lib/types/client/PluginSettingsCard.js +27 -7
- package/lib/types/client/WhalePet.d.ts.map +1 -1
- package/lib/types/client/WhalePet.js +2 -1
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/index.js +3 -3
- package/lib/types/client/settings-form.d.ts +14 -5
- package/lib/types/client/settings-form.d.ts.map +1 -1
- package/lib/types/client/settings-form.js +38 -10
- package/lib/types/dsh-home.d.ts +17 -0
- package/lib/types/dsh-home.d.ts.map +1 -0
- package/lib/types/dsh-home.js +34 -0
- package/lib/types/event-projection.d.ts +36 -0
- package/lib/types/event-projection.d.ts.map +1 -0
- package/lib/types/event-projection.js +98 -0
- package/lib/types/ledger.d.ts +77 -0
- package/lib/types/ledger.d.ts.map +1 -0
- package/lib/types/ledger.js +139 -0
- package/lib/types/persist.d.ts +5 -1
- package/lib/types/persist.d.ts.map +1 -1
- package/lib/types/persist.js +7 -3
- package/lib/types/service.d.ts +24 -44
- package/lib/types/service.d.ts.map +1 -1
- package/lib/types/service.js +98 -131
- 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/affinity.ts +33 -0
- package/src/client/PluginSettingsCard.tsx +83 -17
- package/src/client/WhalePet.test.tsx +25 -1
- package/src/client/WhalePet.tsx +6 -0
- package/src/client/index.ts +3 -3
- package/src/client/pet.module.css +9 -0
- package/src/client/settings-card.module.css +6 -0
- package/src/client/settings-form.ts +41 -9
- package/src/dsh-home.test.ts +35 -0
- package/src/dsh-home.ts +36 -0
- package/src/event-projection.ts +128 -0
- package/src/ledger.test.ts +67 -0
- package/src/ledger.ts +183 -0
- package/src/persist.ts +7 -3
- package/src/service.ts +110 -171
- package/src/state.test.ts +4 -1
- package/src/state.ts +17 -13
package/src/state.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pet state machine — pure, clock-injected. Maps
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* transitions the web UI exposes (turn end celebration, no-session idle).
|
|
2
|
+
* Pet state machine — pure, clock-injected. Maps official DSH session activity
|
|
3
|
+
* and the legacy `activity/status` vocabulary onto the 9-state Codex pet
|
|
4
|
+
* animation contract, plus turn-end celebration and no-session idle.
|
|
6
5
|
*
|
|
7
6
|
* The machine is deliberately dumb: it holds the last input phase, the
|
|
8
7
|
* animation decision, and a one-shot "celebration" window after `done` so the
|
|
@@ -11,8 +10,8 @@
|
|
|
11
10
|
* @module @linxin666/dsh-pet/state
|
|
12
11
|
*/
|
|
13
12
|
|
|
14
|
-
/**
|
|
15
|
-
export type ActivityPhase = 'idle' | 'waiting' | 'thinking' | 'tool' | 'done'
|
|
13
|
+
/** Activity phases understood by the pet host. */
|
|
14
|
+
export type ActivityPhase = 'idle' | 'waiting' | 'thinking' | 'tool' | 'review' | 'done' | 'failed'
|
|
16
15
|
|
|
17
16
|
/** The Codex-compatible 9-state animation contract (spritesheet rows). */
|
|
18
17
|
export type PetAnimation =
|
|
@@ -28,7 +27,7 @@ export type PetAnimation =
|
|
|
28
27
|
|
|
29
28
|
/** One input snapshot consumed by the machine. */
|
|
30
29
|
export interface PetStateInput {
|
|
31
|
-
/** Current
|
|
30
|
+
/** Current activity phase of the active session. */
|
|
32
31
|
phase: ActivityPhase
|
|
33
32
|
/** Human-readable status line (plain text). */
|
|
34
33
|
line?: string
|
|
@@ -60,20 +59,21 @@ export const defaultPetStateConfig: PetStateConfig = { celebrateMs: 2400 }
|
|
|
60
59
|
|
|
61
60
|
/**
|
|
62
61
|
* Map one activity phase onto the animation contract.
|
|
63
|
-
* - thinking
|
|
64
|
-
*
|
|
62
|
+
* - thinking → `running` and tool → `running-right` (focused work).
|
|
63
|
+
* - review → `review` while answer text is streaming.
|
|
65
64
|
* - waiting → `waiting` (expectant pose, needs user input).
|
|
66
65
|
* - done → `jumping` (celebration), then back to `idle` after the window.
|
|
66
|
+
* - failed → `failed` until another activity event arrives.
|
|
67
67
|
* - idle → `idle` (calm breathing loop).
|
|
68
|
-
* `failed` has no DSH phase source yet; the machine keeps the mapping table
|
|
69
|
-
* so a future error event can light it up.
|
|
70
68
|
*/
|
|
71
69
|
export function animationForPhase(phase: ActivityPhase): PetAnimation {
|
|
72
70
|
switch (phase) {
|
|
73
71
|
case 'thinking': return 'running'
|
|
74
72
|
case 'tool': return 'running-right'
|
|
73
|
+
case 'review': return 'review'
|
|
75
74
|
case 'waiting': return 'waiting'
|
|
76
75
|
case 'done': return 'jumping'
|
|
76
|
+
case 'failed': return 'failed'
|
|
77
77
|
case 'idle': return 'idle'
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -110,7 +110,7 @@ export class PetStateMachine {
|
|
|
110
110
|
private readonly now: () => number = Date.now,
|
|
111
111
|
) {}
|
|
112
112
|
|
|
113
|
-
/** Consume one
|
|
113
|
+
/** Consume one projected activity update. */
|
|
114
114
|
onActivityStatus(input: PetStateInput): void {
|
|
115
115
|
this.phase = input.phase
|
|
116
116
|
this.line = input.line
|
|
@@ -144,7 +144,11 @@ export class PetStateMachine {
|
|
|
144
144
|
animation = 'idle'
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
-
const bubble = this.
|
|
147
|
+
const bubble = this.phase === 'done'
|
|
148
|
+
&& this.doneAt !== undefined
|
|
149
|
+
&& nowMs - this.doneAt >= this.config.celebrateMs
|
|
150
|
+
? undefined
|
|
151
|
+
: this.phrase ?? this.line
|
|
148
152
|
return {
|
|
149
153
|
animation,
|
|
150
154
|
...(bubble === undefined ? {} : { bubble }),
|