orb-ui 0.7.0 → 0.8.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.
Files changed (37) hide show
  1. package/README.md +81 -25
  2. package/dist/adapters/audio-level.d.ts +57 -20
  3. package/dist/adapters/elevenlabs/index.d.ts +13 -2
  4. package/dist/adapters/gemini-live/index.d.ts +9 -5
  5. package/dist/adapters/index.d.ts +3 -2
  6. package/dist/adapters/livekit/browser.d.ts +9 -5
  7. package/dist/adapters/livekit/index.d.ts +9 -5
  8. package/dist/adapters/openai-realtime/index.d.ts +9 -5
  9. package/dist/adapters/pipecat/index.d.ts +9 -5
  10. package/dist/adapters/types.d.ts +0 -5
  11. package/dist/adapters/vapi/index.d.ts +29 -3
  12. package/dist/adapters/volume-presets.d.ts +35 -0
  13. package/dist/adapters.cjs +1 -1
  14. package/dist/adapters.js +405 -457
  15. package/dist/components/Orb/Orb.d.ts +1 -1
  16. package/dist/components/Orb/Orb.types.d.ts +87 -14
  17. package/dist/components/Orb/OrbThemeProvider.d.ts +16 -0
  18. package/dist/components/Orb/index.d.ts +6 -1
  19. package/dist/components/Orb/signals.d.ts +1 -1
  20. package/dist/index.d.ts +2 -2
  21. package/dist/livekit-7Re8E7By.js +394 -0
  22. package/dist/livekit-C36Kmz6s.cjs +1 -0
  23. package/dist/livekit-adapter.cjs +1 -1
  24. package/dist/livekit-adapter.js +6 -4
  25. package/dist/orb-ui.cjs +7 -7
  26. package/dist/orb-ui.js +1343 -512
  27. package/dist/themes/bars/BarsTheme.d.ts +8 -4
  28. package/dist/themes/circle/CircleTheme.d.ts +8 -4
  29. package/dist/themes/cloud/CloudTheme.d.ts +8 -4
  30. package/dist/themes/config.d.ts +151 -0
  31. package/dist/themes/css-variables.d.ts +5 -0
  32. package/dist/themes/debug/DebugTheme.d.ts +11 -6
  33. package/dist/themes/radial/RadialTheme.d.ts +8 -2
  34. package/dist/themes/slots.d.ts +4 -0
  35. package/package.json +4 -3
  36. package/dist/livekit-CukEeYFK.js +0 -316
  37. package/dist/livekit-Dt-QZ6Gs.cjs +0 -1
@@ -1,14 +1,18 @@
1
- import { CSSProperties } from 'react';
2
- import { OrbHtmlAttributes, OrbState } from '../../components/Orb/Orb.types.js';
1
+ import { OrbHtmlAttributes, OrbSlotProps, OrbState, OrbStyle } from '../../components/Orb/Orb.types.js';
2
+ import { ResolvedBarsTheme } from '../config.js';
3
3
  interface BarsThemeProps extends OrbHtmlAttributes {
4
4
  state: OrbState;
5
5
  volume: number;
6
6
  size: number;
7
+ declaredSize: number;
7
8
  className?: string;
8
- style?: CSSProperties;
9
+ style?: OrbStyle;
10
+ slotProps?: OrbSlotProps;
11
+ rootRef?: (element: HTMLElement | null) => void;
9
12
  disabled?: boolean;
10
13
  interactive?: boolean;
11
14
  onClick?: () => void;
15
+ config: ResolvedBarsTheme;
12
16
  }
13
- export declare function BarsTheme({ state, volume, size, className, style, disabled, interactive, onClick, ...controlProps }: BarsThemeProps): import("react/jsx-runtime").JSX.Element;
17
+ export declare function BarsTheme({ state, volume, size, declaredSize, className, style, slotProps, rootRef, disabled, interactive, onClick, config, ...controlProps }: BarsThemeProps): import("react/jsx-runtime").JSX.Element;
14
18
  export {};
@@ -1,14 +1,18 @@
1
- import { CSSProperties } from 'react';
2
- import { OrbHtmlAttributes, OrbState } from '../../components/Orb/Orb.types.js';
1
+ import { OrbHtmlAttributes, OrbSlotProps, OrbState, OrbStyle } from '../../components/Orb/Orb.types.js';
2
+ import { ResolvedCircleTheme } from '../config.js';
3
3
  interface CircleThemeProps extends OrbHtmlAttributes {
4
4
  state: OrbState;
5
5
  volume: number;
6
6
  size: number;
7
+ declaredSize: number;
7
8
  className?: string;
8
- style?: CSSProperties;
9
+ style?: OrbStyle;
10
+ slotProps?: OrbSlotProps;
11
+ rootRef?: (element: HTMLElement | null) => void;
9
12
  disabled?: boolean;
10
13
  interactive?: boolean;
11
14
  onClick?: () => void;
15
+ config: ResolvedCircleTheme;
12
16
  }
