@personaai/react 0.7.5 → 0.7.8

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/index.cjs CHANGED
@@ -685,10 +685,14 @@ function useChat(options = {}) {
685
685
  const resolvedThreadId = await (overrideOptions?.threadId ?? options.threadId);
686
686
  chatLogger.trace("resolved threadId", { threadId: resolvedThreadId });
687
687
  const token = getAuthToken ? await getAuthToken() : null;
688
+ const resolvedHookContext = typeof options.context === "function" ? options.context() : options.context;
689
+ const mergedContext = { ...resolvedHookContext, ...overrideOptions?.context };
690
+ const hasContext = Object.keys(mergedContext).length > 0;
688
691
  chatLogger.debug("opening SSE stream", {
689
692
  agentId: targetAgentId,
690
693
  hasToken: !!token,
691
- hasThreadId: !!resolvedThreadId
694
+ hasThreadId: !!resolvedThreadId,
695
+ hasContext
692
696
  });
693
697
  const stream = await openSSEStream({
694
698
  url: `${baseUrl}/chat`,
@@ -701,7 +705,8 @@ function useChat(options = {}) {
701
705
  messages: payloadMessages,
702
706
  threadId: resolvedThreadId,
703
707
  resume: overrideOptions?.resume,
704
- contextOverride: overrideOptions?.contextOverride
708
+ contextOverride: overrideOptions?.contextOverride,
709
+ ...hasContext ? { context: mergedContext } : {}
705
710
  }),
706
711
  signal: controller.signal
707
712
  });
@@ -1435,6 +1440,8 @@ function useVoice(options = {}) {
1435
1440
  const voiceLogger = (0, import_react5.useMemo)(() => logger.child("voice"), [logger]);
1436
1441
  const agentId = options.agentId || defaultAgentId;
1437
1442
  const threadId = options.threadId;
1443
+ const contextOverride = options.contextOverride;
1444
+ const context = options.context;
1438
1445
  const [state, setState] = (0, import_react5.useState)("idle");
1439
1446
  const [isMuted, setIsMuted] = (0, import_react5.useState)(false);
1440
1447
  const [transcript, setTranscript] = (0, import_react5.useState)(
@@ -1704,14 +1711,21 @@ function useVoice(options = {}) {
1704
1711
  setToolCalls([]);
1705
1712
  acceptedTurnSeqRef.current = 0;
1706
1713
  setState("connecting");
1707
- voiceLogger.debug("start() called", { agentId, threadId });
1714
+ voiceLogger.debug("start() called", {
1715
+ agentId,
1716
+ threadId,
1717
+ hasContextOverride: !!contextOverride,
1718
+ hasContext: !!context
1719
+ });
1708
1720
  try {
1709
1721
  const res = await fetchWithAuth("/voice/sessions", {
1710
1722
  method: "POST",
1711
1723
  headers: { "Content-Type": "application/json" },
1712
1724
  body: JSON.stringify({
1713
1725
  agentId,
1714
- ...threadId ? { threadId } : {}
1726
+ ...threadId ? { threadId } : {},
1727
+ ...contextOverride ? { contextOverride } : {},
1728
+ ...context ? { context } : {}
1715
1729
  })
1716
1730
  });
1717
1731
  if (!res.ok) {
@@ -1747,7 +1761,7 @@ function useVoice(options = {}) {
1747
1761
  }
1748
1762
  teardownAudio();
1749
1763
  }
1750
- }, [agentId, threadId, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
1764
+ }, [agentId, threadId, contextOverride, context, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
1751
1765
  const mute = (0, import_react5.useCallback)((muted) => {
1752
1766
  setIsMuted(muted);
1753
1767
  streamRef.current?.getAudioTracks().forEach((track) => {
@@ -1758,6 +1772,10 @@ function useVoice(options = {}) {
1758
1772
  if (!text?.trim() || wsRef.current?.readyState !== WebSocket.OPEN) return;
1759
1773
  wsRef.current.send(JSON.stringify({ type: "voice.text", text }));
1760
1774
  }, []);
1775
+ const updateContext = (0, import_react5.useCallback)((newContext) => {
1776
+ if (wsRef.current?.readyState !== WebSocket.OPEN) return;
1777
+ wsRef.current.send(JSON.stringify({ type: "voice.context", context: newContext }));
1778
+ }, []);
1761
1779
  return {
1762
1780
  state,
1763
1781
  isMuted,
@@ -1769,7 +1787,8 @@ function useVoice(options = {}) {
1769
1787
  start,
1770
1788
  stop,
1771
1789
  mute,
1772
- sendText
1790
+ sendText,
1791
+ updateContext
1773
1792
  };
1774
1793
  }
1775
1794