@livekit/agents-plugin-krisp 1.4.9

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 (48) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +144 -0
  3. package/dist/_krisp.cjs +267 -0
  4. package/dist/_krisp.cjs.map +1 -0
  5. package/dist/_krisp.d.cts +43 -0
  6. package/dist/_krisp.d.ts +43 -0
  7. package/dist/_krisp.d.ts.map +1 -0
  8. package/dist/_krisp.js +241 -0
  9. package/dist/_krisp.js.map +1 -0
  10. package/dist/_krisp_sdk.d.cjs +2 -0
  11. package/dist/_krisp_sdk.d.cjs.map +1 -0
  12. package/dist/_krisp_sdk.d.js +1 -0
  13. package/dist/_krisp_sdk.d.js.map +1 -0
  14. package/dist/auth.cjs +69 -0
  15. package/dist/auth.cjs.map +1 -0
  16. package/dist/auth.d.cts +57 -0
  17. package/dist/auth.d.ts +57 -0
  18. package/dist/auth.d.ts.map +1 -0
  19. package/dist/auth.js +41 -0
  20. package/dist/auth.js.map +1 -0
  21. package/dist/index.cjs +55 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.cts +24 -0
  24. package/dist/index.d.ts +24 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +31 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/log.cjs +30 -0
  29. package/dist/log.cjs.map +1 -0
  30. package/dist/log.d.cts +3 -0
  31. package/dist/log.d.ts +3 -0
  32. package/dist/log.d.ts.map +1 -0
  33. package/dist/log.js +6 -0
  34. package/dist/log.js.map +1 -0
  35. package/dist/viva_filter.cjs +103 -0
  36. package/dist/viva_filter.cjs.map +1 -0
  37. package/dist/viva_filter.d.cts +75 -0
  38. package/dist/viva_filter.d.ts +75 -0
  39. package/dist/viva_filter.d.ts.map +1 -0
  40. package/dist/viva_filter.js +81 -0
  41. package/dist/viva_filter.js.map +1 -0
  42. package/package.json +54 -0
  43. package/src/_krisp.ts +366 -0
  44. package/src/_krisp_sdk.d.ts +57 -0
  45. package/src/auth.ts +109 -0
  46. package/src/index.ts +78 -0
  47. package/src/log.ts +7 -0
  48. package/src/viva_filter.ts +191 -0