13
- export declare function CircleTheme({ state, volume, size, className, style, disabled, interactive, onClick, ...controlProps }: CircleThemeProps): import("react/jsx-runtime").JSX.Element;
17
+ export declare function CircleTheme({ state, volume, size, declaredSize, className, style, slotProps, rootRef, disabled, interactive, onClick, config, ...controlProps }: CircleThemeProps): import("react/jsx-runtime").JSX.Element;
14
18
  export {};
@@ -1,14 +1,18 @@
1
- import { CSSProperties } from 'react';
2
- import { OrbHtmlAttributes, OrbState } from '../../components/Orb/Orb.types.js';
1
+ import { OrbHtmlAttributes, OrbSlotProps, OrbState, OrbStyle } from '../../components/Orb/Orb.types.js';
2
+ import { ResolvedCloudTheme } from '../config.js';
3
3
  interface CloudThemeProps extends OrbHtmlAttributes {
4
4
  state: OrbState;
5
5
  volume: number;
6
6
  size: number;
7
+ declaredSize: number;
7
8
  className?: string;
8
- style?: CSSProperties;
9
+ style?: OrbStyle;
10
+ slotProps?: OrbSlotProps;
11
+ rootRef?: (element: HTMLElement | null) => void;
9
12
  disabled?: boolean;
10
13
  interactive?: boolean;
11
14
  onClick?: () => void;
15
+ config: ResolvedCloudTheme;
12
16
  }
13
- export declare function CloudTheme({ state, volume, size, className, style, disabled, interactive, onClick, ...controlProps }: CloudThemeProps): import("react/jsx-runtime").JSX.Element;
17
+ export declare function CloudTheme({ state, volume, size, declaredSize, className, style, slotProps, rootRef, disabled, interactive, onClick, config, ...controlProps }: CloudThemeProps): import("react/jsx-runtime").JSX.Element;
14
18
  export {};
