@absolutejs/voice 0.0.12 → 0.0.14

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":
@@ -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":
@@ -539,12 +566,19 @@ var createMicrophoneCapture = (options) => {
539
566
  let processorNode = null;
540
567
  let mediaStream = null;
541
568
  const start = async () => {
569
+ if (typeof navigator === "undefined" || !navigator.mediaDevices?.getUserMedia) {
570
+ throw new Error("Browser microphone capture requires navigator.mediaDevices.getUserMedia.");
571
+ }
572
+ const AudioContextCtor = (typeof window !== "undefined" ? window.AudioContext ?? window.webkitAudioContext : undefined) ?? AudioContext;
573
+ if (!AudioContextCtor) {
574
+ throw new Error("Browser microphone capture requires AudioContext support.");
575
+ }
542
576
  mediaStream = await navigator.mediaDevices.getUserMedia({
543
577
  audio: {
544
578
  channelCount: options.channelCount ?? 1
545
579
  }
546
580
  });
547
- audioContext = new AudioContext;
581
+ audioContext = new AudioContextCtor;
548
582
  sourceNode = audioContext.createMediaStreamSource(mediaStream);
549
583
  processorNode = audioContext.createScriptProcessor(4096, 1, 1);
550
584
  processorNode.onaudioprocess = (event) => {
@@ -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":
@@ -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":
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":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",