@personaai/react 0.7.6 → 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 +19 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/package.json +82 -82
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
|
});
|
|
@@ -1436,6 +1441,7 @@ function useVoice(options = {}) {
|
|
|
1436
1441
|
const agentId = options.agentId || defaultAgentId;
|
|
1437
1442
|
const threadId = options.threadId;
|
|
1438
1443
|
const contextOverride = options.contextOverride;
|
|
1444
|
+
const context = options.context;
|
|
1439
1445
|
const [state, setState] = (0, import_react5.useState)("idle");
|
|
1440
1446
|
const [isMuted, setIsMuted] = (0, import_react5.useState)(false);
|
|
1441
1447
|
const [transcript, setTranscript] = (0, import_react5.useState)(
|
|
@@ -1708,7 +1714,8 @@ function useVoice(options = {}) {
|
|
|
1708
1714
|
voiceLogger.debug("start() called", {
|
|
1709
1715
|
agentId,
|
|
1710
1716
|
threadId,
|
|
1711
|
-
hasContextOverride: !!contextOverride
|
|
1717
|
+
hasContextOverride: !!contextOverride,
|
|
1718
|
+
hasContext: !!context
|
|
1712
1719
|
});
|
|
1713
1720
|
try {
|
|
1714
1721
|
const res = await fetchWithAuth("/voice/sessions", {
|
|
@@ -1717,7 +1724,8 @@ function useVoice(options = {}) {
|
|
|
1717
1724
|
body: JSON.stringify({
|
|
1718
1725
|
agentId,
|
|
1719
1726
|
...threadId ? { threadId } : {},
|
|
1720
|
-
...contextOverride ? { contextOverride } : {}
|
|
1727
|
+
...contextOverride ? { contextOverride } : {},
|
|
1728
|
+
...context ? { context } : {}
|
|
1721
1729
|
})
|
|
1722
1730
|
});
|
|
1723
1731
|
if (!res.ok) {
|
|
@@ -1753,7 +1761,7 @@ function useVoice(options = {}) {
|
|
|
1753
1761
|
}
|
|
1754
1762
|
teardownAudio();
|
|
1755
1763
|
}
|
|
1756
|
-
}, [agentId, threadId, contextOverride, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
|
|
1764
|
+
}, [agentId, threadId, contextOverride, context, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
|
|
1757
1765
|
const mute = (0, import_react5.useCallback)((muted) => {
|
|
1758
1766
|
setIsMuted(muted);
|
|
1759
1767
|
streamRef.current?.getAudioTracks().forEach((track) => {
|
|
@@ -1764,6 +1772,10 @@ function useVoice(options = {}) {
|
|
|
1764
1772
|
if (!text?.trim() || wsRef.current?.readyState !== WebSocket.OPEN) return;
|
|
1765
1773
|
wsRef.current.send(JSON.stringify({ type: "voice.text", text }));
|
|
1766
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
|
+
}, []);
|
|
1767
1779
|
return {
|
|
1768
1780
|
state,
|
|
1769
1781
|
isMuted,
|
|
@@ -1775,7 +1787,8 @@ function useVoice(options = {}) {
|
|
|
1775
1787
|
start,
|
|
1776
1788
|
stop,
|
|
1777
1789
|
mute,
|
|
1778
|
-
sendText
|
|
1790
|
+
sendText,
|
|
1791
|
+
updateContext
|
|
1779
1792
|
};
|
|
1780
1793
|
}
|
|
1781
1794
|
|