@skippr/live-agent-sdk 0.13.0 → 0.14.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.
@@ -22,6 +22,7 @@ function useSession({ agentId, authToken, appKey }) {
22
22
  const [isStarting, setIsStarting] = useState(false);
23
23
  const [error, setError] = useState("");
24
24
  const [sessionId, setSessionId] = useState(null);
25
+ const [sessionToken, setSessionToken] = useState(null);
25
26
  const startSession = useCallback(async () => {
26
27
  setIsStarting(true);
27
28
  setError("");
@@ -36,15 +37,17 @@ function useSession({ agentId, authToken, appKey }) {
36
37
  throw new Error(`Failed to create session: ${createResp.status}`);
37
38
  }
38
39
  const { session } = await createResp.json();
40
+ const sessionHeaders = { "X-Session-Token": session.sessionToken };
39
41
  const startResp = await fetch(`${API_URL}/v1/sessions/${session.id}/start`, {
40
42
  method: "POST",
41
- headers: authHeaders
43
+ headers: sessionHeaders
42
44
  });
43
45
  if (!startResp.ok) {
44
46
  throw new Error(`Failed to start session: ${startResp.status}`);
45
47
  }
46
48
  const { connection: conn } = await startResp.json();
47
49
  setSessionId(session.id);
50
+ setSessionToken(session.sessionToken);
48
51
  setConnection({
49
52
  livekitUrl: conn.livekitUrl,
50
53
  token: conn.token
@@ -57,12 +60,12 @@ function useSession({ agentId, authToken, appKey }) {
57
60
  }
58
61
  }, [agentId, authToken, appKey]);
59
62
  const disconnect = useCallback(async () => {
60
- if (sessionId) {
61
- const authHeaders = resolveAuthHeaders(authToken, appKey);
63
+ if (sessionId && sessionToken) {
64
+ const sessionHeaders = { "X-Session-Token": sessionToken };
62
65
  try {
63
66
  await fetch(`${API_URL}/v1/sessions/${sessionId}/complete`, {
64
67
  method: "POST",
65
- headers: { "Content-Type": "application/json", ...authHeaders },
68
+ headers: { "Content-Type": "application/json", ...sessionHeaders },
66
69
  body: JSON.stringify({})
67
70
  });
68
71
  } catch {}
@@ -71,7 +74,8 @@ function useSession({ agentId, authToken, appKey }) {
71
74
  setShouldConnect(false);
72
75
  setConnection(null);
73
76
  setSessionId(null);
74
- }, [sessionId, authToken, appKey]);
77
+ setSessionToken(null);
78
+ }, [sessionId, sessionToken]);
75
79
  return { connection, shouldConnect, isStarting, error, startSession, disconnect };
76
80
  }
77
81