@voicethere/agent 0.36.1 → 0.37.0
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 +11 -11
- package/dist/templates/game-sync/agent.js +256 -52
- package/dist/templates/registry.d.ts.map +1 -1
- package/dist/templates/registry.js +8 -3
- package/dist/templates/registry.js.map +1 -1
- package/dist/templates/world-sync/agent.js +22 -1
- package/dist/templates/world-sync-binary/agent.js +22 -1
- package/eject/llm/loop.ts +1 -1
- package/package.json +30 -1
- package/templates/README.md +11 -11
- package/templates/game-sync/README.md +13 -4
- package/templates/game-sync/agent.ts +175 -60
- package/templates/game-sync/protocol.ts +3 -0
- package/templates/game-sync/quantize.ts +53 -0
- package/templates/game-sync/redis.ts +51 -1
- package/templates/game-sync/sim.ts +6 -0
- package/templates/game-sync/world-layout.ts +191 -0
- package/templates/redis-sync/README.md +7 -5
- package/templates/redis-sync/agent.ts +77 -65
- package/templates/redis-sync/quantize.ts +53 -0
- package/templates/redis-sync/quantized-frames.vectors.json +249 -0
- package/templates/redis-sync/world-layout.ts +278 -116
- package/templates/world-sync/README.md +1 -1
- package/templates/world-sync/agent.ts +39 -4
- package/templates/world-sync-binary/README.md +1 -1
- package/templates/world-sync-binary/agent.ts +29 -2
|
@@ -1377,7 +1377,11 @@ function agentLog(level, message, fieldsOrSessionId, sessionId) {
|
|
|
1377
1377
|
}
|
|
1378
1378
|
|
|
1379
1379
|
// templates/world-sync/agent.ts
|
|
1380
|
+
var BROADCAST_HZ = 30;
|
|
1381
|
+
var BROADCAST_INTERVAL_MS = Math.floor(1e3 / BROADCAST_HZ);
|
|
1380
1382
|
var poses = /* @__PURE__ */ new Map();
|
|
1383
|
+
var dirty = false;
|
|
1384
|
+
var broadcastTimer = null;
|
|
1381
1385
|
function isFiniteNumber(value) {
|
|
1382
1386
|
return typeof value === "number" && Number.isFinite(value);
|
|
1383
1387
|
}
|
|
@@ -1395,6 +1399,7 @@ function parsePoseMessage(message) {
|
|
|
1395
1399
|
return { x: record.x, y: record.y, z: record.z };
|
|
1396
1400
|
}
|
|
1397
1401
|
function broadcastWorld() {
|
|
1402
|
+
dirty = false;
|
|
1398
1403
|
const payload = {
|
|
1399
1404
|
type: "world",
|
|
1400
1405
|
poses: Object.fromEntries(poses)
|
|
@@ -1403,23 +1408,39 @@ function broadcastWorld() {
|
|
|
1403
1408
|
sendToClient(sessionId, payload);
|
|
1404
1409
|
}
|
|
1405
1410
|
}
|
|
1411
|
+
function startTickIfNeeded() {
|
|
1412
|
+
if (broadcastTimer || poses.size === 0) return;
|
|
1413
|
+
broadcastTimer = setInterval(() => {
|
|
1414
|
+
if (dirty) broadcastWorld();
|
|
1415
|
+
}, BROADCAST_INTERVAL_MS);
|
|
1416
|
+
}
|
|
1417
|
+
function stopTickIfIdle() {
|
|
1418
|
+
if (poses.size > 0 || !broadcastTimer) return;
|
|
1419
|
+
clearInterval(broadcastTimer);
|
|
1420
|
+
broadcastTimer = null;
|
|
1421
|
+
dirty = false;
|
|
1422
|
+
}
|
|
1406
1423
|
var agent_default = defineAgent({
|
|
1407
1424
|
onClientJoin({ sessionId }) {
|
|
1408
1425
|
poses.set(sessionId, { x: 0, y: 0, z: 0 });
|
|
1426
|
+
startTickIfNeeded();
|
|
1409
1427
|
broadcastWorld();
|
|
1410
1428
|
},
|
|
1411
1429
|
onClientLeave({ sessionId }) {
|
|
1412
1430
|
poses.delete(sessionId);
|
|
1413
1431
|
broadcastWorld();
|
|
1432
|
+
stopTickIfIdle();
|
|
1414
1433
|
},
|
|
1415
1434
|
onDataChannelMessage({ sessionId, message }) {
|
|
1416
1435
|
const pose = parsePoseMessage(message);
|
|
1417
1436
|
if (!pose) return;
|
|
1418
1437
|
poses.set(sessionId, pose);
|
|
1419
|
-
|
|
1438
|
+
startTickIfNeeded();
|
|
1439
|
+
dirty = true;
|
|
1420
1440
|
}
|
|
1421
1441
|
});
|
|
1422
1442
|
export {
|
|
1443
|
+
BROADCAST_HZ,
|
|
1423
1444
|
agent_default as default,
|
|
1424
1445
|
isFiniteNumber,
|
|
1425
1446
|
parsePoseMessage
|
|
@@ -1543,6 +1543,10 @@ var WorldSnapshotBuffer = class {
|
|
|
1543
1543
|
var defaultSnapshot = new WorldSnapshotBuffer();
|
|
1544
1544
|
|
|
1545
1545
|
// templates/world-sync-binary/agent.ts
|
|
1546
|
+
var BROADCAST_HZ = 30;
|
|
1547
|
+
var BROADCAST_INTERVAL_MS = Math.floor(1e3 / BROADCAST_HZ);
|
|
1548
|
+
var dirty = false;
|
|
1549
|
+
var broadcastTimer = null;
|
|
1546
1550
|
var snapshot = new WorldSnapshotBuffer();
|
|
1547
1551
|
var indexBySession = /* @__PURE__ */ new Map();
|
|
1548
1552
|
var sessionIds = [];
|
|
@@ -1596,17 +1600,32 @@ function removePeer(sessionId) {
|
|
|
1596
1600
|
sessionIds.length = peerCount;
|
|
1597
1601
|
}
|
|
1598
1602
|
function broadcastWorld() {
|
|
1603
|
+
dirty = false;
|
|
1599
1604
|
const payload = snapshot.encodePacked(sessionIds, xyz, peerCount);
|
|
1600
1605
|
broadCastBinaryToClients(payload, sessionIds, "sync");
|
|
1601
1606
|
}
|
|
1607
|
+
function startTickIfNeeded() {
|
|
1608
|
+
if (broadcastTimer || peerCount === 0) return;
|
|
1609
|
+
broadcastTimer = setInterval(() => {
|
|
1610
|
+
if (dirty) broadcastWorld();
|
|
1611
|
+
}, BROADCAST_INTERVAL_MS);
|
|
1612
|
+
}
|
|
1613
|
+
function stopTickIfIdle() {
|
|
1614
|
+
if (peerCount > 0 || !broadcastTimer) return;
|
|
1615
|
+
clearInterval(broadcastTimer);
|
|
1616
|
+
broadcastTimer = null;
|
|
1617
|
+
dirty = false;
|
|
1618
|
+
}
|
|
1602
1619
|
var agent_default = defineAgent({
|
|
1603
1620
|
onClientJoin({ sessionId }) {
|
|
1604
1621
|
setPose(sessionId, 0, 0, 0);
|
|
1622
|
+
startTickIfNeeded();
|
|
1605
1623
|
broadcastWorld();
|
|
1606
1624
|
},
|
|
1607
1625
|
onClientLeave({ sessionId }) {
|
|
1608
1626
|
removePeer(sessionId);
|
|
1609
1627
|
broadcastWorld();
|
|
1628
|
+
stopTickIfIdle();
|
|
1610
1629
|
},
|
|
1611
1630
|
onDataChannelBinary({ sessionId, rawBinary }) {
|
|
1612
1631
|
let index = indexBySession.get(sessionId);
|
|
@@ -1620,9 +1639,11 @@ var agent_default = defineAgent({
|
|
|
1620
1639
|
if (!decodePoseInto(rawBinary, xyz, index * POSE_FLOAT_COUNT)) {
|
|
1621
1640
|
return;
|
|
1622
1641
|
}
|
|
1623
|
-
|
|
1642
|
+
startTickIfNeeded();
|
|
1643
|
+
dirty = true;
|
|
1624
1644
|
}
|
|
1625
1645
|
});
|
|
1626
1646
|
export {
|
|
1647
|
+
BROADCAST_HZ,
|
|
1627
1648
|
agent_default as default
|
|
1628
1649
|
};
|
package/eject/llm/loop.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voicethere/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -92,6 +92,35 @@
|
|
|
92
92
|
"require": "./templates/redis-sync/world-layout.ts",
|
|
93
93
|
"default": "./templates/redis-sync/world-layout.ts"
|
|
94
94
|
},
|
|
95
|
+
"./templates/redis-sync/quantize": {
|
|
96
|
+
"types": "./templates/redis-sync/quantize.ts",
|
|
97
|
+
"import": "./templates/redis-sync/quantize.ts",
|
|
98
|
+
"require": "./templates/redis-sync/quantize.ts",
|
|
99
|
+
"default": "./templates/redis-sync/quantize.ts"
|
|
100
|
+
},
|
|
101
|
+
"./templates/game-sync/world-layout": {
|
|
102
|
+
"types": "./templates/game-sync/world-layout.ts",
|
|
103
|
+
"import": "./templates/game-sync/world-layout.ts",
|
|
104
|
+
"require": "./templates/game-sync/world-layout.ts",
|
|
105
|
+
"default": "./templates/game-sync/world-layout.ts"
|
|
106
|
+
},
|
|
107
|
+
"./templates/game-sync/quantize": {
|
|
108
|
+
"types": "./templates/game-sync/quantize.ts",
|
|
109
|
+
"import": "./templates/game-sync/quantize.ts",
|
|
110
|
+
"require": "./templates/game-sync/quantize.ts",
|
|
111
|
+
"default": "./templates/game-sync/quantize.ts"
|
|
112
|
+
},
|
|
113
|
+
"./templates/game-sync/sim": {
|
|
114
|
+
"types": "./templates/game-sync/sim.ts",
|
|
115
|
+
"import": "./templates/game-sync/sim.ts",
|
|
116
|
+
"require": "./templates/game-sync/sim.ts",
|
|
117
|
+
"default": "./templates/game-sync/sim.ts"
|
|
118
|
+
},
|
|
119
|
+
"./templates/redis-sync/quantized-frames.vectors.json": {
|
|
120
|
+
"import": "./templates/redis-sync/quantized-frames.vectors.json",
|
|
121
|
+
"require": "./templates/redis-sync/quantized-frames.vectors.json",
|
|
122
|
+
"default": "./templates/redis-sync/quantized-frames.vectors.json"
|
|
123
|
+
},
|
|
95
124
|
"./llm/eject/loop.ts": {
|
|
96
125
|
"types": "./eject/llm/loop.ts",
|
|
97
126
|
"import": "./eject/llm/loop.ts",
|
package/templates/README.md
CHANGED
|
@@ -51,7 +51,7 @@ Three product templates cover positional / world sync, from JSON to Redis:
|
|
|
51
51
|
| ------------------- | ------------------------------------------------------------------ | ----------------------------------- |
|
|
52
52
|
| `world-sync` | `onDataChannelMessage` (JSON) | One agent, in-memory, no Redis |
|
|
53
53
|
| `world-sync-binary` | `onDataChannelBinary` + `broadCastBinaryToClients` (`ArrayBuffer`) | One agent, in-memory, no Redis |
|
|
54
|
-
| `game-sync` | JSON control + binary world
|
|
54
|
+
| `game-sync` | JSON control + quantized binary world frames (30 Hz) | Redis when `AGENT_REDIS_URL` is set |
|
|
55
55
|
|
|
56
56
|
See each folder README for the wire format.
|
|
57
57
|
|
|
@@ -66,9 +66,9 @@ Each folder has its own README. Summary:
|
|
|
66
66
|
| `voice-starter` | `voice-starter/` | Every speech event |
|
|
67
67
|
| `language-switch` | `language-switch/` | Manual `setVoiceLanguage`, or runner auto-switch with a localized echo of the recognized text |
|
|
68
68
|
| `speaker-gate` | `speaker-gate/` | Caller speaker gate: `auto` listens to the enrolled caller only, `manual` labels every speaker; switch with `setSpeakerGate` |
|
|
69
|
-
| `world-sync` | `world-sync/` | JSON pose broadcast
|
|
70
|
-
| `world-sync-binary` | `world-sync-binary/` | Binary pose `ArrayBuffer
|
|
71
|
-
| `game-sync` | `game-sync/` | Authoritative sim,
|
|
69
|
+
| `world-sync` | `world-sync/` | JSON pose broadcast, one snapshot per 30 Hz tick when dirty |
|
|
70
|
+
| `world-sync-binary` | `world-sync-binary/` | Binary pose `ArrayBuffer`, one snapshot per 30 Hz tick when dirty |
|
|
71
|
+
| `game-sync` | `game-sync/` | Authoritative 60 Hz sim, quantized binary snapshots at 30 Hz, Redis when set |
|
|
72
72
|
| `voice-showcase` | `voice-showcase/` | Conversational landing demo |
|
|
73
73
|
| `recording-consent` | `recording-consent/` | Recording consent flow |
|
|
74
74
|
| `positional-tts` | `positional-tts/` | Orbiting TTS |
|
|
@@ -88,13 +88,13 @@ Each folder has its own README. Summary:
|
|
|
88
88
|
|
|
89
89
|
These were the end-to-end test fixtures; the tests resolve entries from the package, build them into ephemeral workdirs, and upload `dist/agent.js`.
|
|
90
90
|
|
|
91
|
-
| Id | Source | Purpose
|
|
92
|
-
| ----------------- | ----------------------------------------- |
|
|
93
|
-
| `echo-smoke` | `echo-smoke/agent.ts` | voice-smoke, agent-smoke, cli-smoke
|
|
94
|
-
| `crash` | `crash/agent.ts` | session-errors-smoke, crash-policy smokes
|
|
95
|
-
| `game-sync-smoke` | `game-sync-smoke/agent.ts` | deploy-smoke, shared-child, idle smokes
|
|
96
|
-
| `redis-sync` | `redis-sync/agent.ts` + `world-layout.ts` | redis-sync-smoke (
|
|
97
|
-
| `mix-smoke` | `mix-smoke/agent.ts` | voice-data-mix-smoke
|
|
91
|
+
| Id | Source | Purpose |
|
|
92
|
+
| ----------------- | ----------------------------------------- | ----------------------------------------------------------------------------- |
|
|
93
|
+
| `echo-smoke` | `echo-smoke/agent.ts` | voice-smoke, agent-smoke, cli-smoke |
|
|
94
|
+
| `crash` | `crash/agent.ts` | session-errors-smoke, crash-policy smokes |
|
|
95
|
+
| `game-sync-smoke` | `game-sync-smoke/agent.ts` | deploy-smoke, shared-child, idle smokes |
|
|
96
|
+
| `redis-sync` | `redis-sync/agent.ts` + `world-layout.ts` | redis-sync-smoke (quantized keyframe/delta frames at 20 Hz, Redis world blob) |
|
|
97
|
+
| `mix-smoke` | `mix-smoke/agent.ts` | voice-data-mix-smoke |
|
|
98
98
|
|
|
99
99
|
**Note:** Product `echo` is not the same as e2e `echo-smoke` — keep both ids.
|
|
100
100
|
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
# game-sync
|
|
2
2
|
|
|
3
|
-
Authoritative multi-object world sync for games and simulations. Live objects are capped at **25**. Clients register over JSON; the agent simulates at 60 Hz and broadcasts a **binary**
|
|
3
|
+
Authoritative multi-object world sync for games and simulations. Live objects are capped at **25**. Clients register over JSON; the agent simulates at 60 Hz and broadcasts a **quantized binary** world frame at 30 Hz (every second sim tick) with `broadCastBinaryToClients`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Frame format
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`u8 format (2) · u8 version (1) · u16le objectCount`, then one 18 B record per live object: `u16le objectId` and eight `i16le` values `[posX posY posZ posW dirX dirY dirZ dirW]`. Positions are bounded to the 1280 x 720 board and velocities to +-1024 px/s; `z`, `w`, `dirZ` and `dirW` are unit components stored as `round(v x 32767)`. A value outside its range is clamped and counted. A full frame of 25 objects is 454 B (the earlier Float32 snapshot was 900 B). The vectors in `templates/redis-sync/quantized-frames.vectors.json` (`gameSync`) pin the encoding, and `world-layout.ts` exports the encoder and decoder.
|
|
8
|
+
|
|
9
|
+
## Redis
|
|
10
|
+
|
|
11
|
+
When `AGENT_REDIS_URL` is set (Project Redis), the world blob (float32) lives at `game-sync:world` and is shared across runner workers. World writes (allocate, release, sim commit) take the `game-sync:sim-lock`, which holds a random per-attempt token: it is released by compare-and-delete and every write is conditional on the token, so a pod whose lock expired cannot overwrite a newer world. The world is stored with `game-sync:sim-at` (Redis clock, ms). A step advances by `now - sim-at` and is skipped when that is under one sim interval, so any number of pods simulate wall time once. When the lock is lost twice in a row, a register or unregister answers `{ type: "register_nack" | "unregister_nack", reason: "busy" }` and the client retries. Pods from before 0.37.0 use neither the token-conditional commit nor `game-sync:sim-at`, so do not run old and new game-sync pods side by side in one project; redeploy all pods.
|
|
12
|
+
|
|
13
|
+
Without Redis, state is per-worker in memory. The tick is allocation-free: live object ids go into a reusable `Int32Array`, tick bodies are module-level functions, and the broadcast is one call over a live session array.
|
|
14
|
+
|
|
15
|
+
This is the most advanced world-sync starter: Redis + quantized binary frames + server-side physics.
|
|
8
16
|
|
|
9
17
|
## Build
|
|
10
18
|
|
|
@@ -16,6 +24,7 @@ npx @voicethere/agent build --entry templates/game-sync/agent.ts --outfile dist/
|
|
|
16
24
|
|
|
17
25
|
- `agent.ts` — `defineAgent` wiring, register/unregister, sim loop
|
|
18
26
|
- `protocol.ts` — JSON control messages
|
|
19
|
-
- `world-layout.ts` — Float32Array slot layout
|
|
27
|
+
- `world-layout.ts` — Float32Array slot layout and the quantized frame encoder/decoder
|
|
28
|
+
- `quantize.ts` — int16 quantizer (same content as `redis-sync/quantize.ts`)
|
|
20
29
|
- `sim.ts` — wall bounce + collisions
|
|
21
30
|
- `redis.ts` — Lua allocate/release
|