@maelstrom-co/realtime-livekit-server 0.0.0-stage → 0.1.1

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) 2025-2026 Jose Ignacio Vazquez Calleja, Krzysztof Trześniewski and Javier Cabrera Arteaga
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,100 @@
1
- # Temporary Holding Version
1
+ # @maelstrom-co/realtime-livekit-server
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
+ Server-only handler for minting LiveKit room access tokens.
4
+
5
+ The server sibling of `@maelstrom-co/realtime-livekit`:
6
+ `@maelstrom-co/realtime-protocol` owns the shared LiveKit grant and mint-failure
7
+ contracts, and this package implements the token minter. This package and the
8
+ agent worker both read `LIVEKIT_API_KEY` / `LIVEKIT_API_SECRET`; the browser
9
+ gets a scoped, short-lived grant whose token exposes the API key as its public
10
+ issuer. The signing secret never ships to the browser.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ bun add @maelstrom-co/realtime-livekit-server
16
+ ```
17
+
18
+ Or: `npm install` / `pnpm add` / `yarn add @maelstrom-co/realtime-livekit-server`
19
+
20
+ Do not install `@maelstrom-co/realtime-livekit` here. That is the browser
21
+ adapter; it carries the LiveKit WebRTC peer surface and the browser VAD
22
+ runtime. This package reaches the shared contract through
23
+ `@maelstrom-co/realtime-protocol/livekit` instead, which is what keeps the
24
+ process holding `LIVEKIT_API_SECRET` free of browser code.
25
+
26
+ ## What it does
27
+
28
+ - `mintLiveKitToken` — a `(input: unknown) => Promise<LiveKitMintResult>` that
29
+ signs a LiveKit room JWT scoped to a room + identity, reading credentials
30
+ and the token TTL from `LIVEKIT_*` env vars. The minter owns only request
31
+ shape validation and local provider interaction; application transport owns
32
+ authentication, authorization, CSRF, origin checks, shared rate limits, and
33
+ trusted room scope. The returned grant carries
34
+ `expiresAt`. Token expiry is checked for each initial or fresh room connection,
35
+ including an explicit `connect()` after `disconnect()`. It does not impact
36
+ SDK-managed reconnects for an already connected participant because LiveKit
37
+ pushes refreshed tokens to connected clients, and the SDK uses the refreshed
38
+ token for managed reconnects. Expiry alone does not disconnect an active
39
+ participant or end the room. Each fresh `connect()` invokes `mintToken`.
40
+ - `mintFailureHttpStatus` — a suggested `MintFailureReason -> HTTP status`
41
+ mapping that this package provides by re-exporting it from
42
+ `@maelstrom-co/realtime-protocol` for callers wiring the minter into an HTTP
43
+ transport.
44
+
45
+ ## Quick example
46
+
47
+ ```ts
48
+ import { isErr } from '@maelstrom-co/protocol';
49
+ import {
50
+ mintLiveKitToken,
51
+ LiveKitTokenRequestSchema,
52
+ } from '@maelstrom-co/realtime-livekit-server';
53
+
54
+ // Room name and participant identity come from authenticated server policy,
55
+ // never from the browser. This package signs the scope it is handed; it does
56
+ // not decide who may ask for one.
57
+ const result = await mintLiveKitToken({
58
+ roomName: authenticated.roomName,
59
+ identity: authenticated.identity,
60
+ });
61
+
62
+ const response = isErr(result)
63
+ ? Response.json({ error: 'mint-failed' }, { status: 500 })
64
+ : Response.json(result.value);
65
+ ```
66
+
67
+ `LiveKitTokenRequestSchema` validates the shape of a mint request when your
68
+ transport needs it. The grant carries `roomJoin` for that one room,
69
+ `canPublish`, and `canSubscribe` — no room administration, recording, ingress,
70
+ or egress.
71
+
72
+ Everything that makes this route safe to expose — authentication, origin and
73
+ CSRF checks, rate limits, short token lifetimes, session duration limits,
74
+ no-store headers, redacted telemetry — belongs to the route around it, and is
75
+ worked through step by step in the
76
+ [LiveKit cascade guide](https://docs.maelstrom-ai.co/guides/voice/livekit-cascade/#harden-the-mint-route).
77
+
78
+ The server process requires `LIVEKIT_URL`, `LIVEKIT_API_KEY`, and
79
+ `LIVEKIT_API_SECRET`. `LIVEKIT_TOKEN_TTL` is optional and defaults to `15m`.
80
+ Token TTL does not bound a session: LiveKit pushes refreshed tokens to
81
+ connected participants, so expiry only affects new connections.
82
+
83
+ > **Development-only demo route:** The repository demo mint route at
84
+ > `apps/demo/src/lib/voice/get-livekit-token.ts` currently lacks production
85
+ > authentication, trusted scope derivation, and explicit no-store cache headers.
86
+ > Do not deploy it; use the hardened route from the guide above.
87
+
88
+
89
+ ## Docs
90
+
91
+ - Production guide: https://docs.maelstrom-ai.co/guides/voice/livekit-cascade/
92
+ - Voice overview: https://docs.maelstrom-ai.co/guides/voice/overview/
93
+ - API reference: https://docs.maelstrom-ai.co/reference/realtime-livekit-server/readme/
94
+ - Architecture: https://docs.maelstrom-ai.co/understanding/architecture/
95
+ - LiveKit token generation: https://docs.livekit.io/home/server/generating-tokens/
96
+ - LiveKit voice AI worker guide: https://docs.livekit.io/agents/start/voice-ai/
97
+
98
+ ## License
99
+
100
+ MIT
@@ -0,0 +1,17 @@
1
+ /**
2
+ * `@maelstrom-co/realtime-livekit-server` — server-only, transport-agnostic
3
+ * logic for minting LiveKit room access tokens.
4
+ *
5
+ * The server sibling of `@maelstrom-co/realtime-livekit`: the browser package
6
+ * declares the `LiveKitTokenGrant` contract the adapter consumes, and this
7
+ * package implements it. It is the
8
+ * only side that touches `LIVEKIT_API_KEY` / `LIVEKIT_API_SECRET`, and it
9
+ * never ships to the browser. Wiring the minter into a route (method checks,
10
+ * body parsing, status codes) is the caller's responsibility — see
11
+ * {@link mintLiveKitToken}.
12
+ */
13
+ export type { MintFailure, MintFailureReason, } from '@maelstrom-co/realtime-protocol';
14
+ export { mintFailureHttpStatus } from '@maelstrom-co/realtime-protocol';
15
+ export type { LiveKitMintResult, LiveKitTokenRequest, } from './lib/livekit-mint.js';
16
+ export { LiveKitTokenRequestSchema, mintLiveKitToken, } from './lib/livekit-mint.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,YAAY,EACV,WAAW,EACX,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,YAAY,EACV,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,yBAAyB,EACzB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ import { mintFailureHttpStatus as e } from "@maelstrom-co/realtime-protocol";
2
+ import { err as t, ok as n } from "@maelstrom-co/protocol";
3
+ import { LiveKitTokenGrantSchema as r, USER_PARTICIPANT_IDENTITY as i } from "@maelstrom-co/realtime-protocol/livekit";
4
+ import { AccessToken as a } from "livekit-server-sdk";
5
+ import { z as o } from "zod";
6
+ //#region src/lib/livekit-mint.ts
7
+ var s = o.object({
8
+ roomName: o.string().trim().min(1),
9
+ identity: o.string().min(1).optional()
10
+ }), c = "15m";
11
+ async function l(e) {
12
+ let o = process.env.LIVEKIT_API_KEY, l = process.env.LIVEKIT_API_SECRET;
13
+ if (!o || !l) return t({ reason: "missing-api-key" });
14
+ let u = s.safeParse(e);
15
+ if (!u.success) return t({ reason: "invalid-request" });
16
+ let f = process.env.LIVEKIT_URL;
17
+ if (!f) return console.error("LIVEKIT_URL is required (e.g. ws://localhost:7880 for local dev) — no default is assumed."), t({ reason: "invalid-config" });
18
+ let p = process.env.LIVEKIT_TOKEN_TTL ?? c, m = d(p);
19
+ if (m === null) return console.error(`LIVEKIT_TOKEN_TTL="${p}" is not a supported token lifetime. Use a positive number of seconds (e.g. 900) or <int><unit> with unit s/m/h/d (e.g. 15m, 2h, 7d).`), t({ reason: "invalid-config" });
20
+ try {
21
+ let e = new a(o, l, {
22
+ identity: u.data.identity ?? i,
23
+ ttl: m
24
+ });
25
+ e.addGrant({
26
+ roomJoin: !0,
27
+ room: u.data.roomName,
28
+ canPublish: !0,
29
+ canSubscribe: !0
30
+ });
31
+ let s = await e.toJwt(), c = Math.floor(Date.now() / 1e3) + m, d = r.safeParse({
32
+ token: s,
33
+ url: f,
34
+ expiresAt: c
35
+ });
36
+ return d.success ? n(d.data) : (console.error(`LiveKit token grant failed validation: ${JSON.stringify(d.error.issues)}`), t({ reason: "invalid-config" }));
37
+ } catch {
38
+ return t({ reason: "upstream-failure" });
39
+ }
40
+ }
41
+ var u = {
42
+ s: 1,
43
+ m: 60,
44
+ h: 3600,
45
+ d: 86400
46
+ };
47
+ function d(e) {
48
+ let t = e.trim(), n;
49
+ if (/^\d+$/.test(t)) n = Number(t);
50
+ else {
51
+ let e = /^(\d+)([smhd])$/.exec(t);
52
+ if (!e) return null;
53
+ n = Number(e[1]) * u[e[2]];
54
+ }
55
+ return n > 0 && Number.isSafeInteger(n) ? n : null;
56
+ }
57
+ //#endregion
58
+ export { s as LiveKitTokenRequestSchema, e as mintFailureHttpStatus, l as mintLiveKitToken };
@@ -0,0 +1,135 @@
1
+ import { Result } from '@maelstrom-co/protocol';
2
+ import { MintFailure } from '@maelstrom-co/realtime-protocol';
3
+ import { LiveKitTokenGrant } from '@maelstrom-co/realtime-protocol/livekit';
4
+ import { z } from 'zod';
5
+ /**
6
+ * What a caller passes {@link mintLiveKitToken} to scope a token to one room.
7
+ * The package validates this request shape, while application transport retains
8
+ * authentication, authorization, CSRF, origin, rate-limit, and trusted-scope
9
+ * responsibilities.
10
+ */
11
+ export interface LiveKitTokenRequest {
12
+ /** Caller-provided room scope; validation trims surrounding whitespace before token scoping. */
13
+ readonly roomName: string;
14
+ /** Participant identity, defaulting to `"user"` when omitted. */
15
+ readonly identity?: string;
16
+ }
17
+ /** Wire schema for {@link LiveKitTokenRequest}. */
18
+ export declare const LiveKitTokenRequestSchema: z.ZodObject<{
19
+ roomName: z.ZodString;
20
+ identity: z.ZodOptional<z.ZodString>;
21
+ }, z.core.$strip>;
22
+ /** Outcome of a {@link mintLiveKitToken} call. */
23
+ export type LiveKitMintResult = Result<LiveKitTokenGrant, MintFailure>;
24
+ /**
25
+ * Mints a LiveKit access-token grant scoped to a single room + identity,
26
+ * reading credentials from `LIVEKIT_API_KEY` / `LIVEKIT_API_SECRET`, the room
27
+ * URL from `LIVEKIT_URL` (required — no default, so a deploy that omits it
28
+ * fails closed rather than silently pointing every browser at localhost),
29
+ * and the token lifetime from `LIVEKIT_TOKEN_TTL` (defaulting to `15m`).
30
+ *
31
+ * Result-based rather than throwing: a missing credential is a
32
+ * `missing-api-key` failure and a malformed request an `invalid-request`
33
+ * failure, so a misconfigured deploy surfaces a typed reason a transport can
34
+ * map to a status instead of a raw throw. The returned grant carries
35
+ * `expiresAt` (computed from the TTL), which describes when the JWT can no
36
+ * longer authenticate an initial or fresh room connection. Token expiry is
37
+ * checked for each such connection, including an explicit `connect()` after
38
+ * `disconnect()`. It does not impact SDK-managed reconnects for an already
39
+ * connected participant: LiveKit pushes refreshed tokens to connected clients,
40
+ * and the SDK uses the refreshed token for managed reconnects. Expiry alone does
41
+ * not disconnect an active participant or end the room. Each fresh `connect()`
42
+ * invokes `mintToken`; the adapter does not schedule its own proactive renewal.
43
+ * Expiry does not impose a maximum room duration or adapter cleanup. Production
44
+ * hosts must enforce session-duration and cleanup policy independently.
45
+ *
46
+ * This mint operation is an **unauthenticated bootstrap**. Production transport
47
+ * code must authenticate and authorize callers, enforce a trusted room and
48
+ * identity policy instead of forwarding untrusted values, and add origin
49
+ * controls, rate limits, and abuse controls before exposing the minter.
50
+ * The example's imported authentication, CSRF, origin, shared rate-limit, and
51
+ * telemetry functions are mandatory app-provided fail-closed controls; this
52
+ * package does not implement them. `requireAuthenticatedVoiceSession`
53
+ * authenticates and authorizes the request, binds the principal to trusted
54
+ * session state, and derives room scope; it does not validate CSRF.
55
+ * `isValidVoiceMintCsrf` is the only control in the example that validates the
56
+ * CSRF proof. The controls must deny when policy cannot be evaluated and keep
57
+ * raw failures inside the redacted telemetry boundary.
58
+ *
59
+ * Unlike the OpenAI minter there is no upstream HTTP call to inject a fake
60
+ * `fetch` into: the JWT is signed locally, so tests exercise it by mocking
61
+ * `livekit-server-sdk`.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { isErr } from '@maelstrom-co/protocol';
66
+ * import {
67
+ * mintFailureHttpStatus,
68
+ * mintLiveKitToken,
69
+ * } from '@maelstrom-co/realtime-livekit-server';
70
+ * import { requireAuthenticatedVoiceSession } from './auth';
71
+ * import {
72
+ * consumeVoiceMintRateLimit,
73
+ * isTrustedVoiceMintOrigin,
74
+ * isValidVoiceMintCsrf,
75
+ * } from './voice-mint-policy';
76
+ * import { reportRedactedVoiceMintFailure } from './redacted-telemetry';
77
+ *
78
+ * export async function POST(request: Request): Promise<Response> {
79
+ * const headers = { 'Cache-Control': 'private, no-store' };
80
+ * try {
81
+ * if (!isTrustedVoiceMintOrigin(request)) {
82
+ * return Response.json({ error: 'request-denied' }, { status: 403, headers });
83
+ * }
84
+ *
85
+ * const session = await requireAuthenticatedVoiceSession(request);
86
+ * if (session === null) {
87
+ * return Response.json({ error: 'unauthorized' }, { status: 401, headers });
88
+ * }
89
+ *
90
+ * if (!isValidVoiceMintCsrf(request, session)) {
91
+ * return Response.json({ error: 'request-denied' }, { status: 403, headers });
92
+ * }
93
+ *
94
+ * const rateLimit = await consumeVoiceMintRateLimit(session.principalId);
95
+ * if (!rateLimit.allowed) {
96
+ * return Response.json(
97
+ * { error: 'rate-limited' },
98
+ * {
99
+ * status: 429,
100
+ * headers: { ...headers, 'Retry-After': String(rateLimit.retryAfterSeconds) },
101
+ * },
102
+ * );
103
+ * }
104
+ *
105
+ * const result = await mintLiveKitToken({
106
+ * roomName: session.roomName,
107
+ * identity: session.identity,
108
+ * });
109
+ *
110
+ * if (isErr(result)) {
111
+ * return Response.json(
112
+ * { error: 'mint-failed' },
113
+ * { status: mintFailureHttpStatus(result.error.reason), headers },
114
+ * );
115
+ * }
116
+ * return Response.json(result.value, { headers });
117
+ * } catch (error) {
118
+ * try {
119
+ * await reportRedactedVoiceMintFailure({
120
+ * source: 'livekit-token-route',
121
+ * error,
122
+ * });
123
+ * } catch {
124
+ * // Telemetry failure must not escape the HTTP boundary.
125
+ * }
126
+ * return Response.json(
127
+ * { error: 'mint-failed' },
128
+ * { status: 500, headers },
129
+ * );
130
+ * }
131
+ * }
132
+ * ```
133
+ */
134
+ export declare function mintLiveKitToken(input: unknown): Promise<LiveKitMintResult>;
135
+ //# sourceMappingURL=livekit-mint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"livekit-mint.d.ts","sourceRoot":"","sources":["../../src/lib/livekit-mint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,iCAAiC,CAAC;AAChF,OAAO,EACL,KAAK,iBAAiB,EAGvB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,gGAAgG;IAChG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,mDAAmD;AACnD,eAAO,MAAM,yBAAyB;;;iBAMpC,CAAC;AAEH,kDAAkD;AAClD,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;AAIvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6GG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,iBAAiB,CAAC,CA8E5B"}
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
1
  {
2
2
  "name": "@maelstrom-co/realtime-livekit-server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Server-only minting of LiveKit room access tokens for Maelstrom. The server sibling of @maelstrom-co/realtime-livekit.",
5
+ "keywords": [
6
+ "maelstrom",
7
+ "ai",
8
+ "llm",
9
+ "dynamic-ui",
10
+ "generative-ui",
11
+ "realtime",
12
+ "voice",
13
+ "server",
14
+ "node",
15
+ "livekit",
16
+ "access-token"
17
+ ],
18
+ "license": "MIT",
19
+ "engines": {
20
+ "node": ">=20"
21
+ },
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ "./package.json": "./package.json",
28
+ ".": {
29
+ "@maelstrom-co/source": "./src/index.ts",
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js",
32
+ "default": "./dist/index.js"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "skills",
38
+ "!**/*.tsbuildinfo"
39
+ ],
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/maelstrom-co/maelstrom.git",
43
+ "directory": "packages/realtime-livekit-server"
44
+ },
45
+ "homepage": "https://maelstrom-ai.co",
46
+ "bugs": {
47
+ "url": "https://github.com/maelstrom-co/maelstrom/issues"
48
+ },
49
+ "author": "Maelstrom (https://maelstrom-ai.co)",
50
+ "publishConfig": {
51
+ "registry": "https://registry.npmjs.org",
52
+ "access": "public"
53
+ },
54
+ "dependencies": {
55
+ "@maelstrom-co/protocol": "0.1.1",
56
+ "@maelstrom-co/realtime-protocol": "0.1.1",
57
+ "livekit-server-sdk": "^2.13.1",
58
+ "zod": "4.6.6"
59
+ },
60
+ "nx": {
61
+ "targets": {
62
+ "typecheck": {
63
+ "command": "tsc -p tsconfig.lib.json --noEmit && tsc -p tsconfig.spec.json --noEmit",
64
+ "options": {
65
+ "cwd": "{projectRoot}"
66
+ }
67
+ },
68
+ "test": {
69
+ "command": "bun test",
70
+ "options": {
71
+ "cwd": "{projectRoot}"
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,28 @@
1
+ ---
2
+ name: maelstrom-realtime-livekit-server-sdk
3
+ description: >-
4
+ Version-matched API guide for @maelstrom-co/realtime-livekit-server. Load when implementing or
5
+ reviewing this package's APIs and it is installed; check the owning installed package manifest before relying on API names.
6
+ license: MIT
7
+ metadata:
8
+ author: Maelstrom
9
+ sdkPackage: '@maelstrom-co/realtime-livekit-server'
10
+ ---
11
+
12
+ # @maelstrom-co/realtime-livekit-server
13
+
14
+ This guide is published inside `@maelstrom-co/realtime-livekit-server`; its package version is its
15
+ API version. Before use, read the installed
16
+ package's `package.json` version as the version authority. If the guide is
17
+ not shipped by that exact installed package, do not rely on it:
18
+ inspect that installation's `exports`, declarations, source, and tests.
19
+
20
+ Package scope: Server-only minting of LiveKit room access tokens for Maelstrom. The server sibling of @maelstrom-co/realtime-livekit.
21
+
22
+ Confirm every symbol against this installed package's public exports and
23
+ declarations. Preserve its documented runtime and dependency boundaries; do not
24
+ move behavior owned by adjacent packages or the consuming application into this
25
+ package.
26
+
27
+ When accepting a mint request, read
28
+ [common tasks](references/common-tasks.md) for trusted room scope and route controls.
@@ -0,0 +1,33 @@
1
+ # Validate application-derived room scope
2
+
3
+ Derive the room from authenticated, authorized application state. With the
4
+ supplied Maelstrom cascade worker, use the fixed user identity and one human per
5
+ room. Keep principal authorization in the application's room mapping. This
6
+ fragment validates wire shape; validation is not authorization or minting.
7
+
8
+ ```ts
9
+ import { LiveKitTokenRequestSchema } from '@maelstrom-co/realtime-livekit-server';
10
+ import { USER_PARTICIPANT_IDENTITY } from '@maelstrom-co/realtime-protocol/livekit';
11
+
12
+ export function validateTrustedScope(roomName: string) {
13
+ return LiveKitTokenRequestSchema.safeParse({ roomName, identity: USER_PARTICIPANT_IDENTITY });
14
+ }
15
+ ```
16
+
17
+ Only call `mintLiveKitToken` after application origin, authentication,
18
+ authorization, CSRF, and fail-closed rate-limit checks. The helper reads server
19
+ credentials; no server or worker should import a browser package for wire types.
20
+
21
+ ## Verify
22
+
23
+ Test invalid room scope, missing credentials/URL, invalid TTL, and failure mapping.
24
+ Check that returned Grant scope matches the application session. Return bounded
25
+ error copy with private/no-store headers, not raw provider details.
26
+
27
+ ## Troubleshoot
28
+
29
+ `LIVEKIT_URL` is required. The minter signs locally, so its test seam differs
30
+ from OpenAI's upstream-fetch seam. Token expiry governs fresh authentication,
31
+ not the duration of an already active room. Application policy owns cleanup.
32
+ The supplied worker waits for `USER_PARTICIPANT_IDENTITY`; a different identity
33
+ can validate successfully but leave that worker waiting for its participant.