@personaai/react 0.7.1 → 0.7.2

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.d.cts CHANGED
@@ -574,6 +574,6 @@ declare function supportsStreamingFetch(): boolean;
574
574
  */
575
575
  declare function openSSEStream(opts: OpenSSEOptions): Promise<SSEStream>;
576
576
 
577
- declare const VERSION = "0.7.0";
577
+ declare const VERSION = "0.7.2";
578
578
 
579
579
  export { type OpenSSEOptions, type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMcpConnection, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, type PersonaPresentedFile, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaTodo, type PersonaToolCall, type PersonaVoiceEndReason, type PersonaVoiceState, type PersonaVoiceToolCall, type PersonaVoiceTranscriptLine, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendMessageOverride, type UseChatOptions, type UseMcpConnectionsOptions, type UseVoiceOptions, type UseVoiceResult, VERSION, openSSEStream, supportsStreamingFetch, useAgents, useChat, useConnection, useFiles, useMcpConnections, useMemory, usePersonaContext, useThreads, useVoice };
package/dist/index.d.ts CHANGED
@@ -574,6 +574,6 @@ declare function supportsStreamingFetch(): boolean;
574
574
  */
575
575
  declare function openSSEStream(opts: OpenSSEOptions): Promise<SSEStream>;
576
576
 
577
- declare const VERSION = "0.7.0";
577
+ declare const VERSION = "0.7.2";
578
578
 
579
579
  export { type OpenSSEOptions, type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMcpConnection, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, type PersonaPresentedFile, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaTodo, type PersonaToolCall, type PersonaVoiceEndReason, type PersonaVoiceState, type PersonaVoiceToolCall, type PersonaVoiceTranscriptLine, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendMessageOverride, type UseChatOptions, type UseMcpConnectionsOptions, type UseVoiceOptions, type UseVoiceResult, VERSION, openSSEStream, supportsStreamingFetch, useAgents, useChat, useConnection, useFiles, useMcpConnections, useMemory, usePersonaContext, useThreads, useVoice };
package/dist/index.js CHANGED
@@ -1304,6 +1304,14 @@ function playerWorkletUrl() {
1304
1304
  }
1305
1305
 
1306
1306
  // src/hooks/useVoice.ts
1307
+ function mergeTranscriptText(prev, next) {
1308
+ if (!prev) return next;
1309
+ if (!next) return prev;
1310
+ if (next === prev || prev.endsWith(next)) return prev;
1311
+ if (next.startsWith(prev)) return next;
1312
+ const needSpace = !/\s$/.test(prev) && !/^\s/.test(next);
1313
+ return prev + (needSpace ? " " : "") + next;
1314
+ }
1307
1315
  function useVoice(options = {}) {
1308
1316
  const { defaultAgentId, fetchWithAuth, logger } = usePersonaContext();
1309
1317
  const voiceLogger = useMemo3(() => logger.child("voice"), [logger]);
@@ -1330,6 +1338,9 @@ function useVoice(options = {}) {
1330
1338
  const playerNodeRef = useRef2(null);
1331
1339
  const acceptedTurnSeqRef = useRef2(0);
1332
1340
  const mountedRef = useRef2(true);
1341
+ const lastFinalTurnRef = useRef2(
1342
+ null
1343
+ );
1333
1344
  useEffect4(() => {
1334
1345
  mountedRef.current = true;
1335
1346
  return () => {
@@ -1420,21 +1431,28 @@ function useVoice(options = {}) {
1420
1431
  },
1421
1432
  []
1422
1433
  );
1423
- const handleTranscript = useCallback4(
1424
- (value) => {
1425
- const { speaker, text, isFinal } = value;
1426
- if (isFinal) {
1427
- setPartial((prev) => prev?.speaker === speaker ? null : prev);
1428
- setTranscript((prev) => [
1429
- ...prev,
1430
- { id: `${speaker}-${prev.length}`, speaker, text }
1431
- ]);
1432
- } else {
1433
- setPartial({ id: "partial", speaker, text });
1434
+ const handleTranscript = useCallback4((value) => {
1435
+ const { speaker, text, isFinal, turnSeq } = value;
1436
+ if (!isFinal) {
1437
+ setPartial({ id: "partial", speaker, text });
1438
+ return;
1439
+ }
1440
+ setPartial((prev) => prev?.speaker === speaker ? null : prev);
1441
+ const last = lastFinalTurnRef.current;
1442
+ const sameUtterance = last && last.speaker === speaker && last.turnSeq === turnSeq;
1443
+ setTranscript((prev) => {
1444
+ const tail = prev[prev.length - 1];
1445
+ if (sameUtterance && tail?.speaker === speaker) {
1446
+ const merged = mergeTranscriptText(tail.text, text);
1447
+ if (merged === tail.text) return prev;
1448
+ return prev.map(
1449
+ (l, i) => i === prev.length - 1 ? { ...l, text: merged } : l
1450
+ );
1434
1451
  }
1435
- },
1436
- []
1437
- );
1452
+ return [...prev, { id: `${speaker}-${prev.length}`, speaker, text }];
1453
+ });
1454
+ lastFinalTurnRef.current = { speaker, turnSeq };
1455
+ }, []);
1438
1456
  const handleCustomEvent = useCallback4(
1439
1457
  (name, value) => {
1440
1458
  switch (name) {
@@ -1467,9 +1485,7 @@ function useVoice(options = {}) {
1467
1485
  }
1468
1486
  break;
1469
1487
  case "voice_transcript":
1470
- handleTranscript(
1471
- value
1472
- );
1488
+ handleTranscript(value);
1473
1489
  break;
1474
1490
  case "voice_interrupted":
1475
1491
  acceptedTurnSeqRef.current = value.turnSeq;
@@ -1872,7 +1888,7 @@ import {
1872
1888
  getLogLevel,
1873
1889
  isLevelEnabled
1874
1890
  } from "@personaai/logger";
1875
- var VERSION = "0.7.0";
1891
+ var VERSION = "0.7.2";
1876
1892
  export {
1877
1893
  PersonaProvider,
1878
1894
  VERSION,