@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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Selleo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,276 @@
1
- # Temporary Holding Version
1
+ # Luma SDK
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript SDK for the Luma platform used by Mentingo.
4
+
5
+ It provides two separate clients:
6
+
7
+ - HTTP client for durable course authoring, Mentor chat, assets, administration and configuration
8
+ - Socket client for realtime audio/voice mentor flows
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pnpm add @mentingo/luma-sdk
14
+ # or
15
+ npm install @mentingo/luma-sdk
16
+ # or
17
+ yarn add @mentingo/luma-sdk
18
+ ```
19
+
20
+ ## Quick Start (HTTP)
21
+
22
+ ```ts
23
+ import { createLumaClient } from "@mentingo/luma-sdk";
24
+
25
+ const client = createLumaClient({
26
+ baseURL: "https://your-luma-api.example.com",
27
+ apiKey: process.env.LUMA_API_KEY,
28
+ });
29
+
30
+ const session = await client.authoring.createSession({
31
+ commandId: crypto.randomUUID(),
32
+ courseId: "00000000-0000-4000-8000-000000000001",
33
+ actorId: "author-123",
34
+ language: "en",
35
+ });
36
+
37
+ const snapshot = await client.authoring.getSession({ sessionId: session.sessionId });
38
+ console.log(snapshot.tasks);
39
+ ```
40
+
41
+ Each client uses one `apiKey`. Supply an administration key for admin operations
42
+ or an organization feature key for AI and course operations. The API validates
43
+ the key's type and permissions; using a different SDK method does not grant
44
+ additional access. To perform both kinds of operations, create separate clients
45
+ with the appropriate keys.
46
+
47
+ The SDK sends that key as `X-Admin-API-Key` for `luma.admin` and as `X-API-Key`
48
+ for feature operations, matching the existing API contracts.
49
+
50
+ ```ts
51
+ const luma = createLumaClient({
52
+ baseURL: "https://your-luma-api.example.com",
53
+ apiKey: process.env.LUMA_ADMIN_API_KEY,
54
+ });
55
+
56
+ const keys = await luma.admin.apiKeys.list({ organizationId: "org-123" });
57
+ const created = await luma.admin.apiKeys.create({
58
+ organizationId: "org-123",
59
+ name: "Course generation",
60
+ });
61
+
62
+ await luma.admin.apiKeys.update({
63
+ organizationId: "org-123",
64
+ apiKeyId: created.id,
65
+ name: "Updated course generation",
66
+ });
67
+
68
+ const configuration = await luma.admin.apiKeys.getConfiguration({
69
+ organizationId: "org-123",
70
+ apiKeyId: created.id,
71
+ });
72
+ const assignments = await luma.admin.apiKeys.listAssignments({
73
+ organizationId: "org-123",
74
+ apiKeyId: created.id,
75
+ });
76
+ ```
77
+
78
+ ## Quick Start (Socket)
79
+
80
+ ```ts
81
+ import {
82
+ createLumaSocket,
83
+ LUMA_AUDIO_ACTIONS,
84
+ LUMA_AUDIO_FORMATS,
85
+ LUMA_SOCKET_MESSAGE_TYPES,
86
+ } from "@mentingo/luma-sdk";
87
+
88
+ const socket = createLumaSocket({
89
+ baseURL: "https://your-luma-api.example.com",
90
+ apiKey: process.env.LUMA_API_KEY,
91
+ socketData: {
92
+ sessionId: "session-123",
93
+ userId: "user-123",
94
+ lessonId: "lesson-123",
95
+ },
96
+ });
97
+
98
+ socket
99
+ .onServerConnected((payload) => console.log("connected", payload))
100
+ .onMentorTranscription((payload) => console.log("transcription", payload))
101
+ .onAudioOutputChunk((payload) => console.log("audio chunk", payload));
102
+
103
+ socket.connect();
104
+
105
+ socket.startAudio({
106
+ type: LUMA_SOCKET_MESSAGE_TYPES.AUDIO_START,
107
+ audioAction: LUMA_AUDIO_ACTIONS.VOICE_MENTOR,
108
+ meta: { sr: 16000, channels: 1, format: LUMA_AUDIO_FORMATS.PCM_S16LE },
109
+ });
110
+
111
+ socket.sendAudioChunk(
112
+ {
113
+ type: LUMA_SOCKET_MESSAGE_TYPES.AUDIO_CHUNK,
114
+ meta: { seq: 1, sr: 16000, samples: 320, tsMs: Date.now() },
115
+ },
116
+ new Uint8Array([0, 1, 2]),
117
+ );
118
+
119
+ socket.stopAudio();
120
+ ```
121
+
122
+ Recovery responses expose stable public constants for state handling:
123
+
124
+ ```ts
125
+ import {
126
+ AUDIO_PROVIDER_STATES,
127
+ AUDIO_RECOVERY_STATES,
128
+ type AudioRecoveryPayload,
129
+ } from "@mentingo/luma-sdk";
130
+
131
+ socket.onAudioRecovered((payload: AudioRecoveryPayload) => {
132
+ if (payload.state === AUDIO_RECOVERY_STATES.MENTOR_ACTIVE) {
133
+ // Keep the playback UI active after reconnecting.
134
+ }
135
+
136
+ if (payload.providerState === AUDIO_PROVIDER_STATES.RESTARTED) {
137
+ // The transcription provider was recreated; replay unacknowledged chunks.
138
+ }
139
+ });
140
+ ```
141
+
142
+ ## HTTP Client API
143
+
144
+ ### `createLumaClient(opts)`
145
+
146
+ Options:
147
+
148
+ - `baseURL?: string` - Luma API base URL.
149
+ - `apiKey?: string` - single client credential; sent as `X-Admin-API-Key` for `client.admin` and `X-API-Key` for feature operations. The API enforces its type and permissions.
150
+ - `httpsAgent?: Agent` - custom Node.js HTTPS agent.
151
+ - `allowInsecureTls?: boolean` - if `true`, uses `rejectUnauthorized: false` (dev only).
152
+
153
+ Namespaces:
154
+
155
+ - `client.mentor.streamChat(opts)` - stream mentor chat through the public custom-runtime endpoint. Pass `voiceSessionId` for voice mentor sessions so Luma can forward mentor text directly to the voice session.
156
+ - `client.mentor.chat(opts)` - alias for `client.mentor.streamChat(opts)`.
157
+ - `client.mentor.generateChat(opts)` - generate a non-stream mentor chat response.
158
+ - `client.mentor.judge(opts)`
159
+ - `client.ai.createEmbeddings(opts)`
160
+ - `client.ai.generateJudgeConfiguration(opts)`
161
+ - `client.ai.validateJudgeConfiguration(opts)`
162
+ - `client.ai.generateTranslations(opts)`
163
+ - `client.ai.transcribeDictation(opts)`
164
+ - `client.configuration.get()`
165
+ - `client.admin.apiKeys.list(opts)`
166
+ - `client.admin.apiKeys.create(opts)`
167
+ - `client.admin.apiKeys.get(opts)`
168
+ - `client.admin.apiKeys.update(opts)`
169
+ - `client.admin.apiKeys.revoke(opts)`
170
+ - `client.admin.apiKeys.getConfiguration(opts)`
171
+ - `client.admin.apiKeys.listAssignments(opts)`
172
+ - `client.admin.apiKeys.updateAssignment(opts)`
173
+ - `client.admin.modelProfiles.list(opts)`
174
+
175
+ The HTTP client intentionally exposes public API operations through namespaces
176
+ instead of flat top-level methods.
177
+
178
+ ## Runtime Configuration
179
+
180
+ Use `client.configuration.get()` to inspect which public AI capabilities are enabled
181
+ for the API key. The SDK exports `AiCapability`, `AiCapabilityMode`,
182
+ `AiCapabilityProvider`, `AiRuntimeConfiguration`, and convenience constants such as
183
+ `LUMA_AI_CAPABILITIES` and `LUMA_AI_CAPABILITY_MODES`.
184
+
185
+ Custom model names should use the backend `provider:model` format, for example
186
+ `openai:gpt-4.1-mini` or `ollama:llama3.1`.
187
+
188
+ Voice TTS capabilities expose an optional `vendor` (`TTSProvider`) for core-mode
189
+ routing. API key settings use extensible non-secret metadata, for example
190
+ `metadata: { textToSpeechProvider: TextToSpeechProvider.Elevenlabs }` in
191
+ `admin.apiKeys.update`. Omitted metadata entries stay unchanged; setting an entry
192
+ to `null` removes it. Credentials remain in the write-only `textToSpeechApiKey`
193
+ field; `hasTextToSpeechApiKey` reports whether one is saved.
194
+
195
+ For voice mentor flows, use `client.mentor.streamChat({ ..., voiceSessionId })` so streamed mentor text can be forwarded to the active socket session without a separate polling or relay step. Use `client.mentor.generateChat(opts)` only for normal one-shot text responses.
196
+
197
+ ## Durable Course Authoring
198
+
199
+ Use `client.authoring` to create/list sessions, read snapshots and events, subscribe to SSE,
200
+ submit commands, upload source documents, answer authorized context requests, prepare frozen
201
+ exports, and record application receipts. Course changes remain reviewable proposals; the SDK
202
+ never applies them to the consuming application's database.
203
+
204
+ Snapshot tasks expose optional `failure` metadata with a stable code and recovery action.
205
+ Clients should use `retry_failed_parts`, `answer_question`, `retry_provider`, or `service_fix`
206
+ to present the appropriate next step rather than retrying every failure automatically.
207
+
208
+ Download generated visuals through `client.authoring.downloadAsset({ sessionId, assetId, revision })`.
209
+ The download is authenticated and revision-bound; import the bytes into the consuming application's
210
+ storage and render its native image node. Do not persist temporary download URLs.
211
+
212
+ ## Socket Client API
213
+
214
+ ### `createLumaSocket(opts)`
215
+
216
+ Options:
217
+
218
+ - `baseURL?: string`
219
+ - `apiKey?: string`
220
+ - `allowInsecureTls?: boolean`
221
+ - `socketData?: { sessionId?: string; userId?: string; lessonId?: string }`
222
+
223
+ Emit helpers:
224
+
225
+ - `startAudio(payload)` -> emits `start_audio`
226
+ - `sendAudioChunk(payload, chunk)` -> emits `audio_chunk`
227
+ - `sendClientSpeechStart(payload)` -> emits `client_speech_start`
228
+ - `sendClientSpeechEnd(payload)` -> emits `client_speech_end`
229
+ - `stopAudio(payload?)` -> emits `audio_stop`
230
+ - `sendMentorTextDelta(payload)` -> emits `mentor_text_delta`
231
+ - `sendMentorTextEnd(payload)` -> emits `mentor_text_end`
232
+ - `sendMentorTextError(payload)` -> emits `mentor_text_error`
233
+ - `sendPing(payload?)` -> emits `ping`
234
+
235
+ Listener helpers:
236
+
237
+ - `onServerConnected(handler)` -> listens `server:connected`
238
+ - `onAudioStarted(handler)` -> listens `audio:started`
239
+ - `onAudioChunked(handler)` -> listens `audio:chunked`
240
+ - `onAudioRecovered(handler)` -> listens `audio:recovered`
241
+ - `onAudioStopped(handler)` -> listens `audio:stopped`
242
+ - `onMentorTranscription(handler)` -> listens `mentor:transcription`
243
+ - `onAudioOutputChunk(handler)` -> listens `audio:output:chunk`
244
+ - `onAudioOutputInterrupted(handler)` -> listens `audio:output:interrupted`
245
+ - `onAudioOutputError(handler)` -> listens `audio:output:error`
246
+ - `onAudioOutputComplete(handler)` -> listens `audio:output:complete`
247
+
248
+ ## Public Exports
249
+
250
+ - HTTP: `createLumaClient`, `LumaClient`, `LumaClientOptions`, namespaced HTTP clients
251
+ - Socket: `createLumaSocket`, `LumaSocket`, socket payload/event types from `src/socket/types.ts`
252
+ - Shared API/domain types from `src/types.ts`
253
+
254
+ ## Development
255
+
256
+ ```bash
257
+ pnpm install
258
+ pnpm --filter @mentingo/luma-sdk typecheck
259
+ pnpm --filter @mentingo/luma-sdk test
260
+ pnpm --filter @mentingo/luma-sdk build
261
+ pnpm --filter @mentingo/luma-sdk lint
262
+ ```
263
+
264
+ ### Regenerate API client from OpenAPI schema
265
+
266
+ ```bash
267
+ pnpm generate:client
268
+ ```
269
+
270
+ Uses `src/api/api-schema-public.json` to regenerate `src/api/generated-api.ts`.
271
+
272
+ ## Notes
273
+
274
+ - Built with `tsup` and ships ESM + CJS.
275
+ - HTTP auth uses the `X-API-Key` header.
276
+ - Keep API keys out of source control.