@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.
- package/dist/app/server/index.d.ts +5 -0
- package/dist/app/server/index.d.ts.map +1 -1
- package/dist/app/server/index.js +13 -0
- package/dist/app/session/events.d.ts +35 -23
- package/dist/app/session/events.d.ts.map +1 -1
- package/dist/app/session/events.js +46 -38
- package/dist/app/session/index.d.ts +13 -13
- package/dist/app/session/index.d.ts.map +1 -1
- package/dist/app/session/index.js +237 -204
- package/dist/index.d.ts +28 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -1
- package/dist/types/message-types.d.ts +3 -1
- package/dist/types/message-types.d.ts.map +1 -1
- package/dist/types/message-types.js +9 -5
- package/dist/types/messages/cloud-to-app.d.ts +15 -5
- package/dist/types/messages/cloud-to-app.d.ts.map +1 -1
- package/dist/types/messages/cloud-to-app.js +4 -0
- package/dist/types/messages/cloud-to-glasses.d.ts +1 -0
- package/dist/types/messages/cloud-to-glasses.d.ts.map +1 -1
- package/dist/types/messages/glasses-to-cloud.d.ts +12 -1
- package/dist/types/messages/glasses-to-cloud.d.ts.map +1 -1
- package/dist/types/messages/glasses-to-cloud.js +4 -0
- package/dist/types/streams.d.ts +11 -5
- package/dist/types/streams.d.ts.map +1 -1
- package/dist/types/streams.js +75 -24
- package/package.json +1 -1
package/dist/types/streams.js
CHANGED
@@ -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
|
-
|
129
|
+
console.log(`🎤 Parsing language stream: ${subscription}`);
|
130
|
+
if (typeof subscription !== "string") {
|
130
131
|
return null;
|
131
132
|
}
|
132
|
-
//
|
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,
|
136
|
-
|
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
|
-
|
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,
|
150
|
-
const [
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
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
|
-
|
177
|
-
|
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
|
-
|
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
|
-
|
191
|
-
|
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(
|
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.
|
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",
|