Skip to content

Commit b8c3546

Browse files
committed
fix tests
1 parent d9066f3 commit b8c3546

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

agents/src/voice/agent_activity.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ export class AgentActivity implements RecognitionHooks {
459459
const hasSttOld = !!this.stt;
460460
const hasSttNew = !!newActivity.stt;
461461
const sameSttInstance = this.stt === newActivity.stt;
462-
const sameSttNode = Object.getPrototypeOf(this.agent).sttNode === Object.getPrototypeOf(newActivity.agent).sttNode;
462+
const sameSttNode =
463+
Object.getPrototypeOf(this.agent).sttNode ===
464+
Object.getPrototypeOf(newActivity.agent).sttNode;
463465

464466
if (!hasAudioRecognition || !hasSttOld || !hasSttNew) {
465467
return undefined;

agents/src/voice/audio_recognition.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,15 @@ export class STTPipeline {
9696
const node = await this.sttNode(this._audioChannel.stream(), {});
9797
if (node === null) return;
9898

99-
for await (const value of readStream(node, signal)) {
100-
if (typeof value === 'string') {
101-
throw new Error(`STT node must yield SpeechEvent, got: ${typeof value}`);
99+
try {
100+
for await (const value of readStream(node, signal)) {
101+
if (typeof value === 'string') {
102+
throw new Error(`STT node must yield SpeechEvent, got: ${typeof value}`);
103+
}
104+
await this._eventChannel.write(value);
102105
}
103-
await this._eventChannel.write(value);
106+
} finally {
107+
await node.cancel().catch(() => {});
104108
}
105109
}
106110

agents/src/voice/audio_recognition_handoff.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { describe, expect, it, vi } from 'vitest';
66
import { ChatContext } from '../llm/chat_context.js';
77
import { initializeLogger } from '../log.js';
88
import { type SpeechEvent, SpeechEventType } from '../stt/stt.js';
9-
import { AudioRecognition, STTPipeline, type RecognitionHooks } from './audio_recognition.js';
9+
import { AudioRecognition, type RecognitionHooks, STTPipeline } from './audio_recognition.js';
1010
import type { STTNode } from './io.js';
1111

1212
function createHooks() {

0 commit comments

Comments
 (0)