@mentra/sdk 2.1.13 → 2.1.15

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.
@@ -122,44 +122,78 @@ function isValidLanguageCode(code) {
122
122
  /**
123
123
  * Parse a subscription string to extract language information
124
124
  *
125
- * @param subscription Subscription string (e.g., "transcription:en-US" or "translation:es-ES-to-en-US")
125
+ * @param subscription Subscription string (e.g., "transcription:en-US" or "translation:es-ES-to-en-US" or "transcription:en-US?no-language-identification=true")
126
126
  * @returns Parsed language stream info or null if not a language-specific subscription
127
127
  */
128
128
  function parseLanguageStream(subscription) {
129
- if (typeof subscription !== 'string') {
129
+ console.log(`🎤 Parsing language stream: ${subscription}`);
130
+ if (typeof subscription !== "string") {
130
131
  return null;
131
132
  }
132
- // console.log(`🎤 Parsing language stream: ${subscription}`);
133
- // Handle transcription format (transcription:en-US)
133
+ // Handle transcription format (transcription:en-US or transcription:en-US?options)
134
134
  if (subscription.startsWith(`${StreamType.TRANSCRIPTION}:`)) {
135
- const [baseType, languageCode] = subscription.split(':');
136
- // console.log(`🎤 Parsing transcription stream: ${subscription}`);
137
- // console.log(`🎤 Language code: ${languageCode}`);
135
+ const [baseType, rest] = subscription.split(":");
136
+ const [languageCode, queryString] = rest?.split("?") ?? [];
138
137
  if (languageCode && isValidLanguageCode(languageCode)) {
138
+ const options = {};
139
+ // Parse query parameters if present
140
+ if (queryString) {
141
+ const params = new URLSearchParams(queryString);
142
+ for (const [key, value] of params.entries()) {
143
+ // Convert string values to boolean when appropriate
144
+ if (value === "true") {
145
+ options[key] = true;
146
+ }
147
+ else if (value === "false") {
148
+ options[key] = false;
149
+ }
150
+ else {
151
+ options[key] = value;
152
+ }
153
+ }
154
+ }
139
155
  return {
140
156
  type: StreamType.TRANSCRIPTION,
141
157
  baseType,
142
158
  transcribeLanguage: languageCode,
143
- original: subscription
159
+ options: Object.keys(options).length > 0 ? options : undefined,
160
+ original: subscription,
144
161
  };
145
162
  }
146
163
  }
147
- // Handle translation format (translation:es-ES-to-en-US)
164
+ // Handle translation format (translation:es-ES-to-en-US or translation:es-ES-to-en-US?options)
148
165
  if (subscription.startsWith(`${StreamType.TRANSLATION}:`)) {
149
- const [baseType, languagePair] = subscription.split(':');
150
- const [sourceLanguage, targetLanguage] = languagePair?.split('-to-') ?? [];
151
- // console.log(`🎤 Parsing translation stream: ${subscription}`);
152
- // console.log(`🎤 Source language: ${sourceLanguage}`);
153
- // console.log(`🎤 Target language: ${targetLanguage}`);
154
- if (sourceLanguage && targetLanguage &&
166
+ const [baseType, rest] = subscription.split(":");
167
+ const [languagePair, queryString] = rest?.split("?") ?? [];
168
+ const [sourceLanguage, targetLanguage] = languagePair?.split("-to-") ?? [];
169
+ if (sourceLanguage &&
170
+ targetLanguage &&
155
171
  isValidLanguageCode(sourceLanguage) &&
156
172
  isValidLanguageCode(targetLanguage)) {
173
+ const options = {};
174
+ // Parse query parameters if present
175
+ if (queryString) {
176
+ const params = new URLSearchParams(queryString);
177
+ for (const [key, value] of params.entries()) {
178
+ // Convert string values to boolean when appropriate
179
+ if (value === "true") {
180
+ options[key] = true;
181
+ }
182
+ else if (value === "false") {
183
+ options[key] = false;
184
+ }
185
+ else {
186
+ options[key] = value;
187
+ }
188
+ }
189
+ }
157
190
  return {
158
191
  type: StreamType.TRANSLATION,
159
192
  baseType,
160
193
  transcribeLanguage: sourceLanguage,
161
194
  translateLanguage: targetLanguage,
162
- original: subscription
195
+ options: Object.keys(options).length > 0 ? options : undefined,
196
+ original: subscription,
163
197
  };
164
198
  }
165
199
  }
@@ -172,11 +206,19 @@ function parseLanguageStream(subscription) {
172
206
  * @param language Language code (e.g., "en-US")
173
207
  * @returns Typed stream identifier
174
208
  */
175
- function createTranscriptionStream(language) {
176
- if (!isValidLanguageCode(language)) {
177
- throw new Error(`Invalid language code: ${language}`);
209
+ function createTranscriptionStream(language, options) {
210
+ console.log(`🎤 Creating transcription stream for language: ${language}`);
211
+ console.log(`🎤 Options: ${JSON.stringify(options)}`);
212
+ // Defensively remove any query string from the language parameter
213
+ const languageCode = language.split("?")[0];
214
+ if (!isValidLanguageCode(languageCode)) {
215
+ throw new Error(`Invalid language code: ${languageCode}`);
178
216
  }
179
- return createLanguageStream(`${StreamType.TRANSCRIPTION}:${language}`);
217
+ const base = `${StreamType.TRANSCRIPTION}:${languageCode}`;
218
+ if (options?.disableLanguageIdentification) {
219
+ return `${base}?no-language-identification=true`;
220
+ }
221
+ return base;
180
222
  }
181
223
  /**
182
224
  * Create a translation stream identifier for a language pair
@@ -184,13 +226,22 @@ function createTranscriptionStream(language) {
184
226
  *
185
227
  * @param sourceLanguage Source language code (e.g., "es-ES")
186
228
  * @param targetLanguage Target language code (e.g., "en-US")
229
+ * @param options Optional configuration options
187
230
  * @returns Typed stream identifier
188
231
  */
189
- function createTranslationStream(sourceLanguage, targetLanguage) {
190
- if (!isValidLanguageCode(sourceLanguage) || !isValidLanguageCode(targetLanguage)) {
191
- throw new Error(`Invalid language code(s): ${sourceLanguage}, ${targetLanguage}`);
232
+ function createTranslationStream(sourceLanguage, targetLanguage, options) {
233
+ // Defensively remove any query string from the language parameters
234
+ const cleanSourceLanguage = sourceLanguage.split("?")[0];
235
+ const cleanTargetLanguage = targetLanguage.split("?")[0];
236
+ if (!isValidLanguageCode(cleanSourceLanguage) ||
237
+ !isValidLanguageCode(cleanTargetLanguage)) {
238
+ throw new Error(`Invalid language code(s): ${cleanSourceLanguage}, ${cleanTargetLanguage}`);
239
+ }
240
+ const base = `${StreamType.TRANSLATION}:${cleanSourceLanguage}-to-${cleanTargetLanguage}`;
241
+ if (options?.disableLanguageIdentification) {
242
+ return `${base}?no-language-identification=true`;
192
243
  }
193
- return createLanguageStream(`${StreamType.TRANSLATION}:${sourceLanguage}-to-${targetLanguage}`);
244
+ return createLanguageStream(base);
194
245
  }
195
246
  /**
196
247
  * Check if a subscription is a valid stream type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/sdk",
3
- "version": "2.1.13",
3
+ "version": "2.1.15",
4
4
  "description": "Build apps for MentraOS smartglasses. This SDK provides everything you need to create real-time smartglasses applications.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",