@@ -0,0 +1,43 @@
1
+ import { AudioFrame, FrameProcessor } from '@livekit/rtc-node';
2
+ export interface KrispLicenseFrameProcessorOptions {
3
+ modelPath: string;
4
+ noiseSuppressionLevel: number;
5
+ frameDurationMs: number;
6
+ }
7
+ /**
8
+ * License-mode FrameProcessor wrapping `@krisp/viva-node-sdk`.
9
+ *
10
+ * Internal implementation detail — users call `voiceIsolation()` and the facade
11
+ * selects this when the auth provider is {@link KrispLicenseAuthProvider}.
12
+ *
13
+ * The buffering strategy mirrors the Python plugin: Krisp processes fixed-size
14
+ * chunks (`frameDurationMs` worth of samples) but input frames may arrive at any
15
+ * size, so incoming samples accumulate in {@link inBuf}, are processed one whole
16
+ * chunk at a time, and results queue in {@link outBuf}. Each call emits whatever
17
+ * processed audio is ready (never zero-padded — see {@link process}), so the
18
+ * output frame size floats and real audio is never interrupted by silence.
19
+ */
20
+ export declare class KrispLicenseFrameProcessor extends FrameProcessor<AudioFrame> {
21
+ private enabled;
22
+ private sdkAcquired;
23
+ private module;
24
+ private session;
25
+ private level;
26
+ private readonly frameDurationMs;
27
+ private readonly modelPath;
28
+ private sampleRate;
29
+ private chunkSamples;
30
+ private warnedChannels;
31
+ private inBuf;
32
+ private outBuf;
33
+ constructor(opts: KrispLicenseFrameProcessorOptions);
34
+ private createSession;
35
+ isEnabled(): boolean;
36
+ setEnabled(enabled: boolean): void;
37
+ get noiseSuppressionLevel(): number;
38
+ setNoiseSuppressionLevel(value: number): void;
39
+ process(frame: AudioFrame): AudioFrame;
40
+ private teardown;
41
+ close(): void;
42
+ }
43
+ //# sourceMappingURL=_krisp.d.ts.map
@@ -0,0 +1,43 @@
1
+ import { AudioFrame, FrameProcessor } from '@livekit/rtc-node';
2
+ export interface KrispLicenseFrameProcessorOptions {
3
+ modelPath: string;
4
+ noiseSuppressionLevel: number;
5
+ frameDurationMs: number;
6
+ }
7
+ /**
8
+ * License-mode FrameProcessor wrapping `@krisp/viva-node-sdk`.
9
+ *
10
+ * Internal implementation detail — users call `voiceIsolation()` and the facade
11
+ * selects this when the auth provider is {@link KrispLicenseAuthProvider}.
12
+ *
13
+ * The buffering strategy mirrors the Python plugin: Krisp processes fixed-size
14
+ * chunks (`frameDurationMs` worth of samples) but input frames may arrive at any
15
+ * size, so incoming samples accumulate in {@link inBuf}, are processed one whole
16
+ * chunk at a time, and results queue in {@link outBuf}. Each call emits whatever
17
+ * processed audio is ready (never zero-padded — see {@link process}), so the
18
+ * output frame size floats and real audio is never interrupted by silence.
19
+ */
20
+ export declare class KrispLicenseFrameProcessor extends FrameProcessor<AudioFrame> {
21
+ private enabled;
22
+ private sdkAcquired;
23
+ private module;
24
+ private session;
25
+ private level;
26
+ private readonly frameDurationMs;
27
+ private readonly modelPath;
28
+ private sampleRate;
29
+ private chunkSamples;
30
+ private warnedChannels;
31
+ private inBuf;
32
+ private outBuf;
33
+ constructor(opts: KrispLicenseFrameProcessorOptions);
34
+ private createSession;
35
+ isEnabled(): boolean;
36
+ setEnabled(enabled: boolean): void;
37
+ get noiseSuppressionLevel(): number;
38
+ setNoiseSuppressionLevel(value: number): void;
39
+ process(frame: AudioFrame): AudioFrame;
40
+ private teardown;
41
+ close(): void;
42
+ }
43
+ //# sourceMappingURL=_krisp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_krisp.d.ts","sourceRoot":"","sources":["../src/_krisp.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAwH/D,MAAM,WAAW,iCAAiC;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,0BAA2B,SAAQ,cAAc,CAAC,UAAU,CAAC;IACxE,OAAO,CAAC,OAAO,CAAQ;IAEvB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAA+B;IAC9C,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,MAAM,CAAiC;gBAEnC,IAAI,EAAE,iCAAiC;IA4BnD,OAAO,CAAC,aAAa;IAyCrB,SAAS,IAAI,OAAO;IAIpB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAalC,IAAI,qBAAqB,IAAI,MAAM,CAElC;IAED,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAM7C,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAyEtC,OAAO,CAAC,QAAQ;IAiBhB,KAAK,IAAI,IAAI;CAId"}
package/dist/_krisp.js ADDED
@@ -0,0 +1,241 @@
1
+ import { AudioFrame, FrameProcessor } from "@livekit/rtc-node";
2
+ import { createRequire } from "node:module";
3
+ import { log } from "./log.js";
4
+ const require2 = createRequire(import.meta.url);
5
+ const SUPPORTED_SAMPLE_RATES = [8e3, 16e3, 24e3, 32e3, 44100, 48e3];
6
+ const SUPPORTED_FRAME_DURATIONS_MS = [10, 15, 20, 30, 32];
7
+ function samplingRateEnum(mod, sampleRate) {
8
+ var _a, _b;
9
+ const value = (_b = (_a = mod.enums) == null ? void 0 : _a.SamplingRate) == null ? void 0 : _b[`Sr${sampleRate}Hz`];
10
+ if (value === void 0) {
11
+ throw new Error(
12
+ `Unsupported sample rate: ${sampleRate} Hz. Supported rates: ${SUPPORTED_SAMPLE_RATES.join(", ")} Hz`
13
+ );
14
+ }
15
+ return value;
16
+ }
17
+ function frameDurationEnum(mod, frameDurationMs) {
18
+ var _a, _b;
19
+ const value = (_b = (_a = mod.enums) == null ? void 0 : _a.FrameDuration) == null ? void 0 : _b[`Fd${frameDurationMs}ms`];
20
+ if (value === void 0) {
21
+ throw new Error(
22
+ `Unsupported frame duration: ${frameDurationMs} ms. Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(", ")} ms`
23
+ );
24
+ }
25
+ return value;
26
+ }
27
+ class KrispLicenseSdkManager {
28
+ static module = null;
29
+ static referenceCount = 0;
30
+ /** Acquire a reference, returning the loaded `@krisp/viva-node-sdk` module. */
31
+ static acquire() {
32
+ if (this.referenceCount === 0) {
33
+ let mod;
34
+ try {
35
+ mod = require2("@krisp/viva-node-sdk");
36
+ } catch {
37
+ throw new Error(
38
+ "@krisp/viva-node-sdk is not installed. Install the proprietary Krisp Node SDK (`pnpm add @krisp/viva-node-sdk`) and provide a .kef model, or use the default LiveKit Cloud auth provider (auth.livekitCloud())."
39
+ );
40
+ }
41
+ const licenseKey = process.env.KRISP_VIVA_SDK_LICENSE_KEY;
42
+ if (licenseKey) {
43
+ mod.globalInit("", licenseKey);
44
+ } else {
45
+ mod.globalInit("");
46
+ }
47
+ this.module = mod;
48
+ log().debug("Krisp Audio SDK (license) initialized");
49
+ }
50
+ this.referenceCount += 1;
51
+ log().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);
52
+ return this.module;
53
+ }
54
+ /** Release a reference, destroying the SDK on the last release. */
55
+ static release() {
56
+ if (this.referenceCount === 0) {
57
+ return;
58
+ }
59
+ this.referenceCount -= 1;
60
+ log().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);
61
+ if (this.referenceCount === 0 && this.module !== null) {
62
+ try {
63
+ this.module.globalDestroy();
64
+ log().debug("Krisp Audio SDK (license) destroyed");
65
+ } catch (e) {
66
+ log().error(`Error during Krisp SDK cleanup: ${e}`);
67
+ } finally {
68
+ this.module = null;
69
+ }
70
+ }
71
+ }
72
+ }
73
+ function concatInt16(a, b) {
74
+ const out = new Int16Array(a.length + b.length);
75
+ out.set(a, 0);
76
+ out.set(b, a.length);
77
+ return out;
78
+ }
79
+ function bufferToInt16(buf) {
80
+ const usableBytes = buf.byteLength - buf.byteLength % 2;
81
+ const copy = buf.buffer.slice(buf.byteOffset, buf.byteOffset + usableBytes);
82
+ return new Int16Array(copy);
83
+ }
84
+ function clampLevel(value) {
85
+ return Math.max(0, Math.min(100, Math.round(value)));
86
+ }
87
+ class KrispLicenseFrameProcessor extends FrameProcessor {
88
+ enabled = true;
89
+ sdkAcquired = false;
90
+ module;
91
+ session = null;
92
+ level;
93
+ frameDurationMs;
94
+ modelPath;
95
+ sampleRate = null;
96
+ chunkSamples = null;
97
+ warnedChannels = false;
98
+ inBuf = new Int16Array(0);
99
+ outBuf = new Int16Array(0);
100
+ constructor(opts) {
101
+ super();
102
+ this.level = clampLevel(opts.noiseSuppressionLevel);
103
+ this.frameDurationMs = opts.frameDurationMs;
104
+ this.modelPath = opts.modelPath;
105
+ if (!SUPPORTED_FRAME_DURATIONS_MS.includes(this.frameDurationMs)) {
106
+ throw new Error(
107
+ `Unsupported frame duration: ${this.frameDurationMs} ms. Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(", ")} ms`
108
+ );
109
+ }
110
+ this.module = KrispLicenseSdkManager.acquire();
111
+ this.sdkAcquired = true;
112
+ try {
113
+ this.createSession(16e3);
114
+ log().info("Krisp license frame processor initialized (adapts to input sample rate)");
115
+ } catch (e) {
116
+ this.teardown();
117
+ throw e;
118
+ }
119
+ }
120
+ createSession(sampleRate) {
121
+ if (this.session !== null && this.sampleRate === sampleRate) {
122
+ return;
123
+ }
124
+ if (!SUPPORTED_SAMPLE_RATES.includes(sampleRate)) {
125
+ throw new Error(
126
+ `Unsupported sample rate: ${sampleRate} Hz. Supported rates: ${SUPPORTED_SAMPLE_RATES.join(", ")} Hz`
127
+ );
128
+ }
129
+ log().info(`Creating Krisp session for sample rate: ${sampleRate}Hz`);
130
+ if (this.session !== null) {
131
+ try {
132
+ this.session.destroy();
133
+ } catch (e) {
134
+ log().error(`Error destroying Krisp session: ${e}`);
135
+ }
136
+ this.session = null;
137
+ }
138
+ const inputSampleRate = samplingRateEnum(this.module, sampleRate);
139
+ const config = {
140
+ inputSampleRate,
141
+ inputFrameDuration: frameDurationEnum(this.module, this.frameDurationMs),
142
+ outputSampleRate: inputSampleRate,
143
+ modelInfo: { path: this.modelPath }
144
+ };
145
+ this.session = this.module.NcInt16.create(config);
146
+ this.sampleRate = sampleRate;
147
+ this.chunkSamples = Math.floor(sampleRate * this.frameDurationMs / 1e3);
148
+ this.inBuf = new Int16Array(0);
149
+ this.outBuf = new Int16Array(0);
150
+ }
151
+ isEnabled() {
152
+ return this.enabled;
153
+ }
154
+ setEnabled(enabled) {
155
+ if (this.enabled === enabled) {
156
+ return;
157
+ }
158
+ this.enabled = enabled;
159
+ this.inBuf = new Int16Array(0);
160
+ this.outBuf = new Int16Array(0);
161
+ }
162
+ get noiseSuppressionLevel() {
163
+ return this.level;
164
+ }
165
+ setNoiseSuppressionLevel(value) {
166
+ this.level = clampLevel(value);
167
+ }
168
+ process(frame) {
169
+ if (!this.enabled) {
170
+ return frame;
171
+ }
172
+ if (frame.channels !== 1) {
173
+ if (!this.warnedChannels) {
174
+ log().warn(
175
+ `Krisp filter not applied: expected mono audio but got ${frame.channels} channels; frames are passed through unprocessed.`
176
+ );
177
+ this.warnedChannels = true;
178
+ }
179
+ return frame;
180
+ }
181
+ if (this.session === null || this.sampleRate !== frame.sampleRate) {
182
+ this.createSession(frame.sampleRate);
183
+ }
184
+ const chunk = this.chunkSamples;
185
+ this.inBuf = concatInt16(this.inBuf, frame.data);
186
+ const nChunks = Math.floor(this.inBuf.length / chunk);
187
+ if (nChunks > 0) {
188
+ const consumed = nChunks * chunk;
189
+ const pending = this.inBuf.subarray(0, consumed);
190
+ this.inBuf = this.inBuf.slice(consumed);
191
+ for (let i = 0; i < nChunks; i++) {
192
+ const chunkIn = pending.subarray(i * chunk, (i + 1) * chunk);
193
+ let chunkOut;
194
+ try {
195
+ const inputBuf = Buffer.from(chunkIn.buffer, chunkIn.byteOffset, chunkIn.byteLength);
196
+ const outputBuf = this.session.process(inputBuf, this.level);
197
+ chunkOut = bufferToInt16(outputBuf);
198
+ } catch (e) {
199
+ log().error(`Error processing frame: ${e}`);
200
+ chunkOut = chunkIn;
201
+ }
202
+ if (chunkOut.length !== chunk) {
203
+ log().warn(
204
+ `Krisp returned ${chunkOut.length} samples, expected ${chunk}; using original audio`
205
+ );
206
+ chunkOut = chunkIn;
207
+ }
208
+ this.outBuf = concatInt16(this.outBuf, chunkOut);
209
+ }
210
+ }
211
+ const n = frame.samplesPerChannel;
212
+ const k = Math.min(n, this.outBuf.length);
213
+ const out = this.outBuf.slice(0, k);
214
+ this.outBuf = this.outBuf.slice(k);
215
+ return new AudioFrame(out, frame.sampleRate, frame.channels, out.length);
216
+ }
217
+ teardown() {
218
+ if (this.session !== null) {
219
+ try {
220
+ this.session.destroy();
221
+ } catch (e) {
222
+ log().error(`Error destroying Krisp session: ${e}`);
223
+ }
224
+ this.session = null;
225
+ }
226
+ this.inBuf = new Int16Array(0);
227
+ this.outBuf = new Int16Array(0);
228
+ if (this.sdkAcquired) {
229
+ KrispLicenseSdkManager.release();
230
+ this.sdkAcquired = false;
231
+ }
232
+ }
233
+ close() {
234
+ this.teardown();
235
+ log().debug("Krisp license frame processor closed");
236
+ }
237
+ }
238
+ export {
239
+ KrispLicenseFrameProcessor
240
+ };
241
+ //# sourceMappingURL=_krisp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/_krisp.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * License-mode Krisp internals.\n *\n * This module is private to the plugin. It wraps the public\n * `@krisp/viva-node-sdk` and exposes a {@link KrispLicenseFrameProcessor} that\n * {@link krispVivaFilter} instantiates when the user picks\n * {@link KrispLicenseAuthProvider}.\n *\n * Wires the documented `@krisp/viva-node-sdk` surface (https://sdk-docs.krisp.ai):\n * `globalInit(workingDir, licenseKey)`, the `enums.SamplingRate` and\n * `enums.FrameDuration` tables, `NcInt16.create(config)`, per-frame `process`\n * (byte `Buffer` in and out), and the session/global destroy calls. The license\n * key is read from `KRISP_VIVA_SDK_LICENSE_KEY` and passed to `globalInit`.\n *\n * The frame buffering / reframing logic is ported from the Python plugin.\n */\nimport type { KrispEnumMember, KrispModule, KrispNcSession } from '@krisp/viva-node-sdk';\nimport { AudioFrame, FrameProcessor } from '@livekit/rtc-node';\nimport { createRequire } from 'node:module';\nimport { log } from './log.js';\n\nconst require = createRequire(import.meta.url);\n\nconst SUPPORTED_SAMPLE_RATES: Array<number> = [8000, 16000, 24000, 32000, 44100, 48000] as const;\nconst SUPPORTED_FRAME_DURATIONS_MS: Array<number> = [10, 15, 20, 30, 32] as const;\n\n/** Map a sample rate (Hz) to the SDK's `enums.SamplingRate.Sr<rate>Hz` member. */\nfunction samplingRateEnum(mod: KrispModule, sampleRate: number): KrispEnumMember {\n const value = mod.enums?.SamplingRate?.[`Sr${sampleRate}Hz`];\n if (value === undefined) {\n throw new Error(\n `Unsupported sample rate: ${sampleRate} Hz. ` +\n `Supported rates: ${SUPPORTED_SAMPLE_RATES.join(', ')} Hz`,\n );\n }\n return value;\n}\n\n/** Map a frame duration (ms) to the SDK's `enums.FrameDuration.Fd<ms>ms` member. */\nfunction frameDurationEnum(mod: KrispModule, frameDurationMs: number): KrispEnumMember {\n const value = mod.enums?.FrameDuration?.[`Fd${frameDurationMs}ms`];\n if (value === undefined) {\n throw new Error(\n `Unsupported frame duration: ${frameDurationMs} ms. ` +\n `Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(', ')} ms`,\n );\n }\n return value;\n}\n\n/**\n * Process-singleton ref counter for the proprietary `@krisp/viva-node-sdk`.\n *\n * Krisp's `globalInit` / `globalDestroy` are process-global, so this manager\n * keeps a single SDK alive across multiple license-mode frame processors. The\n * module is lazy-required on first acquire — never loaded in cloud-only\n * deployments.\n */\nclass KrispLicenseSdkManager {\n private static module: KrispModule | null = null;\n private static referenceCount = 0;\n\n /** Acquire a reference, returning the loaded `@krisp/viva-node-sdk` module. */\n static acquire(): KrispModule {\n if (this.referenceCount === 0) {\n let mod: KrispModule;\n try {\n mod = require('@krisp/viva-node-sdk');\n } catch {\n throw new Error(\n '@krisp/viva-node-sdk is not installed. Install the proprietary Krisp Node SDK ' +\n '(`pnpm add @krisp/viva-node-sdk`) and provide a .kef model, or use the ' +\n 'default LiveKit Cloud auth provider (auth.livekitCloud()).',\n );\n }\n\n // Working dir '' uses the SDK default; the license key comes from the\n // environment (KRISP_VIVA_SDK_LICENSE_KEY) and is passed to globalInit.\n const licenseKey = process.env.KRISP_VIVA_SDK_LICENSE_KEY;\n if (licenseKey) {\n mod.globalInit('', licenseKey);\n } else {\n mod.globalInit('');\n }\n\n this.module = mod;\n log().debug('Krisp Audio SDK (license) initialized');\n }\n this.referenceCount += 1;\n log().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);\n // Non-null once refCount > 0: release() only nulls the module at refCount 0.\n return this.module!;\n }\n\n /** Release a reference, destroying the SDK on the last release. */\n static release(): void {\n if (this.referenceCount === 0) {\n return;\n }\n this.referenceCount -= 1;\n log().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);\n if (this.referenceCount === 0 && this.module !== null) {\n try {\n this.module.globalDestroy();\n log().debug('Krisp Audio SDK (license) destroyed');\n } catch (e) {\n log().error(`Error during Krisp SDK cleanup: ${e}`);\n } finally {\n this.module = null;\n }\n }\n }\n}\n\nfunction concatInt16(a: Int16Array, b: Int16Array): Int16Array {\n const out = new Int16Array(a.length + b.length);\n out.set(a, 0);\n out.set(b, a.length);\n return out;\n}\n\n/**\n * Reinterpret a byte buffer of interleaved int16 PCM as an `Int16Array`. Copies\n * into a fresh, 2-byte-aligned buffer — a native-returned `Buffer` may sit at an\n * odd `byteOffset` in a pooled `ArrayBuffer`, which a zero-copy `Int16Array`\n * view cannot represent.\n */\nfunction bufferToInt16(buf: Buffer): Int16Array {\n const usableBytes = buf.byteLength - (buf.byteLength % 2);\n const copy = buf.buffer.slice(buf.byteOffset, buf.byteOffset + usableBytes);\n return new Int16Array(copy);\n}\n\nfunction clampLevel(value: number): number {\n return Math.max(0, Math.min(100, Math.round(value)));\n}\n\nexport interface KrispLicenseFrameProcessorOptions {\n modelPath: string;\n noiseSuppressionLevel: number;\n frameDurationMs: number;\n}\n\n/**\n * License-mode FrameProcessor wrapping `@krisp/viva-node-sdk`.\n *\n * Internal implementation detail — users call `voiceIsolation()` and the facade\n * selects this when the auth provider is {@link KrispLicenseAuthProvider}.\n *\n * The buffering strategy mirrors the Python plugin: Krisp processes fixed-size\n * chunks (`frameDurationMs` worth of samples) but input frames may arrive at any\n * size, so incoming samples accumulate in {@link inBuf}, are processed one whole\n * chunk at a time, and results queue in {@link outBuf}. Each call emits whatever\n * processed audio is ready (never zero-padded — see {@link process}), so the\n * output frame size floats and real audio is never interrupted by silence.\n */\nexport class KrispLicenseFrameProcessor extends FrameProcessor<AudioFrame> {\n private enabled = true;\n\n private sdkAcquired = false;\n private module: KrispModule;\n private session: KrispNcSession | null = null;\n private level: number;\n private readonly frameDurationMs: number;\n private readonly modelPath: string;\n private sampleRate: number | null = null;\n private chunkSamples: number | null = null;\n private warnedChannels = false;\n private inBuf: Int16Array = new Int16Array(0);\n private outBuf: Int16Array = new Int16Array(0);\n\n constructor(opts: KrispLicenseFrameProcessorOptions) {\n super();\n this.level = clampLevel(opts.noiseSuppressionLevel);\n this.frameDurationMs = opts.frameDurationMs;\n this.modelPath = opts.modelPath;\n\n if (!SUPPORTED_FRAME_DURATIONS_MS.includes(this.frameDurationMs)) {\n throw new Error(\n `Unsupported frame duration: ${this.frameDurationMs} ms. ` +\n `Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(', ')} ms`,\n );\n }\n\n this.module = KrispLicenseSdkManager.acquire();\n this.sdkAcquired = true;\n\n try {\n // Pre-load the model now to fail fast on a bad license/model path. The\n // session is recreated automatically if the first frame arrives at a\n // different sample rate.\n this.createSession(16000);\n log().info('Krisp license frame processor initialized (adapts to input sample rate)');\n } catch (e) {\n this.teardown();\n throw e;\n }\n }\n\n private createSession(sampleRate: number): void {\n if (this.session !== null && this.sampleRate === sampleRate) {\n return;\n }\n if (!SUPPORTED_SAMPLE_RATES.includes(sampleRate as never)) {\n throw new Error(\n `Unsupported sample rate: ${sampleRate} Hz. ` +\n `Supported rates: ${SUPPORTED_SAMPLE_RATES.join(', ')} Hz`,\n );\n }\n\n log().info(`Creating Krisp session for sample rate: ${sampleRate}Hz`);\n\n // Free the previous session (if any) before replacing it on a rate change.\n if (this.session !== null) {\n try {\n this.session.destroy();\n } catch (e) {\n log().error(`Error destroying Krisp session: ${e}`);\n }\n this.session = null;\n }\n\n // Int16 noise-cancellation session. Our AudioFrame samples are int16 PCM, so\n // NcInt16 avoids a float round-trip (the docs' Node example shows the NcFloat\n // sibling). Output sample rate is pinned to the input rate — we only filter.\n const inputSampleRate = samplingRateEnum(this.module, sampleRate);\n const config = {\n inputSampleRate,\n inputFrameDuration: frameDurationEnum(this.module, this.frameDurationMs),\n outputSampleRate: inputSampleRate,\n modelInfo: { path: this.modelPath },\n };\n this.session = this.module.NcInt16.create(config);\n this.sampleRate = sampleRate;\n this.chunkSamples = Math.floor((sampleRate * this.frameDurationMs) / 1000);\n // The pending/processed buffers belong to the old rate; start fresh.\n this.inBuf = new Int16Array(0);\n this.outBuf = new Int16Array(0);\n }\n\n isEnabled(): boolean {\n return this.enabled;\n }\n\n setEnabled(enabled: boolean): void {\n if (this.enabled === enabled) {\n return;\n }\n this.enabled = enabled;\n // Drop buffered audio across the transition: while disabled, process()\n // returns raw frames without draining, so a partial input chunk (inBuf) and\n // processed-but-unemitted output (outBuf) captured before the mute would\n // otherwise replay on re-enable and produce a discontinuity.\n this.inBuf = new Int16Array(0);\n this.outBuf = new Int16Array(0);\n }\n\n get noiseSuppressionLevel(): number {\n return this.level;\n }\n\n setNoiseSuppressionLevel(value: number): void {\n // Applied on the next processed frame — the level is passed per-call to the\n // Krisp session, so no session recreation is needed.\n this.level = clampLevel(value);\n }\n\n process(frame: AudioFrame): AudioFrame {\n if (!this.enabled) {\n return frame;\n }\n\n if (frame.channels !== 1) {\n if (!this.warnedChannels) {\n log().warn(\n `Krisp filter not applied: expected mono audio but got ${frame.channels} ` +\n 'channels; frames are passed through unprocessed.',\n );\n this.warnedChannels = true;\n }\n return frame;\n }\n\n // Adapt to the input sample rate, recreating the session on a change.\n if (this.session === null || this.sampleRate !== frame.sampleRate) {\n this.createSession(frame.sampleRate);\n }\n\n const chunk = this.chunkSamples!;\n\n // Accumulate the incoming samples and process every whole chunk available.\n this.inBuf = concatInt16(this.inBuf, frame.data);\n\n const nChunks = Math.floor(this.inBuf.length / chunk);\n if (nChunks > 0) {\n const consumed = nChunks * chunk;\n const pending = this.inBuf.subarray(0, consumed);\n this.inBuf = this.inBuf.slice(consumed);\n\n for (let i = 0; i < nChunks; i++) {\n const chunkIn = pending.subarray(i * chunk, (i + 1) * chunk);\n let chunkOut: Int16Array;\n try {\n // The SDK takes/returns byte buffers of interleaved int16 PCM, so wrap\n // the input samples as a Buffer view and reinterpret the returned\n // Buffer's bytes as int16 samples (its `.length` is bytes = samples×2).\n const inputBuf = Buffer.from(chunkIn.buffer, chunkIn.byteOffset, chunkIn.byteLength);\n // Non-null: the guard above (re)creates the session or throws.\n const outputBuf = this.session!.process(inputBuf, this.level);\n chunkOut = bufferToInt16(outputBuf);\n } catch (e) {\n log().error(`Error processing frame: ${e}`);\n chunkOut = chunkIn;\n }\n if (chunkOut.length !== chunk) {\n log().warn(\n `Krisp returned ${chunkOut.length} samples, expected ${chunk}; using original audio`,\n );\n chunkOut = chunkIn;\n }\n this.outBuf = concatInt16(this.outBuf, chunkOut);\n }\n }\n\n // Emit the processed audio that is ready, keeping any surplus buffered for\n // the next call. We never zero-pad a deficit: doing so injects silence\n // *between* real audio (which recurs whenever the input frame size isn't a\n // multiple of the chunk size) and surfaces as audible gaps once frames are\n // concatenated downstream. Instead the output frame size floats — up to a\n // full chunk of latency at the start (and an empty frame if the buffer is\n // momentarily starved), both of which downstream reframing handles fine —\n // so real audio is never interrupted.\n const n = frame.samplesPerChannel;\n const k = Math.min(n, this.outBuf.length);\n const out = this.outBuf.slice(0, k);\n this.outBuf = this.outBuf.slice(k);\n\n return new AudioFrame(out, frame.sampleRate, frame.channels, out.length);\n }\n\n private teardown(): void {\n if (this.session !== null) {\n try {\n this.session.destroy();\n } catch (e) {\n log().error(`Error destroying Krisp session: ${e}`);\n }\n this.session = null;\n }\n this.inBuf = new Int16Array(0);\n this.outBuf = new Int16Array(0);\n if (this.sdkAcquired) {\n KrispLicenseSdkManager.release();\n this.sdkAcquired = false;\n }\n }\n\n close(): void {\n this.teardown();\n log().debug('Krisp license frame processor closed');\n }\n}\n"],"mappings":"AAqBA,SAAS,YAAY,sBAAsB;AAC3C,SAAS,qBAAqB;AAC9B,SAAS,WAAW;AAEpB,MAAMA,WAAU,cAAc,YAAY,GAAG;AAE7C,MAAM,yBAAwC,CAAC,KAAM,MAAO,MAAO,MAAO,OAAO,IAAK;AACtF,MAAM,+BAA8C,CAAC,IAAI,IAAI,IAAI,IAAI,EAAE;AAGvE,SAAS,iBAAiB,KAAkB,YAAqC;AA/BjF;AAgCE,QAAM,SAAQ,eAAI,UAAJ,mBAAW,iBAAX,mBAA0B,KAAK,UAAU;AACvD,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI;AAAA,MACR,4BAA4B,UAAU,yBAChB,uBAAuB,KAAK,IAAI,CAAC;AAAA,IACzD;AAAA,EACF;AACA,SAAO;AACT;AAGA,SAAS,kBAAkB,KAAkB,iBAA0C;AA3CvF;AA4CE,QAAM,SAAQ,eAAI,UAAJ,mBAAW,kBAAX,mBAA2B,KAAK,eAAe;AAC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AI,WAAW,KAAK,MAAM,YAAY,MAAM,UAAU,IAAI,MAAM;AAAA,EACzE;AAAA,EAEQ,WAAiB;AACvB,QAAI,KAAK,YAAY,MAAM;AACzB,UAAI;AACF,aAAK,QAAQ,QAAQ;AAAA,MACvB,SAAS,GAAG;AACV,YAAI,EAAE,MAAM,mCAAmC,CAAC,EAAE;AAAA,MACpD;AACA,WAAK,UAAU;AAAA,IACjB;AACA,SAAK,QAAQ,IAAI,WAAW,CAAC;AAC7B,SAAK,SAAS,IAAI,WAAW,CAAC;AAC9B,QAAI,KAAK,aAAa;AACpB,6BAAuB,QAAQ;AAC/B,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA,EAEA,QAAc;AACZ,SAAK,SAAS;AACd,QAAI,EAAE,MAAM,sCAAsC;AAAA,EACpD;AACF;","names":["require"]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=_krisp_sdk.d.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=_krisp_sdk.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/auth.cjs ADDED
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var auth_exports = {};
20
+ __export(auth_exports, {
21
+ KRISP_LICENSE_KIND: () => KRISP_LICENSE_KIND,
22
+ KrispLicenseAuthProvider: () => KrispLicenseAuthProvider,
23
+ LIVEKIT_CLOUD_KIND: () => LIVEKIT_CLOUD_KIND,
24
+ LiveKitCloudAuthProvider: () => LiveKitCloudAuthProvider,
25
+ auth: () => auth
26
+ });
27
+ module.exports = __toCommonJS(auth_exports);
28
+ var import_node_fs = require("node:fs");
29
+ const LIVEKIT_CLOUD_KIND = Symbol.for(
30
+ "livekit.agents.krisp.auth.livekitCloud"
31
+ );
32
+ const KRISP_LICENSE_KIND = Symbol.for(
33
+ "livekit.agents.krisp.auth.krispLicense"
34
+ );
35
+ class LiveKitCloudAuthProvider {
36
+ /** @internal */
37
+ kind = LIVEKIT_CLOUD_KIND;
38
+ }
39
+ class KrispLicenseAuthProvider {
40
+ /** @internal */
41
+ kind = KRISP_LICENSE_KIND;
42
+ modelPath;
43
+ constructor() {
44
+ const resolvedModelPath = process.env.KRISP_VIVA_FILTER_MODEL_PATH;
45
+ if (!resolvedModelPath) {
46
+ throw new Error("Krisp model path is required. Set KRISP_VIVA_FILTER_MODEL_PATH.");
47
+ }
48
+ if (!resolvedModelPath.endsWith(".kef")) {
49
+ throw new Error("Krisp model must have a .kef extension");
50
+ }
51
+ if (!(0, import_node_fs.existsSync)(resolvedModelPath) || !(0, import_node_fs.statSync)(resolvedModelPath).isFile()) {
52
+ throw new Error(`Krisp model file not found: ${resolvedModelPath}`);
53
+ }
54
+ this.modelPath = resolvedModelPath;
55
+ }
56
+ }
57
+ const auth = {
58
+ livekitCloud: () => new LiveKitCloudAuthProvider(),
59
+ krispLicense: () => new KrispLicenseAuthProvider()
60
+ };
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ KRISP_LICENSE_KIND,
64
+ KrispLicenseAuthProvider,
65
+ LIVEKIT_CLOUD_KIND,
66
+ LiveKitCloudAuthProvider,
67
+ auth
68
+ });
69
+ //# sourceMappingURL=auth.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auth.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Authentication providers for the Krisp plugin.\n *\n * These types are plain configuration holders — {@link krispVivaFilter}\n * dispatches on the provider instance to pick the matching backend FrameProcessor\n * implementation.\n *\n * - {@link LiveKitCloudAuthProvider} (default): selects the closed-source\n * `@livekit/plugins-krisp-viva-internal` backend. It bundles the model and\n * authenticates against LiveKit Cloud using the room JWT, which the agent\n * framework hands to the FrameProcessor via the standard `onCredentialsUpdated`\n * callback.\n * - {@link KrispLicenseAuthProvider}: selects the proprietary `@krisp/viva-node-sdk`\n * with a `.kef` model file (license key supplied via `KRISP_VIVA_SDK_LICENSE_KEY`).\n *\n * Preferred call sites use the {@link auth} namespace:\n *\n * ```ts\n * import { auth } from '@livekit/agents-plugin-krisp';\n *\n * auth.livekitCloud();\n * auth.krispLicense();\n * ```\n */\nimport { existsSync, statSync } from 'node:fs';\n\n/**\n * Discriminator symbols identifying each auth provider, registered in the global\n * symbol registry via `Symbol.for` so the {@link krispVivaFilter}\n * facade can dispatch reliably even when this module is loaded more than once\n * (e.g. duplicate copies through bundling or linked workspaces) — a case where\n * `instanceof` would silently fail. Not part of the public API surface.\n */\nexport const LIVEKIT_CLOUD_KIND: unique symbol = Symbol.for(\n 'livekit.agents.krisp.auth.livekitCloud',\n);\nexport const KRISP_LICENSE_KIND: unique symbol = Symbol.for(\n 'livekit.agents.krisp.auth.krispLicense',\n);\n\n/**\n * Marker for the LiveKit Cloud-bundled Krisp backend.\n *\n * Auth + metering happen inside `@livekit/plugins-krisp-viva-internal`, which\n * receives the room JWT via the standard FrameProcessor `onCredentialsUpdated`\n * callback (forwarded by the facade). There is nothing to configure on this side.\n *\n * @public\n */\nexport class LiveKitCloudAuthProvider {\n /** @internal */\n readonly kind: typeof LIVEKIT_CLOUD_KIND = LIVEKIT_CLOUD_KIND;\n}\n\n/**\n * Krisp-direct auth using the proprietary `@krisp/viva-node-sdk`.\n *\n * Both inputs are read from the environment, which the native SDK also relies on:\n *\n * - `KRISP_VIVA_FILTER_MODEL_PATH` — path to the `.kef` model file.\n * - `KRISP_VIVA_SDK_LICENSE_KEY` — Krisp license key (read by the SDK directly).\n *\n * @public\n */\nexport class KrispLicenseAuthProvider {\n /** @internal */\n readonly kind: typeof KRISP_LICENSE_KIND = KRISP_LICENSE_KIND;\n readonly modelPath: string;\n\n constructor() {\n const resolvedModelPath = process.env.KRISP_VIVA_FILTER_MODEL_PATH;\n\n if (!resolvedModelPath) {\n throw new Error('Krisp model path is required. Set KRISP_VIVA_FILTER_MODEL_PATH.');\n }\n if (!resolvedModelPath.endsWith('.kef')) {\n throw new Error('Krisp model must have a .kef extension');\n }\n if (!existsSync(resolvedModelPath) || !statSync(resolvedModelPath).isFile()) {\n throw new Error(`Krisp model file not found: ${resolvedModelPath}`);\n }\n\n this.modelPath = resolvedModelPath;\n }\n}\n\n/** @public */\nexport type AuthProvider = LiveKitCloudAuthProvider | KrispLicenseAuthProvider;\n\n/**\n * Preferred factory namespace for auth providers.\n *\n * ```ts\n * import { auth } from '@livekit/agents-plugin-krisp';\n *\n * auth.livekitCloud();\n * auth.krispLicense(); // reads KRISP_VIVA_FILTER_MODEL_PATH + KRISP_VIVA_SDK_LICENSE_KEY\n * ```\n *\n * @public\n */\nexport const auth = {\n livekitCloud: (): LiveKitCloudAuthProvider => new LiveKitCloudAuthProvider(),\n krispLicense: (): KrispLicenseAuthProvider => new KrispLicenseAuthProvider(),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BA,qBAAqC;AAS9B,MAAM,qBAAoC,OAAO;AAAA,EACtD;AACF;AACO,MAAM,qBAAoC,OAAO;AAAA,EACtD;AACF;AAWO,MAAM,yBAAyB;AAAA;AAAA,EAE3B,OAAkC;AAC7C;AAYO,MAAM,yBAAyB;AAAA;AAAA,EAE3B,OAAkC;AAAA,EAClC;AAAA,EAET,cAAc;AACZ,UAAM,oBAAoB,QAAQ,IAAI;AAEtC,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI,MAAM,iEAAiE;AAAA,IACnF;AACA,QAAI,CAAC,kBAAkB,SAAS,MAAM,GAAG;AACvC,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AACA,QAAI,KAAC,2BAAW,iBAAiB,KAAK,KAAC,yBAAS,iBAAiB,EAAE,OAAO,GAAG;AAC3E,YAAM,IAAI,MAAM,+BAA+B,iBAAiB,EAAE;AAAA,IACpE;AAEA,SAAK,YAAY;AAAA,EACnB;AACF;AAiBO,MAAM,OAAO;AAAA,EAClB,cAAc,MAAgC,IAAI,yBAAyB;AAAA,EAC3E,cAAc,MAAgC,IAAI,yBAAyB;AAC7E;","names":[]}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Discriminator symbols identifying each auth provider, registered in the global
3
+ * symbol registry via `Symbol.for` so the {@link krispVivaFilter}
4
+ * facade can dispatch reliably even when this module is loaded more than once
5
+ * (e.g. duplicate copies through bundling or linked workspaces) — a case where
6
+ * `instanceof` would silently fail. Not part of the public API surface.
7
+ */
8
+ export declare const LIVEKIT_CLOUD_KIND: unique symbol;
9
+ export declare const KRISP_LICENSE_KIND: unique symbol;
10
+ /**
11
+ * Marker for the LiveKit Cloud-bundled Krisp backend.
12
+ *
13
+ * Auth + metering happen inside `@livekit/plugins-krisp-viva-internal`, which
14
+ * receives the room JWT via the standard FrameProcessor `onCredentialsUpdated`
15
+ * callback (forwarded by the facade). There is nothing to configure on this side.
16
+ *
17
+ * @public
18
+ */
19
+ export declare class LiveKitCloudAuthProvider {
20
+ /** @internal */
21
+ readonly kind: typeof LIVEKIT_CLOUD_KIND;
22
+ }
23
+ /**
24
+ * Krisp-direct auth using the proprietary `@krisp/viva-node-sdk`.
25
+ *
26
+ * Both inputs are read from the environment, which the native SDK also relies on:
27
+ *
28
+ * - `KRISP_VIVA_FILTER_MODEL_PATH` — path to the `.kef` model file.
29
+ * - `KRISP_VIVA_SDK_LICENSE_KEY` — Krisp license key (read by the SDK directly).
30
+ *
31
+ * @public
32
+ */
33
+ export declare class KrispLicenseAuthProvider {
34
+ /** @internal */
35
+ readonly kind: typeof KRISP_LICENSE_KIND;
36
+ readonly modelPath: string;
37
+ constructor();
38
+ }
39
+ /** @public */
40
+ export type AuthProvider = LiveKitCloudAuthProvider | KrispLicenseAuthProvider;
41
+ /**
42
+ * Preferred factory namespace for auth providers.
43
+ *
44
+ * ```ts
45
+ * import { auth } from '@livekit/agents-plugin-krisp';
46
+ *
47
+ * auth.livekitCloud();
48
+ * auth.krispLicense(); // reads KRISP_VIVA_FILTER_MODEL_PATH + KRISP_VIVA_SDK_LICENSE_KEY
49
+ * ```
50
+ *
51
+ * @public
52
+ */
53
+ export declare const auth: {
54
+ livekitCloud: () => LiveKitCloudAuthProvider;
55
+ krispLicense: () => KrispLicenseAuthProvider;
56
+ };
57
+ //# sourceMappingURL=auth.d.ts.map
package/dist/auth.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Discriminator symbols identifying each auth provider, registered in the global
3
+ * symbol registry via `Symbol.for` so the {@link krispVivaFilter}
4
+ * facade can dispatch reliably even when this module is loaded more than once
5
+ * (e.g. duplicate copies through bundling or linked workspaces) — a case where
6
+ * `instanceof` would silently fail. Not part of the public API surface.
7
+ */
8
+ export declare const LIVEKIT_CLOUD_KIND: unique symbol;
9
+ export declare const KRISP_LICENSE_KIND: unique symbol;
10
+ /**
11
+ * Marker for the LiveKit Cloud-bundled Krisp backend.
12
+ *
13
+ * Auth + metering happen inside `@livekit/plugins-krisp-viva-internal`, which
14
+ * receives the room JWT via the standard FrameProcessor `onCredentialsUpdated`
15
+ * callback (forwarded by the facade). There is nothing to configure on this side.
16
+ *
17
+ * @public
18
+ */
19
+ export declare class LiveKitCloudAuthProvider {
20
+ /** @internal */
21
+ readonly kind: typeof LIVEKIT_CLOUD_KIND;
22
+ }
23
+ /**
24
+ * Krisp-direct auth using the proprietary `@krisp/viva-node-sdk`.
25
+ *
26
+ * Both inputs are read from the environment, which the native SDK also relies on:
27
+ *
28
+ * - `KRISP_VIVA_FILTER_MODEL_PATH` — path to the `.kef` model file.
29
+ * - `KRISP_VIVA_SDK_LICENSE_KEY` — Krisp license key (read by the SDK directly).
30
+ *
31
+ * @public
32
+ */
33
+ export declare class KrispLicenseAuthProvider {
34
+ /** @internal */
35
+ readonly kind: typeof KRISP_LICENSE_KIND;
36
+ readonly modelPath: string;
37
+ constructor();
38
+ }
39
+ /** @public */
40
+ export type AuthProvider = LiveKitCloudAuthProvider | KrispLicenseAuthProvider;
41
+ /**
42
+ * Preferred factory namespace for auth providers.
43
+ *
44
+ * ```ts
45
+ * import { auth } from '@livekit/agents-plugin-krisp';
46
+ *
47
+ * auth.livekitCloud();
48
+ * auth.krispLicense(); // reads KRISP_VIVA_FILTER_MODEL_PATH + KRISP_VIVA_SDK_LICENSE_KEY
49
+ * ```
50
+ *
51
+ * @public
52
+ */
53
+ export declare const auth: {
54
+ livekitCloud: () => LiveKitCloudAuthProvider;
55
+ krispLicense: () => KrispLicenseAuthProvider;
56
+ };
57
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AA8BA;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,OAAO,MAEvC,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,OAAO,MAEvC,CAAC;AAEF;;;;;;;;GAQG;AACH,qBAAa,wBAAwB;IACnC,gBAAgB;IAChB,QAAQ,CAAC,IAAI,EAAE,OAAO,kBAAkB,CAAsB;CAC/D;AAED;;;;;;;;;GASG;AACH,qBAAa,wBAAwB;IACnC,gBAAgB;IAChB,QAAQ,CAAC,IAAI,EAAE,OAAO,kBAAkB,CAAsB;IAC9D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;;CAiB5B;AAED,cAAc;AACd,MAAM,MAAM,YAAY,GAAG,wBAAwB,GAAG,wBAAwB,CAAC;AAE/E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI;wBACG,wBAAwB;wBACxB,wBAAwB;CAC3C,CAAC"}
package/dist/auth.js ADDED
@@ -0,0 +1,41 @@
1
+ import { existsSync, statSync } from "node:fs";
2
+ const LIVEKIT_CLOUD_KIND = Symbol.for(
3
+ "livekit.agents.krisp.auth.livekitCloud"
4
+ );
5
+ const KRISP_LICENSE_KIND = Symbol.for(
6
+ "livekit.agents.krisp.auth.krispLicense"
7
+ );
8
+ class LiveKitCloudAuthProvider {
9
+ /** @internal */
10
+ kind = LIVEKIT_CLOUD_KIND;
11
+ }
12
+ class KrispLicenseAuthProvider {
13
+ /** @internal */
14
+ kind = KRISP_LICENSE_KIND;
15
+ modelPath;
16
+ constructor() {
17
+ const resolvedModelPath = process.env.KRISP_VIVA_FILTER_MODEL_PATH;
18
+ if (!resolvedModelPath) {
19
+ throw new Error("Krisp model path is required. Set KRISP_VIVA_FILTER_MODEL_PATH.");
20
+ }
21
+ if (!resolvedModelPath.endsWith(".kef")) {
22
+ throw new Error("Krisp model must have a .kef extension");
23
+ }
24
+ if (!existsSync(resolvedModelPath) || !statSync(resolvedModelPath).isFile()) {
25
+ throw new Error(`Krisp model file not found: ${resolvedModelPath}`);
26
+ }
27
+ this.modelPath = resolvedModelPath;
28
+ }
29
+ }
30
+ const auth = {
31
+ livekitCloud: () => new LiveKitCloudAuthProvider(),
32
+ krispLicense: () => new KrispLicenseAuthProvider()
33
+ };
34
+ export {
35
+ KRISP_LICENSE_KIND,
36
+ KrispLicenseAuthProvider,
37
+ LIVEKIT_CLOUD_KIND,
38
+ LiveKitCloudAuthProvider,
39
+ auth
40
+ };
41
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auth.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Authentication providers for the Krisp plugin.\n *\n * These types are plain configuration holders — {@link krispVivaFilter}\n * dispatches on the provider instance to pick the matching backend FrameProcessor\n * implementation.\n *\n * - {@link LiveKitCloudAuthProvider} (default): selects the closed-source\n * `@livekit/plugins-krisp-viva-internal` backend. It bundles the model and\n * authenticates against LiveKit Cloud using the room JWT, which the agent\n * framework hands to the FrameProcessor via the standard `onCredentialsUpdated`\n * callback.\n * - {@link KrispLicenseAuthProvider}: selects the proprietary `@krisp/viva-node-sdk`\n * with a `.kef` model file (license key supplied via `KRISP_VIVA_SDK_LICENSE_KEY`).\n *\n * Preferred call sites use the {@link auth} namespace:\n *\n * ```ts\n * import { auth } from '@livekit/agents-plugin-krisp';\n *\n * auth.livekitCloud();\n * auth.krispLicense();\n * ```\n */\nimport { existsSync, statSync } from 'node:fs';\n\n/**\n * Discriminator symbols identifying each auth provider, registered in the global\n * symbol registry via `Symbol.for` so the {@link krispVivaFilter}\n * facade can dispatch reliably even when this module is loaded more than once\n * (e.g. duplicate copies through bundling or linked workspaces) — a case where\n * `instanceof` would silently fail. Not part of the public API surface.\n */\nexport const LIVEKIT_CLOUD_KIND: unique symbol = Symbol.for(\n 'livekit.agents.krisp.auth.livekitCloud',\n);\nexport const KRISP_LICENSE_KIND: unique symbol = Symbol.for(\n 'livekit.agents.krisp.auth.krispLicense',\n);\n\n/**\n * Marker for the LiveKit Cloud-bundled Krisp backend.\n *\n * Auth + metering happen inside `@livekit/plugins-krisp-viva-internal`, which\n * receives the room JWT via the standard FrameProcessor `onCredentialsUpdated`\n * callback (forwarded by the facade). There is nothing to configure on this side.\n *\n * @public\n */\nexport class LiveKitCloudAuthProvider {\n /** @internal */\n readonly kind: typeof LIVEKIT_CLOUD_KIND = LIVEKIT_CLOUD_KIND;\n}\n\n/**\n * Krisp-direct auth using the proprietary `@krisp/viva-node-sdk`.\n *\n * Both inputs are read from the environment, which the native SDK also relies on:\n *\n * - `KRISP_VIVA_FILTER_MODEL_PATH` — path to the `.kef` model file.\n * - `KRISP_VIVA_SDK_LICENSE_KEY` — Krisp license key (read by the SDK directly).\n *\n * @public\n */\nexport class KrispLicenseAuthProvider {\n /** @internal */\n readonly kind: typeof KRISP_LICENSE_KIND = KRISP_LICENSE_KIND;\n readonly modelPath: string;\n\n constructor() {\n const resolvedModelPath = process.env.KRISP_VIVA_FILTER_MODEL_PATH;\n\n if (!resolvedModelPath) {\n throw new Error('Krisp model path is required. Set KRISP_VIVA_FILTER_MODEL_PATH.');\n }\n if (!resolvedModelPath.endsWith('.kef')) {\n throw new Error('Krisp model must have a .kef extension');\n }\n if (!existsSync(resolvedModelPath) || !statSync(resolvedModelPath).isFile()) {\n throw new Error(`Krisp model file not found: ${resolvedModelPath}`);\n }\n\n this.modelPath = resolvedModelPath;\n }\n}\n\n/** @public */\nexport type AuthProvider = LiveKitCloudAuthProvider | KrispLicenseAuthProvider;\n\n/**\n * Preferred factory namespace for auth providers.\n *\n * ```ts\n * import { auth } from '@livekit/agents-plugin-krisp';\n *\n * auth.livekitCloud();\n * auth.krispLicense(); // reads KRISP_VIVA_FILTER_MODEL_PATH + KRISP_VIVA_SDK_LICENSE_KEY\n * ```\n *\n * @public\n */\nexport const auth = {\n livekitCloud: (): LiveKitCloudAuthProvider => new LiveKitCloudAuthProvider(),\n krispLicense: (): KrispLicenseAuthProvider => new KrispLicenseAuthProvider(),\n};\n"],"mappings":"AA4BA,SAAS,YAAY,gBAAgB;AAS9B,MAAM,qBAAoC,OAAO;AAAA,EACtD;AACF;AACO,MAAM,qBAAoC,OAAO;AAAA,EACtD;AACF;AAWO,MAAM,yBAAyB;AAAA;AAAA,EAE3B,OAAkC;AAC7C;AAYO,MAAM,yBAAyB;AAAA;AAAA,EAE3B,OAAkC;AAAA,EAClC;AAAA,EAET,cAAc;AACZ,UAAM,oBAAoB,QAAQ,IAAI;AAEtC,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI,MAAM,iEAAiE;AAAA,IACnF;AACA,QAAI,CAAC,kBAAkB,SAAS,MAAM,GAAG;AACvC,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AACA,QAAI,CAAC,WAAW,iBAAiB,KAAK,CAAC,SAAS,iBAAiB,EAAE,OAAO,GAAG;AAC3E,YAAM,IAAI,MAAM,+BAA+B,iBAAiB,EAAE;AAAA,IACpE;AAEA,SAAK,YAAY;AAAA,EACnB;AACF;AAiBO,MAAM,OAAO;AAAA,EAClB,cAAc,MAAgC,IAAI,yBAAyB;AAAA,EAC3E,cAAc,MAAgC,IAAI,yBAAyB;AAC7E;","names":[]}