@skippr/live-agent-sdk 0.19.0 → 0.20.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/dist/esm/lib-exports.js
CHANGED
|
@@ -8,7 +8,7 @@ var LiveAgentContext = createContext(null);
|
|
|
8
8
|
|
|
9
9
|
// src/hooks/useAuth.ts
|
|
10
10
|
import { useCallback, useEffect, useState } from "react";
|
|
11
|
-
var API_URL = "https://
|
|
11
|
+
var API_URL = "https://specialist.skippr.ai/api";
|
|
12
12
|
function storageKey(appKey) {
|
|
13
13
|
return `skippr_auth_${appKey}`;
|
|
14
14
|
}
|
|
@@ -149,7 +149,7 @@ function useAuth({ appKey }) {
|
|
|
149
149
|
|
|
150
150
|
// src/hooks/useSession.ts
|
|
151
151
|
import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
|
|
152
|
-
var API_URL2 = "https://
|
|
152
|
+
var API_URL2 = "https://specialist.skippr.ai/api";
|
|
153
153
|
async function exchangeForBearerToken(appKey, userToken) {
|
|
154
154
|
const resp = await fetch(`${API_URL2}/v1/auth/token-exchange`, {
|
|
155
155
|
method: "POST",
|
|
@@ -170,6 +170,7 @@ function useSession({ agentId, authToken, appKey, userToken }) {
|
|
|
170
170
|
const [shouldConnect, setShouldConnect] = useState2(false);
|
|
171
171
|
const [isStarting, setIsStarting] = useState2(false);
|
|
172
172
|
const [error, setError] = useState2("");
|
|
173
|
+
const [errorCode, setErrorCode] = useState2(null);
|
|
173
174
|
const [sessionId, setSessionId] = useState2(null);
|
|
174
175
|
const [bearerToken, setBearerToken] = useState2(authToken ?? null);
|
|
175
176
|
useEffect2(() => {
|
|
@@ -199,6 +200,7 @@ function useSession({ agentId, authToken, appKey, userToken }) {
|
|
|
199
200
|
const headers = { Authorization: `Bearer ${bearerToken}` };
|
|
200
201
|
setIsStarting(true);
|
|
201
202
|
setError("");
|
|
203
|
+
setErrorCode(null);
|
|
202
204
|
try {
|
|
203
205
|
const createResp = await fetch(`${API_URL2}/v1/sessions`, {
|
|
204
206
|
method: "POST",
|
|
@@ -207,7 +209,9 @@ function useSession({ agentId, authToken, appKey, userToken }) {
|
|
|
207
209
|
body: JSON.stringify({ agentId })
|
|
208
210
|
});
|
|
209
211
|
if (!createResp.ok) {
|
|
210
|
-
|
|
212
|
+
const body = await createResp.json().catch(() => null);
|
|
213
|
+
setErrorCode(createResp.status);
|
|
214
|
+
throw new Error(body?.detail || `Failed to create session: ${createResp.status}`);
|
|
211
215
|
}
|
|
212
216
|
const { session } = await createResp.json();
|
|
213
217
|
const startResp = await fetch(`${API_URL2}/v1/sessions/${session.id}/start`, {
|
|
@@ -216,7 +220,9 @@ function useSession({ agentId, authToken, appKey, userToken }) {
|
|
|
216
220
|
headers
|
|
217
221
|
});
|
|
218
222
|
if (!startResp.ok) {
|
|
219
|
-
|
|
223
|
+
const body = await startResp.json().catch(() => null);
|
|
224
|
+
setErrorCode(startResp.status);
|
|
225
|
+
throw new Error(body?.detail || `Failed to start session: ${startResp.status}`);
|
|
220
226
|
}
|
|
221
227
|
const { connection: conn } = await startResp.json();
|
|
222
228
|
setSessionId(session.id);
|
|
@@ -247,7 +253,7 @@ function useSession({ agentId, authToken, appKey, userToken }) {
|
|
|
247
253
|
setConnection(null);
|
|
248
254
|
setSessionId(null);
|
|
249
255
|
}, [sessionId, bearerToken]);
|
|
250
|
-
return { connection, shouldConnect, isStarting, error, startSession, disconnect };
|
|
256
|
+
return { connection, shouldConnect, isStarting, error, errorCode, startSession, disconnect };
|
|
251
257
|
}
|
|
252
258
|
|
|
253
259
|
// src/components/MinimizedBubble.tsx
|
|
@@ -1749,7 +1755,7 @@ function LiveAgent({
|
|
|
1749
1755
|
}) {
|
|
1750
1756
|
const auth = useAuth({ appKey });
|
|
1751
1757
|
const effectiveAuthToken = authTokenProp || auth.authToken || undefined;
|
|
1752
|
-
const { connection, shouldConnect, isStarting, error, startSession, disconnect } = useSession({
|
|
1758
|
+
const { connection, shouldConnect, isStarting, error, errorCode, startSession, disconnect } = useSession({
|
|
1753
1759
|
agentId,
|
|
1754
1760
|
authToken: effectiveAuthToken,
|
|
1755
1761
|
appKey,
|
|
@@ -1801,6 +1807,7 @@ function LiveAgent({
|
|
|
1801
1807
|
isConnected,
|
|
1802
1808
|
isStarting,
|
|
1803
1809
|
error,
|
|
1810
|
+
errorCode,
|
|
1804
1811
|
startSession,
|
|
1805
1812
|
disconnect,
|
|
1806
1813
|
isPanelOpen,
|
|
@@ -1827,6 +1834,7 @@ function LiveAgent({
|
|
|
1827
1834
|
isConnected,
|
|
1828
1835
|
isStarting,
|
|
1829
1836
|
error,
|
|
1837
|
+
errorCode,
|
|
1830
1838
|
startSession,
|
|
1831
1839
|
disconnect,
|
|
1832
1840
|
isPanelOpen,
|