@personaai/react 0.7.0 → 0.7.1
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/README.md +39 -0
- package/dist/index.cjs +11 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/package.json +82 -82
package/dist/index.d.cts
CHANGED
|
@@ -300,6 +300,14 @@ type PersonaVoiceEndReason = "client_closed" | "agent_ended" | "max_duration" |
|
|
|
300
300
|
interface UseVoiceOptions {
|
|
301
301
|
/** Falls back to `PersonaProvider`'s `defaultAgentId` if omitted. */
|
|
302
302
|
agentId?: string;
|
|
303
|
+
/**
|
|
304
|
+
* Resume an existing conversation over voice instead of starting fresh.
|
|
305
|
+
* `start()` mints the session with this thread id (same value `useChat`'s
|
|
306
|
+
* `threadId` uses), so voice turns are persisted back into that thread's
|
|
307
|
+
* history — a later text message on the same thread sees them. Omit (or
|
|
308
|
+
* leave undefined) to start a fresh conversation.
|
|
309
|
+
*/
|
|
310
|
+
threadId?: string;
|
|
303
311
|
}
|
|
304
312
|
interface UseVoiceResult {
|
|
305
313
|
state: PersonaVoiceState;
|
package/dist/index.d.ts
CHANGED
|
@@ -300,6 +300,14 @@ type PersonaVoiceEndReason = "client_closed" | "agent_ended" | "max_duration" |
|
|
|
300
300
|
interface UseVoiceOptions {
|
|
301
301
|
/** Falls back to `PersonaProvider`'s `defaultAgentId` if omitted. */
|
|
302
302
|
agentId?: string;
|
|
303
|
+
/**
|
|
304
|
+
* Resume an existing conversation over voice instead of starting fresh.
|
|
305
|
+
* `start()` mints the session with this thread id (same value `useChat`'s
|
|
306
|
+
* `threadId` uses), so voice turns are persisted back into that thread's
|
|
307
|
+
* history — a later text message on the same thread sees them. Omit (or
|
|
308
|
+
* leave undefined) to start a fresh conversation.
|
|
309
|
+
*/
|
|
310
|
+
threadId?: string;
|
|
303
311
|
}
|
|
304
312
|
interface UseVoiceResult {
|
|
305
313
|
state: PersonaVoiceState;
|
package/dist/index.js
CHANGED
|
@@ -1308,6 +1308,7 @@ function useVoice(options = {}) {
|
|
|
1308
1308
|
const { defaultAgentId, fetchWithAuth, logger } = usePersonaContext();
|
|
1309
1309
|
const voiceLogger = useMemo3(() => logger.child("voice"), [logger]);
|
|
1310
1310
|
const agentId = options.agentId || defaultAgentId;
|
|
1311
|
+
const threadId = options.threadId;
|
|
1311
1312
|
const [state, setState] = useState4("idle");
|
|
1312
1313
|
const [isMuted, setIsMuted] = useState4(false);
|
|
1313
1314
|
const [transcript, setTranscript] = useState4(
|
|
@@ -1411,8 +1412,7 @@ function useVoice(options = {}) {
|
|
|
1411
1412
|
(id, patch) => {
|
|
1412
1413
|
setToolCalls((prev) => {
|
|
1413
1414
|
const idx = prev.findIndex((t) => t.id === id);
|
|
1414
|
-
if (idx === -1)
|
|
1415
|
-
return [...prev, { id, status: "running", ...patch }];
|
|
1415
|
+
if (idx === -1) return [...prev, { id, status: "running", ...patch }];
|
|
1416
1416
|
const next = [...prev];
|
|
1417
1417
|
next[idx] = { ...next[idx], ...patch };
|
|
1418
1418
|
return next;
|
|
@@ -1542,7 +1542,9 @@ function useVoice(options = {}) {
|
|
|
1542
1542
|
}
|
|
1543
1543
|
case "RUN_ERROR":
|
|
1544
1544
|
voiceLogger.warn("RUN_ERROR", { message: msg.message });
|
|
1545
|
-
setError(
|
|
1545
|
+
setError(
|
|
1546
|
+
new Error(msg.message || "The agent run failed.")
|
|
1547
|
+
);
|
|
1546
1548
|
setState("error");
|
|
1547
1549
|
break;
|
|
1548
1550
|
default:
|
|
@@ -1567,12 +1569,15 @@ function useVoice(options = {}) {
|
|
|
1567
1569
|
setToolCalls([]);
|
|
1568
1570
|
acceptedTurnSeqRef.current = 0;
|
|
1569
1571
|
setState("connecting");
|
|
1570
|
-
voiceLogger.debug("start() called", { agentId });
|
|
1572
|
+
voiceLogger.debug("start() called", { agentId, threadId });
|
|
1571
1573
|
try {
|
|
1572
1574
|
const res = await fetchWithAuth("/voice/sessions", {
|
|
1573
1575
|
method: "POST",
|
|
1574
1576
|
headers: { "Content-Type": "application/json" },
|
|
1575
|
-
body: JSON.stringify({
|
|
1577
|
+
body: JSON.stringify({
|
|
1578
|
+
agentId,
|
|
1579
|
+
...threadId ? { threadId } : {}
|
|
1580
|
+
})
|
|
1576
1581
|
});
|
|
1577
1582
|
if (!res.ok) {
|
|
1578
1583
|
throw new Error(`Failed to start voice session: ${res.statusText}`);
|
|
@@ -1607,7 +1612,7 @@ function useVoice(options = {}) {
|
|
|
1607
1612
|
}
|
|
1608
1613
|
teardownAudio();
|
|
1609
1614
|
}
|
|
1610
|
-
}, [agentId, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
|
|
1615
|
+
}, [agentId, threadId, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
|
|
1611
1616
|
const mute = useCallback4((muted) => {
|
|
1612
1617
|
setIsMuted(muted);
|
|
1613
1618
|
streamRef.current?.getAudioTracks().forEach((track) => {
|