@volley/recognition-client-sdk 0.1.287 → 0.1.295

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,38 @@ export class SimplifiedVGFRecognitionClient implements ISimplifiedVGFRecognition
254
277
  await this.client.stopRecording();
255
278
  }
256
279
 
280
+ stopAbnormally(): void {
281
+ const clientState = this.client.getState();
282
+
283
+ // Guard: Block if graceful shutdown in progress or already in terminal state
284
+ // This prevents stopAbnormally from disrupting stopRecording's graceful finalization
285
+ if (clientState === ClientState.STOPPING ||
286
+ clientState === ClientState.STOPPED ||
287
+ clientState === ClientState.FAILED) {
288
+ // Already stopping/stopped - do nothing to avoid disrupting graceful shutdown
289
+ return;
290
+ }
291
+
292
+ this.isRecordingAudio = false;
293
+
294
+ // Set state to ABORTED - preserve any partial transcript received so far
295
+ // This clearly indicates the session was cancelled/abandoned by user
296
+ if (this.state.transcriptionStatus !== TranscriptionStatus.ABORTED &&
297
+ this.state.transcriptionStatus !== TranscriptionStatus.FINALIZED) {
298
+ this.state = {
299
+ ...this.state,
300
+ transcriptionStatus: TranscriptionStatus.ABORTED,
301
+ startRecordingStatus: RecordingStatus.FINISHED,
302
+ finalRecordingTimestamp: new Date().toISOString(),
303
+ finalTranscriptionTimestamp: new Date().toISOString()
304
+ };
305
+ this.notifyStateChange();
306
+ }
307
+
308
+ // Delegate to underlying client for actual WebSocket cleanup
309
+ this.client.stopAbnormally();
310
+ }
311
+
257
312
  // Pure delegation methods - no state logic
258
313
  getAudioUtteranceId(): string {
259
314
  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