@linxin666/dsh-pet 0.4.5 → 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 +28 -2
- package/README.zh.md +28 -2
- package/lib/client.js +76 -39
- package/lib/client.js.map +1 -1
- package/lib/index.js +280 -25
- 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.map +1 -1
- package/lib/types/client/index.js +42 -10
- 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 +15 -2
- 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 +151 -19
- 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 +74 -4
- package/src/client/index.ts +42 -10
- package/src/client/locales.ts +4 -0
- package/src/index.test.ts +22 -0
- package/src/index.ts +28 -2
- package/src/panel-actions.test.ts +130 -0
- package/src/panel-actions.ts +182 -0
- package/src/routes.ts +9 -0
- package/src/service.test.ts +128 -0
- package/src/service.ts +206 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAO9C,+CAA+C;AAC/C,eAAO,MAAM,cAAc,aAAa,CAAA;AAExC,0EAA0E;AAC1E,eAAO,MAAM,gBAAgB,SAAS,CAAA;AAMtC;;;;GAIG;AACH,eAAO,MAAM,cAAc;IACzB,yBAAyB;;IAEzB,iDAAiD;;IAEjD,8EAA8E;;CAEtE,CAAA;AAEV,6DAA6D;AAC7D,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAsBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAcrF;AAqPD,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,QAA8B,CAAA;AAe7D,4EAA4E;AAC5E,eAAO,MAAM,eAAe,QAAmB,CAAA;AAE/C,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC9B,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AA4MD,4EAA4E;AAC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O,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,YAAY,CAAA;CAAE,GAAG,eAAe,GAAG,QAAQ,EAAE,CAgGjI;AAGD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA"}
|
package/lib/types/routes.js
CHANGED
|
@@ -598,6 +598,16 @@ export function makePetRoutes(deps) {
|
|
|
598
598
|
return Promise.reject(new Error('invalid-pet'));
|
|
599
599
|
return service.setPetId(petId);
|
|
600
600
|
}),
|
|
601
|
+
// Hover-panel action click (issue #6): the browser half owns no plugin
|
|
602
|
+
// callbacks, so a click on a registered action travels back here and the
|
|
603
|
+
// service dispatches it to the plugin that registered it. Same loopback /
|
|
604
|
+
// paired-device guard as every other endpoint in this family.
|
|
605
|
+
postRoute(ctx, PET_API_PREFIX + '/panel-action', (body) => {
|
|
606
|
+
const id = body.id;
|
|
607
|
+
if (typeof id !== 'string')
|
|
608
|
+
return Promise.reject(new Error('invalid-panel-action'));
|
|
609
|
+
return service.selectPanelAction(id);
|
|
610
|
+
}),
|
|
601
611
|
// Gameplay verbs (miku-pet generalization): touch rolls a named zone's
|
|
602
612
|
// branch; the omitted-zone form is the plain-click boost during a touch
|
|
603
613
|
// animation. Mode/tick/buy drive the work, sleep and shop loops.
|
package/lib/types/service.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type { AffinityConfig, PetAffinityView, PetInteraction } from './affinity
|
|
|
16
16
|
import { type PetAnnouncement } from './announce.ts';
|
|
17
17
|
import type { TreatConfig } from './treats.ts';
|
|
18
18
|
import { type LedgerInteractionResult } from './ledger.ts';
|
|
19
|
+
import { type PetPanelActionRegistration, type PetPanelActionView } from './panel-actions.ts';
|
|
19
20
|
import { type PetDisplayConfig } from './persist.ts';
|
|
20
21
|
import { type PetDefinition, type PetManifest, type PetRegistry, type PetRegistryDiagnostic } from './registry.ts';
|
|
21
22
|
import type { DecorationView } from './contracts/status-decoration.ts';
|
|
@@ -34,6 +35,8 @@ export interface PetConfig {
|
|
|
34
35
|
enabled?: boolean;
|
|
35
36
|
/** Status-decoration master switch (pet-center M5, #567); defaults to on. */
|
|
36
37
|
decorationEnabled?: boolean;
|
|
38
|
+
/** Whether the pet's own session/status bubbles render (issue #6); defaults to 'auto'. */
|
|
39
|
+
statusBubbles?: PetStatusBubbleMode;
|
|
37
40
|
/** Prebuilt registry (tests); defaults to scanning the package + user dirs. */
|
|
38
41
|
registry?: PetRegistry;
|
|
39
42
|
/** Extra manifest entries composed by the embedding application. */
|
|
@@ -66,7 +69,31 @@ export interface PetSettingsSection {
|
|
|
66
69
|
* the settings surface mirrors this field and can turn it off.
|
|
67
70
|
*/
|
|
68
71
|
decorationEnabled?: boolean;
|
|
72
|
+
/** Whether the pet's own session/status bubbles render (issue #6). */
|
|
73
|
+
statusBubbles?: PetStatusBubbleMode;
|
|
69
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Whether the pet renders its own session/status bubbles (issue #6).
|
|
77
|
+
*
|
|
78
|
+
* `auto` is the shipped behavior: every active session keeps a bubble, and a
|
|
79
|
+
* sibling plugin's announcement bubble rides the same stack above them. `off`
|
|
80
|
+
* hides ONLY the pet's own bubbles — the announcement bubble, the interaction
|
|
81
|
+
* feedback bubble and the sprite itself are untouched — which is what a plugin
|
|
82
|
+
* that drives its own bubble surface needs. Anything unknown resolves to
|
|
83
|
+
* `auto`, so an older profile or a hand-edited settings document keeps the
|
|
84
|
+
* status bubbles rather than losing them silently.
|
|
85
|
+
*/
|
|
86
|
+
export type PetStatusBubbleMode = 'auto' | 'off';
|
|
87
|
+
/** Every accepted {@link PetStatusBubbleMode}, in settings-card order. */
|
|
88
|
+
export declare const STATUS_BUBBLE_MODES: readonly PetStatusBubbleMode[];
|
|
89
|
+
/** The shipped default; the switch changes nothing until a user turns it off. */
|
|
90
|
+
export declare const DEFAULT_STATUS_BUBBLE_MODE: PetStatusBubbleMode;
|
|
91
|
+
/**
|
|
92
|
+
* Normalize a stored, live or hand-edited bubble mode.
|
|
93
|
+
* @param value - the value the settings document carries, when any.
|
|
94
|
+
* @returns the effective mode; anything but 'off' renders the bubbles.
|
|
95
|
+
*/
|
|
96
|
+
export declare function statusBubbleMode(value: unknown): PetStatusBubbleMode;
|
|
70
97
|
/** Settings namespace of the pet capability. Spelled here rather than imported: the browser half spells the same value. */
|
|
71
98
|
export declare const PET_SETTINGS_NAMESPACE = "pet";
|
|
72
99
|
/**
|
|
@@ -145,11 +172,36 @@ export interface PetStateView {
|
|
|
145
172
|
*/
|
|
146
173
|
gameplay?: PetGameplayStateView;
|
|
147
174
|
/**
|
|
148
|
-
* The freshest plugin-authored announcement
|
|
149
|
-
*
|
|
150
|
-
*
|
|
175
|
+
* The freshest plugin-authored announcement, within its TTL; absent when none
|
|
176
|
+
* is fresh. Rendered as a dedicated styled bubble above the session stack.
|
|
177
|
+
*
|
|
178
|
+
* Kept alongside `announcements` with exactly the meaning it had when the
|
|
179
|
+
* contract had a single slot, so a browser half predating the per-source
|
|
180
|
+
* upgrade keeps rendering one bubble instead of none (issue #1812). New
|
|
181
|
+
* readers should use `announcements`.
|
|
151
182
|
*/
|
|
152
183
|
announcement?: PetAnnouncement;
|
|
184
|
+
/**
|
|
185
|
+
* Every fresh plugin-authored announcement, one per publishing plugin, in
|
|
186
|
+
* render order (issue #1812). Absent when nothing is fresh, so a host with no
|
|
187
|
+
* publisher serves exactly what it served before the upgrade.
|
|
188
|
+
*/
|
|
189
|
+
announcements?: PetAnnouncement[];
|
|
190
|
+
/**
|
|
191
|
+
* Whether the pet's own session/status bubbles render (issue #6). Absent
|
|
192
|
+
* on a host that predates the switch, which the browser half reads as
|
|
193
|
+
* `'auto'` — the behavior that shipped before it existed. Turning it to
|
|
194
|
+
* `'off'` hides those bubbles only; `announcement` and `bubble` (the
|
|
195
|
+
* legacy single status bubble) are still served, so the wire contract does
|
|
196
|
+
* not change with the display preference.
|
|
197
|
+
*/
|
|
198
|
+
statusBubbles?: PetStatusBubbleMode;
|
|
199
|
+
/**
|
|
200
|
+
* Actions a sibling plugin registered into the hover panel's action row
|
|
201
|
+
* (issue #6), in render order. Absent when none is registered, so the
|
|
202
|
+
* panel row is exactly what it was before the extension point existed.
|
|
203
|
+
*/
|
|
204
|
+
panelActions?: PetPanelActionView[];
|
|
153
205
|
}
|
|
154
206
|
/** Result of `pet.interact`. */
|
|
155
207
|
export type PetInteractResult = LedgerInteractionResult;
|
|
@@ -199,8 +251,17 @@ export declare class PetService extends Service {
|
|
|
199
251
|
private enabled;
|
|
200
252
|
/** Status-decoration master switch (M5, #567); mirrored from settings. */
|
|
201
253
|
private decorationEnabled;
|
|
202
|
-
/**
|
|
203
|
-
private
|
|
254
|
+
/** Whether the pet renders its own session/status bubbles (issue #6). */
|
|
255
|
+
private statusBubbles;
|
|
256
|
+
/**
|
|
257
|
+
* Plugin-authored announcements, one slot per `source` (issue #1812). The
|
|
258
|
+
* contract started as a single slot, where a second announcing plugin
|
|
259
|
+
* displaced the first; the map is the upgrade the design note predicted for
|
|
260
|
+
* exactly this moment. Insertion order is the render order and re-announcing
|
|
261
|
+
* a source updates its entry in place, so two publishers on different
|
|
262
|
+
* cadences never swap positions.
|
|
263
|
+
*/
|
|
264
|
+
private readonly announcements;
|
|
204
265
|
private disposeActivity;
|
|
205
266
|
/** Session whose most recent meaningful event currently drives the global pet. */
|
|
206
267
|
private displaySession;
|
|
@@ -216,6 +277,13 @@ export declare class PetService extends Service {
|
|
|
216
277
|
* disposed sessions are removed by the 'session/disposed' listener.
|
|
217
278
|
*/
|
|
218
279
|
private readonly sessionActivity;
|
|
280
|
+
/**
|
|
281
|
+
* Hover-panel actions registered by sibling plugins (issue #6). The pet owns
|
|
282
|
+
* the panel row and serves the registrations; each plugin owns the callback a
|
|
283
|
+
* click dispatches to. Bounded, in-memory, reclaimed with the registering
|
|
284
|
+
* plugin's disposer.
|
|
285
|
+
*/
|
|
286
|
+
private readonly panelActions;
|
|
219
287
|
/**
|
|
220
288
|
* Sessions whose reward source is the official event stream. This metadata
|
|
221
289
|
* outlives transient visual resets so a derived legacy `done` cannot reward
|
|
@@ -240,17 +308,77 @@ export declare class PetService extends Service {
|
|
|
240
308
|
private voicePools;
|
|
241
309
|
/** Whether the pet service consumes session activity while enabled. */
|
|
242
310
|
isEnabled(): boolean;
|
|
311
|
+
/**
|
|
312
|
+
* The remark layers one pet contributes to the ledger: its manifest pools
|
|
313
|
+
* first, then the voice packs (a pet directory's voice.json over the global
|
|
314
|
+
* `$DSH_HOME/pets/.voice.json`). Every path that seats the ledger's remark
|
|
315
|
+
* pools resolves them here, so no call site can apply the manifest pools and
|
|
316
|
+
* silently drop the voice layer: doing that reverted a pet whose lines a voice
|
|
317
|
+
* pack had translated back to the built-in pools the moment the settings
|
|
318
|
+
* surface applied.
|
|
319
|
+
* @param entry - the pet whose remark pools apply.
|
|
320
|
+
* @returns the layers `PetLedger.setRemarks` takes.
|
|
321
|
+
*/
|
|
322
|
+
private remarkLayers;
|
|
323
|
+
/** Re-seat the ledger's remark pools from one pet's layers. */
|
|
324
|
+
private applyRemarks;
|
|
243
325
|
/** RPC: current pet state snapshot. */
|
|
244
326
|
state(currentSessionId?: string): Promise<PetStateView>;
|
|
245
327
|
/**
|
|
246
|
-
* RPC: one plugin-authored announcement bubble
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
328
|
+
* RPC: one plugin-authored announcement bubble, held in the publisher's own
|
|
329
|
+
* slot keyed by `source` (issue #1812). The payload is validated into a
|
|
330
|
+
* bounded PetAnnouncement; a malformed one is dropped silently — a sibling
|
|
331
|
+
* plugin's bug must never surface as pet breakage. Re-announcing replaces
|
|
332
|
+
* only the caller's own slot, so publishers coexist instead of displacing
|
|
333
|
+
* each other. Announcements are in-memory only.
|
|
334
|
+
*
|
|
335
|
+
* The slot table is bounded by {@link MAX_ANNOUNCEMENTS}. Expired entries are
|
|
336
|
+
* pruned first, so a silent publisher never holds a slot; when the table is
|
|
337
|
+
* genuinely full, the entry that has been silent longest gives up its slot
|
|
338
|
+
* to the arriving one — a publisher that keeps refreshing is never evicted.
|
|
250
339
|
*/
|
|
251
340
|
announce(input: unknown): {
|
|
252
341
|
ok: boolean;
|
|
253
342
|
};
|
|
343
|
+
/**
|
|
344
|
+
* The announcement slots still fresh, in render order. An expired entry
|
|
345
|
+
* simply stops appearing (the client's 2 s poll drops it); no timer owns its
|
|
346
|
+
* removal.
|
|
347
|
+
*/
|
|
348
|
+
private freshAnnouncements;
|
|
349
|
+
/**
|
|
350
|
+
* Register one action into the hover panel's action row (issue #6). The pet
|
|
351
|
+
* renders the button and dispatches the click back to `onSelect`; the plugin
|
|
352
|
+
* decides what the button does. Registering is a wiring step, so a malformed
|
|
353
|
+
* registration throws at the caller's own apply instead of being dropped.
|
|
354
|
+
*
|
|
355
|
+
* The registration is reclaimed by the disposer, so the idiomatic call binds
|
|
356
|
+
* it to the registering plugin's fiber:
|
|
357
|
+
* ```ts
|
|
358
|
+
* ctx.effect(() => ctx.pet.registerPanelAction({
|
|
359
|
+
* id: 'pet-quota-swap',
|
|
360
|
+
* label: '换装',
|
|
361
|
+
* onSelect: async () => { await cycleToNextPet(ctx.pet) },
|
|
362
|
+
* }))
|
|
363
|
+
* ```
|
|
364
|
+
* @param action - the registration to serve in the panel row.
|
|
365
|
+
* @returns a disposer that removes this registration.
|
|
366
|
+
* @throws when the id, label or callback is unusable, or the row is full.
|
|
367
|
+
*/
|
|
368
|
+
registerPanelAction(action: PetPanelActionRegistration): () => void;
|
|
369
|
+
/**
|
|
370
|
+
* RPC: dispatch one hover-panel action click back to the plugin that
|
|
371
|
+
* registered it. A rejected id is a stale click (the plugin disposed its
|
|
372
|
+
* registration between render and click), and a throwing callback is that
|
|
373
|
+
* plugin's own failure — neither may surface as pet breakage, so both answer
|
|
374
|
+
* `{ ok: false }` instead of throwing out of the route.
|
|
375
|
+
* @param id - the action id the browser half reported.
|
|
376
|
+
* @returns whether the click reached a registered action.
|
|
377
|
+
*/
|
|
378
|
+
selectPanelAction(id: string): Promise<{
|
|
379
|
+
ok: boolean;
|
|
380
|
+
error?: string;
|
|
381
|
+
}>;
|
|
254
382
|
/** Current persisted display config (read-only view). */
|
|
255
383
|
display(): PetDisplayConfig;
|
|
256
384
|
/** RPC: the registry entries the browser half renders and selects from. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGtD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACpF,OAAO,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGtD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACpF,OAAO,EAA2D,KAAK,eAAe,EAAE,MAAM,eAAe,CAAA;AAC7G,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAS9C,OAAO,EAAgC,KAAK,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACxF,OAAO,EAAuB,KAAK,0BAA0B,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAClH,OAAO,EAWL,KAAK,gBAAgB,EACtB,MAAM,cAAc,CAAA;AACrB,OAAO,EAML,KAAK,aAAa,EAElB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAA;AAItB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAGL,KAAK,cAAc,EAEnB,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAA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C;QAAC,OAAO,EAAE,gBAAgB,CAAA;KAAE,CAAC;IAYnG,2EAA2E;IACrE,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,EAAE,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAS/F;;;;;OAKG;IACH,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IA4BvD,oFAAoF;IACpF,OAAO,CAAC,mBAAmB;IAgB3B,qFAAqF;IACrF,OAAO,CAAC,UAAU;IAIlB,8EAA8E;IAC9E,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,IAAI;IAkGZ,OAAO,CAAC,KAAK;CAOd"}
|
package/lib/types/service.js
CHANGED
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
* @module @linxin666/dsh-pet/service
|
|
13
13
|
*/
|
|
14
14
|
import { Service } from '@deepseek-ai/cordis';
|
|
15
|
-
import { announcementFresh, parseAnnouncement } from "./announce.js";
|
|
15
|
+
import { announcementFresh, MAX_ANNOUNCEMENTS, parseAnnouncement } from "./announce.js";
|
|
16
16
|
import { emptyProjectionRuntime, isActivityPhase, projectAssistantStreamFrame, projectOfficialEvent, } from "./event-projection.js";
|
|
17
17
|
import { PetLedger } from "./ledger.js";
|
|
18
|
+
import { PanelActionRegistry } from "./panel-actions.js";
|
|
18
19
|
import { DEFAULT_PET_NAME, DISPLAY_INSET_MAX, DISPLAY_SIZE_MAX, BUBBLE_SCALE_MAX, BUBBLE_SCALE_MIN, DISPLAY_SIZE_MIN, PET_NAME_MAX_LENGTH, loadPetPersist, petHomeDir, savePetPersist, } from "./persist.js";
|
|
19
20
|
import { DEFAULT_DECORATION_ID, decorationView, loadPetRegistry, petEntryView, petPackageRoot, } from "./registry.js";
|
|
20
21
|
import { WHISPER_TTL_MS } from "./chatter.js";
|
|
@@ -23,6 +24,18 @@ import { defaultPetStateConfig, PetStateMachine, } from "./state.js";
|
|
|
23
24
|
import { applyGameplayEffects, drawLotteryTier, initialGameplayState, isDeclaredMode, rollTouchBranch, rollWorkOutcome, settleGameplay, } from "./gameplay.js";
|
|
24
25
|
/** The unified gameplay currency: the shared treat (小鱼干) ledger. */
|
|
25
26
|
const GAMEPLAY_TREATS_CURRENCY = 'treats';
|
|
27
|
+
/** Every accepted {@link PetStatusBubbleMode}, in settings-card order. */
|
|
28
|
+
export const STATUS_BUBBLE_MODES = ['auto', 'off'];
|
|
29
|
+
/** The shipped default; the switch changes nothing until a user turns it off. */
|
|
30
|
+
export const DEFAULT_STATUS_BUBBLE_MODE = 'auto';
|
|
31
|
+
/**
|
|
32
|
+
* Normalize a stored, live or hand-edited bubble mode.
|
|
33
|
+
* @param value - the value the settings document carries, when any.
|
|
34
|
+
* @returns the effective mode; anything but 'off' renders the bubbles.
|
|
35
|
+
*/
|
|
36
|
+
export function statusBubbleMode(value) {
|
|
37
|
+
return value === 'off' ? 'off' : DEFAULT_STATUS_BUBBLE_MODE;
|
|
38
|
+
}
|
|
26
39
|
/** Settings namespace of the pet capability. Spelled here rather than imported: the browser half spells the same value. */
|
|
27
40
|
export const PET_SETTINGS_NAMESPACE = 'pet';
|
|
28
41
|
/** Hard cap on simultaneously displayed session bubbles (most recent first). */
|
|
@@ -43,8 +56,17 @@ export class PetService extends Service {
|
|
|
43
56
|
enabled;
|
|
44
57
|
/** Status-decoration master switch (M5, #567); mirrored from settings. */
|
|
45
58
|
decorationEnabled;
|
|
46
|
-
/**
|
|
47
|
-
|
|
59
|
+
/** Whether the pet renders its own session/status bubbles (issue #6). */
|
|
60
|
+
statusBubbles;
|
|
61
|
+
/**
|
|
62
|
+
* Plugin-authored announcements, one slot per `source` (issue #1812). The
|
|
63
|
+
* contract started as a single slot, where a second announcing plugin
|
|
64
|
+
* displaced the first; the map is the upgrade the design note predicted for
|
|
65
|
+
* exactly this moment. Insertion order is the render order and re-announcing
|
|
66
|
+
* a source updates its entry in place, so two publishers on different
|
|
67
|
+
* cadences never swap positions.
|
|
68
|
+
*/
|
|
69
|
+
announcements = new Map();
|
|
48
70
|
disposeActivity;
|
|
49
71
|
/** Session whose most recent meaningful event currently drives the global pet. */
|
|
50
72
|
displaySession;
|
|
@@ -60,6 +82,13 @@ export class PetService extends Service {
|
|
|
60
82
|
* disposed sessions are removed by the 'session/disposed' listener.
|
|
61
83
|
*/
|
|
62
84
|
sessionActivity = new Map();
|
|
85
|
+
/**
|
|
86
|
+
* Hover-panel actions registered by sibling plugins (issue #6). The pet owns
|
|
87
|
+
* the panel row and serves the registrations; each plugin owns the callback a
|
|
88
|
+
* click dispatches to. Bounded, in-memory, reclaimed with the registering
|
|
89
|
+
* plugin's disposer.
|
|
90
|
+
*/
|
|
91
|
+
panelActions = new PanelActionRegistry();
|
|
63
92
|
/**
|
|
64
93
|
* Sessions whose reward source is the official event stream. This metadata
|
|
65
94
|
* outlives transient visual resets so a derived legacy `done` cannot reward
|
|
@@ -93,18 +122,17 @@ export class PetService extends Service {
|
|
|
93
122
|
persist = { ...persist, petId: this.registry.defaultEntry().id };
|
|
94
123
|
}
|
|
95
124
|
const selected = this.registry.byId(persist.petId) ?? this.registry.defaultEntry();
|
|
96
|
-
const voiceRemarks = mergeVoicePacks(this.registry.globalVoice, selected.voice)?.remarks;
|
|
97
125
|
const ledgerConfig = {
|
|
98
126
|
affinity: config.affinity,
|
|
99
127
|
treats: config.treats,
|
|
100
|
-
|
|
101
|
-
voiceRemarks,
|
|
128
|
+
...this.remarkLayers(selected),
|
|
102
129
|
};
|
|
103
130
|
this.ledger = new PetLedger(persist, ledgerConfig);
|
|
104
131
|
this.stateConfig = { ...defaultPetStateConfig, ...(config.state ?? {}) };
|
|
105
132
|
this.machine = new PetStateMachine(this.stateConfig);
|
|
106
133
|
this.enabled = config.enabled ?? true;
|
|
107
134
|
this.decorationEnabled = config.decorationEnabled ?? true;
|
|
135
|
+
this.statusBubbles = statusBubbleMode(config.statusBubbles);
|
|
108
136
|
this.syncActivity();
|
|
109
137
|
}
|
|
110
138
|
/**
|
|
@@ -127,23 +155,118 @@ export class PetService extends Service {
|
|
|
127
155
|
isEnabled() {
|
|
128
156
|
return this.enabled;
|
|
129
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* The remark layers one pet contributes to the ledger: its manifest pools
|
|
160
|
+
* first, then the voice packs (a pet directory's voice.json over the global
|
|
161
|
+
* `$DSH_HOME/pets/.voice.json`). Every path that seats the ledger's remark
|
|
162
|
+
* pools resolves them here, so no call site can apply the manifest pools and
|
|
163
|
+
* silently drop the voice layer: doing that reverted a pet whose lines a voice
|
|
164
|
+
* pack had translated back to the built-in pools the moment the settings
|
|
165
|
+
* surface applied.
|
|
166
|
+
* @param entry - the pet whose remark pools apply.
|
|
167
|
+
* @returns the layers `PetLedger.setRemarks` takes.
|
|
168
|
+
*/
|
|
169
|
+
remarkLayers(entry) {
|
|
170
|
+
return {
|
|
171
|
+
remarks: entry.remarks,
|
|
172
|
+
voiceRemarks: mergeVoicePacks(this.registry.globalVoice, entry.voice)?.remarks,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/** Re-seat the ledger's remark pools from one pet's layers. */
|
|
176
|
+
applyRemarks(entry) {
|
|
177
|
+
const layers = this.remarkLayers(entry);
|
|
178
|
+
this.ledger.setRemarks(layers.remarks, layers.voiceRemarks);
|
|
179
|
+
}
|
|
130
180
|
/** RPC: current pet state snapshot. */
|
|
131
181
|
async state(currentSessionId) {
|
|
132
182
|
return this.view(currentSessionId);
|
|
133
183
|
}
|
|
134
184
|
/**
|
|
135
|
-
* RPC: one plugin-authored announcement bubble
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
185
|
+
* RPC: one plugin-authored announcement bubble, held in the publisher's own
|
|
186
|
+
* slot keyed by `source` (issue #1812). The payload is validated into a
|
|
187
|
+
* bounded PetAnnouncement; a malformed one is dropped silently — a sibling
|
|
188
|
+
* plugin's bug must never surface as pet breakage. Re-announcing replaces
|
|
189
|
+
* only the caller's own slot, so publishers coexist instead of displacing
|
|
190
|
+
* each other. Announcements are in-memory only.
|
|
191
|
+
*
|
|
192
|
+
* The slot table is bounded by {@link MAX_ANNOUNCEMENTS}. Expired entries are
|
|
193
|
+
* pruned first, so a silent publisher never holds a slot; when the table is
|
|
194
|
+
* genuinely full, the entry that has been silent longest gives up its slot
|
|
195
|
+
* to the arriving one — a publisher that keeps refreshing is never evicted.
|
|
139
196
|
*/
|
|
140
197
|
announce(input) {
|
|
141
198
|
const parsed = parseAnnouncement(input, Date.now());
|
|
142
199
|
if (parsed === undefined)
|
|
143
200
|
return { ok: false };
|
|
144
|
-
|
|
201
|
+
const now = Date.now();
|
|
202
|
+
for (const [source, entry] of this.announcements) {
|
|
203
|
+
if (!announcementFresh(entry, now))
|
|
204
|
+
this.announcements.delete(source);
|
|
205
|
+
}
|
|
206
|
+
if (!this.announcements.has(parsed.source) && this.announcements.size >= MAX_ANNOUNCEMENTS) {
|
|
207
|
+
let oldest = '';
|
|
208
|
+
let oldestAt = Number.POSITIVE_INFINITY;
|
|
209
|
+
for (const [source, entry] of this.announcements) {
|
|
210
|
+
if (entry.at < oldestAt) {
|
|
211
|
+
oldest = source;
|
|
212
|
+
oldestAt = entry.at;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (oldest !== '')
|
|
216
|
+
this.announcements.delete(oldest);
|
|
217
|
+
}
|
|
218
|
+
this.announcements.set(parsed.source, parsed);
|
|
145
219
|
return { ok: true };
|
|
146
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* The announcement slots still fresh, in render order. An expired entry
|
|
223
|
+
* simply stops appearing (the client's 2 s poll drops it); no timer owns its
|
|
224
|
+
* removal.
|
|
225
|
+
*/
|
|
226
|
+
freshAnnouncements() {
|
|
227
|
+
const now = Date.now();
|
|
228
|
+
return [...this.announcements.values()].filter(entry => announcementFresh(entry, now));
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Register one action into the hover panel's action row (issue #6). The pet
|
|
232
|
+
* renders the button and dispatches the click back to `onSelect`; the plugin
|
|
233
|
+
* decides what the button does. Registering is a wiring step, so a malformed
|
|
234
|
+
* registration throws at the caller's own apply instead of being dropped.
|
|
235
|
+
*
|
|
236
|
+
* The registration is reclaimed by the disposer, so the idiomatic call binds
|
|
237
|
+
* it to the registering plugin's fiber:
|
|
238
|
+
* ```ts
|
|
239
|
+
* ctx.effect(() => ctx.pet.registerPanelAction({
|
|
240
|
+
* id: 'pet-quota-swap',
|
|
241
|
+
* label: '换装',
|
|
242
|
+
* onSelect: async () => { await cycleToNextPet(ctx.pet) },
|
|
243
|
+
* }))
|
|
244
|
+
* ```
|
|
245
|
+
* @param action - the registration to serve in the panel row.
|
|
246
|
+
* @returns a disposer that removes this registration.
|
|
247
|
+
* @throws when the id, label or callback is unusable, or the row is full.
|
|
248
|
+
*/
|
|
249
|
+
registerPanelAction(action) {
|
|
250
|
+
return this.panelActions.register(action);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* RPC: dispatch one hover-panel action click back to the plugin that
|
|
254
|
+
* registered it. A rejected id is a stale click (the plugin disposed its
|
|
255
|
+
* registration between render and click), and a throwing callback is that
|
|
256
|
+
* plugin's own failure — neither may surface as pet breakage, so both answer
|
|
257
|
+
* `{ ok: false }` instead of throwing out of the route.
|
|
258
|
+
* @param id - the action id the browser half reported.
|
|
259
|
+
* @returns whether the click reached a registered action.
|
|
260
|
+
*/
|
|
261
|
+
async selectPanelAction(id) {
|
|
262
|
+
try {
|
|
263
|
+
const selected = await this.panelActions.select(id, { petId: this.selectedPetId() });
|
|
264
|
+
return selected ? { ok: true } : { ok: false, error: 'unknown-panel-action' };
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return { ok: false, error: 'panel-action-failed' };
|
|
268
|
+
}
|
|
269
|
+
}
|
|
147
270
|
/** Current persisted display config (read-only view). */
|
|
148
271
|
display() {
|
|
149
272
|
return { ...this.ledger.snapshot.display };
|
|
@@ -191,8 +314,7 @@ export class PetService extends Service {
|
|
|
191
314
|
if (entry === undefined)
|
|
192
315
|
return { ok: false, error: 'unknown-pet' };
|
|
193
316
|
this.ledger.setPetId(entry.id);
|
|
194
|
-
|
|
195
|
-
this.ledger.setRemarks(entry.remarks, voiceRemarks);
|
|
317
|
+
this.applyRemarks(entry);
|
|
196
318
|
this.flush();
|
|
197
319
|
this.syncSettingsFromPet();
|
|
198
320
|
return { ok: true, petId: entry.id };
|
|
@@ -594,10 +716,11 @@ export class PetService extends Service {
|
|
|
594
716
|
*/
|
|
595
717
|
applySettingsSection(section) {
|
|
596
718
|
this.decorationEnabled = section.decorationEnabled ?? true;
|
|
719
|
+
this.statusBubbles = statusBubbleMode(section.statusBubbles);
|
|
597
720
|
const selected = typeof section.petId === 'string' ? this.registry.byId(section.petId) : undefined;
|
|
598
721
|
if (selected !== undefined) {
|
|
599
722
|
this.ledger.setPetId(selected.id);
|
|
600
|
-
this.
|
|
723
|
+
this.applyRemarks(selected);
|
|
601
724
|
}
|
|
602
725
|
else if (section.petId !== undefined) {
|
|
603
726
|
// The stored selection names a pet the registry no longer has: keep the
|
|
@@ -701,12 +824,18 @@ export class PetService extends Service {
|
|
|
701
824
|
}
|
|
702
825
|
// Read-only: the ledger settles on economic events only, never on a read,
|
|
703
826
|
// so polling the state cannot trigger pet.json writes.
|
|
704
|
-
//
|
|
705
|
-
// drops it)
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
827
|
+
// One slot per publishing plugin (issue #1812); an expired entry simply
|
|
828
|
+
// stops appearing (the client's 2 s poll drops it), no timer owns removal.
|
|
829
|
+
const announcements = this.freshAnnouncements();
|
|
830
|
+
// The freshest entry keeps the pre-#1812 meaning of the singular field, so
|
|
831
|
+
// a browser half that predates the array still renders one bubble instead
|
|
832
|
+
// of none (a rolling upgrade must never blank a publisher's bubble).
|
|
833
|
+
const announcement = announcements.reduce((freshest, entry) => freshest === undefined || entry.at > freshest.at ? entry : freshest, undefined);
|
|
709
834
|
const skin = this.persistedSkin(entry);
|
|
835
|
+
// The hover panel's action row extensions (issue #6). Served on every poll
|
|
836
|
+
// so a plugin that mounts or disposes its registration shows up (or goes
|
|
837
|
+
// away) within one tick, without a separate endpoint.
|
|
838
|
+
const panelActions = this.panelActions.views();
|
|
710
839
|
return {
|
|
711
840
|
animation: snapshot.animation,
|
|
712
841
|
...(snapshot.bubble === undefined ? {} : { bubble: snapshot.bubble }),
|
|
@@ -715,6 +844,9 @@ export class PetService extends Service {
|
|
|
715
844
|
sessions,
|
|
716
845
|
...(decoration === undefined ? {} : { decoration }),
|
|
717
846
|
...(announcement === undefined ? {} : { announcement }),
|
|
847
|
+
...(announcements.length === 0 ? {} : { announcements }),
|
|
848
|
+
statusBubbles: this.statusBubbles,
|
|
849
|
+
...(panelActions.length === 0 ? {} : { panelActions }),
|
|
718
850
|
affinity: this.ledger.affinityView(Date.now()),
|
|
719
851
|
// The one place the two visibility answers are combined: the pet's own
|
|
720
852
|
// hide/show intent AND the plugin master switch. Producing the effective
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-pet",
|
|
3
3
|
"description": "Multi-pet companion plugin for the dsh web GUI: a registry-driven floating pet that reacts to model activity, with per-pet naming, petting/feeding interactions and an affinity score",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.6",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
package/src/announce.ts
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
* validates it into a bounded payload, and the browser half renders it as a
|
|
5
5
|
* dedicated, specially styled bubble above the session bubble stack.
|
|
6
6
|
*
|
|
7
|
+
* One slot per publisher (issue #1812): `source` is the slot key, so two
|
|
8
|
+
* announcing plugins coexist instead of displacing each other, and each keeps
|
|
9
|
+
* its own TTL. The single-slot contract this replaced is kept on the wire as
|
|
10
|
+
* the freshest entry, so an older browser half keeps working unchanged.
|
|
11
|
+
*
|
|
7
12
|
* The validation lives in this pure module so the wire contract has exactly
|
|
8
13
|
* one home and stays testable without the cordis service.
|
|
9
14
|
* @module @linxin666/dsh-pet/announce
|
|
@@ -36,6 +41,18 @@ export interface PetAnnouncement {
|
|
|
36
41
|
/** Default freshness window. */
|
|
37
42
|
export const ANNOUNCE_DEFAULT_TTL_MS = 10_000
|
|
38
43
|
|
|
44
|
+
/**
|
|
45
|
+
* How many publishers can hold an announcement bubble at once (issue #1812).
|
|
46
|
+
*
|
|
47
|
+
* The contract has exactly one slot per `source` — that is the whole upgrade
|
|
48
|
+
* from the single-slot design — but the pet's bubble stack is a finite column,
|
|
49
|
+
* so the table is bounded rather than open. The bound is deliberately above the
|
|
50
|
+
* realistic publisher count (a quota bubble, a balance bubble, a notification):
|
|
51
|
+
* it exists so a misbehaving publisher that rotates `source` per bubble cannot
|
|
52
|
+
* grow the pet's stack without limit.
|
|
53
|
+
*/
|
|
54
|
+
export const MAX_ANNOUNCEMENTS = 4
|
|
55
|
+
|
|
39
56
|
/**
|
|
40
57
|
* Hard TTL ceiling. A repeating announcer declares its poll cadence as
|
|
41
58
|
* the TTL, so an always-on bubble stays continuous across polls; the
|
|
@@ -41,6 +41,12 @@ export interface PetInjected {
|
|
|
41
41
|
dragEnd: (right: number, bottom: number) => void
|
|
42
42
|
/** Rename the selected pet (persisted by the host). */
|
|
43
43
|
rename: (name: string) => void
|
|
44
|
+
/**
|
|
45
|
+
* Report a click on one plugin-registered panel action (issue #6). The host
|
|
46
|
+
* dispatches it to the plugin that registered the action; the panel itself
|
|
47
|
+
* only renders the button the state snapshot served.
|
|
48
|
+
*/
|
|
49
|
+
panelAction: (id: string) => void
|
|
44
50
|
/** Navigate the GUI to the session a bubble reports on. */
|
|
45
51
|
openSession: (sessionId: string) => void
|
|
46
52
|
/** Clear the reaction bubble. */
|
|
@@ -116,6 +122,7 @@ export function PetDockEntry(props: PetDockEntryProps): ReactElement {
|
|
|
116
122
|
onHide={props.hide}
|
|
117
123
|
onDragEnd={props.dragEnd}
|
|
118
124
|
onRename={props.rename}
|
|
125
|
+
onPanelAction={props.panelAction}
|
|
119
126
|
onOpenSession={props.openSession}
|
|
120
127
|
onFeedbackDone={props.feedbackDone}
|
|
121
128
|
portalTarget={props.portalTarget}
|