@@ -0,0 +1,151 @@
1
+ import { OrbState } from '../components/Orb/Orb.types.js';
2
+ export type OrbThemeName = 'debug' | 'circle' | 'bars' | 'cloud' | 'radial';
3
+ export type OrbThemePreset = 'balanced' | 'calm' | 'expressive';
4
+ export type OrbStateColors = Record<OrbState, string>;
5
+ interface ThemeConfig<Name extends OrbThemeName, Appearance, Geometry, Motion> {
6
+ name: Name;
7
+ /** Starts from a complete preset before low-level overrides are applied. */
8
+ preset?: OrbThemePreset;
9
+ appearance?: Partial<Appearance>;
10
+ geometry?: Partial<Geometry>;
11
+ motion?: Partial<Motion>;
12
+ }
13
+ export interface CircleAppearance {
14
+ colors: Partial<OrbStateColors>;
15
+ listeningGlow: number;
16
+ speakingGlow: number;
17
+ }
18
+ export interface CircleGeometry {
19
+ diameterRatio: number;
20
+ listeningMinScale: number;
21
+ listeningMaxScale: number;
22
+ speakingMinScale: number;
23
+ speakingMaxScale: number;
24
+ }
25
+ export interface CircleMotion {
26
+ responseExponent: number;
27
+ activityRiseMs: number;
28
+ activityFallMs: number;
29
+ stateTransitionMs: number;
30
+ idlePulseMs: number;
31
+ processingPulseMs: number;
32
+ }
33
+ export type CircleThemeConfig = ThemeConfig<'circle', CircleAppearance, CircleGeometry, CircleMotion>;
34
+ export interface BarsAppearance {
35
+ colors: Partial<OrbStateColors>;
36
+ }
37
+ export interface BarsGeometry {
38
+ barWidthRatio: number;
39
+ gapRatio: number;
40
+ minHeightRatio: number;
41
+ maxHeightRatio: number;
42
+ borderRadiusRatio: number;
43
+ }
44
+ export interface BarsMotion {
45
+ responseExponent: number;
46
+ activityRiseMs: number;
47
+ activityFallMs: number;
48
+ stateTransitionMs: number;
49
+ waveFrequency: number;
50
+ listeningTempo: number;
51
+ speakingTempo: number;
52
+ loadingTempo: number;
53
+ }
54
+ export type BarsThemeConfig = ThemeConfig<'bars', BarsAppearance, BarsGeometry, BarsMotion>;
55
+ export interface CloudAppearance {
56
+ deepColor: string;
57
+ upperColor: string;
58
+ lowerColor: string;
59
+ highlightColor: string;
60
+ launchColor: string;
61
+ spinnerColor: string;
62
+ }
63
+ export interface CloudGeometry {
64
+ diameterRatio: number;
65
+ listeningMinScale: number;
66
+ speakingMaxScale: number;
67
+ idleDotScale: number;
68
+ }
69
+ export interface CloudMotion {
70
+ responseExponent: number;
71
+ activityRiseMs: number;
72
+ activityFallMs: number;
73
+ stateTransitionMs: number;
74
+ idleSpeed: number;
75
+ listeningBaseSpeed: number;
76
+ listeningSpeedRange: number;
77
+ speakingBaseSpeed: number;
78
+ speakingSpeedRange: number;
79
+ entranceHoldMs: number;
80
+ entranceGrowMs: number;
81
+ entranceSettleMs: number;
82
+ }
83
+ export type CloudThemeConfig = ThemeConfig<'cloud', CloudAppearance, CloudGeometry, CloudMotion>;
84
+ export interface RadialAppearance {
85
+ deepColor: string;
86
+ cobaltColor: string;
87
+ aquaColor: string;
88
+ paleColor: string;
89
+ membraneColor: string;
90
+ seamColor: string;
91
+ idleControlColor: string;
92
+ activeControlColor: string;
93
+ connectingControlColor: string;
94
+ }
95
+ export interface RadialGeometry {
96
+ diameterRatio: number;
97
+ controlRatio: number;
98
+ }
99
+ export interface RadialMotion {
100
+ responseExponent: number;
101
+ activityRiseMs: number;
102
+ activityFallMs: number;
103
+ stateTransitionMs: number;
104
+ idleSpeed: number;
105
+ listeningBaseSpeed: number;
106
+ listeningSpeedRange: number;
107
+ speakingBaseSpeed: number;
108
+ speakingSpeedRange: number;
109
+ rotationAmount: number;
110
+ }
111
+ export type RadialThemeConfig = ThemeConfig<'radial', RadialAppearance, RadialGeometry, RadialMotion>;
112
+ export interface DebugAppearance {
113
+ colors: Partial<OrbStateColors>;
114
+ backgroundColor: string;
115
+ textColor: string;
116
+ borderColor: string;
117
+ }
118
+ export interface DebugGeometry {
119
+ borderRadius: number;
120
+ padding: number;
121
+ }
122
+ export interface DebugMotion {
123
+ responseExponent: number;
124
+ }
125
+ export type DebugThemeConfig = ThemeConfig<'debug', DebugAppearance, DebugGeometry, DebugMotion>;
126
+ export type OrbThemeConfig = DebugThemeConfig | CircleThemeConfig | BarsThemeConfig | CloudThemeConfig | RadialThemeConfig;
127
+ export type OrbTheme = OrbThemeName | OrbThemeConfig;
128
+ /** Preserve literal theme inference when defining a reusable application theme. */
129
+ export declare function defineOrbTheme<const Theme extends OrbThemeConfig>(theme: Theme): Theme;
130
+ export declare function mergeOrbThemes(base: OrbTheme | undefined, override: OrbTheme | undefined): OrbTheme;
131
+ interface ResolvedTheme<Name extends OrbThemeName, Appearance, Geometry, Motion> {
132
+ name: Name;
133
+ preset: OrbThemePreset;
134
+ appearance: Appearance;
135
+ geometry: Geometry;
136
+ motion: Motion;
137
+ }
138
+ export type ResolvedCircleTheme = ResolvedTheme<'circle', Omit<CircleAppearance, 'colors'> & {
139
+ colors: OrbStateColors;
140
+ }, CircleGeometry, CircleMotion>;
141
+ export type ResolvedBarsTheme = ResolvedTheme<'bars', {
142
+ colors: OrbStateColors;
143
+ }, BarsGeometry, BarsMotion>;
144
+ export type ResolvedCloudTheme = ResolvedTheme<'cloud', CloudAppearance, CloudGeometry, CloudMotion>;
145
+ export type ResolvedRadialTheme = ResolvedTheme<'radial', RadialAppearance, RadialGeometry, RadialMotion>;
146
+ export type ResolvedDebugTheme = ResolvedTheme<'debug', Omit<DebugAppearance, 'colors'> & {
147
+ colors: OrbStateColors;
148
+ }, DebugGeometry, DebugMotion>;
149
+ export type ResolvedOrbTheme = ResolvedDebugTheme | ResolvedCircleTheme | ResolvedBarsTheme | ResolvedCloudTheme | ResolvedRadialTheme;
150
+ export declare function resolveOrbTheme(theme: OrbTheme): ResolvedOrbTheme;
151
+ export {};
@@ -0,0 +1,5 @@
1
+ import { OrbThemeName, ResolvedOrbTheme } from './config.js';
2
+ export type OrbThemeCssSection = 'appearance' | 'geometry' | 'motion';
3
+ export declare function orbThemeCssVariable(theme: OrbThemeName, section: OrbThemeCssSection, property: string, nestedProperty?: string): string;
4
+ /** Resolve external `--orb-ui-*` overrides from a mounted built-in theme root. */
5
+ export declare function readOrbThemeCssVariables(element: HTMLElement, base: ResolvedOrbTheme): ResolvedOrbTheme;
@@ -1,15 +1,20 @@
1
- import { CSSProperties, HTMLAttributes } from 'react';
2
- import { OrbState } from '../../components/Orb/Orb.types.js';
1
+ import { HTMLAttributes } from 'react';
2
+ import { OrbSlotProps, OrbState, OrbStyle } from '../../components/Orb/Orb.types.js';
3
+ import { ResolvedDebugTheme } from '../config.js';
3
4
  type DebugThemeRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'className' | 'style'>;
