@molecule/api-video-rooms-livekit 1.0.0 → 1.0.2

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.
Files changed (2) hide show
  1. package/README.md +377 -0
  2. package/package.json +8 -7
package/README.md ADDED
@@ -0,0 +1,377 @@
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-08-06T06:01:27.511Z
7
+ -->
8
+
9
+ # @molecule/api-video-rooms-livekit
10
+
11
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
12
+ > It is written to be read by coding agents as much as by people, and is generated from this
13
+ > package's source — edit `src/index.ts` JSDoc, not this file.
14
+
15
+ LiveKit video rooms provider for molecule.dev.
16
+
17
+ Implements the `@molecule/api-video-rooms` interface against the
18
+ LiveKit Server API (Twirp transport) and the `livekit-server-sdk`
19
+ `AccessToken` HS256 JWT signer. Self-hostable + LiveKit Cloud — the
20
+ recommended provider for users who need to keep media on their own
21
+ infrastructure.
22
+
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import { setProvider } from '@molecule/api-video-rooms'
27
+ import { createProvider } from '@molecule/api-video-rooms-livekit'
28
+
29
+ // Bond at startup (reads LIVEKIT_URL / LIVEKIT_API_KEY /
30
+ // LIVEKIT_API_SECRET by default)
31
+ setProvider(createProvider())
32
+
33
+ // Explicit config. For real cloud recording, also pass `recordingEgress` — a
34
+ // LiveKit `RoomEgress` (built with RoomCompositeEgressRequest + EncodedFileOutput
35
+ // + your S3/GCP/Azure upload), or a `(roomName) => RoomEgress` factory; see the
36
+ // `recordingEgress` docs in @remarks. With it, `createRoom({ recording: true })`
37
+ // starts a real room-composite egress; WITHOUT it, that call throws rather than
38
+ // silently not recording.
39
+ setProvider(
40
+ createProvider({
41
+ host: 'https://livekit.example.com',
42
+ apiKey: 'APIxxx',
43
+ apiSecret: 'secretxxx',
44
+ }),
45
+ )
46
+ ```
47
+
48
+ ## Type
49
+
50
+ `provider`
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ npm install @molecule/api-video-rooms-livekit @molecule/api-secrets @molecule/api-video-rooms livekit-server-sdk
56
+ ```
57
+
58
+ ## API
59
+
60
+ ### Interfaces
61
+
62
+ #### `LiveKitEgressClient`
63
+
64
+ Minimal `EgressClient` surface used by the provider for listing
65
+ recordings.
66
+
67
+ ```typescript
68
+ interface LiveKitEgressClient {
69
+ /** Lists egress (recording) jobs, optionally filtered by room. */
70
+ listEgress(options?: { roomName?: string }): Promise<LiveKitEgressInfo[]>
71
+ }
72
+ ```
73
+
74
+ #### `LiveKitEgressInfo`
75
+
76
+ Minimal LiveKit egress (recording job) shape. Status is the numeric
77
+ `EgressStatus` enum value from `@livekit/protocol`.
78
+
79
+ ```typescript
80
+ interface LiveKitEgressInfo {
81
+ /** Egress identifier. */
82
+ egressId: string
83
+
84
+ /** Name of the room the egress belongs to. */
85
+ roomName: string
86
+
87
+ /** Numeric `EgressStatus` enum (0=starting … 6=limit_reached). */
88
+ status?: number
89
+
90
+ /** Unix-seconds (or bigint) start time. */
91
+ startedAt?: number | bigint
92
+
93
+ /** Unix-seconds (or bigint) end time. */
94
+ endedAt?: number | bigint
95
+
96
+ /** Recorded file results, when present. */
97
+ fileResults?: Array<{
98
+ location?: string
99
+ duration?: number | bigint
100
+ }>
101
+ }
102
+ ```
103
+
104
+ #### `LiveKitRoom`
105
+
106
+ Minimal LiveKit `Room` shape consumed by the provider. The real
107
+ protobuf class exposes additional fields we don't depend on.
108
+
109
+ ```typescript
110
+ interface LiveKitRoom {
111
+ /** Room name (stable identifier). */
112
+ name: string
113
+
114
+ /** Room sid (unique per-instance id). */
115
+ sid?: string
116
+
117
+ /** Maximum simultaneous participants. */
118
+ maxParticipants?: number
119
+
120
+ /** Empty-room TTL in seconds. */
121
+ emptyTimeout?: number
122
+
123
+ /** Departure-room TTL in seconds. */
124
+ departureTimeout?: number
125
+
126
+ /** Provider-side opaque metadata blob. */
127
+ metadata?: string
128
+
129
+ /** Unix-seconds creation timestamp (the protobuf field is `bigint`). */
130
+ creationTime?: number | bigint
131
+
132
+ /** Whether a recording is currently active on the room. */
133
+ activeRecording?: boolean
134
+ }
135
+ ```
136
+
137
+ #### `LiveKitRoomServiceClient`
138
+
139
+ Minimal `RoomServiceClient` surface used by the provider. Tests inject
140
+ a stub here to avoid HTTP traffic. The real
141
+ `livekit-server-sdk.RoomServiceClient` satisfies this shape.
142
+
143
+ ```typescript
144
+ interface LiveKitRoomServiceClient {
145
+ /** Creates a new LiveKit room. */
146
+ createRoom(options: {
147
+ name: string
148
+ emptyTimeout?: number
149
+ departureTimeout?: number
150
+ maxParticipants?: number
151
+ metadata?: string
152
+ /**
153
+ * Auto-egress specification. When set, LiveKit automatically starts a
154
+ * room-composite (or participant/track) egress once the room becomes
155
+ * active — this is how the bond wires `CreateRoomOptions.recording`.
156
+ */
157
+ egress?: RoomEgress
158
+ }): Promise<LiveKitRoom>
159
+
160
+ /** Lists active rooms, optionally filtered by name. */
161
+ listRooms(names?: string[]): Promise<LiveKitRoom[]>
162
+
163
+ /** Deletes a room by name. */
164
+ deleteRoom(room: string): Promise<void>
165
+ }
166
+ ```
167
+
168
+ #### `LiveKitVideoRoomsConfig`
169
+
170
+ Configuration for the LiveKit video rooms provider.
171
+
172
+ ```typescript
173
+ interface LiveKitVideoRoomsConfig {
174
+ /**
175
+ * LiveKit host (including protocol), e.g.
176
+ * `https://my-project.livekit.cloud` or `https://livekit.example.com`.
177
+ * Defaults to `process.env.LIVEKIT_URL` (which may use `wss://` — the
178
+ * provider rewrites it to `https://` for HTTP/Twirp calls).
179
+ */
180
+ host?: string
181
+
182
+ /**
183
+ * LiveKit API key. Defaults to `process.env.LIVEKIT_API_KEY`.
184
+ */
185
+ apiKey?: string
186
+
187
+ /**
188
+ * LiveKit API secret. Defaults to `process.env.LIVEKIT_API_SECRET`.
189
+ * Used to sign JWT meeting tokens via HS256.
190
+ */
191
+ apiSecret?: string
192
+
193
+ /**
194
+ * Optional default token TTL in seconds. Used when
195
+ * `createMeetingToken()` is called without an `expiresAt`. Defaults to
196
+ * `21600` (6 hours), matching the `livekit-server-sdk` default.
197
+ */
198
+ defaultTokenTtl?: number
199
+
200
+ /**
201
+ * Auto-egress specification used to satisfy `createRoom({ recording:
202
+ * true })`. LiveKit records via Egress, which **requires** a storage
203
+ * destination (S3 / GCP / Azure / AliOSS via `EncodedFileOutput`, or a
204
+ * stream/segment output) — a destination the core `recording: boolean`
205
+ * flag does not carry. Supply the LiveKit `RoomEgress` (with your
206
+ * storage output) here, either as a fixed object or a factory that
207
+ * receives the room name and returns a per-room `RoomEgress`. When it is
208
+ * set, `createRoom({ recording: true })` attaches it to the room so
209
+ * LiveKit auto-starts a room-composite egress once the room is active.
210
+ *
211
+ * When this is **not** configured, `createRoom({ recording: true })`
212
+ * throws rather than silently returning a room with no recording — LiveKit
213
+ * cannot record without a storage output.
214
+ */
215
+ recordingEgress?: RoomEgress | ((roomName: string) => RoomEgress)
216
+
217
+ /**
218
+ * Optional pre-built `RoomServiceClient` (or compatible stub). Tests
219
+ * inject a stub here. When omitted, the provider lazily constructs a
220
+ * real `RoomServiceClient` from the SDK on first use.
221
+ */
222
+ roomServiceClient?: LiveKitRoomServiceClient
223
+
224
+ /**
225
+ * Optional pre-built `EgressClient` (or compatible stub). Tests inject
226
+ * a stub here. When omitted, the provider lazily constructs a real
227
+ * `EgressClient` from the SDK on first use.
228
+ */
229
+ egressClient?: LiveKitEgressClient
230
+
231
+ /**
232
+ * Optional `AccessToken` constructor override. Tests inject a fake
233
+ * builder to avoid the real `jose` HS256 signer. Defaults to the
234
+ * `AccessToken` class exported by `livekit-server-sdk`.
235
+ */
236
+ accessTokenCtor?: AccessTokenCtor
237
+ }
238
+ ```
239
+
240
+ ### Types
241
+
242
+ #### `AccessTokenCtor`
243
+
244
+ Constructor for `livekit-server-sdk`'s `AccessToken` class. Exposed so
245
+ tests can inject a fake builder without spinning up the real `jose`
246
+ signer.
247
+
248
+ ```typescript
249
+ type AccessTokenCtor = new (
250
+ apiKey?: string,
251
+ apiSecret?: string,
252
+ options?: ConstructorParameters<typeof AccessTokenClass>[2],
253
+ ) => AccessTokenClass
254
+ ```
255
+
256
+ ### Functions
257
+
258
+ #### `createProvider(config)`
259
+
260
+ Creates a LiveKit-backed {@link VideoRoomsProvider}.
261
+
262
+ Self-hostable: pass a `host` of e.g. `https://livekit.example.com` or
263
+ set `LIVEKIT_URL` to the same value (or a `wss://` URL — the provider
264
+ rewrites the protocol for the HTTP/Twirp endpoints).
265
+
266
+ The API secret is **never** included in any error thrown by this
267
+ provider — both the missing-secret error and SDK-error wrappers
268
+ scrub it out.
269
+
270
+ ```typescript
271
+ function createProvider(config?: LiveKitVideoRoomsConfig): VideoRoomsProvider
272
+ ```
273
+
274
+ - `config` — LiveKit provider configuration. Falls back to the `LIVEKIT_URL`, `LIVEKIT_API_KEY`, and `LIVEKIT_API_SECRET` env vars when the corresponding fields are omitted.
275
+
276
+ **Returns:** A fully initialised `VideoRoomsProvider` backed by LiveKit.
277
+
278
+ ### Constants
279
+
280
+ #### `videoRoomsLivekitSecretDefinitions`
281
+
282
+ Secret definitions required by the LiveKit video-rooms bond.
283
+
284
+ ```typescript
285
+ const videoRoomsLivekitSecretDefinitions: SecretDefinition[]
286
+ ```
287
+
288
+ ## Core Interface
289
+
290
+ Implements `@molecule/api-video-rooms` interface.
291
+
292
+ ## Injection Notes
293
+
294
+ ### Requirements
295
+
296
+ Peer dependencies:
297
+
298
+ - `@molecule/api-secrets` ^1.0.1
299
+ - `@molecule/api-video-rooms` ^1.0.1
300
+
301
+ ### Environment Variables
302
+
303
+ - `LIVEKIT_URL` _(required)_ — LiveKit server URL
304
+ - Setup: Your LiveKit Cloud project URL (or self-hosted wss:// URL).
305
+ - Get it here: [https://cloud.livekit.io/](https://cloud.livekit.io/)
306
+ - Example: `wss://your-app.livekit.cloud`
307
+ - `LIVEKIT_API_KEY` _(required)_ — LiveKit API key
308
+ - Setup: LiveKit Cloud → project → Settings → Keys.
309
+ - Get it here: [https://cloud.livekit.io/](https://cloud.livekit.io/)
310
+ - `LIVEKIT_API_SECRET` _(required)_ — LiveKit API secret
311
+ - Setup: Shown when creating the key in LiveKit Cloud.
312
+ - Get it here: [https://cloud.livekit.io/](https://cloud.livekit.io/)
313
+
314
+ ### Runtime Dependencies
315
+
316
+ - `@molecule/api-secrets`
317
+ - `@molecule/api-video-rooms`
318
+ - `livekit-server-sdk`
319
+
320
+ - **LiveKit rooms are always token-gated — there is no `public` mode.**
321
+ Every join needs a token from `createMeetingToken()`, and the returned
322
+ `Room.url` is the server's `wss://` endpoint (not a click-to-join link).
323
+ A `private` room is therefore LiveKit's native, enforced behaviour and is
324
+ reported truthfully. Requesting `createRoom({ privacy: 'public' })`
325
+ **throws** — this bond will not return a room falsely labelled `public`.
326
+ - **`recording: true` requires a configured egress output.** LiveKit
327
+ records via Egress, which needs a storage destination (S3 / GCP / Azure /
328
+ AliOSS file output, or a stream/segment output) — a destination the core
329
+ `recording` flag does not carry. Supply it via `config.recordingEgress`
330
+ (a LiveKit `RoomEgress`, or a `(roomName) => RoomEgress` factory); the
331
+ bond attaches it to the room so LiveKit auto-starts a room-composite
332
+ egress once the room is active. `createRoom({ recording: true })`
333
+ **throws** when `recordingEgress` is not configured — it never returns a
334
+ room that silently isn't recording.
335
+ - `listRecordings()` reflects the real LiveKit Egress state (it calls
336
+ `EgressClient.listEgress`): an empty result means no egress ran, not a
337
+ swallowed failure.
338
+ - `expiresAt` on `createRoom` maps to LiveKit's `emptyTimeout` (how long
339
+ an empty room survives), not an absolute expiry.
340
+ - All meeting tokens grant `canPublish` + `canSubscribe`; `isOwner` adds
341
+ `roomAdmin` — there is no subscribe-only token option in this revision.
342
+ - `createProvider()` throws at bond time when LIVEKIT_URL /
343
+ LIVEKIT_API_KEY / LIVEKIT_API_SECRET are unset.
344
+
345
+ ## E2E Tests
346
+
347
+ Integration checklist — drive the real UI (live preview, no mocks), adapt
348
+ each item to this app's actual screens/flows, and check every box off one by
349
+ one. A box you can't check is an integration bug to fix — not a skip.
350
+ CAVEAT: the live A/V call and the in-room video UI run inside the provider's
351
+ client and CANNOT be driven in the sandbox — verify the room LIFECYCLE and the
352
+ per-participant join TOKENS you mint server-side, never the media itself:
353
+
354
+ - [ ] Creating a room returns a usable handle: `createRoom(...)` yields a
355
+ `RoomCreated` with a stable `name` and a joinable `url`, and the app persists
356
+ that `name` on its own record — not a throwaway URL it can never resolve again.
357
+ - [ ] Each participant gets its OWN token: the app calls
358
+ `createMeetingToken(room.name, { userName, expiresAt, isOwner })` per user, so
359
+ two joiners receive two DISTINCT, short-lived credentials — never one static
360
+ shared secret reused for everyone.
361
+ - [ ] The token honors role + scope + expiry: an owner/moderator token
362
+ (`isOwner: true`) differs from a plain-participant token, each is scoped to the
363
+ single `room.name` it was minted for (it admits no other room), and it carries
364
+ the requested `expiresAt` — inspect the minted token's claims; don't assume it,
365
+ and don't hand an owner token to an ordinary participant.
366
+ - [ ] `getRoom(name)` reflects real state: a created room resolves with its
367
+ configured `privacy`/`maxParticipants`/`recording`, and after `deleteRoom(name)`
368
+ it returns `null` — ending a room actually removes it, so its old URL/tokens no
369
+ longer admit a join. (Live participant count is NOT in the core `Room` type —
370
+ don't assert on it.)
371
+ - [ ] Size/quota holds: if the app sets `maxParticipants`, the created room
372
+ carries that cap (the provider enforces it at join) — it isn't silently dropped.
373
+ - [ ] SECURITY — the provider API key (e.g. `DAILY_CO_API_KEY`) stays server-side;
374
+ the browser only ever receives a token/URL your endpoint returned, never the key
375
+ or a direct provider call. Private rooms are un-guessable: only an authorized
376
+ user's request mints a token, and no unauthenticated caller joins a `private`
377
+ room by guessing its `name`/URL without one.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-video-rooms-livekit",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "LiveKit video rooms provider for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,7 +17,8 @@
17
17
  }
18
18
  },
19
19
  "files": [
20
- "dist"
20
+ "dist",
21
+ "README.md"
21
22
  ],
22
23
  "keywords": [
23
24
  "molecule",
@@ -29,24 +30,24 @@
29
30
  ],
30
31
  "license": "Apache-2.0",
31
32
  "peerDependencies": {
32
- "@molecule/api-secrets": "^1.0.0",
33
- "@molecule/api-video-rooms": "1.0.0"
33
+ "@molecule/api-secrets": "^1.0.1",
34
+ "@molecule/api-video-rooms": "^1.0.1"
34
35
  },
35
36
  "dependencies": {
36
37
  "livekit-server-sdk": "2.17.0"
37
38
  },
38
39
  "devDependencies": {
39
- "@molecule/api-video-rooms": "1.0.0",
40
+ "@molecule/api-video-rooms": "1.0.2",
40
41
  "@types/node": "26.1.2",
41
42
  "typescript": "6.0.3",
42
- "vitest": "4.1.10"
43
+ "vitest": "4.1.11"
43
44
  },
44
45
  "repository": {
45
46
  "type": "git",
46
47
  "url": "https://github.com/molecule-dev/molecule.git",
47
48
  "directory": "packages/api/bonds/video-rooms/livekit"
48
49
  },
49
- "homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/api/bonds/video-rooms/livekit",
50
+ "homepage": "https://www.molecule.dev/packages/api-video-rooms-livekit",
50
51
  "bugs": "https://github.com/molecule-dev/molecule/issues",
51
52
  "publishConfig": {
52
53
  "access": "public"