@bytexbyte/nxtlinq-ai-agent-ui-react-development 0.1.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/dist/NxtlinqAgentChat.d.ts +26 -0
- package/dist/NxtlinqAgentChat.d.ts.map +1 -0
- package/dist/NxtlinqAgentChat.js +28 -0
- package/dist/components/AgentAssistantShell.d.ts +5 -0
- package/dist/components/AgentAssistantShell.d.ts.map +1 -0
- package/dist/components/AgentAssistantShell.js +52 -0
- package/dist/components/AgentComposer.d.ts +3 -0
- package/dist/components/AgentComposer.d.ts.map +1 -0
- package/dist/components/AgentComposer.js +60 -0
- package/dist/components/AgentMessageList.d.ts +3 -0
- package/dist/components/AgentMessageList.d.ts.map +1 -0
- package/dist/components/AgentMessageList.js +37 -0
- package/dist/components/AgentRemoteAudio.d.ts +4 -0
- package/dist/components/AgentRemoteAudio.d.ts.map +1 -0
- package/dist/components/AgentRemoteAudio.js +34 -0
- package/dist/components/AgentVoiceBar.d.ts +3 -0
- package/dist/components/AgentVoiceBar.d.ts.map +1 -0
- package/dist/components/AgentVoiceBar.js +91 -0
- package/dist/components/PresetMessageChips.d.ts +3 -0
- package/dist/components/PresetMessageChips.d.ts.map +1 -0
- package/dist/components/PresetMessageChips.js +23 -0
- package/dist/context/AgentAssistantContext.d.ts +32 -0
- package/dist/context/AgentAssistantContext.d.ts.map +1 -0
- package/dist/context/AgentAssistantContext.js +159 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/legacy/assets/images/adiSideItalicDataUri.d.ts +2 -0
- package/dist/legacy/assets/images/adiSideItalicDataUri.d.ts.map +1 -0
- package/dist/legacy/assets/images/adiSideItalicDataUri.js +1 -0
- package/dist/legacy/chatbot/ChatBot.d.ts +5 -0
- package/dist/legacy/chatbot/ChatBot.d.ts.map +1 -0
- package/dist/legacy/chatbot/ChatBot.js +35 -0
- package/dist/legacy/chatbot/context/ChatBotContext.d.ts +5 -0
- package/dist/legacy/chatbot/context/ChatBotContext.d.ts.map +1 -0
- package/dist/legacy/chatbot/context/ChatBotContext.js +2908 -0
- package/dist/legacy/chatbot/types/ChatBotTypes.d.ts +166 -0
- package/dist/legacy/chatbot/types/ChatBotTypes.d.ts.map +1 -0
- package/dist/legacy/chatbot/types/ChatBotTypes.js +1 -0
- package/dist/legacy/chatbot/ui/BerifyMeModal.d.ts +17 -0
- package/dist/legacy/chatbot/ui/BerifyMeModal.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/BerifyMeModal.js +110 -0
- package/dist/legacy/chatbot/ui/ChatBotUI.d.ts +3 -0
- package/dist/legacy/chatbot/ui/ChatBotUI.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/ChatBotUI.js +625 -0
- package/dist/legacy/chatbot/ui/MessageInput.d.ts +3 -0
- package/dist/legacy/chatbot/ui/MessageInput.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/MessageInput.js +321 -0
- package/dist/legacy/chatbot/ui/MessageList.d.ts +4 -0
- package/dist/legacy/chatbot/ui/MessageList.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/MessageList.js +455 -0
- package/dist/legacy/chatbot/ui/ModelSelector.d.ts +4 -0
- package/dist/legacy/chatbot/ui/ModelSelector.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/ModelSelector.js +122 -0
- package/dist/legacy/chatbot/ui/NotificationModal.d.ts +15 -0
- package/dist/legacy/chatbot/ui/NotificationModal.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/NotificationModal.js +53 -0
- package/dist/legacy/chatbot/ui/PermissionForm.d.ts +8 -0
- package/dist/legacy/chatbot/ui/PermissionForm.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/PermissionForm.js +465 -0
- package/dist/legacy/chatbot/ui/PresetMessages.d.ts +4 -0
- package/dist/legacy/chatbot/ui/PresetMessages.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/PresetMessages.js +33 -0
- package/dist/legacy/chatbot/ui/VoiceModePanel.d.ts +3 -0
- package/dist/legacy/chatbot/ui/VoiceModePanel.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/VoiceModePanel.js +95 -0
- package/dist/legacy/chatbot/ui/styles/isolatedStyles.d.ts +73 -0
- package/dist/legacy/chatbot/ui/styles/isolatedStyles.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/styles/isolatedStyles.js +985 -0
- package/dist/legacy/index.d.ts +14 -0
- package/dist/legacy/index.d.ts.map +1 -0
- package/dist/legacy/index.js +12 -0
- package/dist/theme/defaultTheme.d.ts +3 -0
- package/dist/theme/defaultTheme.d.ts.map +1 -0
- package/dist/theme/defaultTheme.js +20 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/voice/useVoiceConnectOrchestration.d.ts +21 -0
- package/dist/voice/useVoiceConnectOrchestration.d.ts.map +1 -0
- package/dist/voice/useVoiceConnectOrchestration.js +86 -0
- package/dist/voice/useVoiceMicState.d.ts +15 -0
- package/dist/voice/useVoiceMicState.d.ts.map +1 -0
- package/dist/voice/useVoiceMicState.js +94 -0
- package/dist/voice/useVoiceSilenceCommit.d.ts +10 -0
- package/dist/voice/useVoiceSilenceCommit.d.ts.map +1 -0
- package/dist/voice/useVoiceSilenceCommit.js +67 -0
- package/dist/voice/useVoiceTranscriptMessages.d.ts +16 -0
- package/dist/voice/useVoiceTranscriptMessages.d.ts.map +1 -0
- package/dist/voice/useVoiceTranscriptMessages.js +129 -0
- package/dist/voice/useWsRealtimeAudio.d.ts +18 -0
- package/dist/voice/useWsRealtimeAudio.d.ts.map +1 -0
- package/dist/voice/useWsRealtimeAudio.js +102 -0
- package/dist/voice/voiceMicConstants.d.ts +4 -0
- package/dist/voice/voiceMicConstants.d.ts.map +1 -0
- package/dist/voice/voiceMicConstants.js +10 -0
- package/dist/voice/ws/BrowserWsPcmPlayer.d.ts +23 -0
- package/dist/voice/ws/BrowserWsPcmPlayer.d.ts.map +1 -0
- package/dist/voice/ws/BrowserWsPcmPlayer.js +137 -0
- package/dist/voice/ws/BrowserWsPcmRecorder.d.ts +17 -0
- package/dist/voice/ws/BrowserWsPcmRecorder.d.ts.map +1 -0
- package/dist/voice/ws/BrowserWsPcmRecorder.js +71 -0
- package/dist/voice/ws/float32ToPcm16.d.ts +2 -0
- package/dist/voice/ws/float32ToPcm16.d.ts.map +1 -0
- package/dist/voice/ws/float32ToPcm16.js +8 -0
- package/dist/voice/ws/voiceSilenceConstants.d.ts +5 -0
- package/dist/voice/ws/voiceSilenceConstants.d.ts.map +1 -0
- package/dist/voice/ws/voiceSilenceConstants.js +4 -0
- package/dist/voice/ws/wsRealtimeConstants.d.ts +2 -0
- package/dist/voice/ws/wsRealtimeConstants.d.ts.map +1 -0
- package/dist/voice/ws/wsRealtimeConstants.js +1 -0
- package/package.json +60 -0
- package/src/NxtlinqAgentChat.tsx +79 -0
- package/src/components/AgentAssistantShell.tsx +104 -0
- package/src/components/AgentComposer.tsx +134 -0
- package/src/components/AgentMessageList.tsx +78 -0
- package/src/components/AgentRemoteAudio.tsx +34 -0
- package/src/components/AgentVoiceBar.tsx +173 -0
- package/src/components/PresetMessageChips.tsx +41 -0
- package/src/context/AgentAssistantContext.tsx +276 -0
- package/src/index.ts +78 -0
- package/src/legacy/assets/images/adiSideItalicDataUri.ts +1 -0
- package/src/legacy/chatbot/ChatBot.tsx +61 -0
- package/src/legacy/chatbot/context/ChatBotContext.tsx +3227 -0
- package/src/legacy/chatbot/types/ChatBotTypes.ts +195 -0
- package/src/legacy/chatbot/ui/BerifyMeModal.tsx +145 -0
- package/src/legacy/chatbot/ui/ChatBotUI.tsx +949 -0
- package/src/legacy/chatbot/ui/MessageInput.tsx +517 -0
- package/src/legacy/chatbot/ui/MessageList.tsx +764 -0
- package/src/legacy/chatbot/ui/ModelSelector.tsx +190 -0
- package/src/legacy/chatbot/ui/NotificationModal.tsx +110 -0
- package/src/legacy/chatbot/ui/PermissionForm.tsx +632 -0
- package/src/legacy/chatbot/ui/PresetMessages.tsx +50 -0
- package/src/legacy/chatbot/ui/VoiceModePanel.tsx +168 -0
- package/src/legacy/chatbot/ui/styles/isolatedStyles.ts +1058 -0
- package/src/legacy/index.ts +26 -0
- package/src/theme/defaultTheme.ts +22 -0
- package/src/types.ts +65 -0
- package/src/voice/useVoiceConnectOrchestration.ts +117 -0
- package/src/voice/useVoiceMicState.ts +117 -0
- package/src/voice/useVoiceTranscriptMessages.ts +173 -0
- package/src/voice/voiceMicConstants.ts +13 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { NxtlinqAgentChatProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Drop-in React Web assistant UI wired to `@bytexbyte/nxtlinq-ai-agent-web-development`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* import { NxtlinqAgentChat } from '@bytexbyte/nxtlinq-ai-agent-ui-react-development';
|
|
9
|
+
*
|
|
10
|
+
* export default function Page() {
|
|
11
|
+
* return (
|
|
12
|
+
* <NxtlinqAgentChat
|
|
13
|
+
* style={{ height: '100vh' }}
|
|
14
|
+
* serviceId="..."
|
|
15
|
+
* apiKey="..."
|
|
16
|
+
* apiSecret="..."
|
|
17
|
+
* environment="staging"
|
|
18
|
+
* pseudoId={userId}
|
|
19
|
+
* loadHistoryOnMount
|
|
20
|
+
* />
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function NxtlinqAgentChat({ title, placeholder, presetMessages, loadHistoryOnMount, historyLast, enableVoice, enableFileUpload, startInVoiceMode, startWithMicMuted, holdMicDuringAssistant, theme, style, headerStyle, onMessage, onError, onToolUse, children, fetchImpl, getTimezone, resetOnIdentityChange, ...agentConfig }: NxtlinqAgentChatProps): React.ReactElement;
|
|
26
|
+
//# sourceMappingURL=NxtlinqAgentChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NxtlinqAgentChat.d.ts","sourceRoot":"","sources":["../src/NxtlinqAgentChat.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,WAAW,EACX,cAAc,EACd,kBAA0B,EAC1B,WAAW,EACX,WAAkB,EAClB,gBAAuB,EACvB,gBAAwB,EACxB,iBAAwB,EACxB,sBAA6B,EAC7B,KAAK,EACL,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,SAAS,EACT,QAAQ,EACR,SAAS,EACT,WAAW,EACX,qBAAqB,EACrB,GAAG,WAAW,EACf,EAAE,qBAAqB,GAAG,KAAK,CAAC,YAAY,CA6B5C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { NxtlinqAgentProvider } from '@bytexbyte/nxtlinq-ai-agent-web-development';
|
|
3
|
+
import { AgentAssistantShell } from './components/AgentAssistantShell';
|
|
4
|
+
/**
|
|
5
|
+
* Drop-in React Web assistant UI wired to `@bytexbyte/nxtlinq-ai-agent-web-development`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { NxtlinqAgentChat } from '@bytexbyte/nxtlinq-ai-agent-ui-react-development';
|
|
10
|
+
*
|
|
11
|
+
* export default function Page() {
|
|
12
|
+
* return (
|
|
13
|
+
* <NxtlinqAgentChat
|
|
14
|
+
* style={{ height: '100vh' }}
|
|
15
|
+
* serviceId="..."
|
|
16
|
+
* apiKey="..."
|
|
17
|
+
* apiSecret="..."
|
|
18
|
+
* environment="staging"
|
|
19
|
+
* pseudoId={userId}
|
|
20
|
+
* loadHistoryOnMount
|
|
21
|
+
* />
|
|
22
|
+
* );
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function NxtlinqAgentChat({ title, placeholder, presetMessages, loadHistoryOnMount = false, historyLast, enableVoice = true, enableFileUpload = true, startInVoiceMode = false, startWithMicMuted = true, holdMicDuringAssistant = true, theme, style, headerStyle, onMessage, onError, onToolUse, children, fetchImpl, getTimezone, resetOnIdentityChange, ...agentConfig }) {
|
|
27
|
+
return (_jsxs(NxtlinqAgentProvider, { fetchImpl: fetchImpl, getTimezone: getTimezone, resetOnIdentityChange: resetOnIdentityChange, onMessage: onMessage, onError: onError, onToolUse: onToolUse, ...agentConfig, children: [_jsx(AgentAssistantShell, { title: title, placeholder: placeholder, presetMessages: presetMessages, loadHistoryOnMount: loadHistoryOnMount, historyLast: historyLast, enableVoice: enableVoice, enableFileUpload: enableFileUpload, startInVoiceMode: startInVoiceMode, startWithMicMuted: startWithMicMuted, holdMicDuringAssistant: holdMicDuringAssistant, theme: theme, style: style, headerStyle: headerStyle }), children] }));
|
|
28
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { NxtlinqAgentChatProps } from '../types';
|
|
3
|
+
export type AgentAssistantShellProps = Pick<NxtlinqAgentChatProps, 'title' | 'placeholder' | 'presetMessages' | 'enableVoice' | 'enableFileUpload' | 'theme' | 'style' | 'headerStyle' | 'loadHistoryOnMount' | 'historyLast' | 'startInVoiceMode' | 'startWithMicMuted' | 'holdMicDuringAssistant'>;
|
|
4
|
+
export declare function AgentAssistantShell(props: AgentAssistantShellProps): React.ReactElement;
|
|
5
|
+
//# sourceMappingURL=AgentAssistantShell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentAssistantShell.d.ts","sourceRoot":"","sources":["../../src/components/AgentAssistantShell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAK3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAOtD,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,qBAAqB,EACnB,OAAO,GACP,aAAa,GACb,gBAAgB,GAChB,aAAa,GACb,kBAAkB,GAClB,OAAO,GACP,OAAO,GACP,aAAa,GACb,oBAAoB,GACpB,aAAa,GACb,kBAAkB,GAClB,mBAAmB,GACnB,wBAAwB,CAC3B,CAAC;AA2DF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,KAAK,CAAC,YAAY,CAiBvF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { AgentAssistantProvider, useAgentAssistant, } from '../context/AgentAssistantContext';
|
|
4
|
+
import { AgentComposer } from './AgentComposer';
|
|
5
|
+
import { AgentMessageList } from './AgentMessageList';
|
|
6
|
+
import { AgentRemoteAudio } from './AgentRemoteAudio';
|
|
7
|
+
import { AgentVoiceBar } from './AgentVoiceBar';
|
|
8
|
+
import { PresetMessageChips } from './PresetMessageChips';
|
|
9
|
+
function AgentAssistantInner({ title, headerStyle, style, loadHistoryOnMount, historyLast, startInVoiceMode, }) {
|
|
10
|
+
const { theme, loadHistory, startVoice, isVoiceAvailable } = useAgentAssistant();
|
|
11
|
+
const [historyReady, setHistoryReady] = useState(!loadHistoryOnMount);
|
|
12
|
+
const voiceAutoStartRef = useRef(false);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (loadHistoryOnMount) {
|
|
15
|
+
void loadHistory({ last: historyLast ?? 50 }).finally(() => setHistoryReady(true));
|
|
16
|
+
}
|
|
17
|
+
}, [loadHistory, loadHistoryOnMount, historyLast]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!startInVoiceMode || !isVoiceAvailable || voiceAutoStartRef.current)
|
|
20
|
+
return;
|
|
21
|
+
voiceAutoStartRef.current = true;
|
|
22
|
+
void startVoice();
|
|
23
|
+
}, [startInVoiceMode, isVoiceAvailable, startVoice]);
|
|
24
|
+
return (_jsxs("div", { style: {
|
|
25
|
+
display: 'flex',
|
|
26
|
+
flexDirection: 'column',
|
|
27
|
+
flex: 1,
|
|
28
|
+
minHeight: 0,
|
|
29
|
+
backgroundColor: theme.colors.background,
|
|
30
|
+
...style,
|
|
31
|
+
}, children: [_jsx("header", { style: {
|
|
32
|
+
padding: theme.spacing.md,
|
|
33
|
+
borderBottom: `1px solid ${theme.colors.border}`,
|
|
34
|
+
backgroundColor: theme.colors.surface,
|
|
35
|
+
fontSize: theme.typography.titleSize,
|
|
36
|
+
fontWeight: 600,
|
|
37
|
+
color: theme.colors.assistantText,
|
|
38
|
+
...headerStyle,
|
|
39
|
+
}, children: title ?? 'AI Assistant' }), _jsx(PresetMessageChips, {}), historyReady ? _jsx(AgentMessageList, {}) : _jsx("div", { style: { flex: 1 } }), _jsx(AgentVoiceBar, {}), _jsx(AgentComposer, {}), _jsx(AgentRemoteAudio, {})] }));
|
|
40
|
+
}
|
|
41
|
+
export function AgentAssistantShell(props) {
|
|
42
|
+
return (_jsx(AgentAssistantProvider, { ui: {
|
|
43
|
+
title: props.title,
|
|
44
|
+
placeholder: props.placeholder,
|
|
45
|
+
presetMessages: props.presetMessages,
|
|
46
|
+
enableVoice: props.enableVoice,
|
|
47
|
+
enableFileUpload: props.enableFileUpload,
|
|
48
|
+
theme: props.theme,
|
|
49
|
+
startWithMicMuted: props.startWithMicMuted,
|
|
50
|
+
holdMicDuringAssistant: props.holdMicDuringAssistant,
|
|
51
|
+
}, children: _jsx(AgentAssistantInner, { ...props }) }));
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentComposer.d.ts","sourceRoot":"","sources":["../../src/components/AgentComposer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,wBAAgB,aAAa,IAAI,KAAK,CAAC,YAAY,GAAG,IAAI,CAkIzD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useAgentAssistant } from '../context/AgentAssistantContext';
|
|
4
|
+
export function AgentComposer() {
|
|
5
|
+
const { theme, placeholder, inputText, setInputText, sendText, isLoading, isVoiceAvailable, interactionMode, startVoice, isVoiceConnecting, enableFileUpload, sendMessage, } = useAgentAssistant();
|
|
6
|
+
const fileInputRef = React.useRef(null);
|
|
7
|
+
if (interactionMode === 'voice') {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const handleFiles = async (files) => {
|
|
11
|
+
if (!files?.length)
|
|
12
|
+
return;
|
|
13
|
+
const { fileToAttachment } = await import('@bytexbyte/nxtlinq-ai-agent-web-development');
|
|
14
|
+
const attachments = await Promise.all(Array.from(files).map((file) => fileToAttachment(file)));
|
|
15
|
+
await sendMessage(attachments.length ? `Uploaded ${attachments.length} file(s)` : '', { attachments });
|
|
16
|
+
if (fileInputRef.current)
|
|
17
|
+
fileInputRef.current.value = '';
|
|
18
|
+
};
|
|
19
|
+
return (_jsxs("div", { style: {
|
|
20
|
+
borderTop: `1px solid ${theme.colors.border}`,
|
|
21
|
+
backgroundColor: theme.colors.surface,
|
|
22
|
+
padding: theme.spacing.md,
|
|
23
|
+
}, children: [_jsxs("div", { style: { display: 'flex', gap: theme.spacing.sm, alignItems: 'flex-end' }, children: [enableFileUpload ? (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", onClick: () => fileInputRef.current?.click(), disabled: isLoading, style: {
|
|
24
|
+
width: 36,
|
|
25
|
+
height: 36,
|
|
26
|
+
borderRadius: theme.radius.button,
|
|
27
|
+
border: `1px solid ${theme.colors.border}`,
|
|
28
|
+
backgroundColor: theme.colors.surface,
|
|
29
|
+
cursor: 'pointer',
|
|
30
|
+
}, "aria-label": "Upload file", children: "+" }), _jsx("input", { ref: fileInputRef, type: "file", multiple: true, accept: "image/*,.pdf,.doc,.docx,.txt", style: { display: 'none' }, onChange: (e) => void handleFiles(e.target.files) })] })) : null, _jsx("textarea", { value: inputText, onChange: (e) => setInputText(e.target.value), placeholder: placeholder, rows: 2, disabled: isLoading, maxLength: 4000, style: {
|
|
31
|
+
flex: 1,
|
|
32
|
+
resize: 'none',
|
|
33
|
+
border: `1px solid ${theme.colors.border}`,
|
|
34
|
+
borderRadius: theme.radius.panel,
|
|
35
|
+
padding: theme.spacing.sm,
|
|
36
|
+
fontSize: theme.typography.bodySize,
|
|
37
|
+
color: theme.colors.assistantText,
|
|
38
|
+
} }), _jsx("button", { type: "button", onClick: () => void sendText(), disabled: isLoading || !inputText.trim(), style: {
|
|
39
|
+
backgroundColor: theme.colors.primary,
|
|
40
|
+
color: theme.colors.primaryText,
|
|
41
|
+
border: 'none',
|
|
42
|
+
borderRadius: theme.radius.button,
|
|
43
|
+
padding: `${theme.spacing.sm}px ${theme.spacing.md}px`,
|
|
44
|
+
fontWeight: 600,
|
|
45
|
+
opacity: isLoading || !inputText.trim() ? 0.5 : 1,
|
|
46
|
+
cursor: 'pointer',
|
|
47
|
+
}, children: "Send" })] }), isVoiceAvailable ? (_jsx("button", { type: "button", onClick: () => {
|
|
48
|
+
startVoice().catch((err) => {
|
|
49
|
+
console.warn('[nxtlinq] startVoice failed:', err);
|
|
50
|
+
});
|
|
51
|
+
}, disabled: isVoiceConnecting, style: {
|
|
52
|
+
display: 'block',
|
|
53
|
+
margin: `${theme.spacing.sm}px auto 0`,
|
|
54
|
+
border: 'none',
|
|
55
|
+
background: 'none',
|
|
56
|
+
color: theme.colors.primary,
|
|
57
|
+
fontSize: theme.typography.captionSize,
|
|
58
|
+
cursor: 'pointer',
|
|
59
|
+
}, children: isVoiceConnecting ? 'Connecting voice…' : 'Switch to voice mode' })) : null] }));
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentMessageList.d.ts","sourceRoot":"","sources":["../../src/components/AgentMessageList.tsx"],"names":[],"mappings":"AACA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAyCjD,wBAAgB,gBAAgB,IAAI,KAAK,CAAC,YAAY,CAmCrD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { useAgentAssistant } from '../context/AgentAssistantContext';
|
|
4
|
+
function MessageBubble({ message }) {
|
|
5
|
+
const { theme } = useAgentAssistant();
|
|
6
|
+
const isUser = message.role === 'user';
|
|
7
|
+
const displayText = message.partialContent && message.isStreaming
|
|
8
|
+
? message.partialContent
|
|
9
|
+
: message.content;
|
|
10
|
+
return (_jsx("div", { style: {
|
|
11
|
+
display: 'flex',
|
|
12
|
+
justifyContent: isUser ? 'flex-end' : 'flex-start',
|
|
13
|
+
marginBottom: theme.spacing.sm,
|
|
14
|
+
}, children: _jsxs("div", { style: {
|
|
15
|
+
maxWidth: '85%',
|
|
16
|
+
padding: `${theme.spacing.sm}px ${theme.spacing.md}px`,
|
|
17
|
+
borderRadius: theme.radius.bubble,
|
|
18
|
+
backgroundColor: isUser ? theme.colors.userBubble : theme.colors.assistantBubble,
|
|
19
|
+
color: isUser ? theme.colors.userText : theme.colors.assistantText,
|
|
20
|
+
fontSize: theme.typography.bodySize,
|
|
21
|
+
whiteSpace: 'pre-wrap',
|
|
22
|
+
}, children: [displayText || ' ', message.error ? (_jsx("div", { style: { color: theme.colors.error, fontSize: theme.typography.captionSize }, children: message.error })) : null] }) }));
|
|
23
|
+
}
|
|
24
|
+
export function AgentMessageList() {
|
|
25
|
+
const { messages, isLoading, theme } = useAgentAssistant();
|
|
26
|
+
const endRef = useRef(null);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
endRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
29
|
+
}, [messages.length, messages[messages.length - 1]?.content, messages[messages.length - 1]?.partialContent]);
|
|
30
|
+
return (_jsxs("div", { style: {
|
|
31
|
+
flex: 1,
|
|
32
|
+
minHeight: 0,
|
|
33
|
+
overflowY: 'auto',
|
|
34
|
+
padding: theme.spacing.md,
|
|
35
|
+
backgroundColor: theme.colors.background,
|
|
36
|
+
}, children: [messages.length === 0 ? (_jsx("p", { style: { textAlign: 'center', color: theme.colors.mutedText, marginTop: 40 }, children: "Send a message to start the conversation." })) : (messages.map((message) => (_jsx(MessageBubble, { message: message }, message.id)))), isLoading ? (_jsx("p", { style: { color: theme.colors.mutedText, fontSize: theme.typography.captionSize }, children: "Thinking\u2026" })) : null, _jsx("div", { ref: endRef })] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentRemoteAudio.d.ts","sourceRoot":"","sources":["../../src/components/AgentRemoteAudio.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAGjD,4EAA4E;AAC5E,wBAAgB,gBAAgB,IAAI,KAAK,CAAC,YAAY,GAAG,IAAI,CA6B5D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { useAgentAssistant } from '../context/AgentAssistantContext';
|
|
4
|
+
/** Plays assistant WebRTC remote audio with retry until stream is ready. */
|
|
5
|
+
export function AgentRemoteAudio() {
|
|
6
|
+
const { getRemoteAudioStream, isVoiceActive, isVoiceChannelReady } = useAgentAssistant();
|
|
7
|
+
const audioRef = useRef(null);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const audio = audioRef.current;
|
|
10
|
+
if (!audio || !isVoiceActive)
|
|
11
|
+
return;
|
|
12
|
+
let cancelled = false;
|
|
13
|
+
const attach = () => {
|
|
14
|
+
if (cancelled)
|
|
15
|
+
return;
|
|
16
|
+
const stream = getRemoteAudioStream();
|
|
17
|
+
if (!stream)
|
|
18
|
+
return;
|
|
19
|
+
audio.srcObject = stream;
|
|
20
|
+
void audio.play().catch(() => undefined);
|
|
21
|
+
};
|
|
22
|
+
attach();
|
|
23
|
+
const timer = window.setInterval(attach, 120);
|
|
24
|
+
return () => {
|
|
25
|
+
cancelled = true;
|
|
26
|
+
window.clearInterval(timer);
|
|
27
|
+
audio.pause();
|
|
28
|
+
audio.srcObject = null;
|
|
29
|
+
};
|
|
30
|
+
}, [getRemoteAudioStream, isVoiceActive, isVoiceChannelReady]);
|
|
31
|
+
if (!isVoiceActive)
|
|
32
|
+
return null;
|
|
33
|
+
return _jsx("audio", { ref: audioRef, autoPlay: true, playsInline: true, style: { display: 'none' } });
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentVoiceBar.d.ts","sourceRoot":"","sources":["../../src/components/AgentVoiceBar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAsC3C,wBAAgB,aAAa,IAAI,KAAK,CAAC,YAAY,GAAG,IAAI,CAsIzD"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useAgentAssistant, voiceStatusLabel, } from '../context/AgentAssistantContext';
|
|
4
|
+
function statusDotColor(status, theme) {
|
|
5
|
+
switch (status) {
|
|
6
|
+
case 'listening':
|
|
7
|
+
return theme.colors.voiceActive;
|
|
8
|
+
case 'speaking':
|
|
9
|
+
return theme.colors.voiceSpeaking;
|
|
10
|
+
case 'idle':
|
|
11
|
+
return theme.colors.mutedText;
|
|
12
|
+
default:
|
|
13
|
+
return theme.colors.primary;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function MicIcon({ color }) {
|
|
17
|
+
return (_jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: color, "aria-hidden": true, children: _jsx("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" }) }));
|
|
18
|
+
}
|
|
19
|
+
function MicOffIcon() {
|
|
20
|
+
return (_jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "#ef4444", "aria-hidden": true, children: _jsx("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" }) }));
|
|
21
|
+
}
|
|
22
|
+
export function AgentVoiceBar() {
|
|
23
|
+
const { theme, interactionMode, voiceStatus, voiceSessionId, isVoiceConnecting, isVoiceChannelReady, stopVoice, isVoiceAvailable, isMicMuted, isMicHeldForAssistant, toggleVoiceMicMute, } = useAgentAssistant();
|
|
24
|
+
const returnToTextMode = useCallback(() => {
|
|
25
|
+
void stopVoice();
|
|
26
|
+
}, [stopVoice]);
|
|
27
|
+
if (!isVoiceAvailable)
|
|
28
|
+
return null;
|
|
29
|
+
if (interactionMode !== 'voice' && !isVoiceConnecting)
|
|
30
|
+
return null;
|
|
31
|
+
const showConnecting = isVoiceConnecting;
|
|
32
|
+
const awaitingChannel = Boolean(voiceSessionId) &&
|
|
33
|
+
!isVoiceConnecting &&
|
|
34
|
+
!isVoiceChannelReady &&
|
|
35
|
+
voiceStatus === 'idle';
|
|
36
|
+
const statusHint = showConnecting
|
|
37
|
+
? 'Tap Back to text mode below to cancel'
|
|
38
|
+
: awaitingChannel
|
|
39
|
+
? 'Waiting for voice channel…'
|
|
40
|
+
: isMicHeldForAssistant
|
|
41
|
+
? 'Assistant is responding — tap mic to interrupt and speak'
|
|
42
|
+
: isMicMuted
|
|
43
|
+
? 'Mic is off — tap the mic when ready to speak'
|
|
44
|
+
: voiceStatus === 'listening'
|
|
45
|
+
? 'Start speaking'
|
|
46
|
+
: voiceStatus === 'speaking'
|
|
47
|
+
? 'Assistant is speaking…'
|
|
48
|
+
: voiceStatus === 'thinking'
|
|
49
|
+
? 'Thinking…'
|
|
50
|
+
: '';
|
|
51
|
+
return (_jsxs("div", { style: {
|
|
52
|
+
borderTop: `1px solid ${theme.colors.border}`,
|
|
53
|
+
backgroundColor: theme.colors.surface,
|
|
54
|
+
padding: theme.spacing.md,
|
|
55
|
+
}, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 10 }, children: [_jsxs("div", { style: {
|
|
56
|
+
flex: 1,
|
|
57
|
+
minWidth: 0,
|
|
58
|
+
border: `1px solid ${theme.colors.border}`,
|
|
59
|
+
borderRadius: 12,
|
|
60
|
+
backgroundColor: theme.colors.background,
|
|
61
|
+
padding: '8px 10px',
|
|
62
|
+
}, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 6 }, children: [_jsx("span", { style: {
|
|
63
|
+
width: 8,
|
|
64
|
+
height: 8,
|
|
65
|
+
borderRadius: 4,
|
|
66
|
+
backgroundColor: statusDotColor(voiceStatus, theme),
|
|
67
|
+
flexShrink: 0,
|
|
68
|
+
} }), _jsx("span", { style: {
|
|
69
|
+
color: theme.colors.assistantText,
|
|
70
|
+
fontSize: theme.typography.captionSize,
|
|
71
|
+
fontWeight: 600,
|
|
72
|
+
}, children: showConnecting || awaitingChannel ? 'Connecting' : voiceStatusLabel(voiceStatus) }), showConnecting ? (_jsx("span", { style: { color: theme.colors.mutedText, fontSize: theme.typography.captionSize }, children: "\u2026" })) : null] }), statusHint ? (_jsx("p", { style: {
|
|
73
|
+
margin: '4px 0 0',
|
|
74
|
+
color: theme.colors.mutedText,
|
|
75
|
+
fontSize: theme.typography.captionSize - 1,
|
|
76
|
+
}, children: statusHint })) : null] }), _jsx("button", { type: "button", onClick: toggleVoiceMicMute, disabled: showConnecting || awaitingChannel, style: {
|
|
77
|
+
border: 'none',
|
|
78
|
+
background: 'none',
|
|
79
|
+
padding: 8,
|
|
80
|
+
cursor: showConnecting || awaitingChannel ? 'not-allowed' : 'pointer',
|
|
81
|
+
opacity: showConnecting || awaitingChannel ? 0.45 : 1,
|
|
82
|
+
}, "aria-label": isMicMuted ? 'Unmute microphone' : 'Mute microphone', children: isMicMuted ? _jsx(MicOffIcon, {}) : _jsx(MicIcon, { color: theme.colors.assistantText }) })] }), _jsx("button", { type: "button", onClick: returnToTextMode, style: {
|
|
83
|
+
display: 'block',
|
|
84
|
+
margin: `${theme.spacing.sm}px auto 0`,
|
|
85
|
+
border: 'none',
|
|
86
|
+
background: 'none',
|
|
87
|
+
color: theme.colors.primary,
|
|
88
|
+
fontSize: theme.typography.captionSize,
|
|
89
|
+
cursor: 'pointer',
|
|
90
|
+
}, children: "Back to text mode" })] }));
|
|
91
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PresetMessageChips.d.ts","sourceRoot":"","sources":["../../src/components/PresetMessageChips.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,wBAAgB,kBAAkB,IAAI,KAAK,CAAC,YAAY,GAAG,IAAI,CAoC9D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useAgentAssistant } from '../context/AgentAssistantContext';
|
|
3
|
+
export function PresetMessageChips() {
|
|
4
|
+
const { presetMessages, selectPreset, theme, interactionMode } = useAgentAssistant();
|
|
5
|
+
if (!presetMessages.length || interactionMode === 'voice') {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
return (_jsx("div", { style: {
|
|
9
|
+
display: 'flex',
|
|
10
|
+
flexWrap: 'wrap',
|
|
11
|
+
gap: theme.spacing.sm,
|
|
12
|
+
padding: `${theme.spacing.sm}px ${theme.spacing.md}px`,
|
|
13
|
+
borderBottom: `1px solid ${theme.colors.border}`,
|
|
14
|
+
}, children: presetMessages.map((preset, index) => (_jsx("button", { type: "button", onClick: () => void selectPreset(preset), style: {
|
|
15
|
+
border: `1px solid ${theme.colors.border}`,
|
|
16
|
+
borderRadius: theme.radius.button,
|
|
17
|
+
padding: `${theme.spacing.xs}px ${theme.spacing.sm}px`,
|
|
18
|
+
backgroundColor: theme.colors.surface,
|
|
19
|
+
color: theme.colors.assistantText,
|
|
20
|
+
fontSize: theme.typography.captionSize,
|
|
21
|
+
cursor: 'pointer',
|
|
22
|
+
}, children: preset.text }, `${preset.text}-${index}`))) }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { VoiceStatus } from '@bytexbyte/nxtlinq-ai-agent-core-development';
|
|
2
|
+
import { type UseNxtlinqAgentResult, type UseNxtlinqVoiceResult } from '@bytexbyte/nxtlinq-ai-agent-web-development';
|
|
3
|
+
import React, { type ReactNode } from 'react';
|
|
4
|
+
import type { AgentAssistantTheme, NxtlinqAgentChatProps, PresetMessage } from '../types';
|
|
5
|
+
export type InteractionMode = 'text' | 'voice';
|
|
6
|
+
export type AgentAssistantContextValue = UseNxtlinqAgentResult & UseNxtlinqVoiceResult & {
|
|
7
|
+
theme: AgentAssistantTheme;
|
|
8
|
+
title: string;
|
|
9
|
+
placeholder: string;
|
|
10
|
+
presetMessages: PresetMessage[];
|
|
11
|
+
interactionMode: InteractionMode;
|
|
12
|
+
setInteractionMode: (mode: InteractionMode) => void;
|
|
13
|
+
inputText: string;
|
|
14
|
+
setInputText: (text: string) => void;
|
|
15
|
+
isVoiceAvailable: boolean;
|
|
16
|
+
isVoiceConnecting: boolean;
|
|
17
|
+
isMicMuted: boolean;
|
|
18
|
+
isMicHeldForAssistant: boolean;
|
|
19
|
+
toggleVoiceMicMute: () => void;
|
|
20
|
+
isVoiceChannelReady: boolean;
|
|
21
|
+
enableFileUpload: boolean;
|
|
22
|
+
sendText: () => Promise<void>;
|
|
23
|
+
selectPreset: (preset: PresetMessage) => Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
export type AgentAssistantProviderProps = {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
ui: Pick<NxtlinqAgentChatProps, 'title' | 'placeholder' | 'presetMessages' | 'enableVoice' | 'enableFileUpload' | 'theme' | 'startWithMicMuted' | 'holdMicDuringAssistant'>;
|
|
28
|
+
};
|
|
29
|
+
export declare function AgentAssistantProvider({ children, ui, }: AgentAssistantProviderProps): React.ReactElement;
|
|
30
|
+
export declare function useAgentAssistant(): AgentAssistantContextValue;
|
|
31
|
+
export declare function voiceStatusLabel(status: VoiceStatus): string;
|
|
32
|
+
//# sourceMappingURL=AgentAssistantContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentAssistantContext.d.ts","sourceRoot":"","sources":["../../src/context/AgentAssistantContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAChF,OAAO,EAGL,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC3B,MAAM,6CAA6C,CAAC;AACrD,OAAO,KAAK,EAAE,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAK1F,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,CAAC;AAE/C,MAAM,MAAM,0BAA0B,GAAG,qBAAqB,GAC5D,qBAAqB,GAAG;IACxB,KAAK,EAAE,mBAAmB,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,aAAa,EAAE,CAAC;IAChC,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,YAAY,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD,CAAC;AAIF,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,SAAS,CAAC;IACpB,EAAE,EAAE,IAAI,CACN,qBAAqB,EACnB,OAAO,GACP,aAAa,GACb,gBAAgB,GAChB,aAAa,GACb,kBAAkB,GAClB,OAAO,GACP,mBAAmB,GACnB,wBAAwB,CAC3B,CAAC;CACH,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,EACR,EAAE,GACH,EAAE,2BAA2B,GAAG,KAAK,CAAC,YAAY,CA4LlD;AAED,wBAAgB,iBAAiB,IAAI,0BAA0B,CAQ9D;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAU5D"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useNxtlinqAgent, useNxtlinqVoice, } from '@bytexbyte/nxtlinq-ai-agent-web-development';
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from 'react';
|
|
4
|
+
import { defaultAgentAssistantTheme } from '../theme/defaultTheme';
|
|
5
|
+
import { useVoiceConnectOrchestration } from '../voice/useVoiceConnectOrchestration';
|
|
6
|
+
import { useVoiceMicState } from '../voice/useVoiceMicState';
|
|
7
|
+
import { useVoiceTranscriptMessages } from '../voice/useVoiceTranscriptMessages';
|
|
8
|
+
const AgentAssistantContext = createContext(null);
|
|
9
|
+
export function AgentAssistantProvider({ children, ui, }) {
|
|
10
|
+
const agent = useNxtlinqAgent();
|
|
11
|
+
const voice = useNxtlinqVoice();
|
|
12
|
+
const [interactionMode, setInteractionModeState] = useState('text');
|
|
13
|
+
const [inputText, setInputText] = useState('');
|
|
14
|
+
const [isVoiceConnecting, setIsVoiceConnecting] = useState(false);
|
|
15
|
+
const isVoiceAvailable = ui.enableVoice !== false;
|
|
16
|
+
const micStartsMuted = ui.startWithMicMuted ?? true;
|
|
17
|
+
const handleVoiceBargeIn = useCallback(() => {
|
|
18
|
+
voice.interrupt();
|
|
19
|
+
}, [voice]);
|
|
20
|
+
const { isMicMuted, isMicHeldForAssistant, toggleVoiceMicMute, prepareForVoiceConnect, resetMicState, clearAssistantMicHold, } = useVoiceMicState(voice, isVoiceConnecting, {
|
|
21
|
+
startWithMicMuted: micStartsMuted,
|
|
22
|
+
holdMicDuringAssistant: ui.holdMicDuringAssistant ?? true,
|
|
23
|
+
onBargeIn: handleVoiceBargeIn,
|
|
24
|
+
});
|
|
25
|
+
const voiceTranscriptApi = useMemo(() => ({
|
|
26
|
+
getMessages: () => agent.agent.getSnapshot().messages,
|
|
27
|
+
setMessages: agent.setMessages,
|
|
28
|
+
syncVoiceTurnHistory: agent.syncVoiceTurnHistory,
|
|
29
|
+
}), [agent.agent, agent.setMessages, agent.syncVoiceTurnHistory]);
|
|
30
|
+
const { handleTranscript, handleDone, clearVoiceStream } = useVoiceTranscriptMessages(voiceTranscriptApi, interactionMode, voice.voiceSessionId);
|
|
31
|
+
const setInteractionMode = useCallback((mode) => {
|
|
32
|
+
if (mode === 'text' && interactionMode === 'voice') {
|
|
33
|
+
void voice.stopVoice('switch_to_text').then(() => {
|
|
34
|
+
clearVoiceStream();
|
|
35
|
+
resetMicState();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
setInteractionModeState(mode);
|
|
39
|
+
}, [interactionMode, voice, resetMicState, clearVoiceStream]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (interactionMode === 'text' && voice.voiceSessionId != null) {
|
|
42
|
+
void voice.stopVoice('mode_text_cleanup').then(() => {
|
|
43
|
+
clearVoiceStream();
|
|
44
|
+
resetMicState();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}, [interactionMode, voice.voiceSessionId, voice, resetMicState, clearVoiceStream]);
|
|
48
|
+
const orchestrationCallbacks = useMemo(() => ({
|
|
49
|
+
handleTranscript,
|
|
50
|
+
handleDone,
|
|
51
|
+
clearVoiceStream,
|
|
52
|
+
prepareForVoiceConnect,
|
|
53
|
+
resetMicState,
|
|
54
|
+
clearAssistantMicHold,
|
|
55
|
+
setInteractionMode,
|
|
56
|
+
setIsVoiceConnecting,
|
|
57
|
+
}), [
|
|
58
|
+
handleTranscript,
|
|
59
|
+
handleDone,
|
|
60
|
+
clearVoiceStream,
|
|
61
|
+
prepareForVoiceConnect,
|
|
62
|
+
resetMicState,
|
|
63
|
+
clearAssistantMicHold,
|
|
64
|
+
setInteractionMode,
|
|
65
|
+
]);
|
|
66
|
+
const { wrappedStartVoice, wrappedStopVoice, wrappedInterrupt, isVoiceChannelReady, } = useVoiceConnectOrchestration(agent, voice, interactionMode, micStartsMuted, orchestrationCallbacks);
|
|
67
|
+
const theme = useMemo(() => ({
|
|
68
|
+
...defaultAgentAssistantTheme,
|
|
69
|
+
...ui.theme,
|
|
70
|
+
colors: { ...defaultAgentAssistantTheme.colors, ...ui.theme?.colors },
|
|
71
|
+
spacing: { ...defaultAgentAssistantTheme.spacing, ...ui.theme?.spacing },
|
|
72
|
+
radius: { ...defaultAgentAssistantTheme.radius, ...ui.theme?.radius },
|
|
73
|
+
typography: {
|
|
74
|
+
...defaultAgentAssistantTheme.typography,
|
|
75
|
+
...ui.theme?.typography,
|
|
76
|
+
},
|
|
77
|
+
}), [ui.theme]);
|
|
78
|
+
const sendText = useCallback(async () => {
|
|
79
|
+
const text = inputText.trim();
|
|
80
|
+
if (!text || agent.isLoading)
|
|
81
|
+
return;
|
|
82
|
+
setInputText('');
|
|
83
|
+
await agent.sendMessage(text);
|
|
84
|
+
}, [agent, inputText]);
|
|
85
|
+
const selectPreset = useCallback(async (preset) => {
|
|
86
|
+
if (preset.autoSend) {
|
|
87
|
+
await agent.sendMessage(preset.text);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
setInputText(preset.text);
|
|
91
|
+
}
|
|
92
|
+
}, [agent]);
|
|
93
|
+
const value = useMemo(() => ({
|
|
94
|
+
...agent,
|
|
95
|
+
...voice,
|
|
96
|
+
startVoice: wrappedStartVoice,
|
|
97
|
+
stopVoice: wrappedStopVoice,
|
|
98
|
+
interrupt: wrappedInterrupt,
|
|
99
|
+
theme,
|
|
100
|
+
title: ui.title ?? 'AI Assistant',
|
|
101
|
+
placeholder: ui.placeholder ?? 'Type a message…',
|
|
102
|
+
presetMessages: ui.presetMessages ?? [],
|
|
103
|
+
interactionMode,
|
|
104
|
+
setInteractionMode,
|
|
105
|
+
inputText,
|
|
106
|
+
setInputText,
|
|
107
|
+
isVoiceAvailable,
|
|
108
|
+
isVoiceConnecting,
|
|
109
|
+
isMicMuted,
|
|
110
|
+
isMicHeldForAssistant,
|
|
111
|
+
toggleVoiceMicMute,
|
|
112
|
+
isVoiceChannelReady,
|
|
113
|
+
enableFileUpload: ui.enableFileUpload !== false,
|
|
114
|
+
sendText,
|
|
115
|
+
selectPreset,
|
|
116
|
+
}), [
|
|
117
|
+
agent,
|
|
118
|
+
voice,
|
|
119
|
+
wrappedStartVoice,
|
|
120
|
+
wrappedStopVoice,
|
|
121
|
+
wrappedInterrupt,
|
|
122
|
+
theme,
|
|
123
|
+
ui.title,
|
|
124
|
+
ui.placeholder,
|
|
125
|
+
ui.presetMessages,
|
|
126
|
+
ui.enableFileUpload,
|
|
127
|
+
interactionMode,
|
|
128
|
+
setInteractionMode,
|
|
129
|
+
inputText,
|
|
130
|
+
isVoiceAvailable,
|
|
131
|
+
isVoiceConnecting,
|
|
132
|
+
isMicMuted,
|
|
133
|
+
isMicHeldForAssistant,
|
|
134
|
+
toggleVoiceMicMute,
|
|
135
|
+
isVoiceChannelReady,
|
|
136
|
+
sendText,
|
|
137
|
+
selectPreset,
|
|
138
|
+
voice.voiceStatus,
|
|
139
|
+
]);
|
|
140
|
+
return (_jsx(AgentAssistantContext.Provider, { value: value, children: children }));
|
|
141
|
+
}
|
|
142
|
+
export function useAgentAssistant() {
|
|
143
|
+
const ctx = useContext(AgentAssistantContext);
|
|
144
|
+
if (!ctx) {
|
|
145
|
+
throw new Error('useAgentAssistant must be used within <NxtlinqAgentChat> or <AgentAssistantProvider>');
|
|
146
|
+
}
|
|
147
|
+
return ctx;
|
|
148
|
+
}
|
|
149
|
+
export function voiceStatusLabel(status) {
|
|
150
|
+
const labels = {
|
|
151
|
+
idle: 'Ready',
|
|
152
|
+
listening: 'Listening',
|
|
153
|
+
transcribing: 'Transcribing',
|
|
154
|
+
thinking: 'Thinking',
|
|
155
|
+
generating: 'Generating',
|
|
156
|
+
speaking: 'Speaking',
|
|
157
|
+
};
|
|
158
|
+
return labels[status] ?? status;
|
|
159
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { NxtlinqAgentChat } from './NxtlinqAgentChat';
|
|
2
|
+
export { ChatBot, NxtlinqChatBot, ChatBotProvider, useChatBot, ChatBotUI, MessageInput, MessageList, ModelSelector, NotificationModal, PermissionForm, PresetMessages, BerifyMeModal, } from './legacy';
|
|
3
|
+
export type { AIModel, AITMetadata, ChatBotContextType, ChatBotProps, NovaError, NovaResponse, ToolCall, } from './legacy';
|
|
4
|
+
export type { NxtlinqAgentChatProps, AgentAssistantTheme, PresetMessage, Message, ToolUse, } from './types';
|
|
5
|
+
export { defaultAgentAssistantTheme } from './theme/defaultTheme';
|
|
6
|
+
export { AgentAssistantProvider, useAgentAssistant, voiceStatusLabel, type AgentAssistantContextValue, type InteractionMode, } from './context/AgentAssistantContext';
|
|
7
|
+
export { AgentMessageList } from './components/AgentMessageList';
|
|
8
|
+
export { AgentComposer } from './components/AgentComposer';
|
|
9
|
+
export { AgentVoiceBar } from './components/AgentVoiceBar';
|
|
10
|
+
export { AgentRemoteAudio } from './components/AgentRemoteAudio';
|
|
11
|
+
export { PresetMessageChips } from './components/PresetMessageChips';
|
|
12
|
+
export { AgentAssistantShell } from './components/AgentAssistantShell';
|
|
13
|
+
export { NxtlinqAgentProvider, useNxtlinqAgent, useNxtlinqVoice, createNxtlinqAgentWeb, fileToAttachment, type NxtlinqAgentProviderProps, } from '@bytexbyte/nxtlinq-ai-agent-web-development';
|
|
14
|
+
export type { AgentEnvironment, AgentConfig, Attachment, AgentResponse, SendMessageOptions, NxtlinqAgentSnapshot, VoiceSession, VoiceStatus, } from '@bytexbyte/nxtlinq-ai-agent-core-development';
|
|
15
|
+
export { NxtlinqAgent, setApiHosts, VoiceNotSupportedError, STORAGE_KEYS, } from '@bytexbyte/nxtlinq-ai-agent-core-development';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EACL,OAAO,EACP,cAAc,EACd,eAAe,EACf,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,QAAQ,GACT,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,OAAO,EACP,OAAO,GACR,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,0BAA0B,EAC/B,KAAK,eAAe,GACrB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,yBAAyB,GAC/B,MAAM,6CAA6C,CAAC;AAErD,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,WAAW,GACZ,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EACL,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,YAAY,GACb,MAAM,8CAA8C,CAAC"}
|