4
5
  interface DebugThemeProps extends DebugThemeRootProps {
5
6
  state: OrbState;
6
7
  volume: number;
7
8
  size: number;
9
+ declaredSize: number;
8
10
  className?: string;
9
- style?: CSSProperties;
11
+ style?: OrbStyle;
12
+ slotProps?: OrbSlotProps;
13
+ rootRef?: (element: HTMLElement | null) => void;
10
14
  disabled?: boolean;
11
- onStart?: () => void;
12
- onStop?: () => void;
15
+ onStart?: () => void | Promise<void>;
16
+ onStop?: () => void | Promise<void>;
17
+ config: ResolvedDebugTheme;
13
18
  }
14
- export declare function DebugTheme({ state, volume, size, className, style, disabled, onStart, onStop, ...rootProps }: DebugThemeProps): import("react/jsx-runtime").JSX.Element;
19
+ export declare function DebugTheme({ state, volume, size, declaredSize, className, style, slotProps, rootRef, disabled, onStart, onStop, config, ...rootProps }: DebugThemeProps): import("react/jsx-runtime").JSX.Element;
15
20
  export {};
@@ -1,13 +1,19 @@
1
- import { OrbHtmlAttributes, OrbState, OrbStyle } from '../../components/Orb/Orb.types.js';
1
+ import { OrbHtmlAttributes, OrbSlotProps, OrbState, OrbStyle, OrbThemeComponents } from '../../components/Orb/Orb.types.js';
2
+ import { ResolvedRadialTheme } from '../config.js';
2
3
  interface RadialThemeProps extends OrbHtmlAttributes {
3
4
  state: OrbState;
4
5
  volume: number;
5
6
  size: number;
7
+ declaredSize: number;
6
8
  className?: string;
7
9
  style?: OrbStyle;
10
+ slotProps?: OrbSlotProps;
11
+ rootRef?: (element: HTMLElement | null) => void;
12
+ components?: OrbThemeComponents;
8
13
  disabled?: boolean;
9
14
  interactive?: boolean;
10
15
  onClick?: () => void;
16
+ config: ResolvedRadialTheme;
11
17
  }
12
- export declare function RadialTheme({ state, volume, size, className, style, disabled, interactive, onClick, ...controlProps }: RadialThemeProps): import("react/jsx-runtime").JSX.Element;
18
+ export declare function RadialTheme({ state, volume, size, declaredSize, className, style, slotProps, rootRef, components, disabled, interactive, onClick, config, ...controlProps }: RadialThemeProps): import("react/jsx-runtime").JSX.Element;
13
19
  export {};
@@ -0,0 +1,4 @@
1
+ import { OrbSlotAttributes, OrbSlotName, OrbSlotProps } from '../components/Orb/Orb.types.js';
2
+ export declare function joinClassNames(...values: Array<string | undefined>): string | undefined;
3
+ export declare function mergeOrbSlotProps(base: OrbSlotProps | undefined, override: OrbSlotProps | undefined): OrbSlotProps | undefined;
4
+ export declare function resolveOrbSlot(slotProps: OrbSlotProps | undefined, name: OrbSlotName, ...classNames: Array<string | undefined>): OrbSlotAttributes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orb-ui",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "React voice agent UI components with audio-reactive adapters for Vapi, ElevenLabs, LiveKit, Pipecat, OpenAI Realtime, Gemini Live, and custom voice AI apps.",
5
5
  "type": "module",
6
6
  "main": "./dist/orb-ui.cjs",
@@ -46,7 +46,7 @@
46
46
  "@playwright/test": "1.61.1",
47
47
  "@types/react": "^18.3.29",
48
48
  "@types/react-dom": "^18.3.7",
49
- "@vapi-ai/web": "2.5.2",
49
+ "@vapi-ai/web": "2.7.0",
50
50
  "@vitejs/plugin-react": "^6.0.2",
51
51
  "eslint": "^10.4.0",
52
52
  "globals": "^17.6.0",
@@ -88,7 +88,7 @@
88
88
  "homepage": "https://orb-ui.com",
89
89
  "repository": {
90
90
  "type": "git",
91
- "url": "https://github.com/alexanderqchen/orb-ui.git"
91
+ "url": "https://github.com/exprmntl/orb-ui.git"
92
92
  },
