@personaai/react 0.7.1 → 0.7.3

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.3";
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.3";
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,29 @@ 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 sameUserBurst = speaker === "user" && last && last.speaker === speaker && last.turnSeq === turnSeq;
1443
+ setTranscript((prev) => {
1444
+ const tail = prev[prev.length - 1];
1445
+ const agentContinues = speaker === "agent" && tail?.speaker === "agent";
1446
+ if (agentContinues || sameUserBurst && tail?.speaker === "user") {
1447
+ const merged = mergeTranscriptText(tail.text, text);
1448
+ if (merged === tail.text) return prev;
1449
+ return prev.map(
1450
+ (l, i) => i === prev.length - 1 ? { ...l, text: merged } : l
1451
+ );
1434
1452
  }
1435
- },
1436
- []
1437
- );
1453
+ return [...prev, { id: `${speaker}-${prev.length}`, speaker, text }];
1454
+ });
1455
+ lastFinalTurnRef.current = { speaker, turnSeq };
1456
+ }, []);
1438
1457
  const handleCustomEvent = useCallback4(
1439
1458
  (name, value) => {
1440
1459
  switch (name) {
@@ -1467,9 +1486,7 @@ function useVoice(options = {}) {
1467
1486
  }
1468
1487
  break;
1469
1488
  case "voice_transcript":
1470
- handleTranscript(
1471
- value
1472
- );
1489
+ handleTranscript(value);
1473
1490
  break;
1474
1491
  case "voice_interrupted":
1475
1492
  acceptedTurnSeqRef.current = value.turnSeq;
@@ -1872,7 +1889,7 @@ import {
1872
1889
  getLogLevel,
1873
1890
  isLevelEnabled
1874
1891
  } from "@personaai/logger";
1875
- var VERSION = "0.7.0";
1892
+ var VERSION = "0.7.3";
1876
1893
  export {
1877
1894
  PersonaProvider,
1878
1895
  VERSION,