@skippr/live-agent-sdk 0.19.0 → 0.21.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.
@@ -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://skipprapi-production.up.railway.app";
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://skipprapi-production.up.railway.app";
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
- throw new Error(`Failed to create session: ${createResp.status}`);
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
- throw new Error(`Failed to start session: ${startResp.status}`);
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,
@@ -1848,25 +1856,27 @@ function LiveAgent({
1848
1856
  auth.logout,
1849
1857
  auth.isSubmitting
1850
1858
  ]);
1851
- const widgetContent = /* @__PURE__ */ jsxs12(Fragment3, {
1859
+ const sdkWidgets = /* @__PURE__ */ jsxs12(Fragment3, {
1852
1860
  children: [
1853
1861
  connection && /* @__PURE__ */ jsx16(RoomAudioRenderer, {}),
1854
1862
  isMinimized && /* @__PURE__ */ jsx16(MinimizedBubble, {}),
1855
1863
  /* @__PURE__ */ jsx16(SidebarTrigger, {}),
1856
- /* @__PURE__ */ jsx16(Sidebar, {}),
1857
- children
1864
+ /* @__PURE__ */ jsx16(Sidebar, {})
1858
1865
  ]
1859
1866
  });
1860
- return /* @__PURE__ */ jsx16(LiveAgentContext.Provider, {
1867
+ return /* @__PURE__ */ jsxs12(LiveAgentContext.Provider, {
1861
1868
  value: ctx,
1862
- children: connection ? /* @__PURE__ */ jsx16(LiveKitRoom, {
1863
- serverUrl: connection.livekitUrl,
1864
- token: connection.token,
1865
- connect: shouldConnect,
1866
- audio: true,
1867
- onDisconnected: disconnect,
1868
- children: widgetContent
1869
- }) : widgetContent
1869
+ children: [
1870
+ connection ? /* @__PURE__ */ jsx16(LiveKitRoom, {
1871
+ serverUrl: connection.livekitUrl,
1872
+ token: connection.token,
1873
+ connect: shouldConnect,
1874
+ audio: true,
1875
+ onDisconnected: disconnect,
1876
+ children: sdkWidgets
1877
+ }) : sdkWidgets,
1878
+ children
1879
+ ]
1870
1880
  });
1871
1881
  }
1872
1882
  export {