orb-ui 0.2.4 → 0.4.0
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/README.md +153 -10
- package/dist/adapters/audio-level.d.ts +23 -0
- package/dist/adapters/gemini-live/index.d.ts +70 -0
- package/dist/adapters/index.d.ts +6 -1
- package/dist/adapters/livekit/index.d.ts +129 -0
- package/dist/adapters/openai-realtime/index.d.ts +37 -0
- package/dist/adapters/pipecat/index.d.ts +46 -0
- package/dist/adapters/types.d.ts +4 -8
- package/dist/adapters/vapi/index.d.ts +2 -2
- package/dist/adapters.cjs +1 -1
- package/dist/adapters.js +983 -66
- package/dist/components/Orb/Orb.d.ts +1 -1
- package/dist/components/Orb/Orb.types.d.ts +31 -10
- package/dist/components/Orb/index.d.ts +1 -1
- package/dist/components/Orb/signals.d.ts +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/orb-ui.cjs +2 -2
- package/dist/orb-ui.js +126 -147
- package/package.json +16 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { OrbProps } from './Orb.types.js';
|
|
2
|
-
export declare function Orb({ state: stateProp, volume: volumeProp, adapter, theme, size, className, style, disabled, onStart, onStop, ...htmlProps }: OrbProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare function Orb({ signal: signalProp, state: stateProp, volume: volumeProp, adapter, theme, size, className, style, disabled, onStart, onStop, ...htmlProps }: OrbProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
import { AriaAttributes, CSSProperties } from 'react';
|
|
2
|
-
export type OrbState = 'idle' | 'connecting' | 'listening' | 'speaking' | 'error';
|
|
2
|
+
export type OrbState = 'idle' | 'connecting' | 'listening' | 'thinking' | 'speaking' | 'error';
|
|
3
3
|
export type OrbTheme = 'debug' | 'circle' | 'bars';
|
|
4
|
+
export interface OrbSignal {
|
|
5
|
+
state: OrbState;
|
|
6
|
+
volume?: number;
|
|
7
|
+
inputVolume?: number;
|
|
8
|
+
outputVolume?: number;
|
|
9
|
+
error?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export type OrbSignalListener = (signal: OrbSignal) => void;
|
|
4
12
|
export interface OrbAdapter {
|
|
5
13
|
/**
|
|
6
|
-
* Subscribe to
|
|
14
|
+
* Subscribe to normalized signal changes from a voice provider.
|
|
7
15
|
* Returns an unsubscribe function to clean up listeners.
|
|
8
16
|
*/
|
|
9
|
-
subscribe(
|
|
10
|
-
onStateChange: (state: OrbState) => void;
|
|
11
|
-
onVolumeChange: (volume: number) => void;
|
|
12
|
-
}): () => void;
|
|
17
|
+
subscribe(listener: OrbSignalListener): () => void;
|
|
13
18
|
/** Start the voice session. Called internally by Orb on click. */
|
|
14
19
|
start?: () => void | Promise<void>;
|
|
15
20
|
/** Stop the voice session. Called internally by Orb on click. */
|
|
16
21
|
stop?: () => void | Promise<void>;
|
|
17
22
|
}
|
|
23
|
+
/** @deprecated Use signal-based OrbAdapter.subscribe(listener). */
|
|
24
|
+
export interface AdapterCallbacks {
|
|
25
|
+
onStateChange: (state: OrbState) => void;
|
|
26
|
+
onVolumeChange: (volume: number) => void;
|
|
27
|
+
}
|
|
28
|
+
/** @deprecated Callback-object adapters will be removed in 0.5.0. */
|
|
29
|
+
export interface LegacyOrbAdapter {
|
|
30
|
+
subscribe(callbacks: AdapterCallbacks): () => void;
|
|
31
|
+
start?: () => void | Promise<void>;
|
|
32
|
+
stop?: () => void | Promise<void>;
|
|
33
|
+
}
|
|
18
34
|
type DataAttributeValue = string | number | boolean | null | undefined;
|
|
19
35
|
export interface OrbHtmlAttributes extends AriaAttributes {
|
|
20
36
|
/** Forwarded to the rendered orb control/container. */
|
|
@@ -29,21 +45,26 @@ export interface OrbHtmlAttributes extends AriaAttributes {
|
|
|
29
45
|
[dataAttribute: `data-${string}`]: DataAttributeValue;
|
|
30
46
|
}
|
|
31
47
|
export interface OrbProps extends OrbHtmlAttributes {
|
|
48
|
+
/**
|
|
49
|
+
* Current voice signal. Use this controlled mode when your app has separate
|
|
50
|
+
* input and output volume levels.
|
|
51
|
+
*/
|
|
52
|
+
signal?: OrbSignal;
|
|
32
53
|
/**
|
|
33
54
|
* Current conversation state. Required in controlled mode (no adapter).
|
|
34
|
-
* Overrides adapter state if
|
|
55
|
+
* Overrides signal and adapter state if provided.
|
|
35
56
|
*/
|
|
36
57
|
state?: OrbState;
|
|
37
58
|
/**
|
|
38
59
|
* Current audio volume, normalized 0–1.
|
|
39
|
-
* Overrides adapter volume if
|
|
60
|
+
* Overrides signal and adapter volume if provided.
|
|
40
61
|
*/
|
|
41
62
|
volume?: number;
|
|
42
63
|
/**
|
|
43
64
|
* Provider adapter (Vapi, ElevenLabs, etc.).
|
|
44
|
-
* Handles
|
|
65
|
+
* Handles signal updates automatically from the SDK.
|
|
45
66
|
*/
|
|
46
|
-
adapter?: OrbAdapter;
|
|
67
|
+
adapter?: OrbAdapter | LegacyOrbAdapter;
|
|
47
68
|
/** Visual theme. Defaults to 'debug'. */
|
|
48
69
|
theme?: OrbTheme;
|
|
49
70
|
/** Size in pixels. Defaults to 200. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Orb } from './Orb.js';
|
|
2
|
-
export type { OrbProps, OrbState, OrbTheme,
|
|
2
|
+
export type { AdapterCallbacks, LegacyOrbAdapter, OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, OrbTheme, } from './Orb.types.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AdapterCallbacks, OrbSignal, OrbSignalListener, OrbState } from './Orb.types.js';
|
|
2
|
+
export type HybridOrbSignalListener = OrbSignalListener & AdapterCallbacks;
|
|
3
|
+
export declare function deriveOrbState(state: OrbState | undefined, signal: OrbSignal | undefined, adapterSignal: OrbSignal): OrbState;
|
|
4
|
+
export declare function deriveOrbVolume(volume: number | undefined, state: OrbState, signal: OrbSignal): number;
|
|
5
|
+
export declare function createOrbSignalListener(onSignal: OrbSignalListener, onLegacyAdapterUsed: () => void): HybridOrbSignalListener;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Orb } from './components/Orb/index.js';
|
|
2
|
-
export type { OrbProps, OrbState, OrbTheme,
|
|
2
|
+
export type { AdapterCallbacks, LegacyOrbAdapter, OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, OrbTheme, } from './components/Orb/index.js';
|
|
3
3
|
export { Orb as VoiceOrb } from './components/Orb/index.js';
|
|
4
4
|
export type { OrbProps as VoiceOrbProps } from './components/Orb/index.js';
|
package/dist/orb-ui.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime");function n(e){
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime");function n(e,t,n){return e??t?.state??n.state}function r(e,t,n){return e===void 0?t===`listening`?n.inputVolume??n.volume??0:t===`speaking`?n.outputVolume??n.volume??0:n.volume??0:e}function i(e,t){let n={state:`idle`},r=t=>{n=t,e(t)},i=(e=>{r(e)});return i.onStateChange=e=>{t(),r({...n,state:e})},i.onVolumeChange=e=>{t(),r({...n,volume:e})},i}var a=[`idle`,`connecting`,`listening`,`thinking`,`speaking`,`error`],o={idle:`#888`,connecting:`#f0c040`,listening:`#40c0f0`,thinking:`#c084fc`,speaking:`#40f080`,error:`#f04040`};function s({state:e,volume:n,size:r,className:i,style:s,disabled:c=!1,onStart:l,onStop:u,...d}){return(0,t.jsxs)(`div`,{...d,className:i,style:{width:r,fontFamily:`monospace`,fontSize:12,background:`#111`,color:`#ccc`,border:`1px solid #333`,borderRadius:8,padding:12,boxSizing:`border-box`,userSelect:`none`,...s},children:[(0,t.jsx)(`div`,{style:{color:`#555`,marginBottom:10,fontSize:10,letterSpacing:1},children:`ORB DEBUG`}),(0,t.jsxs)(`div`,{style:{marginBottom:8},children:[(0,t.jsx)(`span`,{style:{color:`#555`},children:`state `}),(0,t.jsx)(`span`,{style:{color:o[e],fontWeight:`bold`},children:e})]}),(0,t.jsxs)(`div`,{style:{marginBottom:10},children:[(0,t.jsx)(`span`,{style:{color:`#555`},children:`volume `}),(0,t.jsx)(`span`,{style:{color:`#ccc`},children:n.toFixed(2)}),(0,t.jsx)(`div`,{style:{marginTop:4,height:4,background:`#222`,borderRadius:2,overflow:`hidden`},children:(0,t.jsx)(`div`,{style:{height:`100%`,width:`${n*100}%`,background:o[e],borderRadius:2,transition:`width 50ms linear`}})})]}),(0,t.jsxs)(`div`,{style:{marginBottom:10},children:[(0,t.jsx)(`div`,{style:{color:`#555`,marginBottom:4,fontSize:10},children:`force state`}),(0,t.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:4},children:a.map(n=>(0,t.jsx)(`button`,{disabled:c,style:{fontSize:10,padding:`2px 6px`,background:e===n?o[n]:`#222`,color:e===n?`#000`:`#888`,border:`1px solid ${e===n?o[n]:`#333`}`,borderRadius:3,cursor:c?`not-allowed`:`pointer`},onClick:()=>{console.warn(`[orb-ui debug] To force state '${n}', use controlled mode: <Orb state="${n}" />`)},children:n},n))})]}),(0,t.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,t.jsx)(`button`,{disabled:c,onClick:l,style:{flex:1,padding:`4px 0`,background:`#1a3a1a`,color:`#40f080`,border:`1px solid #40f080`,borderRadius:4,cursor:c?`not-allowed`:`pointer`,fontSize:11},children:`Start`}),(0,t.jsx)(`button`,{disabled:c,onClick:u,style:{flex:1,padding:`4px 0`,background:`#3a1a1a`,color:`#f04040`,border:`1px solid #f04040`,borderRadius:4,cursor:c?`not-allowed`:`pointer`,fontSize:11},children:`Stop`})]})]})}var c=typeof window<`u`?e.useLayoutEffect:e.useEffect;function l(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}var u={idle:`#cccccc`,connecting:`#cccccc`,listening:`#999999`,thinking:`#d8d8d8`,speaking:`#e8e8e8`,error:`#f87171`},d=`
|
|
2
2
|
@keyframes orb-circle-idle-pulse {
|
|
3
3
|
from { transform: scale(1); }
|
|
4
4
|
to { transform: scale(1.06); }
|
|
@@ -8,4 +8,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
8
8
|
50% { opacity: 0.6; transform: scale(0.95); }
|
|
9
9
|
100% { opacity: 1; transform: scale(1); }
|
|
10
10
|
}
|
|
11
|
-
`,
|
|
11
|
+
`,f=.95,p=.08,m=.82,h=.18,g=24,_=0,v=.55,y=.12,b=.002;function x({state:n,volume:r,size:i,className:a,style:o,disabled:s=!1,interactive:x=!1,onClick:S,...C}){let w=(0,e.useRef)(null),T=(0,e.useRef)(null),E=(0,e.useRef)(null),D=(0,e.useRef)(0),O=(0,e.useRef)(r);c(()=>{O.current=r},[r]);let k=(0,e.useRef)(1),A=(0,e.useRef)(0),j=(0,e.useRef)(l(u.idle)),M=.06,N=(0,e.useRef)(m),P=(0,e.useRef)(h);(0,e.useEffect)(()=>{let e=`orb-circle-keyframes`;if(!document.getElementById(e)){let t=document.createElement(`style`);t.id=e,t.textContent=d,document.head.appendChild(t)}},[]),(0,e.useEffect)(()=>{let e=w.current;if(e)if(n===`listening`||n===`speaking`){let t=n===`speaking`?f:m,r=n===`speaking`?p:h,i=n===`speaking`?g:_,a=()=>{let o=O.current;N.current+=(t-N.current)*M,P.current+=(r-P.current)*M;let s=N.current+o*P.current,c=o*i;n===`listening`?(k.current+=(s-k.current)*v,A.current+=(c-A.current)*v):(k.current=s,A.current=c);let d=l(u[n]),[f,p,m]=j.current;j.current=[f+(d[0]-f)*.05,p+(d[1]-p)*.05,m+(d[2]-m)*.05];let[h,g,_]=j.current.map(Math.round);e.style.transform=`scale(${k.current})`,e.style.background=`rgb(${h},${g},${_})`,e.style.boxShadow=`none`,e.style.animation=`none`;let y=T.current;if(y){let e=A.current;y.style.transform=`scale(${k.current})`,y.style.boxShadow=e>.5?`0 0 ${e}px ${e*.4}px rgb(${h},${g},${_})`:`none`}D.current=requestAnimationFrame(a)};return D.current=requestAnimationFrame(a),()=>{cancelAnimationFrame(D.current)}}else{cancelAnimationFrame(D.current);let t=u[n]??u.idle,r=l(t),i=()=>{k.current+=(1-k.current)*y,A.current+=(0-A.current)*y;let[a,o,s]=j.current;j.current=[a+(r[0]-a)*y,o+(r[1]-o)*y,s+(r[2]-s)*y];let[c,l,u]=j.current.map(Math.round);e.style.transform=`scale(${k.current})`,e.style.background=`rgb(${c},${l},${u})`,e.style.boxShadow=`none`,e.style.animation=`none`,T.current&&(T.current.style.transform=`scale(${k.current})`,T.current.style.boxShadow=`none`);let d=Math.abs(k.current-1)<b,f=A.current<.1,p=j.current.every((e,t)=>Math.abs(e-r[t])<1);if(d&&f&&p){k.current=1,A.current=0,j.current=r,e.style.transform=``,e.style.boxShadow=`none`,e.style.background=t,T.current&&(T.current.style.transform=`scale(1)`,T.current.style.boxShadow=`none`),n===`idle`?e.style.animation=`orb-circle-idle-pulse 3s ease-in-out infinite alternate`:n===`connecting`||n===`thinking`?e.style.animation=`orb-circle-connecting-pulse 1.5s ease-in-out infinite`:e.style.animation=`none`;return}D.current=requestAnimationFrame(i)};return D.current=requestAnimationFrame(i),()=>cancelAnimationFrame(D.current)}},[n]);let F=i*.55,I={width:i,height:i,display:`flex`,alignItems:`center`,justifyContent:`center`,position:`relative`,...o},L=(0,t.jsxs)(`span`,{ref:E,onMouseEnter:()=>{E.current&&!s&&(E.current.style.transform=`scale(1.06)`,E.current.style.filter=`brightness(1.12)`)},onMouseLeave:()=>{E.current&&(E.current.style.transform=`scale(1)`,E.current.style.filter=`brightness(1)`)},onTouchEnd:()=>{setTimeout(()=>{E.current&&(E.current.style.transform=`scale(1)`,E.current.style.filter=`brightness(1)`)},200)},style:{position:`relative`,display:`inline-block`,transition:`transform 0.3s ease, filter 0.3s ease`,cursor:x?s?`not-allowed`:`pointer`:`default`,borderRadius:`50%`,lineHeight:0},children:[(0,t.jsx)(`span`,{ref:T,style:{position:`absolute`,display:`block`,width:F,height:F,borderRadius:`50%`,pointerEvents:`none`}}),(0,t.jsx)(`span`,{ref:w,style:{position:`relative`,display:`block`,width:F,height:F,borderRadius:`50%`,background:u[n]}})]});return x?(0,t.jsx)(`button`,{...C,type:`button`,className:a,disabled:s,onClick:s?void 0:S,style:{appearance:`none`,WebkitAppearance:`none`,border:0,padding:0,margin:0,background:`transparent`,color:`inherit`,font:`inherit`,cursor:s?`not-allowed`:`pointer`,...I},children:L}):(0,t.jsx)(`div`,{...C,className:a,style:I,children:L})}var S=5,C=1.4,w=Math.PI*2/S,T={idle:`#cccccc`,connecting:`#cccccc`,listening:`#999999`,thinking:`#d8d8d8`,speaking:`#e8e8e8`,error:`#f87171`};function E(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function D({state:n,volume:r,size:i,className:a,style:o,disabled:s=!1,interactive:c=!1,onClick:l,...u}){let d=(0,e.useRef)([]),f=(0,e.useRef)(null),p=(0,e.useRef)(0),m=(0,e.useRef)(Array(S).fill(0)),h=(0,e.useRef)(r),g=(0,e.useRef)(!1),_=(0,e.useRef)(0),v=(0,e.useRef)(E(T.idle)),y=(0,e.useRef)(null),b=(0,e.useRef)(Array(S).fill(0)),x=(0,e.useRef)(n);(0,e.useEffect)(()=>{n!==x.current&&(b.current=[...m.current],y.current=Date.now(),x.current=n)},[n]),(0,e.useEffect)(()=>{h.current=r},[r]),(0,e.useEffect)(()=>{let e=i*.55,t=i*.06,r=T[n]??T.idle,a=i*.1,o=Array.from({length:S},(e,t)=>{let n=(S-1)/2;return 1-.7*(Math.abs(t-n)/n)}),s=()=>{let e=g.current?a:0;_.current+=(e-_.current)*.15},c=(t,r)=>{s();let i=E(r),[a,c,l]=v.current;v.current=[a+(i[0]-a)*.08,c+(i[1]-c)*.08,l+(i[2]-l)*.08];let[u,f,p]=v.current.map(Math.round),m=`rgb(${u},${f},${p})`;for(let r=0;r<S;r++){let i=d.current[r];if(!i)continue;let a=n===`idle`?o[r]:1,s=_.current*a;i.style.height=`${Math.min(t[r]+s,e)}px`,i.style.background=m,i.style.animation=`none`}};if(n===`listening`||n===`speaking`){let i=n===`speaking`?1:.4,a=()=>{let o=h.current,s=Date.now()/1e3;for(let r=0;r<S;r++){let a=.5+.15*Math.sin(s*C*i*Math.PI*2+r*w),c=t+(e-t)*o*a;if(y.current!==null){let e=Date.now()-y.current,t=Math.min(e/300,1),n=1-(1-t)*(1-t);c=b.current[r]+(c-b.current[r])*n,t>=1&&(y.current=null)}let l=n===`listening`?.45:1;m.current[r]+=(c-m.current[r])*l}c(m.current,r),p.current=requestAnimationFrame(a)};return p.current=requestAnimationFrame(a),()=>cancelAnimationFrame(p.current)}if(n===`connecting`||n===`thinking`){let n=Date.now(),i=()=>{let a=(Date.now()-n)/1e3;s();for(let n=0;n<S;n++){let r=(a*.6+n/S*.5)%1,i=r<.5?Math.sin(r/.5*Math.PI):0,o=t+(e*.4-t)*i;m.current[n]+=(o-m.current[n])*.15}c(m.current,r),p.current=requestAnimationFrame(i)};return p.current=requestAnimationFrame(i),()=>cancelAnimationFrame(p.current)}cancelAnimationFrame(p.current);let l=()=>{s();for(let e=0;e<S;e++)m.current[e]+=(t-m.current[e])*.16;c(m.current,r),p.current=requestAnimationFrame(l)};return p.current=requestAnimationFrame(l),()=>cancelAnimationFrame(p.current)},[n,i]);let D=i*.055,O=i*.035,k=i*.03,A=i*.55,j=i*.06,M={width:i,height:i,display:`flex`,alignItems:`center`,justifyContent:`center`,position:`relative`,...o},N=(0,t.jsx)(`span`,{ref:f,onMouseEnter:()=>{s||(g.current=!0,f.current&&(f.current.style.filter=`brightness(1.35)`))},onMouseLeave:()=>{g.current=!1,f.current&&(f.current.style.filter=`brightness(1)`)},onTouchEnd:()=>{setTimeout(()=>{g.current=!1,f.current&&(f.current.style.filter=`brightness(1)`)},200)},style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:O,transition:`filter 0.3s ease`,cursor:c?s?`not-allowed`:`pointer`:`default`},children:Array.from({length:S},(e,r)=>(0,t.jsx)(`span`,{ref:e=>{d.current[r]=e},style:{width:D,minHeight:j,maxHeight:A,height:j,borderRadius:k,background:T[n]??T.idle}},r))});return c?(0,t.jsx)(`button`,{...u,type:`button`,className:a,disabled:s,onClick:s?void 0:l,style:{appearance:`none`,WebkitAppearance:`none`,border:0,padding:0,margin:0,background:`transparent`,color:`inherit`,font:`inherit`,cursor:s?`not-allowed`:`pointer`,...M},children:N}):(0,t.jsx)(`div`,{...u,className:a,style:M,children:N})}var O=!1;function k(){return globalThis.process?.env?.NODE_ENV===`production`}function A(){O||k()||(O=!0,console.warn(`[orb-ui] Callback-object adapters are deprecated. Use subscribe(listener) and emit OrbSignal objects instead. Legacy adapters will be removed in 0.5.0.`))}function j({signal:a,state:o,volume:c,adapter:l,theme:u=`debug`,size:d=200,className:f,style:p,disabled:m=!1,onStart:h,onStop:g,..._}){let[v,y]=(0,e.useState)({state:`idle`});(0,e.useEffect)(()=>{if(y({state:`idle`}),!l)return;let e=i(y,A);return l.subscribe(e)},[l]);let b=a??v,S=n(o,a,v),C=r(c,S,b),w=S!==`idle`&&S!==`error`,T=(0,e.useCallback)(()=>{m||(w?g?g():l?.stop?.():h?h():l?.start?.())},[l,m,w,h,g]),E=w?!!(l?.stop||g):!!(l?.start||h),O=E&&!m?T:void 0,k={state:S,volume:C,size:d,className:f,style:p,disabled:m,..._,"aria-label":_[`aria-label`]??(E?`${w?`Stop`:`Start`} voice session`:void 0)},j={...k,interactive:E};switch(u){case`circle`:return(0,t.jsx)(x,{...j,onClick:O});case`bars`:return(0,t.jsx)(D,{...j,onClick:O});default:return(0,t.jsx)(s,{...k,onStart:m?void 0:h??(()=>l?.start?.()),onStop:m?void 0:g??(()=>l?.stop?.())})}}exports.Orb=j,exports.VoiceOrb=j;
|