@volley/recognition-client-sdk 0.1.800 → 0.1.806

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.
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { getRecognitionServiceBase } from '@recog/shared-config';
7
- import type { GameContextV1, Stage } from '@recog/shared-types';
7
+ import type { GameContextV1, Stage, MicrophoneSourceType } from '@recog/shared-types';
8
8
  import type { RecognitionCallbackUrl } from '../recognition-client.types.js';
9
9
 
10
10
  export interface UrlBuilderConfig {
@@ -17,6 +17,8 @@ export interface UrlBuilderConfig {
17
17
  deviceId?: string;
18
18
  accountId?: string;
19
19
  questionAnswerId?: string;
20
+ clientId?: string;
21
+ microphoneSourceType?: MicrophoneSourceType | string;
20
22
  platform?: string;
21
23
  gameContext?: GameContextV1;
22
24
  /** Standalone gameId - takes precedence over gameContext.gameId if both provided */
@@ -77,6 +79,12 @@ export function buildWebSocketUrl(config: UrlBuilderConfig): string {
77
79
  if (config.questionAnswerId) {
78
80
  url.searchParams.set('questionAnswerId', config.questionAnswerId);
79
81
  }
82
+ if (config.clientId) {
83
+ url.searchParams.set('clientId', config.clientId);
84
+ }
85
+ if (config.microphoneSourceType) {
86
+ url.searchParams.set('microphoneSourceType', config.microphoneSourceType);
87
+ }
80
88
  if (config.platform) {
81
89
  url.searchParams.set('platform', config.platform);
82
90
  }
@@ -46,6 +46,15 @@ export const RecognitionVGFStateSchema = z.object({
46
46
  functionCallConfidence: z.number().optional(), // Confidence score for the function call.
47
47
  finalFunctionCallTimestamp: z.string().optional(), // When the final action after interpreting the transcript was taken. Immutable.
48
48
 
49
+ // Session identity — when set, the VGF client backfills these into
50
+ // GameContextV1 if the caller didn't pass a `gameContext` in config.
51
+ // Lets RecognitionState be the single source of truth: server seeds
52
+ // `gameId` + `gamePhase` + `promptSlotMap` per player, controller passes
53
+ // the whole state as `initialState`, no separate `gameContext` needed.
54
+ // Backward-compatible: if `gameContext` is also passed in config, it wins.
55
+ gameId: z.string().optional(),
56
+ gamePhase: z.string().optional(),
57
+
49
58
  // Support for prompt slot mapping - passed to recognition context when present
50
59
  promptSlotMap: z.record(z.string(), z.array(z.string())).optional(), // Optional map of slot names to prompt values for recognition context
51
60
 
@@ -107,6 +116,22 @@ export function createInitialRecognitionState(audioUtteranceId: string): Recogni
107
116
  }
108
117
  }
109
118
 
119
+ // Helper for "session ended — no more state updates coming".
120
+ // Terminal states are FINALIZED (clean end with transcript), ABORTED
121
+ // (user cancelled), and ERROR (something failed). Use this anywhere
122
+ // you forward RecognitionState updates to a server thunk: persist
123
+ // every update, but only do cleanup / observability / scoring work
124
+ // after isTerminal(state) is true. Branch on `transcriptionStatus`
125
+ // when the action depends on *which* terminal state (e.g. only score
126
+ // on FINALIZED, only emit "cancelled" telemetry on ABORTED).
127
+ export function isTerminal(state: Pick<RecognitionState, "transcriptionStatus">): boolean {
128
+ return (
129
+ state.transcriptionStatus === TranscriptionStatus.FINALIZED ||
130
+ state.transcriptionStatus === TranscriptionStatus.ABORTED ||
131
+ state.transcriptionStatus === TranscriptionStatus.ERROR
132
+ )
133
+ }
134
+
110
135
  // Helper function to validate state transitions
111
136
  export function isValidRecordingStatusTransition(from: string | undefined, to: string): boolean {
112
137
  const statusOrder = [