@takboo/dsh-coopanion 0.4.21 → 0.4.22
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.md +2 -2
- package/dist/build-info.json +2 -2
- package/dist/index.js +12 -4
- package/dist/index.js.map +2 -2
- package/dist/model.js +12 -4
- package/dist/model.js.map +2 -2
- package/docs/characters.md +1 -1
- package/docs/companionship-contract.md +1 -1
- package/docs/development.md +4 -1
- package/docs/multi-display-contract.md +1 -1
- package/docs/release-notes.md +8 -0
- package/docs/usage.md +5 -5
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/model.ts +15 -6
- package/tests/model.test.ts +12 -1
- package/tests/multi-display-ui.mjs +2 -0
- package/tests/npc-drag-ui.mjs +59 -9
- package/tests/ui.mjs +13 -0
- package/web/live-mouth.js +34 -0
- package/web/pet.js +11 -7
- package/web/upstream/UPSTREAM.md +1 -1
- package/web/upstream/kit/body.js +7 -5
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const BURST_MS = 1200;
|
|
2
|
+
const PULSE_INTERVAL_MS = 180;
|
|
3
|
+
|
|
4
|
+
export function createLiveMouth() {
|
|
5
|
+
let seen = new Map(), burstUntil = -Infinity, nextPulseAt = -Infinity;
|
|
6
|
+
return {
|
|
7
|
+
update(snapshot, now) {
|
|
8
|
+
const sessions = snapshot.sessions?.length ? snapshot.sessions
|
|
9
|
+
: snapshot.sessionId ? [{ ...snapshot, id: snapshot.sessionId }] : [];
|
|
10
|
+
const current = new Map();
|
|
11
|
+
let talking = false, fresh = false;
|
|
12
|
+
for (const session of sessions) {
|
|
13
|
+
const hasSpeechProgress = Number.isSafeInteger(session.speechRevision);
|
|
14
|
+
// Older snapshots and the demo only carry presentation revisions.
|
|
15
|
+
const progress = hasSpeechProgress ? session.speechRevision : session.revision ?? 0;
|
|
16
|
+
const previous = seen.get(session.id);
|
|
17
|
+
const lastProgress = previous?.hasSpeechProgress === hasSpeechProgress ? previous.progress : -Infinity;
|
|
18
|
+
current.set(session.id, { hasSpeechProgress, progress: Math.max(lastProgress, progress) });
|
|
19
|
+
if (session.mood !== 'talking' || session.active === false || session.streaming === false) continue;
|
|
20
|
+
talking = true;
|
|
21
|
+
if (progress > lastProgress && (!hasSpeechProgress || progress > 0)) fresh = true;
|
|
22
|
+
}
|
|
23
|
+
seen = current;
|
|
24
|
+
if (!talking) burstUntil = nextPulseAt = -Infinity;
|
|
25
|
+
else if (fresh) burstUntil = now + BURST_MS;
|
|
26
|
+
},
|
|
27
|
+
pulse(now, enabled) {
|
|
28
|
+
if (!enabled) burstUntil = nextPulseAt = -Infinity;
|
|
29
|
+
if (now >= burstUntil || now < nextPulseAt) return false;
|
|
30
|
+
nextPulseAt = now + PULSE_INTERVAL_MS;
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
package/web/pet.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { advanceRenderCadence } from './render-cadence.js';
|
|
2
|
+
import { createLiveMouth } from './live-mouth.js';
|
|
2
3
|
import { createDiagnosticCounters } from './diagnostics.js';
|
|
3
4
|
import { createCompanionStroke } from './companion-touch.js';
|
|
4
5
|
import { initialNpc, stepNpc, npcSpace } from './npc-life.js';
|
|
@@ -45,7 +46,8 @@ let snapshot = { mood: 'idle', text: '你好。点点我,或双击和我说话
|
|
|
45
46
|
let x = innerWidth * .68, y = innerHeight - 155, hovered = false, asleep = false, toastTimer, noticeSession;
|
|
46
47
|
let cursorPoint, lastHit;
|
|
47
48
|
let renderedSessionId = null, reactionUntil = 0, reactionMood, bubbleSession, trayKey, touchTimer, touchBlockedUntil = 0;
|
|
48
|
-
let bubbleResult, readerResult, pendingOnly = false
|
|
49
|
+
let bubbleResult, readerResult, pendingOnly = false;
|
|
50
|
+
const liveMouth = createLiveMouth();
|
|
49
51
|
let readerQueue, inboxState = { requests: [], issues: [], replies: [], total: 0 };
|
|
50
52
|
let resizeLayout, displayGeometry, pendingDisplayPlacement, resizeOrigin;
|
|
51
53
|
let geometryRequestedAt = -Infinity;
|
|
@@ -373,6 +375,7 @@ function updateMood() {
|
|
|
373
375
|
|
|
374
376
|
function render() {
|
|
375
377
|
attentionSnapshot = sessionAttention.project(snapshot, pendingRequests());
|
|
378
|
+
liveMouth.update(attentionSnapshot, performance.now());
|
|
376
379
|
applyLocale(); const labels = uiCopy().labels;
|
|
377
380
|
const previous = renderedSessionId;
|
|
378
381
|
const selected = snapshot.sessions.find(session => session.id === snapshot.sessionId);
|
|
@@ -707,12 +710,13 @@ pet.addEventListener('pointerdown', event => {
|
|
|
707
710
|
function release(event) {
|
|
708
711
|
if (!pressing) return;
|
|
709
712
|
const moved = dragging;
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
713
|
+
const cancelled = event.type === 'pointercancel';
|
|
714
|
+
const point = { x: event.clientX, y: event.clientY, t: event.timeStamp };
|
|
715
|
+
const outsideDisplay = native && (point.x < 0 || point.x >= innerWidth || point.y < 0 || point.y >= innerHeight);
|
|
716
|
+
if (moved && (cancelled || outsideDisplay)) body?.drop(cancelled ? dragPoint : point);
|
|
717
|
+
else body?.pointer(cancelled ? 'cancel' : 'up', point);
|
|
714
718
|
pressing = false; dragging = false; pressedPointerId = undefined;
|
|
715
|
-
if (
|
|
719
|
+
if (!cancelled && native && moved) send({ type: 'move-display' });
|
|
716
720
|
}
|
|
717
721
|
pet.addEventListener('pointerup', release); pet.addEventListener('pointercancel', release);
|
|
718
722
|
// The upstream body owns poke, stroke, wake, grab and drop. Respond to its
|
|
@@ -884,7 +888,7 @@ function animate(now) {
|
|
|
884
888
|
}
|
|
885
889
|
presentNextNotice();
|
|
886
890
|
updateMood();
|
|
887
|
-
if (!reduced && pet.dataset.mood === 'talking'
|
|
891
|
+
if (liveMouth.pulse(now, !reduced && !document.hidden && pet.dataset.mood === 'talking')) body?.talk();
|
|
888
892
|
// Only P1's fully idle pose renders at 30fps. Work and input retain the original cadence.
|
|
889
893
|
// Accumulate real dt so rendering fewer frames never slows physics.
|
|
890
894
|
const companionIdle = options.companionship !== 'off' && pet.dataset.mood === 'idle' && !companion.active && !hovered && !pressing && !dragging && !reducedNeedsStep && body?.layout && !body.layout.moving && !userInputOccupied() && ![...composer.sessions.values()].some(s => !!s.text.trim() || s.phase === 'sending') && interaction.hidden && companionInvitation.hidden;
|
package/web/upstream/UPSTREAM.md
CHANGED
|
@@ -32,5 +32,5 @@ Harness refinements, 2026-10-10:
|
|
|
32
32
|
- Outlined menus and conversation cards use manifest console hues and thumbnails. Session identity comes from public human prompts, cwd, timestamps and distinct short IDs.
|
|
33
33
|
- The native tray projects the same snapshot, selected appearance and acknowledged settings as the desktop page. macOS uses an icon-only template with aggregate attention markers, while menu and tooltip retain state details.
|
|
34
34
|
|
|
35
|
-
- `kit/body.js` adds optional persistent `set({ expression })` for Harness task faces, without repeating expression sounds or bounces.
|
|
35
|
+
- `kit/body.js` adds optional persistent `set({ expression })` for Harness task faces, without repeating expression sounds or bounces. Drag release uses recent pointer samples for momentum. A pause before release lets the body fall without carrying its earlier velocity.
|
|
36
36
|
- Final replies retain complete text and per-result read identity. Bounded previews use the original typewriter, punctuation and mouth pulses; a stable full-text reader and explicit session focus prevent concurrent tasks from interrupting reading or redirecting chat.
|
package/web/upstream/kit/body.js
CHANGED
|
@@ -692,9 +692,10 @@ export function createPet(els, opts) {
|
|
|
692
692
|
|
|
693
693
|
/* pointer: stage-pixel coordinates; `p.t` is when it happened (ms), else now */
|
|
694
694
|
const now = (p) => p?.t ?? performance.now();
|
|
695
|
-
|
|
695
|
+
const momentumWindow = 110;
|
|
696
|
+
function velocity(t) {
|
|
696
697
|
const s = pointer.samples;
|
|
697
|
-
if (s.length < 2) return { x: 0, y: 0 };
|
|
698
|
+
if (s.length < 2 || t - s.at(-1).t > momentumWindow) return { x: 0, y: 0 };
|
|
698
699
|
const a = s[0], b = s[s.length - 1], dt = Math.max(.016, (b.t - a.t) / 1000);
|
|
699
700
|
return { x: (b.x - a.x) / dt, y: (b.y - a.y) / dt };
|
|
700
701
|
}
|
|
@@ -711,8 +712,8 @@ export function createPet(els, opts) {
|
|
|
711
712
|
const ddx = p.x - pointer.x, ddy = p.y - pointer.y;
|
|
712
713
|
Object.assign(pointer, { x: p.x, y: p.y, inside: true });
|
|
713
714
|
pointer.samples.push({ t, x: p.x, y: p.y });
|
|
714
|
-
while (pointer.samples.length > 2 && t - pointer.samples[0].t >
|
|
715
|
-
pointer.vx = lerp(pointer.vx, velocity().x, .35);
|
|
715
|
+
while (pointer.samples.length > 2 && t - pointer.samples[0].t > momentumWindow) pointer.samples.shift();
|
|
716
|
+
pointer.vx = lerp(pointer.vx, velocity(t).x, .35);
|
|
716
717
|
|
|
717
718
|
if (press && pet.mode !== 'drag' && Math.hypot(p.x - press.x, p.y - press.y) > 6) {
|
|
718
719
|
const scruff = toStage(128, 36);
|
|
@@ -740,9 +741,10 @@ export function createPet(els, opts) {
|
|
|
740
741
|
pet.cursor = '';
|
|
741
742
|
if (!press) return;
|
|
742
743
|
if (pet.mode === 'drag') {
|
|
744
|
+
const v = velocity(now(p));
|
|
745
|
+
if (!v.x && !v.y) return dropAt(p);
|
|
743
746
|
// hand over from the scruff anchor to the feet anchor without a visual jump
|
|
744
747
|
const foot = toStage(128, 256);
|
|
745
|
-
const v = velocity();
|
|
746
748
|
pet.x = clamp(foot.x, minX(), maxX());
|
|
747
749
|
pet.fy = Math.min(floorY, foot.y);
|
|
748
750
|
pet.vx = clamp(v.x, -1800, 1800); pet.vy = clamp(v.y, -1800, 1400);
|