@bytexbyte/nxtlinq-ai-agent-ui-react-development 0.1.1 → 0.1.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/context/AgentAssistantContext.d.ts.map +1 -1
- package/dist/context/AgentAssistantContext.js +3 -1
- package/dist/legacy/chatbot/ui/ChatBotHeader.d.ts +15 -0
- package/dist/legacy/chatbot/ui/ChatBotHeader.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/ChatBotHeader.js +62 -0
- package/dist/legacy/chatbot/ui/ChatBotUI.d.ts.map +1 -1
- package/dist/legacy/chatbot/ui/ChatBotUI.js +3 -71
- package/dist/legacy/chatbot/ui/chatBotHeaderParts.d.ts +15 -0
- package/dist/legacy/chatbot/ui/chatBotHeaderParts.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/chatBotHeaderParts.js +50 -0
- package/dist/voice/useVoiceTranscriptMessages.d.ts +7 -5
- package/dist/voice/useVoiceTranscriptMessages.d.ts.map +1 -1
- package/dist/voice/useVoiceTranscriptMessages.js +79 -76
- package/dist/voice/voiceUserBubble.d.ts +10 -0
- package/dist/voice/voiceUserBubble.d.ts.map +1 -0
- package/dist/voice/voiceUserBubble.js +52 -0
- package/package.json +5 -5
- package/src/context/AgentAssistantContext.tsx +4 -2
- package/src/legacy/chatbot/ui/ChatBotHeader.tsx +143 -0
- package/src/legacy/chatbot/ui/ChatBotUI.tsx +13 -144
- package/src/legacy/chatbot/ui/chatBotHeaderParts.tsx +115 -0
- package/src/voice/useVoiceTranscriptMessages.ts +87 -72
- package/src/voice/voiceUserBubble.ts +71 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Message } from '@bytexbyte/nxtlinq-ai-agent-core-development';
|
|
2
|
+
|
|
3
|
+
export const VOICE_USER_INPUT_PLACEHOLDER = '(Voice input)';
|
|
4
|
+
|
|
5
|
+
type VoiceMeta = {
|
|
6
|
+
voiceRealtime: true;
|
|
7
|
+
voiceSessionId?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/** Ensure a user bubble exists before the in-flight assistant reply for this turn. */
|
|
11
|
+
export function ensureUserBubbleForVoiceTurn(
|
|
12
|
+
messages: Message[],
|
|
13
|
+
userText: string,
|
|
14
|
+
userMessageId: string | null | undefined,
|
|
15
|
+
metaForPlaceholder: VoiceMeta | undefined,
|
|
16
|
+
): Message[] {
|
|
17
|
+
const streamIdx = messages.findIndex((m) => m.isStreaming && m.role === 'assistant');
|
|
18
|
+
const insertAt = streamIdx >= 0 ? streamIdx : messages.length;
|
|
19
|
+
const before = messages.slice(0, insertAt);
|
|
20
|
+
|
|
21
|
+
const lastAsstIdx = (() => {
|
|
22
|
+
for (let i = before.length - 1; i >= 0; i -= 1) {
|
|
23
|
+
const m = before[i];
|
|
24
|
+
if (m.role === 'assistant' && !m.isStreaming && Boolean(m.content?.trim())) return i;
|
|
25
|
+
}
|
|
26
|
+
return -1;
|
|
27
|
+
})();
|
|
28
|
+
const lastUserIdx = (() => {
|
|
29
|
+
for (let i = before.length - 1; i >= 0; i -= 1) {
|
|
30
|
+
if (before[i].role === 'user') return i;
|
|
31
|
+
}
|
|
32
|
+
return -1;
|
|
33
|
+
})();
|
|
34
|
+
const hasUserForTurn = lastUserIdx >= 0 && lastUserIdx > lastAsstIdx;
|
|
35
|
+
|
|
36
|
+
const trimmed = userText.trim();
|
|
37
|
+
const displayText = trimmed || VOICE_USER_INPUT_PLACEHOLDER;
|
|
38
|
+
|
|
39
|
+
if (hasUserForTurn) {
|
|
40
|
+
const existing = before[lastUserIdx];
|
|
41
|
+
const shouldUpgrade =
|
|
42
|
+
trimmed &&
|
|
43
|
+
existing.content !== trimmed &&
|
|
44
|
+
(existing.content === VOICE_USER_INPUT_PLACEHOLDER || !existing.content.trim());
|
|
45
|
+
if (!shouldUpgrade) return messages;
|
|
46
|
+
|
|
47
|
+
const upgraded = before.map((m, i) =>
|
|
48
|
+
i === lastUserIdx
|
|
49
|
+
? {
|
|
50
|
+
...m,
|
|
51
|
+
content: trimmed,
|
|
52
|
+
id: userMessageId ?? m.id,
|
|
53
|
+
metadata: userMessageId ? undefined : m.metadata,
|
|
54
|
+
}
|
|
55
|
+
: m,
|
|
56
|
+
);
|
|
57
|
+
return [...upgraded, ...messages.slice(insertAt)];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const userMsg: Message = {
|
|
61
|
+
id: userMessageId ?? `voice-user-${Date.now()}`,
|
|
62
|
+
role: 'user',
|
|
63
|
+
content: displayText,
|
|
64
|
+
timestamp: new Date().toISOString(),
|
|
65
|
+
metadata: userMessageId ? undefined : metaForPlaceholder,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const next = [...messages];
|
|
69
|
+
next.splice(insertAt, 0, userMsg);
|
|
70
|
+
return next;
|
|
71
|
+
}
|