agentgui 1.0.170 → 1.0.172

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.
@@ -134,19 +134,18 @@ class AgentRunner {
134
134
  return;
135
135
  }
136
136
 
137
- const success = code === 0 || (outputs.length > 0 && this.allowNonZeroExit);
138
-
139
- if (success) {
140
- if (jsonBuffer.trim()) {
141
- const parsed = this.parseOutput(jsonBuffer);
142
- if (parsed) {
143
- outputs.push(parsed);
144
- if (parsed.session_id) sessionId = parsed.session_id;
145
- if (onEvent) {
146
- try { onEvent(parsed); } catch (e) {}
147
- }
137
+ if (jsonBuffer.trim()) {
138
+ const parsed = this.parseOutput(jsonBuffer);
139
+ if (parsed) {
140
+ outputs.push(parsed);
141
+ if (parsed.session_id) sessionId = parsed.session_id;
142
+ if (onEvent) {
143
+ try { onEvent(parsed); } catch (e) {}
148
144
  }
149
145
  }
146
+ }
147
+
148
+ if (code === 0 || outputs.length > 0) {
150
149
  resolve({ outputs, sessionId });
151
150
  } else {
152
151
  reject(new Error(`${this.name} exited with code ${code}`));
package/lib/speech.js CHANGED
@@ -8,9 +8,19 @@ const require = createRequire(import.meta.url);
8
8
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
9
  const ROOT = path.dirname(__dirname);
10
10
  const DATA_DIR = path.join(ROOT, 'data');
11
- const VOICES_DIR = path.join(ROOT, 'voices');
12
- const HOME_VOICES_DIR = path.join(os.homedir(), 'voices');
13
11
  const AUDIO_EXTENSIONS = ['.mp3', '.wav', '.ogg', '.flac', '.m4a'];
12
+
13
+ function getVoiceDirs() {
14
+ const dirs = [];
15
+ const seen = new Set();
16
+ const add = (d) => { const r = path.resolve(d); if (!seen.has(r)) { seen.add(r); dirs.push(r); } };
17
+ const startupCwd = process.env.STARTUP_CWD || process.cwd();
18
+ add(path.join(startupCwd, 'voices'));
19
+ add(path.join(ROOT, 'voices'));
20
+ add(path.join(os.homedir(), 'voices'));
21
+ return dirs;
22
+ }
23
+
14
24
  const MIN_WAV_SIZE = 1000;
15
25
 
16
26
  const BASE_VOICES = [
@@ -24,14 +34,46 @@ const BASE_VOICES = [
24
34
  { id: 'ksp', name: 'KSP', gender: 'male', accent: 'Indian' },
25
35
  ];
26
36
 
37
+ async function convertToWav(filePath) {
38
+ const wavPath = filePath.replace(/\.[^.]+$/, '.wav');
39
+ if (fs.existsSync(wavPath)) return wavPath;
40
+ try {
41
+ console.log('[VOICES] Converting to WAV:', filePath);
42
+ const audio = await decodeAudioFile(filePath);
43
+ const wav = encodeWav(audio, SAMPLE_RATE_STT);
44
+ fs.writeFileSync(wavPath, wav);
45
+ console.log('[VOICES] Converted:', path.basename(wavPath));
46
+ return wavPath;
47
+ } catch (err) {
48
+ console.error('[VOICES] Conversion failed for', filePath + ':', err.message);
49
+ return null;
50
+ }
51
+ }
52
+
53
+ const pendingConversions = new Map();
54
+
27
55
  function scanVoiceDir(dir) {
28
56
  const voices = [];
29
57
  try {
30
58
  if (!fs.existsSync(dir)) return voices;
59
+ const listed = new Set();
31
60
  for (const file of fs.readdirSync(dir)) {
32
61
  const ext = path.extname(file).toLowerCase();
33
62
  if (!AUDIO_EXTENSIONS.includes(ext)) continue;
34
63
  const baseName = path.basename(file, ext);
64
+ if (ext !== '.wav') {
65
+ const wavExists = fs.existsSync(path.join(dir, baseName + '.wav'));
66
+ if (wavExists) continue;
67
+ const fullPath = path.join(dir, file);
68
+ if (!pendingConversions.has(fullPath)) {
69
+ pendingConversions.set(fullPath, convertToWav(fullPath).then(result => {
70
+ pendingConversions.delete(fullPath);
71
+ return result;
72
+ }));
73
+ }
74
+ }
75
+ if (listed.has(baseName)) continue;
76
+ listed.add(baseName);
35
77
  const id = 'custom_' + baseName.replace(/[^a-zA-Z0-9_-]/g, '_');
36
78
  const name = baseName.replace(/_/g, ' ');
37
79
  voices.push({ id, name, gender: 'custom', accent: 'custom', isCustom: true, sourceDir: dir });
@@ -45,7 +87,7 @@ function scanVoiceDir(dir) {
45
87
  function loadCustomVoices() {
46
88
  const seen = new Set();
47
89
  const voices = [];
48
- for (const dir of [VOICES_DIR, HOME_VOICES_DIR]) {
90
+ for (const dir of getVoiceDirs()) {
49
91
  for (const v of scanVoiceDir(dir)) {
50
92
  if (seen.has(v.id)) continue;
51
93
  seen.add(v.id);
@@ -170,7 +212,7 @@ async function getSpeakerEmbeddingPipeline() {
170
212
 
171
213
  function findCustomVoiceFile(voiceId) {
172
214
  const baseName = voiceId.replace(/^custom_/, '');
173
- for (const dir of [VOICES_DIR, HOME_VOICES_DIR]) {
215
+ for (const dir of getVoiceDirs()) {
174
216
  for (const ext of AUDIO_EXTENSIONS) {
175
217
  const candidate = path.join(dir, baseName + ext);
176
218
  if (fs.existsSync(candidate)) return candidate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentgui",
3
- "version": "1.0.170",
3
+ "version": "1.0.172",
4
4
  "description": "Multi-agent ACP client with real-time communication",
5
5
  "type": "module",
6
6
  "main": "server.js",
@@ -65,7 +65,7 @@
65
65
  selector.value = saved;
66
66
  }
67
67
  })
68
- .catch(function() {});
68
+ .catch(function(err) { console.error('[Voice] Failed to load voices:', err); });
69
69
  selector.addEventListener('change', function() {
70
70
  selectedVoiceId = selector.value;
71
71
  localStorage.setItem('voice-selected-id', selectedVoiceId);