@voicethere/agent 0.7.1 → 0.7.3

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.
@@ -130,6 +130,24 @@ var SessionSerialQueue = class {
130
130
  var SESSION_START_INIT_DELAY_ENABLED_ENV = "AGENT_SESSION_START_INIT_DELAY_ENABLED";
131
131
  var SESSION_START_INIT_DELAY_MS_ENV = "AGENT_SESSION_START_INIT_DELAY_MS";
132
132
  var DEFAULT_SESSION_START_INIT_DELAY_MS = 500;
133
+ function isPlayAckMessage(value) {
134
+ if (!value || typeof value !== "object")
135
+ return false;
136
+ const msg = value;
137
+ return msg.type === "play_ack" && typeof msg.requestId === "string";
138
+ }
139
+ function isPlayStatusAckMessage(value) {
140
+ if (!value || typeof value !== "object")
141
+ return false;
142
+ const msg = value;
143
+ return msg.type === "play_status_ack" && typeof msg.requestId === "string";
144
+ }
145
+ function isPlayStopAckMessage(value) {
146
+ if (!value || typeof value !== "object")
147
+ return false;
148
+ const msg = value;
149
+ return msg.type === "play_stop_ack" && typeof msg.requestId === "string";
150
+ }
133
151
  function isRecordingControlAckMessage(value) {
134
152
  if (!value || typeof value !== "object")
135
153
  return false;
@@ -190,7 +208,7 @@ function isParentMessage(value) {
190
208
  if (!value || typeof value !== "object")
191
209
  return false;
192
210
  const msg = value;
193
- return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
211
+ return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
194
212
  }
195
213
  function isSessionScopedParentMessage(value) {
196
214
  return isParentMessage(value) && !isWebhookMessage(value);
@@ -207,7 +225,11 @@ var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
207
225
  var mixAvailableBySessionId = /* @__PURE__ */ new Map();
208
226
  var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
209
227
  var endedSessionIds = /* @__PURE__ */ new Set();
228
+ var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
210
229
  var pendingRecordingAcks = /* @__PURE__ */ new Map();
230
+ var pendingPlayAcks = /* @__PURE__ */ new Map();
231
+ var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
232
+ var pendingPlayStopAcks = /* @__PURE__ */ new Map();
211
233
  var pendingMixAcks = /* @__PURE__ */ new Map();
212
234
  var pendingSttAcks = /* @__PURE__ */ new Map();
213
235
  function handleRecordingControlAck(message) {
@@ -222,6 +244,46 @@ function handleRecordingControlAck(message) {
222
244
  requestId: message.requestId
223
245
  });
224
246
  }
247
+ function handlePlayAck(message) {
248
+ const pending = pendingPlayAcks.get(message.requestId);
249
+ if (!pending)
250
+ return;
251
+ clearTimeout(pending.timer);
252
+ pendingPlayAcks.delete(message.requestId);
253
+ pending.resolve({
254
+ ok: message.ok,
255
+ ...message.playId ? { playId: message.playId } : {},
256
+ reason: message.reason,
257
+ requestId: message.requestId
258
+ });
259
+ }
260
+ function handlePlayStatusAck(message) {
261
+ const pending = pendingPlayStatusAcks.get(message.requestId);
262
+ if (!pending)
263
+ return;
264
+ clearTimeout(pending.timer);
265
+ pendingPlayStatusAcks.delete(message.requestId);
266
+ pending.resolve({
267
+ ok: message.ok,
268
+ playId: message.playId,
269
+ ...message.status ? { status: message.status } : {},
270
+ reason: message.reason,
271
+ requestId: message.requestId
272
+ });
273
+ }
274
+ function handlePlayStopAck(message) {
275
+ const pending = pendingPlayStopAcks.get(message.requestId);
276
+ if (!pending)
277
+ return;
278
+ clearTimeout(pending.timer);
279
+ pendingPlayStopAcks.delete(message.requestId);
280
+ pending.resolve({
281
+ ok: message.ok,
282
+ playId: message.playId,
283
+ reason: message.reason,
284
+ requestId: message.requestId
285
+ });
286
+ }
225
287
  function handleMixControlAck(message) {
226
288
  const pending = pendingMixAcks.get(message.requestId);
227
289
  if (!pending)
@@ -307,6 +369,10 @@ function sendParentMessage(message) {
307
369
  process.send?.(message);
308
370
  return;
309
371
  }
372
+ if (msgType === "play" || msgType === "play_status" || msgType === "play_stop") {
373
+ process.send?.(message);
374
+ return;
375
+ }
310
376
  const sessionId = message && typeof message === "object" && "sessionId" in message && typeof message.sessionId === "string" ? message.sessionId : void 0;
311
377
  if (!allowOutboundForSession(sessionId))
312
378
  return;
@@ -458,6 +524,18 @@ function defineAgent(handlers) {
458
524
  handleRecordingControlAck(message);
459
525
  return;
460
526
  }
527
+ if (isPlayAckMessage(message)) {
528
+ handlePlayAck(message);
529
+ return;
530
+ }
531
+ if (isPlayStatusAckMessage(message)) {
532
+ handlePlayStatusAck(message);
533
+ return;
534
+ }
535
+ if (isPlayStopAckMessage(message)) {
536
+ handlePlayStopAck(message);
537
+ return;
538
+ }
461
539
  if (isMixControlAckMessage(message)) {
462
540
  handleMixControlAck(message);
463
541
  return;
@@ -133,6 +133,24 @@ var SessionSerialQueue = class {
133
133
  var SESSION_START_INIT_DELAY_ENABLED_ENV = "AGENT_SESSION_START_INIT_DELAY_ENABLED";
134
134
  var SESSION_START_INIT_DELAY_MS_ENV = "AGENT_SESSION_START_INIT_DELAY_MS";
135
135
  var DEFAULT_SESSION_START_INIT_DELAY_MS = 500;
136
+ function isPlayAckMessage(value) {
137
+ if (!value || typeof value !== "object")
138
+ return false;
139
+ const msg = value;
140
+ return msg.type === "play_ack" && typeof msg.requestId === "string";
141
+ }
142
+ function isPlayStatusAckMessage(value) {
143
+ if (!value || typeof value !== "object")
144
+ return false;
145
+ const msg = value;
146
+ return msg.type === "play_status_ack" && typeof msg.requestId === "string";
147
+ }
148
+ function isPlayStopAckMessage(value) {
149
+ if (!value || typeof value !== "object")
150
+ return false;
151
+ const msg = value;
152
+ return msg.type === "play_stop_ack" && typeof msg.requestId === "string";
153
+ }
136
154
  function isRecordingControlAckMessage(value) {
137
155
  if (!value || typeof value !== "object")
138
156
  return false;
@@ -193,7 +211,7 @@ function isParentMessage(value) {
193
211
  if (!value || typeof value !== "object")
194
212
  return false;
195
213
  const msg = value;
196
- return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
214
+ return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
197
215
  }
198
216
  function isSessionScopedParentMessage(value) {
199
217
  return isParentMessage(value) && !isWebhookMessage(value);
@@ -210,7 +228,11 @@ var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
210
228
  var mixAvailableBySessionId = /* @__PURE__ */ new Map();
211
229
  var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
212
230
  var endedSessionIds = /* @__PURE__ */ new Set();
231
+ var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
213
232
  var pendingRecordingAcks = /* @__PURE__ */ new Map();
233
+ var pendingPlayAcks = /* @__PURE__ */ new Map();
234
+ var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
235
+ var pendingPlayStopAcks = /* @__PURE__ */ new Map();
214
236
  var pendingMixAcks = /* @__PURE__ */ new Map();
215
237
  var pendingSttAcks = /* @__PURE__ */ new Map();
216
238
  function handleRecordingControlAck(message) {
@@ -225,6 +247,46 @@ function handleRecordingControlAck(message) {
225
247
  requestId: message.requestId
226
248
  });
227
249
  }
250
+ function handlePlayAck(message) {
251
+ const pending = pendingPlayAcks.get(message.requestId);
252
+ if (!pending)
253
+ return;
254
+ clearTimeout(pending.timer);
255
+ pendingPlayAcks.delete(message.requestId);
256
+ pending.resolve({
257
+ ok: message.ok,
258
+ ...message.playId ? { playId: message.playId } : {},
259
+ reason: message.reason,
260
+ requestId: message.requestId
261
+ });
262
+ }
263
+ function handlePlayStatusAck(message) {
264
+ const pending = pendingPlayStatusAcks.get(message.requestId);
265
+ if (!pending)
266
+ return;
267
+ clearTimeout(pending.timer);
268
+ pendingPlayStatusAcks.delete(message.requestId);
269
+ pending.resolve({
270
+ ok: message.ok,
271
+ playId: message.playId,
272
+ ...message.status ? { status: message.status } : {},
273
+ reason: message.reason,
274
+ requestId: message.requestId
275
+ });
276
+ }
277
+ function handlePlayStopAck(message) {
278
+ const pending = pendingPlayStopAcks.get(message.requestId);
279
+ if (!pending)
280
+ return;
281
+ clearTimeout(pending.timer);
282
+ pendingPlayStopAcks.delete(message.requestId);
283
+ pending.resolve({
284
+ ok: message.ok,
285
+ playId: message.playId,
286
+ reason: message.reason,
287
+ requestId: message.requestId
288
+ });
289
+ }
228
290
  function handleMixControlAck(message) {
229
291
  const pending = pendingMixAcks.get(message.requestId);
230
292
  if (!pending)
@@ -310,6 +372,10 @@ function sendParentMessage(message) {
310
372
  process.send?.(message);
311
373
  return;
312
374
  }
375
+ if (msgType === "play" || msgType === "play_status" || msgType === "play_stop") {
376
+ process.send?.(message);
377
+ return;
378
+ }
313
379
  const sessionId = message && typeof message === "object" && "sessionId" in message && typeof message.sessionId === "string" ? message.sessionId : void 0;
314
380
  if (!allowOutboundForSession(sessionId))
315
381
  return;
@@ -461,6 +527,18 @@ function defineAgent(handlers) {
461
527
  handleRecordingControlAck(message);
462
528
  return;
463
529
  }
530
+ if (isPlayAckMessage(message)) {
531
+ handlePlayAck(message);
532
+ return;
533
+ }
534
+ if (isPlayStatusAckMessage(message)) {
535
+ handlePlayStatusAck(message);
536
+ return;
537
+ }
538
+ if (isPlayStopAckMessage(message)) {
539
+ handlePlayStopAck(message);
540
+ return;
541
+ }
464
542
  if (isMixControlAckMessage(message)) {
465
543
  handleMixControlAck(message);
466
544
  return;
@@ -10885,6 +10885,24 @@ var SessionSerialQueue = class {
10885
10885
  var SESSION_START_INIT_DELAY_ENABLED_ENV = "AGENT_SESSION_START_INIT_DELAY_ENABLED";
10886
10886
  var SESSION_START_INIT_DELAY_MS_ENV = "AGENT_SESSION_START_INIT_DELAY_MS";
10887
10887
  var DEFAULT_SESSION_START_INIT_DELAY_MS = 500;
10888
+ function isPlayAckMessage(value) {
10889
+ if (!value || typeof value !== "object")
10890
+ return false;
10891
+ const msg = value;
10892
+ return msg.type === "play_ack" && typeof msg.requestId === "string";
10893
+ }
10894
+ function isPlayStatusAckMessage(value) {
10895
+ if (!value || typeof value !== "object")
10896
+ return false;
10897
+ const msg = value;
10898
+ return msg.type === "play_status_ack" && typeof msg.requestId === "string";
10899
+ }
10900
+ function isPlayStopAckMessage(value) {
10901
+ if (!value || typeof value !== "object")
10902
+ return false;
10903
+ const msg = value;
10904
+ return msg.type === "play_stop_ack" && typeof msg.requestId === "string";
10905
+ }
10888
10906
  function isRecordingControlAckMessage(value) {
10889
10907
  if (!value || typeof value !== "object")
10890
10908
  return false;
@@ -10945,7 +10963,7 @@ function isParentMessage(value) {
10945
10963
  if (!value || typeof value !== "object")
10946
10964
  return false;
10947
10965
  const msg = value;
10948
- return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
10966
+ return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
10949
10967
  }
10950
10968
  function isSessionScopedParentMessage(value) {
10951
10969
  return isParentMessage(value) && !isWebhookMessage(value);
@@ -10962,7 +10980,11 @@ var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
10962
10980
  var mixAvailableBySessionId = /* @__PURE__ */ new Map();
10963
10981
  var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
10964
10982
  var endedSessionIds = /* @__PURE__ */ new Set();
10983
+ var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
10965
10984
  var pendingRecordingAcks = /* @__PURE__ */ new Map();
10985
+ var pendingPlayAcks = /* @__PURE__ */ new Map();
10986
+ var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
10987
+ var pendingPlayStopAcks = /* @__PURE__ */ new Map();
10966
10988
  var pendingMixAcks = /* @__PURE__ */ new Map();
10967
10989
  var pendingSttAcks = /* @__PURE__ */ new Map();
10968
10990
  function handleRecordingControlAck(message) {
@@ -10977,6 +10999,46 @@ function handleRecordingControlAck(message) {
10977
10999
  requestId: message.requestId
10978
11000
  });
10979
11001
  }
11002
+ function handlePlayAck(message) {
11003
+ const pending = pendingPlayAcks.get(message.requestId);
11004
+ if (!pending)
11005
+ return;
11006
+ clearTimeout(pending.timer);
11007
+ pendingPlayAcks.delete(message.requestId);
11008
+ pending.resolve({
11009
+ ok: message.ok,
11010
+ ...message.playId ? { playId: message.playId } : {},
11011
+ reason: message.reason,
11012
+ requestId: message.requestId
11013
+ });
11014
+ }
11015
+ function handlePlayStatusAck(message) {
11016
+ const pending = pendingPlayStatusAcks.get(message.requestId);
11017
+ if (!pending)
11018
+ return;
11019
+ clearTimeout(pending.timer);
11020
+ pendingPlayStatusAcks.delete(message.requestId);
11021
+ pending.resolve({
11022
+ ok: message.ok,
11023
+ playId: message.playId,
11024
+ ...message.status ? { status: message.status } : {},
11025
+ reason: message.reason,
11026
+ requestId: message.requestId
11027
+ });
11028
+ }
11029
+ function handlePlayStopAck(message) {
11030
+ const pending = pendingPlayStopAcks.get(message.requestId);
11031
+ if (!pending)
11032
+ return;
11033
+ clearTimeout(pending.timer);
11034
+ pendingPlayStopAcks.delete(message.requestId);
11035
+ pending.resolve({
11036
+ ok: message.ok,
11037
+ playId: message.playId,
11038
+ reason: message.reason,
11039
+ requestId: message.requestId
11040
+ });
11041
+ }
10980
11042
  function handleMixControlAck(message) {
10981
11043
  const pending = pendingMixAcks.get(message.requestId);
10982
11044
  if (!pending)
@@ -11062,6 +11124,10 @@ function sendParentMessage(message) {
11062
11124
  process.send?.(message);
11063
11125
  return;
11064
11126
  }
11127
+ if (msgType === "play" || msgType === "play_status" || msgType === "play_stop") {
11128
+ process.send?.(message);
11129
+ return;
11130
+ }
11065
11131
  const sessionId = message && typeof message === "object" && "sessionId" in message && typeof message.sessionId === "string" ? message.sessionId : void 0;
11066
11132
  if (!allowOutboundForSession(sessionId))
11067
11133
  return;
@@ -11213,6 +11279,18 @@ function defineAgent(handlers) {
11213
11279
  handleRecordingControlAck(message);
11214
11280
  return;
11215
11281
  }
11282
+ if (isPlayAckMessage(message)) {
11283
+ handlePlayAck(message);
11284
+ return;
11285
+ }
11286
+ if (isPlayStatusAckMessage(message)) {
11287
+ handlePlayStatusAck(message);
11288
+ return;
11289
+ }
11290
+ if (isPlayStopAckMessage(message)) {
11291
+ handlePlayStopAck(message);
11292
+ return;
11293
+ }
11216
11294
  if (isMixControlAckMessage(message)) {
11217
11295
  handleMixControlAck(message);
11218
11296
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicethere/agent",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
5
5
  "type": "module",
6
6
  "exports": {
@@ -95,9 +95,9 @@
95
95
  "@node-webrtc-rust/sdk": ">=0.6.5"
96
96
  },
97
97
  "devDependencies": {
98
- "@node-webrtc-rust/helpers": "0.8.0",
99
- "@node-webrtc-rust/sdk": "0.8.0",
100
- "@node-webrtc-rust/signaling": "0.8.0",
98
+ "@node-webrtc-rust/helpers": "0.9.0",
99
+ "@node-webrtc-rust/sdk": "0.9.0",
100
+ "@node-webrtc-rust/signaling": "0.9.0",
101
101
  "@types/node": "22.20.1",
102
102
  "http-server": "14.1.1",
103
103
  "ioredis": "5.11.1",
@@ -10,20 +10,28 @@
10
10
  * - `{ type: "mix", action: "set_global_mute", clientId, muted, sttEnabled? }`
11
11
  * - `{ type: "mix", action: "set_listener_mute", listenerId, targetId, muted }`
12
12
  * - `{ type: "mix", action: "get_status", clientId? }`
13
+ * - `{ type: "mix", action: "set_tts_pose", clientId, pose }`
14
+ * - `{ type: "mix", action: "speak", clientId, text }`
15
+ * - `{ type: "mix", action: "clear_tts_pose", clientId }`
16
+ * - `{ type: "mix", action: "play", sessionIds?, bytes?, url?, volume? }`
13
17
  *
14
18
  * Acks: `{ type: "mix_ack", action, ok: true, statuses?, ... }` or `{ ok: false, error }`.
15
- * Ignores `ping` / chat strings (voice-control readiness). No TTS during smoke.
19
+ * Ignores `ping` / chat strings (voice-control readiness).
16
20
  */
17
21
  import {
18
22
  MIX_REQUIRES_VOICE_PLUS_DATA,
23
+ clearTtsPose,
19
24
  createMixGroup,
20
25
  defineAgent,
21
26
  getClientMixStatus,
27
+ play,
22
28
  sendToClient,
23
29
  setClientPose,
24
30
  setGlobalMute,
25
31
  setListenerMute,
26
32
  setPositionalMixing,
33
+ setTtsPose,
34
+ speak,
27
35
  } from "@voicethere/agent";
28
36
 
29
37
  /** E2E fixture marker — rewritten before each fixture upload when needed. */
@@ -59,7 +67,18 @@ export type MixCommand =
59
67
  targetId: string;
60
68
  muted: boolean;
61
69
  }
62
- | { type: "mix"; action: "get_status"; clientId?: string };
70
+ | { type: "mix"; action: "get_status"; clientId?: string }
71
+ | { type: "mix"; action: "set_tts_pose"; clientId: string; pose: MixPose }
72
+ | { type: "mix"; action: "speak"; clientId: string; text: string }
73
+ | { type: "mix"; action: "clear_tts_pose"; clientId: string }
74
+ | {
75
+ type: "mix";
76
+ action: "play";
77
+ sessionIds?: string[];
78
+ bytes?: string;
79
+ url?: string;
80
+ volume?: number;
81
+ };
63
82
 
64
83
  export type MixClientStatus = {
65
84
  clientId?: string;
@@ -77,6 +96,7 @@ export type MixAck =
77
96
  sessionId?: string;
78
97
  clientIds?: string[];
79
98
  statuses?: MixClientStatus[];
99
+ playId?: string;
80
100
  }
81
101
  | { type: "mix_ack"; action: string; ok: false; error: string };
82
102
 
@@ -161,6 +181,71 @@ export function isMixCommand(message: unknown): message is MixCommand {
161
181
  typeof status.clientId === "string" && status.clientId.trim().length > 0
162
182
  );
163
183
  }
184
+ case "set_tts_pose": {
185
+ const ttsPose = message as { clientId?: unknown; pose?: unknown };
186
+ return (
187
+ typeof ttsPose.clientId === "string" &&
188
+ ttsPose.clientId.trim().length > 0 &&
189
+ isMixPose(ttsPose.pose)
190
+ );
191
+ }
192
+ case "speak": {
193
+ const speakMsg = message as { clientId?: unknown; text?: unknown };
194
+ return (
195
+ typeof speakMsg.clientId === "string" &&
196
+ speakMsg.clientId.trim().length > 0 &&
197
+ typeof speakMsg.text === "string" &&
198
+ speakMsg.text.trim().length > 0
199
+ );
200
+ }
201
+ case "clear_tts_pose": {
202
+ const clearMsg = message as { clientId?: unknown };
203
+ return (
204
+ typeof clearMsg.clientId === "string" &&
205
+ clearMsg.clientId.trim().length > 0
206
+ );
207
+ }
208
+ case "play": {
209
+ const playMsg = message as {
210
+ sessionIds?: unknown;
211
+ bytes?: unknown;
212
+ url?: unknown;
213
+ volume?: unknown;
214
+ };
215
+ const hasBytes =
216
+ typeof playMsg.bytes === "string" && playMsg.bytes.trim().length > 0;
217
+ const hasUrl =
218
+ typeof playMsg.url === "string" && playMsg.url.trim().length > 0;
219
+ if (!hasBytes && !hasUrl) {
220
+ return false;
221
+ }
222
+ if (
223
+ playMsg.bytes !== undefined &&
224
+ (typeof playMsg.bytes !== "string" || playMsg.bytes.trim().length === 0)
225
+ ) {
226
+ return false;
227
+ }
228
+ if (
229
+ playMsg.url !== undefined &&
230
+ (typeof playMsg.url !== "string" || playMsg.url.trim().length === 0)
231
+ ) {
232
+ return false;
233
+ }
234
+ if (playMsg.sessionIds !== undefined) {
235
+ if (
236
+ !Array.isArray(playMsg.sessionIds) ||
237
+ !playMsg.sessionIds.every(
238
+ (id) => typeof id === "string" && id.trim().length > 0,
239
+ )
240
+ ) {
241
+ return false;
242
+ }
243
+ }
244
+ if (playMsg.volume !== undefined && typeof playMsg.volume !== "number") {
245
+ return false;
246
+ }
247
+ return true;
248
+ }
164
249
  default:
165
250
  return false;
166
251
  }
@@ -202,6 +287,7 @@ function ackOk(
202
287
  sessionId?: string;
203
288
  clientIds?: string[];
204
289
  statuses?: MixClientStatus[];
290
+ playId?: string;
205
291
  },
206
292
  ): void {
207
293
  sendToClient(sessionId, {
@@ -327,6 +413,50 @@ async function handleMixCommand(
327
413
  });
328
414
  return;
329
415
  }
416
+ case "set_tts_pose": {
417
+ if (!requireMix(sessionId, action)) return;
418
+ const result = await setTtsPose(command.clientId, command.pose);
419
+ if (!result.ok) {
420
+ ackError(sessionId, action, result.reason ?? "set_tts_pose failed");
421
+ return;
422
+ }
423
+ ackOk(sessionId, action);
424
+ return;
425
+ }
426
+ case "speak": {
427
+ if (!requireMix(sessionId, action)) return;
428
+ speak(command.clientId, command.text);
429
+ ackOk(sessionId, action);
430
+ return;
431
+ }
432
+ case "clear_tts_pose": {
433
+ if (!requireMix(sessionId, action)) return;
434
+ const result = await clearTtsPose(command.clientId);
435
+ if (!result.ok) {
436
+ ackError(sessionId, action, result.reason ?? "clear_tts_pose failed");
437
+ return;
438
+ }
439
+ ackOk(sessionId, action);
440
+ return;
441
+ }
442
+ case "play": {
443
+ const inlineUrl =
444
+ command.url?.trim() || "https://example.com/inline-clip.wav";
445
+ const result = await play({
446
+ url: inlineUrl,
447
+ ...(command.sessionIds?.length
448
+ ? { sessionIds: command.sessionIds }
449
+ : {}),
450
+ ...(command.bytes ? { bytes: command.bytes } : {}),
451
+ ...(command.volume !== undefined ? { volume: command.volume } : {}),
452
+ });
453
+ if (!result.ok || !result.playId) {
454
+ ackError(sessionId, action, result.reason ?? "play failed");
455
+ return;
456
+ }
457
+ ackOk(sessionId, action, { playId: result.playId });
458
+ return;
459
+ }
330
460
  default:
331
461
  ackError(sessionId, "unknown", "unsupported mix action");
332
462
  }