@pagelines/sdk 1.0.877 → 1.0.879

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 (92) hide show
  1. package/README.md +68 -68
  2. package/dist/BotProvider.js +777 -0
  3. package/dist/BotProvider.js.map +1 -0
  4. package/dist/{AgentWidgetInline.js → BotWidgetInline.js} +8 -8
  5. package/dist/BotWidgetInline.js.map +1 -0
  6. package/dist/{AgentWidgetModal.js → BotWidgetModal.js} +7 -7
  7. package/dist/BotWidgetModal.js.map +1 -0
  8. package/dist/{AgentWrap.js → BotWrap.js} +1202 -1155
  9. package/dist/BotWrap.js.map +1 -0
  10. package/dist/{agent/AgentController.d.ts → bot/BotController.d.ts} +36 -18
  11. package/dist/bot/index.d.ts +14 -0
  12. package/dist/{agent → bot}/schema.d.ts +6 -6
  13. package/dist/{agent/ui/AgentAvatar.vue.d.ts → bot/ui/BotAvatar.vue.d.ts} +6 -6
  14. package/dist/{agent/ui/AgentChat.vue.d.ts → bot/ui/BotChat.vue.d.ts} +5 -5
  15. package/dist/{agent/ui/AgentProvider.vue.d.ts → bot/ui/BotProvider.vue.d.ts} +3 -3
  16. package/dist/{agent/ui/AgentWrap.vue.d.ts → bot/ui/BotWrap.vue.d.ts} +3 -4
  17. package/dist/{agent/ui/ElAgentAbout.vue.d.ts → bot/ui/ElBotAbout.vue.d.ts} +2 -2
  18. package/dist/{agent/ui/ElAgentChat.vue.d.ts → bot/ui/ElBotChat.vue.d.ts} +5 -5
  19. package/dist/{agent/ui/ElAgentChatPreview.vue.d.ts → bot/ui/ElBotChatPreview.vue.d.ts} +1 -1
  20. package/dist/{agent/ui/ElAgentHeader.vue.d.ts → bot/ui/ElBotHeader.vue.d.ts} +2 -2
  21. package/dist/{agent/ui/ElAgentModeSidebar.vue.d.ts → bot/ui/ElBotModeSidebar.vue.d.ts} +2 -2
  22. package/dist/{agent/ui/ElAgentSidebar.vue.d.ts → bot/ui/ElBotSidebar.vue.d.ts} +2 -2
  23. package/dist/bot/ui/ElCreateBot.vue.d.ts +12 -0
  24. package/dist/{agent → bot}/ui/ElModeHeader.vue.d.ts +2 -2
  25. package/dist/{agent → bot}/ui/ElProvisioningStatus.vue.d.ts +1 -1
  26. package/dist/{agent → bot}/ui/VoiceMode.vue.d.ts +4 -4
  27. package/dist/{agent → bot}/utils.d.ts +5 -5
  28. package/dist/{agent → bot}/voice/provider.d.ts +2 -2
  29. package/dist/{agent → bot}/voice/providers/livekit/provider.d.ts +8 -7
  30. package/dist/{agent → bot}/voice/voice-session-client.d.ts +2 -1
  31. package/dist/{agent → bot}/work-journal.d.ts +1 -1
  32. package/dist/{agent.js → bot.js} +89 -84
  33. package/dist/bot.js.map +1 -0
  34. package/dist/clients/BillingClient.d.ts +1 -1
  35. package/dist/clients/BotClient.d.ts +26 -0
  36. package/dist/clients/ChatClient.d.ts +6 -5
  37. package/dist/clients/ComputerClient.d.ts +16 -0
  38. package/dist/clients/UserClient.d.ts +4 -7
  39. package/dist/clients/types.d.ts +7 -2
  40. package/dist/contract/build.d.ts +1 -2
  41. package/dist/index.d.ts +3 -2
  42. package/dist/provider.js +1 -1
  43. package/dist/provider.js.map +1 -1
  44. package/dist/provider2.js +28 -36
  45. package/dist/provider2.js.map +1 -1
  46. package/dist/sdk.css +1 -1
  47. package/dist/sdk.js +4 -4
  48. package/dist/sdkClient.d.ts +33 -376
  49. package/dist/sdkClient.js +168 -170
  50. package/dist/sdkClient.js.map +1 -1
  51. package/dist/useWidgetState.js +9 -9
  52. package/dist/useWidgetState.js.map +1 -1
  53. package/dist/widget/PLWidget.d.ts +6 -6
  54. package/dist/widget/composables/useWidgetState.d.ts +3 -402
  55. package/dist/widget/index.d.ts +2 -2
  56. package/dist/widget/mode.d.ts +2 -2
  57. package/dist/widget/ui/{AgentWidgetInline.vue.d.ts → BotWidgetInline.vue.d.ts} +2 -2
  58. package/dist/widget/ui/{AgentWidgetModal.vue.d.ts → BotWidgetModal.vue.d.ts} +2 -2
  59. package/dist/widget/ui/{AgentWidgetPopup.vue.d.ts → BotWidgetPopup.vue.d.ts} +4 -4
  60. package/dist/widget.js +206 -206
  61. package/dist/widget.js.map +1 -1
  62. package/package.json +5 -5
  63. package/dist/AgentProvider.js +0 -764
  64. package/dist/AgentProvider.js.map +0 -1
  65. package/dist/AgentWidgetInline.js.map +0 -1
  66. package/dist/AgentWidgetModal.js.map +0 -1
  67. package/dist/AgentWrap.js.map +0 -1
  68. package/dist/agent/index.d.ts +0 -14
  69. package/dist/agent/ui/ElCreateAgent.vue.d.ts +0 -277
  70. package/dist/agent.js.map +0 -1
  71. package/dist/clients/AgentClient.d.ts +0 -48
  72. /package/dist/{agent → bot}/VoiceRecorderController.d.ts +0 -0
  73. /package/dist/{agent/ui/AgentInputEmail.vue.d.ts → bot/ui/BotInputEmail.vue.d.ts} +0 -0
  74. /package/dist/{agent/ui/AgentInputOneTimeCode.vue.d.ts → bot/ui/BotInputOneTimeCode.vue.d.ts} +0 -0
  75. /package/dist/{agent/ui/AgentSidebarClose.vue.d.ts → bot/ui/BotSidebarClose.vue.d.ts} +0 -0
  76. /package/dist/{agent/ui/AgentToolActivityGroup.vue.d.ts → bot/ui/BotToolActivityGroup.vue.d.ts} +0 -0
  77. /package/dist/{agent/ui/AgentWidget.vue.d.ts → bot/ui/BotWidget.vue.d.ts} +0 -0
  78. /package/dist/{agent → bot}/ui/ChatCardBlock.vue.d.ts +0 -0
  79. /package/dist/{agent → bot}/ui/ChatRichText.vue.d.ts +0 -0
  80. /package/dist/{agent → bot}/ui/ChatScroller.vue.d.ts +0 -0
  81. /package/dist/{agent → bot}/ui/ChatVisualBlock.vue.d.ts +0 -0
  82. /package/dist/{agent → bot}/ui/ElAuthGate.vue.d.ts +0 -0
  83. /package/dist/{agent → bot}/ui/ElAuthPanel.vue.d.ts +0 -0
  84. /package/dist/{agent/ui/ElAgentButton.vue.d.ts → bot/ui/ElBotButton.vue.d.ts} +0 -0
  85. /package/dist/{agent → bot}/ui/ElSidebar.vue.d.ts +0 -0
  86. /package/dist/{agent → bot}/ui/VoiceHistogramController.d.ts +0 -0
  87. /package/dist/{agent → bot}/ui/chat-diagram-layout.d.ts +0 -0
  88. /package/dist/{agent → bot}/ui/chat-visual-format.d.ts +0 -0
  89. /package/dist/{agent → bot}/ui/voice-mode-presentation.d.ts +0 -0
  90. /package/dist/{agent → bot}/voice/voice-error-copy.d.ts +0 -0
  91. /package/dist/{agent → bot}/voice/voice-work-state.d.ts +0 -0
  92. /package/dist/widget/ui/{AgentWidgetOnboard.vue.d.ts → BotWidgetOnboard.vue.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { AgentConfig, ApiResponse, EnrichedUser, LogHelper } from '@pagelines/core';
1
+ import { Bot, BotData, ComputerData, ApiResponse, EnrichedUser, LogHelper } from '@pagelines/core';
2
2
  import { ComputedRef, Ref } from 'vue';
3
3
  import { SDKStorage } from '../sdkStorage';
4
4
  export interface SDKContext {
@@ -9,7 +9,12 @@ export interface SDKContext {
9
9
  token: Ref<string | null>;
10
10
  loading: Ref<boolean>;
11
11
  error: Ref<string | null>;
12
- currentAgent: ComputedRef<AgentConfig | undefined>;
12
+ currentBot: ComputedRef<Bot | undefined>;
13
+ hydrateRoster: (roster: {
14
+ computers: ComputerData[];
15
+ bots: BotData[];
16
+ }) => Bot[];
17
+ clearRoster: () => void;
13
18
  storage: SDKStorage;
14
19
  sessionId: string;
15
20
  logger: LogHelper;
@@ -25,8 +25,7 @@ export interface WireContract {
25
25
  *
26
26
  * Schema discovery walks every export of `@pagelines/core`, picks values
27
27
  * that are Zod schemas, and derives the contract name from the export
28
- * name (`zAgentState` → `AgentState`, `EnrichedAgentSchema` →
29
- * `EnrichedAgent`). `*Wire` namespace exports get the same treatment for
28
+ * name (`zComputer` → `Computer`). `*Wire` namespace exports get the same treatment for
30
29
  * their immediate children. Anything else is ignored — types, constants
31
30
  * like `ERROR_CODES`, helper functions all skip naturally.
32
31
  */
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import { PageLinesSDK } from './sdkClient';
2
2
  export { PageLinesSDK };
3
3
  export type { PageLinesSDKSettings } from './sdkClient';
4
- export { AgentClient } from './clients/AgentClient';
4
+ export { BotClient } from './clients/BotClient';
5
+ export { ComputerClient } from './clients/ComputerClient';
5
6
  export { AuthClient } from './clients/AuthClient';
6
7
  export { BillingClient } from './clients/BillingClient';
7
8
  export { ChatClient } from './clients/ChatClient';
8
9
  export { UserClient } from './clients/UserClient';
9
10
  export type { SDKContext } from './clients/types';
10
11
  export { MediaSchema } from '@pagelines/core';
11
- export type { Agent, User, EnrichedUser, MediaObject, ApiResponse, } from '@pagelines/core';
12
+ export type { Bot, User, EnrichedUser, MediaObject, ApiResponse, } from '@pagelines/core';
12
13
  export { SOCIAL_PLATFORMS } from './constants/socialPlatforms';
13
14
  export type { SocialPlatform } from './constants/socialPlatforms';
package/dist/provider.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime.js";
2
- //#region agent/voice/provider.ts
2
+ //#region bot/voice/provider.ts
3
3
  function isVoiceAudible(e) {
4
4
  return e >= .08;
5
5
  }
@@ -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\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/** Keep the realtime SDK out of the initial chat bundle. */\nexport const createVoiceProviderClient: CreateVoiceProviderClient = async (mint) => {\n const { LiveKitVoiceProvider } = await import('./providers/livekit/provider')\n return new LiveKitVoiceProvider(mint)\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,IAAM,EAAE,4BAAyB,MAAM,OAAO;CAC9C,OAAO,IAAI,EAAqB,CAAI;AACtC;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"}
1
+ {"version":3,"file":"provider.js","names":[],"sources":["../bot/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 = 'bot' | '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 bot: 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/** Keep the realtime SDK out of the initial chat bundle. */\nexport const createVoiceProviderClient: CreateVoiceProviderClient = async (mint) => {\n const { LiveKitVoiceProvider } = await import('./providers/livekit/provider')\n return new LiveKitVoiceProvider(mint)\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,IAAM,EAAE,4BAAyB,MAAM,OAAO;CAC9C,OAAO,IAAI,EAAqB,CAAI;AACtC;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"}
package/dist/provider2.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime.js";
2
- import { s as e } from "./sdkClient.js";
2
+ import { c as e } from "./sdkClient.js";
3
3
  import { r 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) {
@@ -18330,60 +18330,51 @@ var JWSSignatureVerificationFailed = class extends JOSEError {
18330
18330
  };
18331
18331
  _defineProperty(JWSSignatureVerificationFailed, "code", "ERR_JWS_SIGNATURE_VERIFICATION_FAILED");
18332
18332
  //#endregion
18333
- //#region agent/voice/providers/livekit/provider.ts
18334
- var $a = 1e4, eo = "lk.agent.state", LiveKitVoiceProvider = class {
18333
+ //#region bot/voice/providers/livekit/provider.ts
18334
+ var $a = 1e4, eo = "lk.bot.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), 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;
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, "botActiveSpeaker", !1), e(this, "botStateSpeaking", !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
- if (!t.isAgent) return;
18342
+ if (!t.isBot) return;
18343
18343
  let n = t.attributes[eo];
18344
- this.handlers?.onThinkingChange?.(n === "thinking"), this.agentStateSpeaking = n === "speaking", this.publishSpeaking();
18344
+ this.handlers?.onThinkingChange?.(n === "thinking"), this.botStateSpeaking = n === "speaking", this.publishSpeaking();
18345
18345
  }), this.room.on(P.ActiveSpeakersChanged, (e) => {
18346
- this.userSpeaking = e.some((e) => e.isLocal), this.agentActiveSpeaker = e.some((e) => e.isAgent), this.publishSpeaking();
18346
+ this.userSpeaking = e.some((e) => e.isLocal), this.botActiveSpeaker = e.some((e) => e.isBot), this.publishSpeaking();
18347
18347
  }), this.room.on(P.Disconnected, (e) => {
18348
18348
  this.closing || this.handlers?.onDisconnected(disconnectCause(e));
18349
18349
  });
18350
- let t = "VOICE_CONNECT_FAILED", n;
18350
+ let t = "VOICE_CONNECT_FAILED";
18351
18351
  try {
18352
- if (await this.room.connect(this.mint.url, this.mint.token), this.closing) return;
18353
- if (t = "VOICE_MIC_UNAVAILABLE", n = await this.room.localParticipant.setMicrophoneEnabled(!0, {
18354
- echoCancellation: !0,
18355
- noiseSuppression: !0
18356
- }), this.closing) {
18357
- await this.room.localParticipant.setMicrophoneEnabled(!1).catch(() => {});
18358
- return;
18359
- }
18360
- if (t = "VOICE_AGENT_UNAVAILABLE", await this.waitForAgentReady(), this.closing) {
18361
- await this.room.localParticipant.setMicrophoneEnabled(!1).catch(() => {});
18362
- return;
18363
- }
18352
+ if (await this.room.connect(this.mint.url, this.mint.token), this.closing || (t = "VOICE_MIC_UNAVAILABLE", await this.setMuted(!1), this.closing) || (t = "VOICE_BOT_UNAVAILABLE", await this.waitForBotReady(), this.closing)) return;
18364
18353
  t = "VOICE_PLAYBACK_UNAVAILABLE", await this.room.startAudio();
18365
18354
  } catch (e) {
18366
18355
  let n = e instanceof Error ? e : /* @__PURE__ */ Error("Could not open the voice connection.");
18367
18356
  throw "code" in n || Object.assign(n, { code: t }), n;
18368
18357
  }
18369
- this.watchMicLevel(n);
18358
+ this.closing || this.watchMicLevel();
18370
18359
  }
18371
18360
  async disconnect() {
18372
18361
  this.closing = !0, this.cancelReadyWait?.(), this.cancelReadyWait = void 0;
18373
- for (let e of this.analysers) await e.cleanup().catch(() => {});
18374
- this.analysers = [], this.levelSources = [];
18375
- for (let e of this.attachedElements) e.remove();
18376
- this.attachedElements = [], await this.room.disconnect();
18362
+ for (let e of this.attachedElements) e.muted = !0, e.pause(), e.remove();
18363
+ this.attachedElements = [], this.room.localParticipant.getTrackPublication(z.Source.Microphone)?.track?.stop();
18364
+ let e = this.analysers.splice(0);
18365
+ this.levelSources = [], await Promise.allSettled([this.room.disconnect(), ...e.map((e) => e.cleanup())]);
18377
18366
  }
18378
18367
  async setMuted(e) {
18368
+ if (this.closing) return;
18379
18369
  if (e) {
18380
18370
  await this.room.localParticipant.setMicrophoneEnabled(!1);
18381
18371
  return;
18382
18372
  }
18383
- await this.room.localParticipant.setMicrophoneEnabled(!0, {
18373
+ let t = await this.room.localParticipant.setMicrophoneEnabled(!0, {
18384
18374
  echoCancellation: !0,
18385
18375
  noiseSuppression: !0
18386
18376
  });
18377
+ this.closing && t?.track?.stop();
18387
18378
  }
18388
18379
  sampleLevel(e) {
18389
18380
  let t, n = e && this.levelSources.some((t) => t.source === e) ? this.levelSources.filter((t) => t.source === e) : this.levelSources;
@@ -18402,14 +18393,14 @@ var $a = 1e4, eo = "lk.agent.state", LiveKitVoiceProvider = class {
18402
18393
  publishSpeaking() {
18403
18394
  let e = {
18404
18395
  user: this.userSpeaking,
18405
- agent: this.agentActiveSpeaker || this.agentStateSpeaking
18396
+ bot: this.botActiveSpeaker || this.botStateSpeaking
18406
18397
  };
18407
- this.lastSpeaking?.user === e.user && this.lastSpeaking?.agent === e.agent || (this.lastSpeaking = e, this.handlers?.onSpeakingChange?.(e));
18398
+ this.lastSpeaking?.user === e.user && this.lastSpeaking?.bot === e.bot || (this.lastSpeaking = e, this.handlers?.onSpeakingChange?.(e));
18408
18399
  }
18409
- async waitForAgentReady() {
18400
+ async waitForBotReady() {
18410
18401
  let ready = (e) => {
18411
18402
  let t = e.attributes[eo];
18412
- return e.isAgent && (t === "listening" || t === "thinking" || t === "speaking");
18403
+ return e.isBot && (t === "listening" || t === "thinking" || t === "speaking");
18413
18404
  };
18414
18405
  [...this.room.remoteParticipants.values()].some(ready) || await new Promise((e, t) => {
18415
18406
  let n = !1, finish = (i) => {
@@ -18418,7 +18409,7 @@ var $a = 1e4, eo = "lk.agent.state", LiveKitVoiceProvider = class {
18418
18409
  ready(e) && finish();
18419
18410
  }, onAttributes = (e, t) => {
18420
18411
  ready(t) && finish();
18421
- }, r = setTimeout(() => finish(Object.assign(/* @__PURE__ */ Error("The voice assistant did not become ready."), { code: "VOICE_AGENT_UNAVAILABLE" })), $a);
18412
+ }, r = setTimeout(() => finish(Object.assign(/* @__PURE__ */ Error("The voice assistant did not become ready."), { code: "VOICE_BOT_UNAVAILABLE" })), $a);
18422
18413
  this.room.on(P.ParticipantConnected, onParticipant), this.room.on(P.ParticipantAttributesChanged, onAttributes), this.cancelReadyWait = () => finish();
18423
18414
  });
18424
18415
  }
@@ -18441,14 +18432,15 @@ var $a = 1e4, eo = "lk.agent.state", LiveKitVoiceProvider = class {
18441
18432
  return;
18442
18433
  }
18443
18434
  }
18444
- watchMicLevel(e) {
18445
- let t = e ?? this.room.localParticipant.getTrackPublication?.(z.Source.Microphone), n = t?.track ? this.analyserFor(t.track) : void 0;
18446
- n && (this.analysers.push(n), this.levelSources.push({
18435
+ watchMicLevel() {
18436
+ let e = this.room.localParticipant.getTrackPublication(z.Source.Microphone), t = e?.track ? this.analyserFor(e.track) : void 0;
18437
+ t && (this.analysers.push(t), this.levelSources.push({
18447
18438
  source: "mic",
18448
- analyser: n
18439
+ analyser: t
18449
18440
  }));
18450
18441
  }
18451
18442
  attachRemoteAudio(e) {
18443
+ if (this.closing) return;
18452
18444
  try {
18453
18445
  let t = e.attach?.();
18454
18446
  t && typeof document < "u" && (t.style.display = "none", document.body.appendChild(t), this.attachedElements.push(t));
@@ -18461,7 +18453,7 @@ var $a = 1e4, eo = "lk.agent.state", LiveKitVoiceProvider = class {
18461
18453
  }
18462
18454
  };
18463
18455
  function disconnectCause(e) {
18464
- return e === S.ROOM_DELETED || e === S.PARTICIPANT_REMOVED ? "agent" : e === void 0 || e === S.UNKNOWN_REASON ? "unknown" : "network";
18456
+ return e === S.ROOM_DELETED || e === S.PARTICIPANT_REMOVED ? "bot" : e === void 0 || e === S.UNKNOWN_REASON ? "unknown" : "network";
18465
18457
  }
18466
18458
  //#endregion
18467
18459
  export { LiveKitVoiceProvider };