@bytexbyte/nxtlinq-ai-agent-ui-react-development 0.1.2 → 0.1.4
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/ChatBot.d.ts +5 -0
- package/dist/ChatBot.d.ts.map +1 -0
- package/dist/ChatBot.js +35 -0
- package/dist/assets/images/adiSideItalicDataUri.d.ts +2 -0
- package/dist/assets/images/adiSideItalicDataUri.d.ts.map +1 -0
- package/dist/assets/images/adiSideItalicDataUri.js +1 -0
- package/dist/context/AgentAssistantContext.d.ts.map +1 -1
- package/dist/context/AgentAssistantContext.js +18 -0
- package/dist/context/ChatBotContext.d.ts +5 -0
- package/dist/context/ChatBotContext.d.ts.map +1 -0
- package/dist/context/ChatBotContext.js +2908 -0
- package/dist/index.d.ts +5 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -11
- package/dist/legacy/chatbot/context/ChatBotContext.d.ts.map +1 -1
- package/dist/legacy/chatbot/context/ChatBotContext.js +14 -0
- package/dist/types/ChatBotTypes.d.ts +166 -0
- package/dist/types/ChatBotTypes.d.ts.map +1 -0
- package/dist/types/ChatBotTypes.js +1 -0
- package/dist/ui/BerifyMeModal.d.ts +17 -0
- package/dist/ui/BerifyMeModal.d.ts.map +1 -0
- package/dist/ui/BerifyMeModal.js +110 -0
- package/dist/ui/ChatBotHeader.d.ts +15 -0
- package/dist/ui/ChatBotHeader.d.ts.map +1 -0
- package/dist/ui/ChatBotHeader.js +62 -0
- package/dist/ui/ChatBotUI.d.ts +3 -0
- package/dist/ui/ChatBotUI.d.ts.map +1 -0
- package/dist/ui/ChatBotUI.js +557 -0
- package/dist/ui/MessageInput.d.ts +3 -0
- package/dist/ui/MessageInput.d.ts.map +1 -0
- package/dist/ui/MessageInput.js +321 -0
- package/dist/ui/MessageList.d.ts +4 -0
- package/dist/ui/MessageList.d.ts.map +1 -0
- package/dist/ui/MessageList.js +455 -0
- package/dist/ui/ModelSelector.d.ts +4 -0
- package/dist/ui/ModelSelector.d.ts.map +1 -0
- package/dist/ui/ModelSelector.js +122 -0
- package/dist/ui/NotificationModal.d.ts +15 -0
- package/dist/ui/NotificationModal.d.ts.map +1 -0
- package/dist/ui/NotificationModal.js +53 -0
- package/dist/ui/PermissionForm.d.ts +8 -0
- package/dist/ui/PermissionForm.d.ts.map +1 -0
- package/dist/ui/PermissionForm.js +465 -0
- package/dist/ui/PresetMessages.d.ts +4 -0
- package/dist/ui/PresetMessages.d.ts.map +1 -0
- package/dist/ui/PresetMessages.js +33 -0
- package/dist/ui/VoiceModePanel.d.ts +3 -0
- package/dist/ui/VoiceModePanel.d.ts.map +1 -0
- package/dist/ui/VoiceModePanel.js +95 -0
- package/dist/ui/chatBotHeaderParts.d.ts +15 -0
- package/dist/ui/chatBotHeaderParts.d.ts.map +1 -0
- package/dist/ui/chatBotHeaderParts.js +50 -0
- package/dist/ui/index.d.ts +9 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +8 -0
- package/dist/ui/styles/isolatedStyles.d.ts +73 -0
- package/dist/ui/styles/isolatedStyles.d.ts.map +1 -0
- package/dist/ui/styles/isolatedStyles.js +985 -0
- package/package.json +3 -3
- package/src/{legacy/chatbot/context → context}/ChatBotContext.tsx +0 -1
- package/src/index.ts +17 -40
- package/src/{legacy/chatbot/ui → ui}/ModelSelector.tsx +1 -1
- package/src/{legacy/chatbot/ui → ui}/VoiceModePanel.tsx +1 -1
- package/src/ui/index.ts +8 -0
- package/src/NxtlinqAgentChat.tsx +0 -79
- package/src/components/AgentAssistantShell.tsx +0 -104
- package/src/components/AgentComposer.tsx +0 -134
- package/src/components/AgentMessageList.tsx +0 -78
- package/src/components/AgentRemoteAudio.tsx +0 -34
- package/src/components/AgentVoiceBar.tsx +0 -173
- package/src/components/PresetMessageChips.tsx +0 -41
- package/src/context/AgentAssistantContext.tsx +0 -278
- package/src/legacy/index.ts +0 -26
- package/src/theme/defaultTheme.ts +0 -22
- package/src/types.ts +0 -65
- package/src/voice/useVoiceConnectOrchestration.ts +0 -117
- package/src/voice/useVoiceMicState.ts +0 -117
- package/src/voice/useVoiceTranscriptMessages.ts +0 -188
- package/src/voice/voiceMicConstants.ts +0 -13
- package/src/voice/voiceUserBubble.ts +0 -71
- /package/src/{legacy/chatbot/ChatBot.tsx → ChatBot.tsx} +0 -0
- /package/src/{legacy/assets → assets}/images/adiSideItalicDataUri.ts +0 -0
- /package/src/{legacy/chatbot/types → types}/ChatBotTypes.ts +0 -0
- /package/src/{legacy/chatbot/ui → ui}/BerifyMeModal.tsx +0 -0
- /package/src/{legacy/chatbot/ui → ui}/ChatBotHeader.tsx +0 -0
- /package/src/{legacy/chatbot/ui → ui}/ChatBotUI.tsx +0 -0
- /package/src/{legacy/chatbot/ui → ui}/MessageInput.tsx +0 -0
- /package/src/{legacy/chatbot/ui → ui}/MessageList.tsx +0 -0
- /package/src/{legacy/chatbot/ui → ui}/NotificationModal.tsx +0 -0
- /package/src/{legacy/chatbot/ui → ui}/PermissionForm.tsx +0 -0
- /package/src/{legacy/chatbot/ui → ui}/PresetMessages.tsx +0 -0
- /package/src/{legacy/chatbot/ui → ui}/chatBotHeaderParts.tsx +0 -0
- /package/src/{legacy/chatbot/ui → ui}/styles/isolatedStyles.ts +0 -0
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import React, { useCallback } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
useAgentAssistant,
|
|
4
|
-
voiceStatusLabel,
|
|
5
|
-
} from '../context/AgentAssistantContext';
|
|
6
|
-
|
|
7
|
-
function statusDotColor(
|
|
8
|
-
status: ReturnType<typeof useAgentAssistant>['voiceStatus'],
|
|
9
|
-
theme: ReturnType<typeof useAgentAssistant>['theme'],
|
|
10
|
-
): string {
|
|
11
|
-
switch (status) {
|
|
12
|
-
case 'listening':
|
|
13
|
-
return theme.colors.voiceActive;
|
|
14
|
-
case 'speaking':
|
|
15
|
-
return theme.colors.voiceSpeaking;
|
|
16
|
-
case 'idle':
|
|
17
|
-
return theme.colors.mutedText;
|
|
18
|
-
default:
|
|
19
|
-
return theme.colors.primary;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function MicIcon({ color }: { color: string }): React.ReactElement {
|
|
24
|
-
return (
|
|
25
|
-
<svg width="24" height="24" viewBox="0 0 24 24" fill={color} aria-hidden>
|
|
26
|
-
<path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z" />
|
|
27
|
-
</svg>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function MicOffIcon(): React.ReactElement {
|
|
32
|
-
return (
|
|
33
|
-
<svg width="24" height="24" viewBox="0 0 24 24" fill="#ef4444" aria-hidden>
|
|
34
|
-
<path d="M19 11h-1.7c0 .74-.16 1.43-.43 2.05l1.23 1.23c.56-.98.9-2.09.9-3.28zm-4.02.17c0-.06.02-.11.02-.17V5c0-1.66-1.34-3-3-3s-3 1.34-3 3v.18l5.98 5.99zM4.27 3L3 4.27l6.01 6.01V11c0 1.66 1.33 3 2.99 3 .22 0 .44-.03.65-.08l1.66 1.66c-.71.33-1.5.52-2.31.52-2.76 0-5.3-2.1-5.3-5.1H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c.91-.13 1.77-.45 2.54-.9L19.73 21 21 19.73 4.27 3z" />
|
|
35
|
-
</svg>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function AgentVoiceBar(): React.ReactElement | null {
|
|
40
|
-
const {
|
|
41
|
-
theme,
|
|
42
|
-
interactionMode,
|
|
43
|
-
voiceStatus,
|
|
44
|
-
voiceSessionId,
|
|
45
|
-
isVoiceConnecting,
|
|
46
|
-
isVoiceChannelReady,
|
|
47
|
-
stopVoice,
|
|
48
|
-
isVoiceAvailable,
|
|
49
|
-
isMicMuted,
|
|
50
|
-
isMicHeldForAssistant,
|
|
51
|
-
toggleVoiceMicMute,
|
|
52
|
-
} = useAgentAssistant();
|
|
53
|
-
|
|
54
|
-
const returnToTextMode = useCallback(() => {
|
|
55
|
-
void stopVoice();
|
|
56
|
-
}, [stopVoice]);
|
|
57
|
-
|
|
58
|
-
if (!isVoiceAvailable) return null;
|
|
59
|
-
if (interactionMode !== 'voice' && !isVoiceConnecting) return null;
|
|
60
|
-
|
|
61
|
-
const showConnecting = isVoiceConnecting;
|
|
62
|
-
const awaitingChannel =
|
|
63
|
-
Boolean(voiceSessionId) &&
|
|
64
|
-
!isVoiceConnecting &&
|
|
65
|
-
!isVoiceChannelReady &&
|
|
66
|
-
voiceStatus === 'idle';
|
|
67
|
-
|
|
68
|
-
const statusHint = showConnecting
|
|
69
|
-
? 'Tap Back to text mode below to cancel'
|
|
70
|
-
: awaitingChannel
|
|
71
|
-
? 'Waiting for voice channel…'
|
|
72
|
-
: isMicHeldForAssistant
|
|
73
|
-
? 'Assistant is responding — tap mic to interrupt and speak'
|
|
74
|
-
: isMicMuted
|
|
75
|
-
? 'Mic is off — tap the mic when ready to speak'
|
|
76
|
-
: voiceStatus === 'listening'
|
|
77
|
-
? 'Start speaking'
|
|
78
|
-
: voiceStatus === 'speaking'
|
|
79
|
-
? 'Assistant is speaking…'
|
|
80
|
-
: voiceStatus === 'thinking'
|
|
81
|
-
? 'Thinking…'
|
|
82
|
-
: '';
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<div
|
|
86
|
-
style={{
|
|
87
|
-
borderTop: `1px solid ${theme.colors.border}`,
|
|
88
|
-
backgroundColor: theme.colors.surface,
|
|
89
|
-
padding: theme.spacing.md,
|
|
90
|
-
}}
|
|
91
|
-
>
|
|
92
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
|
93
|
-
<div
|
|
94
|
-
style={{
|
|
95
|
-
flex: 1,
|
|
96
|
-
minWidth: 0,
|
|
97
|
-
border: `1px solid ${theme.colors.border}`,
|
|
98
|
-
borderRadius: 12,
|
|
99
|
-
backgroundColor: theme.colors.background,
|
|
100
|
-
padding: '8px 10px',
|
|
101
|
-
}}
|
|
102
|
-
>
|
|
103
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
|
104
|
-
<span
|
|
105
|
-
style={{
|
|
106
|
-
width: 8,
|
|
107
|
-
height: 8,
|
|
108
|
-
borderRadius: 4,
|
|
109
|
-
backgroundColor: statusDotColor(voiceStatus, theme),
|
|
110
|
-
flexShrink: 0,
|
|
111
|
-
}}
|
|
112
|
-
/>
|
|
113
|
-
<span
|
|
114
|
-
style={{
|
|
115
|
-
color: theme.colors.assistantText,
|
|
116
|
-
fontSize: theme.typography.captionSize,
|
|
117
|
-
fontWeight: 600,
|
|
118
|
-
}}
|
|
119
|
-
>
|
|
120
|
-
{showConnecting || awaitingChannel ? 'Connecting' : voiceStatusLabel(voiceStatus)}
|
|
121
|
-
</span>
|
|
122
|
-
{showConnecting ? (
|
|
123
|
-
<span style={{ color: theme.colors.mutedText, fontSize: theme.typography.captionSize }}>
|
|
124
|
-
…
|
|
125
|
-
</span>
|
|
126
|
-
) : null}
|
|
127
|
-
</div>
|
|
128
|
-
{statusHint ? (
|
|
129
|
-
<p
|
|
130
|
-
style={{
|
|
131
|
-
margin: '4px 0 0',
|
|
132
|
-
color: theme.colors.mutedText,
|
|
133
|
-
fontSize: theme.typography.captionSize - 1,
|
|
134
|
-
}}
|
|
135
|
-
>
|
|
136
|
-
{statusHint}
|
|
137
|
-
</p>
|
|
138
|
-
) : null}
|
|
139
|
-
</div>
|
|
140
|
-
<button
|
|
141
|
-
type="button"
|
|
142
|
-
onClick={toggleVoiceMicMute}
|
|
143
|
-
disabled={showConnecting || awaitingChannel}
|
|
144
|
-
style={{
|
|
145
|
-
border: 'none',
|
|
146
|
-
background: 'none',
|
|
147
|
-
padding: 8,
|
|
148
|
-
cursor: showConnecting || awaitingChannel ? 'not-allowed' : 'pointer',
|
|
149
|
-
opacity: showConnecting || awaitingChannel ? 0.45 : 1,
|
|
150
|
-
}}
|
|
151
|
-
aria-label={isMicMuted ? 'Unmute microphone' : 'Mute microphone'}
|
|
152
|
-
>
|
|
153
|
-
{isMicMuted ? <MicOffIcon /> : <MicIcon color={theme.colors.assistantText} />}
|
|
154
|
-
</button>
|
|
155
|
-
</div>
|
|
156
|
-
<button
|
|
157
|
-
type="button"
|
|
158
|
-
onClick={returnToTextMode}
|
|
159
|
-
style={{
|
|
160
|
-
display: 'block',
|
|
161
|
-
margin: `${theme.spacing.sm}px auto 0`,
|
|
162
|
-
border: 'none',
|
|
163
|
-
background: 'none',
|
|
164
|
-
color: theme.colors.primary,
|
|
165
|
-
fontSize: theme.typography.captionSize,
|
|
166
|
-
cursor: 'pointer',
|
|
167
|
-
}}
|
|
168
|
-
>
|
|
169
|
-
Back to text mode
|
|
170
|
-
</button>
|
|
171
|
-
</div>
|
|
172
|
-
);
|
|
173
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useAgentAssistant } from '../context/AgentAssistantContext';
|
|
3
|
-
import type { PresetMessage } from '../types';
|
|
4
|
-
|
|
5
|
-
export function PresetMessageChips(): React.ReactElement | null {
|
|
6
|
-
const { presetMessages, selectPreset, theme, interactionMode } = useAgentAssistant();
|
|
7
|
-
if (!presetMessages.length || interactionMode === 'voice') {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
<div
|
|
13
|
-
style={{
|
|
14
|
-
display: 'flex',
|
|
15
|
-
flexWrap: 'wrap',
|
|
16
|
-
gap: theme.spacing.sm,
|
|
17
|
-
padding: `${theme.spacing.sm}px ${theme.spacing.md}px`,
|
|
18
|
-
borderBottom: `1px solid ${theme.colors.border}`,
|
|
19
|
-
}}
|
|
20
|
-
>
|
|
21
|
-
{presetMessages.map((preset: PresetMessage, index: number) => (
|
|
22
|
-
<button
|
|
23
|
-
key={`${preset.text}-${index}`}
|
|
24
|
-
type="button"
|
|
25
|
-
onClick={() => void selectPreset(preset)}
|
|
26
|
-
style={{
|
|
27
|
-
border: `1px solid ${theme.colors.border}`,
|
|
28
|
-
borderRadius: theme.radius.button,
|
|
29
|
-
padding: `${theme.spacing.xs}px ${theme.spacing.sm}px`,
|
|
30
|
-
backgroundColor: theme.colors.surface,
|
|
31
|
-
color: theme.colors.assistantText,
|
|
32
|
-
fontSize: theme.typography.captionSize,
|
|
33
|
-
cursor: 'pointer',
|
|
34
|
-
}}
|
|
35
|
-
>
|
|
36
|
-
{preset.text}
|
|
37
|
-
</button>
|
|
38
|
-
))}
|
|
39
|
-
</div>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import type { Message, VoiceStatus } from '@bytexbyte/nxtlinq-ai-agent-core-development';
|
|
2
|
-
import {
|
|
3
|
-
useNxtlinqAgent,
|
|
4
|
-
useNxtlinqVoice,
|
|
5
|
-
type UseNxtlinqAgentResult,
|
|
6
|
-
type UseNxtlinqVoiceResult,
|
|
7
|
-
} from '@bytexbyte/nxtlinq-ai-agent-web-development';
|
|
8
|
-
import React, {
|
|
9
|
-
createContext,
|
|
10
|
-
useCallback,
|
|
11
|
-
useContext,
|
|
12
|
-
useEffect,
|
|
13
|
-
useMemo,
|
|
14
|
-
useState,
|
|
15
|
-
type ReactNode,
|
|
16
|
-
} from 'react';
|
|
17
|
-
import { defaultAgentAssistantTheme } from '../theme/defaultTheme';
|
|
18
|
-
import type { AgentAssistantTheme, NxtlinqAgentChatProps, PresetMessage } from '../types';
|
|
19
|
-
import { useVoiceConnectOrchestration } from '../voice/useVoiceConnectOrchestration';
|
|
20
|
-
import { useVoiceMicState } from '../voice/useVoiceMicState';
|
|
21
|
-
import { useVoiceTranscriptMessages } from '../voice/useVoiceTranscriptMessages';
|
|
22
|
-
|
|
23
|
-
export type InteractionMode = 'text' | 'voice';
|
|
24
|
-
|
|
25
|
-
export type AgentAssistantContextValue = UseNxtlinqAgentResult &
|
|
26
|
-
UseNxtlinqVoiceResult & {
|
|
27
|
-
theme: AgentAssistantTheme;
|
|
28
|
-
title: string;
|
|
29
|
-
placeholder: string;
|
|
30
|
-
presetMessages: PresetMessage[];
|
|
31
|
-
interactionMode: InteractionMode;
|
|
32
|
-
setInteractionMode: (mode: InteractionMode) => void;
|
|
33
|
-
inputText: string;
|
|
34
|
-
setInputText: (text: string) => void;
|
|
35
|
-
isVoiceAvailable: boolean;
|
|
36
|
-
isVoiceConnecting: boolean;
|
|
37
|
-
isMicMuted: boolean;
|
|
38
|
-
isMicHeldForAssistant: boolean;
|
|
39
|
-
toggleVoiceMicMute: () => void;
|
|
40
|
-
isVoiceChannelReady: boolean;
|
|
41
|
-
enableFileUpload: boolean;
|
|
42
|
-
sendText: () => Promise<void>;
|
|
43
|
-
selectPreset: (preset: PresetMessage) => Promise<void>;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const AgentAssistantContext = createContext<AgentAssistantContextValue | null>(null);
|
|
47
|
-
|
|
48
|
-
export type AgentAssistantProviderProps = {
|
|
49
|
-
children: ReactNode;
|
|
50
|
-
ui: Pick<
|
|
51
|
-
NxtlinqAgentChatProps,
|
|
52
|
-
| 'title'
|
|
53
|
-
| 'placeholder'
|
|
54
|
-
| 'presetMessages'
|
|
55
|
-
| 'enableVoice'
|
|
56
|
-
| 'enableFileUpload'
|
|
57
|
-
| 'theme'
|
|
58
|
-
| 'startWithMicMuted'
|
|
59
|
-
| 'holdMicDuringAssistant'
|
|
60
|
-
>;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export function AgentAssistantProvider({
|
|
64
|
-
children,
|
|
65
|
-
ui,
|
|
66
|
-
}: AgentAssistantProviderProps): React.ReactElement {
|
|
67
|
-
const agent = useNxtlinqAgent();
|
|
68
|
-
const voice = useNxtlinqVoice();
|
|
69
|
-
const [interactionMode, setInteractionModeState] = useState<InteractionMode>('text');
|
|
70
|
-
const [inputText, setInputText] = useState('');
|
|
71
|
-
const [isVoiceConnecting, setIsVoiceConnecting] = useState(false);
|
|
72
|
-
|
|
73
|
-
const isVoiceAvailable = ui.enableVoice !== false;
|
|
74
|
-
const micStartsMuted = ui.startWithMicMuted ?? true;
|
|
75
|
-
|
|
76
|
-
const handleVoiceBargeIn = useCallback(() => {
|
|
77
|
-
voice.interrupt();
|
|
78
|
-
}, [voice]);
|
|
79
|
-
|
|
80
|
-
const {
|
|
81
|
-
isMicMuted,
|
|
82
|
-
isMicHeldForAssistant,
|
|
83
|
-
toggleVoiceMicMute,
|
|
84
|
-
prepareForVoiceConnect,
|
|
85
|
-
resetMicState,
|
|
86
|
-
clearAssistantMicHold,
|
|
87
|
-
} = useVoiceMicState(voice, isVoiceConnecting, {
|
|
88
|
-
startWithMicMuted: micStartsMuted,
|
|
89
|
-
holdMicDuringAssistant: ui.holdMicDuringAssistant ?? true,
|
|
90
|
-
onBargeIn: handleVoiceBargeIn,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const voiceTranscriptApi = useMemo(
|
|
94
|
-
() => ({
|
|
95
|
-
getMessages: () => agent.agent.getSnapshot().messages,
|
|
96
|
-
updateMessages: (updater: (prev: Message[]) => Message[]) => {
|
|
97
|
-
agent.setMessages(updater(agent.agent.getSnapshot().messages));
|
|
98
|
-
},
|
|
99
|
-
syncVoiceTurnHistory: agent.syncVoiceTurnHistory,
|
|
100
|
-
}),
|
|
101
|
-
[agent.agent, agent.setMessages, agent.syncVoiceTurnHistory],
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const { handleTranscript, handleDone, clearVoiceStream } = useVoiceTranscriptMessages(
|
|
105
|
-
voiceTranscriptApi,
|
|
106
|
-
interactionMode,
|
|
107
|
-
voice.voiceSessionId,
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const setInteractionMode = useCallback(
|
|
111
|
-
(mode: InteractionMode) => {
|
|
112
|
-
if (mode === 'text' && interactionMode === 'voice') {
|
|
113
|
-
void voice.stopVoice('switch_to_text').then(() => {
|
|
114
|
-
clearVoiceStream();
|
|
115
|
-
resetMicState();
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
setInteractionModeState(mode);
|
|
119
|
-
},
|
|
120
|
-
[interactionMode, voice, resetMicState, clearVoiceStream],
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
if (interactionMode === 'text' && voice.voiceSessionId != null) {
|
|
125
|
-
void voice.stopVoice('mode_text_cleanup').then(() => {
|
|
126
|
-
clearVoiceStream();
|
|
127
|
-
resetMicState();
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}, [interactionMode, voice.voiceSessionId, voice, resetMicState, clearVoiceStream]);
|
|
131
|
-
|
|
132
|
-
const orchestrationCallbacks = useMemo(
|
|
133
|
-
() => ({
|
|
134
|
-
handleTranscript,
|
|
135
|
-
handleDone,
|
|
136
|
-
clearVoiceStream,
|
|
137
|
-
prepareForVoiceConnect,
|
|
138
|
-
resetMicState,
|
|
139
|
-
clearAssistantMicHold,
|
|
140
|
-
setInteractionMode,
|
|
141
|
-
setIsVoiceConnecting,
|
|
142
|
-
}),
|
|
143
|
-
[
|
|
144
|
-
handleTranscript,
|
|
145
|
-
handleDone,
|
|
146
|
-
clearVoiceStream,
|
|
147
|
-
prepareForVoiceConnect,
|
|
148
|
-
resetMicState,
|
|
149
|
-
clearAssistantMicHold,
|
|
150
|
-
setInteractionMode,
|
|
151
|
-
],
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
const {
|
|
155
|
-
wrappedStartVoice,
|
|
156
|
-
wrappedStopVoice,
|
|
157
|
-
wrappedInterrupt,
|
|
158
|
-
isVoiceChannelReady,
|
|
159
|
-
} = useVoiceConnectOrchestration(
|
|
160
|
-
agent,
|
|
161
|
-
voice,
|
|
162
|
-
interactionMode,
|
|
163
|
-
micStartsMuted,
|
|
164
|
-
orchestrationCallbacks,
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
const theme = useMemo(
|
|
168
|
-
() => ({
|
|
169
|
-
...defaultAgentAssistantTheme,
|
|
170
|
-
...ui.theme,
|
|
171
|
-
colors: { ...defaultAgentAssistantTheme.colors, ...ui.theme?.colors },
|
|
172
|
-
spacing: { ...defaultAgentAssistantTheme.spacing, ...ui.theme?.spacing },
|
|
173
|
-
radius: { ...defaultAgentAssistantTheme.radius, ...ui.theme?.radius },
|
|
174
|
-
typography: {
|
|
175
|
-
...defaultAgentAssistantTheme.typography,
|
|
176
|
-
...ui.theme?.typography,
|
|
177
|
-
},
|
|
178
|
-
}),
|
|
179
|
-
[ui.theme],
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
const sendText = useCallback(async () => {
|
|
183
|
-
const text = inputText.trim();
|
|
184
|
-
if (!text || agent.isLoading) return;
|
|
185
|
-
setInputText('');
|
|
186
|
-
await agent.sendMessage(text);
|
|
187
|
-
}, [agent, inputText]);
|
|
188
|
-
|
|
189
|
-
const selectPreset = useCallback(
|
|
190
|
-
async (preset: PresetMessage) => {
|
|
191
|
-
if (preset.autoSend) {
|
|
192
|
-
await agent.sendMessage(preset.text);
|
|
193
|
-
} else {
|
|
194
|
-
setInputText(preset.text);
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
[agent],
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
const value = useMemo<AgentAssistantContextValue>(
|
|
201
|
-
() => ({
|
|
202
|
-
...agent,
|
|
203
|
-
...voice,
|
|
204
|
-
startVoice: wrappedStartVoice,
|
|
205
|
-
stopVoice: wrappedStopVoice,
|
|
206
|
-
interrupt: wrappedInterrupt,
|
|
207
|
-
theme,
|
|
208
|
-
title: ui.title ?? 'AI Assistant',
|
|
209
|
-
placeholder: ui.placeholder ?? 'Type a message…',
|
|
210
|
-
presetMessages: ui.presetMessages ?? [],
|
|
211
|
-
interactionMode,
|
|
212
|
-
setInteractionMode,
|
|
213
|
-
inputText,
|
|
214
|
-
setInputText,
|
|
215
|
-
isVoiceAvailable,
|
|
216
|
-
isVoiceConnecting,
|
|
217
|
-
isMicMuted,
|
|
218
|
-
isMicHeldForAssistant,
|
|
219
|
-
toggleVoiceMicMute,
|
|
220
|
-
isVoiceChannelReady,
|
|
221
|
-
enableFileUpload: ui.enableFileUpload !== false,
|
|
222
|
-
sendText,
|
|
223
|
-
selectPreset,
|
|
224
|
-
}),
|
|
225
|
-
[
|
|
226
|
-
agent,
|
|
227
|
-
voice,
|
|
228
|
-
wrappedStartVoice,
|
|
229
|
-
wrappedStopVoice,
|
|
230
|
-
wrappedInterrupt,
|
|
231
|
-
theme,
|
|
232
|
-
ui.title,
|
|
233
|
-
ui.placeholder,
|
|
234
|
-
ui.presetMessages,
|
|
235
|
-
ui.enableFileUpload,
|
|
236
|
-
interactionMode,
|
|
237
|
-
setInteractionMode,
|
|
238
|
-
inputText,
|
|
239
|
-
isVoiceAvailable,
|
|
240
|
-
isVoiceConnecting,
|
|
241
|
-
isMicMuted,
|
|
242
|
-
isMicHeldForAssistant,
|
|
243
|
-
toggleVoiceMicMute,
|
|
244
|
-
isVoiceChannelReady,
|
|
245
|
-
sendText,
|
|
246
|
-
selectPreset,
|
|
247
|
-
voice.voiceStatus,
|
|
248
|
-
],
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
return (
|
|
252
|
-
<AgentAssistantContext.Provider value={value}>
|
|
253
|
-
{children}
|
|
254
|
-
</AgentAssistantContext.Provider>
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export function useAgentAssistant(): AgentAssistantContextValue {
|
|
259
|
-
const ctx = useContext(AgentAssistantContext);
|
|
260
|
-
if (!ctx) {
|
|
261
|
-
throw new Error(
|
|
262
|
-
'useAgentAssistant must be used within <NxtlinqAgentChat> or <AgentAssistantProvider>',
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
return ctx;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export function voiceStatusLabel(status: VoiceStatus): string {
|
|
269
|
-
const labels: Record<VoiceStatus, string> = {
|
|
270
|
-
idle: 'Ready',
|
|
271
|
-
listening: 'Listening',
|
|
272
|
-
transcribing: 'Transcribing',
|
|
273
|
-
thinking: 'Thinking',
|
|
274
|
-
generating: 'Generating',
|
|
275
|
-
speaking: 'Speaking',
|
|
276
|
-
};
|
|
277
|
-
return labels[status] ?? status;
|
|
278
|
-
}
|
package/src/legacy/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export { ChatBot } from './chatbot/ChatBot';
|
|
2
|
-
export { ChatBotProvider, useChatBot } from './chatbot/context/ChatBotContext';
|
|
3
|
-
|
|
4
|
-
export { ChatBotUI } from './chatbot/ui/ChatBotUI';
|
|
5
|
-
export { MessageInput } from './chatbot/ui/MessageInput';
|
|
6
|
-
export { MessageList } from './chatbot/ui/MessageList';
|
|
7
|
-
export { ModelSelector } from './chatbot/ui/ModelSelector';
|
|
8
|
-
export { NotificationModal } from './chatbot/ui/NotificationModal';
|
|
9
|
-
export { PermissionForm } from './chatbot/ui/PermissionForm';
|
|
10
|
-
export { PresetMessages } from './chatbot/ui/PresetMessages';
|
|
11
|
-
export { BerifyMeModal } from './chatbot/ui/BerifyMeModal';
|
|
12
|
-
|
|
13
|
-
export type {
|
|
14
|
-
AIModel,
|
|
15
|
-
AITMetadata,
|
|
16
|
-
ChatBotContextType,
|
|
17
|
-
ChatBotProps,
|
|
18
|
-
NovaError,
|
|
19
|
-
NovaResponse,
|
|
20
|
-
PresetMessage,
|
|
21
|
-
ToolCall,
|
|
22
|
-
ToolUse,
|
|
23
|
-
} from './chatbot/types/ChatBotTypes';
|
|
24
|
-
|
|
25
|
-
/** Alias for consumers migrating to the new package naming. */
|
|
26
|
-
export { ChatBot as NxtlinqChatBot } from './chatbot/ChatBot';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { AgentAssistantTheme } from '../types';
|
|
2
|
-
|
|
3
|
-
export const defaultAgentAssistantTheme: AgentAssistantTheme = {
|
|
4
|
-
colors: {
|
|
5
|
-
background: '#f8fafc',
|
|
6
|
-
surface: '#ffffff',
|
|
7
|
-
border: '#e2e8f0',
|
|
8
|
-
primary: '#2563eb',
|
|
9
|
-
primaryText: '#ffffff',
|
|
10
|
-
userBubble: '#2563eb',
|
|
11
|
-
userText: '#ffffff',
|
|
12
|
-
assistantBubble: '#f1f5f9',
|
|
13
|
-
assistantText: '#0f172a',
|
|
14
|
-
mutedText: '#64748b',
|
|
15
|
-
error: '#dc2626',
|
|
16
|
-
voiceActive: '#22c55e',
|
|
17
|
-
voiceSpeaking: '#ec4899',
|
|
18
|
-
},
|
|
19
|
-
spacing: { xs: 4, sm: 8, md: 16, lg: 24 },
|
|
20
|
-
radius: { bubble: 12, panel: 8, button: 8 },
|
|
21
|
-
typography: { titleSize: 17, bodySize: 15, captionSize: 13 },
|
|
22
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { Message, ToolUse as CoreToolUse } from '@bytexbyte/nxtlinq-ai-agent-core-development';
|
|
2
|
-
import type { NxtlinqAgentProviderProps } from '@bytexbyte/nxtlinq-ai-agent-web-development';
|
|
3
|
-
import type { CSSProperties } from 'react';
|
|
4
|
-
|
|
5
|
-
export type PresetMessage = {
|
|
6
|
-
text: string;
|
|
7
|
-
autoSend?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type AgentAssistantTheme = {
|
|
11
|
-
colors: {
|
|
12
|
-
background: string;
|
|
13
|
-
surface: string;
|
|
14
|
-
border: string;
|
|
15
|
-
primary: string;
|
|
16
|
-
primaryText: string;
|
|
17
|
-
userBubble: string;
|
|
18
|
-
userText: string;
|
|
19
|
-
assistantBubble: string;
|
|
20
|
-
assistantText: string;
|
|
21
|
-
mutedText: string;
|
|
22
|
-
error: string;
|
|
23
|
-
voiceActive: string;
|
|
24
|
-
voiceSpeaking: string;
|
|
25
|
-
};
|
|
26
|
-
spacing: {
|
|
27
|
-
xs: number;
|
|
28
|
-
sm: number;
|
|
29
|
-
md: number;
|
|
30
|
-
lg: number;
|
|
31
|
-
};
|
|
32
|
-
radius: {
|
|
33
|
-
bubble: number;
|
|
34
|
-
panel: number;
|
|
35
|
-
button: number;
|
|
36
|
-
};
|
|
37
|
-
typography: {
|
|
38
|
-
titleSize: number;
|
|
39
|
-
bodySize: number;
|
|
40
|
-
captionSize: number;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export type NxtlinqAgentChatProps = Omit<NxtlinqAgentProviderProps, 'children'> & {
|
|
45
|
-
children?: NxtlinqAgentProviderProps['children'];
|
|
46
|
-
title?: string;
|
|
47
|
-
placeholder?: string;
|
|
48
|
-
presetMessages?: PresetMessage[];
|
|
49
|
-
loadHistoryOnMount?: boolean;
|
|
50
|
-
historyLast?: number;
|
|
51
|
-
enableVoice?: boolean;
|
|
52
|
-
enableFileUpload?: boolean;
|
|
53
|
-
startInVoiceMode?: boolean;
|
|
54
|
-
startWithMicMuted?: boolean;
|
|
55
|
-
holdMicDuringAssistant?: boolean;
|
|
56
|
-
theme?: Partial<AgentAssistantTheme>;
|
|
57
|
-
style?: CSSProperties;
|
|
58
|
-
headerStyle?: CSSProperties;
|
|
59
|
-
onMessage?: NxtlinqAgentProviderProps['onMessage'];
|
|
60
|
-
onError?: NxtlinqAgentProviderProps['onError'];
|
|
61
|
-
onToolUse?: NxtlinqAgentProviderProps['onToolUse'];
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type ToolUse = CoreToolUse;
|
|
65
|
-
export type { Message };
|