@pagelines/sdk 1.0.822 → 1.0.824
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/dist/AgentWrap.js +136 -96
- package/dist/AgentWrap.js.map +1 -1
- package/dist/agent/voice/provider.d.ts +14 -1
- package/dist/agent/voice/providers/livekit/provider.d.ts +7 -2
- package/dist/agent/voice/voice-session-client.d.ts +12 -6
- package/dist/agent.js +74 -53
- package/dist/agent.js.map +1 -1
- package/dist/contract.js +1 -0
- package/dist/contract.js.map +1 -1
- package/dist/provider.js +4 -1
- package/dist/provider.js.map +1 -1
- package/dist/provider2.js +1 -1
- package/dist/provider3.js +29 -14
- package/dist/provider3.js.map +1 -1
- package/dist/sdk.css +1 -1
- package/package.json +1 -1
package/dist/provider.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import "./rolldown-runtime.js";
|
|
2
2
|
//#region agent/voice/provider.ts
|
|
3
|
+
function isVoiceAudible(e) {
|
|
4
|
+
return e >= .08;
|
|
5
|
+
}
|
|
3
6
|
var createVoiceProviderClient = async (e) => {
|
|
4
7
|
switch (e.provider) {
|
|
5
8
|
case "elevenlabs": {
|
|
@@ -35,6 +38,6 @@ function voiceRangeSpectrum(e, t = 9) {
|
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
//#endregion
|
|
38
|
-
export {
|
|
41
|
+
export { voiceSpectrum as i, isVoiceAudible as n, voiceRangeSpectrum as r, createVoiceProviderClient as t };
|
|
39
42
|
|
|
40
43
|
//# sourceMappingURL=provider.js.map
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","names":[],"sources":["../agent/voice/provider.ts"],"sourcesContent":["import type { VoiceSessionMint } from '@pagelines/core'\n\nexport interface VoiceLevelEvent {\n source: 'mic' | 'playback'\n /** Normalized 0..1 signal level. */\n level: number\n /** Speech-spectrum energies, low pitch first. */\n bands?: readonly number[]\n}\n\nexport interface VoiceSessionError {\n code: string\n message: string\n}\n\nexport type VoiceDisconnectCause = 'agent' | 'error' | 'network' | 'unknown'\n\nexport interface VoiceProviderClient {\n connect: (handlers: {\n onDisconnected: (cause: VoiceDisconnectCause) => void\n onError: (error: VoiceSessionError) => void\n onThinkingChange?: (thinking: boolean) => void\n }) => Promise<void>\n disconnect: () => Promise<void>\n sampleLevel: () => VoiceLevelEvent | undefined\n /** Self-mute without ending the live session. */\n setMuted?: (muted: boolean) => Promise<void>\n /**\n * Hand the provider text the caller typed during a live call, as though\n * they had said it — the assistant answers aloud and the turn lands in the\n * transcript through the normal provider path. Optional: a provider that\n * cannot inject text simply omits it and the surface hides the affordance.\n */\n sendUserMessage?: (text: string) => void\n}\n\nexport type CreateVoiceProviderClient = (mint: VoiceSessionMint) => Promise<VoiceProviderClient>\n\n/** Provider selection is a closed union; each SDK remains in its lazy chunk. */\nexport const createVoiceProviderClient: CreateVoiceProviderClient = async (mint) => {\n switch (mint.provider) {\n case 'elevenlabs': {\n const { ElevenLabsVoiceProvider } = await import('./providers/elevenlabs/provider')\n return new ElevenLabsVoiceProvider(mint)\n }\n case 'livekit': {\n const { LiveKitVoiceProvider } = await import('./providers/livekit/provider')\n return new LiveKitVoiceProvider(mint)\n }\n }\n}\n\nexport const VOICE_SPECTRUM_BANDS = 9\n\n/** Log-spaced speech spectrum for transports that expose FFT bins. */\nexport function voiceSpectrum(frequencies: Uint8Array, sampleRate: number, fftSize: number, bandCount = VOICE_SPECTRUM_BANDS): readonly number[] {\n if (!Number.isFinite(sampleRate) || sampleRate <= 0 || !Number.isFinite(fftSize) || fftSize <= 0 || bandCount <= 0)\n return []\n\n const hzPerBin = sampleRate / fftSize\n const fromHz = 80\n const ratio = 4_000 / fromHz\n const bands: number[] = []\n for (let band = 0; band < bandCount; band++) {\n const start = Math.max(0, Math.ceil((fromHz * ratio ** (band / bandCount)) / hzPerBin))\n const end = Math.min(frequencies.length, Math.ceil((fromHz * ratio ** ((band + 1) / bandCount)) / hzPerBin))\n if (end <= start) {\n bands.push(0)\n continue\n }\n let squared = 0\n for (let index = start; index < end; index++)\n squared += (frequencies[index] / 255) ** 2\n bands.push(Math.sqrt(squared / (end - start)))\n }\n return bands\n}\n\n/** Equal-width bands for SDKs that already expose voice-range FFT bins. */\nexport function voiceRangeSpectrum(frequencies: Uint8Array, bandCount = VOICE_SPECTRUM_BANDS): readonly number[] {\n if (!frequencies.length || bandCount <= 0)\n return []\n return Array.from({ length: bandCount }, (_, band) => {\n const start = Math.floor((band * frequencies.length) / bandCount)\n const end = Math.max(start + 1, Math.floor(((band + 1) * frequencies.length) / bandCount))\n let squared = 0\n for (let index = start; index < Math.min(end, frequencies.length); index++)\n squared += (frequencies[index] / 255) ** 2\n return Math.sqrt(squared / Math.max(1, Math.min(end, frequencies.length) - start))\n })\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"provider.js","names":[],"sources":["../agent/voice/provider.ts"],"sourcesContent":["import type { VoiceSessionMint } from '@pagelines/core'\n\nexport interface VoiceLevelEvent {\n source: 'mic' | 'playback'\n /** Normalized 0..1 signal level. */\n level: number\n /** Speech-spectrum energies, low pitch first. */\n bands?: readonly number[]\n}\n\n/** One speech/noise boundary shared by audible UI state and work-cue ducking. */\nexport function isVoiceAudible(level: number): boolean {\n return level >= 0.08\n}\n\nexport interface VoiceSessionError {\n code: string\n message: string\n}\n\nexport type VoiceDisconnectCause = 'agent' | 'error' | 'network' | 'unknown'\n\n/**\n * Who the transport says is talking. Raw energy is not a speech signal — room\n * tone and the speaker's own playback both read as audible — so ducking,\n * tone, and which meter the surface follows come from here.\n */\nexport interface VoiceSpeakingState {\n user: boolean\n agent: boolean\n}\n\nexport interface VoiceProviderClient {\n connect: (handlers: {\n onDisconnected: (cause: VoiceDisconnectCause) => void\n onError: (error: VoiceSessionError) => void\n onThinkingChange?: (thinking: boolean) => void\n onSpeakingChange?: (state: VoiceSpeakingState) => void\n }) => Promise<void>\n disconnect: () => Promise<void>\n /** Loudest source by default; `prefer` pins a meter while someone is known to be speaking. */\n sampleLevel: (prefer?: VoiceLevelEvent['source']) => VoiceLevelEvent | undefined\n /** Self-mute without ending the live session. */\n setMuted?: (muted: boolean) => Promise<void>\n /**\n * Hand the provider text the caller typed during a live call, as though\n * they had said it — the assistant answers aloud and the turn lands in the\n * transcript through the normal provider path. Optional: a provider that\n * cannot inject text simply omits it and the surface hides the affordance.\n */\n sendUserMessage?: (text: string) => void\n}\n\nexport type CreateVoiceProviderClient = (mint: VoiceSessionMint) => Promise<VoiceProviderClient>\n\n/** Provider selection is a closed union; each SDK remains in its lazy chunk. */\nexport const createVoiceProviderClient: CreateVoiceProviderClient = async (mint) => {\n switch (mint.provider) {\n case 'elevenlabs': {\n const { ElevenLabsVoiceProvider } = await import('./providers/elevenlabs/provider')\n return new ElevenLabsVoiceProvider(mint)\n }\n case 'livekit': {\n const { LiveKitVoiceProvider } = await import('./providers/livekit/provider')\n return new LiveKitVoiceProvider(mint)\n }\n }\n}\n\nexport const VOICE_SPECTRUM_BANDS = 9\n\n/** Log-spaced speech spectrum for transports that expose FFT bins. */\nexport function voiceSpectrum(frequencies: Uint8Array, sampleRate: number, fftSize: number, bandCount = VOICE_SPECTRUM_BANDS): readonly number[] {\n if (!Number.isFinite(sampleRate) || sampleRate <= 0 || !Number.isFinite(fftSize) || fftSize <= 0 || bandCount <= 0)\n return []\n\n const hzPerBin = sampleRate / fftSize\n const fromHz = 80\n const ratio = 4_000 / fromHz\n const bands: number[] = []\n for (let band = 0; band < bandCount; band++) {\n const start = Math.max(0, Math.ceil((fromHz * ratio ** (band / bandCount)) / hzPerBin))\n const end = Math.min(frequencies.length, Math.ceil((fromHz * ratio ** ((band + 1) / bandCount)) / hzPerBin))\n if (end <= start) {\n bands.push(0)\n continue\n }\n let squared = 0\n for (let index = start; index < end; index++)\n squared += (frequencies[index] / 255) ** 2\n bands.push(Math.sqrt(squared / (end - start)))\n }\n return bands\n}\n\n/** Equal-width bands for SDKs that already expose voice-range FFT bins. */\nexport function voiceRangeSpectrum(frequencies: Uint8Array, bandCount = VOICE_SPECTRUM_BANDS): readonly number[] {\n if (!frequencies.length || bandCount <= 0)\n return []\n return Array.from({ length: bandCount }, (_, band) => {\n const start = Math.floor((band * frequencies.length) / bandCount)\n const end = Math.max(start + 1, Math.floor(((band + 1) * frequencies.length) / bandCount))\n let squared = 0\n for (let index = start; index < Math.min(end, frequencies.length); index++)\n squared += (frequencies[index] / 255) ** 2\n return Math.sqrt(squared / Math.max(1, Math.min(end, frequencies.length) - start))\n })\n}\n"],"mappings":";;AAWA,SAAgB,eAAe,GAAwB;CACrD,OAAO,KAAS;AAClB;AA2CA,IAAa,4BAAuD,OAAO,MAAS;CAClF,QAAQ,EAAK,UAAb;EACE,KAAK,cAAc;GACjB,IAAM,EAAE,+BAA4B,MAAM,OAAO;GACjD,OAAO,IAAI,EAAwB,CAAI;EACzC;EACA,KAAK,WAAW;GACd,IAAM,EAAE,4BAAyB,MAAM,OAAO;GAC9C,OAAO,IAAI,EAAqB,CAAI;EACtC;CACF;AACF;AAKA,SAAgB,cAAc,GAAyB,GAAoB,GAAiB,IAAA,GAAqD;CAC/I,IAAI,CAAC,OAAO,SAAS,CAAU,KAAK,KAAc,KAAK,CAAC,OAAO,SAAS,CAAO,KAAK,KAAW,KAAK,KAAa,GAC/G,OAAO,CAAC;CAEV,IAAM,IAAW,IAAa,GAGxB,IAAkB,CAAC;CACzB,KAAK,IAAI,IAAO,GAAG,IAAO,GAAW,KAAQ;EAC3C,IAAM,IAAQ,KAAK,IAAI,GAAG,KAAK,KAAM,KAAS,OAAU,IAAO,KAAc,CAAQ,CAAC,GAChF,IAAM,KAAK,IAAI,EAAY,QAAQ,KAAK,KAAM,KAAS,QAAW,IAAO,KAAK,KAAc,CAAQ,CAAC;EAC3G,IAAI,KAAO,GAAO;GAChB,EAAM,KAAK,CAAC;GACZ;EACF;EACA,IAAI,IAAU;EACd,KAAK,IAAI,IAAQ,GAAO,IAAQ,GAAK,KACnC,MAAY,EAAY,KAAS,QAAQ;EAC3C,EAAM,KAAK,KAAK,KAAK,KAAW,IAAM,EAAM,CAAC;CAC/C;CACA,OAAO;AACT;AAGA,SAAgB,mBAAmB,GAAyB,IAAA,GAAqD;CAG/G,OAFI,CAAC,EAAY,UAAU,KAAa,IAC/B,CAAC,IACH,MAAM,KAAK,EAAE,QAAQ,EAAU,IAAI,GAAG,MAAS;EACpD,IAAM,IAAQ,KAAK,MAAO,IAAO,EAAY,SAAU,CAAS,GAC1D,IAAM,KAAK,IAAI,IAAQ,GAAG,KAAK,OAAQ,IAAO,KAAK,EAAY,SAAU,CAAS,CAAC,GACrF,IAAU;EACd,KAAK,IAAI,IAAQ,GAAO,IAAQ,KAAK,IAAI,GAAK,EAAY,MAAM,GAAG,KACjE,MAAY,EAAY,KAAS,QAAQ;EAC3C,OAAO,KAAK,KAAK,IAAU,KAAK,IAAI,GAAG,KAAK,IAAI,GAAK,EAAY,MAAM,IAAI,CAAK,CAAC;CACnF,CAAC;AACH"}
|
package/dist/provider2.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./rolldown-runtime.js";
|
|
2
2
|
import { s as e } from "./sdkClient.js";
|
|
3
|
-
import {
|
|
3
|
+
import { r as t } from "./provider.js";
|
|
4
4
|
//#region ../../node_modules/.pnpm/@elevenlabs+client@1.17.0_@types+dom-mediacapture-record@1.0.22/node_modules/@elevenlabs/client/dist/utils/BaseConnection.js
|
|
5
5
|
var BaseConnection = class {
|
|
6
6
|
constructor(t = {}) {
|
package/dist/provider3.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./rolldown-runtime.js";
|
|
2
2
|
import { s as e } from "./sdkClient.js";
|
|
3
|
-
import {
|
|
3
|
+
import { i as t } from "./provider.js";
|
|
4
4
|
//#region ../../node_modules/.pnpm/livekit-client@2.21.0_@types+dom-mediacapture-record@1.0.22/node_modules/livekit-client/dist/livekit-client.esm.mjs
|
|
5
5
|
function _mergeNamespaces(e, t) {
|
|
6
6
|
return t.forEach(function(t) {
|
|
@@ -18333,19 +18333,23 @@ _defineProperty(JWSSignatureVerificationFailed, "code", "ERR_JWS_SIGNATURE_VERIF
|
|
|
18333
18333
|
//#region agent/voice/providers/livekit/provider.ts
|
|
18334
18334
|
var $a = 1e4, eo = "lk.agent.state", LiveKitVoiceProvider = class {
|
|
18335
18335
|
constructor(t, n = {}) {
|
|
18336
|
-
e(this, "mint", void 0), e(this, "room", void 0), e(this, "createAnalyser", void 0), e(this, "handlers", void 0), e(this, "cancelReadyWait", void 0), e(this, "analysers", []), e(this, "levelSources", []), e(this, "attachedElements", []), e(this, "closing", !1), this.mint = t, this.room = n.createRoom?.() ?? new Za(), this.createAnalyser = n.createAnalyser;
|
|
18336
|
+
e(this, "mint", void 0), e(this, "room", void 0), e(this, "createAnalyser", void 0), e(this, "handlers", void 0), e(this, "cancelReadyWait", void 0), e(this, "analysers", []), e(this, "levelSources", []), e(this, "attachedElements", []), e(this, "closing", !1), e(this, "userSpeaking", !1), e(this, "agentActiveSpeaker", !1), e(this, "agentStateSpeaking", !1), e(this, "lastSpeaking", void 0), this.mint = t, this.room = n.createRoom?.() ?? new Za(), this.createAnalyser = n.createAnalyser;
|
|
18337
18337
|
}
|
|
18338
18338
|
async connect(e) {
|
|
18339
18339
|
this.handlers = e, this.room.on(P.TrackSubscribed, (e) => {
|
|
18340
18340
|
e.kind === z.Kind.Audio && this.attachRemoteAudio(e);
|
|
18341
18341
|
}), this.room.on(P.ParticipantAttributesChanged, (e, t) => {
|
|
18342
|
-
|
|
18342
|
+
if (!t.isAgent) return;
|
|
18343
|
+
let n = t.attributes[eo];
|
|
18344
|
+
this.handlers?.onThinkingChange?.(n === "thinking"), this.agentStateSpeaking = n === "speaking", this.publishSpeaking();
|
|
18345
|
+
}), this.room.on(P.ActiveSpeakersChanged, (e) => {
|
|
18346
|
+
this.userSpeaking = e.some((e) => e.isLocal), this.agentActiveSpeaker = e.some((e) => e.isAgent), this.publishSpeaking();
|
|
18343
18347
|
}), this.room.on(P.Disconnected, (e) => {
|
|
18344
18348
|
this.closing || this.handlers?.onDisconnected(disconnectCause(e));
|
|
18345
18349
|
});
|
|
18346
18350
|
let t = "VOICE_CONNECT_FAILED", n;
|
|
18347
18351
|
try {
|
|
18348
|
-
if (await this.room.connect(this.mint.url, this.mint.token), this.closing
|
|
18352
|
+
if (await this.room.connect(this.mint.url, this.mint.token), this.closing) return;
|
|
18349
18353
|
if (t = "VOICE_MIC_UNAVAILABLE", n = await this.room.localParticipant.setMicrophoneEnabled(!0, {
|
|
18350
18354
|
echoCancellation: !0,
|
|
18351
18355
|
noiseSuppression: !0
|
|
@@ -18353,6 +18357,10 @@ var $a = 1e4, eo = "lk.agent.state", LiveKitVoiceProvider = class {
|
|
|
18353
18357
|
await this.room.localParticipant.setMicrophoneEnabled(!1).catch(() => {});
|
|
18354
18358
|
return;
|
|
18355
18359
|
}
|
|
18360
|
+
if (t = "VOICE_AGENT_UNAVAILABLE", await this.waitForAgentReady(), this.closing) {
|
|
18361
|
+
await this.room.localParticipant.setMicrophoneEnabled(!1).catch(() => {});
|
|
18362
|
+
return;
|
|
18363
|
+
}
|
|
18356
18364
|
t = "VOICE_PLAYBACK_UNAVAILABLE", await this.room.startAudio();
|
|
18357
18365
|
} catch (e) {
|
|
18358
18366
|
let n = e instanceof Error ? e : /* @__PURE__ */ Error("Could not open the voice connection.");
|
|
@@ -18377,19 +18385,26 @@ var $a = 1e4, eo = "lk.agent.state", LiveKitVoiceProvider = class {
|
|
|
18377
18385
|
noiseSuppression: !0
|
|
18378
18386
|
});
|
|
18379
18387
|
}
|
|
18380
|
-
sampleLevel() {
|
|
18381
|
-
let e;
|
|
18382
|
-
for (let { source:
|
|
18383
|
-
let
|
|
18384
|
-
if (!Number.isFinite(
|
|
18388
|
+
sampleLevel(e) {
|
|
18389
|
+
let t, n = e && this.levelSources.some((t) => t.source === e) ? this.levelSources.filter((t) => t.source === e) : this.levelSources;
|
|
18390
|
+
for (let { source: e, analyser: r } of n) {
|
|
18391
|
+
let n = r.calculateVolume();
|
|
18392
|
+
if (!Number.isFinite(n)) continue;
|
|
18385
18393
|
let i = {
|
|
18386
|
-
source:
|
|
18387
|
-
level: Math.min(1, Math.max(0,
|
|
18388
|
-
...
|
|
18394
|
+
source: e,
|
|
18395
|
+
level: Math.min(1, Math.max(0, n)),
|
|
18396
|
+
...r.calculateBands ? { bands: r.calculateBands() } : {}
|
|
18389
18397
|
};
|
|
18390
|
-
(!
|
|
18398
|
+
(!t || i.level > t.level) && (t = i);
|
|
18391
18399
|
}
|
|
18392
|
-
return
|
|
18400
|
+
return t;
|
|
18401
|
+
}
|
|
18402
|
+
publishSpeaking() {
|
|
18403
|
+
let e = {
|
|
18404
|
+
user: this.userSpeaking,
|
|
18405
|
+
agent: this.agentActiveSpeaker || this.agentStateSpeaking
|
|
18406
|
+
};
|
|
18407
|
+
this.lastSpeaking?.user === e.user && this.lastSpeaking?.agent === e.agent || (this.lastSpeaking = e, this.handlers?.onSpeakingChange?.(e));
|
|
18393
18408
|
}
|
|
18394
18409
|
async waitForAgentReady() {
|
|
18395
18410
|
let ready = (e) => {
|