@absolutejs/voice 0.0.13 → 0.0.15

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.
@@ -73,6 +73,33 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
73
73
  import { computed, Injectable, signal } from "@angular/core";
74
74
 
75
75
  // src/client/actions.ts
76
+ var normalizeErrorMessage = (value) => {
77
+ if (typeof value === "string" && value.trim()) {
78
+ return value;
79
+ }
80
+ if (value instanceof Error && value.message.trim()) {
81
+ return value.message;
82
+ }
83
+ if (value && typeof value === "object") {
84
+ const record = value;
85
+ for (const key of ["message", "reason", "description"]) {
86
+ const candidate = record[key];
87
+ if (typeof candidate === "string" && candidate.trim()) {
88
+ return candidate;
89
+ }
90
+ }
91
+ if ("error" in record) {
92
+ return normalizeErrorMessage(record.error);
93
+ }
94
+ if ("cause" in record) {
95
+ return normalizeErrorMessage(record.cause);
96
+ }
97
+ try {
98
+ return JSON.stringify(value);
99
+ } catch {}
100
+ }
101
+ return "Unexpected error";
102
+ };
76
103
  var serverMessageToAction = (message) => {
77
104
  switch (message.type) {
78
105
  case "assistant":
@@ -87,7 +114,7 @@ var serverMessageToAction = (message) => {
87
114
  };
88
115
  case "error":
89
116
  return {
90
- message: message.message,
117
+ message: normalizeErrorMessage(message.message),
91
118
  type: "error"
92
119
  };
93
120
  case "final":
@@ -352,7 +379,7 @@ var createVoiceStreamStore = () => {
352
379
  case "final":
353
380
  state = {
354
381
  ...state,
355
- partial: "",
382
+ partial: action.transcript.text,
356
383
  turns: state.turns.map((turn) => turn)
357
384
  };
358
385
  break;
@@ -253,6 +253,33 @@ var createVoiceConnection = (path, options = {}) => {
253
253
  };
254
254
  };
255
255
  // src/client/actions.ts
256
+ var normalizeErrorMessage = (value) => {
257
+ if (typeof value === "string" && value.trim()) {
258
+ return value;
259
+ }
260
+ if (value instanceof Error && value.message.trim()) {
261
+ return value.message;
262
+ }
263
+ if (value && typeof value === "object") {
264
+ const record = value;
265
+ for (const key of ["message", "reason", "description"]) {
266
+ const candidate = record[key];
267
+ if (typeof candidate === "string" && candidate.trim()) {
268
+ return candidate;
269
+ }
270
+ }
271
+ if ("error" in record) {
272
+ return normalizeErrorMessage(record.error);
273
+ }
274
+ if ("cause" in record) {
275
+ return normalizeErrorMessage(record.cause);
276
+ }
277
+ try {
278
+ return JSON.stringify(value);
279
+ } catch {}
280
+ }
281
+ return "Unexpected error";
282
+ };
256
283
  var serverMessageToAction = (message) => {
257
284
  switch (message.type) {
258
285
  case "assistant":
@@ -267,7 +294,7 @@ var serverMessageToAction = (message) => {
267
294
  };
268
295
  case "error":
269
296
  return {
270
- message: message.message,
297
+ message: normalizeErrorMessage(message.message),
271
298
  type: "error"
272
299
  };
273
300
  case "final":
@@ -348,7 +375,7 @@ var createVoiceStreamStore = () => {
348
375
  case "final":
349
376
  state = {
350
377
  ...state,
351
- partial: "",
378
+ partial: action.transcript.text,
352
379
  turns: state.turns.map((turn) => turn)
353
380
  };
354
381
  break;
package/dist/index.js CHANGED
@@ -236,12 +236,36 @@ var toVoiceSessionSummary = (session) => ({
236
236
 
237
237
  // src/turnDetection.ts
238
238
  var DEFAULT_SILENCE_MS = 700;
239
+ var normalizeText = (value) => value.trim().replace(/\s+/g, " ");
240
+ var mergeTranscriptTexts = (transcripts) => {
241
+ const merged = [];
242
+ for (const transcript of transcripts) {
243
+ const nextText = normalizeText(transcript.text);
244
+ if (!nextText) {
245
+ continue;
246
+ }
247
+ const previous = merged.at(-1);
248
+ if (!previous) {
249
+ merged.push(nextText);
250
+ continue;
251
+ }
252
+ if (nextText === previous || previous.includes(nextText)) {
253
+ continue;
254
+ }
255
+ if (nextText.includes(previous)) {
256
+ merged[merged.length - 1] = nextText;
257
+ continue;
258
+ }
259
+ merged.push(nextText);
260
+ }
261
+ return merged.join(" ").trim();
262
+ };
239
263
  var buildTurnText = (transcripts, partialText) => {
240
- const finalText = transcripts.map((transcript) => transcript.text.trim()).filter(Boolean).join(" ").trim();
264
+ const finalText = mergeTranscriptTexts(transcripts);
241
265
  if (finalText) {
242
266
  return finalText;
243
267
  }
244
- return partialText.trim();
268
+ return normalizeText(partialText);
245
269
  };
246
270
 
247
271
  // src/session.ts
@@ -338,7 +362,7 @@ var createVoiceSession = (options) => {
338
362
  const handlePartial = async (transcript) => {
339
363
  await writeSession((session) => {
340
364
  session.currentTurn.lastAudioAt = Date.now();
341
- session.currentTurn.partialText = transcript.text;
365
+ session.currentTurn.partialText = buildTurnText(session.currentTurn.transcripts, transcript.text);
342
366
  session.lastActivityAt = Date.now();
343
367
  session.status = "active";
344
368
  });
@@ -73,6 +73,33 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
73
73
  import { useEffect, useRef, useSyncExternalStore } from "react";
74
74
 
75
75
  // src/client/actions.ts
76
+ var normalizeErrorMessage = (value) => {
77
+ if (typeof value === "string" && value.trim()) {
78
+ return value;
79
+ }
80
+ if (value instanceof Error && value.message.trim()) {
81
+ return value.message;
82
+ }
83
+ if (value && typeof value === "object") {
84
+ const record = value;
85
+ for (const key of ["message", "reason", "description"]) {
86
+ const candidate = record[key];
87
+ if (typeof candidate === "string" && candidate.trim()) {
88
+ return candidate;
89
+ }
90
+ }
91
+ if ("error" in record) {
92
+ return normalizeErrorMessage(record.error);
93
+ }
94
+ if ("cause" in record) {
95
+ return normalizeErrorMessage(record.cause);
96
+ }
97
+ try {
98
+ return JSON.stringify(value);
99
+ } catch {}
100
+ }
101
+ return "Unexpected error";
102
+ };
76
103
  var serverMessageToAction = (message) => {
77
104
  switch (message.type) {
78
105
  case "assistant":
@@ -87,7 +114,7 @@ var serverMessageToAction = (message) => {
87
114
  };
88
115
  case "error":
89
116
  return {
90
- message: message.message,
117
+ message: normalizeErrorMessage(message.message),
91
118
  type: "error"
92
119
  };
93
120
  case "final":
@@ -352,7 +379,7 @@ var createVoiceStreamStore = () => {
352
379
  case "final":
353
380
  state = {
354
381
  ...state,
355
- partial: "",
382
+ partial: action.transcript.text,
356
383
  turns: state.turns.map((turn) => turn)
357
384
  };
358
385
  break;
@@ -70,6 +70,33 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
70
70
  };
71
71
 
72
72
  // src/client/actions.ts
73
+ var normalizeErrorMessage = (value) => {
74
+ if (typeof value === "string" && value.trim()) {
75
+ return value;
76
+ }
77
+ if (value instanceof Error && value.message.trim()) {
78
+ return value.message;
79
+ }
80
+ if (value && typeof value === "object") {
81
+ const record = value;
82
+ for (const key of ["message", "reason", "description"]) {
83
+ const candidate = record[key];
84
+ if (typeof candidate === "string" && candidate.trim()) {
85
+ return candidate;
86
+ }
87
+ }
88
+ if ("error" in record) {
89
+ return normalizeErrorMessage(record.error);
90
+ }
91
+ if ("cause" in record) {
92
+ return normalizeErrorMessage(record.cause);
93
+ }
94
+ try {
95
+ return JSON.stringify(value);
96
+ } catch {}
97
+ }
98
+ return "Unexpected error";
99
+ };
73
100
  var serverMessageToAction = (message) => {
74
101
  switch (message.type) {
75
102
  case "assistant":
@@ -84,7 +111,7 @@ var serverMessageToAction = (message) => {
84
111
  };
85
112
  case "error":
86
113
  return {
87
- message: message.message,
114
+ message: normalizeErrorMessage(message.message),
88
115
  type: "error"
89
116
  };
90
117
  case "final":
@@ -349,7 +376,7 @@ var createVoiceStreamStore = () => {
349
376
  case "final":
350
377
  state = {
351
378
  ...state,
352
- partial: "",
379
+ partial: action.transcript.text,
353
380
  turns: state.turns.map((turn) => turn)
354
381
  };
355
382
  break;
package/dist/vue/index.js CHANGED
@@ -73,6 +73,33 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
73
73
  import { onUnmounted, ref, shallowRef } from "vue";
74
74
 
75
75
  // src/client/actions.ts
76
+ var normalizeErrorMessage = (value) => {
77
+ if (typeof value === "string" && value.trim()) {
78
+ return value;
79
+ }
80
+ if (value instanceof Error && value.message.trim()) {
81
+ return value.message;
82
+ }
83
+ if (value && typeof value === "object") {
84
+ const record = value;
85
+ for (const key of ["message", "reason", "description"]) {
86
+ const candidate = record[key];
87
+ if (typeof candidate === "string" && candidate.trim()) {
88
+ return candidate;
89
+ }
90
+ }
91
+ if ("error" in record) {
92
+ return normalizeErrorMessage(record.error);
93
+ }
94
+ if ("cause" in record) {
95
+ return normalizeErrorMessage(record.cause);
96
+ }
97
+ try {
98
+ return JSON.stringify(value);
99
+ } catch {}
100
+ }
101
+ return "Unexpected error";
102
+ };
76
103
  var serverMessageToAction = (message) => {
77
104
  switch (message.type) {
78
105
  case "assistant":
@@ -87,7 +114,7 @@ var serverMessageToAction = (message) => {
87
114
  };
88
115
  case "error":
89
116
  return {
90
- message: message.message,
117
+ message: normalizeErrorMessage(message.message),
91
118
  type: "error"
92
119
  };
93
120
  case "final":
@@ -352,7 +379,7 @@ var createVoiceStreamStore = () => {
352
379
  case "final":
353
380
  state = {
354
381
  ...state,
355
- partial: "",
382
+ partial: action.transcript.text,
356
383
  turns: state.turns.map((turn) => turn)
357
384
  };
358
385
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",