93
93
  "typesVersions": {
94
94
  "*": {
@@ -109,6 +109,7 @@
109
109
  "dev:demo": "pnpm --filter orb-ui-demo dev",
110
110
  "format": "prettier . --write",
111
111
  "format:check": "prettier . --check",
112
+ "generate:og": "node scripts/generate-og-image.mjs",
112
113
  "typecheck": "tsc --noEmit",
113
114
  "typecheck:demo": "pnpm --filter orb-ui-demo typecheck",
114
115
  "typecheck:examples": "tsc -p tsconfig.type-tests.json --noEmit",
@@ -1,316 +0,0 @@
1
- //#region src/adapters/types.ts
2
- function e(e) {
3
- let t = Math.min(e / .5, 1);
4
- return t **= 1.3, t;
5
- }
6
- //#endregion
7
- //#region src/adapters/audio-level.ts
8
- var t = {
9
- noiseFloor: 0,
10
- gain: 4,
11
- exponent: .8,
12
- attack: 1,
13
- release: 1
14
- };
15
- function n(e, t, n) {
16
- return Math.min(n, Math.max(t, e));
17
- }
18
- function r(e, t) {
19
- return typeof e == "number" && Number.isFinite(e) ? e : t;
20
- }
21
- function i(e) {
22
- let i = typeof e == "function" ? e() : e;
23
- return {
24
- noiseFloor: n(r(i?.noiseFloor, t.noiseFloor), 0, 1),
25
- gain: Math.max(0, r(i?.gain, t.gain)),
26
- exponent: Math.max(.01, r(i?.exponent, t.exponent)),
27
- attack: n(r(i?.attack, t.attack), 0, 1),
28
- release: n(r(i?.release, t.release), 0, 1)
29
- };
30
- }
31
- function a(e, t, r) {
32
- let a = Number.isFinite(e) ? n(e, 0, 1) : 0, o = i(r), s = n((a <= o.noiseFloor ? 0 : a - o.noiseFloor) * o.gain, 0, 1) ** +o.exponent, c = s > t ? o.attack : o.release;
33
- return {
34
- raw: a,
35
- shaped: s,
36
- normalized: n(t + (s - t) * c, 0, 1)
37
- };
38
- }
39
- function o(e, t, n) {
40
- let r;
41
- try {
42
- if (r = t(), !r) return;
43
- let i = r;
44
- i.state === "suspended" && i.resume().catch(() => void 0);
45
- let a = i.createMediaStreamSource(new MediaStream([e])), o = i.createAnalyser();
46
- o.fftSize = 512, o.smoothingTimeConstant = .25, a.connect(o);
47
- let s = new Float32Array(o.fftSize), c = setInterval(() => {
48
- o.getFloatTimeDomainData(s);
49
- let e = 0;
50
- for (let t of s) e += t * t;
51
- n(Math.sqrt(e / s.length));
52
- }, 33);
53
- return { async stop() {
54
- clearInterval(c);
55
- try {
56
- a.disconnect(), o.disconnect();
57
- } finally {
58
- i.state !== "closed" && await i.close();
59
- }
60
- } };
61
- } catch {
62
- r?.state !== "closed" && r?.close().catch(() => void 0);
63
- return;
64
- }
65
- }
66
- //#endregion
67
- //#region src/adapters/livekit/index.ts
68
- var s = 4, c = {
69
- fftSize: 512,
70
- smoothingTimeConstant: .25,
71
- minDecibels: -85,
72
- maxDecibels: -20
73
- }, l = {
74
- noiseFloor: .015,
75
- gain: 4.6,
76
- exponent: 1.15,
77
- attack: .1,
78
- release: .48
79
- };
80
- function u(e) {
81
- switch (e) {
82
- case "speaking": return "speaking";
83
- case "thinking": return "thinking";
84
- case "listening":
85
- case "idle": return "listening";
86
- case "connecting":
87
- case "pre-connect-buffering":
88
- case "initializing": return "connecting";
89
- case "disconnected": return "idle";
90
- case "failed": return "error";
91
- default: return "idle";
92
- }
93
- }
94
- function d(e) {
95
- return "RoomClass" in e;
96
- }
97
- function f(e) {
98
- return typeof e == "function" ? e() : e;
99
- }
100
- function p(e) {
101
- if (!e) return {};
102
- let t = {}, n = (e, n) => {
103
- n !== void 0 && (t[e] = n);
104
- };
105
- return n("roomName", f(e.roomName)), n("participantName", f(e.participantName)), n("participantIdentity", f(e.participantIdentity)), n("participantMetadata", f(e.participantMetadata)), n("participantAttributes", typeof e.participantAttributes == "function" ? e.participantAttributes() : e.participantAttributes), n("agentName", f(e.agentName)), n("agentMetadata", f(e.agentMetadata)), n("deployment", f(e.deployment)), t;
106
- }
107
- function m(e) {
108
- if (!e.serverUrl || !e.participantToken) throw Error("[orb-ui/livekit] connection details must include serverUrl and participantToken.");
109
- return e;
110
- }
111
- async function h(e) {
112
- let t = p(e.tokenOptions);
113
- return typeof e.getConnectionDetails == "function" ? m(await e.getConnectionDetails(t)) : e.tokenSource ? m(await e.tokenSource.fetch(t)) : m({
114
- serverUrl: e.serverUrl,
115
- participantToken: e.participantToken
116
- });
117
- }
118
- function g(e) {
119
- for (let [, t] of e.remoteParticipants) if (!t.isLocal && (t.kind === s || t.attributes?.["lk.agent.state"] !== void 0)) return t;
120
- return null;
121
- }
122
- function _(e, t, n) {
123
- let r = e.off;
124
- if (r) {
125
- r.call(e, t, n);
126
- return;
127
- }
128
- e.removeListener?.call(e, t, n);
129
- }
130
- function v(e, t, n) {
131
- e.on.call(e, t, n);
132
- }
133
- function y(t) {
134
- let n = d(t), r = t.createAudioAnalyser, i = { current: n ? null : t.room }, o = /* @__PURE__ */ new Set(), f = {
135
- state: "idle",
136
- volume: 0,
137
- inputVolume: 0,
138
- outputVolume: 0
139
- }, p = "idle", m = null, y = null, b = null, x = null, S = null, C = null, w = null, T = 0, E = null;
140
- function D(e) {
141
- f = e, o.forEach((t) => t(e));
142
- }
143
- function O(e) {
144
- D({
145
- ...f,
146
- ...e,
147
- state: e.state ?? f.state
148
- });
149
- }
150
- function k() {
151
- let e = typeof t.outputVolumeCalibration == "function" ? t.outputVolumeCalibration() : t.outputVolumeCalibration;
152
- return {
153
- ...l,
154
- ...e
155
- };
156
- }
157
- function A(e) {
158
- let n = a(e, T, k);
159
- return T = n.normalized, t.onOutputVolumeSample?.(n), n.normalized;
160
- }
161
- function j() {
162
- T = 0, O({
163
- volume: 0,
164
- outputVolume: 0
165
- });
166
- }
167
- function M({ emitZero: e = !0 } = {}) {
168
- S &&= (clearInterval(S), null), x &&= (x.cleanup().catch(() => {}), null), e && O({
169
- volume: 0,
170
- inputVolume: 0
171
- });
172
- }
173
- function N(t) {
174
- if (!(m === t && x)) {
175
- M({ emitZero: !1 }), m = t;
176
- try {
177
- x = r(t, c);
178
- } catch (e) {
179
- console.warn("[orb-ui/livekit] local createAudioAnalyser failed:", e);
180
- return;
181
- }
182
- S = setInterval(() => {
183
- if (!x || p !== "listening") return;
184
- let t = e(x.calculateVolume());
185
- O({
186
- volume: t,
187
- inputVolume: t,
188
- outputVolume: 0
189
- });
190
- }, 33);
191
- }
192
- }
193
- function P({ emitZero: e = !0 } = {}) {
194
- w &&= (clearInterval(w), null), C &&= (C.cleanup().catch(() => {}), null), T = 0, e && O({
195
- volume: 0,
196
- outputVolume: 0
197
- });
198
- }
199
- function F(e) {
200
- P();
201
- try {
202
- C = r(e, c);
203
- } catch (e) {
204
- console.warn("[orb-ui/livekit] remote createAudioAnalyser failed:", e);
205
- return;
206
- }
207
- w = setInterval(() => {
208
- if (!C || p !== "speaking") return;
209
- let e = A(C.calculateVolume());
210
- O({
211
- volume: e,
212
- inputVolume: 0,
213
- outputVolume: e
214
- });
215
- }, 33);
216
- }
217
- function I(e) {
218
- p = e, O({
219
- state: e,
220
- volume: 0,
221
- inputVolume: 0,
222
- outputVolume: 0
223
- }), e === "speaking" && y ? F(y) : e !== "speaking" && P({ emitZero: !1 });
224
- }
225
- function L(e) {
226
- b || typeof document > "u" || (b = e.attach(), b.id = "orb-ui-livekit-agent-audio", document.body.appendChild(b));
227
- }
228
- function R() {
229
- b &&= (b.remove(), null);
230
- }
231
- function z(e) {
232
- y = e, L(e), p === "speaking" && F(e);
233
- }
234
- function B(e) {
235
- N(e);
236
- }
237
- function V(e) {
238
- let t = e.getTrackPublication?.("microphone");
239
- t?.track && B(t.track);
240
- }
241
- function H(e) {
242
- let t = u(e);
243
- t !== p && I(t);
244
- }
245
- function U(e) {
246
- let t = e.attributes?.["lk.agent.state"];
247
- t && H(t);
248
- let n = e.getTrackPublication("microphone");
249
- n?.track && z(n.track);
250
- }
251
- function W(e) {
252
- if (E) return;
253
- let t = (e, t) => {
254
- if (t.isLocal) return;
255
- let n = e["lk.agent.state"];
256
- n && H(n);
257
- }, n = (e, t, n) => {
258
- n.isLocal || !(n.kind === s || n.attributes?.["lk.agent.state"] !== void 0) || e.mediaStreamTrack.kind !== "audio" || z(e);
259
- }, r = (e) => {
260
- y === e && (y = null, R(), P());
261
- }, i = (e) => {
262
- e.source !== "microphone" || !e.track || B(e.track);
263
- }, a = (e) => {
264
- e.source === "microphone" && (m = null, M());
265
- }, o = () => {
266
- m = null, y = null, R(), M({ emitZero: !1 }), P({ emitZero: !1 }), I("idle");
267
- };
268
- if (v(e, "participantAttributesChanged", t), v(e, "trackSubscribed", n), v(e, "trackUnsubscribed", r), v(e, "localTrackPublished", i), v(e, "localTrackUnpublished", a), v(e, "disconnected", o), E = () => {
269
- _(e, "participantAttributesChanged", t), _(e, "trackSubscribed", n), _(e, "trackUnsubscribed", r), _(e, "localTrackPublished", i), _(e, "localTrackUnpublished", a), _(e, "disconnected", o);
270
- }, V(e.localParticipant), e.state === "connected") {
271
- let t = g(e);
272
- t ? U(t) : I("connecting");
273
- } else I("idle");
274
- }
275
- function G() {
276
- E?.(), E = null, m = null, y = null, R(), M({ emitZero: !1 }), P({ emitZero: !1 }), O({
277
- volume: 0,
278
- inputVolume: 0,
279
- outputVolume: 0
280
- });
281
- }
282
- let K = (e) => {
283
- o.add(e), e(f);
284
- let t = i.current;
285
- return t && W(t), () => {
286
- o.delete(e), o.size === 0 && G();
287
- };
288
- };
289
- return n ? {
290
- subscribe: K,
291
- async start() {
292
- if (i.current) return;
293
- let e = t, n = new e.RoomClass();
294
- I("connecting");
295
- try {
296
- let t = await h(e);
297
- if (await n.connect(t.serverUrl, t.participantToken, e.connectOptions), i.current = n, W(n), e.enableMicrophone !== !1) {
298
- let e = (await n.localParticipant.setMicrophoneEnabled(!0))?.track ?? n.localParticipant.getTrackPublication?.("microphone")?.track;
299
- e && B(e);
300
- }
301
- } catch (e) {
302
- throw console.error("[orb-ui/livekit] connect failed:", e), i.current === n && G(), n.disconnect(), i.current = null, I("error"), j(), O({ error: e }), e;
303
- }
304
- },
305
- async stop() {
306
- let e = i.current;
307
- if (!e) {
308
- I("idle");
309
- return;
310
- }
311
- G(), e.disconnect(), i.current = null, I("idle");
312
- }
313
- } : { subscribe: K };
314
- }
315
- //#endregion
316
- export { o as i, t as n, a as r, y as t };
@@ -1 +0,0 @@
1
- function e(e){let t=Math.min(e/.5,1);return t**=1.3,t}var t={noiseFloor:0,gain:4,exponent:.8,attack:1,release:1};function n(e,t,n){return Math.min(n,Math.max(t,e))}function r(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function i(e){let i=typeof e==`function`?e():e;return{noiseFloor:n(r(i?.noiseFloor,t.noiseFloor),0,1),gain:Math.max(0,r(i?.gain,t.gain)),exponent:Math.max(.01,r(i?.exponent,t.exponent)),attack:n(r(i?.attack,t.attack),0,1),release:n(r(i?.release,t.release),0,1)}}function a(e,t,r){let a=Number.isFinite(e)?n(e,0,1):0,o=i(r),s=n((a<=o.noiseFloor?0:a-o.noiseFloor)*o.gain,0,1)**+o.exponent,c=s>t?o.attack:o.release;return{raw:a,shaped:s,normalized:n(t+(s-t)*c,0,1)}}function o(e,t,n){let r;try{if(r=t(),!r)return;let i=r;i.state===`suspended`&&i.resume().catch(()=>void 0);let a=i.createMediaStreamSource(new MediaStream([e])),o=i.createAnalyser();o.fftSize=512,o.smoothingTimeConstant=.25,a.connect(o);let s=new Float32Array(o.fftSize),c=setInterval(()=>{o.getFloatTimeDomainData(s);let e=0;for(let t of s)e+=t*t;n(Math.sqrt(e/s.length))},33);return{async stop(){clearInterval(c);try{a.disconnect(),o.disconnect()}finally{i.state!==`closed`&&await i.close()}}}}catch{r?.state!==`closed`&&r?.close().catch(()=>void 0);return}}var s=4,c={fftSize:512,smoothingTimeConstant:.25,minDecibels:-85,maxDecibels:-20},l={noiseFloor:.015,gain:4.6,exponent:1.15,attack:.1,release:.48};function u(e){switch(e){case`speaking`:return`speaking`;case`thinking`:return`thinking`;case`listening`:case`idle`:return`listening`;case`connecting`:case`pre-connect-buffering`:case`initializing`:return`connecting`;case`disconnected`:return`idle`;case`failed`:return`error`;default:return`idle`}}function d(e){return`RoomClass`in e}function f(e){return typeof e==`function`?e():e}function p(e){if(!e)return{};let t={},n=(e,n)=>{n!==void 0&&(t[e]=n)};return n(`roomName`,f(e.roomName)),n(`participantName`,f(e.participantName)),n(`participantIdentity`,f(e.participantIdentity)),n(`participantMetadata`,f(e.participantMetadata)),n(`participantAttributes`,typeof e.participantAttributes==`function`?e.participantAttributes():e.participantAttributes),n(`agentName`,f(e.agentName)),n(`agentMetadata`,f(e.agentMetadata)),n(`deployment`,f(e.deployment)),t}function m(e){if(!e.serverUrl||!e.participantToken)throw Error(`[orb-ui/livekit] connection details must include serverUrl and participantToken.`);return e}async function h(e){let t=p(e.tokenOptions);return typeof e.getConnectionDetails==`function`?m(await e.getConnectionDetails(t)):e.tokenSource?m(await e.tokenSource.fetch(t)):m({serverUrl:e.serverUrl,participantToken:e.participantToken})}function g(e){for(let[,t]of e.remoteParticipants)if(!t.isLocal&&(t.kind===s||t.attributes?.[`lk.agent.state`]!==void 0))return t;return null}function _(e,t,n){let r=e.off;if(r){r.call(e,t,n);return}e.removeListener?.call(e,t,n)}function v(e,t,n){e.on.call(e,t,n)}function y(t){let n=d(t),r=t.createAudioAnalyser,i={current:n?null:t.room},o=new Set,f={state:`idle`,volume:0,inputVolume:0,outputVolume:0},p=`idle`,m=null,y=null,b=null,x=null,S=null,C=null,w=null,T=0,E=null;function D(e){f=e,o.forEach(t=>t(e))}function O(e){D({...f,...e,state:e.state??f.state})}function k(){let e=typeof t.outputVolumeCalibration==`function`?t.outputVolumeCalibration():t.outputVolumeCalibration;return{...l,...e}}function A(e){let n=a(e,T,k);return T=n.normalized,t.onOutputVolumeSample?.(n),n.normalized}function j(){T=0,O({volume:0,outputVolume:0})}function M({emitZero:e=!0}={}){S&&=(clearInterval(S),null),x&&=(x.cleanup().catch(()=>{}),null),e&&O({volume:0,inputVolume:0})}function N(t){if(!(m===t&&x)){M({emitZero:!1}),m=t;try{x=r(t,c)}catch(e){console.warn(`[orb-ui/livekit] local createAudioAnalyser failed:`,e);return}S=setInterval(()=>{if(!x||p!==`listening`)return;let t=e(x.calculateVolume());O({volume:t,inputVolume:t,outputVolume:0})},33)}}function P({emitZero:e=!0}={}){w&&=(clearInterval(w),null),C&&=(C.cleanup().catch(()=>{}),null),T=0,e&&O({volume:0,outputVolume:0})}function F(e){P();try{C=r(e,c)}catch(e){console.warn(`[orb-ui/livekit] remote createAudioAnalyser failed:`,e);return}w=setInterval(()=>{if(!C||p!==`speaking`)return;let e=A(C.calculateVolume());O({volume:e,inputVolume:0,outputVolume:e})},33)}function I(e){p=e,O({state:e,volume:0,inputVolume:0,outputVolume:0}),e===`speaking`&&y?F(y):e!==`speaking`&&P({emitZero:!1})}function L(e){b||typeof document>`u`||(b=e.attach(),b.id=`orb-ui-livekit-agent-audio`,document.body.appendChild(b))}function R(){b&&=(b.remove(),null)}function z(e){y=e,L(e),p===`speaking`&&F(e)}function B(e){N(e)}function V(e){let t=e.getTrackPublication?.(`microphone`);t?.track&&B(t.track)}function H(e){let t=u(e);t!==p&&I(t)}function U(e){let t=e.attributes?.[`lk.agent.state`];t&&H(t);let n=e.getTrackPublication(`microphone`);n?.track&&z(n.track)}function W(e){if(E)return;let t=(e,t)=>{if(t.isLocal)return;let n=e[`lk.agent.state`];n&&H(n)},n=(e,t,n)=>{n.isLocal||!(n.kind===s||n.attributes?.[`lk.agent.state`]!==void 0)||e.mediaStreamTrack.kind!==`audio`||z(e)},r=e=>{y===e&&(y=null,R(),P())},i=e=>{e.source!==`microphone`||!e.track||B(e.track)},a=e=>{e.source===`microphone`&&(m=null,M())},o=()=>{m=null,y=null,R(),M({emitZero:!1}),P({emitZero:!1}),I(`idle`)};if(v(e,`participantAttributesChanged`,t),v(e,`trackSubscribed`,n),v(e,`trackUnsubscribed`,r),v(e,`localTrackPublished`,i),v(e,`localTrackUnpublished`,a),v(e,`disconnected`,o),E=()=>{_(e,`participantAttributesChanged`,t),_(e,`trackSubscribed`,n),_(e,`trackUnsubscribed`,r),_(e,`localTrackPublished`,i),_(e,`localTrackUnpublished`,a),_(e,`disconnected`,o)},V(e.localParticipant),e.state===`connected`){let t=g(e);t?U(t):I(`connecting`)}else I(`idle`)}function G(){E?.(),E=null,m=null,y=null,R(),M({emitZero:!1}),P({emitZero:!1}),O({volume:0,inputVolume:0,outputVolume:0})}let K=e=>{o.add(e),e(f);let t=i.current;return t&&W(t),()=>{o.delete(e),o.size===0&&G()}};return n?{subscribe:K,async start(){if(i.current)return;let e=t,n=new e.RoomClass;I(`connecting`);try{let t=await h(e);if(await n.connect(t.serverUrl,t.participantToken,e.connectOptions),i.current=n,W(n),e.enableMicrophone!==!1){let e=(await n.localParticipant.setMicrophoneEnabled(!0))?.track??n.localParticipant.getTrackPublication?.(`microphone`)?.track;e&&B(e)}}catch(e){throw console.error(`[orb-ui/livekit] connect failed:`,e),i.current===n&&G(),n.disconnect(),i.current=null,I(`error`),j(),O({error:e}),e}},async stop(){let e=i.current;if(!e){I(`idle`);return}G(),e.disconnect(),i.current=null,I(`idle`)}}:{subscribe:K}}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return y}});