@bytexbyte/nxtlinq-ai-agent-ui-react-development 0.2.4 → 0.3.0
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/ChatBotContext.d.ts.map +1 -1
- package/dist/context/ChatBotContext.js +55 -39
- package/dist/types/ChatBotTypes.d.ts +4 -2
- package/dist/types/ChatBotTypes.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/context/ChatBotContext.tsx +62 -39
- package/src/types/ChatBotTypes.ts +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../src/context/ChatBotContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAyB/B,OAAO,EAEL,kBAAkB,EAClB,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAM/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../src/context/ChatBotContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAyB/B,OAAO,EAEL,kBAAkB,EAClB,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAM/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAmuGlD,CAAC"}
|
|
@@ -14,7 +14,7 @@ export const useChatBot = () => {
|
|
|
14
14
|
}
|
|
15
15
|
return context;
|
|
16
16
|
};
|
|
17
|
-
export const ChatBotProvider = ({ onMessage, onError, onToolUse, presetMessages = [], placeholder = 'Type a message...', className = '', maxRetries = 3, retryDelay = 2000, serviceId, apiKey, apiSecret, environment = 'production', onVerifyWallet, permissionGroup, children,
|
|
17
|
+
export const ChatBotProvider = ({ onMessage, onError, onToolUse, presetMessages = [], placeholder = 'Type a message...', className = '', maxRetries = 3, retryDelay = 2000, serviceId, apiKey, apiSecret, serviceToken, getAuthToken, environment = 'production', onVerifyWallet, permissionGroup, children,
|
|
18
18
|
// AI Model related attributes
|
|
19
19
|
onModelChange,
|
|
20
20
|
// Storage mode configuration
|
|
@@ -35,14 +35,26 @@ customError,
|
|
|
35
35
|
piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary, }) => {
|
|
36
36
|
// Set API hosts immediately based on environment (before any API calls)
|
|
37
37
|
setApiHosts(environment);
|
|
38
|
-
const nxtlinqApi = React.useMemo(() =>
|
|
38
|
+
const nxtlinqApi = React.useMemo(() => (serviceToken || getAuthToken
|
|
39
|
+
? createNxtlinqApi({ apiKey, apiSecret, serviceToken, getAuthToken })
|
|
40
|
+
: createNxtlinqApi(apiKey ?? '', apiSecret ?? '')), [apiKey, apiSecret, serviceToken, getAuthToken]);
|
|
39
41
|
const apiKeyRef = React.useRef(apiKey);
|
|
40
42
|
const apiSecretRef = React.useRef(apiSecret);
|
|
43
|
+
const serviceTokenRef = React.useRef(serviceToken);
|
|
44
|
+
const getAuthTokenRef = React.useRef(getAuthToken);
|
|
41
45
|
const clientTtsVoiceRef = React.useRef(undefined);
|
|
42
46
|
React.useEffect(() => {
|
|
43
47
|
apiKeyRef.current = apiKey;
|
|
44
48
|
apiSecretRef.current = apiSecret;
|
|
45
|
-
|
|
49
|
+
serviceTokenRef.current = serviceToken;
|
|
50
|
+
getAuthTokenRef.current = getAuthToken;
|
|
51
|
+
}, [apiKey, apiSecret, serviceToken, getAuthToken]);
|
|
52
|
+
const authFields = React.useCallback(() => ({
|
|
53
|
+
apiKey: apiKeyRef.current,
|
|
54
|
+
apiSecret: apiSecretRef.current,
|
|
55
|
+
serviceToken: serviceTokenRef.current,
|
|
56
|
+
getAuthToken: getAuthTokenRef.current,
|
|
57
|
+
}), []);
|
|
46
58
|
// Custom hook
|
|
47
59
|
const handleSttCorrected = React.useCallback((rawText, corrected) => {
|
|
48
60
|
const normalizedRaw = normalizeTranscript(rawText);
|
|
@@ -55,8 +67,10 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
55
67
|
});
|
|
56
68
|
}, []);
|
|
57
69
|
const { isMicEnabled, transcript, partialTranscript, isCorrecting, start: startRecording, stop: stopRecording, clear: clearRecording } = useSpeechToTextFromMic({
|
|
58
|
-
apiKey,
|
|
59
|
-
apiSecret,
|
|
70
|
+
apiKey: apiKey ?? '',
|
|
71
|
+
apiSecret: apiSecret ?? '',
|
|
72
|
+
serviceToken,
|
|
73
|
+
getAuthToken,
|
|
60
74
|
phraseHints: sttGlossary,
|
|
61
75
|
onCorrected: handleSttCorrected,
|
|
62
76
|
});
|
|
@@ -160,6 +174,7 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
160
174
|
const lastPartialRangeRef = React.useRef(null);
|
|
161
175
|
const lastAutoSentTranscriptRef = React.useRef('');
|
|
162
176
|
const autoSendTimerRef = React.useRef(null);
|
|
177
|
+
const isCorrectingRef = React.useRef(false);
|
|
163
178
|
const lastCustomErrorRef = React.useRef(undefined);
|
|
164
179
|
function insertPartial(input, partial, caret) {
|
|
165
180
|
let start = caret;
|
|
@@ -239,8 +254,10 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
239
254
|
}
|
|
240
255
|
await streamSpeechToAudioContext({
|
|
241
256
|
text,
|
|
242
|
-
apiKey: apiKeyRef.current,
|
|
243
|
-
apiSecret: apiSecretRef.current,
|
|
257
|
+
apiKey: apiKeyRef.current ?? '',
|
|
258
|
+
apiSecret: apiSecretRef.current ?? '',
|
|
259
|
+
serviceToken: serviceTokenRef.current,
|
|
260
|
+
getAuthToken: getAuthTokenRef.current,
|
|
244
261
|
audioCtx: audioCtxRef.current,
|
|
245
262
|
signal: abortController.signal,
|
|
246
263
|
onSourceScheduled: (source) => {
|
|
@@ -267,8 +284,10 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
267
284
|
}
|
|
268
285
|
const synth = await synthesizeSpeechToBuffer({
|
|
269
286
|
text,
|
|
270
|
-
apiKey: apiKeyRef.current,
|
|
271
|
-
apiSecret: apiSecretRef.current,
|
|
287
|
+
apiKey: apiKeyRef.current ?? '',
|
|
288
|
+
apiSecret: apiSecretRef.current ?? '',
|
|
289
|
+
serviceToken: serviceTokenRef.current,
|
|
290
|
+
getAuthToken: getAuthTokenRef.current,
|
|
272
291
|
settings: clientTtsVoiceRef.current,
|
|
273
292
|
});
|
|
274
293
|
if (!synth)
|
|
@@ -499,11 +518,9 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
499
518
|
clearTimeout(autoSendTimerRef.current);
|
|
500
519
|
}
|
|
501
520
|
const currentTranscript = normalizedText.trim();
|
|
502
|
-
// Wait 3 seconds before auto-sending
|
|
503
|
-
// Timer will be cleared if user continues speaking (transcript/partialTranscript changes)
|
|
504
521
|
const scheduleAutoSend = (text, delay) => {
|
|
505
522
|
autoSendTimerRef.current = setTimeout(() => {
|
|
506
|
-
if (
|
|
523
|
+
if (isCorrectingRef.current) {
|
|
507
524
|
// Correction still in flight — re-check in 300ms
|
|
508
525
|
autoSendTimerRef.current = null;
|
|
509
526
|
scheduleAutoSend(text, 300);
|
|
@@ -528,7 +545,11 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
528
545
|
autoSendTimerRef.current = null;
|
|
529
546
|
}
|
|
530
547
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
531
|
-
}, [transcript, autoSendEnabled, isMicEnabled, isLoading
|
|
548
|
+
}, [transcript, autoSendEnabled, isMicEnabled, isLoading]);
|
|
549
|
+
// Keep isCorrectingRef in sync with isCorrecting state
|
|
550
|
+
React.useEffect(() => {
|
|
551
|
+
isCorrectingRef.current = isCorrecting;
|
|
552
|
+
}, [isCorrecting]);
|
|
532
553
|
// Clear timer when user continues speaking (partialTranscript updates)
|
|
533
554
|
React.useEffect(() => {
|
|
534
555
|
if (partialTranscript && partialTranscript.trim() && autoSendEnabled && isMicEnabled && autoSendTimerRef.current) {
|
|
@@ -761,7 +782,7 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
761
782
|
React.useEffect(() => {
|
|
762
783
|
const fetchModels = async () => {
|
|
763
784
|
try {
|
|
764
|
-
const result = await nxtlinqApi.agent.getServiceModels(
|
|
785
|
+
const result = await nxtlinqApi.agent.getServiceModels(authFields());
|
|
765
786
|
if ('availableModels' in result && Array.isArray(result.availableModels)) {
|
|
766
787
|
setModelsFromApi(result.availableModels);
|
|
767
788
|
}
|
|
@@ -772,7 +793,7 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
772
793
|
}
|
|
773
794
|
};
|
|
774
795
|
fetchModels();
|
|
775
|
-
}, [
|
|
796
|
+
}, [authFields, nxtlinqApi]);
|
|
776
797
|
// Validate selectedModelIndex against effectiveAvailableModels
|
|
777
798
|
React.useEffect(() => {
|
|
778
799
|
// Check if selectedModelIndex is out of bounds
|
|
@@ -1361,8 +1382,7 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
1361
1382
|
return false;
|
|
1362
1383
|
}
|
|
1363
1384
|
const checkToolPermissionResult = await nxtlinqApi.agent.checkToolPermission({
|
|
1364
|
-
|
|
1365
|
-
apiSecret,
|
|
1385
|
+
...authFields(),
|
|
1366
1386
|
aitToken: currentToken,
|
|
1367
1387
|
controller: currentHitAddress,
|
|
1368
1388
|
toolName: requiredPermission
|
|
@@ -1444,8 +1464,7 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
1444
1464
|
}, [effectiveAvailableModels, selectedModelIndex]);
|
|
1445
1465
|
const updateSuggestions = React.useCallback(async (pseudoId, externalId) => {
|
|
1446
1466
|
const result = await nxtlinqApi.agent.generateSuggestions({
|
|
1447
|
-
|
|
1448
|
-
apiSecret,
|
|
1467
|
+
...authFields(),
|
|
1449
1468
|
pseudoId,
|
|
1450
1469
|
externalId
|
|
1451
1470
|
});
|
|
@@ -1533,8 +1552,7 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
1533
1552
|
}
|
|
1534
1553
|
const response = await nxtlinqApi.agent.sendMessage({
|
|
1535
1554
|
model: currentModel.value,
|
|
1536
|
-
|
|
1537
|
-
apiSecret,
|
|
1555
|
+
...authFields(),
|
|
1538
1556
|
pseudoId: pseudoId,
|
|
1539
1557
|
externalId: localStorage.getItem('walletAddress') || undefined,
|
|
1540
1558
|
customUserInfo,
|
|
@@ -1899,11 +1917,10 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
1899
1917
|
}
|
|
1900
1918
|
: msg));
|
|
1901
1919
|
// Update message content in database if assistantMessageId is available
|
|
1902
|
-
if (response.assistantMessageId
|
|
1920
|
+
if (response.assistantMessageId) {
|
|
1903
1921
|
try {
|
|
1904
1922
|
await nxtlinqApi.agent.updateMessageContent({
|
|
1905
|
-
|
|
1906
|
-
apiSecret,
|
|
1923
|
+
...authFields(),
|
|
1907
1924
|
messageId: response.assistantMessageId,
|
|
1908
1925
|
content: finalContent,
|
|
1909
1926
|
});
|
|
@@ -1939,11 +1956,10 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
1939
1956
|
mergedContent += `\n\n${replyText}`;
|
|
1940
1957
|
}
|
|
1941
1958
|
// Update message content in database if assistantMessageId is available
|
|
1942
|
-
if (response.assistantMessageId
|
|
1959
|
+
if (response.assistantMessageId) {
|
|
1943
1960
|
try {
|
|
1944
1961
|
await nxtlinqApi.agent.updateMessageContent({
|
|
1945
|
-
|
|
1946
|
-
apiSecret,
|
|
1962
|
+
...authFields(),
|
|
1947
1963
|
messageId: response.assistantMessageId,
|
|
1948
1964
|
content: mergedContent,
|
|
1949
1965
|
});
|
|
@@ -2254,8 +2270,10 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
2254
2270
|
}
|
|
2255
2271
|
}, [textToSpeechEnabled, stopTextToSpeechAndReset]);
|
|
2256
2272
|
const { isVoiceMode, voiceStatus, isVoiceConnecting, isMicMuted, remoteAudioRef, enterVoiceMode, exitVoiceMode, toggleMicMute: toggleVoiceMicMute, interruptVoice, micRms, } = useVoiceMode({
|
|
2257
|
-
apiKey,
|
|
2258
|
-
apiSecret,
|
|
2273
|
+
apiKey: apiKey ?? '',
|
|
2274
|
+
apiSecret: apiSecret ?? '',
|
|
2275
|
+
serviceToken,
|
|
2276
|
+
getAuthToken,
|
|
2259
2277
|
pseudoId,
|
|
2260
2278
|
externalId: hitAddress || undefined,
|
|
2261
2279
|
aitId: ait?.aitId,
|
|
@@ -2359,15 +2377,14 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
2359
2377
|
}, [requiresGesture, textToSpeechEnabled, retryTtsWithGesture]);
|
|
2360
2378
|
const uploadAttachment = React.useCallback(async (file) => {
|
|
2361
2379
|
const result = await nxtlinqApi.agent.uploadAttachment({
|
|
2362
|
-
|
|
2363
|
-
apiSecret,
|
|
2380
|
+
...authFields(),
|
|
2364
2381
|
pseudoId,
|
|
2365
2382
|
file,
|
|
2366
2383
|
});
|
|
2367
2384
|
if ('error' in result)
|
|
2368
2385
|
return result;
|
|
2369
2386
|
return { url: result.url };
|
|
2370
|
-
}, [nxtlinqApi,
|
|
2387
|
+
}, [nxtlinqApi, authFields, pseudoId]);
|
|
2371
2388
|
// Handle preset message
|
|
2372
2389
|
const handlePresetMessage = (message) => {
|
|
2373
2390
|
// If preset is configured as auto-send, avoid duplicate sends when user clicks repeatedly
|
|
@@ -2860,26 +2877,23 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
2860
2877
|
const updateExternalId = async () => {
|
|
2861
2878
|
const externalId = hitAddress;
|
|
2862
2879
|
await nxtlinqApi.agent.updateMessagesExternalIdByPseudoId({
|
|
2863
|
-
|
|
2864
|
-
apiSecret,
|
|
2880
|
+
...authFields(),
|
|
2865
2881
|
pseudoId,
|
|
2866
2882
|
externalId: externalId,
|
|
2867
2883
|
});
|
|
2868
2884
|
await nxtlinqApi.agent.cloneUserProfileByPseudoId({
|
|
2869
|
-
|
|
2870
|
-
apiSecret,
|
|
2885
|
+
...authFields(),
|
|
2871
2886
|
pseudoId,
|
|
2872
2887
|
externalId: externalId,
|
|
2873
2888
|
});
|
|
2874
2889
|
await nxtlinqApi.agent.cloneUserTopicByPseudoId({
|
|
2875
|
-
|
|
2876
|
-
apiSecret,
|
|
2890
|
+
...authFields(),
|
|
2877
2891
|
pseudoId,
|
|
2878
2892
|
externalId: externalId,
|
|
2879
2893
|
});
|
|
2880
2894
|
};
|
|
2881
2895
|
updateExternalId();
|
|
2882
|
-
}, [hitAddress, nxtlinqApi,
|
|
2896
|
+
}, [hitAddress, nxtlinqApi, authFields, pseudoId]);
|
|
2883
2897
|
const contextValue = {
|
|
2884
2898
|
// State
|
|
2885
2899
|
messages,
|
|
@@ -2986,6 +3000,8 @@ piiDisplayMode = 'redacted', voiceThresholds, debugVoiceRms = false, sttGlossary
|
|
|
2986
3000
|
serviceId,
|
|
2987
3001
|
apiKey,
|
|
2988
3002
|
apiSecret,
|
|
3003
|
+
serviceToken,
|
|
3004
|
+
getAuthToken,
|
|
2989
3005
|
onVerifyWallet,
|
|
2990
3006
|
permissionGroup,
|
|
2991
3007
|
onModelChange,
|
|
@@ -44,8 +44,10 @@ export interface ChatBotProps {
|
|
|
44
44
|
maxRetries?: number;
|
|
45
45
|
retryDelay?: number;
|
|
46
46
|
serviceId: string;
|
|
47
|
-
apiKey
|
|
48
|
-
apiSecret
|
|
47
|
+
apiKey?: string;
|
|
48
|
+
apiSecret?: string;
|
|
49
|
+
serviceToken?: string;
|
|
50
|
+
getAuthToken?: () => Promise<string>;
|
|
49
51
|
environment?: 'production' | 'staging';
|
|
50
52
|
onVerifyWallet?: () => Promise<{
|
|
51
53
|
token: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatBotTypes.d.ts","sourceRoot":"","sources":["../../src/types/ChatBotTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAErI,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAGD,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AACD,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,KA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AE,MAAM,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/E,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,cAAc,EAAE,MAAM,IAAI,CAAC;IAG3B,MAAM,EAAE,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC,CAAC;IAC3D,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,sBAAsB,EAAE,OAAO,CAAC;IAChC,cAAc,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,KAAK,EAAE,YAAY,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytexbyte/nxtlinq-ai-agent-ui-react-development",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Official React Web UI for nxtlinq AI Agent — drop-in chat widget",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@bytexbyte/nxtlinq-ai-agent-core-development": "0.4.4",
|
|
42
|
-
"@bytexbyte/nxtlinq-ai-agent-web-development": "0.
|
|
42
|
+
"@bytexbyte/nxtlinq-ai-agent-web-development": "0.3.0",
|
|
43
43
|
"@emotion/react": "^11.14.0",
|
|
44
44
|
"@emotion/styled": "^11.14.1",
|
|
45
45
|
"@mui/icons-material": "^7.2.0",
|
|
@@ -56,6 +56,8 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
56
56
|
serviceId,
|
|
57
57
|
apiKey,
|
|
58
58
|
apiSecret,
|
|
59
|
+
serviceToken,
|
|
60
|
+
getAuthToken,
|
|
59
61
|
environment = 'production',
|
|
60
62
|
onVerifyWallet,
|
|
61
63
|
permissionGroup,
|
|
@@ -86,15 +88,31 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
86
88
|
// Set API hosts immediately based on environment (before any API calls)
|
|
87
89
|
setApiHosts(environment);
|
|
88
90
|
|
|
89
|
-
const nxtlinqApi = React.useMemo(
|
|
91
|
+
const nxtlinqApi = React.useMemo(
|
|
92
|
+
() => (serviceToken || getAuthToken
|
|
93
|
+
? createNxtlinqApi({ apiKey, apiSecret, serviceToken, getAuthToken })
|
|
94
|
+
: createNxtlinqApi(apiKey ?? '', apiSecret ?? '')),
|
|
95
|
+
[apiKey, apiSecret, serviceToken, getAuthToken],
|
|
96
|
+
);
|
|
90
97
|
|
|
91
98
|
const apiKeyRef = React.useRef(apiKey);
|
|
92
99
|
const apiSecretRef = React.useRef(apiSecret);
|
|
100
|
+
const serviceTokenRef = React.useRef(serviceToken);
|
|
101
|
+
const getAuthTokenRef = React.useRef(getAuthToken);
|
|
93
102
|
const clientTtsVoiceRef = React.useRef<ClientTtsVoiceSettings | undefined>(undefined);
|
|
94
103
|
React.useEffect(() => {
|
|
95
104
|
apiKeyRef.current = apiKey;
|
|
96
105
|
apiSecretRef.current = apiSecret;
|
|
97
|
-
|
|
106
|
+
serviceTokenRef.current = serviceToken;
|
|
107
|
+
getAuthTokenRef.current = getAuthToken;
|
|
108
|
+
}, [apiKey, apiSecret, serviceToken, getAuthToken]);
|
|
109
|
+
|
|
110
|
+
const authFields = React.useCallback(() => ({
|
|
111
|
+
apiKey: apiKeyRef.current,
|
|
112
|
+
apiSecret: apiSecretRef.current,
|
|
113
|
+
serviceToken: serviceTokenRef.current,
|
|
114
|
+
getAuthToken: getAuthTokenRef.current,
|
|
115
|
+
}), []);
|
|
98
116
|
|
|
99
117
|
// Custom hook
|
|
100
118
|
const handleSttCorrected = React.useCallback((rawText: string, corrected: string) => {
|
|
@@ -108,8 +126,10 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
108
126
|
}, []);
|
|
109
127
|
|
|
110
128
|
const { isMicEnabled, transcript, partialTranscript, isCorrecting, start: startRecording, stop: stopRecording, clear: clearRecording } = useSpeechToTextFromMic({
|
|
111
|
-
apiKey,
|
|
112
|
-
apiSecret,
|
|
129
|
+
apiKey: apiKey ?? '',
|
|
130
|
+
apiSecret: apiSecret ?? '',
|
|
131
|
+
serviceToken,
|
|
132
|
+
getAuthToken,
|
|
113
133
|
phraseHints: sttGlossary,
|
|
114
134
|
onCorrected: handleSttCorrected,
|
|
115
135
|
});
|
|
@@ -224,6 +244,7 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
224
244
|
const lastPartialRangeRef = React.useRef<{ start: number; end: number } | null>(null);
|
|
225
245
|
const lastAutoSentTranscriptRef = React.useRef<string>('');
|
|
226
246
|
const autoSendTimerRef = React.useRef<NodeJS.Timeout | null>(null);
|
|
247
|
+
const isCorrectingRef = React.useRef(false);
|
|
227
248
|
const lastCustomErrorRef = React.useRef<string | undefined>(undefined);
|
|
228
249
|
|
|
229
250
|
function insertPartial(input: string, partial: string, caret: number) {
|
|
@@ -314,8 +335,10 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
314
335
|
|
|
315
336
|
await streamSpeechToAudioContext({
|
|
316
337
|
text,
|
|
317
|
-
apiKey: apiKeyRef.current,
|
|
318
|
-
apiSecret: apiSecretRef.current,
|
|
338
|
+
apiKey: apiKeyRef.current ?? '',
|
|
339
|
+
apiSecret: apiSecretRef.current ?? '',
|
|
340
|
+
serviceToken: serviceTokenRef.current,
|
|
341
|
+
getAuthToken: getAuthTokenRef.current,
|
|
319
342
|
audioCtx: audioCtxRef.current,
|
|
320
343
|
signal: abortController.signal,
|
|
321
344
|
onSourceScheduled: (source: AudioBufferSourceNode) => {
|
|
@@ -340,8 +363,10 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
340
363
|
|
|
341
364
|
const synth = await synthesizeSpeechToBuffer({
|
|
342
365
|
text,
|
|
343
|
-
apiKey: apiKeyRef.current,
|
|
344
|
-
apiSecret: apiSecretRef.current,
|
|
366
|
+
apiKey: apiKeyRef.current ?? '',
|
|
367
|
+
apiSecret: apiSecretRef.current ?? '',
|
|
368
|
+
serviceToken: serviceTokenRef.current,
|
|
369
|
+
getAuthToken: getAuthTokenRef.current,
|
|
345
370
|
settings: clientTtsVoiceRef.current,
|
|
346
371
|
});
|
|
347
372
|
if (!synth) throw new Error('Failed to get audio buffer');
|
|
@@ -588,11 +613,9 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
588
613
|
|
|
589
614
|
const currentTranscript = normalizedText.trim();
|
|
590
615
|
|
|
591
|
-
// Wait 3 seconds before auto-sending
|
|
592
|
-
// Timer will be cleared if user continues speaking (transcript/partialTranscript changes)
|
|
593
616
|
const scheduleAutoSend = (text: string, delay: number) => {
|
|
594
617
|
autoSendTimerRef.current = setTimeout(() => {
|
|
595
|
-
if (
|
|
618
|
+
if (isCorrectingRef.current) {
|
|
596
619
|
// Correction still in flight — re-check in 300ms
|
|
597
620
|
autoSendTimerRef.current = null;
|
|
598
621
|
scheduleAutoSend(text, 300);
|
|
@@ -617,7 +640,12 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
617
640
|
autoSendTimerRef.current = null;
|
|
618
641
|
}
|
|
619
642
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
620
|
-
}, [transcript, autoSendEnabled, isMicEnabled, isLoading
|
|
643
|
+
}, [transcript, autoSendEnabled, isMicEnabled, isLoading]);
|
|
644
|
+
|
|
645
|
+
// Keep isCorrectingRef in sync with isCorrecting state
|
|
646
|
+
React.useEffect(() => {
|
|
647
|
+
isCorrectingRef.current = isCorrecting;
|
|
648
|
+
}, [isCorrecting]);
|
|
621
649
|
|
|
622
650
|
// Clear timer when user continues speaking (partialTranscript updates)
|
|
623
651
|
React.useEffect(() => {
|
|
@@ -881,7 +909,7 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
881
909
|
React.useEffect(() => {
|
|
882
910
|
const fetchModels = async () => {
|
|
883
911
|
try {
|
|
884
|
-
const result = await nxtlinqApi.agent.getServiceModels(
|
|
912
|
+
const result = await nxtlinqApi.agent.getServiceModels(authFields());
|
|
885
913
|
|
|
886
914
|
if ('availableModels' in result && Array.isArray(result.availableModels)) {
|
|
887
915
|
setModelsFromApi(result.availableModels);
|
|
@@ -893,7 +921,7 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
893
921
|
};
|
|
894
922
|
|
|
895
923
|
fetchModels();
|
|
896
|
-
}, [
|
|
924
|
+
}, [authFields, nxtlinqApi]);
|
|
897
925
|
|
|
898
926
|
// Validate selectedModelIndex against effectiveAvailableModels
|
|
899
927
|
React.useEffect(() => {
|
|
@@ -1527,8 +1555,7 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
1527
1555
|
}
|
|
1528
1556
|
|
|
1529
1557
|
const checkToolPermissionResult = await nxtlinqApi.agent.checkToolPermission({
|
|
1530
|
-
|
|
1531
|
-
apiSecret,
|
|
1558
|
+
...authFields(),
|
|
1532
1559
|
aitToken: currentToken!,
|
|
1533
1560
|
controller: currentHitAddress!,
|
|
1534
1561
|
toolName: requiredPermission
|
|
@@ -1623,8 +1650,7 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
1623
1650
|
|
|
1624
1651
|
const updateSuggestions = React.useCallback(async (pseudoId: string, externalId?: string) => {
|
|
1625
1652
|
const result = await nxtlinqApi.agent.generateSuggestions({
|
|
1626
|
-
|
|
1627
|
-
apiSecret,
|
|
1653
|
+
...authFields(),
|
|
1628
1654
|
pseudoId,
|
|
1629
1655
|
externalId
|
|
1630
1656
|
});
|
|
@@ -1727,8 +1753,7 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
1727
1753
|
|
|
1728
1754
|
const response: AgentResponse = await nxtlinqApi.agent.sendMessage({
|
|
1729
1755
|
model: currentModel.value,
|
|
1730
|
-
|
|
1731
|
-
apiSecret,
|
|
1756
|
+
...authFields(),
|
|
1732
1757
|
pseudoId: pseudoId,
|
|
1733
1758
|
externalId: localStorage.getItem('walletAddress') || undefined,
|
|
1734
1759
|
customUserInfo,
|
|
@@ -2131,11 +2156,10 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
2131
2156
|
));
|
|
2132
2157
|
|
|
2133
2158
|
// Update message content in database if assistantMessageId is available
|
|
2134
|
-
if (response.assistantMessageId
|
|
2159
|
+
if (response.assistantMessageId) {
|
|
2135
2160
|
try {
|
|
2136
2161
|
await nxtlinqApi.agent.updateMessageContent({
|
|
2137
|
-
|
|
2138
|
-
apiSecret,
|
|
2162
|
+
...authFields(),
|
|
2139
2163
|
messageId: response.assistantMessageId,
|
|
2140
2164
|
content: finalContent,
|
|
2141
2165
|
});
|
|
@@ -2172,11 +2196,10 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
2172
2196
|
}
|
|
2173
2197
|
|
|
2174
2198
|
// Update message content in database if assistantMessageId is available
|
|
2175
|
-
if (response.assistantMessageId
|
|
2199
|
+
if (response.assistantMessageId) {
|
|
2176
2200
|
try {
|
|
2177
2201
|
await nxtlinqApi.agent.updateMessageContent({
|
|
2178
|
-
|
|
2179
|
-
apiSecret,
|
|
2202
|
+
...authFields(),
|
|
2180
2203
|
messageId: response.assistantMessageId,
|
|
2181
2204
|
content: mergedContent,
|
|
2182
2205
|
});
|
|
@@ -2511,8 +2534,10 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
2511
2534
|
interruptVoice,
|
|
2512
2535
|
micRms,
|
|
2513
2536
|
} = useVoiceMode({
|
|
2514
|
-
apiKey,
|
|
2515
|
-
apiSecret,
|
|
2537
|
+
apiKey: apiKey ?? '',
|
|
2538
|
+
apiSecret: apiSecret ?? '',
|
|
2539
|
+
serviceToken,
|
|
2540
|
+
getAuthToken,
|
|
2516
2541
|
pseudoId,
|
|
2517
2542
|
externalId: hitAddress || undefined,
|
|
2518
2543
|
aitId: ait?.aitId,
|
|
@@ -2622,14 +2647,13 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
2622
2647
|
|
|
2623
2648
|
const uploadAttachment = React.useCallback(async (file: File): Promise<{ url: string } | { error: string }> => {
|
|
2624
2649
|
const result = await nxtlinqApi.agent.uploadAttachment({
|
|
2625
|
-
|
|
2626
|
-
apiSecret,
|
|
2650
|
+
...authFields(),
|
|
2627
2651
|
pseudoId,
|
|
2628
2652
|
file,
|
|
2629
2653
|
});
|
|
2630
2654
|
if ('error' in result) return result;
|
|
2631
2655
|
return { url: result.url };
|
|
2632
|
-
}, [nxtlinqApi,
|
|
2656
|
+
}, [nxtlinqApi, authFields, pseudoId]);
|
|
2633
2657
|
|
|
2634
2658
|
// Handle preset message
|
|
2635
2659
|
const handlePresetMessage = (message: PresetMessage) => {
|
|
@@ -3166,29 +3190,26 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
3166
3190
|
const updateExternalId = async () => {
|
|
3167
3191
|
const externalId = hitAddress;
|
|
3168
3192
|
await nxtlinqApi.agent.updateMessagesExternalIdByPseudoId({
|
|
3169
|
-
|
|
3170
|
-
apiSecret,
|
|
3193
|
+
...authFields(),
|
|
3171
3194
|
pseudoId,
|
|
3172
3195
|
externalId: externalId,
|
|
3173
3196
|
})
|
|
3174
3197
|
|
|
3175
3198
|
await nxtlinqApi.agent.cloneUserProfileByPseudoId({
|
|
3176
|
-
|
|
3177
|
-
apiSecret,
|
|
3199
|
+
...authFields(),
|
|
3178
3200
|
pseudoId,
|
|
3179
3201
|
externalId: externalId,
|
|
3180
3202
|
});
|
|
3181
3203
|
|
|
3182
3204
|
await nxtlinqApi.agent.cloneUserTopicByPseudoId({
|
|
3183
|
-
|
|
3184
|
-
apiSecret,
|
|
3205
|
+
...authFields(),
|
|
3185
3206
|
pseudoId,
|
|
3186
3207
|
externalId: externalId,
|
|
3187
3208
|
})
|
|
3188
3209
|
}
|
|
3189
3210
|
|
|
3190
3211
|
updateExternalId()
|
|
3191
|
-
}, [hitAddress, nxtlinqApi,
|
|
3212
|
+
}, [hitAddress, nxtlinqApi, authFields, pseudoId]);
|
|
3192
3213
|
|
|
3193
3214
|
const contextValue: ChatBotContextType = {
|
|
3194
3215
|
// State
|
|
@@ -3300,6 +3321,8 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
3300
3321
|
serviceId,
|
|
3301
3322
|
apiKey,
|
|
3302
3323
|
apiSecret,
|
|
3324
|
+
serviceToken,
|
|
3325
|
+
getAuthToken,
|
|
3303
3326
|
onVerifyWallet,
|
|
3304
3327
|
permissionGroup,
|
|
3305
3328
|
onModelChange,
|
|
@@ -3320,4 +3343,4 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
|
|
|
3320
3343
|
{children}
|
|
3321
3344
|
</ChatBotContext.Provider>
|
|
3322
3345
|
);
|
|
3323
|
-
};
|
|
3346
|
+
};
|
|
@@ -53,8 +53,10 @@ export interface ChatBotProps {
|
|
|
53
53
|
maxRetries?: number;
|
|
54
54
|
retryDelay?: number;
|
|
55
55
|
serviceId: string;
|
|
56
|
-
apiKey
|
|
57
|
-
apiSecret
|
|
56
|
+
apiKey?: string;
|
|
57
|
+
apiSecret?: string;
|
|
58
|
+
serviceToken?: string;
|
|
59
|
+
getAuthToken?: () => Promise<string>;
|
|
58
60
|
environment?: 'production' | 'staging'; // API environment (default: production)
|
|
59
61
|
onVerifyWallet?: () => Promise<{
|
|
60
62
|
token: string;
|