@volley/recognition-client-sdk 0.1.287 → 0.1.294

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.
@@ -8,7 +8,11 @@
8
8
  * All functionality is delegated to the underlying client.
9
9
  */
10
10
 
11
- import { RecognitionState } from './vgf-recognition-state.js';
11
+ import {
12
+ RecognitionState,
13
+ TranscriptionStatus,
14
+ RecordingStatus
15
+ } from './vgf-recognition-state.js';
12
16
  import {
13
17
  IRecognitionClient,
14
18
  IRecognitionClientConfig,
@@ -67,6 +71,25 @@ export interface ISimplifiedVGFRecognitionClient {
67
71
  */
68
72
  stopRecording(): Promise<void>;
69
73
 
74
+ /**
75
+ * Force stop and immediately close connection without waiting for server
76
+ *
77
+ * WARNING: This is an abnormal shutdown that bypasses the graceful stop flow:
78
+ * - Does NOT wait for server to process remaining audio
79
+ * - Does NOT receive final transcript from server (VGF state set to empty)
80
+ * - Immediately closes WebSocket connection
81
+ * - Cleans up resources (buffers, listeners)
82
+ *
83
+ * Use Cases:
84
+ * - User explicitly cancels/abandons the session
85
+ * - Timeout scenarios where waiting is not acceptable
86
+ * - Need immediate cleanup and can't wait for server
87
+ *
88
+ * RECOMMENDED: Use stopRecording() for normal shutdown.
89
+ * Only use this when immediate disconnection is required.
90
+ */
91
+ stopAbnormally(): void;
92
+
70
93
  // ============= VGF State Methods =============
71
94
  /**
72
95
  * Get the current VGF recognition state
@@ -254,6 +277,40 @@ export class SimplifiedVGFRecognitionClient implements ISimplifiedVGFRecognition
254
277
  await this.client.stopRecording();
255
278
  }
256
279
 
280
+ stopAbnormally(): void {
281
+ // Guard: If already aborted/finalized and stopped, do nothing
282
+ if ((this.state.transcriptionStatus === TranscriptionStatus.ABORTED ||
283
+ this.state.transcriptionStatus === TranscriptionStatus.FINALIZED) &&
284
+ this.client.getState() === ClientState.STOPPED) {
285
+ // Already fully stopped - nothing to do
286
+ return;
287
+ }
288
+
289
+ this.isRecordingAudio = false;
290
+
291
+ // Set state to ABORTED with empty transcript
292
+ // This clearly indicates the session was cancelled/abandoned by user
293
+ if (this.state.transcriptionStatus !== TranscriptionStatus.ABORTED &&
294
+ this.state.transcriptionStatus !== TranscriptionStatus.FINALIZED) {
295
+ this.state = {
296
+ ...this.state,
297
+ transcriptionStatus: TranscriptionStatus.ABORTED,
298
+ finalTranscript: '',
299
+ startRecordingStatus: RecordingStatus.FINISHED,
300
+ finalRecordingTimestamp: new Date().toISOString(),
301
+ finalTranscriptionTimestamp: new Date().toISOString()
302
+ };
303
+ this.notifyStateChange();
304
+ }
305
+
306
+ // Delegate to underlying client for actual WebSocket cleanup
307
+ // Only if client is not already in a terminal state
308
+ const clientState = this.client.getState();
309
+ if (clientState !== ClientState.STOPPED && clientState !== ClientState.FAILED) {
310
+ this.client.stopAbnormally();
311
+ }
312
+ }
313
+
257
314
  // Pure delegation methods - no state logic
258
315
  getAudioUtteranceId(): string {
259
316
  return this.client.getAudioUtteranceId();
@@ -18,7 +18,7 @@ export const RecognitionVGFStateSchema = z.object({
18
18
  audioUtteranceId: z.string(),
19
19
  startRecordingStatus: z.string().optional(), // "NOT_READY", "READY", "RECORDING", "FINISHED". States follow this order.
20
20
  // Streaming should only start when "READY". Other states control mic UI and recording.
21
- transcriptionStatus: z.string().optional(), // "NOT_STARTED", "IN_PROGRESS", "FINALIZED", "ERROR"
21
+ transcriptionStatus: z.string().optional(), // "NOT_STARTED", "IN_PROGRESS", "FINALIZED", "ABORTED", "ERROR"
22
22
  finalTranscript: z.string().optional(), // Full finalized transcript for the utterance. Will not change.
23
23
  finalConfidence: z.number().optional(),
24
24
 
@@ -57,6 +57,7 @@ export const TranscriptionStatus = {
57
57
  NOT_STARTED: "NOT_STARTED",
58
58
  IN_PROGRESS: "IN_PROGRESS",
59
59
  FINALIZED: "FINALIZED",
60
+ ABORTED: "ABORTED", // Session was cancelled/abandoned by user
60
61
  ERROR: "ERROR",
61
62
  } as const
62
63