@speeq/react 0.0.0-stage → 0.2.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 +21 -0
- package/README.md +108 -2
- package/dist/index.cjs +273 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +61 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +254 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -3
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
|
-
#
|
|
1
|
+
# @speeq/react
|
|
2
2
|
|
|
3
|
-
|
|
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,273 @@
|
|
|
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) return () => client.cancel();
|
|
213
|
+
}, [owned, client]);
|
|
214
|
+
const value = (0, import_react2.useMemo)(() => {
|
|
215
|
+
const snapshot = initialServerSnapshot(client);
|
|
216
|
+
return { client, getServerSnapshot: () => snapshot, registry };
|
|
217
|
+
}, [client, registry]);
|
|
218
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProviderContext.Provider, { value, children: props.children });
|
|
219
|
+
}
|
|
220
|
+
function useProvider(hook) {
|
|
221
|
+
const value = (0, import_react2.useContext)(ProviderContext);
|
|
222
|
+
if (!value) throw new Error(`${hook} must be used inside <SpeeqProvider>`);
|
|
223
|
+
return value;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/hooks.ts
|
|
227
|
+
function useSpeeq() {
|
|
228
|
+
const { client, getServerSnapshot } = useProvider("useSpeeq");
|
|
229
|
+
const store = (0, import_react3.useMemo)(
|
|
230
|
+
() => ({
|
|
231
|
+
subscribe: client.subscribe.bind(client),
|
|
232
|
+
getSnapshot: client.getSnapshot.bind(client),
|
|
233
|
+
actions: {
|
|
234
|
+
client,
|
|
235
|
+
sendText: client.sendText.bind(client),
|
|
236
|
+
startListening: client.startListening.bind(client),
|
|
237
|
+
stopListening: client.stopListening.bind(client),
|
|
238
|
+
cancel: client.cancel.bind(client),
|
|
239
|
+
setLanguage: client.setLanguage.bind(client),
|
|
240
|
+
confirm: client.confirm.bind(client),
|
|
241
|
+
speak: client.speak.bind(client)
|
|
242
|
+
}
|
|
243
|
+
}),
|
|
244
|
+
[client]
|
|
245
|
+
);
|
|
246
|
+
const snapshot = (0, import_react3.useSyncExternalStore)(store.subscribe, store.getSnapshot, getServerSnapshot);
|
|
247
|
+
return { ...snapshot, ...store.actions };
|
|
248
|
+
}
|
|
249
|
+
function useSpeeqContext(data) {
|
|
250
|
+
const { registry } = useProvider("useSpeeqContext");
|
|
251
|
+
const current = (0, import_react3.useRef)(data);
|
|
252
|
+
current.current = data;
|
|
253
|
+
(0, import_react3.useEffect)(() => registry.register(() => current.current), [registry]);
|
|
254
|
+
}
|
|
255
|
+
function useSpeeqEvent(event, handler) {
|
|
256
|
+
const { client } = useProvider("useSpeeqEvent");
|
|
257
|
+
const current = (0, import_react3.useRef)(handler);
|
|
258
|
+
current.current = handler;
|
|
259
|
+
(0, import_react3.useEffect)(() => client.on(event, (payload) => current.current(payload)), [client, event]);
|
|
260
|
+
}
|
|
261
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
262
|
+
0 && (module.exports = {
|
|
263
|
+
SpeeqError,
|
|
264
|
+
SpeeqProvider,
|
|
265
|
+
isSpeeqError,
|
|
266
|
+
useAuditSession,
|
|
267
|
+
useAuditSessions,
|
|
268
|
+
useSpeeq,
|
|
269
|
+
useSpeeqAudit,
|
|
270
|
+
useSpeeqContext,
|
|
271
|
+
useSpeeqEvent
|
|
272
|
+
});
|
|
273
|
+
//# 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 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 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) return () => client.cancel();\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,CAA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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,eAAW,oCAAqB,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,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"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
cancel: SpeeqClient["cancel"];
|
|
40
|
+
setLanguage: SpeeqClient["setLanguage"];
|
|
41
|
+
confirm: SpeeqClient["confirm"];
|
|
42
|
+
speak: SpeeqClient["speak"];
|
|
43
|
+
}
|
|
44
|
+
/** Reads the current snapshot and actions of the provider's client. */
|
|
45
|
+
declare function useSpeeq(): UseSpeeqResult;
|
|
46
|
+
/** Registers data from the current page for subsequent conversation requests. */
|
|
47
|
+
declare function useSpeeqContext(data: Record<string, unknown>): void;
|
|
48
|
+
/** Subscribes to a client event and calls the latest handler. */
|
|
49
|
+
declare function useSpeeqEvent<K extends keyof SpeeqClientEvents>(event: K, handler: (payload: SpeeqClientEvents[K]) => void): void;
|
|
50
|
+
|
|
51
|
+
/** Configuration for a provider-owned client or an existing client. */
|
|
52
|
+
interface SpeeqProviderProps extends SpeeqClientOptions {
|
|
53
|
+
children: ReactNode;
|
|
54
|
+
/** Use an existing client instead of creating one. The other options are then ignored. */
|
|
55
|
+
client?: SpeeqClient;
|
|
56
|
+
}
|
|
57
|
+
/** Makes a speeq client available to descendant hooks. */
|
|
58
|
+
declare function SpeeqProvider(props: SpeeqProviderProps): JSX.Element;
|
|
59
|
+
|
|
60
|
+
export { SpeeqProvider, useAuditSession, useAuditSessions, useSpeeq, useSpeeqAudit, useSpeeqContext, useSpeeqEvent };
|
|
61
|
+
export type { SpeeqProviderProps, UseAuditSessionResult, UseAuditSessionsOptions, UseAuditSessionsResult, UseSpeeqResult };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
cancel: SpeeqClient["cancel"];
|
|
40
|
+
setLanguage: SpeeqClient["setLanguage"];
|
|
41
|
+
confirm: SpeeqClient["confirm"];
|
|
42
|
+
speak: SpeeqClient["speak"];
|
|
43
|
+
}
|
|
44
|
+
/** Reads the current snapshot and actions of the provider's client. */
|
|
45
|
+
declare function useSpeeq(): UseSpeeqResult;
|
|
46
|
+
/** Registers data from the current page for subsequent conversation requests. */
|
|
47
|
+
declare function useSpeeqContext(data: Record<string, unknown>): void;
|
|
48
|
+
/** Subscribes to a client event and calls the latest handler. */
|
|
49
|
+
declare function useSpeeqEvent<K extends keyof SpeeqClientEvents>(event: K, handler: (payload: SpeeqClientEvents[K]) => void): void;
|
|
50
|
+
|
|
51
|
+
/** Configuration for a provider-owned client or an existing client. */
|
|
52
|
+
interface SpeeqProviderProps extends SpeeqClientOptions {
|
|
53
|
+
children: ReactNode;
|
|
54
|
+
/** Use an existing client instead of creating one. The other options are then ignored. */
|
|
55
|
+
client?: SpeeqClient;
|
|
56
|
+
}
|
|
57
|
+
/** Makes a speeq client available to descendant hooks. */
|
|
58
|
+
declare function SpeeqProvider(props: SpeeqProviderProps): JSX.Element;
|
|
59
|
+
|
|
60
|
+
export { SpeeqProvider, useAuditSession, useAuditSessions, useSpeeq, useSpeeqAudit, useSpeeqContext, useSpeeqEvent };
|
|
61
|
+
export type { SpeeqProviderProps, UseAuditSessionResult, UseAuditSessionsOptions, UseAuditSessionsResult, UseSpeeqResult };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
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) return () => client.cancel();
|
|
195
|
+
}, [owned, client]);
|
|
196
|
+
const value = useMemo2(() => {
|
|
197
|
+
const snapshot = initialServerSnapshot(client);
|
|
198
|
+
return { client, getServerSnapshot: () => snapshot, registry };
|
|
199
|
+
}, [client, registry]);
|
|
200
|
+
return /* @__PURE__ */ jsx(ProviderContext.Provider, { value, children: props.children });
|
|
201
|
+
}
|
|
202
|
+
function useProvider(hook) {
|
|
203
|
+
const value = useContext(ProviderContext);
|
|
204
|
+
if (!value) throw new Error(`${hook} must be used inside <SpeeqProvider>`);
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/hooks.ts
|
|
209
|
+
function useSpeeq() {
|
|
210
|
+
const { client, getServerSnapshot } = useProvider("useSpeeq");
|
|
211
|
+
const store = useMemo3(
|
|
212
|
+
() => ({
|
|
213
|
+
subscribe: client.subscribe.bind(client),
|
|
214
|
+
getSnapshot: client.getSnapshot.bind(client),
|
|
215
|
+
actions: {
|
|
216
|
+
client,
|
|
217
|
+
sendText: client.sendText.bind(client),
|
|
218
|
+
startListening: client.startListening.bind(client),
|
|
219
|
+
stopListening: client.stopListening.bind(client),
|
|
220
|
+
cancel: client.cancel.bind(client),
|
|
221
|
+
setLanguage: client.setLanguage.bind(client),
|
|
222
|
+
confirm: client.confirm.bind(client),
|
|
223
|
+
speak: client.speak.bind(client)
|
|
224
|
+
}
|
|
225
|
+
}),
|
|
226
|
+
[client]
|
|
227
|
+
);
|
|
228
|
+
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);
|
|
229
|
+
return { ...snapshot, ...store.actions };
|
|
230
|
+
}
|
|
231
|
+
function useSpeeqContext(data) {
|
|
232
|
+
const { registry } = useProvider("useSpeeqContext");
|
|
233
|
+
const current = useRef3(data);
|
|
234
|
+
current.current = data;
|
|
235
|
+
useEffect3(() => registry.register(() => current.current), [registry]);
|
|
236
|
+
}
|
|
237
|
+
function useSpeeqEvent(event, handler) {
|
|
238
|
+
const { client } = useProvider("useSpeeqEvent");
|
|
239
|
+
const current = useRef3(handler);
|
|
240
|
+
current.current = handler;
|
|
241
|
+
useEffect3(() => client.on(event, (payload) => current.current(payload)), [client, event]);
|
|
242
|
+
}
|
|
243
|
+
export {
|
|
244
|
+
SpeeqError2 as SpeeqError,
|
|
245
|
+
SpeeqProvider,
|
|
246
|
+
isSpeeqError2 as isSpeeqError,
|
|
247
|
+
useAuditSession,
|
|
248
|
+
useAuditSessions,
|
|
249
|
+
useSpeeq,
|
|
250
|
+
useSpeeqAudit,
|
|
251
|
+
useSpeeqContext,
|
|
252
|
+
useSpeeqEvent
|
|
253
|
+
};
|
|
254
|
+
//# 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 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 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) return () => client.cancel();\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,M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A,QACA,UAAU,OAAO,SAAS,KAAK,MAAM;AAAA,QACrC,gBAAgB,OAAO,eAAe,KAAK,MAAM;AAAA,QACjD,eAAe,OAAO,cAAc,KAAK,MAAM;AAAA,QAC/C,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.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.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.2.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
|
}
|