@oneinbox/web-sdk-react 0.1.0-beta.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OneInbox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @oneinbox/web-sdk-react
2
+
3
+ React bindings for [`@oneinbox/web-sdk`](https://www.npmjs.com/package/@oneinbox/web-sdk) — a `<OneInboxProvider>` and a `useOneInbox()` hook for browser voice calls to a [OneInbox](https://oneinbox.ai) agent over WebRTC.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @oneinbox/web-sdk-react @oneinbox/web-sdk livekit-client react
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { OneInboxProvider, useOneInbox } from "@oneinbox/web-sdk-react";
15
+
16
+ function App() {
17
+ return (
18
+ <OneInboxProvider publishableKey="oi_pk_live_…">
19
+ <CallButton agentId="agt_…" />
20
+ </OneInboxProvider>
21
+ );
22
+ }
23
+
24
+ function CallButton({ agentId }: { agentId: string }) {
25
+ const { start, stop, status, transcripts, isAgentSpeaking, isMuted, setMuted } = useOneInbox();
26
+ const active = status === "active";
27
+ return (
28
+ <div>
29
+ <button onClick={() => (active ? stop() : start(agentId))}>
30
+ {active ? "Hang up" : "Call"}
31
+ </button>
32
+ {active && <button onClick={() => setMuted(!isMuted)}>{isMuted ? "Unmute" : "Mute"}</button>}
33
+ <p>{isAgentSpeaking ? "🗣 agent speaking" : status}</p>
34
+ <ul>{transcripts.map((t, i) => <li key={i}><b>{t.role}:</b> {t.text}</li>)}</ul>
35
+ </div>
36
+ );
37
+ }
38
+ ```
39
+
40
+ `useOneInbox()` returns `{ start, stop, setMuted, status, isMuted, isAgentSpeaking, volume, transcripts, error, client }`. Auth, events, and error codes are documented in [`@oneinbox/web-sdk`](https://www.npmjs.com/package/@oneinbox/web-sdk).
41
+
42
+ ## License
43
+
44
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ var webSdk = require('@oneinbox/web-sdk');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ // src/index.tsx
8
+ var OneInboxContext = react.createContext(null);
9
+ function OneInboxProvider({
10
+ publishableKey,
11
+ children,
12
+ ...config
13
+ }) {
14
+ const baseUrl = config.baseUrl;
15
+ const client = react.useMemo(
16
+ () => new webSdk.OneInbox(publishableKey, { baseUrl }),
17
+ [publishableKey, baseUrl]
18
+ );
19
+ return /* @__PURE__ */ jsxRuntime.jsx(OneInboxContext.Provider, { value: client, children });
20
+ }
21
+ function useOneInboxClient() {
22
+ const client = react.useContext(OneInboxContext);
23
+ if (!client) {
24
+ throw new Error("useOneInbox must be used within an <OneInboxProvider>.");
25
+ }
26
+ return client;
27
+ }
28
+ function useOneInbox() {
29
+ const client = useOneInboxClient();
30
+ const [status, setStatus] = react.useState(client.status);
31
+ const [isMuted, setIsMuted] = react.useState(client.isMuted());
32
+ const [isAgentSpeaking, setIsAgentSpeaking] = react.useState(false);
33
+ const [volume, setVolume] = react.useState(0);
34
+ const [transcripts, setTranscripts] = react.useState([]);
35
+ const [error, setError] = react.useState(null);
36
+ const clientRef = react.useRef(client);
37
+ clientRef.current = client;
38
+ react.useEffect(() => {
39
+ const offs = [
40
+ client.on("status", setStatus),
41
+ client.on("volume-level", setVolume),
42
+ client.on("error", setError),
43
+ client.on("transcript", (t) => setTranscripts((prev) => [...prev, t])),
44
+ client.on("speech-start", (who) => {
45
+ if (who === "agent") setIsAgentSpeaking(true);
46
+ }),
47
+ client.on("speech-end", (who) => {
48
+ if (who === "agent") setIsAgentSpeaking(false);
49
+ }),
50
+ client.on("call-start", () => {
51
+ setTranscripts([]);
52
+ setError(null);
53
+ setIsMuted(client.isMuted());
54
+ }),
55
+ client.on("call-end", () => {
56
+ setIsAgentSpeaking(false);
57
+ setVolume(0);
58
+ })
59
+ ];
60
+ return () => offs.forEach((off) => off());
61
+ }, [client]);
62
+ const start = react.useCallback(
63
+ (agentId, opts) => clientRef.current.start(agentId, opts),
64
+ []
65
+ );
66
+ const stop = react.useCallback(() => clientRef.current.stop(), []);
67
+ const setMuted = react.useCallback((muted) => {
68
+ clientRef.current.setMuted(muted);
69
+ setIsMuted(muted);
70
+ }, []);
71
+ return {
72
+ start,
73
+ stop,
74
+ setMuted,
75
+ status,
76
+ isMuted,
77
+ isAgentSpeaking,
78
+ volume,
79
+ transcripts,
80
+ error,
81
+ client
82
+ };
83
+ }
84
+
85
+ exports.OneInboxProvider = OneInboxProvider;
86
+ exports.useOneInbox = useOneInbox;
87
+ exports.useOneInboxClient = useOneInboxClient;
88
+ //# sourceMappingURL=index.cjs.map
89
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":["createCont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AA,KAAQ,KAAK,CAAA;AAAA,EAC1C,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAEX,EAAA,MAAM,KAAA,GAAQC,iBAAA;AAAA,IACZ,CAAC,OAAA,EAAiB,IAAA,KAAwB,UAAU,OAAA,CAAQ,KAAA,CAAM,SAAS,IAAI,CAAA;AAAA,IAC/E;AAAC,GACH;AACA,EAAA,MAAM,IAAA,GAAOA,kBAAY,MAAM,SAAA,CAAU,QAAQ,IAAA,EAAK,EAAG,EAAE,CAAA;AAC3D,EAAA,MAAM,QAAA,GAAWA,iBAAA,CAAY,CAAC,KAAA,KAAmB;AAC/C,IAAA,SAAA,CAAU,OAAA,CAAQ,SAAS,KAAK,CAAA;AAChC,IAAA,UAAA,CAAW,KAAK,CAAA;AAAA,EAClB,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,eAAA;AAAA,IACA,MAAA;AAAA,IACA,WAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import {\n type CallStatus,\n OneInbox,\n type OneInboxConfig,\n type OneInboxError,\n type StartOptions,\n type TranscriptEvent,\n} from \"@oneinbox/web-sdk\";\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nexport type { CallStatus, OneInboxError, StartOptions, TranscriptEvent };\n\nconst OneInboxContext = createContext<OneInbox | null>(null);\n\nexport interface OneInboxProviderProps extends OneInboxConfig {\n /** Publishable key (`oi_pk_…`). */\n publishableKey: string;\n children: ReactNode;\n}\n\n/**\n * Provides a single `OneInbox` instance to the tree. Place near the root.\n *\n * ```tsx\n * <OneInboxProvider publishableKey=\"oi_pk_…\">\n * <App />\n * </OneInboxProvider>\n * ```\n */\nexport function OneInboxProvider({\n publishableKey,\n children,\n ...config\n}: OneInboxProviderProps) {\n // baseUrl is the only config field today; spread keeps it forward-compatible.\n const baseUrl = config.baseUrl;\n const client = useMemo(\n () => new OneInbox(publishableKey, { baseUrl }),\n [publishableKey, baseUrl],\n );\n return <OneInboxContext.Provider value={client}>{children}</OneInboxContext.Provider>;\n}\n\n/** Access the raw `OneInbox` client from context. Throws outside a provider. */\nexport function useOneInboxClient(): OneInbox {\n const client = useContext(OneInboxContext);\n if (!client) {\n throw new Error(\"useOneInbox must be used within an <OneInboxProvider>.\");\n }\n return client;\n}\n\nexport interface UseOneInbox {\n /** Start a call by agent id (publishable-key path). */\n start: (agentId: string, opts?: StartOptions) => Promise<void>;\n /** End the active call. */\n stop: () => Promise<void>;\n /** Mute/unmute the local microphone. */\n setMuted: (muted: boolean) => void;\n status: CallStatus;\n isMuted: boolean;\n /** Whether the agent is currently speaking (best-effort). */\n isAgentSpeaking: boolean;\n /** Local mic level 0..1 (sampled while active). */\n volume: number;\n /** Accumulated transcript chunks (interim + final), in arrival order. */\n transcripts: TranscriptEvent[];\n /** Last error, if any. */\n error: OneInboxError | null;\n /** Escape hatch to the underlying client. */\n client: OneInbox;\n}\n\n/**\n * Subscribes to the client's events and exposes them as React state.\n *\n * ```tsx\n * const { start, stop, status, transcripts, isAgentSpeaking } = useOneInbox();\n * ```\n */\nexport function useOneInbox(): UseOneInbox {\n const client = useOneInboxClient();\n\n const [status, setStatus] = useState<CallStatus>(client.status);\n const [isMuted, setIsMuted] = useState<boolean>(client.isMuted());\n const [isAgentSpeaking, setIsAgentSpeaking] = useState(false);\n const [volume, setVolume] = useState(0);\n const [transcripts, setTranscripts] = useState<TranscriptEvent[]>([]);\n const [error, setError] = useState<OneInboxError | null>(null);\n // Keep a ref so the imperative callbacks below don't re-create per render.\n const clientRef = useRef(client);\n clientRef.current = client;\n\n useEffect(() => {\n const offs = [\n client.on(\"status\", setStatus),\n client.on(\"volume-level\", setVolume),\n client.on(\"error\", setError),\n client.on(\"transcript\", (t) => setTranscripts((prev) => [...prev, t])),\n client.on(\"speech-start\", (who) => {\n if (who === \"agent\") setIsAgentSpeaking(true);\n }),\n client.on(\"speech-end\", (who) => {\n if (who === \"agent\") setIsAgentSpeaking(false);\n }),\n client.on(\"call-start\", () => {\n setTranscripts([]);\n setError(null);\n setIsMuted(client.isMuted());\n }),\n client.on(\"call-end\", () => {\n setIsAgentSpeaking(false);\n setVolume(0);\n }),\n ];\n return () => offs.forEach((off) => off());\n }, [client]);\n\n const start = useCallback(\n (agentId: string, opts?: StartOptions) => clientRef.current.start(agentId, opts),\n [],\n );\n const stop = useCallback(() => clientRef.current.stop(), []);\n const setMuted = useCallback((muted: boolean) => {\n clientRef.current.setMuted(muted);\n setIsMuted(muted);\n }, []);\n\n return {\n start,\n stop,\n setMuted,\n status,\n isMuted,\n isAgentSpeaking,\n volume,\n transcripts,\n error,\n client,\n };\n}\n"]}
@@ -0,0 +1,52 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { OneInboxConfig, StartOptions, CallStatus, TranscriptEvent, OneInboxError, OneInbox } from '@oneinbox/web-sdk';
4
+ export { CallStatus, OneInboxError, StartOptions, TranscriptEvent } from '@oneinbox/web-sdk';
5
+
6
+ interface OneInboxProviderProps extends OneInboxConfig {
7
+ /** Publishable key (`oi_pk_…`). */
8
+ publishableKey: string;
9
+ children: ReactNode;
10
+ }
11
+ /**
12
+ * Provides a single `OneInbox` instance to the tree. Place near the root.
13
+ *
14
+ * ```tsx
15
+ * <OneInboxProvider publishableKey="oi_pk_…">
16
+ * <App />
17
+ * </OneInboxProvider>
18
+ * ```
19
+ */
20
+ declare function OneInboxProvider({ publishableKey, children, ...config }: OneInboxProviderProps): react.JSX.Element;
21
+ /** Access the raw `OneInbox` client from context. Throws outside a provider. */
22
+ declare function useOneInboxClient(): OneInbox;
23
+ interface UseOneInbox {
24
+ /** Start a call by agent id (publishable-key path). */
25
+ start: (agentId: string, opts?: StartOptions) => Promise<void>;
26
+ /** End the active call. */
27
+ stop: () => Promise<void>;
28
+ /** Mute/unmute the local microphone. */
29
+ setMuted: (muted: boolean) => void;
30
+ status: CallStatus;
31
+ isMuted: boolean;
32
+ /** Whether the agent is currently speaking (best-effort). */
33
+ isAgentSpeaking: boolean;
34
+ /** Local mic level 0..1 (sampled while active). */
35
+ volume: number;
36
+ /** Accumulated transcript chunks (interim + final), in arrival order. */
37
+ transcripts: TranscriptEvent[];
38
+ /** Last error, if any. */
39
+ error: OneInboxError | null;
40
+ /** Escape hatch to the underlying client. */
41
+ client: OneInbox;
42
+ }
43
+ /**
44
+ * Subscribes to the client's events and exposes them as React state.
45
+ *
46
+ * ```tsx
47
+ * const { start, stop, status, transcripts, isAgentSpeaking } = useOneInbox();
48
+ * ```
49
+ */
50
+ declare function useOneInbox(): UseOneInbox;
51
+
52
+ export { OneInboxProvider, type OneInboxProviderProps, type UseOneInbox, useOneInbox, useOneInboxClient };
@@ -0,0 +1,52 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { OneInboxConfig, StartOptions, CallStatus, TranscriptEvent, OneInboxError, OneInbox } from '@oneinbox/web-sdk';
4
+ export { CallStatus, OneInboxError, StartOptions, TranscriptEvent } from '@oneinbox/web-sdk';
5
+
6
+ interface OneInboxProviderProps extends OneInboxConfig {
7
+ /** Publishable key (`oi_pk_…`). */
8
+ publishableKey: string;
9
+ children: ReactNode;
10
+ }
11
+ /**
12
+ * Provides a single `OneInbox` instance to the tree. Place near the root.
13
+ *
14
+ * ```tsx
15
+ * <OneInboxProvider publishableKey="oi_pk_…">
16
+ * <App />
17
+ * </OneInboxProvider>
18
+ * ```
19
+ */
20
+ declare function OneInboxProvider({ publishableKey, children, ...config }: OneInboxProviderProps): react.JSX.Element;
21
+ /** Access the raw `OneInbox` client from context. Throws outside a provider. */
22
+ declare function useOneInboxClient(): OneInbox;
23
+ interface UseOneInbox {
24
+ /** Start a call by agent id (publishable-key path). */
25
+ start: (agentId: string, opts?: StartOptions) => Promise<void>;
26
+ /** End the active call. */
27
+ stop: () => Promise<void>;
28
+ /** Mute/unmute the local microphone. */
29
+ setMuted: (muted: boolean) => void;
30
+ status: CallStatus;
31
+ isMuted: boolean;
32
+ /** Whether the agent is currently speaking (best-effort). */
33
+ isAgentSpeaking: boolean;
34
+ /** Local mic level 0..1 (sampled while active). */
35
+ volume: number;
36
+ /** Accumulated transcript chunks (interim + final), in arrival order. */
37
+ transcripts: TranscriptEvent[];
38
+ /** Last error, if any. */
39
+ error: OneInboxError | null;
40
+ /** Escape hatch to the underlying client. */
41
+ client: OneInbox;
42
+ }
43
+ /**
44
+ * Subscribes to the client's events and exposes them as React state.
45
+ *
46
+ * ```tsx
47
+ * const { start, stop, status, transcripts, isAgentSpeaking } = useOneInbox();
48
+ * ```
49
+ */
50
+ declare function useOneInbox(): UseOneInbox;
51
+
52
+ export { OneInboxProvider, type OneInboxProviderProps, type UseOneInbox, useOneInbox, useOneInboxClient };
package/dist/index.js ADDED
@@ -0,0 +1,85 @@
1
+ import { OneInbox } from '@oneinbox/web-sdk';
2
+ import { createContext, useMemo, useContext, useState, useRef, useEffect, useCallback } from 'react';
3
+ import { jsx } from 'react/jsx-runtime';
4
+
5
+ // src/index.tsx
6
+ var OneInboxContext = createContext(null);
7
+ function OneInboxProvider({
8
+ publishableKey,
9
+ children,
10
+ ...config
11
+ }) {
12
+ const baseUrl = config.baseUrl;
13
+ const client = useMemo(
14
+ () => new OneInbox(publishableKey, { baseUrl }),
15
+ [publishableKey, baseUrl]
16
+ );
17
+ return /* @__PURE__ */ jsx(OneInboxContext.Provider, { value: client, children });
18
+ }
19
+ function useOneInboxClient() {
20
+ const client = useContext(OneInboxContext);
21
+ if (!client) {
22
+ throw new Error("useOneInbox must be used within an <OneInboxProvider>.");
23
+ }
24
+ return client;
25
+ }
26
+ function useOneInbox() {
27
+ const client = useOneInboxClient();
28
+ const [status, setStatus] = useState(client.status);
29
+ const [isMuted, setIsMuted] = useState(client.isMuted());
30
+ const [isAgentSpeaking, setIsAgentSpeaking] = useState(false);
31
+ const [volume, setVolume] = useState(0);
32
+ const [transcripts, setTranscripts] = useState([]);
33
+ const [error, setError] = useState(null);
34
+ const clientRef = useRef(client);
35
+ clientRef.current = client;
36
+ useEffect(() => {
37
+ const offs = [
38
+ client.on("status", setStatus),
39
+ client.on("volume-level", setVolume),
40
+ client.on("error", setError),
41
+ client.on("transcript", (t) => setTranscripts((prev) => [...prev, t])),
42
+ client.on("speech-start", (who) => {
43
+ if (who === "agent") setIsAgentSpeaking(true);
44
+ }),
45
+ client.on("speech-end", (who) => {
46
+ if (who === "agent") setIsAgentSpeaking(false);
47
+ }),
48
+ client.on("call-start", () => {
49
+ setTranscripts([]);
50
+ setError(null);
51
+ setIsMuted(client.isMuted());
52
+ }),
53
+ client.on("call-end", () => {
54
+ setIsAgentSpeaking(false);
55
+ setVolume(0);
56
+ })
57
+ ];
58
+ return () => offs.forEach((off) => off());
59
+ }, [client]);
60
+ const start = useCallback(
61
+ (agentId, opts) => clientRef.current.start(agentId, opts),
62
+ []
63
+ );
64
+ const stop = useCallback(() => clientRef.current.stop(), []);
65
+ const setMuted = useCallback((muted) => {
66
+ clientRef.current.setMuted(muted);
67
+ setIsMuted(muted);
68
+ }, []);
69
+ return {
70
+ start,
71
+ stop,
72
+ setMuted,
73
+ status,
74
+ isMuted,
75
+ isAgentSpeaking,
76
+ volume,
77
+ transcripts,
78
+ error,
79
+ client
80
+ };
81
+ }
82
+
83
+ export { OneInboxProvider, useOneInbox, useOneInboxClient };
84
+ //# sourceMappingURL=index.js.map
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;AAqBA,IAAM,eAAA,GAAkB,cAA+B,IAAI,CAAA;AAiBpD,SAAS,gBAAA,CAAiB;AAAA,EAC/B,cAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAG;AACL,CAAA,EAA0B;AAExB,EAAA,MAAM,UAAU,MAAA,CAAO,OAAA;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AY,MAAM,SAAA,CAAU,QAAQ,IAAA,EAAK,EAAG,EAAE,CAAA;AAC3D,EAAA,MAAM,QAAA,GAAW,WAAA,CAAY,CAAC,KAAA,KAAmB;AAC/C,IAAA,SAAA,CAAU,OAAA,CAAQ,SAAS,KAAK,CAAA;AAChC,IAAA,UAAA,CAAW,KAAK,CAAA;AAAA,EAClB,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,eAAA;AAAA,IACA,MAAA;AAAA,IACA,WAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import {\n type CallStatus,\n OneInbox,\n type OneInboxConfig,\n type OneInboxError,\n type StartOptions,\n type TranscriptEvent,\n} from \"@oneinbox/web-sdk\";\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nexport type { CallStatus, OneInboxError, StartOptions, TranscriptEvent };\n\nconst OneInboxContext = createContext<OneInbox | null>(null);\n\nexport interface OneInboxProviderProps extends OneInboxConfig {\n /** Publishable key (`oi_pk_…`). */\n publishableKey: string;\n children: ReactNode;\n}\n\n/**\n * Provides a single `OneInbox` instance to the tree. Place near the root.\n *\n * ```tsx\n * <OneInboxProvider publishableKey=\"oi_pk_…\">\n * <App />\n * </OneInboxProvider>\n * ```\n */\nexport function OneInboxProvider({\n publishableKey,\n children,\n ...config\n}: OneInboxProviderProps) {\n // baseUrl is the only config field today; spread keeps it forward-compatible.\n const baseUrl = config.baseUrl;\n const client = useMemo(\n () => new OneInbox(publishableKey, { baseUrl }),\n [publishableKey, baseUrl],\n );\n return <OneInboxContext.Provider value={client}>{children}</OneInboxContext.Provider>;\n}\n\n/** Access the raw `OneInbox` client from context. Throws outside a provider. */\nexport function useOneInboxClient(): OneInbox {\n const client = useContext(OneInboxContext);\n if (!client) {\n throw new Error(\"useOneInbox must be used within an <OneInboxProvider>.\");\n }\n return client;\n}\n\nexport interface UseOneInbox {\n /** Start a call by agent id (publishable-key path). */\n start: (agentId: string, opts?: StartOptions) => Promise<void>;\n /** End the active call. */\n stop: () => Promise<void>;\n /** Mute/unmute the local microphone. */\n setMuted: (muted: boolean) => void;\n status: CallStatus;\n isMuted: boolean;\n /** Whether the agent is currently speaking (best-effort). */\n isAgentSpeaking: boolean;\n /** Local mic level 0..1 (sampled while active). */\n volume: number;\n /** Accumulated transcript chunks (interim + final), in arrival order. */\n transcripts: TranscriptEvent[];\n /** Last error, if any. */\n error: OneInboxError | null;\n /** Escape hatch to the underlying client. */\n client: OneInbox;\n}\n\n/**\n * Subscribes to the client's events and exposes them as React state.\n *\n * ```tsx\n * const { start, stop, status, transcripts, isAgentSpeaking } = useOneInbox();\n * ```\n */\nexport function useOneInbox(): UseOneInbox {\n const client = useOneInboxClient();\n\n const [status, setStatus] = useState<CallStatus>(client.status);\n const [isMuted, setIsMuted] = useState<boolean>(client.isMuted());\n const [isAgentSpeaking, setIsAgentSpeaking] = useState(false);\n const [volume, setVolume] = useState(0);\n const [transcripts, setTranscripts] = useState<TranscriptEvent[]>([]);\n const [error, setError] = useState<OneInboxError | null>(null);\n // Keep a ref so the imperative callbacks below don't re-create per render.\n const clientRef = useRef(client);\n clientRef.current = client;\n\n useEffect(() => {\n const offs = [\n client.on(\"status\", setStatus),\n client.on(\"volume-level\", setVolume),\n client.on(\"error\", setError),\n client.on(\"transcript\", (t) => setTranscripts((prev) => [...prev, t])),\n client.on(\"speech-start\", (who) => {\n if (who === \"agent\") setIsAgentSpeaking(true);\n }),\n client.on(\"speech-end\", (who) => {\n if (who === \"agent\") setIsAgentSpeaking(false);\n }),\n client.on(\"call-start\", () => {\n setTranscripts([]);\n setError(null);\n setIsMuted(client.isMuted());\n }),\n client.on(\"call-end\", () => {\n setIsAgentSpeaking(false);\n setVolume(0);\n }),\n ];\n return () => offs.forEach((off) => off());\n }, [client]);\n\n const start = useCallback(\n (agentId: string, opts?: StartOptions) => clientRef.current.start(agentId, opts),\n [],\n );\n const stop = useCallback(() => clientRef.current.stop(), []);\n const setMuted = useCallback((muted: boolean) => {\n clientRef.current.setMuted(muted);\n setIsMuted(muted);\n }, []);\n\n return {\n start,\n stop,\n setMuted,\n status,\n isMuted,\n isAgentSpeaking,\n volume,\n transcripts,\n error,\n client,\n };\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@oneinbox/web-sdk-react",
3
+ "version": "0.1.0-beta.1",
4
+ "description": "React bindings for @oneinbox/web-sdk — <OneInboxProvider> + useOneInbox().",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "dev": "tsup --watch",
28
+ "typecheck": "tsc --noEmit",
29
+ "prepublishOnly": "tsup"
30
+ },
31
+ "peerDependencies": {
32
+ "@oneinbox/web-sdk": "^0.1.0-beta.1",
33
+ "livekit-client": "^2.0.0",
34
+ "react": "^18.0.0 || ^19.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "@oneinbox/web-sdk": "^0.1.0-beta.1",
38
+ "@types/react": "^19.0.0",
39
+ "livekit-client": "^2.5.0",
40
+ "react": "^19.0.0",
41
+ "tsup": "^8.0.0",
42
+ "typescript": "^5.4.0"
43
+ },
44
+ "keywords": ["voice", "ai", "agents", "webrtc", "livekit", "react", "hooks"],
45
+ "author": "OneInbox",
46
+ "homepage": "https://www.npmjs.com/package/@oneinbox/web-sdk-react",
47
+ "license": "MIT",
48
+ "publishConfig": {
49
+ "access": "public"
50
+ }
51
+ }