@speeq/react 0.0.0-stage → 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 speeq contributors
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 CHANGED
@@ -1,3 +1,109 @@
1
- # Temporary Holding Version
1
+ # @speeq/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Headless conversation and audit hooks for React 18.2+ and 19.
4
+
5
+ ```sh
6
+ pnpm add @speeq/react@next
7
+ ```
8
+
9
+ ## Next.js App Router
10
+
11
+ Mount the server handler at `/api/speeq`. Wrap the part of the app that uses conversation hooks with a client component.
12
+
13
+ ```tsx
14
+ "use client";
15
+
16
+ import type { ReactNode } from "react";
17
+ import { SpeeqProvider } from "@speeq/react";
18
+ import { useRouter } from "next/navigation";
19
+
20
+ export function AppSpeeq({ children }: { children: ReactNode }) {
21
+ const router = useRouter();
22
+
23
+ return (
24
+ <SpeeqProvider
25
+ endpoint="/api/speeq"
26
+ onNavigate={({ href }) => {
27
+ const url = new URL(href, window.location.origin);
28
+ if (url.origin === window.location.origin) {
29
+ router.push(url.pathname + url.search + url.hash);
30
+ }
31
+ }}
32
+ >
33
+ {children}
34
+ </SpeeqProvider>
35
+ );
36
+ }
37
+ ```
38
+
39
+ For a provider-owned client, `endpoint`, `languages`, `language`, `speech`, `speakReplies`, `autoSendOnFinal`, `persistSession`, and `fetch` are read once. The provider calls the latest `onNavigate` and `getContext`. Pass `client` to use an existing client with its own options and lifecycle.
40
+
41
+ Server rendering and hydration use a stable initial snapshot with speech unavailable. After hydration, the hooks read the live snapshot, including browser speech support.
42
+
43
+ ## Conversation hooks
44
+
45
+ | Field | Use |
46
+ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------ |
47
+ | `state` | Render idle, listening, thinking, speaking, or error feedback. |
48
+ | `messages`, `interimTranscript` | Show conversation history and live or staged transcription. |
49
+ | `pendingConfirmation` | Show the proposed action and let the user approve or decline. |
50
+ | `error`, `activeTools` | Show the current error and running tools. |
51
+ | `language`, `languages`, `support` | Render language choices and speech controls. |
52
+ | `sessionId`, `config`, `client` | Access the session ID, server configuration, or underlying client. |
53
+ | `sendText`, `startListening`, `stopListening`, `cancel`, `setLanguage`, `confirm`, `speak` | Stable actions for the current client. |
54
+
55
+ ```tsx
56
+ import { useSpeeq, useSpeeqContext, useSpeeqEvent } from "@speeq/react";
57
+
58
+ export function QuestionHelp({ questionId }: { questionId: string }) {
59
+ useSpeeqContext({ questionId });
60
+ useSpeeqEvent("navigate", ({ routeId }) => console.info("Opened", routeId));
61
+ const { sendText } = useSpeeq();
62
+
63
+ return <button onClick={() => void sendText("Explain this question")}>Get help</button>;
64
+ }
65
+ ```
66
+
67
+ Mounted `useSpeeqContext` calls contribute fields to `context.data`. Later registrations take precedence for overlapping fields. `useSpeeqEvent` calls the current handler without resubscribing when only that handler changes.
68
+
69
+ ## Audit hooks
70
+
71
+ Use the hooks in a protected admin page with server-side `audit.authorize` configured. The audit hooks work independently of `SpeeqProvider` and send cookies by default.
72
+
73
+ ```tsx
74
+ import { useState } from "react";
75
+ import { useAuditSession, useAuditSessions } from "@speeq/react";
76
+
77
+ export function AuditPage() {
78
+ const [selected, setSelected] = useState<string | null>(null);
79
+ const options = { endpoint: "/api/speeq" };
80
+ const list = useAuditSessions({ ...options, filter: { limit: 25 } });
81
+ const detail = useAuditSession(selected, options);
82
+
83
+ return (
84
+ <>
85
+ <p>{list.error?.message ?? detail.error?.message}</p>
86
+ <button onClick={list.refresh}>Refresh sessions</button>
87
+ <ul>
88
+ {list.sessions.map(({ id, preview }) => (
89
+ <li key={id}>
90
+ <button onClick={() => setSelected(id)}>{preview ?? id}</button>
91
+ </li>
92
+ ))}
93
+ </ul>
94
+ <button onClick={list.loadMore} disabled={list.loading || !list.hasMore}>
95
+ Load more
96
+ </button>
97
+ <ol>
98
+ {detail.events.map((event) => (
99
+ <li key={event.id}>{event.type}</li>
100
+ ))}
101
+ </ol>
102
+ </>
103
+ );
104
+ }
105
+ ```
106
+
107
+ Use `useSpeeqAudit` to make direct audit calls from your own hooks. It memoizes by endpoint and credentials. Fetch and headers are captured when that client is created.
108
+
109
+ [Related guide or reference](../../docs/reference/react.md)
package/dist/index.cjs ADDED
@@ -0,0 +1,279 @@
1
+ "use client";
2
+ "use strict";
3
+ "use client";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/index.ts
23
+ var src_exports = {};
24
+ __export(src_exports, {
25
+ SpeeqError: () => import_client3.SpeeqError,
26
+ SpeeqProvider: () => SpeeqProvider,
27
+ isSpeeqError: () => import_client3.isSpeeqError,
28
+ useAuditSession: () => useAuditSession,
29
+ useAuditSessions: () => useAuditSessions,
30
+ useSpeeq: () => useSpeeq,
31
+ useSpeeqAudit: () => useSpeeqAudit,
32
+ useSpeeqContext: () => useSpeeqContext,
33
+ useSpeeqEvent: () => useSpeeqEvent
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_client3 = require("@speeq/client");
37
+
38
+ // src/audit-hooks.ts
39
+ var import_client = require("@speeq/client");
40
+ var import_react = require("react");
41
+ function useSpeeqAudit(options) {
42
+ const latest = (0, import_react.useRef)(options);
43
+ latest.current = options;
44
+ const { endpoint, credentials } = options;
45
+ return (0, import_react.useMemo)(
46
+ () => (0, import_client.createAuditClient)({ ...latest.current, endpoint, credentials }),
47
+ [endpoint, credentials]
48
+ );
49
+ }
50
+ function requestError(error) {
51
+ return (0, import_client.isSpeeqError)(error) ? error : new import_client.SpeeqError("INTERNAL");
52
+ }
53
+ var emptyPage = { sessions: [], nextCursor: null };
54
+ function useAuditSessions(options) {
55
+ const client = useSpeeqAudit(options);
56
+ const { userId, from, to, limit } = options.filter ?? {};
57
+ const [version, setVersion] = (0, import_react.useState)(0);
58
+ const key = JSON.stringify({ userId, from, to, limit, version });
59
+ const [state, setState] = (0, import_react.useState)({
60
+ data: emptyPage,
61
+ loading: true,
62
+ error: null
63
+ });
64
+ const load = (0, import_react.useRef)(() => {
65
+ });
66
+ (0, import_react.useEffect)(() => {
67
+ const filter = JSON.parse(key);
68
+ let pending;
69
+ let active = true;
70
+ load.current = (cursor) => {
71
+ if (!active || pending) return;
72
+ const controller = new AbortController();
73
+ pending = controller;
74
+ setState((current) => ({
75
+ data: cursor ? current.data : emptyPage,
76
+ loading: true,
77
+ error: null
78
+ }));
79
+ void client.listSessions({ ...filter, cursor }, controller.signal).then(
80
+ (page) => {
81
+ if (active)
82
+ setState((current) => ({
83
+ data: cursor ? { ...page, sessions: [...current.data.sessions, ...page.sessions] } : page,
84
+ loading: false,
85
+ error: null
86
+ }));
87
+ },
88
+ (error) => {
89
+ if (active)
90
+ setState((current) => ({ ...current, loading: false, error: requestError(error) }));
91
+ }
92
+ ).finally(() => {
93
+ pending = void 0;
94
+ });
95
+ };
96
+ load.current();
97
+ return () => {
98
+ active = false;
99
+ pending?.abort();
100
+ };
101
+ }, [client, key]);
102
+ return {
103
+ sessions: state.data.sessions,
104
+ loading: state.loading,
105
+ error: state.error,
106
+ hasMore: !!state.data.nextCursor,
107
+ loadMore() {
108
+ if (!state.loading && state.data.nextCursor) load.current(state.data.nextCursor);
109
+ },
110
+ refresh() {
111
+ setVersion((current) => current + 1);
112
+ }
113
+ };
114
+ }
115
+ var emptyDetail = { session: null, events: [] };
116
+ function useAuditSession(sessionId, options) {
117
+ const client = useSpeeqAudit(options);
118
+ const [version, setVersion] = (0, import_react.useState)(0);
119
+ const [state, setState] = (0, import_react.useState)({
120
+ data: emptyDetail,
121
+ loading: sessionId !== null,
122
+ error: null
123
+ });
124
+ (0, import_react.useEffect)(() => {
125
+ if (sessionId === null) {
126
+ setState({ data: emptyDetail, loading: false, error: null });
127
+ return;
128
+ }
129
+ const controller = new AbortController();
130
+ setState({ data: emptyDetail, loading: true, error: null });
131
+ void client.getSession(sessionId, controller.signal).then(
132
+ (data) => {
133
+ if (!controller.signal.aborted) setState({ data, loading: false, error: null });
134
+ },
135
+ (error) => {
136
+ if (!controller.signal.aborted)
137
+ setState({ data: emptyDetail, loading: false, error: requestError(error) });
138
+ }
139
+ );
140
+ return () => controller.abort();
141
+ }, [client, sessionId, version]);
142
+ return {
143
+ ...sessionId === null ? emptyDetail : state.data,
144
+ loading: sessionId !== null && state.loading,
145
+ error: sessionId === null ? null : state.error,
146
+ refresh() {
147
+ setVersion((current) => current + 1);
148
+ }
149
+ };
150
+ }
151
+
152
+ // src/hooks.ts
153
+ var import_react3 = require("react");
154
+
155
+ // src/provider.tsx
156
+ var import_client2 = require("@speeq/client");
157
+ var import_react2 = require("react");
158
+
159
+ // src/context-registry.ts
160
+ function createContextRegistry(base) {
161
+ const entries = /* @__PURE__ */ new Set();
162
+ return {
163
+ register(read) {
164
+ entries.add(read);
165
+ return () => {
166
+ entries.delete(read);
167
+ };
168
+ },
169
+ getContext() {
170
+ const context = base();
171
+ if (!entries.size) return context;
172
+ return {
173
+ ...context,
174
+ data: Object.assign({}, context?.data, ...Array.from(entries, (read) => read()))
175
+ };
176
+ }
177
+ };
178
+ }
179
+
180
+ // src/provider.tsx
181
+ var import_jsx_runtime = require("react/jsx-runtime");
182
+ var ProviderContext = (0, import_react2.createContext)(null);
183
+ var serverSnapshots = /* @__PURE__ */ new WeakMap();
184
+ function initialServerSnapshot(client) {
185
+ let snapshot = serverSnapshots.get(client);
186
+ if (!snapshot) {
187
+ snapshot = {
188
+ ...client.getSnapshot(),
189
+ support: { speechInput: false, speechOutput: false, voiceForLanguage: null }
190
+ };
191
+ serverSnapshots.set(client, snapshot);
192
+ }
193
+ return snapshot;
194
+ }
195
+ function SpeeqProvider(props) {
196
+ const navigate = (0, import_react2.useRef)(props.onNavigate);
197
+ const context = (0, import_react2.useRef)(props.getContext);
198
+ navigate.current = props.onNavigate;
199
+ context.current = props.getContext;
200
+ const [registry] = (0, import_react2.useState)(() => createContextRegistry(() => context.current?.()));
201
+ const [initial] = (0, import_react2.useState)(() => ({
202
+ client: props.client ?? (0, import_client2.createSpeeqClient)({
203
+ ...props,
204
+ onNavigate: (action) => navigate.current?.(action),
205
+ getContext: registry.getContext
206
+ }),
207
+ owned: props.client === void 0
208
+ }));
209
+ const client = props.client ?? initial.client;
210
+ const owned = initial.owned && client === initial.client && props.client === void 0;
211
+ (0, import_react2.useEffect)(() => {
212
+ if (owned)
213
+ return () => {
214
+ client.endCall();
215
+ client.cancel();
216
+ };
217
+ }, [owned, client]);
218
+ const value = (0, import_react2.useMemo)(() => {
219
+ const snapshot = initialServerSnapshot(client);
220
+ return { client, getServerSnapshot: () => snapshot, registry };
221
+ }, [client, registry]);
222
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProviderContext.Provider, { value, children: props.children });
223
+ }
224
+ function useProvider(hook) {
225
+ const value = (0, import_react2.useContext)(ProviderContext);
226
+ if (!value) throw new Error(`${hook} must be used inside <SpeeqProvider>`);
227
+ return value;
228
+ }
229
+
230
+ // src/hooks.ts
231
+ function useSpeeq() {
232
+ const { client, getServerSnapshot } = useProvider("useSpeeq");
233
+ const store = (0, import_react3.useMemo)(
234
+ () => ({
235
+ subscribe: client.subscribe.bind(client),
236
+ getSnapshot: client.getSnapshot.bind(client),
237
+ actions: {
238
+ client,
239
+ sendText: client.sendText.bind(client),
240
+ startListening: client.startListening.bind(client),
241
+ stopListening: client.stopListening.bind(client),
242
+ startCall: client.startCall.bind(client),
243
+ endCall: client.endCall.bind(client),
244
+ cancel: client.cancel.bind(client),
245
+ setLanguage: client.setLanguage.bind(client),
246
+ confirm: client.confirm.bind(client),
247
+ speak: client.speak.bind(client)
248
+ }
249
+ }),
250
+ [client]
251
+ );
252
+ const snapshot = (0, import_react3.useSyncExternalStore)(store.subscribe, store.getSnapshot, getServerSnapshot);
253
+ return { ...snapshot, ...store.actions };
254
+ }
255
+ function useSpeeqContext(data) {
256
+ const { registry } = useProvider("useSpeeqContext");
257
+ const current = (0, import_react3.useRef)(data);
258
+ current.current = data;
259
+ (0, import_react3.useEffect)(() => registry.register(() => current.current), [registry]);
260
+ }
261
+ function useSpeeqEvent(event, handler) {
262
+ const { client } = useProvider("useSpeeqEvent");
263
+ const current = (0, import_react3.useRef)(handler);
264
+ current.current = handler;
265
+ (0, import_react3.useEffect)(() => client.on(event, (payload) => current.current(payload)), [client, event]);
266
+ }
267
+ // Annotate the CommonJS export names for ESM import in node:
268
+ 0 && (module.exports = {
269
+ SpeeqError,
270
+ SpeeqProvider,
271
+ isSpeeqError,
272
+ useAuditSession,
273
+ useAuditSessions,
274
+ useSpeeq,
275
+ useSpeeqAudit,
276
+ useSpeeqContext,
277
+ useSpeeqEvent
278
+ });
279
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/audit-hooks.ts","../src/hooks.ts","../src/provider.tsx","../src/context-registry.ts"],"sourcesContent":["\"use client\";\nexport type {\n AuditClient,\n AuditClientOptions,\n AuditListParams,\n ChatMessage,\n ConversationEvent,\n NavigateAction,\n PendingConfirmation,\n SessionSummary,\n SpeeqClient,\n SpeeqClientEvents,\n SpeeqClientOptions,\n SpeeqSnapshot,\n SpeeqState,\n} from \"@speeq/client\";\nexport { isSpeeqError, SpeeqError } from \"@speeq/client\";\nexport type {\n UseAuditSessionResult,\n UseAuditSessionsOptions,\n UseAuditSessionsResult,\n} from \"./audit-hooks.js\";\nexport { useAuditSession, useAuditSessions, useSpeeqAudit } from \"./audit-hooks.js\";\nexport type { UseSpeeqResult } from \"./hooks.js\";\nexport { useSpeeq, useSpeeqContext, useSpeeqEvent } from \"./hooks.js\";\nexport type { SpeeqProviderProps } from \"./provider.js\";\nexport { SpeeqProvider } from \"./provider.js\";\n","import {\n type AuditClient,\n type AuditClientOptions,\n type AuditListParams,\n type ConversationEvent,\n createAuditClient,\n isSpeeqError,\n type SessionSummary,\n SpeeqError,\n} from \"@speeq/client\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\n\n/** Creates an audit client for the endpoint and credential mode. */\nexport function useSpeeqAudit(options: AuditClientOptions): AuditClient {\n const latest = useRef(options);\n latest.current = options;\n const { endpoint, credentials } = options;\n return useMemo(\n () => createAuditClient({ ...latest.current, endpoint, credentials }),\n [endpoint, credentials],\n );\n}\n\n/** Audit connection and optional session list filter. */\nexport interface UseAuditSessionsOptions extends AuditClientOptions {\n filter?: Omit<AuditListParams, \"cursor\">;\n}\n\n/** Current session list with pagination and refresh controls. */\nexport interface UseAuditSessionsResult {\n sessions: SessionSummary[];\n loading: boolean;\n error: SpeeqError | null;\n hasMore: boolean;\n loadMore(): void;\n refresh(): void;\n}\n\ninterface RequestState<T> {\n data: T;\n loading: boolean;\n error: SpeeqError | null;\n}\n\nfunction requestError(error: unknown) {\n return isSpeeqError(error) ? error : new SpeeqError(\"INTERNAL\");\n}\n\nconst emptyPage = { sessions: [] as SessionSummary[], nextCursor: null as string | null };\n\n/** Loads session summaries and appends additional pages on demand. */\nexport function useAuditSessions(options: UseAuditSessionsOptions): UseAuditSessionsResult {\n const client = useSpeeqAudit(options);\n const { userId, from, to, limit } = options.filter ?? {};\n const [version, setVersion] = useState(0);\n const key = JSON.stringify({ userId, from, to, limit, version });\n const [state, setState] = useState<RequestState<typeof emptyPage>>({\n data: emptyPage,\n loading: true,\n error: null,\n });\n const load = useRef<(cursor?: string) => void>(() => {});\n useEffect(() => {\n const filter = JSON.parse(key) as AuditListParams;\n let pending: AbortController | undefined;\n let active = true;\n load.current = (cursor) => {\n if (!active || pending) return;\n const controller = new AbortController();\n pending = controller;\n setState((current) => ({\n data: cursor ? current.data : emptyPage,\n loading: true,\n error: null,\n }));\n void client\n .listSessions({ ...filter, cursor }, controller.signal)\n .then(\n (page) => {\n if (active)\n setState((current) => ({\n data: cursor\n ? { ...page, sessions: [...current.data.sessions, ...page.sessions] }\n : page,\n loading: false,\n error: null,\n }));\n },\n (error) => {\n if (active)\n setState((current) => ({ ...current, loading: false, error: requestError(error) }));\n },\n )\n .finally(() => {\n pending = undefined;\n });\n };\n load.current();\n return () => {\n active = false;\n pending?.abort();\n };\n }, [client, key]);\n return {\n sessions: state.data.sessions,\n loading: state.loading,\n error: state.error,\n hasMore: !!state.data.nextCursor,\n loadMore() {\n if (!state.loading && state.data.nextCursor) load.current(state.data.nextCursor);\n },\n refresh() {\n setVersion((current) => current + 1);\n },\n };\n}\n\n/** Current session, its ordered events and a reload control. */\nexport interface UseAuditSessionResult {\n session: SessionSummary | null;\n events: ConversationEvent[];\n loading: boolean;\n error: SpeeqError | null;\n refresh(): void;\n}\n\nconst emptyDetail = { session: null, events: [] as ConversationEvent[] };\n\n/** Loads and refreshes the event history for a selected session. */\nexport function useAuditSession(\n sessionId: string | null,\n options: AuditClientOptions,\n): UseAuditSessionResult {\n const client = useSpeeqAudit(options);\n const [version, setVersion] = useState(0);\n const [state, setState] = useState<\n RequestState<Pick<UseAuditSessionResult, \"session\" | \"events\">>\n >({\n data: emptyDetail,\n loading: sessionId !== null,\n error: null,\n });\n // biome-ignore lint/correctness/useExhaustiveDependencies: Refresh reloads the same selected session.\n useEffect(() => {\n if (sessionId === null) {\n setState({ data: emptyDetail, loading: false, error: null });\n return;\n }\n const controller = new AbortController();\n setState({ data: emptyDetail, loading: true, error: null });\n void client.getSession(sessionId, controller.signal).then(\n (data) => {\n if (!controller.signal.aborted) setState({ data, loading: false, error: null });\n },\n (error) => {\n if (!controller.signal.aborted)\n setState({ data: emptyDetail, loading: false, error: requestError(error) });\n },\n );\n return () => controller.abort();\n }, [client, sessionId, version]);\n return {\n ...(sessionId === null ? emptyDetail : state.data),\n loading: sessionId !== null && state.loading,\n error: sessionId === null ? null : state.error,\n refresh() {\n setVersion((current) => current + 1);\n },\n };\n}\n","import type { SpeeqClient, SpeeqClientEvents, SpeeqSnapshot } from \"@speeq/client\";\nimport { useEffect, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport { useProvider } from \"./provider.js\";\n\n/** Live client snapshot and stable client actions. */\nexport interface UseSpeeqResult extends SpeeqSnapshot {\n client: SpeeqClient;\n sendText: SpeeqClient[\"sendText\"];\n startListening: SpeeqClient[\"startListening\"];\n stopListening: SpeeqClient[\"stopListening\"];\n startCall: SpeeqClient[\"startCall\"];\n endCall: SpeeqClient[\"endCall\"];\n cancel: SpeeqClient[\"cancel\"];\n setLanguage: SpeeqClient[\"setLanguage\"];\n confirm: SpeeqClient[\"confirm\"];\n speak: SpeeqClient[\"speak\"];\n}\n\n/** Reads the current snapshot and actions of the provider's client. */\nexport function useSpeeq(): UseSpeeqResult {\n const { client, getServerSnapshot } = useProvider(\"useSpeeq\");\n const store = useMemo(\n () => ({\n subscribe: client.subscribe.bind(client),\n getSnapshot: client.getSnapshot.bind(client),\n actions: {\n client,\n sendText: client.sendText.bind(client),\n startListening: client.startListening.bind(client),\n stopListening: client.stopListening.bind(client),\n startCall: client.startCall.bind(client),\n endCall: client.endCall.bind(client),\n cancel: client.cancel.bind(client),\n setLanguage: client.setLanguage.bind(client),\n confirm: client.confirm.bind(client),\n speak: client.speak.bind(client),\n },\n }),\n [client],\n );\n const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);\n return { ...snapshot, ...store.actions };\n}\n\n/** Registers data from the current page for subsequent conversation requests. */\nexport function useSpeeqContext(data: Record<string, unknown>): void {\n const { registry } = useProvider(\"useSpeeqContext\");\n const current = useRef(data);\n current.current = data;\n useEffect(() => registry.register(() => current.current), [registry]);\n}\n\n/** Subscribes to a client event and calls the latest handler. */\nexport function useSpeeqEvent<K extends keyof SpeeqClientEvents>(\n event: K,\n handler: (payload: SpeeqClientEvents[K]) => void,\n): void {\n const { client } = useProvider(\"useSpeeqEvent\");\n const current = useRef(handler);\n current.current = handler;\n useEffect(() => client.on(event, (payload) => current.current(payload)), [client, event]);\n}\n","import {\n createSpeeqClient,\n type SpeeqClient,\n type SpeeqClientOptions,\n type SpeeqSnapshot,\n} from \"@speeq/client\";\nimport {\n createContext,\n type JSX,\n type ReactNode,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createContextRegistry } from \"./context-registry.js\";\n\n/** Configuration for a provider-owned client or an existing client. */\nexport interface SpeeqProviderProps extends SpeeqClientOptions {\n children: ReactNode;\n /** Use an existing client instead of creating one. The other options are then ignored. */\n client?: SpeeqClient;\n}\n\nconst ProviderContext = createContext<{\n client: SpeeqClient;\n getServerSnapshot: () => SpeeqSnapshot;\n registry: ReturnType<typeof createContextRegistry>;\n} | null>(null);\n\nconst serverSnapshots = new WeakMap<SpeeqClient, SpeeqSnapshot>();\n\nfunction initialServerSnapshot(client: SpeeqClient) {\n let snapshot = serverSnapshots.get(client);\n if (!snapshot) {\n snapshot = {\n ...client.getSnapshot(),\n support: { speechInput: false, speechOutput: false, voiceForLanguage: null },\n };\n serverSnapshots.set(client, snapshot);\n }\n return snapshot;\n}\n\n/** Makes a speeq client available to descendant hooks. */\nexport function SpeeqProvider(props: SpeeqProviderProps): JSX.Element {\n const navigate = useRef(props.onNavigate);\n const context = useRef(props.getContext);\n navigate.current = props.onNavigate;\n context.current = props.getContext;\n const [registry] = useState(() => createContextRegistry(() => context.current?.()));\n const [initial] = useState(() => ({\n client:\n props.client ??\n createSpeeqClient({\n ...props,\n onNavigate: (action) => navigate.current?.(action),\n getContext: registry.getContext,\n }),\n owned: props.client === undefined,\n }));\n const client = props.client ?? initial.client;\n const owned = initial.owned && client === initial.client && props.client === undefined;\n useEffect(() => {\n if (owned)\n return () => {\n client.endCall(); // never leave the microphone on after the provider is gone\n client.cancel();\n };\n }, [owned, client]);\n const value = useMemo(() => {\n const snapshot = initialServerSnapshot(client);\n return { client, getServerSnapshot: () => snapshot, registry };\n }, [client, registry]);\n return <ProviderContext.Provider value={value}>{props.children}</ProviderContext.Provider>;\n}\n\n/** Reads the provider store for a named hook. */\nexport function useProvider(hook: string) {\n const value = useContext(ProviderContext);\n if (!value) throw new Error(`${hook} must be used inside <SpeeqProvider>`);\n return value;\n}\n","import type { SpeeqClientOptions } from \"@speeq/client\";\n\ntype GetContext = NonNullable<SpeeqClientOptions[\"getContext\"]>;\n\n/** Collects committed context hooks in registration order. */\nexport function createContextRegistry(base: GetContext) {\n const entries = new Set<() => Record<string, unknown>>();\n return {\n register(read: () => Record<string, unknown>) {\n entries.add(read);\n return () => {\n entries.delete(read);\n };\n },\n getContext() {\n const context = base();\n if (!entries.size) return context;\n return {\n ...context,\n data: Object.assign({}, context?.data, ...Array.from(entries, (read) => read())),\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,IAAAA,iBAAyC;;;AChBzC,oBASO;AACP,mBAAqD;AAG9C,SAAS,cAAc,SAA0C;AACtE,QAAM,aAAS,qBAAO,OAAO;AAC7B,SAAO,UAAU;AACjB,QAAM,EAAE,UAAU,YAAY,IAAI;AAClC,aAAO;AAAA,IACL,UAAM,iCAAkB,EAAE,GAAG,OAAO,SAAS,UAAU,YAAY,CAAC;AAAA,IACpE,CAAC,UAAU,WAAW;AAAA,EACxB;AACF;AAuBA,SAAS,aAAa,OAAgB;AACpC,aAAO,4BAAa,KAAK,IAAI,QAAQ,IAAI,yBAAW,UAAU;AAChE;AAEA,IAAM,YAAY,EAAE,UAAU,CAAC,GAAuB,YAAY,KAAsB;AAGjF,SAAS,iBAAiB,SAA0D;AACzF,QAAM,SAAS,cAAc,OAAO;AACpC,QAAM,EAAE,QAAQ,MAAM,IAAI,MAAM,IAAI,QAAQ,UAAU,CAAC;AACvD,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,CAAC;AACxC,QAAM,MAAM,KAAK,UAAU,EAAE,QAAQ,MAAM,IAAI,OAAO,QAAQ,CAAC;AAC/D,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAyC;AAAA,IACjE,MAAM;AAAA,IACN,SAAS;AAAA,IACT,OAAO;AAAA,EACT,CAAC;AACD,QAAM,WAAO,qBAAkC,MAAM;AAAA,EAAC,CAAC;AACvD,8BAAU,MAAM;AACd,UAAM,SAAS,KAAK,MAAM,GAAG;AAC7B,QAAI;AACJ,QAAI,SAAS;AACb,SAAK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,GAAG,UAAU,GAAG,MAAM,QAAQ;AACzC;AAGO,SAAS,gBAAgB,MAAqC;AACnE,QAAM,EAAE,SAAS,IAAI,YAAY,iBAAiB;AAClD,QAAM,cAAU,sBAAO,IAAI;AAC3B,UAAQ,UAAU;AAClB,+BAAU,MAAM,SAAS,SAAS,MAAM,QAAQ,OAAO,GAAG,CAAC,QAAQ,CAAC;AACtE;AAGO,SAAS,cACd,OACA,SACM;AACN,QAAM,EAAE,OAAO,IAAI,YAAY,eAAe;AAC9C,QAAM,cAAU,sBAAO,OAAO;AAC9B,UAAQ,UAAU;AAClB,+BAAU,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,QAAQ,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,CAAC;AAC1F;","names":["import_client","import_react","import_client","import_react"]}
@@ -0,0 +1,63 @@
1
+ import { SessionSummary, ConversationEvent, SpeeqError, AuditClientOptions, AuditListParams, AuditClient, SpeeqSnapshot, SpeeqClient, SpeeqClientEvents, SpeeqClientOptions } from '@speeq/client';
2
+ export { AuditClient, AuditClientOptions, AuditListParams, ChatMessage, ConversationEvent, NavigateAction, PendingConfirmation, SessionSummary, SpeeqClient, SpeeqClientEvents, SpeeqClientOptions, SpeeqError, SpeeqSnapshot, SpeeqState, isSpeeqError } from '@speeq/client';
3
+ import { ReactNode, JSX } from 'react';
4
+
5
+ /** Creates an audit client for the endpoint and credential mode. */
6
+ declare function useSpeeqAudit(options: AuditClientOptions): AuditClient;
7
+ /** Audit connection and optional session list filter. */
8
+ interface UseAuditSessionsOptions extends AuditClientOptions {
9
+ filter?: Omit<AuditListParams, "cursor">;
10
+ }
11
+ /** Current session list with pagination and refresh controls. */
12
+ interface UseAuditSessionsResult {
13
+ sessions: SessionSummary[];
14
+ loading: boolean;
15
+ error: SpeeqError | null;
16
+ hasMore: boolean;
17
+ loadMore(): void;
18
+ refresh(): void;
19
+ }
20
+ /** Loads session summaries and appends additional pages on demand. */
21
+ declare function useAuditSessions(options: UseAuditSessionsOptions): UseAuditSessionsResult;
22
+ /** Current session, its ordered events and a reload control. */
23
+ interface UseAuditSessionResult {
24
+ session: SessionSummary | null;
25
+ events: ConversationEvent[];
26
+ loading: boolean;
27
+ error: SpeeqError | null;
28
+ refresh(): void;
29
+ }
30
+ /** Loads and refreshes the event history for a selected session. */
31
+ declare function useAuditSession(sessionId: string | null, options: AuditClientOptions): UseAuditSessionResult;
32
+
33
+ /** Live client snapshot and stable client actions. */
34
+ interface UseSpeeqResult extends SpeeqSnapshot {
35
+ client: SpeeqClient;
36
+ sendText: SpeeqClient["sendText"];
37
+ startListening: SpeeqClient["startListening"];
38
+ stopListening: SpeeqClient["stopListening"];
39
+ startCall: SpeeqClient["startCall"];
40
+ endCall: SpeeqClient["endCall"];
41
+ cancel: SpeeqClient["cancel"];
42
+ setLanguage: SpeeqClient["setLanguage"];
43
+ confirm: SpeeqClient["confirm"];
44
+ speak: SpeeqClient["speak"];
45
+ }
46
+ /** Reads the current snapshot and actions of the provider's client. */
47
+ declare function useSpeeq(): UseSpeeqResult;
48
+ /** Registers data from the current page for subsequent conversation requests. */
49
+ declare function useSpeeqContext(data: Record<string, unknown>): void;
50
+ /** Subscribes to a client event and calls the latest handler. */
51
+ declare function useSpeeqEvent<K extends keyof SpeeqClientEvents>(event: K, handler: (payload: SpeeqClientEvents[K]) => void): void;
52
+
53
+ /** Configuration for a provider-owned client or an existing client. */
54
+ interface SpeeqProviderProps extends SpeeqClientOptions {
55
+ children: ReactNode;
56
+ /** Use an existing client instead of creating one. The other options are then ignored. */
57
+ client?: SpeeqClient;
58
+ }
59
+ /** Makes a speeq client available to descendant hooks. */
60
+ declare function SpeeqProvider(props: SpeeqProviderProps): JSX.Element;
61
+
62
+ export { SpeeqProvider, useAuditSession, useAuditSessions, useSpeeq, useSpeeqAudit, useSpeeqContext, useSpeeqEvent };
63
+ export type { SpeeqProviderProps, UseAuditSessionResult, UseAuditSessionsOptions, UseAuditSessionsResult, UseSpeeqResult };
@@ -0,0 +1,63 @@
1
+ import { SessionSummary, ConversationEvent, SpeeqError, AuditClientOptions, AuditListParams, AuditClient, SpeeqSnapshot, SpeeqClient, SpeeqClientEvents, SpeeqClientOptions } from '@speeq/client';
2
+ export { AuditClient, AuditClientOptions, AuditListParams, ChatMessage, ConversationEvent, NavigateAction, PendingConfirmation, SessionSummary, SpeeqClient, SpeeqClientEvents, SpeeqClientOptions, SpeeqError, SpeeqSnapshot, SpeeqState, isSpeeqError } from '@speeq/client';
3
+ import { ReactNode, JSX } from 'react';
4
+
5
+ /** Creates an audit client for the endpoint and credential mode. */
6
+ declare function useSpeeqAudit(options: AuditClientOptions): AuditClient;
7
+ /** Audit connection and optional session list filter. */
8
+ interface UseAuditSessionsOptions extends AuditClientOptions {
9
+ filter?: Omit<AuditListParams, "cursor">;
10
+ }
11
+ /** Current session list with pagination and refresh controls. */
12
+ interface UseAuditSessionsResult {
13
+ sessions: SessionSummary[];
14
+ loading: boolean;
15
+ error: SpeeqError | null;
16
+ hasMore: boolean;
17
+ loadMore(): void;
18
+ refresh(): void;
19
+ }
20
+ /** Loads session summaries and appends additional pages on demand. */
21
+ declare function useAuditSessions(options: UseAuditSessionsOptions): UseAuditSessionsResult;
22
+ /** Current session, its ordered events and a reload control. */
23
+ interface UseAuditSessionResult {
24
+ session: SessionSummary | null;
25
+ events: ConversationEvent[];
26
+ loading: boolean;
27
+ error: SpeeqError | null;
28
+ refresh(): void;
29
+ }
30
+ /** Loads and refreshes the event history for a selected session. */
31
+ declare function useAuditSession(sessionId: string | null, options: AuditClientOptions): UseAuditSessionResult;
32
+
33
+ /** Live client snapshot and stable client actions. */
34
+ interface UseSpeeqResult extends SpeeqSnapshot {
35
+ client: SpeeqClient;
36
+ sendText: SpeeqClient["sendText"];
37
+ startListening: SpeeqClient["startListening"];
38
+ stopListening: SpeeqClient["stopListening"];
39
+ startCall: SpeeqClient["startCall"];
40
+ endCall: SpeeqClient["endCall"];
41
+ cancel: SpeeqClient["cancel"];
42
+ setLanguage: SpeeqClient["setLanguage"];
43
+ confirm: SpeeqClient["confirm"];
44
+ speak: SpeeqClient["speak"];
45
+ }
46
+ /** Reads the current snapshot and actions of the provider's client. */
47
+ declare function useSpeeq(): UseSpeeqResult;
48
+ /** Registers data from the current page for subsequent conversation requests. */
49
+ declare function useSpeeqContext(data: Record<string, unknown>): void;
50
+ /** Subscribes to a client event and calls the latest handler. */
51
+ declare function useSpeeqEvent<K extends keyof SpeeqClientEvents>(event: K, handler: (payload: SpeeqClientEvents[K]) => void): void;
52
+
53
+ /** Configuration for a provider-owned client or an existing client. */
54
+ interface SpeeqProviderProps extends SpeeqClientOptions {
55
+ children: ReactNode;
56
+ /** Use an existing client instead of creating one. The other options are then ignored. */
57
+ client?: SpeeqClient;
58
+ }
59
+ /** Makes a speeq client available to descendant hooks. */
60
+ declare function SpeeqProvider(props: SpeeqProviderProps): JSX.Element;
61
+
62
+ export { SpeeqProvider, useAuditSession, useAuditSessions, useSpeeq, useSpeeqAudit, useSpeeqContext, useSpeeqEvent };
63
+ export type { SpeeqProviderProps, UseAuditSessionResult, UseAuditSessionsOptions, UseAuditSessionsResult, UseSpeeqResult };
package/dist/index.js ADDED
@@ -0,0 +1,260 @@
1
+ "use client";
2
+ "use client";
3
+
4
+ // src/index.ts
5
+ import { isSpeeqError as isSpeeqError2, SpeeqError as SpeeqError2 } from "@speeq/client";
6
+
7
+ // src/audit-hooks.ts
8
+ import {
9
+ createAuditClient,
10
+ isSpeeqError,
11
+ SpeeqError
12
+ } from "@speeq/client";
13
+ import { useEffect, useMemo, useRef, useState } from "react";
14
+ function useSpeeqAudit(options) {
15
+ const latest = useRef(options);
16
+ latest.current = options;
17
+ const { endpoint, credentials } = options;
18
+ return useMemo(
19
+ () => createAuditClient({ ...latest.current, endpoint, credentials }),
20
+ [endpoint, credentials]
21
+ );
22
+ }
23
+ function requestError(error) {
24
+ return isSpeeqError(error) ? error : new SpeeqError("INTERNAL");
25
+ }
26
+ var emptyPage = { sessions: [], nextCursor: null };
27
+ function useAuditSessions(options) {
28
+ const client = useSpeeqAudit(options);
29
+ const { userId, from, to, limit } = options.filter ?? {};
30
+ const [version, setVersion] = useState(0);
31
+ const key = JSON.stringify({ userId, from, to, limit, version });
32
+ const [state, setState] = useState({
33
+ data: emptyPage,
34
+ loading: true,
35
+ error: null
36
+ });
37
+ const load = useRef(() => {
38
+ });
39
+ useEffect(() => {
40
+ const filter = JSON.parse(key);
41
+ let pending;
42
+ let active = true;
43
+ load.current = (cursor) => {
44
+ if (!active || pending) return;
45
+ const controller = new AbortController();
46
+ pending = controller;
47
+ setState((current) => ({
48
+ data: cursor ? current.data : emptyPage,
49
+ loading: true,
50
+ error: null
51
+ }));
52
+ void client.listSessions({ ...filter, cursor }, controller.signal).then(
53
+ (page) => {
54
+ if (active)
55
+ setState((current) => ({
56
+ data: cursor ? { ...page, sessions: [...current.data.sessions, ...page.sessions] } : page,
57
+ loading: false,
58
+ error: null
59
+ }));
60
+ },
61
+ (error) => {
62
+ if (active)
63
+ setState((current) => ({ ...current, loading: false, error: requestError(error) }));
64
+ }
65
+ ).finally(() => {
66
+ pending = void 0;
67
+ });
68
+ };
69
+ load.current();
70
+ return () => {
71
+ active = false;
72
+ pending?.abort();
73
+ };
74
+ }, [client, key]);
75
+ return {
76
+ sessions: state.data.sessions,
77
+ loading: state.loading,
78
+ error: state.error,
79
+ hasMore: !!state.data.nextCursor,
80
+ loadMore() {
81
+ if (!state.loading && state.data.nextCursor) load.current(state.data.nextCursor);
82
+ },
83
+ refresh() {
84
+ setVersion((current) => current + 1);
85
+ }
86
+ };
87
+ }
88
+ var emptyDetail = { session: null, events: [] };
89
+ function useAuditSession(sessionId, options) {
90
+ const client = useSpeeqAudit(options);
91
+ const [version, setVersion] = useState(0);
92
+ const [state, setState] = useState({
93
+ data: emptyDetail,
94
+ loading: sessionId !== null,
95
+ error: null
96
+ });
97
+ useEffect(() => {
98
+ if (sessionId === null) {
99
+ setState({ data: emptyDetail, loading: false, error: null });
100
+ return;
101
+ }
102
+ const controller = new AbortController();
103
+ setState({ data: emptyDetail, loading: true, error: null });
104
+ void client.getSession(sessionId, controller.signal).then(
105
+ (data) => {
106
+ if (!controller.signal.aborted) setState({ data, loading: false, error: null });
107
+ },
108
+ (error) => {
109
+ if (!controller.signal.aborted)
110
+ setState({ data: emptyDetail, loading: false, error: requestError(error) });
111
+ }
112
+ );
113
+ return () => controller.abort();
114
+ }, [client, sessionId, version]);
115
+ return {
116
+ ...sessionId === null ? emptyDetail : state.data,
117
+ loading: sessionId !== null && state.loading,
118
+ error: sessionId === null ? null : state.error,
119
+ refresh() {
120
+ setVersion((current) => current + 1);
121
+ }
122
+ };
123
+ }
124
+
125
+ // src/hooks.ts
126
+ import { useEffect as useEffect3, useMemo as useMemo3, useRef as useRef3, useSyncExternalStore } from "react";
127
+
128
+ // src/provider.tsx
129
+ import {
130
+ createSpeeqClient
131
+ } from "@speeq/client";
132
+ import {
133
+ createContext,
134
+ useContext,
135
+ useEffect as useEffect2,
136
+ useMemo as useMemo2,
137
+ useRef as useRef2,
138
+ useState as useState2
139
+ } from "react";
140
+
141
+ // src/context-registry.ts
142
+ function createContextRegistry(base) {
143
+ const entries = /* @__PURE__ */ new Set();
144
+ return {
145
+ register(read) {
146
+ entries.add(read);
147
+ return () => {
148
+ entries.delete(read);
149
+ };
150
+ },
151
+ getContext() {
152
+ const context = base();
153
+ if (!entries.size) return context;
154
+ return {
155
+ ...context,
156
+ data: Object.assign({}, context?.data, ...Array.from(entries, (read) => read()))
157
+ };
158
+ }
159
+ };
160
+ }
161
+
162
+ // src/provider.tsx
163
+ import { jsx } from "react/jsx-runtime";
164
+ var ProviderContext = createContext(null);
165
+ var serverSnapshots = /* @__PURE__ */ new WeakMap();
166
+ function initialServerSnapshot(client) {
167
+ let snapshot = serverSnapshots.get(client);
168
+ if (!snapshot) {
169
+ snapshot = {
170
+ ...client.getSnapshot(),
171
+ support: { speechInput: false, speechOutput: false, voiceForLanguage: null }
172
+ };
173
+ serverSnapshots.set(client, snapshot);
174
+ }
175
+ return snapshot;
176
+ }
177
+ function SpeeqProvider(props) {
178
+ const navigate = useRef2(props.onNavigate);
179
+ const context = useRef2(props.getContext);
180
+ navigate.current = props.onNavigate;
181
+ context.current = props.getContext;
182
+ const [registry] = useState2(() => createContextRegistry(() => context.current?.()));
183
+ const [initial] = useState2(() => ({
184
+ client: props.client ?? createSpeeqClient({
185
+ ...props,
186
+ onNavigate: (action) => navigate.current?.(action),
187
+ getContext: registry.getContext
188
+ }),
189
+ owned: props.client === void 0
190
+ }));
191
+ const client = props.client ?? initial.client;
192
+ const owned = initial.owned && client === initial.client && props.client === void 0;
193
+ useEffect2(() => {
194
+ if (owned)
195
+ return () => {
196
+ client.endCall();
197
+ client.cancel();
198
+ };
199
+ }, [owned, client]);
200
+ const value = useMemo2(() => {
201
+ const snapshot = initialServerSnapshot(client);
202
+ return { client, getServerSnapshot: () => snapshot, registry };
203
+ }, [client, registry]);
204
+ return /* @__PURE__ */ jsx(ProviderContext.Provider, { value, children: props.children });
205
+ }
206
+ function useProvider(hook) {
207
+ const value = useContext(ProviderContext);
208
+ if (!value) throw new Error(`${hook} must be used inside <SpeeqProvider>`);
209
+ return value;
210
+ }
211
+
212
+ // src/hooks.ts
213
+ function useSpeeq() {
214
+ const { client, getServerSnapshot } = useProvider("useSpeeq");
215
+ const store = useMemo3(
216
+ () => ({
217
+ subscribe: client.subscribe.bind(client),
218
+ getSnapshot: client.getSnapshot.bind(client),
219
+ actions: {
220
+ client,
221
+ sendText: client.sendText.bind(client),
222
+ startListening: client.startListening.bind(client),
223
+ stopListening: client.stopListening.bind(client),
224
+ startCall: client.startCall.bind(client),
225
+ endCall: client.endCall.bind(client),
226
+ cancel: client.cancel.bind(client),
227
+ setLanguage: client.setLanguage.bind(client),
228
+ confirm: client.confirm.bind(client),
229
+ speak: client.speak.bind(client)
230
+ }
231
+ }),
232
+ [client]
233
+ );
234
+ const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);
235
+ return { ...snapshot, ...store.actions };
236
+ }
237
+ function useSpeeqContext(data) {
238
+ const { registry } = useProvider("useSpeeqContext");
239
+ const current = useRef3(data);
240
+ current.current = data;
241
+ useEffect3(() => registry.register(() => current.current), [registry]);
242
+ }
243
+ function useSpeeqEvent(event, handler) {
244
+ const { client } = useProvider("useSpeeqEvent");
245
+ const current = useRef3(handler);
246
+ current.current = handler;
247
+ useEffect3(() => client.on(event, (payload) => current.current(payload)), [client, event]);
248
+ }
249
+ export {
250
+ SpeeqError2 as SpeeqError,
251
+ SpeeqProvider,
252
+ isSpeeqError2 as isSpeeqError,
253
+ useAuditSession,
254
+ useAuditSessions,
255
+ useSpeeq,
256
+ useSpeeqAudit,
257
+ useSpeeqContext,
258
+ useSpeeqEvent
259
+ };
260
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/audit-hooks.ts","../src/hooks.ts","../src/provider.tsx","../src/context-registry.ts"],"sourcesContent":["\"use client\";\nexport type {\n AuditClient,\n AuditClientOptions,\n AuditListParams,\n ChatMessage,\n ConversationEvent,\n NavigateAction,\n PendingConfirmation,\n SessionSummary,\n SpeeqClient,\n SpeeqClientEvents,\n SpeeqClientOptions,\n SpeeqSnapshot,\n SpeeqState,\n} from \"@speeq/client\";\nexport { isSpeeqError, SpeeqError } from \"@speeq/client\";\nexport type {\n UseAuditSessionResult,\n UseAuditSessionsOptions,\n UseAuditSessionsResult,\n} from \"./audit-hooks.js\";\nexport { useAuditSession, useAuditSessions, useSpeeqAudit } from \"./audit-hooks.js\";\nexport type { UseSpeeqResult } from \"./hooks.js\";\nexport { useSpeeq, useSpeeqContext, useSpeeqEvent } from \"./hooks.js\";\nexport type { SpeeqProviderProps } from \"./provider.js\";\nexport { SpeeqProvider } from \"./provider.js\";\n","import {\n type AuditClient,\n type AuditClientOptions,\n type AuditListParams,\n type ConversationEvent,\n createAuditClient,\n isSpeeqError,\n type SessionSummary,\n SpeeqError,\n} from \"@speeq/client\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\n\n/** Creates an audit client for the endpoint and credential mode. */\nexport function useSpeeqAudit(options: AuditClientOptions): AuditClient {\n const latest = useRef(options);\n latest.current = options;\n const { endpoint, credentials } = options;\n return useMemo(\n () => createAuditClient({ ...latest.current, endpoint, credentials }),\n [endpoint, credentials],\n );\n}\n\n/** Audit connection and optional session list filter. */\nexport interface UseAuditSessionsOptions extends AuditClientOptions {\n filter?: Omit<AuditListParams, \"cursor\">;\n}\n\n/** Current session list with pagination and refresh controls. */\nexport interface UseAuditSessionsResult {\n sessions: SessionSummary[];\n loading: boolean;\n error: SpeeqError | null;\n hasMore: boolean;\n loadMore(): void;\n refresh(): void;\n}\n\ninterface RequestState<T> {\n data: T;\n loading: boolean;\n error: SpeeqError | null;\n}\n\nfunction requestError(error: unknown) {\n return isSpeeqError(error) ? error : new SpeeqError(\"INTERNAL\");\n}\n\nconst emptyPage = { sessions: [] as SessionSummary[], nextCursor: null as string | null };\n\n/** Loads session summaries and appends additional pages on demand. */\nexport function useAuditSessions(options: UseAuditSessionsOptions): UseAuditSessionsResult {\n const client = useSpeeqAudit(options);\n const { userId, from, to, limit } = options.filter ?? {};\n const [version, setVersion] = useState(0);\n const key = JSON.stringify({ userId, from, to, limit, version });\n const [state, setState] = useState<RequestState<typeof emptyPage>>({\n data: emptyPage,\n loading: true,\n error: null,\n });\n const load = useRef<(cursor?: string) => void>(() => {});\n useEffect(() => {\n const filter = JSON.parse(key) as AuditListParams;\n let pending: AbortController | undefined;\n let active = true;\n load.current = (cursor) => {\n if (!active || pending) return;\n const controller = new AbortController();\n pending = controller;\n setState((current) => ({\n data: cursor ? current.data : emptyPage,\n loading: true,\n error: null,\n }));\n void client\n .listSessions({ ...filter, cursor }, controller.signal)\n .then(\n (page) => {\n if (active)\n setState((current) => ({\n data: cursor\n ? { ...page, sessions: [...current.data.sessions, ...page.sessions] }\n : page,\n loading: false,\n error: null,\n }));\n },\n (error) => {\n if (active)\n setState((current) => ({ ...current, loading: false, error: requestError(error) }));\n },\n )\n .finally(() => {\n pending = undefined;\n });\n };\n load.current();\n return () => {\n active = false;\n pending?.abort();\n };\n }, [client, key]);\n return {\n sessions: state.data.sessions,\n loading: state.loading,\n error: state.error,\n hasMore: !!state.data.nextCursor,\n loadMore() {\n if (!state.loading && state.data.nextCursor) load.current(state.data.nextCursor);\n },\n refresh() {\n setVersion((current) => current + 1);\n },\n };\n}\n\n/** Current session, its ordered events and a reload control. */\nexport interface UseAuditSessionResult {\n session: SessionSummary | null;\n events: ConversationEvent[];\n loading: boolean;\n error: SpeeqError | null;\n refresh(): void;\n}\n\nconst emptyDetail = { session: null, events: [] as ConversationEvent[] };\n\n/** Loads and refreshes the event history for a selected session. */\nexport function useAuditSession(\n sessionId: string | null,\n options: AuditClientOptions,\n): UseAuditSessionResult {\n const client = useSpeeqAudit(options);\n const [version, setVersion] = useState(0);\n const [state, setState] = useState<\n RequestState<Pick<UseAuditSessionResult, \"session\" | \"events\">>\n >({\n data: emptyDetail,\n loading: sessionId !== null,\n error: null,\n });\n // biome-ignore lint/correctness/useExhaustiveDependencies: Refresh reloads the same selected session.\n useEffect(() => {\n if (sessionId === null) {\n setState({ data: emptyDetail, loading: false, error: null });\n return;\n }\n const controller = new AbortController();\n setState({ data: emptyDetail, loading: true, error: null });\n void client.getSession(sessionId, controller.signal).then(\n (data) => {\n if (!controller.signal.aborted) setState({ data, loading: false, error: null });\n },\n (error) => {\n if (!controller.signal.aborted)\n setState({ data: emptyDetail, loading: false, error: requestError(error) });\n },\n );\n return () => controller.abort();\n }, [client, sessionId, version]);\n return {\n ...(sessionId === null ? emptyDetail : state.data),\n loading: sessionId !== null && state.loading,\n error: sessionId === null ? null : state.error,\n refresh() {\n setVersion((current) => current + 1);\n },\n };\n}\n","import type { SpeeqClient, SpeeqClientEvents, SpeeqSnapshot } from \"@speeq/client\";\nimport { useEffect, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport { useProvider } from \"./provider.js\";\n\n/** Live client snapshot and stable client actions. */\nexport interface UseSpeeqResult extends SpeeqSnapshot {\n client: SpeeqClient;\n sendText: SpeeqClient[\"sendText\"];\n startListening: SpeeqClient[\"startListening\"];\n stopListening: SpeeqClient[\"stopListening\"];\n startCall: SpeeqClient[\"startCall\"];\n endCall: SpeeqClient[\"endCall\"];\n cancel: SpeeqClient[\"cancel\"];\n setLanguage: SpeeqClient[\"setLanguage\"];\n confirm: SpeeqClient[\"confirm\"];\n speak: SpeeqClient[\"speak\"];\n}\n\n/** Reads the current snapshot and actions of the provider's client. */\nexport function useSpeeq(): UseSpeeqResult {\n const { client, getServerSnapshot } = useProvider(\"useSpeeq\");\n const store = useMemo(\n () => ({\n subscribe: client.subscribe.bind(client),\n getSnapshot: client.getSnapshot.bind(client),\n actions: {\n client,\n sendText: client.sendText.bind(client),\n startListening: client.startListening.bind(client),\n stopListening: client.stopListening.bind(client),\n startCall: client.startCall.bind(client),\n endCall: client.endCall.bind(client),\n cancel: client.cancel.bind(client),\n setLanguage: client.setLanguage.bind(client),\n confirm: client.confirm.bind(client),\n speak: client.speak.bind(client),\n },\n }),\n [client],\n );\n const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);\n return { ...snapshot, ...store.actions };\n}\n\n/** Registers data from the current page for subsequent conversation requests. */\nexport function useSpeeqContext(data: Record<string, unknown>): void {\n const { registry } = useProvider(\"useSpeeqContext\");\n const current = useRef(data);\n current.current = data;\n useEffect(() => registry.register(() => current.current), [registry]);\n}\n\n/** Subscribes to a client event and calls the latest handler. */\nexport function useSpeeqEvent<K extends keyof SpeeqClientEvents>(\n event: K,\n handler: (payload: SpeeqClientEvents[K]) => void,\n): void {\n const { client } = useProvider(\"useSpeeqEvent\");\n const current = useRef(handler);\n current.current = handler;\n useEffect(() => client.on(event, (payload) => current.current(payload)), [client, event]);\n}\n","import {\n createSpeeqClient,\n type SpeeqClient,\n type SpeeqClientOptions,\n type SpeeqSnapshot,\n} from \"@speeq/client\";\nimport {\n createContext,\n type JSX,\n type ReactNode,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createContextRegistry } from \"./context-registry.js\";\n\n/** Configuration for a provider-owned client or an existing client. */\nexport interface SpeeqProviderProps extends SpeeqClientOptions {\n children: ReactNode;\n /** Use an existing client instead of creating one. The other options are then ignored. */\n client?: SpeeqClient;\n}\n\nconst ProviderContext = createContext<{\n client: SpeeqClient;\n getServerSnapshot: () => SpeeqSnapshot;\n registry: ReturnType<typeof createContextRegistry>;\n} | null>(null);\n\nconst serverSnapshots = new WeakMap<SpeeqClient, SpeeqSnapshot>();\n\nfunction initialServerSnapshot(client: SpeeqClient) {\n let snapshot = serverSnapshots.get(client);\n if (!snapshot) {\n snapshot = {\n ...client.getSnapshot(),\n support: { speechInput: false, speechOutput: false, voiceForLanguage: null },\n };\n serverSnapshots.set(client, snapshot);\n }\n return snapshot;\n}\n\n/** Makes a speeq client available to descendant hooks. */\nexport function SpeeqProvider(props: SpeeqProviderProps): JSX.Element {\n const navigate = useRef(props.onNavigate);\n const context = useRef(props.getContext);\n navigate.current = props.onNavigate;\n context.current = props.getContext;\n const [registry] = useState(() => createContextRegistry(() => context.current?.()));\n const [initial] = useState(() => ({\n client:\n props.client ??\n createSpeeqClient({\n ...props,\n onNavigate: (action) => navigate.current?.(action),\n getContext: registry.getContext,\n }),\n owned: props.client === undefined,\n }));\n const client = props.client ?? initial.client;\n const owned = initial.owned && client === initial.client && props.client === undefined;\n useEffect(() => {\n if (owned)\n return () => {\n client.endCall(); // never leave the microphone on after the provider is gone\n client.cancel();\n };\n }, [owned, client]);\n const value = useMemo(() => {\n const snapshot = initialServerSnapshot(client);\n return { client, getServerSnapshot: () => snapshot, registry };\n }, [client, registry]);\n return <ProviderContext.Provider value={value}>{props.children}</ProviderContext.Provider>;\n}\n\n/** Reads the provider store for a named hook. */\nexport function useProvider(hook: string) {\n const value = useContext(ProviderContext);\n if (!value) throw new Error(`${hook} must be used inside <SpeeqProvider>`);\n return value;\n}\n","import type { SpeeqClientOptions } from \"@speeq/client\";\n\ntype GetContext = NonNullable<SpeeqClientOptions[\"getContext\"]>;\n\n/** Collects committed context hooks in registration order. */\nexport function createContextRegistry(base: GetContext) {\n const entries = new Set<() => Record<string, unknown>>();\n return {\n register(read: () => Record<string, unknown>) {\n entries.add(read);\n return () => {\n entries.delete(read);\n };\n },\n getContext() {\n const context = base();\n if (!entries.size) return context;\n return {\n ...context,\n data: Object.assign({}, context?.data, ...Array.from(entries, (read) => read())),\n };\n },\n };\n}\n"],"mappings":";;;;AAgBA,SAAS,gBAAAA,eAAc,cAAAC,mBAAkB;;;AChBzC;AAAA,EAKE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,WAAW,SAAS,QAAQ,gBAAgB;AAG9C,SAAS,cAAc,SAA0C;AACtE,QAAM,SAAS,OAAO,OAAO;AAC7B,SAAO,UAAU;AACjB,QAAM,EAAE,UAAU,YAAY,IAAI;AAClC,SAAO;AAAA,IACL,MAAM,kBAAkB,EAAE,GAAG,OAAO,SAAS,UAAU,YAAY,CAAC;AAAA,IACpE,CAAC,UAAU,WAAW;AAAA,EACxB;AACF;AAuBA,SAAS,aAAa,OAAgB;AACpC,SAAO,aAAa,KAAK,IAAI,QAAQ,IAAI,WAAW,UAAU;AAChE;AAEA,IAAM,YAAY,EAAE,UAAU,CAAC,GAAuB,YAAY,KAAsB;AAGjF,SAAS,iBAAiB,SAA0D;AACzF,QAAM,SAAS,cAAc,OAAO;AACpC,QAAM,EAAE,QAAQ,MAAM,IAAI,MAAM,IAAI,QAAQ,UAAU,CAAC;AACvD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,CAAC;AACxC,QAAM,MAAM,KAAK,UAAU,EAAE,QAAQ,MAAM,IAAI,OAAO,QAAQ,CAAC;AAC/D,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAyC;AAAA,IACjE,MAAM;AAAA,IACN,SAAS;AAAA,IACT,OAAO;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QACnC,QAAQ,OAAO,OAAO,KAAK,MAAM;AAAA,QACjC,aAAa,OAAO,YAAY,KAAK,MAAM;AAAA,QAC3C,SAAS,OAAO,QAAQ,KAAK,MAAM;AAAA,QACnC,OAAO,OAAO,MAAM,KAAK,MAAM;AAAA,MACjC;AAAA,IACF;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACA,QAAM,WAAW,qBAAqB,MAAM,WAAW,MAAM,aAAa,iBAAiB;AAC3F,SAAO,EAAE,GAAG,UAAU,GAAG,MAAM,QAAQ;AACzC;AAGO,SAAS,gBAAgB,MAAqC;AACnE,QAAM,EAAE,SAAS,IAAI,YAAY,iBAAiB;AAClD,QAAM,UAAUC,QAAO,IAAI;AAC3B,UAAQ,UAAU;AAClB,EAAAC,WAAU,MAAM,SAAS,SAAS,MAAM,QAAQ,OAAO,GAAG,CAAC,QAAQ,CAAC;AACtE;AAGO,SAAS,cACd,OACA,SACM;AACN,QAAM,EAAE,OAAO,IAAI,YAAY,eAAe;AAC9C,QAAM,UAAUD,QAAO,OAAO;AAC9B,UAAQ,UAAU;AAClB,EAAAC,WAAU,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,QAAQ,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,CAAC;AAC1F;","names":["isSpeeqError","SpeeqError","useEffect","useMemo","useRef","useEffect","useMemo","useRef","useState","useRef","useState","useEffect","useMemo","useMemo","useRef","useEffect"]}
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@speeq/react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.3.0",
4
+ "description": "Headless React bindings for speeq",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Mudavath-Giri-Naik/speeq.git",
11
+ "directory": "packages/react"
12
+ },
13
+ "homepage": "https://github.com/Mudavath-Giri-Naik/speeq#readme",
14
+ "keywords": [
15
+ "speeq",
16
+ "react",
17
+ "agent",
18
+ "headless"
19
+ ],
20
+ "engines": {
21
+ "node": ">=20"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md"
26
+ ],
27
+ "main": "./dist/index.cjs",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "@speeq/source": "./src/index.ts",
33
+ "import": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/index.d.cts",
39
+ "default": "./dist/index.cjs"
40
+ }
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "dependencies": {
48
+ "@speeq/client": "0.3.0"
49
+ },
50
+ "peerDependencies": {
51
+ "react": "^18.2.0 || ^19.0.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "react": {
55
+ "optional": true
56
+ }
57
+ },
58
+ "devDependencies": {
59
+ "@speeq/tsconfig": "0.0.0",
60
+ "@testing-library/dom": "10.4.2",
61
+ "@testing-library/react": "16.3.3",
62
+ "@types/react": "19.3.0",
63
+ "@types/react-dom": "19.3.0",
64
+ "jsdom": "31.0.1",
65
+ "react": "19.3.1",
66
+ "react-dom": "19.3.1"
67
+ },
68
+ "scripts": {
69
+ "build": "tsup",
70
+ "typecheck": "tsc --noEmit",
71
+ "test": "vitest run"
72
+ }
6
73
  }