@skippr/live-agent-sdk 0.8.0 → 0.9.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.
@@ -9,7 +9,7 @@ var LiveAgentContext = createContext(null);
9
9
  // src/hooks/useSession.ts
10
10
  import { useCallback, useState } from "react";
11
11
  var API_URL = "https://skipprapi-production.up.railway.app";
12
- function useSession({ organizationId, agentId }) {
12
+ function useSession({ organizationId, agentId, authToken }) {
13
13
  const [connection, setConnection] = useState(null);
14
14
  const [shouldConnect, setShouldConnect] = useState(false);
15
15
  const [isStarting, setIsStarting] = useState(false);
@@ -19,9 +19,10 @@ function useSession({ organizationId, agentId }) {
19
19
  setIsStarting(true);
20
20
  setError("");
21
21
  try {
22
+ const authHeaders = authToken ? { Authorization: `Bearer ${authToken}` } : {};
22
23
  const createResp = await fetch(`${API_URL}/v1/sessions`, {
23
24
  method: "POST",
24
- headers: { "Content-Type": "application/json" },
25
+ headers: { "Content-Type": "application/json", ...authHeaders },
25
26
  body: JSON.stringify({ organizationId, agentId })
26
27
  });
27
28
  if (!createResp.ok) {
@@ -29,7 +30,8 @@ function useSession({ organizationId, agentId }) {
29
30
  }
30
31
  const { session } = await createResp.json();
31
32
  const startResp = await fetch(`${API_URL}/v1/sessions/${session.id}/start`, {
32
- method: "POST"
33
+ method: "POST",
34
+ headers: authHeaders
33
35
  });
34
36
  if (!startResp.ok) {
35
37
  throw new Error(`Failed to start session: ${startResp.status}`);
@@ -46,13 +48,14 @@ function useSession({ organizationId, agentId }) {
46
48
  } finally {
47
49
  setIsStarting(false);
48
50
  }
49
- }, [organizationId, agentId]);
51
+ }, [organizationId, agentId, authToken]);
50
52
  const disconnect = useCallback(async () => {
51
53
  if (sessionId) {
54
+ const authHeaders = authToken ? { Authorization: `Bearer ${authToken}` } : {};
52
55
  try {
53
56
  await fetch(`${API_URL}/v1/sessions/${sessionId}/complete`, {
54
57
  method: "POST",
55
- headers: { "Content-Type": "application/json" },
58
+ headers: { "Content-Type": "application/json", ...authHeaders },
56
59
  body: JSON.stringify({})
57
60
  });
58
61
  } catch {}
@@ -61,7 +64,7 @@ function useSession({ organizationId, agentId }) {
61
64
  setShouldConnect(false);
62
65
  setConnection(null);
63
66
  setSessionId(null);
64
- }, [sessionId]);
67
+ }, [sessionId, authToken]);
65
68
  return { connection, shouldConnect, isStarting, error, startSession, disconnect };
66
69
  }
67
70
 
@@ -750,12 +753,14 @@ import { jsx as jsx12, jsxs as jsxs9, Fragment as Fragment2 } from "react/jsx-ru
750
753
  function LiveAgent({
751
754
  organizationId,
752
755
  agentId,
756
+ authToken,
753
757
  defaultOpen = false,
754
758
  children
755
759
  }) {
756
760
  const { connection, shouldConnect, isStarting, error, startSession, disconnect } = useSession({
757
761
  organizationId,
758
- agentId
762
+ agentId,
763
+ authToken
759
764
  });
760
765
  const [isPanelOpen, setIsPanelOpen] = useState5(defaultOpen);
761
766
  const openPanel = useCallback5(() => setIsPanelOpen(true), []);