@mentingo/luma-sdk 0.0.0-stage → 0.4.0
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/LICENSE +21 -0
- package/README.md +275 -2
- package/dist/chunk-W5CQGEDB.js +966 -0
- package/dist/contracts-qTi7LQB8.d.cts +3668 -0
- package/dist/contracts-qTi7LQB8.d.ts +3668 -0
- package/dist/contracts.cjs +283 -0
- package/dist/contracts.d.cts +3 -0
- package/dist/contracts.d.ts +3 -0
- package/dist/contracts.js +58 -0
- package/dist/index.cjs +1751 -0
- package/dist/index.d.cts +215 -0
- package/dist/index.d.ts +215 -0
- package/dist/index.js +775 -0
- package/package.json +69 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
import {
|
|
2
|
+
API,
|
|
3
|
+
AUDIO_PROVIDER_STATES,
|
|
4
|
+
AUDIO_RECOVERY_STATES,
|
|
5
|
+
AiCapability,
|
|
6
|
+
AiCapabilityMode,
|
|
7
|
+
AiCapabilityProvider,
|
|
8
|
+
AiModelDomain,
|
|
9
|
+
AiModelProfileKind,
|
|
10
|
+
AuthoringSubscriptionError,
|
|
11
|
+
EXTERNAL_AUDIO_CLIENT_RECONNECT_GRACE_MS,
|
|
12
|
+
EXTERNAL_AUDIO_MAX_BUFFERED_CHUNKS,
|
|
13
|
+
EXTERNAL_AUDIO_MAX_RECOVERY_ATTEMPTS,
|
|
14
|
+
EXTERNAL_AUDIO_OPERATION,
|
|
15
|
+
EXTERNAL_AUDIO_RECOVERY_STATE,
|
|
16
|
+
EXTERNAL_AUDIO_RECOVERY_TIMEOUT_MS,
|
|
17
|
+
EXTERNAL_AUDIO_TERMINAL_RECOVERY_ERROR_CODES,
|
|
18
|
+
LEARNER_TRANSCRIPT_STATUSES,
|
|
19
|
+
LUMA_AI_MODEL_DOMAINS,
|
|
20
|
+
LUMA_AI_MODEL_PROFILE_KINDS,
|
|
21
|
+
LUMA_AUDIO_ACTIONS,
|
|
22
|
+
LUMA_AUDIO_FORMATS,
|
|
23
|
+
LUMA_CAPTURE_PROFILES,
|
|
24
|
+
LUMA_MENTOR_STREAM_EVENT_TYPES,
|
|
25
|
+
LUMA_SOCKET_EMIT_EVENTS,
|
|
26
|
+
LUMA_SOCKET_LISTEN_EVENTS,
|
|
27
|
+
LUMA_SOCKET_MESSAGE_TYPES,
|
|
28
|
+
LUMA_VOICE_TIMING_PRECISION,
|
|
29
|
+
ReasoningEffort,
|
|
30
|
+
TRANSCRIPTION_MODES,
|
|
31
|
+
TTSProvider,
|
|
32
|
+
TaskKind,
|
|
33
|
+
TextToSpeechProvider,
|
|
34
|
+
TurnPartKind,
|
|
35
|
+
TurnPartStatus,
|
|
36
|
+
TurnStatus
|
|
37
|
+
} from "./chunk-W5CQGEDB.js";
|
|
38
|
+
|
|
39
|
+
// src/types.ts
|
|
40
|
+
var AI_MENTOR_CONFIGURATION_TYPES = {
|
|
41
|
+
TEACHER: "teacher",
|
|
42
|
+
ROLEPLAY: "roleplay"
|
|
43
|
+
};
|
|
44
|
+
var LUMA_AI_CAPABILITY_MODES = {
|
|
45
|
+
CORE: "core" /* Core */,
|
|
46
|
+
CUSTOM: "custom" /* Custom */,
|
|
47
|
+
DISABLED: "disabled" /* Disabled */
|
|
48
|
+
};
|
|
49
|
+
var LUMA_AI_CAPABILITY_PROVIDERS = {
|
|
50
|
+
LUMA: "luma" /* Luma */,
|
|
51
|
+
MENTINGO_CORE: "mentingo-core" /* MentingoCore */
|
|
52
|
+
};
|
|
53
|
+
var LUMA_AI_CAPABILITIES = {
|
|
54
|
+
COURSE_GENERATION: "courseGeneration" /* CourseGeneration */,
|
|
55
|
+
COURSE_GENERATION_VISUAL_ASSETS: "courseGenerationVisualAssets" /* CourseGenerationVisualAssets */,
|
|
56
|
+
COURSE_GENERATION_EMBEDDINGS: "courseGenerationEmbeddings" /* CourseGenerationEmbeddings */,
|
|
57
|
+
AI_MENTOR_CHAT: "aiMentorChat" /* AiMentorChat */,
|
|
58
|
+
AI_MENTOR_JUDGE: "aiMentorJudge" /* AiMentorJudge */,
|
|
59
|
+
AI_MENTOR_CONFIGURATION_GENERATOR: "aiMentorConfigurationGenerator" /* AiMentorConfigurationGenerator */,
|
|
60
|
+
AI_JUDGE_CONFIGURATION_GENERATOR: "aiJudgeConfigurationGenerator" /* AiJudgeConfigurationGenerator */,
|
|
61
|
+
AI_JUDGE_CONFIGURATION_VALIDATOR: "aiJudgeConfigurationValidator" /* AiJudgeConfigurationValidator */,
|
|
62
|
+
AI_MENTOR_RAG_EMBEDDINGS: "aiMentorRagEmbeddings" /* AiMentorRagEmbeddings */,
|
|
63
|
+
TRANSLATION_GENERATION: "translationGeneration" /* TranslationGeneration */,
|
|
64
|
+
DICTATION_TRANSCRIPTION: "dictationTranscription" /* DictationTranscription */,
|
|
65
|
+
VOICE_TRANSCRIPTION: "voiceTranscription" /* VoiceTranscription */,
|
|
66
|
+
VOICE_MENTOR: "voiceMentor" /* VoiceMentor */,
|
|
67
|
+
VOICE_TEXT_TO_SPEECH: "voiceTextToSpeech" /* VoiceTextToSpeech */
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/http/ai.ts
|
|
71
|
+
var LumaAiClient = class {
|
|
72
|
+
constructor(apiClient) {
|
|
73
|
+
this.apiClient = apiClient;
|
|
74
|
+
}
|
|
75
|
+
async createEmbeddings(opts) {
|
|
76
|
+
const response = await this.apiClient.api.createEmbeddingsApiPublicV1AiEmbeddingsPost(opts);
|
|
77
|
+
return response.data;
|
|
78
|
+
}
|
|
79
|
+
async generateJudgeConfiguration(opts) {
|
|
80
|
+
const response = await this.apiClient.api.generateJudgeConfigurationApiPublicV1AiJudgeConfigurationGeneratePost(
|
|
81
|
+
opts
|
|
82
|
+
);
|
|
83
|
+
return response.data;
|
|
84
|
+
}
|
|
85
|
+
async generateMentorConfiguration(opts) {
|
|
86
|
+
const configurationType = opts.configurationType === AI_MENTOR_CONFIGURATION_TYPES.TEACHER ? "teacher" /* Teacher */ : "roleplay" /* Roleplay */;
|
|
87
|
+
const response = await this.apiClient.api.generateMentorConfigurationApiPublicV1AiMentorConfigurationGeneratePost(
|
|
88
|
+
{ ...opts, configurationType }
|
|
89
|
+
);
|
|
90
|
+
return response.data;
|
|
91
|
+
}
|
|
92
|
+
async validateJudgeConfiguration(opts) {
|
|
93
|
+
const response = await this.apiClient.api.validateJudgeConfigurationApiPublicV1AiJudgeConfigurationValidatePost(
|
|
94
|
+
opts
|
|
95
|
+
);
|
|
96
|
+
return response.data;
|
|
97
|
+
}
|
|
98
|
+
async validateMentorConfiguration(opts) {
|
|
99
|
+
const response = await this.apiClient.api.validateMentorConfigurationApiPublicV1AiMentorConfigurationValidatePost(
|
|
100
|
+
opts
|
|
101
|
+
);
|
|
102
|
+
return response.data;
|
|
103
|
+
}
|
|
104
|
+
async generateTranslations(opts) {
|
|
105
|
+
const response = await this.apiClient.api.generateTranslationsApiPublicV1AiTranslationsGeneratePost(opts);
|
|
106
|
+
return response.data;
|
|
107
|
+
}
|
|
108
|
+
async transcribeDictation(opts) {
|
|
109
|
+
const response = await this.apiClient.api.transcribeDictationApiPublicV1AiTranscriptionsPost(opts);
|
|
110
|
+
return response.data;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/http/admin.ts
|
|
115
|
+
var ADMIN_API_KEY_REQUIRED_MESSAGE = "Luma API key is required. Pass apiKey to createLumaClient({ apiKey }).";
|
|
116
|
+
var AdminApiExecutions = class {
|
|
117
|
+
constructor(apiClient, apiKey) {
|
|
118
|
+
this.apiClient = apiClient;
|
|
119
|
+
this.apiKey = apiKey;
|
|
120
|
+
}
|
|
121
|
+
assertAdminApiKey() {
|
|
122
|
+
if (!this.apiKey?.trim()) {
|
|
123
|
+
throw new Error(ADMIN_API_KEY_REQUIRED_MESSAGE);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async listApiKeys(opts) {
|
|
127
|
+
this.assertAdminApiKey();
|
|
128
|
+
const response = await this.apiClient.api.listOrganizationApiKeysApiPublicV1AdminOrganizationsOrganizationIdApiKeysGet(
|
|
129
|
+
opts.organizationId
|
|
130
|
+
);
|
|
131
|
+
return response.data;
|
|
132
|
+
}
|
|
133
|
+
async createApiKey(opts) {
|
|
134
|
+
this.assertAdminApiKey();
|
|
135
|
+
const response = await this.apiClient.api.createOrganizationApiKeyApiPublicV1AdminOrganizationsOrganizationIdApiKeysPost(
|
|
136
|
+
opts.organizationId,
|
|
137
|
+
{ name: opts.name }
|
|
138
|
+
);
|
|
139
|
+
return response.data;
|
|
140
|
+
}
|
|
141
|
+
async getApiKey(opts) {
|
|
142
|
+
this.assertAdminApiKey();
|
|
143
|
+
const response = await this.apiClient.api.getOrganizationApiKeyApiPublicV1AdminOrganizationsOrganizationIdApiKeysApiKeyIdGet(
|
|
144
|
+
opts.organizationId,
|
|
145
|
+
opts.apiKeyId
|
|
146
|
+
);
|
|
147
|
+
return response.data;
|
|
148
|
+
}
|
|
149
|
+
async updateApiKey(opts) {
|
|
150
|
+
this.assertAdminApiKey();
|
|
151
|
+
const { organizationId, apiKeyId, ...data } = opts;
|
|
152
|
+
const response = await this.apiClient.api.updateOrganizationApiKeyApiPublicV1AdminOrganizationsOrganizationIdApiKeysApiKeyIdPatch(
|
|
153
|
+
organizationId,
|
|
154
|
+
apiKeyId,
|
|
155
|
+
data
|
|
156
|
+
);
|
|
157
|
+
return response.data;
|
|
158
|
+
}
|
|
159
|
+
async revokeApiKey(opts) {
|
|
160
|
+
this.assertAdminApiKey();
|
|
161
|
+
const response = await this.apiClient.api.revokeOrganizationApiKeyApiPublicV1AdminOrganizationsOrganizationIdApiKeysApiKeyIdDelete(
|
|
162
|
+
opts.organizationId,
|
|
163
|
+
opts.apiKeyId
|
|
164
|
+
);
|
|
165
|
+
return response.data;
|
|
166
|
+
}
|
|
167
|
+
async getConfiguration(opts) {
|
|
168
|
+
this.assertAdminApiKey();
|
|
169
|
+
const response = await this.apiClient.api.getOrganizationApiKeyConfigurationApiPublicV1AdminOrganizationsOrganizationIdApiKeysApiKeyIdConfigurationGet(
|
|
170
|
+
opts.organizationId,
|
|
171
|
+
opts.apiKeyId
|
|
172
|
+
);
|
|
173
|
+
return response.data;
|
|
174
|
+
}
|
|
175
|
+
async listAssignments(opts) {
|
|
176
|
+
this.assertAdminApiKey();
|
|
177
|
+
const response = await this.apiClient.api.listOrganizationApiKeyAssignmentsApiPublicV1AdminOrganizationsOrganizationIdApiKeysApiKeyIdAiModelAssignmentsGet(
|
|
178
|
+
opts.organizationId,
|
|
179
|
+
opts.apiKeyId
|
|
180
|
+
);
|
|
181
|
+
return response.data;
|
|
182
|
+
}
|
|
183
|
+
async updateAssignment(opts) {
|
|
184
|
+
this.assertAdminApiKey();
|
|
185
|
+
const response = await this.apiClient.api.updateOrganizationApiKeyAssignmentApiPublicV1AdminOrganizationsOrganizationIdApiKeysApiKeyIdAiModelAssignmentsDomainPatch(
|
|
186
|
+
opts.organizationId,
|
|
187
|
+
opts.apiKeyId,
|
|
188
|
+
opts.domain,
|
|
189
|
+
{
|
|
190
|
+
mode: opts.mode,
|
|
191
|
+
modelProfileId: opts.modelProfileId
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
return response.data;
|
|
195
|
+
}
|
|
196
|
+
async listModelProfiles(opts) {
|
|
197
|
+
this.assertAdminApiKey();
|
|
198
|
+
const response = await this.apiClient.api.listOrganizationAiModelProfilesApiPublicV1AdminOrganizationsOrganizationIdAiModelProfilesGet(
|
|
199
|
+
opts.organizationId
|
|
200
|
+
);
|
|
201
|
+
return response.data;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
var LumaAdminApiKeysClient = class {
|
|
205
|
+
constructor(executions) {
|
|
206
|
+
this.executions = executions;
|
|
207
|
+
}
|
|
208
|
+
list(opts) {
|
|
209
|
+
return this.executions.listApiKeys(opts);
|
|
210
|
+
}
|
|
211
|
+
create(opts) {
|
|
212
|
+
return this.executions.createApiKey(opts);
|
|
213
|
+
}
|
|
214
|
+
get(opts) {
|
|
215
|
+
return this.executions.getApiKey(opts);
|
|
216
|
+
}
|
|
217
|
+
update(opts) {
|
|
218
|
+
return this.executions.updateApiKey(opts);
|
|
219
|
+
}
|
|
220
|
+
revoke(opts) {
|
|
221
|
+
return this.executions.revokeApiKey(opts);
|
|
222
|
+
}
|
|
223
|
+
getConfiguration(opts) {
|
|
224
|
+
return this.executions.getConfiguration(opts);
|
|
225
|
+
}
|
|
226
|
+
listAssignments(opts) {
|
|
227
|
+
return this.executions.listAssignments(opts);
|
|
228
|
+
}
|
|
229
|
+
updateAssignment(opts) {
|
|
230
|
+
return this.executions.updateAssignment(opts);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var LumaAdminModelProfilesClient = class {
|
|
234
|
+
constructor(executions) {
|
|
235
|
+
this.executions = executions;
|
|
236
|
+
}
|
|
237
|
+
list(opts) {
|
|
238
|
+
return this.executions.listModelProfiles(opts);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
var LumaAdminClient = class {
|
|
242
|
+
constructor(apiClient, apiKey) {
|
|
243
|
+
const executions = new AdminApiExecutions(apiClient, apiKey);
|
|
244
|
+
this.apiKeys = new LumaAdminApiKeysClient(executions);
|
|
245
|
+
this.modelProfiles = new LumaAdminModelProfilesClient(executions);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/http/authoring.stream.ts
|
|
250
|
+
var MAX_FRAME_CHARACTERS = 1048576;
|
|
251
|
+
var toText = (chunk, decoder) => {
|
|
252
|
+
if (typeof chunk === "string") return chunk;
|
|
253
|
+
if (chunk instanceof Uint8Array) return decoder.decode(chunk, { stream: true });
|
|
254
|
+
throw new Error("Unsupported authoring event stream chunk");
|
|
255
|
+
};
|
|
256
|
+
async function* streamChunks(body) {
|
|
257
|
+
if (typeof body === "string" || body instanceof Uint8Array) {
|
|
258
|
+
yield body;
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (typeof body !== "object" || body === null) {
|
|
262
|
+
throw new Error("Authoring event stream body is unavailable");
|
|
263
|
+
}
|
|
264
|
+
const stream = body;
|
|
265
|
+
const iteratorFactory = stream[Symbol.asyncIterator];
|
|
266
|
+
if (iteratorFactory) {
|
|
267
|
+
const iterator = iteratorFactory.call(stream);
|
|
268
|
+
let completed = false;
|
|
269
|
+
try {
|
|
270
|
+
while (true) {
|
|
271
|
+
const item = await iterator.next();
|
|
272
|
+
if (item.done) {
|
|
273
|
+
completed = true;
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
yield item.value;
|
|
277
|
+
}
|
|
278
|
+
} finally {
|
|
279
|
+
if (!completed) await iterator.return?.();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (stream.getReader) {
|
|
283
|
+
const reader = stream.getReader();
|
|
284
|
+
try {
|
|
285
|
+
while (true) {
|
|
286
|
+
const item = await reader.read();
|
|
287
|
+
if (item.done) return;
|
|
288
|
+
yield item.value;
|
|
289
|
+
}
|
|
290
|
+
} finally {
|
|
291
|
+
await reader.cancel?.();
|
|
292
|
+
reader.releaseLock();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
throw new Error("Authoring event stream is not readable");
|
|
296
|
+
}
|
|
297
|
+
var parseFrame = (raw) => {
|
|
298
|
+
let event = "message";
|
|
299
|
+
let id;
|
|
300
|
+
const data = [];
|
|
301
|
+
for (const line of raw.split("\n")) {
|
|
302
|
+
if (!line || line.startsWith(":")) continue;
|
|
303
|
+
const separator = line.indexOf(":");
|
|
304
|
+
const field = separator === -1 ? line : line.slice(0, separator);
|
|
305
|
+
let value = separator === -1 ? "" : line.slice(separator + 1);
|
|
306
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
307
|
+
if (field === "event") event = value;
|
|
308
|
+
if (field === "id") id = value;
|
|
309
|
+
if (field === "data") data.push(value);
|
|
310
|
+
}
|
|
311
|
+
if (data.length === 0) return null;
|
|
312
|
+
return { event, id, data: data.join("\n") };
|
|
313
|
+
};
|
|
314
|
+
var isAuthoringEvent = (value) => {
|
|
315
|
+
if (typeof value !== "object" || value === null) return false;
|
|
316
|
+
const event = value;
|
|
317
|
+
return event.schemaVersion === 1 && typeof event.eventId === "string" && typeof event.sessionId === "string" && Number.isSafeInteger(event.sequence) && Number(event.sequence) > 0 && typeof event.occurredAt === "string" && typeof event.type === "string" && typeof event.payload === "object" && event.payload !== null;
|
|
318
|
+
};
|
|
319
|
+
var terminalError = (data) => {
|
|
320
|
+
const value = JSON.parse(data);
|
|
321
|
+
if (typeof value !== "object" || value === null || !("code" in value)) {
|
|
322
|
+
throw new Error("Invalid authoring.error event payload");
|
|
323
|
+
}
|
|
324
|
+
const code = value.code;
|
|
325
|
+
if (code !== "history_expired" && code !== "permission_revoked") {
|
|
326
|
+
throw new Error(`Unknown authoring.error code: ${String(code)}`);
|
|
327
|
+
}
|
|
328
|
+
return new AuthoringSubscriptionError(code);
|
|
329
|
+
};
|
|
330
|
+
var deliverFrame = async (frame, options) => {
|
|
331
|
+
if (frame.event === "authoring.error") {
|
|
332
|
+
const error = terminalError(frame.data);
|
|
333
|
+
await options.onError?.(error);
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
if (frame.event !== "authoring.event") return;
|
|
337
|
+
const value = JSON.parse(frame.data);
|
|
338
|
+
if (!isAuthoringEvent(value)) throw new Error("Invalid authoring.event payload");
|
|
339
|
+
if (value.sessionId !== options.sessionId) {
|
|
340
|
+
throw new Error("Authoring event session does not match subscription");
|
|
341
|
+
}
|
|
342
|
+
if (frame.id !== void 0 && frame.id !== String(value.sequence)) {
|
|
343
|
+
throw new Error("Authoring event id does not match sequence");
|
|
344
|
+
}
|
|
345
|
+
await options.onEvent(value);
|
|
346
|
+
};
|
|
347
|
+
var consumeAuthoringEventStream = async (body, options) => {
|
|
348
|
+
const decoder = new TextDecoder();
|
|
349
|
+
let buffer = "";
|
|
350
|
+
for await (const chunk of streamChunks(body)) {
|
|
351
|
+
buffer += toText(chunk, decoder);
|
|
352
|
+
buffer = buffer.replace(/\r\n/g, "\n");
|
|
353
|
+
let boundary = buffer.indexOf("\n\n");
|
|
354
|
+
while (boundary !== -1) {
|
|
355
|
+
if (boundary > MAX_FRAME_CHARACTERS) {
|
|
356
|
+
throw new Error("Authoring event stream frame exceeds size limit");
|
|
357
|
+
}
|
|
358
|
+
const frame = parseFrame(buffer.slice(0, boundary));
|
|
359
|
+
buffer = buffer.slice(boundary + 2);
|
|
360
|
+
if (frame) await deliverFrame(frame, options);
|
|
361
|
+
boundary = buffer.indexOf("\n\n");
|
|
362
|
+
}
|
|
363
|
+
if (buffer.length > MAX_FRAME_CHARACTERS) {
|
|
364
|
+
throw new Error("Authoring event stream frame exceeds size limit");
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
buffer += decoder.decode();
|
|
368
|
+
if (buffer.replace(/\r\n/g, "\n").trim()) {
|
|
369
|
+
throw new Error("Authoring event stream ended with a truncated frame");
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// src/http/authoring.ts
|
|
374
|
+
var LumaAuthoringClient = class {
|
|
375
|
+
/** Reuse the authenticated generated client and its configured HTTP policy. */
|
|
376
|
+
constructor(apiClient) {
|
|
377
|
+
this.apiClient = apiClient;
|
|
378
|
+
}
|
|
379
|
+
/** Open or restore the organization/course session using the caller command identity. */
|
|
380
|
+
async createSession(options) {
|
|
381
|
+
const response = await this.apiClient.api.createSessionApiPublicV1AuthoringSessionsPost(options);
|
|
382
|
+
return response.data;
|
|
383
|
+
}
|
|
384
|
+
/** List one server-filtered, offset-paginated page of a course's independent conversations in server-defined latest-activity order. */
|
|
385
|
+
async listSessions(options) {
|
|
386
|
+
const response = await this.apiClient.api.listSessionsApiPublicV1AuthoringSessionsGet({
|
|
387
|
+
course_id: options.courseId,
|
|
388
|
+
keyword: options.keyword,
|
|
389
|
+
page: options.page,
|
|
390
|
+
perPage: options.perPage
|
|
391
|
+
});
|
|
392
|
+
return response.data;
|
|
393
|
+
}
|
|
394
|
+
/** Read the durable workspace snapshot used for initial rendering and resynchronization. */
|
|
395
|
+
async getSession(options) {
|
|
396
|
+
const response = await this.apiClient.api.getSessionApiPublicV1AuthoringSessionsSessionIdGet(
|
|
397
|
+
options.sessionId
|
|
398
|
+
);
|
|
399
|
+
return response.data;
|
|
400
|
+
}
|
|
401
|
+
/** Read an older, stable keyset page of turns and the records for their review cards. */
|
|
402
|
+
async getOlderTurns(options) {
|
|
403
|
+
const response = await this.apiClient.api.getOlderTurnsApiPublicV1AuthoringSessionsSessionIdTurnsGet(
|
|
404
|
+
options.sessionId,
|
|
405
|
+
{ beforeRequestId: options.beforeRequestId }
|
|
406
|
+
);
|
|
407
|
+
return response.data;
|
|
408
|
+
}
|
|
409
|
+
/** Read one ordered event page after a durable cursor; callers own pagination. */
|
|
410
|
+
async getEvents(options) {
|
|
411
|
+
const response = await this.apiClient.api.getEventsApiPublicV1AuthoringSessionsSessionIdEventsGet(
|
|
412
|
+
options.sessionId,
|
|
413
|
+
{
|
|
414
|
+
afterSequence: options.afterSequence,
|
|
415
|
+
limit: options.limit
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
return response.data;
|
|
419
|
+
}
|
|
420
|
+
/** Consume one SSE connection until closure or failure.
|
|
421
|
+
* The caller owns reconnect and cursor persistence; aborting only closes the
|
|
422
|
+
* subscription and never stops generation. Terminal access/history errors reject. */
|
|
423
|
+
async subscribeEvents(options) {
|
|
424
|
+
const controller = new AbortController();
|
|
425
|
+
const abort = () => controller.abort(options.signal?.reason);
|
|
426
|
+
if (options.signal?.aborted) abort();
|
|
427
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
428
|
+
try {
|
|
429
|
+
const response = await this.apiClient.api.subscribeEventsApiPublicV1AuthoringSessionsSessionIdEventsStreamGet(
|
|
430
|
+
options.sessionId,
|
|
431
|
+
{ afterSequence: options.afterSequence },
|
|
432
|
+
{
|
|
433
|
+
format: "stream",
|
|
434
|
+
headers: { Accept: "text/event-stream" },
|
|
435
|
+
signal: controller.signal
|
|
436
|
+
}
|
|
437
|
+
);
|
|
438
|
+
await consumeAuthoringEventStream(response.data, options);
|
|
439
|
+
} finally {
|
|
440
|
+
options.signal?.removeEventListener("abort", abort);
|
|
441
|
+
controller.abort();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/** Upload a source under a stable command ID; processing completes asynchronously. */
|
|
445
|
+
async uploadSource(options) {
|
|
446
|
+
const response = await this.apiClient.api.uploadSourceApiPublicV1AuthoringSessionsSessionIdSourcesPost(
|
|
447
|
+
options.sessionId,
|
|
448
|
+
{ file: options.file, commandId: options.commandId }
|
|
449
|
+
);
|
|
450
|
+
return response.data;
|
|
451
|
+
}
|
|
452
|
+
/** Download one authorized asset revision with a response-size bound.
|
|
453
|
+
* Defaults to 32 MiB. Pass the frozen manifest size when known; invalid limits
|
|
454
|
+
* and oversized responses reject without returning partial asset data. */
|
|
455
|
+
async downloadAsset(options) {
|
|
456
|
+
const maxBytes = options.maxBytes ?? 32 * 1024 * 1024;
|
|
457
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) {
|
|
458
|
+
throw new RangeError("Asset maxBytes must be a nonnegative safe integer");
|
|
459
|
+
}
|
|
460
|
+
const response = await this.apiClient.api.downloadAssetApiPublicV1AuthoringSessionsSessionIdAssetsAssetIdGet(
|
|
461
|
+
options.sessionId,
|
|
462
|
+
options.assetId,
|
|
463
|
+
{ revision: options.revision },
|
|
464
|
+
{ format: "arraybuffer", signal: options.signal, maxContentLength: maxBytes }
|
|
465
|
+
);
|
|
466
|
+
const data = response.data;
|
|
467
|
+
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
468
|
+
if (bytes.byteLength > maxBytes) throw new RangeError("Asset response exceeds maxBytes");
|
|
469
|
+
const contentType = response.headers["content-type"];
|
|
470
|
+
return {
|
|
471
|
+
assetId: options.assetId,
|
|
472
|
+
revision: options.revision ?? 1,
|
|
473
|
+
bytes,
|
|
474
|
+
mimeType: typeof contentType === "string" ? contentType : void 0
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
/** Submit a command with its stable identity and return the server acknowledgement.
|
|
478
|
+
* An acknowledgement records acceptance, not completion of provider work. */
|
|
479
|
+
async sendCommand(options) {
|
|
480
|
+
const response = await this.apiClient.api.commandApiPublicV1AuthoringSessionsSessionIdCommandsPost(
|
|
481
|
+
options.sessionId,
|
|
482
|
+
options.command
|
|
483
|
+
);
|
|
484
|
+
return response.data;
|
|
485
|
+
}
|
|
486
|
+
/** Deliver only the selected Core-authorized context for a pending fenced task. */
|
|
487
|
+
async fulfillContext(options) {
|
|
488
|
+
const response = await this.apiClient.api.fulfillContextApiPublicV1AuthoringSessionsSessionIdContextRequestsContextRequestIdFulfillmentPost(
|
|
489
|
+
options.sessionId,
|
|
490
|
+
options.contextRequestId,
|
|
491
|
+
options.response
|
|
492
|
+
);
|
|
493
|
+
return response.data;
|
|
494
|
+
}
|
|
495
|
+
/** Settle one pending context request when Core cannot return authorized detail. */
|
|
496
|
+
async failContext(options) {
|
|
497
|
+
const response = await this.apiClient.api.failContextApiPublicV1AuthoringSessionsSessionIdContextRequestsContextRequestIdFailurePost(
|
|
498
|
+
options.sessionId,
|
|
499
|
+
options.contextRequestId,
|
|
500
|
+
options.failure
|
|
501
|
+
);
|
|
502
|
+
return response.data;
|
|
503
|
+
}
|
|
504
|
+
/** Freeze selected reviewed changes for Core; this operation does not apply them. */
|
|
505
|
+
async prepareExport(options) {
|
|
506
|
+
const response = await this.apiClient.api.prepareExportApiPublicV1AuthoringSessionsSessionIdExportsPost(
|
|
507
|
+
options.sessionId,
|
|
508
|
+
options.request
|
|
509
|
+
);
|
|
510
|
+
return response.data;
|
|
511
|
+
}
|
|
512
|
+
/** Retrieve the previously frozen bundle without regenerating its content. */
|
|
513
|
+
async getExport(options) {
|
|
514
|
+
const response = await this.apiClient.api.getExportApiPublicV1AuthoringSessionsSessionIdExportsExportIdGet(
|
|
515
|
+
options.sessionId,
|
|
516
|
+
options.exportId
|
|
517
|
+
);
|
|
518
|
+
return response.data;
|
|
519
|
+
}
|
|
520
|
+
/** Deliver Core application feedback so Luma can reconcile the reviewed changes. */
|
|
521
|
+
async recordReceipt(options) {
|
|
522
|
+
const response = await this.apiClient.api.receiptApiPublicV1AuthoringSessionsSessionIdReceiptsPost(
|
|
523
|
+
options.sessionId,
|
|
524
|
+
options.receipt
|
|
525
|
+
);
|
|
526
|
+
return response.data;
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
// src/http/client.ts
|
|
531
|
+
import { Agent as HttpsAgent } from "https";
|
|
532
|
+
|
|
533
|
+
// src/http/configuration.ts
|
|
534
|
+
var LumaConfigurationClient = class {
|
|
535
|
+
constructor(apiClient) {
|
|
536
|
+
this.apiClient = apiClient;
|
|
537
|
+
}
|
|
538
|
+
async get() {
|
|
539
|
+
const response = await this.apiClient.api.getConfigurationStatusApiPublicV1AiConfigurationGet();
|
|
540
|
+
return response.data;
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
// src/http/mentor.ts
|
|
545
|
+
var LumaMentorClient = class {
|
|
546
|
+
constructor(apiClient) {
|
|
547
|
+
this.apiClient = apiClient;
|
|
548
|
+
}
|
|
549
|
+
streamChat(opts, requestOptions = {}) {
|
|
550
|
+
return this.apiClient.api.mentorChatApiPublicV1AiMentorChatPost(opts, {
|
|
551
|
+
format: "stream",
|
|
552
|
+
signal: requestOptions.signal
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
chat(opts, requestOptions = {}) {
|
|
556
|
+
return this.streamChat(opts, requestOptions);
|
|
557
|
+
}
|
|
558
|
+
async generateChat(opts) {
|
|
559
|
+
const response = await this.apiClient.api.generateMentorChatApiPublicV1AiMentorChatGeneratePost(opts);
|
|
560
|
+
return response.data;
|
|
561
|
+
}
|
|
562
|
+
async judge(opts) {
|
|
563
|
+
const response = await this.apiClient.api.mentorJudgeApiPublicV1AiMentorJudgePost(opts);
|
|
564
|
+
return response.data;
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
// src/http/client.ts
|
|
569
|
+
var LumaClient = class {
|
|
570
|
+
/** Configure authenticated transports; TLS verification stays enabled unless explicitly disabled. */
|
|
571
|
+
constructor(opts) {
|
|
572
|
+
const httpsAgent = opts.httpsAgent ?? (opts.allowInsecureTls ? new HttpsAgent({ rejectUnauthorized: false }) : void 0);
|
|
573
|
+
this.apiClient = new API({
|
|
574
|
+
baseURL: opts.baseURL,
|
|
575
|
+
secure: true,
|
|
576
|
+
httpsAgent,
|
|
577
|
+
headers: {
|
|
578
|
+
"X-API-Key": opts.apiKey
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
const adminApiClient = new API({
|
|
582
|
+
baseURL: opts.baseURL,
|
|
583
|
+
secure: true,
|
|
584
|
+
httpsAgent,
|
|
585
|
+
headers: {
|
|
586
|
+
"X-Admin-API-Key": opts.apiKey
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
this.ai = new LumaAiClient(this.apiClient);
|
|
590
|
+
this.admin = new LumaAdminClient(adminApiClient, opts.apiKey);
|
|
591
|
+
this.authoring = new LumaAuthoringClient(this.apiClient);
|
|
592
|
+
this.configuration = new LumaConfigurationClient(this.apiClient);
|
|
593
|
+
this.mentor = new LumaMentorClient(this.apiClient);
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
var createLumaClient = (opts) => {
|
|
597
|
+
return new LumaClient(opts);
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
// src/socket/client.ts
|
|
601
|
+
import { io } from "socket.io-client";
|
|
602
|
+
var createLumaSocket = (opts) => {
|
|
603
|
+
const socket = io(opts.baseURL, {
|
|
604
|
+
transports: ["websocket", "polling"],
|
|
605
|
+
autoConnect: false,
|
|
606
|
+
secure: true,
|
|
607
|
+
rejectUnauthorized: !opts.allowInsecureTls,
|
|
608
|
+
auth: {
|
|
609
|
+
apiKey: opts.apiKey,
|
|
610
|
+
sessionId: opts.socketData?.sessionId,
|
|
611
|
+
currentSocketUser: {
|
|
612
|
+
userId: opts.socketData?.userId,
|
|
613
|
+
lessonId: opts.socketData?.lessonId
|
|
614
|
+
}
|
|
615
|
+
},
|
|
616
|
+
path: "/api/ws/socket.io"
|
|
617
|
+
});
|
|
618
|
+
socket.startAudio = (payload) => {
|
|
619
|
+
socket.emit(LUMA_SOCKET_EMIT_EVENTS.START_AUDIO, payload);
|
|
620
|
+
return socket;
|
|
621
|
+
};
|
|
622
|
+
socket.sendAudioChunk = (payload, chunk) => {
|
|
623
|
+
socket.emit(LUMA_SOCKET_EMIT_EVENTS.AUDIO_CHUNK, payload, chunk);
|
|
624
|
+
return socket;
|
|
625
|
+
};
|
|
626
|
+
socket.reconnectAudio = (payload) => {
|
|
627
|
+
socket.emit(LUMA_SOCKET_EMIT_EVENTS.AUDIO_RECONNECT, payload);
|
|
628
|
+
return socket;
|
|
629
|
+
};
|
|
630
|
+
socket.stopAudio = (payload) => {
|
|
631
|
+
socket.emit(
|
|
632
|
+
LUMA_SOCKET_EMIT_EVENTS.AUDIO_STOP,
|
|
633
|
+
payload ?? { type: LUMA_SOCKET_MESSAGE_TYPES.AUDIO_STOP }
|
|
634
|
+
);
|
|
635
|
+
return socket;
|
|
636
|
+
};
|
|
637
|
+
socket.sendClientSpeechStart = (payload) => {
|
|
638
|
+
socket.emit(LUMA_SOCKET_EMIT_EVENTS.CLIENT_SPEECH_START, payload);
|
|
639
|
+
return socket;
|
|
640
|
+
};
|
|
641
|
+
socket.sendClientSpeechEnd = (payload) => {
|
|
642
|
+
socket.emit(LUMA_SOCKET_EMIT_EVENTS.CLIENT_SPEECH_END, payload);
|
|
643
|
+
return socket;
|
|
644
|
+
};
|
|
645
|
+
socket.sendMentorTextDelta = (payload) => {
|
|
646
|
+
socket.emit(LUMA_SOCKET_EMIT_EVENTS.MENTOR_TEXT_DELTA, payload);
|
|
647
|
+
return socket;
|
|
648
|
+
};
|
|
649
|
+
socket.sendMentorTextEnd = (payload) => {
|
|
650
|
+
socket.emit(LUMA_SOCKET_EMIT_EVENTS.MENTOR_TEXT_END, payload);
|
|
651
|
+
return socket;
|
|
652
|
+
};
|
|
653
|
+
socket.sendMentorTextError = (payload) => {
|
|
654
|
+
socket.emit(LUMA_SOCKET_EMIT_EVENTS.MENTOR_TEXT_ERROR, payload);
|
|
655
|
+
return socket;
|
|
656
|
+
};
|
|
657
|
+
socket.sendPing = (payload) => {
|
|
658
|
+
socket.emit(LUMA_SOCKET_EMIT_EVENTS.PING, payload);
|
|
659
|
+
return socket;
|
|
660
|
+
};
|
|
661
|
+
socket.sendTTSTrigger = (payload) => {
|
|
662
|
+
socket.emit(LUMA_SOCKET_EMIT_EVENTS.TRIGGER_TTS, payload);
|
|
663
|
+
return socket;
|
|
664
|
+
};
|
|
665
|
+
socket.onServerConnected = (handler) => {
|
|
666
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.SERVER_CONNECTED, handler);
|
|
667
|
+
return socket;
|
|
668
|
+
};
|
|
669
|
+
socket.onAudioStarted = (handler) => {
|
|
670
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_STARTED, handler);
|
|
671
|
+
return socket;
|
|
672
|
+
};
|
|
673
|
+
socket.onAudioChunked = (handler) => {
|
|
674
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_CHUNKED, handler);
|
|
675
|
+
return socket;
|
|
676
|
+
};
|
|
677
|
+
socket.onAudioChunkError = (handler) => {
|
|
678
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_CHUNK_ERROR, handler);
|
|
679
|
+
return socket;
|
|
680
|
+
};
|
|
681
|
+
socket.onAudioRecovered = (handler) => {
|
|
682
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_RECOVERED, handler);
|
|
683
|
+
return socket;
|
|
684
|
+
};
|
|
685
|
+
socket.onAudioReconnectError = (handler) => {
|
|
686
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_RECONNECT_ERROR, handler);
|
|
687
|
+
return socket;
|
|
688
|
+
};
|
|
689
|
+
socket.onAudioStopped = (handler) => {
|
|
690
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_STOPPED, handler);
|
|
691
|
+
return socket;
|
|
692
|
+
};
|
|
693
|
+
socket.onLearnerTranscription = (handler) => {
|
|
694
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.LEARNER_TRANSCRIPTION, handler);
|
|
695
|
+
return socket;
|
|
696
|
+
};
|
|
697
|
+
socket.onMentorTranscription = (handler) => {
|
|
698
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.LEARNER_TRANSCRIPTION, (payload) => {
|
|
699
|
+
if (payload.data.status === LEARNER_TRANSCRIPT_STATUSES.FINAL) handler(payload);
|
|
700
|
+
});
|
|
701
|
+
return socket;
|
|
702
|
+
};
|
|
703
|
+
socket.onAudioOutputChunk = (handler) => {
|
|
704
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_OUTPUT_CHUNK, handler);
|
|
705
|
+
return socket;
|
|
706
|
+
};
|
|
707
|
+
socket.onAudioOutputAlignment = (handler) => {
|
|
708
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_OUTPUT_ALIGNMENT, handler);
|
|
709
|
+
return socket;
|
|
710
|
+
};
|
|
711
|
+
socket.onAudioOutputInterrupted = (handler) => {
|
|
712
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_OUTPUT_INTERRUPTED, handler);
|
|
713
|
+
return socket;
|
|
714
|
+
};
|
|
715
|
+
socket.onAudioOutputError = (handler) => {
|
|
716
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_OUTPUT_ERROR, handler);
|
|
717
|
+
return socket;
|
|
718
|
+
};
|
|
719
|
+
socket.onAudioOutputComplete = (handler) => {
|
|
720
|
+
socket.on(LUMA_SOCKET_LISTEN_EVENTS.AUDIO_OUTPUT_COMPLETE, handler);
|
|
721
|
+
return socket;
|
|
722
|
+
};
|
|
723
|
+
return socket;
|
|
724
|
+
};
|
|
725
|
+
export {
|
|
726
|
+
AI_MENTOR_CONFIGURATION_TYPES,
|
|
727
|
+
AUDIO_PROVIDER_STATES,
|
|
728
|
+
AUDIO_RECOVERY_STATES,
|
|
729
|
+
AiCapability,
|
|
730
|
+
AiCapabilityMode,
|
|
731
|
+
AiCapabilityProvider,
|
|
732
|
+
AiModelDomain,
|
|
733
|
+
AiModelProfileKind,
|
|
734
|
+
AuthoringSubscriptionError,
|
|
735
|
+
EXTERNAL_AUDIO_CLIENT_RECONNECT_GRACE_MS,
|
|
736
|
+
EXTERNAL_AUDIO_MAX_BUFFERED_CHUNKS,
|
|
737
|
+
EXTERNAL_AUDIO_MAX_RECOVERY_ATTEMPTS,
|
|
738
|
+
EXTERNAL_AUDIO_OPERATION,
|
|
739
|
+
EXTERNAL_AUDIO_RECOVERY_STATE,
|
|
740
|
+
EXTERNAL_AUDIO_RECOVERY_TIMEOUT_MS,
|
|
741
|
+
EXTERNAL_AUDIO_TERMINAL_RECOVERY_ERROR_CODES,
|
|
742
|
+
LEARNER_TRANSCRIPT_STATUSES,
|
|
743
|
+
LUMA_AI_CAPABILITIES,
|
|
744
|
+
LUMA_AI_CAPABILITY_MODES,
|
|
745
|
+
LUMA_AI_CAPABILITY_PROVIDERS,
|
|
746
|
+
LUMA_AI_MODEL_DOMAINS,
|
|
747
|
+
LUMA_AI_MODEL_PROFILE_KINDS,
|
|
748
|
+
LUMA_AUDIO_ACTIONS,
|
|
749
|
+
LUMA_AUDIO_FORMATS,
|
|
750
|
+
LUMA_CAPTURE_PROFILES,
|
|
751
|
+
LUMA_MENTOR_STREAM_EVENT_TYPES,
|
|
752
|
+
LUMA_SOCKET_EMIT_EVENTS,
|
|
753
|
+
LUMA_SOCKET_LISTEN_EVENTS,
|
|
754
|
+
LUMA_SOCKET_MESSAGE_TYPES,
|
|
755
|
+
LUMA_VOICE_TIMING_PRECISION,
|
|
756
|
+
LumaAdminApiKeysClient,
|
|
757
|
+
LumaAdminClient,
|
|
758
|
+
LumaAdminModelProfilesClient,
|
|
759
|
+
LumaAiClient,
|
|
760
|
+
LumaAuthoringClient,
|
|
761
|
+
LumaClient,
|
|
762
|
+
LumaConfigurationClient,
|
|
763
|
+
LumaMentorClient,
|
|
764
|
+
ReasoningEffort,
|
|
765
|
+
TRANSCRIPTION_MODES,
|
|
766
|
+
TTSProvider,
|
|
767
|
+
TaskKind,
|
|
768
|
+
TextToSpeechProvider,
|
|
769
|
+
TurnPartKind,
|
|
770
|
+
TurnPartStatus,
|
|
771
|
+
TurnStatus,
|
|
772
|
+
consumeAuthoringEventStream,
|
|
773
|
+
createLumaClient,
|
|
774
|
+
createLumaSocket
|
|
775
|
+
};
|