@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
|
@@ -38,6 +38,13 @@ export interface PetSpriteProps {
|
|
|
38
38
|
onDraggingChange?: (dragging: boolean) => void;
|
|
39
39
|
/** Rename the selected pet (persisted by the host). */
|
|
40
40
|
onRename: (name: string) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Report a click on one plugin-registered action (issue #6). The buttons
|
|
43
|
+
* themselves come from the state snapshot's `panelActions` slice, so the
|
|
44
|
+
* panel renders exactly the registrations the host serves and adds nothing
|
|
45
|
+
* of its own.
|
|
46
|
+
*/
|
|
47
|
+
onPanelAction: (id: string) => void;
|
|
41
48
|
/** Navigate to the session one status bubble reports on. */
|
|
42
49
|
onOpenSession: (sessionId: string) => void;
|
|
43
50
|
/** Clear the reaction bubble (after its CSS animation). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PetSprite.d.ts","sourceRoot":"","sources":["../../../src/client/PetSprite.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAkE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAGnH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AACnE,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAGpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAIjD,OAAO,EAAE,EAAE,EAAE,MAAM,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AC7E,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;IAC9C,uDAAuD;IACvD,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC;;;;;OAKG;IACH,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,4DAA4D;IAC5D,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1C,2DAA2D;IAC3D,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB;;;;OAIG;IACH,GAAG,CAAC,EAAE,SAAS,CAAA;IACf;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9D;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAC3B,qEAAqE;IACrE,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;OAGG;IACH,GAAG,CAAC,EAAE,WAAW,CAAA;IACjB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,+CAA+C;IAC/C,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC,CAAA;CAC1B;AAkJD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,WAAW,CA8tB5D"}
|
|
@@ -507,20 +507,30 @@ export function PetSprite(props) {
|
|
|
507
507
|
// is hovered/pinned open. The legacy single 'bubble' is the fallback when
|
|
508
508
|
// the host serves no per-session list. The hover panel normally sits below
|
|
509
509
|
// the sprite, so the bubbles stay visible and clickable — no region swap.
|
|
510
|
-
|
|
510
|
+
// Whether the pet renders its OWN session/status bubbles (issue #6). Only
|
|
511
|
+
// these are gated: the interaction feedback bubble and a sibling plugin's
|
|
512
|
+
// announcement bubble are separate surfaces and keep rendering, so a plugin
|
|
513
|
+
// that drives its own bubble can switch the built-in ones off. A host that
|
|
514
|
+
// predates the field serves no mode at all, which reads as 'auto' — the
|
|
515
|
+
// behavior that shipped before the switch existed.
|
|
516
|
+
const statusBubblesOn = (snapshot?.statusBubbles ?? 'auto') !== 'off';
|
|
517
|
+
const sessionBubbles = statusBubblesOn ? (snapshot?.sessions ?? []) : [];
|
|
511
518
|
const stackOpen = stackPeek || stackPinned;
|
|
512
519
|
const collapsed = !stackOpen && sessionBubbles.length > 1;
|
|
513
520
|
const visibleSessions = collapsed ? sessionBubbles.slice(0, 1) : sessionBubbles;
|
|
514
|
-
const statusBubble = feedback === null && sessionBubbles.length === 0
|
|
521
|
+
const statusBubble = statusBubblesOn && feedback === null && sessionBubbles.length === 0
|
|
515
522
|
? snapshot?.bubble
|
|
516
523
|
: undefined;
|
|
517
|
-
// The
|
|
518
|
-
//
|
|
519
|
-
//
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
+
// The plugin-authored announcements: one dedicated, specially styled bubble
|
|
525
|
+
// per publishing plugin above the session stack (issue #1812 — the contract
|
|
526
|
+
// used to hold a single slot, so a second publisher displaced the first).
|
|
527
|
+
// The host already TTL-filters; this client-side check covers the last poll
|
|
528
|
+
// tick. A host predating the array serves the singular field only, and a
|
|
529
|
+
// browser half predating it (this file, before the upgrade) renders the same
|
|
530
|
+
// one bubble, so neither side of a rolling upgrade loses a publisher.
|
|
531
|
+
const announced = snapshot?.announcements ?? (snapshot?.announcement !== undefined ? [snapshot.announcement] : []);
|
|
532
|
+
const now = Date.now();
|
|
533
|
+
const usageAnnouncements = feedback === null ? announced.filter(entry => announcementFresh(entry, now)) : [];
|
|
524
534
|
// Each session's inner whisper (碎碎念) rides its own bubble — short
|
|
525
535
|
// inner-voice copy woken by that session's activity, never the model's or
|
|
526
536
|
// another session's. Instead of a second bubble of its own, a fresh
|
|
@@ -528,7 +538,7 @@ export function PetSprite(props) {
|
|
|
528
538
|
// never wears two voices at once. Interaction feedback takes over the
|
|
529
539
|
// whole bubble area while it plays, so whispers yield to it like status
|
|
530
540
|
// copy.
|
|
531
|
-
const bubblePresent = feedback !== null || sessionBubbles.length > 0 || statusBubble !== undefined ||
|
|
541
|
+
const bubblePresent = feedback !== null || sessionBubbles.length > 0 || statusBubble !== undefined || usageAnnouncements.length > 0;
|
|
532
542
|
const displayName = snapshot?.name ?? definition.displayName;
|
|
533
543
|
// The host-served status decoration (M5, #567); absent = text-only bubbles.
|
|
534
544
|
const decoration = snapshot?.decoration;
|
|
@@ -615,7 +625,7 @@ export function PetSprite(props) {
|
|
|
615
625
|
}
|
|
616
626
|
}
|
|
617
627
|
props.onPet();
|
|
618
|
-
}, role: "button", "aria-label": definition.displayName, children: props.visual }) }), props.hud, feedback !== null && (_jsx("div", { ref: bubbleRef, className: clsx(styles.bubble, feedback.kind === 'feed' ? styles.bubbleFeed : styles.bubblePet), children: feedback.text }, feedback.at)), feedback === null && (sessionBubbles.length > 0 || statusBubble !== undefined ||
|
|
628
|
+
}, role: "button", "aria-label": definition.displayName, children: props.visual }) }), props.hud, feedback !== null && (_jsx("div", { ref: bubbleRef, className: clsx(styles.bubble, feedback.kind === 'feed' ? styles.bubbleFeed : styles.bubblePet), children: feedback.text }, feedback.at)), feedback === null && (sessionBubbles.length > 0 || statusBubble !== undefined || usageAnnouncements.length > 0) && (_jsxs("div", { ref: bubbleRef, className: styles.bubbleStack, onPointerEnter: () => setStackPeek(true), onPointerLeave: () => setStackPeek(false), children: [visibleSessions.map((session, index) => {
|
|
619
629
|
// A session's whisper rides ITS OWN bubble (the stack lead when
|
|
620
630
|
// the current session has one, any bubble when the stack is
|
|
621
631
|
// expanded). The key swap restarts the entrance animation so the
|
|
@@ -634,7 +644,7 @@ export function PetSprite(props) {
|
|
|
634
644
|
e.stopPropagation();
|
|
635
645
|
setStackPinned(open => !open);
|
|
636
646
|
}, children: stackOpen ? '×' : '+' + String(sessionBubbles.length - 1) })] }, "primary"));
|
|
637
|
-
}), sessionBubbles.length === 0 && statusBubble !== undefined && (_jsxs("div", { className: clsx(styles.bubble, styles.bubbleStatus), role: "status", "aria-live": "polite", children: [decoration !== undefined && (_jsx(StatusOrnament, { decoration: decoration, phase: phase })), statusBubble] }, "status")),
|
|
647
|
+
}), sessionBubbles.length === 0 && statusBubble !== undefined && (_jsxs("div", { className: clsx(styles.bubble, styles.bubbleStatus), role: "status", "aria-live": "polite", children: [decoration !== undefined && (_jsx(StatusOrnament, { decoration: decoration, phase: phase })), statusBubble] }, "status")), usageAnnouncements.map(entry => (_jsx(UsageAnnouncementBubble, { announcement: entry }, entry.source)))] })), hovered && dragRef.current === null && (_jsx("div", { ref: panelRef, className: clsx(styles.panel, panelAbove && styles.panelAbove), "data-placement": panelAbove ? 'above' : 'below', style: panelAbove && panelLift > 0
|
|
638
648
|
? { marginBottom: panelLift }
|
|
639
649
|
: undefined, onPointerEnter: () => {
|
|
640
650
|
// Reaching the panel (or its bridge) must cancel any hide timer
|
|
@@ -678,6 +688,6 @@ export function PetSprite(props) {
|
|
|
678
688
|
clearHideTimer();
|
|
679
689
|
setNameDraft(displayName);
|
|
680
690
|
setRenaming(true);
|
|
681
|
-
}, children: panelLabel('rename', props.t('pet.rename')) })), panelShows('hide') && (_jsx("button", { type: "button", className: styles.action, onClick: props.onHide, children: panelLabel('hide', props.t('pet.hide')) })), props.onGameplayMenu !== undefined && (_jsx("button", { type: "button", className: styles.action, onClick: props.onGameplayMenu, children: props.t('pet.gameplay.menu') }))] })] })) }))] }));
|
|
691
|
+
}, children: panelLabel('rename', props.t('pet.rename')) })), panelShows('hide') && (_jsx("button", { type: "button", className: styles.action, onClick: props.onHide, children: panelLabel('hide', props.t('pet.hide')) })), props.onGameplayMenu !== undefined && (_jsx("button", { type: "button", className: styles.action, onClick: props.onGameplayMenu, children: props.t('pet.gameplay.menu') })), (snapshot?.panelActions ?? []).map(action => (_jsx("button", { type: "button", className: styles.action, "data-dsh-pet-panel-action": action.id, ...(action.title === undefined ? {} : { title: action.title }), onClick: () => { props.onPanelAction(action.id); }, children: action.label }, action.id)))] })] })) }))] }));
|
|
682
692
|
return createPortal(float, props.portalTarget ?? document.body);
|
|
683
693
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGnE,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,4CAA4C,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGnE,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,4CAA4C,CAAA;AAuFhG,wEAAwE;AACxE,eAAO,MAAM,MAAM,UAAwF,CAAA;AAE3G,qEAAqE;AACrE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACxE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC7D,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AACtF,YAAY,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,OAAO;QACf;;;;WAIG;QACH,aAAa,CAAC,EAAE;YACd,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE;gBAAE,SAAS,EAAE,MAAM,CAAC;gBAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,GAAG,SAAS,CAAA;aAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;SAClG,CAAA;KACF;CACF;AAUD,mFAAmF;AACnF,eAAO,MAAM,eAAe,MAAM,CAAA;AA2NlC,wBAAgB,KAAK,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CA6V9C"}
|
|
@@ -22,7 +22,7 @@ import { live2dRenderer } from "./renderers/live2d.js";
|
|
|
22
22
|
import { frames2dRenderer } from "./renderers/frames2d.js";
|
|
23
23
|
import { registerPetUiTeardown, takeoverPetUiTeardown } from "./ui-teardown.js";
|
|
24
24
|
import { PetSettingsSection, PetSettingsCardController } from "./PetSettingsCard.js";
|
|
25
|
-
import { NS, en, zh
|
|
25
|
+
import { NS, en, zh } from "./locales.js";
|
|
26
26
|
import { mainViewSessionId } from "./main-session.js";
|
|
27
27
|
import { reportDailyHeartbeat } from "./telemetry.js";
|
|
28
28
|
/** Same-origin JSON fetch helper (GET without body, POST with JSON body). */
|
|
@@ -49,6 +49,7 @@ const petApi = {
|
|
|
49
49
|
setConfig: (patch) => petFetch('/api/pet/set-config', patch),
|
|
50
50
|
setName: (name) => petFetch('/api/pet/set-name', { name }),
|
|
51
51
|
setPet: (petId) => petFetch('/api/pet/set-pet', { petId }),
|
|
52
|
+
panelAction: (id) => petFetch('/api/pet/panel-action', { id }),
|
|
52
53
|
setSkin: (skin) => petFetch('/api/pet/set-skin', skin === undefined ? {} : { skin }),
|
|
53
54
|
gameplayTouch: (zone) => petFetch('/api/pet/gameplay/touch', zone === undefined ? {} : { zone }),
|
|
54
55
|
gameplaySetMode: (mode) => petFetch('/api/pet/gameplay/mode', { mode }),
|
|
@@ -108,20 +109,27 @@ class DeferredSettingsForm {
|
|
|
108
109
|
this.ctx = ctx;
|
|
109
110
|
this.fallback = ctx.configForms.get(this.resolveFallbackEntryId());
|
|
110
111
|
// No binder yet: the aggregate publishes it after an async mount, so keep
|
|
111
|
-
// probing. A shared form that can answer for itself is adopted at
|
|
112
|
+
// probing. A shared form that can already answer for itself is adopted at
|
|
113
|
+
// once; one still loading has simply not been filled in yet.
|
|
112
114
|
if (!this.resolve() && !this.fallbackSettled())
|
|
113
115
|
this.scheduleRetry();
|
|
114
116
|
else if (this.current === undefined)
|
|
115
117
|
this.adoptFallback();
|
|
116
118
|
}
|
|
117
119
|
/**
|
|
118
|
-
* True
|
|
119
|
-
*
|
|
120
|
-
*
|
|
120
|
+
* True only once the shared mirror answers for the pet namespace itself.
|
|
121
|
+
*
|
|
122
|
+
* 'ready' is the only state that answers (#1813). A host-persisted row starts
|
|
123
|
+
* out as 'loading' — the mirror has published no view yet — and that is not
|
|
124
|
+
* an answer: adopting it on sight drops the retry window, and under the
|
|
125
|
+
* aggregate, which serves only the renamed 'web-ui-pet' row, the form then
|
|
126
|
+
* settles into 'unavailable' and the page stays "not exposed" for good. So
|
|
127
|
+
* 'loading' and 'unavailable' both keep the window open and let the binder be
|
|
128
|
+
* adopted the moment the aggregate publishes it.
|
|
121
129
|
*/
|
|
122
130
|
fallbackSettled() {
|
|
123
131
|
try {
|
|
124
|
-
return this.fallback.getSnapshot().status
|
|
132
|
+
return this.fallback.getSnapshot().status === 'ready';
|
|
125
133
|
}
|
|
126
134
|
catch {
|
|
127
135
|
return false;
|
|
@@ -178,9 +186,10 @@ class DeferredSettingsForm {
|
|
|
178
186
|
return true;
|
|
179
187
|
}
|
|
180
188
|
/**
|
|
181
|
-
* Adopt the shared per-entry form. It is used immediately unless it
|
|
182
|
-
*
|
|
183
|
-
* and the retry window takes over
|
|
189
|
+
* Adopt the shared per-entry form. It is used immediately unless it cannot
|
|
190
|
+
* answer yet (still loading, or reporting the namespace unavailable), in which
|
|
191
|
+
* case the binder may still be on its way and the retry window takes over
|
|
192
|
+
* (see scheduleRetry).
|
|
184
193
|
*/
|
|
185
194
|
adoptFallback() {
|
|
186
195
|
this.current = this.fallback;
|
|
@@ -503,6 +512,20 @@ export function apply(ctx) {
|
|
|
503
512
|
// Ignore; next poll resyncs.
|
|
504
513
|
});
|
|
505
514
|
},
|
|
515
|
+
// A panel action click (issue #6) travels back to the host, which
|
|
516
|
+
// dispatches it to the plugin that registered the action. The plugin's
|
|
517
|
+
// own callback does the work; the browser half only reports the id, and
|
|
518
|
+
// the next poll brings back whatever that callback changed. A click on
|
|
519
|
+
// an action the plugin already disposed answers { ok: false } — the
|
|
520
|
+
// button was one poll tick stale, which is not a pet failure.
|
|
521
|
+
panelAction: (id) => {
|
|
522
|
+
petApi.panelAction(id).then((result) => {
|
|
523
|
+
if (result.ok)
|
|
524
|
+
pollNow();
|
|
525
|
+
}, () => {
|
|
526
|
+
// Ignore; next poll resyncs.
|
|
527
|
+
});
|
|
528
|
+
},
|
|
506
529
|
feedbackDone: () => {
|
|
507
530
|
setFeedback(null);
|
|
508
531
|
},
|
|
@@ -557,7 +580,16 @@ export function apply(ctx) {
|
|
|
557
580
|
// root then owns the whole surface, so a root-keyed suppressor (the
|
|
558
581
|
// portrait mobile layer, which hides [data-dsh-plugin="pet"]) really
|
|
559
582
|
// hides the sprite instead of missing the portaled float.
|
|
560
|
-
|
|
583
|
+
//
|
|
584
|
+
// The floating surface has no session-scoped locale seat, so it must be
|
|
585
|
+
// handed the framework one explicitly. Resolving its copy from the
|
|
586
|
+
// plugin's own zh/en dictionary keyed on <html lang> sent every
|
|
587
|
+
// registered language except English to Chinese: a ru/ja/de page showed a
|
|
588
|
+
// Chinese panel while the settings card beside it was translated. Binding
|
|
589
|
+
// the 'pet' namespace instead follows the active language, the English
|
|
590
|
+
// fallback, and every language pack that registers a dictionary for it
|
|
591
|
+
// (the settings section label already resolves through the same seat).
|
|
592
|
+
petRoot.render(createElement(PetDockEntry, { ...injected(), t: ctx.locale.bind(NS), portalTarget: container }));
|
|
561
593
|
let uiGone = false;
|
|
562
594
|
disposeUi = () => {
|
|
563
595
|
if (uiGone)
|
|
@@ -60,6 +60,8 @@ export declare const zh: {
|
|
|
60
60
|
readonly 'settings.enabledHint': "关闭后隐藏宠物并停止轮询,可在设置里重新启用。";
|
|
61
61
|
readonly 'settings.decoration': "状态装饰";
|
|
62
62
|
readonly 'settings.decorationHint': "在宠物状态气泡里显示喷水鲸鱼等状态装饰;关闭后气泡只剩文字。";
|
|
63
|
+
readonly 'settings.statusBubbles': "状态气泡";
|
|
64
|
+
readonly 'settings.statusBubblesHint': "宠物自带的会话/状态气泡(正在思考、正在使用 xxx)。关掉后只剩第三方插件通过公告契约推送的气泡与互动反馈气泡;默认开启。";
|
|
63
65
|
readonly 'settings.visible': "显示宠物";
|
|
64
66
|
readonly 'settings.visibleHint': "关闭后宠物隐藏,可从聊天输入区重新召唤。";
|
|
65
67
|
readonly 'settings.size': "大小(px)";
|
|
@@ -142,6 +144,8 @@ export declare const en: {
|
|
|
142
144
|
readonly 'settings.enabledHint': "When off, the pet hides and polling stops; re-enable it here.";
|
|
143
145
|
readonly 'settings.decoration': "Status decoration";
|
|
144
146
|
readonly 'settings.decorationHint': "Show ornaments like the spouting whale inside the pet status bubbles; when off, bubbles stay text-only.";
|
|
147
|
+
readonly 'settings.statusBubbles': "Status bubbles";
|
|
148
|
+
readonly '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.";
|
|
145
149
|
readonly 'settings.visible': "Show the pet";
|
|
146
150
|
readonly 'settings.visibleHint': "When off, the pet hides; summon it again from the input row.";
|
|
147
151
|
readonly 'settings.size': "Size (px)";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../../src/client/locales.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mDAAmD;AACnD,eAAO,MAAM,EAAE,QAAQ,CAAA;AAEvB,oBAAoB;AACpB,eAAO,MAAM,EAAE
|
|
1
|
+
{"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../../src/client/locales.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mDAAmD;AACnD,eAAO,MAAM,EAAE,QAAQ,CAAA;AAEvB,oBAAoB;AACpB,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoFL,CAAA;AAEV,oBAAoB;AACpB,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoFL,CAAA;AAEV,oCAAoC;AACpC,MAAM,MAAM,MAAM,GAAG,MAAM,OAAO,EAAE,CAAA;AAEpC,qDAAqD;AACrD,MAAM,MAAM,eAAe,GAAG,MAAM,CAAA;AAEpC;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAGnD;AAED;;;;;;;GAOG;AACH,wBAAgB,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAQvE;AAED,OAAO,QAAQ,kCAAkC,CAAC;IAChD,UAAU,kBAAkB;QAC1B,uBAAuB;QACvB,GAAG,EAAE,MAAM,CAAA;KACZ;CACF"}
|
|
@@ -62,6 +62,8 @@ export const zh = {
|
|
|
62
62
|
'settings.enabledHint': '关闭后隐藏宠物并停止轮询,可在设置里重新启用。',
|
|
63
63
|
'settings.decoration': '状态装饰',
|
|
64
64
|
'settings.decorationHint': '在宠物状态气泡里显示喷水鲸鱼等状态装饰;关闭后气泡只剩文字。',
|
|
65
|
+
'settings.statusBubbles': '状态气泡',
|
|
66
|
+
'settings.statusBubblesHint': '宠物自带的会话/状态气泡(正在思考、正在使用 xxx)。关掉后只剩第三方插件通过公告契约推送的气泡与互动反馈气泡;默认开启。',
|
|
65
67
|
'settings.visible': '显示宠物',
|
|
66
68
|
'settings.visibleHint': '关闭后宠物隐藏,可从聊天输入区重新召唤。',
|
|
67
69
|
'settings.size': '大小(px)',
|
|
@@ -146,6 +148,8 @@ export const en = {
|
|
|
146
148
|
'settings.enabledHint': 'When off, the pet hides and polling stops; re-enable it here.',
|
|
147
149
|
'settings.decoration': 'Status decoration',
|
|
148
150
|
'settings.decorationHint': 'Show ornaments like the spouting whale inside the pet status bubbles; when off, bubbles stay text-only.',
|
|
151
|
+
'settings.statusBubbles': 'Status bubbles',
|
|
152
|
+
'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.',
|
|
149
153
|
'settings.visible': 'Show the pet',
|
|
150
154
|
'settings.visibleHint': 'When off, the pet hides; summon it again from the input row.',
|
|
151
155
|
'settings.size': 'Size (px)',
|
package/lib/types/index.d.ts
CHANGED
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { Context, type Volatile } from '@deepseek-ai/cordis';
|
|
14
14
|
import z from '@deepseek-ai/schemastery';
|
|
15
|
-
import { type PetConfig, type PetSettingsSection } from './service.ts';
|
|
15
|
+
import { type PetConfig, type PetSettingsSection, type PetStatusBubbleMode } from './service.ts';
|
|
16
16
|
import { type PetDisplayConfig } from './persist.ts';
|
|
17
|
-
export { PetService, MAX_SESSION_BUBBLES } from './service.ts';
|
|
18
|
-
export type { PetConfig, PetInteractResult, PetSettingsSection, PetSessionView, PetStateView, } from './service.ts';
|
|
17
|
+
export { PetService, MAX_SESSION_BUBBLES, DEFAULT_STATUS_BUBBLE_MODE, STATUS_BUBBLE_MODES, statusBubbleMode } from './service.ts';
|
|
18
|
+
export type { PetConfig, PetInteractResult, PetSettingsSection, PetSessionView, PetStateView, PetStatusBubbleMode, } from './service.ts';
|
|
19
|
+
export { MAX_PANEL_ACTIONS, PanelActionRegistry, normalizePanelAction } from './panel-actions.ts';
|
|
20
|
+
export type { PetPanelActionContext, PetPanelActionHandler, PetPanelActionRegistration, PetPanelActionView, } from './panel-actions.ts';
|
|
19
21
|
export { AFFINITY_MAX, AFFINITY_RANKS, applyInteraction, applyTurnReward, emptyAffinity, rankOf, } from './affinity.ts';
|
|
20
22
|
export type { AffinityConfig, AffinityState, InteractionOutcome, PetInteraction, } from './affinity.ts';
|
|
21
23
|
export { animationForPhase, PetStateMachine, rowOf, } from './state.ts';
|
|
@@ -47,6 +49,7 @@ export declare const PET_FORM_DEFAULTS: {
|
|
|
47
49
|
readonly petId: "whale-girl";
|
|
48
50
|
readonly enabled: true;
|
|
49
51
|
readonly decorationEnabled: true;
|
|
52
|
+
readonly statusBubbles: PetStatusBubbleMode;
|
|
50
53
|
};
|
|
51
54
|
/**
|
|
52
55
|
* One settings field as the config carries it. The Host commits an edit into
|
|
@@ -61,6 +64,12 @@ export interface PetFormConfig {
|
|
|
61
64
|
enabled?: LiveField<boolean>;
|
|
62
65
|
/** Status-decoration master switch (pet-center M5, #567); defaults to on. */
|
|
63
66
|
decorationEnabled?: LiveField<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the pet renders its own session/status bubbles (issue #6);
|
|
69
|
+
* defaults to 'auto', which is exactly the behavior that shipped before
|
|
70
|
+
* the switch existed.
|
|
71
|
+
*/
|
|
72
|
+
statusBubbles?: LiveField<PetStatusBubbleMode | undefined>;
|
|
64
73
|
/** Master switch for the pet surface. */
|
|
65
74
|
visible?: LiveField<boolean>;
|
|
66
75
|
/** Scale of the rendered pet in px (sprite cell height). */
|
|
@@ -98,6 +107,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
98
107
|
petId: z<string, string, "volatile">;
|
|
99
108
|
enabled: z<boolean, boolean, "volatile-defined">;
|
|
100
109
|
decorationEnabled: z<boolean, boolean, "volatile-defined">;
|
|
110
|
+
statusBubbles: z<"auto" | "off", "auto" | "off", "volatile-defined">;
|
|
101
111
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
102
112
|
visible: z<boolean, boolean, "volatile-defined">;
|
|
103
113
|
size: z<number, number, "volatile-defined">;
|
|
@@ -107,6 +117,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
107
117
|
petId: z<string, string, "volatile">;
|
|
108
118
|
enabled: z<boolean, boolean, "volatile-defined">;
|
|
109
119
|
decorationEnabled: z<boolean, boolean, "volatile-defined">;
|
|
120
|
+
statusBubbles: z<"auto" | "off", "auto" | "off", "volatile-defined">;
|
|
110
121
|
}>>, "plain">;
|
|
111
122
|
/**
|
|
112
123
|
* The settings section the pet runs with: the effective values of the row's
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAI5D,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAI5D,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,EAAyG,KAAK,SAAS,EAAE,KAAK,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAGvM,OAAO,EAA6G,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAG/J,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACjI,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,mBAAmB,GACpB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,iBA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;;;;;;;;;;;;;;;;;;aAgBjB,CAAA;AAkDF;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,MAAM,EACrB,SAAS,GAAE,OAAO,CAAC,gBAAgB,CAAM,EACzC,SAAS,GAAE,OAAO,CAAC,gBAAgB,CAAM,GACxC,kBAAkB,CAgCpB;AA4CD,0EAA0E;AAC1E,eAAO,MAAM,KAAK,kBAA6C,CAAA;AAE/D,4FAA4F;AAC5F,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,EAAE,SAAS,GAAG,mBAAmB,CAAC,GAAG,aAAa,CAAA;AAE9F,iBAAS,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,eAAoB,GAAG,IAAI,CA+EnE;AAED,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,MAAM;QACd;;;;WAIG;QACH,wBAAwB,CAAC,KAAK,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAA;KACtE;CACF"}
|
package/lib/types/index.js
CHANGED
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
* @module @linxin666/dsh-pet
|
|
12
12
|
*/
|
|
13
13
|
import z from '@deepseek-ai/schemastery';
|
|
14
|
-
import { PET_SETTINGS_NAMESPACE, PetService } from "./service.js";
|
|
14
|
+
import { DEFAULT_STATUS_BUBBLE_MODE, PET_SETTINGS_NAMESPACE, PetService, STATUS_BUBBLE_MODES, statusBubbleMode } from "./service.js";
|
|
15
15
|
import { makePetRoutes } from "./routes.js";
|
|
16
16
|
import { loadPetRegistry, petPackageRoot } from "./registry.js";
|
|
17
17
|
import { BUBBLE_SCALE_MAX, BUBBLE_SCALE_MIN, DEFAULT_PET_ID, DISPLAY_INSET_MAX, DISPLAY_SIZE_MAX, DISPLAY_SIZE_MIN } from "./persist.js";
|
|
18
18
|
import { mountOnce } from "./mount-once.js";
|
|
19
|
-
export { PetService, MAX_SESSION_BUBBLES } from "./service.js";
|
|
19
|
+
export { PetService, MAX_SESSION_BUBBLES, DEFAULT_STATUS_BUBBLE_MODE, STATUS_BUBBLE_MODES, statusBubbleMode } from "./service.js";
|
|
20
|
+
export { MAX_PANEL_ACTIONS, PanelActionRegistry, normalizePanelAction } from "./panel-actions.js";
|
|
20
21
|
export { AFFINITY_MAX, AFFINITY_RANKS, applyInteraction, applyTurnReward, emptyAffinity, rankOf, } from "./affinity.js";
|
|
21
22
|
export { animationForPhase, PetStateMachine, rowOf, } from "./state.js";
|
|
22
23
|
export { consumeTreat, defaultTreatConfig, emptyTreatLedger, settleTreatGrants, } from "./treats.js";
|
|
@@ -42,6 +43,7 @@ export const PET_FORM_DEFAULTS = {
|
|
|
42
43
|
petId: DEFAULT_PET_ID,
|
|
43
44
|
enabled: true,
|
|
44
45
|
decorationEnabled: true,
|
|
46
|
+
statusBubbles: DEFAULT_STATUS_BUBBLE_MODE,
|
|
45
47
|
};
|
|
46
48
|
/**
|
|
47
49
|
* Plugin configuration. Under the 0.1.7 settings model a plugin's own Cordis
|
|
@@ -69,6 +71,11 @@ export const Config = z.object({
|
|
|
69
71
|
petId: z.string().volatile(),
|
|
70
72
|
enabled: z.boolean().default(PET_FORM_DEFAULTS.enabled).volatile(),
|
|
71
73
|
decorationEnabled: z.boolean().default(PET_FORM_DEFAULTS.decorationEnabled).volatile(),
|
|
74
|
+
// The pet's own session/status bubbles (issue #6). 'auto' is the shipped
|
|
75
|
+
// behavior; 'off' is the opt-in a user (or a plugin that drives its own
|
|
76
|
+
// bubble surface) needs, and it hides ONLY those bubbles — the sprite, the
|
|
77
|
+
// interaction feedback and a sibling plugin's announcement bubble stay.
|
|
78
|
+
statusBubbles: z.union([...STATUS_BUBBLE_MODES]).default(PET_FORM_DEFAULTS.statusBubbles).volatile(),
|
|
72
79
|
});
|
|
73
80
|
/**
|
|
74
81
|
* Read one live config field.
|
|
@@ -153,6 +160,11 @@ export function petSettingsSection(config, fallbackPetId, persisted = {}, commit
|
|
|
153
160
|
petId: readLive(config.petId, fallbackPetId),
|
|
154
161
|
enabled,
|
|
155
162
|
decorationEnabled: readLive(config.decorationEnabled, PET_FORM_DEFAULTS.decorationEnabled),
|
|
163
|
+
// Not a display field: the bubble switch has no persisted pet.json twin
|
|
164
|
+
// (it is a plugin-level rendering preference, like `decorationEnabled`),
|
|
165
|
+
// so it reads the live value directly and normalizes anything unknown to
|
|
166
|
+
// the shipped default instead of trusting the document.
|
|
167
|
+
statusBubbles: statusBubbleMode(readLive(config.statusBubbles, undefined)),
|
|
156
168
|
};
|
|
157
169
|
}
|
|
158
170
|
/** The settings row ids a pet install is served under, most specific first. */
|
|
@@ -197,6 +209,7 @@ function applyImpl(ctx, config = {}) {
|
|
|
197
209
|
...config,
|
|
198
210
|
enabled: readLive(config.enabled, PET_FORM_DEFAULTS.enabled),
|
|
199
211
|
decorationEnabled: readLive(config.decorationEnabled, PET_FORM_DEFAULTS.decorationEnabled),
|
|
212
|
+
statusBubbles: statusBubbleMode(readLive(config.statusBubbles, undefined)),
|
|
200
213
|
registry,
|
|
201
214
|
});
|
|
202
215
|
// The mirror back into the settings document (see syncSettingsFromPet) has to
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hover-panel action contract — the extension point a sibling plugin uses to
|
|
3
|
+
* add its own button to the pet's floating hover panel (issue #6).
|
|
4
|
+
*
|
|
5
|
+
* A plugin registers one action in process through the pet service
|
|
6
|
+
* (`ctx.pet.registerPanelAction({ id, label, onSelect })`); the host validates
|
|
7
|
+
* it into a bounded view, serves the registered actions in the state snapshot
|
|
8
|
+
* (`PetStateView.panelActions`), and the browser half renders one button per
|
|
9
|
+
* entry at the end of the panel's action row. A click travels back through
|
|
10
|
+
* `POST /api/pet/panel-action`, which dispatches to the registering plugin's
|
|
11
|
+
* own callback — the pet owns the row, the plugin owns what the button does.
|
|
12
|
+
*
|
|
13
|
+
* The validation and the registry live in this pure module so the contract has
|
|
14
|
+
* exactly one home and stays testable without the cordis service.
|
|
15
|
+
* @module @linxin666/dsh-pet/panel-actions
|
|
16
|
+
*/
|
|
17
|
+
/** How many plugin actions one hover panel can carry at most. */
|
|
18
|
+
export declare const MAX_PANEL_ACTIONS = 8;
|
|
19
|
+
/** One registered action as the browser half renders it. */
|
|
20
|
+
export interface PetPanelActionView {
|
|
21
|
+
/** Registration id; the click dispatches back on it. */
|
|
22
|
+
id: string;
|
|
23
|
+
/** Button label. */
|
|
24
|
+
label: string;
|
|
25
|
+
/** Optional tooltip (the label's longer explanation). */
|
|
26
|
+
title?: string;
|
|
27
|
+
/** Sort key within the registered block; ties break on id. */
|
|
28
|
+
order: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* What a panel action click knows about the pet at the moment it arrives. The
|
|
32
|
+
* registering plugin may read more off the service (`selectedPetId()`), so this
|
|
33
|
+
* stays a read-only snapshot rather than a live handle.
|
|
34
|
+
*/
|
|
35
|
+
export interface PetPanelActionContext {
|
|
36
|
+
/** The selected pet id when the click arrived. */
|
|
37
|
+
petId: string;
|
|
38
|
+
}
|
|
39
|
+
/** The callback a registration carries; a click invokes it in the host. */
|
|
40
|
+
export type PetPanelActionHandler = (context: PetPanelActionContext) => void | Promise<void>;
|
|
41
|
+
/** One action a sibling plugin registers into the panel's action row. */
|
|
42
|
+
export interface PetPanelActionRegistration {
|
|
43
|
+
/** Unique, stable id (kebab-case); re-registering the same id replaces it. */
|
|
44
|
+
id: string;
|
|
45
|
+
/** Button label (bounded). */
|
|
46
|
+
label: string;
|
|
47
|
+
/** Optional tooltip rendered as the button's `title`. */
|
|
48
|
+
title?: string;
|
|
49
|
+
/** Sort key within the registered block (default 0; ascending, ties on id). */
|
|
50
|
+
order?: number;
|
|
51
|
+
/** Invoked in the host when the browser half dispatches this action. */
|
|
52
|
+
onSelect: PetPanelActionHandler;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Validate one registration. Returns undefined — never throws — when the shape
|
|
56
|
+
* is unusable: the id must match the id grammar and the label must survive
|
|
57
|
+
* truncation, so a click can always be dispatched back to a known row.
|
|
58
|
+
* @param input - the registration a sibling plugin passed to the service.
|
|
59
|
+
* @returns the wire view, or undefined when the registration is malformed.
|
|
60
|
+
*/
|
|
61
|
+
export declare function normalizePanelAction(input: unknown): PetPanelActionView | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* The panel's action registry: one bounded, ordered table of plugin actions.
|
|
64
|
+
*
|
|
65
|
+
* Registration is id-wins (a later registration of the same id replaces the
|
|
66
|
+
* earlier one, and the superseded disposer stops touching the table so a
|
|
67
|
+
* disposing plugin can never remove the action that replaced it). The table is
|
|
68
|
+
* in-memory only — it dies with the pet service fiber — and every entry is
|
|
69
|
+
* reclaimed by the disposer the registering plugin runs with its own fiber.
|
|
70
|
+
*/
|
|
71
|
+
export declare class PanelActionRegistry {
|
|
72
|
+
private readonly actions;
|
|
73
|
+
/**
|
|
74
|
+
* Register one action.
|
|
75
|
+
* @param input - the registration a sibling plugin passed to the service.
|
|
76
|
+
* @returns a disposer removing this registration.
|
|
77
|
+
* @throws when the registration is malformed. Unlike `announce` — a hot path
|
|
78
|
+
* whose payload a caller may build from untrusted data — a registration is
|
|
79
|
+
* built once at the registering plugin's own apply, so a bad id or label is a
|
|
80
|
+
* wiring mistake that should fail where it was written.
|
|
81
|
+
*/
|
|
82
|
+
register(input: unknown): () => void;
|
|
83
|
+
/** The registered actions as the state view serves them, in render order. */
|
|
84
|
+
views(): PetPanelActionView[];
|
|
85
|
+
/**
|
|
86
|
+
* Dispatch a click to the plugin that registered this id.
|
|
87
|
+
* @param id - the id the browser half reported.
|
|
88
|
+
* @param context - what the pet looked like when the click arrived.
|
|
89
|
+
* @returns whether the id was registered. A handler that throws rejects:
|
|
90
|
+
* the caller decides how a sibling plugin's failure is reported.
|
|
91
|
+
*/
|
|
92
|
+
select(id: string, context: PetPanelActionContext): Promise<boolean>;
|
|
93
|
+
/** Drop every registration (service teardown; tests). */
|
|
94
|
+
clear(): void;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=panel-actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel-actions.d.ts","sourceRoot":"","sources":["../../src/panel-actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAoBlC,4DAA4D;AAC5D,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,EAAE,EAAE,MAAM,CAAA;IACV,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAA;CACd;AAED,2EAA2E;AAC3E,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,EAAE,qBAAqB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAE5F,yEAAyE;AACzE,MAAM,WAAW,0BAA0B;IACzC,8EAA8E;IAC9E,EAAE,EAAE,MAAM,CAAA;IACV,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,wEAAwE;IACxE,QAAQ,EAAE,qBAAqB,CAAA;CAChC;AAeD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,GAAG,SAAS,CAkBnF;AAED;;;;;;;;GAQG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsC;IAE9D;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,IAAI;IAkBpC,6EAA6E;IAC7E,KAAK,IAAI,kBAAkB,EAAE;IAM7B;;;;;;OAMG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,OAAO,CAAC;IAO1E,yDAAyD;IACzD,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hover-panel action contract — the extension point a sibling plugin uses to
|
|
3
|
+
* add its own button to the pet's floating hover panel (issue #6).
|
|
4
|
+
*
|
|
5
|
+
* A plugin registers one action in process through the pet service
|
|
6
|
+
* (`ctx.pet.registerPanelAction({ id, label, onSelect })`); the host validates
|
|
7
|
+
* it into a bounded view, serves the registered actions in the state snapshot
|
|
8
|
+
* (`PetStateView.panelActions`), and the browser half renders one button per
|
|
9
|
+
* entry at the end of the panel's action row. A click travels back through
|
|
10
|
+
* `POST /api/pet/panel-action`, which dispatches to the registering plugin's
|
|
11
|
+
* own callback — the pet owns the row, the plugin owns what the button does.
|
|
12
|
+
*
|
|
13
|
+
* The validation and the registry live in this pure module so the contract has
|
|
14
|
+
* exactly one home and stays testable without the cordis service.
|
|
15
|
+
* @module @linxin666/dsh-pet/panel-actions
|
|
16
|
+
*/
|
|
17
|
+
/** How many plugin actions one hover panel can carry at most. */
|
|
18
|
+
export const MAX_PANEL_ACTIONS = 8;
|
|
19
|
+
/**
|
|
20
|
+
* Action id grammar: a lowercase id in the shape pet and decoration ids use
|
|
21
|
+
* (`^` + kebab/dot segments). The id is what a click travels back on, so it
|
|
22
|
+
* has to be stable, addressable and free of separators the wire would treat as
|
|
23
|
+
* structure.
|
|
24
|
+
*/
|
|
25
|
+
const ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
26
|
+
/**
|
|
27
|
+
* Label bound. The action row is compact and wraps beyond a few characters per
|
|
28
|
+
* button, so a plugin names its action (换装, Quota) rather than a sentence;
|
|
29
|
+
* the optional title carries the longer explanation as a tooltip.
|
|
30
|
+
*/
|
|
31
|
+
const LABEL_MAX = 24;
|
|
32
|
+
/** Title (tooltip) bound; the same reason voice-pack labels are bounded. */
|
|
33
|
+
const TITLE_MAX = 80;
|
|
34
|
+
function boundedString(value, max) {
|
|
35
|
+
if (typeof value !== 'string')
|
|
36
|
+
return undefined;
|
|
37
|
+
const trimmed = value.trim();
|
|
38
|
+
if (trimmed === '')
|
|
39
|
+
return undefined;
|
|
40
|
+
return trimmed.length <= max ? trimmed : trimmed.slice(0, max);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validate one registration. Returns undefined — never throws — when the shape
|
|
44
|
+
* is unusable: the id must match the id grammar and the label must survive
|
|
45
|
+
* truncation, so a click can always be dispatched back to a known row.
|
|
46
|
+
* @param input - the registration a sibling plugin passed to the service.
|
|
47
|
+
* @returns the wire view, or undefined when the registration is malformed.
|
|
48
|
+
*/
|
|
49
|
+
export function normalizePanelAction(input) {
|
|
50
|
+
if (typeof input !== 'object' || input === null)
|
|
51
|
+
return undefined;
|
|
52
|
+
const data = input;
|
|
53
|
+
// The id is an identity, not copy: an over-long one is refused rather than
|
|
54
|
+
// truncated, because truncating it could silently collapse two plugins'
|
|
55
|
+
// registrations onto one row.
|
|
56
|
+
const id = typeof data.id === 'string' ? data.id.trim() : undefined;
|
|
57
|
+
if (id === undefined || !ID_PATTERN.test(id))
|
|
58
|
+
return undefined;
|
|
59
|
+
const label = boundedString(data.label, LABEL_MAX);
|
|
60
|
+
if (label === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
const title = boundedString(data.title, TITLE_MAX);
|
|
63
|
+
const order = typeof data.order === 'number' && Number.isFinite(data.order) ? data.order : 0;
|
|
64
|
+
return {
|
|
65
|
+
id,
|
|
66
|
+
label,
|
|
67
|
+
...(title === undefined ? {} : { title }),
|
|
68
|
+
order,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The panel's action registry: one bounded, ordered table of plugin actions.
|
|
73
|
+
*
|
|
74
|
+
* Registration is id-wins (a later registration of the same id replaces the
|
|
75
|
+
* earlier one, and the superseded disposer stops touching the table so a
|
|
76
|
+
* disposing plugin can never remove the action that replaced it). The table is
|
|
77
|
+
* in-memory only — it dies with the pet service fiber — and every entry is
|
|
78
|
+
* reclaimed by the disposer the registering plugin runs with its own fiber.
|
|
79
|
+
*/
|
|
80
|
+
export class PanelActionRegistry {
|
|
81
|
+
actions = new Map();
|
|
82
|
+
/**
|
|
83
|
+
* Register one action.
|
|
84
|
+
* @param input - the registration a sibling plugin passed to the service.
|
|
85
|
+
* @returns a disposer removing this registration.
|
|
86
|
+
* @throws when the registration is malformed. Unlike `announce` — a hot path
|
|
87
|
+
* whose payload a caller may build from untrusted data — a registration is
|
|
88
|
+
* built once at the registering plugin's own apply, so a bad id or label is a
|
|
89
|
+
* wiring mistake that should fail where it was written.
|
|
90
|
+
*/
|
|
91
|
+
register(input) {
|
|
92
|
+
const registration = (typeof input === 'object' && input !== null ? input : {});
|
|
93
|
+
const view = normalizePanelAction(registration);
|
|
94
|
+
if (view === undefined)
|
|
95
|
+
throw new Error('[dsh-pet] invalid panel action: id and label are required');
|
|
96
|
+
if (typeof registration.onSelect !== 'function') {
|
|
97
|
+
throw new Error('[dsh-pet] invalid panel action: onSelect must be a function');
|
|
98
|
+
}
|
|
99
|
+
if (!this.actions.has(view.id) && this.actions.size >= MAX_PANEL_ACTIONS) {
|
|
100
|
+
throw new Error('[dsh-pet] panel action limit reached: ' + MAX_PANEL_ACTIONS);
|
|
101
|
+
}
|
|
102
|
+
const entry = { view, onSelect: registration.onSelect };
|
|
103
|
+
this.actions.set(view.id, entry);
|
|
104
|
+
return () => {
|
|
105
|
+
// Only the registration that still owns the id may clear it.
|
|
106
|
+
if (this.actions.get(view.id) === entry)
|
|
107
|
+
this.actions.delete(view.id);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** The registered actions as the state view serves them, in render order. */
|
|
111
|
+
views() {
|
|
112
|
+
return [...this.actions.values()]
|
|
113
|
+
.map(entry => entry.view)
|
|
114
|
+
.sort((a, b) => a.order - b.order || a.id.localeCompare(b.id));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Dispatch a click to the plugin that registered this id.
|
|
118
|
+
* @param id - the id the browser half reported.
|
|
119
|
+
* @param context - what the pet looked like when the click arrived.
|
|
120
|
+
* @returns whether the id was registered. A handler that throws rejects:
|
|
121
|
+
* the caller decides how a sibling plugin's failure is reported.
|
|
122
|
+
*/
|
|
123
|
+
async select(id, context) {
|
|
124
|
+
const entry = this.actions.get(id);
|
|
125
|
+
if (entry === undefined)
|
|
126
|
+
return false;
|
|
127
|
+
await entry.onSelect(context);
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
/** Drop every registration (service teardown; tests). */
|
|
131
|
+
clear() {
|
|
132
|
+
this.actions.clear();
|
|
133
|
+
}
|
|
134
|
+
}
|